|
@@ -3,7 +3,7 @@ defineOptions({
|
|
|
// name 作为一种规范最好必须写上并且和路由的name保持一致
|
|
|
name: "rolePower"
|
|
|
});
|
|
|
-import { ref, reactive } from "vue";
|
|
|
+import { ref, reactive, watch } from "vue";
|
|
|
import { ElMessageBox, ElMessage } from "element-plus";
|
|
|
import { Search } from "@element-plus/icons-vue";
|
|
|
import addRole from "./components/addRole.vue";
|
|
@@ -94,13 +94,16 @@ const bgColor = ref(null);
|
|
|
const lookRoles = item => {
|
|
|
paramsPageUser.roleName = item.roleName;
|
|
|
paramsPageUser.roleCode = item.roleCode;
|
|
|
- bgColor.value = item.id;
|
|
|
+ bgColor.value = item.roleCode;
|
|
|
rolesList.rolesName = item.roleName;
|
|
|
Object.assign(rolesList.addPerson, item);
|
|
|
getMenuListApi();
|
|
|
postPageUserByRoleApi();
|
|
|
- getMenuListCodeForRoleApi(item);
|
|
|
getUserPermissionsByRoleCodeApi(item.roleCode);
|
|
|
+ setTimeout(() => {
|
|
|
+ // 查看角色权限
|
|
|
+ getMenuListCodeForRoleApi(item);
|
|
|
+ }, 500);
|
|
|
Object.assign(roleParams, {
|
|
|
roleName: "",
|
|
|
roleSort: 0,
|
|
@@ -204,40 +207,41 @@ const postPageUserByRoleApi = async () => {
|
|
|
const handleClick = (tab, event) => {
|
|
|
console.log(tab, event);
|
|
|
};
|
|
|
+// 查询角色的权限
|
|
|
+// 递归处理菜单回显判断并更新 show 和 allShow
|
|
|
+function updateMenuShow(menuList, data) {
|
|
|
+ menuList.forEach(menu => {
|
|
|
+ // 判断当前菜单的 menuCode 是否在 data 中
|
|
|
+ if (data.includes(menu.menuCode)) {
|
|
|
+ menu.show = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果有子菜单,递归检查
|
|
|
+ if (menu.childrenRes && menu.childrenRes.length > 0) {
|
|
|
+ updateMenuShow(menu.childrenRes, data);
|
|
|
+
|
|
|
+ // 检查所有子菜单的 show 属性是否都为 true
|
|
|
+ const allChildrenShow = menu.childrenRes.every(
|
|
|
+ child => child.show === true
|
|
|
+ );
|
|
|
+ if (allChildrenShow) {
|
|
|
+ menu.allShow = true;
|
|
|
+ menu.show = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+}
|
|
|
|
|
|
-// const postAddMenuListApi = async () => {
|
|
|
-// const { code } = await updateMenu({
|
|
|
-// menuName: "指标库",
|
|
|
-// menuType: "menu",
|
|
|
-// parentCode: "",
|
|
|
-// orderNum: 1,
|
|
|
-// url: "",
|
|
|
-// moduleUrl: "/indexDefine",
|
|
|
-// icon: "",
|
|
|
-// // remark: "",
|
|
|
-// remark: "系统管理",
|
|
|
-// menuCode: "menu340900015906103296"
|
|
|
-// });
|
|
|
-// };
|
|
|
-// postAddMenuListApi();
|
|
|
-// {
|
|
|
-// menuName: "新建模板",
|
|
|
-// menuType: "menu",
|
|
|
-// parentCode: "menu340271989673566208",
|
|
|
-// orderNum: 0,
|
|
|
-// url: "",
|
|
|
-// moduleUrl: "/evaluate/children/change/components/newAdd",
|
|
|
-// icon: "",
|
|
|
-// remark: "",
|
|
|
-// menuCode: ""
|
|
|
-// }
|
|
|
const getMenuListCodeForRoleApi = async item => {
|
|
|
- console.log("item", item);
|
|
|
const { code, data } = await getMenuListCodeForRole({
|
|
|
roleCode: item.roleCode
|
|
|
});
|
|
|
- // console.log("菜单", data);
|
|
|
+ if (code == 200) {
|
|
|
+ roleParams.menuCodes = data;
|
|
|
+ updateMenuShow(menuListRoleList.value, data);
|
|
|
+ }
|
|
|
};
|
|
|
+// 分页----------------
|
|
|
const handleSizeChange = val => {
|
|
|
paramsPageUser.pageSize = val;
|
|
|
postPageUserByRoleApi();
|
|
@@ -246,6 +250,7 @@ const handleCurrentChange = val => {
|
|
|
paramsPageUser.pageNumber = val;
|
|
|
postPageUserByRoleApi();
|
|
|
};
|
|
|
+// ------------------------
|
|
|
// 查看角色菜单权限表
|
|
|
const menuListRole = ref<any>([]);
|
|
|
const menuListRoleList = ref<any>([]);
|
|
@@ -267,9 +272,13 @@ const getMenuListApi = async () => {
|
|
|
modifiedMenuData.forEach(item => {
|
|
|
item.allShow = false;
|
|
|
});
|
|
|
+ // 忘记干嘛的了,递归错数据了
|
|
|
function checkMenuCodes(menuItems) {
|
|
|
+ console.log("menuListRole-1111", menuListRole);
|
|
|
menuListRole.value.forEach(item => {
|
|
|
+ console.log("item", item);
|
|
|
const hasRole = menuListRole.value.includes(item.menuCode);
|
|
|
+ console.log("hasRole", hasRole);
|
|
|
item.show = hasRole;
|
|
|
|
|
|
// Recursively check children
|
|
@@ -286,18 +295,17 @@ const getMenuListApi = async () => {
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
- checkMenuCodes(modifiedMenuData);
|
|
|
+ // checkMenuCodes(modifiedMenuData);
|
|
|
+ // -------------------------------------
|
|
|
menuListRoleList.value = modifiedMenuData;
|
|
|
- console.log("菜单列表", menuListRoleList.value);
|
|
|
+ console.log("21312", menuListRoleList.value);
|
|
|
}
|
|
|
};
|
|
|
-// getMenuListApi();
|
|
|
const getUserPermissionsByRoleCodeApi = async roleCode => {
|
|
|
const { code, msg, data } = await getUserPermissionsByRoleCode({
|
|
|
roleCode
|
|
|
});
|
|
|
if (code == 200) {
|
|
|
- // getMenuListApi();
|
|
|
menuListRole.value = data;
|
|
|
}
|
|
|
};
|
|
@@ -329,37 +337,75 @@ function collectMenuCodes(menu) {
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
-function collectMenuShow(menu) {
|
|
|
- // 添加当前菜单的 menuCode 到 roleParams.menuCodes
|
|
|
- menu.show = false;
|
|
|
- // 如果有子菜单,递归处理
|
|
|
- if (menu.childrenRes && menu.childrenRes.length > 0) {
|
|
|
- menu.childrenRes.forEach(child => {
|
|
|
- collectMenuCodes(child);
|
|
|
- });
|
|
|
- }
|
|
|
+// function collectMenuShow(menu, allShow) {
|
|
|
+// // 添加当前菜单的 menuCode 到 roleParams.menuCodes
|
|
|
+// if (!allShow) {
|
|
|
+// menu.show = true;
|
|
|
+// } else {
|
|
|
+// menu.show = false;
|
|
|
+// }
|
|
|
+// // 如果有子菜单,递归处理
|
|
|
+// if (menu.childrenRes && menu.childrenRes.length > 0) {
|
|
|
+// menu.childrenRes.forEach(child => {
|
|
|
+// collectMenuCodes(child);
|
|
|
+// });
|
|
|
+// }
|
|
|
+// }
|
|
|
+function collectMenuShow(data, allShow) {
|
|
|
+ // 遍历 data 数组
|
|
|
+ data.forEach(item => {
|
|
|
+ // 设置当前项的 show 和 allShow 属性
|
|
|
+ if (!allShow) {
|
|
|
+ item.show = true;
|
|
|
+ roleParams.menuCodes.push(item.menuCode);
|
|
|
+ } else {
|
|
|
+ item.show = false;
|
|
|
+ console.log("data", data);
|
|
|
+ data.map(itCode => {
|
|
|
+ data.map(itCode => {
|
|
|
+ // 使用 filter 来过滤掉与 itCode.menuCode 相同的元素
|
|
|
+ roleParams.menuCodes = roleParams.menuCodes.filter(
|
|
|
+ j => j !== itCode.menuCode
|
|
|
+ );
|
|
|
+ });
|
|
|
+ });
|
|
|
+ // roleParams.menuCodes = []
|
|
|
+ }
|
|
|
+ // 如果存在子菜单 (childrenRes),则递归调用
|
|
|
+ if (item.childrenRes && item.childrenRes.length > 0) {
|
|
|
+ collectMenuShow(item.childrenRes, allShow);
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
const roleShowClick = (item, type: any) => {
|
|
|
roleParams.roleName = rolesList.addPerson.roleName;
|
|
|
roleParams.roleCode = rolesList.addPerson.roleCode;
|
|
|
- console.log("角色", item);
|
|
|
if (type) {
|
|
|
// 不是全选
|
|
|
if (item.show) {
|
|
|
- roleParams.menuCodes.push(item.menuCode);
|
|
|
+ item.show = false;
|
|
|
+ console.log("menuListRoleList", menuListRoleList);
|
|
|
+ console.log("menuListRoleList", item);
|
|
|
+ menuListRoleList.value.map = row => {
|
|
|
+ if (row.menuCode == it.parentCode) {
|
|
|
+ row.allShow = !row.allShow;
|
|
|
+ }
|
|
|
+ };
|
|
|
+ roleParams.menuCodes.filter(it => it !== it.menuCode);
|
|
|
postUpdateRoleApi();
|
|
|
} else {
|
|
|
- roleParams.menuCodes.filter(value => value !== item.menuCode);
|
|
|
+ item.show = true;
|
|
|
+ roleParams.menuCodes.push(item.menuCode);
|
|
|
postUpdateRoleApi();
|
|
|
}
|
|
|
} else {
|
|
|
+ console.log("allShow", item);
|
|
|
if (!item.allShow) {
|
|
|
- collectMenuCodes(item);
|
|
|
+ collectMenuShow([item], item.allShow);
|
|
|
postUpdateRoleApi();
|
|
|
} else {
|
|
|
- roleParams.menuCodes = [];
|
|
|
+ collectMenuShow([item], item.allShow);
|
|
|
postUpdateRoleApi();
|
|
|
- collectMenuShow(item);
|
|
|
}
|
|
|
}
|
|
|
};
|
|
@@ -399,7 +445,7 @@ const roleShowClick = (item, type: any) => {
|
|
|
<div
|
|
|
:class="[
|
|
|
'w-[100%] flex justify-between items-center mt-2 cursor-pointer',
|
|
|
- { 'roles-bg': bgColor === item.id }
|
|
|
+ { 'roles-bg': bgColor === item.roleCode }
|
|
|
]"
|
|
|
>
|
|
|
<div
|
|
@@ -411,7 +457,9 @@ const roleShowClick = (item, type: any) => {
|
|
|
<div class="flex justify-between items-center">
|
|
|
<el-dropdown trigger="click">
|
|
|
<span>
|
|
|
- <el-icon><Operation /></el-icon>
|
|
|
+ <el-icon>
|
|
|
+ <Operation />
|
|
|
+ </el-icon>
|
|
|
</span>
|
|
|
<template #dropdown>
|
|
|
<el-dropdown-menu class="setting">
|
|
@@ -447,7 +495,7 @@ const roleShowClick = (item, type: any) => {
|
|
|
<div
|
|
|
:class="[
|
|
|
'w-[100%] flex justify-between items-center mt-2 cursor-pointer',
|
|
|
- { 'roles-bg': bgColor === item.id }
|
|
|
+ { 'roles-bg': bgColor === item.roleCode }
|
|
|
]"
|
|
|
>
|
|
|
<div
|
|
@@ -459,7 +507,9 @@ const roleShowClick = (item, type: any) => {
|
|
|
<div class="flex justify-between items-center">
|
|
|
<el-dropdown trigger="click">
|
|
|
<span>
|
|
|
- <el-icon><Operation /></el-icon>
|
|
|
+ <el-icon>
|
|
|
+ <Operation />
|
|
|
+ </el-icon>
|
|
|
</span>
|
|
|
<template #dropdown>
|
|
|
<el-dropdown-menu class="setting">
|
|
@@ -551,7 +601,7 @@ const roleShowClick = (item, type: any) => {
|
|
|
<input
|
|
|
v-model="row.show"
|
|
|
type="checkbox"
|
|
|
- @click="roleShowClick(row, (type = 1))"
|
|
|
+ @click="roleShowClick(row, 1)"
|
|
|
/>{{ row.menuName }}
|
|
|
</div>
|
|
|
</template>
|
|
@@ -566,7 +616,7 @@ const roleShowClick = (item, type: any) => {
|
|
|
<input
|
|
|
v-model="item1.show"
|
|
|
type="checkbox"
|
|
|
- @click="roleShowClick(row, (type = 1))"
|
|
|
+ @click="roleShowClick(item1, 1)"
|
|
|
/>{{ item1.menuName }}
|
|
|
</div>
|
|
|
</div>
|
|
@@ -578,7 +628,7 @@ const roleShowClick = (item, type: any) => {
|
|
|
<input
|
|
|
v-model="row.allShow"
|
|
|
type="checkbox"
|
|
|
- @click="roleShowClick(row, (type = 0))"
|
|
|
+ @click="roleShowClick(row, 0)"
|
|
|
/>{{ row.date }}全选
|
|
|
</div>
|
|
|
</template>
|
|
@@ -597,7 +647,7 @@ const roleShowClick = (item, type: any) => {
|
|
|
<input
|
|
|
v-model="item2.show"
|
|
|
type="checkbox"
|
|
|
- @click="roleShowClick(row, (type = 1))"
|
|
|
+ @click="roleShowClick(item2, 1)"
|
|
|
/>{{ item2.menuName }}
|
|
|
</div>
|
|
|
</div>
|
|
@@ -643,15 +693,22 @@ const roleShowClick = (item, type: any) => {
|
|
|
}
|
|
|
|
|
|
.infinite-list {
|
|
|
- -ms-overflow-style: none; /* IE和Edge */
|
|
|
- scrollbar-width: none; /* Firefox */
|
|
|
+ -ms-overflow-style: none;
|
|
|
+
|
|
|
+ /* IE和Edge */
|
|
|
+ scrollbar-width: none;
|
|
|
+
|
|
|
+ /* Firefox */
|
|
|
// border: 1px solid red;
|
|
|
}
|
|
|
|
|
|
/* 隐藏滚动条 */
|
|
|
.infinite-list::-webkit-scrollbar {
|
|
|
- display: none; /* 对于 Webkit 浏览器(Chrome, Safari等) */
|
|
|
+ display: none;
|
|
|
+
|
|
|
+ /* 对于 Webkit 浏览器(Chrome, Safari等) */
|
|
|
}
|
|
|
+
|
|
|
// ::v-deep .el-dropdown {
|
|
|
// line-height: 1;
|
|
|
// }
|