From cb98465a22cc88684c5798df88f2e0795a5e6ba8 Mon Sep 17 00:00:00 2001
From: zhangxiao <898441624@qq.com>
Date: 星期二, 10 九月 2024 09:48:53 +0800
Subject: [PATCH] 修改资源配置中菜单界面bug

---
 src/views/authority/role/index.vue |  403 +++++++++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 360 insertions(+), 43 deletions(-)

diff --git a/src/views/authority/role/index.vue b/src/views/authority/role/index.vue
index baa7842..76db54f 100644
--- a/src/views/authority/role/index.vue
+++ b/src/views/authority/role/index.vue
@@ -87,20 +87,26 @@
         </template>
         <template #operations="{ record }">
           <a-space>
+            <a-button type="outline" @click="operation(2, record)"
+            >缂栬緫</a-button
+            >
             <a-button
               type="dashed"
               status="warning"
               @click="operation(4, record)"
-            >瑙掕壊鏉冮檺</a-button>
+            >璧勬簮閰嶇疆</a-button>
+            <a-button
+              type="dashed"
+              status="success"
+              @click="operation(5, record)"
+            >閮ㄩ棬閰嶇疆</a-button>
             <a-popconfirm
-              content="Are you sure you want to delete?"
+              content="璇风‘璁ゆ槸鍚﹀垹闄わ紵"
               type="success"
               @ok="operation(3, record)"
             >
               <a-button type="outline" status="danger">鍒犻櫎</a-button>
             </a-popconfirm>
-
-
           </a-space>
         </template>
       </a-table>
@@ -111,8 +117,8 @@
       @cancel="handleCancel(1)"
       @ok="editHandleOk"
     >
-      <a-form :model="editform">
-        <a-form-item required field="roleName" label="瑙掕壊鍚�">
+      <a-form  ref="formRef" :model="editform">
+        <a-form-item required field="roleName" label="瑙掕壊鍚�" :rules="[{required:true,message:'瑙掕壊鍚嶅繀濉�'},{maxLength:50,message:'闀垮害涓嶈秴杩�50'}]">
           <a-input v-model="editform.roleName" />
         </a-form-item>
         <a-form-item field="remark" label="澶囨敞">
@@ -136,22 +142,23 @@
               <icon-calendar />
               鑿滃崟
             </template>
+            <div class="cdtree">
             <a-tree
               class="tree-demo"
               v-model:checked-keys="checkedKeysMenu"
               v-model:expanded-keys="expandKdysMenu"
+              :only-check-leaf=true
               :checkable="true"
               :data="treeDataMenu"
-              :show-line="showLineMenu"
               @check="onCheckMenu"
               :fieldNames="{
                 key: 'menuId',
                 title: 'menuName',
                 children: 'children',
               }"
-              :check-strictly="checkStrictlyMenu"
             >
             </a-tree>
+            </div>
           </a-tab-pane>
           <a-tab-pane key="2">
             <template #title>
@@ -193,8 +200,8 @@
               </a-checkbox>
             </a-checkbox-group>
             <a-checkbox-group
-              v-model="checkedKeysDialog"
-              @change="onCheckDialog"
+              v-model="checkedKeysAgent"
+              @change="onCheckAgent"
             >
               <a-checkbox
                 v-for="(agent, index) of AgentList"
@@ -203,6 +210,24 @@
                 @change="onCheckAgent"
                 style="width:150px">
                 {{ agent.title }}
+              </a-checkbox>
+            </a-checkbox-group>
+          </a-tab-pane>
+          <a-tab-pane key="4">
+            <template #title>
+              <icon-user />
+              妯″瀷
+            </template>
+            <a-checkbox-group
+              v-model="checkedKeysModel"
+              @change="onCheckModel"
+            >
+              <a-checkbox
+                v-for="(model, index) of ModelList"
+                :value="model.id"
+                @change="onCheckModel"
+                style="width:100%">
+                {{ model.llm_factory+" "+model.llm_name+" "+model.model_type }}
               </a-checkbox>
             </a-checkbox-group>
           </a-tab-pane>
