index.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661
  1. <!-- 在线考试列表 -->
  2. <template>
  3. <view class="safetyEducationExamination-exam">
  4. <!-- 顶部 Tab -->
  5. <view class="tab-bar">
  6. <view
  7. v-for="(tab, index) in tabs"
  8. :key="index"
  9. class="tab-item"
  10. :class="{ active: activeTab === index }"
  11. @click="switchTab(index)"
  12. >
  13. {{ tab }}
  14. </view>
  15. </view>
  16. <!-- 内容区 -->
  17. <scroll-view scroll-y class="scroll-content" @scrolltolower="onScrollToLower">
  18. <!-- 考试任务 -->
  19. <view v-if="activeTab === 0" class="panel">
  20. <view
  21. v-for="(item, index) in examTaskList"
  22. :key="index"
  23. class="exam-card"
  24. @click="goToExamDetail(item)"
  25. >
  26. <view class="card-top">
  27. <view class="card-top-left">
  28. <text class="tag tag-blue">{{ item.examTypeName }}</text>
  29. <view class="status-dot" :class="item.examStatus == 1 ? 'dot-green' : 'dot-orange'"></view>
  30. <text class="status-text" :class="item.examStatus == 1 ? 'text-gray' : 'text-orange'">
  31. {{ item.examStatus == 1 ? '未开始' : '进行中' }}
  32. </text>
  33. </view>
  34. <text class="arrow-icon">›</text>
  35. </view>
  36. <text class="exam-name">{{ item.examName }}</text>
  37. <!-- 有学时要求:三列 -->
  38. <view v-if="item.needStudy || item.examStudy || item.mockExam" class="info-grid col3">
  39. <view class="info-item">
  40. <text class="info-label">学时要求</text>
  41. <text class="info-value" :class="item.needStudy ? 'text-orange' : 'text-green'">
  42. {{ item.completedStudyHours }}/{{ item.studyHoursRequirement }}
  43. <text v-if="item.needStudy"> 未达标</text>
  44. <text v-else> 已达标</text>
  45. </text>
  46. </view>
  47. <view class="info-item">
  48. <text class="info-label">学习任务</text>
  49. <text class="info-value" :class="item.examStudy ? 'text-orange' : 'text-green'">
  50. {{ item.examStudy ? '待完成' : '已完成' }}
  51. </text>
  52. </view>
  53. <view class="info-item">
  54. <text class="info-label">模拟考试</text>
  55. <text class="info-value" :class="item.mockExam ? 'text-orange' : 'text-green'">
  56. {{ item.mockExam ? '待完成' : '已完成' }}
  57. </text>
  58. </view>
  59. </view>
  60. <!-- 无前置条件:两列 -->
  61. <view v-else class="info-grid col2">
  62. <view class="info-item">
  63. <text class="info-label">满分/及格</text>
  64. <text class="info-value">{{ item.totalScore }} / {{ item.passScore }} 分</text>
  65. </view>
  66. <view class="info-item">
  67. <text class="info-label">可考次数</text>
  68. <text class="info-value text-gray">{{ item.attemptLimit === 0 ? '不限' : item.attemptLimit + ' 次' }}</text>
  69. </view>
  70. </view>
  71. </view>
  72. <view v-if="!examTaskList[0] && !examTaskLoading" class="empty-tip">暂无考试任务</view>
  73. <view v-if="examTaskLoading" class="loading-tip">加载中...</view>
  74. </view>
  75. <!-- 模拟考试 -->
  76. <view v-if="activeTab === 1" class="panel">
  77. <view
  78. v-for="(item, index) in mockExamList"
  79. :key="index"
  80. class="exam-card"
  81. @click="goToMockDetail(item)"
  82. >
  83. <view class="card-top">
  84. <view class="card-top-left">
  85. <text class="tag tag-blue">{{ item.examTypeName }}</text>
  86. <text class="tag tag-orange" style="margin-left:8rpx;">模拟卷</text>
  87. </view>
  88. <text class="arrow-icon">›</text>
  89. </view>
  90. <text class="exam-name">{{ item.examName }}</text>
  91. <view class="info-grid col2">
  92. <view class="info-item-2">
  93. <span class="info-value" style="color:#8896a7;">最高成绩:
  94. <span class="info-value" :class="item.maxScore >= item.passScore ? 'text-green' : 'text-orange'">
  95. {{ item.maxScore > 0 ? item.maxScore + ' 分' : '未参加' }}
  96. </span></span>
  97. </view>
  98. <view class="info-item-2">
  99. <text class="info-value" style="text-align:right;color:#8896a7;">及格线:{{ item.passScore }} 分</text>
  100. </view>
  101. </view>
  102. </view>
  103. <view v-if="!mockExamList[0] && !mockExamLoading" class="empty-tip">暂无模拟考试</view>
  104. <view v-if="mockExamLoading" class="loading-tip">加载中...</view>
  105. </view>
  106. <!-- 我的成绩 -->
  107. <view v-if="activeTab === 2" class="panel">
  108. <!-- 筛选区 -->
  109. <view class="filter-row">
  110. <picker :range="resultOptions" :range-key="'label'" @change="onResultChange">
  111. <view class="picker-input" style="width:100rpx;">{{ resultOptions[resultIndex].label }} ▾</view>
  112. </picker>
  113. <picker mode="date" :value="startDate" @change="onStartDateChange">
  114. <view class="picker-input top-picker-input-box" :style="!startDate?'color:#999;font-size:22rpx;':''">{{ startDate?startDate:'请选择' }}</view>
  115. </picker>
  116. <text class="filter-sep">至</text>
  117. <picker mode="date" :value="endDate" @change="onEndDateChange" >
  118. <view class="picker-input top-picker-input-box" :style="!endDate?'color:#999;font-size:22rpx;':''">{{ endDate?endDate:'请选择' }}</view>
  119. </picker>
  120. <view class="top-right-box-button" @click="resetScoreList()">重置</view>
  121. </view>
  122. <!-- 考试类型标签 -->
  123. <scroll-view scroll-x class="tag-scroll">
  124. <view class="tag-scroll-inner">
  125. <text
  126. v-for="(tag, index) in examTypeTags"
  127. :key="index"
  128. class="filter-tag"
  129. :class="{ 'filter-tag-active': activeTagIndex === index }"
  130. @click="onTagChange(index)"
  131. >{{ tag.label }}</text>
  132. </view>
  133. </scroll-view>
  134. <!-- 成绩卡片 -->
  135. <view
  136. v-for="(item, index) in scoreList"
  137. :key="index"
  138. class="score-card"
  139. @click="goToScoreList(item)"
  140. >
  141. <view class="card-top">
  142. <text class="tag tag-blue">{{ item.examTypeName }}</text>
  143. <text class="score-result" :class="item.resultStatus == 2 ? 'result-pass' : 'result-fail'">
  144. {{ item.resultStatus == 2 ? '通过' : '未通过' }}
  145. </text>
  146. </view>
  147. <text class="score-exam-name">{{ item.examName }}</text>
  148. <view class="score-info-grid">
  149. <view><text class="text-gray">考试时间:</text>{{ item.startTime }}</view>
  150. <view><text class="text-gray">时长:</text>{{ item.answerDuration }} 分钟</view>
  151. <view><text class="text-gray">满分/及格:</text>{{ item.totalScore }} / {{ item.passScore }}</view>
  152. <view><text class="text-gray">考次:</text>{{ item.attemptCount }} / {{ item.attemptLimit === 0 ? '不限' : item.attemptLimit }}</view>
  153. <view><text class="text-gray">用时:</text>{{ item.myDuration || '-' }}</view>
  154. <view>
  155. <text class="text-gray">最高成绩:</text>
  156. <text :class="item.bestScore >= item.passScore ? 'text-green' : 'text-red'">{{ item.bestScore }} 分</text>
  157. </view>
  158. <view>
  159. <text class="text-gray">获得积分:</text>
  160. <text :class="item.myScore > 0 ? 'text-orange' : 'text-gray'">
  161. {{ item.myScore > 0 ? '+' + item.myScore + '分' : '无' }}
  162. </text>
  163. </view>
  164. <view>
  165. <text class="text-gray">考试结果:</text>
  166. <text :class="item.resultStatus == 2 ? 'text-green' : 'text-red'">
  167. {{ item.resultStatus == 2 ? '通过' : '未通过' }}
  168. </text>
  169. </view>
  170. </view>
  171. <view v-if="item.certificatePath" class="card-actions">
  172. <text class="btn-cert" @click.stop="goToCert(item)">查看证书</text>
  173. </view>
  174. </view>
  175. <view v-if="!scoreList[0] && !scoreLoading" class="empty-tip">暂无成绩记录</view>
  176. <view v-if="scoreLoading" class="loading-tip">加载中...</view>
  177. <view v-if="scoreNoMore && scoreList[0]" class="loading-tip">没有更多了</view>
  178. </view>
  179. </scroll-view>
  180. </view>
  181. </template>
  182. <script>
  183. import {
  184. parseTime
  185. } from '@/component/public.js'
  186. import {
  187. examUserExamList,
  188. examUserExamMockList,
  189. examElExamUserResultMyScoreListPage,
  190. examUserExamTypeSelectExamType,
  191. } from '@/pages_safetyEducationExamination/api/index.js'
  192. export default {
  193. data() {
  194. return {
  195. tabs: ['考试任务', '模拟考试', '我的成绩'],
  196. activeTab: 0,
  197. // 考试任务
  198. examTaskList: [],
  199. examTaskLoading: false,
  200. // 模拟考试
  201. mockExamList: [],
  202. mockExamLoading: false,
  203. // 我的成绩
  204. scoreList: [],
  205. scoreLoading: false,
  206. scorePage: 1,
  207. scorePageSize: 10,
  208. scoreTotal: 0,
  209. scoreNoMore: false,
  210. // 筛选
  211. resultOptions: [
  212. { label: '全部', value: null },
  213. { label: '通过', value: 1 },
  214. { label: '未通过', value: 2 },
  215. ],
  216. resultIndex: 0,
  217. startDate: '',
  218. endDate: '',
  219. examTypeTags: [{ label: '全部', value: null }],
  220. activeTagIndex: 0,
  221. }
  222. },
  223. created() {
  224. this.loadExamTypeTags();
  225. },
  226. onShow() {
  227. this.refreshCurrentTab();
  228. },
  229. methods: {
  230. switchTab(index) {
  231. this.activeTab = index;
  232. this.refreshCurrentTab();
  233. },
  234. refreshCurrentTab() {
  235. if (this.activeTab === 0) {
  236. this.loadExamTaskList();
  237. } else if (this.activeTab === 1) {
  238. this.loadMockExamList();
  239. } else if (this.activeTab === 2) {
  240. this.resetScoreList();
  241. }
  242. },
  243. // 考试类型标签(用于我的成绩筛选)
  244. async loadExamTypeTags() {
  245. try {
  246. const { data } = await examUserExamTypeSelectExamType({});
  247. if (data.code === 200 && data.data) {
  248. const tags = (data.data || []).map(item => ({
  249. label: item.examTypeName,
  250. value: item.examTypeId,
  251. }));
  252. this.$set(this, 'examTypeTags', [{ label: '全部', value: null }, ...tags]);
  253. }
  254. } catch (e) {
  255. console.error('获取考试类型失败', e);
  256. }
  257. },
  258. // 考试任务列表
  259. async loadExamTaskList() {
  260. if (this.examTaskLoading) return;
  261. this.examTaskLoading = true;
  262. try {
  263. const { data } = await examUserExamList({ page: 1, pageSize: 50 });
  264. if (data.code === 200) {
  265. this.$set(this, 'examTaskList', data.data.records || []);
  266. }
  267. } catch (e) {
  268. console.error('获取考试任务失败', e);
  269. } finally {
  270. this.examTaskLoading = false;
  271. }
  272. },
  273. // 模拟考试列表
  274. async loadMockExamList() {
  275. if (this.mockExamLoading) return;
  276. this.mockExamLoading = true;
  277. try {
  278. const { data } = await examUserExamMockList({ page: 1, pageSize: 50 });
  279. if (data.code === 200) {
  280. this.$set(this, 'mockExamList', data.data.records || []);
  281. }
  282. } catch (e) {
  283. console.error('获取模拟考试失败', e);
  284. } finally {
  285. this.mockExamLoading = false;
  286. }
  287. },
  288. // 重置成绩列表(筛选条件变更时调用)
  289. resetScoreList() {
  290. this.scorePage = 1;
  291. this.scoreNoMore = false;
  292. this.startTime = '';
  293. this.endTime = '';
  294. this.$set(this, 'scoreList', []);
  295. this.loadScoreList();
  296. },
  297. // 我的成绩列表(支持分页)
  298. async loadScoreList() {
  299. if (this.scoreLoading || this.scoreNoMore) return;
  300. this.scoreLoading = true;
  301. try {
  302. const tag = this.examTypeTags[this.activeTagIndex];
  303. const result = this.resultOptions[this.resultIndex];
  304. const obj = {
  305. page: this.scorePage,
  306. pageSize: this.scorePageSize,
  307. examTypeId: tag.value || '',
  308. resultStatus: result.value || '',
  309. startTime: this.startDate?this.startDate + 'T00:00:00':'',
  310. endTime: this.endDate?this.endDate + 'T23:59:59':'',
  311. examScene:null
  312. };
  313. const { data } = await examElExamUserResultMyScoreListPage(obj);
  314. if (data.code === 200) {
  315. for(let i=0;i<data.data.records.length;i++){
  316. data.data.records[i].startTime = parseTime(data.data.records[i].startTime, "{y}-{m}-{d}")
  317. }
  318. const records = data.data.records || [];
  319. const newList = this.scorePage === 1 ? records : [...this.scoreList, ...records];
  320. this.$set(this, 'scoreList', newList);
  321. this.scoreTotal = data.data.total;
  322. if (newList.length >= this.scoreTotal) {
  323. this.scoreNoMore = true;
  324. } else {
  325. this.scorePage++;
  326. }
  327. }
  328. } catch (e) {
  329. console.error('获取成绩列表失败', e);
  330. } finally {
  331. this.scoreLoading = false;
  332. }
  333. },
  334. // 滚动到底部加载更多(我的成绩)
  335. onScrollToLower() {
  336. if (this.activeTab === 2) {
  337. this.loadScoreList();
  338. }
  339. },
  340. onResultChange(e) {
  341. this.resultIndex = e.detail.value;
  342. this.resetScoreList();
  343. },
  344. onStartDateChange(e) {
  345. this.startDate = e.detail.value;
  346. this.resetScoreList();
  347. },
  348. onEndDateChange(e) {
  349. this.endDate = e.detail.value;
  350. this.resetScoreList();
  351. },
  352. onTagChange(index) {
  353. this.activeTagIndex = index;
  354. this.resetScoreList();
  355. },
  356. goToExamDetail(item) {
  357. // 跳转考试详情,传递完整考试数据
  358. const examData = encodeURIComponent(JSON.stringify(item));
  359. uni.navigateTo({
  360. url: `/pages_safetyEducationExamination/views/exam/onlineExamInfo?examData=${examData}`
  361. });
  362. },
  363. goToMockDetail(item) {
  364. // 跳转模拟考试详情,传递完整模拟考试数据
  365. const examData = encodeURIComponent(JSON.stringify(item));
  366. uni.navigateTo({
  367. url: `/pages_safetyEducationExamination/views/exam/mockExamInfo?examData=${examData}`
  368. });
  369. },
  370. goToScoreList(item) {
  371. // 跳转答题详情,传递 attemptId / examId
  372. uni.navigateTo({
  373. url: `/pages_safetyEducationExamination/views/exam/scoreList?examId=${item.examId}`
  374. });
  375. },
  376. goToCert(item) {
  377. // 跳转证书,传递 certificatePath
  378. },
  379. },
  380. }
  381. </script>
  382. <style lang="stylus" scoped>
  383. .safetyEducationExamination-exam
  384. height 100%
  385. display flex
  386. flex-direction column
  387. overflow hidden
  388. background-color #f0f4fb
  389. // 顶部 Tab
  390. .tab-bar
  391. background #fff
  392. border-bottom 1rpx solid #e8edf3
  393. display flex
  394. flex-shrink 0
  395. .tab-item
  396. flex 1
  397. text-align center
  398. padding 18rpx 8rpx 16rpx
  399. font-size 26rpx
  400. color #888
  401. border-bottom 4rpx solid transparent
  402. .tab-item.active
  403. color #1677ff
  404. font-weight 600
  405. border-bottom-color #1677ff
  406. // 滚动区
  407. .scroll-content
  408. flex 1
  409. overflow hidden
  410. .panel
  411. padding 24rpx
  412. // 考试卡片
  413. .exam-card
  414. background #fff
  415. border-radius 20rpx
  416. padding 24rpx 28rpx
  417. margin-bottom 20rpx
  418. box-shadow 0 2rpx 12rpx rgba(0,0,0,0.04)
  419. border 1rpx solid #dde3ed
  420. .card-top
  421. display flex
  422. justify-content space-between
  423. align-items center
  424. margin-bottom 16rpx
  425. .card-top-left
  426. display flex
  427. align-items center
  428. .arrow-icon
  429. font-size 32rpx
  430. color #bbb
  431. // 标签
  432. .tag
  433. font-size 20rpx
  434. padding 4rpx 12rpx
  435. border-radius 8rpx
  436. border 1rpx solid transparent
  437. .tag-blue
  438. background #e6f4ff
  439. color #1677ff
  440. border-color #91caff
  441. .tag-orange
  442. background #fff7e6
  443. color #d46b08
  444. border-color #ffd591
  445. // 状态点
  446. .status-dot
  447. width 12rpx
  448. height 12rpx
  449. border-radius 50%
  450. margin-left 24rpx
  451. margin-right:10rpx;
  452. .dot-orange
  453. background #fa8c16
  454. .dot-green
  455. background #999
  456. .status-text
  457. font-size 22rpx
  458. margin-left 6rpx
  459. .text-orange
  460. color #fa8c16
  461. .text-gray
  462. color #999
  463. .text-green
  464. color #52c41a
  465. .text-blue
  466. color #1677ff
  467. .text-red
  468. color #f5222d
  469. // 考试名称
  470. .exam-name
  471. display block
  472. font-size 28rpx
  473. font-weight 600
  474. color #222
  475. margin-bottom 16rpx
  476. // 信息格
  477. .info-grid
  478. display grid
  479. gap 12rpx
  480. .col3
  481. grid-template-columns 1fr 1fr 1fr
  482. .col2
  483. grid-template-columns 1fr 1fr
  484. .info-item
  485. background #f4f6fa
  486. border-radius 12rpx
  487. padding 12rpx 16rpx
  488. display flex
  489. flex-direction column
  490. .info-item-2
  491. display flex
  492. flex-direction column
  493. .info-label
  494. font-size 20rpx
  495. color #999
  496. margin-bottom 8rpx
  497. .info-value
  498. font-size 22rpx
  499. // 筛选
  500. .filter-row
  501. display flex
  502. align-items center
  503. gap 12rpx
  504. padding 16rpx 0 8rpx
  505. flex-wrap nowrap
  506. .top-picker-input-box{
  507. width:190rpx;
  508. height:54rpx;
  509. padding:0;
  510. text-align: center;
  511. line-height:54rpx;
  512. }
  513. .top-right-box-button{
  514. border: 1rpx solid #dde3ed;
  515. border-radius:10rpx
  516. background:#fff;
  517. font-size:24rpx;
  518. width:100rpx;
  519. height:54rpx;
  520. padding:0;
  521. text-align: center;
  522. line-height:54rpx;
  523. }
  524. .picker-input
  525. font-size 24rpx
  526. color #333
  527. background #fff
  528. border 1rpx solid #dde3ed
  529. border-radius 10rpx
  530. padding 10rpx 16rpx
  531. .filter-sep
  532. font-size 22rpx
  533. color #999
  534. flex-shrink 0
  535. // 类型标签滚动
  536. .tag-scroll
  537. white-space nowrap
  538. padding 8rpx 0 16rpx
  539. .tag-scroll-inner
  540. display inline-flex
  541. gap 12rpx
  542. .filter-tag
  543. display inline-block
  544. font-size 22rpx
  545. padding 8rpx 20rpx
  546. border-radius 30rpx
  547. background #eef1f6
  548. color #666
  549. border 1rpx solid transparent
  550. .filter-tag-active
  551. background #e6f0ff
  552. color #1677ff
  553. border-color #91caff
  554. // 成绩卡片
  555. .score-card
  556. background #fff
  557. border-radius 20rpx
  558. padding 24rpx 28rpx
  559. margin-bottom 20rpx
  560. box-shadow 0 2rpx 12rpx rgba(0,0,0,0.04)
  561. border 1rpx solid #dde3ed
  562. .score-result
  563. font-size 22rpx
  564. font-weight 600
  565. padding 4rpx 16rpx
  566. border-radius 20rpx
  567. .result-pass
  568. background #f6ffed
  569. color #52c41a
  570. border 1rpx solid #b7eb8f
  571. .result-fail
  572. background #fff2f0
  573. color #f5222d
  574. border 1rpx solid #ffccc7
  575. .score-exam-name
  576. display block
  577. font-size 30rpx
  578. font-weight 700
  579. color #222
  580. margin 16rpx 0
  581. .score-info-grid
  582. display grid
  583. grid-template-columns 1fr 1fr
  584. gap 12rpx
  585. margin-bottom 20rpx
  586. font-size 26rpx
  587. color #333
  588. .card-actions
  589. display flex
  590. gap 16rpx
  591. margin-top 16rpx
  592. .btn-cert
  593. font-size 24rpx
  594. padding 10rpx 20rpx
  595. background #fff7e6
  596. color #d46b08
  597. border 1rpx solid #ffd591
  598. border-radius 12rpx
  599. .empty-tip
  600. text-align center
  601. line-height 80rpx
  602. color #aaa
  603. font-size 24rpx
  604. .loading-tip
  605. text-align center
  606. line-height 60rpx
  607. color #aaa
  608. font-size 22rpx
  609. </style>