From 6bd3ddb555cdfb3e352b7ca051f5612eedfae539 Mon Sep 17 00:00:00 2001
From: "HUOJIN\\92525" <925258474@qq.com>
Date: Mon, 12 May 2025 15:12:40 +0800
Subject: [PATCH] no message
---
 .../wms/base/location/location-api.ts         |   8 +-
 .../api/business/wms/base/stock/stock-api.ts  |   8 +-
 .../wms/base/address/address-list.vue         |   1 +
 .../business/wms/base/item/item-list.vue      |   1 +
 .../wms/base/location/location-list.vue       | 129 ++++++++++++++++-
 .../business/wms/base/stock/stock-list.vue    | 137 +++++++++++++++++-
 6 files changed, 268 insertions(+), 16 deletions(-)
diff --git a/nc_wms_web/src/api/business/wms/base/location/location-api.ts b/nc_wms_web/src/api/business/wms/base/location/location-api.ts
index 1030dee..529f8c2 100644
--- a/nc_wms_web/src/api/business/wms/base/location/location-api.ts
+++ b/nc_wms_web/src/api/business/wms/base/location/location-api.ts
@@ -5,7 +5,7 @@
  * @Date:      2024-11-18 14:17:31
  * @Copyright  友仓
  */
-import {postRequest, getRequest, getDownload} from '/@/lib/axios';
+import {postRequest, getRequest, postDownload2} from '/@/lib/axios';
 
 export const locationApi = {
 
@@ -76,7 +76,7 @@ export const locationApi = {
     /**
      * 导出  @author  hj
      */
-    exportLocations : () =>{
-        return getDownload('/location/exportLocations',{});
-    }
+    exportLocations: (taskId: string, param: any, signal?: AbortSignal) => {
+        return postDownload2(`/location/exportLocations/${taskId}`, param, signal);
+    },
 };
diff --git a/nc_wms_web/src/api/business/wms/base/stock/stock-api.ts b/nc_wms_web/src/api/business/wms/base/stock/stock-api.ts
index 40bdc51..b0922b2 100644
--- a/nc_wms_web/src/api/business/wms/base/stock/stock-api.ts
+++ b/nc_wms_web/src/api/business/wms/base/stock/stock-api.ts
@@ -5,7 +5,7 @@
  * @Date:      2024-11-26 11:37:48
  * @Copyright  友仓
  */
-import {postRequest, getRequest,getDownload} from '/@/lib/axios';
+import {postRequest, getRequest,postDownload2} from '/@/lib/axios';
 
 export const stockApi = {
 
@@ -61,9 +61,9 @@ export const stockApi = {
     /**
      * 导出  @author  hj
      */
-    exportStocks: () => {
-        return getDownload('/stock/exportStocks', {});
-    }
+    exportStocks: (taskId: string, param: any, signal?: AbortSignal) => {
+        return postDownload2(`/stock/exportStocks/${taskId}`, param, signal);
+    },
 
 
 };
diff --git a/nc_wms_web/src/views/business/wms/base/address/address-list.vue b/nc_wms_web/src/views/business/wms/base/address/address-list.vue
index d5dce1b..7c35112 100644
--- a/nc_wms_web/src/views/business/wms/base/address/address-list.vue
+++ b/nc_wms_web/src/views/business/wms/base/address/address-list.vue
@@ -544,6 +544,7 @@ const onCancel = () => {
     abortController.value.abort();
     abortController.value = null;
   }
+  handleExportError();
 };
 
 onMounted(queryData);
diff --git a/nc_wms_web/src/views/business/wms/base/item/item-list.vue b/nc_wms_web/src/views/business/wms/base/item/item-list.vue
index 36fcdc5..0b34b5e 100644
--- a/nc_wms_web/src/views/business/wms/base/item/item-list.vue
+++ b/nc_wms_web/src/views/business/wms/base/item/item-list.vue
@@ -598,6 +598,7 @@ const onCancel = () => {
     abortController.value.abort();
     abortController.value = null;
   }
+  handleExportError();
 };
 
 onMounted(queryData);
diff --git a/nc_wms_web/src/views/business/wms/base/location/location-list.vue b/nc_wms_web/src/views/business/wms/base/location/location-list.vue
index f6d6577..25ee221 100644
--- a/nc_wms_web/src/views/business/wms/base/location/location-list.vue
+++ b/nc_wms_web/src/views/business/wms/base/location/location-list.vue
@@ -85,6 +85,28 @@
           导入
         
 
