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.

3624 lines
107 KiB

4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
3 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
  1. <script setup>
  2. import { ref, onMounted, watch, nextTick, reactive, onUnmounted } from "vue";
  3. import { ElDialog } 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. import katex from "katex"; // 引入 KaTeX 库
  22. import { htmlToText } from "html-to-text";
  23. import { Howl, Howler } from "howler";
  24. import * as echarts from "echarts";
  25. import _, { add } from "lodash";
  26. import moment from "moment";
  27. import title1 from "@/assets/img/AIchat/核心价值评估标题.png";
  28. import title2 from "@/assets/img/AIchat/主力作战.png";
  29. import title3 from "@/assets/img/AIchat/攻防三维.png";
  30. import title4 from "@/assets/img/AIchat/综合作战.png";
  31. import logo1 from "@/assets/img/AIchat/夺宝奇兵logo.png";
  32. import logo2 from "@/assets/img/AIchat/开启无限财富.png";
  33. import bgc from "@/assets/img/AIchat/圈.png";
  34. const chatStore = useChatStore();
  35. const audioStore = useAudioStore();
  36. const dataStore = useDataStore();
  37. // 随机GIF
  38. const currentGif = ref("");
  39. const renderer = new marked.Renderer();
  40. // 重写 del 方法,让删除线不生效
  41. renderer.del = function (text) {
  42. // 处理各种数据类型
  43. console.log("text", text);
  44. return "~" + text.tokens[0].raw + "<br>" + text.tokens[2].raw + "~";
  45. };
  46. // 定义自定义事件
  47. const emit = defineEmits(["updateMessage", "sendMessage"]);
  48. // 音频播放方法
  49. const playAudio = (url) => {
  50. // 添加空值校验
  51. if (!url) {
  52. console.warn("音频URL为空,跳过播放");
  53. audioStore.isPlaying = false;
  54. return;
  55. }
  56. const handlePlay = () => {
  57. // if (audioStore.soundInstance) {
  58. // Howler.unload(); // 添加清理旧实例
  59. // // audioStore.soundInstance.stop()
  60. // }
  61. if (audioStore.isNewInstance) {
  62. const newSound = new Howl({
  63. src: [url],
  64. html5: true, // 强制HTML5 Audio解决iOS兼容问题
  65. format: ["mp3", "acc"],
  66. rate: 1.2, // 调整播放速度
  67. onplay: () => {
  68. audioStore.isPlaying = true; // 改为更新store状态
  69. newSound.volume(1); // 添加音量设置
  70. },
  71. onend: () => (audioStore.isPlaying = false),
  72. onstop: () => (audioStore.isPlaying = false),
  73. onloaderror: (id, err) => {
  74. console.error("音频加载失败:", err);
  75. ElMessage.error("音频播放失败,请检查网络连接");
  76. },
  77. });
  78. if (audioStore.nowSound) {
  79. audioStore.nowSound.stop();
  80. }
  81. audioStore.nowSound = newSound;
  82. audioStore.isNewInstance = false;
  83. console.log("新音频");
  84. } else {
  85. console.log("已经有音频");
  86. }
  87. const newSound = audioStore.nowSound;
  88. // 添加立即播放逻辑
  89. newSound.play();
  90. audioStore.setAudioInstance(newSound);
  91. Howler._howls.push(newSound); // 强制注册到全局管理
  92. // // 处理浏览器自动播放策略
  93. // if (Howler.autoUnlock) {
  94. // Howler.autoUnlock();
  95. // }
  96. };
  97. // if (/iPhone|iPad|iPod/.test(navigator.userAgent)) {
  98. // document.addEventListener('touchstart', handlePlay, { once: true });
  99. // ElMessage.info('请轻触屏幕以启用音频播放');
  100. // } else {
  101. // handlePlay();
  102. // }
  103. handlePlay();
  104. // Howler.volume(1.0) // 添加全局音量设置
  105. };
  106. // 新增暂停方法
  107. const pauseAudio = () => {
  108. if (audioStore.soundInstance) {
  109. // 添加移动端特殊处理
  110. // if (/iPhone|iPad|iPod/.test(navigator.userAgent)) {
  111. // Howler.pause(); // iOS需要强制停止音频上下文
  112. // } else {
  113. // audioStore.soundInstance.pause();
  114. // }
  115. audioStore.soundInstance.pause();
  116. audioStore.isPlaying = false;
  117. // // 添加状态同步
  118. // nextTick(() => {
  119. // Howler.unload();
  120. // audioStore.soundInstance = null;
  121. // });
  122. }
  123. };
  124. // 音频轮流播放方法
  125. const playAudioSequence = (audioUrls) => {
  126. console.log("playAudioSequence被调用,参数:", audioUrls);
  127. if (!audioUrls || audioUrls.length === 0) {
  128. console.warn("音频URL列表为空,跳过播放");
  129. return;
  130. }
  131. let currentIndex = 0;
  132. let audioSequence = [...audioUrls]; // 保存音频序列
  133. const playNext = () => {
  134. if (currentIndex >= audioSequence.length) {
  135. console.log("所有音频播放完成,重置到第一个音频");
  136. // 播放完成后重置到第一个音频,但不自动播放
  137. currentIndex = 0;
  138. audioStore.isPlaying = false;
  139. audioStore.isPaused = false;
  140. audioStore.playbackPosition = 0;
  141. if (audioSequence.length > 0) {
  142. audioStore.setCurrentAudioUrl(audioSequence[0]);
  143. }
  144. return;
  145. }
  146. const currentUrl = audioSequence[currentIndex];
  147. console.log(`正在播放第${currentIndex + 1}个音频:`, currentUrl);
  148. console.log(
  149. "音频URL有效性检查:",
  150. !!currentUrl,
  151. "长度:",
  152. currentUrl?.length
  153. );
  154. // 设置当前音频URL
  155. audioStore.setCurrentAudioUrl(currentUrl);
  156. // 停止当前播放的音频
  157. if (audioStore.nowSound) {
  158. audioStore.nowSound.stop();
  159. }
  160. const sound = new Howl({
  161. src: [currentUrl],
  162. html5: true,
  163. format: ["mp3", "acc"],
  164. rate: 1.2,
  165. onplay: () => {
  166. audioStore.isPlaying = true;
  167. audioStore.isPaused = false;
  168. console.log(`开始播放音频 ${currentIndex + 1}`);
  169. },
  170. onpause: () => {
  171. audioStore.isPlaying = false;
  172. audioStore.isPaused = true;
  173. audioStore.playbackPosition = sound.seek() || 0;
  174. console.log(`音频 ${currentIndex + 1} 已暂停`);
  175. },
  176. onend: () => {
  177. audioStore.isPlaying = false;
  178. audioStore.isPaused = false;
  179. audioStore.playbackPosition = 0;
  180. console.log(`音频 ${currentIndex + 1} 播放完成`);
  181. currentIndex++;
  182. // 播放下一个音频
  183. setTimeout(() => {
  184. playNext();
  185. }, 500); // 间隔500ms播放下一个
  186. },
  187. onstop: () => {
  188. audioStore.isPlaying = false;
  189. audioStore.isPaused = false;
  190. audioStore.playbackPosition = 0;
  191. console.log(`音频 ${currentIndex + 1} 已停止`);
  192. },
  193. onloaderror: (id, err) => {
  194. console.error(`音频 ${currentIndex + 1} 加载失败:`, err);
  195. currentIndex++;
  196. // 跳过失败的音频,播放下一个
  197. setTimeout(() => {
  198. playNext();
  199. }, 100);
  200. },
  201. });
  202. audioStore.nowSound = sound;
  203. audioStore.setAudioInstance(sound);
  204. sound.play();
  205. };
  206. // 重写togglePlayPause方法以支持音频序列控制
  207. const originalTogglePlayPause = audioStore.togglePlayPause;
  208. audioStore.togglePlayPause = () => {
  209. if (audioStore.soundInstance) {
  210. if (audioStore.isPlaying) {
  211. // 暂停当前音频
  212. audioStore.pause();
  213. } else if (audioStore.isPaused) {
  214. // 从暂停位置继续播放
  215. audioStore.play();
  216. } else {
  217. // 重新开始播放当前音频或从头开始播放序列
  218. if (currentIndex >= audioSequence.length) {
  219. currentIndex = 0; // 重置到第一个音频
  220. }
  221. playNext();
  222. }
  223. } else {
  224. // 没有音频实例时,从头开始播放
  225. currentIndex = 0;
  226. playNext();
  227. }
  228. };
  229. // 开始播放第一个音频
  230. playNext();
  231. };
  232. // 获取消息
  233. const chatMsg = computed(() => chatStore.messages);
  234. const props = defineProps({
  235. messages: Array,
  236. chartData: {
  237. type: Object,
  238. default: null,
  239. },
  240. index: {
  241. type: Number,
  242. required: true,
  243. },
  244. });
  245. // 打字机效果
  246. const typewriterContent = ref("");
  247. const isTyping = ref(false);
  248. const typeWriter = (text, callback) => {
  249. let index = 0;
  250. isTyping.value = true;
  251. typewriterContent.value = "";
  252. const typingInterval = setInterval(() => {
  253. if (index < text.length) {
  254. typewriterContent.value += text.charAt(index);
  255. index++;
  256. // 自动滚动到底部
  257. nextTick(() => {
  258. const container = document.querySelector(".message-area");
  259. if (container) container.scrollTop = container.scrollHeight;
  260. });
  261. } else {
  262. clearInterval(typingInterval);
  263. isTyping.value = false;
  264. if (callback) callback();
  265. }
  266. }, 50); // 调整速度(毫秒)
  267. };
  268. const fnGetData = (data) => {
  269. const YaLiZhiChengLuoPan = data.YaLiZhiChengLuoPan;
  270. let sz = ref(5.5); // 进行判断
  271. const yl = YaLiZhiChengLuoPan.Yali; // 压力位
  272. const zc = YaLiZhiChengLuoPan.ZhiCheng; // 支撑位
  273. console.log("yl", yl, "zc", zc);
  274. if (yl == "较大" && zc == "较弱") {
  275. sz.value = 0.5; // 极高风险
  276. } else if (yl == "一般" && zc == "较弱") {
  277. sz.value = 1.5; // 弱撑中压区
  278. } else if (yl == "较弱" && zc == "较弱") {
  279. sz.value = 2.5; // 弱撑弱压区
  280. } else if (yl == "较大" && zc == "较大") {
  281. sz.value = 3.5; // 强撑强压区
  282. } else if (yl == "一般" && zc == "较大") {
  283. sz.value = 4.5; // 强撑中压
  284. } else if (yl == "较弱" && zc == "较大") {
  285. sz.value = 5.5; // 强撑弱压区
  286. } else if (yl == "较大" && zc == "一般") {
  287. sz.value = 0.2;
  288. } else if (yl == "一般" && zc == "一般") {
  289. sz.value = 3;
  290. } else if (yl == "较弱" && zc == "一般") {
  291. sz.value = 5.8;
  292. }
  293. return sz.value;
  294. };
  295. const typingQueue = ref([]);
  296. const isTypingInProgress = ref(false);
  297. // 创建打字机效果的Promise函数
  298. const createTypingEffect = (message, content, speed) => {
  299. return new Promise((resolve) => {
  300. chatStore.messages.push(message);
  301. if (Array.isArray(content) && content.length > 0) {
  302. message.content = "";
  303. message.isTyping = true;
  304. let currentIndex = 0;
  305. const processNextElement = () => {
  306. if (currentIndex >= content.length) {
  307. message.isTyping = false;
  308. nextTick(() => {
  309. resolve(); // 完成后resolve
  310. });
  311. return;
  312. }
  313. if (currentIndex % 2 === 0) {
  314. // 偶数下标:直接加入
  315. message.content += content[currentIndex];
  316. currentIndex++;
  317. processNextElement(); // 立即处理下一个元素
  318. } else {
  319. // 奇数下标:打字机效果
  320. const text = content[currentIndex];
  321. let charIndex = 0;
  322. const typingInterval = setInterval(() => {
  323. if (charIndex < text.length) {
  324. message.content += text.charAt(charIndex);
  325. charIndex++;
  326. } else {
  327. clearInterval(typingInterval);
  328. currentIndex++;
  329. processNextElement(); // 处理下一个元素
  330. }
  331. }, speed);
  332. }
  333. };
  334. processNextElement(); // 开始处理
  335. } else {
  336. if (message.kline) {
  337. if (message.klineType == 1) {
  338. console.log("六色罗盘消息已添加到聊天列表");
  339. // 在渲染完成后初始化图表
  340. nextTick(() => {
  341. console.log("nextTick开始 - 准备渲染图表");
  342. console.log("消息列表:", chatStore.messages);
  343. // 寻找最新添加的K线消息索引
  344. let klineIndex = -1;
  345. for (let i = 0; i < chatStore.messages.length; i++) {
  346. if (chatStore.messages[i].messageId === message.messageId) {
  347. klineIndex = i;
  348. break;
  349. }
  350. }
  351. console.log("找到的K线消息索引:", klineIndex);
  352. if (klineIndex !== -1) {
  353. const containerId = `kline-container-${klineIndex}`;
  354. console.log("图表容器ID:", containerId);
  355. // 确保DOM已经渲染完成
  356. setTimeout(() => {
  357. console.log("延时执行,确保DOM已渲染");
  358. KlineCanvsEcharts(containerId);
  359. }, 100); // 短暂延时确保DOM已渲染
  360. } else {
  361. console.warn("未找到K线消息");
  362. }
  363. });
  364. } else {
  365. console.log("K线消息已添加到聊天列表");
  366. // 在渲染完成后初始化图表
  367. nextTick(() => {
  368. console.log("nextTick开始 - 准备渲染图表");
  369. console.log("消息列表:", chatStore.messages);
  370. // 寻找最新添加的K线消息索引
  371. let klineIndex = -1;
  372. for (let i = 0; i < chatStore.messages.length; i++) {
  373. if (chatStore.messages[i].messageId === message.messageId) {
  374. klineIndex = i;
  375. break;
  376. }
  377. }
  378. console.log("找到的K线消息索引:", klineIndex);
  379. if (klineIndex !== -1) {
  380. const containerId = `kline-container-${klineIndex}`;
  381. console.log("图表容器ID:", containerId);
  382. // 确保DOM已经渲染完成
  383. setTimeout(() => {
  384. console.log("延时执行,确保DOM已渲染");
  385. KlineCanvsEcharts(containerId);
  386. }, 100); // 短暂延时确保DOM已渲染
  387. } else {
  388. console.warn("未找到K线消息");
  389. }
  390. });
  391. }
  392. // 延时1秒后resolve
  393. setTimeout(() => {
  394. resolve();
  395. }, 1000);
  396. } else {
  397. // 延时1秒后resolve
  398. setTimeout(() => {
  399. resolve();
  400. }, 1000);
  401. }
  402. }
  403. });
  404. };
  405. // 队列处理函数
  406. const processTypingQueue = async () => {
  407. if (isTypingInProgress.value || typingQueue.value.length === 0) {
  408. return;
  409. }
  410. isTypingInProgress.value = true;
  411. while (typingQueue.value.length > 0) {
  412. const task = typingQueue.value.shift();
  413. await createTypingEffect(task.message, task.content, task.speed);
  414. }
  415. isTypingInProgress.value = false;
  416. };
  417. // 添加打字机任务到队列
  418. const addTypingTask = (message, content, speed = 50) => {
  419. typingQueue.value.push({ message, content, speed });
  420. processTypingQueue();
  421. };
  422. const hasValidData = ref(false);
  423. // 创建一个非响应式的对象来存储图表实例
  424. const chartInstancesMap = {};
  425. // 存储上一次的消息的length
  426. const previousMessagesLength = ref(0);
  427. watch(
  428. () => props.messages,
  429. async (newVal, oldVal) => {
  430. // console.log(newVal, 'newVal')
  431. // console.log(oldVal, 'oldVal')
  432. // console.log(previousMessagesLength.value, 'previousMessagesLength')
  433. // console.log(newVal.length, 'newVal.length')
  434. // // 添加空值判断
  435. if (!newVal?.length || newVal === previousMessagesLength.value) return;
  436. previousMessagesLength.value = newVal.length;
  437. if (newVal.length > 0) {
  438. console.log("消息列表已更新,最新消息:", newVal[newVal.length - 1]);
  439. chatStore.messages.push(newVal[newVal.length - 1]);
  440. console.log("消息列表已更新,最新消息:", chatMsg[chatMsg.length - 1]);
  441. console.log("token", localStorage.getItem("localToken"));
  442. // 获取权限
  443. const userStore = useUserStore();
  444. const params1 = {
  445. content: newVal[newVal.length - 1].content,
  446. language: "cn",
  447. marketList: "usa,sg,my,hk,cn,can,vi,th,in",
  448. token: localStorage.getItem("localToken"),
  449. // language: "cn",
  450. // marketList: "hk,cn,usa,my,sg,vi,in,gb"
  451. // token: "+SsksARQgUHIbIG3rRnnbZi0+fEeMx8pywnIlrmTxo5EOPR/wjWDV7w7+ZUseiBtf9kFa/atmNx6QfSpv5w",
  452. };
  453. // 标志
  454. let flag = true;
  455. const codeData = ref();
  456. // 第一阶段,意图识别
  457. try {
  458. // 调用工作流获取回复
  459. const result = await dbqbFirstAPI(params1);
  460. codeData.value = result.data;
  461. console.log(codeData.value, "codeData");
  462. // 根据意图识别结果判断
  463. if (result.code == 200) {
  464. chatStore.messages.push({
  465. class: "ing",
  466. type: "ing",
  467. flag: flag,
  468. content: result.data.kaishi,
  469. });
  470. } else {
  471. flag = false;
  472. console.log("执行回绝话术");
  473. const AIcontent = ref(result.msg);
  474. // 修改后的消息处理逻辑
  475. const processedContent = marked(AIcontent.value);
  476. const katexRegex = /\$\$(.*?)\$\$/g;
  477. const aiContent = processedContent.replace(
  478. katexRegex,
  479. (match, formula) => {
  480. try {
  481. return katex.renderToString(formula, { throwOnError: false });
  482. } catch (error) {
  483. console.error("KaTeX 渲染错误:", error);
  484. return match;
  485. }
  486. }
  487. );
  488. console.log(aiContent, "aiContent");
  489. chatStore.messages.push({
  490. class: "ing",
  491. type: "ing",
  492. flag: flag,
  493. content: aiContent,
  494. });
  495. chatStore.setLoading(false);
  496. }
  497. } catch (e) {
  498. console.log(e, "意图识别失败");
  499. }
  500. if (flag) {
  501. const params2 = {
  502. content: newVal[newVal.length - 1].content,
  503. language: "cn",
  504. marketList: "usa,sg,my,hk,cn,can,vi,th,in",
  505. token: localStorage.getItem("localToken"),
  506. // language: "cn",
  507. // marketList: "hk,cn,usa,my,sg,vi,in,gb"
  508. // token: "+SsksARQgUHIbIG3rRnnbZi0+fEeMx8pywnIlrmTxo5EOPR/wjWDV7w7+ZUseiBtf9kFa/atmNx6QfSpv5w",
  509. name: codeData.value.name,
  510. code: codeData.value.code,
  511. market: codeData.value.market,
  512. };
  513. try {
  514. const result20 = await dataListAPI({
  515. token: localStorage.getItem("localToken"),
  516. market: codeData.value.market,
  517. code: codeData.value.code,
  518. language: "cn", //t.value.suoxie,
  519. // brainPrivilegeState: 1,
  520. // swordPrivilegeState: 1,
  521. // stockForecastPrivilegeState: 1,
  522. // spaceForecastPrivilegeState: 1,
  523. // aibullPrivilegeState: 1,
  524. // aigoldBullPrivilegeState: 1,
  525. // airadarPrivilegeState: 1,
  526. // marketList: 1,
  527. brainPrivilegeState: userStore.brainPerssion,
  528. swordPrivilegeState: userStore.swordPerssion,
  529. stockForecastPrivilegeState: userStore.pricePerssion,
  530. spaceForecastPrivilegeState: userStore.timePerssion,
  531. aibullPrivilegeState: userStore.aibullPerssion,
  532. aigoldBullPrivilegeState: userStore.aiGnbullPerssion,
  533. airadarPrivilegeState: userStore.airadarPerssion,
  534. marketList: userStore.aiGoldMarketList,
  535. });
  536. const HomePage = result20.data.HomePage;
  537. const AIGoldBull = result20.data.AIGoldBull;
  538. const katexRegex = /\$\$(.*?)\$\$/g;
  539. let result21;
  540. let result22;
  541. let result23;
  542. let result24;
  543. // 用于跟踪API完成状态和结果
  544. const apiStatus = {
  545. one: { completed: false, result: null, error: null },
  546. two: { completed: false, result: null, error: null },
  547. three: { completed: false, result: null, error: null },
  548. four: { completed: false, result: null, error: null },
  549. };
  550. // 检查并按顺序执行代码的函数
  551. const checkAndExecuteInOrder = () => {
  552. // 检查OneAPI
  553. if (apiStatus.one.completed && !apiStatus.one.executed) {
  554. apiStatus.one.executed = true;
  555. if (apiStatus.one.result) {
  556. console.log("执行OneAPI代码:", apiStatus.one.result);
  557. // 在这里添加OneAPI成功后需要执行的代码
  558. // 删除正在为您生成信息
  559. chatStore.messages.pop();
  560. // 添加报告头和时间
  561. addTypingTask(
  562. {
  563. sender: "ai",
  564. class: "title1",
  565. type: "title1",
  566. content: codeData.value.name + "全景作战报告",
  567. date: moment().format("DD/MM/YYYY"),
  568. },
  569. "",
  570. 50
  571. );
  572. // chatStore.messages.push({
  573. // sender: "ai",
  574. // class: "title1",
  575. // type: "title1",
  576. // content: codeData.value.name + "全景作战报告",
  577. // date: moment().format("MM/DD/YYYY"),
  578. // });
  579. // 添加股票信息框
  580. const pc1 = marked(
  581. result21.data.name +
  582. "\n" +
  583. result21.data.price +
  584. "\n" +
  585. result21.data.date
  586. );
  587. const ac1 = pc1.replace(katexRegex, (match, formula) => {
  588. try {
  589. return katex.renderToString(formula, {
  590. throwOnError: false,
  591. });
  592. } catch (error) {
  593. console.error("KaTeX 渲染错误:", error);
  594. return match;
  595. }
  596. });
  597. // 先推送初始消息
  598. const aiMessage1 = reactive({
  599. sender: "ai",
  600. class: "content1",
  601. type: "content1",
  602. content: "",
  603. isTyping: true,
  604. });
  605. // chatStore.messages.push(aiMessage1);
  606. // let index1 = 0;
  607. // const typingInterval1 = setInterval(() => {
  608. // if (index1 < ac1.length) {
  609. // aiMessage1.content += ac1.charAt(index1);
  610. // index1++;
  611. // } else {
  612. // clearInterval(typingInterval1);
  613. // aiMessage1.isTyping = false;
  614. // }
  615. // }, 50); // 调整速度为50ms/字符
  616. addTypingTask(aiMessage1, ["", ac1], 50);
  617. // chatStore.messages.push({
  618. // sender: "ai",
  619. // class: "content1",
  620. // type: "content1",
  621. // content: ac1,
  622. // });
  623. // 添加六色罗盘
  624. const LiuSeData = JSON.parse(JSON.stringify(toRaw(HomePage)));
  625. const sz = fnGetData(LiuSeData);
  626. if (sz) {
  627. hasValidData.value = true;
  628. console.log("hasValidData设置为:", hasValidData.value);
  629. }
  630. // 先推送K线图消息
  631. const klineMessageId1 = `kline-${Date.now()}`;
  632. console.log("生成K线消息ID:", klineMessageId1);
  633. addTypingTask(
  634. {
  635. sender: "ai",
  636. class: "content1",
  637. type: "content1",
  638. kline: true,
  639. chartData: sz,
  640. messageId: klineMessageId1,
  641. hasValidData: true,
  642. klineType: 1,
  643. },
  644. "",
  645. 50
  646. );
  647. // chatStore.messages.push({
  648. // sender: "ai",
  649. // class: "content1",
  650. // type: "content1",
  651. // kline: true,
  652. // chartData: sz,
  653. // messageId: klineMessageId1,
  654. // hasValidData: true,
  655. // klineType: 1,
  656. // });
  657. // console.log("六色罗盘消息已添加到聊天列表");
  658. // // 在渲染完成后初始化图表
  659. // nextTick(() => {
  660. // console.log("nextTick开始 - 准备渲染图表");
  661. // console.log("消息列表:", chatStore.messages);
  662. // // 寻找最新添加的K线消息索引
  663. // let klineIndex = -1;
  664. // for (let i = 0; i < chatStore.messages.length; i++) {
  665. // if (chatStore.messages[i].messageId === klineMessageId1) {
  666. // klineIndex = i;
  667. // break;
  668. // }
  669. // }
  670. // console.log("找到的K线消息索引:", klineIndex);
  671. // if (klineIndex !== -1) {
  672. // const containerId = `kline-container-${klineIndex}`;
  673. // console.log("图表容器ID:", containerId);
  674. // // 确保DOM已经渲染完成
  675. // setTimeout(() => {
  676. // console.log("延时执行,确保DOM已渲染");
  677. // KlineCanvsEcharts(containerId);
  678. // }, 100); // 短暂延时确保DOM已渲染
  679. // } else {
  680. // console.warn("未找到K线消息");
  681. // }
  682. // });
  683. // 度牛尺K线图
  684. const AIGoldBullData = JSON.parse(
  685. JSON.stringify(toRaw(AIGoldBull))
  686. );
  687. const HomePageData = JSON.parse(
  688. JSON.stringify(toRaw(HomePage))
  689. );
  690. console.log("处理 K 线数据 - 开始");
  691. console.log("AIGoldBullData", AIGoldBullData);
  692. console.log("HomePageData", HomePageData);
  693. const Kline20 = {
  694. name: HomePageData.StockInformation.Name,
  695. Kline: AIGoldBullData,
  696. };
  697. // 打印K线数据结构
  698. console.log("K线数据结构:", Kline20);
  699. console.log("K线数据名称:", Kline20.name);
  700. console.log("K线数据:", Kline20.Kline ? Kline20.Kline : null);
  701. // 设置数据有效标志
  702. hasValidData.value = true;
  703. console.log("hasValidData设置为:", hasValidData.value);
  704. // chatStore.messages.pop();
  705. // 先推送K线图消息
  706. const klineMessageId2 = `kline-${Date.now() + 1}`;
  707. console.log("生成K线消息ID:", klineMessageId2);
  708. // chatStore.messages.push({
  709. // sender: "ai",
  710. // class: "content2",
  711. // type: "content2",
  712. // kline: true,
  713. // chartData: Kline20,
  714. // messageId: klineMessageId2,
  715. // hasValidData: true, // 添加hasValidData标志
  716. // klineType: 2,
  717. // });
  718. addTypingTask(
  719. {
  720. sender: "ai",
  721. class: "content2",
  722. type: "content2",
  723. kline: true,
  724. chartData: Kline20,
  725. messageId: klineMessageId2,
  726. hasValidData: true, // 添加hasValidData标志
  727. klineType: 2,
  728. },
  729. "",
  730. 50
  731. );
  732. // console.log("K线消息已添加到聊天列表");
  733. // // 在渲染完成后初始化图表
  734. // nextTick(() => {
  735. // console.log("nextTick开始 - 准备渲染图表");
  736. // console.log("消息列表:", chatStore.messages);
  737. // // 寻找最新添加的K线消息索引
  738. // let klineIndex = -1;
  739. // for (let i = 0; i < chatStore.messages.length; i++) {
  740. // if (chatStore.messages[i].messageId === klineMessageId2) {
  741. // klineIndex = i;
  742. // break;
  743. // }
  744. // }
  745. // console.log("找到的K线消息索引:", klineIndex);
  746. // if (klineIndex !== -1) {
  747. // const containerId = `kline-container-${klineIndex}`;
  748. // console.log("图表容器ID:", containerId);
  749. // // 确保DOM已经渲染完成
  750. // setTimeout(() => {
  751. // console.log("延时执行,确保DOM已渲染");
  752. // KlineCanvsEcharts(containerId);
  753. // }, 100); // 短暂延时确保DOM已渲染
  754. // } else {
  755. // console.warn("未找到K线消息");
  756. // }
  757. // });
  758. }
  759. }
  760. // 检查TwoAPI(需要OneAPI已执行)
  761. if (
  762. apiStatus.one.executed &&
  763. apiStatus.two.completed &&
  764. !apiStatus.two.executed
  765. ) {
  766. apiStatus.two.executed = true;
  767. if (apiStatus.two.result) {
  768. console.log("执行TwoAPI代码:", apiStatus.two.result);
  769. // 在这里添加TwoAPI成功后需要执行的代码
  770. // 添加标题2
  771. addTypingTask(
  772. {
  773. sender: "ai",
  774. class: "title2",
  775. type: "title2",
  776. content: "",
  777. },
  778. "",
  779. 50
  780. );
  781. // chatStore.messages.push({
  782. // sender: "ai",
  783. // class: "title2",
  784. // type: "title2",
  785. // content: "",
  786. // });
  787. // 添加内容框1
  788. const pc2 = marked(result22.data.hxjzpg);
  789. console.log(pc2, "pc2");
  790. const ac2 = pc2.replace(katexRegex, (match, formula) => {
  791. try {
  792. return katex.renderToString(formula, {
  793. throwOnError: false,
  794. });
  795. } catch (error) {
  796. console.error("KaTeX 渲染错误:", error);
  797. return match;
  798. }
  799. });
  800. // 先推送初始消息
  801. const aiMessage2 = reactive({
  802. sender: "ai",
  803. class: "content3",
  804. type: "content3",
  805. content: "",
  806. isTyping: true,
  807. });
  808. // chatStore.messages.push(aiMessage2);
  809. // let index2 = 0;
  810. // const typingInterval2 = setInterval(() => {
  811. // if (index2 < ac2.length) {
  812. // aiMessage2.content += ac2.charAt(index2);
  813. // index2++;
  814. // } else {
  815. // clearInterval(typingInterval2);
  816. // aiMessage2.isTyping = false;
  817. // }
  818. // }, 50); // 调整速度为50ms/字符
  819. addTypingTask(aiMessage2, ["", ac2], 50);
  820. // chatStore.messages.push({
  821. // sender: "ai",
  822. // class: "content3",
  823. // type: "content3",
  824. // content: ac2,
  825. // });
  826. }
  827. }
  828. // 检查ThreeAPI(需要TwoAPI已执行)
  829. if (
  830. apiStatus.two.executed &&
  831. apiStatus.three.completed &&
  832. !apiStatus.three.executed
  833. ) {
  834. apiStatus.three.executed = true;
  835. if (apiStatus.three.result) {
  836. console.log("执行ThreeAPI代码:", apiStatus.three.result);
  837. // 在这里添加ThreeAPI成功后需要执行的代码
  838. // 添加标题3-2
  839. addTypingTask(
  840. {
  841. sender: "ai",
  842. class: "title3",
  843. type: "title3",
  844. content: title2,
  845. },
  846. "",
  847. 50
  848. );
  849. // chatStore.messages.push({
  850. // sender: "ai",
  851. // class: "title3",
  852. // type: "title3",
  853. // content: title2,
  854. // });
  855. // 添加内容框2
  856. // const pc3 = marked(result23.data.zhuli1+'\n'+result23.data.zhuli2+'\n'+result23.data.zhuli3);
  857. // const ac3 = pc3.replace(
  858. // katexRegex,
  859. // (match, formula) => {
  860. // try {
  861. // return katex.renderToString(formula, { throwOnError: false });
  862. // } catch (error) {
  863. // console.error("KaTeX 渲染错误:", error);
  864. // return match;
  865. // }
  866. // }
  867. // );
  868. const ac31 = `<p style="margin:0;color:#FADC0C;display:flex;justify-content:center;font-size:28px">【主力行为】</p><p>`;
  869. const ac32 = `${result23.data.zhuli1}</p><p>${result23.data.zhuli2}</p><p>${result23.data.zhuli3}</p>`;
  870. const ac3 = `<p style="margin:0;color:#FADC0C;display:flex;justify-content:center;font-size:28px">【主力行为】</p><p>${result23.data.zhuli1}</p><p>${result23.data.zhuli2}</p><p>${result23.data.zhuli3}</p>`;
  871. // 先推送初始消息
  872. const aiMessage3 = reactive({
  873. sender: "ai",
  874. class: "content3",
  875. type: "content3",
  876. content: "",
  877. isTyping: true,
  878. });
  879. // chatStore.messages.push(aiMessage3);
  880. // let index3 = 0;
  881. // const typingInterval3 = setInterval(() => {
  882. // if (index3 < ac3.length) {
  883. // aiMessage3.content += ac3.charAt(index3);
  884. // index3++;
  885. // } else {
  886. // clearInterval(typingInterval3);
  887. // aiMessage3.isTyping = false;
  888. // }
  889. // }, 50); // 调整速度为50ms/字符
  890. addTypingTask(aiMessage3, [ac31, ac32], 50);
  891. // chatStore.messages.push({
  892. // sender: "ai",
  893. // class: "content3",
  894. // type: "content3",
  895. // content: ac3,
  896. // });
  897. // 添加标题3-3
  898. addTypingTask(
  899. {
  900. sender: "ai",
  901. class: "title3",
  902. type: "title3",
  903. content: title3,
  904. },
  905. "",
  906. 50
  907. );
  908. // chatStore.messages.push({
  909. // sender: "ai",
  910. // class: "title3",
  911. // type: "title3",
  912. // content: title3,
  913. // });
  914. // 添加内容框3
  915. const arr = result23.data.kongjian.split(",");
  916. const kongjian = `<p style="margin:0;color:#FADC0C;display:flex;justify-content:center;font-size:28px">【空间维度】</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>`;
  917. const shijian = `<p style="margin:0;color:#FADC0C;display:flex;justify-content:center;font-size:28px">【时间维度】</p><p style="display:flex;justify-content:center;">${result23.data.shijian}</p>`;
  918. const nengliang = `<p style="margin:0;color:#FADC0C;display:flex;justify-content:center;font-size:28px">【能量维度】</p><p>${result23.data.nengliang}</p>`;
  919. const ac4 = kongjian + shijian + nengliang;
  920. const ac41 = `<p style="margin:0;color:#FADC0C;display:flex;justify-content:center;font-size:28px">【空间维度】</p><p style="display:flex;justify-content:center;">`;
  921. const ac42 = `${arr[0]},${arr[1]}`;
  922. const ac43 = `</p><p style="display:flex;justify-content:center;">`;
  923. const ac44 = `${arr[2]},${arr[3]}</p>`;
  924. const ac45 = `<p style="margin:0;color:#FADC0C;display:flex;justify-content:center;font-size:28px">【时间维度】</p><p style="display:flex;justify-content:center;">`;
  925. const ac46 = `${result23.data.shijian}</p>`;
  926. const ac47 = `<p style="margin:0;color:#FADC0C;display:flex;justify-content:center;font-size:28px">【能量维度】</p><p>`;
  927. const ac48 = `${result23.data.nengliang}</p>`;
  928. // const pc4 = marked(
  929. // kongjian +
  930. // "\n" +
  931. // result23.data.shijian +
  932. // "\n" +
  933. // result23.data.nengliang
  934. // );
  935. // const ac4 = pc4.replace(katexRegex, (match, formula) => {
  936. // try {
  937. // return katex.renderToString(formula, { throwOnError: false });
  938. // } catch (error) {
  939. // console.error("KaTeX 渲染错误:", error);
  940. // return match;
  941. // }
  942. // });
  943. // 先推送初始消息
  944. const aiMessage4 = reactive({
  945. sender: "ai",
  946. class: "content3",
  947. type: "content3",
  948. content: "",
  949. isTyping: true,
  950. });
  951. // chatStore.messages.push(aiMessage4);
  952. // let index4 = 0;
  953. // const typingInterval4 = setInterval(() => {
  954. // if (index4 < ac4.length) {
  955. // aiMessage4.content += ac4.charAt(index4);
  956. // index4++;
  957. // } else {
  958. // clearInterval(typingInterval4);
  959. // aiMessage4.isTyping = false;
  960. // }
  961. // }, 50); // 调整速度为50ms/字符
  962. addTypingTask(
  963. aiMessage4,
  964. [ac41, ac42, ac43, ac44, ac45, ac46, ac47, ac48],
  965. 50
  966. );
  967. // chatStore.messages.push({
  968. // sender: "ai",
  969. // class: "content3",
  970. // type: "content3",
  971. // content: ac4,
  972. // });
  973. }
  974. }
  975. // 检查FourAPI(需要ThreeAPI已执行)
  976. if (
  977. apiStatus.three.executed &&
  978. apiStatus.four.completed &&
  979. !apiStatus.four.executed
  980. ) {
  981. apiStatus.four.executed = true;
  982. if (apiStatus.four.result) {
  983. console.log("执行FourAPI代码:", apiStatus.four.result);
  984. // 在这里添加FourAPI成功后需要执行的代码
  985. // 添加标题3-4
  986. addTypingTask(
  987. {
  988. sender: "ai",
  989. class: "title3",
  990. type: "title3",
  991. content: title4,
  992. },
  993. "",
  994. 50
  995. );
  996. // chatStore.messages.push({
  997. // sender: "ai",
  998. // class: "title3",
  999. // type: "title3",
  1000. // content: title4,
  1001. // });
  1002. // 添加内容框4
  1003. const cftj = `<p style="margin:0;color:#FADC0C;display:flex;justify-content:center;font-size:28px">【触发条件】</p><p>${result24.data.cftl}</p>`;
  1004. const gfzl = `<p style="margin:0;color:#FADC0C;display:flex;justify-content:center;font-size:28px">【攻防指令】</p><p>${result24.data.gfzl}</p>`;
  1005. const ac5 = cftj + gfzl;
  1006. const ac51 = `<p style="margin:0;color:#FADC0C;display:flex;justify-content:center;font-size:28px">【触发条件】</p><p>`;
  1007. const ac52 = `${result24.data.cftl}</p>`;
  1008. const ac53 = `<p style="margin:0;color:#FADC0C;display:flex;justify-content:center;font-size:28px">【攻防指令】</p><p>`;
  1009. const ac54 = `${result24.data.gfzl}</p>`;
  1010. // const pc5 = marked(result24.data.cftl + "/n" + result24.data.gfzl);
  1011. // const ac5 = pc5.replace(katexRegex, (match, formula) => {
  1012. // try {
  1013. // return katex.renderToString(formula, { throwOnError: false });
  1014. // } catch (error) {
  1015. // console.error("KaTeX 渲染错误:", error);
  1016. // return match;
  1017. // }
  1018. // });
  1019. // 先推送初始消息
  1020. const aiMessage5 = reactive({
  1021. sender: "ai",
  1022. class: "content3",
  1023. type: "content3",
  1024. content: "",
  1025. isTyping: true,
  1026. });
  1027. // chatStore.messages.push(aiMessage5);
  1028. // let index5 = 0;
  1029. // const typingInterval5 = setInterval(() => {
  1030. // if (index5 < ac5.length) {
  1031. // aiMessage5.content += ac5.charAt(index5);
  1032. // index5++;
  1033. // } else {
  1034. // clearInterval(typingInterval5);
  1035. // aiMessage5.isTyping = false;
  1036. // }
  1037. // }, 50); // 调整速度为50ms/字符
  1038. addTypingTask(aiMessage5, [ac51,ac52,ac53,ac54], 50);
  1039. // chatStore.messages.push({
  1040. // sender: "ai",
  1041. // class: "content3",
  1042. // type: "content3",
  1043. // content: ac5,
  1044. // });
  1045. const ac6 = "内容由AI生成,请注意甄别";
  1046. // 先推送初始消息
  1047. const aiMessage6 = reactive({
  1048. sender: "ai",
  1049. class: "mianze",
  1050. type: "mianze",
  1051. content: "",
  1052. isTyping: true,
  1053. });
  1054. // chatStore.messages.push(aiMessage6);
  1055. // let index6 = 0;
  1056. // const typingInterval6 = setInterval(() => {
  1057. // if (index6 < ac6.length) {
  1058. // aiMessage6.content += ac6.charAt(index6);
  1059. // index6++;
  1060. // } else {
  1061. // clearInterval(typingInterval6);
  1062. // aiMessage6.isTyping = false;
  1063. // }
  1064. // }, 50); // 调整速度为50ms/字符
  1065. addTypingTask(aiMessage6, ["", ac6], 100);
  1066. // chatStore.messages.push({
  1067. // sender: "ai",
  1068. // class: "mianze",
  1069. // type: "mianze",
  1070. // content: "内容由AI生成,请注意甄别",
  1071. // });
  1072. }
  1073. }
  1074. // 检查是否所有API都已完成并执行
  1075. if (
  1076. apiStatus.one.completed &&
  1077. apiStatus.two.completed &&
  1078. apiStatus.three.completed &&
  1079. apiStatus.four.completed &&
  1080. apiStatus.four.executed
  1081. ) {
  1082. console.log("所有API已完成,开始收集音频URL");
  1083. // 收集所有音频URL
  1084. const audioUrls = [];
  1085. console.log("API返回结果检查:");
  1086. console.log("result21:", result21);
  1087. console.log("result22:", result22);
  1088. console.log("result23:", result23);
  1089. console.log("result24:", result24);
  1090. if (result21?.data?.url) {
  1091. console.log("添加result21音频URL:", result21.data.url);
  1092. audioUrls.push(result21.data.url.trim());
  1093. }
  1094. if (result22?.data?.url) {
  1095. console.log("添加result22音频URL:", result22.data.url);
  1096. audioUrls.push(result22.data.url.trim());
  1097. }
  1098. if (result23?.data?.url) {
  1099. console.log("添加result23音频URL:", result23.data.url);
  1100. audioUrls.push(result23.data.url.trim());
  1101. }
  1102. if (result24?.data?.url) {
  1103. console.log("添加result24音频URL:", result24.data.url);
  1104. audioUrls.push(result24.data.url.trim());
  1105. }
  1106. console.log("收集到的音频URLs:", audioUrls);
  1107. console.log("语音是否启用:", audioStore.isVoiceEnabled);
  1108. // 开始轮流播放音频
  1109. if (audioUrls.length > 0 && audioStore.isVoiceEnabled) {
  1110. console.log("开始播放音频序列");
  1111. playAudioSequence(audioUrls);
  1112. } else {
  1113. console.log(
  1114. "跳过音频播放 - audioUrls长度:",
  1115. audioUrls.length,
  1116. "语音启用状态:",
  1117. audioStore.isVoiceEnabled
  1118. );
  1119. }
  1120. }
  1121. };
  1122. const handleOneAPI = async () => {
  1123. try {
  1124. result21 = await dbqbSecondOneAPI(params2);
  1125. console.log("OneAPI成功返回:", result21);
  1126. apiStatus.one.completed = true;
  1127. apiStatus.one.result = result21;
  1128. // 检查是否可以执行
  1129. checkAndExecuteInOrder();
  1130. } catch (error) {
  1131. console.error("OneAPI失败:", error);
  1132. apiStatus.one.completed = true;
  1133. apiStatus.one.error = error;
  1134. // 即使失败也要检查后续执行
  1135. checkAndExecuteInOrder();
  1136. }
  1137. };
  1138. const handleTwoAPI = async () => {
  1139. try {
  1140. result22 = await dbqbSecondTwoAPI(params2);
  1141. console.log("TwoAPI成功返回:", result22);
  1142. apiStatus.two.completed = true;
  1143. apiStatus.two.result = result22;
  1144. // 检查是否可以执行
  1145. checkAndExecuteInOrder();
  1146. } catch (error) {
  1147. console.error("TwoAPI失败:", error);
  1148. apiStatus.two.completed = true;
  1149. apiStatus.two.error = error;
  1150. checkAndExecuteInOrder();
  1151. }
  1152. };
  1153. const handleThreeAPI = async () => {
  1154. try {
  1155. result23 = await dbqbSecondThreeAPI(params2);
  1156. console.log("ThreeAPI成功返回:", result23);
  1157. apiStatus.three.completed = true;
  1158. apiStatus.three.result = result23;
  1159. // 检查是否可以执行
  1160. checkAndExecuteInOrder();
  1161. } catch (error) {
  1162. console.error("ThreeAPI失败:", error);
  1163. apiStatus.three.completed = true;
  1164. apiStatus.three.error = error;
  1165. checkAndExecuteInOrder();
  1166. }
  1167. };
  1168. const handleFourAPI = async () => {
  1169. try {
  1170. result24 = await dbqbSecondFourAPI(params2);
  1171. console.log("FourAPI成功返回:", result24);
  1172. apiStatus.four.completed = true;
  1173. apiStatus.four.result = result24;
  1174. // 检查是否可以执行
  1175. checkAndExecuteInOrder();
  1176. } catch (error) {
  1177. console.error("FourAPI失败:", error);
  1178. apiStatus.four.completed = true;
  1179. apiStatus.four.error = error;
  1180. checkAndExecuteInOrder();
  1181. }
  1182. };
  1183. handleOneAPI();
  1184. handleTwoAPI();
  1185. handleThreeAPI();
  1186. handleFourAPI();
  1187. // 同时发起所有API调用
  1188. // const promises = [
  1189. // dbqbSecondOneAPI(params2),
  1190. // dbqbSecondTwoAPI(params2),
  1191. // dbqbSecondThreeAPI(params2),
  1192. // dbqbSecondFourAPI(params2),
  1193. // ];
  1194. // const results = await Promise.allSettled(promises);
  1195. // let result21;
  1196. // let result22;
  1197. // let result23;
  1198. // let result24;
  1199. // // 检查每个API的结果并执行相应代码
  1200. // console
  1201. // if (results[0].status === "fulfilled") {
  1202. // result21 = results[0].value;
  1203. // // oneAPI成功返回时执行的代码
  1204. // console.log("oneAPI成功:", result21);
  1205. // // 在这里添加你的业务逻辑
  1206. // }
  1207. // if (results[1].status === "fulfilled") {
  1208. // result22 = results[1].value;
  1209. // // twoAPI成功返回时执行的代码
  1210. // console.log("twoAPI成功:", result22);
  1211. // // 在这里添加你的业务逻辑
  1212. // }
  1213. // if (results[2].status === "fulfilled") {
  1214. // result23 = results[2].value;
  1215. // // threeAPI成功返回时执行的代码
  1216. // console.log("threeAPI成功:", result23);
  1217. // }
  1218. // if (results[3].status === "fulfilled") {
  1219. // result24 = results[3].value;
  1220. // // fourAPI成功返回时执行的代码
  1221. // console.log("fourAPI成功:", result24);
  1222. // }
  1223. // const result21 = await dbqbSecondOneAPI(params2);
  1224. // const result22 = await dbqbSecondTwoAPI(params2);
  1225. // const result23 = await dbqbSecondThreeAPI(params2);
  1226. // const result24 = await dbqbSecondFourAPI(params2);
  1227. // 音频收集逻辑已移至checkAndExecuteInOrder函数内部
  1228. // // 修改后的消息处理逻辑
  1229. // const processedContent = marked(AIcontent.value);
  1230. // const katexRegex = /\$\$(.*?)\$\$/g;
  1231. // const plainTextContent = htmlToText(processedContent);
  1232. // // 获取音频数据
  1233. // const TTSResult = (
  1234. // await TTSAPI({
  1235. // language: "cn",
  1236. // content: plainTextContent,
  1237. // })
  1238. // ).json();
  1239. // const tts = ref();
  1240. // await TTSResult.then((res) => {
  1241. // tts.value = JSON.parse(res.data);
  1242. // });
  1243. // const ttsUrl = ref();
  1244. // if (tts.value.tts_cn !== null) {
  1245. // audioStore.ttsUrl = tts.value.tts_cn.url;
  1246. // ttsUrl.value = tts.value.tts_cn.url;
  1247. // audioStore.isNewInstance = true;
  1248. // } else if (tts.value.tts_en !== null) {
  1249. // audioStore.ttsUrl = tts.value.tts_en.url;
  1250. // ttsUrl.value = tts.value.tts_en.url;
  1251. // audioStore.isNewInstance = true;
  1252. // }
  1253. // if (ttsUrl.value) {
  1254. // nextTick(() => {
  1255. // if (audioStore.isVoiceEnabled) {
  1256. // console.log("ttsUrl.value", ttsUrl.value);
  1257. // // 播放音频
  1258. // playAudio(ttsUrl.value);
  1259. // }
  1260. // });
  1261. // }
  1262. // // chatStore.messages.pop();
  1263. // // 先推送初始消息
  1264. // const aiMessage = reactive({
  1265. // sender: "ai",
  1266. // content: "",
  1267. // isTyping: true,
  1268. // });
  1269. // chatStore.messages.push(aiMessage);
  1270. // let index = 0;
  1271. // const typingInterval = setInterval(() => {
  1272. // if (index < processedContent.length) {
  1273. // aiMessage.content += processedContent.charAt(index);
  1274. // index++;
  1275. // } else {
  1276. // clearInterval(typingInterval);
  1277. // aiMessage.isTyping = false;
  1278. // // 延迟处理KaTeX确保DOM已更新
  1279. // nextTick(() => {
  1280. // aiMessage.content = aiMessage.content.replace(
  1281. // katexRegex,
  1282. // (match, formula) => {
  1283. // try {
  1284. // return katex.renderToString(formula, {
  1285. // throwOnError: false,
  1286. // });
  1287. // } catch (error) {
  1288. // console.error("KaTeX 渲染错误:", error);
  1289. // return match;
  1290. // }
  1291. // }
  1292. // );
  1293. // chatStore.setLoading(false);
  1294. // });
  1295. // }
  1296. // }, 50); // 调整速度为50ms/字符
  1297. // // } else {
  1298. // // chatStore.messages.pop();
  1299. // // chatStore.messages.push({
  1300. // // sender: "ai",
  1301. // // content: status.msg
  1302. // // });
  1303. // // chatStore.setLoading(false);
  1304. // // }
  1305. // }
  1306. } catch (e) {
  1307. console.error("请求失败:", e);
  1308. hasValidData.value = false; // 请求失败时设置数据无效
  1309. // chatStore.messages.pop();
  1310. // chatStore.messages.push({
  1311. // sender: "ai",
  1312. // content: "AI思考失败,请稍后再试... ",
  1313. // });
  1314. // chatStore.setLoading(false);
  1315. } finally {
  1316. chatStore.setLoading(false);
  1317. await chatStore.getUserCount();
  1318. }
  1319. }
  1320. }
  1321. },
  1322. { deep: true }
  1323. );
  1324. function KlineCanvsEcharts(containerId) {
  1325. function vwToPx(vw) {
  1326. console.log((window.innerWidth * vw) / 100, "vwToPx");
  1327. return (window.innerWidth * vw) / 100;
  1328. }
  1329. console.log("KLine渲染: 开始处理数据, 容器ID:", containerId);
  1330. // 从 chatStore 中获取数据
  1331. const messages = chatStore.messages;
  1332. console.log("KLine渲染: 获取到的消息:", messages);
  1333. let klineMessageIndex = -1;
  1334. let klineData = null;
  1335. // 查找最近的 K线 消息
  1336. // for (let i = messages.length - 1; i >= 0; i--) {
  1337. // console.log('KLine渲染: 检查消息:', messages[i]);
  1338. // if (messages[i].type === 'kline' && messages[i].chartData) {
  1339. // klineMessageIndex = i;
  1340. // klineData = messages[i].chartData;
  1341. // console.log('KLine渲染: 找到K线消息索引:', klineMessageIndex);
  1342. // console.log('KLine渲染: 找到K线数据:', klineData);
  1343. // break;
  1344. // }
  1345. // }
  1346. klineMessageIndex = containerId.split("-")[2];
  1347. console.log("KLine渲染: 找到K线消息索引:", klineMessageIndex);
  1348. if (
  1349. messages[klineMessageIndex].kline &&
  1350. messages[klineMessageIndex].chartData
  1351. ) {
  1352. klineData = messages[klineMessageIndex].chartData;
  1353. }
  1354. var KlineOption = {};
  1355. // 检测设备类型
  1356. const isMobile = window.innerWidth < 768;
  1357. const isTablet = window.innerWidth >= 768 && window.innerWidth < 1024;
  1358. console.log(
  1359. "KLine渲染: 设备类型",
  1360. isMobile ? "移动设备" : isTablet ? "平板设备" : "桌面设备"
  1361. );
  1362. if (messages[klineMessageIndex].klineType == 1) {
  1363. if (!klineData) {
  1364. console.warn("六色罗盘渲染: 数据无效 - 在chatStore中找不到有效的K线数据");
  1365. return;
  1366. }
  1367. // 获取容器元素
  1368. const container = document.getElementById(containerId);
  1369. if (!container) {
  1370. console.error("六色罗盘渲染: 找不到容器元素:", containerId);
  1371. return;
  1372. }
  1373. // 创建图表实例
  1374. console.log("六色罗盘渲染: 创建图表实例");
  1375. try {
  1376. // 如果已有实例,先销毁
  1377. if (chartInstancesMap[containerId]) {
  1378. console.log("六色罗盘渲染: 销毁已有图表实例");
  1379. chartInstancesMap[containerId].dispose();
  1380. delete chartInstancesMap[containerId];
  1381. }
  1382. // 使用普通变量存储实例
  1383. chartInstancesMap[containerId] = echarts.init(container);
  1384. console.log("六色罗盘渲染: 图表实例创建成功");
  1385. } catch (error) {
  1386. console.error("六色罗盘渲染: 图表实例创建失败:", error);
  1387. return;
  1388. }
  1389. const name = ref("六色罗盘");
  1390. const size = ref(16);
  1391. // PC版字体大小
  1392. if (window.innerWidth > 768) {
  1393. size.value = 25;
  1394. }
  1395. KlineOption = {
  1396. tooltip: {
  1397. show: !1,
  1398. },
  1399. series: [
  1400. {
  1401. name: "\u4eea\u8868\u76d8",
  1402. type: "gauge",
  1403. center: ["50%", "50%"],
  1404. radius: "90%",
  1405. startAngle: 140,
  1406. endAngle: -140,
  1407. min: 0,
  1408. max: 6,
  1409. precision: 0,
  1410. splitNumber: 30, // 分成30份
  1411. axisLine: {
  1412. show: !0,
  1413. lineStyle: {
  1414. color: [
  1415. [0.17, "#FC4407"],
  1416. [0.33, "#FDC404"],
  1417. [0.5, "#2D8FFD"],
  1418. [0.67, "#87CCE7"],
  1419. [0.83, "#C1F478"],
  1420. [1, "#8FEB8D"],
  1421. ],
  1422. width: 20,
  1423. },
  1424. },
  1425. axisTick: {
  1426. show: !0,
  1427. splitNumber: 9,
  1428. length: 8,
  1429. lineStyle: {
  1430. color: "#eee",
  1431. width: 1,
  1432. type: "solid",
  1433. },
  1434. },
  1435. axisLabel: {
  1436. show: true,
  1437. formatter: function (v) {},
  1438. textStyle: {
  1439. color: "auto",
  1440. },
  1441. },
  1442. // 中途切割
  1443. splitLine: {
  1444. show: !0,
  1445. length: 20,
  1446. lineStyle: {
  1447. color: "#eee",
  1448. width: 2,
  1449. type: "solid",
  1450. },
  1451. },
  1452. pointer: {
  1453. length: "80%",
  1454. width: 8,
  1455. color: "auto",
  1456. },
  1457. title: {
  1458. show: !0,
  1459. offsetCenter: ["-65%", -10],
  1460. textStyle: {
  1461. color: "#333",
  1462. fontSize: 15,
  1463. },
  1464. },
  1465. detail: {
  1466. show: !0,
  1467. backgroundColor: "rgba(0,0,0,0)",
  1468. borderWidth: 0,
  1469. borderColor: "#ccc",
  1470. width: 100,
  1471. height: 40,
  1472. offsetCenter: ["-90%", 0], // name位置
  1473. formatter: function () {
  1474. return name.value;
  1475. },
  1476. textStyle: {
  1477. color: "auto",
  1478. fontSize: size.value, // 字体尺寸
  1479. },
  1480. },
  1481. data: [{ value: klineData }],
  1482. },
  1483. ],
  1484. };
  1485. } else if (messages[klineMessageIndex].klineType == 2) {
  1486. if (!klineData || !klineData.Kline) {
  1487. console.warn("KLine渲染: 数据无效 - 在chatStore中找不到有效的K线数据");
  1488. return;
  1489. }
  1490. // 获取容器元素
  1491. const container = document.getElementById(containerId);
  1492. if (!container) {
  1493. console.error("KLine渲染: 找不到容器元素:", containerId);
  1494. return;
  1495. }
  1496. // 创建图表实例
  1497. console.log("KLine渲染: 创建图表实例");
  1498. try {
  1499. // 如果已有实例,先销毁
  1500. if (chartInstancesMap[containerId]) {
  1501. console.log("KLine渲染: 销毁已有图表实例");
  1502. chartInstancesMap[containerId].dispose();
  1503. delete chartInstancesMap[containerId];
  1504. }
  1505. // 使用普通变量存储实例
  1506. chartInstancesMap[containerId] = echarts.init(container);
  1507. console.log("KLine渲染: 图表实例创建成功");
  1508. } catch (error) {
  1509. console.error("KLine渲染: 图表实例创建失败:", error);
  1510. return;
  1511. }
  1512. const data = klineData.Kline;
  1513. console.log("KLine渲染: Kline数据", data);
  1514. // 切割数据方法
  1515. const splitData = (a) => {
  1516. console.log("KLine渲染: 开始数据切割");
  1517. const categoryData = [];
  1518. let values = [];
  1519. for (let i = 0; i < a.length; i++) {
  1520. categoryData.push(a[i][0]);
  1521. values.push([a[i][1], a[i][2], a[i][3], a[i][4]]);
  1522. }
  1523. console.log("KLine渲染: 日期数据点数量", categoryData.length);
  1524. console.log("KLine渲染: 值数据点数量", values.length);
  1525. return { categoryData, values };
  1526. };
  1527. // 给配置项
  1528. console.log("KLine渲染: 开始配置图表选项");
  1529. const arr1 = [];
  1530. const arr2 = [];
  1531. const arr3 = [];
  1532. const arr4 = [];
  1533. const changeColorKline = (QSXH, KLine20) => {
  1534. if (QSXH) {
  1535. QSXH.map((item) => {
  1536. KLine20.map((kline_item) => {
  1537. if (item[1] == 1 && item[0] == kline_item[0]) {
  1538. arr1.push(kline_item);
  1539. arr2.push([
  1540. kline_item[0],
  1541. null,
  1542. null,
  1543. null,
  1544. null,
  1545. null,
  1546. null,
  1547. null,
  1548. ]);
  1549. arr3.push([
  1550. kline_item[0],
  1551. null,
  1552. null,
  1553. null,
  1554. null,
  1555. null,
  1556. null,
  1557. null,
  1558. ]);
  1559. arr4.push([
  1560. kline_item[0],
  1561. null,
  1562. null,
  1563. null,
  1564. null,
  1565. null,
  1566. null,
  1567. null,
  1568. ]);
  1569. }
  1570. if (item[1] == 2 && item[0] == kline_item[0]) {
  1571. arr2.push(kline_item);
  1572. arr1.push([
  1573. kline_item[0],
  1574. null,
  1575. null,
  1576. null,
  1577. null,
  1578. null,
  1579. null,
  1580. null,
  1581. ]);
  1582. arr3.push([
  1583. kline_item[0],
  1584. null,
  1585. null,
  1586. null,
  1587. null,
  1588. null,
  1589. null,
  1590. null,
  1591. ]);
  1592. arr4.push([
  1593. kline_item[0],
  1594. null,
  1595. null,
  1596. null,
  1597. null,
  1598. null,
  1599. null,
  1600. null,
  1601. ]);
  1602. }
  1603. if (item[1] == 3 && item[0] == kline_item[0]) {
  1604. arr3.push(kline_item);
  1605. arr2.push([
  1606. kline_item[0],
  1607. null,
  1608. null,
  1609. null,
  1610. null,
  1611. null,
  1612. null,
  1613. null,
  1614. ]);
  1615. arr1.push([
  1616. kline_item[0],
  1617. null,
  1618. null,
  1619. null,
  1620. null,
  1621. null,
  1622. null,
  1623. null,
  1624. ]);
  1625. arr4.push([
  1626. kline_item[0],
  1627. null,
  1628. null,
  1629. null,
  1630. null,
  1631. null,
  1632. null,
  1633. null,
  1634. ]);
  1635. }
  1636. if (item[1] == 4 && item[0] == kline_item[0]) {
  1637. arr4.push(kline_item);
  1638. arr2.push([
  1639. kline_item[0],
  1640. null,
  1641. null,
  1642. null,
  1643. null,
  1644. null,
  1645. null,
  1646. null,
  1647. ]);
  1648. arr3.push([
  1649. kline_item[0],
  1650. null,
  1651. null,
  1652. null,
  1653. null,
  1654. null,
  1655. null,
  1656. null,
  1657. ]);
  1658. arr1.push([
  1659. kline_item[0],
  1660. null,
  1661. null,
  1662. null,
  1663. null,
  1664. null,
  1665. null,
  1666. null,
  1667. ]);
  1668. }
  1669. });
  1670. });
  1671. }
  1672. };
  1673. console.log(arr1, arr2, arr3, arr4);
  1674. changeColorKline(data.QSXH, data.KLine20);
  1675. var dealData = splitData(data.KLine20);
  1676. var dealData1 = splitData(arr1);
  1677. var dealData2 = splitData(arr2);
  1678. var dealData3 = splitData(arr3);
  1679. var dealData4 = splitData(arr4);
  1680. var dealGnBullData = data.JN;
  1681. function processMAData(data) {
  1682. let processedData = [];
  1683. data.forEach((item, idx) => {
  1684. processedData.push({
  1685. date: item[0],
  1686. value: item[1],
  1687. type: item[2],
  1688. });
  1689. });
  1690. // 当某一种type只存在一天,设置另一种type透明
  1691. let singleTypeRed = [{ min: 0, max: 0, color: "#000" }];
  1692. let singleTypeYellow = [{ min: 0, max: 0, color: "#000" }];
  1693. let singleTypeGreen = [{ min: 0, max: 0, color: "#000" }];
  1694. for (let i = 1; i < processedData.length; i++) {
  1695. if (processedData[i].type !== processedData[i - 1].type) {
  1696. if (
  1697. i == processedData.length - 1 ||
  1698. (processedData[i].type !== processedData[i + 1].type &&
  1699. processedData[i - 1].type === processedData[i + 1].type)
  1700. ) {
  1701. if (processedData[i - 1].type === 0) {
  1702. singleTypeGreen.push({
  1703. min: i - 1,
  1704. max: i,
  1705. color: "rgba(0,0,0,0)",
  1706. });
  1707. } else if (processedData[i - 1].type === 1) {
  1708. singleTypeRed.push({
  1709. min: i - 1,
  1710. max: i,
  1711. color: "rgba(0,0,0,0)",
  1712. });
  1713. } else if (processedData[i - 1].type === 2) {
  1714. singleTypeYellow.push({
  1715. min: i - 1,
  1716. max: i,
  1717. color: "rgba(0,0,0,0)",
  1718. });
  1719. }
  1720. }
  1721. }
  1722. if (processedData[i].type !== processedData[i - 1].type) {
  1723. if (processedData[i].type == 0) {
  1724. processedData[i - 1].isTransitionGreen = 1;
  1725. } else if (processedData[i].type == 1) {
  1726. processedData[i - 1].isTransitionRed = 1;
  1727. } else if (processedData[i].type == 2) {
  1728. processedData[i - 1].isTransitionYellow = 1;
  1729. }
  1730. // // 创建过渡点,使用前一个点的值
  1731. // processedData[i - 1].isTransition = true
  1732. }
  1733. }
  1734. let greenData = [];
  1735. let redData = [];
  1736. let yellowData = [];
  1737. processedData.forEach((item, idx) => {
  1738. const point = [item.date, item.value];
  1739. if (item.type === 0) {
  1740. greenData.push(point);
  1741. redData.push([item.date, "-"]);
  1742. yellowData.push([item.date, "-"]);
  1743. // if (item.isTransition) {
  1744. // redData[redData.length - 1] = [processedData[idx].date, processedData[idx].value]
  1745. // yellowData[yellowData.length - 1] = [processedData[idx].date, processedData[idx].value]
  1746. // }
  1747. if (item.isTransitionGreen) {
  1748. greenData[greenData.length - 1] = [
  1749. processedData[idx].date,
  1750. processedData[idx].value,
  1751. ];
  1752. } else if (item.isTransitionRed) {
  1753. redData[redData.length - 1] = [
  1754. processedData[idx].date,
  1755. processedData[idx].value,
  1756. ];
  1757. } else if (item.isTransitionYellow) {
  1758. yellowData[yellowData.length - 1] = [
  1759. processedData[idx].date,
  1760. processedData[idx].value,
  1761. ];
  1762. }
  1763. } else if (item.type === 1) {
  1764. redData.push(point);
  1765. greenData.push([item.date, "-"]);
  1766. yellowData.push([item.date, "-"]);
  1767. // if (item.isTransition) {
  1768. // greenData[greenData.length - 1] = [processedData[idx].date, processedData[idx].value]
  1769. // yellowData[yellowData.length - 1] = [processedData[idx].date, processedData[idx].value]
  1770. // }
  1771. if (item.isTransitionGreen) {
  1772. greenData[greenData.length - 1] = [
  1773. processedData[idx].date,
  1774. processedData[idx].value,
  1775. ];
  1776. } else if (item.isTransitionRed) {
  1777. redData[redData.length - 1] = [
  1778. processedData[idx].date,
  1779. processedData[idx].value,
  1780. ];
  1781. } else if (item.isTransitionYellow) {
  1782. yellowData[yellowData.length - 1] = [
  1783. processedData[idx].date,
  1784. processedData[idx].value,
  1785. ];
  1786. }
  1787. } else if (item.type === 2) {
  1788. redData.push([item.date, "-"]);
  1789. greenData.push([item.date, "-"]);
  1790. yellowData.push(point);
  1791. // if (item.isTransition) {
  1792. // greenData[greenData.length - 1] = [processedData[idx].date, processedData[idx].value]
  1793. // redData[redData.length - 1] = [processedData[idx].date, processedData[idx].value]
  1794. // }
  1795. if (item.isTransitionGreen) {
  1796. greenData[greenData.length - 1] = [
  1797. processedData[idx].date,
  1798. processedData[idx].value,
  1799. ];
  1800. } else if (item.isTransitionRed) {
  1801. redData[redData.length - 1] = [
  1802. processedData[idx].date,
  1803. processedData[idx].value,
  1804. ];
  1805. } else if (item.isTransitionYellow) {
  1806. yellowData[yellowData.length - 1] = [
  1807. processedData[idx].date,
  1808. processedData[idx].value,
  1809. ];
  1810. }
  1811. }
  1812. });
  1813. return {
  1814. greenData: greenData,
  1815. redData: redData,
  1816. yellowData: yellowData,
  1817. singleTypeGreen: singleTypeGreen,
  1818. singleTypeRed: singleTypeRed,
  1819. singleTypeYellow: singleTypeYellow,
  1820. };
  1821. }
  1822. const maData = processMAData(data.FCX);
  1823. const maDuchiData = processMAData(data.DNC);
  1824. if (data.FCX[0][1] == "-1") {
  1825. maData.greenData = [];
  1826. maData.redData = [];
  1827. maData.yellowData = [];
  1828. }
  1829. const processBarData = (data) => {
  1830. const barData = [];
  1831. const markPointData = [];
  1832. data.forEach((item) => {
  1833. let color;
  1834. switch (item[4]) {
  1835. case 1:
  1836. color = "#13E113";
  1837. break;
  1838. case 2:
  1839. color = "#FF0E00";
  1840. break;
  1841. case 3:
  1842. color = "#0000FE";
  1843. break;
  1844. case 4:
  1845. color = "#1397FF";
  1846. break;
  1847. }
  1848. barData.push({
  1849. value: item[5],
  1850. itemStyle: {
  1851. normal: {
  1852. color: color,
  1853. },
  1854. },
  1855. });
  1856. if (item[1] === 1) {
  1857. markPointData.push({
  1858. coord: [item[0], item[5]],
  1859. symbol:
  1860. "image://https://d31zlh4on95l9h.cloudfront.net/images/5iujb101000d5si3v3hr7w2vg0h43z1u.png",
  1861. symbolSize: [30, 30],
  1862. label: {
  1863. normal: {
  1864. color: "rgba(0, 0, 0, 0)",
  1865. },
  1866. },
  1867. });
  1868. }
  1869. if (item[2] === 1) {
  1870. markPointData.push({
  1871. coord: [item[0], item[5] / 2],
  1872. symbol:
  1873. "image://https://d31zlh4on95l9h.cloudfront.net/images/5iujaz01000d5si016bxdf6vh0377d2h.png",
  1874. symbolSize: [30, 30],
  1875. label: {
  1876. normal: {
  1877. color: "rgba(0, 0, 0, 0)",
  1878. },
  1879. },
  1880. });
  1881. }
  1882. if (item[3] === 1) {
  1883. markPointData.push({
  1884. coord: [item[0], 0],
  1885. symbol:
  1886. "image://https://d31zlh4on95l9h.cloudfront.net/images/5iujb001000d5shzls0tmd4vs0e5tdrw.png",
  1887. symbolSize: [30, 30],
  1888. label: {
  1889. normal: {
  1890. color: "rgba(0, 0, 0, 0)",
  1891. },
  1892. },
  1893. });
  1894. }
  1895. });
  1896. return { barData, markPointData };
  1897. };
  1898. const { barData, markPointData } = processBarData(dealGnBullData);
  1899. KlineOption = {
  1900. legend: [
  1901. {
  1902. textStyle: {
  1903. color: "black",
  1904. fontSize: window.innerWidth > 768 ? 15 : vwToPx(1.8),
  1905. },
  1906. width: "100%",
  1907. top: window.innerWidth > 768 ? "0%" : "-1%",
  1908. left: "center",
  1909. itemGap: window.innerWidth > 768 ? 20 : 10,
  1910. itemWidth: 10,
  1911. itemHeight: 10,
  1912. data: [
  1913. {
  1914. name: "进攻K线",
  1915. itemStyle: {
  1916. color: "rgb(255,0,0)",
  1917. },
  1918. },
  1919. {
  1920. name: "防守K线",
  1921. itemStyle: {
  1922. color: "red",
  1923. },
  1924. },
  1925. {
  1926. name: "推进K线",
  1927. itemStyle: {
  1928. color: "orange",
  1929. },
  1930. },
  1931. {
  1932. name: "撤退K线",
  1933. itemStyle: {
  1934. color: "rgb(84,252,252)",
  1935. },
  1936. },
  1937. ],
  1938. },
  1939. {
  1940. textStyle: {
  1941. color: "black",
  1942. fontSize: window.innerWidth > 768 ? 15 : vwToPx(1.8),
  1943. },
  1944. orient: "horizontal",
  1945. top: window.innerWidth > 768 ? "3%" : "2%",
  1946. width: "100%",
  1947. left: "center",
  1948. itemGap: 15,
  1949. data: [
  1950. {
  1951. name: "{green|━}{red|━} " + "牵牛绳",
  1952. icon: "none",
  1953. textStyle: {
  1954. rich: {
  1955. green: {
  1956. color: "green",
  1957. fontSize: window.innerWidth > 768 ? 20 : 10,
  1958. },
  1959. red: {
  1960. color: "red",
  1961. fontSize: window.innerWidth > 768 ? 20 : 10,
  1962. },
  1963. },
  1964. },
  1965. },
  1966. {
  1967. name: "龙线",
  1968. },
  1969. {
  1970. name: "虫线",
  1971. },
  1972. ],
  1973. },
  1974. {
  1975. textStyle: {
  1976. color: "black",
  1977. fontSize: window.innerWidth > 768 ? 15 : vwToPx(1.8),
  1978. },
  1979. orient: "horizontal",
  1980. top: window.innerWidth > 768 ? "68%" : "64%",
  1981. width: "100%",
  1982. left: "center",
  1983. itemGap: 15,
  1984. data: [
  1985. {
  1986. name: "{green|━}{red|━} " + "度牛尺",
  1987. icon: "none",
  1988. textStyle: {
  1989. rich: {
  1990. green: {
  1991. color: "green",
  1992. fontSize: window.innerWidth > 768 ? 20 : 10,
  1993. },
  1994. red: {
  1995. color: "red",
  1996. fontSize: window.innerWidth > 768 ? 20 : 10,
  1997. },
  1998. },
  1999. },
  2000. },
  2001. ],
  2002. },
  2003. ],
  2004. tooltip: {
  2005. formatter: function (a, b, d) {
  2006. if (a[0].seriesIndex == 0) {
  2007. const KlineTag = ref([]);
  2008. const AIBullTag = ref([]);
  2009. KlineTag.value = a.find((item) => item.data[1])?.data || [];
  2010. AIBullTag.value =
  2011. a.slice(4).find((item) => item.data[1] !== "-")?.data || [];
  2012. // console.log(AIBullTag.value)
  2013. return (
  2014. a[0].name +
  2015. "<br/>" +
  2016. "开盘价" +
  2017. ":" +
  2018. KlineTag.value[1] +
  2019. "<br/>" +
  2020. "收盘价" +
  2021. ":" +
  2022. KlineTag.value[2] +
  2023. "<br/>" +
  2024. "最低价" +
  2025. ":" +
  2026. KlineTag.value[3] +
  2027. "<br/>" +
  2028. "最高价" +
  2029. ":" +
  2030. KlineTag.value[4] +
  2031. "<br/>" +
  2032. "牵牛绳" +
  2033. ":" +
  2034. AIBullTag.value[1]
  2035. );
  2036. }
  2037. if (a[0].seriesIndex == 4) {
  2038. let formattedVolume;
  2039. if (a[0].data.value >= 10000) {
  2040. formattedVolume = (a[0].data.value / 10000).toFixed(2) + "w";
  2041. } else {
  2042. formattedVolume = a[0].data.value;
  2043. }
  2044. return a[0].name + "<br/>" + "成交量" + ":" + formattedVolume;
  2045. }
  2046. if ([10, 11, 12].includes(a[0].seriesIndex)) {
  2047. const duchiData = a.find(
  2048. (item) => item.data && item.data[1] !== "-"
  2049. );
  2050. return duchiData
  2051. ? a[0].axisValue + "<br/>" + "度牛尺" + ":" + duchiData.data[1]
  2052. : null;
  2053. }
  2054. },
  2055. trigger: "axis",
  2056. axisPointer: {
  2057. type: "cross",
  2058. },
  2059. backgroundColor: "rgba(119, 120, 125, 0.6)",
  2060. borderWidth: 1,
  2061. borderColor: "#77787D",
  2062. padding: 10,
  2063. textStyle: {
  2064. color: "#fff",
  2065. },
  2066. },
  2067. axisPointer: {
  2068. link: [
  2069. {
  2070. xAxisIndex: "all",
  2071. },
  2072. ],
  2073. label: {
  2074. backgroundColor: "#77787D",
  2075. },
  2076. },
  2077. toolbox: {
  2078. show: false,
  2079. },
  2080. grid: [
  2081. {
  2082. left: window.innerWidth > 1024 ? '70vw' : window.innerWidth>768? '65vw' : '55vw',
  2083. right: window.innerWidth > 1024 ? '40vw' : window.innerWidth>768? '30vw' : '40vw',
  2084. top: window.innerWidth > 768 ? "8%" : "5%",
  2085. height: window.innerWidth > 768 ? "34%" : "34%",
  2086. containLabel: false,
  2087. },
  2088. {
  2089. left: window.innerWidth > 1024 ? '70vw' : window.innerWidth>768? '65vw' : '55vw',
  2090. right: window.innerWidth > 1024 ? '40vw' : window.innerWidth>768? '30vw' : '40vw',
  2091. top: window.innerWidth > 768 ? "45%" : "42%",
  2092. height: window.innerWidth > 768 ? "22%" : "22%",
  2093. containLabel: false,
  2094. },
  2095. {
  2096. left: window.innerWidth > 1024 ? '70vw' : window.innerWidth>768? '65vw' : '55vw',
  2097. right: window.innerWidth > 1024 ? '40vw' : window.innerWidth>768? '30vw' : '40vw',
  2098. top: window.innerWidth > 768 ? "73%" : "70%",
  2099. height: window.innerWidth > 768 ? "20%" : "22%",
  2100. containLabel: false,
  2101. },
  2102. ],
  2103. xAxis: [
  2104. {
  2105. type: "category",
  2106. data: dealData.categoryData,
  2107. boundaryGap: true,
  2108. axisLine: { onZero: false },
  2109. splitLine: { show: false },
  2110. min: "dataMin",
  2111. max: "dataMax",
  2112. axisPointer: {
  2113. z: 100,
  2114. },
  2115. axisLine: {
  2116. lineStyle: {
  2117. color: "black",
  2118. },
  2119. }, //
  2120. axisLabel: { show: false },
  2121. axisTick: { show: false },
  2122. },
  2123. {
  2124. type: "category",
  2125. gridIndex: 1,
  2126. data: dealData.categoryData,
  2127. boundaryGap: true,
  2128. axisLine: { lineStyle: { color: "black" } },
  2129. axisLabel: {
  2130. show: false,
  2131. interval: "auto",
  2132. },
  2133. },
  2134. {
  2135. type: "category",
  2136. gridIndex: 2,
  2137. data: dealData.categoryData,
  2138. boundaryGap: true,
  2139. axisLine: { lineStyle: { color: "black" } },
  2140. axisLabel: {
  2141. show: true,
  2142. interval: "auto",
  2143. },
  2144. },
  2145. ],
  2146. yAxis: [
  2147. {
  2148. scale: true,
  2149. gridIndex: 0,
  2150. position: "left",
  2151. axisLabel: {
  2152. inside: false,
  2153. align: "right",
  2154. fontSize: window.innerWidth > 768 ? 15 : 10,
  2155. },
  2156. axisLine: {
  2157. show: true,
  2158. lineStyle: {
  2159. fontSize: "",
  2160. color: "black",
  2161. },
  2162. },
  2163. axisTick: { show: false },
  2164. splitLine: { show: false },
  2165. },
  2166. {
  2167. scale: true,
  2168. gridIndex: 1,
  2169. splitNumber: 4,
  2170. min: 0,
  2171. minInterval: 1,
  2172. axisLabel: {
  2173. show: true,
  2174. fontSize: window.innerWidth > 768 ? 15 : 10,
  2175. margin: 8,
  2176. formatter: (value) => {
  2177. if (value >= 1000000000) {
  2178. return (value / 1000000000).toFixed(1) + "B";
  2179. } else if (value >= 1000000) {
  2180. return (value / 1000000).toFixed(1) + "M";
  2181. } else if (value >= 10000) {
  2182. return (value / 10000).toFixed(1) + "W";
  2183. }
  2184. return value.toFixed(0);
  2185. },
  2186. },
  2187. axisLine: { show: true, lineStyle: { color: "black" } },
  2188. axisTick: { show: false },
  2189. splitLine: { show: true, lineStyle: { type: "dashed" } },
  2190. boundaryGap: ["20%", "20%"],
  2191. },
  2192. {
  2193. type: "value",
  2194. gridIndex: 2,
  2195. min: 0,
  2196. max: 100,
  2197. axisLabel: {
  2198. show: true,
  2199. fontSize: window.innerWidth > 768 ? 15 : 10,
  2200. formatter: function (value) {
  2201. var customValues = [0, 20, 50, 80, 100];
  2202. return customValues.indexOf(value) > -1 ? value : "";
  2203. },
  2204. },
  2205. axisLine: {
  2206. show: true,
  2207. lineStyle: {
  2208. color: "black",
  2209. },
  2210. },
  2211. axisTick: {
  2212. show: false,
  2213. },
  2214. splitNumber: 10,
  2215. splitLine: {
  2216. show: true,
  2217. lineStyle: {
  2218. type: "dashed",
  2219. color: "#fff",
  2220. width: 1,
  2221. },
  2222. interval: function (index, value) {
  2223. return [20, 50, 80, 100].indexOf(value) > -1;
  2224. },
  2225. },
  2226. },
  2227. ],
  2228. dataZoom: [
  2229. {
  2230. type: "inside",
  2231. xAxisIndex: [0, 1, 2],
  2232. start: 55,
  2233. end: 100,
  2234. },
  2235. {
  2236. show: true,
  2237. xAxisIndex: [0, 1, 2],
  2238. type: "slider",
  2239. top: window.innerWidth > 768 ? "95%" : "96%",
  2240. // left: window.innerWidth > 768 ? "10%" : "8%",
  2241. // right: window.innerWidth > 768 ? "4%" : "8%",
  2242. start: 98,
  2243. end: 100,
  2244. },
  2245. ],
  2246. visualMap: [
  2247. {
  2248. type: "piecewise",
  2249. show: false,
  2250. pieces: maData.singleTypeGreen,
  2251. outOfRange: {
  2252. color: "green",
  2253. },
  2254. dimension: 0,
  2255. seriesIndex: 7,
  2256. },
  2257. {
  2258. type: "piecewise",
  2259. show: false,
  2260. pieces: maData.singleTypeRed,
  2261. outOfRange: {
  2262. color: "red",
  2263. },
  2264. dimension: 0,
  2265. seriesIndex: 8,
  2266. },
  2267. {
  2268. type: "piecewise",
  2269. show: false,
  2270. pieces: maData.singleTypeYellow,
  2271. outOfRange: {
  2272. color: "yellow",
  2273. },
  2274. dimension: 0,
  2275. seriesIndex: 9,
  2276. },
  2277. ],
  2278. series: [
  2279. {
  2280. name: "进攻K线",
  2281. type: "candlestick",
  2282. barWidth: "50%",
  2283. data: dealData1.values,
  2284. xAxisIndex: 0,
  2285. yAxisIndex: 0,
  2286. itemStyle: {
  2287. normal: {
  2288. color: "rgb(255,0,0)",
  2289. color0: "rgb(255,0,0)",
  2290. borderColor: "rgb(255,0,0)",
  2291. borderColor0: "rgb(255,0,0)",
  2292. },
  2293. },
  2294. gridIndex: 0,
  2295. },
  2296. //
  2297. {
  2298. name: "推进K线",
  2299. type: "candlestick",
  2300. barWidth: "50%",
  2301. data: dealData2.values,
  2302. xAxisIndex: 0,
  2303. yAxisIndex: 0,
  2304. itemStyle: {
  2305. normal: {
  2306. color: "rgb(0,0,252)",
  2307. color0: "rgb(0,0,252)",
  2308. borderColor: "rgb(0,0,252)",
  2309. borderColor0: "rgb(0,0,252)",
  2310. },
  2311. },
  2312. gridIndex: 0,
  2313. },
  2314. {
  2315. name: "防守K线",
  2316. type: "candlestick",
  2317. barWidth: "50%",
  2318. data: dealData3.values,
  2319. xAxisIndex: 0,
  2320. yAxisIndex: 0,
  2321. itemStyle: {
  2322. normal: {
  2323. color: "orange",
  2324. color0: "orange",
  2325. borderColor: "orange",
  2326. borderColor0: "orange",
  2327. },
  2328. },
  2329. gridIndex: 0,
  2330. },
  2331. {
  2332. name: "撤退K线",
  2333. type: "candlestick",
  2334. barWidth: "50%",
  2335. data: dealData4.values,
  2336. xAxisIndex: 0,
  2337. yAxisIndex: 0,
  2338. itemStyle: {
  2339. normal: {
  2340. color: "rgb(84,252,252)",
  2341. color0: "rgb(84,252,252)",
  2342. borderColor: "rgb(84,252,252)",
  2343. borderColor0: "rgb(84,252,252)",
  2344. },
  2345. },
  2346. gridIndex: 0,
  2347. },
  2348. {
  2349. name: "成交量",
  2350. type: "bar",
  2351. barWidth: "70%",
  2352. xAxisIndex: 1,
  2353. yAxisIndex: 1,
  2354. data: barData,
  2355. markPoint: {
  2356. data: markPointData,
  2357. label: {
  2358. show: false,
  2359. },
  2360. },
  2361. },
  2362. {
  2363. name: "{green|━}{red|━} " + "牵牛绳",
  2364. type: "line",
  2365. data: [],
  2366. smooth: true,
  2367. symbol: "none",
  2368. xAxisIndex: 0,
  2369. yAxisIndex: 0,
  2370. showSymbol: false,
  2371. lineStyle: {
  2372. opacity: 0,
  2373. },
  2374. itemStyle: {
  2375. normal: {
  2376. color: "green",
  2377. },
  2378. },
  2379. gridIndex: 0,
  2380. },
  2381. {
  2382. name: "{green|━}{red|━} " + "度牛尺",
  2383. type: "line",
  2384. data: [],
  2385. smooth: true,
  2386. symbol: "none",
  2387. xAxisIndex: 0,
  2388. yAxisIndex: 0,
  2389. showSymbol: false,
  2390. lineStyle: {
  2391. opacity: 0,
  2392. },
  2393. itemStyle: {
  2394. normal: {
  2395. color: "green",
  2396. },
  2397. },
  2398. gridIndex: 0,
  2399. },
  2400. {
  2401. name: "虫线",
  2402. type: "line",
  2403. data: maData.greenData,
  2404. smooth: true,
  2405. symbol: "none",
  2406. xAxisIndex: 0,
  2407. yAxisIndex: 0,
  2408. itemStyle: {
  2409. normal: {
  2410. color: "green",
  2411. lineStyle: {
  2412. width: 2,
  2413. type: "solid",
  2414. },
  2415. },
  2416. },
  2417. gridIndex: 0,
  2418. },
  2419. {
  2420. name: "龙线",
  2421. type: "line",
  2422. data: maData.redData,
  2423. smooth: true,
  2424. symbol: "none",
  2425. xAxisIndex: 0,
  2426. yAxisIndex: 0,
  2427. itemStyle: {
  2428. normal: {
  2429. color: "red",
  2430. lineStyle: {
  2431. width: 2,
  2432. type: "solid",
  2433. },
  2434. },
  2435. },
  2436. gridIndex: 0,
  2437. },
  2438. {
  2439. name: "黄色",
  2440. type: "line",
  2441. data: maData.yellowData,
  2442. smooth: true,
  2443. symbol: "none",
  2444. xAxisIndex: 0,
  2445. yAxisIndex: 0,
  2446. itemStyle: {
  2447. normal: {
  2448. color: "yellow",
  2449. lineStyle: {
  2450. width: 2,
  2451. type: "solid",
  2452. },
  2453. },
  2454. },
  2455. gridIndex: 0,
  2456. },
  2457. {
  2458. name: "背景区域",
  2459. type: "line",
  2460. data: [],
  2461. xAxisIndex: 2,
  2462. yAxisIndex: 2,
  2463. markArea: {
  2464. silent: true,
  2465. itemStyle: {
  2466. normal: {
  2467. opacity: 1,
  2468. },
  2469. },
  2470. label: {
  2471. normal: {
  2472. show: true,
  2473. position: "insideRight",
  2474. fontSize: window.innerWidth > 768 ? 16 : 12,
  2475. fontWeight: "bold",
  2476. color: "#13E113",
  2477. distance: 10,
  2478. },
  2479. },
  2480. data: [
  2481. [
  2482. {
  2483. yAxis: 0,
  2484. itemStyle: {
  2485. normal: {
  2486. color: "#CFFFCF",
  2487. },
  2488. },
  2489. label: {
  2490. normal: {
  2491. formatter: "度牛区",
  2492. },
  2493. },
  2494. },
  2495. {
  2496. yAxis: 20,
  2497. },
  2498. ],
  2499. [
  2500. {
  2501. yAxis: 20,
  2502. itemStyle: {
  2503. normal: {
  2504. color: "#A6FFFF",
  2505. },
  2506. },
  2507. },
  2508. {
  2509. yAxis: 40,
  2510. },
  2511. ],
  2512. [
  2513. {
  2514. yAxis: 40,
  2515. itemStyle: {
  2516. normal: {
  2517. color: "#FFF686",
  2518. },
  2519. },
  2520. },
  2521. {
  2522. yAxis: 60,
  2523. },
  2524. ],
  2525. [
  2526. {
  2527. yAxis: 60,
  2528. itemStyle: {
  2529. normal: { color: "#FFD2B3" },
  2530. },
  2531. },
  2532. {
  2533. yAxis: 80,
  2534. },
  2535. ],
  2536. [
  2537. {
  2538. yAxis: 80,
  2539. itemStyle: {
  2540. normal: { color: "#FFB8B8" },
  2541. },
  2542. label: {
  2543. normal: {
  2544. formatter: "度牛区",
  2545. color: "#FF0000",
  2546. position: "insideLeft",
  2547. distance: 10,
  2548. },
  2549. },
  2550. },
  2551. {
  2552. yAxis: 100,
  2553. },
  2554. ],
  2555. ],
  2556. },
  2557. },
  2558. {
  2559. name: "度牛尺",
  2560. type: "line",
  2561. data: maDuchiData.greenData,
  2562. symbol: "none",
  2563. xAxisIndex: 2,
  2564. yAxisIndex: 2,
  2565. itemStyle: {
  2566. normal: {
  2567. color: "green",
  2568. lineStyle: {
  2569. width: 2,
  2570. type: "solid",
  2571. },
  2572. },
  2573. },
  2574. gridIndex: 2,
  2575. markPoint: {
  2576. symbol: "rect",
  2577. symbolSize: (value, params) => {
  2578. const width = window.innerWidth;
  2579. const baseHeight = 22;
  2580. // if (width <= 375) {
  2581. // return [2, 16];
  2582. // } else if (width <= 768) {
  2583. // return [2, 22];
  2584. // }
  2585. return [2, baseHeight];
  2586. },
  2587. itemStyle: {
  2588. normal: {
  2589. label: {
  2590. show: false,
  2591. },
  2592. },
  2593. },
  2594. data: [
  2595. ...maDuchiData.greenData
  2596. .map((item) => {
  2597. if (item[1] === 0) {
  2598. return {
  2599. coord: [item[0], 20],
  2600. symbolOffset: [0, 10],
  2601. itemStyle: {
  2602. color: "#00ff00",
  2603. },
  2604. };
  2605. }
  2606. })
  2607. .filter(Boolean),
  2608. ],
  2609. },
  2610. },
  2611. {
  2612. type: "line",
  2613. data: maDuchiData.redData,
  2614. // smooth: true,
  2615. symbol: "none",
  2616. xAxisIndex: 2,
  2617. yAxisIndex: 2,
  2618. itemStyle: {
  2619. normal: {
  2620. color: "red",
  2621. lineStyle: {
  2622. width: 2,
  2623. type: "solid",
  2624. },
  2625. },
  2626. },
  2627. gridIndex: 2,
  2628. markPoint: {
  2629. symbol: "rect",
  2630. symbolSize: (value, params) => {
  2631. const width = window.innerWidth;
  2632. const baseHeight = 22;
  2633. // if (width <= 375) {
  2634. // return [2, 16];
  2635. // } else if (width <= 768) {
  2636. // return [2, 24];
  2637. // }
  2638. return [2, baseHeight];
  2639. },
  2640. itemStyle: {
  2641. normal: {
  2642. label: {
  2643. show: false,
  2644. },
  2645. },
  2646. },
  2647. data: [
  2648. ...maDuchiData.redData
  2649. .map((item) => {
  2650. if (item[1] === 100) {
  2651. return {
  2652. coord: [item[0], 80],
  2653. symbolOffset:
  2654. [0, -10],
  2655. itemStyle: {
  2656. color: "#ff0000",
  2657. },
  2658. };
  2659. }
  2660. })
  2661. .filter(Boolean),
  2662. ],
  2663. },
  2664. },
  2665. {
  2666. name: "辅助线",
  2667. type: "line",
  2668. data: [],
  2669. xAxisIndex: 2,
  2670. yAxisIndex: 2,
  2671. markLine: {
  2672. silent: true,
  2673. symbol: "none",
  2674. lineStyle: {
  2675. color: "#000000",
  2676. width: 3,
  2677. type: "solid",
  2678. },
  2679. data: [{ yAxis: 20 }],
  2680. },
  2681. },
  2682. {
  2683. name: "辅助线",
  2684. type: "line",
  2685. data: [],
  2686. xAxisIndex: 2,
  2687. yAxisIndex: 2,
  2688. markLine: {
  2689. silent: true,
  2690. symbol: "none",
  2691. lineStyle: {
  2692. color: "#000000",
  2693. width: 3,
  2694. type: "solid",
  2695. },
  2696. data: [{ yAxis: 50 }],
  2697. },
  2698. },
  2699. {
  2700. name: "辅助线",
  2701. type: "line",
  2702. data: [],
  2703. xAxisIndex: 2,
  2704. yAxisIndex: 2,
  2705. markLine: {
  2706. silent: true,
  2707. symbol: "none",
  2708. lineStyle: {
  2709. color: "#000000",
  2710. width: 3,
  2711. type: "solid",
  2712. },
  2713. data: [{ yAxis: 80 }],
  2714. },
  2715. },
  2716. {
  2717. name: "辅助线",
  2718. type: "line",
  2719. data: [],
  2720. xAxisIndex: 2,
  2721. yAxisIndex: 2,
  2722. markLine: {
  2723. silent: true,
  2724. symbol: "none",
  2725. lineStyle: {
  2726. color: "#000000",
  2727. width: 3,
  2728. type: "solid",
  2729. },
  2730. data: [{ yAxis: 100 }],
  2731. },
  2732. },
  2733. ],
  2734. };
  2735. }
  2736. console.log("KLine渲染: 图表配置完成");
  2737. try {
  2738. // 应用配置
  2739. console.log("KLine渲染: 开始设置图表选项");
  2740. chartInstancesMap[containerId].setOption(KlineOption);
  2741. console.log("KLine渲染: 图表选项设置成功");
  2742. // 窗口大小变化时重新渲染图表
  2743. const resizeFunc = _.throttle(
  2744. function () {
  2745. console.log("窗口大小改变,调整图表大小");
  2746. if (
  2747. chartInstancesMap[containerId] &&
  2748. !chartInstancesMap[containerId].isDisposed()
  2749. ) {
  2750. // 如果设备类型发生变化,重新渲染
  2751. const newIsMobile = window.innerWidth < 768;
  2752. const newIsTablet =
  2753. window.innerWidth >= 768 && window.innerWidth < 1024;
  2754. if (newIsMobile !== isMobile || newIsTablet !== isTablet) {
  2755. console.log("设备类型变化,重新渲染图表");
  2756. KlineCanvsEcharts(containerId);
  2757. return;
  2758. }
  2759. chartInstancesMap[containerId].resize();
  2760. }
  2761. },
  2762. 1000,
  2763. { trailing: false }
  2764. );
  2765. // 给resize事件绑定一个特定的函数名,便于后续移除
  2766. window[`resize_${containerId}`] = resizeFunc;
  2767. // 绑定resize事件
  2768. window.removeEventListener("resize", window[`resize_${containerId}`]);
  2769. window.addEventListener("resize", window[`resize_${containerId}`]);
  2770. console.log("KLine渲染: 图表渲染完成");
  2771. } catch (error) {
  2772. console.error("KLine渲染: 图表渲染出错", error);
  2773. }
  2774. }
  2775. watch(
  2776. () => audioStore.isVoiceEnabled,
  2777. (newVal) => {
  2778. // 添加状态锁定逻辑
  2779. if (newVal === audioStore.lastVoiceState) return;
  2780. audioStore.lastVoiceState = newVal;
  2781. if (newVal) {
  2782. console.log("开启语音播放");
  2783. // 添加重试机制
  2784. const tryPlay = () => {
  2785. if (!audioStore.ttsUrl) return; // 新增空值判断
  2786. if (audioStore.soundInstance?.playing()) return;
  2787. playAudio(audioStore.ttsUrl);
  2788. setTimeout(() => {
  2789. if (!audioStore.soundInstance?.playing()) {
  2790. Howler.unload();
  2791. }
  2792. }, 1000);
  2793. };
  2794. tryPlay();
  2795. } else {
  2796. console.log("关闭语音播放");
  2797. pauseAudio();
  2798. // 强制停止并释放资源
  2799. // Howler.stop();
  2800. // Howler.unload();
  2801. // if (audioStore.soundInstance) {
  2802. // audioStore.soundInstance.off(); // 移除所有事件监听
  2803. // audioStore.soundInstance = null;
  2804. // }
  2805. }
  2806. },
  2807. { immediate: true }
  2808. );
  2809. watch(
  2810. () => dataStore.activeTabIndex,
  2811. (newVal) => {
  2812. setTimeout(() => {
  2813. console.log("activeTabIndex变化:", newVal);
  2814. // 当标签页切换回来时,重新渲染所有图表
  2815. if (newVal === 0) {
  2816. console.log("切换到AI聊天页,重新渲染图表");
  2817. // 延迟执行以确保DOM已渲染
  2818. renderAllKlineCharts();
  2819. }
  2820. }, 1000);
  2821. },
  2822. { immediate: true } // 添加immediate属性,确保初始化时执行一次
  2823. );
  2824. // 添加渲染所有K线图的方法
  2825. function renderAllKlineCharts() {
  2826. console.log("重新渲染所有K线图");
  2827. // 查找所有K线消息
  2828. const messages = chatStore.messages;
  2829. for (let i = 0; i < messages.length; i++) {
  2830. if (messages[i].kline && messages[i].chartData) {
  2831. const containerId = `kline-container-${i}`;
  2832. console.log(`尝试渲染K线图: ${containerId}`);
  2833. // 确保DOM已经渲染
  2834. const container = document.getElementById(containerId);
  2835. if (container) {
  2836. // 渲染图表
  2837. KlineCanvsEcharts(containerId);
  2838. } else {
  2839. console.warn(`找不到容器: ${containerId}`);
  2840. }
  2841. }
  2842. }
  2843. }
  2844. // 初始化随机GIF
  2845. onMounted(() => {
  2846. // 初始化marked组件
  2847. marked.setOptions({
  2848. breaks: true, // 支持换行符转换为 <br>
  2849. gfm: true, // 启用 GitHub Flavored Markdown
  2850. sanitize: false, // 不清理 HTML(谨慎使用)
  2851. smartLists: true, // 智能列表
  2852. smartypants: true, // 智能标点符号
  2853. xhtml: false, // 不使用 XHTML 输出
  2854. renderer: renderer,
  2855. });
  2856. renderAllKlineCharts();
  2857. console.log("组件挂载完成");
  2858. // 添加页面可见性变化监听器
  2859. document.addEventListener("visibilitychange", handleVisibilityChange);
  2860. // 添加DOM变化监听器
  2861. const observer = new MutationObserver((mutations) => {
  2862. mutations.forEach((mutation) => {
  2863. if (mutation.type === "childList" && mutation.addedNodes.length) {
  2864. // 检查是否添加了图表容器
  2865. const containers = document.querySelectorAll(
  2866. '[id^="kline-container-"]'
  2867. );
  2868. if (containers.length) {
  2869. // console.log("DOM变化监听到K线容器:", Array.from(containers).map(el => el.id));
  2870. }
  2871. }
  2872. });
  2873. });
  2874. // 开始监听DOM变化
  2875. observer.observe(document.body, { childList: true, subtree: true });
  2876. });
  2877. // 页面可见性变化处理
  2878. let wasPlayingBeforeHidden = false;
  2879. const handleVisibilityChange = () => {
  2880. if (document.hidden) {
  2881. // 页面被隐藏时,如果音频正在播放,则暂停并记录状态
  2882. if (audioStore.isPlaying) {
  2883. wasPlayingBeforeHidden = true;
  2884. audioStore.pause();
  2885. console.log("页面切换离开,音频已暂停");
  2886. } else {
  2887. wasPlayingBeforeHidden = false;
  2888. }
  2889. } else {
  2890. // 页面重新可见时,如果之前在播放,则恢复播放
  2891. if (wasPlayingBeforeHidden && !audioStore.isPlaying) {
  2892. audioStore.play();
  2893. console.log("页面切换回来,音频已恢复播放");
  2894. wasPlayingBeforeHidden = false;
  2895. }
  2896. }
  2897. };
  2898. // 组件卸载时清理所有图表实例和事件监听器
  2899. onUnmounted(() => {
  2900. // 移除页面可见性变化监听器
  2901. document.removeEventListener("visibilitychange", handleVisibilityChange);
  2902. // 停止音频播放
  2903. if (audioStore.isPlaying) {
  2904. audioStore.stop();
  2905. console.log("组件卸载,音频已停止");
  2906. }
  2907. // 清理所有图表实例
  2908. Object.keys(chartInstancesMap).forEach((key) => {
  2909. if (chartInstancesMap[key]) {
  2910. // 移除resize事件监听
  2911. if (window[`resize_${key}`]) {
  2912. window.removeEventListener("resize", window[`resize_${key}`]);
  2913. delete window[`resize_${key}`];
  2914. }
  2915. // 销毁图表实例
  2916. chartInstancesMap[key].dispose();
  2917. delete chartInstancesMap[key];
  2918. }
  2919. });
  2920. });
  2921. </script>
  2922. <template>
  2923. <div class="chat-container">
  2924. <!-- GIF区域 -->
  2925. <div class="gif-area">
  2926. <img :src="bgc" alt="夺宝奇兵大模型logo" class="bgc" />
  2927. <img :src="logo1" alt="夺宝奇兵大模型logo" class="logo1" />
  2928. <img :src="logo2" alt="夺宝奇兵大模型logo" class="logo2" />
  2929. </div>
  2930. <div
  2931. v-for="(msg, index) in chatMsg"
  2932. :key="index"
  2933. :class="{
  2934. 'message-bubble': true,
  2935. [msg.sender]: msg.sender,
  2936. [msg.class]: msg.class,
  2937. }"
  2938. >
  2939. <div v-if="msg.type === 'kline'" class="kline-container">
  2940. <div :id="'kline-container-' + index" class="chart-mount-point">
  2941. <div v-if="!msg.hasValidData" class="no-data-message">
  2942. <p>暂无K线数据</p>
  2943. </div>
  2944. </div>
  2945. </div>
  2946. <div v-else-if="msg.type == 'ing'">
  2947. <div v-if="msg.flag">
  2948. <span>{{ msg.content }}</span>
  2949. <span class="loading-dots">
  2950. <span class="dot">.</span>
  2951. <span class="dot">.</span>
  2952. <span class="dot">.</span>
  2953. <span class="dot">.</span>
  2954. <span class="dot">.</span>
  2955. <span class="dot">.</span>
  2956. </span>
  2957. </div>
  2958. <div v-else v-html="msg.content"></div>
  2959. </div>
  2960. <div v-else-if="msg.type == 'title1'" style="display: flex; width: 100%">
  2961. <div class="mainTitle">
  2962. {{ msg.content }}
  2963. </div>
  2964. <div class="date">
  2965. {{ msg.date }}
  2966. </div>
  2967. </div>
  2968. <div v-else-if="msg.type == 'title2'" class="title2">
  2969. <img class="title1Img" :src="title1" alt="出错了" />
  2970. </div>
  2971. <div v-else-if="msg.type == 'title3'" class="title3">
  2972. <img class="title2Img" :src="msg.content" alt="出错了" />
  2973. </div>
  2974. <div v-else-if="msg.type == 'content1'" class="content1">
  2975. <div v-if="msg.kline" class="kline-container content1chart">
  2976. <div :id="'kline-container-' + index" class="chart-mount-point">
  2977. <div v-if="!msg.hasValidData" class="no-data-message">
  2978. <p>暂无数据</p>
  2979. </div>
  2980. </div>
  2981. </div>
  2982. <div v-else class="content1Text">
  2983. <div v-html="msg.content" class="text1"></div>
  2984. </div>
  2985. </div>
  2986. <div v-else-if="msg.type == 'content2'" class="content2">
  2987. <div class="kline-container content2chart">
  2988. <div :id="'kline-container-' + index" class="chart-mount-point">
  2989. <div v-if="!msg.hasValidData" class="no-data-message">
  2990. <p>暂无数据</p>
  2991. </div>
  2992. </div>
  2993. </div>
  2994. </div>
  2995. <div v-else-if="msg.type == 'content3'" class="content3">
  2996. <div class="content3Text">
  2997. <div v-html="msg.content" class="text3"></div>
  2998. </div>
  2999. </div>
  3000. <div v-else-if="msg.type == 'mianze'" class="mianze">
  3001. <div v-html="msg.content"></div>
  3002. </div>
  3003. <div v-else v-html="msg.content"></div>
  3004. </div>
  3005. </div>
  3006. </template>
  3007. <style scoped>
  3008. .bgc {
  3009. position: absolute;
  3010. z-index: -1;
  3011. max-width: 530px;
  3012. min-width: 340px;
  3013. width: 40%;
  3014. height: auto;
  3015. /* right: 30px; */
  3016. /* top: -30px; */
  3017. }
  3018. .logo1 {
  3019. max-width: 350px;
  3020. min-width: 200px;
  3021. width: 25%;
  3022. }
  3023. .logo2 {
  3024. margin-top: 20px;
  3025. max-width: 350px;
  3026. min-width: 200px;
  3027. width: 30%;
  3028. /* position: relative; */
  3029. }
  3030. .chat-container {
  3031. display: flex;
  3032. flex-direction: column;
  3033. overflow: hidden;
  3034. }
  3035. .gif-area {
  3036. padding: 70px 0px;
  3037. position: relative;
  3038. /* height: 30vh; */
  3039. display: flex;
  3040. flex-direction: column;
  3041. justify-content: center;
  3042. align-items: center;
  3043. flex-shrink: 0;
  3044. /* 防止GIF区域被压缩 */
  3045. }
  3046. .gif-area img {
  3047. /* width: 30%; */
  3048. /* 改为百分比单位 */
  3049. /* min-width: 200px; */
  3050. /* 最小尺寸 */
  3051. /* max-width: 400px; */
  3052. /* 最大尺寸 */
  3053. /* height: auto; */
  3054. /* left: 50%; */
  3055. /* transition: all 0.3s; */
  3056. /* 添加过渡效果 */
  3057. }
  3058. .message-area {
  3059. margin-top: 2%;
  3060. flex: 1;
  3061. /* 消息区域占据剩余空间 */
  3062. overflow-y: auto;
  3063. padding: 20px;
  3064. display: flex;
  3065. flex-direction: column;
  3066. gap: 15px;
  3067. }
  3068. .marquee-container {
  3069. /* position: absolute; */
  3070. bottom: 0;
  3071. width: 100%;
  3072. /* ga */
  3073. }
  3074. .marquee-row {
  3075. white-space: nowrap;
  3076. overflow: visible;
  3077. padding: 8px 0;
  3078. width: 100%;
  3079. }
  3080. .marquee-item {
  3081. display: inline-block;
  3082. margin: 0 15px;
  3083. padding: 8px 20px;
  3084. background: rgba(255, 255, 255, 0.9);
  3085. /* 白色背景 */
  3086. border-radius: 10px;
  3087. /* 圆角矩形 */
  3088. color: #333;
  3089. /* 文字颜色改为深色 */
  3090. box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  3091. /* 添加阴影 */
  3092. transition: all 0.3s;
  3093. transition: color 0.3s;
  3094. }
  3095. .top {
  3096. animation: marquee 25s linear infinite;
  3097. /* 默认动画是运行状态 */
  3098. animation-play-state: running;
  3099. }
  3100. .bottom {
  3101. animation: marquee 15s linear infinite reverse;
  3102. /* 默认动画是运行状态 */
  3103. animation-play-state: running;
  3104. }
  3105. /* 添加PC端专用速度 */
  3106. @media (min-width: 768px) {
  3107. .top {
  3108. animation-duration: 35s;
  3109. /* PC端改为35秒 */
  3110. }
  3111. .bottom {
  3112. animation-duration: 35s;
  3113. /* PC端改为35秒 */
  3114. }
  3115. }
  3116. @keyframes marquee {
  3117. 0% {
  3118. transform: translateX(100%);
  3119. }
  3120. 100% {
  3121. transform: translateX(-250%);
  3122. }
  3123. }
  3124. .loading-dots {
  3125. display: inline-block;
  3126. }
  3127. .dot {
  3128. opacity: 0.4;
  3129. animation: loading 1.4s infinite;
  3130. }
  3131. .dot:nth-child(1) {
  3132. animation-delay: 0s;
  3133. }
  3134. .dot:nth-child(2) {
  3135. animation-delay: 0.2s;
  3136. }
  3137. .dot:nth-child(3) {
  3138. animation-delay: 0.4s;
  3139. }
  3140. .dot:nth-child(4) {
  3141. animation-delay: 0.6s;
  3142. }
  3143. .dot:nth-child(5) {
  3144. animation-delay: 0.8s;
  3145. }
  3146. .dot:nth-child(6) {
  3147. animation-delay: 1s;
  3148. }
  3149. @keyframes loading {
  3150. 0%,
  3151. 60%,
  3152. 100% {
  3153. opacity: 0.4;
  3154. }
  3155. 30% {
  3156. opacity: 1;
  3157. }
  3158. }
  3159. .message-bubble {
  3160. max-width: 80%;
  3161. margin: 10px 0px;
  3162. padding: 15px 20px;
  3163. position: relative;
  3164. }
  3165. .message-bubble.user {
  3166. color: #6d22f8;
  3167. background: white;
  3168. font-weight: bold;
  3169. margin-left: auto;
  3170. border-radius: 10px;
  3171. margin-right: 20px;
  3172. /* border-bottom-right-radius: 5px; */
  3173. }
  3174. .message-bubble.ai {
  3175. background: #2b378d;
  3176. color: #ffffff;
  3177. margin: 0 auto;
  3178. /* border-bottom-left-radius: 5px; */
  3179. }
  3180. .message-bubble.ing {
  3181. background: #ffffff;
  3182. color: #000000;
  3183. font-weight: bold;
  3184. border-radius: 10px;
  3185. margin-left: 20px;
  3186. margin-right: auto;
  3187. /* border-bottom-left-radius: 5px; */
  3188. }
  3189. .message-bubble.ai.title1 {
  3190. width: 100%;
  3191. display: flex;
  3192. border-radius: 10px 10px 0px 0px;
  3193. /* border-bottom-left-radius: 5px; */
  3194. }
  3195. .mainTitle {
  3196. font-size: 16px;
  3197. font-weight: bold;
  3198. background-image: url("@/assets/img/AiEmotion/bk01.png");
  3199. background-repeat: no-repeat;
  3200. background-size: 100% 100%;
  3201. min-width: 200px;
  3202. width: 20vw;
  3203. height: 50px;
  3204. padding: 5px 0px 0px 0px;
  3205. display: flex;
  3206. justify-content: center;
  3207. align-items: center;
  3208. }
  3209. .date {
  3210. font-size: 18px;
  3211. font-weight: bold;
  3212. margin-left: auto;
  3213. /* width: 100px; */
  3214. display: flex;
  3215. justify-content: center;
  3216. align-items: center;
  3217. }
  3218. .message-bubble.ai.title2 {
  3219. width: 100%;
  3220. display: flex;
  3221. justify-content: center;
  3222. align-items: center;
  3223. }
  3224. .title1Img {
  3225. max-width: 500px;
  3226. width: 80vw;
  3227. }
  3228. .message-bubble.ai.title3 {
  3229. width: 100%;
  3230. display: flex;
  3231. justify-content: center;
  3232. align-items: center;
  3233. }
  3234. .title2Img {
  3235. max-width: 500px;
  3236. width: 90vw;
  3237. }
  3238. .message-bubble.ai.content1 {
  3239. width: 100%;
  3240. display: flex;
  3241. justify-content: center;
  3242. align-items: center;
  3243. }
  3244. .content1chart {
  3245. background-image: url("@/assets/img/AIchat/罗盘边框.png");
  3246. background-repeat: no-repeat;
  3247. background-size: 100% 100%;
  3248. width: 50vw;
  3249. min-width: 350px;
  3250. display: flex;
  3251. justify-content: center;
  3252. align-items: center;
  3253. }
  3254. .content1Text {
  3255. background-image: url("@/assets/img/AIchat/框.png");
  3256. background-repeat: no-repeat;
  3257. background-size: 100% 100%;
  3258. width: 50vw;
  3259. min-width: 350px;
  3260. /* height: 20vw; */
  3261. /* max-height: 400px; */
  3262. padding: 5% 0;
  3263. }
  3264. .text1 {
  3265. font-weight: bold;
  3266. /* margin-left: 6%; */
  3267. /* margin-bottom: 10px; */
  3268. margin: 0px 6% 10px 6%;
  3269. font-size: 30px;
  3270. }
  3271. .message-bubble.ai.content2 {
  3272. width: 100%;
  3273. display: flex;
  3274. justify-content: center;
  3275. align-items: center;
  3276. }
  3277. .content2chart {
  3278. background-image: url("@/assets/img/AIchat/PCbackPic.png");
  3279. background-repeat: no-repeat;
  3280. background-size: 100% 100%;
  3281. width: 50vw;
  3282. min-width: 350px;
  3283. display: flex;
  3284. justify-content: center;
  3285. align-items: center;
  3286. height: calc(500px + 10vw) !important;
  3287. }
  3288. .message-bubble.ai.content3 {
  3289. width: 100%;
  3290. display: flex;
  3291. justify-content: center;
  3292. align-items: center;
  3293. }
  3294. .content3Text {
  3295. background-image: url("@/assets/img/AIchat/边框.png");
  3296. background-repeat: no-repeat;
  3297. background-size: 100% 100%;
  3298. width: 50vw;
  3299. min-width: 350px;
  3300. /* height: 20vw; */
  3301. /* max-height: 400px; */
  3302. padding: 5% 0px;
  3303. }
  3304. .text3 {
  3305. /* font-weight: bold; */
  3306. /* margin-left: 6%; */
  3307. /* margin-bottom: 10px; */
  3308. margin: 0px 6% 10px 6%;
  3309. font-size: 30px;
  3310. }
  3311. .message-bubble.ai.mianze {
  3312. width: 100%;
  3313. text-align: center;
  3314. font-weight: bold;
  3315. font-size: 24px;
  3316. border-radius: 0px 0px 10px 10px;
  3317. }
  3318. .kline-container {
  3319. margin-top: 10px;
  3320. /* 最小高度 */
  3321. min-height: 320px;
  3322. /* 视口高度单位 */
  3323. height: 40vh;
  3324. width: 50vw;
  3325. }
  3326. @media (max-width: 768px) {
  3327. .kline-container {
  3328. min-width: 75vw;
  3329. }
  3330. .content1Text {
  3331. width: 77vw;
  3332. min-width: 0px;
  3333. /* height: 20vw; */
  3334. /* min-height: 150px; */
  3335. }
  3336. .text1 {
  3337. font-size: 20px;
  3338. }
  3339. .content2chart {
  3340. background-image: url("@/assets/img/AIchat/new-app-bgc.png") !important;
  3341. height: 100vw;
  3342. }
  3343. .content3Text {
  3344. width: 77vw;
  3345. min-width: 0px;
  3346. /* height: 20vw; */
  3347. /* min-height: 150px; */
  3348. }
  3349. .text3 {
  3350. font-size: 20px;
  3351. }
  3352. .message-bubble.ai.mianze {
  3353. font-size: 18px;
  3354. }
  3355. }
  3356. .kline-container .chart-mount-point {
  3357. display: flex;
  3358. justify-content: center;
  3359. align-items: center;
  3360. height: 80%;
  3361. width: 90%;
  3362. }
  3363. </style>