|
|
@@ -1,26 +1,36 @@
|
|
|
<template>
|
|
|
<el-drawer title="权限设置" :visible.sync="showStatus" size="70%" :before-close="closeFn">
|
|
|
<div class="role-set-wrap">
|
|
|
- <div class="role-list">
|
|
|
+ <div class="role-list" v-for="(item, index) in permTree" :key="index">
|
|
|
<el-checkbox
|
|
|
- :indeterminate="isIndeterminate"
|
|
|
- v-model="checkAll"
|
|
|
- @change="handleCheckAllChange"
|
|
|
- >全选</el-checkbox
|
|
|
+ :indeterminate="isIndeterminate[index]"
|
|
|
+ v-model="checkAll[index]"
|
|
|
+ @change="handleCheckAllChange($event, index)"
|
|
|
+ >{{ item.authName }}</el-checkbox
|
|
|
>
|
|
|
<div style="margin: 15px 0;"></div>
|
|
|
- <el-checkbox-group v-model="checkedCities" @change="handleCheckedCitiesChange">
|
|
|
- <el-checkbox v-for="city in cities" :label="city" :key="city">{{
|
|
|
- city
|
|
|
- }}</el-checkbox>
|
|
|
+ <el-checkbox-group
|
|
|
+ v-model="checkedPerm"
|
|
|
+ @change="handlecheckedPermChange($event, index)"
|
|
|
+ >
|
|
|
+ <el-checkbox
|
|
|
+ v-for="(items, subIndex) in item.children"
|
|
|
+ :label="items.id"
|
|
|
+ :key="items.id"
|
|
|
+ >{{ items.authName }}</el-checkbox
|
|
|
+ >
|
|
|
</el-checkbox-group>
|
|
|
</div>
|
|
|
</div>
|
|
|
+ <!-- button -->
|
|
|
+ <div class="button-wrap flex-center">
|
|
|
+ <el-button size="mini" @click="closeFn">关闭</el-button>
|
|
|
+ <el-button type="primary" size="mini" @click="saveFn">保存</el-button>
|
|
|
+ </div>
|
|
|
</el-drawer>
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
-const cityOptions = ['上海', '北京', '广州', '深圳'];
|
|
|
export default {
|
|
|
name: 'role-set',
|
|
|
props: {
|
|
|
@@ -37,11 +47,11 @@ export default {
|
|
|
return {
|
|
|
showStatus: false,
|
|
|
data: {},
|
|
|
+ permTree: [],
|
|
|
|
|
|
- checkAll: false,
|
|
|
- checkedCities: ['上海', '北京'],
|
|
|
- cities: cityOptions,
|
|
|
- isIndeterminate: true
|
|
|
+ checkAll: [],
|
|
|
+ checkedPerm: [],
|
|
|
+ isIndeterminate: []
|
|
|
};
|
|
|
},
|
|
|
watch: {
|
|
|
@@ -54,23 +64,70 @@ export default {
|
|
|
},
|
|
|
methods: {
|
|
|
init() {
|
|
|
- this.$service.sassAuth.authList().then(res => {
|
|
|
- console.log(res);
|
|
|
+ this._getTreeB().then(res => {
|
|
|
+ console.log('res', res);
|
|
|
+ // this._getAuthB
|
|
|
+ });
|
|
|
+ },
|
|
|
+ async _getTreeB() {
|
|
|
+ let data = {};
|
|
|
+ await this.$service.common.permTree({ endId: 1 }).then(res => {
|
|
|
+ this.permTree = res;
|
|
|
+ this.permTree.map(() => {
|
|
|
+ this.isIndeterminate.push(false);
|
|
|
+ this.checkAll.push(false);
|
|
|
+ });
|
|
|
+ data = res;
|
|
|
});
|
|
|
+ return data;
|
|
|
+ },
|
|
|
+ async _getAuthB() {
|
|
|
+ let data = {};
|
|
|
+ await this.$service.common.permAuth().then(res => {
|
|
|
+ data = res;
|
|
|
+ });
|
|
|
+ return data;
|
|
|
+ },
|
|
|
+
|
|
|
+ saveFn() {
|
|
|
+ console.log('this.info', this.info);
|
|
|
+ this.$service.auth
|
|
|
+ .authUpdate({
|
|
|
+ roleId: this.info.roleId,
|
|
|
+ authIdList: this.checkedPerm
|
|
|
+ })
|
|
|
+ .then(res => {
|
|
|
+ this.closeFn();
|
|
|
+ this.$message.success('保存成功!');
|
|
|
+ });
|
|
|
},
|
|
|
+
|
|
|
closeFn(done) {
|
|
|
this.$emit('update:show', false);
|
|
|
- done();
|
|
|
+ if (done) {
|
|
|
+ done();
|
|
|
+ }
|
|
|
},
|
|
|
|
|
|
- handleCheckAllChange(val) {
|
|
|
- this.checkedCities = val ? cityOptions : [];
|
|
|
- this.isIndeterminate = false;
|
|
|
+ handleCheckAllChange(val, index) {
|
|
|
+ let arr = this.permTree[index].children
|
|
|
+ ? this.permTree[index].children
|
|
|
+ : this.permTree[index];
|
|
|
+
|
|
|
+ arr = arr.map(e => e.id);
|
|
|
+
|
|
|
+ this.checkedPerm = val ? arr : [];
|
|
|
+ this.$set(this.isIndeterminate, index, false);
|
|
|
},
|
|
|
- handleCheckedCitiesChange(value) {
|
|
|
+ handlecheckedPermChange(value, index) {
|
|
|
let checkedCount = value.length;
|
|
|
- this.checkAll = checkedCount === this.cities.length;
|
|
|
- this.isIndeterminate = checkedCount > 0 && checkedCount < this.cities.length;
|
|
|
+ let arrLen = this.permTree[index].children ? this.permTree[index].children.length : 0;
|
|
|
+
|
|
|
+ let checkAllStatus = checkedCount === arrLen;
|
|
|
+ this.$set(this.checkAll, index, checkAllStatus);
|
|
|
+
|
|
|
+ let isIndeterminateStatus = checkedCount > 0 && checkedCount < arrLen;
|
|
|
+ this.$set(this.isIndeterminate, index, isIndeterminateStatus);
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
@@ -79,5 +136,9 @@ export default {
|
|
|
<style lang="scss" scoped>
|
|
|
.role-set-wrap {
|
|
|
padding: 0 20px;
|
|
|
+ height: calc(100% - 50px);
|
|
|
+}
|
|
|
+.button-wrap {
|
|
|
+ padding-left: 20px;
|
|
|
}
|
|
|
</style>
|