Files
ny-exam-platform/tools/docs-preview.js
T
nxxy335 25a2e8a42c 文档部署到 /ny-exam-platform 子路径 + 移除快照/趋势/异常 + 打印与 UI 全面完善
文档站(#88)
- base 默认改为 /ny-exam-platform/,可用 DOCS_BASE=/ 覆盖本地预览
- 新增 DOCS_OUT 环境变量,避免构建时清空输出目录失败导致产物半截
- 新增 tools/docs-preview.js:按子路径重写路由的本地预览服务
- 删除 docs/guide/snapshot.md,同步清理全部相关文档

移除存快照 / 趋势 / 异常(#89)
- 后端:删除 api.php 的 snapshot_save/list/delete/trend 四个 action 与
  $WRITE_ACTIONS 中的同名条目;删除 lib/Snapshot.php 与自动加载注册;
  DataService 移除 detectAnomalies() 及其调用
- 前端:移除三个按钮与三个弹窗、相关 JS 处理与 state 字段
- 测试:移除对应用例,补充 5 条名单导入列识别断言(17+9+18+32+29+11 全过)

打印完善(#90)
- 改用隐藏 iframe 输出,规避弹窗拦截;@page A4 支持纵向/横向
- 表头每页重复、行内不跨页断开、全表连续名次、可选「是否合格」列
- 分组小计(人数/平均/最高/最低/合格人数与合格率)、可附缺考名单另起一页
- 末尾签字栏;缺考名单打印改为同一套输出

UI / 交互 / Bug 修复(#91)
- dashboard.php:补「← 主系统 / 退出」入口(此前全屏后无法离开);
  修复成员下钻 onclick 里 JSON.stringify 双引号提前闭合属性导致点击报错,
  改为 data-sid 事件委托;补 Esc 关弹窗;后台标签页暂停轮询、切回自动补拉;
  刷新中断原因写入 title;数值字段统一兜底,避免 NaN / undefined%
- draw.php / draw.js:结果表新增「登陆账号」列(导出前可核对,缺失显示 学号 ⚠);
  弹窗只关最上层且支持 Esc;「全部」改为跟随候选池,手工改人数即解除;
  候选池不足时给出明确提示;自定义比例框隐藏时清空,避免旧权重被误读
- app.js / dashboard.php:成绩着色改为按「占本卷满分的百分比」判断,
  修复满分不是 100 时整列误标红
- style.css:数值列右对齐;新增 subbar、draw-stage-sub;
  看板顶栏窄屏下拉与按钮换行,消除横向滚动
2026-09-11 16:23:08 +08:00

107 lines
3.4 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env node
/**
* 文档站本地预览服务
*
* 站点是按 /ny-exam-platform 子路径构建的(base: '/ny-exam-platform/'),
* 直接把 dist 目录当根来跑静态服务会导致所有资源 404。
* 这里做一层前缀重写:把 /ny-exam-platform/<path> 映射到 dist 目录下的 <path>,
* 根路径 / 自动跳转到 /ny-exam-platform/。
*
* 用法:
* node tools/docs-preview.js [端口] [dist目录]
* node tools/docs-preview.js 5199 docs/.vitepress/dist-final
*/
'use strict';
const http = require('http');
const fs = require('fs');
const path = require('path');
const PORT = parseInt(process.argv[2], 10) || 5199;
const DIST = path.resolve(process.argv[3] || path.join(__dirname, '..', 'docs', '.vitepress', 'dist-final'));
const BASE = (process.env.DOCS_BASE || '/ny-exam-platform').replace(/\/+$/, '');
const MIME = {
'.html': 'text/html; charset=utf-8',
'.js': 'text/javascript; charset=utf-8',
'.mjs': 'text/javascript; charset=utf-8',
'.css': 'text/css; charset=utf-8',
'.json': 'application/json; charset=utf-8',
'.svg': 'image/svg+xml',
'.png': 'image/png',
'.jpg': 'image/jpeg',
'.jpeg': 'image/jpeg',
'.gif': 'image/gif',
'.webp': 'image/webp',
'.ico': 'image/x-icon',
'.woff': 'font/woff',
'.woff2': 'font/woff2',
'.ttf': 'font/ttf',
'.txt': 'text/plain; charset=utf-8',
'.map': 'application/json; charset=utf-8',
};
if (!fs.existsSync(DIST)) {
console.error('[docs-preview] 找不到构建产物:' + DIST);
console.error('请先构建:DOCS_OUT=.vitepress/dist-final npx vitepress build .');
process.exit(1);
}
/** 把 URL 中的前缀剥掉,得到 dist 内的相对路径 */
function toRel(urlPath) {
let p = decodeURIComponent(urlPath.split('?')[0].split('#')[0]);
if (p === BASE || p === BASE + '/') return '/index.html';
if (p.startsWith(BASE + '/')) p = p.slice(BASE.length);
return p;
}
/** 依次尝试:原样 / .html / 目录下 index.html,模拟静态托管的行为 */
function resolveFile(rel) {
const clean = path.normalize(rel).replace(/^([/\\])+/, '');
const full = path.join(DIST, clean);
if (full.indexOf(DIST) !== 0) return null; // 防目录穿越
const candidates = [full, full + '.html', path.join(full, 'index.html')];
for (const c of candidates) {
try {
if (fs.existsSync(c) && fs.statSync(c).isFile()) return c;
} catch (e) { /* 忽略 */ }
}
return null;
}
const server = http.createServer((req, res) => {
const urlPath = req.url || '/';
// 根路径 / 直接跳到子路径首页
if (urlPath === '/' || urlPath === '') {
res.writeHead(302, { Location: BASE + '/' });
res.end();
return;
}
const rel = toRel(urlPath);
const file = resolveFile(rel);
if (!file) {
res.writeHead(404, { 'Content-Type': 'text/plain; charset=utf-8' });
res.end('404 Not Found: ' + urlPath);
return;
}
const ext = path.extname(file).toLowerCase();
res.writeHead(200, {
'Content-Type': MIME[ext] || 'application/octet-stream',
'Cache-Control': 'no-cache',
});
fs.createReadStream(file).pipe(res);
});
server.listen(PORT, '127.0.0.1', () => {
console.log('[docs-preview] 文档站已启动');
console.log(' 访问地址:http://127.0.0.1:' + PORT + BASE + '/');
console.log(' 构建目录:' + DIST);
});
server.on('error', e => {
console.error('[docs-preview] 启动失败:' + e.message);
process.exit(1);
});