You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

5105 lines
154 KiB

5 months ago
3 days ago
5 months ago
5 months ago
5 months ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
5 months ago
5 months ago
5 months ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
3 days ago
3 days ago
3 days ago
5 months ago
1 month ago
1 month ago
1 month ago
2 months ago
2 months ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
5 months ago
3 days ago
5 months ago
3 days ago
5 months ago
5 months ago
3 days ago
5 months ago
5 months ago
1 month ago
1 month ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
5 months ago
5 months ago
3 days ago
5 months ago
5 months ago
1 month ago
1 month ago
1 month ago
5 months ago
  1. <script setup>
  2. import { ref, onMounted, watch, nextTick, reactive, onUnmounted } from "vue";
  3. import { ElDialog, ElMessage } from "element-plus";
  4. import {
  5. getReplyStreamAPI,
  6. getReplyAPI,
  7. TTSAPI,
  8. qsArpAamClickAPI,
  9. dbqbFirstAPI,
  10. dbqbSecondOneAPI,
  11. dbqbSecondTwoAPI,
  12. dbqbSecondThreeAPI,
  13. dbqbSecondFourAPI,
  14. dataListAPI,
  15. } from "../api/AIxiaocaishen";
  16. import { useUserStore } from "../store/userPessionCode";
  17. import { useChatStore } from "../store/chat";
  18. import { useAudioStore } from "../store/audio";
  19. import { useDataStore } from "@/store/dataList.js";
  20. import { marked } from "marked"; // 引入marked库
  21. // 导入思考过程GIF
  22. import thinkingGif from "@/assets/img/gif/思考.gif";
  23. import analyzeGif from "@/assets/img/gif/解析.gif";
  24. import generateGif from "@/assets/img/gif/生成.gif";
  25. import katex from "katex"; // 引入 KaTeX 库
  26. import { htmlToText } from "html-to-text";
  27. import { Howl, Howler } from "howler";
  28. import * as echarts from "echarts";
  29. import _, { add } from "lodash";
  30. import moment from "moment";
  31. import title1 from "@/assets/img/AIchat/核心价值评估.png";
  32. import title2 from "@/assets/img/AIchat/主力作战.png";
  33. import title3 from "@/assets/img/AIchat/攻防三维.png";
  34. import title4 from "@/assets/img/AIchat/综合作战.png";
  35. import logo1 from "@/assets/img/AIchat/夺宝奇兵logo.png";
  36. import logo2 from "@/assets/img/AIchat/开启无限财富.png";
  37. import getCountAll from "../assets/img/homePage/get-count-all.png";
  38. import voice from "../assets/img/homePage/tail/voice.png";
  39. import voiceNoActive from "../assets/img/homePage/tail/voice-no-active.png";
  40. const chatStore = useChatStore();
  41. const audioStore = useAudioStore();
  42. const dataStore = useDataStore();
  43. // 将这些变量移到全局作用域
  44. const audioQueue = ref([]);
  45. const isPlayingAudio = ref(false);
  46. let currentPlayIndex = 0;
  47. let isCallingPlayNext = false;
  48. // 音频预加载状态
  49. const audioPreloadStatus = {
  50. one: { loaded: false, url: null },
  51. two: { loaded: false, url: null },
  52. three: { loaded: false, url: null },
  53. four: { loaded: false, url: null },
  54. };
  55. // 音频队列顺序管理
  56. const audioQueueOrder = {
  57. "API1-第一个": 1,
  58. "API2-第二个": 2,
  59. "API3-第三个": 3,
  60. "API4-第四个": 4,
  61. };
  62. // 播放下一个音频的函数
  63. const playNextAudio = () => {
  64. if (isCallingPlayNext) {
  65. console.log("playNextAudio已在执行中,跳过重复调用");
  66. return;
  67. }
  68. if (currentPlayIndex >= audioQueue.value.length) {
  69. console.log("所有音频播放完成,重置到第一个音频");
  70. // 播放完成后重置到第一个音频,但不自动播放
  71. currentPlayIndex = 0;
  72. audioStore.isPlaying = false;
  73. audioStore.isPaused = false;
  74. audioStore.playbackPosition = 0;
  75. // 清除音频实例,确保下次点击从头开始
  76. audioStore.soundInstance = null;
  77. audioStore.nowSound = null;
  78. if (audioQueue.value.length > 0) {
  79. audioStore.setCurrentAudioUrl(audioQueue.value[0]);
  80. }
  81. return;
  82. }
  83. // if (currentPlayIndex >= audioQueue.value.length) {
  84. // console.log("所有音频播放完成");
  85. // isPlayingAudio.value = false;
  86. // return;
  87. // }
  88. isCallingPlayNext = true;
  89. const audioInfo = audioQueue.value[currentPlayIndex];
  90. if (!audioInfo || !audioInfo.url) {
  91. console.warn(`音频信息无效,跳过索引 ${currentPlayIndex}`);
  92. currentPlayIndex++;
  93. isCallingPlayNext = false;
  94. playNextAudio();
  95. return;
  96. }
  97. console.log(`开始播放 ${audioInfo.name},索引: ${currentPlayIndex}`);
  98. const audio = new Howl({
  99. src: [audioInfo.url],
  100. html5: true,
  101. format: ["mp3", "acc"],
  102. rate: 1.2,
  103. retryCount: 0,
  104. onplay: () => {
  105. audioStore.isPlaying = true;
  106. isPlayingAudio.value = true;
  107. isCallingPlayNext = false;
  108. console.log(`${audioInfo.name}音频开始播放`);
  109. },
  110. onpause: () => {
  111. audioStore.isPlaying = false;
  112. audioStore.isPaused = true;
  113. audioStore.playbackPosition = audio.seek() || 0;
  114. console.log(`${audioInfo.name}音频已暂停`);
  115. },
  116. onresume: () => {
  117. audioStore.isPlaying = true;
  118. audioStore.isPaused = false;
  119. console.log(`${audioInfo.name}音频继续播放`);
  120. },
  121. onend: () => {
  122. console.log(`${audioInfo.name}音频播放完成,准备播放下一个`);
  123. audioStore.isPlaying = false;
  124. audioStore.isPaused = false;
  125. audioStore.playbackPosition = 0;
  126. isPlayingAudio.value = false;
  127. currentPlayIndex++;
  128. console.log(
  129. "currentPlayIndex",
  130. currentPlayIndex,
  131. "audioQueue.value.length",
  132. audioQueue.value.length
  133. );
  134. if (currentPlayIndex < audioQueue.value.length) {
  135. console.log(
  136. `队列中还有音频,500ms后播放下一个 (索引:${currentPlayIndex})`
  137. );
  138. setTimeout(() => {
  139. isCallingPlayNext = false;
  140. playNextAudio();
  141. }, 200);
  142. } else {
  143. console.log("🎉 所有音频播放完成,清除音频实例");
  144. chatStore.messages[chatStore.currentUserIndex].audioStatus = false;
  145. audioStore.nowSound = null;
  146. audioStore.soundInstance = null;
  147. // currentPlayIndex = 0;
  148. isCallingPlayNext = false;
  149. // setTimeout(() => {
  150. // isCallingPlayNext = false;
  151. // playNextAudio();
  152. // }, 500); // 间隔500ms播放下一个
  153. }
  154. },
  155. onstop: () => {
  156. console.log(`${audioInfo.name}音频被停止`);
  157. audioStore.isPlaying = false;
  158. audioStore.isPaused = false;
  159. audioStore.playbackPosition = 0;
  160. },
  161. onloaderror: (id, err) => {
  162. console.error(`${audioInfo.name}音频播放失败:`, err);
  163. isPlayingAudio.value = false;
  164. isCallingPlayNext = false;
  165. setTimeout(() => {
  166. playNextAudio();
  167. }, 100);
  168. },
  169. });
  170. audioStore.setCurrentAudioUrl(audioInfo.url);
  171. audioStore.nowSound = audio;
  172. audioStore.setAudioInstance(audio);
  173. console.log(`尝试播放${audioInfo.name}音频`);
  174. audio.play();
  175. };
  176. // 添加音频到播放队列(确保顺序)
  177. const addToAudioQueue = (url, name) => {
  178. console.log(`=== 添加音频到队列 ===`);
  179. console.log("URL:", url);
  180. console.log("Name:", name);
  181. console.log("音频启用状态:", audioStore.isVoiceEnabled);
  182. if (url && audioStore.isVoiceEnabled) {
  183. const audioItem = {
  184. url,
  185. name,
  186. order: audioQueueOrder[name] || 999,
  187. };
  188. audioQueue.value.push(audioItem);
  189. // 按顺序排序队列
  190. audioQueue.value.sort((a, b) => a.order - b.order);
  191. console.log(`音频${name}已添加到播放队列,顺序:${audioItem.order}`);
  192. console.log(
  193. "当前队列顺序:",
  194. audioQueue.value.map((item) => `${item.name}(${item.order})`)
  195. );
  196. // 只有在确实没有音频在播放且这是第一个音频时才开始播放
  197. if (
  198. !isPlayingAudio.value &&
  199. !audioStore.isPlaying &&
  200. audioQueue.value.length === 1
  201. ) {
  202. console.log("✅ 条件满足:没有音频在播放且这是第一个音频,立即开始播放", {
  203. isPlayingAudio: isPlayingAudio.value,
  204. audioStoreIsPlaying: audioStore.isPlaying,
  205. queueLength: audioQueue.value.length,
  206. });
  207. playNextAudio();
  208. } else {
  209. console.log("⏳ 等待条件:", {
  210. isPlayingAudio: isPlayingAudio.value,
  211. audioStoreIsPlaying: audioStore.isPlaying,
  212. queueLength: audioQueue.value.length,
  213. reason:
  214. audioQueue.value.length > 1 ? "队列中已有其他音频" : "有音频正在播放",
  215. });
  216. }
  217. } else {
  218. console.log("❌ 跳过添加音频:", {
  219. hasUrl: !!url,
  220. voiceEnabled: audioStore.isVoiceEnabled,
  221. });
  222. }
  223. console.log(`=== 添加音频完成 ===`);
  224. };
  225. // 语音播放控制函数
  226. const toggleVoiceForUser = (index) => {
  227. console.log(
  228. "上一个按钮坐标",
  229. chatStore.currentUserIndex,
  230. "当前按钮坐标",
  231. index
  232. );
  233. if (
  234. !chatStore.messages[index].audioArray[0] ||
  235. !chatStore.messages[index].audioArray[1] ||
  236. !chatStore.messages[index].audioArray[2] ||
  237. !chatStore.messages[index].audioArray[3]
  238. ) {
  239. return;
  240. }
  241. // 先把当前按钮状态修改
  242. chatStore.messages[index].audioStatus =
  243. !chatStore.messages[index].audioStatus;
  244. // 如果当前按钮和之前的按钮不是同一个则再修改之前的按钮的状态
  245. if (chatStore.currentUserIndex != index) {
  246. if (chatStore.currentUserIndex != null) {
  247. if (audioStore.isPlaying) {
  248. audioStore.togglePlayPause();
  249. }
  250. chatStore.messages[chatStore.currentUserIndex].audioStatus = false;
  251. }
  252. audioPreloadStatus.one = { loaded: false, url: null };
  253. audioPreloadStatus.two = { loaded: false, url: null };
  254. audioPreloadStatus.three = { loaded: false, url: null };
  255. audioPreloadStatus.four = { loaded: false, url: null };
  256. if (chatStore.messages[index].audioArray[0]) {
  257. audioPreloadStatus.one.loaded = true;
  258. audioPreloadStatus.one.url = chatStore.messages[index].audioArray[0];
  259. }
  260. if (chatStore.messages[index].audioArray[1]) {
  261. audioPreloadStatus.two.loaded = true;
  262. audioPreloadStatus.two.url = chatStore.messages[index].audioArray[1];
  263. }
  264. if (chatStore.messages[index].audioArray[2]) {
  265. audioPreloadStatus.three.loaded = true;
  266. audioPreloadStatus.three.url = chatStore.messages[index].audioArray[2];
  267. }
  268. if (chatStore.messages[index].audioArray[3]) {
  269. audioPreloadStatus.four.loaded = true;
  270. audioPreloadStatus.four.url = chatStore.messages[index].audioArray[3];
  271. }
  272. chatStore.currentUserIndex = index;
  273. audioQueue.value = [];
  274. isPlayingAudio.value = false;
  275. audioStore.soundInstance = null;
  276. currentPlayIndex = 0;
  277. isCallingPlayNext = false;
  278. addToAudioQueue(chatStore.messages[index].audioArray[0], "API1-第一个");
  279. addToAudioQueue(chatStore.messages[index].audioArray[1], "API2-第二个");
  280. addToAudioQueue(chatStore.messages[index].audioArray[2], "API3-第三个");
  281. addToAudioQueue(chatStore.messages[index].audioArray[3], "API4-第四个");
  282. if (!audioStore.isVoiceEnabled) {
  283. audioStore.toggleVoice();
  284. } else {
  285. if (audioStore.currentAudioUrl || audioStore.ttsUrl) {
  286. audioStore.togglePlayPause();
  287. } else {
  288. audioStore.toggleVoice();
  289. }
  290. }
  291. } else {
  292. if (!audioStore.isVoiceEnabled) {
  293. console.log("1111");
  294. audioStore.toggleVoice();
  295. } else {
  296. if (currentPlayIndex >= audioQueue.value.length) {
  297. console.log("重新开始播放音频序列");
  298. currentPlayIndex = 0;
  299. isPlayingAudio.value = false;
  300. isCallingPlayNext = false;
  301. audioStore.soundInstance = null;
  302. // 重新开始播放
  303. if (audioQueue.value.length > 0) {
  304. playNextAudio();
  305. }
  306. } else if (audioStore.currentAudioUrl || audioStore.ttsUrl) {
  307. console.log("2222");
  308. audioStore.togglePlayPause();
  309. } else {
  310. console.log("3333");
  311. audioStore.toggleVoice();
  312. }
  313. }
  314. }
  315. };
  316. // 计算属性:判断语音是否启用
  317. const isVoice = computed(() => {
  318. return audioStore.isVoiceEnabled;
  319. });
  320. // 随机GIF
  321. const currentGif = ref("");
  322. const renderer = new marked.Renderer();
  323. // 重写 del 方法,让删除线不生效
  324. renderer.del = function (text) {
  325. // 处理各种数据类型
  326. console.log("text", text);
  327. return "~" + text.tokens[0].raw + "<br>" + text.tokens[2].raw + "~";
  328. };
  329. // 定义自定义事件
  330. const emit = defineEmits(["updateMessage", "sendMessage", "enableInput"]);
  331. // 音频播放方法
  332. const playAudio = (url) => {
  333. // 添加空值校验
  334. if (!url) {
  335. console.warn("音频URL为空,跳过播放");
  336. audioStore.isPlaying = false;
  337. return;
  338. }
  339. const handlePlay = () => {
  340. if (audioStore.isNewInstance) {
  341. const newSound = new Howl({
  342. src: [url],
  343. html5: true, // 强制HTML5 Audio解决iOS兼容问题
  344. format: ["mp3", "acc"],
  345. rate: 1.2, // 调整播放速度
  346. onplay: () => {
  347. audioStore.isPlaying = true; // 改为更新store状态
  348. newSound.volume(1); // 添加音量设置
  349. },
  350. onend: () => (audioStore.isPlaying = false),
  351. onstop: () => (audioStore.isPlaying = false),
  352. onloaderror: (id, err) => {
  353. console.error("音频加载失败:", err);
  354. ElMessage.error("音频播放失败,请检查网络连接");
  355. },
  356. });
  357. if (audioStore.nowSound) {
  358. audioStore.nowSound.stop();
  359. }
  360. audioStore.nowSound = newSound;
  361. audioStore.isNewInstance = false;
  362. console.log("新音频");
  363. } else {
  364. console.log("已经有音频");
  365. }
  366. const newSound = audioStore.nowSound;
  367. // 添加立即播放逻辑
  368. newSound.play();
  369. audioStore.setAudioInstance(newSound);
  370. Howler._howls.push(newSound); // 强制注册到全局管理
  371. // // 处理浏览器自动播放策略
  372. // if (Howler.autoUnlock) {
  373. // Howler.autoUnlock();
  374. // }
  375. };
  376. // if (/iPhone|iPad|iPod/.test(navigator.userAgent)) {
  377. // document.addEventListener('touchstart', handlePlay, { once: true });
  378. // ElMessage.info('请轻触屏幕以启用音频播放');
  379. // } else {
  380. // handlePlay();
  381. // }
  382. handlePlay();
  383. // Howler.volume(1.0) // 添加全局音量设置
  384. };
  385. // 新增暂停方法
  386. const pauseAudio = () => {
  387. if (audioStore.soundInstance) {
  388. audioStore.soundInstance.pause();
  389. audioStore.isPlaying = false;
  390. }
  391. };
  392. // 音频轮流播放方法
  393. const playAudioSequence = (audioUrls) => {
  394. console.log("playAudioSequence被调用,参数:", audioUrls);
  395. if (!audioUrls || audioUrls.length === 0) {
  396. console.warn("音频URL列表为空,跳过播放");
  397. return;
  398. }
  399. let currentIndex = 0;
  400. let audioSequence = [...audioUrls]; // 保存音频序列
  401. const playNext = () => {
  402. if (currentIndex >= audioSequence.length) {
  403. console.log("所有音频播放完成,重置到第一个音频");
  404. // 播放完成后重置到第一个音频,但不自动播放
  405. currentIndex = 0;
  406. audioStore.isPlaying = false;
  407. audioStore.isPaused = false;
  408. audioStore.playbackPosition = 0;
  409. // 清除音频实例,确保下次点击从头开始
  410. audioStore.soundInstance = null;
  411. audioStore.nowSound = null;
  412. if (audioSequence.length > 0) {
  413. audioStore.setCurrentAudioUrl(audioSequence[0]);
  414. }
  415. return;
  416. }
  417. const currentUrl = audioSequence[currentIndex];
  418. console.log(`正在播放第${currentIndex + 1}个音频:`, currentUrl);
  419. console.log(
  420. "音频URL有效性检查:",
  421. !!currentUrl,
  422. "长度:",
  423. currentUrl?.length
  424. );
  425. // 增强URL验证
  426. if (
  427. !currentUrl ||
  428. typeof currentUrl !== "string" ||
  429. currentUrl.trim() === ""
  430. ) {
  431. console.error(`音频 ${currentIndex + 1} URL无效,跳过该音频`);
  432. currentIndex++;
  433. setTimeout(() => {
  434. playNext();
  435. }, 100);
  436. return;
  437. }
  438. // 检查URL格式
  439. try {
  440. new URL(currentUrl);
  441. } catch (e) {
  442. console.error(`音频 ${currentIndex + 1} URL格式错误:`, currentUrl);
  443. currentIndex++;
  444. setTimeout(() => {
  445. playNext();
  446. }, 100);
  447. return;
  448. }
  449. // 设置当前音频URL
  450. audioStore.setCurrentAudioUrl(currentUrl);
  451. // 停止当前播放的音频
  452. if (audioStore.nowSound) {
  453. audioStore.nowSound.stop();
  454. }
  455. const sound = new Howl({
  456. src: [currentUrl],
  457. html5: true,
  458. format: ["mp3", "acc"],
  459. rate: 1.2,
  460. onplay: () => {
  461. audioStore.isPlaying = true;
  462. audioStore.isPaused = false;
  463. console.log(`开始播放音频 ${currentIndex + 1}`);
  464. console.log("音频播放状态:", {
  465. duration: sound.duration(),
  466. state: sound.state(),
  467. playing: sound.playing(),
  468. });
  469. },
  470. onpause: () => {
  471. audioStore.isPlaying = false;
  472. audioStore.isPaused = true;
  473. audioStore.playbackPosition = sound.seek() || 0;
  474. console.log(`音频 ${currentIndex + 1} 已暂停`);
  475. },
  476. onend: () => {
  477. audioStore.isPlaying = false;
  478. audioStore.isPaused = false;
  479. audioStore.playbackPosition = 0;
  480. console.log(`音频 ${currentIndex + 1} 播放完成`);
  481. currentIndex++;
  482. // 如果是最后一个音频播放完成,立即清除实例
  483. if (currentIndex >= audioSequence.length) {
  484. console.log("最后一个音频播放完成,清除音频实例");
  485. audioStore.soundInstance = null;
  486. audioStore.nowSound = null;
  487. currentIndex = 0; // 立即重置索引
  488. }
  489. // 播放下一个音频
  490. setTimeout(() => {
  491. playNext();
  492. }, 500); // 间隔500ms播放下一个
  493. },
  494. onstop: () => {
  495. audioStore.isPlaying = false;
  496. audioStore.isPaused = false;
  497. audioStore.playbackPosition = 0;
  498. console.log(`音频 ${currentIndex + 1} 已停止`);
  499. },
  500. onloaderror: (id, err) => {
  501. console.error(`音频 ${currentIndex + 1} 加载失败:`, err);
  502. console.error("失败的音频URL:", currentUrl);
  503. console.error("错误详情:", { id, err });
  504. // 增加重试机制
  505. if (!sound.retryCount) {
  506. sound.retryCount = 0;
  507. }
  508. if (sound.retryCount < 2) {
  509. sound.retryCount++;
  510. console.log(
  511. `音频 ${currentIndex + 1}${sound.retryCount}次重试加载`
  512. );
  513. setTimeout(() => {
  514. sound.load();
  515. }, 1000 * sound.retryCount); // 递增延时重试
  516. } else {
  517. console.warn(`音频 ${currentIndex + 1} 重试失败,跳过该音频`);
  518. currentIndex++;
  519. // 跳过失败的音频,播放下一个
  520. setTimeout(() => {
  521. playNext();
  522. }, 100);
  523. }
  524. },
  525. });
  526. audioStore.nowSound = sound;
  527. audioStore.setAudioInstance(sound);
  528. // 添加播放超时检测
  529. const playTimeout = setTimeout(() => {
  530. if (!audioStore.isPlaying && sound.state() === "loading") {
  531. console.warn(`音频 ${currentIndex + 1} 播放超时,可能网络问题`);
  532. sound.stop();
  533. currentIndex++;
  534. playNext();
  535. }
  536. }, 10000); // 10秒超时
  537. // 播放成功后清除超时
  538. sound.once("play", () => {
  539. clearTimeout(playTimeout);
  540. });
  541. console.log(`尝试播放音频 ${currentIndex + 1},URL: ${currentUrl}`);
  542. sound.play();
  543. };
  544. // 重写togglePlayPause方法以支持音频序列控制
  545. const originalTogglePlayPause = audioStore.togglePlayPause;
  546. audioStore.togglePlayPause = () => {
  547. console.log("音频控制按钮被点击 11111111111");
  548. console.log("当前播放状态:", audioStore.isPlaying);
  549. console.log("当前暂停状态:", audioStore.isPaused);
  550. console.log("当前音频实例:", audioStore.soundInstance);
  551. console.log(
  552. "当前索引:",
  553. currentIndex,
  554. "音频序列长度:",
  555. audioSequence.length
  556. );
  557. if (audioStore.soundInstance) {
  558. if (audioStore.isPlaying) {
  559. // 暂停当前音频
  560. console.log("暂停当前音频");
  561. audioStore.pause();
  562. } else if (audioStore.isPaused) {
  563. // 从暂停位置继续播放
  564. console.log("从暂停位置继续播放");
  565. audioStore.play();
  566. } else {
  567. // 重新开始播放当前音频或从头开始播放序列
  568. console.log("重新开始播放,当前索引:", currentIndex);
  569. if (currentIndex >= audioSequence.length) {
  570. console.log("所有音频已播放完成,从头开始");
  571. currentIndex = 0; // 重置到第一个音频
  572. }
  573. playNext();
  574. }
  575. } else {
  576. // 没有音频实例时,从头开始播放
  577. console.log("没有音频实例,从头开始播放");
  578. currentIndex = 0;
  579. playNext();
  580. }
  581. };
  582. // 开始播放第一个音频
  583. playNext();
  584. };
  585. // 获取消息
  586. const chatMsg = computed(() => chatStore.messages);
  587. const props = defineProps({
  588. messages: Array,
  589. chartData: {
  590. type: Object,
  591. default: null,
  592. },
  593. index: {
  594. type: Number,
  595. required: true,
  596. },
  597. });
  598. // 打字机效果
  599. const typewriterContent = ref("");
  600. const isTyping = ref(false);
  601. const typeWriter = (text, callback) => {
  602. let index = 0;
  603. isTyping.value = true;
  604. typewriterContent.value = "";
  605. const typingInterval = setInterval(() => {
  606. if (index < text.length) {
  607. typewriterContent.value += text.charAt(index);
  608. index++;
  609. // 自动滚动到底部
  610. nextTick(() => {
  611. const container = document.querySelector(".message-area");
  612. if (container) container.scrollTop = container.scrollHeight;
  613. });
  614. } else {
  615. clearInterval(typingInterval);
  616. isTyping.value = false;
  617. if (callback) callback();
  618. }
  619. }, 50); // 调整速度(毫秒)
  620. };
  621. const fnGetData = (data) => {
  622. const YaLiZhiChengLuoPan = data.YaLiZhiChengLuoPan;
  623. let sz = ref(5.5); // 进行判断
  624. const yl = YaLiZhiChengLuoPan.Yali; // 压力位
  625. const zc = YaLiZhiChengLuoPan.ZhiCheng; // 支撑位
  626. console.log("yl", yl, "zc", zc);
  627. if (yl == "较大" && zc == "较弱") {
  628. sz.value = 0.5; // 极高风险
  629. } else if (yl == "一般" && zc == "较弱") {
  630. sz.value = 1.5; // 弱撑中压区
  631. } else if (yl == "较弱" && zc == "较弱") {
  632. sz.value = 2.5; // 弱撑弱压区
  633. } else if (yl == "较大" && zc == "较大") {
  634. sz.value = 3.5; // 强撑强压区
  635. } else if (yl == "一般" && zc == "较大") {
  636. sz.value = 4.5; // 强撑中压
  637. } else if (yl == "较弱" && zc == "较大") {
  638. sz.value = 5.5; // 强撑弱压区
  639. } else if (yl == "较大" && zc == "一般") {
  640. sz.value = 0.2;
  641. } else if (yl == "一般" && zc == "一般") {
  642. sz.value = 3;
  643. } else if (yl == "较弱" && zc == "一般") {
  644. sz.value = 5.8;
  645. }
  646. return sz.value;
  647. };
  648. const typingQueue = ref([]);
  649. const isTypingInProgress = ref(false);
  650. // 创建打字机效果的Promise函数
  651. const createTypingEffect = (message, content, speed) => {
  652. return new Promise((resolve) => {
  653. chatStore.messages.push(message);
  654. if (Array.isArray(content) && content.length > 0) {
  655. message.content = "";
  656. message.isTyping = true;
  657. let currentIndex = 0;
  658. const processNextElement = () => {
  659. if (currentIndex >= content.length) {
  660. if (message.isEnd) {
  661. if (message.isEnd == "1") {
  662. apiStatus.one.isEnd = true;
  663. } else if (message.isEnd == "2") {
  664. apiStatus.two.isEnd = true;
  665. } else if (message.isEnd == "3") {
  666. apiStatus.three.isEnd = true;
  667. } else if (message.isEnd == "4") {
  668. apiStatus.four.isEnd = true;
  669. }
  670. }
  671. if (message.error) {
  672. chatStore.messages.push({
  673. class: "ing",
  674. type: "ing",
  675. flag: false,
  676. content: "工作流返回出错,请稍后重试",
  677. });
  678. chatStore.isLoading = false;
  679. emit("enableInput");
  680. if (message.error == "2") {
  681. apiStatus.two.isError = true;
  682. } else if (message.error == "3") {
  683. apiStatus.three.isError = true;
  684. } else if (message.error == "4") {
  685. apiStatus.four.isError = true;
  686. }
  687. }
  688. if (message.end) {
  689. chatStore.getUserCount();
  690. chatStore.isLoading = false;
  691. console.log("打印完毕,接触输入框禁用状态");
  692. emit("enableInput");
  693. }
  694. message.isTyping = false;
  695. nextTick(() => {
  696. resolve(); // 完成后resolve
  697. });
  698. return;
  699. }
  700. if (currentIndex % 2 === 0) {
  701. // 偶数下标:直接加入
  702. message.content += content[currentIndex];
  703. currentIndex++;
  704. processNextElement(); // 立即处理下一个元素
  705. } else {
  706. // 奇数下标:打字机效果
  707. const text = content[currentIndex];
  708. let charIndex = 0;
  709. const typingInterval = setInterval(() => {
  710. if (charIndex < text.length) {
  711. message.content += text.charAt(charIndex);
  712. charIndex++;
  713. } else {
  714. clearInterval(typingInterval);
  715. currentIndex++;
  716. processNextElement(); // 处理下一个元素
  717. }
  718. }, speed);
  719. }
  720. };
  721. processNextElement(); // 开始处理
  722. } else {
  723. if (message.kline) {
  724. if (message.klineType == 1) {
  725. console.log("六色罗盘消息已添加到聊天列表");
  726. // 在渲染完成后初始化图表
  727. nextTick(() => {
  728. console.log("nextTick开始 - 准备渲染图表");
  729. console.log("消息列表:", chatStore.messages);
  730. // 寻找最新添加的K线消息索引
  731. let klineIndex = -1;
  732. for (let i = 0; i < chatStore.messages.length; i++) {
  733. if (chatStore.messages[i].messageId === message.messageId) {
  734. klineIndex = i;
  735. break;
  736. }
  737. }
  738. console.log("找到的K线消息索引:", klineIndex);
  739. if (klineIndex !== -1) {
  740. const containerId = `kline-container-${klineIndex}`;
  741. console.log("图表容器ID:", containerId);
  742. // 确保DOM已经渲染完成
  743. setTimeout(() => {
  744. console.log("延时执行,确保DOM已渲染");
  745. KlineCanvsEcharts(containerId);
  746. }, 100); // 短暂延时确保DOM已渲染
  747. } else {
  748. console.warn("未找到K线消息");
  749. }
  750. });
  751. } else {
  752. console.log("K线消息已添加到聊天列表");
  753. // 在渲染完成后初始化图表
  754. nextTick(() => {
  755. console.log("nextTick开始 - 准备渲染图表");
  756. console.log("消息列表:", chatStore.messages);
  757. // 寻找最新添加的K线消息索引
  758. let klineIndex = -1;
  759. for (let i = 0; i < chatStore.messages.length; i++) {
  760. if (chatStore.messages[i].messageId === message.messageId) {
  761. klineIndex = i;
  762. break;
  763. }
  764. }
  765. console.log("找到的K线消息索引:", klineIndex);
  766. if (klineIndex !== -1) {
  767. const containerId = `kline-container-${klineIndex}`;
  768. console.log("图表容器ID:", containerId);
  769. // 确保DOM已经渲染完成
  770. setTimeout(() => {
  771. console.log("延时执行,确保DOM已渲染");
  772. KlineCanvsEcharts(containerId);
  773. }, 100); // 短暂延时确保DOM已渲染
  774. } else {
  775. console.warn("未找到K线消息");
  776. }
  777. });
  778. }
  779. if (message.isEnd) {
  780. if (message.isEnd == "1") {
  781. apiStatus.one.isEnd = true;
  782. } else if (message.isEnd == "2") {
  783. apiStatus.two.isEnd = true;
  784. } else if (message.isEnd == "3") {
  785. apiStatus.three.isEnd = true;
  786. } else if (message.isEnd == "4") {
  787. apiStatus.four.isEnd = true;
  788. }
  789. }
  790. if (message.error) {
  791. chatStore.messages.push({
  792. class: "ing",
  793. type: "ing",
  794. flag: false,
  795. content: "工作流返回出错,请稍后重试",
  796. });
  797. chatStore.isLoading = false;
  798. emit("enableInput");
  799. if (message.error == "2") {
  800. apiStatus.two.isError = true;
  801. } else if (message.error == "3") {
  802. apiStatus.three.isError = true;
  803. } else if (message.error == "4") {
  804. apiStatus.four.isError = true;
  805. }
  806. }
  807. // 延时1秒后resolve
  808. setTimeout(() => {
  809. resolve();
  810. }, 1000);
  811. } else {
  812. if (message.isEnd) {
  813. if (message.isEnd == "1") {
  814. apiStatus.one.isEnd = true;
  815. } else if (message.isEnd == "2") {
  816. apiStatus.two.isEnd = true;
  817. } else if (message.isEnd == "3") {
  818. apiStatus.three.isEnd = true;
  819. } else if (message.isEnd == "4") {
  820. apiStatus.four.isEnd = true;
  821. }
  822. }
  823. if (message.error) {
  824. chatStore.messages.push({
  825. class: "ing",
  826. type: "ing",
  827. flag: false,
  828. content: "工作流返回出错,请稍后重试",
  829. });
  830. chatStore.isLoading = false;
  831. emit("enableInput");
  832. if (message.error == "2") {
  833. apiStatus.two.isError = true;
  834. } else if (message.error == "3") {
  835. apiStatus.three.isError = true;
  836. } else if (message.error == "4") {
  837. apiStatus.four.isError = true;
  838. }
  839. }
  840. // 延时1秒后resolve
  841. setTimeout(() => {
  842. resolve();
  843. }, 1000);
  844. }
  845. }
  846. });
  847. };
  848. let apiStatus = {};
  849. // 队列处理函数
  850. const processTypingQueue = async () => {
  851. if (isTypingInProgress.value || typingQueue.value.length === 0) {
  852. return;
  853. }
  854. isTypingInProgress.value = true;
  855. while (typingQueue.value.length > 0) {
  856. const task = typingQueue.value.shift();
  857. await createTypingEffect(task.message, task.content, task.speed);
  858. }
  859. isTypingInProgress.value = false;
  860. };
  861. // 添加打字机任务到队列
  862. const addTypingTask = (message, content, speed) => {
  863. typingQueue.value.push({ message, content, speed });
  864. processTypingQueue();
  865. };
  866. // 显示思考过程
  867. async function showThinkingProcess(stockName = null) {
  868. // 第一步:正在思考
  869. const thinkingMessage1 = reactive({
  870. sender: "ai",
  871. class: "ing",
  872. type: "ing",
  873. flag: true,
  874. content: "夺宝奇兵大模型正在思考",
  875. gif: thinkingGif,
  876. });
  877. chatStore.messages.push(thinkingMessage1);
  878. await new Promise((resolve) => setTimeout(resolve, 1500));
  879. chatStore.messages.pop();
  880. // 第二步:正在解析关键数据(持续显示直到获取到股票名称)
  881. const thinkingMessage2 = reactive({
  882. sender: "ai",
  883. class: "ing",
  884. type: "ing",
  885. flag: true,
  886. content: "正在解析关键数据",
  887. gif: analyzeGif,
  888. });
  889. chatStore.messages.push(thinkingMessage2);
  890. // 如果没有股票名称,保持第二步显示
  891. if (!stockName) {
  892. return thinkingMessage2; // 返回消息引用,以便后续更新
  893. }
  894. // 有股票名称后,继续后续步骤
  895. await new Promise((resolve) => setTimeout(resolve, 1500));
  896. chatStore.messages.pop();
  897. // 第三步:生成具体股票的全景作战报告
  898. const thinkingMessage3 = reactive({
  899. sender: "ai",
  900. class: "ing",
  901. type: "ing",
  902. flag: true,
  903. content: `正在生成${stockName}全景作战报告`,
  904. gif: generateGif,
  905. });
  906. chatStore.messages.push(thinkingMessage3);
  907. await new Promise((resolve) => setTimeout(resolve, 1500));
  908. chatStore.messages.pop();
  909. // 第四步:报告已生成
  910. const thinkingMessage4 = reactive({
  911. sender: "ai",
  912. class: "ing",
  913. type: "ing",
  914. content: "报告已生成!",
  915. });
  916. chatStore.messages.push(thinkingMessage4);
  917. await new Promise((resolve) => setTimeout(resolve, 1500));
  918. chatStore.messages.pop();
  919. return null;
  920. }
  921. // 继续思考过程(当获取到股票名称后调用)
  922. async function continueThinkingProcess(thinkingMessageRef, stockName) {
  923. if (!thinkingMessageRef || !stockName) return;
  924. // 等待一段时间后继续
  925. await new Promise((resolve) => setTimeout(resolve, 1500));
  926. // 移除第二步消息
  927. const index = chatStore.messages.indexOf(thinkingMessageRef);
  928. if (index > -1) {
  929. chatStore.messages.splice(index, 1);
  930. }
  931. // 第三步:生成具体股票的全景作战报告
  932. const thinkingMessage3 = reactive({
  933. sender: "ai",
  934. class: "ing",
  935. type: "ing",
  936. flag: true,
  937. content: `正在生成${stockName}全景作战报告`,
  938. gif: generateGif,
  939. });
  940. chatStore.messages.push(thinkingMessage3);
  941. await new Promise((resolve) => setTimeout(resolve, 1500));
  942. chatStore.messages.pop();
  943. // 第四步:报告已生成
  944. const thinkingMessage4 = reactive({
  945. sender: "ai",
  946. class: "ing",
  947. type: "ing",
  948. content: "报告已生成!",
  949. });
  950. chatStore.messages.push(thinkingMessage4);
  951. await new Promise((resolve) => setTimeout(resolve, 1500));
  952. chatStore.messages.pop();
  953. }
  954. const hasValidData = ref(false);
  955. // 创建一个非响应式的对象来存储图表实例
  956. const chartInstancesMap = {};
  957. // 存储上一次的消息的length
  958. const previousMessagesLength = ref(0);
  959. watch(
  960. () => props.messages,
  961. async (newVal, oldVal) => {
  962. // // 添加空值判断
  963. if (!newVal?.length || newVal === previousMessagesLength.value) return;
  964. previousMessagesLength.value = newVal.length;
  965. if (newVal.length > 0) {
  966. // 清理语音下标
  967. console.log("chatStore.currentUserIndex", chatStore.currentUserIndex);
  968. if (chatStore.currentUserIndex != null) {
  969. chatStore.messages[chatStore.currentUserIndex].audioStatus = false;
  970. }
  971. chatStore.currentUserIndex = null;
  972. audioStore.stop(); // 暂停语音
  973. // 🔧 新增:重置音频队列状态,确保新音频能够自动播放
  974. audioQueue.value = [];
  975. isPlayingAudio.value = false;
  976. currentPlayIndex = 0;
  977. isCallingPlayNext = false;
  978. // 重置音频预加载状态
  979. audioPreloadStatus.one = { loaded: false, url: null };
  980. audioPreloadStatus.two = { loaded: false, url: null };
  981. audioPreloadStatus.three = { loaded: false, url: null };
  982. audioPreloadStatus.four = { loaded: false, url: null };
  983. // 清除音频实例
  984. audioStore.soundInstance = null;
  985. audioStore.nowSound = null;
  986. audioStore.isPlaying = false;
  987. audioStore.isPaused = false;
  988. audioStore.playbackPosition = 0;
  989. console.log("消息列表已更新,最新消息:", newVal[newVal.length - 1]);
  990. chatStore.messages.push(newVal[newVal.length - 1]);
  991. chatStore.currentUserIndex = chatStore.messages.length - 1;
  992. console.log(
  993. "消息列表已更新,最新消息:",
  994. chatStore.messages[chatStore.messages.length - 1],
  995. "最新用户坐标",
  996. chatStore.currentUserIndex
  997. );
  998. // 获取权限
  999. const userStore = useUserStore();
  1000. const params1 = {
  1001. language: "cn",
  1002. marketList: "usa,sg,my,hk,cn,can,vi,th,in",
  1003. content: newVal[newVal.length - 1].content,
  1004. token: localStorage.getItem("localToken"),
  1005. model: 1,
  1006. // language: "cn",
  1007. // marketList: "hk,cn,usa,my,sg,vi,in,gb"
  1008. // token: "+SsksARQgUHIbIG3rRnnbZi0+fEeMx8pywnIlrmTxo5EOPR/wjWDV7w7+ZUseiBtf9kFa/atmNx6QfSpv5w",
  1009. };
  1010. // 标志
  1011. let flag = true;
  1012. const codeData = ref();
  1013. // 开始思考过程(不带股票名称)
  1014. const thinkingMessageRef = await showThinkingProcess();
  1015. // 第一阶段,意图识别
  1016. try {
  1017. // 调用工作流获取回复
  1018. const result = await dbqbFirstAPI(params1);
  1019. codeData.value = result.data;
  1020. console.log(codeData.value, "codeData");
  1021. // 根据意图识别结果判断
  1022. if (result.code == 200) {
  1023. // 意图识别成功后,更新历史记录状态
  1024. chatStore.searchRecord = true;
  1025. // 获取到股票名称后,继续思考过程
  1026. if (thinkingMessageRef && codeData.value.name) {
  1027. await continueThinkingProcess(
  1028. thinkingMessageRef,
  1029. codeData.value.name
  1030. );
  1031. }
  1032. for (let i = chatStore.messages.length - 1; i >= 0; --i) {
  1033. if (chatStore.messages[i].sender == "user") {
  1034. chatStore.messages[i].audioStatus = true;
  1035. break;
  1036. }
  1037. }
  1038. chatStore.messages.push({
  1039. class: "ing",
  1040. type: "ing",
  1041. flag: flag,
  1042. // content: result.data.kaishi,
  1043. });
  1044. } else {
  1045. // 意图识别失败,先清理思考过程消息
  1046. if (thinkingMessageRef) {
  1047. const index = chatStore.messages.indexOf(thinkingMessageRef);
  1048. if (index > -1) {
  1049. chatStore.messages.splice(index, 1);
  1050. }
  1051. }
  1052. flag = false;
  1053. console.log("执行回绝话术");
  1054. const AIcontent = ref(result.msg);
  1055. // 修改后的消息处理逻辑
  1056. const processedContent = marked(AIcontent.value);
  1057. const katexRegex = /\$\$(.*?)\$\$/g;
  1058. const aiContent = processedContent.replace(
  1059. katexRegex,
  1060. (match, formula) => {
  1061. try {
  1062. return katex.renderToString(formula, { throwOnError: false });
  1063. } catch (error) {
  1064. console.error("KaTeX 渲染错误:", error);
  1065. return match;
  1066. }
  1067. }
  1068. );
  1069. console.log(aiContent, "aiContent");
  1070. chatStore.messages.push({
  1071. class: "ing",
  1072. type: "ing",
  1073. flag: flag,
  1074. content: AIcontent,
  1075. });
  1076. chatStore.isLoading = false;
  1077. emit("enableInput");
  1078. }
  1079. } catch (e) {
  1080. // 意图识别异常,先清理思考过程消息
  1081. if (thinkingMessageRef) {
  1082. const index = chatStore.messages.indexOf(thinkingMessageRef);
  1083. if (index > -1) {
  1084. chatStore.messages.splice(index, 1);
  1085. }
  1086. }
  1087. console.log(e, "意图识别失败");
  1088. chatStore.messages.push({
  1089. class: "ing",
  1090. type: "ing",
  1091. flag: false,
  1092. content: "工作流返回出错,请稍后重试",
  1093. });
  1094. chatStore.isLoading = false;
  1095. emit("enableInput");
  1096. }
  1097. if (flag) {
  1098. const params2 = {
  1099. language: "cn",
  1100. token: localStorage.getItem("localToken"),
  1101. parentId: codeData.value.parentId,
  1102. stockId: codeData.value.stockId,
  1103. recordId: codeData.value.recordId,
  1104. // content: newVal[newVal.length - 1].content,
  1105. // marketList: "usa,sg,my,hk,cn,can,vi,th,in",
  1106. // name: codeData.value.name,
  1107. // code: codeData.value.code,
  1108. // market: codeData.value.market,
  1109. // language: "cn",
  1110. // marketList: "hk,cn,usa,my,sg,vi,in,gb"
  1111. // token: "+SsksARQgUHIbIG3rRnnbZi0+fEeMx8pywnIlrmTxo5EOPR/wjWDV7w7+ZUseiBtf9kFa/atmNx6QfSpv5w",
  1112. };
  1113. try {
  1114. const env = import.meta.env.VITE_ENV;
  1115. const result20 = await dataListAPI({
  1116. token:
  1117. "8Csj5VVX1UbIb4C3oxrnbZi0+fEeMx8pywnIlrmTm45Cb/EllzWACLto9J9+fCFsfdgBOvKvyY94FvqlvM0",
  1118. // "8nkj4QBV1RPIb4CzoRTnbZi0+fEeMx8pywnIlrmTxdwROKkuwWqAWu9orpkpeXVqL98DPfeonNYpHv+mucA",
  1119. market: codeData.value.market,
  1120. code: codeData.value.code,
  1121. language: "cn", //t.value.suoxie,
  1122. brainPrivilegeState: 1,
  1123. swordPrivilegeState: 1,
  1124. stockForecastPrivilegeState: 1,
  1125. spaceForecastPrivilegeState: 1,
  1126. aibullPrivilegeState: 1,
  1127. aigoldBullPrivilegeState: 1,
  1128. airadarPrivilegeState: 1,
  1129. // marketList: 1,
  1130. // brainPrivilegeState: userStore.brainPerssion,
  1131. // swordPrivilegeState: userStore.swordPerssion,
  1132. // stockForecastPrivilegeState: userStore.pricePerssion,
  1133. // spaceForecastPrivilegeState: userStore.timePerssion,
  1134. // aibullPrivilegeState: userStore.aibullPerssion,
  1135. // aigoldBullPrivilegeState: userStore.aiGnbullPerssion,
  1136. // airadarPrivilegeState: userStore.airadarPerssion,
  1137. marketList: "usa,sg,my,hk,cn,can,vi,th,in,gb",
  1138. });
  1139. // 添加空值检查防止访问null对象的属性
  1140. const HomePage = result20.data?.HomePage || null;
  1141. const AIGoldBull = result20.data?.AIGoldBull || null;
  1142. const isLiuSe = HomePage ? true : false;
  1143. const isAIGoldBull =
  1144. AIGoldBull &&
  1145. AIGoldBull.DNC &&
  1146. AIGoldBull.FCX &&
  1147. AIGoldBull.JN &&
  1148. AIGoldBull.KLine20 &&
  1149. AIGoldBull.QSXH
  1150. ? true
  1151. : false;
  1152. const katexRegex = /\$\$(.*?)\$\$/g;
  1153. let result21;
  1154. let result22;
  1155. let result23;
  1156. let result24;
  1157. // 用于跟踪API完成状态和结果
  1158. apiStatus = {
  1159. one: {
  1160. completed: false,
  1161. result: null,
  1162. error: null,
  1163. isError: false,
  1164. isEnd: false,
  1165. },
  1166. two: {
  1167. completed: false,
  1168. result: null,
  1169. error: null,
  1170. isError: false,
  1171. isEnd: false,
  1172. },
  1173. three: {
  1174. completed: false,
  1175. result: null,
  1176. error: null,
  1177. isError: false,
  1178. isEnd: false,
  1179. },
  1180. four: {
  1181. completed: false,
  1182. result: null,
  1183. error: null,
  1184. isError: false,
  1185. isEnd: false,
  1186. },
  1187. };
  1188. // 音频播放队列管理已移到全局作用域
  1189. // 重写audioStore的togglePlayPause方法以支持队列播放控制
  1190. const originalTogglePlayPause = audioStore.togglePlayPause;
  1191. audioStore.togglePlayPause = () => {
  1192. console.log("主页音频控制按钮被点击22222222222222");
  1193. console.log(
  1194. "当前音频状态 - isPlaying:",
  1195. audioStore.isPlaying,
  1196. "isPaused:",
  1197. audioStore.isPaused
  1198. );
  1199. console.log("当前音频实例:", audioStore.soundInstance);
  1200. console.log(
  1201. "队列播放状态 - isPlayingAudio:",
  1202. isPlayingAudio.value,
  1203. "队列长度:",
  1204. audioQueue.value.length
  1205. );
  1206. console.log(
  1207. "当前播放索引:",
  1208. currentPlayIndex,
  1209. "是否所有音频播放完成:",
  1210. currentPlayIndex >= audioQueue.value.length
  1211. );
  1212. // 检查是否所有音频都播放完成,如果是则重新开始
  1213. if (
  1214. audioStore.soundInstance &&
  1215. currentPlayIndex < audioQueue.value.length &&
  1216. isPlayingAudio.value
  1217. ) {
  1218. if (audioStore.isPlaying) {
  1219. // 暂停当前音频
  1220. console.log("暂停当前音频");
  1221. audioStore.soundInstance.pause();
  1222. } else if (
  1223. audioStore.isPaused &&
  1224. audioStore.playbackPosition > 0
  1225. ) {
  1226. // 从暂停位置继续播放
  1227. console.log(
  1228. "从暂停位置继续播放音频,位置:",
  1229. audioStore.playbackPosition
  1230. );
  1231. audioStore.soundInstance.seek(audioStore.playbackPosition);
  1232. audioStore.soundInstance.play();
  1233. } else {
  1234. // 重新开始播放
  1235. console.log("重新开始播放音频");
  1236. audioStore.soundInstance.play();
  1237. }
  1238. } else {
  1239. console.log("没有音频实例,检查是否需要重新播放队列");
  1240. console.log("重新播放条件检查:", {
  1241. isPlayingAudio: isPlayingAudio.value,
  1242. queueLength: audioQueue.value.length,
  1243. currentPlayIndex: currentPlayIndex,
  1244. condition1: audioQueue.value.length === 0,
  1245. condition2: currentPlayIndex >= audioQueue.value.length,
  1246. finalCondition:
  1247. !isPlayingAudio.value &&
  1248. (audioQueue.value.length === 0 ||
  1249. currentPlayIndex >= audioQueue.value.length),
  1250. });
  1251. // 没有音频实例时,检查是否所有音频都播放完成
  1252. if (
  1253. !isPlayingAudio.value &&
  1254. (audioQueue.value.length === 0 ||
  1255. currentPlayIndex >= audioQueue.value.length)
  1256. ) {
  1257. console.log("所有音频播放完成,重新构建队列从第一个开始播放");
  1258. // 重新构建音频队列,按顺序添加所有音频(不自动播放)
  1259. const audioItems = [];
  1260. if (audioPreloadStatus.one.url) {
  1261. audioItems.push({
  1262. url: audioPreloadStatus.one.url,
  1263. name: "API1-第一个",
  1264. order: 1,
  1265. });
  1266. }
  1267. if (audioPreloadStatus.two.url) {
  1268. audioItems.push({
  1269. url: audioPreloadStatus.two.url,
  1270. name: "API2-第二个",
  1271. order: 2,
  1272. });
  1273. }
  1274. if (audioPreloadStatus.three.url) {
  1275. audioItems.push({
  1276. url: audioPreloadStatus.three.url,
  1277. name: "API3-第三个",
  1278. order: 3,
  1279. });
  1280. }
  1281. if (audioPreloadStatus.four.url) {
  1282. audioItems.push({
  1283. url: audioPreloadStatus.four.url,
  1284. name: "API4-第四个",
  1285. order: 4,
  1286. });
  1287. }
  1288. // 按顺序排序并添加到队列
  1289. audioItems.sort((a, b) => a.order - b.order);
  1290. audioQueue.value = audioItems;
  1291. console.log(
  1292. "队列重建完成,队列内容:",
  1293. audioQueue.value.map((item) => item.name)
  1294. );
  1295. console.log("开始从第一个音频播放");
  1296. // 重置播放状态并开始播放第一个音频
  1297. if (audioQueue.value.length > 0) {
  1298. // 完全重置所有播放相关状态
  1299. isPlayingAudio.value = false;
  1300. isCallingPlayNext = false;
  1301. currentPlayIndex = 0; // 重置播放索引到第一个音频
  1302. audioStore.isPlaying = false;
  1303. audioStore.isPaused = false;
  1304. audioStore.playbackPosition = 0;
  1305. audioStore.nowSound = null;
  1306. audioStore.soundInstance = null;
  1307. console.log("🔄 状态完全重置完成,准备从第一个音频开始播放");
  1308. console.log("✅ 完全重置播放状态,准备播放第一个音频");
  1309. console.log("重置后状态检查:", {
  1310. isPlayingAudio: isPlayingAudio.value,
  1311. isCallingPlayNext: isCallingPlayNext,
  1312. currentPlayIndex: currentPlayIndex,
  1313. audioStoreIsPlaying: audioStore.isPlaying,
  1314. queueLength: audioQueue.value.length,
  1315. });
  1316. setTimeout(() => {
  1317. console.log("🚀 延迟后开始播放第一个音频");
  1318. console.log("播放前最终状态检查:", {
  1319. currentPlayIndex: currentPlayIndex,
  1320. queueLength: audioQueue.value.length,
  1321. queueItems: audioQueue.value.map(
  1322. (item, index) => `${index}: ${item.name}`
  1323. ),
  1324. isPlayingAudio: isPlayingAudio.value,
  1325. isCallingPlayNext: isCallingPlayNext,
  1326. audioStoreIsPlaying: audioStore.isPlaying,
  1327. audioStoreInstance: !!audioStore.soundInstance,
  1328. });
  1329. console.log(
  1330. "🎯 即将调用 playNextAudio,期望播放:",
  1331. audioQueue.value[currentPlayIndex]?.name || "无音频"
  1332. );
  1333. playNextAudio();
  1334. }, 200);
  1335. }
  1336. } else if (!isPlayingAudio.value && audioQueue.value.length > 0) {
  1337. console.log("队列中还有音频,继续播放");
  1338. playNextAudio();
  1339. } else {
  1340. console.log(
  1341. "无法播放 - isPlayingAudio:",
  1342. isPlayingAudio.value,
  1343. "队列长度:",
  1344. audioQueue.value.length
  1345. );
  1346. }
  1347. }
  1348. };
  1349. // 预加载音频函数
  1350. const preloadAudio = (url, apiKey) => {
  1351. if (!url || !audioStore.isVoiceEnabled) {
  1352. audioPreloadStatus[apiKey].loaded = true;
  1353. return Promise.resolve();
  1354. }
  1355. // 立即设置URL,确保即使预加载失败也能使用
  1356. audioPreloadStatus[apiKey].url = url;
  1357. console.log(`设置音频${apiKey}的URL:`, url);
  1358. return new Promise((resolve) => {
  1359. const audio = new Howl({
  1360. src: [url],
  1361. html5: true,
  1362. format: ["mp3", "acc"],
  1363. rate: 1.2,
  1364. preload: true,
  1365. onload: () => {
  1366. console.log(`音频${apiKey}预加载完成:`, url);
  1367. audioPreloadStatus[apiKey].loaded = true;
  1368. resolve();
  1369. },
  1370. onloaderror: (id, err) => {
  1371. console.error(`音频${apiKey}预加载失败:`, err);
  1372. audioPreloadStatus[apiKey].loaded = true; // 标记为已处理,避免阻塞
  1373. // URL已经在上面设置了,即使预加载失败也保留URL
  1374. resolve();
  1375. },
  1376. });
  1377. });
  1378. };
  1379. // 检查第一个接口是否可以开始输出(文本和音频都准备好)
  1380. const canStartFirstOutput = () => {
  1381. return apiStatus.one.completed && audioPreloadStatus.one.loaded;
  1382. };
  1383. // 检查并按顺序执行代码的函数
  1384. const checkAndExecuteInOrder = () => {
  1385. // 检查OneAPI - 只有当文本和音频都准备好时才开始输出
  1386. if (canStartFirstOutput() && !apiStatus.one.executed) {
  1387. if (apiStatus.one.result) {
  1388. apiStatus.one.executed = true;
  1389. console.log(
  1390. "执行OneAPI代码(文本和音频同步开始):",
  1391. apiStatus.one.result
  1392. );
  1393. // 将第一个音频添加到播放队列(确保顺序:API1)
  1394. if (audioPreloadStatus.one.url) {
  1395. chatStore.messages[
  1396. chatStore.currentUserIndex
  1397. ].audioArray.push(audioPreloadStatus.one.url);
  1398. addToAudioQueue(audioPreloadStatus.one.url, "API1-第一个");
  1399. console.log(
  1400. "音频队列:添加API1音频,当前队列长度:",
  1401. audioQueue.value.length
  1402. );
  1403. }
  1404. // 在这里添加OneAPI成功后需要执行的代码
  1405. // 删除正在为您生成信息
  1406. chatStore.messages.pop();
  1407. // 添加报告头和时间
  1408. addTypingTask(
  1409. {
  1410. sender: "ai",
  1411. class: "title1",
  1412. type: "title1",
  1413. content: codeData.value.name + "全景作战报告",
  1414. date: result21.data.date,
  1415. },
  1416. "",
  1417. 50
  1418. );
  1419. // chatStore.messages.push({
  1420. // sender: "ai",
  1421. // class: "title1",
  1422. // type: "title1",
  1423. // content: codeData.value.name + "全景作战报告",
  1424. // date: moment().format("MM/DD/YYYY"),
  1425. // });
  1426. // 添加股票信息框
  1427. const pc1 = marked(
  1428. result21.data.name +
  1429. "\n" +
  1430. result21.data.price +
  1431. "\n" +
  1432. result21.data.date
  1433. );
  1434. const ac1 = pc1.replace(katexRegex, (match, formula) => {
  1435. try {
  1436. return katex.renderToString(formula, {
  1437. throwOnError: false,
  1438. });
  1439. } catch (error) {
  1440. console.error("KaTeX 渲染错误:", error);
  1441. return match;
  1442. }
  1443. });
  1444. // 先推送初始消息
  1445. const aiMessage1 = reactive({
  1446. sender: "ai",
  1447. class: "content1",
  1448. type: "content1",
  1449. content: "",
  1450. isTyping: true,
  1451. });
  1452. // chatStore.messages.push(aiMessage1);
  1453. // let index1 = 0;
  1454. // const typingInterval1 = setInterval(() => {
  1455. // if (index1 < ac1.length) {
  1456. // aiMessage1.content += ac1.charAt(index1);
  1457. // index1++;
  1458. // } else {
  1459. // clearInterval(typingInterval1);
  1460. // aiMessage1.isTyping = false;
  1461. // }
  1462. // }, 50); // 调整速度为50ms/字符
  1463. addTypingTask(aiMessage1, ["", ac1], 130);
  1464. // chatStore.messages.push({
  1465. // sender: "ai",
  1466. // class: "content1",
  1467. // type: "content1",
  1468. // content: ac1,
  1469. // });
  1470. // 添加六色罗盘
  1471. if (HomePage) {
  1472. const LiuSeData = JSON.parse(JSON.stringify(toRaw(HomePage)));
  1473. const sz = fnGetData(LiuSeData);
  1474. if (sz) {
  1475. hasValidData.value = true;
  1476. console.log("hasValidData设置为:", hasValidData.value);
  1477. }
  1478. // 先推送K线图消息
  1479. const klineMessageId1 = `kline-${Date.now()}`;
  1480. console.log("生成K线消息ID:", klineMessageId1);
  1481. addTypingTask(
  1482. {
  1483. sender: "ai",
  1484. class: "content1",
  1485. type: "content1",
  1486. kline: true,
  1487. chartData: sz,
  1488. messageId: klineMessageId1,
  1489. hasValidData: true,
  1490. klineType: 1,
  1491. },
  1492. "",
  1493. 50
  1494. );
  1495. // chatStore.messages.push({
  1496. // sender: "ai",
  1497. // class: "content1",
  1498. // type: "content1",
  1499. // kline: true,
  1500. // chartData: sz,
  1501. // messageId: klineMessageId1,
  1502. // hasValidData: true,
  1503. // klineType: 1,
  1504. // });
  1505. // console.log("六色罗盘消息已添加到聊天列表");
  1506. // // 在渲染完成后初始化图表
  1507. // nextTick(() => {
  1508. // console.log("nextTick开始 - 准备渲染图表");
  1509. // console.log("消息列表:", chatStore.messages);
  1510. // // 寻找最新添加的K线消息索引
  1511. // let klineIndex = -1;
  1512. // for (let i = 0; i < chatStore.messages.length; i++) {
  1513. // if (chatStore.messages[i].messageId === klineMessageId1) {
  1514. // klineIndex = i;
  1515. // break;
  1516. // }
  1517. // }
  1518. // console.log("找到的K线消息索引:", klineIndex);
  1519. // if (klineIndex !== -1) {
  1520. // const containerId = `kline-container-${klineIndex}`;
  1521. // console.log("图表容器ID:", containerId);
  1522. // // 确保DOM已经渲染完成
  1523. // setTimeout(() => {
  1524. // console.log("延时执行,确保DOM已渲染");
  1525. // KlineCanvsEcharts(containerId);
  1526. // }, 100); // 短暂延时确保DOM已渲染
  1527. // } else {
  1528. // console.warn("未找到K线消息");
  1529. // }
  1530. // });
  1531. }
  1532. // 度牛尺K线图
  1533. if (
  1534. AIGoldBull &&
  1535. AIGoldBull.DNC &&
  1536. AIGoldBull.FCX &&
  1537. AIGoldBull.JN &&
  1538. AIGoldBull.KLine20 &&
  1539. AIGoldBull.QSXH
  1540. ) {
  1541. const AIGoldBullData = JSON.parse(
  1542. JSON.stringify(toRaw(AIGoldBull))
  1543. );
  1544. const HomePageData = JSON.parse(
  1545. JSON.stringify(toRaw(HomePage))
  1546. );
  1547. console.log("处理 K 线数据 - 开始");
  1548. console.log("AIGoldBullData", AIGoldBullData);
  1549. console.log("HomePageData", HomePageData);
  1550. const Kline20 = {
  1551. name: HomePageData.StockInformation.Name,
  1552. Kline: AIGoldBullData,
  1553. };
  1554. // 打印K线数据结构
  1555. console.log("K线数据结构:", Kline20);
  1556. console.log("K线数据名称:", Kline20.name);
  1557. console.log("K线数据:", Kline20.Kline ? Kline20.Kline : null);
  1558. // 设置数据有效标志
  1559. hasValidData.value = true;
  1560. console.log("hasValidData设置为:", hasValidData.value);
  1561. // chatStore.messages.pop();
  1562. // 先推送K线图消息
  1563. const klineMessageId2 = `kline-${Date.now() + 1}`;
  1564. console.log("生成K线消息ID:", klineMessageId2);
  1565. // chatStore.messages.push({
  1566. // sender: "ai",
  1567. // class: "content2",
  1568. // type: "content2",
  1569. // kline: true,
  1570. // chartData: Kline20,
  1571. // messageId: klineMessageId2,
  1572. // hasValidData: true, // 添加hasValidData标志
  1573. // klineType: 2,
  1574. // });
  1575. addTypingTask(
  1576. {
  1577. sender: "ai",
  1578. class: "content2",
  1579. type: "content2",
  1580. kline: true,
  1581. chartData: Kline20,
  1582. messageId: klineMessageId2,
  1583. hasValidData: true, // 添加hasValidData标志
  1584. klineType: 2,
  1585. error: apiStatus.two.error ? "2" : "",
  1586. isEnd: "1",
  1587. },
  1588. "",
  1589. 50
  1590. );
  1591. // console.log("K线消息已添加到聊天列表");
  1592. // // 在渲染完成后初始化图表
  1593. // nextTick(() => {
  1594. // console.log("nextTick开始 - 准备渲染图表");
  1595. // console.log("消息列表:", chatStore.messages);
  1596. // // 寻找最新添加的K线消息索引
  1597. // let klineIndex = -1;
  1598. // for (let i = 0; i < chatStore.messages.length; i++) {
  1599. // if (chatStore.messages[i].messageId === klineMessageId2) {
  1600. // klineIndex = i;
  1601. // break;
  1602. // }
  1603. // }
  1604. // console.log("找到的K线消息索引:", klineIndex);
  1605. // if (klineIndex !== -1) {
  1606. // const containerId = `kline-container-${klineIndex}`;
  1607. // console.log("图表容器ID:", containerId);
  1608. // // 确保DOM已经渲染完成
  1609. // setTimeout(() => {
  1610. // console.log("延时执行,确保DOM已渲染");
  1611. // KlineCanvsEcharts(containerId);
  1612. // }, 100); // 短暂延时确保DOM已渲染
  1613. // } else {
  1614. // console.warn("未找到K线消息");
  1615. // }
  1616. // });
  1617. }
  1618. } else {
  1619. chatStore.messages.push({
  1620. class: "ing",
  1621. type: "ing",
  1622. flag: false,
  1623. content: "工作流返回出错,请稍后重试",
  1624. });
  1625. chatStore.isLoading = false;
  1626. emit("enableInput");
  1627. }
  1628. }
  1629. // 检查TwoAPI(需要OneAPI已执行)
  1630. if (
  1631. apiStatus.one.executed &&
  1632. apiStatus.two.completed &&
  1633. !apiStatus.two.executed
  1634. ) {
  1635. if (apiStatus.two.result) {
  1636. apiStatus.two.executed = true;
  1637. console.log("执行TwoAPI代码:", apiStatus.two.result);
  1638. // 将第二个音频添加到播放队列(确保顺序:API2)
  1639. if (audioPreloadStatus.two.url) {
  1640. chatStore.messages[
  1641. chatStore.currentUserIndex
  1642. ].audioArray.push(audioPreloadStatus.two.url);
  1643. addToAudioQueue(audioPreloadStatus.two.url, "API2-第二个");
  1644. console.log(
  1645. "音频队列:添加API2音频,当前队列长度:",
  1646. audioQueue.value.length
  1647. );
  1648. }
  1649. // 在这里添加TwoAPI成功后需要执行的代码
  1650. // 添加标题2
  1651. addTypingTask(
  1652. {
  1653. sender: "ai",
  1654. class: "title2",
  1655. type: "title2",
  1656. content: "",
  1657. },
  1658. "",
  1659. 50
  1660. );
  1661. // chatStore.messages.push({
  1662. // sender: "ai",
  1663. // class: "title2",
  1664. // type: "title2",
  1665. // content: "",
  1666. // });
  1667. // 添加内容框1
  1668. const pc2 = marked(result22.data.hxjzpg);
  1669. console.log(pc2, "pc2");
  1670. const ac2 = pc2.replace(katexRegex, (match, formula) => {
  1671. try {
  1672. return katex.renderToString(formula, {
  1673. throwOnError: false,
  1674. });
  1675. } catch (error) {
  1676. console.error("KaTeX 渲染错误:", error);
  1677. return match;
  1678. }
  1679. });
  1680. // 先推送初始消息
  1681. const aiMessage2 = reactive({
  1682. sender: "ai",
  1683. class: "content3",
  1684. type: "content3",
  1685. content: "",
  1686. isTyping: true,
  1687. error: apiStatus.three.error ? "3" : "",
  1688. isEnd: "2",
  1689. });
  1690. // chatStore.messages.push(aiMessage2);
  1691. // let index2 = 0;
  1692. // const typingInterval2 = setInterval(() => {
  1693. // if (index2 < ac2.length) {
  1694. // aiMessage2.content += ac2.charAt(index2);
  1695. // index2++;
  1696. // } else {
  1697. // clearInterval(typingInterval2);
  1698. // aiMessage2.isTyping = false;
  1699. // }
  1700. // }, 50); // 调整速度为50ms/字符
  1701. addTypingTask(aiMessage2, ["", ac2], 130);
  1702. // chatStore.messages.push({
  1703. // sender: "ai",
  1704. // class: "content3",
  1705. // type: "content3",
  1706. // content: ac2,
  1707. // });
  1708. } else {
  1709. console.log("1111111111111111111");
  1710. if (
  1711. apiStatus.one.isEnd &&
  1712. apiStatus.two.error &&
  1713. !apiStatus.two.isError
  1714. ) {
  1715. apiStatus.two.isError = true;
  1716. chatStore.messages.push({
  1717. class: "ing",
  1718. type: "ing",
  1719. flag: false,
  1720. content: "工作流返回出错,请稍后重试",
  1721. });
  1722. chatStore.isLoading = false;
  1723. emit("enableInput");
  1724. }
  1725. }
  1726. }
  1727. // 检查ThreeAPI(需要TwoAPI已执行)
  1728. if (
  1729. apiStatus.two.executed &&
  1730. apiStatus.three.completed &&
  1731. !apiStatus.three.executed
  1732. ) {
  1733. if (apiStatus.three.result) {
  1734. apiStatus.three.executed = true;
  1735. console.log("执行ThreeAPI代码:", apiStatus.three.result);
  1736. // 将第三个音频添加到播放队列(确保顺序:API3)
  1737. if (audioPreloadStatus.three.url) {
  1738. chatStore.messages[
  1739. chatStore.currentUserIndex
  1740. ].audioArray.push(audioPreloadStatus.three.url);
  1741. addToAudioQueue(audioPreloadStatus.three.url, "API3-第三个");
  1742. console.log(
  1743. "音频队列:添加API3音频,当前队列长度:",
  1744. audioQueue.value.length
  1745. );
  1746. }
  1747. // 在这里添加ThreeAPI成功后需要执行的代码
  1748. // 添加标题3-2
  1749. addTypingTask(
  1750. {
  1751. sender: "ai",
  1752. class: "title3",
  1753. type: "title3",
  1754. content: title2,
  1755. },
  1756. "",
  1757. 50
  1758. );
  1759. // chatStore.messages.push({
  1760. // sender: "ai",
  1761. // class: "title3",
  1762. // type: "title3",
  1763. // content: title2,
  1764. // });
  1765. // 添加内容框2
  1766. // const pc3 = marked(result23.data.zhuli1+'\n'+result23.data.zhuli2+'\n'+result23.data.zhuli3);
  1767. // const ac3 = pc3.replace(
  1768. // katexRegex,
  1769. // (match, formula) => {
  1770. // try {
  1771. // return katex.renderToString(formula, { throwOnError: false });
  1772. // } catch (error) {
  1773. // console.error("KaTeX 渲染错误:", error);
  1774. // return match;
  1775. // }
  1776. // }
  1777. // );
  1778. const ac31 = `<p style="margin:0;color:#FFD700;font-weight:bold;display:flex;justify-content:center;font-size:22px">【主力行为】</p><p>`;
  1779. const ac32 = `${result23.data.zhuli1}</p><p>${result23.data.zhuli2}</p><p>${result23.data.zhuli3}</p>`;
  1780. const ac3 = `<p style="margin:0;color:#FFD700;font-weight:bold;display:flex;justify-content:center;font-size:22px">【主力行为】</p><p>${result23.data.zhuli1}</p><p>${result23.data.zhuli2}</p><p>${result23.data.zhuli3}</p>`;
  1781. // 先推送初始消息
  1782. const aiMessage3 = reactive({
  1783. sender: "ai",
  1784. class: "content3",
  1785. type: "content3",
  1786. content: "",
  1787. isTyping: true,
  1788. });
  1789. // chatStore.messages.push(aiMessage3);
  1790. // let index3 = 0;
  1791. // const typingInterval3 = setInterval(() => {
  1792. // if (index3 < ac3.length) {
  1793. // aiMessage3.content += ac3.charAt(index3);
  1794. // index3++;
  1795. // } else {
  1796. // clearInterval(typingInterval3);
  1797. // aiMessage3.isTyping = false;
  1798. // }
  1799. // }, 50); // 调整速度为50ms/字符
  1800. addTypingTask(aiMessage3, [ac31, ac32], 200);
  1801. // chatStore.messages.push({
  1802. // sender: "ai",
  1803. // class: "content3",
  1804. // type: "content3",
  1805. // content: ac3,
  1806. // });
  1807. // 添加标题3-3
  1808. addTypingTask(
  1809. {
  1810. sender: "ai",
  1811. class: "title3",
  1812. type: "title3",
  1813. content: title3,
  1814. },
  1815. "",
  1816. 50
  1817. );
  1818. // chatStore.messages.push({
  1819. // sender: "ai",
  1820. // class: "title3",
  1821. // type: "title3",
  1822. // content: title3,
  1823. // });
  1824. // 添加内容框3
  1825. const arr = result23.data.kongjian.split(",");
  1826. const kongjian = `<p style="margin:0;color:#FFD700;font-weight:bold;display:flex;justify-content:center;font-size:22px">【空间维度】</p><p style="display:flex;justify-content:center;">${arr[0]},${arr[1]}</p><p style="display:flex;justify-content:center;">${arr[2]},${arr[3]}</p>`;
  1827. const shijian = `<p style="margin:0;color:#FFD700;font-weight:bold;display:flex;justify-content:center;font-size:22px">【时间维度】</p><p style="display:flex;justify-content:center;">${result23.data.shijian}</p>`;
  1828. const nengliang = `<p style="margin:0;color:#FFD700;font-weight:bold;display:flex;justify-content:center;font-size:22px">【能量维度】</p><p>${result23.data.nengliang}</p>`;
  1829. const ac4 = kongjian + shijian + nengliang;
  1830. const ac41 = `<p style="margin:0;color:#FFD700;font-weight:bold;display:flex;justify-content:center;font-size:22px">【空间维度】</p><p style="display:flex;justify-content:center;">`;
  1831. const ac42 = `${arr[0]},${arr[1]}`;
  1832. const ac43 = `</p><p style="display:flex;justify-content:center;">`;
  1833. const ac44 = `${arr[2]},${arr[3]}</p>`;
  1834. const ac45 = `<p style="margin:0;color:#FFD700;font-weight:bold;display:flex;justify-content:center;font-size:22px">【时间维度】</p><p style="display:flex;justify-content:center;">`;
  1835. const ac46 = `${result23.data.shijian}</p>`;
  1836. const ac47 = `<p style="margin:0;color:#FADC0C;font-weight:bold;display:flex;justify-content:center;font-size:22px">【能量维度】</p><p style="display:flex;justify-content:center;">`;
  1837. const ac48 = `${result23.data.nengliang}</p>`;
  1838. // const pc4 = marked(
  1839. // kongjian +
  1840. // "\n" +
  1841. // result23.data.shijian +
  1842. // "\n" +
  1843. // result23.data.nengliang
  1844. // );
  1845. // const ac4 = pc4.replace(katexRegex, (match, formula) => {
  1846. // try {
  1847. // return katex.renderToString(formula, { throwOnError: false });
  1848. // } catch (error) {
  1849. // console.error("KaTeX 渲染错误:", error);
  1850. // return match;
  1851. // }
  1852. // });
  1853. // 先推送初始消息
  1854. const aiMessage4 = reactive({
  1855. sender: "ai",
  1856. class: "content3",
  1857. type: "content3",
  1858. content: "",
  1859. isTyping: true,
  1860. error: apiStatus.four.error ? "4" : "",
  1861. isEnd: "3",
  1862. });
  1863. // chatStore.messages.push(aiMessage4);
  1864. // let index4 = 0;
  1865. // const typingInterval4 = setInterval(() => {
  1866. // if (index4 < ac4.length) {
  1867. // aiMessage4.content += ac4.charAt(index4);
  1868. // index4++;
  1869. // } else {
  1870. // clearInterval(typingInterval4);
  1871. // aiMessage4.isTyping = false;
  1872. // }
  1873. // }, 50); // 调整速度为50ms/字符
  1874. addTypingTask(
  1875. aiMessage4,
  1876. [ac41, ac42, ac43, ac44, ac45, ac46, ac47, ac48],
  1877. 200
  1878. );
  1879. // chatStore.messages.push({
  1880. // sender: "ai",
  1881. // class: "content3",
  1882. // type: "content3",
  1883. // content: ac4,
  1884. // });
  1885. } else {
  1886. if (
  1887. apiStatus.two.isEnd &&
  1888. apiStatus.three.error &&
  1889. !apiStatus.three.isError
  1890. ) {
  1891. apiStatus.three.isError = true;
  1892. chatStore.messages.push({
  1893. class: "ing",
  1894. type: "ing",
  1895. flag: false,
  1896. content: "工作流返回出错,请稍后重试1111",
  1897. });
  1898. chatStore.isLoading = false;
  1899. emit("enableInput");
  1900. }
  1901. }
  1902. }
  1903. // 检查FourAPI(需要ThreeAPI已执行)
  1904. if (
  1905. apiStatus.three.executed &&
  1906. apiStatus.four.completed &&
  1907. !apiStatus.four.executed
  1908. ) {
  1909. if (apiStatus.four.result) {
  1910. apiStatus.four.executed = true;
  1911. console.log("执行FourAPI代码:", apiStatus.four.result);
  1912. // 将第四个音频添加到播放队列(确保顺序:API4)
  1913. if (audioPreloadStatus.four.url) {
  1914. chatStore.messages[
  1915. chatStore.currentUserIndex
  1916. ].audioArray.push(audioPreloadStatus.four.url);
  1917. addToAudioQueue(audioPreloadStatus.four.url, "API4-第四个");
  1918. console.log(
  1919. "音频队列:添加API4音频,当前队列长度:",
  1920. audioQueue.value.length
  1921. );
  1922. }
  1923. // 在这里添加FourAPI成功后需要执行的代码
  1924. // 添加标题3-4
  1925. addTypingTask(
  1926. {
  1927. sender: "ai",
  1928. class: "title3",
  1929. type: "title3",
  1930. content: title4,
  1931. },
  1932. "",
  1933. 50
  1934. );
  1935. // chatStore.messages.push({
  1936. // sender: "ai",
  1937. // class: "title3",
  1938. // type: "title3",
  1939. // content: title4,
  1940. // });
  1941. // 添加内容框4
  1942. const cftj = `<p style="margin:0;color:#FFD700;font-weight:bold;display:flex;justify-content:center;font-size:22px">【触发条件】</p><p>${result24.data.cftl}</p>`;
  1943. const gfzl = `<p style="margin:0;color:#FFD700;font-weight:bold;display:flex;justify-content:center;font-size:22px">【攻防指令】</p><p>${result24.data.gfzl}</p>`;
  1944. const ac5 = cftj + gfzl;
  1945. const ac51 = `<p style="margin:0;color:#FFD700;font-weight:bold;display:flex;justify-content:center;font-size:22px">【触发条件】</p><p>`;
  1946. const ac52 = `${result24.data.cftl}</p>`;
  1947. const ac53 = `<p style="margin:0;color:#FFD700;font-weight:bold;display:flex;justify-content:center;font-size:22px">【攻防指令】</p><p>`;
  1948. const ac54 = `${result24.data.gfzl}</p>`;
  1949. // const pc5 = marked(result24.data.cftl + "/n" + result24.data.gfzl);
  1950. // const ac5 = pc5.replace(katexRegex, (match, formula) => {
  1951. // try {
  1952. // return katex.renderToString(formula, { throwOnError: false });
  1953. // } catch (error) {
  1954. // console.error("KaTeX 渲染错误:", error);
  1955. // return match;
  1956. // }
  1957. // });
  1958. // 先推送初始消息
  1959. const aiMessage5 = reactive({
  1960. sender: "ai",
  1961. class: "content3",
  1962. type: "content3",
  1963. content: "",
  1964. isTyping: true,
  1965. });
  1966. // chatStore.messages.push(aiMessage5);
  1967. // let index5 = 0;
  1968. // const typingInterval5 = setInterval(() => {
  1969. // if (index5 < ac5.length) {
  1970. // aiMessage5.content += ac5.charAt(index5);
  1971. // index5++;
  1972. // } else {
  1973. // clearInterval(typingInterval5);
  1974. // aiMessage5.isTyping = false;
  1975. // }
  1976. // }, 50); // 调整速度为50ms/字符
  1977. addTypingTask(aiMessage5, [ac51, ac52, ac53, ac54], 240);
  1978. // chatStore.messages.push({
  1979. // sender: "ai",
  1980. // class: "content3",
  1981. // type: "content3",
  1982. // content: ac5,
  1983. // });
  1984. const ac6 = "该内容由AI生成,请注意甄别";
  1985. // 先推送初始消息
  1986. const aiMessage6 = reactive({
  1987. sender: "ai",
  1988. class: "mianze",
  1989. type: "mianze",
  1990. content: "",
  1991. isTyping: true,
  1992. end: true,
  1993. });
  1994. // chatStore.messages.push(aiMessage6);
  1995. // let index6 = 0;
  1996. // const typingInterval6 = setInterval(() => {
  1997. // if (index6 < ac6.length) {
  1998. // aiMessage6.content += ac6.charAt(index6);
  1999. // index6++;
  2000. // } else {
  2001. // clearInterval(typingInterval6);
  2002. // aiMessage6.isTyping = false;
  2003. // }
  2004. // }, 50); // 调整速度为50ms/字符
  2005. addTypingTask(aiMessage6, ["", ac6], 210);
  2006. // chatStore.isLoading = false;
  2007. // chatStore.messages.push({
  2008. // sender: "ai",
  2009. // class: "mianze",
  2010. // type: "mianze",
  2011. // content: "内容由AI生成,请注意甄别",
  2012. // });
  2013. } else {
  2014. if (
  2015. apiStatus.three.isEnd &&
  2016. apiStatus.four.error &&
  2017. !apiStatus.four.isError
  2018. ) {
  2019. apiStatus.four.isError = true;
  2020. chatStore.messages.push({
  2021. class: "ing",
  2022. type: "ing",
  2023. flag: false,
  2024. content: "工作流返回出错,请稍后重试",
  2025. });
  2026. chatStore.isLoading = false;
  2027. emit("enableInput");
  2028. }
  2029. }
  2030. }
  2031. // 检查是否所有API都已完成并执行
  2032. if (
  2033. apiStatus.one.completed &&
  2034. apiStatus.two.completed &&
  2035. apiStatus.three.completed &&
  2036. apiStatus.four.completed &&
  2037. apiStatus.four.executed
  2038. ) {
  2039. console.log("所有API已完成,开始收集预加载的音频URL");
  2040. // 收集所有预加载的音频URL
  2041. const audioUrls = [];
  2042. console.log("预加载音频状态检查:");
  2043. console.log("audioPreloadStatus:", audioPreloadStatus);
  2044. if (audioPreloadStatus.one.url) {
  2045. console.log(
  2046. "添加预加载音频URL one:",
  2047. audioPreloadStatus.one.url
  2048. );
  2049. audioUrls.push(audioPreloadStatus.one.url);
  2050. }
  2051. if (audioPreloadStatus.two.url) {
  2052. console.log(
  2053. "添加预加载音频URL two:",
  2054. audioPreloadStatus.two.url
  2055. );
  2056. audioUrls.push(audioPreloadStatus.two.url);
  2057. }
  2058. if (audioPreloadStatus.three.url) {
  2059. console.log(
  2060. "添加预加载音频URL three:",
  2061. audioPreloadStatus.three.url
  2062. );
  2063. audioUrls.push(audioPreloadStatus.three.url);
  2064. }
  2065. if (audioPreloadStatus.four.url) {
  2066. console.log(
  2067. "添加预加载音频URL four:",
  2068. audioPreloadStatus.four.url
  2069. );
  2070. audioUrls.push(audioPreloadStatus.four.url);
  2071. }
  2072. console.log("收集到的预加载音频URLs:", audioUrls);
  2073. console.log("语音是否启用:", audioStore.isVoiceEnabled);
  2074. // 音频播放逻辑已移至各个接口的执行代码中
  2075. console.log("所有接口执行完成,音频已在各接口中单独播放");
  2076. }
  2077. };
  2078. const handleOneAPI = async () => {
  2079. try {
  2080. result21 = await dbqbSecondOneAPI(params2);
  2081. if (result21.code == 400) {
  2082. throw new Error("API返回错误码400,请求失败");
  2083. }
  2084. console.log("OneAPI成功返回:", result21);
  2085. apiStatus.one.completed = true;
  2086. apiStatus.one.result = result21;
  2087. // 预加载第一个接口的音频
  2088. if (result21?.data?.url) {
  2089. await preloadAudio(result21.data.url.trim(), "one");
  2090. } else {
  2091. audioPreloadStatus.one.loaded = true;
  2092. }
  2093. // 检查是否可以执行
  2094. checkAndExecuteInOrder();
  2095. } catch (error) {
  2096. console.error("OneAPI失败:", error);
  2097. apiStatus.one.completed = true;
  2098. apiStatus.one.error = error;
  2099. audioPreloadStatus.one.loaded = true; // 失败时也标记为已处理
  2100. // 即使失败也要检查后续执行
  2101. checkAndExecuteInOrder();
  2102. }
  2103. };
  2104. const handleTwoAPI = async () => {
  2105. try {
  2106. result22 = await dbqbSecondTwoAPI(params2);
  2107. if (result22.code == 400) {
  2108. throw new Error("API返回错误码400,请求失败");
  2109. }
  2110. console.log("TwoAPI成功返回:", result22);
  2111. apiStatus.two.completed = true;
  2112. apiStatus.two.result = result22;
  2113. // 预加载第二个接口的音频
  2114. if (result22?.data?.url) {
  2115. await preloadAudio(result22.data.url.trim(), "two");
  2116. } else {
  2117. audioPreloadStatus.two.loaded = true;
  2118. }
  2119. // 检查是否可以执行
  2120. checkAndExecuteInOrder();
  2121. } catch (error) {
  2122. console.error("TwoAPI失败:", error);
  2123. apiStatus.two.completed = true;
  2124. apiStatus.two.error = error;
  2125. audioPreloadStatus.two.loaded = true;
  2126. checkAndExecuteInOrder();
  2127. }
  2128. };
  2129. const handleThreeAPI = async () => {
  2130. try {
  2131. result23 = await dbqbSecondThreeAPI(params2);
  2132. if (result23.code == 400) {
  2133. throw new Error("API返回错误码400,请求失败");
  2134. }
  2135. // result23 = await dbqbSecondThreeAPI();
  2136. console.log("ThreeAPI成功返回:", result23);
  2137. apiStatus.three.completed = true;
  2138. apiStatus.three.result = result23;
  2139. // 预加载第三个接口的音频
  2140. if (result23?.data?.url) {
  2141. await preloadAudio(result23.data.url.trim(), "three");
  2142. } else {
  2143. audioPreloadStatus.three.loaded = true;
  2144. }
  2145. // 检查是否可以执行
  2146. checkAndExecuteInOrder();
  2147. } catch (error) {
  2148. console.error("ThreeAPI失败:", error);
  2149. apiStatus.three.completed = true;
  2150. apiStatus.three.error = error;
  2151. audioPreloadStatus.three.loaded = true;
  2152. checkAndExecuteInOrder();
  2153. }
  2154. };
  2155. const handleFourAPI = async () => {
  2156. try {
  2157. result24 = await dbqbSecondFourAPI(params2);
  2158. if (result24.code == 400) {
  2159. throw new Error("API返回错误码400,请求失败");
  2160. }
  2161. console.log("FourAPI成功返回:", result24);
  2162. apiStatus.four.completed = true;
  2163. apiStatus.four.result = result24;
  2164. // 预加载第四个接口的音频
  2165. if (result24?.data?.url) {
  2166. await preloadAudio(result24.data.url.trim(), "four");
  2167. } else {
  2168. audioPreloadStatus.four.loaded = true;
  2169. }
  2170. // 检查是否可以执行
  2171. checkAndExecuteInOrder();
  2172. } catch (error) {
  2173. console.error("FourAPI失败:", error);
  2174. apiStatus.four.completed = true;
  2175. apiStatus.four.error = error;
  2176. audioPreloadStatus.four.loaded = true;
  2177. checkAndExecuteInOrder();
  2178. }
  2179. };
  2180. if (isLiuSe && isAIGoldBull) {
  2181. handleOneAPI();
  2182. handleTwoAPI();
  2183. handleThreeAPI();
  2184. handleFourAPI();
  2185. } else {
  2186. chatStore.messages.pop();
  2187. chatStore.messages.push({
  2188. class: "ing",
  2189. type: "ing",
  2190. flag: false,
  2191. content: "数据缺失,请稍后重试",
  2192. });
  2193. chatStore.isLoading = false;
  2194. emit("enableInput");
  2195. }
  2196. } catch (e) {
  2197. console.error("请求失败:", e);
  2198. hasValidData.value = false; // 请求失败时设置数据无效
  2199. // chatStore.messages.pop();
  2200. // chatStore.messages.push({
  2201. // sender: "ai",
  2202. // content: "AI思考失败,请稍后再试... ",
  2203. // });
  2204. // chatStore.setLoading(false);
  2205. } finally {
  2206. // chatStore.setLoading(false);
  2207. await chatStore.getUserCount();
  2208. }
  2209. }
  2210. }
  2211. },
  2212. { deep: false }
  2213. );
  2214. // 点击历史记录
  2215. watch(
  2216. () => chatStore.dbqbClickRecord,
  2217. (newValue, oldValue) => {
  2218. console.log("new", newValue);
  2219. if (!newValue || Object.keys(newValue).length === 0) {
  2220. return;
  2221. }
  2222. const clickRecord = ref(newValue);
  2223. console.log("dbqbClickRecord 发生变化:", clickRecord.value);
  2224. // 在下一个事件循环中清空 dbqbClickRecord
  2225. setTimeout(() => {
  2226. chatStore.dbqbClickRecord = {};
  2227. console.log("dbqbClickRecord 已清空");
  2228. }, 0);
  2229. if (
  2230. !clickRecord.value.wokeFlowData.One ||
  2231. !clickRecord.value.wokeFlowData.Two ||
  2232. !clickRecord.value.wokeFlowData.Three ||
  2233. !clickRecord.value.wokeFlowData.Four
  2234. ) {
  2235. return;
  2236. }
  2237. try {
  2238. // 清理语音下标
  2239. chatStore.currentUserIndex = null;
  2240. audioStore.stop(); // 暂停语音
  2241. // 解开输入框
  2242. emit("enableInput");
  2243. // 清除打字机队列和状态
  2244. typingQueue.value = [];
  2245. isTypingInProgress.value = false;
  2246. // 清空聊天框内容
  2247. chatStore.messages = [];
  2248. chatStore.messages.push({
  2249. sender: "user",
  2250. timestamp: clickRecord.value.createdTime,
  2251. content: clickRecord.value.stockName+'('+clickRecord.value.stockCode+')',
  2252. audioArray: [
  2253. clickRecord.value.wokeFlowData.One.url,
  2254. clickRecord.value.wokeFlowData.Two.url,
  2255. clickRecord.value.wokeFlowData.Three.url,
  2256. clickRecord.value.wokeFlowData.Four.url,
  2257. ],
  2258. audioStatus: false,
  2259. });
  2260. chatStore.messages.push({
  2261. sender: "ai",
  2262. class: "title1",
  2263. type: "title1",
  2264. content: clickRecord.value.stockName + "全景作战报告",
  2265. date: clickRecord.value.wokeFlowData.One.date,
  2266. });
  2267. const pc1 = marked(
  2268. clickRecord.value.wokeFlowData.One.name +
  2269. "\n" +
  2270. clickRecord.value.wokeFlowData.One.price +
  2271. "\n" +
  2272. clickRecord.value.wokeFlowData.One.date
  2273. );
  2274. chatStore.messages.push({
  2275. sender: "ai",
  2276. class: "content1",
  2277. type: "content1",
  2278. content: pc1,
  2279. });
  2280. const HomePage = clickRecord.value.stockData.HomePage;
  2281. if (HomePage) {
  2282. const LiuSeData = JSON.parse(JSON.stringify(toRaw(HomePage)));
  2283. const sz = fnGetData(LiuSeData);
  2284. if (sz) {
  2285. hasValidData.value = true;
  2286. console.log("hasValidData设置为:", hasValidData.value);
  2287. }
  2288. // 先推送K线图消息
  2289. const klineMessageId1 = `kline-${Date.now()}`;
  2290. console.log("生成K线消息ID:", klineMessageId1);
  2291. chatStore.messages.push({
  2292. sender: "ai",
  2293. class: "content1",
  2294. type: "content1",
  2295. kline: true,
  2296. chartData: sz,
  2297. messageId: klineMessageId1,
  2298. hasValidData: true,
  2299. klineType: 1,
  2300. });
  2301. // 在渲染完成后初始化图表
  2302. nextTick(() => {
  2303. console.log("nextTick开始 - 准备渲染图表");
  2304. console.log("消息列表:", chatStore.messages);
  2305. // 寻找最新添加的K线消息索引
  2306. let klineIndex = -1;
  2307. for (let i = 0; i < chatStore.messages.length; i++) {
  2308. if (chatStore.messages[i].messageId === klineMessageId1) {
  2309. klineIndex = i;
  2310. break;
  2311. }
  2312. }
  2313. console.log("找到的K线消息索引:", klineIndex);
  2314. if (klineIndex !== -1) {
  2315. const containerId = `kline-container-${klineIndex}`;
  2316. console.log("图表容器ID:", containerId);
  2317. // 确保DOM已经渲染完成
  2318. setTimeout(() => {
  2319. console.log("延时执行,确保DOM已渲染");
  2320. KlineCanvsEcharts(containerId);
  2321. }, 100); // 短暂延时确保DOM已渲染
  2322. } else {
  2323. console.warn("未找到K线消息");
  2324. }
  2325. });
  2326. }
  2327. const AIGoldBull = clickRecord.value.stockData.AIGoldBull;
  2328. // 度牛尺K线图
  2329. if (
  2330. AIGoldBull &&
  2331. AIGoldBull.DNC &&
  2332. AIGoldBull.FCX &&
  2333. AIGoldBull.JN &&
  2334. AIGoldBull.KLine20 &&
  2335. AIGoldBull.QSXH
  2336. ) {
  2337. const AIGoldBullData = JSON.parse(JSON.stringify(toRaw(AIGoldBull)));
  2338. const HomePageData = JSON.parse(JSON.stringify(toRaw(HomePage)));
  2339. console.log("处理 K 线数据 - 开始");
  2340. console.log("AIGoldBullData", AIGoldBullData);
  2341. console.log("HomePageData", HomePageData);
  2342. const Kline20 = {
  2343. name: HomePageData.StockInformation.Name,
  2344. Kline: AIGoldBullData,
  2345. };
  2346. // 打印K线数据结构
  2347. console.log("K线数据结构:", Kline20);
  2348. console.log("K线数据名称:", Kline20.name);
  2349. console.log("K线数据:", Kline20.Kline ? Kline20.Kline : null);
  2350. // 设置数据有效标志
  2351. hasValidData.value = true;
  2352. console.log("hasValidData设置为:", hasValidData.value);
  2353. // chatStore.messages.pop();
  2354. // 先推送K线图消息
  2355. const klineMessageId2 = `kline-${Date.now() + 1}`;
  2356. console.log("生成K线消息ID:", klineMessageId2);
  2357. chatStore.messages.push({
  2358. sender: "ai",
  2359. class: "content2",
  2360. type: "content2",
  2361. kline: true,
  2362. chartData: Kline20,
  2363. messageId: klineMessageId2,
  2364. hasValidData: true, // 添加hasValidData标志
  2365. klineType: 2,
  2366. });
  2367. // 在渲染完成后初始化图表
  2368. nextTick(() => {
  2369. console.log("nextTick开始 - 准备渲染图表");
  2370. console.log("消息列表:", chatStore.messages);
  2371. // 寻找最新添加的K线消息索引
  2372. let klineIndex = -1;
  2373. for (let i = 0; i < chatStore.messages.length; i++) {
  2374. if (chatStore.messages[i].messageId === klineMessageId2) {
  2375. klineIndex = i;
  2376. break;
  2377. }
  2378. }
  2379. console.log("找到的K线消息索引:", klineIndex);
  2380. if (klineIndex !== -1) {
  2381. const containerId = `kline-container-${klineIndex}`;
  2382. console.log("图表容器ID:", containerId);
  2383. // 确保DOM已经渲染完成
  2384. setTimeout(() => {
  2385. console.log("延时执行,确保DOM已渲染");
  2386. KlineCanvsEcharts(containerId);
  2387. }, 100); // 短暂延时确保DOM已渲染
  2388. } else {
  2389. console.warn("未找到K线消息");
  2390. }
  2391. });
  2392. }
  2393. chatStore.messages.push({
  2394. sender: "ai",
  2395. class: "title2",
  2396. type: "title2",
  2397. content: "",
  2398. });
  2399. const pc2 = marked(clickRecord.value.wokeFlowData.Two.hxjzpg);
  2400. // 先推送初始消息
  2401. chatStore.messages.push({
  2402. sender: "ai",
  2403. class: "content3",
  2404. type: "content3",
  2405. content: pc2,
  2406. });
  2407. chatStore.messages.push({
  2408. sender: "ai",
  2409. class: "title3",
  2410. type: "title3",
  2411. content: title2,
  2412. });
  2413. const ac3 = `<p style="margin:0;color:#FFD700;font-weight:bold;display:flex;justify-content:center;font-size:22px">【主力行为】</p><p>${clickRecord.value.wokeFlowData.Three.zhuli1}</p><p>${clickRecord.value.wokeFlowData.Three.zhuli2}</p><p>${clickRecord.value.wokeFlowData.Three.zhuli3}</p>`;
  2414. // 先推送初始消息
  2415. chatStore.messages.push({
  2416. sender: "ai",
  2417. class: "content3",
  2418. type: "content3",
  2419. content: ac3,
  2420. isTyping: true,
  2421. });
  2422. chatStore.messages.push({
  2423. sender: "ai",
  2424. class: "title3",
  2425. type: "title3",
  2426. content: title3,
  2427. });
  2428. const arr = clickRecord.value.wokeFlowData.Three.kongjian.split(",");
  2429. const kongjian = `<p style="margin:0;color:#FFD700;font-weight:bold;display:flex;justify-content:center;font-size:22px">【空间维度】</p><p style="display:flex;justify-content:center;">${arr[0]},${arr[1]}</p><p style="display:flex;justify-content:center;">${arr[2]},${arr[3]}</p>`;
  2430. const shijian = `<p style="margin:0;color:#FFD700;font-weight:bold;display:flex;justify-content:center;font-size:22px">【时间维度】</p><p style="display:flex;justify-content:center;">${clickRecord.value.wokeFlowData.Three.shijian}</p>`;
  2431. const nengliang = `<p style="margin:0;color:#FFD700;font-weight:bold;display:flex;justify-content:center;font-size:22px">【能量维度】</p><p style="display:flex;justify-content:center;">${clickRecord.value.wokeFlowData.Three.nengliang}</p>`;
  2432. const ac4 = kongjian + shijian + nengliang;
  2433. // 先推送初始消息
  2434. chatStore.messages.push({
  2435. sender: "ai",
  2436. class: "content3",
  2437. type: "content3",
  2438. content: ac4,
  2439. });
  2440. chatStore.messages.push({
  2441. sender: "ai",
  2442. class: "title3",
  2443. type: "title3",
  2444. content: title4,
  2445. });
  2446. const cftj = `<p style="margin:0;color:#FFD700;font-weight:bold;display:flex;justify-content:center;font-size:22px">【触发条件】</p><p>${clickRecord.value.wokeFlowData.Four.cftl}</p>`;
  2447. const gfzl = `<p style="margin:0;color:#FFD700;font-weight:bold;display:flex;justify-content:center;font-size:22px">【攻防指令】</p><p>${clickRecord.value.wokeFlowData.Four.gfzl}</p>`;
  2448. const ac5 = cftj + gfzl;
  2449. // 先推送初始消息
  2450. chatStore.messages.push({
  2451. sender: "ai",
  2452. class: "content3",
  2453. type: "content3",
  2454. content: ac5,
  2455. });
  2456. chatStore.messages.push({
  2457. sender: "ai",
  2458. class: "mianze",
  2459. type: "mianze",
  2460. content: "该内容由AI生成,请注意甄别",
  2461. end: true,
  2462. });
  2463. } catch (e) {
  2464. ElMessage.error("历史数据获取出错!");
  2465. console.error("e", e);
  2466. }
  2467. },
  2468. {
  2469. deep: true, // 深度监听对象内部属性的变化
  2470. immediate: true, // 立即执行一次回调
  2471. }
  2472. );
  2473. function KlineCanvsEcharts(containerId) {
  2474. function vwToPx(vw) {
  2475. console.log((window.innerWidth * vw) / 100, "vwToPx");
  2476. return (window.innerWidth * vw) / 100;
  2477. }
  2478. // console.log("KLine渲染: 开始处理数据, 容器ID:", containerId);
  2479. // 从 chatStore 中获取数据
  2480. const messages = chatStore.messages;
  2481. // console.log("KLine渲染: 获取到的消息:", messages);
  2482. let klineMessageIndex = -1;
  2483. let klineData = null;
  2484. // 查找最近的 K线 消息
  2485. // for (let i = messages.length - 1; i >= 0; i--) {
  2486. // console.log('KLine渲染: 检查消息:', messages[i]);
  2487. // if (messages[i].type === 'kline' && messages[i].chartData) {
  2488. // klineMessageIndex = i;
  2489. // klineData = messages[i].chartData;
  2490. // console.log('KLine渲染: 找到K线消息索引:', klineMessageIndex);
  2491. // console.log('KLine渲染: 找到K线数据:', klineData);
  2492. // break;
  2493. // }
  2494. // }
  2495. klineMessageIndex = containerId.split("-")[2];
  2496. // console.log("KLine渲染: 找到K线消息索引:", klineMessageIndex);
  2497. if (
  2498. messages[klineMessageIndex].kline &&
  2499. messages[klineMessageIndex].chartData
  2500. ) {
  2501. klineData = messages[klineMessageIndex].chartData;
  2502. }
  2503. var KlineOption = {};
  2504. // 检测设备类型
  2505. const isMobile = window.innerWidth < 768;
  2506. const isTablet = window.innerWidth >= 768 && window.innerWidth < 1024;
  2507. console.log(
  2508. "KLine渲染: 设备类型",
  2509. isMobile ? "移动设备" : isTablet ? "平板设备" : "桌面设备"
  2510. );
  2511. if (messages[klineMessageIndex].klineType == 1) {
  2512. if (!klineData) {
  2513. // console.warn("六色罗盘渲染: 数据无效 - 在chatStore中找不到有效的K线数据");
  2514. return;
  2515. }
  2516. // 获取容器元素
  2517. const container = document.getElementById(containerId);
  2518. if (!container) {
  2519. // console.error("六色罗盘渲染: 找不到容器元素:", containerId);
  2520. return;
  2521. }
  2522. // 创建图表实例
  2523. // console.log("六色罗盘渲染: 创建图表实例");
  2524. try {
  2525. // 如果已有实例,先销毁
  2526. if (chartInstancesMap[containerId]) {
  2527. // console.log("六色罗盘渲染: 销毁已有图表实例");
  2528. chartInstancesMap[containerId].dispose();
  2529. delete chartInstancesMap[containerId];
  2530. }
  2531. // 使用普通变量存储实例
  2532. chartInstancesMap[containerId] = echarts.init(container);
  2533. // console.log("六色罗盘渲染: 图表实例创建成功");
  2534. } catch (error) {
  2535. // console.error("六色罗盘渲染: 图表实例创建失败:", error);
  2536. return;
  2537. }
  2538. const name = ref("六色罗盘");
  2539. const size = ref(16);
  2540. // PC版字体大小
  2541. if (window.innerWidth > 768) {
  2542. size.value = 25;
  2543. }
  2544. KlineOption = {
  2545. tooltip: {
  2546. show: !1,
  2547. },
  2548. series: [
  2549. {
  2550. name: "\u4eea\u8868\u76d8",
  2551. type: "gauge",
  2552. center: ["50%", "50%"],
  2553. radius: window.innerWidth > 768 ? "90%" : "70%",
  2554. startAngle: 140,
  2555. endAngle: -140,
  2556. min: 0,
  2557. max: 6,
  2558. precision: 0,
  2559. splitNumber: 30, // 分成30份
  2560. axisLine: {
  2561. show: !0,
  2562. lineStyle: {
  2563. color: [
  2564. [0.17, "#FC4407"],
  2565. [0.33, "#FDC404"],
  2566. [0.5, "#2D8FFD"],
  2567. [0.67, "#87CCE7"],
  2568. [0.83, "#C1F478"],
  2569. [1, "#8FEB8D"],
  2570. ],
  2571. width: 20,
  2572. },
  2573. },
  2574. axisTick: {
  2575. show: !0,
  2576. splitNumber: 9,
  2577. length: 8,
  2578. lineStyle: {
  2579. color: "#eee",
  2580. width: 1,
  2581. type: "solid",
  2582. },
  2583. },
  2584. axisLabel: {
  2585. show: true,
  2586. formatter: function (v) {},
  2587. textStyle: {
  2588. color: "auto",
  2589. },
  2590. },
  2591. // 中途切割
  2592. splitLine: {
  2593. show: !0,
  2594. length: 20,
  2595. lineStyle: {
  2596. color: "#eee",
  2597. width: 2,
  2598. type: "solid",
  2599. },
  2600. },
  2601. pointer: {
  2602. length: "80%",
  2603. width: 8,
  2604. color: "auto",
  2605. },
  2606. title: {
  2607. show: !0,
  2608. offsetCenter: ["-65%", -10],
  2609. textStyle: {
  2610. color: "#333",
  2611. fontSize: 15,
  2612. },
  2613. },
  2614. detail: {
  2615. show: !0,
  2616. backgroundColor: "rgba(0,0,0,0)",
  2617. borderWidth: 0,
  2618. borderColor: "#ccc",
  2619. width: 100,
  2620. height: 40,
  2621. offsetCenter: ["-90%", 0], // name位置
  2622. formatter: function () {
  2623. return name.value;
  2624. },
  2625. textStyle: {
  2626. color: "auto",
  2627. fontSize: size.value, // 字体尺寸
  2628. },
  2629. },
  2630. data: [{ value: klineData }],
  2631. },
  2632. ],
  2633. };
  2634. } else if (messages[klineMessageIndex].klineType == 2) {
  2635. if (!klineData || !klineData.Kline) {
  2636. // console.warn("KLine渲染: 数据无效 - 在chatStore中找不到有效的K线数据");
  2637. return;
  2638. }
  2639. // 获取容器元素
  2640. const container = document.getElementById(containerId);
  2641. if (!container) {
  2642. // console.error("KLine渲染: 找不到容器元素:", containerId);
  2643. return;
  2644. }
  2645. // 创建图表实例
  2646. // console.log("KLine渲染: 创建图表实例");
  2647. try {
  2648. // 如果已有实例,先销毁
  2649. if (chartInstancesMap[containerId]) {
  2650. // console.log("KLine渲染: 销毁已有图表实例");
  2651. chartInstancesMap[containerId].dispose();
  2652. delete chartInstancesMap[containerId];
  2653. }
  2654. // 使用普通变量存储实例
  2655. chartInstancesMap[containerId] = echarts.init(container);
  2656. // console.log("KLine渲染: 图表实例创建成功");
  2657. } catch (error) {
  2658. // console.error("KLine渲染: 图表实例创建失败:", error);
  2659. return;
  2660. }
  2661. const data = klineData.Kline;
  2662. // console.log("KLine渲染: Kline数据", data);
  2663. // 切割数据方法
  2664. const splitData = (a) => {
  2665. // console.log("KLine渲染: 开始数据切割");
  2666. const categoryData = [];
  2667. let values = [];
  2668. for (let i = 0; i < a.length; i++) {
  2669. categoryData.push(a[i][0]);
  2670. values.push([a[i][1], a[i][2], a[i][3], a[i][4]]);
  2671. }
  2672. // console.log("KLine渲染: 日期数据点数量", categoryData.length);
  2673. // console.log("KLine渲染: 值数据点数量", values.length);
  2674. return { categoryData, values };
  2675. };
  2676. // 给配置项
  2677. // console.log("KLine渲染: 开始配置图表选项");
  2678. const arr1 = [];
  2679. const arr2 = [];
  2680. const arr3 = [];
  2681. const arr4 = [];
  2682. const changeColorKline = (QSXH, KLine20) => {
  2683. if (QSXH) {
  2684. QSXH.map((item) => {
  2685. KLine20.map((kline_item) => {
  2686. if (item[1] == 1 && item[0] == kline_item[0]) {
  2687. arr1.push(kline_item);
  2688. arr2.push([
  2689. kline_item[0],
  2690. null,
  2691. null,
  2692. null,
  2693. null,
  2694. null,
  2695. null,
  2696. null,
  2697. ]);
  2698. arr3.push([
  2699. kline_item[0],
  2700. null,
  2701. null,
  2702. null,
  2703. null,
  2704. null,
  2705. null,
  2706. null,
  2707. ]);
  2708. arr4.push([
  2709. kline_item[0],
  2710. null,
  2711. null,
  2712. null,
  2713. null,
  2714. null,
  2715. null,
  2716. null,
  2717. ]);
  2718. }
  2719. if (item[1] == 2 && item[0] == kline_item[0]) {
  2720. arr2.push(kline_item);
  2721. arr1.push([
  2722. kline_item[0],
  2723. null,
  2724. null,
  2725. null,
  2726. null,
  2727. null,
  2728. null,
  2729. null,
  2730. ]);
  2731. arr3.push([
  2732. kline_item[0],
  2733. null,
  2734. null,
  2735. null,
  2736. null,
  2737. null,
  2738. null,
  2739. null,
  2740. ]);
  2741. arr4.push([
  2742. kline_item[0],
  2743. null,
  2744. null,
  2745. null,
  2746. null,
  2747. null,
  2748. null,
  2749. null,
  2750. ]);
  2751. }
  2752. if (item[1] == 3 && item[0] == kline_item[0]) {
  2753. arr3.push(kline_item);
  2754. arr2.push([
  2755. kline_item[0],
  2756. null,
  2757. null,
  2758. null,
  2759. null,
  2760. null,
  2761. null,
  2762. null,
  2763. ]);
  2764. arr1.push([
  2765. kline_item[0],
  2766. null,
  2767. null,
  2768. null,
  2769. null,
  2770. null,
  2771. null,
  2772. null,
  2773. ]);
  2774. arr4.push([
  2775. kline_item[0],
  2776. null,
  2777. null,
  2778. null,
  2779. null,
  2780. null,
  2781. null,
  2782. null,
  2783. ]);
  2784. }
  2785. if (item[1] == 4 && item[0] == kline_item[0]) {
  2786. arr4.push(kline_item);
  2787. arr2.push([
  2788. kline_item[0],
  2789. null,
  2790. null,
  2791. null,
  2792. null,
  2793. null,
  2794. null,
  2795. null,
  2796. ]);
  2797. arr3.push([
  2798. kline_item[0],
  2799. null,
  2800. null,
  2801. null,
  2802. null,
  2803. null,
  2804. null,
  2805. null,
  2806. ]);
  2807. arr1.push([
  2808. kline_item[0],
  2809. null,
  2810. null,
  2811. null,
  2812. null,
  2813. null,
  2814. null,
  2815. null,
  2816. ]);
  2817. }
  2818. });
  2819. });
  2820. }
  2821. };
  2822. console.log(arr1, arr2, arr3, arr4);
  2823. changeColorKline(data.QSXH, data.KLine20);
  2824. var dealData = splitData(data.KLine20);
  2825. var dealData1 = splitData(arr1);
  2826. var dealData2 = splitData(arr2);
  2827. var dealData3 = splitData(arr3);
  2828. var dealData4 = splitData(arr4);
  2829. var dealGnBullData = data.JN;
  2830. function processMAData(data) {
  2831. let processedData = [];
  2832. data.forEach((item, idx) => {
  2833. processedData.push({
  2834. date: item[0],
  2835. value: item[1],
  2836. type: item[2],
  2837. });
  2838. });
  2839. // 当某一种type只存在一天,设置另一种type透明
  2840. let singleTypeRed = [{ min: 0, max: 0, color: "#000" }];
  2841. let singleTypeYellow = [{ min: 0, max: 0, color: "#000" }];
  2842. let singleTypeGreen = [{ min: 0, max: 0, color: "#000" }];
  2843. for (let i = 1; i < processedData.length; i++) {
  2844. if (processedData[i].type !== processedData[i - 1].type) {
  2845. if (
  2846. i == processedData.length - 1 ||
  2847. (processedData[i].type !== processedData[i + 1].type &&
  2848. processedData[i - 1].type === processedData[i + 1].type)
  2849. ) {
  2850. if (processedData[i - 1].type === 0) {
  2851. singleTypeGreen.push({
  2852. min: i - 1,
  2853. max: i,
  2854. color: "rgba(0,0,0,0)",
  2855. });
  2856. } else if (processedData[i - 1].type === 1) {
  2857. singleTypeRed.push({
  2858. min: i - 1,
  2859. max: i,
  2860. color: "rgba(0,0,0,0)",
  2861. });
  2862. } else if (processedData[i - 1].type === 2) {
  2863. singleTypeYellow.push({
  2864. min: i - 1,
  2865. max: i,
  2866. color: "rgba(0,0,0,0)",
  2867. });
  2868. }
  2869. }
  2870. }
  2871. if (processedData[i].type !== processedData[i - 1].type) {
  2872. if (processedData[i].type == 0) {
  2873. processedData[i - 1].isTransitionGreen = 1;
  2874. } else if (processedData[i].type == 1) {
  2875. processedData[i - 1].isTransitionRed = 1;
  2876. } else if (processedData[i].type == 2) {
  2877. processedData[i - 1].isTransitionYellow = 1;
  2878. }
  2879. // // 创建过渡点,使用前一个点的值
  2880. // processedData[i - 1].isTransition = true
  2881. }
  2882. }
  2883. let greenData = [];
  2884. let redData = [];
  2885. let yellowData = [];
  2886. processedData.forEach((item, idx) => {
  2887. const point = [item.date, item.value];
  2888. if (item.type === 0) {
  2889. greenData.push(point);
  2890. redData.push([item.date, "-"]);
  2891. yellowData.push([item.date, "-"]);
  2892. // if (item.isTransition) {
  2893. // redData[redData.length - 1] = [processedData[idx].date, processedData[idx].value]
  2894. // yellowData[yellowData.length - 1] = [processedData[idx].date, processedData[idx].value]
  2895. // }
  2896. if (item.isTransitionGreen) {
  2897. greenData[greenData.length - 1] = [
  2898. processedData[idx].date,
  2899. processedData[idx].value,
  2900. ];
  2901. } else if (item.isTransitionRed) {
  2902. redData[redData.length - 1] = [
  2903. processedData[idx].date,
  2904. processedData[idx].value,
  2905. ];
  2906. } else if (item.isTransitionYellow) {
  2907. yellowData[yellowData.length - 1] = [
  2908. processedData[idx].date,
  2909. processedData[idx].value,
  2910. ];
  2911. }
  2912. } else if (item.type === 1) {
  2913. redData.push(point);
  2914. greenData.push([item.date, "-"]);
  2915. yellowData.push([item.date, "-"]);
  2916. // if (item.isTransition) {
  2917. // greenData[greenData.length - 1] = [processedData[idx].date, processedData[idx].value]
  2918. // yellowData[yellowData.length - 1] = [processedData[idx].date, processedData[idx].value]
  2919. // }
  2920. if (item.isTransitionGreen) {
  2921. greenData[greenData.length - 1] = [
  2922. processedData[idx].date,
  2923. processedData[idx].value,
  2924. ];
  2925. } else if (item.isTransitionRed) {
  2926. redData[redData.length - 1] = [
  2927. processedData[idx].date,
  2928. processedData[idx].value,
  2929. ];
  2930. } else if (item.isTransitionYellow) {
  2931. yellowData[yellowData.length - 1] = [
  2932. processedData[idx].date,
  2933. processedData[idx].value,
  2934. ];
  2935. }
  2936. } else if (item.type === 2) {
  2937. redData.push([item.date, "-"]);
  2938. greenData.push([item.date, "-"]);
  2939. yellowData.push(point);
  2940. // if (item.isTransition) {
  2941. // greenData[greenData.length - 1] = [processedData[idx].date, processedData[idx].value]
  2942. // redData[redData.length - 1] = [processedData[idx].date, processedData[idx].value]
  2943. // }
  2944. if (item.isTransitionGreen) {
  2945. greenData[greenData.length - 1] = [
  2946. processedData[idx].date,
  2947. processedData[idx].value,
  2948. ];
  2949. } else if (item.isTransitionRed) {
  2950. redData[redData.length - 1] = [
  2951. processedData[idx].date,
  2952. processedData[idx].value,
  2953. ];
  2954. } else if (item.isTransitionYellow) {
  2955. yellowData[yellowData.length - 1] = [
  2956. processedData[idx].date,
  2957. processedData[idx].value,
  2958. ];
  2959. }
  2960. }
  2961. });
  2962. return {
  2963. greenData: greenData,
  2964. redData: redData,
  2965. yellowData: yellowData,
  2966. singleTypeGreen: singleTypeGreen,
  2967. singleTypeRed: singleTypeRed,
  2968. singleTypeYellow: singleTypeYellow,
  2969. };
  2970. }
  2971. const maData = processMAData(data.FCX);
  2972. const maDuchiData = processMAData(data.DNC);
  2973. if (data.FCX[0][1] == "-1") {
  2974. maData.greenData = [];
  2975. maData.redData = [];
  2976. maData.yellowData = [];
  2977. }
  2978. const processBarData = (data) => {
  2979. const barData = [];
  2980. const markPointData = [];
  2981. data.forEach((item) => {
  2982. let color;
  2983. switch (item[4]) {
  2984. case 1:
  2985. color = "#13E113";
  2986. break;
  2987. case 2:
  2988. color = "#FF0E00";
  2989. break;
  2990. case 3:
  2991. color = "#0000FE";
  2992. break;
  2993. case 4:
  2994. color = "#1397FF";
  2995. break;
  2996. }
  2997. barData.push({
  2998. value: item[5],
  2999. itemStyle: {
  3000. normal: {
  3001. color: color,
  3002. },
  3003. },
  3004. });
  3005. if (item[1] === 1) {
  3006. markPointData.push({
  3007. coord: [item[0], item[5]],
  3008. symbol:
  3009. "image://https://d31zlh4on95l9h.cloudfront.net/images/5iujb101000d5si3v3hr7w2vg0h43z1u.png",
  3010. symbolSize: [30, 30],
  3011. label: {
  3012. normal: {
  3013. color: "rgba(0, 0, 0, 0)",
  3014. },
  3015. },
  3016. });
  3017. }
  3018. if (item[2] === 1) {
  3019. markPointData.push({
  3020. coord: [item[0], item[5] / 2],
  3021. symbol:
  3022. "image://https://d31zlh4on95l9h.cloudfront.net/images/5iujaz01000d5si016bxdf6vh0377d2h.png",
  3023. symbolSize: [30, 30],
  3024. label: {
  3025. normal: {
  3026. color: "rgba(0, 0, 0, 0)",
  3027. },
  3028. },
  3029. });
  3030. }
  3031. if (item[3] === 1) {
  3032. markPointData.push({
  3033. coord: [item[0], 0],
  3034. symbol:
  3035. "image://https://d31zlh4on95l9h.cloudfront.net/images/5iujb001000d5shzls0tmd4vs0e5tdrw.png",
  3036. symbolSize: [30, 30],
  3037. label: {
  3038. normal: {
  3039. color: "rgba(0, 0, 0, 0)",
  3040. },
  3041. },
  3042. });
  3043. }
  3044. });
  3045. return { barData, markPointData };
  3046. };
  3047. const { barData, markPointData } = processBarData(dealGnBullData);
  3048. KlineOption = {
  3049. legend: [
  3050. {
  3051. textStyle: {
  3052. color: "black",
  3053. fontSize: window.innerWidth > 768 ? 12 : 9,
  3054. },
  3055. width: "100%",
  3056. top: window.innerWidth > 768 ? "5%" : "4%",
  3057. left: "center",
  3058. itemGap: window.innerWidth > 768 ? 20 : 10,
  3059. itemWidth: 10,
  3060. itemHeight: 10,
  3061. data: [
  3062. {
  3063. name: "进攻K线",
  3064. itemStyle: {
  3065. color: "rgb(255,0,0)",
  3066. },
  3067. },
  3068. {
  3069. name: "防守K线",
  3070. itemStyle: {
  3071. color: "red",
  3072. },
  3073. },
  3074. {
  3075. name: "推进K线",
  3076. itemStyle: {
  3077. color: "orange",
  3078. },
  3079. },
  3080. {
  3081. name: "撤退K线",
  3082. itemStyle: {
  3083. color: "rgb(84,252,252)",
  3084. },
  3085. },
  3086. ],
  3087. },
  3088. {
  3089. textStyle: {
  3090. color: "black",
  3091. fontSize: window.innerWidth > 768 ? 12 : 9,
  3092. },
  3093. orient: "horizontal",
  3094. top: window.innerWidth > 768 ? "8%" : "7%",
  3095. width: "100%",
  3096. left: "center",
  3097. itemGap: 15,
  3098. data: [
  3099. {
  3100. name: "{green|━}{red|━} " + "牵牛绳",
  3101. icon: "none",
  3102. textStyle: {
  3103. rich: {
  3104. green: {
  3105. color: "green",
  3106. fontSize: window.innerWidth > 768 ? 12 : 9,
  3107. },
  3108. red: {
  3109. color: "red",
  3110. fontSize: window.innerWidth > 768 ? 12 : 9,
  3111. },
  3112. },
  3113. },
  3114. },
  3115. {
  3116. name: "龙线",
  3117. },
  3118. {
  3119. name: "虫线",
  3120. },
  3121. ],
  3122. },
  3123. {
  3124. textStyle: {
  3125. color: "black",
  3126. fontSize: window.innerWidth > 768 ? 12 : 9,
  3127. },
  3128. orient: "horizontal",
  3129. top: window.innerWidth > 768 ? "62%" : "60%",
  3130. width: "100%",
  3131. left: "center",
  3132. itemGap: 15,
  3133. data: [
  3134. {
  3135. name: "{green|━}{red|━} " + "度牛尺",
  3136. icon: "none",
  3137. textStyle: {
  3138. rich: {
  3139. green: {
  3140. color: "green",
  3141. fontSize: window.innerWidth > 768 ? 12 : 9,
  3142. },
  3143. red: {
  3144. color: "red",
  3145. fontSize: window.innerWidth > 768 ? 12 : 9,
  3146. },
  3147. },
  3148. },
  3149. },
  3150. ],
  3151. },
  3152. ],
  3153. tooltip: {
  3154. formatter: function (a, b, d) {
  3155. if (a[0].seriesIndex == 0) {
  3156. const KlineTag = ref([]);
  3157. const AIBullTag = ref([]);
  3158. KlineTag.value = a.find((item) => item.data[1])?.data || [];
  3159. AIBullTag.value =
  3160. a.slice(4).find((item) => item.data[1] !== "-")?.data || [];
  3161. // console.log(AIBullTag.value)
  3162. return (
  3163. a[0].name +
  3164. "<br/>" +
  3165. "开盘价" +
  3166. ":" +
  3167. KlineTag.value[1] +
  3168. "<br/>" +
  3169. "收盘价" +
  3170. ":" +
  3171. KlineTag.value[2] +
  3172. "<br/>" +
  3173. "最低价" +
  3174. ":" +
  3175. KlineTag.value[3] +
  3176. "<br/>" +
  3177. "最高价" +
  3178. ":" +
  3179. KlineTag.value[4] +
  3180. "<br/>" +
  3181. "牵牛绳" +
  3182. ":" +
  3183. AIBullTag.value[1]
  3184. );
  3185. }
  3186. if (a[0].seriesIndex == 4) {
  3187. let formattedVolume;
  3188. if (a[0].data.value >= 10000) {
  3189. formattedVolume = (a[0].data.value / 10000).toFixed(2) + "w";
  3190. } else {
  3191. formattedVolume = a[0].data.value;
  3192. }
  3193. return a[0].name + "<br/>" + "成交量" + ":" + formattedVolume;
  3194. }
  3195. if ([10, 11, 12].includes(a[0].seriesIndex)) {
  3196. const duchiData = a.find(
  3197. (item) => item.data && item.data[1] !== "-"
  3198. );
  3199. return duchiData
  3200. ? a[0].axisValue + "<br/>" + "度牛尺" + ":" + duchiData.data[1]
  3201. : null;
  3202. }
  3203. },
  3204. trigger: "axis",
  3205. axisPointer: {
  3206. type: "cross",
  3207. },
  3208. backgroundColor: "rgba(119, 120, 125, 0.6)",
  3209. borderWidth: 1,
  3210. borderColor: "#77787D",
  3211. padding: 10,
  3212. textStyle: {
  3213. color: "#fff",
  3214. },
  3215. },
  3216. axisPointer: {
  3217. link: [
  3218. {
  3219. xAxisIndex: "all",
  3220. },
  3221. ],
  3222. label: {
  3223. backgroundColor: "#77787D",
  3224. },
  3225. },
  3226. toolbox: {
  3227. show: false,
  3228. },
  3229. grid: [
  3230. {
  3231. top: window.innerWidth > 768 ? "12%" : "10%",
  3232. left:
  3233. window.innerWidth > 1024
  3234. ? "14%"
  3235. : window.innerWidth > 768
  3236. ? "18%"
  3237. : window.innerWidth > 375
  3238. ? "20%"
  3239. : "22%",
  3240. right:
  3241. window.innerWidth > 1024
  3242. ? "9%"
  3243. : window.innerWidth > 768
  3244. ? "12%"
  3245. : "14%",
  3246. height: window.innerWidth > 768 ? "27%" : "29%",
  3247. containLabel: false,
  3248. },
  3249. {
  3250. top: window.innerWidth > 768 ? "42%" : "42%",
  3251. left:
  3252. window.innerWidth > 1024
  3253. ? "14%"
  3254. : window.innerWidth > 768
  3255. ? "18%"
  3256. : window.innerWidth > 375
  3257. ? "20%"
  3258. : "22%",
  3259. right:
  3260. window.innerWidth > 1024
  3261. ? "9%"
  3262. : window.innerWidth > 768
  3263. ? "12%"
  3264. : "14%",
  3265. height: window.innerWidth > 768 ? "20%" : "18%",
  3266. containLabel: false,
  3267. },
  3268. {
  3269. top: window.innerWidth > 768 ? "66%" : "64%",
  3270. left:
  3271. window.innerWidth > 1024
  3272. ? "14%"
  3273. : window.innerWidth > 768
  3274. ? "18%"
  3275. : window.innerWidth > 375
  3276. ? "20%"
  3277. : "22%",
  3278. right:
  3279. window.innerWidth > 1024
  3280. ? "9%"
  3281. : window.innerWidth > 768
  3282. ? "12%"
  3283. : "14%",
  3284. height: window.innerWidth > 768 ? "20%" : "22%",
  3285. containLabel: false,
  3286. },
  3287. ],
  3288. xAxis: [
  3289. {
  3290. type: "category",
  3291. data: dealData.categoryData,
  3292. boundaryGap: true,
  3293. axisLine: { onZero: false },
  3294. splitLine: { show: false },
  3295. min: "dataMin",
  3296. max: "dataMax",
  3297. axisPointer: {
  3298. z: 100,
  3299. },
  3300. axisLine: {
  3301. lineStyle: {
  3302. color: "black",
  3303. },
  3304. }, //
  3305. axisLabel: { show: false },
  3306. axisTick: { show: false },
  3307. },
  3308. {
  3309. type: "category",
  3310. gridIndex: 1,
  3311. data: dealData.categoryData,
  3312. boundaryGap: true,
  3313. axisLine: { lineStyle: { color: "black" } },
  3314. axisLabel: {
  3315. show: false,
  3316. interval: "auto",
  3317. },
  3318. },
  3319. {
  3320. type: "category",
  3321. gridIndex: 2,
  3322. data: dealData.categoryData,
  3323. boundaryGap: true,
  3324. axisLine: { lineStyle: { color: "black" } },
  3325. axisLabel: {
  3326. show: true,
  3327. interval: "auto",
  3328. fontSize: window.innerWidth > 768 ? 12 : 9,
  3329. },
  3330. },
  3331. ],
  3332. yAxis: [
  3333. {
  3334. scale: true,
  3335. gridIndex: 0,
  3336. position: "left",
  3337. axisLabel: {
  3338. inside: false,
  3339. align: "right",
  3340. fontSize: window.innerWidth > 768 ? 15 : 10,
  3341. },
  3342. axisLine: {
  3343. show: true,
  3344. lineStyle: {
  3345. fontSize: "",
  3346. color: "black",
  3347. },
  3348. },
  3349. axisTick: { show: false },
  3350. splitLine: { show: false },
  3351. },
  3352. {
  3353. scale: true,
  3354. gridIndex: 1,
  3355. splitNumber: 4,
  3356. min: 0,
  3357. minInterval: 1,
  3358. axisLabel: {
  3359. show: true,
  3360. fontSize: window.innerWidth > 768 ? 15 : 10,
  3361. margin: 8,
  3362. formatter: (value) => {
  3363. if (value >= 1000000000) {
  3364. return (value / 1000000000).toFixed(1) + "B";
  3365. } else if (value >= 1000000) {
  3366. return (value / 1000000).toFixed(1) + "M";
  3367. } else if (value >= 10000) {
  3368. return (value / 10000).toFixed(1) + "W";
  3369. }
  3370. return value.toFixed(0);
  3371. },
  3372. },
  3373. axisLine: { show: true, lineStyle: { color: "black" } },
  3374. axisTick: { show: false },
  3375. splitLine: { show: true, lineStyle: { type: "dashed" } },
  3376. boundaryGap: ["20%", "20%"],
  3377. },
  3378. {
  3379. type: "value",
  3380. gridIndex: 2,
  3381. min: 0,
  3382. max: 100,
  3383. axisLabel: {
  3384. show: true,
  3385. fontSize: window.innerWidth > 768 ? 15 : 10,
  3386. formatter: function (value) {
  3387. var customValues = [0, 20, 50, 80, 100];
  3388. return customValues.indexOf(value) > -1 ? value : "";
  3389. },
  3390. },
  3391. axisLine: {
  3392. show: true,
  3393. lineStyle: {
  3394. color: "black",
  3395. },
  3396. },
  3397. axisTick: {
  3398. show: false,
  3399. },
  3400. splitNumber: 10,
  3401. splitLine: {
  3402. show: true,
  3403. lineStyle: {
  3404. type: "dashed",
  3405. color: "#fff",
  3406. width: 1,
  3407. },
  3408. interval: function (index, value) {
  3409. return [20, 50, 80, 100].indexOf(value) > -1;
  3410. },
  3411. },
  3412. },
  3413. ],
  3414. dataZoom: [
  3415. {
  3416. type: "inside",
  3417. xAxisIndex: [0, 1, 2],
  3418. start: 55,
  3419. end: 100,
  3420. },
  3421. {
  3422. show: true,
  3423. xAxisIndex: [0, 1, 2],
  3424. type: "slider",
  3425. top: window.innerWidth > 768 ? "90%" : "91%",
  3426. // left: window.innerWidth > 768 ? "10%" : "8%",
  3427. // right: window.innerWidth > 768 ? "4%" : "8%",
  3428. height: 20,
  3429. start: 98,
  3430. end: 100,
  3431. textStyle: {
  3432. fontSize: window.innerWidth > 768 ? 12 : 9,
  3433. },
  3434. },
  3435. ],
  3436. visualMap: [
  3437. {
  3438. type: "piecewise",
  3439. show: false,
  3440. pieces: maData.singleTypeGreen,
  3441. outOfRange: {
  3442. color: "green",
  3443. },
  3444. dimension: 0,
  3445. seriesIndex: 7,
  3446. },
  3447. {
  3448. type: "piecewise",
  3449. show: false,
  3450. pieces: maData.singleTypeRed,
  3451. outOfRange: {
  3452. color: "red",
  3453. },
  3454. dimension: 0,
  3455. seriesIndex: 8,
  3456. },
  3457. {
  3458. type: "piecewise",
  3459. show: false,
  3460. pieces: maData.singleTypeYellow,
  3461. outOfRange: {
  3462. color: "yellow",
  3463. },
  3464. dimension: 0,
  3465. seriesIndex: 9,
  3466. },
  3467. ],
  3468. series: [
  3469. {
  3470. name: "进攻K线",
  3471. type: "candlestick",
  3472. barWidth: "50%",
  3473. data: dealData1.values,
  3474. xAxisIndex: 0,
  3475. yAxisIndex: 0,
  3476. itemStyle: {
  3477. normal: {
  3478. color: "rgb(255,0,0)",
  3479. color0: "rgb(255,0,0)",
  3480. borderColor: "rgb(255,0,0)",
  3481. borderColor0: "rgb(255,0,0)",
  3482. },
  3483. },
  3484. gridIndex: 0,
  3485. },
  3486. //
  3487. {
  3488. name: "推进K线",
  3489. type: "candlestick",
  3490. barWidth: "50%",
  3491. data: dealData2.values,
  3492. xAxisIndex: 0,
  3493. yAxisIndex: 0,
  3494. itemStyle: {
  3495. normal: {
  3496. color: "rgb(0,0,252)",
  3497. color0: "rgb(0,0,252)",
  3498. borderColor: "rgb(0,0,252)",
  3499. borderColor0: "rgb(0,0,252)",
  3500. },
  3501. },
  3502. gridIndex: 0,
  3503. },
  3504. {
  3505. name: "防守K线",
  3506. type: "candlestick",
  3507. barWidth: "50%",
  3508. data: dealData3.values,
  3509. xAxisIndex: 0,
  3510. yAxisIndex: 0,
  3511. itemStyle: {
  3512. normal: {
  3513. color: "orange",
  3514. color0: "orange",
  3515. borderColor: "orange",
  3516. borderColor0: "orange",
  3517. },
  3518. },
  3519. gridIndex: 0,
  3520. },
  3521. {
  3522. name: "撤退K线",
  3523. type: "candlestick",
  3524. barWidth: "50%",
  3525. data: dealData4.values,
  3526. xAxisIndex: 0,
  3527. yAxisIndex: 0,
  3528. itemStyle: {
  3529. normal: {
  3530. color: "rgb(84,252,252)",
  3531. color0: "rgb(84,252,252)",
  3532. borderColor: "rgb(84,252,252)",
  3533. borderColor0: "rgb(84,252,252)",
  3534. },
  3535. },
  3536. gridIndex: 0,
  3537. },
  3538. {
  3539. name: "成交量",
  3540. type: "bar",
  3541. barWidth: "70%",
  3542. xAxisIndex: 1,
  3543. yAxisIndex: 1,
  3544. data: barData,
  3545. markPoint: {
  3546. data: markPointData,
  3547. label: {
  3548. show: false,
  3549. },
  3550. },
  3551. },
  3552. {
  3553. name: "{green|━}{red|━} " + "牵牛绳",
  3554. type: "line",
  3555. data: [],
  3556. smooth: true,
  3557. symbol: "none",
  3558. xAxisIndex: 0,
  3559. yAxisIndex: 0,
  3560. showSymbol: false,
  3561. lineStyle: {
  3562. opacity: 0,
  3563. },
  3564. itemStyle: {
  3565. normal: {
  3566. color: "green",
  3567. },
  3568. },
  3569. gridIndex: 0,
  3570. },
  3571. {
  3572. name: "{green|━}{red|━} " + "度牛尺",
  3573. type: "line",
  3574. data: [],
  3575. smooth: true,
  3576. symbol: "none",
  3577. xAxisIndex: 0,
  3578. yAxisIndex: 0,
  3579. showSymbol: false,
  3580. lineStyle: {
  3581. opacity: 0,
  3582. },
  3583. itemStyle: {
  3584. normal: {
  3585. color: "green",
  3586. },
  3587. },
  3588. gridIndex: 0,
  3589. },
  3590. {
  3591. name: "虫线",
  3592. type: "line",
  3593. data: maData.greenData,
  3594. smooth: true,
  3595. symbol: "none",
  3596. xAxisIndex: 0,
  3597. yAxisIndex: 0,
  3598. itemStyle: {
  3599. normal: {
  3600. color: "green",
  3601. lineStyle: {
  3602. width: 2,
  3603. type: "solid",
  3604. },
  3605. },
  3606. },
  3607. gridIndex: 0,
  3608. },
  3609. {
  3610. name: "龙线",
  3611. type: "line",
  3612. data: maData.redData,
  3613. smooth: true,
  3614. symbol: "none",
  3615. xAxisIndex: 0,
  3616. yAxisIndex: 0,
  3617. itemStyle: {
  3618. normal: {
  3619. color: "red",
  3620. lineStyle: {
  3621. width: 2,
  3622. type: "solid",
  3623. },
  3624. },
  3625. },
  3626. gridIndex: 0,
  3627. },
  3628. {
  3629. name: "黄色",
  3630. type: "line",
  3631. data: maData.yellowData,
  3632. smooth: true,
  3633. symbol: "none",
  3634. xAxisIndex: 0,
  3635. yAxisIndex: 0,
  3636. itemStyle: {
  3637. normal: {
  3638. color: "yellow",
  3639. lineStyle: {
  3640. width: 2,
  3641. type: "solid",
  3642. },
  3643. },
  3644. },
  3645. gridIndex: 0,
  3646. },
  3647. {
  3648. name: "背景区域",
  3649. type: "line",
  3650. data: [],
  3651. xAxisIndex: 2,
  3652. yAxisIndex: 2,
  3653. markArea: {
  3654. silent: true,
  3655. itemStyle: {
  3656. normal: {
  3657. opacity: 1,
  3658. },
  3659. },
  3660. label: {
  3661. normal: {
  3662. show: true,
  3663. position: "insideRight",
  3664. fontSize: window.innerWidth > 768 ? 16 : 12,
  3665. fontWeight: "bold",
  3666. color: "#13E113",
  3667. distance: 10,
  3668. },
  3669. },
  3670. data: [
  3671. [
  3672. {
  3673. yAxis: 0,
  3674. itemStyle: {
  3675. normal: {
  3676. color: "#CFFFCF",
  3677. },
  3678. },
  3679. label: {
  3680. normal: {
  3681. formatter: "度牛区",
  3682. },
  3683. },
  3684. },
  3685. {
  3686. yAxis: 20,
  3687. },
  3688. ],
  3689. [
  3690. {
  3691. yAxis: 20,
  3692. itemStyle: {
  3693. normal: {
  3694. color: "#A6FFFF",
  3695. },
  3696. },
  3697. },
  3698. {
  3699. yAxis: 40,
  3700. },
  3701. ],
  3702. [
  3703. {
  3704. yAxis: 40,
  3705. itemStyle: {
  3706. normal: {
  3707. color: "#FFF686",
  3708. },
  3709. },
  3710. },
  3711. {
  3712. yAxis: 60,
  3713. },
  3714. ],
  3715. [
  3716. {
  3717. yAxis: 60,
  3718. itemStyle: {
  3719. normal: { color: "#FFD2B3" },
  3720. },
  3721. },
  3722. {
  3723. yAxis: 80,
  3724. },
  3725. ],
  3726. [
  3727. {
  3728. yAxis: 80,
  3729. itemStyle: {
  3730. normal: { color: "#FFB8B8" },
  3731. },
  3732. label: {
  3733. normal: {
  3734. formatter: "度牛区",
  3735. color: "#FF0000",
  3736. position: "insideLeft",
  3737. distance: 10,
  3738. },
  3739. },
  3740. },
  3741. {
  3742. yAxis: 100,
  3743. },
  3744. ],
  3745. ],
  3746. },
  3747. },
  3748. {
  3749. name: "度牛尺",
  3750. type: "line",
  3751. data: maDuchiData.greenData,
  3752. symbol: "none",
  3753. xAxisIndex: 2,
  3754. yAxisIndex: 2,
  3755. itemStyle: {
  3756. normal: {
  3757. color: "green",
  3758. lineStyle: {
  3759. width: 2,
  3760. type: "solid",
  3761. },
  3762. },
  3763. },
  3764. gridIndex: 2,
  3765. markPoint: {
  3766. symbol: "rect",
  3767. symbolSize: (value, params) => {
  3768. const width = window.innerWidth;
  3769. const baseHeight = 22;
  3770. // if (width <= 375) {
  3771. // return [2, 16];
  3772. // } else if (width <= 768) {
  3773. // return [2, 22];
  3774. // }
  3775. return [2, baseHeight];
  3776. },
  3777. itemStyle: {
  3778. normal: {
  3779. label: {
  3780. show: false,
  3781. },
  3782. },
  3783. },
  3784. data: [
  3785. ...maDuchiData.greenData
  3786. .map((item) => {
  3787. if (item[1] === 0) {
  3788. return {
  3789. coord: [item[0], 20],
  3790. symbolOffset: [0, 10],
  3791. itemStyle: {
  3792. color: "#00ff00",
  3793. },
  3794. };
  3795. }
  3796. })
  3797. .filter(Boolean),
  3798. ],
  3799. },
  3800. },
  3801. {
  3802. type: "line",
  3803. data: maDuchiData.redData,
  3804. // smooth: true,
  3805. symbol: "none",
  3806. xAxisIndex: 2,
  3807. yAxisIndex: 2,
  3808. itemStyle: {
  3809. normal: {
  3810. color: "red",
  3811. lineStyle: {
  3812. width: 2,
  3813. type: "solid",
  3814. },
  3815. },
  3816. },
  3817. gridIndex: 2,
  3818. markPoint: {
  3819. symbol: "rect",
  3820. symbolSize: (value, params) => {
  3821. const width = window.innerWidth;
  3822. const baseHeight = 22;
  3823. // if (width <= 375) {
  3824. // return [2, 16];
  3825. // } else if (width <= 768) {
  3826. // return [2, 24];
  3827. // }
  3828. return [2, baseHeight];
  3829. },
  3830. itemStyle: {
  3831. normal: {
  3832. label: {
  3833. show: false,
  3834. },
  3835. },
  3836. },
  3837. data: [
  3838. ...maDuchiData.redData
  3839. .map((item) => {
  3840. if (item[1] === 100) {
  3841. return {
  3842. coord: [item[0], 80],
  3843. symbolOffset: [0, -10],
  3844. itemStyle: {
  3845. color: "#ff0000",
  3846. },
  3847. };
  3848. }
  3849. })
  3850. .filter(Boolean),
  3851. ],
  3852. },
  3853. },
  3854. {
  3855. name: "辅助线",
  3856. type: "line",
  3857. data: [],
  3858. xAxisIndex: 2,
  3859. yAxisIndex: 2,
  3860. markLine: {
  3861. silent: true,
  3862. symbol: "none",
  3863. lineStyle: {
  3864. color: "#000000",
  3865. width: 3,
  3866. type: "solid",
  3867. },
  3868. data: [{ yAxis: 20 }],
  3869. label: {
  3870. normal: {
  3871. fontSize: window.innerWidth > 768 ? 12 : 9,
  3872. },
  3873. },
  3874. },
  3875. },
  3876. {
  3877. name: "辅助线",
  3878. type: "line",
  3879. data: [],
  3880. xAxisIndex: 2,
  3881. yAxisIndex: 2,
  3882. markLine: {
  3883. silent: true,
  3884. symbol: "none",
  3885. lineStyle: {
  3886. color: "#000000",
  3887. width: 3,
  3888. type: "solid",
  3889. },
  3890. data: [{ yAxis: 50 }],
  3891. label: {
  3892. normal: {
  3893. fontSize: window.innerWidth > 768 ? 12 : 9,
  3894. },
  3895. },
  3896. },
  3897. },
  3898. {
  3899. name: "辅助线",
  3900. type: "line",
  3901. data: [],
  3902. xAxisIndex: 2,
  3903. yAxisIndex: 2,
  3904. markLine: {
  3905. silent: true,
  3906. symbol: "none",
  3907. lineStyle: {
  3908. color: "#000000",
  3909. width: 3,
  3910. type: "solid",
  3911. },
  3912. data: [{ yAxis: 80 }],
  3913. label: {
  3914. normal: {
  3915. fontSize: window.innerWidth > 768 ? 12 : 9,
  3916. },
  3917. },
  3918. },
  3919. },
  3920. {
  3921. name: "辅助线",
  3922. type: "line",
  3923. data: [],
  3924. xAxisIndex: 2,
  3925. yAxisIndex: 2,
  3926. markLine: {
  3927. silent: true,
  3928. symbol: "none",
  3929. lineStyle: {
  3930. color: "#000000",
  3931. width: 3,
  3932. type: "solid",
  3933. },
  3934. data: [{ yAxis: 100 }],
  3935. label: {
  3936. normal: {
  3937. fontSize: window.innerWidth > 768 ? 12 : 9,
  3938. },
  3939. },
  3940. },
  3941. },
  3942. ],
  3943. };
  3944. }
  3945. // console.log("KLine渲染: 图表配置完成");
  3946. try {
  3947. // 应用配置
  3948. // console.log("KLine渲染: 开始设置图表选项");
  3949. chartInstancesMap[containerId].setOption(KlineOption);
  3950. // console.log("KLine渲染: 图表选项设置成功");
  3951. // 窗口大小变化时重新渲染图表
  3952. const resizeFunc = _.throttle(
  3953. function () {
  3954. console.log("窗口大小改变,调整图表大小");
  3955. if (
  3956. chartInstancesMap[containerId] &&
  3957. !chartInstancesMap[containerId].isDisposed()
  3958. ) {
  3959. // 如果设备类型发生变化,重新渲染
  3960. const newIsMobile = window.innerWidth < 768;
  3961. const newIsTablet =
  3962. window.innerWidth >= 768 && window.innerWidth < 1024;
  3963. if (newIsMobile !== isMobile || newIsTablet !== isTablet) {
  3964. console.log("设备类型变化,重新渲染图表");
  3965. KlineCanvsEcharts(containerId);
  3966. return;
  3967. }
  3968. chartInstancesMap[containerId].resize();
  3969. }
  3970. },
  3971. 1000,
  3972. { trailing: false }
  3973. );
  3974. // 给resize事件绑定一个特定的函数名,便于后续移除
  3975. window[`resize_${containerId}`] = resizeFunc;
  3976. // 绑定resize事件
  3977. window.removeEventListener("resize", window[`resize_${containerId}`]);
  3978. window.addEventListener("resize", window[`resize_${containerId}`]);
  3979. // console.log("KLine渲染: 图表渲染完成");
  3980. } catch (error) {
  3981. // console.error("KLine渲染: 图表渲染出错", error);
  3982. }
  3983. }
  3984. watch(
  3985. () => audioStore.isVoiceEnabled,
  3986. (newVal) => {
  3987. // 添加状态锁定逻辑
  3988. if (newVal === audioStore.lastVoiceState) return;
  3989. audioStore.lastVoiceState = newVal;
  3990. if (newVal) {
  3991. console.log("开启语音播放");
  3992. // 添加重试机制
  3993. const tryPlay = () => {
  3994. if (!audioStore.ttsUrl) return; // 新增空值判断
  3995. if (audioStore.soundInstance?.playing()) return;
  3996. playAudio(audioStore.ttsUrl);
  3997. setTimeout(() => {
  3998. if (!audioStore.soundInstance?.playing()) {
  3999. Howler.unload();
  4000. }
  4001. }, 1000);
  4002. };
  4003. tryPlay();
  4004. } else {
  4005. console.log("关闭语音播放");
  4006. pauseAudio();
  4007. }
  4008. },
  4009. { immediate: true }
  4010. );
  4011. watch(
  4012. () => dataStore.activeTabIndex,
  4013. (newVal) => {
  4014. setTimeout(() => {
  4015. console.log("activeTabIndex变化:", newVal);
  4016. // 当标签页切换回来时,重新渲染所有图表
  4017. if (newVal === 0) {
  4018. console.log("切换到AI聊天页,重新渲染图表");
  4019. // 延迟执行以确保DOM已渲染
  4020. renderAllKlineCharts();
  4021. }
  4022. }, 1000);
  4023. },
  4024. { immediate: true } // 添加immediate属性,确保初始化时执行一次
  4025. );
  4026. // 添加渲染所有K线图的方法
  4027. function renderAllKlineCharts() {
  4028. console.log("重新渲染所有K线图");
  4029. // 查找所有K线消息
  4030. const messages = chatStore.messages;
  4031. for (let i = 0; i < messages.length; i++) {
  4032. if (messages[i].kline && messages[i].chartData) {
  4033. const containerId = `kline-container-${i}`;
  4034. console.log(`尝试渲染K线图: ${containerId}`);
  4035. // 确保DOM已经渲染
  4036. const container = document.getElementById(containerId);
  4037. if (container) {
  4038. // 渲染图表
  4039. KlineCanvsEcharts(containerId);
  4040. } else {
  4041. console.warn(`找不到容器: ${containerId}`);
  4042. }
  4043. }
  4044. }
  4045. }
  4046. // 初始化随机GIF
  4047. onMounted(() => {
  4048. // 初始化marked组件
  4049. marked.setOptions({
  4050. breaks: true, // 支持换行符转换为 <br>
  4051. gfm: true, // 启用 GitHub Flavored Markdown
  4052. sanitize: false, // 不清理 HTML(谨慎使用)
  4053. smartLists: true, // 智能列表
  4054. smartypants: true, // 智能标点符号
  4055. xhtml: false, // 不使用 XHTML 输出
  4056. renderer: renderer,
  4057. });
  4058. renderAllKlineCharts();
  4059. console.log("组件挂载完成");
  4060. // 重置音频下标
  4061. chatStore.currentUserIndex = null;
  4062. chatStore.messages.forEach((item) => {
  4063. if (item.sender == "user") {
  4064. item.audioStatus = false;
  4065. }
  4066. });
  4067. // 添加页面可见性变化监听器
  4068. document.addEventListener("visibilitychange", handleVisibilityChange);
  4069. // 添加DOM变化监听器
  4070. const observer = new MutationObserver((mutations) => {
  4071. mutations.forEach((mutation) => {
  4072. if (mutation.type === "childList" && mutation.addedNodes.length) {
  4073. // 检查是否添加了图表容器
  4074. const containers = document.querySelectorAll(
  4075. '[id^="kline-container-"]'
  4076. );
  4077. if (containers.length) {
  4078. // console.log("DOM变化监听到K线容器:", Array.from(containers).map(el => el.id));
  4079. }
  4080. }
  4081. });
  4082. });
  4083. // 开始监听DOM变化
  4084. observer.observe(document.body, { childList: true, subtree: true });
  4085. });
  4086. // 页面可见性变化处理
  4087. let wasPlayingBeforeHidden = false;
  4088. const handleVisibilityChange = () => {
  4089. if (document.hidden) {
  4090. // 页面被隐藏时,如果音频正在播放,则暂停并记录状态
  4091. if (audioStore.isPlaying) {
  4092. wasPlayingBeforeHidden = true;
  4093. audioStore.pause();
  4094. console.log("页面切换离开,音频已暂停");
  4095. } else {
  4096. wasPlayingBeforeHidden = false;
  4097. }
  4098. } else {
  4099. // 页面重新可见时,如果之前在播放,则恢复播放
  4100. if (wasPlayingBeforeHidden && !audioStore.isPlaying) {
  4101. audioStore.play();
  4102. console.log("页面切换回来,音频已恢复播放");
  4103. wasPlayingBeforeHidden = false;
  4104. }
  4105. }
  4106. };
  4107. // 组件卸载时清理所有图表实例和事件监听器
  4108. onUnmounted(() => {
  4109. // 移除页面可见性变化监听器
  4110. document.removeEventListener("visibilitychange", handleVisibilityChange);
  4111. // 停止音频播放
  4112. if (audioStore.isPlaying) {
  4113. audioStore.stop();
  4114. console.log("组件卸载,音频已停止");
  4115. }
  4116. // 清理所有图表实例
  4117. Object.keys(chartInstancesMap).forEach((key) => {
  4118. if (chartInstancesMap[key]) {
  4119. // 移除resize事件监听
  4120. if (window[`resize_${key}`]) {
  4121. window.removeEventListener("resize", window[`resize_${key}`]);
  4122. delete window[`resize_${key}`];
  4123. }
  4124. // 销毁图表实例
  4125. chartInstancesMap[key].dispose();
  4126. delete chartInstancesMap[key];
  4127. }
  4128. });
  4129. });
  4130. </script>
  4131. <template>
  4132. <div class="chat-container">
  4133. <!-- GIF区域 -->
  4134. <div class="gif-area">
  4135. <img
  4136. src="https://d31zlh4on95l9h.cloudfront.net/images/03ddbbbee489f29dc6a1427f9ed4f389.png"
  4137. alt="夺宝奇兵大模型logo"
  4138. class="bgc"
  4139. />
  4140. <img :src="logo1" alt="夺宝奇兵大模型logo" class="logo1" />
  4141. <img :src="logo2" alt="夺宝奇兵大模型logo" class="logo2" />
  4142. </div>
  4143. <div v-for="(msg, index) in chatMsg" :key="index">
  4144. <!-- 用户消息容器包含喇叭按钮 -->
  4145. <div v-if="msg.sender === 'user'" class="user-message-container">
  4146. <div class="user-msg">
  4147. <div class="user-content">
  4148. <img
  4149. :src="msg.audioStatus ? voice : voiceNoActive"
  4150. class="user-message-speaker"
  4151. :class="{
  4152. 'speaker-active': msg.audioStatus,
  4153. }"
  4154. @click="toggleVoiceForUser(index)"
  4155. alt="喇叭"
  4156. />
  4157. <div
  4158. :class="{
  4159. 'message-bubble': true,
  4160. [msg.sender]: msg.sender,
  4161. [msg.class]: msg.class,
  4162. }"
  4163. >
  4164. <div v-html="msg.content"></div>
  4165. </div>
  4166. </div>
  4167. <div class="user-sendTime">
  4168. {{ moment(msg.timestamp).format("YYYY-MM-DD HH:mm:ss") }}
  4169. </div>
  4170. </div>
  4171. </div>
  4172. <!-- AI消息和其他类型消息 -->
  4173. <div
  4174. v-else
  4175. :class="{
  4176. 'message-bubble': true,
  4177. [msg.sender]: msg.sender,
  4178. [msg.class]: msg.class,
  4179. }"
  4180. >
  4181. <div v-if="msg.type === 'kline'" class="kline-container">
  4182. <div :id="'kline-container-' + index" class="chart-mount-point">
  4183. <div v-if="!msg.hasValidData" class="no-data-message">
  4184. <p>暂无K线数据</p>
  4185. </div>
  4186. </div>
  4187. </div>
  4188. <div v-else-if="msg.type == 'ing'" class="ai-message-container">
  4189. <img
  4190. v-if="msg.gif"
  4191. :src="msg.gif"
  4192. alt="思考过程"
  4193. class="thinking-gif"
  4194. />
  4195. <div class="ai-message-content">
  4196. <div v-if="msg.flag">
  4197. <span>{{ msg.content }}</span>
  4198. <span class="loading-dots">
  4199. <span class="dot">.</span>
  4200. <span class="dot">.</span>
  4201. <span class="dot">.</span>
  4202. <span class="dot">.</span>
  4203. <span class="dot">.</span>
  4204. <span class="dot">.</span>
  4205. </span>
  4206. </div>
  4207. <div v-else v-html="msg.content"></div>
  4208. </div>
  4209. </div>
  4210. <div
  4211. v-else-if="msg.type == 'title1'"
  4212. style="display: flex; width: 100%"
  4213. >
  4214. <div class="mainTitle">
  4215. {{ msg.content }}
  4216. </div>
  4217. <div class="date">
  4218. {{ msg.date }}
  4219. </div>
  4220. </div>
  4221. <div v-else-if="msg.type == 'title2'" class="title2">
  4222. <img class="title1Img" :src="title1" alt="出错了" />
  4223. </div>
  4224. <div v-else-if="msg.type == 'title3'" class="title3">
  4225. <img class="title2Img" :src="msg.content" alt="出错了" />
  4226. </div>
  4227. <div v-else-if="msg.type == 'content1'" class="content1">
  4228. <div v-if="msg.kline" class="kline-container content1chart">
  4229. <div :id="'kline-container-' + index" class="chart-mount-point">
  4230. <div v-if="!msg.hasValidData" class="no-data-message">
  4231. <p>暂无数据</p>
  4232. </div>
  4233. </div>
  4234. </div>
  4235. <div v-else class="content1Text">
  4236. <div v-html="msg.content" class="text1"></div>
  4237. </div>
  4238. </div>
  4239. <div v-else-if="msg.type == 'content2'" class="content2">
  4240. <div class="kline-container content2chart">
  4241. <div :id="'kline-container-' + index" class="chart-mount-pointJN">
  4242. <div v-if="!msg.hasValidData" class="no-data-message">
  4243. <p>暂无数据</p>
  4244. </div>
  4245. </div>
  4246. </div>
  4247. </div>
  4248. <div v-else-if="msg.type == 'content3'" class="content3">
  4249. <div class="content3Text">
  4250. <div v-html="msg.content" class="text3"></div>
  4251. </div>
  4252. </div>
  4253. <div v-else-if="msg.type == 'mianze'" class="mianze">
  4254. <div v-html="msg.content"></div>
  4255. </div>
  4256. <div v-else v-html="msg.content"></div>
  4257. </div>
  4258. </div>
  4259. </div>
  4260. </template>
  4261. <style scoped>
  4262. p {
  4263. font-size: 20px;
  4264. }
  4265. .bgc {
  4266. position: absolute;
  4267. z-index: -1;
  4268. max-width: 440px;
  4269. min-width: 300px;
  4270. top: -15px;
  4271. width: 40%;
  4272. height: auto;
  4273. /* 添加旋转动画 */
  4274. animation: rotate 10s linear infinite reverse;
  4275. }
  4276. /* 定义旋转动画 */
  4277. @keyframes rotate {
  4278. from {
  4279. transform: rotate(0deg);
  4280. }
  4281. to {
  4282. transform: rotate(360deg);
  4283. }
  4284. }
  4285. .logo1 {
  4286. max-width: 350px;
  4287. min-width: 200px;
  4288. width: 25%;
  4289. }
  4290. .logo2 {
  4291. margin-top: 20px;
  4292. max-width: 350px;
  4293. min-width: 200px;
  4294. width: 30%;
  4295. /* position: relative; */
  4296. }
  4297. .chat-container {
  4298. display: flex;
  4299. flex-direction: column;
  4300. overflow: hidden;
  4301. }
  4302. .gif-area {
  4303. padding: 70px 0px;
  4304. position: relative;
  4305. /* height: 30vh; */
  4306. display: flex;
  4307. flex-direction: column;
  4308. justify-content: center;
  4309. align-items: center;
  4310. flex-shrink: 0;
  4311. /* 防止GIF区域被压缩 */
  4312. }
  4313. .message-area {
  4314. margin-top: 2%;
  4315. flex: 1;
  4316. /* 消息区域占据剩余空间 */
  4317. overflow-y: auto;
  4318. padding: 20px;
  4319. display: flex;
  4320. flex-direction: column;
  4321. gap: 15px;
  4322. }
  4323. .marquee-container {
  4324. /* position: absolute; */
  4325. bottom: 0;
  4326. width: 100%;
  4327. /* ga */
  4328. }
  4329. .marquee-row {
  4330. white-space: nowrap;
  4331. overflow: visible;
  4332. padding: 8px 0;
  4333. width: 100%;
  4334. }
  4335. .marquee-item {
  4336. display: inline-block;
  4337. margin: 0 15px;
  4338. padding: 8px 20px;
  4339. background: rgba(255, 255, 255, 0.9);
  4340. /* 白色背景 */
  4341. border-radius: 10px;
  4342. /* 圆角矩形 */
  4343. color: #333;
  4344. /* 文字颜色改为深色 */
  4345. box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  4346. /* 添加阴影 */
  4347. transition: all 0.3s;
  4348. transition: color 0.3s;
  4349. }
  4350. .top {
  4351. animation: marquee 25s linear infinite;
  4352. /* 默认动画是运行状态 */
  4353. animation-play-state: running;
  4354. }
  4355. .bottom {
  4356. animation: marquee 15s linear infinite reverse;
  4357. /* 默认动画是运行状态 */
  4358. animation-play-state: running;
  4359. }
  4360. /* 添加PC端专用速度 */
  4361. @media (min-width: 768px) {
  4362. .top {
  4363. animation-duration: 35s;
  4364. /* PC端改为35秒 */
  4365. }
  4366. .bottom {
  4367. animation-duration: 35s;
  4368. /* PC端改为35秒 */
  4369. }
  4370. }
  4371. @keyframes marquee {
  4372. 0% {
  4373. transform: translateX(100%);
  4374. }
  4375. 100% {
  4376. transform: translateX(-250%);
  4377. }
  4378. }
  4379. .loading-dots {
  4380. display: inline-block;
  4381. }
  4382. .dot {
  4383. opacity: 0.4;
  4384. animation: loading 1.4s infinite;
  4385. }
  4386. .dot:nth-child(1) {
  4387. animation-delay: 0s;
  4388. }
  4389. .dot:nth-child(2) {
  4390. animation-delay: 0.2s;
  4391. }
  4392. .dot:nth-child(3) {
  4393. animation-delay: 0.4s;
  4394. }
  4395. .dot:nth-child(4) {
  4396. animation-delay: 0.6s;
  4397. }
  4398. .dot:nth-child(5) {
  4399. animation-delay: 0.8s;
  4400. }
  4401. .dot:nth-child(6) {
  4402. animation-delay: 1s;
  4403. }
  4404. @keyframes loading {
  4405. 0%,
  4406. 60%,
  4407. 100% {
  4408. opacity: 0.4;
  4409. }
  4410. 30% {
  4411. opacity: 1;
  4412. }
  4413. }
  4414. .message-bubble {
  4415. max-width: 80%;
  4416. margin: 10px 0px;
  4417. padding: 15px 20px;
  4418. position: relative;
  4419. }
  4420. /* 用户消息容器样式 */
  4421. .user-message-container {
  4422. display: flex;
  4423. /* align-items: flex-start; */
  4424. margin: 10px 0px;
  4425. justify-content: flex-end;
  4426. gap: 10px;
  4427. /* align-items: center; */
  4428. flex-direction: column;
  4429. }
  4430. .user-msg {
  4431. margin-left: auto;
  4432. }
  4433. .user-content {
  4434. display: flex;
  4435. height: 100%;
  4436. align-items: center;
  4437. margin-right: 5px;
  4438. }
  4439. .user-sendTime {
  4440. width: 100%;
  4441. text-align: center;
  4442. color: rgba(255, 255, 255, 0.6);
  4443. font-size: 0.8rem;
  4444. }
  4445. .user-message-speaker {
  4446. width: 32px;
  4447. height: 32px;
  4448. object-fit: contain;
  4449. margin-right: 5px;
  4450. cursor: pointer;
  4451. transition: all 0.3s ease;
  4452. }
  4453. .user-message-speaker:hover {
  4454. transform: scale(1.1);
  4455. }
  4456. .user-message-speaker.speaker-active {
  4457. animation: pulse 1.5s infinite;
  4458. }
  4459. @keyframes pulse {
  4460. 0% {
  4461. transform: scale(1);
  4462. }
  4463. 50% {
  4464. transform: scale(1.1);
  4465. }
  4466. 100% {
  4467. transform: scale(1);
  4468. }
  4469. }
  4470. .message-bubble.user {
  4471. color: #6d22f8;
  4472. background: white;
  4473. font-weight: bold;
  4474. border-radius: 10px;
  4475. margin: 0;
  4476. width: fit-content;
  4477. display: flex;
  4478. align-items: center;
  4479. }
  4480. .message-bubble.ai {
  4481. background: #2b378d;
  4482. color: #ffffff;
  4483. margin: 0 auto;
  4484. /* border-bottom-left-radius: 5px; */
  4485. }
  4486. .message-bubble.ing {
  4487. background: #ffffff;
  4488. color: #000000;
  4489. font-weight: bold;
  4490. border-radius: 10px;
  4491. margin-left: 20px;
  4492. margin-right: auto;
  4493. display: flex;
  4494. align-items: center;
  4495. width: fit-content;
  4496. }
  4497. .message-bubble.ai.title1 {
  4498. width: 100%;
  4499. display: flex;
  4500. border-radius: 10px 10px 0px 0px;
  4501. /* border-bottom-left-radius: 5px; */
  4502. }
  4503. .mainTitle {
  4504. font-size: 16px;
  4505. font-weight: bold;
  4506. background-image: url("@/assets/img/AiEmotion/bk01.png");
  4507. background-repeat: no-repeat;
  4508. background-size: 100% 100%;
  4509. min-width: 200px;
  4510. width: 20vw;
  4511. max-width: 50%;
  4512. height: 50px;
  4513. padding: 15px 10px;
  4514. text-align: center;
  4515. line-height: 20px;
  4516. overflow: hidden;
  4517. text-overflow: ellipsis;
  4518. white-space: nowrap;
  4519. box-sizing: border-box;
  4520. }
  4521. .date {
  4522. font-size: 1.5rem;
  4523. font-weight: bold;
  4524. margin-left: auto;
  4525. /* width: 100px; */
  4526. display: flex;
  4527. justify-content: center;
  4528. align-items: center;
  4529. }
  4530. .message-bubble.ai.title2 {
  4531. width: 100%;
  4532. display: flex;
  4533. justify-content: center;
  4534. align-items: center;
  4535. }
  4536. .title1Img {
  4537. max-width: 500px;
  4538. width: 90vw;
  4539. }
  4540. .message-bubble.ai.title3 {
  4541. width: 100%;
  4542. display: flex;
  4543. justify-content: center;
  4544. align-items: center;
  4545. }
  4546. .title2Img {
  4547. max-width: 500px;
  4548. width: 90vw;
  4549. }
  4550. .message-bubble.ai.content1 {
  4551. width: 100%;
  4552. display: flex;
  4553. justify-content: center;
  4554. align-items: center;
  4555. }
  4556. .content1chart {
  4557. background-image: url("@/assets/img/AIchat/罗盘边框.png");
  4558. background-repeat: no-repeat;
  4559. background-size: 100% 100%;
  4560. width: 50vw;
  4561. min-width: 350px;
  4562. display: flex;
  4563. justify-content: center;
  4564. align-items: center;
  4565. }
  4566. .content1Text {
  4567. background-image: url("@/assets/img/AIchat/框.png");
  4568. background-repeat: no-repeat;
  4569. background-size: 100% 100%;
  4570. width: 50vw;
  4571. min-width: 350px;
  4572. /* height: 20vw; */
  4573. /* max-height: 400px; */
  4574. padding: 5% 0;
  4575. }
  4576. .text1 {
  4577. font-weight: bold;
  4578. /* margin-left: 6%; */
  4579. /* margin-bottom: 10px; */
  4580. margin: 0px 6% 10px 6%;
  4581. font-size: 20px;
  4582. }
  4583. .message-bubble.ai.content2 {
  4584. width: 100%;
  4585. display: flex;
  4586. justify-content: center;
  4587. align-items: center;
  4588. }
  4589. .content2chart {
  4590. background-image: url("@/assets/img/AIchat/PCbackPic.png");
  4591. background-repeat: no-repeat;
  4592. background-size: 100% 100%;
  4593. width: 50vw;
  4594. min-width: 350px;
  4595. display: flex;
  4596. justify-content: center;
  4597. align-items: center;
  4598. height: calc(500px + 10vw) !important;
  4599. }
  4600. .message-bubble.ai.content3 {
  4601. width: 100%;
  4602. display: flex;
  4603. justify-content: center;
  4604. align-items: center;
  4605. }
  4606. .content3Text {
  4607. background-image: url("@/assets/img/AIchat/边框.png");
  4608. background-repeat: no-repeat;
  4609. background-size: 100% 100%;
  4610. width: 50vw;
  4611. min-width: 350px;
  4612. /* height: 20vw; */
  4613. /* max-height: 400px; */
  4614. padding: 5% 0px;
  4615. }
  4616. .text3 {
  4617. /* font-weight: bold; */
  4618. /* margin-left: 6%; */
  4619. /* margin-bottom: 10px; */
  4620. margin: 0px 6% 10px 6%;
  4621. font-size: 20px;
  4622. }
  4623. .message-bubble.ai.mianze {
  4624. width: 100%;
  4625. text-align: center;
  4626. font-weight: bold;
  4627. font-size: 24px;
  4628. border-radius: 0px 0px 10px 10px;
  4629. }
  4630. .kline-container {
  4631. margin-top: 10px;
  4632. /* 最小高度 */
  4633. min-height: 320px;
  4634. /* 视口高度单位 */
  4635. height: 40vh;
  4636. width: 50vw;
  4637. }
  4638. @media (max-width: 768px) {
  4639. .kline-container {
  4640. min-width: 75vw;
  4641. }
  4642. .content1Text {
  4643. width: 77vw;
  4644. min-width: 0px;
  4645. /* height: 20vw; */
  4646. /* min-height: 150px; */
  4647. }
  4648. .date {
  4649. font-size: 14px;
  4650. }
  4651. .text1 {
  4652. font-size: 20px;
  4653. }
  4654. .content2chart {
  4655. background-image: url("@/assets/img/AIchat/new-app-bgc.png") !important;
  4656. height: 100vw;
  4657. }
  4658. .content3Text {
  4659. width: 77vw;
  4660. min-width: 0px;
  4661. /* height: 20vw; */
  4662. /* min-height: 150px; */
  4663. }
  4664. .text3 {
  4665. font-size: 20px;
  4666. }
  4667. .message-bubble.ai.mianze {
  4668. font-size: 18px;
  4669. }
  4670. }
  4671. .kline-container .chart-mount-point {
  4672. display: flex;
  4673. justify-content: center;
  4674. align-items: center;
  4675. height: 80%;
  4676. width: 90%;
  4677. }
  4678. .kline-container .chart-mount-pointJN {
  4679. display: flex;
  4680. justify-content: center;
  4681. align-items: center;
  4682. height: 100%;
  4683. width: 100%;
  4684. }
  4685. /* AI消息容器样式 */
  4686. .ai-message-container {
  4687. display: flex;
  4688. align-items: center;
  4689. gap: 10px;
  4690. margin-right: auto;
  4691. max-width: 80%;
  4692. }
  4693. /* 思考过程动图样式 */
  4694. .thinking-gif {
  4695. width: 40px;
  4696. height: 40px;
  4697. object-fit: contain;
  4698. margin-top: 5px;
  4699. border-radius: 8px;
  4700. animation: float 2s ease-in-out infinite;
  4701. }
  4702. @keyframes float {
  4703. 0%,
  4704. 100% {
  4705. transform: translateY(0px);
  4706. }
  4707. 50% {
  4708. transform: translateY(-5px);
  4709. }
  4710. }
  4711. /* AI消息内容样式 */
  4712. .ai-message-content {
  4713. display: flex;
  4714. align-items: center;
  4715. /* white-space: nowrap; */
  4716. width: fit-content;
  4717. overflow: visible;
  4718. }
  4719. </style>