fix(XZH-21): 统一回收站路由与模块标签、历史旧口径对齐、升级后会话不再误判
- AdminTools.vue: 回收站恢复/永久删除统一走 /admin-tools/trash/{kind}/{id}(RSS/提示词/工作流/收集箱此前拼到 /library → 404);模块标签改由后端 /admin-tools/trash/kinds 提供;过滤下拉覆盖全部 11 个模块
- adminRoutes.ts: moduleNames 与后端 TrashService 对齐(笔记/素材…),补 prompts/flows/inbox
- AdminToolsController: TRASH 视图限定 planner kind;新增 GET /admin-tools/trash/kinds
- LibraryController: /library/{kind}/trash 接受全部 kind,与 /admin-tools/trash 行为一致;删除通知标题列改用 TrashService.titleColumn(笔记不再写成素材)
- NotesController: history/{n} 对旧口径行按「≤n 的最大旧版本号」解析,旧库升级后最高一版保存前内容可读、恢复写回正确内容
- App.vue: 401 先确认 /auth/me,避免切模块时偶发 401 清掉登录态导致白屏
This commit is contained in:
1 parent
a60ea8d262
commit
bd8264b8cf
6 files changed
+84
-30
No files matched your search
@@ -6,11 +6,12 @@ import BookmarkTransfer from "./BookmarkTransfer.vue";
|
||||
import Icon from "./Icon.vue";
|
||||
import NoteHistory from "./NoteHistory.vue";
|
||||
import { moduleNames, toolPages } from "./adminRoutes";
|
||||
import type { ModuleKind, ToolId } from "./adminRoutes";
|
||||
import type { ModuleKind, PlannerKind, ToolId } from "./adminRoutes";
|
||||
import type { LibraryNote } from "./library";
|
||||
|
||||
interface Summary { tags:number; versions:number; trash:number; flows:number; inbox:number }
|
||||
interface Row { id:string; title:string; kind:ModuleKind; deleted_at:string; versions:number; folder:string; category:string }
|
||||
interface TrashKind { kind:ModuleKind; label:string; titleColumn:string; planner:boolean }
|
||||
interface Flow { id:string; title:string; instructions:string }
|
||||
interface Run { id:string; title:string; result:string; created_at:string }
|
||||
const props=defineProps<{ page:ToolId|"tools"; summary:Summary }>();
|
||||
@@ -21,7 +22,11 @@ const flows=ref<Flow[]>([]);
|
||||
const runs=ref<Run[]>([]);
|
||||
const result=ref<Run|null>(null);
|
||||
const kind=ref<ModuleKind|"">("");
|
||||
const batchKind=ref<Exclude<ModuleKind,"rss">>("notes");
|
||||
const trashKinds=ref<TrashKind[]>([]);
|
||||
// 回收站模块标签由后端 /admin-tools/trash/kinds 给出,新增模块不用再同步前端
|
||||
const kindLabels=computed<Partial<Record<ModuleKind,string>>>(() =>
|
||||
Object.fromEntries(trashKinds.value.map(item=>[item.kind,item.label])));
|
||||
const batchKind=ref<"notes"|"blogs"|"assets"|"bookmarks"|PlannerKind>("notes");
|
||||
const categories=ref<string[]>([]);
|
||||
const selected=ref<string[]>([]);
|
||||
const query=ref("");
|
||||
@@ -54,6 +59,7 @@ async function load() {
|
||||
busy.value=true; error.value="";
|
||||
try {
|
||||
const params=new URLSearchParams({q:query.value,kind:kind.value,offset:String(offset.value)});
|
||||
if(props.page==="trash" && !trashKinds.value.length) trashKinds.value=await api<TrashKind[]>("/admin-tools/trash/kinds");
|
||||
if(props.page==="tags") {
|
||||
const list=await api<typeof tags.value>("/admin-tools/tags");
|
||||
if(sequence===request) tags.value=list;
|
||||
@@ -98,12 +104,13 @@ async function removeTag(tag:string) {
|
||||
if(await confirm("将从使用此标签的记录中移除标签。","删除标签"))
|
||||
await update(()=>api("/admin-tools/tags?"+new URLSearchParams({name:tag}),{method:"DELETE"}));
|
||||
}
|
||||
// 统一回收站的所有模块(含 RSS/提示词/工作流/收集箱)都走 /admin-tools/trash,不再按模块拼 /library
|
||||
async function trash(row:Row,remove:boolean) {
|
||||
if(remove && !(await confirm("永久删除后无法恢复。","永久删除"))) return;
|
||||
const path=(row.kind==="tasks" || row.kind==="events" || row.kind==="snippets"
|
||||
? "/admin-tools/trash/"+row.kind : "/library/"+row.kind+"/trash")+"/"+row.id;
|
||||
await update(()=>api(path,{method:remove?"DELETE":"POST"}));
|
||||
await update(()=>api("/admin-tools/trash/"+row.kind+"/"+row.id,{method:remove?"DELETE":"POST"}));
|
||||
}
|
||||
// 回收站标签:有分类列为空的模块(待办/日程/代码片段/RSS/工作流/收集箱)显示分类,其余只显示模块名
|
||||
function kindOf(row:Row) { return kindLabels.value[row.kind] || moduleNames[row.kind] || row.kind; }
|
||||
async function openHistory(row:Row) {
|
||||
try { historyNote.value=await api<LibraryNote>("/notes/"+row.id); historyOpen.value=true; }
|
||||
catch(failure) { ElMessage.error((failure as Error).message); }
|
||||
@@ -174,7 +181,7 @@ const captureBookmark = "javascript:(()=>{if(!/^https?:$/.test(location.protocol
|
||||
<div class="library-actions">
|
||||
<select v-if="page==='trash'" class="field library-select" v-model="kind" aria-label="回收站模块" @change="offset=0">
|
||||
<option value="">全部类型</option>
|
||||
<option v-for="(label,id) in moduleNames" v-show="id!=='rss'" :key="id" :value="id">{{ label }}</option>
|
||||
<option v-for="item in trashKinds" :key="item.kind" :value="item.kind">{{ item.label }}</option>
|
||||
</select>
|
||||
<select v-if="page==='batch'" class="field library-select" v-model="batchKind" aria-label="批量模块" @change="offset=0; selected=[]">
|
||||
<option v-for="id in batchKinds" :key="id" :value="id">{{ moduleNames[id] }}</option>
|
||||
@@ -193,7 +200,7 @@ const captureBookmark = "javascript:(()=>{if(!/^https?:$/.test(location.protocol
|
||||
<div v-for="row in rows" :key="row.id" class="card library-dialog-row admin-row">
|
||||
<input v-if="page==='batch'" type="checkbox" v-model="selected" :value="row.id" :aria-label="'选择 '+row.title" />
|
||||
<div class="grow"><strong>{{ row.title }}</strong><div class="small muted">
|
||||
{{ page==='trash' ? moduleNames[row.kind]+' · '+new Date(row.deleted_at).toLocaleString()
|
||||
{{ page==='trash' ? kindOf(row)+' · '+new Date(row.deleted_at).toLocaleString()
|
||||
: page==='history' ? row.folder+' · '+row.versions+' 个版本' : row.category }}
|
||||
</div></div>
|
||||
<template v-if="page==='trash'">
|
||||
|
||||
+15
-3
@@ -106,7 +106,7 @@ const searchItems=ref<SearchItem[]>([]);
|
||||
const searched=ref(false);
|
||||
const tool= computed(()=>toolPage(page.value));
|
||||
const toolView=computed<ToolId|"tools"|null>(()=>tool.value?.id ?? (page.value==="tools"?"tools":null));
|
||||
const searchNames:Record<string,string>={...moduleNames,prompts:"提示词",chat:"AI 对话",image:"AI 图片",inbox:"收集箱"};
|
||||
const searchNames:Record<string,string>={...moduleNames,chat:"AI 对话",image:"AI 图片"};
|
||||
const publicationLabel=computed(()=>summary.value.publication.pending?"有改动待同步"
|
||||
:summary.value.publication.published_at?"已同步":"待首次同步");
|
||||
const publicLinksOpen = ref(false);
|
||||
@@ -1007,8 +1007,20 @@ function syncTheme(event:StorageEvent) {
|
||||
dark.value=localStorage.getItem("myspace-theme")==="dark";
|
||||
document.documentElement.dataset.theme=dark.value?"dark":"light";
|
||||
}
|
||||
function expired() {
|
||||
user.value = "";
|
||||
// 401 只代表「这一次请求没通过」,不能据此清掉登录态:切到别的模块时某个接口 401 会让整站白屏。
|
||||
// 这里先向后端确认会话;只有 /auth/me 也失败(会话真的失效)才要求重新登录。
|
||||
let checkingSession = false;
|
||||
async function expired() {
|
||||
if (checkingSession) return;
|
||||
checkingSession = true;
|
||||
try {
|
||||
await refreshCsrf();
|
||||
user.value = (await api("/auth/me")).username;
|
||||
} catch {
|
||||
user.value = "";
|
||||
} finally {
|
||||
checkingSession = false;
|
||||
}
|
||||
}
|
||||
function beforeUnload(e: BeforeUnloadEvent) {
|
||||
if (dirty.value) {
|
||||
|
||||
@@ -7,10 +7,15 @@ export const toolPages = [
|
||||
{ id: "browser", icon: "link", title: "浏览器工具", description: "导入书签或从浏览器收集网页" },
|
||||
{ id: "linkage", icon: "graph", title: "联动说明", description: "查看各业务模块的转存路径" },
|
||||
] as const;
|
||||
export const moduleNames = {
|
||||
notes: "知识库", blogs: "博客", assets: "图床", bookmarks: "书签",
|
||||
tasks: "待办", events: "日程", snippets: "代码片段", rss: "RSS",
|
||||
} as const;
|
||||
// 与后端 TrashService.KINDS 的标签文案一致;回收站与批量管理共用。
|
||||
// 标签接口只覆盖 notes/blogs/assets/bookmarks/tasks/events/snippets,其余模块用「模块 · 动态标签」。
|
||||
export type ModuleKind =
|
||||
| "notes" | "blogs" | "assets" | "bookmarks" | "tasks" | "events" | "snippets"
|
||||
| "rss" | "prompts" | "flows" | "inbox";
|
||||
export const moduleNames: Record<ModuleKind, string> = {
|
||||
notes: "笔记", blogs: "博客", assets: "素材", bookmarks: "书签",
|
||||
tasks: "待办", events: "日程", snippets: "代码片段", rss: "RSS 订阅",
|
||||
prompts: "AI 提示词", flows: "自动化工作流", inbox: "收集项",
|
||||
};
|
||||
export type PlannerKind = "tasks" | "events" | "snippets";
|
||||
export type ModuleKind = keyof typeof moduleNames;
|
||||
export type ToolId = typeof toolPages[number]["id"];
|
||||
Reference in new issue
Block a user