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 | 326 +++++++++++++++++++++++++++--------------------------- 1 files changed, 163 insertions(+), 163 deletions(-) diff --git a/src/views/authority/role/index.vue b/src/views/authority/role/index.vue index 2704363..a3b1cc1 100644 --- a/src/views/authority/role/index.vue +++ b/src/views/authority/role/index.vue @@ -77,9 +77,6 @@ <template #index="{ rowIndex }"> {{ rowIndex + 1 + (pagination.current - 1) * pagination.pageSize }} </template> - <template #dept="{ record }">{{ - record.dept ? record.dept.deptName : '' - }}</template> <template #status="{ record }"> <a-switch checked-value="1" @@ -90,25 +87,20 @@ </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-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-button - type="dashed" - status="warning" - @click="operation(4, record)" - >鏉冮檺閰嶇疆</a-button - > - <a-button status="success" @click="operation(5, record)" - >閮ㄩ棬閰嶇疆</a-button - > + + </a-space> </template> </a-table> @@ -119,60 +111,14 @@ @cancel="handleCancel(1)" @ok="editHandleOk" > - <a-form :model="editform"> - <a-form-item 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="roleKey" label="鏉冮檺瀛楃涓�"> - <a-input v-model="editform.roleKey" /> </a-form-item> <a-form-item field="remark" label="澶囨敞"> <a-input v-model="editform.remark" /> </a-form-item> </a-form> - </a-modal> - <a-modal - width="50%" - v-model:visible="deptvisible" - title="閮ㄩ棬閰嶇疆" - @cancel="handleCancel(2)" - @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', - }" - :check-strictly="checkStrictly" - > - </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> </a-modal> <a-modal width="30%" @@ -194,16 +140,15 @@ 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> </a-tab-pane> @@ -215,7 +160,6 @@ <a-space direction="vertical" size="large"> <a-checkbox-group v-model="checkedKeysKnowledge" - direction="vertical" @change="onCheckKnowledge" > <a-checkbox @@ -223,7 +167,7 @@ :value="knowledg.id" :lable="knowledg.name" @change="onCheckKnowledge" - > + style="width:150px"> {{ knowledg.name }} </a-checkbox> </a-checkbox-group> @@ -236,7 +180,6 @@ </template> <a-checkbox-group v-model="checkedKeysDialog" - direction="vertical" @change="onCheckDialog" > <a-checkbox @@ -244,8 +187,21 @@ :value="dialog.id" :lable="dialog.name" @change="onCheckDialog" - > + style="width:150px"> {{ dialog.name }} + </a-checkbox> + </a-checkbox-group> + <a-checkbox-group + v-model="checkedKeysAgent" + @change="onCheckAgent" + > + <a-checkbox + v-for="(agent, index) of AgentList" + :value="agent.id" + :lable="agent.title" + @change="onCheckAgent" + style="width:150px"> + {{ agent.title }} </a-checkbox> </a-checkbox-group> </a-tab-pane> @@ -258,7 +214,7 @@ 'margin': '1px', }" class="card-demo" - title="鐢ㄦ埛鎵�鏈夋潈闄�" + title="瑙掕壊鎵�鏈夋潈闄�" hoverable > <a-space wrap> @@ -292,6 +248,13 @@ > {{ 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-card> </div> @@ -320,11 +283,10 @@ } from "@/api/authority"; import { Modal } from '@arco-design/web-vue'; import Authheader from '@/views/authority/components/authheader.vue'; - - let treeData = ref([]); - let checkedKeys = ref([]); - let expandKdys = ref([]); - let checkStrictly = ref([]); + 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([]); @@ -337,8 +299,12 @@ let checkedKeysDialog = ref([]); let checkStrictlyDialog = ref([]); + let checkedKeysAgent = ref([]); + let checkStrictlyAgent = ref([]); + let knowledgeList = ref([]); let DialogsList = ref([]); + let AgentList = ref([]); let menuTips = ref(['鏉冮檺绠$悊', '瑙掕壊']); type SizeProps = 'mini' | 'small' | 'medium' | 'large'; @@ -369,36 +335,55 @@ let size = ref<SizeProps>('medium'); let visible = ref(false); - let deptvisible = ref(false); let resourcevisible = ref(false); let selectRole = ref({}); - const onCheck = (newCheckedKeys, event) => { - let o = { deptId: event.node.deptId, deptName: event.node.deptName }; - if (event.checked) { - checkStrictly.value.push(o); - } else { - checkStrictly.value.forEach((val, idx, array) => { - // val: 褰撳墠鍊� - if (val.deptId == event.node.deptId) { - checkStrictly.value.splice(idx, 1); - return true; + 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) => { @@ -413,6 +398,23 @@ // val: 褰撳墠鍊� if (val.knowledgeId == event.target.value) { checkStrictlyKnowledge.value.splice(idx, 1); + return true; + } + }); + } + }; + const onCheckAgent = (newCheckedKeys, event) => { + let o = { + agentId: event.target.value, + agentTitle: event.target.labels[0].innerText, + }; + if (event.target.checked) { + checkStrictlyAgent.value.push(o); + } else { + checkStrictlyAgent.value.forEach((val, idx, array) => { + // val: 褰撳墠鍊� + if (val.agentId == event.target.value) { + checkStrictlyAgent.value.splice(idx, 1); return true; } }); @@ -436,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 @@ -454,7 +454,7 @@ (tag) => tag !== key ); }; - + let formRef = ref(); const basePagination: Pagination = { current: 1, pageSize: 15, @@ -492,15 +492,6 @@ dataIndex: 'roleName', }, { - title: t('鍒涘缓鏃堕棿'), - dataIndex: 'createTime', - }, - { - title: t('鏉冮檺瀛楃涓�'), - dataIndex: 'roleKey', - slotName: 'roleKey', - }, - { title: t('鐘舵��'), dataIndex: 'status', slotName: 'status', @@ -521,28 +512,15 @@ visible.value = false; } if (type == 2) { - deptvisible.value = false; - } - if (type == 2) { resourcevisible.value = false; } }; - 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 editResourceHandleOk = async () => { let resources: Array = [], dialogs: Array = [], + agents: Array = [], Knowledges: Array = [], role: Role = { roleId: selectRole.value.roleId }; checkStrictlyMenu.value.forEach((val) => { @@ -560,25 +538,39 @@ }); role.dialogs = dialogs; + checkStrictlyAgent.value.forEach((val) => { + agents.push(val.agentId); + }); + role.agents = agents; + await RoleEdit(role).then((res) => { fetchData(); }); }; - const editHandleOk = async () => { - 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) { @@ -588,15 +580,7 @@ editform.value.roleKey = ""; editform.value.remark = ""; } - //缂栬緫 - if (t == 2) { - visible.value = true; - save.value = '缂栬緫'; - editform.value.roleId=record.roleId - editform.value.roleName = record.roleName; - editform.value.roleKey = record.roleKey; - editform.value.remark = record.remark; - } + //鍒犻櫎 if (t == 3) { await RoleDelete(record.roleId).then((res) => { @@ -614,6 +598,7 @@ checkStrictlyKnowledge.value = []; checkedKeysKnowledge.value = []; checkStrictlyDialog.value = []; + checkStrictlyAgent.value = []; checkedKeysDialog.value = []; selectRole.value = record; if (record.resources) { @@ -644,23 +629,13 @@ checkedKeysDialog.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, + if (record.agents) { + record.agents.forEach((val) => { + checkStrictlyAgent.value.push({ + agentId: val.id, + agentTitle: val.title, }); - checkedKeys.value.push(val.deptId); - expandKdys.value.push(val.deptId); + checkedKeysAgent.value.push(val.id); }); } } @@ -695,26 +670,51 @@ fetchData({ ...basePagination, current }); }; - const OrganizationData = async (key) => { - await OrganizationList(key).then((res) => { - treeData.value = [...res.rows]; + + 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 }); fetchData(); - OrganizationData(''); MenuData(); const reset = () => { -- Gitblit v1.8.0