From 112c70179920a4d0651cc208f1b1e1e4bbf7f317 Mon Sep 17 00:00:00 2001 From: xuziqiang <1344691446@qq.com> Date: Fri, 7 Jun 2024 14:14:21 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=A1=A5=E5=85=85=E8=A7=92=E8=89=B2?= =?UTF-8?q?=E6=9D=83=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hx-ai-intelligent/src/api/origanizemanage.ts | 3 + hx-ai-intelligent/src/router/organizationManage.ts | 5 +- .../organizationManage/departmentManage/index.vue | 178 +++++++++++++++------ hx-ai-intelligent/vite.config.ts | 2 +- 4 files changed, 131 insertions(+), 57 deletions(-) diff --git a/hx-ai-intelligent/src/api/origanizemanage.ts b/hx-ai-intelligent/src/api/origanizemanage.ts index 12d2b93..aa3821c 100644 --- a/hx-ai-intelligent/src/api/origanizemanage.ts +++ b/hx-ai-intelligent/src/api/origanizemanage.ts @@ -28,4 +28,7 @@ export enum department { addRole = `${BASE_URL}/api/dept/addRole`, editRole = `${BASE_URL}/api/dept/editRole`, queryRoleTree = `${BASE_URL}/api/dept/queryRoleTree`, + + queryDeptPermission = `${BASE_URL}/api/dept/queryDeptPermission`, + queryRolePermission = `${BASE_URL}/api/dept/queryRolePermission`, } diff --git a/hx-ai-intelligent/src/router/organizationManage.ts b/hx-ai-intelligent/src/router/organizationManage.ts index 363e6e0..e6031ff 100644 --- a/hx-ai-intelligent/src/router/organizationManage.ts +++ b/hx-ai-intelligent/src/router/organizationManage.ts @@ -83,11 +83,11 @@ const organizationManage = { name: 'AuthorityManage', meta: { title: '部门/权限', hideChildren: true, icon: 'dicizhishou' }, component: Base, - redirect: { name: 'authorityManageIndex' }, + redirect: { name: 'AuthorityManageIndex' }, children: [ { path: 'index', - name: 'authorityManageIndex', + name: 'AuthorityManageIndex', component: () => import('/@/view/organizationManage/departmentManage/index.vue'), meta: { title: '部门/权限', @@ -97,7 +97,6 @@ const organizationManage = { }, ], }, - ], }; export default organizationManage; diff --git a/hx-ai-intelligent/src/view/organizationManage/departmentManage/index.vue b/hx-ai-intelligent/src/view/organizationManage/departmentManage/index.vue index e505664..3b1df11 100644 --- a/hx-ai-intelligent/src/view/organizationManage/departmentManage/index.vue +++ b/hx-ai-intelligent/src/view/organizationManage/departmentManage/index.vue @@ -39,21 +39,28 @@ formLayout="vertical" class="form" /> - + - + - 取消 - 确定 +
+ 取消 + 确定 +
+
+ 确定 +
@@ -61,9 +68,7 @@
角色管理
- 新增角色 + 新增角色 新增子角色 删除
- + - - + @select="UserSelect" /> - 取消 - 确定 +
+ 取消 + 确定 +
+
+ 确定 +
@@ -112,7 +121,7 @@ import { Modal } from 'ant-design-vue'; import { ExclamationCircleOutlined } from '@ant-design/icons-vue'; import { http } from '/nerv-lib/util/http'; - import { cloneDeep } from 'lodash-es'; + import { cloneDeep, get } from 'lodash-es'; import { formConfig, formConfig2 } from './config'; import { department } from '/@/api/origanizemanage'; import { permission } from '/@/api/origanizemanage'; @@ -140,34 +149,18 @@ const projectId = JSON.parse(sessionStorage.getItem('userInfo')).projectId; const userAdminTreeData = ref([]); const apartmentTreeData = ref([]); + const apartmentAdminTreeData = ref([]); const userTreeData = ref([]); const getPermissionTree = (params) => { - return http.post(permission.permissionTree, params); + return http.post(permission.permissionTree, params).then((res) => { + apartmentAdminTreeData.value = get(res, 'data.data'); + userAdminTreeData.value = get(res, 'data.data'); + }); }; + getPermissionTree({ projectId }); - const apartmentAdminTreeData = [ - { - title: '首页', - key: '0-0', - children: [ - { - title: '控制台', - key: '0-0-0', - children: [ - { title: 'leaf', key: '0-0-0-0' }, - { title: 'leaf', key: '0-0-0-1' }, - ], - }, - { - title: '用户管理', - key: '0-0-1', - children: [{ key: '0-0-1-0', title: 'sss' }], - }, - ], - }, - ]; watch(ApartcheckedKeys, () => { console.log('checkedKeys', ApartcheckedKeys.value); }); @@ -183,6 +176,7 @@ apartmentTreeData.value = res.data; }); + // 获取部门树 const getTree = () => { getDepartList({ orgId }).then((res) => { apartmentTreeData.value = res.data; @@ -190,14 +184,17 @@ }); }; - const getUserTree = (params = { deptId: selectRef.value.deptInfo.deptId }) => { + // 获取角色树 + const getUserTree = (params = { deptId: selectRef.value?.deptInfo?.deptId }) => { http.post(department.queryRoleTree, params).then((res) => { userTreeData.value = res.data; }); }; // 根据依赖刷新角色树 watchEffect(() => { - if (selectRef.value) getUserTree(); + if (selectRef.value) { + getUserTree(); + } }); const opMap: any = { @@ -284,7 +281,7 @@ onOk() { http.post(department.deptDel, { deptId: selectRef.value.deptInfo.deptId }).then(() => { getTree(); - clearData(); + clearApartData(); }); }, onCancel() { @@ -307,13 +304,78 @@ class: 'test', }); }; - const clearData = () => { + + const clearApartData = () => { selectRef.value = {}; formData.value = {}; opMap.type = ''; opMap.fuc = ''; selectKey.value = ''; }; + + // 保存部门权限 + const apartmentPermission = () => { + http + .post(department.addPermission, { + deptId: selectRef.value?.deptInfo.deptId, + projectId, + permissionVoList: ApartcheckedKeys.value.map((item) => { + return { permissionId: item }; + }), + }) + .then(() => { + NsMessage.success('保存成功'); + }); + }; + // 保存角色权限 + const rolePermission = () => { + http + .post(department.addRolePermission, { + // deptId: selectRef.value?.deptInfo.deptId, + roleId: selectRef2.value?.roleId, + projectId, + permissionVoList: UsercheckedKeys.value.map((item) => { + return { permissionId: item }; + }), + }) + .then(() => { + NsMessage.success('保存成功'); + }); + }; + + // 获取部门拥有的权限 + const getDeptPermission = () => { + http + .post(department.queryDeptPermission, { deptId: selectRef.value?.deptInfo.deptId }) + .then((res) => { + ApartcheckedKeys.value = res.data.map((item) => { + return item.permissionId; + }); + }); + }; + + // 获取角色拥有的权限 + const getRolePermission = () => { + http + .post(department.queryRolePermission, { roleId: selectRef2.value?.roleId }) + .then((res) => { + UsercheckedKeys.value = res.data.map((item) => { + return item.permissionId; + }); + }); + }; + + /** + * 默认选中视为编辑部门 + * type editDpet + */ + const apartmentChoose = () => { + opMap.type = 'editDpet'; + opMap.fuc = (params) => { + return http.post(department.deptEdit, params); + }; + }; + // 部门选择 const SelectApartmentTree = (selectedKeys: any, info: any) => { const { selected } = info; @@ -322,12 +384,21 @@ selectKey.value = selectedKeys[0]; selectRef.value = info.node.dataRef; formData.value = cloneDeep(info.node.dataRef.deptInfo); + apartmentChoose(); + ApartcheckedKeys.value.splice(0); + getDeptPermission(); + // getUserTree({ deptId: selectRef.value.deptInfo.deptId }); + }; + + /** + * 默认选中视为编辑角色 + * type editDpet + */ + const roleChoose = () => { opMap.type = 'editDpet'; opMap.fuc = (params) => { return http.post(department.deptEdit, params); }; - - // getUserTree({ deptId: selectRef.value.deptInfo.deptId }); }; // 角色选择 @@ -339,14 +410,15 @@ selectKey2.value = selectedKeys[0]; selectRef2.value = info.node.dataRef; formData2.value = cloneDeep(info.node.dataRef); - opMap.type = 'editRole'; - opMap.fuc = (params) => { - return http.post(department.editRole, params); - }; + roleChoose(); + UsercheckedKeys.value.splice(0); + getRolePermission(); }; const CancelApartment = () => { disabled.value = true; + // 取消视为转入编辑状态 + // clearApartData(); }; const CancelUser = () => { @@ -382,10 +454,9 @@ opMap.fuc && opMap.fuc({ ...formData.value, selectRef: selectRef.value }); } }; + const UserSure = () => { disabled2.value = !disabled2.value; - console.log(formData2.value, 'formData2'); - console.log(opMap.type, 'opMap.type'); const typeArr = ['addUserSon', 'addUser', 'editRole']; if (typeArr.includes(opMap.type)) { opMap.fuc && @@ -403,7 +474,6 @@ else { console.log('ss'); } - formData2.value = {}; }; return { @@ -436,6 +506,8 @@ UsercheckedKeys, UserSelect, formRef, + apartmentPermission, + rolePermission, }; }, }); diff --git a/hx-ai-intelligent/vite.config.ts b/hx-ai-intelligent/vite.config.ts index 2494632..7372520 100644 --- a/hx-ai-intelligent/vite.config.ts +++ b/hx-ai-intelligent/vite.config.ts @@ -12,7 +12,7 @@ const proxy = { changeOrigin: true, }, '/carbon-smart': { - target: 'http://123.60.103.97:8224', + target: 'http://192.168.112.144:8224', changeOrigin: true, rewrite: (path) => path.replace(/^\/carbon-smart/, ''), },