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.

5296 lines
160 KiB

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