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