@@ -215,7 +240,7 @@
             'margin': '1px',
           }"
           class="card-demo"
-          title="鐢ㄦ埛鎵�鏈夋潈闄�"
+          title="瑙掕壊鎵�鏈夋潈闄�"
           hoverable
         >
           <a-space wrap>
@@ -249,6 +274,64 @@
             >
               {{ tag.dialogName }}
             </a-tag>
+            <a-tag
+              v-for="(tag, index) of checkStrictlyAgent"
+              :key="tag.agentId"
+              @close="handleDialogRemove(tag)"
+            >
+              {{ tag.agentTitle }}
+            </a-tag>
+          </a-space>
+          <a-divider />
+          <a-space wrap>
+            妯″瀷:
+            <a-tag
+              v-for="(tag, index) of checkStrictlyModel"
+              :key="tag.modelId"
+            >
+              {{ tag.modelTitle }}
+            </a-tag>
+          </a-space>
+        </a-card>
+      </div>
+    </a-modal>
+    <a-modal
+      width="50%"
+      v-model:visible="deptvisible"
+      title="閮ㄩ棬閰嶇疆"
+      @cancel="handleCancel(3)"
+      @ok="editDeptHandleOk"
+    >
+      <div :style="{ display: 'flex' }">
+        <a-card
+          :style="{ 'width': '460px', 'height': '500px', 'overflow-y': 'auto' }"
+          title="閮ㄩ棬閰嶇疆"
+          hoverable
+        >
+          <a-tree
+            class="tree-demo"
+            v-model:checked-keys="checkedKeys"
+            v-model:expanded-keys="expandKdys"
+            :checkable="true"
+            :data="treeData"
+            :show-line="showLine"
+            @check="onCheck"
+            :fieldNames="{
+              key: 'deptId',
+              title: 'deptName',
+              children: 'children',
+            }"
+          >
+          </a-tree>
+        </a-card>
+        <a-card class="card-demo" title="瑙掕壊鎵�灞為儴闂�" hoverable>
+          <a-space wrap>
+            <a-tag
+              v-for="(tag, index) of checkStrictly"
+              :key="tag.deptId"
+            >
+              {{ tag.deptName }}
+            </a-tag>
           </a-space>
         </a-card>
       </div>
@@ -278,7 +361,14 @@
   import { Modal } from '@arco-design/web-vue';
   import Authheader from '@/views/authority/components/authheader.vue';
   import router from "@/router";
-  import { queryCanvasList } from "@/api/Agent";
+  import { queryCanvasList, queryModelList } from "@/api/Agent";
+  import { getUserInfo, getUserResources } from "@/utils/auth";
+  import { forEach } from "lodash";
+
+  let treeData = ref([]);
+  let checkedKeys = ref([]);
+  let expandKdys = ref([]);
+  let checkStrictly = ref([]);
 
   let treeDataMenu = ref([]);
   let checkedKeysMenu = ref([]);
@@ -293,10 +383,15 @@
 
   let checkedKeysAgent = ref([]);
   let checkStrictlyAgent = ref([]);
+  let checkStrictlyModel = ref([]);
+  let checkedKeysModel = ref([]);
+
 
   let knowledgeList = ref([]);
   let DialogsList = ref([]);
   let AgentList = ref([]);
+  let ModelList = ref([]);
+
 
   let menuTips = ref(['鏉冮檺绠$悊', '瑙掕壊']);
   type SizeProps = 'mini' | 'small' | 'medium' | 'large';
@@ -327,21 +422,123 @@
 
   let size = ref<SizeProps>('medium');
   let visible = ref(false);
+  let deptvisible = ref(false);
   let resourcevisible = ref(false);
   let selectRole = ref({});
