Browse Source

feat: 请求参数附加examId

chenhao 2 years ago
parent
commit
075076efb4

+ 2 - 0
src/constants/storage.ts

@@ -8,4 +8,6 @@ export const LOCAL_STORAGE_KEYS = {
 export const SESSION_STORAGE_KEYS = {
 export const SESSION_STORAGE_KEYS = {
   /** 登录返回结果 */
   /** 登录返回结果 */
   LOGIN_RESULT: 'login-result',
   LOGIN_RESULT: 'login-result',
+  /** 超管选择的考试ID */
+  EXAM_ID: 'exam-id',
 }
 }

+ 5 - 3
src/modules/bootstrap/check-exam/index.vue

@@ -13,7 +13,7 @@
         ></base-select>
         ></base-select>
         <div :class="{ 'm-t-super-large': !isCreate }">
         <div :class="{ 'm-t-super-large': !isCreate }">
           <confirm-button
           <confirm-button
-            :loading="loading || checkLoading"
+            :loading="loading"
             :ok-text="isCreate ? '创建考试' : '确定'"
             :ok-text="isCreate ? '创建考试' : '确定'"
             cancel-text="退出"
             cancel-text="退出"
             @confirm="joinOrCreateExam(isCreate)"
             @confirm="joinOrCreateExam(isCreate)"
@@ -30,6 +30,7 @@ import { ref, computed } from 'vue'
 import { useRouter } from 'vue-router'
 import { useRouter } from 'vue-router'
 import { ElMessage } from 'element-plus'
 import { ElMessage } from 'element-plus'
 import { logout } from '@/utils/shared'
 import { logout } from '@/utils/shared'
+import { sessionStorage } from '@/plugins/storage'
 import useFetch from '@/hooks/useFetch'
 import useFetch from '@/hooks/useFetch'
 import useMainStore from '@/store/main'
 import useMainStore from '@/store/main'
 import BaseSelect from '@/components/element/BaseSelect.vue'
 import BaseSelect from '@/components/element/BaseSelect.vue'
@@ -41,7 +42,7 @@ const mainStore = useMainStore()
 const examId = ref<number>()
 const examId = ref<number>()
 
 
 const { result, loading, fetch } = useFetch('getExamList')
 const { result, loading, fetch } = useFetch('getExamList')
-const { fetch: checkExam, loading: checkLoading } = useFetch('checkExam')
+// const { fetch: checkExam, loading: checkLoading } = useFetch('checkExam')
 
 
 const examList = computed(() => {
 const examList = computed(() => {
   return result.value?.result?.map((exam) => ({ ...exam, value: exam.id, label: exam.name })) || []
   return result.value?.result?.map((exam) => ({ ...exam, value: exam.id, label: exam.name })) || []
@@ -65,7 +66,8 @@ async function joinOrCreateExam(isCreate: boolean) {
     replace({ name: 'InitCreateExam' })
     replace({ name: 'InitCreateExam' })
   } else {
   } else {
     if (examId.value) {
     if (examId.value) {
-      await checkExam({ examId: examId.value })
+      // await checkExam({ examId: examId.value })
+      sessionStorage.set('EXAM_ID', examId.value)
     } else {
     } else {
       ElMessage.error(`请选择一个考试批次`)
       ElMessage.error(`请选择一个考试批次`)
     }
     }

+ 2 - 0
src/modules/bootstrap/login/index.vue

@@ -115,6 +115,8 @@ function loginSuccess(loginInfo: ExtractApiResponse<'userLogin'>) {
     replace({ name: 'CheckExam' })
     replace({ name: 'CheckExam' })
   }
   }
 }
 }
+
+sessionStorage.clear()
 </script>
 </script>
 
 
 <style scoped lang="scss">
 <style scoped lang="scss">

+ 4 - 1
src/plugins/request/index.ts

@@ -1,6 +1,6 @@
 import axios, { AxiosError } from 'axios'
 import axios, { AxiosError } from 'axios'
 import { ElMessage } from 'element-plus'
 import { ElMessage } from 'element-plus'
-import { setupAuthSign, transformRequestData, transformGetParams } from '@/plugins/request/plugin'
+import { setupAuthSign, transformRequestData, transformGetParams, appendExamId } from '@/plugins/request/plugin'
 import { filterEmpty, downloadBlob, extractFileName } from '@/utils/common'
 import { filterEmpty, downloadBlob, extractFileName } from '@/utils/common'
 import { logout } from '@/utils/shared'
 import { logout } from '@/utils/shared'
 import useMainStore from '@/store/main'
 import useMainStore from '@/store/main'
@@ -24,6 +24,9 @@ request.interceptors.request.use(
     if (!config.url) {
     if (!config.url) {
       throw new AxiosError('request must should a url parameter', 'REQUEST_PARAMETER_ERROR', config)
       throw new AxiosError('request must should a url parameter', 'REQUEST_PARAMETER_ERROR', config)
     }
     }
+
+    appendExamId(config)
+
     config.data = filterEmpty(config.data)
     config.data = filterEmpty(config.data)
     config.params = filterEmpty(config.params)
     config.params = filterEmpty(config.params)
 
 

+ 9 - 0
src/plugins/request/plugin.ts

@@ -52,6 +52,15 @@ export const transformRequestData = (config: AxiosRequestConfig) => {
   return config
   return config
 }
 }
 
 
+/**
+ * @description 添加examId参数
+ */
+export const appendExamId = (config: AxiosRequestConfig) => {
+  config.params ??= {}
+  config.params.examId = sessionStorage.get('EXAM_ID')
+  return config
+}
+
 /**
 /**
  * @description get请求数组参数转换
  * @description get请求数组参数转换
  */
  */