+        
+          
+          
+            
+            
+            {{ progressTitle }}
+            
+          
+          
+            
+              取消
+            
+          
+        
         
           
             
@@ -226,6 +248,7 @@ import {reactive, ref, onMounted} from 'vue';
 import {message, Modal} from 'ant-design-vue';
 import {SmartLoading} from '/@/components/framework/smart-loading';
 import {locationApi} from '/@/api/business/wms/base/location/location-api';
+import {exportApi} from "/@/api/business/wms/export/export-api";
 import {PAGE_SIZE_OPTIONS} from '/@/constants/common-const';
 import {smartSentry} from '/@/lib/smart-sentry';
 import TableOperator from '/@/components/support/table-operator/index.vue';
@@ -239,6 +262,7 @@ import DictLabel from '/@/components/support/dict-label/index.vue';
 import MultipleInsert from "/@/views/business/wms/base/location/multiple-insert.vue";
 import {UploadFile} from 'ant-design-vue';
 import {fileApi} from "/@/api/support/file-api";
+import {LoadingOutlined} from "@ant-design/icons-vue";
 // ---------------------------- 表格列 ----------------------------
 
 let columns = ref([
@@ -554,9 +578,108 @@ async function onImportLocations() {
 }
 
 //导出
-function onExportLocations() {
-  locationApi.exportLocations();
-}
+const progressTitle = ref('文件下载中,请稍等...');//标题
+const progressPercent = ref(0);//进度百分比
+const progressStatus = ref('active');
+const currentTaskId = ref('');//当前任务ID
+const open = ref(false);//打开进度条窗口
+const timerId = ref(null); // 定时器引用
+const isExporting = ref(false); // 防止重复提交
+const abortController = ref(null);// 用于取消请求
+
+const onExportLocations = async () => {
+  if (isExporting.value) return;
+
+  try {
+    isExporting.value = true;
+    abortController.value = new AbortController(); // 创建控制器
+    open.value = true;
+    resetProgressState(); // 重置进度状态
+
+    // 创建导出任务
+    const {data: taskId} = await exportApi.createExportTask();
+    currentTaskId.value = taskId;
+    // 发起导出请求
+    try {
+      locationApi.exportLocations(taskId, queryForm, abortController.value.signal)
+    } catch (error) {
+      handleExportError();
+    }
+
+    // 清理之前的定时器
+    if (timerId.value) {
+      clearInterval(timerId.value);
+    }
+
+    // 启动轮询
+    timerId.value = setInterval(async () => {
+      try {
+        const {data: progress} = await exportApi.getExportProgress(currentTaskId.value);
+
+        if (progress == -1) {
+          handleExportError();
+        }
+
+        progressPercent.value = progress;
+        console.log('progress', progress);
+        if (progress >= 100) {
+          handleExportSuccess();
+        }
+
+      } catch (error) {
+        handleExportError();
+      }
+    }, 1000);
+
+  } catch (error) {
+    handleExportError();
+  } finally {
+    isExporting.value = false;
+  }
+};
+
+//  处理导出成功
+const handleExportSuccess = () => {
+  if (timerId.value) {
+    clearInterval(timerId.value);
+  }
+  progressStatus.value = 'success';
+  progressTitle.value = '文件下载完成';
+
+  setTimeout(() => {
+    open.value = false;
+    resetProgressState();
+  }, 1000);
+};
+
+// 处理导出失败
+const handleExportError = () => {
+  if (timerId.value) clearInterval(timerId.value);
+  progressStatus.value = 'exception';
+  progressPercent.value = 0;
+  open.value = false;
+  resetProgressState();
+};
+
+// 重置进度状态
+const resetProgressState = () => {
+  progressPercent.value = 0;
+  progressStatus.value = 'active';
+  progressTitle.value = '文件下载中,请稍等...';
+  currentTaskId.value = '';
+};
+
+//取消
+const onCancel = () => {
+  // 中止进行中的请求
+  open.value = false;
+  if (abortController.value) {
+    abortController.value.abort();
+    abortController.value = null;
+  }
+  handleExportError();
+};
+
 
 onMounted(queryData);
 
diff --git a/nc_wms_web/src/views/business/wms/base/stock/stock-list.vue b/nc_wms_web/src/views/business/wms/base/stock/stock-list.vue
index b669536..5b47803 100644
--- a/nc_wms_web/src/views/business/wms/base/stock/stock-list.vue
+++ b/nc_wms_web/src/views/business/wms/base/stock/stock-list.vue
@@ -16,10 +16,12 @@
         
       
       
-        
+        
       
       
-        
+        
           启用
           禁用
         
@@ -68,6 +70,28 @@
           导入
         
 
+        
+          
+          
+            
+            
+            {{ progressTitle }}
+            
+          
+          
+            
+              取消
+            
+          
+        
         
           
             
@@ -200,6 +224,9 @@ import StockSelect from "/@/views/business/wms/base/stock/stock-select.vue";
 import SmartEnumSelect from "/@/components/framework/smart-enum-select/index.vue";
 import LocationSelect from "/@/views/business/wms/base/location/location-select.vue";
 import DictLabel from "/@/components/support/dict-label/index.vue";
+import {LoadingOutlined} from "@ant-design/icons-vue";
+import {exportApi} from "/@/api/business/wms/export/export-api";
+import {itemApi} from "/@/api/business/wms/base/item/item-api";
 // ---------------------------- 表格列 ----------------------------
 
 let columns = ref([
@@ -479,9 +506,109 @@ async function onImportStocks() {
 }
 
 //导出
-function onExportStocks() {
-  stockApi.exportStocks();
-}
+const progressTitle = ref('文件下载中,请稍等...');//标题
+const progressPercent = ref(0);//进度百分比
+const progressStatus = ref('active');
+const currentTaskId = ref('');//当前任务ID
+const open = ref(false);//打开进度条窗口
+const timerId = ref(null); // 定时器引用
+const isExporting = ref(false); // 防止重复提交
+const abortController = ref(null);// 用于取消请求
+
+const onExportStocks = async () => {
+  if (isExporting.value) return;
+
+  try {
+    isExporting.value = true;
+    abortController.value = new AbortController(); // 创建控制器
+    open.value = true;
+    resetProgressState(); // 重置进度状态
+
+    // 创建导出任务
+    const {data: taskId} = await exportApi.createExportTask();
+    currentTaskId.value = taskId;
+
+    // 发起导出请求
+    try {
+      itemApi.exportItems(taskId, queryForm, abortController.value.signal)
+    } catch (error) {
+      handleExportError();
+    }
+
+    // 清理之前的定时器
+    if (timerId.value) {
+      clearInterval(timerId.value);
+    }
+
+    // 启动轮询
+    timerId.value = setInterval(async () => {
+      try {
+        const {data: progress} = await exportApi.getExportProgress(currentTaskId.value);
+
+        if (progress == -1) {
+          handleExportError();
+        }
+
+        progressPercent.value = progress;
+
+        if (progress >= 100) {
+          handleExportSuccess();
+        }
+
+      } catch (error) {
+        handleExportError();
+      }
+    }, 1000);
+
+  } catch (error) {
+    handleExportError();
+  } finally {
+    isExporting.value = false;
+  }
+};
+
+//  处理导出成功
+const handleExportSuccess = () => {
+  if (timerId.value) {
+    clearInterval(timerId.value);
+  }
+  progressStatus.value = 'success';
+  progressTitle.value = '文件下载完成';
+
+  setTimeout(() => {
+    open.value = false;
+    resetProgressState();
+  }, 1000);
+};
+
+// 处理导出失败
+const handleExportError = () => {
+  if (timerId.value) clearInterval(timerId.value);
+  progressStatus.value = 'exception';
+  progressPercent.value = 0;
+  open.value = false;
+  resetProgressState();
+};
+
+// 重置进度状态
+const resetProgressState = () => {
+  progressPercent.value = 0;
+  progressStatus.value = 'active';
+  progressTitle.value = '文件下载中,请稍等...';
+  currentTaskId.value = '';
+};
+
+//取消
+const onCancel = () => {
+  // 中止进行中的请求
+  open.value = false;
+  if (abortController.value) {
+    abortController.value.abort();
+    abortController.value = null;
+  }
+  handleExportError();
+};
+
 
 onMounted(queryData);