Răsfoiți Sursa

Merge branch 'test'

WanGxC 8 luni în urmă
părinte
comite
bfc295f3ac

+ 1 - 1
src/components/FileDowlander/index.vue

@@ -40,7 +40,7 @@ async function handleDownload() {
 
     // 释放 URL 对象
     window.URL.revokeObjectURL(url);
-    if (response.code === 2000) ElMessage.success('文件下载成功');
+    if (response.code === 2000) ElMessage.success(response.msg);
   } catch (error) {
     console.error('==Error==:', error);
     ElMessage.error('文件下载失败,请重试');

+ 2 - 1
src/utils/useElTableData.ts

@@ -1,4 +1,5 @@
 import { nextTick, Ref } from 'vue';
+import { response } from '/@/utils/tools';
 
 
 /**
@@ -20,7 +21,7 @@ export async function useElTableData(apiFunction: Function, query: any, tableDat
     }
     total.value = response.total;
     tableData.value = responseData;
-    return { success: true, data: responseData };
+    return { success: true, data: responseData, code: response.code, msg: response.msg };
   } catch (error) {
     console.error('Error in useElTableData==> ', error);
     return { success: false, error };

+ 44 - 15
src/views/featureWord/featureWordDownload/index.vue

@@ -11,12 +11,14 @@ import { usePagination } from '/@/utils/usePagination';
 import FileDownLoader from '/@/components/FileDowlander/index.vue';
 import * as api from './api';
 import { useElTableData } from '/@/utils/useElTableData';
-import { Download } from '@element-plus/icons-vue';
+import { Download, Refresh } from '@element-plus/icons-vue';
+import { ElMessage } from 'element-plus';
 
 
 const date = ref(calculateLastMonthFirstWeek());
 const dateRange = ref(date.value[0]);
 const loading = ref(false);
+const btnLoading = ref(false);
 const { tableData, total, currentPage, pageSize, handlePageChange } = usePagination(handleQuery);
 
 const filter = ref({
@@ -73,8 +75,6 @@ async function handleQuery() {
 }
 
 function handleDownload(row: any) {
-  console.log("(index.vue: 77)=> row", row);
-
   const url = row.Url;
   const fileName = url.split('/').pop();
 
@@ -86,6 +86,43 @@ function handleDownload(row: any) {
   link.click();
   document.body.removeChild(link);
 }
+
+async function queryDownload() {
+  btnLoading.value = true;
+  const query = {
+    ...filter.value,
+    date_start: date.value[0],
+    date_end: date.value[1],
+    reportDate: undefined,
+    page: currentPage.value,
+    limit: pageSize.value,
+  };
+  try {
+    const response = await api.wordDownload(query);
+    if (response.code === 2000) ElMessage.success(response.msg);
+  } catch(error) {
+    console.log('Error==>', error);
+  } finally {
+    btnLoading.value = false;
+    await handleQuery();
+  }
+}
+
+async function handleRefresh(row: any) {
+  const query = {
+    search_term: row.searchTerm,
+    marketplace_Ids: row.marketplace_id,
+    report_type: row.tableName.split('_').pop(),
+    date_start: row.daterange.slice(0, 10),
+    date_end: row.daterange.slice(10),
+  };
+  try {
+    const { code, msg } = await useElTableData(api.wordDownload, query, tableData, total, loading);
+    if (code === 2000) ElMessage.success({ message: msg, plain: true})
+  } catch(error) {
+    console.log('Error==>', error);
+  }
+}
 </script>
 
 <template>
@@ -133,18 +170,9 @@ function handleDownload(row: any) {
         </div>
       </div>
       <div class="flex gap-3.5">
-        <FileDownLoader
-            :api="api.wordDownload" :query="{
-              ...filter,
-              date_start: date[0],
-              date_end: date[1],
-              reportDate: undefined
-            }"
-            plain
-            round
-            type="success">
+        <el-button @click="queryDownload" :icon="Download" plain round type="success" :loading="btnLoading">
           文件下载
-        </FileDownLoader>
+        </el-button>
       </div>
     </el-card>
     <el-card shadow="hover" style="border: none; margin-bottom: 10px">
@@ -166,7 +194,7 @@ function handleDownload(row: any) {
         </el-table-column>
         <el-table-column align="center" label="日期范围" prop="daterange">
           <template #default="{ row }">
-            <span class="font-semibold">{{ row.daterange }}</span>
+            <span class="font-semibold">{{ row.daterange.slice(0, 10) }} To {{ row.daterange.slice(10) }}</span>
           </template>
         </el-table-column>
         <el-table-column align="center" label="表名" prop="tableName">
@@ -178,6 +206,7 @@ function handleDownload(row: any) {
           <template #default="{ row }">
             <span class="font-semibold">{{ row.State }}</span>
             <el-button :icon="Download" class="ml-2" link type="success" :disabled="row.State!='success'" @click="handleDownload(row)"></el-button>
+            <el-button :icon="Refresh" type="primary" link @click="handleRefresh(row)"></el-button>
           </template>
         </el-table-column>
       </el-table>