diff --git a/src/views/AIchat.vue b/src/views/AIchat.vue index 75c4ab0..85e4328 100644 --- a/src/views/AIchat.vue +++ b/src/views/AIchat.vue @@ -176,7 +176,11 @@ const playAudioSequence = (audioUrls) => { ); // 增强URL验证 - if (!currentUrl || typeof currentUrl !== 'string' || currentUrl.trim() === '') { + if ( + !currentUrl || + typeof currentUrl !== "string" || + currentUrl.trim() === "" + ) { console.error(`音频 ${currentIndex + 1} URL无效,跳过该音频`); currentIndex++; setTimeout(() => { @@ -214,10 +218,10 @@ const playAudioSequence = (audioUrls) => { audioStore.isPlaying = true; audioStore.isPaused = false; console.log(`开始播放音频 ${currentIndex + 1}`); - console.log('音频播放状态:', { + console.log("音频播放状态:", { duration: sound.duration(), state: sound.state(), - playing: sound.playing() + playing: sound.playing(), }); }, onpause: () => { @@ -234,7 +238,7 @@ const playAudioSequence = (audioUrls) => { currentIndex++; // 如果是最后一个音频播放完成,立即清除实例 if (currentIndex >= audioSequence.length) { - console.log('最后一个音频播放完成,清除音频实例'); + console.log("最后一个音频播放完成,清除音频实例"); audioStore.soundInstance = null; audioStore.nowSound = null; currentIndex = 0; // 立即重置索引 @@ -252,8 +256,8 @@ const playAudioSequence = (audioUrls) => { }, onloaderror: (id, err) => { console.error(`音频 ${currentIndex + 1} 加载失败:`, err); - console.error('失败的音频URL:', currentUrl); - console.error('错误详情:', { id, err }); + console.error("失败的音频URL:", currentUrl); + console.error("错误详情:", { id, err }); // 增加重试机制 if (!sound.retryCount) { @@ -262,7 +266,9 @@ const playAudioSequence = (audioUrls) => { if (sound.retryCount < 2) { sound.retryCount++; - console.log(`音频 ${currentIndex + 1} 第${sound.retryCount}次重试加载`); + console.log( + `音频 ${currentIndex + 1} 第${sound.retryCount}次重试加载` + ); setTimeout(() => { sound.load(); }, 1000 * sound.retryCount); // 递增延时重试 @@ -282,7 +288,7 @@ const playAudioSequence = (audioUrls) => { // 添加播放超时检测 const playTimeout = setTimeout(() => { - if (!audioStore.isPlaying && sound.state() === 'loading') { + if (!audioStore.isPlaying && sound.state() === "loading") { console.warn(`音频 ${currentIndex + 1} 播放超时,可能网络问题`); sound.stop(); currentIndex++; @@ -291,7 +297,7 @@ const playAudioSequence = (audioUrls) => { }, 10000); // 10秒超时 // 播放成功后清除超时 - sound.once('play', () => { + sound.once("play", () => { clearTimeout(playTimeout); }); @@ -302,33 +308,38 @@ const playAudioSequence = (audioUrls) => { // 重写togglePlayPause方法以支持音频序列控制 const originalTogglePlayPause = audioStore.togglePlayPause; audioStore.togglePlayPause = () => { - console.log('音频控制按钮被点击'); - console.log('当前播放状态:', audioStore.isPlaying); - console.log('当前暂停状态:', audioStore.isPaused); - console.log('当前音频实例:', audioStore.soundInstance); - console.log('当前索引:', currentIndex, '音频序列长度:', audioSequence.length); + console.log("音频控制按钮被点击"); + console.log("当前播放状态:", audioStore.isPlaying); + console.log("当前暂停状态:", audioStore.isPaused); + console.log("当前音频实例:", audioStore.soundInstance); + console.log( + "当前索引:", + currentIndex, + "音频序列长度:", + audioSequence.length + ); if (audioStore.soundInstance) { if (audioStore.isPlaying) { // 暂停当前音频 - console.log('暂停当前音频'); + console.log("暂停当前音频"); audioStore.pause(); } else if (audioStore.isPaused) { // 从暂停位置继续播放 - console.log('从暂停位置继续播放'); + console.log("从暂停位置继续播放"); audioStore.play(); } else { // 重新开始播放当前音频或从头开始播放序列 - console.log('重新开始播放,当前索引:', currentIndex); + console.log("重新开始播放,当前索引:", currentIndex); if (currentIndex >= audioSequence.length) { - console.log('所有音频已播放完成,从头开始'); + console.log("所有音频已播放完成,从头开始"); currentIndex = 0; // 重置到第一个音频 } playNext(); } } else { // 没有音频实例时,从头开始播放 - console.log('没有音频实例,从头开始播放'); + console.log("没有音频实例,从头开始播放"); currentIndex = 0; playNext(); } @@ -422,13 +433,13 @@ const createTypingEffect = (message, content, speed) => { const processNextElement = () => { if (currentIndex >= content.length) { if (message.isEnd) { - if (message.isEnd == '1') { + if (message.isEnd == "1") { apiStatus.one.isEnd = true; - } else if (message.isEnd == '2') { + } else if (message.isEnd == "2") { apiStatus.two.isEnd = true; - } else if (message.isEnd == '3') { + } else if (message.isEnd == "3") { apiStatus.three.isEnd = true; - } else if (message.isEnd == '4') { + } else if (message.isEnd == "4") { apiStatus.four.isEnd = true; } } @@ -437,14 +448,14 @@ const createTypingEffect = (message, content, speed) => { class: "ing", type: "ing", flag: false, - content: '工作流返回出错,请稍后重试', - }) + content: "工作流返回出错,请稍后重试", + }); chatStore.isLoading = false; - if (message.error == '2') { + if (message.error == "2") { apiStatus.two.isError = true; - } else if (message.error == '3') { + } else if (message.error == "3") { apiStatus.three.isError = true; - } else if (message.error == '4') { + } else if (message.error == "4") { apiStatus.four.isError = true; } } @@ -551,13 +562,13 @@ const createTypingEffect = (message, content, speed) => { }); } if (message.isEnd) { - if (message.isEnd == '1') { + if (message.isEnd == "1") { apiStatus.one.isEnd = true; - } else if (message.isEnd == '2') { + } else if (message.isEnd == "2") { apiStatus.two.isEnd = true; - } else if (message.isEnd == '3') { + } else if (message.isEnd == "3") { apiStatus.three.isEnd = true; - } else if (message.isEnd == '4') { + } else if (message.isEnd == "4") { apiStatus.four.isEnd = true; } } @@ -566,14 +577,14 @@ const createTypingEffect = (message, content, speed) => { class: "ing", type: "ing", flag: false, - content: '工作流返回出错,请稍后重试', - }) + content: "工作流返回出错,请稍后重试", + }); chatStore.isLoading = false; - if (message.error == '2') { + if (message.error == "2") { apiStatus.two.isError = true; - } else if (message.error == '3') { + } else if (message.error == "3") { apiStatus.three.isError = true; - } else if (message.error == '4') { + } else if (message.error == "4") { apiStatus.four.isError = true; } } @@ -583,13 +594,13 @@ const createTypingEffect = (message, content, speed) => { }, 1000); } else { if (message.isEnd) { - if (message.isEnd == '1') { + if (message.isEnd == "1") { apiStatus.one.isEnd = true; - } else if (message.isEnd == '2') { + } else if (message.isEnd == "2") { apiStatus.two.isEnd = true; - } else if (message.isEnd == '3') { + } else if (message.isEnd == "3") { apiStatus.three.isEnd = true; - } else if (message.isEnd == '4') { + } else if (message.isEnd == "4") { apiStatus.four.isEnd = true; } } @@ -598,14 +609,14 @@ const createTypingEffect = (message, content, speed) => { class: "ing", type: "ing", flag: false, - content: '工作流返回出错,请稍后重试', - }) + content: "工作流返回出错,请稍后重试", + }); chatStore.isLoading = false; - if (message.error == '2') { + if (message.error == "2") { apiStatus.two.isError = true; - } else if (message.error == '3') { + } else if (message.error == "3") { apiStatus.three.isError = true; - } else if (message.error == '4') { + } else if (message.error == "4") { apiStatus.four.isError = true; } } @@ -618,7 +629,7 @@ const createTypingEffect = (message, content, speed) => { }); }; -let apiStatus = {} +let apiStatus = {}; // 队列处理函数 const processTypingQueue = async () => { @@ -734,8 +745,8 @@ watch( class: "ing", type: "ing", flag: false, - content: '工作流返回出错,请稍后重试', - }) + content: "工作流返回出错,请稍后重试", + }); chatStore.isLoading = false; } @@ -757,7 +768,7 @@ watch( const env = import.meta.env.VITE_ENV; const result20 = await dataListAPI({ token: - '8Csj5VVX1UbIb4C3oxrnbZi0+fEeMx8pywnIlrmTm45Cb/EllzWACLto9J9+fCFsfdgBOvKvyY94FvqlvM0', + "8Csj5VVX1UbIb4C3oxrnbZi0+fEeMx8pywnIlrmTm45Cb/EllzWACLto9J9+fCFsfdgBOvKvyY94FvqlvM0", // "8nkj4QBV1RPIb4CzoRTnbZi0+fEeMx8pywnIlrmTxdwROKkuwWqAWu9orpkpeXVqL98DPfeonNYpHv+mucA", market: codeData.value.market, code: codeData.value.code, @@ -780,11 +791,19 @@ watch( marketList: userStore.aiGoldMarketList, }); - - const HomePage = result20.data.HomePage; const AIGoldBull = result20.data.AIGoldBull; + const isLiuSe = HomePage ? true : false; + const isAIGoldBull = + AIGoldBull.DNC && + AIGoldBull.FCX && + AIGoldBull.JN && + AIGoldBull.KLine20 && + AIGoldBull.QSXH + ? true + : false; + const katexRegex = /\$\$(.*?)\$\$/g; let result21; @@ -793,10 +812,34 @@ watch( let result24; // 用于跟踪API完成状态和结果 apiStatus = { - one: { completed: false, result: null, error: null, isError: false, isEnd: false }, - two: { completed: false, result: null, error: null, isError: false, isEnd: false }, - three: { completed: false, result: null, error: null, isError: false, isEnd: false }, - four: { completed: false, result: null, error: null, isError: false, isEnd: false }, + one: { + completed: false, + result: null, + error: null, + isError: false, + isEnd: false, + }, + two: { + completed: false, + result: null, + error: null, + isError: false, + isEnd: false, + }, + three: { + completed: false, + result: null, + error: null, + isError: false, + isEnd: false, + }, + four: { + completed: false, + result: null, + error: null, + isError: false, + isEnd: false, + }, }; // 音频预加载状态跟踪 @@ -804,7 +847,7 @@ watch( one: { loaded: false, url: null }, two: { loaded: false, url: null }, three: { loaded: false, url: null }, - four: { loaded: false, url: null } + four: { loaded: false, url: null }, }; // 音频播放队列管理 @@ -818,24 +861,38 @@ watch( let currentPlayIndex = 0; const playNextAudio = () => { - console.log('=== playNextAudio 被调用 ==='); - console.log('当前队列状态:', { + console.log("=== playNextAudio 被调用 ==="); + console.log("当前队列状态:", { queueLength: audioQueue.value.length, - queueItems: audioQueue.value.map(item => item.name), + queueItems: audioQueue.value.map((item) => item.name), currentPlayIndex: currentPlayIndex, isPlayingAudio: isPlayingAudio.value, isCallingPlayNext: isCallingPlayNext, - audioStoreIsPlaying: audioStore.isPlaying + audioStoreIsPlaying: audioStore.isPlaying, }); - if (audioQueue.value.length === 0 || isPlayingAudio.value || isCallingPlayNext) { - console.log('❌ 播放条件不满足 - 队列长度:', audioQueue.value.length, '正在播放:', isPlayingAudio.value, '正在调用:', isCallingPlayNext); + if ( + audioQueue.value.length === 0 || + isPlayingAudio.value || + isCallingPlayNext + ) { + console.log( + "❌ 播放条件不满足 - 队列长度:", + audioQueue.value.length, + "正在播放:", + isPlayingAudio.value, + "正在调用:", + isCallingPlayNext + ); return; } // 检查是否已播放完所有音频(仅在队列不为空时重置) - if (currentPlayIndex >= audioQueue.value.length && audioQueue.value.length > 0) { - console.log('🔄 所有音频播放完成,重置索引从第一个开始'); + if ( + currentPlayIndex >= audioQueue.value.length && + audioQueue.value.length > 0 + ) { + console.log("🔄 所有音频播放完成,重置索引从第一个开始"); currentPlayIndex = 0; } @@ -843,12 +900,25 @@ watch( isPlayingAudio.value = true; const audioInfo = audioQueue.value[currentPlayIndex]; - console.log(`✅ 开始播放${audioInfo.name}音频 (索引:${currentPlayIndex}),队列总长度:`, audioQueue.value.length); - console.log('完整队列内容:', audioQueue.value.map((item, index) => `${index === currentPlayIndex ? '▶️' : '⏸️'} ${item.name}`)); + console.log( + `✅ 开始播放${audioInfo.name}音频 (索引:${currentPlayIndex}),队列总长度:`, + audioQueue.value.length + ); + console.log( + "完整队列内容:", + audioQueue.value.map( + (item, index) => + `${index === currentPlayIndex ? "▶️" : "⏸️"} ${item.name}` + ) + ); // 只有在确实需要停止时才停止之前的音频 - if (audioStore.nowSound && (audioStore.nowSound.playing() || audioStore.nowSound.state() === 'loading')) { - console.log('停止之前的音频实例'); + if ( + audioStore.nowSound && + (audioStore.nowSound.playing() || + audioStore.nowSound.state() === "loading") + ) { + console.log("停止之前的音频实例"); audioStore.nowSound.stop(); } @@ -862,14 +932,25 @@ watch( audioStore.isPaused = false; isPlayingAudio.value = true; // 确保状态同步 isCallingPlayNext = false; // 重置调用标志 - console.log(`${audioInfo.name}音频开始播放,时长:`, audio.duration()); - console.log('音频播放状态确认 - isPlayingAudio:', isPlayingAudio.value, 'audioStore.isPlaying:', audioStore.isPlaying); + console.log( + `${audioInfo.name}音频开始播放,时长:`, + audio.duration() + ); + console.log( + "音频播放状态确认 - isPlayingAudio:", + isPlayingAudio.value, + "audioStore.isPlaying:", + audioStore.isPlaying + ); }, onpause: () => { audioStore.isPlaying = false; audioStore.isPaused = true; audioStore.playbackPosition = audio.seek() || 0; - console.log(`${audioInfo.name}音频已暂停,位置:`, audioStore.playbackPosition); + console.log( + `${audioInfo.name}音频已暂停,位置:`, + audioStore.playbackPosition + ); }, onresume: () => { audioStore.isPlaying = true; @@ -878,7 +959,14 @@ watch( }, onend: () => { console.log(`${audioInfo.name}音频播放完成,准备播放下一个`); - console.log('播放完成时的状态 - 当前索引:', currentPlayIndex, '队列长度:', audioQueue.value.length, 'isPlayingAudio:', isPlayingAudio.value); + console.log( + "播放完成时的状态 - 当前索引:", + currentPlayIndex, + "队列长度:", + audioQueue.value.length, + "isPlayingAudio:", + isPlayingAudio.value + ); audioStore.isPlaying = false; audioStore.isPaused = false; audioStore.playbackPosition = 0; @@ -889,13 +977,23 @@ watch( // 确保只有在音频真正播放完成时才播放下一个 if (currentPlayIndex < audioQueue.value.length) { - console.log(`队列中还有音频,500ms后播放下一个 (索引:${currentPlayIndex}),当前队列:`, audioQueue.value.map((item, index) => `${index === currentPlayIndex ? '▶️' : '⏸️'} ${item.name}`)); + console.log( + `队列中还有音频,500ms后播放下一个 (索引:${currentPlayIndex}),当前队列:`, + audioQueue.value.map( + (item, index) => + `${index === currentPlayIndex ? "▶️" : "⏸️"} ${ + item.name + }` + ) + ); setTimeout(() => { isCallingPlayNext = false; // 在调用前重置标志 playNextAudio(); }, 500); } else { - console.log('🎉 所有音频播放完成,清除音频实例,队列保持完整,下次播放将从第一个开始'); + console.log( + "🎉 所有音频播放完成,清除音频实例,队列保持完整,下次播放将从第一个开始" + ); // 清除音频实例,确保重新播放时不会使用旧实例 audioStore.nowSound = null; audioStore.soundInstance = null; @@ -917,7 +1015,7 @@ watch( setTimeout(() => { playNextAudio(); }, 100); - } + }, }); // 设置当前音频URL到store @@ -931,51 +1029,69 @@ watch( // 音频队列顺序管理 const audioQueueOrder = { - 'API1-第一个': 1, - 'API2-第二个': 2, - 'API3-第三个': 3, - 'API4-第四个': 4 + "API1-第一个": 1, + "API2-第二个": 2, + "API3-第三个": 3, + "API4-第四个": 4, }; // 添加音频到播放队列(确保顺序) const addToAudioQueue = (url, name) => { console.log(`=== 添加音频到队列 ===`); - console.log('URL:', url); - console.log('Name:', name); - console.log('音频启用状态:', audioStore.isVoiceEnabled); + console.log("URL:", url); + console.log("Name:", name); + console.log("音频启用状态:", audioStore.isVoiceEnabled); if (url && audioStore.isVoiceEnabled) { - const audioItem = { url, name, order: audioQueueOrder[name] || 999 }; + const audioItem = { + url, + name, + order: audioQueueOrder[name] || 999, + }; audioQueue.value.push(audioItem); // 按顺序排序队列 audioQueue.value.sort((a, b) => a.order - b.order); - console.log(`音频${name}已添加到播放队列,顺序:${audioItem.order}`); - console.log('当前队列顺序:', audioQueue.value.map(item => `${item.name}(${item.order})`)); - console.log('当前播放状态详情:'); - console.log(' - isPlayingAudio:', isPlayingAudio.value); - console.log(' - audioStore.isPlaying:', audioStore.isPlaying); - console.log(' - audioStore.nowSound:', audioStore.nowSound); - console.log(' - isCallingPlayNext:', isCallingPlayNext); - console.log(' - 队列长度:', audioQueue.value.length); + console.log( + `音频${name}已添加到播放队列,顺序:${audioItem.order}` + ); + console.log( + "当前队列顺序:", + audioQueue.value.map((item) => `${item.name}(${item.order})`) + ); + console.log("当前播放状态详情:"); + console.log(" - isPlayingAudio:", isPlayingAudio.value); + console.log(" - audioStore.isPlaying:", audioStore.isPlaying); + console.log(" - audioStore.nowSound:", audioStore.nowSound); + console.log(" - isCallingPlayNext:", isCallingPlayNext); + console.log(" - 队列长度:", audioQueue.value.length); // 只有在确实没有音频在播放且这是第一个音频时才开始播放 - if (!isPlayingAudio.value && !audioStore.isPlaying && audioQueue.value.length === 1) { - console.log('✅ 条件满足:没有音频在播放且这是第一个音频,立即开始播放'); + if ( + !isPlayingAudio.value && + !audioStore.isPlaying && + audioQueue.value.length === 1 + ) { + console.log( + "✅ 条件满足:没有音频在播放且这是第一个音频,立即开始播放" + ); playNextAudio(); } else { - console.log('⏳ 等待条件:', { + console.log("⏳ 等待条件:", { isPlayingAudio: isPlayingAudio.value, audioStoreIsPlaying: audioStore.isPlaying, queueLength: audioQueue.value.length, - reason: audioQueue.value.length > 1 ? '队列中已有其他音频' : '有音频正在播放' + reason: + audioQueue.value.length > 1 + ? "队列中已有其他音频" + : "有音频正在播放", }); } } else { - console.log('❌ 跳过添加音频:', { + console.log("❌ 跳过添加音频:", { hasUrl: !!url, - voiceEnabled: audioStore.isVoiceEnabled + voiceEnabled: audioStore.isVoiceEnabled, }); } console.log(`=== 添加音频完成 ===`); @@ -984,62 +1100,113 @@ watch( // 重写audioStore的togglePlayPause方法以支持队列播放控制 const originalTogglePlayPause = audioStore.togglePlayPause; audioStore.togglePlayPause = () => { - console.log('主页音频控制按钮被点击'); - console.log('当前音频状态 - isPlaying:', audioStore.isPlaying, 'isPaused:', audioStore.isPaused); - console.log('当前音频实例:', audioStore.soundInstance); - console.log('队列播放状态 - isPlayingAudio:', isPlayingAudio.value, '队列长度:', audioQueue.value.length); - console.log('当前播放索引:', currentPlayIndex, '是否所有音频播放完成:', currentPlayIndex >= audioQueue.value.length); + console.log("主页音频控制按钮被点击"); + console.log( + "当前音频状态 - isPlaying:", + audioStore.isPlaying, + "isPaused:", + audioStore.isPaused + ); + console.log("当前音频实例:", audioStore.soundInstance); + console.log( + "队列播放状态 - isPlayingAudio:", + isPlayingAudio.value, + "队列长度:", + audioQueue.value.length + ); + console.log( + "当前播放索引:", + currentPlayIndex, + "是否所有音频播放完成:", + currentPlayIndex >= audioQueue.value.length + ); // 检查是否所有音频都播放完成,如果是则重新开始 - if (audioStore.soundInstance && currentPlayIndex < audioQueue.value.length && isPlayingAudio.value) { + if ( + audioStore.soundInstance && + currentPlayIndex < audioQueue.value.length && + isPlayingAudio.value + ) { if (audioStore.isPlaying) { // 暂停当前音频 - console.log('暂停当前音频'); + console.log("暂停当前音频"); audioStore.soundInstance.pause(); - } else if (audioStore.isPaused && audioStore.playbackPosition > 0) { + } else if ( + audioStore.isPaused && + audioStore.playbackPosition > 0 + ) { // 从暂停位置继续播放 - console.log('从暂停位置继续播放音频,位置:', audioStore.playbackPosition); + console.log( + "从暂停位置继续播放音频,位置:", + audioStore.playbackPosition + ); audioStore.soundInstance.seek(audioStore.playbackPosition); audioStore.soundInstance.play(); } else { // 重新开始播放 - console.log('重新开始播放音频'); + console.log("重新开始播放音频"); audioStore.soundInstance.play(); } } else { - console.log('没有音频实例,检查是否需要重新播放队列'); - console.log('重新播放条件检查:', { + console.log("没有音频实例,检查是否需要重新播放队列"); + console.log("重新播放条件检查:", { isPlayingAudio: isPlayingAudio.value, queueLength: audioQueue.value.length, currentPlayIndex: currentPlayIndex, condition1: audioQueue.value.length === 0, condition2: currentPlayIndex >= audioQueue.value.length, - finalCondition: !isPlayingAudio.value && (audioQueue.value.length === 0 || currentPlayIndex >= audioQueue.value.length) + finalCondition: + !isPlayingAudio.value && + (audioQueue.value.length === 0 || + currentPlayIndex >= audioQueue.value.length), }); // 没有音频实例时,检查是否所有音频都播放完成 - if (!isPlayingAudio.value && (audioQueue.value.length === 0 || currentPlayIndex >= audioQueue.value.length)) { - console.log('所有音频播放完成,重新构建队列从第一个开始播放'); + if ( + !isPlayingAudio.value && + (audioQueue.value.length === 0 || + currentPlayIndex >= audioQueue.value.length) + ) { + console.log("所有音频播放完成,重新构建队列从第一个开始播放"); // 重新构建音频队列,按顺序添加所有音频(不自动播放) const audioItems = []; if (audioPreloadStatus.one.url) { - audioItems.push({ url: audioPreloadStatus.one.url, name: "API1-第一个", order: 1 }); + audioItems.push({ + url: audioPreloadStatus.one.url, + name: "API1-第一个", + order: 1, + }); } if (audioPreloadStatus.two.url) { - audioItems.push({ url: audioPreloadStatus.two.url, name: "API2-第二个", order: 2 }); + audioItems.push({ + url: audioPreloadStatus.two.url, + name: "API2-第二个", + order: 2, + }); } if (audioPreloadStatus.three.url) { - audioItems.push({ url: audioPreloadStatus.three.url, name: "API3-第三个", order: 3 }); + audioItems.push({ + url: audioPreloadStatus.three.url, + name: "API3-第三个", + order: 3, + }); } if (audioPreloadStatus.four.url) { - audioItems.push({ url: audioPreloadStatus.four.url, name: "API4-第四个", order: 4 }); + audioItems.push({ + url: audioPreloadStatus.four.url, + name: "API4-第四个", + order: 4, + }); } // 按顺序排序并添加到队列 audioItems.sort((a, b) => a.order - b.order); audioQueue.value = audioItems; - console.log('队列重建完成,队列内容:', audioQueue.value.map(item => item.name)); - console.log('开始从第一个音频播放'); + console.log( + "队列重建完成,队列内容:", + audioQueue.value.map((item) => item.name) + ); + console.log("开始从第一个音频播放"); // 重置播放状态并开始播放第一个音频 if (audioQueue.value.length > 0) { @@ -1053,37 +1220,47 @@ watch( audioStore.nowSound = null; audioStore.soundInstance = null; - console.log('🔄 状态完全重置完成,准备从第一个音频开始播放'); + console.log("🔄 状态完全重置完成,准备从第一个音频开始播放"); - console.log('✅ 完全重置播放状态,准备播放第一个音频'); - console.log('重置后状态检查:', { + console.log("✅ 完全重置播放状态,准备播放第一个音频"); + console.log("重置后状态检查:", { isPlayingAudio: isPlayingAudio.value, isCallingPlayNext: isCallingPlayNext, currentPlayIndex: currentPlayIndex, audioStoreIsPlaying: audioStore.isPlaying, - queueLength: audioQueue.value.length + queueLength: audioQueue.value.length, }); setTimeout(() => { - console.log('🚀 延迟后开始播放第一个音频'); - console.log('播放前最终状态检查:', { + console.log("🚀 延迟后开始播放第一个音频"); + console.log("播放前最终状态检查:", { currentPlayIndex: currentPlayIndex, queueLength: audioQueue.value.length, - queueItems: audioQueue.value.map((item, index) => `${index}: ${item.name}`), + queueItems: audioQueue.value.map( + (item, index) => `${index}: ${item.name}` + ), isPlayingAudio: isPlayingAudio.value, isCallingPlayNext: isCallingPlayNext, audioStoreIsPlaying: audioStore.isPlaying, - audioStoreInstance: !!audioStore.soundInstance + audioStoreInstance: !!audioStore.soundInstance, }); - console.log('🎯 即将调用 playNextAudio,期望播放:', audioQueue.value[currentPlayIndex]?.name || '无音频'); + console.log( + "🎯 即将调用 playNextAudio,期望播放:", + audioQueue.value[currentPlayIndex]?.name || "无音频" + ); playNextAudio(); }, 200); } } else if (!isPlayingAudio.value && audioQueue.value.length > 0) { - console.log('队列中还有音频,继续播放'); + console.log("队列中还有音频,继续播放"); playNextAudio(); } else { - console.log('无法播放 - isPlayingAudio:', isPlayingAudio.value, '队列长度:', audioQueue.value.length); + console.log( + "无法播放 - isPlayingAudio:", + isPlayingAudio.value, + "队列长度:", + audioQueue.value.length + ); } } }; @@ -1116,7 +1293,7 @@ watch( audioPreloadStatus[apiKey].loaded = true; // 标记为已处理,避免阻塞 // URL已经在上面设置了,即使预加载失败也保留URL resolve(); - } + }, }); }); }; @@ -1132,12 +1309,18 @@ watch( if (canStartFirstOutput() && !apiStatus.one.executed) { if (apiStatus.one.result) { apiStatus.one.executed = true; - console.log("执行OneAPI代码(文本和音频同步开始):", apiStatus.one.result); + console.log( + "执行OneAPI代码(文本和音频同步开始):", + apiStatus.one.result + ); // 将第一个音频添加到播放队列(确保顺序:API1) if (audioPreloadStatus.one.url) { addToAudioQueue(audioPreloadStatus.one.url, "API1-第一个"); - console.log("音频队列:添加API1音频,当前队列长度:", audioQueue.value.length); + console.log( + "音频队列:添加API1音频,当前队列长度:", + audioQueue.value.length + ); } // 在这里添加OneAPI成功后需要执行的代码 @@ -1166,10 +1349,10 @@ watch( const pc1 = marked( result21.data.name + - "\n" + - result21.data.price + - "\n" + - result21.data.date + "\n" + + result21.data.price + + "\n" + + result21.data.date ); const ac1 = pc1.replace(katexRegex, (match, formula) => { try { @@ -1212,170 +1395,179 @@ watch( // content: ac1, // }); // 添加六色罗盘 - const LiuSeData = JSON.parse(JSON.stringify(toRaw(HomePage))); - const sz = fnGetData(LiuSeData); - if (sz) { - hasValidData.value = true; - console.log("hasValidData设置为:", hasValidData.value); + if (HomePage) { + const LiuSeData = JSON.parse(JSON.stringify(toRaw(HomePage))); + const sz = fnGetData(LiuSeData); + if (sz) { + hasValidData.value = true; + console.log("hasValidData设置为:", hasValidData.value); + } + // 先推送K线图消息 + const klineMessageId1 = `kline-${Date.now()}`; + console.log("生成K线消息ID:", klineMessageId1); + + addTypingTask( + { + sender: "ai", + class: "content1", + type: "content1", + kline: true, + chartData: sz, + messageId: klineMessageId1, + hasValidData: true, + klineType: 1, + }, + "", + 50 + ); + // chatStore.messages.push({ + // sender: "ai", + // class: "content1", + // type: "content1", + // kline: true, + // chartData: sz, + // messageId: klineMessageId1, + // hasValidData: true, + // klineType: 1, + // }); + + // console.log("六色罗盘消息已添加到聊天列表"); + + // // 在渲染完成后初始化图表 + // nextTick(() => { + // console.log("nextTick开始 - 准备渲染图表"); + // console.log("消息列表:", chatStore.messages); + + // // 寻找最新添加的K线消息索引 + // let klineIndex = -1; + // for (let i = 0; i < chatStore.messages.length; i++) { + // if (chatStore.messages[i].messageId === klineMessageId1) { + // klineIndex = i; + // break; + // } + // } + + // console.log("找到的K线消息索引:", klineIndex); + + // if (klineIndex !== -1) { + // const containerId = `kline-container-${klineIndex}`; + // console.log("图表容器ID:", containerId); + + // // 确保DOM已经渲染完成 + // setTimeout(() => { + // console.log("延时执行,确保DOM已渲染"); + // KlineCanvsEcharts(containerId); + // }, 100); // 短暂延时确保DOM已渲染 + // } else { + // console.warn("未找到K线消息"); + // } + // }); } - // 先推送K线图消息 - const klineMessageId1 = `kline-${Date.now()}`; - console.log("生成K线消息ID:", klineMessageId1); - - addTypingTask( - { - sender: "ai", - class: "content1", - type: "content1", - kline: true, - chartData: sz, - messageId: klineMessageId1, - hasValidData: true, - klineType: 1, - }, - "", - 50 - ); - // chatStore.messages.push({ - // sender: "ai", - // class: "content1", - // type: "content1", - // kline: true, - // chartData: sz, - // messageId: klineMessageId1, - // hasValidData: true, - // klineType: 1, - // }); - - // console.log("六色罗盘消息已添加到聊天列表"); - - // // 在渲染完成后初始化图表 - // nextTick(() => { - // console.log("nextTick开始 - 准备渲染图表"); - // console.log("消息列表:", chatStore.messages); - - // // 寻找最新添加的K线消息索引 - // let klineIndex = -1; - // for (let i = 0; i < chatStore.messages.length; i++) { - // if (chatStore.messages[i].messageId === klineMessageId1) { - // klineIndex = i; - // break; - // } - // } - - // console.log("找到的K线消息索引:", klineIndex); - - // if (klineIndex !== -1) { - // const containerId = `kline-container-${klineIndex}`; - // console.log("图表容器ID:", containerId); - - // // 确保DOM已经渲染完成 - // setTimeout(() => { - // console.log("延时执行,确保DOM已渲染"); - // KlineCanvsEcharts(containerId); - // }, 100); // 短暂延时确保DOM已渲染 - // } else { - // console.warn("未找到K线消息"); - // } - // }); - // 度牛尺K线图 - const AIGoldBullData = JSON.parse( - JSON.stringify(toRaw(AIGoldBull)) - ); - const HomePageData = JSON.parse( - JSON.stringify(toRaw(HomePage)) - ); - console.log("处理 K 线数据 - 开始"); - console.log("AIGoldBullData", AIGoldBullData); - console.log("HomePageData", HomePageData); - - const Kline20 = { - name: HomePageData.StockInformation.Name, - Kline: AIGoldBullData, - }; - - // 打印K线数据结构 - console.log("K线数据结构:", Kline20); - console.log("K线数据名称:", Kline20.name); - console.log("K线数据:", Kline20.Kline ? Kline20.Kline : null); - - // 设置数据有效标志 - hasValidData.value = true; - console.log("hasValidData设置为:", hasValidData.value); - - // chatStore.messages.pop(); - - // 先推送K线图消息 - const klineMessageId2 = `kline-${Date.now() + 1}`; - console.log("生成K线消息ID:", klineMessageId2); - - // chatStore.messages.push({ - // sender: "ai", - // class: "content2", - // type: "content2", - // kline: true, - // chartData: Kline20, - // messageId: klineMessageId2, - // hasValidData: true, // 添加hasValidData标志 - // klineType: 2, - // }); - - addTypingTask( - { - sender: "ai", - class: "content2", - type: "content2", - kline: true, - chartData: Kline20, - messageId: klineMessageId2, - hasValidData: true, // 添加hasValidData标志 - klineType: 2, - error: apiStatus.two.error ? '2' : '', - isEnd: '1', - }, - "", - 50 - ); - - // console.log("K线消息已添加到聊天列表"); - - // // 在渲染完成后初始化图表 - // nextTick(() => { - // console.log("nextTick开始 - 准备渲染图表"); - // console.log("消息列表:", chatStore.messages); - - // // 寻找最新添加的K线消息索引 - // let klineIndex = -1; - // for (let i = 0; i < chatStore.messages.length; i++) { - // if (chatStore.messages[i].messageId === klineMessageId2) { - // klineIndex = i; - // break; - // } - // } - - // console.log("找到的K线消息索引:", klineIndex); - - // if (klineIndex !== -1) { - // const containerId = `kline-container-${klineIndex}`; - // console.log("图表容器ID:", containerId); + if ( + AIGoldBull.DNC && + AIGoldBull.FCX && + AIGoldBull.JN && + AIGoldBull.KLine20 && + AIGoldBull.QSXH + ) { + const AIGoldBullData = JSON.parse( + JSON.stringify(toRaw(AIGoldBull)) + ); + const HomePageData = JSON.parse( + JSON.stringify(toRaw(HomePage)) + ); + console.log("处理 K 线数据 - 开始"); + console.log("AIGoldBullData", AIGoldBullData); + console.log("HomePageData", HomePageData); + + const Kline20 = { + name: HomePageData.StockInformation.Name, + Kline: AIGoldBullData, + }; + + // 打印K线数据结构 + console.log("K线数据结构:", Kline20); + console.log("K线数据名称:", Kline20.name); + console.log("K线数据:", Kline20.Kline ? Kline20.Kline : null); + + // 设置数据有效标志 + hasValidData.value = true; + console.log("hasValidData设置为:", hasValidData.value); - // // 确保DOM已经渲染完成 - // setTimeout(() => { - // console.log("延时执行,确保DOM已渲染"); - // KlineCanvsEcharts(containerId); - // }, 100); // 短暂延时确保DOM已渲染 - // } else { - // console.warn("未找到K线消息"); - // } - // }); + // chatStore.messages.pop(); + + // 先推送K线图消息 + const klineMessageId2 = `kline-${Date.now() + 1}`; + console.log("生成K线消息ID:", klineMessageId2); + + // chatStore.messages.push({ + // sender: "ai", + // class: "content2", + // type: "content2", + // kline: true, + // chartData: Kline20, + // messageId: klineMessageId2, + // hasValidData: true, // 添加hasValidData标志 + // klineType: 2, + // }); + + addTypingTask( + { + sender: "ai", + class: "content2", + type: "content2", + kline: true, + chartData: Kline20, + messageId: klineMessageId2, + hasValidData: true, // 添加hasValidData标志 + klineType: 2, + error: apiStatus.two.error ? "2" : "", + isEnd: "1", + }, + "", + 50 + ); + + // console.log("K线消息已添加到聊天列表"); + + // // 在渲染完成后初始化图表 + // nextTick(() => { + // console.log("nextTick开始 - 准备渲染图表"); + // console.log("消息列表:", chatStore.messages); + + // // 寻找最新添加的K线消息索引 + // let klineIndex = -1; + // for (let i = 0; i < chatStore.messages.length; i++) { + // if (chatStore.messages[i].messageId === klineMessageId2) { + // klineIndex = i; + // break; + // } + // } + + // console.log("找到的K线消息索引:", klineIndex); + + // if (klineIndex !== -1) { + // const containerId = `kline-container-${klineIndex}`; + // console.log("图表容器ID:", containerId); + + // // 确保DOM已经渲染完成 + // setTimeout(() => { + // console.log("延时执行,确保DOM已渲染"); + // KlineCanvsEcharts(containerId); + // }, 100); // 短暂延时确保DOM已渲染 + // } else { + // console.warn("未找到K线消息"); + // } + // }); + } } else { chatStore.messages.push({ class: "ing", type: "ing", flag: false, - content: '工作流返回出错,请稍后重试', - }) + content: "工作流返回出错,请稍后重试", + }); chatStore.isLoading = false; } } @@ -1386,7 +1578,6 @@ watch( apiStatus.two.completed && !apiStatus.two.executed ) { - if (apiStatus.two.result) { apiStatus.two.executed = true; console.log("执行TwoAPI代码:", apiStatus.two.result); @@ -1394,7 +1585,10 @@ watch( // 将第二个音频添加到播放队列(确保顺序:API2) if (audioPreloadStatus.two.url) { addToAudioQueue(audioPreloadStatus.two.url, "API2-第二个"); - console.log("音频队列:添加API2音频,当前队列长度:", audioQueue.value.length); + console.log( + "音频队列:添加API2音频,当前队列长度:", + audioQueue.value.length + ); } // 在这里添加TwoAPI成功后需要执行的代码 @@ -1436,8 +1630,8 @@ watch( type: "content3", content: "", isTyping: true, - error: apiStatus.three.error ? '3' : '', - isEnd: '2' + error: apiStatus.three.error ? "3" : "", + isEnd: "2", }); // chatStore.messages.push(aiMessage2); @@ -1460,15 +1654,19 @@ watch( // content: ac2, // }); } else { - console.log('1111111111111111111') - if (apiStatus.one.isEnd && apiStatus.two.error && !apiStatus.two.isError) { - apiStatus.two.isError = true + console.log("1111111111111111111"); + if ( + apiStatus.one.isEnd && + apiStatus.two.error && + !apiStatus.two.isError + ) { + apiStatus.two.isError = true; chatStore.messages.push({ class: "ing", type: "ing", flag: false, - content: '工作流返回出错,请稍后重试', - }) + content: "工作流返回出错,请稍后重试", + }); chatStore.isLoading = false; } } @@ -1480,7 +1678,6 @@ watch( apiStatus.three.completed && !apiStatus.three.executed ) { - if (apiStatus.three.result) { apiStatus.three.executed = true; console.log("执行ThreeAPI代码:", apiStatus.three.result); @@ -1488,7 +1685,10 @@ watch( // 将第三个音频添加到播放队列(确保顺序:API3) if (audioPreloadStatus.three.url) { addToAudioQueue(audioPreloadStatus.three.url, "API3-第三个"); - console.log("音频队列:添加API3音频,当前队列长度:", audioQueue.value.length); + console.log( + "音频队列:添加API3音频,当前队列长度:", + audioQueue.value.length + ); } // 在这里添加ThreeAPI成功后需要执行的代码 @@ -1585,7 +1785,7 @@ watch( const ac44 = `${arr[2]},${arr[3]}

