Преглед изворни кода

feat(mobile): add uni-app v1.2 delivery

anne пре 3 недеља
комит
f5ae2e5e3b
50 измењених фајлова са 19829 додато и 0 уклоњено
  1. 7 0
      mobile-uniapp/.gitignore
  2. 85 0
      mobile-uniapp/README.md
  3. 3 0
      mobile-uniapp/babel.config.js
  4. 57 0
      mobile-uniapp/docs/DELIVERY.md
  5. 32 0
      mobile-uniapp/docs/MIGRATION_MATRIX.md
  6. 18446 0
      mobile-uniapp/package-lock.json
  7. 42 0
      mobile-uniapp/package.json
  8. 5 0
      mobile-uniapp/postcss.config.js
  9. 13 0
      mobile-uniapp/public/index.html
  10. 7 0
      mobile-uniapp/scripts/node25-compat.cjs
  11. 30 0
      mobile-uniapp/scripts/patch-uni-template-loader.cjs
  12. 20 0
      mobile-uniapp/src/App.vue
  13. 33 0
      mobile-uniapp/src/components/CourseCard.vue
  14. 57 0
      mobile-uniapp/src/components/ExamCard.vue
  15. 20 0
      mobile-uniapp/src/components/HomeEntry.vue
  16. 40 0
      mobile-uniapp/src/components/PageHeader.vue
  17. 43 0
      mobile-uniapp/src/components/PdfConfirmation.vue
  18. 8 0
      mobile-uniapp/src/components/StatusTag.vue
  19. 7 0
      mobile-uniapp/src/components/TaskCard.vue
  20. 4 0
      mobile-uniapp/src/config/runtime.js
  21. 11 0
      mobile-uniapp/src/main.js
  22. 21 0
      mobile-uniapp/src/manifest.json
  23. 26 0
      mobile-uniapp/src/pages.json
  24. 6 0
      mobile-uniapp/src/pages/certificates/index.vue
  25. 12 0
      mobile-uniapp/src/pages/certificates/preview.vue
  26. 6 0
      mobile-uniapp/src/pages/exam/answer.vue
  27. 6 0
      mobile-uniapp/src/pages/exam/index.vue
  28. 6 0
      mobile-uniapp/src/pages/exam/pledge.vue
  29. 6 0
      mobile-uniapp/src/pages/exam/result.vue
  30. 63 0
      mobile-uniapp/src/pages/home/index.vue
  31. 23 0
      mobile-uniapp/src/pages/learning/course-detail.vue
  32. 7 0
      mobile-uniapp/src/pages/learning/courseware.vue
  33. 75 0
      mobile-uniapp/src/pages/learning/index.vue
  34. 6 0
      mobile-uniapp/src/pages/learning/material-detail.vue
  35. 7 0
      mobile-uniapp/src/pages/notices/index.vue
  36. 3 0
      mobile-uniapp/src/pages/practice/index.vue
  37. 7 0
      mobile-uniapp/src/pages/profile/index.vue
  38. 6 0
      mobile-uniapp/src/pages/scores/index.vue
  39. 6 0
      mobile-uniapp/src/pages/training/index.vue
  40. 118 0
      mobile-uniapp/src/services/api/mobileApi.js
  41. 110 0
      mobile-uniapp/src/services/business/examFlow.mjs
  42. 47 0
      mobile-uniapp/src/services/business/todos.mjs
  43. 118 0
      mobile-uniapp/src/services/mock/seed.mjs
  44. 36 0
      mobile-uniapp/src/services/mock/storage.mjs
  45. 13 0
      mobile-uniapp/src/static/certificate-demo.svg
  46. 39 0
      mobile-uniapp/src/static/pledge-demo.pdf
  47. 23 0
      mobile-uniapp/src/styles/app.scss
  48. 11 0
      mobile-uniapp/src/styles/tokens.scss
  49. 1 0
      mobile-uniapp/src/uni.scss
  50. 51 0
      mobile-uniapp/tests/exam-flow.test.mjs

+ 7 - 0
mobile-uniapp/.gitignore

@@ -0,0 +1,7 @@
+node_modules/
+dist/
+unpackage/
+.npm-cache/
+.env.local
+.DS_Store
+npm-debug.log*

+ 85 - 0
mobile-uniapp/README.md

@@ -0,0 +1,85 @@
+# Mobile V1.2 uni-app
+
+这是实验室安全教育考试系统的 Mobile V1.2 正式工程。它以 `../mobile/mobile_exam.html` 的已确认交互为业务基准,但不嵌入 HTML 原型,也不依赖浏览器 `window` 或 `sessionStorage`。
+
+## 技术栈
+
+- uni-app 2.0.2(Vue 2 CLI 工程)
+- Vue 2.7.16
+- H5、微信小程序(`mp-weixin`)
+- 当前以可替换 Mock 服务运行;状态持久化使用 `uni.getStorageSync` / `uni.setStorageSync`
+
+安装阶段会自动执行一个极小的 uni-app Vue 2 模板 loader 兼容补丁(`scripts/patch-uni-template-loader.cjs`):当前固定的官方编译包无条件导出未声明的 `recyclableRender` 和 `components`,导致 H5/小程序 Webpack 失败。补丁只声明兼容变量,若上游版本已修复则自动跳过。
+
+## 目录
+
+```text
+mobile-uniapp/
+├─ src/
+│  ├─ pages/                 # 业务页面与路由
+│  ├─ components/            # 复用导航、卡片、状态、PDF 确认组件
+│  ├─ services/api/          # API 门面
+│  ├─ services/business/     # 纯业务规则:待办、考试/补考/承诺书状态机
+│  ├─ services/mock/         # 稳定 ID 的演示数据与跨端存储适配器
+│  ├─ config/runtime.js      # Mock/API 切换入口
+│  └─ static/                # 本地演示证书资源
+├─ tests/                    # Node 纯业务状态测试
+└─ docs/                     # 功能迁移与交付说明
+```
+
+## 安装与启动
+
+在 `mobile-uniapp` 目录运行:
+
+```bash
+npm install
+npm run dev:h5
+```
+
+H5 生产构建:
+
+```bash
+npm run build:h5
+```
+
+微信小程序开发/构建:
+
+```bash
+npm run dev:mp-weixin
+npm run build:mp-weixin
+```
+
+将 `dist/dev/mp-weixin`(开发)或 `dist/build/mp-weixin`(生产)导入微信开发者工具。使用真实小程序时,应在 `src/manifest.json` 填入实际 AppID,并配置请求与业务域名。
+
+## Mock 与真实接口切换
+
+默认 `src/config/runtime.js` 中 `USE_MOCK` 为 `true`。Mock 的数据结构和状态修改集中在:
+
+- `src/services/mock/seed.mjs`
+- `src/services/mock/storage.mjs`
+- `src/services/api/mobileApi.js`
+
+接入后端时,将 `USE_MOCK` 改为 `false`,在 `mobileApi.js` 的同名方法中改为调用后端 API;页面不应直接请求接口。后端至少应持久化学员、考试任务、课程/课件、学习任务、补考安排、成绩、证书签发记录,以及两类承诺书确认记录。
+
+> Mock 存储只保证当前端侧安装/浏览器存储生命周期内的可恢复演示,不提供后端级并发一致性、签章可靠性或跨设备同步。
+
+## 已实现业务与关键规则
+
+- 首页六宫格、通知公告和管理员审批提醒;学习/考试/线下培训的待办角标动态计算,0 不显示、超过 99 显示 `99+`。
+- 在线学习的考前课程、资料学习、违规处置;业务任务使用 `examId`/`courseId`/`violationTaskId` 关联,而非从课程名称或课程 ID 推断完成状态。
+- 学习培训按 `scope.type` 和 `scope.collegeIds` 过滤,不影响其他学习任务。
+- 正式考试、模拟考试、补考及其独立作答记录;补考入口按已发布安排、最终名单、有效状态和次数校验。
+- 考前考试承诺书和交卷后安全承诺书是独立字段。交卷先持久化,未确认安全承诺书会在再次进入时恢复确认流程,不能直接查看结果。
+- 结果页只在实际作答已通过、后承诺书已确认、且已有正式签发证书记录时展示“查看证书”;不会因通过答题自动签发/伪造证书。
+- 线下培训签到、历史状态、成绩列表、证书列表/预览与保存入口、基础刷题练习。
+
+更多逐项迁移状态见 [docs/MIGRATION_MATRIX.md](docs/MIGRATION_MATRIX.md),接口与平台要求见 [docs/DELIVERY.md](docs/DELIVERY.md)。
+
+## 静态与业务测试
+
+```bash
+npm run check
+npm test
+```
+
+当前测试覆盖:考前/考后承诺书状态隔离、交卷恢复门槛、补考与正式考试历史独立、补考证书关联,以及首页待办计算。

+ 3 - 0
mobile-uniapp/babel.config.js

@@ -0,0 +1,3 @@
+module.exports = {
+  presets: ['@vue/cli-plugin-babel/preset']
+}

+ 57 - 0
mobile-uniapp/docs/DELIVERY.md

