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.

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