库位导入显示进度条

main
HUOJIN\霍先森 2025-03-17 00:43:13 +08:00
parent 9480a8f874
commit 2c1e96580c
3 changed files with 129 additions and 2 deletions

View File

@ -65,4 +65,11 @@ export const locationApi = {
multipleInsert: (param: object) => {
return postRequest('/location/multipleInsert', param);
},
/**
* @author hj
*/
importLocations: (file: object, config = {}) => {
return postRequest('/location/importLocations', file, config);
},
};

View File

@ -146,11 +146,12 @@ export const request = (config) => {
/**
* post
*/
export const postRequest = (url, data) => {
export const postRequest = (url, data,configs = {}) => {
return request({
data,
url,
method: 'post',
...configs,
});
};

View File

@ -69,11 +69,18 @@
<a-button @click="showMultipleInsertForm" type="primary" v-privilege="'location:multipleInsert'">
<template #icon>
<EditOutlined/>
<PlusOutlined/>
</template>
批量新建
</a-button>
<a-button @click="showImportModal" type="primary" v-privilege="'location:importLocations'">
<template #icon>
<ImportOutlined/>
</template>
导入
</a-button>
</div>
<div class="smart-table-setting-block">
<TableOperator v-model="columns" :tableId="TABLE_ID_CONST.BUSINESS.BASE.LOCATION" :refresh="queryData"/>
@ -166,6 +173,39 @@
<!-- 批量新建-->
<MultipleInsert ref="multipleInsertFormRef" @reloadList="queryData"/>
<a-modal v-model:open="importModalShowFlag" title="导入" @onCancel="hideImportModal" @ok="hideImportModal">
<div style="text-align: center; width: 400px; margin: 0 auto">
<a-button @click="downloadExcel">
<download-outlined/>
第一步下载模板
</a-button>
<br/>
<br/>
<a-upload
v-model:fileList="fileList"
name="file"
:multiple="false"
action="https://www.mocky.io/v2/5cc8019d300000980a055e76"
accept=".xls,.xlsx"
:before-upload="beforeUpload"
@remove="handleRemove"
>
<a-button>
<upload-outlined/>
第二步选择文件
</a-button>
</a-upload>
<br/>
<a-button @click="onImportLocations">
<ImportOutlined/>
第三步开始导入
</a-button>
<!-- 新增进度条 -->
<a-progress v-if="uploadProgress > 0" :percent="uploadProgress" status="active" />
</div>
</a-modal>
</a-card>
</template>
<script setup lang="ts">
@ -185,6 +225,7 @@ import SmartEnumSelect from '/@/components/framework/smart-enum-select/index.vue
import DictPreview from '/@/components/dict-preview/index.vue';
import {useDict} from '/@/utils/dict';
import MultipleInsert from "/@/views/business/base/location/multiple-insert.vue";
import { UploadFile } from 'ant-design-vue';
const locType = useDict('LOC_TYPE');
@ -407,4 +448,82 @@ const multipleInsertFormRef = ref();
function showMultipleInsertForm() {
multipleInsertFormRef.value.showMultipleInsert();
}
// ------------------------------- ---------------------------------
//
const importModalShowFlag = ref(false);
const fileList = ref<UploadFile[]>([])
//
const uploadProgress = ref(0);
//
function showImportModal() {
fileList.value = [];
uploadProgress.value = 0;
importModalShowFlag.value = true;
}
//
function hideImportModal() {
importModalShowFlag.value = false;
uploadProgress.value = 0;
}
//
function downloadExcel() {
window.open('https://smartadmin.vip/cdn/%E5%95%86%E5%93%81%E6%A8%A1%E6%9D%BF.xls');
}
//
function handleRemove(file: UploadFile) {
const index = fileList.value.indexOf(file);
const newFileList = fileList.value.slice();
newFileList.splice(index, 1);
fileList.value = newFileList;
}
//
function beforeUpload(file:UploadFile) {
fileList.value = [...(fileList.value || []), file];
return false;
}
//
async function onImportLocations() {
console.log(fileList.value.length);
if (fileList.value.length === 0) {
return message.error('请选择文件');
}
const formData = new FormData();
fileList.value.forEach((file: UploadFile) => {
formData.append('file', file.originFileObj!);
});
SmartLoading.show();
try {
//
const config = {
onUploadProgress: (progressEvent) => {
const percentCompleted = Math.round((progressEvent.loaded * 100) / progressEvent.total);
//
console.log(`上传进度: ${percentCompleted}%`);
uploadProgress.value = percentCompleted;
},
};
let res = await locationApi.importLocations(formData, config);
message.success(res.msg);
await queryData();
} catch (e) {
smartSentry.captureError(e);
message.error('导入失败');
} finally {
SmartLoading.hide();
}
}
</script>