diff --git a/src/views/AIchat.vue b/src/views/AIchat.vue index 8085cf8..fc22c7e 100644 --- a/src/views/AIchat.vue +++ b/src/views/AIchat.vue @@ -24,14 +24,6 @@ import { Howl, Howler } from "howler"; import * as echarts from "echarts"; import _, { add } from "lodash"; import moment from "moment"; - -import AIgif1 from "@/assets/img/AIchat/AIgif1.gif"; -import AIgif2 from "@/assets/img/AIchat/AIgif2.gif"; -import AIgif3 from "@/assets/img/AIchat/AIgif3.gif"; -import AIgif4 from "@/assets/img/AIchat/AIgif4.gif"; -import AIgif5 from "@/assets/img/AIchat/AIgif5.gif"; -import AIgif6 from "@/assets/img/AIchat/AIgif6.gif"; -import AIgif7 from "@/assets/img/AIchat/AIgif7.gif"; import title1 from "@/assets/img/AIchat/核心价值评估标题.png"; import title2 from "@/assets/img/AIchat/主力作战.png"; import title3 from "@/assets/img/AIchat/攻防三维.png"; @@ -39,7 +31,6 @@ import title4 from "@/assets/img/AIchat/综合作战.png"; import logo1 from "@/assets/img/AIchat/夺宝奇兵logo.png"; import logo2 from "@/assets/img/AIchat/开启无限财富.png"; -const gifList = [AIgif1, AIgif2, AIgif3, AIgif4, AIgif5, AIgif6, AIgif7]; const chatStore = useChatStore(); const audioStore = useAudioStore(); const dataStore = useDataStore(); @@ -154,7 +145,7 @@ const playAudioSequence = (audioUrls) => { } let currentIndex = 0; - + const playNext = () => { if (currentIndex >= audioUrls.length) { console.log("所有音频播放完成"); @@ -163,7 +154,7 @@ const playAudioSequence = (audioUrls) => { const currentUrl = audioUrls[currentIndex]; console.log(`正在播放第${currentIndex + 1}个音频:`, currentUrl); - + // 停止当前播放的音频 if (audioStore.nowSound) { audioStore.nowSound.stop(); @@ -197,7 +188,7 @@ const playAudioSequence = (audioUrls) => { setTimeout(() => { playNext(); }, 100); - } + }, }); audioStore.nowSound = sound; @@ -552,524 +543,712 @@ watch( const HomePage = result20.data.HomePage; const AIGoldBull = result20.data.AIGoldBull; - const result21 = await dbqbSecondOneAPI(params2); - const result22 = await dbqbSecondTwoAPI(params2); - const result23 = await dbqbSecondThreeAPI(params2); - const result24 = await dbqbSecondFourAPI(params2); - - // 收集所有音频URL - const audioUrls = []; - if (result21.data.url) audioUrls.push(result21.data.url.trim()); - if (result22.data.url) audioUrls.push(result22.data.url.trim()); - if (result23.data.url) audioUrls.push(result23.data.url.trim()); - if (result24.data.url) audioUrls.push(result24.data.url.trim()); - - // 开始轮流播放音频 - if (audioUrls.length > 0 && audioStore.isVoiceEnabled) { - playAudioSequence(audioUrls); - } - const katexRegex = /\$\$(.*?)\$\$/g; - // 删除正在为您生成信息 - chatStore.messages.pop(); - // 添加报告头和时间 - addTypingTask( - { - sender: "ai", - class: "title1", - type: "title1", - content: codeData.value.name + "全景作战报告", - date: moment().format("MM/DD/YYYY"), - }, - "", - 50 - ); - // chatStore.messages.push({ - // sender: "ai", - // class: "title1", - // type: "title1", - // content: codeData.value.name + "全景作战报告", - // date: moment().format("MM/DD/YYYY"), - // }); - // 添加股票信息框 - - const pc1 = marked( - result21.data.name + - "\n" + - result21.data.price + - "\n" + - result21.data.date - ); - const ac1 = pc1.replace(katexRegex, (match, formula) => { - try { - return katex.renderToString(formula, { throwOnError: false }); - } catch (error) { - console.error("KaTeX 渲染错误:", error); - return match; - } - }); - - // 先推送初始消息 - const aiMessage1 = reactive({ - sender: "ai", - class: "content1", - type: "content1", - content: "", - isTyping: true, - }); - // chatStore.messages.push(aiMessage1); - - // let index1 = 0; - // const typingInterval1 = setInterval(() => { - // if (index1 < ac1.length) { - // aiMessage1.content += ac1.charAt(index1); - // index1++; - // } else { - // clearInterval(typingInterval1); - // aiMessage1.isTyping = false; - // } - // }, 50); // 调整速度为50ms/字符 - - addTypingTask(aiMessage1, ac1, 50); - - // chatStore.messages.push({ - // sender: "ai", - // class: "content1", - // type: "content1", - // content: ac1, - // }); - // 添加六色罗盘 - 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 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, + let result21; + let result22; + let result23; + let result24; + // 用于跟踪API完成状态和结果 + const apiStatus = { + one: { completed: false, result: null, error: null }, + two: { completed: false, result: null, error: null }, + three: { completed: false, result: null, error: null }, + four: { completed: false, result: null, error: null }, }; - // 打印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, - }, - "", - 50 - ); - - // console.log("K线消息已添加到聊天列表"); + // 检查并按顺序执行代码的函数 + const checkAndExecuteInOrder = () => { + // 检查OneAPI + if (apiStatus.one.completed && !apiStatus.one.executed) { + apiStatus.one.executed = true; + if (apiStatus.one.result) { + console.log("执行OneAPI代码:", apiStatus.one.result); + // 在这里添加OneAPI成功后需要执行的代码 + // 删除正在为您生成信息 + chatStore.messages.pop(); + // 添加报告头和时间 + addTypingTask( + { + sender: "ai", + class: "title1", + type: "title1", + content: codeData.value.name + "全景作战报告", + date: moment().format("MM/DD/YYYY"), + }, + "", + 50 + ); + // chatStore.messages.push({ + // sender: "ai", + // class: "title1", + // type: "title1", + // content: codeData.value.name + "全景作战报告", + // date: moment().format("MM/DD/YYYY"), + // }); + // 添加股票信息框 + + const pc1 = marked( + result21.data.name + + "\n" + + result21.data.price + + "\n" + + result21.data.date + ); + const ac1 = pc1.replace(katexRegex, (match, formula) => { + try { + return katex.renderToString(formula, { + throwOnError: false, + }); + } catch (error) { + console.error("KaTeX 渲染错误:", error); + return match; + } + }); + + // 先推送初始消息 + const aiMessage1 = reactive({ + sender: "ai", + class: "content1", + type: "content1", + content: "", + isTyping: true, + }); + // chatStore.messages.push(aiMessage1); + + // let index1 = 0; + // const typingInterval1 = setInterval(() => { + // if (index1 < ac1.length) { + // aiMessage1.content += ac1.charAt(index1); + // index1++; + // } else { + // clearInterval(typingInterval1); + // aiMessage1.isTyping = false; + // } + // }, 50); // 调整速度为50ms/字符 + + addTypingTask(aiMessage1, ac1, 50); + + // chatStore.messages.push({ + // sender: "ai", + // class: "content1", + // type: "content1", + // content: ac1, + // }); + // 添加六色罗盘 + 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 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, + }, + "", + 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线消息"); + // } + // }); + } + } - // // 在渲染完成后初始化图表 - // nextTick(() => { - // console.log("nextTick开始 - 准备渲染图表"); - // console.log("消息列表:", chatStore.messages); + // 检查TwoAPI(需要OneAPI已执行) + if ( + apiStatus.one.executed && + apiStatus.two.completed && + !apiStatus.two.executed + ) { + apiStatus.two.executed = true; + if (apiStatus.two.result) { + console.log("执行TwoAPI代码:", apiStatus.two.result); + // 在这里添加TwoAPI成功后需要执行的代码 + // 添加标题2 + addTypingTask( + { + sender: "ai", + class: "title2", + type: "title2", + content: "", + }, + "", + 50 + ); + // chatStore.messages.push({ + // sender: "ai", + // class: "title2", + // type: "title2", + // content: "", + // }); + // 添加内容框1 + const pc2 = marked(result22.data.hxjzpg); + console.log(pc2, "pc2"); + const ac2 = pc2.replace(katexRegex, (match, formula) => { + try { + return katex.renderToString(formula, { + throwOnError: false, + }); + } catch (error) { + console.error("KaTeX 渲染错误:", error); + return match; + } + }); + + // 先推送初始消息 + const aiMessage2 = reactive({ + sender: "ai", + class: "content3", + type: "content3", + content: "", + isTyping: true, + }); + // chatStore.messages.push(aiMessage2); + + // let index2 = 0; + // const typingInterval2 = setInterval(() => { + // if (index2 < ac2.length) { + // aiMessage2.content += ac2.charAt(index2); + // index2++; + // } else { + // clearInterval(typingInterval2); + // aiMessage2.isTyping = false; + // } + // }, 50); // 调整速度为50ms/字符 + addTypingTask(aiMessage2, ac2, 50); + + // chatStore.messages.push({ + // sender: "ai", + // class: "content3", + // type: "content3", + // content: ac2, + // }); + } + } - // // 寻找最新添加的K线消息索引 - // let klineIndex = -1; - // for (let i = 0; i < chatStore.messages.length; i++) { - // if (chatStore.messages[i].messageId === klineMessageId2) { - // klineIndex = i; - // break; - // } - // } + // 检查ThreeAPI(需要TwoAPI已执行) + if ( + apiStatus.two.executed && + apiStatus.three.completed && + !apiStatus.three.executed + ) { + apiStatus.three.executed = true; + if (apiStatus.three.result) { + console.log("执行ThreeAPI代码:", apiStatus.three.result); + // 在这里添加ThreeAPI成功后需要执行的代码 + // 添加标题3-2 + addTypingTask( + { + sender: "ai", + class: "title3", + type: "title3", + content: title2, + }, + "", + 50 + ); + // chatStore.messages.push({ + // sender: "ai", + // class: "title3", + // type: "title3", + // content: title2, + // }); + // 添加内容框2 + // const pc3 = marked(result23.data.zhuli1+'\n'+result23.data.zhuli2+'\n'+result23.data.zhuli3); + // const ac3 = pc3.replace( + // katexRegex, + // (match, formula) => { + // try { + // return katex.renderToString(formula, { throwOnError: false }); + // } catch (error) { + // console.error("KaTeX 渲染错误:", error); + // return match; + // } + // } + // ); + const ac3 = `

【主力行为】

${result23.data.zhuli1}

${result23.data.zhuli2}

${result23.data.zhuli3}

`; + + // 先推送初始消息 + const aiMessage3 = reactive({ + sender: "ai", + class: "content3", + type: "content3", + content: "", + isTyping: true, + }); + // chatStore.messages.push(aiMessage3); + + // let index3 = 0; + // const typingInterval3 = setInterval(() => { + // if (index3 < ac3.length) { + // aiMessage3.content += ac3.charAt(index3); + // index3++; + // } else { + // clearInterval(typingInterval3); + // aiMessage3.isTyping = false; + + // } + // }, 50); // 调整速度为50ms/字符 + addTypingTask(aiMessage3, ac3, 50); + + // chatStore.messages.push({ + // sender: "ai", + // class: "content3", + // type: "content3", + // content: ac3, + // }); + // 添加标题3-3 + addTypingTask( + { + sender: "ai", + class: "title3", + type: "title3", + content: title3, + }, + "", + 50 + ); + // chatStore.messages.push({ + // sender: "ai", + // class: "title3", + // type: "title3", + // content: title3, + // }); + // 添加内容框3 + const arr = result23.data.kongjian.split(","); + const kongjian = `

【空间维度】

${arr[0]},${arr[1]}

${arr[2]},${arr[3]}

`; + const shijian = `

【时间维度】

${result23.data.shijian}

`; + const nengliang = `

【能量维度】

${result23.data.nengliang}

`; + const ac4 = kongjian + shijian + nengliang; + + // const pc4 = marked( + // kongjian + + // "\n" + + // result23.data.shijian + + // "\n" + + // result23.data.nengliang + // ); + // const ac4 = pc4.replace(katexRegex, (match, formula) => { + // try { + // return katex.renderToString(formula, { throwOnError: false }); + // } catch (error) { + // console.error("KaTeX 渲染错误:", error); + // return match; + // } + // }); + + // 先推送初始消息 + const aiMessage4 = reactive({ + sender: "ai", + class: "content3", + type: "content3", + content: "", + isTyping: true, + }); + // chatStore.messages.push(aiMessage4); + + // let index4 = 0; + // const typingInterval4 = setInterval(() => { + // if (index4 < ac4.length) { + // aiMessage4.content += ac4.charAt(index4); + // index4++; + // } else { + // clearInterval(typingInterval4); + // aiMessage4.isTyping = false; + + // } + // }, 50); // 调整速度为50ms/字符 + addTypingTask(aiMessage4, ac4, 50); + + // chatStore.messages.push({ + // sender: "ai", + // class: "content3", + // type: "content3", + // content: ac4, + // }); + } + } - // console.log("找到的K线消息索引:", klineIndex); + // 检查FourAPI(需要ThreeAPI已执行) + if ( + apiStatus.three.executed && + apiStatus.four.completed && + !apiStatus.four.executed + ) { + apiStatus.four.executed = true; + if (apiStatus.four.result) { + console.log("执行FourAPI代码:", apiStatus.four.result); + // 在这里添加FourAPI成功后需要执行的代码 + // 添加标题3-4 + addTypingTask( + { + sender: "ai", + class: "title3", + type: "title3", + content: title4, + }, + "", + 50 + ); + // chatStore.messages.push({ + // sender: "ai", + // class: "title3", + // type: "title3", + // content: title4, + // }); + // 添加内容框4 + const cftj = `

【触发条件】

${result24.data.cftl}

`; + const gfzl = `

【攻防指令】

${result24.data.gfzl}

`; + const ac5 = cftj + gfzl; + + // const pc5 = marked(result24.data.cftl + "/n" + result24.data.gfzl); + // const ac5 = pc5.replace(katexRegex, (match, formula) => { + // try { + // return katex.renderToString(formula, { throwOnError: false }); + // } catch (error) { + // console.error("KaTeX 渲染错误:", error); + // return match; + // } + // }); + + // 先推送初始消息 + const aiMessage5 = reactive({ + sender: "ai", + class: "content3", + type: "content3", + content: "", + isTyping: true, + }); + // chatStore.messages.push(aiMessage5); + + // let index5 = 0; + // const typingInterval5 = setInterval(() => { + // if (index5 < ac5.length) { + // aiMessage5.content += ac5.charAt(index5); + // index5++; + // } else { + // clearInterval(typingInterval5); + // aiMessage5.isTyping = false; + + // } + // }, 50); // 调整速度为50ms/字符 + addTypingTask(aiMessage5, ac5, 50); + + // chatStore.messages.push({ + // sender: "ai", + // class: "content3", + // type: "content3", + // content: ac5, + // }); + + const ac6 = "内容由AI生成,请注意甄别"; + // 先推送初始消息 + const aiMessage6 = reactive({ + sender: "ai", + class: "mianze", + type: "mianze", + content: "", + isTyping: true, + }); + // chatStore.messages.push(aiMessage6); + + // let index6 = 0; + // const typingInterval6 = setInterval(() => { + // if (index6 < ac6.length) { + // aiMessage6.content += ac6.charAt(index6); + // index6++; + // } else { + // clearInterval(typingInterval6); + // aiMessage6.isTyping = false; + + // } + // }, 50); // 调整速度为50ms/字符 + addTypingTask(aiMessage6, ac6, 100); + + // chatStore.messages.push({ + // sender: "ai", + // class: "mianze", + // type: "mianze", + // content: "内容由AI生成,请注意甄别", + // }); + } + } + }; - // if (klineIndex !== -1) { - // const containerId = `kline-container-${klineIndex}`; - // console.log("图表容器ID:", containerId); + const handleOneAPI = async () => { + try { + result21 = await dbqbSecondOneAPI(params2); + console.log("OneAPI成功返回:", result21); - // // 确保DOM已经渲染完成 - // setTimeout(() => { - // console.log("延时执行,确保DOM已渲染"); - // KlineCanvsEcharts(containerId); - // }, 100); // 短暂延时确保DOM已渲染 - // } else { - // console.warn("未找到K线消息"); - // } - // }); + apiStatus.one.completed = true; + apiStatus.one.result = result21; - // 添加标题2 - addTypingTask( - { - sender: "ai", - class: "title2", - type: "title2", - content: "", - }, - "", - 50 - ); - // chatStore.messages.push({ - // sender: "ai", - // class: "title2", - // type: "title2", - // content: "", - // }); - // 添加内容框1 - const pc2 = marked(result22.data.hxjzpg); - console.log(pc2, "pc2"); - const ac2 = pc2.replace(katexRegex, (match, formula) => { - try { - return katex.renderToString(formula, { throwOnError: false }); + // 检查是否可以执行 + checkAndExecuteInOrder(); } catch (error) { - console.error("KaTeX 渲染错误:", error); - return match; + console.error("OneAPI失败:", error); + apiStatus.one.completed = true; + apiStatus.one.error = error; + // 即使失败也要检查后续执行 + checkAndExecuteInOrder(); } - }); - - // 先推送初始消息 - const aiMessage2 = reactive({ - sender: "ai", - class: "content3", - type: "content3", - content: "", - isTyping: true, - }); - // chatStore.messages.push(aiMessage2); - - // let index2 = 0; - // const typingInterval2 = setInterval(() => { - // if (index2 < ac2.length) { - // aiMessage2.content += ac2.charAt(index2); - // index2++; - // } else { - // clearInterval(typingInterval2); - // aiMessage2.isTyping = false; - // } - // }, 50); // 调整速度为50ms/字符 - addTypingTask(aiMessage2, ac2, 50); + }; - // chatStore.messages.push({ - // sender: "ai", - // class: "content3", - // type: "content3", - // content: ac2, - // }); - // 添加标题3-2 - addTypingTask( - { - sender: "ai", - class: "title3", - type: "title3", - content: title2, - }, - "", - 50 - ); - // chatStore.messages.push({ - // sender: "ai", - // class: "title3", - // type: "title3", - // content: title2, - // }); - // 添加内容框2 - // const pc3 = marked(result23.data.zhuli1+'\n'+result23.data.zhuli2+'\n'+result23.data.zhuli3); - // const ac3 = pc3.replace( - // katexRegex, - // (match, formula) => { - // try { - // return katex.renderToString(formula, { throwOnError: false }); - // } catch (error) { - // console.error("KaTeX 渲染错误:", error); - // return match; - // } - // } - // ); - const ac3 = `

【主力行为】

${result23.data.zhuli1}

${result23.data.zhuli2}

${result23.data.zhuli3}

`; - - // 先推送初始消息 - const aiMessage3 = reactive({ - sender: "ai", - class: "content3", - type: "content3", - content: "", - isTyping: true, - }); - // chatStore.messages.push(aiMessage3); + const handleTwoAPI = async () => { + try { + result22 = await dbqbSecondTwoAPI(params2); + console.log("TwoAPI成功返回:", result22); - // let index3 = 0; - // const typingInterval3 = setInterval(() => { - // if (index3 < ac3.length) { - // aiMessage3.content += ac3.charAt(index3); - // index3++; - // } else { - // clearInterval(typingInterval3); - // aiMessage3.isTyping = false; + apiStatus.two.completed = true; + apiStatus.two.result = result22; - // } - // }, 50); // 调整速度为50ms/字符 - addTypingTask(aiMessage3, ac3, 50); + // 检查是否可以执行 + checkAndExecuteInOrder(); + } catch (error) { + console.error("TwoAPI失败:", error); + apiStatus.two.completed = true; + apiStatus.two.error = error; + checkAndExecuteInOrder(); + } + }; - // chatStore.messages.push({ - // sender: "ai", - // class: "content3", - // type: "content3", - // content: ac3, - // }); - // 添加标题3-3 - addTypingTask( - { - sender: "ai", - class: "title3", - type: "title3", - content: title3, - }, - "", - 50 - ); - // chatStore.messages.push({ - // sender: "ai", - // class: "title3", - // type: "title3", - // content: title3, - // }); - // 添加内容框3 - const arr = result23.data.kongjian.split(","); - const kongjian = `

【空间维度】

${arr[0]},${arr[1]}

${arr[2]},${arr[3]}

`; - const shijian = `

【时间维度】

${result23.data.shijian}

`; - const nengliang = `

【能量维度】

${result23.data.nengliang}

`; - const ac4 = kongjian + shijian + nengliang; - - // const pc4 = marked( - // kongjian + - // "\n" + - // result23.data.shijian + - // "\n" + - // result23.data.nengliang - // ); - // const ac4 = pc4.replace(katexRegex, (match, formula) => { - // try { - // return katex.renderToString(formula, { throwOnError: false }); - // } catch (error) { - // console.error("KaTeX 渲染错误:", error); - // return match; - // } - // }); + const handleThreeAPI = async () => { + try { + result23 = await dbqbSecondThreeAPI(params2); + console.log("ThreeAPI成功返回:", result23); - // 先推送初始消息 - const aiMessage4 = reactive({ - sender: "ai", - class: "content3", - type: "content3", - content: "", - isTyping: true, - }); - // chatStore.messages.push(aiMessage4); + apiStatus.three.completed = true; + apiStatus.three.result = result23; - // let index4 = 0; - // const typingInterval4 = setInterval(() => { - // if (index4 < ac4.length) { - // aiMessage4.content += ac4.charAt(index4); - // index4++; - // } else { - // clearInterval(typingInterval4); - // aiMessage4.isTyping = false; + // 检查是否可以执行 + checkAndExecuteInOrder(); + } catch (error) { + console.error("ThreeAPI失败:", error); + apiStatus.three.completed = true; + apiStatus.three.error = error; + checkAndExecuteInOrder(); + } + }; - // } - // }, 50); // 调整速度为50ms/字符 - addTypingTask(aiMessage4, ac4, 50); + const handleFourAPI = async () => { + try { + result24 = await dbqbSecondFourAPI(params2); + console.log("FourAPI成功返回:", result24); - // chatStore.messages.push({ - // sender: "ai", - // class: "content3", - // type: "content3", - // content: ac4, - // }); - // 添加标题3-4 - addTypingTask( - { - sender: "ai", - class: "title3", - type: "title3", - content: title4, - }, - "", - 50 - ); - chatStore.messages.push({ - sender: "ai", - class: "title3", - type: "title3", - content: title4, - }); - // 添加内容框4 - const cftj = `

【触发条件】

${result24.data.cftl}

`; - const gfzl = `

【攻防指令】

${result24.data.gfzl}

`; - const ac5 = cftj + gfzl; - - // const pc5 = marked(result24.data.cftl + "/n" + result24.data.gfzl); - // const ac5 = pc5.replace(katexRegex, (match, formula) => { - // try { - // return katex.renderToString(formula, { throwOnError: false }); - // } catch (error) { - // console.error("KaTeX 渲染错误:", error); - // return match; - // } - // }); + apiStatus.four.completed = true; + apiStatus.four.result = result24; - // 先推送初始消息 - const aiMessage5 = reactive({ - sender: "ai", - class: "content3", - type: "content3", - content: "", - isTyping: true, - }); - // chatStore.messages.push(aiMessage5); + // 检查是否可以执行 + checkAndExecuteInOrder(); + } catch (error) { + console.error("FourAPI失败:", error); + apiStatus.four.completed = true; + apiStatus.four.error = error; + checkAndExecuteInOrder(); + } + }; - // let index5 = 0; - // const typingInterval5 = setInterval(() => { - // if (index5 < ac5.length) { - // aiMessage5.content += ac5.charAt(index5); - // index5++; - // } else { - // clearInterval(typingInterval5); - // aiMessage5.isTyping = false; + handleOneAPI(); + handleTwoAPI(); + handleThreeAPI(); + handleFourAPI(); + + // 同时发起所有API调用 + // const promises = [ + // dbqbSecondOneAPI(params2), + // dbqbSecondTwoAPI(params2), + // dbqbSecondThreeAPI(params2), + // dbqbSecondFourAPI(params2), + // ]; + // const results = await Promise.allSettled(promises); + // let result21; + // let result22; + // let result23; + // let result24; + // // 检查每个API的结果并执行相应代码 + // console + // if (results[0].status === "fulfilled") { + // result21 = results[0].value; + // // oneAPI成功返回时执行的代码 + // console.log("oneAPI成功:", result21); + // // 在这里添加你的业务逻辑 + // } - // } - // }, 50); // 调整速度为50ms/字符 - addTypingTask(aiMessage5, ac5, 50); + // if (results[1].status === "fulfilled") { + // result22 = results[1].value; + // // twoAPI成功返回时执行的代码 + // console.log("twoAPI成功:", result22); + // // 在这里添加你的业务逻辑 + // } - // chatStore.messages.push({ - // sender: "ai", - // class: "content3", - // type: "content3", - // content: ac5, - // }); + // if (results[2].status === "fulfilled") { + // result23 = results[2].value; + // // threeAPI成功返回时执行的代码 + // console.log("threeAPI成功:", result23); + // } - const ac6 = "内容由AI生成,请注意甄别"; - // 先推送初始消息 - const aiMessage6 = reactive({ - sender: "ai", - class: "mianze", - type: "mianze", - content: "", - isTyping: true, - }); - // chatStore.messages.push(aiMessage6); + // if (results[3].status === "fulfilled") { + // result24 = results[3].value; + // // fourAPI成功返回时执行的代码 + // console.log("fourAPI成功:", result24); + // } - // let index6 = 0; - // const typingInterval6 = setInterval(() => { - // if (index6 < ac6.length) { - // aiMessage6.content += ac6.charAt(index6); - // index6++; - // } else { - // clearInterval(typingInterval6); - // aiMessage6.isTyping = false; + // const result21 = await dbqbSecondOneAPI(params2); + // const result22 = await dbqbSecondTwoAPI(params2); + // const result23 = await dbqbSecondThreeAPI(params2); + // const result24 = await dbqbSecondFourAPI(params2); - // } - // }, 50); // 调整速度为50ms/字符 - addTypingTask(aiMessage6, ac6, 100); + // 收集所有音频URL + const audioUrls = []; + if (result21.data.url) audioUrls.push(result21.data.url.trim()); + if (result22.data.url) audioUrls.push(result22.data.url.trim()); + if (result23.data.url) audioUrls.push(result23.data.url.trim()); + if (result24.data.url) audioUrls.push(result24.data.url.trim()); - // chatStore.messages.push({ - // sender: "ai", - // class: "mianze", - // type: "mianze", - // content: "内容由AI生成,请注意甄别", - // }); + // 开始轮流播放音频 + if (audioUrls.length > 0 && audioStore.isVoiceEnabled) { + playAudioSequence(audioUrls); + } // // 修改后的消息处理逻辑 // const processedContent = marked(AIcontent.value); @@ -2754,9 +2933,6 @@ onMounted(() => { renderer: renderer, }); - const random = Math.floor(Math.random() * 6) + 1; - currentGif.value = gifList[random]; - console.log("组件挂载完成"); // 添加DOM变化监听器 @@ -2802,7 +2978,7 @@ onUnmounted(() => {
夺宝奇兵大模型logo - 夺宝奇兵大模型logo + 夺宝奇兵大模型logo
{