no message
parent
fb50787fcd
commit
6bd3ddb555
|
|
@ -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);
|
||||
},
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
},
|
||||
|
||||
|
||||
};
|
||||
|
|
|
|||
|
|
@ -544,6 +544,7 @@ const onCancel = () => {
|
|||
abortController.value.abort();
|
||||
abortController.value = null;
|
||||
}
|
||||
handleExportError();
|
||||
};
|
||||
|
||||
onMounted(queryData);
|
||||
|
|
|
|||
|
|
@ -598,6 +598,7 @@ const onCancel = () => {
|
|||
abortController.value.abort();
|
||||
abortController.value = null;
|
||||
}
|
||||
handleExportError();
|
||||
};
|
||||
|
||||
onMounted(queryData);
|
||||
|
|
|
|||
|
|
@ -85,6 +85,28 @@
|
|||
导入
|
||||
</a-button>
|
||||
|
||||
<a-modal
|
||||
v-model:open="open"
|
||||
@cancel="onCancel"
|
||||
:closable="false"
|
||||
:maskClosable="false"
|
||||
:destroyOnClose="true">
|
||||
<a-progress
|
||||
:percent="progressPercent"
|
||||
:status="progressStatus"
|
||||
/>
|
||||
<template #title>
|
||||
<span style="display: inline-flex; align-items: center">
|
||||
<LoadingOutlined style="margin-right: 8px"/>
|
||||
{{ progressTitle }}
|
||||
</span>
|
||||
</template>
|
||||
<template #footer>
|
||||
<a-space>
|
||||
<a-button @click="onCancel">取消</a-button>
|
||||
</a-space>
|
||||
</template>
|
||||
</a-modal>
|
||||
<a-button @click="onExportLocations" type="primary" v-privilege="'location:exportLocations'">
|
||||
<template #icon>
|
||||
<ExportOutlined/>
|
||||
|
|
@ -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,10 +578,109 @@ 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<NodeJS.Timeout | null>(null); // 定时器引用
|
||||
const isExporting = ref(false); // 防止重复提交
|
||||
const abortController = ref<AbortController | null>(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);
|
||||
</script>
|
||||
<style scoped>
|
||||
|
|
|
|||
|
|
@ -16,10 +16,12 @@
|
|||
<LocationSelect v-model:value="queryForm.locationId" :disabledFlag="true" @change="onSearch"/>
|
||||
</a-form-item>
|
||||
<a-form-item label="状态" class="smart-query-form-item">
|
||||
<SmartEnumSelect style="width: 200px" enum-name="USAGE_STATUS_ENUM" v-model:value="queryForm.status" @change="onSearch"/>
|
||||
<SmartEnumSelect style="width: 200px" enum-name="USAGE_STATUS_ENUM" v-model:value="queryForm.status"
|
||||
@change="onSearch"/>
|
||||
</a-form-item>
|
||||
<a-form-item label="是否启用" class="smart-query-form-item">
|
||||
<a-select style="width: 200px" v-model:value="queryForm.disabledFlag" allowClear placeholder="请选择" @change="onSearch">
|
||||
<a-select style="width: 200px" v-model:value="queryForm.disabledFlag" allowClear placeholder="请选择"
|
||||
@change="onSearch">
|
||||
<a-select-option :value="true">启用</a-select-option>
|
||||
<a-select-option :value="false">禁用</a-select-option>
|
||||
</a-select>
|
||||
|
|
@ -68,6 +70,28 @@
|
|||
导入
|
||||
</a-button>
|
||||
|
||||
<a-modal
|
||||
v-model:open="open"
|
||||
@cancel="onCancel"
|
||||
:closable="false"
|
||||
:maskClosable="false"
|
||||
:destroyOnClose="true">
|
||||
<a-progress
|
||||
:percent="progressPercent"
|
||||
:status="progressStatus"
|
||||
/>
|
||||
<template #title>
|
||||
<span style="display: inline-flex; align-items: center">
|
||||
<LoadingOutlined style="margin-right: 8px"/>
|
||||
{{ progressTitle }}
|
||||
</span>
|
||||
</template>
|
||||
<template #footer>
|
||||
<a-space>
|
||||
<a-button @click="onCancel">取消</a-button>
|
||||
</a-space>
|
||||
</template>
|
||||
</a-modal>
|
||||
<a-button @click="onExportStocks" type="primary" v-privilege="'stock:exportStocks'">
|
||||
<template #icon>
|
||||
<ExportOutlined/>
|
||||
|
|
@ -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<NodeJS.Timeout | null>(null); // 定时器引用
|
||||
const isExporting = ref(false); // 防止重复提交
|
||||
const abortController = ref<AbortController | null>(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);
|
||||
</script>
|
||||
|
|
|
|||
Loading…
Reference in New Issue