From 61845699b3898907bbc127b14abf867e385474de Mon Sep 17 00:00:00 2001 From: Orion Date: Fri, 18 Sep 2026 10:29:20 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(frontend):=20=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E5=9B=9E=E6=94=B6=E7=AB=99=E6=B8=85=E7=90=86=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5=E6=8F=90=E7=A4=BA=E4=B8=8E=E6=81=A2=E5=A4=8D=E6=96=87?= =?UTF-8?q?=E6=A1=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/manage/TrashView.vue | 9 ++++---- tests/README.md | 7 ++++++ tests/purgeFailure.browser.mjs | 39 +++++++++++++++++++++++++++++++++ tests/trashWorkflow.browser.mjs | 4 ++-- 4 files changed, 53 insertions(+), 6 deletions(-) create mode 100644 tests/purgeFailure.browser.mjs diff --git a/src/views/manage/TrashView.vue b/src/views/manage/TrashView.vue index c157781..1844281 100644 --- a/src/views/manage/TrashView.vue +++ b/src/views/manage/TrashView.vue @@ -4,7 +4,7 @@

回收站

-

删除文件会先保留在这里;恢复后将生成新的 8 位取件码。

+

删除文件会先保留在这里;恢复后沿用原取件码。

清理设置 @@ -32,7 +32,7 @@

{{ resultText }}

@@ -80,6 +80,7 @@

将永久清理所选 {{ purgeIds.length }} 条记录的文件本体。此操作不可恢复,审计记录和取件历史仍保留。

