新增功能:支持单独删除分析列表中的文件

This commit is contained in:
2026-01-11 11:49:44 +08:00
parent 223d4859d1
commit 463573235b
3 changed files with 75 additions and 2 deletions
+19
View File
@@ -129,6 +129,25 @@ def upload_file():
return jsonify({'error': '不支持的文件格式'}), 400
@app.route('/delete/<filename>', methods=['POST'])
def delete_file(filename):
"""删除指定的单个文件"""
try:
filename = secure_filename(filename)
upload_folder = app.config['UPLOAD_FOLDER']
filepath = os.path.join(upload_folder, filename)
if os.path.exists(filepath):
os.remove(filepath)
return jsonify({
'success': True,
'message': f'文件 {filename} 已成功删除'
})
else:
return jsonify({'error': '文件不存在'}), 404
except Exception as e:
return jsonify({'error': f'删除文件失败: {str(e)}'}), 500
@app.route('/cleanup', methods=['POST'])
def cleanup_files():
"""清理上传的文件(立即清理)"""
+31 -1
View File
@@ -244,7 +244,7 @@ body {
.file-tag {
font-size: 12px;
padding: 4px 12px;
padding: 4px 8px 4px 12px;
background: rgba(255, 255, 255, 0.6);
border: 1px solid #e2e8f0;
border-radius: 20px;
@@ -252,6 +252,9 @@ body {
cursor: pointer;
white-space: nowrap;
transition: all 0.2s;
display: inline-flex;
align-items: center;
gap: 8px;
}
.file-tag.active {
@@ -261,6 +264,33 @@ body {
font-weight: 500;
}
.delete-file-btn {
width: 18px;
height: 18px;
display: flex;
align-items: center;
justify-content: center;
border-radius: 50%;
transition: all 0.2s;
color: var(--text-tertiary);
font-size: 10px;
}
.delete-file-btn:hover {
background: rgba(239, 68, 68, 0.1);
color: #ef4444;
transform: scale(1.1);
}
.file-tag.active .delete-file-btn {
color: var(--primary-light);
}
.file-tag.active .delete-file-btn:hover {
background: rgba(239, 68, 68, 0.2);
color: #ef4444;
}
/* Dashboard Grid */
.summary-cards {
display: grid;
+25 -1
View File
@@ -356,11 +356,35 @@ function renderFileList(files) {
elements.fileSelector.style.display = 'flex';
elements.fileList.innerHTML = files.map(f => `
<div class="file-tag ${f.filename === state.currentFile ? 'active' : ''}" onclick="loadFile('${f.filename}')">
${f.original_name}
<span class="file-name">${f.original_name}</span>
<i class="fas fa-times delete-file-btn" onclick="deleteFile('${f.filename}', event)" title="删除此文件"></i>
</div>
`).join('');
}
function deleteFile(filename, event) {
if (event) event.stopPropagation();
if (!confirm('确认删除此文件?')) return;
fetch(`/delete/${filename}`, { method: 'POST' })
.then(res => res.json())
.then(data => {
if (data.success) {
if (state.currentFile === filename) {
state.currentFile = null;
state.allData = null;
state.filteredData = null;
elements.noData.style.display = 'flex';
elements.dataDisplay.style.display = 'none';
}
loadFileList();
} else {
alert(data.error || '删除失败');
}
})
.catch(err => alert('删除错误: ' + err.message));
}
// --- Utils ---
function openUploadModal() {