feat:增加学习残片生成功能

This commit is contained in:
2025-07-26 15:39:37 +08:00
parent 4faf2db730
commit ae73665e6d
4 changed files with 146 additions and 8 deletions
+75 -6
View File
@@ -2,9 +2,23 @@
<script setup lang="ts">
import { ref, computed, onMounted } from 'vue';
import { useRoute } from 'vue-router';
import { ElMessage } from 'element-plus';
import {ElMessage, ElMessageBox} from 'element-plus';
import { useTimer } from '@/components/composables/useTimer';
import { continueSession, pauseSession, endSession, startOrContinueStudySession } from '@/api/studySessions';
import { useStudyFragment } from '@/components/composables/fragment';
import {routes} from "vue-router/auto-routes";
import router from "@/router";
const {
fragmentsDialogVisible,
fragmentContent,
openFragmentDialog,
closeFragmentDialog,
confirmGenerateFragment
} = useStudyFragment();
const summaryDialogVisible = ref(false);
const summaryContent = ref('');
const route = useRoute();
const taskNum = route.params.taskNum as string;
@@ -76,12 +90,38 @@ const stopTimer = async () => {
clear();
};
const endTimer = async () => {
const res = await endSession(taskInfo.value.sessionNum, "用户手动结束");
if (res.code === 200) ElMessage.success('任务结束');
clear();
const endTimer = async (content: string) => {
if (!content) {
ElMessage.warning('请输入学习总结内容');
return;
}
ElMessageBox.confirm('确定要结束吗?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'info',
}).then(async () => {
const res = await endSession(taskInfo.value.sessionNum, content);
if (res.code === 200) ElMessage.success('任务结束');
router.back();
clear();
})
};
const openSummaryDialog = async () => {
summaryDialogVisible.value = true;
}
const closeSummaryDialog = async () => {
ElMessageBox.alert('确定取消吗?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
}).then(() => {
summaryDialogVisible.value = false;
ElMessage.info('已取消结束操作')
})
}
const restTimer = async () => {
await stopTimer();
runCountdown(5 * 60 * 1000);
@@ -142,10 +182,39 @@ onMounted(() => {
<div class="actions">
<el-button @click="startTimer" :disabled="timerRunning">开始</el-button>
<el-button @click="stopTimer" :disabled="!timerRunning" v-if="!timerIsOver">暂停</el-button>
<el-button @click="openFragmentDialog" :disabled="!timerRunning">生成学习残片</el-button>
<el-button @click="restTimer" v-if="timerIsOver">休息</el-button>
<el-button @click="endTimer">结束</el-button>
<el-button @click="openSummaryDialog">结束</el-button>
</div>
</div>
<el-dialog v-model="fragmentsDialogVisible" title="生成学习残片" width="500px">
<el-input
type="textarea"
v-model="fragmentContent"
placeholder="请输入本次学习的内容"
rows="5"
/>
<template #footer>
<span>
<el-button @click="closeFragmentDialog">取消生成</el-button>
<el-button type="primary" @click="confirmGenerateFragment(taskInfo.sessionNum)">确定生成</el-button>
</span>
</template>
</el-dialog>
<el-dialog v-model="summaryDialogVisible" title="本次学习内容总结" width="500px">
<el-input
type="textarea"
v-model="summaryContent"
placeholder="请输入本次学习的内容总结"
rows="5"
/>
<template #footer>
<span>
<el-button @click="closeSummaryDialog">取消</el-button>
<el-button type="primary" @click="endTimer(summaryContent)">确定</el-button>
</span>
</template>
</el-dialog>
</template>
<style scoped>