fix: 完善任务导航与结束会话错误处理

- 结束会话 API 异常时显示错误,不导航(可重试)
- 结束会话硬跳转改为软导航 router.push
- TaskForm 创建/更新/取消后跳转任务列表页
- 移除 TaskForm 页面内大标题
This commit is contained in:
2026-05-23 22:55:03 +08:00
parent 43e8cd4965
commit fce4ba194b
2 changed files with 22 additions and 31 deletions
+19 -13
View File
@@ -172,16 +172,22 @@ const endTimer = async (content: string) => {
cancelButtonText: "取消", cancelButtonText: "取消",
type: "warning", type: "warning",
}); });
} catch {
// 用户取消结束会话,不做任何操作
return;
}
try {
const res = await endSession(taskInfo.value.sessionNum, content); const res = await endSession(taskInfo.value.sessionNum, content);
if (res.code === 200) { if (res.code === 200) {
ElMessage.success("任务结束"); ElMessage.success("任务结束");
} else {
ElMessage.error(res.message || "结束会话失败");
} }
clear(); clear();
window.location.assign("/study"); await router.push("/study");
} catch { } catch {
// 用户取消结束会话,或接口异常时由请求层统一提示 ElMessage.error("结束会话失败,请重试");
} }
}; };
@@ -238,13 +244,10 @@ onUnmounted(() => {
<template> <template>
<section class="start-page"> <section class="start-page">
<header class="surface-card top-head"> <div class="task-info-bar">
<div>
<h1 class="page-title">{{ taskInfo.taskName || "学习会话" }}</h1>
<p class="page-subtitle">状态{{ statusText }}</p>
</div>
<el-tag type="success" effect="plain">任务编号{{ taskInfo.taskNum }}</el-tag> <el-tag type="success" effect="plain">任务编号{{ taskInfo.taskNum }}</el-tag>
</header> <span class="status-text">状态{{ statusText }}</span>
</div>
<el-alert <el-alert
v-if="taskInfo.systemMessage" v-if="taskInfo.systemMessage"
@@ -331,14 +334,17 @@ onUnmounted(() => {
gap: 14px; gap: 14px;
} }
.top-head { .task-info-bar {
padding: 18px 20px;
display: flex; display: flex;
justify-content: space-between; align-items: center;
align-items: flex-start;
gap: 12px; gap: 12px;
} }
.status-text {
font-size: 14px;
color: var(--text-secondary);
}
.session-grid { .session-grid {
display: grid; display: grid;
grid-template-columns: 380px 1fr; grid-template-columns: 380px 1fr;
+3 -18
View File
@@ -22,12 +22,6 @@ const priority = ref({
}); });
const priorityOptions = [0, 1, 2, 3, 4, 5]; const priorityOptions = [0, 1, 2, 3, 4, 5];
const pageTitle = computed(() => (route.name === "update-task" ? "更新学习任务" : "创建学习任务"));
const pageSubtitle = computed(() =>
route.name === "update-task"
? "修改任务信息后保存,后续学习会话将使用最新内容"
: "填写任务基本信息与优先级维度,帮助系统更好排序"
);
const createTask = () => { const createTask = () => {
request request
@@ -40,7 +34,7 @@ const createTask = () => {
.then((result) => { .then((result) => {
if (result.code === 200) { if (result.code === 200) {
ElMessage.success("创建任务成功"); ElMessage.success("创建任务成功");
router.back(); router.push({ name: "study" });
} else { } else {
ElMessage.error("任务创建失败:" + result.message); ElMessage.error("任务创建失败:" + result.message);
} }
@@ -81,7 +75,7 @@ const updateTask = () => {
.then((result) => { .then((result) => {
if (result.code === 200) { if (result.code === 200) {
ElMessage.success("更新任务成功"); ElMessage.success("更新任务成功");
router.back(); router.push({ name: "study" });
} else { } else {
ElMessage.error("任务更新失败:" + result.message); ElMessage.error("任务更新失败:" + result.message);
} }
@@ -90,7 +84,7 @@ const updateTask = () => {
const cancelTask = () => { const cancelTask = () => {
ElMessage.info("已取消操作"); ElMessage.info("已取消操作");
router.back(); router.push({ name: "study" });
}; };
const submitTask = () => { const submitTask = () => {
@@ -126,11 +120,6 @@ const isMobile = computed(() => screenWidth.value <= 900);
<template> <template>
<section class="task-form-page"> <section class="task-form-page">
<header class="surface-card form-header">
<h1 class="page-title">{{ pageTitle }}</h1>
<p class="page-subtitle">{{ pageSubtitle }}</p>
</header>
<el-form label-position="top" class="surface-card form-shell"> <el-form label-position="top" class="surface-card form-shell">
<div class="group"> <div class="group">
<h3>基础信息</h3> <h3>基础信息</h3>
@@ -195,10 +184,6 @@ const isMobile = computed(() => screenWidth.value <= 900);
gap: 14px; gap: 14px;
} }
.form-header {
padding: 20px 22px;
}
.form-shell { .form-shell {
padding: 22px; padding: 22px;
} }