feat: 新增按标签复习与标签导图页面
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||
|
||||
vi.mock('@/utils/request', () => ({
|
||||
default: {
|
||||
get: vi.fn(),
|
||||
post: vi.fn(),
|
||||
put: vi.fn(),
|
||||
del: vi.fn(),
|
||||
},
|
||||
}))
|
||||
|
||||
import request from '@/utils/request'
|
||||
import { listTagRecallRecords, queryTagMindMap, updateTagMindMap } from '@/api/tagMindMap'
|
||||
|
||||
const mockedRequest = vi.mocked(request)
|
||||
|
||||
describe('tagMindMap API(闭环-04)', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
})
|
||||
|
||||
it('queryTagMindMap 用请求体传标签集合与取数模式(标签名可能含逗号)', async () => {
|
||||
mockedRequest.post.mockResolvedValue({ code: 200, data: { scopeKey: 'S1' } })
|
||||
await queryTagMindMap(['英语', '数学'], 'INTERSECT')
|
||||
expect(mockedRequest.post).toHaveBeenCalledWith('/review/tag-mind-map/query', {
|
||||
tags: ['英语', '数学'],
|
||||
mode: 'INTERSECT',
|
||||
})
|
||||
})
|
||||
|
||||
it('updateTagMindMap 保存整体大纲', async () => {
|
||||
mockedRequest.put.mockResolvedValue({ code: 200, data: { id: 1 } })
|
||||
await updateTagMindMap(['英语'], '- 英语\n - 时态', 'UNION')
|
||||
expect(mockedRequest.put).toHaveBeenCalledWith('/review/tag-mind-map', {
|
||||
tags: ['英语'],
|
||||
mode: 'UNION',
|
||||
outline: '- 英语\n - 时态',
|
||||
})
|
||||
})
|
||||
|
||||
it('listTagRecallRecords 按范围取回忆记录', async () => {
|
||||
mockedRequest.post.mockResolvedValue({ code: 200, data: [] })
|
||||
await listTagRecallRecords(['英语'], 'UNION')
|
||||
expect(mockedRequest.post).toHaveBeenCalledWith('/review/tag-mind-map/recall-records', {
|
||||
tags: ['英语'],
|
||||
mode: 'UNION',
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,193 @@
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||
import { flushPromises, mount } from '@vue/test-utils'
|
||||
import ElementPlus from 'element-plus'
|
||||
import TagReview from '@/components/TagReview.vue'
|
||||
import { queryTagMindMap, listTagRecallRecords } from '@/api/tagMindMap'
|
||||
import { listTagCandidates } from '@/api/markers'
|
||||
import { submitAiTask } from '@/api/aiTasks'
|
||||
|
||||
vi.mock('@/api/tagMindMap', () => ({
|
||||
queryTagMindMap: vi.fn(),
|
||||
updateTagMindMap: vi.fn(),
|
||||
listTagRecallRecords: vi.fn(),
|
||||
}))
|
||||
|
||||
vi.mock('@/api/markers', () => ({
|
||||
listTagCandidates: vi.fn(),
|
||||
}))
|
||||
|
||||
vi.mock('@/api/aiTasks', async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import('@/api/aiTasks')>()
|
||||
return { ...actual, submitAiTask: vi.fn(), getAiTask: vi.fn(), getLatestAiTask: vi.fn() }
|
||||
})
|
||||
|
||||
/** 回忆导图桩:toOutline 的返回值由测试控制 */
|
||||
let recallOutline = '- 根主题'
|
||||
const mindMapStub = {
|
||||
name: 'MindMapViewer',
|
||||
template: '<div class="mindmap-stub" />',
|
||||
methods: { toOutline: () => recallOutline },
|
||||
}
|
||||
|
||||
const tagMap = {
|
||||
id: 1,
|
||||
scopeKey: 'SCOPE_1',
|
||||
combineMode: 'UNION',
|
||||
tagNames: '["英语"]',
|
||||
title: '英语',
|
||||
content: JSON.stringify({ title: '英语', children: [{ title: '时态', children: [] }] }),
|
||||
outline: '- 英语\n - 时态',
|
||||
summary: 'AI 生成,共 2 个节点',
|
||||
generator: 'AI',
|
||||
sourceFragmentCount: 3,
|
||||
}
|
||||
|
||||
const mountTagReview = async () => {
|
||||
const wrapper = mount(TagReview, {
|
||||
global: { plugins: [ElementPlus], stubs: { MindMapViewer: mindMapStub } },
|
||||
})
|
||||
await flushPromises()
|
||||
return wrapper
|
||||
}
|
||||
|
||||
/** 选标签:el-select 多选在 jsdom 里直接写 v-model 更稳定 */
|
||||
const selectTags = async (wrapper: any, tags: string[]) => {
|
||||
;(wrapper.vm as unknown as { selectedTags: string[] }).selectedTags = tags
|
||||
await flushPromises()
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
recallOutline = '- 根主题'
|
||||
vi.mocked(listTagCandidates).mockResolvedValue({ code: 200, data: ['英语', '数学'] } as never)
|
||||
vi.mocked(listTagRecallRecords).mockResolvedValue({ code: 200, data: [] } as never)
|
||||
vi.mocked(submitAiTask).mockResolvedValue({ code: 201, data: { taskNum: 'AI1', status: 'PENDING' } } as never)
|
||||
})
|
||||
|
||||
describe('TagReview 按标签复习(闭环-04)', () => {
|
||||
it('未选标签时不发请求,选标签后按范围查询并提示生成导图', async () => {
|
||||
vi.mocked(queryTagMindMap).mockResolvedValue({
|
||||
code: 200,
|
||||
data: { scopeKey: 'SCOPE_1', tags: ['英语'], mode: 'UNION', map: null, latestRecallRecord: null },
|
||||
} as never)
|
||||
const wrapper = await mountTagReview()
|
||||
|
||||
const start = wrapper.findAll('button').find((b) => b.text().includes('开始复习'))
|
||||
await start!.trigger('click')
|
||||
await flushPromises()
|
||||
expect(queryTagMindMap).not.toHaveBeenCalled()
|
||||
|
||||
await selectTags(wrapper, ['英语'])
|
||||
await start!.trigger('click')
|
||||
await flushPromises()
|
||||
|
||||
expect(queryTagMindMap).toHaveBeenCalledWith(['英语'], 'UNION')
|
||||
expect(wrapper.text()).toContain('这个标签范围还没有导图')
|
||||
wrapper.unmount()
|
||||
})
|
||||
|
||||
it('生成导图走 TAG_MIND_MAP 异步任务,targetNum 用范围键', async () => {
|
||||
vi.mocked(queryTagMindMap).mockResolvedValue({
|
||||
code: 200,
|
||||
data: { scopeKey: 'SCOPE_1', tags: ['英语'], mode: 'UNION', map: null, latestRecallRecord: null },
|
||||
} as never)
|
||||
const wrapper = await mountTagReview()
|
||||
await selectTags(wrapper, ['英语'])
|
||||
const start = wrapper.findAll('button').find((b) => b.text().includes('开始复习'))
|
||||
await start!.trigger('click')
|
||||
await flushPromises()
|
||||
|
||||
const generate = wrapper.findAll('button').find((b) => b.text().trim() === '生成导图')
|
||||
await generate!.trigger('click')
|
||||
await flushPromises()
|
||||
|
||||
expect(submitAiTask).toHaveBeenCalledWith({
|
||||
type: 'TAG_MIND_MAP',
|
||||
targetNum: 'SCOPE_1',
|
||||
params: { tags: ['英语'], combineMode: 'UNION', mode: 'ensure' },
|
||||
})
|
||||
wrapper.unmount()
|
||||
})
|
||||
|
||||
it('交集模式按用户选择传参,并展示已有导图与历史记录', async () => {
|
||||
vi.mocked(queryTagMindMap).mockResolvedValue({
|
||||
code: 200,
|
||||
data: { scopeKey: 'SCOPE_2', tags: ['英语', '数学'], mode: 'INTERSECT', map: tagMap, latestRecallRecord: null },
|
||||
} as never)
|
||||
vi.mocked(listTagRecallRecords).mockResolvedValue({
|
||||
code: 200,
|
||||
data: [
|
||||
{
|
||||
id: 5,
|
||||
scopeKey: 'SCOPE_2',
|
||||
recallContent: '- 英语',
|
||||
compareResult: JSON.stringify({
|
||||
matchedTree: { title: '英语', notes: 'MATCHED', children: [{ title: '时态', notes: 'MISSED|' }] },
|
||||
extraNodes: [{ title: '额外点' }],
|
||||
recallRatio: 0.5,
|
||||
matchedCount: 1,
|
||||
missedCount: 1,
|
||||
extraCount: 1,
|
||||
}),
|
||||
recallRatio: 0.5,
|
||||
matchedCount: 1,
|
||||
missedCount: 1,
|
||||
extraCount: 1,
|
||||
reviewDurationSeconds: 42,
|
||||
createdTime: '2026-10-10T10:00:00',
|
||||
},
|
||||
],
|
||||
} as never)
|
||||
|
||||
const wrapper = await mountTagReview()
|
||||
;(wrapper.vm as unknown as { combineMode: string }).combineMode = 'INTERSECT'
|
||||
await selectTags(wrapper, ['英语', '数学'])
|
||||
const start = wrapper.findAll('button').find((b) => b.text().includes('开始复习'))
|
||||
await start!.trigger('click')
|
||||
await flushPromises()
|
||||
|
||||
expect(queryTagMindMap).toHaveBeenCalledWith(['英语', '数学'], 'INTERSECT')
|
||||
expect(wrapper.text()).toContain('标签导图')
|
||||
expect(wrapper.text()).toContain('回忆对比')
|
||||
expect(wrapper.text()).toContain('覆盖率:50.0%')
|
||||
expect(wrapper.text()).toContain('复习历史')
|
||||
expect(wrapper.text()).toContain('遗漏项')
|
||||
expect(wrapper.text()).toContain('额外项')
|
||||
wrapper.unmount()
|
||||
})
|
||||
|
||||
it('回忆内容只有一个节点时拒绝提交,补全后才提交对比任务', async () => {
|
||||
vi.mocked(queryTagMindMap).mockResolvedValue({
|
||||
code: 200,
|
||||
data: { scopeKey: 'SCOPE_3', tags: ['英语'], mode: 'UNION', map: tagMap, latestRecallRecord: null },
|
||||
} as never)
|
||||
const wrapper = await mountTagReview()
|
||||
await selectTags(wrapper, ['英语'])
|
||||
const start = wrapper.findAll('button').find((b) => b.text().includes('开始复习'))
|
||||
await start!.trigger('click')
|
||||
await flushPromises()
|
||||
|
||||
const submit = wrapper.findAll('button').find((b) => b.text().includes('提交对比'))
|
||||
recallOutline = '- 只有根节点'
|
||||
await submit!.trigger('click')
|
||||
await flushPromises()
|
||||
expect(submitAiTask).not.toHaveBeenCalled()
|
||||
|
||||
recallOutline = '- 根主题\n - 子节点'
|
||||
await submit!.trigger('click')
|
||||
await flushPromises()
|
||||
|
||||
expect(submitAiTask).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
type: 'TAG_RECALL_COMPARE',
|
||||
targetNum: 'SCOPE_3',
|
||||
params: expect.objectContaining({
|
||||
tags: ['英语'],
|
||||
combineMode: 'UNION',
|
||||
recallOutline: '- 根主题\n - 子节点',
|
||||
}),
|
||||
}),
|
||||
)
|
||||
wrapper.unmount()
|
||||
})
|
||||
})
|
||||
+27
-1
@@ -2,7 +2,12 @@
|
||||
import request from "@/utils/request";
|
||||
|
||||
/** AI 异步任务类型 */
|
||||
export type AiTaskType = "RECALL_COMPARE" | "MIND_MAP" | "REPORT_DRAFT";
|
||||
export type AiTaskType =
|
||||
| "RECALL_COMPARE"
|
||||
| "MIND_MAP"
|
||||
| "REPORT_DRAFT"
|
||||
| "TAG_MIND_MAP"
|
||||
| "TAG_RECALL_COMPARE";
|
||||
|
||||
export type AiTaskStatus = "PENDING" | "RUNNING" | "SUCCEEDED" | "FAILED";
|
||||
|
||||
@@ -39,6 +44,27 @@ export type MindMapParams = {
|
||||
mode: "full" | "incremental" | "ensure";
|
||||
};
|
||||
|
||||
/**
|
||||
* TAG_MIND_MAP(闭环-04):targetNum 为标签范围键,范围由 tags + combineMode 给出;
|
||||
* 目标与参数算出的范围不一致时后端直接失败,避免写到别的范围上。
|
||||
*/
|
||||
export type TagMindMapParams = {
|
||||
tags: string[];
|
||||
combineMode: "UNION" | "INTERSECT";
|
||||
mode: "full" | "incremental" | "ensure";
|
||||
};
|
||||
|
||||
/** TAG_RECALL_COMPARE:targetNum 为标签范围键,其余字段与任务范围回忆对比同名同义 */
|
||||
export type TagRecallCompareParams = {
|
||||
tags: string[];
|
||||
combineMode: "UNION" | "INTERSECT";
|
||||
recallOutline: string;
|
||||
focusPath?: string;
|
||||
reviewStartedAt?: string;
|
||||
reviewLastInteractionAt?: string;
|
||||
reviewDurationSeconds?: number;
|
||||
};
|
||||
|
||||
/** 轮询间隔(毫秒):提交本身秒级返回,后续进度靠轮询获取 */
|
||||
export const AI_TASK_POLL_INTERVAL_MS = 2000;
|
||||
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
// src/api/tagMindMap.ts
|
||||
import request from "@/utils/request";
|
||||
|
||||
/** 取数模式:UNION=并集(默认)/ INTERSECT=交集 */
|
||||
export type TagCombineMode = "UNION" | "INTERSECT";
|
||||
|
||||
/**
|
||||
* 标签思维导图(闭环-04):以一个「标签集合 + 取数模式」为范围的导图,与任务导图并存。
|
||||
* 范围键由后端按标签集合与模式算稳定哈希:集合相同且模式相同即同一张导图。
|
||||
*/
|
||||
export interface TagMindMap {
|
||||
id: number;
|
||||
scopeKey: string;
|
||||
combineMode: TagCombineMode;
|
||||
/** 范围的标签集合(JSON 数组字符串,按归一化名排序) */
|
||||
tagNames: string;
|
||||
title: string;
|
||||
content: string;
|
||||
outline: string;
|
||||
summary: string;
|
||||
generator: "BUILTIN" | "AI" | "USER" | "USER_MERGE";
|
||||
generatorVersion?: string;
|
||||
sourceFragmentCount?: number;
|
||||
generatedTime?: string;
|
||||
/** 素材(碎片标签)变化后置 true:需要重建,重建由用户手动触发 */
|
||||
needsUpdate?: boolean;
|
||||
needsUpdateTime?: string;
|
||||
}
|
||||
|
||||
/** 标签范围的回忆记录:任务列为空,范围由 scopeKey + 标签集合 + 模式描述 */
|
||||
export interface TagRecallRecord {
|
||||
id: number;
|
||||
taskNum?: string | null;
|
||||
scopeType?: string;
|
||||
scopeKey?: string;
|
||||
scopeTags?: string;
|
||||
scopeMode?: TagCombineMode;
|
||||
standardMapId?: number | null;
|
||||
focusPath?: string;
|
||||
recallContent: string;
|
||||
compareResult: string;
|
||||
recallRatio: number;
|
||||
matchedCount?: number;
|
||||
missedCount?: number;
|
||||
extraCount?: number;
|
||||
reviewDurationSeconds?: number;
|
||||
createdTime: string;
|
||||
}
|
||||
|
||||
/** 一个标签复习范围的当前状态:范围键与标签集合总是返回,map 为空表示还没生成过 */
|
||||
export interface TagMindMapView {
|
||||
scopeKey: string;
|
||||
tags: string[];
|
||||
mode: TagCombineMode;
|
||||
map: TagMindMap | null;
|
||||
latestRecallRecord: TagRecallRecord | null;
|
||||
}
|
||||
|
||||
/** 读取该范围的状态(不触发生成) */
|
||||
export const queryTagMindMap = (tags: string[], mode: TagCombineMode) => {
|
||||
return request.post<TagMindMapView>("/review/tag-mind-map/query", { tags, mode });
|
||||
};
|
||||
|
||||
/** 用户编辑标签导图(缩进大纲);该范围还没有导图时保存即为新建 */
|
||||
export const updateTagMindMap = (tags: string[], outline: string, mode: TagCombineMode) => {
|
||||
return request.put<TagMindMap>("/review/tag-mind-map", { tags, mode, outline });
|
||||
};
|
||||
|
||||
/** 该范围的回忆对比记录(倒序) */
|
||||
export const listTagRecallRecords = (tags: string[], mode: TagCombineMode) => {
|
||||
return request.post<TagRecallRecord[]>("/review/tag-mind-map/recall-records", { tags, mode });
|
||||
};
|
||||
@@ -441,6 +441,7 @@ onMounted(async () => {
|
||||
<div class="page-toolbar">
|
||||
<el-button :loading="loading" @click="loadTasks">刷新</el-button>
|
||||
<el-button plain @click="openSortDialog">智能排序偏好</el-button>
|
||||
<el-button plain @click="router.push('/review/by-tag')">按标签复习</el-button>
|
||||
<el-button plain @click="openTagDialog">标签管理</el-button>
|
||||
<el-button type="success" plain @click="openExportDialog">导出数据</el-button>
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,539 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref } from "vue";
|
||||
import { ElMessage, ElMessageBox } from "element-plus";
|
||||
import MindMapViewer, { type MindMapTreeNode } from "@/components/MindMapViewer.vue";
|
||||
import {
|
||||
listTagRecallRecords,
|
||||
queryTagMindMap,
|
||||
updateTagMindMap,
|
||||
type TagCombineMode,
|
||||
type TagMindMapView,
|
||||
type TagRecallRecord,
|
||||
} from "@/api/tagMindMap";
|
||||
import { listTagCandidates } from "@/api/markers";
|
||||
import { isAiTaskCancelled, useAiTask } from "@/components/composables/useAiTask";
|
||||
import { useReviewDuration } from "@/components/composables/useReviewDuration";
|
||||
|
||||
/**
|
||||
* 按标签复习(闭环-04):选一个或多个标签 → 聚合成标签导图 → 走既有的回忆对比链路。
|
||||
* 与按任务复习并存:任务导图仍在 ReviewRecall 里,这里只处理「标签集合 + 并集/交集」这一半。
|
||||
*/
|
||||
|
||||
const candidates = ref<string[]>([]);
|
||||
const selectedTags = ref<string[]>([]);
|
||||
const combineMode = ref<TagCombineMode>("UNION");
|
||||
const view = ref<TagMindMapView | null>(null);
|
||||
const records = ref<TagRecallRecord[]>([]);
|
||||
const lastResult = ref<any>(null);
|
||||
const currentDurationSeconds = ref(0);
|
||||
|
||||
const busy = ref(false);
|
||||
const saving = ref(false);
|
||||
const editing = ref(false);
|
||||
const editViewer = ref<InstanceType<typeof MindMapViewer> | null>(null);
|
||||
const recallViewer = ref<InstanceType<typeof MindMapViewer> | null>(null);
|
||||
const recallTree = ref<MindMapTreeNode | null>(null);
|
||||
|
||||
const mindMapTask = useAiTask();
|
||||
const { running: generating, seconds: generatingSeconds } = mindMapTask;
|
||||
const recallTask = useAiTask();
|
||||
const { running: comparing, seconds: comparingSeconds } = recallTask;
|
||||
const {
|
||||
start: startReviewDuration,
|
||||
snapshot: reviewDurationSnapshot,
|
||||
reset: resetReviewDuration,
|
||||
} = useReviewDuration();
|
||||
|
||||
const errorMessageOf = (error: unknown, fallback: string): string => {
|
||||
if (error && typeof error === "object" && "message" in error) {
|
||||
const message = (error as { message?: unknown }).message;
|
||||
if (typeof message === "string" && message.trim()) return message;
|
||||
}
|
||||
return fallback;
|
||||
};
|
||||
|
||||
const parseTree = (content?: string): MindMapTreeNode | null => {
|
||||
if (!content) return null;
|
||||
try {
|
||||
return JSON.parse(content) as MindMapTreeNode;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
const map = computed(() => view.value?.map || null);
|
||||
const standardTree = computed<MindMapTreeNode | null>(() => parseTree(map.value?.content));
|
||||
const resultTree = computed<MindMapTreeNode | null>(() => lastResult.value?.matchedTree || null);
|
||||
|
||||
/** 回忆导图的初始根节点:只给主题,内容凭记忆补全 */
|
||||
const buildEmptyRecallTree = (): MindMapTreeNode => ({
|
||||
title: map.value?.title || selectedTags.value.join(" / ") || "这次复习",
|
||||
children: [],
|
||||
});
|
||||
|
||||
const missedItems = computed(() => {
|
||||
if (!lastResult.value?.matchedTree) return [];
|
||||
const items: { title: string; sourceType: string; sourceId: number }[] = [];
|
||||
const walk = (node: any) => {
|
||||
if (String(node.notes || "").startsWith("MISSED|")) {
|
||||
items.push({
|
||||
title: node.title || "",
|
||||
sourceType: node.sourceType || "",
|
||||
sourceId: node.sourceId,
|
||||
});
|
||||
}
|
||||
(node.children || []).forEach(walk);
|
||||
};
|
||||
walk(lastResult.value.matchedTree);
|
||||
return items;
|
||||
});
|
||||
|
||||
const extraNodes = computed(() => {
|
||||
const raw = lastResult.value?.extraNodes || [];
|
||||
return raw.map((item: any) => (typeof item === "string" ? { title: item } : item));
|
||||
});
|
||||
|
||||
const ratioPercent = computed(() =>
|
||||
lastResult.value?.recallRatio ? `${(lastResult.value.recallRatio * 100).toFixed(1)}%` : "0%",
|
||||
);
|
||||
|
||||
const loadCandidates = async () => {
|
||||
try {
|
||||
const res = await listTagCandidates();
|
||||
candidates.value = res?.data || [];
|
||||
} catch {
|
||||
candidates.value = [];
|
||||
}
|
||||
};
|
||||
|
||||
const loadRecords = async () => {
|
||||
if (selectedTags.value.length === 0) {
|
||||
records.value = [];
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const res = await listTagRecallRecords(selectedTags.value, combineMode.value);
|
||||
records.value = res?.data || [];
|
||||
} catch {
|
||||
records.value = [];
|
||||
}
|
||||
};
|
||||
|
||||
const loadComparisonResult = () => {
|
||||
const latest = records.value[0];
|
||||
if (!latest) {
|
||||
lastResult.value = null;
|
||||
return;
|
||||
}
|
||||
try {
|
||||
lastResult.value = JSON.parse(latest.compareResult);
|
||||
} catch {
|
||||
lastResult.value = null;
|
||||
}
|
||||
currentDurationSeconds.value = latest.reviewDurationSeconds ?? 0;
|
||||
};
|
||||
|
||||
/** 开始复习:解析范围(读取不触发生成),拿到范围键后再决定生成还是直接展示 */
|
||||
const startReview = async () => {
|
||||
if (selectedTags.value.length === 0) {
|
||||
ElMessage.warning("请先选至少一个标签");
|
||||
return;
|
||||
}
|
||||
busy.value = true;
|
||||
try {
|
||||
const res = await queryTagMindMap(selectedTags.value, combineMode.value);
|
||||
view.value = res?.data || null;
|
||||
editing.value = false;
|
||||
recallTree.value = buildEmptyRecallTree();
|
||||
lastResult.value = null;
|
||||
await loadRecords();
|
||||
loadComparisonResult();
|
||||
resetReviewDuration();
|
||||
if (map.value) startReviewDuration();
|
||||
} catch {
|
||||
// 请求层已提示具体错误
|
||||
} finally {
|
||||
busy.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
const refreshMap = async () => {
|
||||
const res = await queryTagMindMap(selectedTags.value, combineMode.value);
|
||||
view.value = res?.data || null;
|
||||
startReviewDuration();
|
||||
};
|
||||
|
||||
const generateMap = async (mode: "full" | "incremental" | "ensure" = "ensure") => {
|
||||
if (!view.value?.scopeKey) return;
|
||||
try {
|
||||
await mindMapTask.run("TAG_MIND_MAP", view.value.scopeKey, {
|
||||
tags: selectedTags.value,
|
||||
combineMode: combineMode.value,
|
||||
mode,
|
||||
});
|
||||
await refreshMap();
|
||||
recallTree.value = buildEmptyRecallTree();
|
||||
ElMessage.success(mode === "incremental" ? "标签导图已增量更新" : "标签导图已生成");
|
||||
} catch (e) {
|
||||
if (isAiTaskCancelled(e)) return;
|
||||
ElMessage.error(errorMessageOf(e, "标签导图生成失败,请稍后重试"));
|
||||
}
|
||||
};
|
||||
|
||||
const handleRegenerate = async () => {
|
||||
if (generating.value) return;
|
||||
let mode: "full" | "incremental" = "full";
|
||||
if (map.value?.generator === "USER" || map.value?.generator === "USER_MERGE") {
|
||||
try {
|
||||
await ElMessageBox.confirm("检测到这张标签导图被编辑过,请选择重新生成方式:", "重新生成", {
|
||||
confirmButtonText: "全量重新生成",
|
||||
cancelButtonText: "增量更新(保留编辑)",
|
||||
type: "warning",
|
||||
distinguishCancelAndClose: true,
|
||||
});
|
||||
} catch (e) {
|
||||
if (e === "cancel" || String(e).includes("cancel")) {
|
||||
mode = "incremental";
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
await ElMessageBox.confirm("重新生成会从带这些标签的碎片里重新提取结构,确定?", "提示", {
|
||||
confirmButtonText: "确定",
|
||||
cancelButtonText: "取消",
|
||||
type: "info",
|
||||
});
|
||||
} catch {
|
||||
return;
|
||||
}
|
||||
}
|
||||
await generateMap(mode);
|
||||
};
|
||||
|
||||
const startEditStandard = () => {
|
||||
editing.value = true;
|
||||
};
|
||||
|
||||
const cancelEditStandard = () => {
|
||||
editing.value = false;
|
||||
};
|
||||
|
||||
const saveStandardEdit = async () => {
|
||||
const outline = editViewer.value?.toOutline() || "";
|
||||
if (outline.split(/\r?\n/).filter((line) => line.trim()).length <= 1) {
|
||||
ElMessage.warning("导图至少需要一个节点");
|
||||
return;
|
||||
}
|
||||
saving.value = true;
|
||||
try {
|
||||
const res = await updateTagMindMap(selectedTags.value, outline, combineMode.value);
|
||||
if (view.value && res?.data) {
|
||||
view.value = { ...view.value, map: res.data };
|
||||
}
|
||||
editing.value = false;
|
||||
ElMessage.success("标签导图已更新");
|
||||
} catch (e) {
|
||||
ElMessage.error(errorMessageOf(e, "保存失败"));
|
||||
} finally {
|
||||
saving.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
const submitCompare = async () => {
|
||||
if (!view.value?.scopeKey || comparing.value) return;
|
||||
const outline = recallViewer.value?.toOutline() || "";
|
||||
if (outline.split(/\r?\n/).filter((line) => line.trim()).length <= 1) {
|
||||
ElMessage.warning("请先在回忆导图中添加节点(选中节点后按 Tab 加子节点)");
|
||||
return;
|
||||
}
|
||||
const timing = reviewDurationSnapshot();
|
||||
try {
|
||||
await recallTask.run("TAG_RECALL_COMPARE", view.value.scopeKey, {
|
||||
tags: selectedTags.value,
|
||||
combineMode: combineMode.value,
|
||||
recallOutline: outline,
|
||||
reviewStartedAt: timing.startedAt,
|
||||
reviewLastInteractionAt: timing.lastInteractionAt,
|
||||
reviewDurationSeconds: timing.durationSeconds,
|
||||
});
|
||||
currentDurationSeconds.value = timing.durationSeconds;
|
||||
await loadRecords();
|
||||
loadComparisonResult();
|
||||
resetReviewDuration();
|
||||
ElMessage.success("回忆对比完成");
|
||||
} catch (e) {
|
||||
if (isAiTaskCancelled(e)) return;
|
||||
ElMessage.error(errorMessageOf(e, "对比失败"));
|
||||
}
|
||||
};
|
||||
|
||||
const resetRecall = () => {
|
||||
recallTree.value = buildEmptyRecallTree();
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
void loadCandidates();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section class="tag-review-page">
|
||||
<article class="surface-card scope-card" v-loading="busy">
|
||||
<h3>按标签复习</h3>
|
||||
<p class="scope-hint">
|
||||
选一个或多个标签,把带这些标签的知识碎片聚合成一张导图,然后凭记忆重绘它。
|
||||
标签导图与按任务复习并存,互不替代。
|
||||
</p>
|
||||
<div class="scope-field">
|
||||
<span class="scope-label">标签</span>
|
||||
<el-select
|
||||
v-model="selectedTags"
|
||||
class="scope-select"
|
||||
multiple
|
||||
filterable
|
||||
allow-create
|
||||
default-first-option
|
||||
placeholder="选择或输入标签"
|
||||
>
|
||||
<el-option v-for="name in candidates" :key="name" :label="name" :value="name" />
|
||||
</el-select>
|
||||
</div>
|
||||
<div class="scope-field">
|
||||
<span class="scope-label">多个标签取</span>
|
||||
<el-radio-group v-model="combineMode">
|
||||
<el-radio value="UNION">并集(带任一标签)</el-radio>
|
||||
<el-radio value="INTERSECT">交集(同时带全部标签)</el-radio>
|
||||
</el-radio-group>
|
||||
</div>
|
||||
<div class="scope-actions">
|
||||
<el-button type="success" :loading="busy" @click="startReview">开始复习</el-button>
|
||||
</div>
|
||||
</article>
|
||||
|
||||
<template v-if="view">
|
||||
<article class="surface-card map-card">
|
||||
<div class="card-header">
|
||||
<h3>标签导图</h3>
|
||||
<div class="card-actions">
|
||||
<template v-if="editing">
|
||||
<el-button size="small" @click="cancelEditStandard">取消</el-button>
|
||||
<el-button size="small" type="success" :loading="saving" @click="saveStandardEdit">保存</el-button>
|
||||
</template>
|
||||
<template v-else-if="map">
|
||||
<el-button size="small" type="primary" @click="startEditStandard">编辑</el-button>
|
||||
<el-button size="small" :loading="generating" @click="handleRegenerate">重新生成</el-button>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
<p v-if="generating" class="ai-waiting">
|
||||
<template v-if="generatingSeconds < 3">正在准备生成…</template>
|
||||
<template v-else>AI 正在生成中,已等待 {{ generatingSeconds }} 秒,请稍候…</template>
|
||||
</p>
|
||||
<el-alert
|
||||
v-if="map && map.needsUpdate"
|
||||
type="warning"
|
||||
show-icon
|
||||
:closable="false"
|
||||
title="内容归属或标签变化,这张导图需要重建"
|
||||
description="重建由你手动触发:点「重新生成」。"
|
||||
/>
|
||||
<div v-if="!map" class="empty-state">
|
||||
<el-empty description="这个标签范围还没有导图" :image-size="64">
|
||||
<el-button type="success" :loading="generating" @click="generateMap('ensure')">生成导图</el-button>
|
||||
</el-empty>
|
||||
</div>
|
||||
<div v-else-if="editing" class="edit-area">
|
||||
<p class="panel-hint">直接在导图上编辑(Tab 加子节点 / Enter 加同级 / 双击改文字),保存后生效。</p>
|
||||
<MindMapViewer ref="editViewer" :tree="standardTree" :editable="true" height="50vh" />
|
||||
</div>
|
||||
<div v-else class="standard-content">
|
||||
<MindMapViewer v-if="standardTree" :tree="standardTree" height="50vh" />
|
||||
<pre v-else class="standard-outline">{{ map.outline || map.content }}</pre>
|
||||
<p v-if="map.summary" class="generator-info">{{ map.summary }}</p>
|
||||
</div>
|
||||
</article>
|
||||
|
||||
<article class="surface-card recall-card" v-if="map">
|
||||
<div class="card-header">
|
||||
<h3>回忆对比</h3>
|
||||
<div class="card-actions">
|
||||
<el-button size="small" @click="resetRecall">清空重写</el-button>
|
||||
</div>
|
||||
</div>
|
||||
<p class="panel-hint">先凭记忆把结构画回来,再和上面的标签导图对照。</p>
|
||||
<MindMapViewer ref="recallViewer" :tree="recallTree" :editable="true" height="40vh" />
|
||||
<p v-if="comparing" class="ai-waiting">
|
||||
AI 正在对比中,已等待 {{ comparingSeconds }} 秒,请稍候…
|
||||
</p>
|
||||
<div class="recall-actions">
|
||||
<el-button type="success" :loading="comparing" @click="submitCompare">提交对比</el-button>
|
||||
</div>
|
||||
</article>
|
||||
|
||||
<article class="surface-card result-card" v-if="lastResult">
|
||||
<h3>本次结果</h3>
|
||||
<div class="result-metrics">
|
||||
<span>覆盖率:<strong>{{ ratioPercent }}</strong></span>
|
||||
<span>命中:{{ lastResult.matchedCount || 0 }}</span>
|
||||
<span>遗漏:{{ lastResult.missedCount || 0 }}</span>
|
||||
<span>额外:{{ lastResult.extraCount || 0 }}</span>
|
||||
<span v-if="currentDurationSeconds">复习耗时:{{ currentDurationSeconds }} 秒</span>
|
||||
</div>
|
||||
<MindMapViewer
|
||||
v-if="resultTree"
|
||||
:tree="resultTree"
|
||||
:color-by-compare="true"
|
||||
height="50vh"
|
||||
/>
|
||||
<p v-if="lastResult.evaluation" class="result-evaluation">{{ lastResult.evaluation }}</p>
|
||||
<div v-if="missedItems.length > 0" class="result-list">
|
||||
<h4>遗漏项</h4>
|
||||
<div v-for="(item, idx) in missedItems" :key="idx" class="result-item">
|
||||
<span class="result-item-title">{{ item.title }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="extraNodes.length > 0" class="result-list">
|
||||
<h4>额外项</h4>
|
||||
<div v-for="(item, idx) in extraNodes" :key="idx" class="result-item">
|
||||
<span class="result-item-title">{{ item.title }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</article>
|
||||
|
||||
<article class="surface-card history-card" v-if="records.length > 0">
|
||||
<h3>复习历史</h3>
|
||||
<div v-for="record in records" :key="record.id" class="history-row">
|
||||
<span class="history-time">{{ record.createdTime?.replace("T", " ")?.substring(0, 16) }}</span>
|
||||
<span class="history-ratio">覆盖率 {{ ((record.recallRatio || 0) * 100).toFixed(1) }}%</span>
|
||||
<span class="history-meta">
|
||||
命中 {{ record.matchedCount || 0 }} · 遗漏 {{ record.missedCount || 0 }} · 额外 {{ record.extraCount || 0 }}
|
||||
</span>
|
||||
</div>
|
||||
</article>
|
||||
</template>
|
||||
</section>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.tag-review-page {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 14px;
|
||||
max-width: 960px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
.scope-card,
|
||||
.map-card,
|
||||
.recall-card,
|
||||
.result-card,
|
||||
.history-card {
|
||||
padding: 18px;
|
||||
}
|
||||
|
||||
.scope-hint,
|
||||
.panel-hint {
|
||||
margin: 0 0 12px;
|
||||
font-size: 13px;
|
||||
color: var(--text-secondary);
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.scope-field {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
margin-bottom: 10px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.scope-label {
|
||||
font-size: 13px;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.scope-select {
|
||||
min-width: 320px;
|
||||
}
|
||||
|
||||
.scope-actions,
|
||||
.recall-actions {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.card-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 10px;
|
||||
flex-wrap: wrap;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.card-actions {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.empty-state {
|
||||
padding: 8px 0;
|
||||
}
|
||||
|
||||
.generator-info {
|
||||
margin: 8px 0 0;
|
||||
font-size: 12px;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.standard-outline {
|
||||
white-space: pre-wrap;
|
||||
font-size: 13px;
|
||||
line-height: 1.7;
|
||||
}
|
||||
|
||||
.ai-waiting {
|
||||
margin: 6px 0;
|
||||
font-size: 13px;
|
||||
color: var(--green-700);
|
||||
}
|
||||
|
||||
.result-metrics {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 14px;
|
||||
margin-bottom: 10px;
|
||||
font-size: 13px;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.result-evaluation {
|
||||
margin: 10px 0 0;
|
||||
font-size: 13px;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.result-list h4 {
|
||||
margin: 12px 0 6px;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.result-item {
|
||||
padding: 4px 0;
|
||||
border-bottom: 1px dashed var(--border-soft);
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.history-row {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 12px;
|
||||
padding: 6px 0;
|
||||
border-bottom: 1px dashed var(--border-soft);
|
||||
font-size: 13px;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
</style>
|
||||
@@ -48,6 +48,11 @@ const routes: RouteRecordRaw[] = [
|
||||
component: () => import("@/components/ReviewRecall.vue"),
|
||||
meta: { requiresAuth: true, title: "回忆复习", wide: true },
|
||||
},
|
||||
{
|
||||
path: "/review/by-tag",
|
||||
component: () => import("@/components/TagReview.vue"),
|
||||
meta: { requiresAuth: true, title: "按标签复习", wide: true },
|
||||
},
|
||||
{
|
||||
path: "/start-task/:taskNum",
|
||||
name: "start-task",
|
||||
|
||||
Reference in New Issue
Block a user