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.

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