From 72a1792289d6b290075217deecd69bfe69deeb43 Mon Sep 17 00:00:00 2001 From: cat-shark <1716967236@qq.com> Date: Sat, 10 Oct 2026 16:09:38 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E6=8C=89=E6=A0=87?= =?UTF-8?q?=E7=AD=BE=E5=A4=8D=E4=B9=A0=E4=B8=8E=E6=A0=87=E7=AD=BE=E5=AF=BC?= =?UTF-8?q?=E5=9B=BE=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/__tests__/api/tagMindMap.spec.ts | 49 ++ src/__tests__/components/TagReview.spec.ts | 193 ++++++++ src/api/aiTasks.ts | 28 +- src/api/tagMindMap.ts | 72 +++ src/components/Review.vue | 1 + src/components/TagReview.vue | 539 +++++++++++++++++++++ src/router/index.ts | 5 + 7 files changed, 886 insertions(+), 1 deletion(-) create mode 100644 src/__tests__/api/tagMindMap.spec.ts create mode 100644 src/__tests__/components/TagReview.spec.ts create mode 100644 src/api/tagMindMap.ts create mode 100644 src/components/TagReview.vue diff --git a/src/__tests__/api/tagMindMap.spec.ts b/src/__tests__/api/tagMindMap.spec.ts new file mode 100644 index 0000000..ab464b8 --- /dev/null +++ b/src/__tests__/api/tagMindMap.spec.ts @@ -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', + }) + }) +}) diff --git a/src/__tests__/components/TagReview.spec.ts b/src/__tests__/components/TagReview.spec.ts new file mode 100644 index 0000000..d81c085 --- /dev/null +++ b/src/__tests__/components/TagReview.spec.ts @@ -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() + return { ...actual, submitAiTask: vi.fn(), getAiTask: vi.fn(), getLatestAiTask: vi.fn() } +}) + +/** 回忆导图桩:toOutline 的返回值由测试控制 */ +let recallOutline = '- 根主题' +const mindMapStub = { + name: 'MindMapViewer', + template: '
', + 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() + }) +}) diff --git a/src/api/aiTasks.ts b/src/api/aiTasks.ts index 3ef6158..bcc544f 100644 --- a/src/api/aiTasks.ts +++ b/src/api/aiTasks.ts @@ -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; diff --git a/src/api/tagMindMap.ts b/src/api/tagMindMap.ts new file mode 100644 index 0000000..f7ba677 --- /dev/null +++ b/src/api/tagMindMap.ts @@ -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("/review/tag-mind-map/query", { tags, mode }); +}; + +/** 用户编辑标签导图(缩进大纲);该范围还没有导图时保存即为新建 */ +export const updateTagMindMap = (tags: string[], outline: string, mode: TagCombineMode) => { + return request.put("/review/tag-mind-map", { tags, mode, outline }); +}; + +/** 该范围的回忆对比记录(倒序) */ +export const listTagRecallRecords = (tags: string[], mode: TagCombineMode) => { + return request.post("/review/tag-mind-map/recall-records", { tags, mode }); +}; diff --git a/src/components/Review.vue b/src/components/Review.vue index fa9f9c3..6bc3bcd 100644 --- a/src/components/Review.vue +++ b/src/components/Review.vue @@ -441,6 +441,7 @@ onMounted(async () => {
刷新 智能排序偏好 + 按标签复习 标签管理 导出数据
diff --git a/src/components/TagReview.vue b/src/components/TagReview.vue new file mode 100644 index 0000000..469dfb8 --- /dev/null +++ b/src/components/TagReview.vue @@ -0,0 +1,539 @@ + + + + + diff --git a/src/router/index.ts b/src/router/index.ts index 356be8f..b57f99f 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -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",