feat:部门权限
This commit is contained in:
1 parent
26cc0e1231
commit
6dddc12da8
3 files changed
+36
-19
No files matched your search
@@ -1,6 +1,6 @@
|
||||
<template>
|
||||
<div style="height: 100%">
|
||||
<vue3-tree-org ref="treeOrgRef" :props="props" :data="data" :label-style="style" :define-menus="getMenus()"
|
||||
<vue3-tree-org ref="treeOrgRef" :props="props" :data="data" :label-style="style" :define-menus="getMenus"
|
||||
:default-expand-level="expandLevel" center :horizontal="horizontal" :collapsable="collapsable"
|
||||
:only-one-node="onlyOneNode" :filter-node-method="filterNodeMethod" :clone-node-drag="cloneNodeDrag"
|
||||
:node-add="addNode" :node-delete="delNode" :node-edit="editNode" @on-node-click="onNodeClick" />
|
||||
@@ -17,11 +17,14 @@ import { useI18n } from "vue-i18n"
|
||||
import { storeToRefs } from "pinia"
|
||||
import { useThemeConfig } from "/@/stores/themeConfig"
|
||||
import { auth } from "/@/utils/authFunction"
|
||||
import { useUserInfo } from "/@/stores/userInfo"
|
||||
|
||||
const DeptForm = defineAsyncComponent(() => import("./form.vue"))
|
||||
|
||||
const { t } = useI18n()
|
||||
|
||||
const stores = useUserInfo();
|
||||
|
||||
// 定义org组件key-value定义
|
||||
const props = reactive({ id: "id", pid: "parentId", label: "name", expand: "expand", children: "children" })
|
||||
const data = reactive({})
|
||||
@@ -69,8 +72,14 @@ const filterNodeMethod = (value, data) => {
|
||||
return data.label.indexOf(value) !== -1
|
||||
}
|
||||
|
||||
const getMenus = () => {
|
||||
const getMenus = (event: any, v: any) => {
|
||||
const menus = []
|
||||
if (stores.userInfos.roleCodes.includes('DEPT_ADMIN')) {
|
||||
if (v.id == stores.userInfos.user.deptId) {
|
||||
return [{ name: t("sysdept.editNodeText"), command: "edit" }]
|
||||
}
|
||||
return []
|
||||
}
|
||||
if (auth("sys_dept_add")) {
|
||||
menus.push({ name: t("sysdept.addNodeText"), command: "add" })
|
||||
}
|
||||
@@ -173,9 +182,32 @@ const getOrgData = async () => {
|
||||
deptTree().then((res) => {
|
||||
Object.assign(data, { id: "0", name: tenant.data.name })
|
||||
data.children = res.data
|
||||
if (data.children && data.children.length && stores.userInfos.roleCodes.includes('DEPT_ADMIN')) {
|
||||
data.children = filterVisibleNodes(data.children)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const filterVisibleNodes = (nodes) => {
|
||||
if (!Array.isArray(nodes)) return [];
|
||||
return nodes.reduce((filtered, node) => {
|
||||
if (node.visible) {
|
||||
const filteredNode = { ...node };
|
||||
if (node.children?.length) {
|
||||
filteredNode.children = filterVisibleNodes(node.children);
|
||||
}
|
||||
filtered.push(filteredNode);
|
||||
} else if (node.children?.length) {
|
||||
// 如果当前节点不是visible,但是它的子节点可能是visible,所以需要继续检查
|
||||
const filteredChildren = filterVisibleNodes(node.children);
|
||||
if (filteredChildren.length > 0) {
|
||||
filtered.push({ ...node, children: filteredChildren });
|
||||
}
|
||||
}
|
||||
return filtered;
|
||||
}, []);
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
getOrgData()
|
||||
})
|
||||
|
||||
Reference in new issue
Block a user