ソースを参照

refactor(api): 修改API地址为相对路径并调整轮询间隔

feat(search): 增加搜索表单展开状态和验证逻辑
refactor(hooks): 提取培训计划相关逻辑到独立文件
fix(http): 添加错误消息显示控制选项
zhanghaijun 10 ヶ月 前
親
コミット
2019117da3

+ 1 - 1
.env.mock

@@ -4,7 +4,7 @@
 VITE_BASE_URL = ./
 
 # API 地址前缀
-VITE_API_URL = https://m1.apifoxmock.com/m1/7156555-6880574-default
+VITE_API_URL = /api
 
 # 权限模式( frontend | backend )
 VITE_ACCESS_MODE = frontend

+ 3 - 1
src/utils/http/server.axios.ts

@@ -51,7 +51,9 @@ export class RequestHttp {
         if (code === ApiStatus.success) return response
         if (code === ApiStatus.unauthorized) handleUnauthorizedError(msg)
         if (code === ApiStatus.internalServerError) {
-          ElMessage.error('接口报错:' + (msg || $t('httpMsg.requestFailed')))
+          if (config.showErrorMessage ?? true) {
+            ElMessage.error('接口报错:' + (msg || $t('httpMsg.requestFailed')))
+          }
         }
         throw new Error(msg || $t('httpMsg.requestFailed'))
       },

+ 6 - 6
src/views/train/course/list/plan.hook.ts

@@ -24,15 +24,16 @@ export interface StudentItem {
 }
 
 export const usePlanOptions = () => {
-  const { getUserType } = toRefs(useUserStore())
+  const { userInfo, getUserType } = toRefs(useUserStore())
   const planStore = usePlanStore()
   // 培训计划选项
   const planActive = ref<string[]>([])
   const planDate = ref<PlanItem[]>([])
   const getTrainPlanOptions = async () => {
-    const { data } = await request.post<PlanItem[]>('/course/tmsplan', {})
+    const { data } = await request.post<PlanItem[]>('/course/tmsplan', {}, { showErrorMessage: false })
     planDate.value = data || []
-    //   planDate.value = [{
+    // planDate.value = [
+    //   {
     //     PXSSID: '20251114135547847001283163793969',
     //     PXSSMC: '11月牵引变电培训',
     //     PlanInfo: [
@@ -60,13 +61,12 @@ export const usePlanOptions = () => {
   })
 
   // 学员列表
-  const studentActive = ref<string>(getUserType.value === 2 ? '' : '1001')
+  const studentActive = ref<string>(getUserType.value === 2 ? '' : String(userInfo.value?.userId ?? ''))
   const studentData = ref<StudentItem[]>([])
   const getStudentOptions = async () => {
-    console.log(planActive.value)
     if (planActive.value.length === 0) return
     const lastPlan = planActive.value[0]
-    const { data } = await request.post<StudentItem[]>('/course/tmsplanstudent', { PXSSID: lastPlan || '' })
+    const { data } = await request.post<StudentItem[]>('/course/tmsplanstudent', { PXSSID: lastPlan || '' }, { showErrorMessage: false })
     studentData.value = data || []
     // studentData.value = [
     //   { XYEMPID: '1001', XYXM: '孙鑫' },

+ 12 - 5
src/views/train/course/list/search.vue

@@ -1,5 +1,5 @@
 <template>
-  <ArtSearchBar ref="courseSearchRef" v-model="courseFormData" :items="formItems" labelWidth="100px" @search="courseSearchHandle">
+  <ArtSearchBar ref="courseSearchRef" v-model="courseFormData" :items="formItems" :isExpand="true" labelWidth="100px" @search="courseSearchHandle">
     <template #PXSSID>
       <el-cascader :options="planOptions" v-model="planActive" clearable placeholder="选择培训计划" />
     </template>
@@ -14,7 +14,7 @@
 <script setup lang="ts">
   import { Course } from '@/api/course.api'
   import { useDictStore } from '@/store/modules/dict'
-  import { usePlanOptions } from './plan.hook'
+  import { usePlanOptions } from './course.plan'
 
   const { planId, getUserType, planActive, planOptions, studentActive, studentOptions } = usePlanOptions()
   const dictStore = useDictStore()
@@ -51,7 +51,6 @@
     {
       label: '* 培训计划',
       key: 'PXSSID',
-      helpMessage: ['type="year"'],
       type: 'input',
       placeholder: '请选择培训计划',
       clearable: true,
@@ -59,12 +58,20 @@
       rules: [{ required: true, message: '请选择培训计划', trigger: ['change'] }]
     },
     ...(getUserType.value === 2
-      ? []
-      : [{ label: '* 学员名单', key: 'XYEMPID', type: 'input', placeholder: '请选择学员', clearable: true, options: [], rules: [{ required: true, message: '请选择学员', trigger: ['change'] }] }])
+      ? [{ label: '* 学员名单', key: 'XYEMPID', type: 'input', placeholder: '请选择学员', clearable: true, options: [], rules: [{ required: true, message: '请选择学员', trigger: ['change'] }] }]
+      : [])
   ])
 
   const courseSearchHandle = async () => {
     await courseSearchRef.value.validate()
+    if (planActive.value.length === 0) {
+      ElMessage.error('请选择培训计划')
+      return
+    }
+    if (getUserType.value === 2 && studentActive.value.length === 0) {
+      ElMessage.error('请选择学员')
+      return
+    }
     emit('search', { ...courseFormData, PXSSID: planId.value })
   }
 

+ 1 - 1
src/views/train/course/trainer_teacher/course.run.hooks.ts

@@ -16,7 +16,7 @@ export const useCourseRunStatus = () => {
 
   onMounted(() => {
     getRunStatusData()
-    timer = setInterval(() => getRunStatusData(), 1000)
+    timer = setInterval(() => getRunStatusData(), 5000)
   })
 
   onUnmounted(() => {