刘翔宇-旅管家 3 years ago
parent a37f0794a8
commit acb3114d76

@ -3,7 +3,7 @@
<!-- 查询配置 --> <!-- 查询配置 -->
<div> <div>
<div ref="lxHeader"> <div ref="lxHeader">
<LxHeader icon="md-apps" text="权限管理" style="margin-bottom: 10px; border: 0px; margin-top: 15px"> <LxHeader icon="md-apps" style="margin-bottom: 10px; border: 0px; margin-top: 15px" text="权限管理">
<div slot="content"></div> <div slot="content"></div>
<slot> <slot>
</slot> </slot>
@ -17,10 +17,10 @@
<div slot="title" class="clearfix" style="height: 32px;line-height: 32px;"> <div slot="title" class="clearfix" style="height: 32px;line-height: 32px;">
<span>角色列表</span> <span>角色列表</span>
</div> </div>
<div style="overflow: auto;" :style="{height:height+'px'}"> <div :style="{height:height+'px'}" style="overflow: auto;">
<el-scrollbar style="flex: 1"> <el-scrollbar style="flex: 1">
<el-tabs tab-position="left" v-model="activeRole" @tab-click="roleChange"> <el-tabs v-model="activeRole" tab-position="left" @tab-click="roleChange">
<el-tab-pane :label="item.name" :name="item.rowid" v-for="(item,index) in rolelist"> <el-tab-pane v-for="(item,index) in rolelist" :key="item.id" :label="item.name" :name="item.rowid">
</el-tab-pane> </el-tab-pane>
</el-tabs> </el-tabs>
</el-scrollbar> </el-scrollbar>
@ -34,17 +34,19 @@
<Button style="float: right;" type="primary" @click="savepermission"></Button> <Button style="float: right;" type="primary" @click="savepermission"></Button>
</div> </div>
<div style="overflow: auto;" :style="{height:height+'px'}"> <div :style="{height:height+'px'}" style="overflow: auto;">
<el-scrollbar style="flex: 1"> <el-scrollbar style="flex: 1">
<el-tree ref="tree" :data="tree" show-checkbox style="padding: 15px" node-key="id" default-expand-all <el-tree ref="tree" :data="tree" :expand-on-click-node="false" default-expand-all node-key="id" show-checkbox
:expand-on-click-node="false"> style="padding: 15px"
<div class="action-group" slot-scope="{ node, data }"> >
<div class="action-text" :style="{ width: (4 - data.lv) * 18 + 150 + 'px' }"> <div slot-scope="{ node, data }" class="action-group">
<div :style="{ width: (4 - data.lv) * 18 + 150 + 'px' }" class="action-text">
{{ data.name }} {{ data.name }}
</div> </div>
<div class="action-item"> <div class="action-item">
<el-checkbox v-for="(item, index) in data.auth_node_tags_array" :key="index" <el-checkbox v-for="(item, index) in data.auth_node_tags_array" :key="index"
v-model="item.checked" @change="() => {}"> v-model="item.checked" @change="()=>{}"
>
{{ item.name }} {{ item.name }}
</el-checkbox> </el-checkbox>
</div> </div>
@ -60,254 +62,245 @@
</template> </template>
<script> <script>
import LxHeader from "@/components/LxHeader/index.vue"; import LxHeader from '@/components/LxHeader/index.vue'
import { import {
list list
} from "../../api/system/role.js"; } from '../../api/system/role.js'
import { import {
listmenu listmenu
} from "../../api/system/menu.js"; } from '../../api/system/menu.js'
import { import {
setPermissions setPermissions
} from "../../api/system/permission.js" } from '../../api/system/permission.js'
export default {
components: { export default {
LxHeader components: {
}, LxHeader
created() { },
mounted() {
}, },
mounted() {}, data() {
data() { return {
return { activeRole: '',
activeRole: "", rolelist: [],
rolelist: [], selectIndex: -1,
selectIndex: -1, checked: false,
checked: false, data: [],
data: [], tree: [],
tree: [], height: 0
height: 0
} }
}, },
created() { created() {
var that = this; var that = this
this.initLoad(); this.initLoad()
this.load(function() { this.load(function() {
that.loadrole(); that.loadrole()
}); })
},
methods: {
initLoad() {
var that = this
var clientHeight = document.documentElement.clientHeight
var lxHeader_height = 67 //
var card_Height = 109 //
var topHeight = 50 //
let height = clientHeight - lxHeader_height - topHeight - card_Height
that.height = height
}, },
methods: { loadrole() {
initLoad() { var that = this
var that = this; list().then(response => {
var clientHeight = document.documentElement.clientHeight let cur = 0
var lxHeader_height = 67; // that.rolelist = response
var card_Height = 109; //
var topHeight = 50; // for (let mod of response) {
let height = clientHeight - lxHeader_height - topHeight - card_Height; mod.rowid = mod.id.toString()
that.height = height; console.log(mod)
}, if (cur == 0) {
loadrole() { that.activeRole = mod.rowid
var that = this; that.loadPermisstions(0, that.activeRole)
list().then(response => {
let cur = 0;
that.rolelist = response;
for (var mod of response) {
mod.rowid = mod.id.toString();
if (cur == 0) {
that.activeRole = mod.rowid;
that.loadPermisstions(0, that.activeRole);
}
cur++;
} }
cur++
}
}).catch(error => { }).catch(error => {
//reject(error) })
}) },
}, load(callback) {
load(callback) { var that = this
var that = this; listmenu().then(response => {
listmenu().then(response => { this.tree = response
this.tree = response;
this.tree.map((tree, index1) => { this.tree.forEach((tree, index1) => {
let children = tree.children let children = tree.children
children.map((menu, index3) => { children.forEach((menu, index3) => {
menu.auth_node_tags_array.map((m, index4) => { menu.auth_node_tags_array.map((m, index4) => {
m.checked = false; m.checked = false
that.$forceUpdate(); that.$forceUpdate()
})
}) })
}) })
callback();
}).catch(error => {
//reject(error)
}) })
}, callback()
roleChange(tab, event) { }).catch(error => {
this.loadPermisstions(parseInt(tab.index), tab.name) })
}, },
loadPermisstions(index, name) { roleChange(tab, event) {
let select = this.rolelist[index].permissions; this.loadPermisstions(parseInt(tab.index), tab.name)
this.$refs.tree.setCheckedKeys([]); },
this.activeRole = name; loadPermisstions(index, name) {
let select = this.rolelist[index].permissions
this.$refs.tree.setCheckedKeys([])
let that = this; this.activeRole = name
this.tree.map((tree, index1) => {
let children = tree.children; let that = this
select.map((item, index2) => { this.tree.forEach((tree, index1) => {
let selectMenu = children.filter(m => { let children = tree.children
return m.id == item.id select.forEach((item, index2) => {
}); let selectMenu = children.filter(m => {
return m.id == item.id
})
selectMenu.map((menu, index3) => { selectMenu.forEach((menu, index3) => {
if (item.has_auth_node_tags.length > 0) { if (item.has_auth_node_tags.length > 0) {
menu.auth_node_tags_array.map((m, index4) => { menu.auth_node_tags_array.forEach((m, index4) => {
if (item.has_auth_node_tags.indexOf(m.tag) > -1) { if (item.has_auth_node_tags.indexOf(m.tag) > -1) {
that.$set(that.tree[index1].children[index3].auth_node_tags_array[index4], that.$set(m,
"checked", true); 'checked', true)
}
else{
that.$set(that.tree[index1].children[index3].auth_node_tags_array[index4],
"checked", false);
}
})
} else { } else {
menu.auth_node_tags_array.map(m => { that.$set(m,
m.checked = false; 'checked', false)
})
} }
}) })
} else {
menu.auth_node_tags_array.map(m => {
m.checked = false
})
}
}) })
this.$refs.tree.updateKeyChildren(tree.id, JSON.parse(JSON.stringify(children)))
}) })
this.$refs.tree.updateKeyChildren(tree.id, JSON.parse(JSON.stringify(children)))
})
this.$refs.tree.setCheckedNodes(select)
that.$forceUpdate()
},
savepermission() {
this.$refs.tree.setCheckedNodes(select); var checkedList = this.$refs.tree.getCheckedNodes()
that.$forceUpdate(); console.log(checkedList)
if (checkedList.length == 0) {
this.$message.error('请选择菜单')
}, return false
savepermission() { }
var checkedList = this.$refs.tree.getCheckedNodes(); let data = {}
console.log(checkedList) data.id = this.activeRole
if (checkedList.length == 0) { let permission = []
this.$message.error("请选择菜单"); for (var m of checkedList) {
return false; let tags = []
} var mod = {}
let data = {}; mod.permission_id = m.id
data.id = this.activeRole; m.auth_node_tags_array.map(item => {
let permission = []; if (item.checked) {
for (var m of checkedList) { tags.push(item.tag)
let tags = []; }
var mod = {};
mod.permission_id = m.id;
m.auth_node_tags_array.map(item => {
if (item.checked) {
tags.push(item.tag);
}
});
mod.auth_node_tags = tags.join(",");
permission.push(mod);
}
data.permission_list = permission;
setPermissions(data).then(response => {
console.log(response)
this.$Message.success('操作成功');
that.dialogFormVisible = false;
that.load();
}).catch(error => {
//reject(error)
}) })
mod.auth_node_tags = tags.join(',')
permission.push(mod)
} }
data.permission_list = permission
setPermissions(data).then(response => {
console.log(response)
this.$Message.success('操作成功')
that.dialogFormVisible = false
that.load()
}).catch(error => {
})
} }
}; }
}
</script> </script>
<style lang="less" scoped> <style lang="less" scoped>
.t-tree { .t-tree {
position: absolute;
width: 100%;
height: 100%;
display: flex;
padding: 12px;
background: #eee;
/* padding: 100px; */
}
.header {
background: #f9f8f8;
line-height: 40px;
border-bottom: 1px solid #eee;
position: relative;
font-size: 15px;
padding: 0 15px;
button {
position: absolute; position: absolute;
width: 100%; right: 15px;
height: 100%; top: 4px;
display: flex;
padding: 12px;
background: #eee;
/* padding: 100px; */
}
.header {
background: #f9f8f8;
line-height: 40px;
border-bottom: 1px solid #eee;
position: relative;
font-size: 15px;
padding: 0 15px;
button {
position: absolute;
right: 15px;
top: 4px;
}
}
.action-container {
border-radius: 4px;
flex: 1;
margin-left: 15px;
background: white;
border-bottom: 1px solid #eee;
display: flex;
flex-direction: column;
}
.role-list {
width: 200px;
border: 1px solid #eee;
border-bottom: 0;
}
.actived {
color: #409efe !important;
background-color: #f3f7f9;
} }
}
.action-container {
border-radius: 4px;
flex: 1;
margin-left: 15px;
background: white;
border-bottom: 1px solid #eee;
display: flex;
flex-direction: column;
}
.role-list {
width: 200px;
border: 1px solid #eee;
border-bottom: 0;
}
.actived {
color: #409efe !important;
background-color: #f3f7f9;
}
</style> </style>
<style scoped> <style scoped>
.roleitem { .roleitem {
margin-bottom: 5px; margin-bottom: 5px;
} }
.action-group { .action-group {
width: 100%; width: 100%;
display: flex; display: flex;
} }
.action-text { .action-text {
font-size: 14px; font-size: 14px;
margin-right: 10px; margin-right: 10px;
} }
.action-item { .action-item {
flex: 1; flex: 1;
} }
.action-item>label { .action-item > label {
width: 55px; width: 55px;
margin-left: 3px; margin-left: 3px;
} }
.action-container>>>.el-tree-node { .action-container >>> .el-tree-node {
padding: 5px 0; padding: 5px 0;
} }
.action-container>>>.el-checkbox__label { .action-container >>> .el-checkbox__label {
padding-left: 5px; padding-left: 5px;
} }
</style> </style>

Loading…
Cancel
Save