Forráskód Böngészése

调整分页设置

dodo hold 2 éve
szülő
commit
63bdcf38df
4 módosított fájl, 149 hozzáadás és 142 törlés
  1. 10 18
      index.html
  2. 110 107
      src/api/interceptor.ts
  3. 6 11
      src/env.d.ts
  4. 23 6
      src/views/taobao/report_daily.vue

+ 10 - 18
index.html

@@ -1,21 +1,13 @@
 <!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>
-        <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>
+  <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>
 </html>

+ 110 - 107
src/api/interceptor.ts

@@ -5,128 +5,131 @@ import { useUserStore } from '@/store';
 import { getToken } from '@/utils/auth';
 
 export interface HttpResponse<T = unknown> {
-    status: number;
-    msg: string;
-    code: number;
-    data: T;
+  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;
 }
 
 let API_SCOPE = 'admin';
-if (window.apiserver) axios.defaults.baseURL = window.apiserver;
-if (window.apiscope) API_SCOPE = window.apiscope;
+if (import.meta.env.VITE_API_BASE_SCOPE) {
+  API_SCOPE = import.meta.env.VITE_API_BASE_SCOPE;
+}
 
 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}`;
-        }
-        return config;
-    },
-    (error) => {
-        // do something
-        return Promise.reject(error);
+    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);
+  }
 );
 // 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;
-
-        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();
+            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();
-                    },
-                });
-            } else {
-                Message.error({
-                    content: result.data.msg || 'Error',
-                    duration: 5 * 1000,
-                });
-            }
-        }
+    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 && 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);
-        }
+    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: error.msg || 'Request Error',
-            duration: 5 * 1000,
+          content: result.data.msg || '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);
+  }
 );

+ 6 - 11
src/env.d.ts

@@ -1,17 +1,12 @@
 /// <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;
-}
-
-interface Window {
-    apiserver: string;
-    apiscope: string;
+  readonly VITE_API_BASE_URL: string;
+  readonly VITE_API_BASE_SCOPE: string;
 }

+ 23 - 6
src/views/taobao/report_daily.vue

@@ -90,7 +90,7 @@
             <a-table row-key="id" :loading="loading" :pagination="pagination" :summary="true" summary-text="汇总"
                 :columns="(cloneColumns as TableColumnData[])" :scroll="scroll" :scrollbar="scrollbar"
                 :data="renderData" :bordered="{ headerCell: true }" :size="size" :load-more="loadMore"
-                @page-change="onPageChange">
+                @page-change="onPageChange" @page-size-change="onPageSizeChange">
                 <template #xAxis="{ record }">
                     <template v-if="record.accountName !== '' && !record.isLeaf">
                         {{ record.accountName }}
@@ -233,9 +233,9 @@
                         column.slotName == 'refund_order_ord_amt' ||
                         column.slotName == 'refund_order_ord_tfee' ||
                         column.slotName == 'refund_order_ord_amt_4' ||
-                        column.slotName == 'refund_order_ord_tfee_4'||
-                        column.slotName == 'refund_order_ord_deduct_tfee'||
-                        column.slotName == 'refund_order_ord_freeze_tfee'||
+                        column.slotName == 'refund_order_ord_tfee_4' ||
+                        column.slotName == 'refund_order_ord_deduct_tfee' ||
+                        column.slotName == 'refund_order_ord_freeze_tfee' ||
                         column.slotName == 'refund_order_ord_unfreeze_tfee'">
 
                         <div>{{ amountFormat(record[column.dataIndex]) }}</div>
@@ -322,10 +322,17 @@ const scroll = {
 
 const basePagination: Pagination = {
     current: 1,
-    pageSize: 30,
+    pageSize: 31,
 };
 const pagination = reactive({
     ...basePagination,
+    showTotal: true,
+    showJumper: true,
+    showMore: true,
+    showPageSize: true,
+    pageSizeOptions: [10, 20, 30, 31, 50, 100, 200],
+    sizePageSize: true,
+
 });
 const densityList = computed(() => [
     {
@@ -752,7 +759,7 @@ const columns = computed<TableColumnData[]>(() => [
 const fetchData = async (
     params: TkReportParams = {
         current: 1,
-        pageSize: 30,
+        pageSize: basePagination.pageSize,
         sort: 'report_date',
         order: 'descending',
     }
@@ -852,6 +859,16 @@ const onPageChange = (current: number) => {
     });
 };
 
+const onPageSizeChange = (current: number) => {
+    basePagination.pageSize = current;
+    pagination.pageSize = current;
+    fetchData({
+        ...basePagination,
+        ...formModel.value,
+        current: 1,
+    });
+};
+
 fetchData();
 const reset = () => {
     formModel.value = generateFormModel();