diff --git a/app.py b/app.py index 4d67c30..312a033 100644 --- a/app.py +++ b/app.py @@ -129,6 +129,25 @@ def upload_file(): return jsonify({'error': '不支持的文件格式'}), 400 +@app.route('/delete/', 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(): """清理上传的文件(立即清理)""" diff --git a/static/css/style.css b/static/css/style.css index e304f05..a0ec36a 100644 --- a/static/css/style.css +++ b/static/css/style.css @@ -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; diff --git a/static/js/main.js b/static/js/main.js index ca64f72..c596645 100644 --- a/static/js/main.js +++ b/static/js/main.js @@ -356,11 +356,35 @@ function renderFileList(files) { elements.fileSelector.style.display = 'flex'; elements.fileList.innerHTML = files.map(f => `
- ${f.original_name} + ${f.original_name} +
`).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() {