From 9b87a035222ba5c6a26cebc8841e0325952be70a Mon Sep 17 00:00:00 2001 From: zhangdaiscott Date: Sun, 5 Nov 2023 10:34:32 +0800 Subject: [PATCH] =?UTF-8?q?=E6=88=91=E7=9A=84=E7=A7=9F=E6=88=B7=E8=8F=9C?= =?UTF-8?q?=E5=8D=95=E5=8A=A0=E6=8F=90=E9=86=92=EF=BC=9A=E9=9C=80=E8=A6=81?= =?UTF-8?q?=E5=9C=A8=E5=A4=9A=E7=A7=9F=E6=88=B7=E6=A8=A1=E5=BC=8F=E4=B8=8B?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=EF=BC=8C=E5=90=A6=E5=88=99=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E4=BC=9A=E5=87=BA=E7=8E=B0=E6=B7=B7=E4=B9=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/common/compUtils.ts | 52 +++++++++++++++++++ src/views/system/role/TenantRoleList.vue | 8 ++- src/views/system/tenant/TenantUserList.vue | 11 +++- src/views/system/tenant/my/MyTenantList.vue | 8 ++- .../system/usersetting/TenantSetting.vue | 50 ++---------------- 5 files changed, 80 insertions(+), 49 deletions(-) diff --git a/src/utils/common/compUtils.ts b/src/utils/common/compUtils.ts index 140fc04..1d41585 100644 --- a/src/utils/common/compUtils.ts +++ b/src/utils/common/compUtils.ts @@ -6,6 +6,9 @@ import { reactive } from "vue"; import { getTenantId, getToken } from "/@/utils/auth"; import { useUserStoreWithOut } from "/@/store/modules/user"; +import { Modal } from "ant-design-vue"; +import { defHttp } from "@/utils/http/axios"; + const globSetting = useGlobSetting(); const baseApiUrl = globSetting.domainUrl; /** @@ -459,3 +462,52 @@ export function replaceUserInfoByExpression(expression: string | any[]) { // @ts-ignore return isString ? replace(expression) : expression.map(replace); } + +/** + * 设置租户缓存,当租户退出的时候 + * + * @param tenantId + */ +export async function userExitChangeLoginTenantId(tenantId){ + const userStore = useUserStoreWithOut(); + //step 1 获取用户租户 + const url = '/sys/tenant/getCurrentUserTenant' + let currentTenantId = null; + const data = await defHttp.get({ url }); + if(data && data.list){ + let arr = data.list; + if(arr.length>0){ + //step 2.判断当前id是否存在用户租户中 + let filterTenantId = arr.filter((item) => item.id == tenantId); + //存在说明不是退出的不是当前租户,还用用来的租户即可 + if(filterTenantId && filterTenantId.length>0){ + currentTenantId = tenantId; + }else{ + //不存在默认第一个 + currentTenantId = arr[0].id + } + } + } + userStore.setTenant(currentTenantId); + //切换租户后要刷新首页 + window.location.reload(); +} + +/** + * 我的租户模块需要开启多租户提示 + * + * @param title 标题 + */ +export function tenantSaasMessage(title){ + let tenantId = getTenantId(); + if(!tenantId){ + Modal.confirm({ + title:title, + content: '此菜单需要在多租户模式下使用,否则数据会出现混乱', + okText: '确认', + okType: 'danger', + // @ts-ignore + cancelButtonProps: { style: { display: 'none' } }, + }) + } +} \ No newline at end of file diff --git a/src/views/system/role/TenantRoleList.vue b/src/views/system/role/TenantRoleList.vue index 42d2368..7d4451b 100644 --- a/src/views/system/role/TenantRoleList.vue +++ b/src/views/system/role/TenantRoleList.vue @@ -30,7 +30,7 @@