no message
parent
031a187db2
commit
c7c8ae9adc
|
|
@ -725,58 +725,49 @@ export default {
|
||||||
},
|
},
|
||||||
|
|
||||||
async confirmImport() {
|
async confirmImport() {
|
||||||
// 校验当前tab是否有文件
|
// 提取当前 tab 对应的文件信息
|
||||||
let hasFile = false;
|
const getFileFromTab = (tab) => {
|
||||||
let fileName = '';
|
const fileMap = {
|
||||||
let currentFile = null; // 新增变量存储文件对象
|
template1: this.fileList1,
|
||||||
|
template2: this.fileList2,
|
||||||
|
template3: this.fileList3,
|
||||||
|
};
|
||||||
|
const list = fileMap[tab] || [];
|
||||||
|
return list.length > 0 ? list[0] : null;
|
||||||
|
};
|
||||||
|
|
||||||
if (this.activeImportTab === 'template1') {
|
const currentFile = getFileFromTab(this.activeImportTab);
|
||||||
hasFile = this.fileList1.length > 0;
|
if (!currentFile || !currentFile.raw) {
|
||||||
if (hasFile) {
|
this.crud.notify('请先上传文件', CRUD.NOTIFICATION_TYPE.WARNING);
|
||||||
currentFile = this.fileList1[0]; // 获取文件对象
|
|
||||||
fileName = currentFile.name;
|
|
||||||
}
|
|
||||||
} else if (this.activeImportTab === 'template2') {
|
|
||||||
hasFile = this.fileList2.length > 0;
|
|
||||||
if (hasFile) {
|
|
||||||
currentFile = this.fileList2[0];
|
|
||||||
fileName = currentFile.name;
|
|
||||||
}
|
|
||||||
} else if (this.activeImportTab === 'template3') {
|
|
||||||
hasFile = this.fileList3.length > 0;
|
|
||||||
if (hasFile) {
|
|
||||||
currentFile = this.fileList3[0];
|
|
||||||
fileName = currentFile.name;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!hasFile || !currentFile) {
|
|
||||||
this.$message.warning('请先上传文件');
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const fileName = currentFile.name;
|
||||||
this.importLoading = true;
|
this.importLoading = true;
|
||||||
console.log('开始导入...' + this.activeImportTab + '文件:' + fileName);
|
console.log(`开始导入 ${this.activeImportTab} 文件: ${fileName}`);
|
||||||
|
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
// 修复:使用 currentFile.raw 获取原始文件对象
|
|
||||||
formData.append('file', currentFile.raw);
|
formData.append('file', currentFile.raw);
|
||||||
formData.append('templateType', this.activeImportTab);
|
formData.append('templateType', this.activeImportTab);
|
||||||
|
|
||||||
|
try {
|
||||||
const response = await importData.importAsnData(formData);
|
const response = await importData.importAsnData(formData);
|
||||||
|
console.log(response);
|
||||||
if (response.status === 200) {
|
if (response.status === 200) {
|
||||||
this.crud.notify(response.message, CRUD.NOTIFICATION_TYPE.SUCCESS)
|
this.crud.notify(response.message, CRUD.NOTIFICATION_TYPE.SUCCESS);
|
||||||
this.importDialogVisible = false;
|
this.importDialogVisible = false;
|
||||||
this.importLoading = false;
|
|
||||||
this.crud.toQuery(); // 刷新列表
|
this.crud.toQuery(); // 刷新列表
|
||||||
// 清空所有fileList
|
|
||||||
this.fileList1 = [];
|
|
||||||
this.fileList2 = [];
|
|
||||||
this.fileList3 = [];
|
|
||||||
} else {
|
|
||||||
this.crud.notify(response.message, CRUD.NOTIFICATION_TYPE.ERROR)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// 动态清空 fileList
|
||||||
|
['fileList1', 'fileList2', 'fileList3'].forEach(key => {
|
||||||
|
this[key] = [];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('导入失败:', error);
|
||||||
|
} finally {
|
||||||
|
this.importLoading = false;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
cancelImport() {
|
cancelImport() {
|
||||||
this.fileList1 = [];
|
this.fileList1 = [];
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue