Sfoglia il codice sorgente

增加搜同款超时时间;
增加后端接口地址配置位置;

dodo hold 2 anni fa
parent
commit
a7b7e912b2
5 ha cambiato i file con 143 aggiunte e 126 eliminazioni
  1. 18 10
      index.html
  2. 107 110
      src/api/interceptor.ts
  3. 1 0
      src/api/taobao.ts
  4. 11 6
      src/env.d.ts
  5. 6 0
      src/views/settings/config.vue

+ 18 - 10
index.html

@@ -1,13 +1,21 @@
 <!DOCTYPE html>
 <html lang="en">
-  <head>
-    <meta charset="UTF-8" />
-    <link rel="shortcut icon" type="image/x-icon" href="https://unpkg.byted-static.com/latest/byted/arco-config/assets/favicon.ico">
-    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
-    <title>Molilian</title>
-  </head>
-  <body>
-    <div id="app"></div>
-    <script type="module" src="/src/main.ts"></script>
-  </body>
+    <head>
+        <meta charset="UTF-8" />
+        <link
+            rel="shortcut icon"
+            type="image/x-icon"
+            href="https://unpkg.byted-static.com/latest/byted/arco-config/assets/favicon.ico"
+        />
+        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
+        <title>Molilian</title>
+        <script>
+            window.apiserver = 'https://adminapi.molilian.com';
+            window.apiscope = 'admin';
+        </script>
+    </head>
+    <body>
+        <div id="app"></div>
+        <script type="module" src="/src/main.ts"></script>
+    </body>
 </html>

+ 107 - 110
src/api/interceptor.ts

@@ -5,131 +5,128 @@ import { useUserStore } from '@/store';
 import { getToken } from '@/utils/auth';
 
 export interface HttpResponse<T = unknown> {
-  status: number;
-  msg: string;
-  code: number;
-  data: T;
-}
-
-if (import.meta.env.VITE_API_BASE_URL) {
-  axios.defaults.baseURL = import.meta.env.VITE_API_BASE_URL;
+    status: number;
+    msg: string;
+    code: number;
+    data: T;
 }
 
 let API_SCOPE = 'admin';
-if (import.meta.env.VITE_API_BASE_SCOPE) {
-  API_SCOPE = import.meta.env.VITE_API_BASE_SCOPE;
-}
+if (window.apiserver) axios.defaults.baseURL = window.apiserver;
+if (window.apiscope) API_SCOPE = window.apiscope;
 
 axios.interceptors.request.use(
-  (config: AxiosRequestConfig) => {
-    // let each request carry token
-    // this example using the JWT token
-    // Authorization is a custom headers key
-    // please modify it according to the actual situation
+    (config: AxiosRequestConfig) => {
+        // let each request carry token
+        // this example using the JWT token
+        // Authorization is a custom headers key
+        // please modify it according to the actual situation
 
-    const token = getToken();
-    if (token) {
-      if (!config.headers) {
-        config.headers = {
-        };
-      }
-      if (API_SCOPE) {
-        config.headers.scope = API_SCOPE;
-      }
-      config.headers.Authorization = `Bearer ${token}`;
+        const token = getToken();
+        if (token) {
+            if (!config.headers) {
+                config.headers = {};
+            }
+            if (API_SCOPE) {
+                config.headers.scope = API_SCOPE;
+            }
+            config.headers.Authorization = `Bearer ${token}`;
+        }
+        return config;
+    },
+    (error) => {
+        // do something
+        return Promise.reject(error);
     }
-    return config;
-  },
-  (error) => {
-    // do something
-    return Promise.reject(error);
-  }
 );
 // add response interceptors
 axios.interceptors.response.use(
-  (response: AxiosResponse<HttpResponse>) => {
-    const res = response.data;
-    // if the custom code is not 20000, it is judged as an error.
-    if (res.code !== 200) {
-      Message.error({
-        content: res.msg || 'Error',
-        duration: 5 * 1000,
-      });
-      // 50008: Illegal token; 50012: Other clients logged in; 50014: Token expired;
-      if (
-        [401].includes(res.code) &&
-        response.config.url !== '/api/user/info'
-      ) {
-        Modal.error({
-          title: 'Confirm logout',
-          content:
-            'You have been logged out, you can cancel to stay on this page, or log in again',
-          okText: 'Re-Login',
-          async onOk() {
-            const userStore = useUserStore();
+    (response: AxiosResponse<HttpResponse>) => {
+        const res = response.data;
+        // if the custom code is not 20000, it is judged as an error.
+        if (res.code !== 200) {
+            Message.error({
+                content: res.msg || 'Error',
+                duration: 5 * 1000,
+            });
+            // 50008: Illegal token; 50012: Other clients logged in; 50014: Token expired;
+            if (
+                [401].includes(res.code) &&
+                response.config.url !== '/api/user/info'
+            ) {
+                Modal.error({
+                    title: 'Confirm logout',
+                    content:
+                        'You have been logged out, you can cancel to stay on this page, or log in again',
+                    okText: 'Re-Login',
+                    async onOk() {
+                        const userStore = useUserStore();
 
-            await userStore.logout();
-            window.location.reload();
-          },
-        });
-      }
-      return Promise.reject(new Error(res.msg || 'Error'));
-    }
-    return res;
-  },
-  (error) => {
-    const result = error.response;
+                        await userStore.logout();
+                        window.location.reload();
+                    },
+                });
+            }
+            return Promise.reject(new Error(res.msg || 'Error'));
+        }
+        return res;
+    },
+    (error) => {
+        const result = error.response;
 
-    if (error.response) {
-      if (error.response.request.responseType === 'arraybuffer' && error.response.data.toString() === '[object ArrayBuffer]') {
-        const text = Buffer.from(error.response.data).toString('utf8');
-        result.data = JSON.parse(text);
-      }
-    } else {
-      Message.error({
-        content: error.msg || 'Request Error',
-        duration: 5 * 1000,
-      });
-      return Promise.reject(error);
-    }
+        if (error.response) {
+            if (
+                error.response.request.responseType === 'arraybuffer' &&
+                error.response.data.toString() === '[object ArrayBuffer]'
+            ) {
+                const text = Buffer.from(error.response.data).toString('utf8');
+                result.data = JSON.parse(text);
+            }
+        } else {
+            Message.error({
+                content: error.msg || 'Request Error',
+                duration: 5 * 1000,
+            });
+            return Promise.reject(error);
+        }
 
-    if (result.data.code !== 200) {
-      const url = result.data.config?.url
-      // 50008: Illegal token; 50012: Other clients logged in; 50014: Token expired;
-      if (result.data.code === 401 && url !== '/api/user/info') {
-        Modal.error({
-          title: 'Confirm logout',
-          content:
-            'You have been logged out, you can cancel to stay on this page, or log in again',
-          okText: 'Re-Login',
-          async onOk() {
-            const userStore = useUserStore();
+        if (result.data.code !== 200) {
+            const url = result.data.config?.url;
+            // 50008: Illegal token; 50012: Other clients logged in; 50014: Token expired;
+            if (result.data.code === 401 && url !== '/api/user/info') {
+                Modal.error({
+                    title: 'Confirm logout',
+                    content:
+                        'You have been logged out, you can cancel to stay on this page, or log in again',
+                    okText: 'Re-Login',
+                    async onOk() {
+                        const userStore = useUserStore();
+
+                        await userStore.logout();
+                        window.location.reload();
+                    },
+                });
+            } else {
+                Message.error({
+                    content: result.data.msg || 'Error',
+                    duration: 5 * 1000,
+                });
+            }
+        }
+
+        if (result && typeof result.data.code !== 'undefined') {
+            const err = new Error(result.data.msg);
+            Message.error({
+                content: err.message || 'Request Error',
+                duration: 5 * 1000,
+            });
+            return Promise.reject(err);
+        }
 
-            await userStore.logout();
-            window.location.reload();
-          },
-        });
-      } else {
         Message.error({
-          content: result.data.msg || 'Error',
-          duration: 5 * 1000,
+            content: error.msg || 'Request Error',
+            duration: 5 * 1000,
         });
-      }
+        return Promise.reject(error);
     }
-
-    if (result && typeof (result.data.code) !== 'undefined') {
-      const err = new Error(result.data.msg);
-      Message.error({
-        content: err.message || 'Request Error',
-        duration: 5 * 1000,
-      });
-      return Promise.reject(err);
-    }
-
-    Message.error({
-      content: error.msg || 'Request Error',
-      duration: 5 * 1000,
-    });
-    return Promise.reject(error);
-  }
 );

+ 1 - 0
src/api/taobao.ts

@@ -14,6 +14,7 @@ export interface UpdateConfigModel {
     fake_click_max: number;
     fake_click_ttl: number;
     rt_max: number;
+    similar_timeout: number;
     tk_whitelist_regular: string;
     tk_blacklist_regular: string;
     multi_token_regular: string;

+ 11 - 6
src/env.d.ts

@@ -1,12 +1,17 @@
 /// <reference types="vite/client" />
 
 declare module '*.vue' {
-  import { DefineComponent } from 'vue';
-  // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/ban-types
-  const component: DefineComponent<{}, {}, any>;
-  export default component;
+    import { DefineComponent } from 'vue';
+    // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/ban-types
+    const component: DefineComponent<{}, {}, any>;
+    export default component;
 }
 interface ImportMetaEnv {
-  readonly VITE_API_BASE_URL: string;
-  readonly VITE_API_BASE_SCOPE: string;
+    readonly VITE_API_BASE_URL: string;
+    readonly VITE_API_BASE_SCOPE: string;
+}
+
+interface Window {
+    apiserver: string;
+    apiscope: string;
 }

+ 6 - 0
src/views/settings/config.vue

@@ -50,6 +50,11 @@
                             </a-form-item>
 
 
+                            <a-form-item field="similar_timeout" label="搜同款超时" :rules="[{ required: true }]">
+                                <a-input-number v-model="formData.similar_timeout" :min="1000" placeholder="搜同款API最长超时时间,单位毫秒" />
+                            </a-form-item>
+
+
                             <a-form-item field="tk_whitelist_regular" label="淘口令正则">
                                 <a-textarea v-model="formData.tk_whitelist_regular" auto-size placeholder="淘口令正则" />
                                 <template #extra>
@@ -131,6 +136,7 @@ const formData = ref<UpdateConfigModel>({
     fake_click_max: 0,
     fake_click_ttl: 0,
     rt_max: 0,
+    similar_timeout: 0,
     tk_whitelist_regular: '',
     tk_blacklist_regular: '',
     multi_token_regular: '',