新增功能:支持单独删除分析列表中的文件
This commit is contained in:
@@ -129,6 +129,25 @@ def upload_file():
|
|||||||
|
|
||||||
return jsonify({'error': '不支持的文件格式'}), 400
|
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'])
|
@app.route('/cleanup', methods=['POST'])
|
||||||
def cleanup_files():
|
def cleanup_files():
|
||||||
"""清理上传的文件(立即清理)"""
|
"""清理上传的文件(立即清理)"""
|
||||||
|
|||||||
+31
-1
@@ -244,7 +244,7 @@ body {
|
|||||||
|
|
||||||
.file-tag {
|
.file-tag {
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
padding: 4px 12px;
|
padding: 4px 8px 4px 12px;
|
||||||
background: rgba(255, 255, 255, 0.6);
|
background: rgba(255, 255, 255, 0.6);
|
||||||
border: 1px solid #e2e8f0;
|
border: 1px solid #e2e8f0;
|
||||||
border-radius: 20px;
|
border-radius: 20px;
|
||||||
@@ -252,6 +252,9 @@ body {
|
|||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
transition: all 0.2s;
|
transition: all 0.2s;
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.file-tag.active {
|
.file-tag.active {
|
||||||
@@ -261,6 +264,33 @@ body {
|
|||||||
font-weight: 500;
|
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 */
|
/* Dashboard Grid */
|
||||||
.summary-cards {
|
.summary-cards {
|
||||||
display: grid;
|
display: grid;
|
||||||
|
|||||||
+25
-1
@@ -356,11 +356,35 @@ function renderFileList(files) {
|
|||||||
elements.fileSelector.style.display = 'flex';
|
elements.fileSelector.style.display = 'flex';
|
||||||
elements.fileList.innerHTML = files.map(f => `
|
elements.fileList.innerHTML = files.map(f => `
|
||||||
<div class="file-tag ${f.filename === state.currentFile ? 'active' : ''}" onclick="loadFile('${f.filename}')">
|
<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>
|
</div>
|
||||||
`).join('');
|
`).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 ---
|
// --- Utils ---
|
||||||
|
|
||||||
function openUploadModal() {
|
function openUploadModal() {
|
||||||
|
|||||||
Reference in New Issue
Block a user