From 06bd37d6cb3772e0ae8af3d455efa8bf2a595896 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=91=E6=96=87=E5=8F=AF?= <1041367524@qq.com> Date: Tue, 17 May 2022 16:28:10 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=83=A8=E9=97=A8=E8=A7=92=E8=89=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/extensions.json | 4 +- src/api/permission/dept.js | 7 ++ src/store/modules/permission/dept/dept.js | 1 + src/store/modules/permission/dept/deptRole.js | 76 +++++++++++++ src/views/permission/dept/index.vue | 104 +++++++++++++++++- 5 files changed, 186 insertions(+), 6 deletions(-) create mode 100644 src/store/modules/permission/dept/deptRole.js diff --git a/.vscode/extensions.json b/.vscode/extensions.json index f9ca4ee..ea33ddc 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -7,8 +7,8 @@ "ecmel.vscode-html-css", "abusaidm.html-snippets", "octref.vetur", - "johnsoncodehk.volar", "dbaeumer.vscode-eslint", - "esbenp.prettier-vscode" + "esbenp.prettier-vscode", + "Vue.volar" ] } diff --git a/src/api/permission/dept.js b/src/api/permission/dept.js index 17049ee..71ded74 100644 --- a/src/api/permission/dept.js +++ b/src/api/permission/dept.js @@ -47,6 +47,13 @@ export const remove = (idList) => { params: { idList }, }); }; +export const searchRole = (params) => { + return request({ + url: '/uc/role/department', + method: 'get', + params, + }); +}; export const addRole = (data) => { return request({ url: '/uc/department/role', diff --git a/src/store/modules/permission/dept/dept.js b/src/store/modules/permission/dept/dept.js index be24b6e..fcc7f67 100644 --- a/src/store/modules/permission/dept/dept.js +++ b/src/store/modules/permission/dept/dept.js @@ -6,6 +6,7 @@ const state = () => ({ total: 0, opts: { init: false, + role: [], }, }); const getters = {}; diff --git a/src/store/modules/permission/dept/deptRole.js b/src/store/modules/permission/dept/deptRole.js new file mode 100644 index 0000000..84e093c --- /dev/null +++ b/src/store/modules/permission/dept/deptRole.js @@ -0,0 +1,76 @@ +import * as api from '@/api/permission/dept.js'; +import { ElMessage, ElMessageBox } from '@/plugins/element-plus'; +const state = () => ({ + code: 'DeptRoleManagement', + condition: {}, + list: [], + total: 0, + opts: { + init: false, + }, +}); +const getters = {}; +const mutations = { + setCondition: (state, data) => (state.condition = data), + setList: (state, data) => (state.list = data), + setTotal: (state, data) => (state.total = data), + setOpts: (state, data) => (state.opts = data), +}; +const actions = { + search: async ({ state, commit }) => { + let res = await api.searchRole(state.condition); + commit('setList', res || []); + if (!res) { + ElMessage.error('查询部门角色失败'); + } + return res; + }, + load: async ({ state, commit }) => { + commit('setOpts', { + ...state.opts, + init: true, + }); + }, + detail: async (context, id) => { + let res = await api.detail(id); + if (!res) { + ElMessage.error('加载详情失败'); + } + return res; + }, + save: async ({ dispatch }, data) => { + let save = data.id ? api.update : api.create; + let res = await save(data); + if (res) { + ElMessage.success('保存成功'); + dispatch('search'); + } else { + ElMessage.error('保存失败'); + } + 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); + } + } + }, +}; +export default { + state, + getters, + mutations, + actions, +}; diff --git a/src/views/permission/dept/index.vue b/src/views/permission/dept/index.vue index b24ab98..21acd2d 100644 --- a/src/views/permission/dept/index.vue +++ b/src/views/permission/dept/index.vue @@ -22,7 +22,7 @@ children: 'childDepartment', disabled: (data) => !data.isEnable, }" - @current-change="(data) => (state.condition2.departmentId = data.id)" + @current-change="(data) => handleChange(data.id)" >