From 83f1933bdc2d6b451daf4c957c49e7b5e7ba9191 Mon Sep 17 00:00:00 2001 From: pixel <303176530@qq.com> Date: Fri, 13 Dec 2019 11:16:25 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=94=B9=E4=BA=86=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E8=A7=92=E8=89=B2=20=E5=92=8C=E8=A7=92?= =?UTF-8?q?=E8=89=B2=E8=AE=BE=E7=BD=AE=E8=8F=9C=E5=8D=95=20=E8=A7=92?= =?UTF-8?q?=E8=89=B2=E8=AE=BE=E7=BD=AE=E6=9D=83=E9=99=90=E7=9A=84=E5=89=8D?= =?UTF-8?q?=E7=AB=AF=E4=BA=A4=E4=BA=92=E4=BD=93=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../view/superAdmin/authority/authority.vue | 186 ++++-------------- .../superAdmin/authority/components/apis.vue | 99 ++++++++++ .../superAdmin/authority/components/menus.vue | 76 +++++++ .../src/view/superAdmin/menu/menu.vue | 10 +- .../src/view/superAdmin/user/user.vue | 65 +++--- 5 files changed, 246 insertions(+), 190 deletions(-) create mode 100644 QMPlusVuePage/src/view/superAdmin/authority/components/apis.vue create mode 100644 QMPlusVuePage/src/view/superAdmin/authority/components/menus.vue diff --git a/QMPlusVuePage/src/view/superAdmin/authority/authority.vue b/QMPlusVuePage/src/view/superAdmin/authority/authority.vue index a404d21e..f4eee894 100644 --- a/QMPlusVuePage/src/view/superAdmin/authority/authority.vue +++ b/QMPlusVuePage/src/view/superAdmin/authority/authority.vue @@ -1,5 +1,5 @@ @@ -89,9 +62,10 @@ import { deleteAuthority, createAuthority } from '@/api/authority' -import { getBaseMenuTree, addMenuAuthority, getMenuAuthority } from '@/api/menu' -import { getAllApis } from '@/api/api' -import { casbinPUpdata, getPolicyPathByAuthorityId } from '@/api/casbin' + +import Menus from '@/view/superAdmin/authority/components/menus' +import Apis from '@/view/superAdmin/authority/components/apis' + import infoList from '@/components/mixins/infoList' export default { name: 'Authority', @@ -100,22 +74,10 @@ export default { return { listApi: getAuthorityList, listKey: 'list', + drawer: false, + activeRow: {}, activeUserId: 0, - menuTreeData: [], - menuTreeIds: [], - menuDefaultProps: { - children: 'children', - label: 'nickName' - }, - - apiTreeData: [], - apiTreeIds: [], - apiDefaultProps: { - children: 'children', - label: 'description' - }, dialogFormVisible: false, - menuDialogFlag: false, apiDialogFlag: false, form: { authorityId: '', @@ -123,7 +85,15 @@ export default { } } }, + components: { + Menus, + Apis + }, methods: { + opdendrawer(row) { + this.drawer = true + this.activeRow = row + }, // 删除角色 deleteAuth(row) { this.$confirm('此操作将永久删除该角色, 是否继续?', '提示', { @@ -158,7 +128,6 @@ export default { closeDialog() { this.initForm() this.dialogFormVisible = false - this.menuDialogFlag = false this.apiDialogFlag = false }, // 确定弹窗 @@ -179,98 +148,23 @@ export default { // 增加角色 addAuthority() { this.dialogFormVisible = true - }, - - // 关联用户列表关系 - async addAuthMenu(row) { - const res1 = await getMenuAuthority({ authorityId: row.authorityId }) - const menus = res1.data.menus - const arr = [] - menus.map(item => { - // 防止直接选中父级造成全选 - if (!menus.some(same => same.parentId === item.menuId)) { - arr.push(Number(item.menuId)) - } - }) - this.menuTreeIds = arr - this.activeUserId = row.authorityId - this.menuDialogFlag = true - }, - // 关联树 确认方法 - async relation() { - const checkArr = this.$refs.menuTree.getCheckedNodes(false, true) - const res = await addMenuAuthority({ - menus: checkArr, - authorityId: this.activeUserId - }) - if (res.success) { - this.$message({ - type: 'success', - message: '添加成功!' - }) - } - this.closeDialog() - }, - // 创建api树方法 - buildApiTree(apis) { - const apiObj = new Object() - apis && - apis.map(item => { - if (apiObj.hasOwnProperty(item.group)) { - apiObj[item.group].push(item) - } else { - Object.assign(apiObj, { [item.group]: [item] }) - } - }) - const apiTree = [] - for (const key in apiObj) { - const treeNode = { - ID: key, - description: key + '组', - children: apiObj[key] - } - apiTree.push(treeNode) - } - return apiTree - }, - // 关联用户api关系 - async addAuthApi(row) { - const res = await getPolicyPathByAuthorityId({ - authorityId: row.authorityId - }) - this.activeUserId = row.authorityId - this.apiTreeIds = res.data.paths || [] - this.apiDialogFlag = true - }, - // 关联关系确定 - async authApiEnter() { - const checkArr = this.$refs.apiTree.getCheckedKeys(true) - const res = await casbinPUpdata({ - authorityId: this.activeUserId, - paths: checkArr - }) - if (res.success) { - this.$message({ type: 'success', message: res.msg }) - this.closeDialog() - } } - }, - async created() { - // 获取所有菜单树 - const res = await getBaseMenuTree() - this.menuTreeData = res.data.menus - // 获取api并整理成树结构 - const res2 = await getAllApis() - const apis = res2.data.apis - this.apiTreeData = this.buildApiTree(apis) } } - \ No newline at end of file diff --git a/QMPlusVuePage/src/view/superAdmin/authority/components/apis.vue b/QMPlusVuePage/src/view/superAdmin/authority/components/apis.vue new file mode 100644 index 00000000..9aa6a77c --- /dev/null +++ b/QMPlusVuePage/src/view/superAdmin/authority/components/apis.vue @@ -0,0 +1,99 @@ + + + \ No newline at end of file diff --git a/QMPlusVuePage/src/view/superAdmin/authority/components/menus.vue b/QMPlusVuePage/src/view/superAdmin/authority/components/menus.vue new file mode 100644 index 00000000..11927333 --- /dev/null +++ b/QMPlusVuePage/src/view/superAdmin/authority/components/menus.vue @@ -0,0 +1,76 @@ + + + \ No newline at end of file diff --git a/QMPlusVuePage/src/view/superAdmin/menu/menu.vue b/QMPlusVuePage/src/view/superAdmin/menu/menu.vue index 9cea43a5..fd03b045 100644 --- a/QMPlusVuePage/src/view/superAdmin/menu/menu.vue +++ b/QMPlusVuePage/src/view/superAdmin/menu/menu.vue @@ -43,7 +43,7 @@ layout="total, sizes, prev, pager, next, jumper" > - + @@ -116,6 +116,10 @@ export default { } }, methods: { + handleClose(done){ + this.initForm() + done() + }, // 懒加载子菜单 load(tree, treeNode, resolve) { resolve([ @@ -172,7 +176,6 @@ export default { }, // 关闭弹窗 closeDialog() { - this.initForm() this.dialogFormVisible = false }, // 添加menu @@ -189,15 +192,12 @@ export default { message: '添加成功!' }) this.getTableData() - this.closeDialog() } else { this.$message({ type: 'error', message: '添加失败!' }) - this.closeDialog() } - this.initForm() this.dialogFormVisible = false }, // 添加菜单方法,id为 0则为添加根菜单 diff --git a/QMPlusVuePage/src/view/superAdmin/user/user.vue b/QMPlusVuePage/src/view/superAdmin/user/user.vue index b09e1c86..227e6dd1 100644 --- a/QMPlusVuePage/src/view/superAdmin/user/user.vue +++ b/QMPlusVuePage/src/view/superAdmin/user/user.vue @@ -12,14 +12,20 @@ - + - - - @@ -40,6 +46,7 @@ -- GitLab