Bladeren bron

feat(课程管理): 完善课程列表功能及开课限制

添加学生选项获取方法,优化搜索栏重置逻辑
修改课程列表API支持加载全部课程
增加开课时的课程冲突检查
zhanghaijun 9 maanden geleden
bovenliggende
commit
e309aaa731

+ 2 - 2
src/api/course.api.ts

@@ -24,10 +24,10 @@ export interface Course {
 }
 
 export class CourseServer {
-  public static list = (params: Record<string, unknown>) => {
+  public static list = (params: Record<string, unknown>, loadAll: boolean = false) => {
     const { trainingPlanID } = usePlanStore()
     return request.post<Course[]>('/course/list', {
-      ...(trainingPlanID ? { JXJHID: trainingPlanID } : {}),
+      ...(!loadAll && trainingPlanID ? { JXJHID: trainingPlanID } : {}),
       ...(params.courseID ? { courseID: Number(params.courseID) } : {}),
       ...(params.courseName ? { courseName: params.courseName } : {}),
       ...(params.typeID ? { typeID: Number(params.typeID) } : {}),

+ 1 - 1
src/components/core/forms/art-search-bar/index.vue

@@ -278,7 +278,7 @@
     // 清空所有表单项值(包含隐藏项)
     Object.assign(modelValue.value, Object.fromEntries(props.items.map(({ key }) => [key, undefined])))
 
-    handleSearch()
+    emit('reset')
   }
 
   /**

+ 2 - 2
src/views/train/course/index.vue

@@ -1,6 +1,6 @@
 <template>
   <div class="page-content">
-    <course-search ref="courseSearchRef" v-show="showSearchBar" @search="getCourseData" :edit="true"></course-search>
+    <course-search ref="courseSearchRef" v-show="showSearchBar" @search="getCourseData" @reset="() => getCourseData({})" :edit="true"></course-search>
     <el-card class="art-table-card" shadow="never">
       <ArtTableHeader v-model:showSearchBar="showSearchBar" :loading="loading" @refresh="() => getCourseData({})" layout="search,refresh">
         <template #left>
@@ -79,7 +79,7 @@
     if (Object.keys(params).length === 0) {
       courseSearchRef?.value?.reset()
     }
-    const { data } = await CourseServer.list(params)
+    const { data } = await CourseServer.list(params, true)
     courseData.value = data!
     loading.value = false
   }

+ 1 - 0
src/views/train/course/list/course.plan.ts

@@ -92,6 +92,7 @@ export const usePlanOptions = () => {
 
   onMounted(() => {
     getTrainPlanOptions()
+    getStudentOptions()
   })
 
   return {

+ 2 - 1
src/views/train/course/list/search.vue

@@ -1,5 +1,5 @@
 <template>
-  <ArtSearchBar ref="courseSearchRef" v-model="courseFormData" :items="formItems" :isExpand="true" labelWidth="100px" @search="courseSearchHandle">
+  <ArtSearchBar ref="courseSearchRef" v-model="courseFormData" :items="formItems" :isExpand="true" labelWidth="100px" @search="courseSearchHandle" @reset="() => emit('reset')">
     <template #PXSSID>
       <el-cascader :options="planOptions" v-model="planActive" clearable placeholder="选择培训计划" />
     </template>
@@ -31,6 +31,7 @@
   const courseSearchRef = ref()
   const emit = defineEmits<{
     (e: 'search', params: Record<string, unknown>): void
+    (e: 'reset'): void
   }>()
 
   const courseFormData = reactive<CourseSearch>({

+ 11 - 1
src/views/train/course/trainer_teacher/course-list.vue

@@ -70,7 +70,13 @@
 
   const props = withDefaults(defineProps<{ data: Course[]; loading: boolean }>(), { data: () => [], loading: true })
 
-  const startCourse = (item: Course) => router.push({ path: '/trainer/course/run/' + item.courseID })
+  const startCourse = (item: Course) => {
+    if (runCourseID && String(runCourseID) !== String(item.courseID)) {
+      ElMessage.warning('请先结束正在开课的课程')
+      return
+    }
+    router.push({ path: '/trainer/course/run/' + item.courseID })
+  }
 
   const courseDetailRef = ref()
   const recordListRef = ref()
@@ -78,6 +84,10 @@
     recordListRef.value.show(item.courseID, item.courseName)
   }
   const courseDetailShow = (item: Course) => {
+    if (runCourseID && String(runCourseID) !== String(item.courseID)) {
+      ElMessage.warning('请先结束正在开课的课程')
+      return
+    }
     courseDetailRef.value.show(item)
   }
 

+ 4 - 4
src/views/train/course/trainer_teacher/index.vue

@@ -1,7 +1,7 @@
 <!-- 表格搜索栏示例 -->
 <template>
   <div class="search-bar">
-    <course-search ref="courseSearchRef" @search="getCourseData"></course-search>
+    <course-search ref="courseSearchRef" @search="(params) => getCourseData(params, false)" @reset="() => getCourseData({}, true)"></course-search>
     <course-list :data="courseData" :loading="loading" :is-run="true">
       <template #default="{ item }">
         <div class="flex items-center">
@@ -32,15 +32,15 @@
   const courseSearchRef = ref()
 
   onMounted(async () => {
-    getCourseData()
+    getCourseData({}, true)
   })
 
-  const getCourseData = async (params: Record<string, unknown> = {}) => {
+  const getCourseData = async (params: Record<string, unknown> = {}, loadAll: boolean = false) => {
     loading.value = true
     if (Object.keys(params).length === 0) {
       courseSearchRef?.value?.reset()
     }
-    const { data } = await CourseServer.list(params)
+    const { data } = await CourseServer.list(params, loadAll)
     courseData.value = data!
     loading.value = false
   }