|
|
@@ -16,7 +16,7 @@ import { setObjToUrlParams } from '@/utils/urlUtils';
|
|
|
|
|
|
import { RequestOptions, Result, CreateAxiosOptions } from './types';
|
|
|
|
|
|
-import { useUserStoreWidthOut } from '@/store/modules/user';
|
|
|
+import { useUserStore, useUserStoreWidthOut } from '@/store/modules/user';
|
|
|
import urlJoin from 'url-join';
|
|
|
|
|
|
const globSetting = useGlobSetting();
|
|
|
@@ -25,6 +25,7 @@ const urlPrefix = globSetting.urlPrefix || '';
|
|
|
import router from '@/router';
|
|
|
import { storage } from '@/utils/Storage';
|
|
|
import { getRedirectUrl } from '@/utils/getRedirectUrl';
|
|
|
+import { useTargetTenantIdSetting } from '@/utils/useTargetTenantIdSetting';
|
|
|
|
|
|
/**
|
|
|
* @description: 数据处理,方便区分多种处理方式
|
|
|
@@ -205,9 +206,10 @@ const transform: AxiosTransform = {
|
|
|
requestInterceptors: (config, options) => {
|
|
|
// 请求之前处理config
|
|
|
const userStore = useUserStoreWidthOut();
|
|
|
+ const { getValue } = useTargetTenantIdSetting();
|
|
|
const token = userStore.getToken;
|
|
|
const tenantId = userStore.getTenantId;
|
|
|
- const targetTenantId = localStorage.getItem('targetTenantId');
|
|
|
+ const targetTenantId = getValue();
|
|
|
if (token && (config as Recordable)?.requestOptions?.withToken !== false) {
|
|
|
// jwt token
|
|
|
(config as Recordable).headers.satoken = options.authenticationScheme
|
|
|
@@ -321,3 +323,21 @@ export const http = createAxios();
|
|
|
// urlPrefix: 'api',
|
|
|
// },
|
|
|
// });
|
|
|
+
|
|
|
+/** 生成所需要的headers */
|
|
|
+export const getHeaders = () => {
|
|
|
+ const userStore = useUserStore();
|
|
|
+ const { getValue } = useTargetTenantIdSetting();
|
|
|
+ const localTId = getValue();
|
|
|
+ const baseHeaders = {
|
|
|
+ Satoken: userStore.getToken,
|
|
|
+ Tenantid: userStore.getTenantId,
|
|
|
+ };
|
|
|
+ if (localTId) {
|
|
|
+ return {
|
|
|
+ ...baseHeaders,
|
|
|
+ targetTenantId: localTId,
|
|
|
+ };
|
|
|
+ }
|
|
|
+ return baseHeaders;
|
|
|
+};
|