<template>
|
<el-dialog v-dialogDrag :visible.sync="currentDialogVisible" title="数据权限设置" class="dialog-container" width="980px" @open="onOpen">
|
<el-table ref="table" :data="tableData" style="width: 100%">
|
<el-table-column label="模块" width="180">
|
<template slot-scope="{row}">
|
<el-checkbox v-model="row.allChecked" @change="(val)=>{selectAll(val, row)}"></el-checkbox>
|
<span style="margin-left: 10px">{{ row.moduleName }}</span>
|
</template>
|
</el-table-column>
|
<el-table-column label="权限点">
|
<template slot-scope="{row}">
|
<div class="padding-bottom-10">
|
<el-checkbox v-model="row.isAll">全部</el-checkbox>
|
</div>
|
<el-checkbox v-for="(item, index) in row.authNodeList" :key="index" :disabled="row.isAll" v-model="item.isCheck">{{ item.nodeName }}</el-checkbox>
|
</template>
|
</el-table-column>
|
</el-table>
|
|
<span slot="footer" class="dialog-footer">
|
<el-button @click="currentDialogVisible = false">取 消</el-button>
|
<el-button :loading="isSave" type="primary" icon="el-icon-yrt-baocun2" @click="save">保存</el-button>
|
</span>
|
</el-dialog>
|
</template>
|
|
<script>
|
export default {
|
props: {
|
visible: {
|
type: Boolean,
|
default: false
|
},
|
label: {
|
type: String,
|
default: null
|
},
|
userId: {
|
type: Number,
|
required: true
|
}
|
},
|
data() {
|
return {
|
isSave: false,
|
tableData: []
|
};
|
},
|
computed: {
|
// 显示窗口
|
currentDialogVisible: {
|
get: function() {
|
return this.visible;
|
},
|
set: function(val) {
|
this.$emit("update:visible", val);
|
}
|
}
|
},
|
watch: {},
|
created() {},
|
methods: {
|
// 初始化数据
|
init() {
|
const url = "/api/auth/getDataAuth";
|
const params = {
|
openNodeApi: true,
|
id: this.userId
|
};
|
this.common.ajax(
|
url,
|
params,
|
res => {
|
this.common.showMsg(res);
|
if (res.result) {
|
this.tableData = res.data;
|
this.tableData.forEach(item => {
|
var allChecked = true;
|
item.authNodeList.forEach(node => {
|
if (!node.isCheck) {
|
allChecked = false;
|
}
|
});
|
item.allChecked = allChecked;
|
// 是否全部
|
const allNode = item.authNodeList.find(node => node.node_Id === 0);
|
this.$set(item, "isAll", allNode ? allNode.isCheck : false);
|
|
// 排除掉0
|
item.authNodeList = item.authNodeList.filter(node => node.node_Id !== 0);
|
});
|
}
|
},
|
this.$refs.table
|
);
|
},
|
// 对话框打开事件
|
onOpen() {
|
this.init();
|
},
|
// 全选
|
selectAll(val, row) {
|
row.authNodeList.forEach(item => {
|
item.isCheck = val;
|
});
|
},
|
save() {
|
const _tableData = JSON.parse(JSON.stringify(this.tableData));
|
|
_tableData.forEach(item => {
|
item.user_Id = this.userId;
|
item.authNodeList.forEach(node => {
|
delete node.nodeName;
|
});
|
item.authNodeList = item.authNodeList.filter(node => node.isCheck);
|
const allNode = item.authNodeList.find(node => node.node_Id === 0);
|
if (!allNode) {
|
item.authNodeList.push({
|
node_Id: 0,
|
isCheck: item.isAll
|
});
|
} else {
|
allNode.isCheck = item.isAll;
|
}
|
});
|
const url = "/api/auth/saveUserDataAuth";
|
const params = {
|
code: JSON.stringify(_tableData)
|
};
|
this.common.ajax(
|
url,
|
params,
|
res => {
|
this.common.showMsg(res);
|
this.currentDialogVisible = false;
|
},
|
this.$refs.table
|
);
|
}
|
}
|
};
|
</script>
|
|
<style lang="scss" scoped>
|
.dialog-container {
|
/deep/ .el-upload-list {
|
margin-right: 20px;
|
}
|
/deep/ .scrollbar-wrap {
|
max-height: 400px;
|
overflow-x: hidden;
|
padding: 0px;
|
}
|
.msg-container {
|
margin: 0;
|
padding: 0;
|
.msg-item {
|
margin: 0;
|
padding: 5px 0;
|
word-wrap: break-word;
|
}
|
}
|
}
|
</style>
|