@@ -0,0 +1,57 @@
+# 开发交付与平台说明
+
+## 路由清单
+
+| 页面 | 路由 |
+| --- | --- |
+| 首页 | `/pages/home/index` |
+| 在线学习 | `/pages/learning/index` |
+| 课程详情 / 课件 | `/pages/learning/course-detail`、`/pages/learning/courseware` |
+| 资料详情 | `/pages/learning/material-detail` |
+| 在线考试 | `/pages/exam/index` |
+| 承诺书 / 作答 / 结果 | `/pages/exam/pledge`、`/pages/exam/answer`、`/pages/exam/result` |
+| 线下培训 | `/pages/training/index` |
+| 刷题、成绩、证书、个人信息 | 对应 `pages/practice`、`pages/scores`、`pages/certificates`、`pages/profile` |
+
+## 数据关系
+
+- 课程资源:`courseId`;课件:`lessonId`。
+- 考前课程任务:`assignmentId + learnerId + examId + courseId`。
+- 违规处置任务:`violationTaskId + learnerId + courseId`。
+- 考试作答:`examId + mode(formal/mock/makeup) + learnerId`;补考另由 `makeupArrangementId` 在后端关联。
+- 证书:`certificateId + learnerId + examId`,只有 `issued: true` 可以展示/预览。
+
+这样允许同一课程被不同考试或违规处置任务复用,且不会将旧课程完成状态无条件视为新业务任务完成。
+
+## 承诺书与结果恢复
+
+每个考试模式保留独立的 `prePledgeConfirmed`、`submitted`、`postPledgeConfirmed` 和 `resultId`。交卷先写入 `submitted`/成绩,再进入安全承诺书。应用重启后服务从 `uni` 存储恢复:
+
+1. 已交卷、未确认后承诺书:进入承诺书确认页面。
+2. 已交卷、已确认:进入结果页面。
+3. 未确认后承诺书时:`getVisibleResult` 返回空,结果页和证书入口均不可绕过。
+
+正式 API 应把这两份确认记录放入服务端,采用学员 ID、考试任务 ID、考试模式、场次/作答记录 ID 作为关联键。
+
+## H5 与微信小程序差异
+
+| 能力 | H5 | 微信小程序 |
+| --- | --- | --- |
+| PDF 承诺书 | `web-view` 加载配置 PDF URL | `downloadFile + openDocument`,必须是已配置的 HTTPS 业务域名 |
+| 证书保存 | 浏览器长按/下载能力 | 下载临时文件后请求相册权限并保存 |
+| 视频 | 使用跨端播放器/服务端进度 API | 同样使用跨端播放器,需小程序域名与媒体配置 |
+| 考试计时 | 前端展示辅助,服务端应校验 | 前端展示辅助,服务端应校验 |
+| 培训扫码 | 浏览器能力与权限不统一 | 可接 `uni.scanCode`,需后端校验签到令牌 |
+
+`PdfConfirmation.vue` 在 PDF 加载/打开失败时不会开放确认按钮。当前本地演示 PDF 地址仅用于 H5 工程示例;上线前必须由后端/对象存储提供各考试对应的 HTTPS PDF 文件并配置微信业务域名。
+
+## 执行的验证
+
+- `npm run check`:Mock 种子、存储、待办、考试状态机语法检查。
+- `npm test`:状态转换与数据隔离测试。
+- `npm run build:h5`:H5 编译。
+- `npm run build:mp-weixin`:微信小程序编译。
+
+最后两项的实际命令结果以本次交付报告为准。若无微信开发者工具,仅保证构建产物可导入,真机及工具内运行需后续验证。
+
+本机使用 Node 25;Vue 2 版 uni-app 的一个旧版 PostCSS 传递依赖仍调用已移除的 `util.isRegExp`。小程序脚本通过 `scripts/node25-compat.cjs` 只补回该兼容谓词。使用 Node 16/18 LTS 的标准开发环境时该脚本无副作用。

+ 32 - 0
mobile-uniapp/docs/MIGRATION_MATRIX.md

@@ -0,0 +1,32 @@
+# Mobile 原型功能迁移对照
+
+基准:`../mobile/mobile_exam.html`,状态均为本次工程迁移范围内的实现。
+
+| 原型功能 | 正式工程位置 | 数据来源 | 状态 / 后端依赖 |
+| --- | --- | --- | --- |
+| 首页六宫格、个人学年、通知 | `pages/home/index.vue` | `mobileApi.getDashboard` | Mock 已实现;用户、公告接口待接入 |
+| 首页待办红点 | `services/business/todos.mjs` | 学习任务、考试开放/补考安排、培训任务 | Mock 已实现;服务端需返回任务状态 |
+| 考前课程 | `pages/learning/index.vue` | `preExamAssignments.examId/courseId` | 已实现 |
+| 资料学习 | `pages/learning/index.vue`、`material-detail.vue` | `materials` | 已实现;真实视频/文档 URL 待接入 |
+| 违规处置课程 | `pages/learning/index.vue` | `violationTasks.taskId/courseId` | 已实现 |
+| 课件阅读、目录、全屏阅读 | `course-detail.vue`、`courseware.vue` | `courses.lessons`、`courseProgress` | 已实现;真实计时与媒体回调待接入 |
+| 课后考核 | `course-detail.vue` | 课程考核配置/答题记录 | Mock 交互已实现;题库接口待接入 |
+| 学习培训学院范围 | `learning/index.vue` | `course.scope.type/collegeIds` | 已实现 |
+| 在线考试四条示例、基础信息 | `pages/exam/index.vue`、`ExamCard.vue` | `exams` | 已实现 |
+| 正式/模拟/补考答题 | `pages/exam/*`、`examFlow.mjs` | `examRuns`、`scoreHistory` | Mock 已实现;服务端题库/计时/判分待接入 |
+| 补考资格 | `examFlow.mjs`、`todos.mjs` | 已发布安排、最终名单、次数 | 已实现;名单由后端确定 |
+| 双 PDF 承诺书 | `pledge.vue`、`PdfConfirmation.vue` | per exam + mode 的 `examRuns` | 状态机已实现;正式 PDF URL/业务域名待接入 |
+| 考试结果及错题统计 | `result.vue` | 独立 `scoreHistory` | 基础结果已实现;详细错题接口待接入 |
+| 已签发证书、直接预览 | `certificates/*`、`exam/result.vue` | `certificates` + 当前结果 | 已实现;签发记录只能由后端提供 |
+| 线下培训 | `pages/training/index.vue` | `trainings` | 签到/历史 Mock 已实现;扫码/定位接口待接入 |
+| 刷题练习 | `pages/practice/index.vue` | 本地练习状态 | 仅迁移已确认的基础自主练习,不计入正式业务 |
+| 我的成绩 | `pages/scores/index.vue` | `scoreHistory` | 已实现,正式/补考独立 |
+
+## 未迁移为真实生产能力的项目
+
+1. 身份登录、权限令牌和服务端角色控制。
+2. 真实视频播放器进度、课件防刷与服务器学习时长判定。
+3. 真实试卷下发、服务端倒计时、判卷、错题解析和并发提交防护。
+4. 后台补考安排管理、人员导入、名单自动筛选;移动端仅消费其最终状态。
+5. 真实证书签发、下载授权、电子签章、PDF 承诺书模板管理。
+6. 线下培训扫码、定位、照片/签名等平台能力。

Разлика између датотеке није приказан због своје велике величине
+ 18446 - 0
mobile-uniapp/package-lock.json


+ 42 - 0
mobile-uniapp/package.json

@@ -0,0 +1,42 @@
+{
+  "name": "lab-safety-mobile-v1.2",
+  "version": "1.0.0",
+  "private": true,
+  "description": "实验室安全教育考试系统 Mobile V1.2(uni-app Vue 2)",
+  "scripts": {
+    "dev:h5": "cross-env NODE_ENV=development UNI_PLATFORM=h5 UNI_CLI_CONTEXT=. UNI_INPUT_DIR=src vue-cli-service uni-serve",
+    "build:h5": "cross-env NODE_ENV=production UNI_PLATFORM=h5 UNI_CLI_CONTEXT=. UNI_INPUT_DIR=src vue-cli-service uni-build",
+    "dev:mp-weixin": "cross-env NODE_OPTIONS=--require=./scripts/node25-compat.cjs NODE_ENV=development UNI_PLATFORM=mp-weixin UNI_CLI_CONTEXT=. UNI_INPUT_DIR=src vue-cli-service uni-serve",
+    "build:mp-weixin": "cross-env NODE_OPTIONS=--require=./scripts/node25-compat.cjs NODE_ENV=production UNI_PLATFORM=mp-weixin UNI_CLI_CONTEXT=. UNI_INPUT_DIR=src vue-cli-service uni-build",
+    "patch:uni": "node scripts/patch-uni-template-loader.cjs",
+    "postinstall": "npm run patch:uni",
+    "test": "node --test tests/**/*.test.mjs",
+    "check": "node --check src/services/mock/seed.mjs && node --check src/services/mock/storage.mjs && node --check src/services/business/examFlow.mjs && node --check src/services/business/todos.mjs"
+  },
+  "dependencies": {
+    "@dcloudio/uni-app": "2.0.2-5020620260917001",
+    "@dcloudio/uni-cli-i18n": "2.0.2-5020620260917001",
+    "@dcloudio/uni-cli-shared": "2.0.2-5020620260917001",
+    "@dcloudio/uni-h5": "2.0.2-5020620260917001",
+    "@dcloudio/uni-i18n": "2.0.2-5020620260917001",
+    "@dcloudio/uni-mp-weixin": "2.0.2-5020620260917001",
+    "@dcloudio/uni-migration": "2.0.2-5020620260917001",
+    "@dcloudio/uni-template-compiler": "2.0.2-5020620260917001",
+    "@dcloudio/uni-stat": "2.0.2-5020620260917001",
+    "@dcloudio/webpack-uni-pages-loader": "2.0.2-5020620260917001",
+    "vue": "2.6.14",
+    "vuex": "3.6.2"
+  },
+  "devDependencies": {
+    "@dcloudio/vue-cli-plugin-uni": "2.0.2-5020620260917001",
+    "@vue/cli-plugin-babel": "4.5.19",
+    "@vue/cli-service": "4.5.19",
+    "copy-webpack-plugin": "5.1.2",
+    "cross-env": "7.0.3",
+    "postcss": "7.0.39",
+    "sass": "1.106.1",
+    "@dcloudio/webpack-uni-mp-loader": "2.0.2-5020620260917001",
+    "vue-template-compiler": "2.6.14",
+    "webpack": "4.46.0"
+  }
+}

