const fs = require('fs'); const path = require('path'); const filePath = path.join(__dirname, 'admin.html'); let html = fs.readFileSync(filePath, 'utf8'); // ─── EXAM TEMPLATE PAGE HTML ─────────────────────────────────────────────── const examPageHtml = `
考试模版
管理各类考试的模版配置,包含基本设置、考前配置、防作弊及证书颁发等。
唯一模版
开学考试
分级考试
应知应会
权限层级:
每学年自动按配置日期创建考试
基本设置
考试类型 系统内置,不可更改
风险等级
考试名称
答卷次数
显示共享 开课共享,全程有学号信息不可匿名
启用
考卷
实验室安全基础知识×
建议按知识点选择覆盖本校安全要求的试卷
考试时间
考试时长
分钟
限制答卷最大时长
考试范围
用户类别
学时配置
用户类别所需学时备注
新入学本科生
新入学研究生
新入职教职工
`; // end examPageHtml // ─── JS FUNCTIONS TO INJECT ──────────────────────────────────────────────── const examJsFunctions = ` // ===== EXAM TEMPLATE PAGE ===== function switchExamTab(tab) { document.querySelectorAll('.exam-tab-panel').forEach(function(p) { p.style.display = 'none'; }); var panel = document.getElementById('exam-tab-' + tab); if (panel) { panel.style.display = tab === 'yingzhi' ? 'flex' : 'flex'; if (tab === 'fenji') { // ensure flex for fenji sub-tab wrapper panel.style.display = 'block'; } } document.querySelectorAll('#exam-top-tabs .view-tab').forEach(function(t) { t.classList.remove('active'); }); var tabMap = { kaixue: 0, fenji: 1, yingzhi: 2 }; var tabs = document.querySelectorAll('#exam-top-tabs .view-tab'); if (tabs[tabMap[tab]]) tabs[tabMap[tab]].classList.add('active'); } function switchExamSection(prefix, section) { // Hide all sections in this prefix's container var secs = document.querySelectorAll('#' + prefix + '-sec-basic, #' + prefix + '-sec-preexam, #' + prefix + '-sec-cheat, #' + prefix + '-sec-cert'); secs.forEach(function(s) { s.style.display = 'none'; }); var target = document.getElementById(prefix + '-sec-' + section); if (target) target.style.display = 'block'; // Update nav active state - find nav items in same sidebar var secContainer = target && target.closest('[style*="overflow:hidden"]'); if (secContainer) { secContainer.querySelectorAll('.nav-item').forEach(function(n) { n.classList.remove('active'); var oc = n.getAttribute('onclick') || ''; if (oc.includes("'" + section + "'")) n.classList.add('active'); }); } } function switchGradeTab(grade) { document.querySelectorAll('.fenji-grade-panel').forEach(function(p) { p.style.display = 'none'; }); var panel = document.getElementById('fenji-grade-' + grade); if (panel) panel.style.display = 'flex'; document.querySelectorAll('#fenji-grade-tabs .view-tab').forEach(function(t) { t.classList.remove('active'); }); var gradeMap = { g1: 0, g2: 1, g3: 2, g4: 3 }; var tabs = document.querySelectorAll('#fenji-grade-tabs .view-tab'); if (tabs[gradeMap[grade]]) tabs[gradeMap[grade]].classList.add('active'); } function setKaixueScope(mode) { document.getElementById('kaixue-scope-table').style.display = (mode === 'specify' || mode === 'student') ? 'block' : 'none'; document.querySelectorAll('[name="kaixue-scope"]').forEach(function(r) { r.checked = (r.value === mode); }); } function stepNum(id, delta) { var el = document.getElementById(id); if (!el) return; var val = (parseInt(el.value, 10) || 0) + delta; var min = parseInt(el.min, 10); if (!isNaN(min) && val < min) val = min; el.value = val; } function updateKaixueHours() { // Reflect checked user types in the hours table var tbody = document.getElementById('kaixue-hours-tbody'); if (!tbody) return; var types = [ { id: 'kaixue-user-undergrad', label: '新入学本科生', def: 4 }, { id: 'kaixue-user-postgrad', label: '新入学研究生', def: 4 }, { id: 'kaixue-user-staff', label: '新入职教职工', def: 2 } ]; var rows = ''; types.forEach(function(t) { var cb = document.getElementById(t.id); if (cb && cb.checked) { rows += '' + t.label + ''; } }); tbody.innerHTML = rows || '请先选择用户类别'; } `; // end examJsFunctions // ─── PERFORM REPLACEMENTS ────────────────────────────────────────────────── const PLACEHOLDER = ''; if (!html.includes(PLACEHOLDER)) { console.error('ERROR: Placeholder not found in admin.html'); process.exit(1); } html = html.replace(PLACEHOLDER, examPageHtml); // Inject JS before closing tag const SCRIPT_END = ''; const lastScriptEnd = html.lastIndexOf(SCRIPT_END); if (lastScriptEnd === -1) { console.error('ERROR: No closing tag found'); process.exit(1); } html = html.slice(0, lastScriptEnd) + examJsFunctions + '\n' + SCRIPT_END + html.slice(lastScriptEnd + SCRIPT_END.length); fs.writeFileSync(filePath, html, 'utf8'); console.log('inject_exam.js: admin.html updated successfully.');