From ab8436dff7aebe71efe39ddd1a38d2d2e2fc6846 Mon Sep 17 00:00:00 2001 From: thinkgem Date: Thu, 7 Nov 2024 08:59:22 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=20=E7=AA=97=E5=8F=A3?= =?UTF-8?q?=E5=8F=B3=E4=B8=8A=E8=A7=92=E7=9A=84=E5=A4=B4=E5=83=8F=E4=B8=8B?= =?UTF-8?q?=E6=8B=89=E8=8F=9C=E5=8D=95=EF=BC=8C=E5=88=87=E6=8D=A2=E5=BD=93?= =?UTF-8?q?=E5=89=8D=E7=94=A8=E6=88=B7=E6=89=80=E5=B1=9E=E5=B2=97=E4=BD=8D?= =?UTF-8?q?=EF=BC=8C=E5=B9=B6=E8=81=94=E5=8A=A8=E5=88=87=E6=8D=A2=E5=BD=93?= =?UTF-8?q?=E5=89=8D=E8=8F=9C=E5=8D=95=E6=9D=83=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/sys/login.ts | 12 ++- .../header/components/user-dropdown/index.vue | 90 +++++++++++++------ src/store/modules/user.ts | 2 + src/views/sys/empUser/list.vue | 2 +- types/store.d.ts | 1 + 5 files changed, 79 insertions(+), 28 deletions(-) diff --git a/src/api/sys/login.ts b/src/api/sys/login.ts index 3cd152374e..65a18af85a 100644 --- a/src/api/sys/login.ts +++ b/src/api/sys/login.ts @@ -35,6 +35,7 @@ export interface LoginResult { msgEnabled: boolean; sysCode: string; roleCode: string; + postCode: string; title: string; company: string; version: string; @@ -60,11 +61,18 @@ export const loginApi = (params: LoginParams, mode: ErrorMessageMode = 'none') = }; export const switchSys = (sysCode: string) => { - return defHttp.get({ url: adminPath + '/switch/' + sysCode }); + const params = sysCode ? '/' + sysCode : sysCode; + return defHttp.get({ url: adminPath + '/switch' + params }); }; export const switchRole = (roleCode: string) => { - return defHttp.get({ url: adminPath + '/switchRole/' + roleCode }); + const params = roleCode ? '/' + roleCode : roleCode; + return defHttp.get({ url: adminPath + '/switchRole' + params }); +}; + +export const switchPost = (postCode: string) => { + const params = postCode ? '/' + postCode : postCode; + return defHttp.get({ url: adminPath + '/switchPost' + params }); }; export const switchSkin = (name = '') => { diff --git a/src/layouts/default/header/components/user-dropdown/index.vue b/src/layouts/default/header/components/user-dropdown/index.vue index 086fe3f4e2..2c6dace801 100644 --- a/src/layouts/default/header/components/user-dropdown/index.vue +++ b/src/layouts/default/header/components/user-dropdown/index.vue @@ -64,29 +64,52 @@ :text="item.name" :icon="sysCodeRef == item.value ? 'i-ant-design:check-outlined' : 'i-radix-icons:dot'" /> - - - - - + + @@ -105,7 +128,7 @@ import { propTypes } from '/@/utils/propTypes'; import { openWindow } from '/@/utils'; import { useDict } from '/@/components/Dict'; - import { switchSys, switchRole } from '/@/api/sys/login'; + import { switchSys, switchRole, switchPost } from '/@/api/sys/login'; import { PageEnum } from '/@/enums/pageEnum'; import { Icon } from '/@/components/Icon'; import MenuItem from './DropMenuItem.vue'; @@ -139,14 +162,22 @@ const sysCodeRef = ref('default'); const sysListRef = ref([]); const roleCodeRef = ref(''); + const postCodeRef = ref(''); const getUserInfo = computed(() => { - const { userName = '', avatarUrl, remarks, roleList } = userStore.getUserInfo || {}; + const { + userName = '', + avatarUrl, + remarks, + roleList, + postList, + } = userStore.getUserInfo || {}; return { userName, avatarUrl, remarks, roleList: (roleList || []).filter((e) => e.isShow == '1'), + postList: postList || [], }; }); @@ -154,6 +185,7 @@ onMounted(async () => { sysCodeRef.value = userStore.getPageCacheByKey('sysCode', 'default'); roleCodeRef.value = userStore.getPageCacheByKey('roleCode', ''); + postCodeRef.value = userStore.getPageCacheByKey('postCode', ''); const sysList = await useDict().initGetDictList('sys_menu_sys_code'); if (sysList.length > 1) { var sysCodes: string[] = []; @@ -224,6 +256,13 @@ await switchRole(roleCode); location.reload(); } + const postCodePrefix = 'postCode-'; + if (String(e.key).startsWith(postCodePrefix)) { + go(userStore.getUserInfo.homePath || PageEnum.BASE_HOME); + const postCode = String(e.key).substring(postCodePrefix.length); + await switchPost(postCode); + location.reload(); + } break; } } @@ -240,6 +279,7 @@ sysCodeRef, sysListRef, roleCodeRef, + postCodeRef, props, }; }, diff --git a/src/store/modules/user.ts b/src/store/modules/user.ts index fa29f332c0..53cc00c715 100644 --- a/src/store/modules/user.ts +++ b/src/store/modules/user.ts @@ -96,6 +96,7 @@ export const useUserStore = defineStore({ info.avatarUrl = url || logoImg; info.homePath = res.desktopUrl; info.roleList = res.roleList; + info.postList = res.postList; } this.userInfo = info; this.lastUpdateTime = new Date().getTime(); @@ -190,6 +191,7 @@ export const useUserStore = defineStore({ this.setPageCache('modifyPasswordMsg', res.modifyPasswordMsg); this.setPageCache('sysCode', res.sysCode); this.setPageCache('roleCode', res.roleCode); + this.setPageCache('postCode', res.postCode); this.setPageCache('title', res.title); this.setPageCache('company', res.company); this.setPageCache('version', res.version); diff --git a/src/views/sys/empUser/list.vue b/src/views/sys/empUser/list.vue index d734a03bb6..608a489bd9 100644 --- a/src/views/sys/empUser/list.vue +++ b/src/views/sys/empUser/list.vue @@ -12,10 +12,10 @@ {{ t('删除') }} ({{ selectedRowKeysRef.length diff --git a/types/store.d.ts b/types/store.d.ts index 30a9ecacf6..0f17d3cedc 100644 --- a/types/store.d.ts +++ b/types/store.d.ts @@ -42,6 +42,7 @@ export interface UserInfo { avatarUrl: string; remarks?: string; roleList?: any[]; + postList?: any[]; homePath?: string; // roles: RoleInfo[]; }