<el-button type="warning"
icon="el-icon-setting"
size="mini"
@click="showSetRightDialog(scope.row)">分配权限</el-button>
<!-- 分配权限的对话框 -->
<el-dialog title="分配权限"
:visible.sync="setRightDialogVisible"
width="50%">
<!-- 树形控件 -->
<el-tree :data="rightsList"
:props="treeProps"
show-checkbox
node-key="id"
default-expand-all
:default-checked-keys="defKeys"></el-tree>
<span slot="footer"
class="dialog-footer">
<el-button @click="setRightDialogVisible = false">取 消</el-button>
<el-button type="primary"
@click="setRightDialogVisible = false">确 定</el-button>
</span>
</el-dialog>
<script>
export default {
name: 'Roles',
mixins: [],
components: {},
props: {},
data () {
return {
// 所有角色列表数据
rolelist: [],
// 控制全新啊对话框的显示和隐藏
setRightDialogVisible: false,
// 所有权限数据
rightsList: [],
// 树形控件的属性绑定对象
treeProps: {
label: 'authName',
children: 'children'
},
// 默认选中选中节点Id值的数组
defKeys: []
}
},
watch: {},
computed: {},
methods: {
// 展示分配权限的对话框
async showSetRightDialog (role) {
// 获取所有权限数据
const { data: res } = await this.$http.get('rights/tree')
if (res.meta.status !== 200) {
return this.$message.error('获取权限数据失败')
}
// 把获取到的权限数据保存到data中
this.rightsList = res.data
console.log(this.rightsList)
// 递归获取三级节点的Id
this.getleafKeys(role, this.defKeys)
this.setRightDialogVisible = true
},
// 通过递归的形式,户去交涉下所有三级权限的id,并保存到defKeys数组中
getleafKeys (node, arr) {
// 如果当前node节点不包含children属性,则是三级节点
if (!node.children) {
return arr.push(node.id)
}
node.children.forEach(item => {
this.getleafKeys(item, arr)
})
}
},
created () {
this.getRolesList()
},
mounted () { }
}
</script>