refactor: StartTask 抽取功能域组合式函数
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
import { ref } from 'vue';
|
||||
import { getReportDraft } from '@/api/studySessions';
|
||||
import { useElapsedSeconds } from './useElapsedSeconds';
|
||||
|
||||
/**
|
||||
* “结束会话总结”弹窗:编辑/预览总结内容。
|
||||
* 有学习残片且尚未填写内容时,先取 AI 聚合草稿作为编辑起点(失败不阻塞手写),
|
||||
* 等待期间展示“已等待 N 秒”提示。
|
||||
*/
|
||||
export function useSummaryReport(options: {
|
||||
getSessionNum: () => string;
|
||||
hasFragments: () => boolean;
|
||||
}) {
|
||||
const summaryDialogVisible = ref(false);
|
||||
const summaryContent = ref("");
|
||||
const summaryPreview = ref(false);
|
||||
const summaryLoading = ref(false);
|
||||
const { seconds: summaryLoadingSeconds, start: startLoadingTimer, stop: stopLoadingTimer } = useElapsedSeconds();
|
||||
|
||||
const openSummaryDialog = async () => {
|
||||
summaryDialogVisible.value = true;
|
||||
// 有残片且未填写过总结时,用 AI 聚合草稿作为编辑起点
|
||||
if (!summaryContent.value.trim() && options.hasFragments()) {
|
||||
summaryLoading.value = true;
|
||||
startLoadingTimer();
|
||||
try {
|
||||
const res = await getReportDraft(options.getSessionNum());
|
||||
if (res?.code === 200 && res.data) {
|
||||
summaryContent.value = res.data;
|
||||
}
|
||||
} catch {
|
||||
// 草稿失败不阻塞手写
|
||||
} finally {
|
||||
summaryLoading.value = false;
|
||||
stopLoadingTimer();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const closeSummaryDialog = () => {
|
||||
summaryDialogVisible.value = false;
|
||||
stopLoadingTimer();
|
||||
};
|
||||
|
||||
return {
|
||||
summaryDialogVisible,
|
||||
summaryContent,
|
||||
summaryPreview,
|
||||
summaryLoading,
|
||||
summaryLoadingSeconds,
|
||||
openSummaryDialog,
|
||||
closeSummaryDialog,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user