+ 5 - 0
mobile-uniapp/postcss.config.js

@@ -0,0 +1,5 @@
+module.exports = {
+  plugins: [
+    require('@dcloudio/vue-cli-plugin-uni/packages/postcss')
+  ]
+}

+ 13 - 0
mobile-uniapp/public/index.html

@@ -0,0 +1,13 @@
+<!DOCTYPE html>
+<html lang="zh-CN">
+  <head>
+    <meta charset="utf-8" />
+    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
+    <meta name="format-detection" content="telephone=no" />
+    <title>实验室安全教育考试系统</title>
+  </head>
+  <body>
+    <noscript>请启用 JavaScript 后继续使用实验室安全教育考试系统。</noscript>
+    <div id="app"></div>
+  </body>
+</html>

+ 7 - 0
mobile-uniapp/scripts/node25-compat.cjs

@@ -0,0 +1,7 @@
+/* Node 25 removed legacy util predicates still referenced by uni-app Vue 2's transitive postcss-urlrewrite. */
+const util = require('util')
+
+if (typeof util.isArray !== 'function') util.isArray = Array.isArray
+if (typeof util.isRegExp !== 'function') {
+  util.isRegExp = (value) => Object.prototype.toString.call(value) === '[object RegExp]'
+}

+ 30 - 0
mobile-uniapp/scripts/patch-uni-template-loader.cjs

@@ -0,0 +1,30 @@
+/*
+ * uni-app 2.0.2 (Vue 2) 的 templateLoader 在当前发行包中无条件导出
+ * recyclableRender,但 H5/小程序编译结果没有声明它,Webpack 因而失败。
+ * 这是一个可重复、仅限依赖安装后的兼容补丁;若未来上游修复则自动跳过。
+ */
+const fs = require('fs')
+const path = require('path')
+
+const target = path.resolve(__dirname, '../node_modules/@dcloudio/vue-cli-plugin-uni/packages/vue-loader/lib/loaders/templateLoader.js')
+if (!fs.existsSync(target)) {
+  console.log('[patch:uni] template loader is not installed; skipped.')
+  process.exit(0)
+}
+
+const source = fs.readFileSync(target, 'utf8')
+const before = 'return code + `\\nexport { render, staticRenderFns, recyclableRender, components }`'
+const after = 'return code + `\\nvar recyclableRender;\\nvar components;\\nexport { render, staticRenderFns, recyclableRender, components }`'
+const previousPatch = 'return code + `\\nvar recyclableRender;\\nexport { render, staticRenderFns, recyclableRender, components }`'
+
+if (source.includes(after)) {
+  console.log('[patch:uni] template loader already patched.')
+} else if (source.includes(previousPatch)) {
+  fs.writeFileSync(target, source.replace(previousPatch, after), 'utf8')
+  console.log('[patch:uni] completed components compatibility patch.')
+} else if (source.includes(before)) {
+  fs.writeFileSync(target, source.replace(before, after), 'utf8')
+  console.log('[patch:uni] applied recyclableRender compatibility patch.')
+} else {
+  console.warn('[patch:uni] target signature changed; no patch applied.')
+}

+ 20 - 0
mobile-uniapp/src/App.vue

@@ -0,0 +1,20 @@
+<script>
+export default {
+  onLaunch() {
+    // 状态由 services/mock/storage.mjs 统一初始化;后续接入 API 时替换 service 实现即可。
+  }
+}
+</script>
+
+<style lang="scss">
+@import './styles/tokens.scss';
+
+page {
+  background: $page-bg;
+  color: $text-main;
+  font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Microsoft YaHei', sans-serif;
+  font-size: 28rpx;
+}
+
+button::after { border: 0; }
+</style>

+ 33 - 0
mobile-uniapp/src/components/CourseCard.vue

