From af08dae54f74aa9a94f82f298410165fa9b7b614 Mon Sep 17 00:00:00 2001
From: yinbangzhong <zhongbangyin@126.com>
Date: 星期三, 04 九月 2024 13:56:02 +0800
Subject: [PATCH] 单文档

---
 src/api/Agent.ts                    |    4 
 src/views/authority/role/index.vue  |  220 +++++++++++++++++++++++++++++++++++++++++++
 src/views/authority/users/index.vue |   66 ++++++++++---
 src/store/modules/user/index.ts     |    2 
 src/api/authority.ts                |    1 
 5 files changed, 273 insertions(+), 20 deletions(-)

diff --git a/src/api/Agent.ts b/src/api/Agent.ts
index de7af61..a3a690a 100644
--- a/src/api/Agent.ts
+++ b/src/api/Agent.ts
@@ -41,6 +41,10 @@
   });
 }
 
+export function queryModelList() {
+  return axios.get('/api/v1/llm/distinct', {});
+}
+
 // 鐢ㄦ埛涔犳儻浼氳瘽鍒楄〃
 export function appUsageSessionListApi(dialog_id) {
   return axios.get(
diff --git a/src/api/authority.ts b/src/api/authority.ts
index 8f445ae..db2b6a5 100644
--- a/src/api/authority.ts
+++ b/src/api/authority.ts
@@ -80,6 +80,7 @@
   knowledges: any;
   dialogs: any;
   agents: any;
+  llms: any;
 }
 
 export function RoleList(params: Pagination) {
diff --git a/src/store/modules/user/index.ts b/src/store/modules/user/index.ts
index 84388d7..22143e5 100644
--- a/src/store/modules/user/index.ts
+++ b/src/store/modules/user/index.ts
@@ -74,7 +74,7 @@
        
         const userInfo = {
           avatar: res.data.avatar,
-          name: res.data.userName,
+          name: res.data.loginName,
           email: res.data.email,
           role: res.data.roles[0].roleKey,
         };
diff --git a/src/views/authority/role/index.vue b/src/views/authority/role/index.vue
index ea318ca..bdb5a19 100644
--- a/src/views/authority/role/index.vue
+++ b/src/views/authority/role/index.vue
@@ -94,7 +94,12 @@
               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="璇风‘璁ゆ槸鍚﹀垹闄わ紵"
               type="success"
@@ -102,8 +107,6 @@
             >
               <a-button type="outline" status="danger">鍒犻櫎</a-button>
             </a-popconfirm>
-
-
           </a-space>
         </template>
       </a-table>
@@ -208,6 +211,24 @@
               </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>
         </a-tabs>
         <a-card
           :style="{
@@ -259,6 +280,57 @@
               {{ 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>
     </a-modal>
@@ -287,9 +359,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([]);
@@ -304,10 +381,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';
@@ -338,10 +420,78 @@
 
   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) {
@@ -423,6 +573,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,
@@ -517,6 +685,9 @@
     if (type == 2) {
       resourcevisible.value = false;
     }
+    if (type == 3) {
+      deptvisible.value = false;
+    }
   };
 
 
@@ -525,6 +696,7 @@
       dialogs: Array = [],
       agents: Array = [],
       Knowledges: Array = [],
+      llms: Array = [],
       role: Role = { roleId: selectRole.value.roleId };
     checkStrictlyMenu.value.forEach((val) => {
       resources.push(val.menuId);
@@ -545,6 +717,11 @@
       agents.push(val.agentId);
     });
     role.agents = agents;
+
+    checkStrictlyModel.value.forEach((val) => {
+      llms.push(val.modelId);
+    });
+    role.llms = llms;
 
     await RoleEdit(role).then((res) => {
       fetchData();
@@ -610,6 +787,7 @@
       checkedKeysKnowledge.value = [];
       checkStrictlyDialog.value = [];
       checkStrictlyAgent.value = [];
+      checkStrictlyModel.value = [];
       checkedKeysDialog.value = [];
       selectRole.value = record;
       if (record.resources) {
@@ -647,6 +825,35 @@
             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);
         });
       }
     }
@@ -725,8 +932,13 @@
   queryCanvasList(null).then((canvas) => {
     AgentList= canvas.data
   });
+  queryModelList().then((models) => {
+    ModelList = models.data;
+  });
+
   fetchData();
   MenuData();
+  OrganizationData("");
 
   const reset = () => {
     formModel.value = generateFormModel();
diff --git a/src/views/authority/users/index.vue b/src/views/authority/users/index.vue
index 068e9b5..37aeefe 100644
--- a/src/views/authority/users/index.vue
+++ b/src/views/authority/users/index.vue
@@ -171,10 +171,8 @@
           </a-col>
           <a-col :span="10">
             <a-form-item
-              required
               field="role"
               label="瑙掕壊"
-              :rules="[{ required: true, message: '瑙掕壊蹇呴��' }]"
             >
               <a-select
                 multiple
@@ -218,17 +216,28 @@
           >
           </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"
-              @close="handleRemove(tag)"
-            >
-              {{ tag.deptName }}
-            </a-tag>
-          </a-space>
-        </a-card>
+        <div :style="{ 'display': 'flex', 'flex-direction': 'column' }">
+          <a-card class="card-demo" title="鐢ㄦ埛鎵�灞為儴闂�" :style="{ 'width': '460px', 'height': '500px', 'overflow-y': 'auto' }">
+            <a-space wrap>
+              <a-tag
+                v-for="(tag, index) of checkStrictly"
+                :key="tag.deptId"
+              >
+                {{ tag.deptName }}
+              </a-tag>
+            </a-space>
+            <a-divider />
+            <a-space wrap>
+              閮ㄩ棬瑙掕壊:
+              <a-tag
+                v-for="(tag, index) of checkStrictlyDeptRole"
+                :key="tag.roleId"
+              >
+                {{ tag.roleName }}
+              </a-tag>
+            </a-space>
+          </a-card>
+        </div>
       </div>
     </a-modal>
     <a-modal
@@ -327,6 +336,7 @@
   let checkStrictlyKnowledge = ref([]);
   let checkStrictlyDialog = ref([]);
   let checkStrictlyAgent = ref([]);
+  let checkStrictlyDeptRole = ref([]);
   let formRef = ref();
 
   let menuTips = ref(['鏉冮檺绠$悊', '璐﹀彿']);
@@ -377,12 +387,22 @@
   const onCheck = (newCheckedKeys, event) => {
     let o = { deptId: event.node.deptId, deptName: event.node.deptName };
     if (event.checked) {
+      event.node.roles.forEach(
+        (val) => {
+          checkStrictlyDeptRole.value.push(val);
+        }
+      );
       checkStrictly.value.push(o);
     } else {
       checkStrictly.value.forEach((val, idx, array) => {
         // val: 褰撳墠鍊�
         if (val.deptId == event.node.deptId) {
           checkStrictly.value.splice(idx, 1);
+          checkStrictlyDeptRole.value.forEach((val2, idx2, array2) => {
+            if (val2.deptId == event.node.deptId) {
+              checkStrictlyDeptRole.value.splice(idx2, 1);
+            }
+          });
           return true;
         }
       });
@@ -632,16 +652,32 @@
       checkedKeys.value = [];
       expandKdys.value = [];
       checkStrictly.value = [];
+      checkStrictlyDeptRole.value=[];
       selectUser.value = record;
-      expandKdys.value.push('0');
+      expandKdys.value.push("0");
       if (record?.dept) {
         record.dept.forEach((val) => {
           checkStrictly.value.push({
             deptId: val.deptId,
-            deptName: val.deptName,
+            deptName: val.deptName
           });
           checkedKeys.value.push(val.deptId);
           expandKdys.value.push(val.deptId);
+          record.roles.forEach(
+            (r) => {
+              if (r.dept) {
+                r.dept.forEach((d) => {
+                  if (d.deptId == val.deptId) {
+                    checkStrictlyDeptRole.value.push({
+                      roleId: r.roleId,
+                      roleName: r.roleName,
+                      deptId:d.deptId,
+                    });
+                  }
+                });
+              }
+            }
+          );
         });
       }
     }

--
Gitblit v1.8.0