From 7801a90dcb2029c5abb23e3fa94c3cee775d397a Mon Sep 17 00:00:00 2001 From: Li Kui <90845831+likui628@users.noreply.github.com> Date: Sat, 13 Jul 2024 11:26:36 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20unify=20frontend=20and=20backend=20?= =?UTF-8?q?access=20control=20with=20shared=20page=20=E2=80=A6=20(#43)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * refactor: unify frontend and backend access control with shared page components * fix: role switch not show * chore: update title --- .../src/modules/menu/menu.controller.ts | 63 +++----- apps/web-antd/src/locales/langs/en-US.json | 1 - apps/web-antd/src/locales/langs/zh-CN.json | 1 - .../src/router/routes/modules/demos.ts | 146 +++++++---------- .../access/{backend => }/admin-visible.vue | 0 .../access/{backend => }/button-control.vue | 0 .../demos/access/frontend/admin-visible.vue | 13 -- .../demos/access/frontend/button-control.vue | 149 ------------------ .../src/views/demos/access/frontend/index.vue | 84 ---------- .../demos/access/frontend/super-visible.vue | 13 -- .../demos/access/frontend/user-visible.vue | 13 -- .../demos/access/{backend => }/index.vue | 56 +++---- .../{frontend => }/menu-visible-403.vue | 0 .../access/{backend => }/super-visible.vue | 0 .../access/{backend => }/user-visible.vue | 0 15 files changed, 108 insertions(+), 431 deletions(-) rename apps/web-antd/src/views/demos/access/{backend => }/admin-visible.vue (100%) rename apps/web-antd/src/views/demos/access/{backend => }/button-control.vue (100%) delete mode 100644 apps/web-antd/src/views/demos/access/frontend/admin-visible.vue delete mode 100644 apps/web-antd/src/views/demos/access/frontend/button-control.vue delete mode 100644 apps/web-antd/src/views/demos/access/frontend/index.vue delete mode 100644 apps/web-antd/src/views/demos/access/frontend/super-visible.vue delete mode 100644 apps/web-antd/src/views/demos/access/frontend/user-visible.vue rename apps/web-antd/src/views/demos/access/{backend => }/index.vue (64%) rename apps/web-antd/src/views/demos/access/{frontend => }/menu-visible-403.vue (100%) rename apps/web-antd/src/views/demos/access/{backend => }/super-visible.vue (100%) rename apps/web-antd/src/views/demos/access/{backend => }/user-visible.vue (100%) diff --git a/apps/backend-mock/src/modules/menu/menu.controller.ts b/apps/backend-mock/src/modules/menu/menu.controller.ts index 92c137dc..ddf9755d 100644 --- a/apps/backend-mock/src/modules/menu/menu.controller.ts +++ b/apps/backend-mock/src/modules/menu/menu.controller.ts @@ -50,30 +50,30 @@ export class MenuController { const createDemosMenus = (role: 'admin' | 'super' | 'user') => { const roleWithMenus = { admin: { - component: '/demos/access/backend/admin-visible', + component: '/demos/access/admin-visible', meta: { icon: 'mdi:button-cursor', title: 'page.demos.access.adminVisible', }, - name: 'AccessBackendAdminVisible', + name: 'AccessAdminVisible', path: 'admin-visible', }, super: { - component: '/demos/access/backend/super-visible', + component: '/demos/access/super-visible', meta: { icon: 'mdi:button-cursor', title: 'page.demos.access.superVisible', }, - name: 'AccessBackendSuperVisible', + name: 'AccessSuperVisible', path: 'super-visible', }, user: { - component: '/demos/access/backend/user-visible', + component: '/demos/access/user-visible', meta: { icon: 'mdi:button-cursor', title: 'page.demos.access.userVisible', }, - name: 'AccessBackendUserVisible', + name: 'AccessUserVisible', path: 'user-visible', }, }; @@ -92,44 +92,33 @@ export class MenuController { redirect: '/demos/access', children: [ { - meta: { - icon: 'mdi:shield-key-outline', - title: 'page.demos.access.title', - }, name: 'Access', path: 'access', - redirect: '/demos/access/backend', + meta: { + icon: 'mdi:cloud-key-outline', + title: 'page.demos.access.backendControl', + }, + redirect: '/demos/access/page-control', children: [ { - name: 'AccessBackend', - path: 'backend', + name: 'AccessPageControl', + path: 'page-control', + component: '/demos/access/index', meta: { - icon: 'mdi:cloud-key-outline', - title: 'page.demos.access.backendControl', + icon: 'mdi:page-previous-outline', + title: 'page.demos.access.pageAccess', }, - redirect: '/demos/access/backend/page-control', - children: [ - { - name: 'AccessBackendPageControl', - path: 'page-control', - component: '/demos/access/backend/index', - meta: { - icon: 'mdi:page-previous-outline', - title: 'page.demos.access.pageAccess', - }, - }, - { - name: 'AccessBackendButtonControl', - path: 'button-control', - component: '/demos/access/backend/button-control', - meta: { - icon: 'mdi:button-cursor', - title: 'page.demos.access.buttonControl', - }, - }, - roleWithMenus[role], - ], }, + { + name: 'AccessButtonControl', + path: 'button-control', + component: '/demos/access/button-control', + meta: { + icon: 'mdi:button-cursor', + title: 'page.demos.access.buttonControl', + }, + }, + roleWithMenus[role], ], }, ], diff --git a/apps/web-antd/src/locales/langs/en-US.json b/apps/web-antd/src/locales/langs/en-US.json index b12f278a..4b2a5fe5 100644 --- a/apps/web-antd/src/locales/langs/en-US.json +++ b/apps/web-antd/src/locales/langs/en-US.json @@ -3,7 +3,6 @@ "demos": { "title": "Demos", "access": { - "title": "Access Control", "frontendControl": "Frontend Control", "backendControl": "Backend Control", "pageAccess": "Page Access", diff --git a/apps/web-antd/src/locales/langs/zh-CN.json b/apps/web-antd/src/locales/langs/zh-CN.json index e877d506..d99d1e36 100644 --- a/apps/web-antd/src/locales/langs/zh-CN.json +++ b/apps/web-antd/src/locales/langs/zh-CN.json @@ -3,7 +3,6 @@ "demos": { "title": "演示", "access": { - "title": "访问控制", "frontendControl": "前端控制", "backendControl": "后端控制", "pageAccess": "页面访问", diff --git a/apps/web-antd/src/router/routes/modules/demos.ts b/apps/web-antd/src/router/routes/modules/demos.ts index 80e8199f..4d8c0e81 100644 --- a/apps/web-antd/src/router/routes/modules/demos.ts +++ b/apps/web-antd/src/router/routes/modules/demos.ts @@ -19,109 +19,71 @@ const routes: RouteRecordRaw[] = [ { meta: { icon: 'mdi:shield-key-outline', - title: $t('page.demos.access.title'), + title: $t('page.demos.access.frontendControl'), }, name: 'Access', path: 'access', - redirect: '/demos/access/frontend', + redirect: '/demos/access', children: [ { - name: 'AccessFrontend', - path: 'frontend', - redirect: '/demos/access/frontend/page-control', + name: 'AccessPageControl', + path: 'page-control', + component: () => import('#/views/demos/access/index.vue'), meta: { - icon: 'mdi:table-key', - title: $t('page.demos.access.frontendControl'), + icon: 'mdi:page-previous-outline', + title: $t('page.demos.access.pageAccess'), }, - children: [ - { - name: 'AccessFrontendPageControl', - path: 'page-control', - component: () => - import('#/views/demos/access/frontend/index.vue'), - meta: { - icon: 'mdi:page-previous-outline', - title: $t('page.demos.access.pageAccess'), - }, - }, - { - name: 'AccessFrontendButtonControl', - path: 'button-control', - component: () => - import('#/views/demos/access/frontend/button-control.vue'), - meta: { - icon: 'mdi:button-cursor', - title: $t('page.demos.access.buttonControl'), - }, - }, - { - name: 'AccessFrontendMenuVisible403', - path: 'menu-visible-403', - component: () => - import('#/views/demos/access/frontend/menu-visible-403.vue'), - meta: { - authority: ['no-body'], - icon: 'mdi:button-cursor', - menuVisibleWithForbidden: true, - title: $t('page.demos.access.menuVisible403'), - }, - }, - - { - name: 'AccessFrontendSuperVisible', - path: 'super-visible', - component: () => - import('#/views/demos/access/frontend/super-visible.vue'), - meta: { - authority: ['super'], - icon: 'mdi:button-cursor', - title: $t('page.demos.access.superVisible'), - }, - }, - { - name: 'AccessFrontendAdminVisible', - path: 'admin-visible', - component: () => - import('#/views/demos/access/frontend/admin-visible.vue'), - meta: { - authority: ['admin'], - icon: 'mdi:button-cursor', - title: $t('page.demos.access.adminVisible'), - }, - }, - { - name: 'AccessFrontendUserVisible', - path: 'user-visible', - component: () => - import('#/views/demos/access/frontend/user-visible.vue'), - meta: { - authority: ['user'], - icon: 'mdi:button-cursor', - title: $t('page.demos.access.userVisible'), - }, - }, - ], }, { - name: 'AccessBackend', - path: 'backend', - component: () => import('#/views/demos/access/backend/index.vue'), + name: 'AccessButtonControl', + path: 'button-control', + component: () => import('#/views/demos/access/button-control.vue'), meta: { - icon: 'mdi:cloud-key-outline', - title: $t('page.demos.access.backendControl'), + icon: 'mdi:button-cursor', + title: $t('page.demos.access.buttonControl'), + }, + }, + { + name: 'AccessMenuVisible403', + path: 'menu-visible-403', + component: () => + import('#/views/demos/access/menu-visible-403.vue'), + meta: { + authority: ['no-body'], + icon: 'mdi:button-cursor', + menuVisibleWithForbidden: true, + title: $t('page.demos.access.menuVisible403'), + }, + }, + { + name: 'AccessSuperVisible', + path: 'super-visible', + component: () => import('#/views/demos/access/super-visible.vue'), + meta: { + authority: ['super'], + icon: 'mdi:button-cursor', + title: $t('page.demos.access.superVisible'), + }, + }, + { + name: 'AccessAdminVisible', + path: 'admin-visible', + component: () => import('#/views/demos/access/admin-visible.vue'), + meta: { + authority: ['admin'], + icon: 'mdi:button-cursor', + title: $t('page.demos.access.adminVisible'), + }, + }, + { + name: 'AccessUserVisible', + path: 'user-visible', + component: () => import('#/views/demos/access/user-visible.vue'), + meta: { + authority: ['user'], + icon: 'mdi:button-cursor', + title: $t('page.demos.access.userVisible'), }, - children: [ - { - name: 'AccessBackendPageControl', - path: 'page-control', - component: () => - import('#/views/demos/access/frontend/index.vue'), - meta: { - icon: 'mdi:page-previous-outline', - title: $t('page.demos.access.pageAccess'), - }, - }, - ], }, ], }, diff --git a/apps/web-antd/src/views/demos/access/backend/admin-visible.vue b/apps/web-antd/src/views/demos/access/admin-visible.vue similarity index 100% rename from apps/web-antd/src/views/demos/access/backend/admin-visible.vue rename to apps/web-antd/src/views/demos/access/admin-visible.vue diff --git a/apps/web-antd/src/views/demos/access/backend/button-control.vue b/apps/web-antd/src/views/demos/access/button-control.vue similarity index 100% rename from apps/web-antd/src/views/demos/access/backend/button-control.vue rename to apps/web-antd/src/views/demos/access/button-control.vue diff --git a/apps/web-antd/src/views/demos/access/frontend/admin-visible.vue b/apps/web-antd/src/views/demos/access/frontend/admin-visible.vue deleted file mode 100644 index e70d78f1..00000000 --- a/apps/web-antd/src/views/demos/access/frontend/admin-visible.vue +++ /dev/null @@ -1,13 +0,0 @@ - - - diff --git a/apps/web-antd/src/views/demos/access/frontend/button-control.vue b/apps/web-antd/src/views/demos/access/frontend/button-control.vue deleted file mode 100644 index 4d3d9605..00000000 --- a/apps/web-antd/src/views/demos/access/frontend/button-control.vue +++ /dev/null @@ -1,149 +0,0 @@ - - - diff --git a/apps/web-antd/src/views/demos/access/frontend/index.vue b/apps/web-antd/src/views/demos/access/frontend/index.vue deleted file mode 100644 index 7d90133e..00000000 --- a/apps/web-antd/src/views/demos/access/frontend/index.vue +++ /dev/null @@ -1,84 +0,0 @@ - - - diff --git a/apps/web-antd/src/views/demos/access/frontend/super-visible.vue b/apps/web-antd/src/views/demos/access/frontend/super-visible.vue deleted file mode 100644 index edcfe5e3..00000000 --- a/apps/web-antd/src/views/demos/access/frontend/super-visible.vue +++ /dev/null @@ -1,13 +0,0 @@ - - - diff --git a/apps/web-antd/src/views/demos/access/frontend/user-visible.vue b/apps/web-antd/src/views/demos/access/frontend/user-visible.vue deleted file mode 100644 index 628d86d4..00000000 --- a/apps/web-antd/src/views/demos/access/frontend/user-visible.vue +++ /dev/null @@ -1,13 +0,0 @@ - - - diff --git a/apps/web-antd/src/views/demos/access/backend/index.vue b/apps/web-antd/src/views/demos/access/index.vue similarity index 64% rename from apps/web-antd/src/views/demos/access/backend/index.vue rename to apps/web-antd/src/views/demos/access/index.vue index ac5e9aa6..c78dcbbd 100644 --- a/apps/web-antd/src/views/demos/access/backend/index.vue +++ b/apps/web-antd/src/views/demos/access/index.vue @@ -9,7 +9,7 @@ import { Button } from 'ant-design-vue'; import { useAccessStore, useAppStore } from '#/store'; -defineOptions({ name: 'AccessBackend' }); +defineOptions({ name: 'Access' }); const accounts: Record = { admin: { @@ -41,7 +41,7 @@ async function changeAccount(role: string) { } const account = accounts[role]; - await appStore.resetAppState(); + appStore.resetAppState(); await accessStore.authLogin(account, async () => { router.go(0); }); @@ -49,7 +49,7 @@ async function changeAccount(role: string) { async function handleToggleAccessMode() { await toggleAccessMode(); - await appStore.resetAppState(); + appStore.resetAppState(); await accessStore.authLogin(accounts.super, async () => { router.go(0); }); @@ -59,7 +59,9 @@ async function handleToggleAccessMode() { diff --git a/apps/web-antd/src/views/demos/access/frontend/menu-visible-403.vue b/apps/web-antd/src/views/demos/access/menu-visible-403.vue similarity index 100% rename from apps/web-antd/src/views/demos/access/frontend/menu-visible-403.vue rename to apps/web-antd/src/views/demos/access/menu-visible-403.vue diff --git a/apps/web-antd/src/views/demos/access/backend/super-visible.vue b/apps/web-antd/src/views/demos/access/super-visible.vue similarity index 100% rename from apps/web-antd/src/views/demos/access/backend/super-visible.vue rename to apps/web-antd/src/views/demos/access/super-visible.vue diff --git a/apps/web-antd/src/views/demos/access/backend/user-visible.vue b/apps/web-antd/src/views/demos/access/user-visible.vue similarity index 100% rename from apps/web-antd/src/views/demos/access/backend/user-visible.vue rename to apps/web-antd/src/views/demos/access/user-visible.vue