cover.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <!--
  2. * @Author: wanglj wanglijie@dashoo.cn
  3. * @Date: 2025-03-11 18:02:10
  4. * @LastEditors: wanglj wanglijie@dashoo.cn
  5. * @LastEditTime: 2025-03-18 14:56:23
  6. * @FilePath: \vant-demo-master\vant\vue3-ts\src\view\login\index.vue
  7. * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
  8. -->
  9. <template>
  10. <div class="app-container">
  11. <h4 class="mt10 mb10">{{ state.form.name }}</h4>
  12. <van-cell-group>
  13. <van-cell title="考生姓名" :value="state.form.userName" />
  14. <van-cell title="考试总分" :value="`${state.form.totalScore}分`" />
  15. <van-cell title="及格分数" :value="`${state.form.passScore}分`" />
  16. <van-cell title="考试时间" :value="formatDate(new Date(state.form.startTime), 'YYYY-mm-dd HH:MM')" />
  17. <van-cell title="答题时间" :value="`${state.form.duration}分钟`" />
  18. <van-cell title="考试次数" :value="`${state.form.examineCount}/${state.form.totalCount}`" />
  19. </van-cell-group>
  20. <van-button type="primary" class="mt10" @click="startExam">开始考试</van-button>
  21. </div>
  22. </template>
  23. <script name="home" lang="ts" setup>
  24. import to from 'await-to-js'
  25. import { computed, onMounted, reactive, ref } from 'vue'
  26. import { useRouter } from 'vue-router'
  27. import { formatDate } from '/@/utils/formatTime'
  28. import { useDictApi } from '/@/api/system/dict'
  29. import { showConfirmDialog, showNotify } from 'vant'
  30. import { useTrainingApi } from '/@/api/training/index'
  31. const router = useRouter()
  32. const trainingApi = useTrainingApi()
  33. const state = reactive({
  34. form: {
  35. name: '',
  36. userName: '',
  37. examId: 0,
  38. examCover: '',
  39. epId: 0,
  40. duration: 0,
  41. totalScore: 0,
  42. passScore: 0,
  43. totalCount: 0,
  44. startTime: '',
  45. endTime: '',
  46. examineCount: 0
  47. }
  48. })
  49. const onClickRight = () => {
  50. router.go(-1)
  51. }
  52. const initExam = async () => {
  53. const [err, res]: ToResponse = await to(trainingApi.getMineExamResultInfo({ id: 233 }))
  54. if (err) return
  55. state.form = res?.data
  56. }
  57. const startExam = async () => {
  58. if (state.form.epId == 0) {
  59. showNotify({
  60. message: '该考试未配置试卷,请联系管理员配置试卷',
  61. type: 'warning'
  62. })
  63. } else {
  64. // 进入试卷获取试卷的前置条件
  65. checkEnterTestPaper();
  66. }
  67. }
  68. const checkEnterTestPaper = () => {
  69. trainingApi.enterExam({ examId: state.form.examId }).then((res: any) => {
  70. if (res.code == 200) {
  71. localStorage.setItem('currentStartTime', res.data.currentStartTime);
  72. localStorage.setItem('duration', state.form.duration + '');
  73. router.push({
  74. path: '/exam',
  75. query: {
  76. answerId: res.data.answerId,
  77. epId: state.form.epId,
  78. }
  79. })
  80. }
  81. });
  82. }
  83. onMounted(() => {
  84. initExam()
  85. })
  86. </script>
  87. <style lang="scss" scoped>
  88. .app-container {
  89. display: flex;
  90. flex-direction: column;
  91. h4 {
  92. font-size: 20px;
  93. height: 20px;
  94. line-height: 20px;
  95. &::before {
  96. display: inline-block;
  97. content: '';
  98. width: 3px;
  99. height: 20px;
  100. background-color: #1c9bfd;
  101. margin-right: 4px;
  102. vertical-align: middle;
  103. }
  104. }
  105. }
  106. </style>