+
+  let u =JSON.parse(getUserInfo());
+
+
+  const editDeptHandleOk = async () => {
+    let depts: Array = [],
+      role: Role = { roleId: selectRole.value.roleId };
+    checkStrictly.value.forEach((val) => {
+      depts.push(val.deptId);
+    });
+    role.dept = depts;
+    await RoleEdit(role).then((res) => {
+      fetchData();
+    });
+  };
+
+  const onCheck = (newCheckedKeys, event) => {
+    if (event.checked) {
+      if (event.node.children.length > 0) {
+        event.checkedNodes.forEach((node) => {
+          let o = { deptId: node.deptId, deptName: node.deptName,parentId: node.parentId };
+          checkStrictly.value.push(o);
+        });
+      } else {
+        let o = { deptId: event.node.deptId, deptName: event.node.deptName,parentId: event.node.parentId };
+        checkStrictly.value.push(o);
+      }
+    } else {
+      let depts = [];
+      let isParent = false;
+      let parentNode;
+      checkStrictly.value.forEach((val, idx, array) => {
+        if (val.deptId == event.node.parentId) {
+          parentNode = { deptId: val.deptId, deptName: val.deptName, parentId: val.parentId };
+        } else {
+          if (val.deptId != event.node.deptId && !findDeptChild(event.node, val)) {
+            depts.push({ deptId: val.deptId, deptName: val.deptName, parentId: val.parentId });
+            if (val.parentId == event.node.parentId && val.parentId.length>0) {
+              isParent = true;
+            }
+          }
+        }
+      });
+      if (isParent && parentNode) {
+        depts.push(parentNode);
+      }
+      checkStrictly.value = depts;
+    }
+  };
+
+  const findDeptChild = (node, val): boolean => {
+    let isExist = false;
+    if (node.children?.length > 0) {
+      node.children.forEach((child) => {
+        if (val.deptId == child.deptId) {
+          isExist = isExist || true;
+        } else {
+          isExist = isExist || findDeptChild(child, val);
+        }
+      });
+    }
+    return isExist;
+  };
+
+  const OrganizationData = async (key) => {
+    await OrganizationList(key).then((res) => {
+      treeData.value = [...res.rows];
+    });
+  };
+
+  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) => {
@@ -378,6 +575,24 @@
       });
     }
   };
+  const onCheckModel = (newCheckedKeys, event) => {
+    let o = {
+      modelId: event.target.value,
+      modelTitle: event.target.labels[0].innerText,
+    };
+    if (event.target.checked) {
+      checkStrictlyModel.value.push(o);
+    } else {
+      checkStrictlyModel.value.forEach((val, idx, array) => {
+        // val: 褰撳墠鍊�
+        if (val.modelId == event.target.value) {
+          checkStrictlyModel.value.splice(idx, 1);
+          return true;
+        }
+      });
+    }
+  };
+
   const onCheckDialog = (newCheckedKeys, event) => {
     let o = {
       dialogId: event.target.value,
@@ -396,9 +611,7 @@
     }
   };
 
-  const handleRemove = (key) => {
-    checkStrictly.value = checkStrictly.value.filter((tag) => tag !== key);
-  };
+
   const handleMenuRemove = (key) => {
     checkStrictlyMenu.value = checkStrictlyMenu.value.filter(
       (tag) => tag !== key
@@ -414,7 +627,7 @@
       (tag) => tag !== key
     );
   };
-
+  let formRef = ref();
   const basePagination: Pagination = {
     current: 1,
     pageSize: 15,
@@ -474,13 +687,18 @@
     if (type == 2) {
       resourcevisible.value = false;
     }
+    if (type == 3) {
+      deptvisible.value = false;
+    }
   };
 
 
   const editResourceHandleOk = async () => {
     let resources: Array = [],
       dialogs: Array = [],
+      agents: Array = [],
       Knowledges: Array = [],
+      llms: Array = [],
       role: Role = { roleId: selectRole.value.roleId };
     checkStrictlyMenu.value.forEach((val) => {
       resources.push(val.menuId);
@@ -497,32 +715,44 @@
     });
     role.dialogs = dialogs;
 
+    checkStrictlyAgent.value.forEach((val) => {
+      agents.push(val.agentId);
+    });
+    role.agents = agents;
+
+    checkStrictlyModel.value.forEach((val) => {
+      llms.push(val.modelId);
+    });
+    role.llms = llms;
+
     await RoleEdit(role).then((res) => {
       fetchData();
     });
   };
 
