Browse Source

Merge remote-tracking branch 'origin/wanzi' into muzi

liyanbo 1 month ago
parent
commit
e4ef20122f
2 changed files with 37 additions and 26 deletions
  1. 35 3
      src/components/study/SelfDirectedLearning.vue
  2. 2 23
      src/views/AIPage/AIGeneralCourse.vue

+ 35 - 3
src/components/study/SelfDirectedLearning.vue

@@ -99,6 +99,7 @@ import {
   sendChatMessageStream, textToSpeech
 } from "@/api/questions.js";
 import {Message} from "@/utils/message/Message.js";
+import {teacherList} from "@/api/teachers.js";
 
 // 定义props
 const props = defineProps({
@@ -109,6 +110,9 @@ const props = defineProps({
   }
 })
 
+// 本地数字人列表
+const localScriptRoles = ref([])
+
 // 发送消息输入框
 const prompt = ref(""); // prompt
 
@@ -786,7 +790,8 @@ const progressSteps = ref([
 
 // 计算主讲下拉框选项
 const teacherOptions = computed(() => {
-  return props.scriptRoles.map(role => ({
+  const roles = props.scriptRoles.length > 0 ? props.scriptRoles : localScriptRoles.value;
+  return roles.map(role => ({
     label: role.name,
     value: role.name
   }));
@@ -794,12 +799,33 @@ const teacherOptions = computed(() => {
 
 // 计算助教下拉框选项
 const assistantOptions = computed(() => {
-  return props.scriptRoles.map(role => ({
+  const roles = props.scriptRoles.length > 0 ? props.scriptRoles : localScriptRoles.value;
+  return roles.map(role => ({
     label: role.name,
     value: role.name
   }));
 });
 
+/**
+ * 获取角色列表
+ * @returns {Promise<void>}
+ */
+const getRoleList = async () => {
+  try {
+    let grade = localStorage.getItem('selectedGrade')
+    grade = grade ? grade : '小学低年级'
+    // 获取小学低年级AI数据
+    const listAiRes = await teacherList({ category: grade + 'AI' })
+    const listRes = await teacherList({ category: grade })
+    const listAi = listAiRes.data.list || []
+    const list = listRes.data.list || []
+    listAi.push(...list)
+    localScriptRoles.value = listAi
+  } catch (error) {
+    console.error('获取角色数据失败:', error)
+  }
+}
+
 // 下拉框配置
 const dropdowns = ref([
   {
@@ -932,9 +958,15 @@ const allStepsCompleted = computed(() => {
 });
 
 // 组件挂载时
-onMounted(() => {
+onMounted(async () => {
   // 初始状态下不显示生成进度
   showNewContainer.value = false;
+  
+  // 如果父组件没有传递scriptRoles,则自己获取
+  if (props.scriptRoles.length === 0) {
+    await getRoleList();
+  }
+  
   // 初始化主讲下拉框选项
   dropdowns.value[1].options = teacherOptions.value;
   // 初始化助教下拉框选项

+ 2 - 23
src/views/AIPage/AIGeneralCourse.vue

@@ -120,7 +120,7 @@
       <div class="box-2">
         <!-- 自主学习组件,只在AI自主学习时显示 -->
         <SelfDirectedLearning v-if="currentOpenedMenu === 'selfstudy'"
-                              :scriptRoles="scriptRoles" @refreshData="refreshData" />
+                              @refreshData="refreshData" />
         
         <div
           class="small-box"
@@ -180,8 +180,6 @@ const handleVisibleChange = (visible) => {
   dropdownVisible.value = visible
 }
 
-// 脚本角色数据
-const scriptRoles = ref([])
 
 // 课程数据管理
 const courseData = ref({
@@ -336,7 +334,7 @@ onMounted(() => {
     currentActiveIndex.value = savedIndex
   }
 
-  getRoleList()
+
 
   // const title = history.state?.title
   // if (title) {
@@ -367,25 +365,6 @@ const querySearch = (queryString, cb) => {
   cb(results)
 }
 
-/**
- * 获取角色列表
- * @returns {Promise<void>}
- */
-const getRoleList = async () => {
-  try {
-    let grade = localStorage.getItem('selectedGrade')
-    grade = grade ? grade : '小学低年级'
-    // 获取小学低年级AI数据
-    const listAiRes = await teacherList({ category: grade + 'AI' })
-    const listRes = await teacherList({ category: grade })
-    const listAi = listAiRes.data.list || []
-    const list = listRes.data.list || []
-    listAi.push(...list)
-    scriptRoles.value = listAi
-  } catch (error) {
-    console.error('获取角色数据失败:', error)
-  }
-}
 
 // 搜索选择处理方法
 const handleSearchSelect = item => {