index.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <template>
  2. <div class="grid full check-exam-view">
  3. <div class="check-exam-modal">
  4. <div class="p-l-large modal-header">请选择考试</div>
  5. <div class="login-modal-content">
  6. <base-select
  7. v-if="examList.length"
  8. v-model="examId"
  9. class="full-w"
  10. :options="examList"
  11. placeholder="选择考试批次"
  12. size="large"
  13. ></base-select>
  14. <div :class="{ 'm-t-super-large': !isCreate }">
  15. <confirm-button
  16. :loading="loading"
  17. :ok-text="isCreate ? '创建考试' : '确定'"
  18. cancel-text="退出"
  19. @confirm="joinOrCreateExam(isCreate)"
  20. @cancel="logout()"
  21. ></confirm-button>
  22. </div>
  23. </div>
  24. </div>
  25. </div>
  26. </template>
  27. <script setup lang="ts" name="CheckExam">
  28. import { ref, computed } from 'vue'
  29. import { useRouter } from 'vue-router'
  30. import { ElMessage } from 'element-plus'
  31. import { logout } from '@/utils/shared'
  32. import { sessionStorage } from '@/plugins/storage'
  33. import useFetch from '@/hooks/useFetch'
  34. import useMainStore from '@/store/main'
  35. import BaseSelect from '@/components/element/BaseSelect.vue'
  36. import ConfirmButton from '@/components/common/ConfirmButton.vue'
  37. const { push, replace } = useRouter()
  38. const mainStore = useMainStore()
  39. const examId = ref<number>()
  40. const { result, loading, fetch } = useFetch('getExamList')
  41. // const { fetch: checkExam, loading: checkLoading } = useFetch('checkExam')
  42. const examList = computed(() => {
  43. return result.value?.result?.map((exam) => ({ ...exam, value: exam.id, label: exam.name })) || []
  44. })
  45. const isCreate = computed(() => {
  46. return !loading.value && !examList?.value?.length
  47. })
  48. fetch({ pageNumber: 1, pageSize: 9999, enable: true }).then((result) => {
  49. if (result?.result?.length && !examId.value) {
  50. examId.value = result.result[0].id
  51. }
  52. })
  53. async function joinOrCreateExam(isCreate: boolean) {
  54. if (loading.value) {
  55. return
  56. }
  57. if (isCreate) {
  58. push({ name: 'InitCreateExam' })
  59. } else {
  60. if (examId.value) {
  61. // await checkExam({ examId: examId.value })
  62. sessionStorage.set('EXAM_ID', examId.value)
  63. } else {
  64. ElMessage.error(`请选择一个考试批次`)
  65. }
  66. mainStore.getMyUserInfo()
  67. replace({ name: 'UserManage' })
  68. }
  69. }
  70. </script>
  71. <style scoped lang="scss">
  72. .check-exam-view {
  73. place-items: center;
  74. .check-exam-modal {
  75. width: 640px;
  76. background: $LoginModalBg;
  77. border-radius: $LoginModalRadius;
  78. overflow: hidden;
  79. .modal-header {
  80. height: $LoginModalHeaderHeight;
  81. line-height: $LoginModalHeaderHeight;
  82. background: $LoginModalHeaderBg;
  83. font-size: $LoginModalHeaderFontSize;
  84. font-weight: normal;
  85. color: $LoginModalHeaderFontColor;
  86. }
  87. .login-modal-content {
  88. padding: 52px 80px;
  89. }
  90. :deep(button.el-button) {
  91. width: 120px;
  92. height: 48px;
  93. }
  94. }
  95. }
  96. </style>