From c14ece600ff7baf578fa67c04ea611568a55b4ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=91=E6=96=87=E5=8F=AF?= <1041367524@qq.com> Date: Thu, 19 May 2022 15:09:35 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=BB=84=E7=BB=87=E6=9E=B6=E6=9E=84?= =?UTF-8?q?=E8=A7=92=E8=89=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/store/modules/permission/dept/dept.js | 4 +- src/store/modules/permission/dept/deptRole.js | 42 ++++--- src/store/modules/permission/role/role.js | 2 +- src/views/permission/dept/index.vue | 108 ++++++++++++------ src/views/permission/role/index.vue | 2 +- 5 files changed, 98 insertions(+), 60 deletions(-) diff --git a/src/store/modules/permission/dept/dept.js b/src/store/modules/permission/dept/dept.js index fcc7f67..dfccae3 100644 --- a/src/store/modules/permission/dept/dept.js +++ b/src/store/modules/permission/dept/dept.js @@ -1,4 +1,5 @@ import * as api from '@/api/permission/dept.js'; +import * as systemAPI from '@/api/permission/system.js'; import { ElMessage, ElMessageBox } from '@/plugins/element-plus'; const state = () => ({ condition: {}, @@ -6,7 +7,7 @@ const state = () => ({ total: 0, opts: { init: false, - role: [], + system: [], }, }); const getters = {}; @@ -29,6 +30,7 @@ const actions = { commit('setOpts', { ...state.opts, init: true, + system: await systemAPI.search(), }); }, detail: async (context, id) => { diff --git a/src/store/modules/permission/dept/deptRole.js b/src/store/modules/permission/dept/deptRole.js index 84e093c..84d3969 100644 --- a/src/store/modules/permission/dept/deptRole.js +++ b/src/store/modules/permission/dept/deptRole.js @@ -1,4 +1,5 @@ import * as api from '@/api/permission/dept.js'; +import * as roleAPI from '@/api/permission/role.js'; import { ElMessage, ElMessageBox } from '@/plugins/element-plus'; const state = () => ({ code: 'DeptRoleManagement', @@ -9,7 +10,9 @@ const state = () => ({ init: false, }, }); -const getters = {}; +const getters = { + roleList: (state) => (systemId) => state.list.find((item) => item.systemVO.id === systemId)?.roleListVO || [], +}; const mutations = { setCondition: (state, data) => (state.condition = data), setList: (state, data) => (state.list = data), @@ -31,16 +34,15 @@ const actions = { init: true, }); }, - detail: async (context, id) => { - let res = await api.detail(id); + role: async (context, systemId) => { + let res = await roleAPI.search({ pageIndex: 1, length: 9999, systemId }); if (!res) { - ElMessage.error('加载详情失败'); + ElMessage.error('查询系统角色失败'); } - return res; + return res?.records || []; }, save: async ({ dispatch }, data) => { - let save = data.id ? api.update : api.create; - let res = await save(data); + let res = await api.addRole(data); if (res) { ElMessage.success('保存成功'); dispatch('search'); @@ -49,22 +51,18 @@ const actions = { } return res; }, - remove: async ({ dispatch }, idList) => { - if (!idList.length) { - ElMessage.warning('请选择要删除的数据'); - } else { - try { - await ElMessageBox.confirm('数据删除后无法恢复,确定要删除吗?', '危险操作'); - let res = await api.remove(idList.join(',')); - if (res) { - ElMessage.success('删除成功'); - dispatch('search'); - } else { - ElMessage.error('删除失败'); - } - } catch (e) { - console.info('取消删除', e); + remove: async ({ dispatch }, data) => { + try { + await ElMessageBox.confirm('数据删除后无法恢复,确定要删除吗?', '危险操作'); + let res = await api.delRole(data); + if (res) { + ElMessage.success('删除成功'); + dispatch('search'); + } else { + ElMessage.error('删除失败'); } + } catch (e) { + console.info('取消删除', e); } }, }; diff --git a/src/store/modules/permission/role/role.js b/src/store/modules/permission/role/role.js index ea43e75..48d21e4 100644 --- a/src/store/modules/permission/role/role.js +++ b/src/store/modules/permission/role/role.js @@ -68,7 +68,7 @@ const actions = { let update = data.roleIds instanceof Array ? deptAPI.addRole : deptAPI.delRole; let res = await update(data); if (!res) { - ElMessage.error('保存组织机构失败'); + ElMessage.error('保存失败'); } return res; }, diff --git a/src/views/permission/dept/index.vue b/src/views/permission/dept/index.vue index 21acd2d..154eeb5 100644 --- a/src/views/permission/dept/index.vue +++ b/src/views/permission/dept/index.vue @@ -107,40 +107,51 @@ -
-
-

- {{ item.systemVO.systemName }} -

-
- - {{ role.roleName }} - - - -

还没做

-
- 取消 - 确定 -
- -
+ +
请选择组织架构
+ + + + + + + +
@@ -282,7 +293,9 @@ /* 角色 */ const loading3 = ref(false); const roleVisible = ref(false); - const roleList = computed(() => _.cloneDeep(store.state.deptRole.list)); + const systemRoleList = ref([]); + const currentSystemId = ref(null); + const checkedRole = ref([]); const handleSearchRole = async () => { if (state.condition3.departmentId) { loading3.value = true; @@ -304,9 +317,34 @@ { immediate: true, deep: true } ); const handleDelRole = async (id) => { - store.dispatch('deptRole/remove', { id }); + store.dispatch('deptRole/remove', { + departmentId: state.condition3.departmentId, + isDeleteDepartmentOfEmployeeRole: true, + roleId: id, + }); + }; + const handleAddRole = async (id) => { + loading3.value = true; + roleVisible.value = true; + currentSystemId.value = id; + systemRoleList.value = await store.dispatch('deptRole/role', id); + loading3.value = false; + }; + const handleSaveRole = async () => { + loading3.value = true; + let res = + !unref(checkedRole).length || + (await store.dispatch('deptRole/save', { + departmentId: state.condition3.departmentId, + isDistributionCurrentDepartmentEmployee: true, + roleIds: unref(checkedRole), + })); + if (res) { + roleVisible.value = false; + handleSearchRole(); + } + loading3.value = false; }; - const handleAddRole = async () => {}; /* 表单 */ const refsForm = ref(null); diff --git a/src/views/permission/role/index.vue b/src/views/permission/role/index.vue index 2d62710..45d1de9 100644 --- a/src/views/permission/role/index.vue +++ b/src/views/permission/role/index.vue @@ -291,7 +291,7 @@ isDistributionCurrentDepartmentEmployee: true, roleIds: [formState.form.id], } - : { departmentId: data.id, isDeleteDepartmentOfEmployeeRole: true, roleIds: formState.form.id }; + : { departmentId: data.id, isDeleteDepartmentOfEmployeeRole: true, roleId: formState.form.id }; store.dispatch('role/updateDept', params); nextTick(() => { try {