`; const ac45 = `

【时间维度】

`; const ac46 = `${result23.data.shijian}

`; - const ac47 = `

【能量维度】

`; + const ac47 = `

【能量维度】

`; const ac48 = `${result23.data.nengliang}

`; // const pc4 = marked( @@ -1611,8 +1811,8 @@ watch( type: "content3", content: "", isTyping: true, - error: apiStatus.four.error ? '4' : '', - isEnd: '3' + error: apiStatus.four.error ? "4" : "", + isEnd: "3", }); // chatStore.messages.push(aiMessage4); @@ -1640,14 +1840,18 @@ watch( // content: ac4, // }); } else { - if (apiStatus.two.isEnd && apiStatus.three.error && !apiStatus.three.isError) { + if ( + apiStatus.two.isEnd && + apiStatus.three.error && + !apiStatus.three.isError + ) { apiStatus.three.isError = true; chatStore.messages.push({ class: "ing", type: "ing", flag: false, - content: '工作流返回出错,请稍后重试1111', - }) + content: "工作流返回出错,请稍后重试1111", + }); chatStore.isLoading = false; } } @@ -1659,7 +1863,6 @@ watch( apiStatus.four.completed && !apiStatus.four.executed ) { - if (apiStatus.four.result) { apiStatus.four.executed = true; console.log("执行FourAPI代码:", apiStatus.four.result); @@ -1667,7 +1870,10 @@ watch( // 将第四个音频添加到播放队列(确保顺序:API4) if (audioPreloadStatus.four.url) { addToAudioQueue(audioPreloadStatus.four.url, "API4-第四个"); - console.log("音频队列:添加API4音频,当前队列长度:", audioQueue.value.length); + console.log( + "音频队列:添加API4音频,当前队列长度:", + audioQueue.value.length + ); } // 在这里添加FourAPI成功后需要执行的代码 @@ -1744,7 +1950,7 @@ watch( type: "mianze", content: "", isTyping: true, - end: true + end: true, }); // chatStore.messages.push(aiMessage6); @@ -1766,16 +1972,20 @@ watch( // class: "mianze", // type: "mianze", // content: "内容由AI生成,请注意甄别", - // }); + // }); } else { - if (apiStatus.three.isEnd && apiStatus.four.error && !apiStatus.four.isError) { + if ( + apiStatus.three.isEnd && + apiStatus.four.error && + !apiStatus.four.isError + ) { apiStatus.four.isError = true; chatStore.messages.push({ class: "ing", type: "ing", flag: false, - content: '工作流返回出错,请稍后重试', - }) + content: "工作流返回出错,请稍后重试", + }); chatStore.isLoading = false; } } @@ -1796,19 +2006,31 @@ watch( console.log("audioPreloadStatus:", audioPreloadStatus); if (audioPreloadStatus.one.url) { - console.log("添加预加载音频URL one:", audioPreloadStatus.one.url); + console.log( + "添加预加载音频URL one:", + audioPreloadStatus.one.url + ); audioUrls.push(audioPreloadStatus.one.url); } if (audioPreloadStatus.two.url) { - console.log("添加预加载音频URL two:", audioPreloadStatus.two.url); + console.log( + "添加预加载音频URL two:", + audioPreloadStatus.two.url + ); audioUrls.push(audioPreloadStatus.two.url); } if (audioPreloadStatus.three.url) { - console.log("添加预加载音频URL three:", audioPreloadStatus.three.url); + console.log( + "添加预加载音频URL three:", + audioPreloadStatus.three.url + ); audioUrls.push(audioPreloadStatus.three.url); } if (audioPreloadStatus.four.url) { - console.log("添加预加载音频URL four:", audioPreloadStatus.four.url); + console.log( + "添加预加载音频URL four:", + audioPreloadStatus.four.url + ); audioUrls.push(audioPreloadStatus.four.url); } @@ -1830,7 +2052,7 @@ watch( // 预加载第一个接口的音频 if (result21?.data?.url) { - await preloadAudio(result21.data.url.trim(), 'one'); + await preloadAudio(result21.data.url.trim(), "one"); } else { audioPreloadStatus.one.loaded = true; } @@ -1857,7 +2079,7 @@ watch( // 预加载第二个接口的音频 if (result22?.data?.url) { - await preloadAudio(result22.data.url.trim(), 'two'); + await preloadAudio(result22.data.url.trim(), "two"); } else { audioPreloadStatus.two.loaded = true; } @@ -1870,7 +2092,6 @@ watch( apiStatus.two.error = error; audioPreloadStatus.two.loaded = true; checkAndExecuteInOrder(); - } }; @@ -1886,7 +2107,7 @@ watch( // 预加载第三个接口的音频 if (result23?.data?.url) { - await preloadAudio(result23.data.url.trim(), 'three'); + await preloadAudio(result23.data.url.trim(), "three"); } else { audioPreloadStatus.three.loaded = true; } @@ -1912,7 +2133,7 @@ watch( // 预加载第四个接口的音频 if (result24?.data?.url) { - await preloadAudio(result24.data.url.trim(), 'four'); + await preloadAudio(result24.data.url.trim(), "four"); } else { audioPreloadStatus.four.loaded = true; } @@ -1925,14 +2146,24 @@ watch( apiStatus.four.error = error; audioPreloadStatus.four.loaded = true; checkAndExecuteInOrder(); - } }; - handleOneAPI(); - handleTwoAPI(); - handleThreeAPI(); - handleFourAPI(); + if (isLiuSe && isAIGoldBull) { + handleOneAPI(); + handleTwoAPI(); + handleThreeAPI(); + handleFourAPI(); + } else { + chatStore.messages.pop(); + chatStore.messages.push({ + class: "ing", + type: "ing", + flag: false, + content: "数据缺失,请稍后重试", + }); + chatStore.isLoading = false; + } // 同时发起所有API调用 // const promises = [ @@ -2211,7 +2442,7 @@ function KlineCanvsEcharts(containerId) { }, axisLabel: { show: true, - formatter: function (v) { }, + formatter: function (v) {}, textStyle: { color: "auto", }, @@ -2877,14 +3108,14 @@ function KlineCanvsEcharts(containerId) { window.innerWidth > 1024 ? "70vw" : window.innerWidth > 768 - ? "65vw" - : "55vw", + ? "65vw" + : "55vw", right: window.innerWidth > 1024 ? "40vw" : window.innerWidth > 768 - ? "30vw" - : "40vw", + ? "30vw" + : "40vw", top: window.innerWidth > 768 ? "8%" : "5%", height: window.innerWidth > 768 ? "34%" : "34%", containLabel: false, @@ -2894,14 +3125,14 @@ function KlineCanvsEcharts(containerId) { window.innerWidth > 1024 ? "70vw" : window.innerWidth > 768 - ? "65vw" - : "55vw", + ? "65vw" + : "55vw", right: window.innerWidth > 1024 ? "40vw" : window.innerWidth > 768 - ? "30vw" - : "40vw", + ? "30vw" + : "40vw", top: window.innerWidth > 768 ? "45%" : "42%", height: window.innerWidth > 768 ? "22%" : "22%", containLabel: false, @@ -2911,14 +3142,14 @@ function KlineCanvsEcharts(containerId) { window.innerWidth > 1024 ? "70vw" : window.innerWidth > 768 - ? "65vw" - : "55vw", + ? "65vw" + : "55vw", right: window.innerWidth > 1024 ? "40vw" : window.innerWidth > 768 - ? "30vw" - : "40vw", + ? "30vw" + : "40vw", top: window.innerWidth > 768 ? "73%" : "70%", height: window.innerWidth > 768 ? "20%" : "22%", containLabel: false, @@ -3778,11 +4009,15 @@ onUnmounted(() => { 夺宝奇兵大模型logo -
+
@@ -3853,8 +4088,7 @@ onUnmounted(() => { \ No newline at end of file diff --git a/src/views/homePage.vue b/src/views/homePage.vue index 1a491e5..1d64fc1 100644 --- a/src/views/homePage.vue +++ b/src/views/homePage.vue @@ -1,6 +1,6 @@