202501-Wms-Kate-Wuxi/dev_wms_client/src/excel/UploadExcelInventory.vue
liang d35cf10f93 1. 暂时取消日志文件的数据库保存
2. 增加批量盘点的功能
3. 导出模版的日期格式化
2025-06-08 20:23:01 +08:00

98 lines
2.7 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<el-upload ref="uploadRef" :on-preview="previewFile" :limit="1" :on-change="changeFile" :auto-upload="false"
:data="uploadForm.data">
<template #trigger>
<el-button type="primary">选取盘点请求文件</el-button>
</template>
<el-button style="margin-left: 10px;" type="success" @click="uploadBaseGoods">上传盘点请求列表</el-button>
</el-upload>
</template>
<script setup>
import store from '@/store'
import {ref, reactive} from 'vue';
import {uploadExcelBaseGoods, uploadExcelInventoryRequest} from '@/api/excel.js'
import {ElMessage} from 'element-plus'
import {errorBox} from '@/utils/myMessageBox';
import {sizeFormatter} from '@/utils/formatter.js'
import {loading} from '@/utils/loading.js'
import {getHashString} from '@/utils/hashUtils.js'
var currentHash = ''
const file = ref()
const uploadForm = reactive({
data: {
fileId: '',
name: '',
type: '',
size: null,
hash: '',
userName: store.getters.getUserName,
standId: store.getters.getStandId
}
})
const changeFile = (uploadFile) => {
file.value = uploadFile
uploadForm.data = {
fileId: file.value.raw.uid,
name: file.value.raw.name,
type: file.value.raw.type,
size: sizeFormatter(file.value.raw.size),
hash: getHashString(uploadFile),
userName: store.getters.getUserName,
standId: store.getters.getStandId
}
}
const uploadRef = ref()
const uploadBaseGoods = () => {
if (uploadForm === undefined || file.value === undefined) {
errorBox('请选择文件之后再上传')
return
}
if (currentHash !== '' && currentHash === uploadForm.data.hash) {
errorBox('请勿重复上传')
return
}
currentHash = uploadForm.data.hash
const jsonStr = JSON.stringify(uploadForm.data);
const blob = new Blob([jsonStr], {
type: 'application/json'
});
let formData = new FormData();
// 这里很重要 file.value.raw才是真实的file文件file.value只是一个Proxy代理对象
formData.append("fileVo", blob);
formData.append("file", file.value.raw);
loading.open('导入中...')
uploadExcelInventoryRequest(formData).then(res => {
if (res.data.code === 0) {
ElMessage.success(res.data.message)
clearFileInfos()
} else {
errorBox(res.data.message)
}
}).catch(err => {
console.log(err)
errorBox('上传错误')
}).finally(() => {
currentHash = ''
loading.close()
})
}
const clearFileInfos = () => {
// 清空选择的文件项
uploadRef.value.clearFiles()
uploadForm.data = {
fileId: '',
name: '',
type: '',
size: null,
hash: '',
userName: store.getters.getUserName,
standId: store.getters.getStandId
}
file.value = undefined
}
const previewFile = () => {
}
</script>
<style scoped></style>