多文件上传累积模式,前端文件列表支持删除,后端接收前端指定的文件列表
This commit is contained in:
@@ -64,29 +64,49 @@ if (fileInput) {
|
||||
fileInput.addEventListener('click', (e) => e.stopPropagation());
|
||||
}
|
||||
|
||||
// Track all uploaded file paths for this session
|
||||
let uploadedFilePaths = [];
|
||||
|
||||
async function handleFiles(files) {
|
||||
if (files.length === 0) return;
|
||||
|
||||
fileList.innerHTML = '';
|
||||
const formData = new FormData();
|
||||
|
||||
for (const file of files) {
|
||||
formData.append('files', file);
|
||||
const fileItem = document.createElement('div');
|
||||
fileItem.className = 'file-item';
|
||||
fileItem.innerHTML = `<i class="fa-regular fa-file-excel"></i> ${file.name}`;
|
||||
fileList.appendChild(fileItem);
|
||||
}
|
||||
|
||||
try {
|
||||
const res = await fetch('/api/upload', { method: 'POST', body: formData });
|
||||
if (!res.ok) alert('Upload failed');
|
||||
if (!res.ok) { alert('Upload failed'); return; }
|
||||
const data = await res.json();
|
||||
// Accumulate uploaded paths
|
||||
if (data.paths) {
|
||||
uploadedFilePaths = uploadedFilePaths.concat(data.paths);
|
||||
}
|
||||
renderFileList();
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
alert('Upload failed');
|
||||
}
|
||||
}
|
||||
|
||||
function renderFileList() {
|
||||
fileList.innerHTML = '';
|
||||
for (let i = 0; i < uploadedFilePaths.length; i++) {
|
||||
const fname = uploadedFilePaths[i].split('/').pop().split('\\').pop();
|
||||
const fileItem = document.createElement('div');
|
||||
fileItem.className = 'file-item';
|
||||
fileItem.innerHTML = `<i class="fa-regular fa-file-excel"></i> ${fname}
|
||||
<span class="file-remove" onclick="removeUploadedFile(${i})" title="移除">×</span>`;
|
||||
fileList.appendChild(fileItem);
|
||||
}
|
||||
}
|
||||
|
||||
window.removeUploadedFile = function(index) {
|
||||
uploadedFilePaths.splice(index, 1);
|
||||
renderFileList();
|
||||
}
|
||||
|
||||
// --- Template Logic ---
|
||||
async function loadTemplates() {
|
||||
try {
|
||||
@@ -142,6 +162,9 @@ async function startAnalysis() {
|
||||
if (selectedTemplate) {
|
||||
body.template = selectedTemplate;
|
||||
}
|
||||
if (uploadedFilePaths.length > 0) {
|
||||
body.files = uploadedFilePaths;
|
||||
}
|
||||
|
||||
const res = await fetch('/api/start', {
|
||||
method: 'POST',
|
||||
|
||||
Reference in New Issue
Block a user