瀏覽代碼

Merge branch 'lll_speech_to_text' of FanYanPeng/EAIFrontend into host-nju

LiuLuLin 10 月之前
父節點
當前提交
0d94b4f675
共有 1 個文件被更改,包括 18 次插入2 次删除
  1. 18 2
      src/views/AiSpeakingPage/SpeakingPage.vue

+ 18 - 2
src/views/AiSpeakingPage/SpeakingPage.vue

@@ -70,7 +70,7 @@
                     :value="voice.code"
                   >
                   <div style="display: flex; align-items: center;">
-                    <el-avatar :src="voice.avatar" size="small" style="margin-right: 10px;"></el-avatar>
+                    <el-avatar :src="voice.avatar || voiceOptions[0]?.avatar" size="small" style="margin-right: 10px;"></el-avatar>
                     <span>{{ voice.name }}</span>
                     <el-button
                       @click.stop="toggleAudio(voice)"
@@ -112,7 +112,7 @@
               }"
             >
               <el-avatar
-                :src="message.sender === 'user' ? userAvatar : (message.voiceCode !== null ? voiceOptions[message.voiceCode].avatar : voiceOptions[voiceCode].avatar)"
+                :src="message.sender === 'user' ? userAvatar : getAvatar(message.voiceCode)"
                 size="small"
                 style="flex-shrink:0"
                 shape="circle"
@@ -766,6 +766,22 @@ const saveHomework = async () => {
   }
 };
 
+// 安全的头像获取方法
+const getAvatar = (voiceCode) => {
+  if (voiceCode === null || voiceCode === undefined) {
+    return voiceOptions.value[0]?.avatar || userAvatar;
+  }
+  return voiceOptions.value[voiceCode]?.avatar || voiceOptions.value[0]?.avatar || gavinAvatar;
+};
+
+// 安全的语音选项获取方法
+const getVoiceOption = (voiceCode) => {
+  if (voiceCode === null || voiceCode === undefined) {
+    return voiceOptions.value[0];
+  }
+  return voiceOptions.value[voiceCode] || voiceOptions.value[0];
+};
+
 // 文档预览相关
 const open = ref(false)
 const alertProps = reactive({