feat: 文件上传优化loading

dev2.5_scan
chenhc 3 days ago
parent 367fa63866
commit 15c8f6c984

@ -394,7 +394,7 @@
<!-- v-if="(curAction.checkWebNew !== 2 || viewType !== 1) && orderFormData.billNo"--> <!-- v-if="(curAction.checkWebNew !== 2 || viewType !== 1) && orderFormData.billNo"-->
</el-button </el-button
> >
<el-button size="mini" type="primary" @click="triggerFileUpload" icon="el-icon-upload2" <el-button size="mini" type="primary" @click="triggerFileUpload" icon="el-icon-upload2" :loading="this.loading"
v-if="curAction.checkWebNew != 2 || viewType !=1" v-if="curAction.checkWebNew != 2 || viewType !=1"
> >
导入阳采追溯码 导入阳采追溯码
@ -848,14 +848,26 @@ export default {
this.$refs.fileInput.click(); this.$refs.fileInput.click();
}, },
triggerFileUpload2() { triggerFileUpload2() {
this.$refs.fileInput2.click(); this.$refs.fileInput2.click();
}, },
handleFileUpload(event) { handleFileUpload(event) {
//
const loading = this.$loading({
lock: true,
text: '数据提交中,请稍候',
spinner: 'el-icon-loading',
background: 'rgba(0, 0, 0, 0.7)'
});
const file = event.target.files[0]; const file = event.target.files[0];
const billNo = this.orderFormData.billNo; const billNo = this.orderFormData.billNo;
const uploadUrl = process.env.VUE_APP_BASE_API + '/udiwms/inout/order/yc/fileUpload'; const uploadUrl = process.env.VUE_APP_BASE_API + '/udiwms/inout/order/yc/fileUpload';
if (this.$isBlank(this.orderFormData.billNo)) { if (this.$isBlank(this.orderFormData.billNo)) {
//
loading.close();
this.$message.error("单据编号不可以为空!"); this.$message.error("单据编号不可以为空!");
return; return;
} }
@ -876,12 +888,16 @@ export default {
}) })
.then(response => { .then(response => {
if (!response.ok) { if (!response.ok) {
//
loading.close();
throw new Error(`HTTP error! Status: ${response.status}`); throw new Error(`HTTP error! Status: ${response.status}`);
} }
return response.json(); return response.json();
}) })
.then(data => { .then(data => {
if (data.code === 20000) { if (data.code === 20000) {
//
loading.close();
// //
if (data.data && data.data.billNo) { if (data.data && data.data.billNo) {
this.orderFormData.billNo = data.data.billNo; this.orderFormData.billNo = data.data.billNo;
@ -895,6 +911,8 @@ export default {
} }
}) })
.catch(error => { .catch(error => {
//
loading.close();
console.error('File upload failed:', error); console.error('File upload failed:', error);
this.$message.error('文件上传失败:' + error.message); this.$message.error('文件上传失败:' + error.message);
}); });
@ -902,8 +920,19 @@ export default {
// //
event.target.value = ''; event.target.value = '';
//
loading.close();
}, },
handleFileUpload2(event) { handleFileUpload2(event) {
//
const loading = this.$loading({
lock: true,
text: '数据提交中,请稍候',
spinner: 'el-icon-loading',
background: 'rgba(0, 0, 0, 0.7)'
});
const file = event.target.files[0]; const file = event.target.files[0];
const uploadUrl = process.env.VUE_APP_BASE_API + '/udiwms/inout/order/yc/orderFileUpload'; const uploadUrl = process.env.VUE_APP_BASE_API + '/udiwms/inout/order/yc/orderFileUpload';
@ -925,12 +954,16 @@ export default {
}) })
.then(response => { .then(response => {
if (!response.ok) { if (!response.ok) {
//
loading.close();
throw new Error(`HTTP error! Status: ${response.status}`); throw new Error(`HTTP error! Status: ${response.status}`);
} }
return response.json(); return response.json();
}) })
.then(data => { .then(data => {
if (data.code === 20000) { if (data.code === 20000) {
//
loading.close();
// //
if (data.data && data.data.billNo) { if (data.data && data.data.billNo) {
this.orderFormData.billNo = data.data.billNo; this.orderFormData.billNo = data.data.billNo;
@ -954,15 +987,21 @@ export default {
} }
}) })
.catch(error => { .catch(error => {
//
loading.close();
console.error('File upload failed:', error); console.error('File upload failed:', error);
this.$message.error('文件上传失败:' + error.message); this.$message.error('文件上传失败:' + error.message);
}); });
} else { } else {
//
loading.close();
this.$message.warning('请选择要上传的文件'); this.$message.warning('请选择要上传的文件');
} }
// //
event.target.value = ''; event.target.value = '';
//
loading.close();
}, },
// //
findInvListByUser() { findInvListByUser() {
@ -2034,6 +2073,7 @@ export default {
<style scoped> <style scoped>
</style> </style>

Loading…
Cancel
Save