-  const editHandleOk = async () => {
-    if(editform.value.roleName==""){
-      Modal.warning({
-        title: '璀﹀憡',
-        content: '鍚嶇О涓嶈兘涓虹┖'
-      });
-      return;
-    }
-    if (editform.value.roleId.length > 0) {
-      await RoleEdit({
-        ...editform.value,
-      } as unknown as Role).then((res) => {
-        fetchData();
-      });
+  const cb = async (err) => {
+    if (err) {
+      visible.value = true;
     } else {
-      await RoleAdd({
-        ...editform.value,
-      } as unknown as Role).then((res) => {
-        fetchData();
-      });
+      if (editform.value.roleId.length > 0) {
+        await RoleEdit({
+          ...editform.value,
+        } as unknown as Role).then((res) => {
+          fetchData();
+        });
+      } else {
+        await RoleAdd({
+          ...editform.value,
+        } as unknown as Role).then((res) => {
+          fetchData();
+        });
+      }
     }
+
+  };
+
+  const editHandleOk =  () => {
+    formRef.value.validate(cb);
   };
   const operation = async (t, record) => {
     if (t == 0) {
@@ -531,6 +761,14 @@
       editform.value.roleName = "";
       editform.value.roleKey = "";
       editform.value.remark = "";
+    }
+
+    if (t == 2) {
+      visible.value = true;
+      formRef.value?.resetFields();
+      save.value = '缂栬緫';
+      editform.value.roleId=record.roleId
+      editform.value.roleName = record.roleName;
     }
 
     //鍒犻櫎
@@ -550,6 +788,8 @@
       checkStrictlyKnowledge.value = [];
       checkedKeysKnowledge.value = [];
       checkStrictlyDialog.value = [];
+      checkStrictlyAgent.value = [];
+      checkStrictlyModel.value = [];
       checkedKeysDialog.value = [];
       selectRole.value = record;
       if (record.resources) {
@@ -578,6 +818,44 @@
             dialogName: val.name,
           });
           checkedKeysDialog.value.push(val.id);
+        });
+      }
+      if (record.agents) {
+        record.agents.forEach((val) => {
+          checkStrictlyAgent.value.push({
+            agentId: val.id,
+            agentTitle: val.title,
+          });
+          checkedKeysAgent.value.push(val.id);
+        });
+      }
+      if (record.llms) {
+        record.llms.forEach((val) => {
+          checkStrictlyModel.value.push({
+            modelId: val.id,
+            modelTitle: val.llm_name,
+          });
+          checkedKeysModel.value.push(val.id);
+        });
+      }
+
+    }
+    //閮ㄩ棬閰嶇疆
+    if (t == 5) {
+      deptvisible.value = true;
+      checkedKeys.value = [];
+      expandKdys.value = [];
+      checkStrictly.value = [];
+      selectRole.value = record;
+      expandKdys.value.push('0');
+      if (record?.dept) {
+        record.dept.forEach((val) => {
+          checkStrictly.value.push({
+            deptId: val.deptId,
+            deptName: val.deptName,
+          });
+          checkedKeys.value.push(val.deptId);
+          expandKdys.value.push(val.deptId);
         });
       }
     }
@@ -613,24 +891,56 @@
   };
 
 
+  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
   });
+  queryModelList().then((models) => {
+    ModelList = models.data;
+  });
+
   fetchData();
   MenuData();
+  OrganizationData("");
 
   const reset = () => {
     formModel.value = generateFormModel();
@@ -722,3 +1032,10 @@
     }
   }
 </style>
+<style>
+.cdtree {
+  .arco-tree-node-is-leaf {
+    display: inline-flex;
+  }
+}
+</style>
\ No newline at end of file

--
Gitblit v1.8.0