|
@@ -1,9 +1,11 @@
|
|
|
import dayjs from 'dayjs';
|
|
|
import { kebabCase } from 'lodash-es';
|
|
|
|
|
|
+import { useUserInfoStore } from '@/stores/user-info';
|
|
|
import { t } from '@/i18n';
|
|
|
import { fileContentTypeRegExp, TimeScaleType } from '@/constants';
|
|
|
|
|
|
+import { removeToken } from './auth';
|
|
|
import { fetchWithTimeout } from './fetch';
|
|
|
|
|
|
import type { SorterResult } from 'ant-design-vue/es/table/interface';
|
|
@@ -17,17 +19,12 @@ export const request = async <T>(url: string, init: RequestInit = {}, timeout?:
|
|
|
if (typeof init?.body === 'string') {
|
|
|
headers['Content-Type'] = 'application/json;charset=UTF-8';
|
|
|
}
|
|
|
-
|
|
|
- // const { token, saveToken, resetToken } = useUserInfoStore();
|
|
|
- // const { resetDevInfo } = useDeviceInfoStore();
|
|
|
-
|
|
|
- // if (token) {
|
|
|
- // Object.assign(headers, {
|
|
|
- // [TOKEN_KEY]: token,
|
|
|
- // });
|
|
|
- // }
|
|
|
-
|
|
|
- headers['Authorization'] = 'Bearer ' + import.meta.env.VITE_TEMP_TOKEN;
|
|
|
+ const { token, resetToken } = useUserInfoStore();
|
|
|
+ if (token) {
|
|
|
+ Object.assign(headers, {
|
|
|
+ Authorization: 'Bearer ' + token,
|
|
|
+ });
|
|
|
+ }
|
|
|
|
|
|
Object.assign(headers, init?.headers);
|
|
|
|
|
@@ -41,11 +38,9 @@ export const request = async <T>(url: string, init: RequestInit = {}, timeout?:
|
|
|
);
|
|
|
|
|
|
if (res.status === 401) {
|
|
|
- // removeToken();
|
|
|
- // resetToken();
|
|
|
- // resetDevInfo();
|
|
|
- // location.replace('/login');
|
|
|
-
|
|
|
+ removeToken();
|
|
|
+ resetToken();
|
|
|
+ location.replace('/login');
|
|
|
throw new Error(t('common.reLogin'));
|
|
|
}
|
|
|
|
|
@@ -55,14 +50,6 @@ export const request = async <T>(url: string, init: RequestInit = {}, timeout?:
|
|
|
throw new Error(`HTTP Error: ${res.status} ${errMsg}`);
|
|
|
}
|
|
|
|
|
|
- // if (res.url.includes('/Uboxlogin')) {
|
|
|
- // const token = res.headers.get(TOKEN_KEY);
|
|
|
-
|
|
|
- // if (token) {
|
|
|
- // setToken(token);
|
|
|
- // saveToken(token);
|
|
|
- // }
|
|
|
- // }
|
|
|
const contentType = res.headers.get('content-type');
|
|
|
const isBlob = fileContentTypeRegExp.test(contentType || '');
|
|
|
|