<重点>更新权限

This commit is contained in:
xing 2020-06-22 17:27:19 +08:00
parent a48b3f0557
commit a0dd85cdfd

View File

@ -44,10 +44,26 @@
<template scope="scope"> <template scope="scope">
<el-button size="mini" icon="el-icon-edit" type="primary" @click="edit(scope.row.id)">编辑</el-button> <el-button size="mini" icon="el-icon-edit" type="primary" @click="edit(scope.row.id)">编辑</el-button>
<el-button size="mini" icon="el-icon-delete" type="danger">删除</el-button> <el-button size="mini" icon="el-icon-delete" type="danger">删除</el-button>
<el-button size="mini" icon="el-icon-setting" type="warning">分配权限</el-button> <el-button size="mini" icon="el-icon-setting" @click="setRole(scope.row)" type="warning">分配权限</el-button>
</template> </template>
</el-table-column> </el-table-column>
</el-table> </el-table>
<el-dialog title="分配权限" :visible.sync="dialogVisible" @close="selectKey=[]">
<el-tree
:data="rights"
:props="props"
node-key="id"
:default-checked-keys="selectKey"
default-expand-all
show-checkbox
ref="treeRef"
>
</el-tree>
<span slot="footer" class="dialog-footer">
<el-button @click="dialogVisible=false">取消</el-button>
<el-button type="primary" @click="sub()">确定</el-button>
</span>
</el-dialog>
</el-card> </el-card>
</div> </div>
</template> </template>
@ -57,10 +73,50 @@ export default {
name: 'roles', name: 'roles',
data () { data () {
return { return {
data: [] data: [],
selectKey: [],
dialogVisible: false,
rights: [],
id: 0,
props: {
children: 'children',
label: 'authName'
}
} }
}, },
methods: { methods: {
sub () {
const keys = [...this.$refs.treeRef.getCheckedKeys(),
...this.$refs.treeRef.getHalfCheckedKeys()].join(',')
this.$http.post(`roles/${this.id}/rights`, { rids: keys }).then(response => {
const res = response.data
if (res.meta.status !== 200) {
return this.$message.error(res.meta.msg)
}
this.$message.success(res.meta.msg)
this.list()
this.dialogVisible = false
})
},
select (v) {
if (v) {
v.forEach(vv => {
this.selectKey.push(vv.id)
if (vv.children) {
this.select(vv.children)
}
})
}
},
setRole (row) {
this.id = row.id
this.select(row.children)
this.dialogVisible = true
this.$http.get('rights/tree').then(response => {
const res = response.data
this.rights = res.data
}).catch(error => error)
},
edit (id) { edit (id) {
}, },