diff --git a/src/api/module/cms.ts b/src/api/module/cms.ts index 64cb180..8f3a8e0 100644 --- a/src/api/module/cms.ts +++ b/src/api/module/cms.ts @@ -166,7 +166,7 @@ class ArticleApi { class AttachmentApi { page(siteId: number, orphanOnly: boolean, page: number, pageSize: number) { - return get & { orphanCount: number }>(`${ATTACHMENT}/page`, { + return get & { unusedCount: number }>(`${ATTACHMENT}/page`, { siteId, orphanOnly, page, diff --git a/src/types/cms.ts b/src/types/cms.ts index c9449d1..c7ce9aa 100644 --- a/src/types/cms.ts +++ b/src/types/cms.ts @@ -173,11 +173,14 @@ export interface AttachmentVo { id: number; siteId: number; articleId?: number; + /** 场景引用类型(B2):banner/link/site;空=无场景引用 */ + refType?: string; fileName: string; url: string; fileSize?: number; mimeType?: string; createTime?: string; + /** 未使用(B2 语义:无文章引用且无场景引用) */ orphan: boolean; } diff --git a/src/views/cms/ArticleList.vue b/src/views/cms/ArticleList.vue index 4ac25d2..09d1e18 100644 --- a/src/views/cms/ArticleList.vue +++ b/src/views/cms/ArticleList.vue @@ -174,7 +174,7 @@ function doDelete(row: ArticlePageItem) { MyConfirm({ title: "删除文章", msg: `确定删除「${row.title}」吗?`, - info: "删除后正文图片将转为孤儿附件,可在附件管理中清理", + info: "删除后正文图片将转为未使用附件,可在附件管理中清理", async onOk() { await articleApi.delete({ id: row.id, siteId: store.siteId! }).send(); Message.success("操作成功!"); diff --git a/src/views/cms/AttachmentManage.vue b/src/views/cms/AttachmentManage.vue index 9a5c229..20eff5d 100644 --- a/src/views/cms/AttachmentManage.vue +++ b/src/views/cms/AttachmentManage.vue @@ -11,7 +11,7 @@ const store = useCmsStore(); const rows = ref([]); const total = ref(0); -const orphanCount = ref(0); +const unusedCount = ref(0); const loading = ref(false); const pageNum = ref(1); const pageSize = ref(parseInt(localStorage.getItem("customPageCount") || "10")); @@ -32,16 +32,17 @@ const columns = [ }, { title: "大小", key: "fileSize", width: 100, render: (h: any, p: any) => h("span", Utils.getFileSize(p.row.fileSize || 0)) }, { - title: "关联文章", - key: "articleId", - width: 100, + title: "用途", + key: "usage", + width: 110, align: "center", - render: (h: any, p: any) => - h( - Tag, - { color: p.row.orphan ? "warning" : "default" }, - () => (p.row.orphan ? "孤儿" : p.row.articleId) - ), + render: (h: any, p: any) => { + // B2 引用模型:文章(articleId)优先,其次场景引用(banner/link/site),均无=未使用 + const usage = p.row.articleId + ? "文章" + : { banner: "轮播", link: "友链", site: "站点配置" }[p.row.refType as string] || "未使用"; + return h(Tag, { color: usage === "未使用" ? "warning" : "default" }, () => usage); + }, }, { title: "上传时间", key: "createTime", width: 170 }, { @@ -68,7 +69,7 @@ async function run() { .send(); rows.value = page?.list || []; total.value = page?.total || 0; - orphanCount.value = (page as any)?.orphanCount || 0; + unusedCount.value = (page as any)?.unusedCount || 0; } finally { loading.value = false; } @@ -95,9 +96,9 @@ function doDelete(row: AttachmentVo) { function cleanOrphans() { MyConfirm({ - title: "清理孤儿附件", - msg: `当前共有 ${orphanCount.value} 条孤儿附件记录(关联文章已删除),仅清理列表页中勾选的记录。`, - info: "为避免误删被封面/轮播引用的文件,MVP 不提供一键全清", + title: "查看未使用附件", + msg: `当前共有 ${unusedCount.value} 条未使用附件记录(无文章引用且无场景引用),点击确定切换到未使用列表。`, + info: "为避免误删被引用的文件,MVP 不提供一键全清;旧数据在重新保存对应内容前显示为未使用属正常现象", onOk() { filter.orphanOnly = true; pageNum.value = 1; @@ -140,11 +141,11 @@ watch(() => store.siteId, () => {
- 仅看孤儿附件 + 仅看未使用附件
store.siteId, () => run()); store.siteId, () => run());