提交 f0b387d6 authored 作者: yujiejie's avatar yujiejie

821最终版本

上级 94dfffef
# 0823 导师部署验收台重构 - 交接文档
> 更新时间:2026-06-16
> 项目:`0820studyweb_Prototype`
> 涉及文件:`pages-mentor.js`(主改)、`pages-student.js`(仅核对,未改)
> 状态:步骤 0 → 13 已按方案全部完成
---
## 1. 本次重构完成内容
### 步骤 1:全局状态与命名
- `MENTOR_DEPLOY_TASKS`:任务定义表,含「任务一 文本模型 / 任务二 图像生成」两个任务的路径、默认参数。
- `mentorDeployReviewState`:验收台状态全部改为「任务 × 学生」两级索引(`params / tests / scores / comments / conclusion`)。
- 提交数据 `deploySubmissionsByStudent` 二维化:`[学生 id][taskKey]`。
### 步骤 2:测试函数 + Mock 数据
- 四个学生 × 两个任务共 8 组 mock 提交数据,覆盖:待验收 / 已驳回(第 1 轮)/ 未提交 / 部分提交。
- 真实 API 测试函数:`runMentorDeployModelsTest / runMentorDeployChatTest / runMentorDeployGenSubmitTest / runMentorDeployGenStatusTest`,每个测试函数显式绑定任务维度,防止串数据。
### 步骤 3-5:三栏布局与中栏 Tab
- 左侧学生列表卡:显示每个学生两个任务的状态徽章 + 提交完整度。
- 顶部全局任务 Tab(任务一 / 任务二),切换联动中栏与右栏。
- 中栏内部 Tab:部署产物 / 实操日志 / 实操报告(只读展示 + 复制入口)。
### 步骤 7-8:产物复制与全局配置
- 产物 API Key / 地址一键复制,并可快速填入测试配置。
- 右栏顶部全局配置区:API 地址 + API Key 临时覆盖(`window.__mentorDeployTempApiUrl / TempApiKey`),「应用 / 恢复学生值」。
### 步骤 9-10:API 测试区重构
- **文本模型卡**:任务说明条(非竖排横向布局)+「恢复任务默认值」+ 默认值文案,测试项含模型列表 / 聊天补全。
- **图像生成卡**:任务说明条 +「恢复任务默认值」+ 图片尺寸 / **宽高比(1:1 / 3:4 / 4:3 / 9:16 / 16:9)** / 随机种子参数,提交 body 携带 `options.aspect_ratio`。
### 步骤 11:验收结论区重构(整体单选)
- 取消「产物 / 报告分项验收」,改为**整体单选**:通过 / 驳回 / 待补充。
- `getMentorDeployReviewConclusion / setMentorDeployReviewConclusion`:结论草稿按学生索引。
- 提交校验:
- 通过 → 产物与报告必须都已提交,且关键 API 测试全部通过。
- 驳回 / 待补充 → 评语必填。
- 锁定态只读卡与历史记录卡同步移除分项展示。
### 步骤 12:提交同步与锁定适配
- `submitMentorDeployReview`:按当前任务提交,快照本轮测试结果与参数,仅「通过」写入评分。
- 同步 `studentState`:`deployReviewTaskKey / deployReviewStatus / deployReviewComment / deployPassed / deployRejected` 等;驳回 / 待补充时重置学生提交状态(学生可重新编辑提交)。
- `isMentorDeployReviewLocked`:仅 `已通过 / 已驳回 / 待补充` 三种正式结论锁定;`验收中 / 待验收` 仍可编辑。
### 步骤 13:整体联调与样式打磨
- 图像生成**自动轮询**:`startMentorDeployGenPolling / stopMentorDeployGenPolling`,3 秒一次,成功 / 失败 / 网络错误 3 次自动停止;提交成功自动启动,轮询开关可手动切换(`toggleMentorDeployGenPolling`)。
- 图片预览:`succeeded` 时展示 `outputs[].url` 图片 + 打开原图链接,加载失败降级提示。
- 生成进度条:`running` 状态展示进度百分比进度条。
- **保存草稿**:`saveMentorDeployReviewDraft`,未给正式结论时置为「验收中」(不锁定),同步学生端状态。
- 轮询清理:切换学生、切换任务 Tab、提交结论三处均调用 `stopMentorDeployGenPolling()`。
- 状态颜色统一:通过绿 / 驳回红 / 待补充紫 / 验收中蓝 / 待验收琥珀。
---
## 2. 数据结构速览
### 任务定义(`MENTOR_DEPLOY_TASKS`)
```javascript
'text-model': { tabName: '任务一', title: '文本模型部署', mainPath: '/v1/chat/completions', ... }
'image-gen': { tabName: '任务二', title: '图像生成 API', mainPath: '/v1/generations', statusPath: '/v1/generations/{id}', defaultImagePrompt, defaultSize, defaultAspectRatio }
```
### 验收台状态(`mentorDeployReviewState`)
```javascript
{
activeTask, contentTab,
params, // [taskKey][sid] -> { apiUrl, apiKey, modelName, prompt, maxTokens, temperature | imagePrompt, size, aspectRatio, seed }
tests, // [taskKey][sid] -> { models, chat | genSubmit, genStatus }
scores, // [taskKey][sid] -> { api(40), deployment(20), logs(15), report(15), reflection(10) }
comments, // [taskKey][sid] -> string
conclusion, // [sid] -> '通过' | '驳回' | '待补充'(草稿,全局共享)
pollTimer, pollAuto
}
```
### 测试结果结构
- `genSubmit`:`{ status, httpStatus, latency, taskId, raw, error, testedAt, url }`
- `genStatus`:`{ status, httpStatus, latency, taskId, taskStatus, progress, outputs, raw, error, testedAt, url }`
- `chat`:`{ status, httpStatus, latency, responseText, returnedModel, raw, error, testedAt, url }`
---
## 3. 验收结论流转
```
未提交 → 待验收(双提交完成)→ 验收中(导师保存草稿,可编辑)
→ 已通过 / 已驳回 / 待补充(导师提交,锁定只读)
→ 驳回 / 待补充后学生重新编辑提交 → 新一轮「待验收」
```
---
## 4. 已知限制与注意事项
1. **`Lundefined:undefined` lint 预警**(4 条):来自 HTML 模板字符串,已知无害,可忽略。
2. **真实 API 受 CORS 限制**:AutoDL 服务未允许跨域时测试会失败,错误提示已覆盖;原型保持真实请求,不加伪造数据。
3. **`studentState` 为全局单例**:导师端同步的仍是同一份演示数据,最后一次提交为准。
4. **轮询基于真实 HTTP**:无真实服务时自动轮询会因网络错误在 3 次后自动停止,不会无限重试。
5. **步骤 6(日志关键词高亮)本次未实施**:中栏日志为只读展示,未做高亮;如后续需要可在此基础上补充。
6. **宽高比参数名**:请求 body 使用 `options.aspect_ratio`,若实际服务端字段不同需按服务端文档调整。
7. **轮询间隔**:3 秒 / 最多 30 次(约 90 秒),如需更久请调整 `startMentorDeployGenPolling` 内的 `poll` 对象。
---
## 5. 验证方式
- 语法检查:`node --check pages-mentor.js`(每步完成后执行)。
- 浏览器流程(导师端 → 部署验收):
1. 任务 Tab 切换:任务一 / 任务二状态徽章与内容区联动。
2. 文本任务:模型列表 / 聊天补全测试,四要素(状态码 / 耗时 / 结论 / JSON)。
3. 图像任务:提交生成任务 → 自动轮询 → 进度条 → 图片预览;宽高比参数生效。
4. 结论:整体单选 → 保存草稿(状态变「验收中」且不锁定)→ 提交(通过需 API 全过 + 双提交;驳回 / 待补充需评语)。
5. 锁定后只读;驳回后学生重新提交 → 新轮次解锁。
- 自动化冒烟:`node _tmp_*.js`(临时脚本已清理)。
......@@ -1467,7 +1467,8 @@ function issueMentorAutodl() {
function selectMentorDeployReviewStudent(id) {
mentorState.deployReviewStudentId = Number(id);
// 切换学生时重置全局配置临时变量,避免上一学生输入残留
// 切换学生时停止图像轮询并重置全局配置临时变量,避免上一学生残留
if (typeof stopMentorDeployGenPolling === 'function') stopMentorDeployGenPolling();
window.__mentorDeployTempApiUrl = null;
window.__mentorDeployTempApiKey = null;
renderContent();
......@@ -1514,8 +1515,8 @@ function getMentorDeployStudentStatus(studentId, taskKey) {
function isMentorDeployReviewLocked(studentId, taskKey) {
var sub = getMentorDeploySubmission(studentId, taskKey);
if (!sub || !sub.review || !sub.review.status) return false;
// 只有导师真正提交的验收结论(已通过/已驳回/待补充)才锁定,「待验收」仍可编辑
return sub.review.status !== '待验收';
// 只有导师真正提交的验收结论(已通过/已驳回/待补充)才锁定,「验收中 / 待验收」仍可编辑
return sub.review.status === '已通过' || sub.review.status === '已驳回' || sub.review.status === '待补充';
}
function getMentorDeployStatusBadge(status) {
......@@ -1746,7 +1747,8 @@ var MENTOR_DEPLOY_TASKS = {
mainPath: '/v1/generations',
statusPath: '/v1/generations/{id}',
defaultImagePrompt: '一只戴蓝色围巾的柴犬,半身像,自然光',
defaultSize: '1024x1024'
defaultSize: '1024x1024',
defaultAspectRatio: '1:1'
}
};
......@@ -1758,7 +1760,9 @@ var mentorDeployReviewState = {
tests: {}, // [taskKey][sid] -> { models, chat | genSubmit | genStatus }
scores: {}, // [taskKey][sid] -> { api, deployment, logs, report, reflection }
comments: {}, // [taskKey][sid] -> string
conclusion: {} // 整体验收结论草稿:conclusion[sid] = '通过' | '驳回' | '待补充'
conclusion: {}, // 整体验收结论草稿:conclusion[sid] = '通过' | '驳回' | '待补充'
pollTimer: null, // 图像任务自动轮询定时器
pollAuto: true // 自动轮询开关(默认开)
};
// 返回验收台状态中指定容器在当前任务维度的「学生 map」,自动初始化中间层级
......@@ -1789,6 +1793,7 @@ function getMentorDeployReviewParams(studentId, taskKey) {
temperature: saved.temperature != null ? saved.temperature : (def.defaultTemperature || '0.2'),
imagePrompt: saved.imagePrompt != null ? saved.imagePrompt : (def.defaultImagePrompt || '一只戴蓝色围巾的柴犬,半身像,自然光'),
size: saved.size != null ? saved.size : (def.defaultSize || '1024x1024'),
aspectRatio: saved.aspectRatio != null ? saved.aspectRatio : (def.defaultAspectRatio || '1:1'),
seed: saved.seed != null ? saved.seed : ''
};
}
......@@ -2020,6 +2025,79 @@ function mentorDeployPickTaskInfo(data) {
};
}
// ===== 图像生成自动轮询 =====
function startMentorDeployGenPolling() {
stopMentorDeployGenPolling();
var poll = { count: 0, max: 30 };
mentorDeployReviewState.pollTimer = setInterval(function() {
poll.count += 1;
var sid = Number(mentorState.deployReviewStudentId);
var tests = getMentorDeployReviewNode('tests', sid, 'image-gen')[sid] || {};
var st = tests.genStatus;
if (st && (st.taskStatus === 'succeeded' || st.taskStatus === 'failed')) {
stopMentorDeployGenPolling();
return;
}
if (poll.count > poll.max) {
stopMentorDeployGenPolling();
return;
}
runMentorDeployGenStatusTest();
}, 3000);
}
function stopMentorDeployGenPolling() {
if (mentorDeployReviewState.pollTimer) {
clearInterval(mentorDeployReviewState.pollTimer);
mentorDeployReviewState.pollTimer = null;
}
}
function toggleMentorDeployGenPolling() {
mentorDeployReviewState.pollAuto = !mentorDeployReviewState.pollAuto;
if (mentorDeployReviewState.pollAuto) {
var sid = Number(mentorState.deployReviewStudentId);
var tests = getMentorDeployReviewNode('tests', sid, 'image-gen')[sid] || {};
var taskId = (tests.genSubmit && tests.genSubmit.taskId) || '';
if (taskId) startMentorDeployGenPolling();
} else {
stopMentorDeployGenPolling();
}
renderContent();
}
function getMentorDeployAspectRatioOptions(current) {
var ratios = ['1:1', '3:4', '4:3', '9:16', '16:9'];
var cur = current || '';
return ratios.map(function(r) {
return '<option value="' + r + '"' + (r === cur ? ' selected' : '') + '>' + r + '</option>';
}).join('');
}
function buildMentorDeployGenImagePreview(result) {
if (!result || result.taskStatus !== 'succeeded') return '';
if (!result.outputs || !result.outputs.length) return '';
var cards = result.outputs.map(function(out, i) {
var url = (out && (out.url || (out.image && out.image.url))) || '';
if (!url) return '';
return '<div class="mt-2">' +
'<img src="' + mentorDeployReviewEsc(url) + '" alt="生成图片 ' + (i + 1) + '" class="rounded-lg border border-[#E5E6EB] max-h-56 w-auto" loading="lazy" onerror="this.closest(\'div\').outerHTML=\'<p class=&quot;text-xs text-rose-500 mt-2&quot;>图片地址无法加载(CORS 或链接已过期),原始响应见下方 JSON。</p>\'">' +
'<a class="mt-1 inline-block text-xs text-[#165DFF] hover:underline" href="' + mentorDeployReviewEsc(url) + '" target="_blank" rel="noopener">打开原图 ↗</a>' +
'</div>';
}).join('');
return cards;
}
function buildMentorDeployGenProgressBar(result) {
if (!result || result.taskStatus !== 'running') return '';
var pct = Math.max(0, Math.min(100, parseInt(result.progress, 10) || 0));
return '<div class="mt-2">' +
'<div class="flex justify-between text-xs text-[#86909C] mb-1"><span>生成进度</span><span>' + pct + '%</span></div>' +
'<div class="h-1.5 rounded-full bg-[#E5E6EB] overflow-hidden"><div class="h-full rounded-full bg-[#165DFF] transition-all" style="width:' + pct + '%"></div></div>' +
'</div>';
}
function runMentorDeployGenSubmitTest() {
var sid = Number(mentorState.deployReviewStudentId);
var tk = 'image-gen';
......@@ -2042,6 +2120,7 @@ function runMentorDeployGenSubmitTest() {
inputs: []
};
body.options = { size: p.size || '1024x1024' };
if (p.aspectRatio) body.options.aspect_ratio = p.aspectRatio;
var seed = parseInt(p.seed, 10);
if (!isNaN(seed)) body.options.seed = seed;
fetch(url, {
......@@ -2074,6 +2153,11 @@ function runMentorDeployGenSubmitTest() {
testedAt: getMentorDeployNowTimestamp(),
url: url
};
// 首次查询:若拿到任务 ID,立即查询一次状态;提交成功且自动轮询开启时启动轮询
if (info.id && currentPage === 'mentor-deploy-review') {
runMentorDeployGenStatusTest();
if (mentorDeployReviewState.pollAuto) startMentorDeployGenPolling();
}
if (currentPage === 'mentor-deploy-review') renderContent();
});
})
......@@ -2142,6 +2226,8 @@ function runMentorDeployGenStatusTest() {
testedAt: getMentorDeployNowTimestamp(),
url: url
};
// 任务结束(成功 / 失败)时停止自动轮询
if (info.status === 'succeeded' || info.status === 'failed') stopMentorDeployGenPolling();
if (currentPage === 'mentor-deploy-review') renderContent();
});
})
......@@ -2160,6 +2246,12 @@ function runMentorDeployGenStatusTest() {
testedAt: getMentorDeployNowTimestamp(),
url: url
};
// 网络错误超过 3 次后停止轮询,避免无限重试
var cnt = mentorDeployReviewState._pollFailCount = (mentorDeployReviewState._pollFailCount || 0) + 1;
if (cnt >= 3) {
mentorDeployReviewState._pollFailCount = 0;
stopMentorDeployGenPolling();
}
if (currentPage === 'mentor-deploy-review') renderContent();
});
}
......@@ -2356,6 +2448,7 @@ function resetMentorDeployImageGenParams() {
if (!map[sid]) map[sid] = {};
delete map[sid].imagePrompt;
delete map[sid].size;
delete map[sid].aspectRatio;
delete map[sid].seed;
renderContent();
}
......@@ -2391,9 +2484,10 @@ function buildMentorDeployImageGenItems(sid) {
'<textarea class="input-field text-sm min-h-[64px] resize-none mt-1" oninput="setMentorDeployReviewParam(\'imagePrompt\', this.value)">' + mentorDeployReviewEsc(p.imagePrompt) + '</textarea>' +
'<div class="grid grid-cols-2 gap-2 mt-2">' +
'<div><label class="text-xs font-medium text-[#4E5969] block mb-1">图片尺寸</label><select class="input-field text-sm" onchange="setMentorDeployReviewParam(\'size\', this.value)">' + getMentorDeploySizeOptions(p.size) + '</select></div>' +
'<div><label class="text-xs font-medium text-[#4E5969] block mb-1">宽高比</label><select class="input-field text-sm" onchange="setMentorDeployReviewParam(\'aspectRatio\', this.value)">' + getMentorDeployAspectRatioOptions(p.aspectRatio || taskDef.defaultAspectRatio) + '</select></div>' +
'<div><label class="text-xs font-medium text-[#4E5969] block mb-1">随机种子</label><input class="input-field text-sm" placeholder="可选" value="' + mentorDeployReviewEsc(p.seed) + '" oninput="setMentorDeployReviewParam(\'seed\', this.value)"></div>' +
'</div>' +
'<div class="mt-2 text-xs text-[#86909C]">默认值:描述「' + mentorDeployReviewEsc(taskDef.defaultImagePrompt || '') + '」,尺寸 ' + mentorDeployReviewEsc(taskDef.defaultSize || '') + '</div>' +
'<div class="mt-2 text-xs text-[#86909C]">默认值:描述「' + mentorDeployReviewEsc(taskDef.defaultImagePrompt || '') + '」,尺寸 ' + mentorDeployReviewEsc(taskDef.defaultSize || '') + ',宽高比 ' + mentorDeployReviewEsc(taskDef.defaultAspectRatio || '1:1') + '</div>' +
buildMentorDeployTestMeta(genResult) +
(genResult && genResult.taskId ? '<div class="mt-1.5 text-xs text-[#4E5969]">任务 ID:<b class="font-mono">' + mentorDeployReviewEsc(genResult.taskId) + '</b></div>' : '') +
buildMentorDeployTestError(genResult) +
......@@ -2404,10 +2498,15 @@ function buildMentorDeployImageGenItems(sid) {
'<div class="mt-2 text-xs font-mono text-[#4E5969] bg-white border border-[#E5E6EB] rounded p-2 break-all">' + mentorDeployReviewEsc(getMentorDeployGenStatusUrl()) + '</div>' +
buildMentorDeployTestMeta(statusResult) +
(statusResult && statusResult.taskStatus
? '<div class="mt-1.5 text-xs text-[#4E5969]">任务状态:<b class="' + (statusResult.taskStatus === 'succeeded' ? 'text-emerald-600' : 'text-[#1D2129]') + '">' + mentorDeployReviewEsc(statusResult.taskStatus) + '</b> · 进度:' + (statusResult.progress || 0) + '%</div>'
? '<div class="mt-1.5 text-xs text-[#4E5969]">任务状态:<b class="' + (statusResult.taskStatus === 'succeeded' ? 'text-emerald-600' : statusResult.taskStatus === 'failed' ? 'text-rose-500' : 'text-[#1D2129]') + '">' + mentorDeployReviewEsc(statusResult.taskStatus) + '</b>' + (statusResult.taskStatus === 'succeeded' ? ' · 已生成 ' + (statusResult.outputs ? statusResult.outputs.length : 0) + ' 张图片' : '') + '</div>'
: '') +
buildMentorDeployGenProgressBar(statusResult) +
buildMentorDeployGenImagePreview(statusResult) +
buildMentorDeployTestError(statusResult) +
'<button class="btn-outline w-full mt-3 py-2 text-sm" onclick="runMentorDeployGenStatusTest()" ' + (statusLoading ? ' disabled' : '') + '>' + (statusLoading ? '查询中…' : '查询状态') + '</button>' +
'<div class="flex items-center justify-between gap-2 mt-3">' +
'<button class="btn-outline flex-1 py-2 text-sm" onclick="runMentorDeployGenStatusTest()" ' + (statusLoading ? ' disabled' : '') + '>' + (statusLoading ? '查询中…' : '立即查询') + '</button>' +
'<button class="text-xs px-2 py-1.5 rounded border transition-all ' + (mentorDeployReviewState.pollAuto ? 'bg-[#E8F3FF] text-[#165DFF] border-[#165DFF]' : 'bg-[#F2F3F5] text-[#86909C] border-[#E5E6EB]') + '" type="button" onclick="toggleMentorDeployGenPolling()">自动轮询:' + (mentorDeployReviewState.pollAuto ? '开' : '关') + '</button>' +
'</div>' +
'</div>' +
'</div>';
}
......@@ -2545,6 +2644,27 @@ function setMentorDeployReviewConclusion(value) {
renderContent();
}
function saveMentorDeployReviewDraft() {
var sid = Number(mentorState.deployReviewStudentId);
var taskKey = getMentorDeployTaskKey(sid);
var sub = getMentorDeploySubmission(sid, taskKey);
if (!sub) {
showStudentFlowModal('无法保存草稿', '该学生暂无提交内容。');
return;
}
if (!sub.review) sub.review = {};
// 仅当尚未给出正式结论时置为「验收中」,不锁定
if (!sub.review.status || sub.review.status === '待验收' || sub.review.status === '验收中') {
sub.review.status = '验收中';
if (typeof studentState !== 'undefined') {
studentState.deployReviewTaskKey = taskKey;
studentState.deployReviewStatus = '验收中';
}
}
showStudentFlowModal('草稿已保存', '验收配置、评分与评语已暂存,学生状态已标记为「验收中」,可继续编辑后提交。');
renderContent();
}
function buildMentorDeployConclusionPanel(sid) {
var comment = getMentorDeployReviewComment(sid);
var current = getMentorDeployReviewConclusion(sid);
......@@ -2567,8 +2687,11 @@ function buildMentorDeployConclusionPanel(sid) {
'<textarea id="deployReviewComment" class="input-field text-sm min-h-[110px] resize-none" placeholder="请填写验收结论、发现的问题、修改建议、补充材料要求或后续学习建议…" oninput="setMentorDeployReviewComment(this.value)">' + mentorDeployReviewEsc(comment) + '</textarea>' +
'<p class="text-xs text-[#86909C] mt-1">有驳回或要求补充材料时评语必填。</p>' +
'</div>' +
'<button class="w-full py-2.5 text-sm font-medium rounded-lg bg-[#165DFF] hover:bg-[#4080FF] text-white transition-all" onclick="submitMentorDeployReview()">提交验收结论并通知学生</button>' +
'<p class="text-xs text-[#86909C] mt-2 leading-relaxed">请先选择整体结论,然后填写评语,最后点击提交。</p>' +
'<div class="flex gap-2">' +
'<button class="btn-outline flex-1 py-2.5 text-sm font-medium rounded-lg" onclick="saveMentorDeployReviewDraft()">保存草稿</button>' +
'<button class="flex-1 py-2.5 text-sm font-medium rounded-lg bg-[#165DFF] hover:bg-[#4080FF] text-white transition-all" onclick="submitMentorDeployReview()">提交验收结论并通知学生</button>' +
'</div>' +
'<p class="text-xs text-[#86909C] mt-2 leading-relaxed">请先选择整体结论,然后填写评语;可先保存草稿,确认无误后再提交。</p>' +
'</div>';
}
......@@ -2688,6 +2811,7 @@ function submitMentorDeployReview() {
var sid = Number(mentorState.deployReviewStudentId);
var taskKey = getMentorDeployTaskKey(sid);
var sub = getMentorDeploySubmission(sid, taskKey);
if (typeof stopMentorDeployGenPolling === 'function') stopMentorDeployGenPolling();
if (!sub) {
showStudentFlowModal('无法验收', '该学生暂无提交内容。');
return;
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论