From 361d46d0e2a9c5f795f766ed819037faef612167 Mon Sep 17 00:00:00 2001
From: yinbangzhong <zhongbangyin@126.com>
Date: 星期二, 27 八月 2024 09:23:31 +0800
Subject: [PATCH] bug fix

---
 src/views/authority/role/index.vue |   90 ++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 76 insertions(+), 14 deletions(-)

diff --git a/src/views/authority/role/index.vue b/src/views/authority/role/index.vue
index 48ceba2..a3b1cc1 100644
--- a/src/views/authority/role/index.vue
+++ b/src/views/authority/role/index.vue
@@ -93,7 +93,7 @@
               @click="operation(4, record)"
             >瑙掕壊鏉冮檺</a-button>
             <a-popconfirm
-              content="Are you sure you want to delete?"
+              content="璇风‘璁ゆ槸鍚﹀垹闄わ紵"
               type="success"
               @ok="operation(3, record)"
             >
@@ -140,6 +140,7 @@
               class="tree-demo"
               v-model:checked-keys="checkedKeysMenu"
               v-model:expanded-keys="expandKdysMenu"
+              :only-check-leaf=true
               :checkable="true"
               :data="treeDataMenu"
               @check="onCheckMenu"
@@ -148,7 +149,6 @@
                 title: 'menuName',
                 children: 'children',
               }"
-              :check-strictly="checkStrictlyMenu"
             >
             </a-tree>
           </a-tab-pane>
@@ -214,7 +214,7 @@
             'margin': '1px',
           }"
           class="card-demo"
-          title="鐢ㄦ埛鎵�鏈夋潈闄�"
+          title="瑙掕壊鎵�鏈夋潈闄�"
           hoverable
         >
           <a-space wrap>
@@ -285,6 +285,8 @@
   import Authheader from '@/views/authority/components/authheader.vue';
   import router from "@/router";
   import { queryCanvasList } from "@/api/Agent";
+  import { getUserInfo, getUserResources } from "@/utils/auth";
+  import { forEach } from "lodash";
 
   let treeDataMenu = ref([]);
   let checkedKeysMenu = ref([]);
@@ -336,18 +338,52 @@
   let resourcevisible = ref(false);
   let selectRole = ref({});
 
+  let u =JSON.parse(getUserInfo());
+
+  const eachChildrenAdd=(node)=>{
+    if (node.children?.length > 0) {
+      node.children.forEach((child) => {
+        checkStrictlyMenu.value.push({ menuId: child.menuId, menuName: child.menuName });
+        eachChildrenAdd(child);
+      });
+    }
+  }
+
+  const findChild = (node, val): boolean => {
+    let isExist = false;
+    if (node.children?.length > 0) {
+      node.children.forEach((child) => {
+        if (val.menuId == child.menuId) {
+          isExist = isExist || true;
+        } else {
+          isExist = isExist || findChild(child, val);
+        }
+      });
+    }
+    return isExist;
+  };
+
   const onCheckMenu = (newCheckedKeys, event) => {
     let o = { menuId: event.node.menuId, menuName: event.node.menuName };
     if (event.checked) {
       checkStrictlyMenu.value.push(o);
+      eachChildrenAdd(event.node);
+      if (event.halfCheckedNodes?.length > 0) {
+        event.halfCheckedNodes.forEach((child) => {
+          let e = { menuId: child.menuId, menuName: child.menuName };
+          if (checkStrictlyMenu.value.find((item) => item.menuId === e.menuId) == undefined) {
+            checkStrictlyMenu.value.push(e);
+          }
+        });
+      }
     } else {
+      let menus=[];
       checkStrictlyMenu.value.forEach((val, idx, array) => {
-        // val: 褰撳墠鍊�
-        if (val.menuId == event.node.menuId) {
-          checkStrictlyMenu.value.splice(idx, 1);
-          return true;
+        if (val.menuId != event.node.menuId && !findChild(event.node, val)) {
+          menus.push({ menuId: val.menuId, menuName: val.menuName });
         }
       });
+      checkStrictlyMenu.value = menus;
     }
   };
   const onCheckKnowledge = (newCheckedKeys, event) => {
@@ -402,9 +438,7 @@
     }
   };
 
-  const handleRemove = (key) => {
-    checkStrictly.value = checkStrictly.value.filter((tag) => tag !== key);
-  };
+
   const handleMenuRemove = (key) => {
     checkStrictlyMenu.value = checkStrictlyMenu.value.filter(
       (tag) => tag !== key
@@ -564,6 +598,7 @@
       checkStrictlyKnowledge.value = [];
       checkedKeysKnowledge.value = [];
       checkStrictlyDialog.value = [];
+      checkStrictlyAgent.value = [];
       checkedKeysDialog.value = [];
       selectRole.value = record;
       if (record.resources) {
@@ -636,18 +671,45 @@
   };
 
 
+  let userResources = JSON.parse(getUserResources());
+  const isExist = (val): boolean => {
+    let isok = false;
+    userResources.forEach((r) => {
+      if (val == r.menuId) {
+        isok = true;
+      }
+    });
+    return isok;
+  };
+  const removeChild = (nodes,newT) => {
+    nodes.forEach((child) => {
+      if (isExist(child.menuId)){
+        newT.push(child);
+        let nt = [];
+        if (child.children?.length > 0) {
+          removeChild(child.children, nt);
+          child.children = nt;
+        }
+      }
+    });
+  };
+
   const MenuData = async (key) => {
     await ResourceList(key).then((res) => {
+      let newTree = [];
+      if (u.role != "admin") {
+        removeChild(res.rows, newTree);
+      }
       treeDataMenu.value = [...res.rows];
     });
   };
 
-  KnowledgeList().then((res) => {
-    knowledgeList.value = res.rows;
+  KnowledgeList(u.role).then((res) => {
+    knowledgeList.value = res.data;
   });
 
-  DialogList().then((res) => {
-    DialogsList.value = res.rows;
+  DialogList(u.role).then((res) => {
+    DialogsList.value = res.data;
   });
   queryCanvasList(null).then((canvas) => {
     AgentList= canvas.data

--
Gitblit v1.8.0