feat:增加学习残片生成功能
This commit is contained in:
@@ -0,0 +1,6 @@
|
|||||||
|
// src/api/reportFragments.ts
|
||||||
|
import request from "@/utils/request";
|
||||||
|
|
||||||
|
export const createFragments = (sessionNum: string, content: string) => {
|
||||||
|
return request.post(`/report-fragments`, {sessionNum, content})
|
||||||
|
}
|
||||||
@@ -2,9 +2,23 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, computed, onMounted } from 'vue';
|
import { ref, computed, onMounted } from 'vue';
|
||||||
import { useRoute } from 'vue-router';
|
import { useRoute } from 'vue-router';
|
||||||
import { ElMessage } from 'element-plus';
|
import {ElMessage, ElMessageBox} from 'element-plus';
|
||||||
import { useTimer } from '@/components/composables/useTimer';
|
import { useTimer } from '@/components/composables/useTimer';
|
||||||
import { continueSession, pauseSession, endSession, startOrContinueStudySession } from '@/api/studySessions';
|
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 route = useRoute();
|
||||||
const taskNum = route.params.taskNum as string;
|
const taskNum = route.params.taskNum as string;
|
||||||
@@ -76,12 +90,38 @@ const stopTimer = async () => {
|
|||||||
clear();
|
clear();
|
||||||
};
|
};
|
||||||
|
|
||||||
const endTimer = async () => {
|
const endTimer = async (content: string) => {
|
||||||
const res = await endSession(taskInfo.value.sessionNum, "用户手动结束");
|
if (!content) {
|
||||||
if (res.code === 200) ElMessage.success('任务结束');
|
ElMessage.warning('请输入学习总结内容');
|
||||||
clear();
|
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 () => {
|
const restTimer = async () => {
|
||||||
await stopTimer();
|
await stopTimer();
|
||||||
runCountdown(5 * 60 * 1000);
|
runCountdown(5 * 60 * 1000);
|
||||||
@@ -142,10 +182,39 @@ onMounted(() => {
|
|||||||
<div class="actions">
|
<div class="actions">
|
||||||
<el-button @click="startTimer" :disabled="timerRunning">开始</el-button>
|
<el-button @click="startTimer" :disabled="timerRunning">开始</el-button>
|
||||||
<el-button @click="stopTimer" :disabled="!timerRunning" v-if="!timerIsOver">暂停</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="restTimer" v-if="timerIsOver">休息</el-button>
|
||||||
<el-button @click="endTimer">结束</el-button>
|
<el-button @click="openSummaryDialog">结束</el-button>
|
||||||
</div>
|
</div>
|
||||||
</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>
|
</template>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
|
|||||||
@@ -98,8 +98,6 @@ onMounted(() => {
|
|||||||
<el-descriptions-item label="有效学习时间">1小时</el-descriptions-item>
|
<el-descriptions-item label="有效学习时间">1小时</el-descriptions-item>
|
||||||
<el-descriptions-item label="备注">学习了“动态面板”的基本使用方式</el-descriptions-item>
|
<el-descriptions-item label="备注">学习了“动态面板”的基本使用方式</el-descriptions-item>
|
||||||
</el-descriptions>
|
</el-descriptions>
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<div v-else>
|
<div v-else>
|
||||||
<p>请选择任务或等待任务加载完成。</p>
|
<p>请选择任务或等待任务加载完成。</p>
|
||||||
|
|||||||
@@ -0,0 +1,65 @@
|
|||||||
|
import {ref} from 'vue';
|
||||||
|
import {ElMessage, ElMessageBox} from 'element-plus';
|
||||||
|
import {createFragments} from '@/api/reportFragments';
|
||||||
|
|
||||||
|
export const useStudyFragment = () => {
|
||||||
|
const fragmentsDialogVisible = ref(false);
|
||||||
|
const fragmentContent = ref('');
|
||||||
|
|
||||||
|
const openFragmentDialog = () => {
|
||||||
|
fragmentContent.value = '';
|
||||||
|
fragmentsDialogVisible.value = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
const closeFragmentDialog = () => {
|
||||||
|
ElMessageBox.confirm('确定取消生成吗?', '提示', {
|
||||||
|
confirmButtonText: '确定',
|
||||||
|
cancelButtonText: '取消',
|
||||||
|
type: 'warning',
|
||||||
|
}).then(() => {
|
||||||
|
fragmentsDialogVisible.value = false;
|
||||||
|
ElMessage.info('已取消生成');
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
// 用户取消了操作,无需处理
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const confirmGenerateFragment = async (sessionNum: string) => {
|
||||||
|
if (!fragmentContent.value.trim()) {
|
||||||
|
ElMessage.warning('请输入学习内容!');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ElMessageBox.confirm('确定要生成学习残片吗?', '提示', {
|
||||||
|
confirmButtonText: '确定',
|
||||||
|
cancelButtonText: '取消',
|
||||||
|
type: 'info',
|
||||||
|
})
|
||||||
|
.then(async () => {
|
||||||
|
try {
|
||||||
|
const res = await createFragments(sessionNum, fragmentContent.value);
|
||||||
|
|
||||||
|
if (res.code === 200) {
|
||||||
|
ElMessage.success('学习残片生成成功!');
|
||||||
|
fragmentsDialogVisible.value = false;
|
||||||
|
} else {
|
||||||
|
ElMessage.error(res.message || '生成学习残片失败');
|
||||||
|
}
|
||||||
|
} catch (error: any) {
|
||||||
|
ElMessage.error(error.message || '请求失败');
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
ElMessage.info('已取消生成');
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
fragmentsDialogVisible,
|
||||||
|
fragmentContent,
|
||||||
|
openFragmentDialog,
|
||||||
|
closeFragmentDialog,
|
||||||
|
confirmGenerateFragment,
|
||||||
|
};
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user