From be6db84da0e6c8c8fc792da4dada98f8aa8cea74 Mon Sep 17 00:00:00 2001 From: leiyun Date: Fri, 7 Aug 2026 00:41:08 +0800 Subject: [PATCH] feat: add work deletion actions --- app/components/WorkDetailModal.vue | 48 ++++++++++++++++++++++- app/pages/works.vue | 61 +++++++++++++++++++++++++++++- 2 files changed, 105 insertions(+), 4 deletions(-) diff --git a/app/components/WorkDetailModal.vue b/app/components/WorkDetailModal.vue index 14d9c0e..ac46c3c 100644 --- a/app/components/WorkDetailModal.vue +++ b/app/components/WorkDetailModal.vue @@ -160,6 +160,16 @@
+
- +
@@ -263,6 +271,55 @@ function openWork(item) { detailOpen.value = true } +function resolveWorkId(item = {}) { + return item.photo_open_id || item.chat_open_id || item.id || '' +} + +function getDeleteRequest(item = {}) { + const id = resolveWorkId(item) + if (!id) return null + if (item.work_type === 'photo') return { path: '/idphoto/del', body: { photo_open_id: id } } + if (item.work_type === 'oldphoto') return { path: '/oldphoto/del', body: { photo_open_id: id } } + if (item.work_type === 'portrait') return { path: '/portrait/del', body: { photo_open_id: id } } + if (item.work_type === 'ainame') return { path: '/ainame/del', body: { chat_open_id: id } } + if (item.work_type === 'anime') return { path: '/anime/del', body: { chat_open_id: id } } + return { path: '/chat/del', body: { chat_open_id: id } } +} + +function removeDeletedFromList(item = {}) { + const id = String(resolveWorkId(item)) + if (!id) return + const deleted = list.value.find(row => String(resolveWorkId(row)) === id) + list.value = list.value.filter(row => String(resolveWorkId(row)) !== id) + if (deleted) { + total.value = Math.max(0, total.value - 1) + const type = deleted.work_type || 'all' + counts.value = { + ...counts.value, + all: Math.max(0, Number(counts.value.all || 0) - 1), + [type]: Math.max(0, Number(counts.value[type] || 0) - 1), + } + } +} + +async function deleteWork(item) { + const req = getDeleteRequest(item) + if (!req) return + if (!window.confirm('确认删除该作品记录?删除后将不再展示。')) return + try { + await post(req.path, req.body) + removeDeletedFromList(item) + toast.add({ title: '删除成功', color: 'success' }) + } catch (e) { + toast.add({ title: e.message || '删除失败', color: 'error' }) + } +} + +function handleDeleted(item) { + removeDeletedFromList(item) + fetchList(true, true) +} + function statusClass(item) { const status = Number(item.status) if (status === 0) return 'bg-[var(--c-fff5e8)] text-[var(--c-ff8a00)]'