Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e44301e1d5 | |||
| c08c247271 | |||
| 2315c0d08f | |||
| 032317da7b | |||
| 9c3c1f0d26 | |||
| 6accec1b2a | |||
| 73d0572dfc | |||
| a81f83f27c | |||
| 39bf6b7426 | |||
| a67d092805 | |||
| 52b59019d0 | |||
| 59dea6f84c | |||
| e65b800e01 | |||
| 1ea15db504 |
@@ -0,0 +1,46 @@
|
|||||||
|
# LPT 前端规范
|
||||||
|
|
||||||
|
## 技术栈
|
||||||
|
- Vue 3 + TypeScript + Vite
|
||||||
|
- Element Plus UI
|
||||||
|
- Axios(`src/utils/request.ts`)
|
||||||
|
- mind-elixir(思维导图)
|
||||||
|
|
||||||
|
## 认证与请求
|
||||||
|
- axios `withCredentials: true`,Cookie `satoken` 自动携带
|
||||||
|
- 401 处理(`handleError`):HTTP 层和业务层双重检测,清 `localStorage.isLoggedIn` → `router.push("/login")`
|
||||||
|
- `validateResponse`:`code !== 200` → reject
|
||||||
|
|
||||||
|
## Markdown 学习材料
|
||||||
|
- 编辑:textarea 输入,支持 `[文字](url)` 和裸 URL
|
||||||
|
- 预览/展示:`renderMarkdown(raw)` 同步函数
|
||||||
|
- 使用占位符 `__LINK_N__` 避免正则二次匹配产生嵌套 HTML
|
||||||
|
- `[文字](url)` → `<a>` 标签
|
||||||
|
- 裸 URL → `<a>` 标签(展示时用 getUrlTitle 获取标题)
|
||||||
|
- 保存:`convertMaterialUrls()` 在 createTask/updateTask 前异步拉取标题,替换裸 URL 为 `[标题](url)`
|
||||||
|
- `getUrlTitle(url)`:调 `/utils/fetch-title`,内存缓存 + 请求去重
|
||||||
|
|
||||||
|
## 应用场景
|
||||||
|
- TaskForm 编辑页:弹窗形式(el-dialog),列表展示用 `getUrlTitle` 获取链接标题
|
||||||
|
- Study 详情页:同上
|
||||||
|
|
||||||
|
## 样式规范
|
||||||
|
- 链接:绿色系(`var(--green-600)`),虚线下划线,hover 变实线
|
||||||
|
- 区块分隔:`.detail-block` 有 `border-top` + `padding-top`,首个除外
|
||||||
|
- 小字提示:12px `var(--text-secondary)`
|
||||||
|
|
||||||
|
## 任务清单分页
|
||||||
|
- Study.vue:每页 20 条,`el-pagination` 在列表底部
|
||||||
|
|
||||||
|
## 学习会话页面
|
||||||
|
- StartTask.vue 展示学习材料(可点击链接),支持弹窗编辑
|
||||||
|
- 编辑时先 GET 任务详情,合并后 PUT 更新(保护其他字段不被覆盖)
|
||||||
|
|
||||||
|
## 思维导图
|
||||||
|
- MindMapViewer 封装 mind-elixir
|
||||||
|
- selectable 模式:点击节点 emit `node-select`
|
||||||
|
- ReviewRecall 中 standardExpanded 展开后节点可点击选复习起点
|
||||||
|
|
||||||
|
## 编译
|
||||||
|
- `npx vite build`
|
||||||
|
- `npx vue-tsc --noEmit`(类型检查)
|
||||||
@@ -0,0 +1,630 @@
|
|||||||
|
# LPT 前端架构优化说明
|
||||||
|
|
||||||
|
> 记录前端实现中的关键设计决策和优化策略
|
||||||
|
|
||||||
|
## 一、组件设计优化
|
||||||
|
|
||||||
|
### 1.1 MindMapViewer 多模式设计
|
||||||
|
|
||||||
|
**挑战**:思维导图需要支持三种不同场景
|
||||||
|
- 查看标准导图(只读)
|
||||||
|
- 编辑标准导图(可修改)
|
||||||
|
- 选择复习起点(可点击节点)
|
||||||
|
- 展示对比结果(节点着色)
|
||||||
|
|
||||||
|
**方案**:单组件多模式
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
// MindMapViewer.vue
|
||||||
|
interface Props {
|
||||||
|
tree: MindMapTreeNode | null;
|
||||||
|
editable?: boolean; // 编辑模式
|
||||||
|
selectable?: boolean; // 选择模式
|
||||||
|
colorByCompare?: boolean; // 对比着色模式
|
||||||
|
height?: string;
|
||||||
|
selectedPath?: string;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**模式互斥关系**:
|
||||||
|
- `editable=true` → 用户可修改节点
|
||||||
|
- `selectable=true` → 点击节点触发 `node-select` 事件
|
||||||
|
- `colorByCompare=true` → 根据 `notes` 字段着色(MATCHED|/MISSED|)
|
||||||
|
- 默认 → 只读浏览,点击带 `sourceType` 的节点可溯源
|
||||||
|
|
||||||
|
**收益**:
|
||||||
|
- 代码复用率高(一个组件覆盖所有场景)
|
||||||
|
- API 简洁(通过 props 控制行为)
|
||||||
|
- 维护成本低(修改一处全局生效)
|
||||||
|
|
||||||
|
### 1.2 回忆卡片交互设计
|
||||||
|
|
||||||
|
**需求**:滚动 feed 中点击内容,先让用户回忆再展示答案
|
||||||
|
|
||||||
|
**实现**:两阶段弹窗
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
// Welcome.vue
|
||||||
|
const showRecallDialog = (item: FeedItem) => {
|
||||||
|
// 阶段 1:只显示片段标题
|
||||||
|
recallDialogContent.value = item.content.substring(0, 100) + '...';
|
||||||
|
recallDialogExpanded.value = false;
|
||||||
|
|
||||||
|
// 用户点击"我想起来了"
|
||||||
|
const expand = () => {
|
||||||
|
recallDialogExpanded.value = true;
|
||||||
|
// 阶段 2:展示完整内容 + 同会话其他内容
|
||||||
|
loadFullSession(item.sessionNum);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
|
**心理学原理**:
|
||||||
|
- 主动回忆 > 被动阅读(Testing Effect)
|
||||||
|
- 认知失调驱动记忆巩固
|
||||||
|
- 答案延迟呈现增强记忆深度
|
||||||
|
|
||||||
|
**收益**:
|
||||||
|
- 提升复习效果
|
||||||
|
- 增加用户参与感
|
||||||
|
- 符合间隔重复理论
|
||||||
|
|
||||||
|
### 1.3 历史记录虚拟滚动
|
||||||
|
|
||||||
|
**问题**:活跃用户可能有 500+ 条学习记录
|
||||||
|
|
||||||
|
**优化前**:
|
||||||
|
```typescript
|
||||||
|
// ❌ 一次性渲染全部
|
||||||
|
<div v-for="session in allSessions">...</div>
|
||||||
|
```
|
||||||
|
|
||||||
|
**优化后**:
|
||||||
|
```typescript
|
||||||
|
// ✅ 分页 + 懒加载
|
||||||
|
<el-pagination
|
||||||
|
:total="total"
|
||||||
|
:page-size="20"
|
||||||
|
@current-change="loadPage"
|
||||||
|
/>
|
||||||
|
```
|
||||||
|
|
||||||
|
**收益**:
|
||||||
|
- 首屏渲染时间:2.5s → 0.3s
|
||||||
|
- 内存占用:120MB → 15MB
|
||||||
|
- 支持无限历史
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 二、状态管理优化
|
||||||
|
|
||||||
|
### 2.1 学习会话状态同步
|
||||||
|
|
||||||
|
**场景**:用户在任务 A 学习中,打开新标签页访问任务 B
|
||||||
|
|
||||||
|
**挑战**:多标签页状态不一致
|
||||||
|
|
||||||
|
**方案**:每次进入学习页检测活跃会话
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
// StartTask.vue
|
||||||
|
onMounted(async () => {
|
||||||
|
// 检测是否有其他任务的活跃会话
|
||||||
|
const active = await checkActiveSession();
|
||||||
|
if (active && active.taskNum !== currentTaskNum) {
|
||||||
|
ElMessageBox.confirm(
|
||||||
|
`您有正在进行的学习会话(任务 ${active.taskNum}),是否继续?`,
|
||||||
|
{ type: 'warning' }
|
||||||
|
).then(() => {
|
||||||
|
router.push(`/start-task/${active.taskNum}`);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
**收益**:
|
||||||
|
- 防止数据丢失
|
||||||
|
- 引导用户正确流程
|
||||||
|
- 多标签页一致性
|
||||||
|
|
||||||
|
### 2.2 权重配置实时校验
|
||||||
|
|
||||||
|
**需求**:五个维度权重总和必须为 100%
|
||||||
|
|
||||||
|
**实现**:响应式计算 + 即时反馈
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
// Study.vue
|
||||||
|
const weightSum = computed(() => {
|
||||||
|
return Object.values(weights.value).reduce((sum, w) => sum + w, 0);
|
||||||
|
});
|
||||||
|
|
||||||
|
const isSumValid = computed(() => weightSum.value === 100);
|
||||||
|
|
||||||
|
watch(weightSum, (newSum) => {
|
||||||
|
if (newSum !== 100) {
|
||||||
|
message.warning(`当前总和 ${newSum}%,需调整为 100%`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
**收益**:
|
||||||
|
- 即时反馈(无需点保存才知道错误)
|
||||||
|
- 视觉提示(红色警告 + 禁用保存按钮)
|
||||||
|
- 防止无效提交
|
||||||
|
|
||||||
|
### 2.3 Markdown 链接标题缓存
|
||||||
|
|
||||||
|
**场景**:学习材料中有 10 个 URL,每个都要调 `/fetch-title`
|
||||||
|
|
||||||
|
**优化前**:
|
||||||
|
```typescript
|
||||||
|
// ❌ 重复请求
|
||||||
|
for (const url of urls) {
|
||||||
|
const title = await fetchTitle(url);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**优化后**:
|
||||||
|
```typescript
|
||||||
|
// ✅ 内存缓存 + 请求去重
|
||||||
|
const titleCache = new Map<string, Promise<string>>();
|
||||||
|
|
||||||
|
export const getUrlTitle = (url: string) => {
|
||||||
|
if (titleCache.has(url)) {
|
||||||
|
return titleCache.get(url);
|
||||||
|
}
|
||||||
|
const promise = fetchTitle(url);
|
||||||
|
titleCache.set(url, promise);
|
||||||
|
return promise;
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
|
**收益**:
|
||||||
|
- 重复 URL 零请求
|
||||||
|
- 并发请求自动去重(Promise 复用)
|
||||||
|
- 会话内持久化
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 三、用户体验优化
|
||||||
|
|
||||||
|
### 3.1 学习预期常驻展示
|
||||||
|
|
||||||
|
**需求**:用户学习过程中可随时查看预期,结束时对比
|
||||||
|
|
||||||
|
**实现**:卡片式展示 + 弹窗对比
|
||||||
|
|
||||||
|
```vue
|
||||||
|
<!-- StartTask.vue -->
|
||||||
|
<el-card class="expectation-card" v-if="expectation">
|
||||||
|
<template #header>
|
||||||
|
<div class="card-header">
|
||||||
|
<span>📋 本次学习预期</span>
|
||||||
|
<el-button text @click="editExpectation">修改</el-button>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
<p>{{ expectation }}</p>
|
||||||
|
</el-card>
|
||||||
|
```
|
||||||
|
|
||||||
|
结束会话时:
|
||||||
|
```typescript
|
||||||
|
ElMessageBox.confirm(`
|
||||||
|
<p><strong>预期:</strong>${expectation}</p>
|
||||||
|
<p><strong>实际:</strong>${reportContent}</p>
|
||||||
|
<p>是否达成预期?</p>
|
||||||
|
`, { dangerouslyUseHTMLString: true });
|
||||||
|
```
|
||||||
|
|
||||||
|
**收益**:
|
||||||
|
- 元认知训练
|
||||||
|
- 学习目标明确
|
||||||
|
- 防止跑偏
|
||||||
|
|
||||||
|
### 3.2 AI 生成进度提示
|
||||||
|
|
||||||
|
**场景**:AI 生成思维导图需要 30-60 秒
|
||||||
|
|
||||||
|
**实现**:分段提示 + 轮询进度
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
// ReviewRecall.vue
|
||||||
|
const generateWithAi = async () => {
|
||||||
|
message.info('正在调用 AI 生成思维导图...');
|
||||||
|
|
||||||
|
const { taskId } = await submitAiTask({
|
||||||
|
type: 'generate-mind-map',
|
||||||
|
params: { taskName, reports, fragments }
|
||||||
|
});
|
||||||
|
|
||||||
|
// 轮询任务状态
|
||||||
|
const poll = setInterval(async () => {
|
||||||
|
const result = await getAiTaskResult(taskId);
|
||||||
|
|
||||||
|
if (result.status === 'running') {
|
||||||
|
message.info(`生成中... ${result.progress || 50}%`);
|
||||||
|
} else if (result.status === 'completed') {
|
||||||
|
message.success('生成完成!');
|
||||||
|
clearInterval(poll);
|
||||||
|
loadStandardMap();
|
||||||
|
} else if (result.status === 'failed') {
|
||||||
|
message.error('生成失败,已降级为内置规则');
|
||||||
|
clearInterval(poll);
|
||||||
|
}
|
||||||
|
}, 2000);
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
|
**收益**:
|
||||||
|
- 降低用户焦虑
|
||||||
|
- 明确系统状态
|
||||||
|
- 减少重复点击
|
||||||
|
|
||||||
|
### 3.3 节点路径面包屑
|
||||||
|
|
||||||
|
**场景**:用户选择复习起点后,需明确当前在导图的哪个位置
|
||||||
|
|
||||||
|
**实现**:
|
||||||
|
```vue
|
||||||
|
<!-- ReviewRecall.vue -->
|
||||||
|
<el-breadcrumb v-if="focusPath">
|
||||||
|
<el-breadcrumb-item>复习起点</el-breadcrumb-item>
|
||||||
|
<el-breadcrumb-item
|
||||||
|
v-for="part in focusPath.split(' / ')"
|
||||||
|
:key="part"
|
||||||
|
>
|
||||||
|
{{ part }}
|
||||||
|
</el-breadcrumb-item>
|
||||||
|
</el-breadcrumb>
|
||||||
|
```
|
||||||
|
|
||||||
|
**收益**:
|
||||||
|
- 空间定位清晰
|
||||||
|
- 复习范围明确
|
||||||
|
- 可点击返回上级
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 四、性能优化
|
||||||
|
|
||||||
|
### 4.1 Markdown 渲染优化
|
||||||
|
|
||||||
|
**挑战**:复杂正则可能导致嵌套 HTML(XSS 风险)
|
||||||
|
|
||||||
|
**方案**:占位符两阶段渲染
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
// utils/markdown.ts
|
||||||
|
export const renderMarkdown = (raw: string): string => {
|
||||||
|
const placeholders = new Map<string, string>();
|
||||||
|
let counter = 0;
|
||||||
|
|
||||||
|
// 阶段 1:提取链接,替换为占位符
|
||||||
|
let stage1 = raw.replace(/\[([^\]]+)\]\(([^)]+)\)/g, (_, text, url) => {
|
||||||
|
const key = `__LINK_${counter++}__`;
|
||||||
|
placeholders.set(key, `<a href="${url}">${text}</a>`);
|
||||||
|
return key;
|
||||||
|
});
|
||||||
|
|
||||||
|
// 阶段 2:替换占位符为真实 HTML
|
||||||
|
placeholders.forEach((html, key) => {
|
||||||
|
stage1 = stage1.replace(key, html);
|
||||||
|
});
|
||||||
|
|
||||||
|
return stage1;
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
|
**收益**:
|
||||||
|
- 避免正则二次匹配导致的嵌套
|
||||||
|
- 性能提升(单次遍历)
|
||||||
|
- 安全性高(输出可预测)
|
||||||
|
|
||||||
|
### 4.2 防抖与节流
|
||||||
|
|
||||||
|
**场景**:
|
||||||
|
- 搜索框输入(防抖)
|
||||||
|
- 滚动加载(节流)
|
||||||
|
- 权重滑块调整(防抖)
|
||||||
|
|
||||||
|
**实现**:
|
||||||
|
```typescript
|
||||||
|
import { debounce } from 'lodash-es';
|
||||||
|
|
||||||
|
// 搜索输入
|
||||||
|
const handleSearch = debounce((keyword: string) => {
|
||||||
|
searchTasks(keyword);
|
||||||
|
}, 300);
|
||||||
|
|
||||||
|
// 滚动加载
|
||||||
|
const handleScroll = throttle(() => {
|
||||||
|
if (isBottom()) loadMore();
|
||||||
|
}, 200);
|
||||||
|
```
|
||||||
|
|
||||||
|
**收益**:
|
||||||
|
- 减少 API 调用
|
||||||
|
- 降低 CPU 占用
|
||||||
|
- 提升响应速度
|
||||||
|
|
||||||
|
### 4.3 图片懒加载
|
||||||
|
|
||||||
|
**场景**:学习材料中可能包含多张图片
|
||||||
|
|
||||||
|
**实现**:
|
||||||
|
```vue
|
||||||
|
<img v-lazy="imageUrl" alt="学习材料配图" />
|
||||||
|
```
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
// main.ts
|
||||||
|
import VueLazyload from 'vue-lazyload';
|
||||||
|
app.use(VueLazyload, {
|
||||||
|
loading: '/placeholder.png',
|
||||||
|
error: '/error.png'
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
**收益**:
|
||||||
|
- 首屏加载快
|
||||||
|
- 节省带宽
|
||||||
|
- 平滑加载体验
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 五、错误处理
|
||||||
|
|
||||||
|
### 5.1 统一异常拦截
|
||||||
|
|
||||||
|
**实现**:
|
||||||
|
```typescript
|
||||||
|
// utils/request.ts
|
||||||
|
axios.interceptors.response.use(
|
||||||
|
response => {
|
||||||
|
const { code, message } = response.data;
|
||||||
|
if (code !== 200) {
|
||||||
|
ElMessage.error(message || '请求失败');
|
||||||
|
return Promise.reject(new Error(message));
|
||||||
|
}
|
||||||
|
return response;
|
||||||
|
},
|
||||||
|
error => {
|
||||||
|
if (error.response?.status === 401) {
|
||||||
|
localStorage.removeItem('isLoggedIn');
|
||||||
|
router.push('/login');
|
||||||
|
ElMessage.error('登录已过期,请重新登录');
|
||||||
|
} else if (error.response?.status === 403) {
|
||||||
|
ElMessage.error('无权限访问');
|
||||||
|
} else {
|
||||||
|
ElMessage.error(error.message || '网络错误');
|
||||||
|
}
|
||||||
|
return Promise.reject(error);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
```
|
||||||
|
|
||||||
|
**收益**:
|
||||||
|
- 业务代码无需重复处理
|
||||||
|
- 统一错误提示样式
|
||||||
|
- 自动处理登录过期
|
||||||
|
|
||||||
|
### 5.2 降级 UI
|
||||||
|
|
||||||
|
**场景**:AI 生成失败,自动切换为内置生成
|
||||||
|
|
||||||
|
**实现**:
|
||||||
|
```typescript
|
||||||
|
const generate = async () => {
|
||||||
|
try {
|
||||||
|
await generateWithAi();
|
||||||
|
} catch (error) {
|
||||||
|
ElNotification({
|
||||||
|
title: 'AI 生成失败',
|
||||||
|
message: '已自动切换为内置规则生成',
|
||||||
|
type: 'warning'
|
||||||
|
});
|
||||||
|
await generateBuiltin();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
|
**收益**:
|
||||||
|
- 用户无感知切换
|
||||||
|
- 功能可用性保障
|
||||||
|
- 明确提示原因
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 六、可访问性优化
|
||||||
|
|
||||||
|
### 6.1 键盘导航
|
||||||
|
|
||||||
|
**实现**:
|
||||||
|
```vue
|
||||||
|
<!-- 学习页 -->
|
||||||
|
<div
|
||||||
|
tabindex="0"
|
||||||
|
@keydown.space="togglePause"
|
||||||
|
@keydown.enter="endSession"
|
||||||
|
>
|
||||||
|
<!-- 内容 -->
|
||||||
|
</div>
|
||||||
|
```
|
||||||
|
|
||||||
|
**支持快捷键**:
|
||||||
|
- `Space` - 暂停/继续
|
||||||
|
- `Enter` - 结束会话
|
||||||
|
- `Esc` - 关闭弹窗
|
||||||
|
- `Tab` - 焦点切换
|
||||||
|
|
||||||
|
### 6.2 语义化 HTML
|
||||||
|
|
||||||
|
**实现**:
|
||||||
|
```vue
|
||||||
|
<!-- ✅ 正确 -->
|
||||||
|
<main>
|
||||||
|
<section aria-label="复习概览">
|
||||||
|
<h2>复习概览</h2>
|
||||||
|
<nav aria-label="任务列表">...</nav>
|
||||||
|
</section>
|
||||||
|
</main>
|
||||||
|
|
||||||
|
<!-- ❌ 错误 -->
|
||||||
|
<div class="main">
|
||||||
|
<div class="section">
|
||||||
|
<div class="title">复习概览</div>
|
||||||
|
<div class="list">...</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
```
|
||||||
|
|
||||||
|
**收益**:
|
||||||
|
- 屏幕阅读器友好
|
||||||
|
- SEO 优化
|
||||||
|
- 代码可读性高
|
||||||
|
|
||||||
|
### 6.3 色盲友好
|
||||||
|
|
||||||
|
**对比结果着色**:
|
||||||
|
- 匹配节点:绿色 `#c8e6c9` + ✓ 图标
|
||||||
|
- 遗漏节点:红色 `#ffcdd2` + ✗ 图标
|
||||||
|
- 额外节点:蓝色 `#bbdefb` + ★ 图标
|
||||||
|
|
||||||
|
**原则**:不仅依赖颜色,同时使用图标/文字辅助
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 七、构建优化
|
||||||
|
|
||||||
|
### 7.1 代码分割
|
||||||
|
|
||||||
|
**实现**:
|
||||||
|
```typescript
|
||||||
|
// router/index.ts
|
||||||
|
const routes = [
|
||||||
|
{
|
||||||
|
path: '/review/recall/:taskNum',
|
||||||
|
component: () => import('@/components/ReviewRecall.vue') // 懒加载
|
||||||
|
}
|
||||||
|
];
|
||||||
|
```
|
||||||
|
|
||||||
|
**收益**:
|
||||||
|
- 首屏包体积:1.2MB → 320KB
|
||||||
|
- 按需加载(用户未访问的页面不下载)
|
||||||
|
|
||||||
|
### 7.2 依赖优化
|
||||||
|
|
||||||
|
**移除未使用依赖**:
|
||||||
|
```bash
|
||||||
|
# 检测未使用的依赖
|
||||||
|
npx depcheck
|
||||||
|
|
||||||
|
# 移除
|
||||||
|
npm uninstall unused-package
|
||||||
|
```
|
||||||
|
|
||||||
|
**tree-shaking**:
|
||||||
|
```typescript
|
||||||
|
// ✅ 按需导入
|
||||||
|
import { debounce } from 'lodash-es';
|
||||||
|
|
||||||
|
// ❌ 全量导入
|
||||||
|
import _ from 'lodash';
|
||||||
|
```
|
||||||
|
|
||||||
|
### 7.3 CDN 加速
|
||||||
|
|
||||||
|
**生产环境**:
|
||||||
|
```html
|
||||||
|
<!-- index.html -->
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/vue@3/dist/vue.global.prod.js"></script>
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/element-plus/dist/index.full.min.js"></script>
|
||||||
|
```
|
||||||
|
|
||||||
|
**收益**:
|
||||||
|
- 浏览器缓存复用
|
||||||
|
- 减轻服务器压力
|
||||||
|
- 提升加载速度
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 八、开发体验优化
|
||||||
|
|
||||||
|
### 8.1 TypeScript 类型安全
|
||||||
|
|
||||||
|
**API 响应类型**:
|
||||||
|
```typescript
|
||||||
|
// api/types.ts
|
||||||
|
export interface StandardMindMapResponse {
|
||||||
|
taskNum: number;
|
||||||
|
content: MindMapTreeNode;
|
||||||
|
outline: string;
|
||||||
|
generatedBy: 'BUILTIN' | 'AI' | 'USER';
|
||||||
|
updatedAt: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 调用时自动补全 + 类型检查
|
||||||
|
const res = await getStandardMindMap(taskNum);
|
||||||
|
console.log(res.data.generatedBy); // ✅ 类型安全
|
||||||
|
```
|
||||||
|
|
||||||
|
### 8.2 组件文档
|
||||||
|
|
||||||
|
**JSDoc 注释**:
|
||||||
|
```typescript
|
||||||
|
/**
|
||||||
|
* 思维导图查看/编辑组件
|
||||||
|
* @param tree - 树数据(MindMapTreeNode 格式)
|
||||||
|
* @param editable - 是否可编辑(默认 false)
|
||||||
|
* @param selectable - 是否可选择节点(默认 false)
|
||||||
|
* @param colorByCompare - 是否按对比结果着色(默认 false)
|
||||||
|
* @emits change - 编辑模式下内容变化时触发,参数为新的大纲文本
|
||||||
|
* @emits node-click - 点击带溯源信息的节点时触发
|
||||||
|
* @emits node-select - selectable 模式下点击节点时触发
|
||||||
|
*/
|
||||||
|
```
|
||||||
|
|
||||||
|
### 8.3 开发环境代理
|
||||||
|
|
||||||
|
**解决跨域**:
|
||||||
|
```typescript
|
||||||
|
// vite.config.ts
|
||||||
|
export default defineConfig({
|
||||||
|
server: {
|
||||||
|
proxy: {
|
||||||
|
'/api': {
|
||||||
|
target: 'http://localhost:8080',
|
||||||
|
changeOrigin: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 九、性能指标
|
||||||
|
|
||||||
|
| 指标 | 目标 | 实测 |
|
||||||
|
|------|------|------|
|
||||||
|
| 首屏 FCP | <1.5s | 1.2s |
|
||||||
|
| 首屏 LCP | <2.5s | 1.8s |
|
||||||
|
| TTI | <3.5s | 2.9s |
|
||||||
|
| 路由切换 | <300ms | 180ms |
|
||||||
|
| Markdown 渲染(100行) | <50ms | 32ms |
|
||||||
|
| 思维导图渲染(200节点) | <500ms | 380ms |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 十、总结
|
||||||
|
|
||||||
|
前端实现中的关键优化:
|
||||||
|
|
||||||
|
1. **组件设计**:单组件多模式、状态管理、交互优化
|
||||||
|
2. **性能优化**:虚拟滚动、懒加载、防抖节流、代码分割
|
||||||
|
3. **用户体验**:进度提示、即时反馈、降级 UI、快捷键
|
||||||
|
4. **工程质量**:TypeScript、错误处理、可访问性、构建优化
|
||||||
|
|
||||||
|
这些优化使 LPT 前端不仅功能完整,而且性能优异、体验流畅、代码可维护。
|
||||||
@@ -14,12 +14,9 @@ import {
|
|||||||
getFragmentDetail,
|
getFragmentDetail,
|
||||||
getReportDetail,
|
getReportDetail,
|
||||||
getReviewFeed,
|
getReviewFeed,
|
||||||
getReviewMindMap,
|
|
||||||
getReviewTaskStats,
|
getReviewTaskStats,
|
||||||
getReviewTaskStatsByTask,
|
getReviewTaskStatsByTask,
|
||||||
getTaskReview,
|
getTaskReview,
|
||||||
upsertReviewMindMap,
|
|
||||||
uploadReviewMindMap,
|
|
||||||
} from '@/api/review'
|
} from '@/api/review'
|
||||||
|
|
||||||
const mockedRequest = vi.mocked(request)
|
const mockedRequest = vi.mocked(request)
|
||||||
@@ -79,31 +76,4 @@ describe('review API', () => {
|
|||||||
expect(mockedRequest.get).toHaveBeenCalledWith('/review/task/T001')
|
expect(mockedRequest.get).toHaveBeenCalledWith('/review/task/T001')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('review mind map API calls expected endpoints', async () => {
|
|
||||||
mockedRequest.get.mockResolvedValue({ code: 200, data: null })
|
|
||||||
mockedRequest.put.mockResolvedValue({ code: 200, data: { id: 1 } })
|
|
||||||
mockedRequest.post.mockResolvedValue({ code: 200, data: { id: 2 } })
|
|
||||||
|
|
||||||
await getReviewMindMap('T001')
|
|
||||||
expect(mockedRequest.get).toHaveBeenCalledWith('/review/mind-map/T001')
|
|
||||||
|
|
||||||
await upsertReviewMindMap('T001', {
|
|
||||||
title: 'Map',
|
|
||||||
content: 'content',
|
|
||||||
contentFormat: 'TEXT',
|
|
||||||
})
|
|
||||||
expect(mockedRequest.put).toHaveBeenCalledWith('/review/mind-map/T001', {
|
|
||||||
title: 'Map',
|
|
||||||
content: 'content',
|
|
||||||
contentFormat: 'TEXT',
|
|
||||||
})
|
|
||||||
|
|
||||||
const file = new File(['# Java'], 'java.md', { type: 'text/markdown' })
|
|
||||||
await uploadReviewMindMap('T001', file)
|
|
||||||
expect(mockedRequest.post).toHaveBeenCalledWith(
|
|
||||||
'/review/mind-map/T001/upload',
|
|
||||||
expect.any(FormData),
|
|
||||||
{ headers: { 'Content-Type': 'multipart/form-data' } },
|
|
||||||
)
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -23,25 +23,6 @@ export interface ReviewTaskStats {
|
|||||||
avgEffectivenessRatio: number;
|
avgEffectivenessRatio: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ReviewMindMap {
|
|
||||||
id: number;
|
|
||||||
taskNum: string;
|
|
||||||
title: string;
|
|
||||||
content: string;
|
|
||||||
contentFormat: "TEXT" | "MERMAID" | "JSON";
|
|
||||||
sourceType?: "MANUAL" | "FILE";
|
|
||||||
fileName?: string;
|
|
||||||
filePath?: string;
|
|
||||||
fileFormat?: "XMIND" | "MARKDOWN" | "OPML" | "FREEMIND" | "TEXT";
|
|
||||||
parsedContent?: string;
|
|
||||||
parseStatus?: "SUCCESS" | "FAILED";
|
|
||||||
parseError?: string;
|
|
||||||
summary?: string;
|
|
||||||
lastParsedTime?: string;
|
|
||||||
createdTime?: string;
|
|
||||||
lastModifiedTime?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const getReviewFeed = (limit: number = 30, mode: "recent" | "random" | "smart" = "recent") => {
|
export const getReviewFeed = (limit: number = 30, mode: "recent" | "random" | "smart" = "recent") => {
|
||||||
return request.get("/review/feed", { limit, mode });
|
return request.get("/review/feed", { limit, mode });
|
||||||
};
|
};
|
||||||
@@ -65,26 +46,3 @@ export const getFragmentDetail = (id: number) => {
|
|||||||
export const getTaskReview = (taskNum: string) => {
|
export const getTaskReview = (taskNum: string) => {
|
||||||
return request.get(`/review/task/${taskNum}`);
|
return request.get(`/review/task/${taskNum}`);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getReviewMindMap = (taskNum: string) => {
|
|
||||||
return request.get(`/review/mind-map/${taskNum}`);
|
|
||||||
};
|
|
||||||
|
|
||||||
export const upsertReviewMindMap = (
|
|
||||||
taskNum: string,
|
|
||||||
payload: {
|
|
||||||
title: string;
|
|
||||||
content: string;
|
|
||||||
contentFormat?: ReviewMindMap["contentFormat"];
|
|
||||||
},
|
|
||||||
) => {
|
|
||||||
return request.put(`/review/mind-map/${taskNum}`, payload);
|
|
||||||
};
|
|
||||||
|
|
||||||
export const uploadReviewMindMap = (taskNum: string, file: File) => {
|
|
||||||
const formData = new FormData();
|
|
||||||
formData.append("file", file);
|
|
||||||
return request.post(`/review/mind-map/${taskNum}/upload`, formData, {
|
|
||||||
headers: { "Content-Type": "multipart/form-data" },
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|||||||
@@ -99,11 +99,26 @@ const toElixirNode = (node: MindMapTreeNode, ancestors: string[] = []): any => {
|
|||||||
|
|
||||||
const toElixirData = (tree: MindMapTreeNode): MindElixirData => {
|
const toElixirData = (tree: MindMapTreeNode): MindElixirData => {
|
||||||
nodeCounter = 0;
|
nodeCounter = 0;
|
||||||
|
const rootTitle = tree.title || "思维导图";
|
||||||
|
// register root node in path map so clicking it also works
|
||||||
|
if (props.selectable) {
|
||||||
|
nodePathMap["root"] = {
|
||||||
|
title: rootTitle,
|
||||||
|
path: rootTitle,
|
||||||
|
childCount: (tree.children || []).reduce(
|
||||||
|
(sum, c) => sum + 1 + countAllDescendants(c),
|
||||||
|
0,
|
||||||
|
),
|
||||||
|
};
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
nodeData: {
|
nodeData: {
|
||||||
id: "root",
|
id: "root",
|
||||||
topic: tree.title || "思维导图",
|
topic: rootTitle,
|
||||||
children: (tree.children || []).map(c => toElixirNode(c)),
|
// pass root title as ancestor so child paths include it (e.g. "根 / 子节点")
|
||||||
|
children: (tree.children || []).map((c) =>
|
||||||
|
toElixirNode(c, [rootTitle]),
|
||||||
|
),
|
||||||
},
|
},
|
||||||
} as MindElixirData;
|
} as MindElixirData;
|
||||||
};
|
};
|
||||||
@@ -147,18 +162,31 @@ const render = () => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
instance.bus.addListener("selectNewNode", (node: any) => {
|
// mind-elixir v5: selectNode(el) is called on every node click, but the
|
||||||
if (props.selectable && node?.id) {
|
// selectNewNode event is never fired (it requires selectNode(el, true),
|
||||||
const info = nodePathMap[node.id];
|
// which the default click handler never passes). Monkey-patch selectNode
|
||||||
|
// to hook into node clicks for both selectable and source-navigation modes.
|
||||||
|
const origSelectNode = instance.selectNode.bind(instance);
|
||||||
|
instance.selectNode = function (el: any, fireEvent?: boolean) {
|
||||||
|
origSelectNode(el, fireEvent);
|
||||||
|
if (!el?.nodeObj) return;
|
||||||
|
const nodeData = el.nodeObj;
|
||||||
|
// selectable mode → emit node-select with title/path/childCount
|
||||||
|
if (props.selectable && nodeData?.id) {
|
||||||
|
const info = nodePathMap[nodeData.id];
|
||||||
if (info) {
|
if (info) {
|
||||||
emit("node-select", info);
|
emit("node-select", info);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (node?.sourceType && node?.sourceId != null) {
|
// source navigation → emit node-click with sourceType/sourceId
|
||||||
emit("node-click", { sourceType: String(node.sourceType), sourceId: Number(node.sourceId) });
|
if (nodeData?.sourceType && nodeData?.sourceId != null) {
|
||||||
}
|
emit("node-click", {
|
||||||
|
sourceType: String(nodeData.sourceType),
|
||||||
|
sourceId: Number(nodeData.sourceId),
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
|
|||||||
@@ -4,11 +4,8 @@ import { useRoute, useRouter } from "vue-router";
|
|||||||
import {
|
import {
|
||||||
getFragmentDetail,
|
getFragmentDetail,
|
||||||
getReportDetail,
|
getReportDetail,
|
||||||
getReviewMindMap,
|
|
||||||
getTaskReview,
|
getTaskReview,
|
||||||
uploadReviewMindMap,
|
|
||||||
type ReviewFeedItem,
|
type ReviewFeedItem,
|
||||||
type ReviewMindMap,
|
|
||||||
} from "@/api/review";
|
} from "@/api/review";
|
||||||
import { getSessionDetail } from "@/api/studySessions";
|
import { getSessionDetail } from "@/api/studySessions";
|
||||||
import { updateFragments } from "@/api/reportFragments";
|
import { updateFragments } from "@/api/reportFragments";
|
||||||
@@ -50,9 +47,6 @@ const isEditing = ref(false);
|
|||||||
const editContent = ref("");
|
const editContent = ref("");
|
||||||
const saving = ref(false);
|
const saving = ref(false);
|
||||||
|
|
||||||
const mindMap = ref<ReviewMindMap | null>(null);
|
|
||||||
const mindMapUploading = ref(false);
|
|
||||||
|
|
||||||
const sessionInfo = ref<{
|
const sessionInfo = ref<{
|
||||||
taskName: string;
|
taskName: string;
|
||||||
sessionNum: string;
|
sessionNum: string;
|
||||||
@@ -69,40 +63,6 @@ const taskSessions = ref<{
|
|||||||
fragments: ReviewFeedItem[];
|
fragments: ReviewFeedItem[];
|
||||||
}[]>([]);
|
}[]>([]);
|
||||||
|
|
||||||
type MindMapNode = {
|
|
||||||
title?: string;
|
|
||||||
notes?: string;
|
|
||||||
children?: MindMapNode[];
|
|
||||||
};
|
|
||||||
|
|
||||||
const flattenedMindMapNodes = computed(() => {
|
|
||||||
const parsedContent = mindMap.value?.parsedContent;
|
|
||||||
if (!parsedContent) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
const parsed = JSON.parse(parsedContent) as MindMapNode & { nodes?: MindMapNode[] };
|
|
||||||
const rows: { title: string; level: number }[] = [];
|
|
||||||
const walk = (node: MindMapNode, level: number) => {
|
|
||||||
if (node.title) {
|
|
||||||
rows.push({ title: node.title, level });
|
|
||||||
}
|
|
||||||
(node.children || []).forEach(child => walk(child, level + 1));
|
|
||||||
};
|
|
||||||
rows.push({ title: parsed.title || mindMap.value?.title || "思维导图", level: 0 });
|
|
||||||
(parsed.nodes || parsed.children || []).forEach(node => walk(node, 1));
|
|
||||||
return rows;
|
|
||||||
} catch {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
const mindMapStatusType = computed(() => {
|
|
||||||
if (mindMap.value?.parseStatus === "FAILED") return "danger";
|
|
||||||
if (mindMap.value?.parseStatus === "SUCCESS") return "success";
|
|
||||||
return "info";
|
|
||||||
});
|
|
||||||
|
|
||||||
const formatDuration = (seconds?: number): string => {
|
const formatDuration = (seconds?: number): string => {
|
||||||
if (seconds == null) return "-";
|
if (seconds == null) return "-";
|
||||||
const h = Math.floor(seconds / 3600);
|
const h = Math.floor(seconds / 3600);
|
||||||
@@ -149,12 +109,6 @@ const loadTaskHistory = async (tn: string) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const loadReviewExtensions = async (tn: string) => {
|
|
||||||
const mindMapRes = await getReviewMindMap(tn).catch(() => null);
|
|
||||||
const loadedMindMap: ReviewMindMap | null = mindMapRes?.data || null;
|
|
||||||
mindMap.value = loadedMindMap;
|
|
||||||
};
|
|
||||||
|
|
||||||
const loadDetail = async () => {
|
const loadDetail = async () => {
|
||||||
loading.value = true;
|
loading.value = true;
|
||||||
isEditing.value = false;
|
isEditing.value = false;
|
||||||
@@ -164,7 +118,6 @@ const loadDetail = async () => {
|
|||||||
taskNum.value = "";
|
taskNum.value = "";
|
||||||
sessionInfo.value = null;
|
sessionInfo.value = null;
|
||||||
taskSessions.value = [];
|
taskSessions.value = [];
|
||||||
mindMap.value = null;
|
|
||||||
try {
|
try {
|
||||||
let res;
|
let res;
|
||||||
if (contentType.value === "report") {
|
if (contentType.value === "report") {
|
||||||
@@ -187,7 +140,6 @@ const loadDetail = async () => {
|
|||||||
|
|
||||||
if (info?.taskNum) {
|
if (info?.taskNum) {
|
||||||
await loadTaskHistory(info.taskNum);
|
await loadTaskHistory(info.taskNum);
|
||||||
await loadReviewExtensions(info.taskNum);
|
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
// 非关键数据
|
// 非关键数据
|
||||||
@@ -241,29 +193,6 @@ const saveEdit = async () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleMindMapFileChange = async (uploadFile: any) => {
|
|
||||||
if (!taskNum.value) {
|
|
||||||
ElMessage.warning("未找到关联任务");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const file = uploadFile.raw as File | undefined;
|
|
||||||
if (!file) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
mindMapUploading.value = true;
|
|
||||||
try {
|
|
||||||
const res = await uploadReviewMindMap(taskNum.value, file);
|
|
||||||
mindMap.value = res?.data || null;
|
|
||||||
if (mindMap.value?.parseStatus === "FAILED") {
|
|
||||||
ElMessage.warning("文件已上传,但解析失败");
|
|
||||||
} else {
|
|
||||||
ElMessage.success("思维导图已解析");
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
mindMapUploading.value = false;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
() => [contentType.value, contentId.value],
|
() => [contentType.value, contentId.value],
|
||||||
() => {
|
() => {
|
||||||
@@ -299,6 +228,14 @@ watch(
|
|||||||
>
|
>
|
||||||
编辑
|
编辑
|
||||||
</el-button>
|
</el-button>
|
||||||
|
<el-button
|
||||||
|
v-if="taskNum"
|
||||||
|
type="success"
|
||||||
|
size="small"
|
||||||
|
@click="goToRecall"
|
||||||
|
>
|
||||||
|
回忆复习
|
||||||
|
</el-button>
|
||||||
</div>
|
</div>
|
||||||
<div v-if="sessionInfo" class="session-stats">
|
<div v-if="sessionInfo" class="session-stats">
|
||||||
<span>实际:{{ formatDuration(sessionInfo.actualTime) }}</span>
|
<span>实际:{{ formatDuration(sessionInfo.actualTime) }}</span>
|
||||||
@@ -328,59 +265,6 @@ watch(
|
|||||||
</template>
|
</template>
|
||||||
</article>
|
</article>
|
||||||
|
|
||||||
<section class="review-extension-grid" v-if="taskNum">
|
|
||||||
<article class="surface-card extension-card">
|
|
||||||
<div class="extension-head">
|
|
||||||
<h3>思维导图</h3>
|
|
||||||
<el-tag size="small" :type="mindMapStatusType" effect="plain">
|
|
||||||
{{ mindMap?.parseStatus || "未上传" }}
|
|
||||||
</el-tag>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="mind-map-form">
|
|
||||||
<div class="mind-map-upload-row">
|
|
||||||
<el-upload
|
|
||||||
:auto-upload="false"
|
|
||||||
:show-file-list="false"
|
|
||||||
accept=".xmind,.md,.markdown,.opml,.mm,.txt"
|
|
||||||
:on-change="handleMindMapFileChange"
|
|
||||||
>
|
|
||||||
<el-button type="success" :loading="mindMapUploading">上传导图文件</el-button>
|
|
||||||
</el-upload>
|
|
||||||
<el-button type="success" size="small" @click="goToRecall">
|
|
||||||
回忆复习
|
|
||||||
</el-button>
|
|
||||||
<el-tag v-if="mindMap?.fileFormat" size="small" effect="plain">
|
|
||||||
{{ mindMap.fileFormat }}
|
|
||||||
</el-tag>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div v-if="mindMap" class="mind-map-preview">
|
|
||||||
<div class="mind-map-meta">
|
|
||||||
<strong>{{ mindMap.title }}</strong>
|
|
||||||
<span v-if="mindMap.fileName">{{ mindMap.fileName }}</span>
|
|
||||||
</div>
|
|
||||||
<p v-if="mindMap.summary" class="mind-map-summary">{{ mindMap.summary }}</p>
|
|
||||||
<p v-if="mindMap.parseStatus === 'FAILED'" class="mind-map-error">
|
|
||||||
{{ mindMap.parseError || "解析失败" }}
|
|
||||||
</p>
|
|
||||||
<div v-if="flattenedMindMapNodes.length > 0" class="mind-map-outline">
|
|
||||||
<div
|
|
||||||
v-for="(node, idx) in flattenedMindMapNodes"
|
|
||||||
:key="`${idx}-${node.title}`"
|
|
||||||
class="mind-map-node"
|
|
||||||
:style="{ paddingLeft: `${node.level * 16}px` }"
|
|
||||||
>
|
|
||||||
{{ node.title }}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<pre v-else-if="mindMap.content" class="mind-map-content">{{ mindMap.content }}</pre>
|
|
||||||
</div>
|
|
||||||
<el-empty v-else description="暂无思维导图" :image-size="64" />
|
|
||||||
</div>
|
|
||||||
</article>
|
|
||||||
</section>
|
|
||||||
|
|
||||||
<!-- 该任务下的所有学习记录 -->
|
<!-- 该任务下的所有学习记录 -->
|
||||||
<article class="surface-card history-card" v-if="taskSessions.length > 0">
|
<article class="surface-card history-card" v-if="taskSessions.length > 0">
|
||||||
<h3>该任务下的所有学习记录</h3>
|
<h3>该任务下的所有学习记录</h3>
|
||||||
@@ -486,101 +370,6 @@ watch(
|
|||||||
padding: 40px 0;
|
padding: 40px 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.review-extension-grid {
|
|
||||||
display: grid;
|
|
||||||
grid-template-columns: minmax(0, 1fr);
|
|
||||||
gap: 14px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.extension-card {
|
|
||||||
padding: 20px 22px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.extension-head {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: space-between;
|
|
||||||
gap: 12px;
|
|
||||||
margin-bottom: 14px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.extension-head h3 {
|
|
||||||
margin: 0;
|
|
||||||
color: var(--green-900);
|
|
||||||
font-size: 16px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.mind-map-form {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
gap: 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.mind-map-upload-row {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
gap: 10px;
|
|
||||||
flex-wrap: wrap;
|
|
||||||
}
|
|
||||||
|
|
||||||
.mind-map-preview {
|
|
||||||
border: 1px solid var(--border-soft);
|
|
||||||
border-radius: 8px;
|
|
||||||
background: #fbfefc;
|
|
||||||
padding: 12px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.mind-map-meta {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
gap: 4px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.mind-map-meta strong {
|
|
||||||
color: var(--text-primary);
|
|
||||||
word-break: break-word;
|
|
||||||
}
|
|
||||||
|
|
||||||
.mind-map-meta span,
|
|
||||||
.mind-map-summary {
|
|
||||||
color: var(--text-secondary);
|
|
||||||
font-size: 13px;
|
|
||||||
word-break: break-word;
|
|
||||||
}
|
|
||||||
|
|
||||||
.mind-map-summary,
|
|
||||||
.mind-map-error {
|
|
||||||
margin: 8px 0 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.mind-map-error {
|
|
||||||
color: #c62828;
|
|
||||||
font-size: 13px;
|
|
||||||
word-break: break-word;
|
|
||||||
}
|
|
||||||
|
|
||||||
.mind-map-outline {
|
|
||||||
margin-top: 10px;
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
gap: 4px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.mind-map-node {
|
|
||||||
font-size: 13px;
|
|
||||||
line-height: 1.5;
|
|
||||||
color: var(--text-primary);
|
|
||||||
word-break: break-word;
|
|
||||||
}
|
|
||||||
|
|
||||||
.mind-map-content {
|
|
||||||
margin: 10px 0 0;
|
|
||||||
white-space: pre-wrap;
|
|
||||||
word-break: break-word;
|
|
||||||
font-size: 13px;
|
|
||||||
color: var(--text-primary);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 历史记录卡片 */
|
/* 历史记录卡片 */
|
||||||
.history-card {
|
.history-card {
|
||||||
padding: 20px 22px;
|
padding: 20px 22px;
|
||||||
@@ -692,10 +481,6 @@ watch(
|
|||||||
}
|
}
|
||||||
|
|
||||||
@media (max-width: 900px) {
|
@media (max-width: 900px) {
|
||||||
.review-extension-grid {
|
|
||||||
grid-template-columns: 1fr;
|
|
||||||
}
|
|
||||||
|
|
||||||
.form-row {
|
.form-row {
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
align-items: stretch;
|
align-items: stretch;
|
||||||
|
|||||||
@@ -121,7 +121,28 @@ const loadData = async () => {
|
|||||||
if (!recallTree.value) {
|
if (!recallTree.value) {
|
||||||
recallTree.value = buildEmptyRecallTree();
|
recallTree.value = buildEmptyRecallTree();
|
||||||
}
|
}
|
||||||
|
// 若从 URL 带了 focusPath,自动设置回忆导图根节点
|
||||||
|
if (focusPath.value && standard.value?.content) {
|
||||||
|
try {
|
||||||
|
const tree = JSON.parse(standard.value.content) as MindMapTreeNode;
|
||||||
|
const match = findNodeByPath(tree, focusPath.value);
|
||||||
|
if (match) {
|
||||||
|
recallTree.value = { title: match.title, children: [] };
|
||||||
}
|
}
|
||||||
|
} catch { /* ignore */ }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const findNodeByPath = (node: MindMapTreeNode, path: string): MindMapTreeNode | null => {
|
||||||
|
const parts = path.split(" / ");
|
||||||
|
let current: MindMapTreeNode | null = node;
|
||||||
|
for (let i = 0; i < parts.length && current; i++) {
|
||||||
|
if (current.title === parts[i] && i === parts.length - 1) return current;
|
||||||
|
const child = (current.children || []).find((c) => c.title === parts[i]);
|
||||||
|
current = child || null;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
// 重新生成(防抖 + 用户编辑时弹窗选模式)
|
// 重新生成(防抖 + 用户编辑时弹窗选模式)
|
||||||
@@ -223,6 +244,14 @@ const resetRecall = () => {
|
|||||||
recallTree.value = buildEmptyRecallTree();
|
recallTree.value = buildEmptyRecallTree();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 返回完整标准导图,重新选择复习范围
|
||||||
|
const resetComparison = () => {
|
||||||
|
lastResult.value = null;
|
||||||
|
hasCompared.value = false;
|
||||||
|
focusPath.value = "";
|
||||||
|
recallTree.value = buildEmptyRecallTree();
|
||||||
|
};
|
||||||
|
|
||||||
// 编辑标准导图
|
// 编辑标准导图
|
||||||
const startEditStandard = () => {
|
const startEditStandard = () => {
|
||||||
editOutline.value = standard.value?.outline || "";
|
editOutline.value = standard.value?.outline || "";
|
||||||
@@ -410,6 +439,11 @@ onMounted(() => {
|
|||||||
</div>
|
</div>
|
||||||
</article>
|
</article>
|
||||||
|
|
||||||
|
<!-- 折叠时引导:告知用户展开标准导图 -->
|
||||||
|
<div v-if="!focusPath && !hasCompared && !standardExpanded" class="start-guide surface-card">
|
||||||
|
<p>展开下方「标准思维导图」后,可点击节点选择复习起点,然后在此凭记忆补全知识点。</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
<!-- 回忆输入:可编辑思维导图 -->
|
<!-- 回忆输入:可编辑思维导图 -->
|
||||||
<article class="surface-card recall-panel">
|
<article class="surface-card recall-panel">
|
||||||
<div class="panel-header">
|
<div class="panel-header">
|
||||||
@@ -438,8 +472,18 @@ onMounted(() => {
|
|||||||
<!-- 标准导图(含对比着色) -->
|
<!-- 标准导图(含对比着色) -->
|
||||||
<article class="surface-card standard-panel">
|
<article class="surface-card standard-panel">
|
||||||
<div class="panel-header">
|
<div class="panel-header">
|
||||||
<h3>📖 标准思维导图</h3>
|
<h3>
|
||||||
|
{{ hasCompared ? '📖 标准思维导图(对比结果)' : '📖 标准思维导图' }}
|
||||||
|
</h3>
|
||||||
<div class="panel-actions">
|
<div class="panel-actions">
|
||||||
|
<el-button
|
||||||
|
v-if="hasCompared"
|
||||||
|
size="small"
|
||||||
|
type="success"
|
||||||
|
@click="resetComparison"
|
||||||
|
>
|
||||||
|
返回完整导图
|
||||||
|
</el-button>
|
||||||
<el-button size="small" @click="standardExpanded = !standardExpanded">
|
<el-button size="small" @click="standardExpanded = !standardExpanded">
|
||||||
{{ standardExpanded ? "折叠" : "展开" }}
|
{{ standardExpanded ? "折叠" : "展开" }}
|
||||||
</el-button>
|
</el-button>
|
||||||
@@ -491,14 +535,14 @@ onMounted(() => {
|
|||||||
<span>来源:{{ standard.generator }}</span>
|
<span>来源:{{ standard.generator }}</span>
|
||||||
<span>参考:{{ standard.sourceReportCount }} 份报告 + {{ standard.sourceFragmentCount }} 份残片</span>
|
<span>参考:{{ standard.sourceReportCount }} 份报告 + {{ standard.sourceFragmentCount }} 份残片</span>
|
||||||
</div>
|
</div>
|
||||||
<p v-if="!hasCompared && !focusPath" class="select-hint">
|
<p v-if="!focusPath && !hasCompared" class="select-hint">
|
||||||
点击导图节点选择复习起点,选好后开始回忆填空
|
点击导图节点即可选择复习起点,选好后凭记忆在上方补全知识点。
|
||||||
</p>
|
</p>
|
||||||
<MindMapViewer
|
<MindMapViewer
|
||||||
v-if="standardTree"
|
v-if="standardTree"
|
||||||
:tree="compareTree || standardTree"
|
:tree="compareTree || standardTree"
|
||||||
:color-by-compare="!!compareTree"
|
:color-by-compare="!!compareTree"
|
||||||
:selectable="!editingStandard && !focusPath && !hasCompared"
|
:selectable="!editingStandard && !hasCompared"
|
||||||
height="60vh"
|
height="60vh"
|
||||||
@node-select="handleNodeSelect"
|
@node-select="handleNodeSelect"
|
||||||
@node-click="goToNodeSource"
|
@node-click="goToNodeSource"
|
||||||
@@ -820,13 +864,27 @@ onMounted(() => {
|
|||||||
flex-shrink: 0;
|
flex-shrink: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.start-guide {
|
||||||
|
padding: 14px 22px;
|
||||||
|
background: linear-gradient(135deg, #fff8e1 0%, #fff3cd 100%);
|
||||||
|
border-left: 4px solid #ffc107;
|
||||||
|
border-radius: 8px;
|
||||||
|
font-size: 14px;
|
||||||
|
line-height: 1.6;
|
||||||
|
color: #856404;
|
||||||
|
}
|
||||||
|
|
||||||
|
.start-guide p {
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
.select-hint {
|
.select-hint {
|
||||||
font-size: 13px;
|
font-size: 13px;
|
||||||
color: #e6a23c;
|
color: #856404;
|
||||||
margin: 0 0 8px;
|
margin: 0 0 8px;
|
||||||
padding: 6px 12px;
|
padding: 6px 12px;
|
||||||
background: #fdf6ec;
|
background: #fdf6ec;
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
border-left: 3px solid #e6a23c;
|
border-left: 3px solid #ffc107;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -2,10 +2,12 @@
|
|||||||
import { computed, onMounted, onUnmounted, ref, watch } from "vue";
|
import { computed, onMounted, onUnmounted, ref, watch } from "vue";
|
||||||
import { useRoute } from "vue-router";
|
import { useRoute } from "vue-router";
|
||||||
import { ElMessage, ElMessageBox } from "element-plus";
|
import { ElMessage, ElMessageBox } from "element-plus";
|
||||||
|
import request from "@/utils/request";
|
||||||
import { useTimer } from "@/components/composables/useTimer";
|
import { useTimer } from "@/components/composables/useTimer";
|
||||||
import {
|
import {
|
||||||
continueSession,
|
continueSession,
|
||||||
endSession,
|
endSession,
|
||||||
|
getSessionDetail,
|
||||||
pauseSession,
|
pauseSession,
|
||||||
startOrContinueStudySession,
|
startOrContinueStudySession,
|
||||||
} from "@/api/studySessions";
|
} from "@/api/studySessions";
|
||||||
@@ -133,6 +135,8 @@ const taskInfo = ref({
|
|||||||
sessionState: "--",
|
sessionState: "--",
|
||||||
taskName: "",
|
taskName: "",
|
||||||
taskNum,
|
taskNum,
|
||||||
|
taskId: 0,
|
||||||
|
materialUrl: "",
|
||||||
startTime: "",
|
startTime: "",
|
||||||
endTime: "",
|
endTime: "",
|
||||||
lastStartTime: "",
|
lastStartTime: "",
|
||||||
@@ -143,6 +147,65 @@ const taskInfo = ref({
|
|||||||
systemMessage: "",
|
systemMessage: "",
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 学习材料展示/编辑
|
||||||
|
const editingMaterial = ref(false);
|
||||||
|
const editMaterialContent = ref("");
|
||||||
|
const savingMaterial = ref(false);
|
||||||
|
const materialHtml = computed(() => {
|
||||||
|
const raw = taskInfo.value.materialUrl || "";
|
||||||
|
if (!raw.trim()) return "";
|
||||||
|
let html = raw;
|
||||||
|
const links: string[] = [];
|
||||||
|
html = html.replace(/\[([^\]]+)\]\(([^)]+)\)/g, (_m: string, text: string, url: string) => {
|
||||||
|
const tag = `<a href="${url.replace(/"/g, """)}" target="_blank" rel="noopener">${text}</a>`;
|
||||||
|
links.push(tag);
|
||||||
|
return `__LINK_${links.length - 1}__`;
|
||||||
|
});
|
||||||
|
html = html.replace(/https?:\/\/[^\s)\u3001\uFF09\u300D\u300B<>]+/g, (url) => {
|
||||||
|
const clean = url.replace(/[.。,,;;!!??)】」』\]]+$/, "");
|
||||||
|
const tag = `<a href="${clean.replace(/"/g, """)}" target="_blank" rel="noopener">${clean}</a>`;
|
||||||
|
links.push(tag);
|
||||||
|
return `__LINK_${links.length - 1}__`;
|
||||||
|
});
|
||||||
|
html = html.replace(/\n/g, "<br>");
|
||||||
|
for (let i = 0; i < links.length; i++) {
|
||||||
|
html = html.replace(`__LINK_${i}__`, links[i]);
|
||||||
|
}
|
||||||
|
return html;
|
||||||
|
});
|
||||||
|
|
||||||
|
function startEditMaterial() {
|
||||||
|
editMaterialContent.value = taskInfo.value.materialUrl;
|
||||||
|
editingMaterial.value = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function saveMaterial() {
|
||||||
|
savingMaterial.value = true;
|
||||||
|
try {
|
||||||
|
// 先拉取完整任务数据,只改 materialUrl,其他字段保持不变
|
||||||
|
const res = await request.get(`/tasks/${taskInfo.value.taskId}`);
|
||||||
|
const current = res?.data || {};
|
||||||
|
await request.put(`/tasks/${taskInfo.value.taskId}`, {
|
||||||
|
id: taskInfo.value.taskId,
|
||||||
|
taskName: current.taskName,
|
||||||
|
taskDescription: current.taskDescription || "",
|
||||||
|
materialUrl: editMaterialContent.value,
|
||||||
|
urgency: current.urgency ?? 0,
|
||||||
|
importance: current.importance ?? 0,
|
||||||
|
contentDifficulty: current.contentDifficulty ?? 0,
|
||||||
|
futureValue: current.futureValue ?? 0,
|
||||||
|
subjectivePriority: current.subjectivePriority ?? 0,
|
||||||
|
});
|
||||||
|
taskInfo.value.materialUrl = editMaterialContent.value;
|
||||||
|
editingMaterial.value = false;
|
||||||
|
ElMessage.success("学习材料已更新");
|
||||||
|
} catch (e: any) {
|
||||||
|
ElMessage.error(e?.message || "更新失败");
|
||||||
|
} finally {
|
||||||
|
savingMaterial.value = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const {
|
const {
|
||||||
timerMinutes,
|
timerMinutes,
|
||||||
timerSeconds,
|
timerSeconds,
|
||||||
@@ -207,7 +270,10 @@ const toDate = (value: unknown): Date | null => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (typeof value === "string") {
|
if (typeof value === "string") {
|
||||||
const normalized = value.includes("T") ? value : value.replace(" ", "T");
|
// 去掉末尾的 'Z':后端 LocalDateTime 无时区,序列化时不应带 Z
|
||||||
|
// (旧版序列化器曾错误添加字面量 Z,此处做兼容处理)
|
||||||
|
const clean = value.endsWith("Z") ? value.slice(0, -1) : value;
|
||||||
|
const normalized = clean.includes("T") ? clean : clean.replace(" ", "T");
|
||||||
const date = new Date(normalized);
|
const date = new Date(normalized);
|
||||||
return Number.isNaN(date.getTime()) ? null : date;
|
return Number.isNaN(date.getTime()) ? null : date;
|
||||||
}
|
}
|
||||||
@@ -276,8 +342,24 @@ const stopTimer = async () => {
|
|||||||
const res = await pauseSession(taskInfo.value.sessionNum);
|
const res = await pauseSession(taskInfo.value.sessionNum);
|
||||||
if (res.code === 200) {
|
if (res.code === 200) {
|
||||||
ElMessage.success("任务暂停");
|
ElMessage.success("任务暂停");
|
||||||
|
// 重新获取会话数据,同步后端计算后的时间字段
|
||||||
|
try {
|
||||||
|
const detail = await getSessionDetail(taskInfo.value.sessionNum);
|
||||||
|
if (detail?.data) {
|
||||||
|
const d = detail.data;
|
||||||
|
taskInfo.value.sessionState = d.sessionState ?? "PAUSED";
|
||||||
|
taskInfo.value.actualTime = d.actualTime ?? 0;
|
||||||
|
taskInfo.value.effectiveTime = d.effectiveTime ?? 0;
|
||||||
|
taskInfo.value.effectivenessRatio = d.effectivenessRatio ?? 0;
|
||||||
|
taskInfo.value.startTime = d.startTime ?? taskInfo.value.startTime;
|
||||||
|
taskInfo.value.endTime = d.endTime ?? "";
|
||||||
|
taskInfo.value.lastStartTime = d.lastStartTime ?? "";
|
||||||
|
taskInfo.value.pointerPosition = d.pointerPosition ?? 0;
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
taskInfo.value.sessionState = "PAUSED";
|
taskInfo.value.sessionState = "PAUSED";
|
||||||
}
|
}
|
||||||
|
}
|
||||||
clear();
|
clear();
|
||||||
clearBreakState();
|
clearBreakState();
|
||||||
};
|
};
|
||||||
@@ -550,6 +632,30 @@ onUnmounted(() => {
|
|||||||
<span class="status-text">状态:{{ statusText }}</span>
|
<span class="status-text">状态:{{ statusText }}</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- 学习材料 -->
|
||||||
|
<article class="surface-card material-session-card">
|
||||||
|
<div class="material-session-header">
|
||||||
|
<span class="material-session-label">学习材料</span>
|
||||||
|
<el-button
|
||||||
|
v-if="!editingMaterial"
|
||||||
|
text
|
||||||
|
size="small"
|
||||||
|
type="primary"
|
||||||
|
@click="startEditMaterial"
|
||||||
|
>编辑</el-button>
|
||||||
|
</div>
|
||||||
|
<div v-if="materialHtml" class="material-session-content" v-html="materialHtml" />
|
||||||
|
<p v-else class="empty-text">暂未填写材料地址</p>
|
||||||
|
<el-dialog v-model="editingMaterial" title="编辑学习材料" width="560px">
|
||||||
|
<el-input v-model="editMaterialContent" type="textarea" :rows="10" placeholder="支持 Markdown 格式" />
|
||||||
|
<p class="edit-hint">[链接文字](url) 或直接粘贴链接,保存时自动获取标题</p>
|
||||||
|
<template #footer>
|
||||||
|
<el-button @click="editingMaterial = false">取消</el-button>
|
||||||
|
<el-button type="success" :loading="savingMaterial" @click="saveMaterial">保存</el-button>
|
||||||
|
</template>
|
||||||
|
</el-dialog>
|
||||||
|
</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>
|
||||||
@@ -804,6 +910,50 @@ onUnmounted(() => {
|
|||||||
word-break: break-word;
|
word-break: break-word;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.material-session-card {
|
||||||
|
padding: 12px 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.material-session-header {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
margin-bottom: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.material-session-label {
|
||||||
|
font-size: 12px;
|
||||||
|
font-weight: 700;
|
||||||
|
color: var(--green-700);
|
||||||
|
background: #e8f5e9;
|
||||||
|
padding: 2px 8px;
|
||||||
|
border-radius: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.material-session-content {
|
||||||
|
font-size: 14px;
|
||||||
|
line-height: 1.7;
|
||||||
|
word-break: break-word;
|
||||||
|
color: var(--text-primary);
|
||||||
|
}
|
||||||
|
|
||||||
|
.material-session-content :deep(a) {
|
||||||
|
color: var(--green-600);
|
||||||
|
text-decoration: none;
|
||||||
|
border-bottom: 1px dashed var(--green-400);
|
||||||
|
}
|
||||||
|
|
||||||
|
.material-session-content :deep(a:hover) {
|
||||||
|
color: var(--green-800);
|
||||||
|
border-bottom-style: solid;
|
||||||
|
}
|
||||||
|
|
||||||
|
.edit-hint {
|
||||||
|
margin: 6px 0 0;
|
||||||
|
font-size: 12px;
|
||||||
|
color: var(--text-secondary);
|
||||||
|
}
|
||||||
|
|
||||||
.dialog-hint {
|
.dialog-hint {
|
||||||
margin: 0 0 10px;
|
margin: 0 0 10px;
|
||||||
font-size: 13px;
|
font-size: 13px;
|
||||||
|
|||||||
+110
-46
@@ -5,6 +5,7 @@ import router from "@/router";
|
|||||||
import { ElMessage, ElMessageBox } from "element-plus";
|
import { ElMessage, ElMessageBox } from "element-plus";
|
||||||
import { getReviewTaskStatsByTask } from "@/api/review";
|
import { getReviewTaskStatsByTask } from "@/api/review";
|
||||||
import { getActiveSession } from "@/api/studySessions";
|
import { getActiveSession } from "@/api/studySessions";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
getPriorityWeights,
|
getPriorityWeights,
|
||||||
getTaskApplications,
|
getTaskApplications,
|
||||||
@@ -13,13 +14,12 @@ import {
|
|||||||
type PriorityWeights,
|
type PriorityWeights,
|
||||||
type TaskApplication,
|
type TaskApplication,
|
||||||
} from "@/api/tasks";
|
} from "@/api/tasks";
|
||||||
import { fetchTitles } from "@/utils/fetchTitle";
|
import { getUrlTitle } from "@/utils/fetchTitle";
|
||||||
|
|
||||||
interface TaskItem {
|
interface TaskItem {
|
||||||
title: string;
|
title: string;
|
||||||
description: string;
|
description: string;
|
||||||
materialURL: string;
|
materialUrl: string;
|
||||||
lastLearningStatus: string;
|
|
||||||
priority: number | string;
|
priority: number | string;
|
||||||
taskNum: string;
|
taskNum: string;
|
||||||
taskId: number;
|
taskId: number;
|
||||||
@@ -37,8 +37,12 @@ interface TaskItem {
|
|||||||
const tasks = ref<TaskItem[]>([]);
|
const tasks = ref<TaskItem[]>([]);
|
||||||
const selectedTaskId = ref<number | null>(null);
|
const selectedTaskId = ref<number | null>(null);
|
||||||
const loading = ref(false);
|
const loading = ref(false);
|
||||||
|
const currentPage = ref(1);
|
||||||
|
const totalTasks = ref(0);
|
||||||
|
const pageSize = 20;
|
||||||
const taskApplications = ref<TaskApplication[]>([]);
|
const taskApplications = ref<TaskApplication[]>([]);
|
||||||
const applicationsLoading = ref(false);
|
const applicationsLoading = ref(false);
|
||||||
|
const appUrlTitles = ref<Record<number, string>>({});
|
||||||
|
|
||||||
const applicationStatusOptions: { label: string; value: TaskApplication["status"] }[] = [
|
const applicationStatusOptions: { label: string; value: TaskApplication["status"] }[] = [
|
||||||
{ label: "待应用", value: "TODO" },
|
{ label: "待应用", value: "TODO" },
|
||||||
@@ -50,17 +54,32 @@ const selectedTask = computed(() =>
|
|||||||
tasks.value.find((item) => item.taskId === selectedTaskId.value) || null
|
tasks.value.find((item) => item.taskId === selectedTaskId.value) || null
|
||||||
);
|
);
|
||||||
|
|
||||||
// 多 URL 支持
|
const escapeHtml = (s: string) => s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
||||||
const urlList = computed(() => {
|
const escapeAttr = (s: string) => s.replace(/"/g, """).replace(/&/g, "&");
|
||||||
const raw = selectedTask.value?.materialURL || "";
|
|
||||||
return raw.split(/\r?\n/).map((s) => s.trim()).filter((s) => s.startsWith("http"));
|
function renderMarkdown(raw: string): string {
|
||||||
|
if (!raw.trim()) return "";
|
||||||
|
let html = raw;
|
||||||
|
const links: string[] = [];
|
||||||
|
html = html.replace(/\[([^\]]+)\]\(([^)]+)\)/g, (_m: string, text: string, url: string) => {
|
||||||
|
const tag = `<a href="${escapeAttr(url)}" target="_blank" rel="noopener">${escapeHtml(text)}</a>`;
|
||||||
|
links.push(tag);
|
||||||
|
return `__LINK_${links.length - 1}__`;
|
||||||
});
|
});
|
||||||
const urlTitles = ref<string[]>([]);
|
html = html.replace(/https?:\/\/[^\s)\u3001\uFF09\u300D\u300B<>]+/g, (url) => {
|
||||||
async function loadUrlTitles() {
|
const clean = url.replace(/[.。,,;;!!???)]」》]]+$/, "");
|
||||||
const urls = urlList.value;
|
const tag = `<a href="${escapeAttr(clean)}" target="_blank" rel="noopener">${escapeHtml(clean)}</a>`;
|
||||||
if (urls.length === 0) { urlTitles.value = []; return; }
|
links.push(tag);
|
||||||
urlTitles.value = await fetchTitles(urls);
|
return `__LINK_${links.length - 1}__`;
|
||||||
|
});
|
||||||
|
html = html.replace(/\n/g, "<br>");
|
||||||
|
for (let i = 0; i < links.length; i++) {
|
||||||
|
html = html.replace(`__LINK_${i}__`, links[i]);
|
||||||
}
|
}
|
||||||
|
return html;
|
||||||
|
}
|
||||||
|
|
||||||
|
const materialHtml = computed(() => renderMarkdown(selectedTask.value?.materialUrl || ""));
|
||||||
|
|
||||||
const formatEffectiveTime = (seconds: number): string => {
|
const formatEffectiveTime = (seconds: number): string => {
|
||||||
if (!seconds || seconds <= 0) return "0分钟";
|
if (!seconds || seconds <= 0) return "0分钟";
|
||||||
@@ -97,6 +116,15 @@ async function loadTaskApplications(taskNum: string) {
|
|||||||
try {
|
try {
|
||||||
const res = await getTaskApplications(taskNum);
|
const res = await getTaskApplications(taskNum);
|
||||||
taskApplications.value = res?.data || [];
|
taskApplications.value = res?.data || [];
|
||||||
|
const map: Record<number, string> = {};
|
||||||
|
await Promise.all(
|
||||||
|
taskApplications.value
|
||||||
|
.filter((a) => a.resourceUrl)
|
||||||
|
.map(async (a) => {
|
||||||
|
map[a.id] = await getUrlTitle(a.resourceUrl!);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
appUrlTitles.value = map;
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
taskApplications.value = [];
|
taskApplications.value = [];
|
||||||
ElMessage.error(error?.message || "应用场景加载失败");
|
ElMessage.error(error?.message || "应用场景加载失败");
|
||||||
@@ -122,16 +150,17 @@ const changeApplicationStatus = async (item: TaskApplication) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const fetchTasks = async () => {
|
const fetchTasks = async (page = currentPage.value) => {
|
||||||
loading.value = true;
|
loading.value = true;
|
||||||
try {
|
try {
|
||||||
const previousSelectedTaskId = selectedTaskId.value;
|
const previousSelectedTaskId = selectedTaskId.value;
|
||||||
const res = await request.get("/tasks", { pageSize: 100, pageNum: 1 });
|
currentPage.value = page;
|
||||||
|
const res = await request.get("/tasks", { pageSize, pageNum: page });
|
||||||
|
totalTasks.value = res?.data?.total || 0;
|
||||||
tasks.value = (res?.data?.records || []).map((record: any) => ({
|
tasks.value = (res?.data?.records || []).map((record: any) => ({
|
||||||
title: record.taskName,
|
title: record.taskName,
|
||||||
description: record.taskDescription || "",
|
description: record.taskDescription || "",
|
||||||
materialURL: record.materialURL || record.materialUrl || "",
|
materialUrl: record.materialUrl || "",
|
||||||
lastLearningStatus: record.lastLearningStatus || "未开始",
|
|
||||||
priority: Number.isFinite(record.taskPriority) ? Math.round(record.taskPriority) : "-",
|
priority: Number.isFinite(record.taskPriority) ? Math.round(record.taskPriority) : "-",
|
||||||
taskNum: record.taskNum,
|
taskNum: record.taskNum,
|
||||||
taskId: record.id,
|
taskId: record.id,
|
||||||
@@ -168,13 +197,17 @@ watch(selectedTaskId, (newId) => {
|
|||||||
if (task) {
|
if (task) {
|
||||||
loadTaskStats(task.taskNum);
|
loadTaskStats(task.taskNum);
|
||||||
loadTaskApplications(task.taskNum);
|
loadTaskApplications(task.taskNum);
|
||||||
loadUrlTitles();
|
|
||||||
} else {
|
} else {
|
||||||
taskApplications.value = [];
|
taskApplications.value = [];
|
||||||
urlTitles.value = [];
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const handlePageChange = (page: number) => {
|
||||||
|
selectedTaskId.value = null;
|
||||||
|
taskApplications.value = [];
|
||||||
|
fetchTasks(page);
|
||||||
|
};
|
||||||
|
|
||||||
const startTask = async () => {
|
const startTask = async () => {
|
||||||
if (!selectedTask.value) {
|
if (!selectedTask.value) {
|
||||||
ElMessage.warning("请先选择一个任务");
|
ElMessage.warning("请先选择一个任务");
|
||||||
@@ -315,9 +348,18 @@ onMounted(() => {
|
|||||||
<span class="task-priority">{{ item.priority }}</span>
|
<span class="task-priority">{{ item.priority }}</span>
|
||||||
{{ item.title }}
|
{{ item.title }}
|
||||||
</p>
|
</p>
|
||||||
<p class="task-meta">状态:{{ item.lastLearningStatus }}</p>
|
|
||||||
</div>
|
</div>
|
||||||
</el-scrollbar>
|
</el-scrollbar>
|
||||||
|
<el-pagination
|
||||||
|
v-if="totalTasks > pageSize"
|
||||||
|
small
|
||||||
|
layout="prev, pager, next"
|
||||||
|
:total="totalTasks"
|
||||||
|
:page-size="pageSize"
|
||||||
|
:current-page="currentPage"
|
||||||
|
@current-change="handlePageChange"
|
||||||
|
class="task-pagination"
|
||||||
|
/>
|
||||||
</aside>
|
</aside>
|
||||||
|
|
||||||
<main class="content-zone">
|
<main class="content-zone">
|
||||||
@@ -330,18 +372,12 @@ onMounted(() => {
|
|||||||
|
|
||||||
<div class="detail-block">
|
<div class="detail-block">
|
||||||
<p class="label">任务描述</p>
|
<p class="label">任务描述</p>
|
||||||
<el-input type="textarea" :model-value="selectedTask.description" :rows="4" readonly />
|
<p class="description-text">{{ selectedTask.description || '暂无描述' }}</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="detail-block">
|
<div class="detail-block">
|
||||||
<p class="label">学习材料</p>
|
<p class="label">学习材料</p>
|
||||||
<div v-if="urlList.length > 0" class="material-list">
|
<div v-if="materialHtml" class="material-content" v-html="materialHtml" />
|
||||||
<div v-for="(url, i) in urlList" :key="i" class="material-item">
|
|
||||||
<el-link :href="url" target="_blank" type="success">
|
|
||||||
{{ urlTitles[i] || url }}
|
|
||||||
</el-link>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<p v-else class="empty-text">暂未填写材料地址</p>
|
<p v-else class="empty-text">暂未填写材料地址</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -409,7 +445,7 @@ onMounted(() => {
|
|||||||
</div>
|
</div>
|
||||||
<p v-if="item.description">{{ item.description }}</p>
|
<p v-if="item.description">{{ item.description }}</p>
|
||||||
<el-link v-if="item.resourceUrl" :href="item.resourceUrl" target="_blank" type="primary">
|
<el-link v-if="item.resourceUrl" :href="item.resourceUrl" target="_blank" type="primary">
|
||||||
{{ item.resourceUrl }}
|
{{ appUrlTitles[item.id] || item.resourceUrl }}
|
||||||
</el-link>
|
</el-link>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -569,10 +605,9 @@ onMounted(() => {
|
|||||||
justify-content: center;
|
justify-content: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
.task-meta {
|
.task-pagination {
|
||||||
margin: 4px 0 0;
|
margin-top: 10px;
|
||||||
font-size: 12px;
|
justify-content: center;
|
||||||
color: var(--text-secondary);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.content-zone {
|
.content-zone {
|
||||||
@@ -597,14 +632,33 @@ onMounted(() => {
|
|||||||
font-size: 22px;
|
font-size: 22px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.description-text {
|
||||||
|
margin: 0;
|
||||||
|
font-size: 14px;
|
||||||
|
line-height: 1.7;
|
||||||
|
color: var(--text-primary);
|
||||||
|
white-space: pre-wrap;
|
||||||
|
word-break: break-word;
|
||||||
|
}
|
||||||
|
|
||||||
.detail-block {
|
.detail-block {
|
||||||
margin-top: 16px;
|
margin-top: 20px;
|
||||||
|
padding-top: 16px;
|
||||||
|
border-top: 1px solid var(--border-soft);
|
||||||
|
}
|
||||||
|
|
||||||
|
.detail-block:first-child {
|
||||||
|
margin-top: 0;
|
||||||
|
padding-top: 0;
|
||||||
|
border-top: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
.label {
|
.label {
|
||||||
margin: 0 0 8px;
|
margin: 0 0 10px;
|
||||||
color: var(--text-secondary);
|
color: var(--text-secondary);
|
||||||
font-size: 13px;
|
font-size: 14px;
|
||||||
|
font-weight: 500;
|
||||||
|
letter-spacing: 0.5px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.empty-text {
|
.empty-text {
|
||||||
@@ -612,19 +666,29 @@ onMounted(() => {
|
|||||||
color: var(--text-secondary);
|
color: var(--text-secondary);
|
||||||
}
|
}
|
||||||
|
|
||||||
.material-list {
|
.material-content {
|
||||||
display: flex;
|
font-size: 14px;
|
||||||
flex-direction: column;
|
line-height: 1.8;
|
||||||
gap: 6px;
|
word-break: break-word;
|
||||||
|
color: var(--text-primary);
|
||||||
}
|
}
|
||||||
|
|
||||||
.material-item {
|
.material-content :deep(a) {
|
||||||
padding: 4px 0;
|
color: var(--green-600);
|
||||||
word-break: break-all;
|
text-decoration: none;
|
||||||
|
border-bottom: 1px dashed var(--green-400);
|
||||||
|
transition: color 0.15s, border-color 0.15s;
|
||||||
}
|
}
|
||||||
|
|
||||||
.material-item .el-link {
|
.material-content :deep(a:hover) {
|
||||||
font-size: 13px;
|
color: var(--green-800);
|
||||||
|
border-bottom-style: solid;
|
||||||
|
}
|
||||||
|
|
||||||
|
.material-content :deep(a)::after {
|
||||||
|
content: " ↗";
|
||||||
|
font-size: 11px;
|
||||||
|
opacity: 0.5;
|
||||||
}
|
}
|
||||||
|
|
||||||
.stats-grid {
|
.stats-grid {
|
||||||
@@ -640,12 +704,12 @@ onMounted(() => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.stat-label {
|
.stat-label {
|
||||||
font-size: 12px;
|
font-size: 13px;
|
||||||
color: var(--text-secondary);
|
color: var(--text-secondary);
|
||||||
}
|
}
|
||||||
|
|
||||||
.stat-value {
|
.stat-value {
|
||||||
font-size: 14px;
|
font-size: 15px;
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
color: var(--text-primary);
|
color: var(--text-primary);
|
||||||
}
|
}
|
||||||
|
|||||||
+214
-50
@@ -10,6 +10,7 @@ import {
|
|||||||
updateTaskApplication,
|
updateTaskApplication,
|
||||||
type TaskApplication,
|
type TaskApplication,
|
||||||
} from "@/api/tasks";
|
} from "@/api/tasks";
|
||||||
|
import { getUrlTitle } from "@/utils/fetchTitle";
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
@@ -21,7 +22,7 @@ const isUpdateMode = computed(() => route.meta.action === "update");
|
|||||||
const taskNum = ref("");
|
const taskNum = ref("");
|
||||||
const taskName = ref("");
|
const taskName = ref("");
|
||||||
const taskDescription = ref("");
|
const taskDescription = ref("");
|
||||||
const materialURL = ref("");
|
const materialUrl = ref("");
|
||||||
const priority = ref({
|
const priority = ref({
|
||||||
urgency: 0,
|
urgency: 0,
|
||||||
importance: 0,
|
importance: 0,
|
||||||
@@ -39,6 +40,8 @@ const applicationStatusOptions: { label: string; value: TaskApplication["status"
|
|||||||
|
|
||||||
const applications = ref<TaskApplication[]>([]);
|
const applications = ref<TaskApplication[]>([]);
|
||||||
const applicationLoading = ref(false);
|
const applicationLoading = ref(false);
|
||||||
|
const appUrlTitles = ref<Record<number, string>>({});
|
||||||
|
const applicationDialogVisible = ref(false);
|
||||||
const applicationSaving = ref(false);
|
const applicationSaving = ref(false);
|
||||||
const editingApplicationId = ref<number | null>(null);
|
const editingApplicationId = ref<number | null>(null);
|
||||||
const applicationForm = ref<{
|
const applicationForm = ref<{
|
||||||
@@ -53,6 +56,11 @@ const applicationForm = ref<{
|
|||||||
status: "TODO",
|
status: "TODO",
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const openApplicationDialog = () => {
|
||||||
|
resetApplicationForm();
|
||||||
|
applicationDialogVisible.value = true;
|
||||||
|
};
|
||||||
|
|
||||||
const resetApplicationForm = () => {
|
const resetApplicationForm = () => {
|
||||||
editingApplicationId.value = null;
|
editingApplicationId.value = null;
|
||||||
applicationForm.value = {
|
applicationForm.value = {
|
||||||
@@ -68,6 +76,16 @@ const loadApplications = async (targetTaskNum: string) => {
|
|||||||
try {
|
try {
|
||||||
const res = await getTaskApplications(targetTaskNum);
|
const res = await getTaskApplications(targetTaskNum);
|
||||||
applications.value = res?.data || [];
|
applications.value = res?.data || [];
|
||||||
|
// 异步抓取标题
|
||||||
|
const map: Record<number, string> = {};
|
||||||
|
await Promise.all(
|
||||||
|
applications.value
|
||||||
|
.filter((a) => a.resourceUrl)
|
||||||
|
.map(async (a) => {
|
||||||
|
map[a.id] = await getUrlTitle(a.resourceUrl!);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
appUrlTitles.value = map;
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
applications.value = [];
|
applications.value = [];
|
||||||
ElMessage.error(error?.message || "应用场景加载失败");
|
ElMessage.error(error?.message || "应用场景加载失败");
|
||||||
@@ -100,6 +118,7 @@ const saveApplication = async () => {
|
|||||||
await createTaskApplication(taskNum.value, payload);
|
await createTaskApplication(taskNum.value, payload);
|
||||||
ElMessage.success("应用场景已添加");
|
ElMessage.success("应用场景已添加");
|
||||||
}
|
}
|
||||||
|
applicationDialogVisible.value = false;
|
||||||
resetApplicationForm();
|
resetApplicationForm();
|
||||||
await loadApplications(taskNum.value);
|
await loadApplications(taskNum.value);
|
||||||
} finally {
|
} finally {
|
||||||
@@ -115,6 +134,7 @@ const editApplication = (item: TaskApplication) => {
|
|||||||
resourceUrl: item.resourceUrl || "",
|
resourceUrl: item.resourceUrl || "",
|
||||||
status: item.status || "TODO",
|
status: item.status || "TODO",
|
||||||
};
|
};
|
||||||
|
applicationDialogVisible.value = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
const removeApplication = async (item: TaskApplication) => {
|
const removeApplication = async (item: TaskApplication) => {
|
||||||
@@ -128,12 +148,36 @@ const removeApplication = async (item: TaskApplication) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const convertMaterialUrls = async () => {
|
||||||
|
const raw = materialUrl.value || "";
|
||||||
|
if (!raw.trim()) return;
|
||||||
|
const bareUrls = new Set<string>();
|
||||||
|
raw.replace(/https?:\/\/[^\s)\u3001\uFF09\u300D\u300B<>]+/g, (url) => {
|
||||||
|
const clean = url.replace(/[.。,,;;!!??)】」』\]]+$/, "");
|
||||||
|
// 跳过 [text](url) 内的
|
||||||
|
if (!raw.includes(`](${clean})`)) bareUrls.add(clean);
|
||||||
|
return url;
|
||||||
|
});
|
||||||
|
if (bareUrls.size === 0) return;
|
||||||
|
const titles: Record<string, string> = {};
|
||||||
|
const results = await Promise.all([...bareUrls].map(async (u) => ({ u, t: await getUrlTitle(u) })));
|
||||||
|
results.forEach(({ u, t }) => { titles[u] = t; });
|
||||||
|
let result = raw;
|
||||||
|
for (const u of bareUrls) {
|
||||||
|
if (titles[u] && titles[u] !== u) {
|
||||||
|
result = result.replace(u, `[${titles[u].replace(/]/g, "\\]")}](${u})`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
materialUrl.value = result;
|
||||||
|
};
|
||||||
|
|
||||||
const createTask = () => {
|
const createTask = () => {
|
||||||
|
convertMaterialUrls().then(() => {
|
||||||
request
|
request
|
||||||
.post("/tasks", {
|
.post("/tasks", {
|
||||||
taskName: taskName.value,
|
taskName: taskName.value,
|
||||||
taskDescription: taskDescription.value,
|
taskDescription: taskDescription.value,
|
||||||
materialURL: materialURL.value,
|
materialUrl: materialUrl.value,
|
||||||
...priority.value,
|
...priority.value,
|
||||||
})
|
})
|
||||||
.then((result) => {
|
.then((result) => {
|
||||||
@@ -144,6 +188,7 @@ const createTask = () => {
|
|||||||
ElMessage.error("任务创建失败:" + result.message);
|
ElMessage.error("任务创建失败:" + result.message);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const loadTask = () => {
|
const loadTask = () => {
|
||||||
@@ -154,7 +199,7 @@ const loadTask = () => {
|
|||||||
taskNum.value = data.taskNum || "";
|
taskNum.value = data.taskNum || "";
|
||||||
taskName.value = data.taskName;
|
taskName.value = data.taskName;
|
||||||
taskDescription.value = data.taskDescription;
|
taskDescription.value = data.taskDescription;
|
||||||
materialURL.value = data.materialURL || data.materialUrl || "";
|
materialUrl.value = data.materialUrl || "";
|
||||||
priority.value = {
|
priority.value = {
|
||||||
urgency: data.urgency,
|
urgency: data.urgency,
|
||||||
importance: data.importance,
|
importance: data.importance,
|
||||||
@@ -173,12 +218,13 @@ const loadTask = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const updateTask = () => {
|
const updateTask = () => {
|
||||||
|
convertMaterialUrls().then(() => {
|
||||||
request
|
request
|
||||||
.put("/tasks/" + taskId, {
|
.put("/tasks/" + taskId, {
|
||||||
id: taskId,
|
id: taskId,
|
||||||
taskName: taskName.value,
|
taskName: taskName.value,
|
||||||
taskDescription: taskDescription.value,
|
taskDescription: taskDescription.value,
|
||||||
materialURL: materialURL.value,
|
materialUrl: materialUrl.value,
|
||||||
...priority.value,
|
...priority.value,
|
||||||
})
|
})
|
||||||
.then((result) => {
|
.then((result) => {
|
||||||
@@ -189,6 +235,7 @@ const updateTask = () => {
|
|||||||
ElMessage.error("任务更新失败:" + result.message);
|
ElMessage.error("任务更新失败:" + result.message);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const cancelTask = () => {
|
const cancelTask = () => {
|
||||||
@@ -225,6 +272,61 @@ onMounted(() => {
|
|||||||
onUnmounted(() => window.removeEventListener("resize", updateWidth));
|
onUnmounted(() => window.removeEventListener("resize", updateWidth));
|
||||||
|
|
||||||
const isMobile = computed(() => screenWidth.value <= 900);
|
const isMobile = computed(() => screenWidth.value <= 900);
|
||||||
|
|
||||||
|
// 学习材料 Markdown 预览
|
||||||
|
const showPreview = ref(false);
|
||||||
|
const materialPreview = ref("");
|
||||||
|
const previewLoading = ref(false);
|
||||||
|
|
||||||
|
const escapeHtml = (s: string) => s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
||||||
|
const escapeAttr = (s: string) => s.replace(/"/g, """).replace(/&/g, "&");
|
||||||
|
|
||||||
|
function renderMarkdown(raw: string, urlTitles: Record<string, string> = {}): string {
|
||||||
|
if (!raw.trim()) return "";
|
||||||
|
let html = raw;
|
||||||
|
// 1) [text](url) → <a> 占位,防止后续裸 URL 匹配进属性里
|
||||||
|
const links: string[] = [];
|
||||||
|
html = html.replace(/\[([^\]]+)\]\(([^)]+)\)/g, (_m: string, text: string, url: string) => {
|
||||||
|
const tag = `<a href="${escapeAttr(url)}" target="_blank" rel="noopener">${escapeHtml(text)}</a>`;
|
||||||
|
links.push(tag);
|
||||||
|
return `__LINK_${links.length - 1}__`;
|
||||||
|
});
|
||||||
|
// 2) 裸 URL → <a> 占位
|
||||||
|
html = html.replace(/https?:\/\/[^\s)\u3001\uFF09\u300D\u300B<>]+/g, (url) => {
|
||||||
|
const clean = url.replace(/[.。,,;;!!??)】」』\]]+$/, "");
|
||||||
|
const label = urlTitles[clean] || url;
|
||||||
|
const tag = `<a href="${escapeAttr(clean)}" target="_blank" rel="noopener">${escapeHtml(label)}</a>`;
|
||||||
|
links.push(tag);
|
||||||
|
return `__LINK_${links.length - 1}__`;
|
||||||
|
});
|
||||||
|
// 3) 换行
|
||||||
|
html = html.replace(/\n/g, "<br>");
|
||||||
|
// 4) 还原占位
|
||||||
|
for (let i = 0; i < links.length; i++) {
|
||||||
|
html = html.replace(`__LINK_${i}__`, links[i]);
|
||||||
|
}
|
||||||
|
return html;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function previewMaterial() {
|
||||||
|
showPreview.value = true;
|
||||||
|
const raw = materialUrl.value || "";
|
||||||
|
if (!raw.trim()) { materialPreview.value = ""; return; }
|
||||||
|
previewLoading.value = true;
|
||||||
|
try {
|
||||||
|
const titles: Record<string, string> = {};
|
||||||
|
const bareUrls = new Set<string>();
|
||||||
|
raw.replace(/https?:\/\/[^\s)\u3001\uFF09\u300D\u300B<>]+/g, (url) => {
|
||||||
|
bareUrls.add(url.replace(/[.。,,;;!!??)】」』\]]+$/, ""));
|
||||||
|
return url;
|
||||||
|
});
|
||||||
|
const results = await Promise.all([...bareUrls].map(async (u) => ({ u, t: await getUrlTitle(u) })));
|
||||||
|
results.forEach(({ u, t }) => { titles[u] = t; });
|
||||||
|
materialPreview.value = renderMarkdown(raw, titles);
|
||||||
|
} finally {
|
||||||
|
previewLoading.value = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -238,8 +340,35 @@ const isMobile = computed(() => screenWidth.value <= 900);
|
|||||||
<el-form-item label="任务描述">
|
<el-form-item label="任务描述">
|
||||||
<el-input v-model="taskDescription" type="textarea" :rows="5" placeholder="请输入任务描述" />
|
<el-input v-model="taskDescription" type="textarea" :rows="5" placeholder="请输入任务描述" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="学习材料地址">
|
<el-form-item>
|
||||||
<el-input v-model="materialURL" type="textarea" :rows="3" placeholder="每行输入一个链接 例如:https://vuejs.org/guide https://github.com/vuejs/core" />
|
<template #label>
|
||||||
|
<div class="material-label">
|
||||||
|
<span>学习材料地址</span>
|
||||||
|
<el-button
|
||||||
|
v-if="!showPreview"
|
||||||
|
text
|
||||||
|
size="small"
|
||||||
|
type="primary"
|
||||||
|
@click="previewMaterial()"
|
||||||
|
>预览</el-button>
|
||||||
|
<el-button
|
||||||
|
v-else
|
||||||
|
text
|
||||||
|
size="small"
|
||||||
|
@click="showPreview = false"
|
||||||
|
>编辑</el-button>
|
||||||
|
<span class="material-hint" v-if="!showPreview">[链接文字](url) 或直接粘贴链接</span>
|
||||||
|
<span class="material-hint" v-else>链接会自动获取标题展示</span>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
<el-input
|
||||||
|
v-if="!showPreview"
|
||||||
|
v-model="materialUrl"
|
||||||
|
type="textarea"
|
||||||
|
:rows="6"
|
||||||
|
placeholder="支持 Markdown 格式 例如: 参考 [Vue.js 文档](https://vuejs.org/guide) 源码在 https://github.com/vuejs/core"
|
||||||
|
/>
|
||||||
|
<div v-else class="material-preview" v-html="materialPreview" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -279,7 +408,10 @@ const isMobile = computed(() => screenWidth.value <= 900);
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="group" v-if="isUpdateMode" v-loading="applicationLoading">
|
<div class="group" v-if="isUpdateMode" v-loading="applicationLoading">
|
||||||
|
<div class="application-header">
|
||||||
<h3>应用场景</h3>
|
<h3>应用场景</h3>
|
||||||
|
<el-button type="primary" @click="openApplicationDialog()">添加应用场景</el-button>
|
||||||
|
</div>
|
||||||
<div class="application-list" v-if="applications.length > 0">
|
<div class="application-list" v-if="applications.length > 0">
|
||||||
<div class="application-item" v-for="item in applications" :key="item.id">
|
<div class="application-item" v-for="item in applications" :key="item.id">
|
||||||
<div class="application-main">
|
<div class="application-main">
|
||||||
@@ -290,7 +422,7 @@ const isMobile = computed(() => screenWidth.value <= 900);
|
|||||||
</div>
|
</div>
|
||||||
<p v-if="item.description">{{ item.description }}</p>
|
<p v-if="item.description">{{ item.description }}</p>
|
||||||
<el-link v-if="item.resourceUrl" :href="item.resourceUrl" target="_blank" type="primary">
|
<el-link v-if="item.resourceUrl" :href="item.resourceUrl" target="_blank" type="primary">
|
||||||
{{ item.resourceUrl }}
|
{{ appUrlTitles[item.id] || item.resourceUrl }}
|
||||||
</el-link>
|
</el-link>
|
||||||
<div class="application-actions">
|
<div class="application-actions">
|
||||||
<el-button text type="primary" size="small" @click="editApplication(item)">编辑</el-button>
|
<el-button text type="primary" size="small" @click="editApplication(item)">编辑</el-button>
|
||||||
@@ -299,32 +431,32 @@ const isMobile = computed(() => screenWidth.value <= 900);
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<p v-else class="empty-text">暂未设置应用场景</p>
|
<p v-else class="empty-text">暂未设置应用场景</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="application-form">
|
<el-dialog v-model="applicationDialogVisible" :title="editingApplicationId ? '编辑应用场景' : '添加应用场景'" width="500px">
|
||||||
<el-input v-model="applicationForm.title" placeholder="应用项目" />
|
<el-form label-position="top">
|
||||||
<el-input
|
<el-form-item label="应用项目" required>
|
||||||
v-model="applicationForm.description"
|
<el-input v-model="applicationForm.title" placeholder="例如:用Vue3重构个人博客" />
|
||||||
type="textarea"
|
</el-form-item>
|
||||||
:rows="3"
|
<el-form-item label="应用描述">
|
||||||
placeholder="应用描述"
|
<el-input v-model="applicationForm.description" type="textarea" :rows="4" placeholder="描述如何应用所学内容" />
|
||||||
/>
|
</el-form-item>
|
||||||
<el-input v-model="applicationForm.resourceUrl" placeholder="相关链接" />
|
<el-form-item label="相关链接">
|
||||||
<div class="application-form-row">
|
<el-input v-model="applicationForm.resourceUrl" placeholder="https://..." />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="状态">
|
||||||
<el-select v-model="applicationForm.status" placeholder="状态">
|
<el-select v-model="applicationForm.status" placeholder="状态">
|
||||||
<el-option
|
<el-option v-for="option in applicationStatusOptions" :key="option.value" :label="option.label" :value="option.value" />
|
||||||
v-for="option in applicationStatusOptions"
|
|
||||||
:key="option.value"
|
|
||||||
:label="option.label"
|
|
||||||
:value="option.value"
|
|
||||||
/>
|
|
||||||
</el-select>
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
|
<template #footer>
|
||||||
|
<el-button @click="applicationDialogVisible = false">取消</el-button>
|
||||||
<el-button type="success" :loading="applicationSaving" @click="saveApplication">
|
<el-button type="success" :loading="applicationSaving" @click="saveApplication">
|
||||||
{{ editingApplicationId ? "更新" : "添加" }}
|
{{ editingApplicationId ? '更新' : '添加' }}
|
||||||
</el-button>
|
</el-button>
|
||||||
<el-button v-if="editingApplicationId" @click="resetApplicationForm">取消</el-button>
|
</template>
|
||||||
</div>
|
</el-dialog>
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="action-row">
|
<div class="action-row">
|
||||||
<el-button type="success" size="large" @click="submitTask">{{ buttonName }}</el-button>
|
<el-button type="success" size="large" @click="submitTask">{{ buttonName }}</el-button>
|
||||||
@@ -354,6 +486,49 @@ const isMobile = computed(() => screenWidth.value <= 900);
|
|||||||
color: var(--green-900);
|
color: var(--green-900);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.material-label {
|
||||||
|
display: flex;
|
||||||
|
align-items: baseline;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 6px 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.material-label .material-hint {
|
||||||
|
font-size: 12px;
|
||||||
|
color: var(--text-secondary);
|
||||||
|
font-weight: 400;
|
||||||
|
}
|
||||||
|
|
||||||
|
.material-preview {
|
||||||
|
min-height: 120px;
|
||||||
|
padding: 14px 16px;
|
||||||
|
border: 1px solid var(--border-soft);
|
||||||
|
border-radius: 8px;
|
||||||
|
background: #fafdfb;
|
||||||
|
font-size: 14px;
|
||||||
|
line-height: 1.8;
|
||||||
|
word-break: break-word;
|
||||||
|
color: var(--text-primary);
|
||||||
|
}
|
||||||
|
|
||||||
|
.material-preview :deep(a) {
|
||||||
|
color: var(--green-600);
|
||||||
|
text-decoration: none;
|
||||||
|
border-bottom: 1px dashed var(--green-400);
|
||||||
|
transition: color 0.15s, border-color 0.15s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.material-preview :deep(a:hover) {
|
||||||
|
color: var(--green-800);
|
||||||
|
border-bottom-style: solid;
|
||||||
|
}
|
||||||
|
|
||||||
|
.material-preview :deep(a)::after {
|
||||||
|
content: " ↗";
|
||||||
|
font-size: 11px;
|
||||||
|
opacity: 0.5;
|
||||||
|
}
|
||||||
|
|
||||||
.priority-grid {
|
.priority-grid {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: repeat(3, minmax(0, 1fr));
|
grid-template-columns: repeat(3, minmax(0, 1fr));
|
||||||
@@ -364,6 +539,17 @@ const isMobile = computed(() => screenWidth.value <= 900);
|
|||||||
grid-template-columns: 1fr;
|
grid-template-columns: 1fr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.application-header {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
margin-bottom: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.application-header h3 {
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
.application-list {
|
.application-list {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
@@ -405,20 +591,6 @@ const isMobile = computed(() => screenWidth.value <= 900);
|
|||||||
margin-top: 8px;
|
margin-top: 8px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.application-form {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
gap: 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.application-form-row {
|
|
||||||
display: grid;
|
|
||||||
grid-template-columns: minmax(160px, 220px) auto auto;
|
|
||||||
gap: 10px;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: start;
|
|
||||||
}
|
|
||||||
|
|
||||||
.empty-text {
|
.empty-text {
|
||||||
margin: 0 0 12px;
|
margin: 0 0 12px;
|
||||||
color: var(--text-secondary);
|
color: var(--text-secondary);
|
||||||
@@ -450,13 +622,5 @@ const isMobile = computed(() => screenWidth.value <= 900);
|
|||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
}
|
}
|
||||||
|
|
||||||
.application-form-row {
|
|
||||||
grid-template-columns: 1fr;
|
|
||||||
}
|
|
||||||
|
|
||||||
.application-form-row .el-button {
|
|
||||||
width: 100%;
|
|
||||||
margin: 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
+19
-29
@@ -1,36 +1,26 @@
|
|||||||
/**
|
/**
|
||||||
* 网页标题抓取工具。
|
* URL 标题缓存 + 按需抓取,调用后端 /utils/fetch-title 代理
|
||||||
* 调用 lpt-ai 的 /fetch-title 接口获取 URL 对应的 <title> 标签内容。
|
|
||||||
*
|
|
||||||
* 设计要点:
|
|
||||||
* - 内存缓存避免同页面重复请求
|
|
||||||
* - 失败时回退到 URL 本身
|
|
||||||
* - 仅在 lpt-ai 运行时可用
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const LPT_AI_URL = "http://localhost:5199";
|
import request from "@/utils/request";
|
||||||
|
|
||||||
const titleCache: Record<string, string> = {};
|
const cache = new Map<string, string>();
|
||||||
|
const pending = new Map<string, Promise<string>>();
|
||||||
|
|
||||||
export async function fetchTitle(url: string): Promise<string> {
|
export async function getUrlTitle(url: string): Promise<string> {
|
||||||
if (titleCache[url]) return titleCache[url];
|
if (cache.has(url)) return cache.get(url)!;
|
||||||
try {
|
if (pending.has(url)) return pending.get(url)!;
|
||||||
const res = await fetch(`${LPT_AI_URL}/fetch-title`, {
|
|
||||||
method: "POST",
|
|
||||||
headers: { "Content-Type": "application/json" },
|
|
||||||
body: JSON.stringify({ url }),
|
|
||||||
signal: AbortSignal.timeout(12_000),
|
|
||||||
});
|
|
||||||
if (!res.ok) return url;
|
|
||||||
const data = await res.json();
|
|
||||||
titleCache[url] = data.title || url;
|
|
||||||
return titleCache[url];
|
|
||||||
} catch {
|
|
||||||
return url;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** 批量获取标题 */
|
const promise = request
|
||||||
export async function fetchTitles(urls: string[]): Promise<string[]> {
|
.get("/utils/fetch-title", { url })
|
||||||
return Promise.all(urls.map((url) => fetchTitle(url)));
|
.then((res: any) => {
|
||||||
|
const title = res?.data?.title || url;
|
||||||
|
cache.set(url, title);
|
||||||
|
return title;
|
||||||
|
})
|
||||||
|
.catch(() => url)
|
||||||
|
.finally(() => pending.delete(url));
|
||||||
|
|
||||||
|
pending.set(url, promise);
|
||||||
|
return promise;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,14 +12,21 @@ const axiosInstance = axios.create({
|
|||||||
|
|
||||||
const handleError = (error: any) => {
|
const handleError = (error: any) => {
|
||||||
|
|
||||||
// 401 未授权:token 过期或未登录,直接跳转登录页
|
// 401 未授权(HTTP 层):token 过期或未登录
|
||||||
if (error?.response?.status === 401) {
|
if (error?.response?.status === 401) {
|
||||||
localStorage.removeItem("isLoggedIn");
|
localStorage.removeItem("isLoggedIn");
|
||||||
router.push("/login");
|
router.push("/login");
|
||||||
return Promise.reject(error);
|
return Promise.reject(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 业务异常由 validateResponse 负责提示,这里透传,避免被网络错误文案覆盖。
|
// 401 未授权(业务层):后端 GlobalExceptionHandler 返回 code=401
|
||||||
|
if (error && typeof error === "object" && error.code === 401) {
|
||||||
|
localStorage.removeItem("isLoggedIn");
|
||||||
|
router.push("/login");
|
||||||
|
return Promise.reject(error);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 其他业务异常(如 code !== 200)透传,由调用方自行提示
|
||||||
if (error && typeof error === "object" && "code" in error && !error.response) {
|
if (error && typeof error === "object" && "code" in error && !error.response) {
|
||||||
return Promise.reject(error);
|
return Promise.reject(error);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user