From 37391f840c884a04374f6476c0b9b8aaa7a5bbc5 Mon Sep 17 00:00:00 2001 From: colin Date: Sat, 29 Mar 2025 08:24:52 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=A7=9F=E6=88=B7cookie=E6=94=B9?= =?UTF-8?q?=E4=B8=BAstore?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../apps/app-antd/src/adapter/request/index.ts | 5 +++++ apps/vben5/packages/@abp/core/src/store/abp.ts | 8 ++++++++ apps/vben5/packages/@abp/saas/package.json | 2 -- .../src/components/tenants/TenantSelectModal.vue | 14 ++------------ 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/apps/vben5/apps/app-antd/src/adapter/request/index.ts b/apps/vben5/apps/app-antd/src/adapter/request/index.ts index 855047496..ddafbf93c 100644 --- a/apps/vben5/apps/app-antd/src/adapter/request/index.ts +++ b/apps/vben5/apps/app-antd/src/adapter/request/index.ts @@ -6,6 +6,7 @@ import { import { useAccessStore } from '@vben/stores'; import { useOAuthError, useTokenApi } from '@abp/account'; +import { useAbpStore } from '@abp/core'; import { requestClient, useWrapperResult } from '@abp/request'; import { message } from 'ant-design-vue'; @@ -58,12 +59,16 @@ export function initRequestClient() { // 请求头处理 requestClient.addRequestInterceptor({ fulfilled: async (config) => { + const abpStore = useAbpStore(); const accessStore = useAccessStore(); if (accessStore.accessToken) { config.headers.Authorization = `${accessStore.accessToken}`; } config.headers['Accept-Language'] = preferences.app.locale; config.headers['X-Request-From'] = 'vben'; + if (abpStore.tenantId) { + config.headers.__tenant = abpStore.tenantId; + } return config; }, }); diff --git a/apps/vben5/packages/@abp/core/src/store/abp.ts b/apps/vben5/packages/@abp/core/src/store/abp.ts index f17801928..c3d9e4f44 100644 --- a/apps/vben5/packages/@abp/core/src/store/abp.ts +++ b/apps/vben5/packages/@abp/core/src/store/abp.ts @@ -10,6 +10,7 @@ import { acceptHMRUpdate, defineStore } from 'pinia'; export const useAbpStore = defineStore( 'abp', () => { + const tenantId = ref(); const application = ref(); const localization = ref(); /** 获取 i18n 格式本地化文本 */ @@ -44,6 +45,11 @@ export const useAbpStore = defineStore( }); return abpLocales; } + + function setTenantId(val?: string) { + tenantId.value = val; + } + function setApplication(val: ApplicationConfigurationDto) { application.value = val; } @@ -63,6 +69,8 @@ export const useAbpStore = defineStore( localization, setApplication, setLocalization, + setTenantId, + tenantId, }; }, { diff --git a/apps/vben5/packages/@abp/saas/package.json b/apps/vben5/packages/@abp/saas/package.json index f536c9515..d8fe93258 100644 --- a/apps/vben5/packages/@abp/saas/package.json +++ b/apps/vben5/packages/@abp/saas/package.json @@ -31,11 +31,9 @@ "@vben/hooks": "workspace:*", "@vben/icons": "workspace:*", "@vben/locales": "workspace:*", - "@vueuse/integrations": "catalog:", "ant-design-vue": "catalog:", "dayjs": "catalog:", "lodash.debounce": "catalog:", - "universal-cookie": "catalog:", "vue": "catalog:*", "vxe-table": "catalog:" }, diff --git a/apps/vben5/packages/@abp/saas/src/components/tenants/TenantSelectModal.vue b/apps/vben5/packages/@abp/saas/src/components/tenants/TenantSelectModal.vue index 6ad05d021..d917fb1c8 100644 --- a/apps/vben5/packages/@abp/saas/src/components/tenants/TenantSelectModal.vue +++ b/apps/vben5/packages/@abp/saas/src/components/tenants/TenantSelectModal.vue @@ -4,7 +4,6 @@ import { ref } from 'vue'; import { useVbenForm, useVbenModal } from '@vben/common-ui'; import { $t } from '@vben/locales'; -import { useCookies } from '@vueuse/integrations/useCookies'; import { message } from 'ant-design-vue'; import { useMultiTenancyApi } from '../../api/useMultiTenancyApi'; @@ -19,7 +18,6 @@ const emits = defineEmits<{ }>(); const tenant = ref(); -const cookies = useCookies(); const { findTenantByNameApi } = useMultiTenancyApi(); const [Form, formApi] = useVbenForm({ @@ -55,10 +53,7 @@ async function onSubmit(values: Record) { modalApi.setState({ submitting: true }); try { tenant.value = undefined; - cookies.remove('__tenant', { - path: '/', - }); - // localStorage.removeItem('__tenant'); + localStorage.removeItem('__tenant'); if (values.name) { const result = await findTenantByNameApi(values.name); if (!result.success) { @@ -74,12 +69,7 @@ async function onSubmit(values: Record) { return; } tenant.value = { id: result.tenantId, name: result.normalizedName }; - if (result.tenantId) { - // localStorage.setItem('__tenant', result.tenantId); - cookies.set('__tenant', result.tenantId, { - path: '/', - }); - } + localStorage.setItem('__tenant', result.tenantId!); } emits('change', tenant.value); modalApi.close();