({
// ... 现有字段
examMode: false,
examDuration: 60, // 默认60分钟
});
```
编辑时数据回填:
```typescript
Object.assign(newAssignmentInfo, {
// ... 现有字段
examMode: assignment.examMode ?? false,
examDuration: assignment.examDuration ?? 60,
});
```
提交验证:
```typescript
if (newAssignmentInfo.examMode && (!newAssignmentInfo.examDuration || newAssignmentInfo.examDuration < 1)) {
ElNotification({ title: '考试模式下考试时长不得为空', type: 'error' });
return;
}
```
---
### 阶段4:作业详情页修改
#### 4.1 `HomeworkDetail.vue`
修改点:显示模式标识和时长
```vue
作业模式:
{{ data.examMode ? '考试模式' : '普通作业' }}
时长: {{ data.examDuration }}分钟
```
---
### 阶段5:写作页面修改(核心)
#### 5.1 `EditPage.vue`
考试模式下的布局调整:
```vue
```
考试倒计时集成:
```typescript
import { useExamCountdown } from '@/hooks/useExamCountdown';
// 计算属性
const isExamMode = computed(() => dataForm.assignment?.examMode ?? false);
const examDuration = computed(() => dataForm.assignment?.examDuration ?? 0);
// 倒计时hook
const { remainingTime, isWarning, formattedTime, start: startCountdown } = useExamCountdown({
startTime: new Date(dataForm.assignment.startTime),
duration: examDuration.value,
onAutoSubmit: async () => {
ElMessage.warning('考试时间已到,正在自动提交...');
await handleStage(); // 自动暂存
await handleSubmit(); // 自动提交
},
onWarning: () => {
ElMessage.info('距离考试结束还有5分钟,请注意暂存您的内容!');
}
});
onMounted(() => {
if (isExamMode.value) {
startCountdown();
}
});
```
---
### 阶段6:编辑组件提交确认
#### 6.1 `Edit/index.vue`
考试模式提交确认:
```typescript
const handleSubmit = async () => {
if (isExamMode) {
// 考试模式:确认提示
await ElMessageBox.confirm(
'考试时间结束后将自动交卷,确认现在提交吗?提交后不可再修改。',
'确认交卷',
{
confirmButtonText: '确认提交',
cancelButtonText: '取消',
type: 'warning',
}
);
}
// 执行提交...
};
```
Props接收考试模式标识:
```typescript
interface IEditProps {
engagement: engagementVO
isExamMode?: boolean;
}
defineProps();
```
---
## 四、考试模式功能差异对照表
| 功能 | 普通作业模式 | 考试模式 |
|------|------------|---------|
| AI助手 | ✅ 正常显示 | ✅ 正常显示 |
| 词典 | ✅ 正常显示 | ✅ 正常显示 |
| 暂存按钮 | ✅ 显示 | ✅ 显示(考试期间可暂存) |
| 批改区域 | ✅ 显示 | ❌ 隐藏 |
| 倒计时 | ❌ 不显示 | ✅ 显示 |
| 提交次数限制 | 多次 | 仅一次 |
| 提交确认提示 | 无 | 有"不可修改"提示 |
| 5分钟警告 | 无 | 有暂存提示 |
| 自动交卷 | 无 | 倒计时结束自动暂存并提交 |
---
## 五、实施顺序
1. **类型定义更新**(dto.ts, vo.ts)
2. **新建 useExamCountdown hook**
3. **WritingAssignmentDialogue.vue** - 教师端添加考试模式选项
4. **HomeworkDetail.vue** - 显示模式标识
5. **EditPage.vue** - 集成倒计时横幅
6. **Edit/index.vue** - 考试模式提交确认
7. **样式文件** - 考试模式UI
---
## 六、注意事项
1. 考试时长从 `assignment` 获取(教师设置),不是从 `engagement`
2. 倒计时基于 `startTime` + `examDuration` 计算结束时间
3. 自动交卷需要先暂存当前内容,再提交
4. 已提交状态的严格校验在后端完成
5. 考试模式下的各个辅助功能正常可用,仅隐藏批改区域