Browse Source

feat: 租户cookie改为store

pull/1154/head
colin 10 months ago
parent
commit
37391f840c
  1. 5
      apps/vben5/apps/app-antd/src/adapter/request/index.ts
  2. 8
      apps/vben5/packages/@abp/core/src/store/abp.ts
  3. 2
      apps/vben5/packages/@abp/saas/package.json
  4. 14
      apps/vben5/packages/@abp/saas/src/components/tenants/TenantSelectModal.vue

5
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;
},
});

8
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<string>();
const application = ref<ApplicationConfigurationDto>();
const localization = ref<ApplicationLocalizationDto>();
/** 获取 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,
};
},
{

2
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:"
},

14
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<Tenant>();
const cookies = useCookies();
const { findTenantByNameApi } = useMultiTenancyApi();
const [Form, formApi] = useVbenForm({
@ -55,10 +53,7 @@ async function onSubmit(values: Record<string, any>) {
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<string, any>) {
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();

Loading…
Cancel
Save