feat: batch delete
This commit is contained in:
@@ -92,6 +92,8 @@
|
||||
.btn:disabled { background: var(--text-dim); cursor: not-allowed; }
|
||||
.btn.ghost { background: var(--panel-2); }
|
||||
.btn.danger { background: var(--danger); }
|
||||
.btn.ghost.danger { background: var(--panel-2); color: var(--danger); border: 1px solid var(--danger); }
|
||||
.btn.ghost.danger:hover { background: var(--danger); color: #0f1115; }
|
||||
.btn-row { display: flex; gap: 12px; margin-top: 16px; flex-wrap: wrap; align-items: center; }
|
||||
|
||||
/* Progress */
|
||||
|
||||
+3
-1
@@ -21,13 +21,15 @@ const checkAll = $('checkAll');
|
||||
const checkAllWrap = $('checkAllWrap');
|
||||
const batchBtn = $('batchBtn');
|
||||
const batchCount = $('batchCount');
|
||||
const batchDeleteBtn = $('batchDeleteBtn');
|
||||
const batchDeleteCount= $('batchDeleteCount');
|
||||
|
||||
// pending[i] = { id, file, xhr, status: 'pending'|'uploading'|'done'|'error'|'cancelled', progress, error }
|
||||
let pending = [];
|
||||
let nextId = 1;
|
||||
let isUploading = false;
|
||||
|
||||
// selectedFiles 在 batch.js 顶层 var 声明, 同 <script> 内共享.
|
||||
// selectedFiles 在 batch.js 顶层 var 声明, 跨文件共享 (classic <script> 加载顺序: app.js → helpers.js → batch.js).
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Toast
|
||||
|
||||
+35
-4
@@ -1,9 +1,9 @@
|
||||
'use strict';
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// 批量选择 / 批量下载 (依赖 app.js 的 consts: checkAll, checkAllWrap,
|
||||
// batchBtn, batchCount, filesList, toast)
|
||||
// 用 var 顶层声明, 与 app.js 同 <script> 内共享 (loadFiles / fileRow 读写).
|
||||
// 批量选择 / 批量下载 / 批量删除 (依赖 app.js 的 consts: checkAll, checkAllWrap,
|
||||
// batchBtn, batchCount, batchDeleteBtn, batchDeleteCount, filesList, toast)
|
||||
// 用 var 顶层声明, 跨文件共享 (classic <script> 加载顺序: app.js → helpers.js → batch.js).
|
||||
// ---------------------------------------------------------------------------
|
||||
var selectedFiles = new Set();
|
||||
|
||||
@@ -17,6 +17,8 @@ function updateBatchUI() {
|
||||
const n = selectedFiles.size;
|
||||
batchCount.textContent = n;
|
||||
batchBtn.style.display = n > 0 ? 'inline-block' : 'none';
|
||||
batchDeleteCount.textContent = n;
|
||||
batchDeleteBtn.style.display = n > 0 ? 'inline-block' : 'none';
|
||||
|
||||
const checks = filesList.querySelectorAll('.file-check');
|
||||
if (checks.length === 0) {
|
||||
@@ -81,8 +83,37 @@ batchBtn.addEventListener('click', async () => {
|
||||
}
|
||||
});
|
||||
|
||||
batchDeleteBtn.addEventListener('click', async () => {
|
||||
if (selectedFiles.size === 0) return;
|
||||
const names = [...selectedFiles];
|
||||
if (!confirm(`确定删除选中的 ${names.length} 个文件吗? 该操作不可恢复.`)) return;
|
||||
batchDeleteBtn.disabled = true;
|
||||
const restore = () => { batchDeleteBtn.disabled = false; batchDeleteBtn.textContent = `批量删除 (${selectedFiles.size})`; };
|
||||
batchDeleteBtn.textContent = '删除中...';
|
||||
try {
|
||||
const r = await fetch('/files-delete', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ files: names }),
|
||||
});
|
||||
if (!r.ok) {
|
||||
let msg = 'HTTP ' + r.status;
|
||||
try { msg = (await r.json()).error || msg; } catch {}
|
||||
throw new Error(msg);
|
||||
}
|
||||
const data = await r.json();
|
||||
toast(`已删除 ${data.deleted} 个文件`, 'success');
|
||||
selectedFiles.clear();
|
||||
await loadFiles();
|
||||
} catch (e) {
|
||||
toast('批量删除失败: ' + e.message, 'error');
|
||||
} finally {
|
||||
restore();
|
||||
}
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Boot (从 app.js 末尾移过来, 确保 selectedFiles 已声明再启动首次 loadFiles)
|
||||
// ---------------------------------------------------------------------------
|
||||
loadFiles();
|
||||
setInterval(loadFiles, 30000);
|
||||
setInterval(loadFiles, 30000);
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// 纯函数 + 倒计时 interval
|
||||
// 与 app.js 同 <script> 内共享 (load order: app → helpers → batch).
|
||||
// 跨文件共享 (classic <script> 加载顺序: app.js → helpers.js → batch.js).
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function formatRemain(iso) {
|
||||
|
||||
@@ -4,8 +4,7 @@
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>临时文件上传 · TTL 24h</title>
|
||||
<style>
|
||||
/*EMBED_CSS*/</style>
|
||||
<link rel="stylesheet" href="/static/app.css" />
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
@@ -42,6 +41,7 @@
|
||||
</label>
|
||||
<span class="meta" id="filesMeta">加载中...</span>
|
||||
<button class="btn ghost batch-btn" id="batchBtn" style="display:none">批量下载 (<span id="batchCount">0</span>)</button>
|
||||
<button class="btn ghost batch-btn danger" id="batchDeleteBtn" style="display:none">批量删除 (<span id="batchDeleteCount">0</span>)</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="quota-wrap" id="quotaWrap" style="display:none">
|
||||
@@ -62,7 +62,8 @@
|
||||
|
||||
<div class="toast" id="toast"></div>
|
||||
|
||||
<script>
|
||||
/*EMBED_JS*/</script>
|
||||
<script src="/static/app.js"></script>
|
||||
<script src="/static/helpers.js"></script>
|
||||
<script src="/static/batch.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user