index.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670
  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="resetButton()">重置</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.$set(this, 'scoreList', []);
  293. this.loadScoreList();
  294. },
  295. resetButton(){
  296. this.scorePage = 1;
  297. this.scoreNoMore = false;
  298. this.startDate = '';
  299. this.endDate = '';
  300. this.resultIndex = 0;
  301. this.activeTagIndex = 0;
  302. this.$set(this, 'scoreList', []);
  303. this.loadScoreList();
  304. },
  305. // 我的成绩列表(支持分页)
  306. async loadScoreList() {
  307. if (this.scoreLoading || this.scoreNoMore) return;
  308. this.scoreLoading = true;
  309. try {
  310. const tag = this.examTypeTags[this.activeTagIndex];
  311. const result = this.resultOptions[this.resultIndex];
  312. const obj = {
  313. page: this.scorePage,
  314. pageSize: this.scorePageSize,
  315. examTypeId: tag.value || '',
  316. resultStatus: result.value || '',
  317. startTime: this.startDate?this.startDate + 'T00:00:00':'',
  318. endTime: this.endDate?this.endDate + 'T23:59:59':'',
  319. examScene:1,
  320. };
  321. const { data } = await examElExamUserResultMyScoreListPage(obj);
  322. if (data.code === 200) {
  323. for(let i=0;i<data.data.records.length;i++){
  324. data.data.records[i].startTime = parseTime(data.data.records[i].startTime, "{y}-{m}-{d}")
  325. }
  326. const records = data.data.records || [];
  327. const newList = this.scorePage === 1 ? records : [...this.scoreList, ...records];
  328. this.$set(this, 'scoreList', newList);
  329. this.scoreTotal = data.data.total;
  330. if (newList.length >= this.scoreTotal) {
  331. this.scoreNoMore = true;
  332. } else {
  333. this.scorePage++;
  334. }
  335. }
  336. } catch (e) {
  337. console.error('获取成绩列表失败', e);
  338. } finally {
  339. this.scoreLoading = false;
  340. }
  341. },
  342. // 滚动到底部加载更多(我的成绩)
  343. onScrollToLower() {
  344. if (this.activeTab === 2) {
  345. this.loadScoreList();
  346. }
  347. },
  348. onResultChange(e) {
  349. this.resultIndex = e.detail.value;
  350. this.resetScoreList();
  351. },
  352. onStartDateChange(e) {
  353. this.startDate = e.detail.value;
  354. this.resetScoreList();
  355. },
  356. onEndDateChange(e) {
  357. this.endDate = e.detail.value;
  358. this.resetScoreList();
  359. },
  360. onTagChange(index) {
  361. this.activeTagIndex = index;
  362. this.resetScoreList();
  363. },
  364. goToExamDetail(item) {
  365. // 跳转考试详情,传递完整考试数据
  366. const examData = encodeURIComponent(JSON.stringify(item));
  367. uni.navigateTo({
  368. url: `/pages_safetyEducationExamination/views/exam/onlineExamInfo?examData=${examData}`
  369. });
  370. },
  371. goToMockDetail(item) {
  372. // 跳转模拟考试详情,传递完整模拟考试数据
  373. const examData = encodeURIComponent(JSON.stringify(item));
  374. uni.navigateTo({
  375. url: `/pages_safetyEducationExamination/views/exam/mockExamInfo?examData=${examData}`
  376. });
  377. },
  378. goToScoreList(item) {
  379. console.log('item',item);
  380. // 跳转答题详情,传递 attemptId / examId
  381. uni.navigateTo({
  382. url: `/pages_safetyEducationExamination/views/exam/scoresList?examId=${item.examId}`
  383. });
  384. },
  385. goToCert(item) {
  386. // 跳转证书,传递 certificatePath
  387. },
  388. },
  389. }
  390. </script>
  391. <style lang="stylus" scoped>
  392. .safetyEducationExamination-exam
  393. height 100%
  394. display flex
  395. flex-direction column
  396. overflow hidden
  397. background-color #f0f4fb
  398. // 顶部 Tab
  399. .tab-bar
  400. background #fff
  401. border-bottom 1rpx solid #e8edf3
  402. display flex
  403. flex-shrink 0
  404. .tab-item
  405. flex 1
  406. text-align center
  407. padding 18rpx 8rpx 16rpx
  408. font-size 26rpx
  409. color #888
  410. border-bottom 4rpx solid transparent
  411. .tab-item.active
  412. color #1677ff
  413. font-weight 600
  414. border-bottom-color #1677ff
  415. // 滚动区
  416. .scroll-content
  417. flex 1
  418. overflow hidden
  419. .panel
  420. padding 24rpx
  421. // 考试卡片
  422. .exam-card
  423. background #fff
  424. border-radius 20rpx
  425. padding 24rpx 28rpx
  426. margin-bottom 20rpx
  427. box-shadow 0 2rpx 12rpx rgba(0,0,0,0.04)
  428. border 1rpx solid #dde3ed
  429. .card-top
  430. display flex
  431. justify-content space-between
  432. align-items center
  433. margin-bottom 16rpx
  434. .card-top-left
  435. display flex
  436. align-items center
  437. .arrow-icon
  438. font-size 32rpx
  439. color #bbb
  440. // 标签
  441. .tag
  442. font-size 20rpx
  443. padding 4rpx 12rpx
  444. border-radius 8rpx
  445. border 1rpx solid transparent
  446. .tag-blue
  447. background #e6f4ff
  448. color #1677ff
  449. border-color #91caff
  450. .tag-orange
  451. background #fff7e6
  452. color #d46b08
  453. border-color #ffd591
  454. // 状态点
  455. .status-dot
  456. width 12rpx
  457. height 12rpx
  458. border-radius 50%
  459. margin-left 24rpx
  460. margin-right:10rpx;
  461. .dot-orange
  462. background #fa8c16
  463. .dot-green
  464. background #999
  465. .status-text
  466. font-size 22rpx
  467. margin-left 6rpx
  468. .text-orange
  469. color #fa8c16
  470. .text-gray
  471. color #999
  472. .text-green
  473. color #52c41a
  474. .text-blue
  475. color #1677ff
  476. .text-red
  477. color #f5222d
  478. // 考试名称
  479. .exam-name
  480. display block
  481. font-size 28rpx
  482. font-weight 600
  483. color #222
  484. margin-bottom 16rpx
  485. // 信息格
  486. .info-grid
  487. display grid
  488. gap 12rpx
  489. .col3
  490. grid-template-columns 1fr 1fr 1fr
  491. .col2
  492. grid-template-columns 1fr 1fr
  493. .info-item
  494. background #f4f6fa
  495. border-radius 12rpx
  496. padding 12rpx 16rpx
  497. display flex
  498. flex-direction column
  499. .info-item-2
  500. display flex
  501. flex-direction column
  502. .info-label
  503. font-size 20rpx
  504. color #999
  505. margin-bottom 8rpx
  506. .info-value
  507. font-size 22rpx
  508. // 筛选
  509. .filter-row
  510. display flex
  511. align-items center
  512. gap 12rpx
  513. padding 16rpx 0 8rpx
  514. flex-wrap nowrap
  515. .top-picker-input-box{
  516. width:190rpx;
  517. height:54rpx;
  518. padding:0;
  519. text-align: center;
  520. line-height:54rpx;
  521. }
  522. .top-right-box-button{
  523. border: 1rpx solid #dde3ed;
  524. border-radius:10rpx
  525. background:#fff;
  526. font-size:24rpx;
  527. width:100rpx;
  528. height:54rpx;
  529. padding:0;
  530. text-align: center;
  531. line-height:54rpx;
  532. }
  533. .picker-input
  534. font-size 24rpx
  535. color #333
  536. background #fff
  537. border 1rpx solid #dde3ed
  538. border-radius 10rpx
  539. padding 10rpx 16rpx
  540. .filter-sep
  541. font-size 22rpx
  542. color #999
  543. flex-shrink 0
  544. // 类型标签滚动
  545. .tag-scroll
  546. white-space nowrap
  547. padding 8rpx 0 16rpx
  548. .tag-scroll-inner
  549. display inline-flex
  550. gap 12rpx
  551. .filter-tag
  552. display inline-block
  553. font-size 22rpx
  554. padding 8rpx 20rpx
  555. border-radius 30rpx
  556. background #eef1f6
  557. color #666
  558. border 1rpx solid transparent
  559. .filter-tag-active
  560. background #e6f0ff
  561. color #1677ff
  562. border-color #91caff
  563. // 成绩卡片
  564. .score-card
  565. background #fff
  566. border-radius 20rpx
  567. padding 24rpx 28rpx
  568. margin-bottom 20rpx
  569. box-shadow 0 2rpx 12rpx rgba(0,0,0,0.04)
  570. border 1rpx solid #dde3ed
  571. .score-result
  572. font-size 22rpx
  573. font-weight 600
  574. padding 4rpx 16rpx
  575. border-radius 20rpx
  576. .result-pass
  577. background #f6ffed
  578. color #52c41a
  579. border 1rpx solid #b7eb8f
  580. .result-fail
  581. background #fff2f0
  582. color #f5222d
  583. border 1rpx solid #ffccc7
  584. .score-exam-name
  585. display block
  586. font-size 30rpx
  587. font-weight 700
  588. color #222
  589. margin 16rpx 0
  590. .score-info-grid
  591. display grid
  592. grid-template-columns 1fr 1fr
  593. gap 12rpx
  594. margin-bottom 20rpx
  595. font-size 26rpx
  596. color #333
  597. .card-actions
  598. display flex
  599. gap 16rpx
  600. margin-top 16rpx
  601. .btn-cert
  602. font-size 24rpx
  603. padding 10rpx 20rpx
  604. background #fff7e6
  605. color #d46b08
  606. border 1rpx solid #ffd591
  607. border-radius 12rpx
  608. .empty-tip
  609. text-align center
  610. line-height 80rpx
  611. color #aaa
  612. font-size 24rpx
  613. .loading-tip
  614. text-align center
  615. line-height 60rpx
  616. color #aaa
  617. font-size 22rpx
  618. </style>