+
@@ -174,7 +175,7 @@ const executeBatch = async (action: TrashBatchRequest['action'], ids: number[], } catch (error) { errorText.value = getErrorMessage(error, '操作失败,请重试'); return false } finally { busy.value = false } } -const restore = (item: TrashFileItem) => supportsBatch.value ? executeBatch('restore', [item.id]) : runSingle(() => restoreTrashItem(item.id), '已恢复,请到文件管理查看新取件码') +const restore = (item: TrashFileItem) => supportsBatch.value ? executeBatch('restore', [item.id]) : runSingle(() => restoreTrashItem(item.id), '已恢复,请到文件管理查看取件码') const makePermanent = (item: TrashFileItem) => supportsBatch.value ? executeBatch('retention', [item.id], { retentionDays: 0 }) : runSingle(() => updateTrashRetention(item.id, { retentionDays: 0 }), '已设为永久保留') const retentionOpen = ref(false), retentionIds = ref([]), retainForever = ref(false), cleanupTime = ref(''), dialogError = ref('') const localDateTime = (date: Date) => `${date.getFullYear()}-${String(date.getMonth()+1).padStart(2,'0')}-${String(date.getDate()).padStart(2,'0')}T${String(date.getHours()).padStart(2,'0')}:${String(date.getMinutes()).padStart(2,'0')}` @@ -196,7 +197,7 @@ const saveRetention = async () => { } catch (error) { dialogError.value = getErrorMessage(error, '请选择有效的清理时间') } } const purgeOpen = ref(false), purgeIds = ref([]) -const askPurge = (ids: number[]) => { purgeIds.value = [...ids]; purgeOpen.value = true } +const askPurge = (ids: number[]) => { errorText.value = ''; purgeIds.value = [...ids]; purgeOpen.value = true } const confirmPurge = async () => { const ok = supportsBatch.value ? await executeBatch('purge', purgeIds.value) : await runSingle(() => purgeTrashItem(purgeIds.value[0]), '文件本体已清理,审计记录已保留') if (ok || operationResult.value) purgeOpen.value = false diff --git a/tests/README.md b/tests/README.md index 0e02908..357bdbf 100644 --- a/tests/README.md +++ b/tests/README.md @@ -54,3 +54,10 @@ inner cards and action buttons retain their motion. List rows only fade their background with no border or box-shadow. Light card shadows are bright at the upper left and shaded at the lower right; dark mode reverses that direction. Primary submit actions must not add white/gradient hover overlays. + +## 清理失败弹窗 + +`purgeFailure.browser.mjs` 导出 `runPurgeFailureChecks(page, failure)`,接受独立 +Playwright Page。Vite 固定运行于 `127.0.0.1:5180`;分别传入 `http` 和 `network` +验证服务端 500、断网时错误显示于弹窗内、原记录保留,以及重新打开时清空旧错误。 +测试拦截全部管理 API,不会修改部署实例。 diff --git a/tests/purgeFailure.browser.mjs b/tests/purgeFailure.browser.mjs new file mode 100644 index 0000000..caeed2d --- /dev/null +++ b/tests/purgeFailure.browser.mjs @@ -0,0 +1,39 @@ +import assert from 'node:assert/strict' + +// Call with a fresh Playwright page and the local Vite fixture; all API calls +// are intercepted, so this check cannot modify a deployed backend. +export async function runPurgeFailureChecks(page, failure = 'http') { + await page.route('**/*', route => { + const url = new URL(route.request().url()) + return url.hostname === '127.0.0.1' ? route.continue() : route.abort() + }) + await page.route('**/admin/**', async route => { + const url = new URL(route.request().url()) + const headers = { 'access-control-allow-origin': '*', 'access-control-allow-headers': '*', 'access-control-allow-methods': '*' } + if (route.request().method() === 'OPTIONS') return route.fulfill({ status: 204, headers }) + if (url.pathname === '/admin/trash/list') { + return route.fulfill({ json: { code: 200, detail: { + page: 1, size: 20, total: 1, + data: [{ id: 900001, name: 'isolated-check.txt', code: 'CHECK001', size: 16, + isTrashPurged: false, isTrashPermanent: true, trashReason: 'manual' }], + capabilities: { batch: true, filters: true, customRetention: true }, + summary: { total: 1, recoverable: 1, purged: 0 } + } }, headers }) + } + if (url.pathname === '/admin/trash/batch') { + assert.deepEqual(route.request().postDataJSON(), { action: 'purge', ids: [900001] }) + return failure === 'network' ? route.abort() : route.fulfill({ status: 500, json: { detail: '测试服务暂时不可用' }, headers }) + } + throw new Error(`Unexpected API request: ${url.pathname}`) + }) + await page.goto('http://127.0.0.1:5180/theme-assets/tests/trash-workflow.html') + await page.getByRole('button', { name: '彻底删除', exact: true }).click() + const dialog = page.getByRole('dialog') + await dialog.getByRole('button', { name: '确认清理 1 项' }).click() + await dialog.getByRole('alert').waitFor({ state: 'visible', timeout: 4000 }) + assert.ok((await dialog.getByRole('alert').textContent()).trim()) + assert.equal(await page.locator('article').count(), 1) + await dialog.getByRole('button', { name: '取消', exact: true }).click() + await page.getByRole('button', { name: '彻底删除', exact: true }).click() + assert.equal(await page.getByRole('dialog').getByRole('alert').count(), 0) +} diff --git a/tests/trashWorkflow.browser.mjs b/tests/trashWorkflow.browser.mjs index 3fcc0a5..b10076a 100644 --- a/tests/trashWorkflow.browser.mjs +++ b/tests/trashWorkflow.browser.mjs @@ -48,8 +48,8 @@ export async function runTrashWorkflowChecks() { const selectable=[...document.querySelectorAll('article input')].filter(e=>!e.disabled) selectable[0].click();await new Promise(r=>setTimeout(r,0));selectable[1].click();await new Promise(r=>setTimeout(r,0));await wait(()=>button('批量恢复'));assert([...document.querySelectorAll('article input')].filter(e=>e.checked).length===2,'未选中两条记录') button('批量恢复').click();await wait(()=>document.querySelectorAll('article').length===4) - assert(document.querySelectorAll('code').length===2,'未展示恢复后的新取件码') - done('通过:批量恢复、列表刷新和新取件码展示') + assert(document.querySelectorAll('code').length===2,'未展示恢复后的取件码') + done('通过:批量恢复、列表刷新和取件码展示') document.querySelector('input[type=checkbox]').click();await wait(()=>button('批量清理')) button('批量清理').click();await wait(()=>document.querySelector('[role=dialog]')) modal=document.querySelector('[role=dialog]');assert(modal.textContent.includes('不可恢复')&&modal.textContent.includes('3'),'缺少删除数量或后果提示')