Răsfoiți Sursa

提交优化和样式

丸子 8 luni în urmă
părinte
comite
d8d69cae39
1 a modificat fișierele cu 23 adăugiri și 21 ștergeri
  1. 23 21
      src/views/AIGeneralCourse.vue

+ 23 - 21
src/views/AIGeneralCourse.vue

@@ -158,6 +158,23 @@ const selectedGrade = ref('')
 
 // 添加抽屉显示状态
 const drawerVisible = ref(true)
+
+// 统一函数来获取课程大纲数据
+const fetchClassOutline = async (classId) => {
+  try {
+    const res = await ClassOutline(classId)
+    if (res.code === 0) {
+      classOutlineData.value = res.data
+      classOutlineData.value.map((item, index) => {
+        item.ctTypeSort = index + 1
+        item.ctTypeSort = item.ctTypeSort > 9 ? item.ctTypeSort : "0" + item.ctTypeSort
+      })
+    }
+  } catch (error) {
+    console.error('获取课程大纲数据失败:', error)
+  }
+}
+
 // 处理下拉菜单选择
 const handleGradeSelect = command => {
   selectedGrade.value = command
@@ -168,17 +185,8 @@ const handleGradeSelect = command => {
   // 存储年级id
   if (selectedItem) {
     localStorage.setItem('selectedGradeId', selectedItem.id)
-  }
-  if (selectedItem) {
-    ClassOutline(selectedItem.id).then(res => {
-      if (res.code === 0) {
-        classOutlineData.value = res.data
-        classOutlineData.value.map((item, index) => {
-          item.ctTypeSort = index + 1
-          item.ctTypeSort = item.ctTypeSort > 9 ? item.ctTypeSort : "0" + item.ctTypeSort
-        })
-      }
-    })
+    // 获取课程大纲
+    fetchClassOutline(selectedItem.id)
   }
 }
 // 添加切换抽屉显示状态的函数
@@ -190,6 +198,8 @@ const classData = ref([])
 // 添加接口返回的数据引用,用于存储 ClassOutline 结果
 const classOutlineData = ref([])
 
+
+
 const fetchCtTypes = async () => {
   try {
     const response = await ClassList()
@@ -205,16 +215,8 @@ const fetchCtTypes = async () => {
         classData.value.find(item => item.ctType === selectedGrade.value) ||
         classData.value[0]
       if (selectedItem) {
-        ClassOutline(selectedItem.id).then(res => {
-          console.log(res);
-          if (res.code === 0) {
-            classOutlineData.value = res.data
-            classOutlineData.value.map((item, index) => {
-              item.ctTypeSort = index + 1
-              item.ctTypeSort = item.ctTypeSort > 9 ? item.ctTypeSort : "0" + item.ctTypeSort
-            })
-          }
-        })
+        // 使用新函数获取课程大纲
+        fetchClassOutline(selectedItem.id)
       }
     }
   } catch (error) {