feat: 任务执行页展示并编辑基础导图
This commit is contained in:
@@ -16,6 +16,7 @@ import {
|
|||||||
startOrContinueStudySession,
|
startOrContinueStudySession,
|
||||||
} from '@/api/studySessions'
|
} from '@/api/studySessions'
|
||||||
import { getFragmentsBySession } from '@/api/reportFragments'
|
import { getFragmentsBySession } from '@/api/reportFragments'
|
||||||
|
import { getStandardMindMap, updateStandardMindMap } from '@/api/standardMindMap'
|
||||||
|
|
||||||
vi.mock('@/api/studySessions', () => ({
|
vi.mock('@/api/studySessions', () => ({
|
||||||
abortSession: vi.fn(),
|
abortSession: vi.fn(),
|
||||||
@@ -47,6 +48,11 @@ vi.mock('@/api/reportFragments', () => ({
|
|||||||
updateFragments: vi.fn(),
|
updateFragments: vi.fn(),
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
vi.mock('@/api/standardMindMap', () => ({
|
||||||
|
getStandardMindMap: vi.fn(),
|
||||||
|
updateStandardMindMap: vi.fn(),
|
||||||
|
}))
|
||||||
|
|
||||||
const defaultSessionData = {
|
const defaultSessionData = {
|
||||||
sessionNum: 'SESSION_001',
|
sessionNum: 'SESSION_001',
|
||||||
sessionState: 'PAUSED',
|
sessionState: 'PAUSED',
|
||||||
@@ -63,7 +69,7 @@ const defaultSessionData = {
|
|||||||
systemMessage: '',
|
systemMessage: '',
|
||||||
}
|
}
|
||||||
|
|
||||||
async function mountTask() {
|
async function mountTask(extraStubs: Record<string, unknown> = {}) {
|
||||||
localStorage.setItem('isLoggedIn', 'true')
|
localStorage.setItem('isLoggedIn', 'true')
|
||||||
const testRouter = createRouter({
|
const testRouter = createRouter({
|
||||||
history: createMemoryHistory(),
|
history: createMemoryHistory(),
|
||||||
@@ -81,6 +87,7 @@ async function mountTask() {
|
|||||||
shallow: true,
|
shallow: true,
|
||||||
global: {
|
global: {
|
||||||
plugins: [ElementPlus, testRouter],
|
plugins: [ElementPlus, testRouter],
|
||||||
|
stubs: extraStubs,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
await flushPromises()
|
await flushPromises()
|
||||||
@@ -95,6 +102,7 @@ describe('StartTask.vue', () => {
|
|||||||
vi.mocked(startOrContinueStudySession).mockResolvedValue({ code: 200, data: defaultSessionData } as any)
|
vi.mocked(startOrContinueStudySession).mockResolvedValue({ code: 200, data: defaultSessionData } as any)
|
||||||
vi.mocked(getExpectation).mockResolvedValue({ code: 200, data: { description: '本次学习预期' } } as any)
|
vi.mocked(getExpectation).mockResolvedValue({ code: 200, data: { description: '本次学习预期' } } as any)
|
||||||
vi.mocked(getFragmentsBySession).mockResolvedValue({ code: 200, data: [] } as any)
|
vi.mocked(getFragmentsBySession).mockResolvedValue({ code: 200, data: [] } as any)
|
||||||
|
vi.mocked(getStandardMindMap).mockResolvedValue({ code: 200, data: null } as any)
|
||||||
vi.mocked(ElMessageBox.confirm).mockResolvedValue('confirm')
|
vi.mocked(ElMessageBox.confirm).mockResolvedValue('confirm')
|
||||||
await router.push('/login')
|
await router.push('/login')
|
||||||
await router.isReady()
|
await router.isReady()
|
||||||
@@ -287,4 +295,68 @@ describe('StartTask.vue', () => {
|
|||||||
expect(router.currentRoute.value.path).not.toBe('/study')
|
expect(router.currentRoute.value.path).not.toBe('/study')
|
||||||
wrapper.unmount()
|
wrapper.unmount()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('闭环-05:展示任务基础导图,并把编辑结果整体 PUT 保存', async () => {
|
||||||
|
vi.mocked(getStandardMindMap).mockResolvedValue({
|
||||||
|
code: 200,
|
||||||
|
data: {
|
||||||
|
id: 1,
|
||||||
|
taskNum: 'T001',
|
||||||
|
title: '根主题',
|
||||||
|
content: JSON.stringify({ title: '根主题', children: [{ title: '子节点', children: [] }] }),
|
||||||
|
outline: '- 根主题\n - 子节点',
|
||||||
|
summary: '',
|
||||||
|
generator: 'AI',
|
||||||
|
sourceReportCount: 1,
|
||||||
|
},
|
||||||
|
} as any)
|
||||||
|
vi.mocked(updateStandardMindMap).mockResolvedValue({
|
||||||
|
code: 200,
|
||||||
|
data: {
|
||||||
|
id: 1,
|
||||||
|
taskNum: 'T001',
|
||||||
|
title: '根主题',
|
||||||
|
content: JSON.stringify({ title: '根主题', children: [{ title: '改过的子节点', children: [] }] }),
|
||||||
|
outline: '- 根主题\n - 改过的子节点',
|
||||||
|
summary: '用户编辑,共 2 个节点',
|
||||||
|
generator: 'USER',
|
||||||
|
sourceReportCount: 1,
|
||||||
|
},
|
||||||
|
} as any)
|
||||||
|
|
||||||
|
const wrapper = await mountTask({
|
||||||
|
MindMapViewer: {
|
||||||
|
name: 'MindMapViewer',
|
||||||
|
template: '<div class="mindmap-stub" />',
|
||||||
|
methods: { toOutline: () => '- 根主题\n - 改过的子节点' },
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
// 拉取到导图后能渲染成树
|
||||||
|
expect(getStandardMindMap).toHaveBeenCalledWith('T001')
|
||||||
|
expect((wrapper.vm.standardTree as any)?.title).toBe('根主题')
|
||||||
|
|
||||||
|
wrapper.vm.startEditStandard()
|
||||||
|
await flushPromises()
|
||||||
|
expect(wrapper.vm.editingStandard).toBe(true)
|
||||||
|
|
||||||
|
await wrapper.vm.saveStandardEdit()
|
||||||
|
|
||||||
|
expect(updateStandardMindMap).toHaveBeenCalledWith('T001', '- 根主题\n - 改过的子节点')
|
||||||
|
expect(wrapper.vm.editingStandard).toBe(false)
|
||||||
|
expect((wrapper.vm.standard as any)?.outline).toBe('- 根主题\n - 改过的子节点')
|
||||||
|
wrapper.unmount()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('闭环-05:没有导图时可用任务名作为根节点新建', async () => {
|
||||||
|
vi.mocked(getStandardMindMap).mockResolvedValue({ code: 200, data: null } as any)
|
||||||
|
const wrapper = await mountTask()
|
||||||
|
|
||||||
|
expect(wrapper.vm.standardTree).toBeNull()
|
||||||
|
wrapper.vm.startEditStandard()
|
||||||
|
await flushPromises()
|
||||||
|
|
||||||
|
expect((wrapper.vm.editableStandardTree as any)?.title).toBe('测试任务')
|
||||||
|
wrapper.unmount()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -23,6 +23,12 @@ import { formatRatio } from "@/utils/format";
|
|||||||
import { useSessionHistory } from "@/components/composables/useSessionHistory";
|
import { useSessionHistory } from "@/components/composables/useSessionHistory";
|
||||||
import { useSummaryReport, isSummarySectionsEmpty, type SummarySections } from "@/components/composables/useSummaryReport";
|
import { useSummaryReport, isSummarySectionsEmpty, type SummarySections } from "@/components/composables/useSummaryReport";
|
||||||
import { useSessionExpectation } from "@/components/composables/useSessionExpectation";
|
import { useSessionExpectation } from "@/components/composables/useSessionExpectation";
|
||||||
|
import {
|
||||||
|
getStandardMindMap,
|
||||||
|
updateStandardMindMap,
|
||||||
|
type StandardMindMap,
|
||||||
|
} from "@/api/standardMindMap";
|
||||||
|
import MindMapViewer, { type MindMapTreeNode } from "@/components/MindMapViewer.vue";
|
||||||
|
|
||||||
const {
|
const {
|
||||||
fragmentsDialogVisible,
|
fragmentsDialogVisible,
|
||||||
@@ -507,6 +513,66 @@ const restTimer = async () => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 闭环-05:任务执行页展示并就地编辑该任务的基础导图
|
||||||
|
const standard = ref<StandardMindMap | null>(null);
|
||||||
|
const editingStandard = ref(false);
|
||||||
|
const savingStandard = ref(false);
|
||||||
|
const editViewer = ref<InstanceType<typeof MindMapViewer> | null>(null);
|
||||||
|
|
||||||
|
const standardTree = computed<MindMapTreeNode | null>(() => {
|
||||||
|
if (!standard.value?.content) return null;
|
||||||
|
try {
|
||||||
|
return JSON.parse(standard.value.content) as MindMapTreeNode;
|
||||||
|
} catch {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
/** 编辑态的初始树:没有导图时给一个以任务名命名的根节点,保存即新建 */
|
||||||
|
const editableStandardTree = computed<MindMapTreeNode | null>(() => {
|
||||||
|
if (standardTree.value) return standardTree.value;
|
||||||
|
if (!editingStandard.value) return null;
|
||||||
|
return { title: taskInfo.value.taskName || `任务 ${taskNum}`, children: [] };
|
||||||
|
});
|
||||||
|
|
||||||
|
const loadStandardMindMap = async () => {
|
||||||
|
try {
|
||||||
|
const res = await getStandardMindMap(taskNum);
|
||||||
|
standard.value = res?.data || null;
|
||||||
|
} catch {
|
||||||
|
// 非关键数据:拉取失败不影响学习页主流程
|
||||||
|
standard.value = null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const startEditStandard = () => {
|
||||||
|
editingStandard.value = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
const cancelStandardEdit = () => {
|
||||||
|
editingStandard.value = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
// 全量编辑:导出大纲后整体 PUT,与回忆页口径一致
|
||||||
|
const saveStandardEdit = async () => {
|
||||||
|
const outline = editViewer.value?.toOutline() || "";
|
||||||
|
if (outline.split(/\r?\n/).filter((line) => line.trim()).length <= 1) {
|
||||||
|
ElMessage.warning("导图至少需要一个节点");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
savingStandard.value = true;
|
||||||
|
try {
|
||||||
|
const res = await updateStandardMindMap(taskNum, outline);
|
||||||
|
standard.value = res?.data || null;
|
||||||
|
editingStandard.value = false;
|
||||||
|
ElMessage.success("基础导图已更新");
|
||||||
|
} catch (e) {
|
||||||
|
ElMessage.error(errorMessageOf(e, "保存失败"));
|
||||||
|
} finally {
|
||||||
|
savingStandard.value = false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const loadTaskSession = async () => {
|
const loadTaskSession = async () => {
|
||||||
try {
|
try {
|
||||||
const activeRes = await getActiveSession();
|
const activeRes = await getActiveSession();
|
||||||
@@ -538,6 +604,7 @@ const loadTaskSession = async () => {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
await loadExpectation();
|
await loadExpectation();
|
||||||
|
void loadStandardMindMap();
|
||||||
|
|
||||||
// 检查是否有未结束的休息
|
// 检查是否有未结束的休息
|
||||||
const storedEnd = localStorage.getItem(BREAK_END_KEY.value);
|
const storedEnd = localStorage.getItem(BREAK_END_KEY.value);
|
||||||
@@ -720,6 +787,46 @@ defineExpose({
|
|||||||
</el-dialog>
|
</el-dialog>
|
||||||
</article>
|
</article>
|
||||||
|
|
||||||
|
<!-- 闭环-05:基础导图展示与就地编辑 -->
|
||||||
|
<article class="surface-card mindmap-card">
|
||||||
|
<div class="mindmap-header">
|
||||||
|
<h3>基础导图</h3>
|
||||||
|
<div class="mindmap-actions">
|
||||||
|
<template v-if="editingStandard">
|
||||||
|
<el-button size="small" @click="cancelStandardEdit">取消</el-button>
|
||||||
|
<el-button size="small" type="success" :loading="savingStandard" @click="saveStandardEdit">
|
||||||
|
保存
|
||||||
|
</el-button>
|
||||||
|
</template>
|
||||||
|
<el-button v-else size="small" type="success" plain @click="startEditStandard">
|
||||||
|
{{ standard ? "编辑" : "新建导图" }}
|
||||||
|
</el-button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<el-alert
|
||||||
|
v-if="standard && standard.needsUpdate"
|
||||||
|
type="warning"
|
||||||
|
show-icon
|
||||||
|
:closable="false"
|
||||||
|
title="内容归属已变化,这张导图需要重建"
|
||||||
|
description="重建在复习页里手动触发;这里可以先把发现的问题直接改掉。"
|
||||||
|
/>
|
||||||
|
<p v-if="editingStandard" class="mindmap-hint">
|
||||||
|
直接在导图上编辑(Tab 加子节点 / Enter 加同级 / 双击改文字),保存后生效。
|
||||||
|
</p>
|
||||||
|
<MindMapViewer
|
||||||
|
v-if="editingStandard"
|
||||||
|
ref="editViewer"
|
||||||
|
:tree="editableStandardTree"
|
||||||
|
:editable="true"
|
||||||
|
height="50vh"
|
||||||
|
/>
|
||||||
|
<template v-else>
|
||||||
|
<MindMapViewer v-if="standardTree" :tree="standardTree" height="50vh" />
|
||||||
|
<p v-else class="empty-text">这个任务还没有基础导图,点「新建导图」开始。</p>
|
||||||
|
</template>
|
||||||
|
</article>
|
||||||
|
|
||||||
<!-- 学习预期 -->
|
<!-- 学习预期 -->
|
||||||
<article class="surface-card expectation-card" v-if="expectationSaved">
|
<article class="surface-card expectation-card" v-if="expectationSaved">
|
||||||
<span class="expectation-label">本次预期</span>
|
<span class="expectation-label">本次预期</span>
|
||||||
@@ -1081,6 +1188,28 @@ defineExpose({
|
|||||||
padding: 12px 16px;
|
padding: 12px 16px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.mindmap-card {
|
||||||
|
padding: 12px 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mindmap-header {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
margin-bottom: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mindmap-actions {
|
||||||
|
display: flex;
|
||||||
|
gap: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mindmap-hint {
|
||||||
|
margin: 0 0 8px;
|
||||||
|
font-size: 12px;
|
||||||
|
color: var(--text-secondary);
|
||||||
|
}
|
||||||
|
|
||||||
.material-session-header {
|
.material-session-header {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
|||||||
Reference in New Issue
Block a user