// axios.ts 文件
'use strict';
import {
MError, createAxios, removeAbortSignals, clearLocalStorage,
clearSessionStorage,
} from 'metro-os-tools';
export default function (
baseURL: string,
abort: boolean = false,
obj?: any,
) {
const { signals, _axios } = createAxios(baseURL, abort, obj);
_axios.interceptors.response.use(
function (response) {
if (response && response.config) {
abort && removeAbortSignals(response.config, signals);
}
if (response.data?.result?.resultCode === '0') {
return Promise.resolve(response.data);
} else if (response.data?.result?.resultCode === '3') {
MError({
message:
response.data.result.resultError || 'Token失效,请重新登录!',
});
clearSessionStorage('windowStoreTask');
clearLocalStorage('token');
return Promise.reject(response.data);
} else if (response.status === 200) {
return Promise.resolve(response.data);
}
return Promise.reject(response.data);
},
function (error) {
if (error) {
return Promise.reject('request canceled!');
}
const status = error.response?.status;
if (status) {
return Promise.reject(error);
} else {
return Promise.reject({
result: { resultCode: '-1', resultError: '请求异常' },
});
}
},
);
return { signals, _axios };
};
// api.ts 文件 =========================
import { IResponse } from '@/types/lineType';
import createAxios from '@/utils/axios';
const { _axios } = createAxios('/mos/mos-bizcenter-server/');
// 查看所有文件目录
export const getFolderListApi = async () => {
return await _axios.get('/folder/list');
};
// 新建文件目录
export const createFolderApi = async (data: createFolderParams) => {
return await _axios.post('/folder/create', data);
};
// 删除文件夹
export const removeFolderApi = async (folderId: string) => {
return await _axios.delete(`/folder/${folderId}`);
};
// 获取PA数据
export function vehiclePadataQuery() {
return _axios({
method: 'POST',
url: Url.vehiclePadataQuery,
data: {}
})
}
import {
setLocalStorage,
getLocalStorage,
clearLocalStorage,
setSessionStorage,
getSessionStorage,
clearSessionStorage,
} from 'metro-os-tools';