bill 1 سال پیش
والد
کامیت
bb3fa72ce3
5فایلهای تغییر یافته به همراه939 افزوده شده و 500 حذف شده
  1. 904 485
      public/package/data.json
  2. 17 9
      src/api/offline.ts
  3. 6 5
      src/api/setup.ts
  4. 1 1
      src/model/app.vue
  5. 11 0
      src/utils/params.ts

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 904 - 485
public/package/data.json


+ 17 - 9
src/api/offline.ts

@@ -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))
-};

+ 6 - 5
src/api/setup.ts

@@ -24,11 +24,6 @@ export const axiosFactory = (axiosRaw: AxiosInstance = Axios.create()) => {
     hook: [] as Hook[]
   }
 
-  if ((window as any).offline) {
-    setOfflineAxios(axiosRaw)
-  }
-
-
 
   type AxiosConfig = typeof axiosConfig
   type ExponseApi<K extends keyof AxiosConfig> = 
@@ -153,6 +148,12 @@ export const axiosFactory = (axiosRaw: AxiosInstance = Axios.create()) => {
     }
   )
 
+  if ((window as any).offline) {
+    setOfflineAxios(axiosRaw)
+  }
+
+
+
   axiosRaw.interceptors.response.use(
     (response: AxiosResponse<ResData<any>>) => {
       for (const hook of axiosConfig.hook) {

+ 1 - 1
src/model/app.vue

@@ -66,7 +66,7 @@ export const Model = defineComponent({
         return setUrl("");
       }
       const type = scene.value.type;
-      const urls = (window as any).offline
+      const urls = !(window as any).offline
         ? {
             [SceneType.SWKK]: `/swkk/spg.html?m=${scene.value.num}`,
             [SceneType.SWKJ]: `/swkk/spg.html?m=${scene.value.num}`,

+ 11 - 0
src/utils/params.ts

@@ -15,4 +15,15 @@ export const strToParams = (str: string) => {
   }
 
   return result
+}
+
+export const paramsToStr = (params: {[key in string]: string}) => {
+  
+  if (params && Object.keys(params).length > 0) {
+    const entitys = Object.entries(params)
+    entitys.sort((a, b) => a[0].localeCompare(b[0]))
+    return '?' + entitys.map(([k, v]) => `${k}=${v}`).join('&')
+  } else {
+    return ''
+  }
 }