|
@@ -1,3 +1,5 @@
|
|
|
+import { params as envParams } from "@/env";
|
|
|
+import { paramsToStr, strToParams } from "@/utils/params";
|
|
|
import { AxiosInstance } from "axios";
|
|
|
import Axios from 'axios'
|
|
|
|
|
@@ -17,12 +19,19 @@ export const setOfflineAxios = (axios: AxiosInstance) => {
|
|
|
// 添加请求拦截器
|
|
|
axios.interceptors.request.use(
|
|
|
async function (config) {
|
|
|
- if (config.url! in data) {
|
|
|
+ const params = {...config.params}
|
|
|
+ let item = data[config.url!+ paramsToStr(params)]
|
|
|
+ if (!item) {
|
|
|
+ delete params.caseId
|
|
|
+ item = data[config.url!+ paramsToStr(params)]
|
|
|
+ }
|
|
|
+
|
|
|
+ if (item) {
|
|
|
throw {
|
|
|
isFakeResponse: true,
|
|
|
config,
|
|
|
response: {
|
|
|
- data: data[config.url!],
|
|
|
+ data: item,
|
|
|
status: 200,
|
|
|
statusText: 'OK',
|
|
|
headers: {},
|
|
@@ -57,22 +66,21 @@ export const setOfflineAxios = (axios: AxiosInstance) => {
|
|
|
axios.interceptors.response.use(
|
|
|
function (response) {
|
|
|
if (!files[response.config.url!]) {
|
|
|
- console.error(response.config.url, '正在添加到离线包中!')
|
|
|
- data[response.config.url!] = response.data
|
|
|
+ console.error(response.config.url + paramsToStr(response.config.params), '正在添加到离线包中!')
|
|
|
+ data[response.config.url+ paramsToStr(response.config.params)!] = response.data
|
|
|
}
|
|
|
// 对响应数据做点什么
|
|
|
return response;
|
|
|
},
|
|
|
err => {
|
|
|
- console.log(err)
|
|
|
if (err.isFakeResponse) {
|
|
|
return Promise.resolve(err.response);
|
|
|
}
|
|
|
}
|
|
|
);
|
|
|
|
|
|
+ (window as any).proxyData = () => {
|
|
|
+ console.log(data)
|
|
|
+ console.log(JSON.stringify(data))
|
|
|
+ };
|
|
|
}
|
|
|
-
|
|
|
-(window as any).proxyData = () => {
|
|
|
- console.log(JSON.stringify(data))
|
|
|
-};
|