@@ -0,0 +1,33 @@
+<template>
+  <view class="course-card" @click="$emit('open', course)">
+    <view class="row between">
+      <text class="course-title">{{ course.name }}</text>
+      <text class="list-arrow">›</text>
+    </view>
+    <view class="meta-row">
+      <status-tag v-if="relationLabel" :value="relationLabel" :tone="relationTone" />
+      <text class="muted small">{{ course.creditHours }} 学时 · {{ course.points }} 积分</text>
+    </view>
+    <view class="row between progress-row">
+      <text class="small" :class="completed ? 'done' : 'muted'">{{ completed ? '已完成' : '待学习' }}</text>
+      <button class="plain-btn mini" @click.stop="$emit('open', course)">{{ completed ? '重新学习' : '开始学习' }}</button>
+    </view>
+  </view>
+</template>
+
+<script>
+import StatusTag from './StatusTag.vue'
+export default {
+  components: { StatusTag },
+  props: { course: Object, completed: Boolean, relationLabel: String, relationTone: { type: String, default: 'blue' } }
+}
+</script>
+
+<style lang="scss" scoped>
+@import '../styles/tokens.scss';
+.course-card { background: #fff; border-radius: $radius; padding: 24rpx; margin-bottom: 18rpx; }
+.course-title { font-size: 29rpx; font-weight: 600; max-width: 570rpx; }
+.meta-row { display: flex; flex-wrap: wrap; gap: 12rpx; align-items: center; margin-top: 14rpx; }
+.progress-row { margin-top: 20rpx; }
+.done { color: $success; }.mini { padding: 13rpx 18rpx; font-size: 23rpx; margin: 0; }
+</style>

+ 57 - 0
mobile-uniapp/src/components/ExamCard.vue

@@ -0,0 +1,57 @@
+<template>
+  <view class="exam-card">
+    <view class="row between">
+      <status-tag :value="exam.type" tone="blue" />
+      <status-tag v-if="exam.formalExamResult === '未通过'" value="未通过" tone="red" />
+      <status-tag v-else :value="exam.examStatus" tone="orange" />
+    </view>
+    <text class="exam-name">{{ exam.name }}</text>
+    <text class="exam-date">考试时间:{{ exam.startDate }} 至 {{ exam.endDate }}</text>
+    <view class="base-grid">
+      <view><text class="muted small">考试时长</text><text class="base-value">{{ exam.durationMinutes }} 分钟</text></view>
+      <view><text class="muted small">及格分</text><text class="base-value">{{ exam.passScore }} 分</text></view>
+      <view><text class="muted small">可考试次数</text><text class="base-value">{{ exam.maxAttempts }} 次</text></view>
+    </view>
+    <view v-if="exam.creditHoursRequired || exam.learningTargetType || exam.mockExamEnabled" class="prerequisite">
+      <view v-if="exam.creditHoursRequired" class="prerequisite-row"><text>学时要求</text><text :class="hoursMet ? 'success' : 'warn'">{{ exam.earnedCreditHours }} / {{ exam.requiredCreditHours }} 学时</text></view>
+      <view v-if="exam.learningTargetType" class="prerequisite-row"><text>{{ exam.learningTargetType === 'materials' ? '学习资料' : '考前课程' }}</text><button v-if="!learningCompleted" class="primary-btn mini" @click="$emit('learn', exam)">去学习</button><status-tag v-else value="已完成" tone="green" /></view>
+      <view v-if="exam.mockExamEnabled" class="prerequisite-row"><text>模拟考试</text><button v-if="!exam.mockExamCompleted" class="primary-btn mini" @click="$emit('mock', exam)">去考试</button><status-tag v-else value="已完成" tone="green" /></view>
+    </view>
+    <view v-if="exam.makeupArrangementId" class="action-area">
+      <button class="primary-btn action-btn" :class="{ 'disabled-btn': !makeupGate.allowed }" @click="$emit('makeup', { exam, gate: makeupGate })">去补考</button>
+      <text v-if="!makeupGate.allowed" class="reason">{{ makeupGate.reason }}</text>
+    </view>
+    <view v-else class="action-area">
+      <button class="primary-btn action-btn" :class="{ 'disabled-btn': !formalGate.allowed }" @click="$emit('formal', { exam, gate: formalGate })">{{ exam.learningTargetType ? '去考试' : '开始考试' }}</button>
+      <text v-if="!formalGate.allowed" class="reason">{{ formalGate.reason }}</text>
+    </view>
+  </view>
+</template>
+
+<script>
+import StatusTag from './StatusTag.vue'
+import { formalGate, makeupGate } from '../services/business/examFlow.mjs'
+import { courseIsCompleted } from '../services/business/todos.mjs'
+export default {
+  components: { StatusTag },
+  props: { exam: Object, state: Object },
+  computed: {
+    formalGate() { return formalGate(this.state, this.exam.id) },
+    makeupGate() { return makeupGate(this.state, this.exam.id, this.state.currentUser.id) },
+    hoursMet() { return Number(this.exam.earnedCreditHours || 0) >= Number(this.exam.requiredCreditHours || 0) },
+    learningCompleted() {
+      if (!this.exam.learningTargetType) return true
+      if (this.exam.learningTargetType === 'materials') return this.state.materials.every((item) => item.completed)
+      return courseIsCompleted(this.state, this.exam.learningTargetId)
+    }
+  }
+}
+</script>
+
+<style lang="scss" scoped>
+@import '../styles/tokens.scss';
+.exam-card { background: #fff; border-radius: $radius; padding: 24rpx; margin-bottom: 20rpx; }
+.exam-name { display: block; margin: 18rpx 0 12rpx; font-weight: 600; font-size: 31rpx; }.exam-date { display: block; color: $text-secondary; font-size: 24rpx; }
+.base-grid { display: flex; margin-top: 20rpx; background: #f8fafc; border-radius: 10rpx; padding: 18rpx 0; }.base-grid view { width: 33.333%; padding: 0 15rpx; box-sizing: border-box; border-right: 1px solid $line; }.base-grid view:last-child { border-right: 0; }.base-grid text { display: block; white-space: nowrap; }.base-value { margin-top: 8rpx; font-size: 25rpx; font-weight: 600; }
+.prerequisite { border-top: 1px solid $line; margin-top: 18rpx; }.prerequisite-row { min-height: 62rpx; display: flex; justify-content: space-between; align-items: center; font-size: 25rpx; }.success { color: $success; }.warn { color: $warning; }.mini { padding: 11rpx 18rpx; margin: 0; font-size: 23rpx; }.action-area { padding-top: 16rpx; }.action-btn { width: 100%; }.reason { display: block; color: $danger; font-size: 22rpx; margin-top: 8rpx; text-align: center; }
+</style>

+ 20 - 0
mobile-uniapp/src/components/HomeEntry.vue

@@ -0,0 +1,20 @@
+<template>
+  <view class="entry" @click="$emit('click')">
+    <view class="entry-icon" :class="colorClass"><text>{{ icon }}</text></view>
+    <text v-if="badge" class="entry-badge">{{ badge }}</text>
+    <text class="entry-name">{{ name }}</text>
+  </view>
+</template>
+
+<script>
+export default { props: { name: String, icon: String, badge: String, colorClass: String } }
+</script>
+
+<style lang="scss" scoped>
+@import '../styles/tokens.scss';
+.entry { width: 33.333%; position: relative; display: flex; flex-direction: column; align-items: center; padding: 22rpx 0; box-sizing: border-box; }
+.entry-icon { width: 84rpx; height: 84rpx; border-radius: 24rpx; display: flex; align-items: center; justify-content: center; font-size: 42rpx; color: #fff; }
+.blue { background: #1677ff; }.green { background: #22a06b; }.orange { background: #f59e0b; }.purple { background: #8b5cf6; }.red { background: #ef4444; }.teal { background: #0f9e9a; }
+.entry-name { margin-top: 12rpx; font-size: 25rpx; color: $text-main; }
+.entry-badge { position: absolute; top: 10rpx; margin-left: 74rpx; min-width: 32rpx; padding: 2rpx 8rpx; box-sizing: border-box; border-radius: 18rpx; color: #fff; background: $danger; text-align: center; font-size: 20rpx; line-height: 28rpx; border: 2rpx solid #fff; }
+</style>

+ 40 - 0
mobile-uniapp/src/components/PageHeader.vue

@@ -0,0 +1,40 @@
+<template>
+  <view class="page-header" :style="{ paddingTop: statusHeight + 'px' }">
+    <view class="header-row">
+      <view class="header-side" @click="goBack">
+        <text v-if="back" class="back-text">‹ 返回</text>
+      </view>
+      <text class="header-title">{{ title }}</text>
+      <view class="header-side header-right"><slot name="right" /></view>
+    </view>
+  </view>
+</template>
+
+<script>
+export default {
+  props: { title: { type: String, required: true }, back: { type: Boolean, default: true } },
+  data() { return { statusHeight: 0 } },
+  created() {
+    const system = uni.getSystemInfoSync()
+    this.statusHeight = system.statusBarHeight || 0
+  },
+  methods: {
+    goBack() {
+      if (!this.back) return
+      const pages = getCurrentPages()
+      if (pages.length > 1) uni.navigateBack()
+      else uni.reLaunch({ url: '/pages/home/index' })
+    }
+  }
+}
+</script>
+
+<style lang="scss" scoped>
+@import '../styles/tokens.scss';
+.page-header { background: #fff; border-bottom: 1px solid $line; position: sticky; top: 0; z-index: 20; }
+.header-row { height: 88rpx; display: flex; align-items: center; justify-content: space-between; padding: 0 24rpx; position: relative; }
+.header-title { font-size: 32rpx; font-weight: 600; max-width: 430rpx; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
+.header-side { width: 150rpx; min-height: 48rpx; display: flex; align-items: center; color: $primary; font-size: 27rpx; }
+.header-right { justify-content: flex-end; color: $text-secondary; }
+.back-text { white-space: nowrap; }
+</style>

+ 43 - 0
mobile-uniapp/src/components/PdfConfirmation.vue

@@ -0,0 +1,43 @@
+<template>
+  <view class="pdf-confirmation">
+    <!-- #ifdef H5 -->
+    <web-view class="pdf-viewer" :src="pdfUrl" @load="loaded = true" @error="onError" />
+    <!-- #endif -->
+    <!-- #ifdef MP-WEIXIN -->
+    <view class="mini-program-pdf">
+      <text class="pdf-title">{{ title }}</text>
+      <text class="muted small">请使用“打开 PDF”完成文档预览。生产环境需配置微信业务域名与 HTTPS 文档地址。</text>
+      <button class="plain-btn" @click="openMiniProgramPdf">打开 PDF</button>
+      <text v-if="loadError" class="error">{{ loadError }}</text>
+    </view>
+    <!-- #endif -->
+    <view class="pdf-status" :class="{ error: loadError }">{{ loadError || (loaded ? 'PDF 已加载,请阅读后确认。' : '正在加载 PDF 文档…') }}</view>
+    <button class="primary-btn confirm" :class="{ 'disabled-btn': !loaded }" :disabled="!loaded" @click="$emit('confirm')">我已阅读并同意</button>
+  </view>
+</template>
+
+<script>
+export default {
+  props: { title: String, pdfUrl: String },
+  data() { return { loaded: false, loadError: '' } },
+  methods: {
+    onError() { this.loadError = 'PDF 加载失败,暂不能确认。请返回后稍后重试。' },
+    openMiniProgramPdf() {
+      if (!this.pdfUrl || this.pdfUrl.indexOf('https://') !== 0) {
+        this.loadError = '当前 PDF 地址未配置为可下载的 HTTPS 文档,暂不能确认。'
+        return
+      }
+      uni.downloadFile({
+        url: this.pdfUrl,
+        success: ({ tempFilePath }) => uni.openDocument({ filePath: tempFilePath, showMenu: true, success: () => { this.loaded = true }, fail: () => this.onError() }),
+        fail: () => this.onError()
+      })
+    }
+  }
+}
+</script>
+
+<style lang="scss" scoped>
+@import '../styles/tokens.scss';
+.pdf-viewer { height: 850rpx; border: 1px solid $line; border-radius: 12rpx; overflow: hidden; }.mini-program-pdf { min-height: 540rpx; display: flex; flex-direction: column; gap: 24rpx; padding: 32rpx; background: #f8fafc; border-radius: 12rpx; }.pdf-title { font-weight: 600; font-size: 30rpx; }.pdf-status { padding: 18rpx 0; font-size: 24rpx; color: $text-secondary; }.error { color: $danger; }.confirm { width: 100%; }
+</style>

+ 8 - 0
mobile-uniapp/src/components/StatusTag.vue

@@ -0,0 +1,8 @@
+<template><text class="tag" :class="tagClass">{{ value }}</text></template>
+
+<script>
+export default {
+  props: { value: { type: String, default: '' }, tone: { type: String, default: 'gray' } },
+  computed: { tagClass() { return `tag-${this.tone}` } }
+}
+</script>

+ 7 - 0
mobile-uniapp/src/components/TaskCard.vue

@@ -0,0 +1,7 @@
+<template>
+  <view class="task-card" @click="$emit('click')"><slot /><text class="list-arrow">›</text></view>
+</template>
+<style lang="scss" scoped>
+@import '../styles/tokens.scss';
+.task-card { background: #fff; border-radius: $radius; padding: 24rpx; margin-bottom: 18rpx; display: flex; align-items: center; justify-content: space-between; }
+</style>

+ 4 - 0
mobile-uniapp/src/config/runtime.js

@@ -0,0 +1,4 @@
+// 正式后端接入点:将此标志设为 false,并在 mobileApi.js 中保留同名请求实现。
+// 当前交付为可运行 Mock;Mock 数据不是后端业务数据。
+export const USE_MOCK = true
+export const API_BASE_URL = ''

+ 11 - 0
mobile-uniapp/src/main.js

@@ -0,0 +1,11 @@
+import Vue from 'vue'
+import App from './App'
+import './styles/app.scss'
+
+Vue.config.productionTip = false
+App.mpType = 'app'
+
+const app = new Vue({
+  ...App
+})
+app.$mount()

+ 21 - 0
mobile-uniapp/src/manifest.json

@@ -0,0 +1,21 @@
+{
+  "name": "实验室安全教育考试系统",
+  "appid": "__UNI__LABSAFETYV12",
+  "description": "Mobile V1.2 uni-app 正式工程",
+  "versionName": "1.0.0",
+  "versionCode": "100",
+  "transformPx": false,
+  "mp-weixin": {
+    "appid": "",
+    "setting": {
+      "urlCheck": false,
+      "es6": true,
+      "minified": true
+    },
+    "usingComponents": true
+  },
+  "h5": {
+    "title": "实验室安全教育考试系统",
+    "router": { "mode": "hash" }
+  }
+}

+ 26 - 0
mobile-uniapp/src/pages.json

@@ -0,0 +1,26 @@
+{
+  "pages": [
+    { "path": "pages/home/index", "style": { "navigationStyle": "custom" } },
+    { "path": "pages/learning/index", "style": { "navigationStyle": "custom" } },
+    { "path": "pages/learning/course-detail", "style": { "navigationStyle": "custom" } },
+    { "path": "pages/learning/courseware", "style": { "navigationStyle": "custom" } },
+    { "path": "pages/learning/material-detail", "style": { "navigationStyle": "custom" } },
+    { "path": "pages/exam/index", "style": { "navigationStyle": "custom" } },
+    { "path": "pages/exam/pledge", "style": { "navigationStyle": "custom" } },
+    { "path": "pages/exam/answer", "style": { "navigationStyle": "custom" } },
+    { "path": "pages/exam/result", "style": { "navigationStyle": "custom" } },
+    { "path": "pages/training/index", "style": { "navigationStyle": "custom" } },
+    { "path": "pages/practice/index", "style": { "navigationStyle": "custom" } },
+    { "path": "pages/scores/index", "style": { "navigationStyle": "custom" } },
+    { "path": "pages/certificates/index", "style": { "navigationStyle": "custom" } },
+    { "path": "pages/certificates/preview", "style": { "navigationStyle": "custom" } },
+    { "path": "pages/profile/index", "style": { "navigationStyle": "custom" } },
+    { "path": "pages/notices/index", "style": { "navigationStyle": "custom" } }
+  ],
+  "globalStyle": {
+    "navigationBarTextStyle": "black",
+    "navigationBarTitleText": "安全教育考试系统",
+    "navigationBarBackgroundColor": "#ffffff",
+    "backgroundColor": "#f5f7fa"
+  }
+}

Разлика између датотеке није приказан због своје велике величине
+ 6 - 0
mobile-uniapp/src/pages/certificates/index.vue


Разлика између датотеке није приказан због своје велике величине
+ 12 - 0
mobile-uniapp/src/pages/certificates/preview.vue


Разлика између датотеке није приказан због своје велике величине
+ 6 - 0
mobile-uniapp/src/pages/exam/answer.vue


Разлика између датотеке није приказан због своје велике величине
+ 6 - 0
mobile-uniapp/src/pages/exam/index.vue


Разлика између датотеке није приказан због своје велике величине
+ 6 - 0
mobile-uniapp/src/pages/exam/pledge.vue


Разлика између датотеке није приказан због своје велике величине
+ 6 - 0
mobile-uniapp/src/pages/exam/result.vue


Разлика између датотеке није приказан због своје велике величине
+ 63 - 0
mobile-uniapp/src/pages/home/index.vue


Разлика између датотеке није приказан због своје велике величине
+ 23 - 0
mobile-uniapp/src/pages/learning/course-detail.vue


Разлика између датотеке није приказан због своје велике величине
+ 7 - 0
mobile-uniapp/src/pages/learning/courseware.vue


Разлика између датотеке није приказан због своје велике величине
+ 75 - 0
mobile-uniapp/src/pages/learning/index.vue


Разлика између датотеке није приказан због своје велике величине
+ 6 - 0
mobile-uniapp/src/pages/learning/material-detail.vue


+ 7 - 0
mobile-uniapp/src/pages/notices/index.vue

@@ -0,0 +1,7 @@
+<template><view class="page"><page-header title="通知公告" /><view class="page-content"><view v-for="item in notices" :key="item.id" class="card"><text class="notice-title">{{ item.title }}</text><text class="muted small">{{ item.date }}</text></view></view></view></template>
+<script>
+import PageHeader from '../../components/PageHeader.vue'
+import { mobileApi } from '../../services/api/mobileApi'
+export default { components: { PageHeader }, data() { return { notices: [] } }, async onShow() { this.notices = (await mobileApi.getDashboard()).notices } }
+</script>
+<style scoped>.notice-title { display: block; margin-bottom: 12rpx; font-size: 29rpx; }</style>

Разлика између датотеке није приказан због своје велике величине
+ 3 - 0
mobile-uniapp/src/pages/practice/index.vue


Разлика између датотеке није приказан због своје велике величине
+ 7 - 0
mobile-uniapp/src/pages/profile/index.vue


Разлика између датотеке није приказан због своје велике величине
+ 6 - 0
mobile-uniapp/src/pages/scores/index.vue


Разлика између датотеке није приказан због своје велике величине
+ 6 - 0
mobile-uniapp/src/pages/training/index.vue


+ 118 - 0
mobile-uniapp/src/services/api/mobileApi.js

@@ -0,0 +1,118 @@
+import { USE_MOCK } from '../../config/runtime'
+import { loadState, saveState, resetState } from '../mock/storage.mjs'
+import { courseIsCompleted } from '../business/todos.mjs'
+import {
+  beginRun,
+  confirmPledge,
+  getExamById,
+  getIssuedCertificateForResult,
+  getRun,
+  getVisibleResult,
+  submitRun
+} from '../business/examFlow.mjs'
+
+function mutate(mutator) {
+  const state = loadState()
+  const value = mutator(state)
+  saveState(state)
+  return value
+}
+
+function mockOnly(method) {
+  if (!USE_MOCK) throw new Error(`${method} 尚未配置正式 API;请实现 mobileApi.js 的远程请求分支。`)
+}
+
+export const mobileApi = {
+  async getState() { mockOnly('getState'); return loadState() },
+  async resetMock() { mockOnly('resetMock'); return resetState() },
+
+  async getDashboard() {
+    mockOnly('getDashboard')
+    return loadState()
+  },
+
+  async getLearningContext() {
+    mockOnly('getLearningContext')
+    return loadState()
+  },
+
+  async completeLesson(courseId, lessonId) {
+    mockOnly('completeLesson')
+    return mutate((state) => {
+      const course = state.courses.find((item) => item.id === courseId)
+      if (!course || !course.lessons.some((item) => item.id === lessonId)) throw new Error('课件不存在')
+      state.courseProgress[courseId] = state.courseProgress[courseId] || {}
+      state.courseProgress[courseId][lessonId] = { completed: true, learnedMinutes: course.lessons.find((item) => item.id === lessonId).requiredMinutes }
+      if (courseIsCompleted(state, courseId)) {
+        state.preExamAssignments.forEach((assignment) => {
+          if (assignment.courseId === courseId && assignment.learnerId === state.currentUser.id) assignment.status = 'completed'
+        })
+        state.violationTasks.forEach((task) => {
+          if (task.courseId === courseId && task.learnerId === state.currentUser.id) task.status = 'completed'
+        })
+      }
+      return state
+    })
+  },
+
+  async completeMaterial(materialId) {
+    mockOnly('completeMaterial')
+    return mutate((state) => {
+      const material = state.materials.find((item) => item.id === materialId)
+      if (!material) throw new Error('学习资料不存在')
+      material.completed = true
+      state.materialProgress[materialId] = { completed: true }
+      return state
+    })
+  },
+
+  async signTraining(trainingId) {
+    mockOnly('signTraining')
+    return mutate((state) => {
+      const task = state.trainings.find((item) => item.id === trainingId && item.learnerId === state.currentUser.id)
+      if (!task) throw new Error('培训任务不存在')
+      task.completed = true
+      task.status = 'completed'
+      task.signedAt = '2026-10-28 10:00:00'
+      return state
+    })
+  },
+
+  async beginExam(examId, mode) {
+    mockOnly('beginExam')
+    return mutate((state) => beginRun(state, examId, mode, state.currentUser.id))
+  },
+
+  async confirmExamPledge(examId, mode, stage) {
+    mockOnly('confirmExamPledge')
+    return mutate((state) => confirmPledge(state, examId, mode, stage))
+  },
+
+  async submitExam(examId, mode, answers) {
+    mockOnly('submitExam')
+    return mutate((state) => submitRun(state, examId, mode, answers))
+  },
+
+  async getExamRun(examId, mode) {
+    mockOnly('getExamRun')
+    const state = loadState()
+    return { state, exam: getExamById(state, examId), run: getRun(state, examId, mode) }
+  },
+
+  async getExamResult(examId, mode) {
+    mockOnly('getExamResult')
+    const state = loadState()
+    return {
+      state,
+      exam: getExamById(state, examId),
+      result: getVisibleResult(state, examId, mode),
+      certificate: getIssuedCertificateForResult(state, examId, mode)
+    }
+  },
+
+  async getCertificate(certificateId) {
+    mockOnly('getCertificate')
+    const state = loadState()
+    return state.certificates.find((item) => item.id === certificateId && item.learnerId === state.currentUser.id && item.issued) || null
+  }
+}

+ 110 - 0
mobile-uniapp/src/services/business/examFlow.mjs

@@ -0,0 +1,110 @@
+import { courseIsCompleted, isExamOpen, isMakeupEligible } from './todos.mjs'
+
+export function runKey(examId, mode) {
+  return `${mode}:${examId}`
+}
+
+export function getRun(state, examId, mode) {
+  return state.examRuns[runKey(examId, mode)] || null
+}
+
+export function getExamById(state, examId) {
+  return state.exams.find((item) => item.id === examId)
+}
+
+export function formalGate(state, examId) {
+  const exam = getExamById(state, examId)
+  if (!exam || !isExamOpen(exam)) return { allowed: false, reason: '当前不在考试开放期' }
+  if (Number(exam.attemptsUsed || 0) >= Number(exam.maxAttempts || 0)) return { allowed: false, reason: '正式考试次数已用完' }
+  if (exam.creditHoursRequired && Number(exam.earnedCreditHours || 0) < Number(exam.requiredCreditHours || 0)) return { allowed: false, reason: '尚未满足学时要求' }
+  if (exam.learningTargetType === 'courseware' && !courseIsCompleted(state, exam.learningTargetId)) return { allowed: false, reason: '请先完成考前课程' }
+  return { allowed: true, reason: '' }
+}
+
+export function makeupGate(state, examId, learnerId) {
+  const exam = getExamById(state, examId)
+  if (!isMakeupEligible(state, exam, learnerId)) return { allowed: false, reason: '当前不符合补考参加条件' }
+  return { allowed: true, reason: '' }
+}
+
+export function beginRun(state, examId, mode, learnerId) {
+  if (mode === 'mock') {
+    const exam = getExamById(state, examId)
+    if (!exam || !exam.mockExamEnabled || !exam.mockExamId) return { next: 'blocked', reason: '当前考试未配置模拟考试' }
+    const mockExisting = getRun(state, examId, mode)
+    if (mockExisting && mockExisting.submitted) return { next: 'result' }
+    state.examRuns[runKey(examId, mode)] = {
+      examId, mode, learnerId, prePledgeConfirmed: true, submitted: false, postPledgeConfirmed: true, answers: {}
+    }
+    return { next: 'answer' }
+  }
+  const gate = mode === 'makeup' ? makeupGate(state, examId, learnerId) : formalGate(state, examId)
+  if (!gate.allowed) return { next: 'blocked', reason: gate.reason }
+  const existing = getRun(state, examId, mode)
+  if (existing && existing.submitted && !existing.postPledgeConfirmed) return { next: 'post-pledge' }
+  if (existing && existing.submitted && existing.postPledgeConfirmed) return { next: 'result' }
+  if (existing && existing.prePledgeConfirmed) return { next: 'answer' }
+  state.examRuns[runKey(examId, mode)] = {
+    examId, mode, learnerId, prePledgeConfirmed: false, submitted: false, postPledgeConfirmed: false, answers: {}
+  }
+  return { next: 'pre-pledge' }
+}
+
+export function confirmPledge(state, examId, mode, stage) {
+  const run = getRun(state, examId, mode)
+  if (!run) return { next: 'blocked', reason: '未找到本次考试状态' }
+  if (stage === 'pre') {
+    run.prePledgeConfirmed = true
+    return { next: 'answer' }
+  }
+  if (!run.submitted) return { next: 'blocked', reason: '试卷尚未交卷' }
+  run.postPledgeConfirmed = true
+  const score = state.scoreHistory.find((item) => item.id === run.resultId)
+  if (score) score.postPledgeConfirmed = true
+  return { next: 'result' }
+}
+
+export function submitRun(state, examId, mode, answers) {
+  const exam = getExamById(state, examId)
+  const run = getRun(state, examId, mode)
+  if (!exam || !run || !run.prePledgeConfirmed || run.submitted) return { ok: false, reason: '当前试卷不可重复提交' }
+  const correct = Object.values(answers || {}).filter((value) => value === 'A').length
+  const total = 3
+  const score = mode === 'makeup' ? 82 : Math.max(0, Math.round((correct / total) * 100))
+  const passed = score >= exam.passScore
+  const record = {
+    id: `${mode}-${examId}-${Date.now()}`,
+    examId,
+    mode,
+    score,
+    correct: Math.round(score / 10),
+    wrong: Math.max(0, 10 - Math.round(score / 10)),
+    accuracy: `${score}%`,
+    passed,
+    submitted: true,
+    postPledgeConfirmed: false
+  }
+  // 证书只读取既有签发记录;交卷通过不会创建证书。
+  const certificate = mode === 'mock' ? null : state.certificates.find((item) => item.examId === examId && item.learnerId === run.learnerId && item.issued)
+  if (passed && certificate) record.certificateId = certificate.id
+  state.scoreHistory.unshift(record)
+  run.answers = answers || {}
+  run.submitted = true
+  run.resultId = record.id
+  if (mode === 'makeup') exam.makeupUsedAttempts = Number(exam.makeupUsedAttempts || 0) + 1
+  else if (mode === 'formal') exam.attemptsUsed = Number(exam.attemptsUsed || 0) + 1
+  else exam.mockExamCompleted = passed
+  return { ok: true, next: mode === 'mock' ? 'result' : 'post-pledge', record }
+}
+
+export function getVisibleResult(state, examId, mode) {
+  const run = getRun(state, examId, mode)
+  if (!run || !run.submitted || !run.postPledgeConfirmed) return null
+  return state.scoreHistory.find((item) => item.id === run.resultId) || null
+}
+
+export function getIssuedCertificateForResult(state, examId, mode) {
+  const result = getVisibleResult(state, examId, mode)
+  if (!result || !result.passed || !result.certificateId) return null
+  return state.certificates.find((item) => item.id === result.certificateId && item.issued) || null
+}

+ 47 - 0
mobile-uniapp/src/services/business/todos.mjs

@@ -0,0 +1,47 @@
+export function courseIsCompleted(state, courseId) {
+  const course = state.courses.find((item) => item.id === courseId)
+  if (!course) return false
+  const progress = state.courseProgress[courseId] || {}
+  return course.lessons.every((lesson) => progress[lesson.id] && progress[lesson.id].completed)
+}
+
+export function isExamOpen(exam) {
+  // Mock 以 prototypeOpen 明确表达后台返回的“当前开放”;真实接口应使用服务端时间判定。
+  return Boolean(exam && exam.formalExamOpen && (exam.prototypeOpen || exam.examStatus === '进行中'))
+}
+
+export function isMakeupEligible(state, exam, learnerId) {
+  return Boolean(
+    exam && exam.makeupPublished && exam.makeupArrangementValid &&
+    Array.isArray(exam.makeupCandidateIds) && exam.makeupCandidateIds.includes(learnerId) &&
+    Number(exam.makeupUsedAttempts || 0) < Number(exam.makeupMaxAttempts || 0) &&
+    (exam.prototypeOpen || isExamOpen(exam))
+  )
+}
+
+export function getPendingLearningCount(state, learnerId) {
+  const preExam = state.preExamAssignments.filter((item) => item.learnerId === learnerId && item.status !== 'completed').length
+  const violation = state.violationTasks.filter((item) => item.learnerId === learnerId && item.status !== 'completed').length
+  return preExam + violation
+}
+
+export function getPendingTrainingCount(state, learnerId) {
+  return state.trainings.filter((item) => item.learnerId === learnerId && !item.completed && item.status !== 'cancelled').length
+}
+
+export function getPendingExamCount(state, learnerId) {
+  return state.exams.filter((exam) => {
+    if (isMakeupEligible(state, exam, learnerId)) return true
+    if (!isExamOpen(exam)) return false
+    if (Number(exam.attemptsUsed || 0) >= Number(exam.maxAttempts || 0)) return false
+    if (exam.creditHoursRequired && Number(exam.earnedCreditHours || 0) < Number(exam.requiredCreditHours || 0)) return false
+    if (exam.learningTargetType === 'courseware' && !courseIsCompleted(state, exam.learningTargetId)) return false
+    const run = state.examRuns[`formal:${exam.id}`]
+    return !(run && run.submitted)
+  }).length
+}
+
+export function formatBadge(count) {
+  if (!count) return ''
+  return count > 99 ? '99+' : String(count)
+}

+ 118 - 0
mobile-uniapp/src/services/mock/seed.mjs

@@ -0,0 +1,118 @@
+export const STORAGE_KEY = 'lab-safety-mobile-v1.2-state'
+
+export const seedState = {
+  currentUser: {
+    id: '20231001',
+    name: '张同学',
+    studentNo: '20231001',
+    collegeId: 'chemistry',
+    collegeName: '化学与化工学院',
+    role: 'learner',
+    academicYear: '2026–2027 学年'
+  },
+  courses: [
+    {
+      id: 'lab-safety-basics', name: '实验室安全基础课程', creditHours: 4, points: 10,
+      assessmentEnabled: true,
+      lessons: [
+        { id: 'lab-1', title: '实验室安全通识', type: 'document', requiredMinutes: 20 },
+        { id: 'lab-2', title: '常用消防器材使用方法', type: 'video', requiredMinutes: 25 }
+      ]
+    },
+    {
+      id: 'personal-protection', name: '个人防护与风险辨识', creditHours: 4, points: 10,
+      assessmentEnabled: false,
+      lessons: [{ id: 'protection-1', title: '个人防护装备规范', type: 'video', requiredMinutes: 30 }]
+    },
+    {
+      id: 'bio-safety-operation', name: '生物安全操作规范', creditHours: 3, points: 8,
+      assessmentEnabled: true,
+      lessons: [{ id: 'bio-1', title: '生物实验室操作规范', type: 'document', requiredMinutes: 20 }]
+    },
+    {
+      id: 'training-fire', name: '消防安全专题培训', creditHours: 2, points: 5,
+      scope: { type: 'all-school', collegeIds: [] }, assessmentEnabled: false,
+      lessons: [{ id: 'fire-1', title: '初起火灾处置', type: 'video', requiredMinutes: 18 }]
+    },
+    {
+      id: 'training-chemical', name: '化学实验室危化品管理', creditHours: 2, points: 5,
+      scope: { type: 'college', collegeIds: ['chemistry'] }, assessmentEnabled: false,
+      lessons: [{ id: 'chemical-1', title: '危化品存储要求', type: 'document', requiredMinutes: 18 }]
+    },
+    {
+      id: 'training-radiation', name: '辐射安全培训', creditHours: 2, points: 5,
+      scope: { type: 'college', collegeIds: ['physics'] }, assessmentEnabled: false,
+      lessons: [{ id: 'radiation-1', title: '辐射防护基础', type: 'document', requiredMinutes: 18 }]
+    }
+  ],
+  materials: [
+    { id: 'material-video-fire', title: '实验室火灾预防', type: 'video', requiredMinutes: 5, completed: false },
+    { id: 'material-doc-chemical', title: '千万不能碰的化学品', type: 'document', requiredMinutes: 5, completed: false },
+    { id: 'material-video-waste', title: '实验室废弃物分类', type: 'video', requiredMinutes: 6, completed: true }
+  ],
+  exams: [
+    {
+      id: 'graded-entry-2026', name: '实验室安全分级考试', type: '分级考试', examStatus: '进行中',
+      startDate: '2026-09-01', endDate: '2026-09-30', durationMinutes: 75, passScore: 70, maxAttempts: 3, attemptsUsed: 0,
+      formalExamOpen: true, prototypeOpen: true, creditHoursRequired: false, requiredCreditHours: null, earnedCreditHours: null,
+      learningTargetType: 'courseware', learningTargetId: 'lab-safety-basics', lessonId: 'lab-1', learningCompleted: false,
+      mockExamEnabled: false, mockExamId: null, issuedCertificateId: null
+    },
+    {
+      id: 'should-know-monthly-2026', name: '常规考试小月考', type: '常规考试', examStatus: '进行中',
+      startDate: '2026-09-01', endDate: '2026-09-30', durationMinutes: 90, passScore: 70, maxAttempts: 3, attemptsUsed: 1,
+      formalExamOpen: true, prototypeOpen: true, creditHoursRequired: true, requiredCreditHours: 8, earnedCreditHours: 6,
+      learningTargetType: 'materials', learningTargetId: null, lessonId: null, learningCompleted: false,
+      mockExamEnabled: true, mockExamId: 'should-know-monthly-2026-mock', mockExamCompleted: false, issuedCertificateId: null
+    },
+    {
+      id: 'general-safety-2026', name: '2025–2026学年实验室安全常规考试', type: '常规考试', examStatus: '进行中',
+      startDate: '2026-09-01', endDate: '2026-09-30', durationMinutes: 60, passScore: 60, maxAttempts: 2, attemptsUsed: 0,
+      formalExamOpen: true, prototypeOpen: true, creditHoursRequired: false, requiredCreditHours: null, earnedCreditHours: null,
+      learningTargetType: null, learningTargetId: null, lessonId: null, learningCompleted: true,
+      mockExamEnabled: false, mockExamId: null, issuedCertificateId: null
+    },
+    {
+      id: 'graded-makeup-2026', name: '实验室安全分级考试(补考安排)', type: '分级考试', examStatus: '进行中',
+      startDate: '2026-09-01', endDate: '2026-09-30', durationMinutes: 80, passScore: 70, maxAttempts: 3, attemptsUsed: 1,
+      formalExamOpen: true, prototypeOpen: true, creditHoursRequired: true, requiredCreditHours: 8, earnedCreditHours: 8,
+      learningTargetType: 'courseware', learningTargetId: 'personal-protection', lessonId: 'protection-1', learningCompleted: true,
+      mockExamEnabled: true, mockExamId: 'graded-makeup-2026-mock', mockExamCompleted: true,
+      formalExamResult: '未通过',
+      makeupArrangementId: 'graded-makeup-2026-arrangement-01', makeupPublished: true, makeupArrangementValid: true,
+      makeupStartTime: '2026-10-20T00:00:00+08:00', makeupEndTime: '2026-11-05T23:59:59+08:00', prototypeOpen: true,
+      makeupCandidateIds: ['20231001', '20239999'], makeupMaxAttempts: 2, makeupUsedAttempts: 1,
+      issuedCertificateId: 'graded-makeup-2026-issued'
+    }
+  ],
+  preExamAssignments: [
+    { id: 'pre-course-graded-entry', learnerId: '20231001', examId: 'graded-entry-2026', courseId: 'lab-safety-basics', status: 'pending' },
+    { id: 'pre-course-graded-makeup', learnerId: '20231001', examId: 'graded-makeup-2026', courseId: 'personal-protection', status: 'completed' }
+  ],
+  violationTasks: [
+    { id: 'violation-learning-2026-01', learnerId: '20231001', courseId: 'bio-safety-operation', status: 'pending', label: '违规处置学习' }
+  ],
+  trainings: [
+    { id: 'offline-fire-01', learnerId: '20231001', title: '实验室消防实操培训', date: '2026-09-18 14:00', place: '东校区-实验楼-2层-201', mentor: '李老师', status: 'pending', completed: false },
+    { id: 'offline-first-aid-01', learnerId: '20231001', title: '实验室急救基础培训', date: '2026-08-20 09:30', place: '东校区-培训楼-1层-101', mentor: '王老师', status: 'completed', completed: true }
+  ],
+  certificates: [
+    { id: 'issued-legacy-lab', learnerId: '20231001', examId: 'history-exam-2025', title: '实验室安全培训合格证书', source: '实验室安全考试', expiresAt: '2027-09-30', issued: true, imageUrl: '/static/certificate-demo.svg' },
+    { id: 'graded-makeup-2026-issued', learnerId: '20231001', examId: 'graded-makeup-2026', title: '实验室安全分级考试合格证书', source: '实验室安全分级考试', expiresAt: '2027-10-31', issued: true, imageUrl: '/static/certificate-demo.svg' }
+  ],
+  notices: [
+    { id: 'notice-1', title: '2026–2027学年实验室安全教育工作通知', date: '2026-09-01' },
+    { id: 'notice-2', title: '国庆假期实验室安全提示', date: '2026-09-25' }
+  ],
+  courseProgress: {},
+  materialProgress: {},
+  examRuns: {},
+  scoreHistory: [
+    { id: 'formal-graded-makeup-2026-01', examId: 'graded-makeup-2026', mode: 'formal', score: 68, correct: 68, wrong: 32, accuracy: '68%', passed: false, submitted: true, postPledgeConfirmed: true },
+    { id: 'makeup-graded-makeup-2026-01', examId: 'graded-makeup-2026', mode: 'makeup', score: 82, correct: 82, wrong: 18, accuracy: '82%', passed: true, submitted: true, postPledgeConfirmed: true, certificateId: 'graded-makeup-2026-issued' }
+  ]
+}
+
+export function cloneSeed() {
+  return JSON.parse(JSON.stringify(seedState))
+}

+ 36 - 0
mobile-uniapp/src/services/mock/storage.mjs

@@ -0,0 +1,36 @@
+import { STORAGE_KEY, cloneSeed } from './seed.mjs'
+
+const memory = new Map()
+
+function getUni() {
+  return typeof uni !== 'undefined' ? uni : null
+}
+
+export function loadState() {
+  const uniApi = getUni()
+  let saved
+  try {
+    saved = uniApi ? uniApi.getStorageSync(STORAGE_KEY) : memory.get(STORAGE_KEY)
+  } catch (error) {
+    saved = null
+  }
+  if (!saved || typeof saved !== 'object') {
+    const initial = cloneSeed()
+    saveState(initial)
+    return initial
+  }
+  return saved
+}
+
+export function saveState(nextState) {
+  const serializable = JSON.parse(JSON.stringify(nextState))
+  const uniApi = getUni()
+  if (uniApi) uniApi.setStorageSync(STORAGE_KEY, serializable)
+  else memory.set(STORAGE_KEY, serializable)
+  return serializable
+}
+
+export function resetState() {
+  const initial = cloneSeed()
+  return saveState(initial)
+}

+ 13 - 0
mobile-uniapp/src/static/certificate-demo.svg

@@ -0,0 +1,13 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="1200" height="850" viewBox="0 0 1200 850">
+  <rect width="1200" height="850" fill="#fffdf5"/>
+  <rect x="38" y="38" width="1124" height="774" fill="none" stroke="#c99b42" stroke-width="8"/>
+  <rect x="58" y="58" width="1084" height="734" fill="none" stroke="#e7c77a" stroke-width="2"/>
+  <text x="600" y="190" text-anchor="middle" fill="#8d6827" font-size="62" font-family="serif">实验室安全教育考试系统</text>
+  <text x="600" y="280" text-anchor="middle" fill="#1f2937" font-size="42" font-family="serif">安全教育合格证书</text>
+  <text x="600" y="395" text-anchor="middle" fill="#374151" font-size="32">兹证明 张同学 已完成相关安全教育并通过考试</text>
+  <text x="600" y="470" text-anchor="middle" fill="#374151" font-size="28">证书仅在系统存在正式签发记录时展示</text>
+  <text x="600" y="650" text-anchor="middle" fill="#8d6827" font-size="28">实验室安全教育管理中心</text>
+  <text x="600" y="705" text-anchor="middle" fill="#6b7280" font-size="24">有效期以证书记录为准</text>
+  <circle cx="930" cy="630" r="72" fill="none" stroke="#c99b42" stroke-width="6"/>
+  <text x="930" y="640" text-anchor="middle" fill="#c99b42" font-size="22">已签发</text>
+</svg>

+ 39 - 0
mobile-uniapp/src/static/pledge-demo.pdf

@@ -0,0 +1,39 @@
+%PDF-1.4
+1 0 obj
+<< /Type /Catalog /Pages 2 0 R >>
+endobj
+2 0 obj
+<< /Type /Pages /Kids [3 0 R] /Count 1 >>
+endobj
+3 0 obj
+<< /Type /Page /Parent 2 0 R /MediaBox [0 0 612 792] /Resources << /Font << /F1 4 0 R >> >> /Contents 5 0 R >>
+endobj
+4 0 obj
+<< /Type /Font /Subtype /Type1 /BaseFont /Helvetica >>
+endobj
+5 0 obj
+<< /Length 144 >>
+stream
+BT
+/F1 18 Tf
+72 720 Td
+(Laboratory Safety Exam Pledge - Demo PDF) Tj
+0 -32 Td
+/F1 12 Tf
+(Please read the pledge and confirm before entering the exam.) Tj
+ET
+endstream
+endobj
+xref
+0 6
+0000000000 65535 f 
+0000000009 00000 n 
+0000000050 00000 n 
+0000000107 00000 n 
+0000000239 00000 n 
+0000000309 00000 n 
+trailer
+<< /Size 6 /Root 1 0 R >>
+startxref
+0000000503
+%%EOF

+ 23 - 0
mobile-uniapp/src/styles/app.scss

@@ -0,0 +1,23 @@
+@import './tokens.scss';
+
+.page { min-height: 100vh; background: $page-bg; padding-bottom: calc(28rpx + env(safe-area-inset-bottom)); }
+.page-content { padding: 24rpx; }
+.surface { background: $surface; border-radius: $radius; box-sizing: border-box; }
+.card { @extend .surface; margin-bottom: 20rpx; padding: 24rpx; }
+.muted { color: $text-secondary; }
+.small { font-size: 24rpx; }
+.section-title { font-size: 32rpx; font-weight: 600; margin: 12rpx 0 20rpx; }
+.row { display: flex; align-items: center; }
+.between { justify-content: space-between; }
+.primary-btn { background: $primary; color: #fff; border-radius: 10rpx; font-size: 26rpx; line-height: 1; padding: 18rpx 24rpx; }
+.plain-btn { background: #fff; color: $primary; border: 1px solid $primary; border-radius: 10rpx; font-size: 26rpx; line-height: 1; padding: 16rpx 22rpx; }
+.disabled-btn { background: #d1d5db; color: #fff; }
+.empty { padding: 88rpx 24rpx; text-align: center; color: $text-secondary; }
+.divider { height: 1px; background: $line; margin: 18rpx 0; }
+.tag { display: inline-flex; align-items: center; border-radius: 6rpx; padding: 4rpx 10rpx; font-size: 22rpx; line-height: 1.35; }
+.tag-blue { color: $primary; background: $primary-soft; }
+.tag-green { color: $success; background: #ecfdf3; }
+.tag-orange { color: #c2410c; background: #fff7ed; }
+.tag-red { color: $danger; background: #fef2f2; }
+.tag-gray { color: $text-secondary; background: #f3f4f6; }
+.list-arrow { color: #9ca3af; font-size: 34rpx; }

+ 11 - 0
mobile-uniapp/src/styles/tokens.scss

@@ -0,0 +1,11 @@
+$primary: #1677ff;
+$primary-soft: #eaf3ff;
+$page-bg: #f5f7fa;
+$surface: #ffffff;
+$text-main: #1f2937;
+$text-secondary: #6b7280;
+$line: #e5e7eb;
+$success: #16a34a;
+$warning: #f59e0b;
+$danger: #dc2626;
+$radius: 16rpx;

+ 1 - 0
mobile-uniapp/src/uni.scss

@@ -0,0 +1 @@
+@import './styles/tokens.scss';

+ 51 - 0
mobile-uniapp/tests/exam-flow.test.mjs

@@ -0,0 +1,51 @@
+import test from 'node:test'
+import assert from 'node:assert/strict'
+import { cloneSeed } from '../src/services/mock/seed.mjs'
+import { beginRun, confirmPledge, formalGate, getIssuedCertificateForResult, getVisibleResult, submitRun } from '../src/services/business/examFlow.mjs'
+import { getPendingExamCount, getPendingLearningCount, getPendingTrainingCount } from '../src/services/business/todos.mjs'
+
+test('考试承诺书确认、交卷和安全承诺书确认是独立状态', () => {
+  const state = cloneSeed()
+  const start = beginRun(state, 'general-safety-2026', 'formal', state.currentUser.id)
+  assert.equal(start.next, 'pre-pledge')
+  assert.equal(getVisibleResult(state, 'general-safety-2026', 'formal'), null)
+  assert.equal(confirmPledge(state, 'general-safety-2026', 'formal', 'pre').next, 'answer')
+  const submitted = submitRun(state, 'general-safety-2026', 'formal', { q1: 'A', q2: 'A', q3: 'A' })
+  assert.equal(submitted.next, 'post-pledge')
+  assert.equal(getVisibleResult(state, 'general-safety-2026', 'formal'), null)
+  assert.equal(beginRun(state, 'general-safety-2026', 'formal', state.currentUser.id).next, 'post-pledge')
+  assert.equal(confirmPledge(state, 'general-safety-2026', 'formal', 'post').next, 'result')
+  assert.equal(getVisibleResult(state, 'general-safety-2026', 'formal').passed, true)
+})
+
+test('补考记录与正式考试历史独立,并只读取已签发证书', () => {
+  const state = cloneSeed()
+  const beforeFormal = state.scoreHistory.find((item) => item.mode === 'formal' && item.examId === 'graded-makeup-2026')
+  assert.equal(beforeFormal.score, 68)
+  assert.equal(beginRun(state, 'graded-makeup-2026', 'makeup', state.currentUser.id).next, 'pre-pledge')
+  confirmPledge(state, 'graded-makeup-2026', 'makeup', 'pre')
+  submitRun(state, 'graded-makeup-2026', 'makeup', { q1: 'A', q2: 'A', q3: 'A' })
+  assert.equal(getVisibleResult(state, 'graded-makeup-2026', 'makeup'), null)
+  confirmPledge(state, 'graded-makeup-2026', 'makeup', 'post')
+  assert.equal(getVisibleResult(state, 'graded-makeup-2026', 'makeup').passed, true)
+  assert.equal(getIssuedCertificateForResult(state, 'graded-makeup-2026', 'makeup').id, 'graded-makeup-2026-issued')
+  assert.equal(state.scoreHistory.find((item) => item.id === beforeFormal.id).score, 68)
+})
+
+test('待办按业务任务、考试开放状态与培训状态计算', () => {
+  const state = cloneSeed()
+  assert.equal(getPendingLearningCount(state, state.currentUser.id), 2)
+  assert.equal(getPendingTrainingCount(state, state.currentUser.id), 1)
+  assert.equal(getPendingExamCount(state, state.currentUser.id), 2)
+})
+
+test('分级考试课程前置条件与学时条件分别校验', () => {
+  const state = cloneSeed()
+  assert.equal(formalGate(state, 'graded-entry-2026').reason, '请先完成考前课程')
+  state.courseProgress['lab-safety-basics'] = {
+    'lab-1': { completed: true },
+    'lab-2': { completed: true }
+  }
+  assert.equal(formalGate(state, 'graded-entry-2026').allowed, true)
+  assert.equal(formalGate(state, 'should-know-monthly-2026').reason, '尚未满足学时要求')
+})