|
@@ -12,6 +12,7 @@ import { GlobalStore } from '@/stores/index'
|
|
|
import { ref, reactive, nextTick } from 'vue'
|
|
|
import Drawer from '@/components/Drawer/index.vue'
|
|
|
import Dialog from '@/components/dialog/Dialog.vue'
|
|
|
+import { ElTree } from 'element-plus'
|
|
|
import TableBase from '@/components/TableBase/index.vue'
|
|
|
import type { FormInstance, FormRules } from 'element-plus'
|
|
|
import type { ColumnProps } from '@/components/TableBase/interface/index'
|
|
@@ -25,6 +26,7 @@ interface InSys {
|
|
|
checkList: string[]
|
|
|
}
|
|
|
|
|
|
+const menuMap = new Map()
|
|
|
const isNew = ref(true)
|
|
|
let currentVal: any = {}
|
|
|
const SysList = ref<InSys[]>([])
|
|
@@ -45,7 +47,7 @@ const DialogOpen = async (row: any) => {
|
|
|
dialog.value?.DialogOpen()
|
|
|
}
|
|
|
|
|
|
-const checkList = ref<string[]>([])
|
|
|
+// const checkList = ref<string[]>([])
|
|
|
const columns: ColumnProps[] = [
|
|
|
{ type: 'index', label: '#', width: 80 },
|
|
|
{ prop: 'T_name', label: '姓名' },
|
|
@@ -56,46 +58,62 @@ const columns: ColumnProps[] = [
|
|
|
const getSysList = async () => {
|
|
|
const { Data } = await User_Sys_List({ User_tokey: globalStore.GET_User_tokey })
|
|
|
SysList.value = Data as InSys[]
|
|
|
- for await (let item of SysList.value) {
|
|
|
- getMenuList(item.T_sys)
|
|
|
+ // for await (let item of SysList.value) {
|
|
|
+ // getMenuList(item.T_sys)
|
|
|
+ // }
|
|
|
+ const promises = []
|
|
|
+ for (let item of SysList.value) {
|
|
|
+ promises.push(getMenuList(item.T_sys))
|
|
|
}
|
|
|
-}
|
|
|
|
|
|
+ Promise.all(promises).then(res => {
|
|
|
+ const menuListTemporary: any[] = []
|
|
|
+ res.forEach((item: any) => {
|
|
|
+ const { Children, T_permission } = item.Data.Menu[0]
|
|
|
+ item.Data.Menu[0].children = Children
|
|
|
+ if (['/account', 'mangage', '/salary', '/stock'].includes(T_permission)) {
|
|
|
+ item.Data.Menu[0].father = true
|
|
|
+ menuMap.set(T_permission, { code: item.code, children: [] })
|
|
|
+ }
|
|
|
+ if (item.Data.Menu_checked) {
|
|
|
+ getPermissionArr(item.Data)
|
|
|
+ }
|
|
|
+ menuListTemporary.push(item.Data.Menu[0])
|
|
|
+ })
|
|
|
+ menuList.value = menuListTemporary
|
|
|
+ setCheckedTreeKeys(permissionArr.value)
|
|
|
+ })
|
|
|
+}
|
|
|
const getMenuList = async (code: string) => {
|
|
|
const res: any = await User_Power_Get({ User_tokey: globalStore.GET_User_tokey, T_code: code, T_id: currentVal.T_id })
|
|
|
- const sys = SysList.value.find(item => item.T_sys === code) as InSys
|
|
|
- sys.children = res.Data.Menu[0].Children
|
|
|
- if (res.Data.Menu_checked) {
|
|
|
- sys.checkList = sys.children.map((m: any) => {
|
|
|
- if (res.Data.Menu_checked.includes(m.Id)) return m.T_name
|
|
|
- })
|
|
|
- } else {
|
|
|
- sys.checkList = []
|
|
|
+ return {
|
|
|
+ code,
|
|
|
+ ...res
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-const submitUserRole = async (item: InSys) => {
|
|
|
- let Sys: any = SysList.value.find(sys => item.T_sys === sys.T_sys)
|
|
|
- let childs = Sys?.children.filter((child: InSys) => Sys.checkList.includes(child.T_name))
|
|
|
- let T_menu = ''
|
|
|
- childs.forEach((f: any) => {
|
|
|
- let str = 'M' + f.Id + '|'
|
|
|
- T_menu += str
|
|
|
- })
|
|
|
- const params = {
|
|
|
- User_tokey: globalStore.GET_User_tokey,
|
|
|
- T_id: currentVal.T_id,
|
|
|
- T_code: item.T_sys,
|
|
|
- T_menu
|
|
|
- }
|
|
|
+const permissionArr = ref<string[]>([])
|
|
|
+const getPermissionArr = (menu: any) => {
|
|
|
+ const { Menu, Menu_checked } = menu
|
|
|
+ const { Children, T_permission } = Menu[0]
|
|
|
+ getCurrentFlatMenu(Children, Menu_checked, T_permission)
|
|
|
+}
|
|
|
|
|
|
- const res = await User_Power_Edit_Menu(params)
|
|
|
- if (res.Code === 200) {
|
|
|
- ElMessage.success('修改成功!')
|
|
|
- dialog.value?.DialogClose()
|
|
|
- checkList.value = []
|
|
|
- }
|
|
|
+const getCurrentFlatMenu = (children: any[], arr: number[], permission: strng) => {
|
|
|
+ const fatherMenu = menuMap.get(permission)
|
|
|
+
|
|
|
+ children.forEach((item: any) => {
|
|
|
+ const index = arr.findIndex((num: any) => num === item.Id)
|
|
|
+ if (item.Children) {
|
|
|
+ getCurrentFlatMenu(item.Children, arr, permission)
|
|
|
+ }
|
|
|
+ if (index !== -1 && !item.Children) {
|
|
|
+ permissionArr.value.push(item.T_permission)
|
|
|
+ fatherMenu.children.push(item)
|
|
|
+ }
|
|
|
+ })
|
|
|
}
|
|
|
+const setCheckedTreeKeys = (arr: string[]) => treeRef.value?.setCheckedKeys(arr, true)
|
|
|
|
|
|
// 添加角色
|
|
|
type Fn = () => void
|
|
@@ -182,6 +200,79 @@ const searchHandle = () => {
|
|
|
initParam.T_name = search.value
|
|
|
TableRef.value?.searchTable()
|
|
|
}
|
|
|
+
|
|
|
+// 重写角色权限
|
|
|
+const treeRef = ref<InstanceType<typeof ElTree>>()
|
|
|
+const menuList = ref<any[]>([])
|
|
|
+
|
|
|
+const append = async (data: any) => {
|
|
|
+ const currentMenu = menuMap.get(data.T_permission)
|
|
|
+ const { code, children } = currentMenu
|
|
|
+
|
|
|
+ let T_menu = ''
|
|
|
+ children.forEach((item: any) => {
|
|
|
+ let str = 'M' + item.Id + '|'
|
|
|
+ T_menu += str
|
|
|
+ })
|
|
|
+ const params = {
|
|
|
+ User_tokey: globalStore.GET_User_tokey,
|
|
|
+ T_id: currentVal.T_id,
|
|
|
+ T_code: code,
|
|
|
+ T_menu
|
|
|
+ }
|
|
|
+ const res = await User_Power_Edit_Menu(params)
|
|
|
+ if (res.Code === 200) {
|
|
|
+ ElMessage.success('修改成功!')
|
|
|
+ dialog.value?.DialogClose()
|
|
|
+ }
|
|
|
+}
|
|
|
+let fatherData: any = {}
|
|
|
+const checkChange = (data: any, check: boolean) => {
|
|
|
+ const father = menuMap.get(data.T_permission)
|
|
|
+ if (father) {
|
|
|
+ fatherData = data
|
|
|
+ fatherCheckHandle(data.Children, father, check)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ const prevFather = menuMap.get(fatherData.T_permission)
|
|
|
+ const { children } = prevFather
|
|
|
+ if (check) {
|
|
|
+ prevFather.children.push(data)
|
|
|
+ }
|
|
|
+ if (!father && !check) {
|
|
|
+ const index = children.findIndex((item: any) => item.T_permission === data.T_permission)
|
|
|
+ if (index !== -1) {
|
|
|
+ children.splice(index, 1)
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+/**
|
|
|
+ * 处理点击父级 tree 时的处理
|
|
|
+ */
|
|
|
+const fatherCheckHandle = (children: any[], father: any, check: boolean) => {
|
|
|
+ if (check) {
|
|
|
+ children.forEach((item: any) => {
|
|
|
+ if (item.Children) {
|
|
|
+ father.children.push(item)
|
|
|
+ fatherCheckHandle(item.Children, father, check)
|
|
|
+ } else {
|
|
|
+ father.children.push(item)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ father.children = []
|
|
|
+ }
|
|
|
+}
|
|
|
+/**
|
|
|
+ * dialog 关闭回调
|
|
|
+ */
|
|
|
+const dialogCloseCallback = () => {
|
|
|
+ nextTick(() => {
|
|
|
+ menuMap.clear()
|
|
|
+ permissionArr.value = []
|
|
|
+ fatherData = {}
|
|
|
+ })
|
|
|
+}
|
|
|
</script>
|
|
|
|
|
|
<template>
|
|
@@ -205,38 +296,36 @@ const searchHandle = () => {
|
|
|
<el-button link type="danger" size="small" :icon="Delete" @click="UserDelete(row)">删除</el-button>
|
|
|
</template>
|
|
|
</TableBase>
|
|
|
- <Dialog ref="dialog" width="80%">
|
|
|
+ <Dialog ref="dialog" width="50%" :handleClose="dialogCloseCallback">
|
|
|
<template #header>
|
|
|
<h3>编辑权限</h3>
|
|
|
</template>
|
|
|
- <el-row :gutter="24">
|
|
|
- <el-col :span="3"><div class="grid-content b-radius-4">功能模块</div></el-col>
|
|
|
- <el-col :span="18"><div class="grid-content b-radius-4">权限</div></el-col>
|
|
|
- <el-col :span="3"><div class="grid-content b-radius-4">操作</div></el-col>
|
|
|
- </el-row>
|
|
|
- <el-row :gutter="24" v-for="item in SysList" :key="item.T_sys">
|
|
|
- <el-col :span="3"
|
|
|
- ><div class="grid-content b-radius-4">
|
|
|
- <el-button type="success" link>{{ item.T_name }}</el-button>
|
|
|
- </div></el-col
|
|
|
- >
|
|
|
- <el-col :span="18"
|
|
|
- ><div class="grid-content grid-active b-radius-4">
|
|
|
- <transition appear name="fade-transform" mode="out-in">
|
|
|
- <el-checkbox-group v-model="item.checkList" v-if="item.children">
|
|
|
- <el-checkbox :label="child.T_name" v-for="child in item.children" :key="'rr' + child.Id">{{
|
|
|
- child.T_name
|
|
|
- }}</el-checkbox>
|
|
|
- </el-checkbox-group>
|
|
|
- </transition>
|
|
|
- </div>
|
|
|
- </el-col>
|
|
|
- <el-col :span="3"
|
|
|
- ><div class="grid-content b-radius-4">
|
|
|
- <el-button type="primary" @click="submitUserRole(item)">提交</el-button>
|
|
|
- </div></el-col
|
|
|
+ <transition appear name="fade" mode="out-in">
|
|
|
+ <el-tree
|
|
|
+ ref="treeRef"
|
|
|
+ :data="menuList"
|
|
|
+ show-checkbox
|
|
|
+ node-key="T_permission"
|
|
|
+ :expand-on-click-node="false"
|
|
|
+ :props="{ label: 'T_name', children: 'Children' }"
|
|
|
+ @check-change="checkChange"
|
|
|
>
|
|
|
- </el-row>
|
|
|
+ <template #default="{ data }">
|
|
|
+ <div
|
|
|
+ class="custom-tree-node"
|
|
|
+ :style="{ 'border-bottom': data.Children && data.father ? ' 1px solid #ddd' : '' }"
|
|
|
+ >
|
|
|
+ <span>{{ data.T_name }}</span>
|
|
|
+ <span v-if="data.Children && data.father">
|
|
|
+ <el-button type="primary" size="small" @click="append(data)">提交</el-button>
|
|
|
+ </span>
|
|
|
+ </div>
|
|
|
+ </template>
|
|
|
+ <template #empty>
|
|
|
+ <el-empty></el-empty>
|
|
|
+ </template>
|
|
|
+ </el-tree>
|
|
|
+ </transition>
|
|
|
</Dialog>
|
|
|
<Drawer ref="drawerRef" :handleClose="callbackDrawer">
|
|
|
<template #header="{ params }">
|
|
@@ -261,19 +350,19 @@ const searchHandle = () => {
|
|
|
.roles {
|
|
|
@include f-direction;
|
|
|
}
|
|
|
-/* fade-transform */
|
|
|
-.fade-transform-leave-active,
|
|
|
-.fade-transform-enter-active {
|
|
|
- transition: all 0.5s;
|
|
|
+/* fade */
|
|
|
+.fade-leave-active,
|
|
|
+.fade-enter-active {
|
|
|
+ transition: all 1s;
|
|
|
}
|
|
|
-.fade-transform-enter-from {
|
|
|
+.fade-enter-from {
|
|
|
opacity: 0;
|
|
|
- transition: all 0.5s;
|
|
|
- transform: translateY(-30px);
|
|
|
+ transition: all 1s;
|
|
|
+ transform: translateY(-60px);
|
|
|
}
|
|
|
-.fade-transform-leave-to {
|
|
|
+.fade-leave-to {
|
|
|
opacity: 0;
|
|
|
- transition: all 0.5s;
|
|
|
- transform: translateY(30px);
|
|
|
+ transition: all 1s;
|
|
|
+ transform: translateY(60px);
|
|
|
}
|
|
|
</style>
|