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.

4178 lines
121 KiB

4 weeks ago
4 weeks ago
3 weeks ago
3 weeks ago
4 weeks ago
4 weeks ago
3 weeks ago
3 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
3 weeks ago
3 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
3 weeks ago
3 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
3 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
3 weeks ago
3 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
  1. <script setup>
  2. import { ref, onMounted, watch, nextTick, reactive, onUnmounted } from "vue";
  3. import { ElDialog, ElMessage } from "element-plus";
  4. import MessageItem from "@/components/deepNine/MessageItem.vue";
  5. import ThinkingGif from "@/components/deepNine/ThinkingGif.vue";
  6. import {
  7. dbqbFirstAPI,
  8. dbqbSecondOneAPI,
  9. dbqbSecondTwoAPI,
  10. dbqbSecondThreeAPI,
  11. dbqbSecondFourAPI,
  12. dataListAPI,
  13. } from "../api/AIxiaocaishen";
  14. import {
  15. getNineTurnsAPI,
  16. deepNineFirstAPI,
  17. deepNineSecondOneAPI,
  18. deepNineSecondTwoAPI,
  19. deepNineSecondThreeAPI,
  20. } from "../api/deepNine";
  21. import { useUserStore } from "../store/userPessionCode";
  22. import { useDeepNineStore } from "../store/deepNine";
  23. import { useDeepNineAudioStore } from "../store/deepNineAudio";
  24. import { useDataStore } from "@/store/dataList.js";
  25. import { marked } from "marked"; // 引入marked库
  26. // 导入思考过程GIF
  27. import thinkingGif from "@/assets/img/gif/思考.gif";
  28. import analyzeGif from "@/assets/img/gif/解析.gif";
  29. import generateGif from "@/assets/img/gif/生成.gif";
  30. import katex from "katex"; // 引入 KaTeX 库
  31. import { htmlToText } from "html-to-text";
  32. import { Howl, Howler } from "howler";
  33. import * as echarts from "echarts";
  34. import _, { add } from "lodash";
  35. import moment from "moment";
  36. import title1 from "@/assets/img/AIchat/核心价值评估.png";
  37. import title2 from "@/assets/img/AIchat/主力作战.png";
  38. import title3 from "@/assets/img/AIchat/攻防三维.png";
  39. import title4 from "@/assets/img/AIchat/综合作战.png";
  40. import logo2 from "@/assets/img/AIchat/开启无限财富.png";
  41. import getCountAll from "../assets/img/homePage/get-count-all.png";
  42. import voice from "../assets/img/homePage/tail/voice.png";
  43. import voiceNoActive from "../assets/img/homePage/tail/voice-no-active.png";
  44. import { useChatStore } from "../store/chat";
  45. const homepageChatStore = useChatStore();
  46. const chatStore = useDeepNineStore();
  47. const audioStore = useDeepNineAudioStore();
  48. const dataStore = useDataStore();
  49. // 将这些变量移到全局作用域
  50. const audioQueue = ref([]);
  51. const isPlayingAudio = ref(false);
  52. let currentPlayIndex = 0;
  53. let isCallingPlayNext = false;
  54. // 音频预加载状态
  55. const audioPreloadStatus = {
  56. one: { loaded: false, url: null },
  57. two: { loaded: false, url: null },
  58. three: { loaded: false, url: null },
  59. four: { loaded: false, url: null },
  60. five: { loaded: false, url: null },
  61. };
  62. // 音频队列顺序管理
  63. const audioQueueOrder = {
  64. "API1-第一个": 1, // 第一个接口的第一个音频 (link1)
  65. "API1-第二个": 2, // 第一个接口的第二个音频 (link)
  66. "API2-第一个": 3, // 第二个接口的第一个音频 (link3)
  67. "API2-第二个": 4, // 第二个接口的第二个音频 (link1)
  68. "API3-第一个": 5, // 第三个接口的音频 (link)
  69. };
  70. // 播放下一个音频的函数
  71. const playNextAudio = () => {
  72. if (isCallingPlayNext) {
  73. console.log("playNextAudio已在执行中,跳过重复调用");
  74. return;
  75. }
  76. if (currentPlayIndex >= audioQueue.value.length) {
  77. console.log(
  78. "所有音频播放完成,重置到第一个音频 currentPlayIndex",
  79. currentPlayIndex
  80. );
  81. // 播放完成后重置到第一个音频,但不自动播放
  82. currentPlayIndex = 0;
  83. audioStore.isPlaying = false;
  84. audioStore.isPaused = false;
  85. audioStore.playbackPosition = 0;
  86. // 清除音频实例,确保下次点击从头开始
  87. audioStore.soundInstance = null;
  88. audioStore.nowSound = null;
  89. if (audioQueue.value.length > 0) {
  90. audioStore.setCurrentAudioUrl(audioQueue.value[0]);
  91. }
  92. return;
  93. }
  94. isCallingPlayNext = true;
  95. const audioInfo = audioQueue.value[currentPlayIndex];
  96. if (!audioInfo || !audioInfo.url) {
  97. console.warn(`音频信息无效,跳过索引 ${currentPlayIndex}`);
  98. currentPlayIndex++;
  99. isCallingPlayNext = false;
  100. playNextAudio();
  101. return;
  102. }
  103. console.log(`开始播放 ${audioInfo.name},索引: ${currentPlayIndex}`);
  104. const audio = new Howl({
  105. src: [audioInfo.url],
  106. html5: false,
  107. format: ["mp3", "acc"],
  108. // rate: 2,
  109. retryCount: 0,
  110. onplay: () => {
  111. audioStore.isPlaying = true;
  112. isPlayingAudio.value = true;
  113. isCallingPlayNext = false;
  114. console.log(`${audioInfo.name}音频开始播放111`);
  115. },
  116. onpause: () => {
  117. audioStore.isPlaying = false;
  118. audioStore.isPaused = true;
  119. audioStore.playbackPosition = audio.seek() || 0;
  120. console.log(`${audioInfo.name}音频已暂停`);
  121. },
  122. onresume: () => {
  123. audioStore.isPlaying = true;
  124. audioStore.isPaused = false;
  125. console.log(`${audioInfo.name}音频继续播放`);
  126. },
  127. onend: () => {
  128. console.log(`${audioInfo.name}音频播放完成,准备播放下一个`);
  129. audioStore.isPlaying = false;
  130. audioStore.isPaused = false;
  131. audioStore.playbackPosition = 0;
  132. isPlayingAudio.value = false;
  133. currentPlayIndex++;
  134. console.log(
  135. "currentPlayIndex",
  136. currentPlayIndex,
  137. "audioQueue.value.length",
  138. audioQueue.value.length
  139. );
  140. if (currentPlayIndex < audioQueue.value.length) {
  141. console.log(
  142. `队列中还有音频,500ms后播放下一个 (索引:${currentPlayIndex})`
  143. );
  144. setTimeout(() => {
  145. isCallingPlayNext = false;
  146. playNextAudio();
  147. }, 200);
  148. } else {
  149. console.log("🎉 所有音频播放完成,清除音频实例");
  150. chatStore.messages[chatStore.currentUserIndex].audioStatus = false;
  151. audioStore.nowSound = null;
  152. audioStore.soundInstance = null;
  153. isCallingPlayNext = false;
  154. }
  155. },
  156. onstop: () => {
  157. console.log(`${audioInfo.name}音频被停止`);
  158. audioStore.isPlaying = false;
  159. audioStore.isPaused = false;
  160. audioStore.playbackPosition = 0;
  161. },
  162. onloaderror: (id, err) => {
  163. console.error(`${audioInfo.name}音频播放失败:`, err);
  164. isPlayingAudio.value = false;
  165. isCallingPlayNext = false;
  166. setTimeout(() => {
  167. playNextAudio();
  168. }, 100);
  169. },
  170. });
  171. audioStore.setCurrentAudioUrl(audioInfo.url);
  172. audioStore.nowSound = audio;
  173. audioStore.setAudioInstance(audio);
  174. console.log(`尝试播放${audioInfo.name}音频`);
  175. audio.play();
  176. };
  177. // 添加音频到播放队列(确保顺序)
  178. const addToAudioQueue = (url, name) => {
  179. console.log(`=== 添加音频到队列 ===`);
  180. console.log("URL:", url);
  181. console.log("Name:", name);
  182. console.log("音频启用状态:", audioStore.isVoiceEnabled);
  183. if (url && audioStore.isVoiceEnabled) {
  184. const audioItem = {
  185. url,
  186. name,
  187. order: audioQueueOrder[name] || 999,
  188. };
  189. audioQueue.value.push(audioItem);
  190. // 按顺序排序队列
  191. audioQueue.value.sort((a, b) => a.order - b.order);
  192. console.log(`音频${name}已添加到播放队列,顺序:${audioItem.order}`);
  193. console.log(
  194. "当前队列顺序:",
  195. audioQueue.value.map((item) => `${item.name}(${item.order})`)
  196. );
  197. // 只有在确实没有音频在播放且这是第一个音频时才开始播放
  198. if (
  199. !isPlayingAudio.value &&
  200. !audioStore.isPlaying &&
  201. audioQueue.value.length === 1
  202. ) {
  203. console.log("✅ 条件满足:没有音频在播放且这是第一个音频,立即开始播放", {
  204. isPlayingAudio: isPlayingAudio.value,
  205. audioStoreIsPlaying: audioStore.isPlaying,
  206. queueLength: audioQueue.value.length,
  207. });
  208. playNextAudio();
  209. } else {
  210. console.log("⏳ 等待条件:", {
  211. isPlayingAudio: isPlayingAudio.value,
  212. audioStoreIsPlaying: audioStore.isPlaying,
  213. queueLength: audioQueue.value.length,
  214. reason:
  215. audioQueue.value.length > 1 ? "队列中已有其他音频" : "有音频正在播放",
  216. });
  217. }
  218. } else {
  219. console.log("❌ 跳过添加音频:", {
  220. hasUrl: !!url,
  221. voiceEnabled: audioStore.isVoiceEnabled,
  222. });
  223. }
  224. console.log(`=== 添加音频完成 ===`);
  225. };
  226. // 语音播放控制函数
  227. const toggleVoiceForUser = (index) => {
  228. console.log(
  229. "上一个按钮坐标",
  230. chatStore.currentUserIndex,
  231. "当前按钮坐标",
  232. index
  233. );
  234. if (
  235. !chatStore.messages[index].audioArray[0] ||
  236. !chatStore.messages[index].audioArray[1] ||
  237. !chatStore.messages[index].audioArray[2] ||
  238. !chatStore.messages[index].audioArray[3]
  239. ) {
  240. return;
  241. }
  242. // 先把当前按钮状态修改
  243. chatStore.messages[index].audioStatus =
  244. !chatStore.messages[index].audioStatus;
  245. // 如果当前按钮和之前的按钮不是同一个则再修改之前的按钮的状态
  246. if (chatStore.currentUserIndex != index) {
  247. if (chatStore.currentUserIndex != null) {
  248. if (audioStore.isPlaying) {
  249. audioStore.togglePlayPause();
  250. }
  251. chatStore.messages[chatStore.currentUserIndex].audioStatus = false;
  252. }
  253. // 强制停止所有音频实例(移动端兼容)
  254. if (audioStore.soundInstance) {
  255. audioStore.soundInstance.stop();
  256. audioStore.soundInstance = null;
  257. }
  258. audioPreloadStatus.one = { loaded: false, url: null };
  259. audioPreloadStatus.two = { loaded: false, url: null };
  260. audioPreloadStatus.three = { loaded: false, url: null };
  261. audioPreloadStatus.four = { loaded: false, url: null };
  262. audioPreloadStatus.five = { loaded: false, url: null };
  263. if (chatStore.messages[index].audioArray[0]) {
  264. audioPreloadStatus.one.loaded = true;
  265. audioPreloadStatus.one.url = chatStore.messages[index].audioArray[0];
  266. }
  267. if (chatStore.messages[index].audioArray[1]) {
  268. audioPreloadStatus.two.loaded = true;
  269. audioPreloadStatus.two.url = chatStore.messages[index].audioArray[1];
  270. }
  271. if (chatStore.messages[index].audioArray[2]) {
  272. audioPreloadStatus.three.loaded = true;
  273. audioPreloadStatus.three.url = chatStore.messages[index].audioArray[2];
  274. }
  275. if (chatStore.messages[index].audioArray[3]) {
  276. audioPreloadStatus.four.loaded = true;
  277. audioPreloadStatus.four.url = chatStore.messages[index].audioArray[3];
  278. }
  279. chatStore.currentUserIndex = index;
  280. audioQueue.value = [];
  281. isPlayingAudio.value = false;
  282. audioStore.soundInstance = null;
  283. currentPlayIndex = 0;
  284. isCallingPlayNext = false;
  285. setTimeout(() => {
  286. addToAudioQueue(chatStore.messages[index].audioArray[0], "API1-第一个");
  287. addToAudioQueue(chatStore.messages[index].audioArray[1], "API2-第二个");
  288. addToAudioQueue(chatStore.messages[index].audioArray[2], "API3-第三个");
  289. addToAudioQueue(chatStore.messages[index].audioArray[3], "API4-第四个");
  290. if (!audioStore.isVoiceEnabled) {
  291. audioStore.toggleVoice();
  292. } else {
  293. if (audioStore.currentAudioUrl || audioStore.ttsUrl) {
  294. // audioStore.togglePlayPause();
  295. } else {
  296. audioStore.toggleVoice();
  297. }
  298. }
  299. }, 100); // 100ms延迟足够移动端清理音频实例
  300. } else {
  301. if (!audioStore.isVoiceEnabled) {
  302. console.log("1111");
  303. audioStore.toggleVoice();
  304. } else {
  305. if (currentPlayIndex >= audioQueue.value.length) {
  306. console.log("重新开始播放音频序列");
  307. currentPlayIndex = 0;
  308. isPlayingAudio.value = false;
  309. isCallingPlayNext = false;
  310. audioStore.soundInstance = null;
  311. // 重新开始播放
  312. if (audioQueue.value.length > 0) {
  313. playNextAudio();
  314. }
  315. } else if (audioStore.currentAudioUrl || audioStore.ttsUrl) {
  316. console.log("2222");
  317. audioStore.togglePlayPause();
  318. } else {
  319. console.log("3333");
  320. audioStore.toggleVoice();
  321. }
  322. }
  323. }
  324. };
  325. // 计算属性:判断语音是否启用
  326. const isVoice = computed(() => {
  327. return audioStore.isVoiceEnabled;
  328. });
  329. // 随机GIF
  330. const currentGif = ref("");
  331. const renderer = new marked.Renderer();
  332. // 重写 del 方法,让删除线不生效
  333. renderer.del = function (text) {
  334. // 处理各种数据类型
  335. console.log("text", text);
  336. return "~" + text.tokens[0].raw + "<br>" + text.tokens[2].raw + "~";
  337. };
  338. // 定义自定义事件
  339. const emit = defineEmits([
  340. "updateMessage",
  341. "sendMessage",
  342. "enableInput",
  343. "ensureAIchat",
  344. "scrollToBottom",
  345. "showCount",
  346. ]);
  347. // 音频播放方法
  348. const playAudio = (url) => {
  349. // 添加空值校验
  350. if (!url) {
  351. console.warn("音频URL为空,跳过播放");
  352. audioStore.isPlaying = false;
  353. return;
  354. }
  355. const handlePlay = () => {
  356. if (audioStore.isNewInstance) {
  357. const newSound = new Howl({
  358. src: [url],
  359. html5: true, // 强制HTML5 Audio解决iOS兼容问题
  360. format: ["mp3", "acc"],
  361. rate: 1.2, // 调整播放速度
  362. onplay: () => {
  363. audioStore.isPlaying = true; // 改为更新store状态
  364. newSound.volume(1); // 添加音量设置
  365. },
  366. onend: () => (audioStore.isPlaying = false),
  367. onstop: () => (audioStore.isPlaying = false),
  368. onloaderror: (id, err) => {
  369. console.error("音频加载失败:", err);
  370. ElMessage.error("音频播放失败,请检查网络连接");
  371. },
  372. });
  373. if (audioStore.nowSound) {
  374. audioStore.nowSound.stop();
  375. }
  376. audioStore.nowSound = newSound;
  377. audioStore.isNewInstance = false;
  378. console.log("新音频");
  379. } else {
  380. console.log("已经有音频");
  381. }
  382. const newSound = audioStore.nowSound;
  383. // 添加立即播放逻辑
  384. newSound.play();
  385. audioStore.setAudioInstance(newSound);
  386. Howler._howls.push(newSound); // 强制注册到全局管理
  387. };
  388. handlePlay();
  389. };
  390. // 新增暂停方法
  391. const pauseAudio = () => {
  392. if (audioStore.soundInstance) {
  393. audioStore.soundInstance.pause();
  394. audioStore.isPlaying = false;
  395. }
  396. };
  397. // 音频轮流播放方法
  398. const playAudioSequence = (audioUrls) => {
  399. console.log("playAudioSequence被调用,参数:", audioUrls);
  400. if (!audioUrls || audioUrls.length === 0) {
  401. console.warn("音频URL列表为空,跳过播放");
  402. return;
  403. }
  404. let currentIndex = 0;
  405. let audioSequence = [...audioUrls]; // 保存音频序列
  406. const playNext = () => {
  407. if (currentIndex >= audioSequence.length) {
  408. console.log("所有音频播放完成,重置到第一个音频");
  409. // 播放完成后重置到第一个音频,但不自动播放
  410. currentIndex = 0;
  411. audioStore.isPlaying = false;
  412. audioStore.isPaused = false;
  413. audioStore.playbackPosition = 0;
  414. // 清除音频实例,确保下次点击从头开始
  415. audioStore.soundInstance = null;
  416. audioStore.nowSound = null;
  417. if (audioSequence.length > 0) {
  418. audioStore.setCurrentAudioUrl(audioSequence[0]);
  419. }
  420. return;
  421. }
  422. const currentUrl = audioSequence[currentIndex];
  423. console.log(`正在播放第${currentIndex + 1}个音频:`, currentUrl);
  424. console.log(
  425. "音频URL有效性检查:",
  426. !!currentUrl,
  427. "长度:",
  428. currentUrl?.length
  429. );
  430. // 增强URL验证
  431. if (
  432. !currentUrl ||
  433. typeof currentUrl !== "string" ||
  434. currentUrl.trim() === ""
  435. ) {
  436. console.error(`音频 ${currentIndex + 1} URL无效,跳过该音频`);
  437. currentIndex++;
  438. setTimeout(() => {
  439. playNext();
  440. }, 100);
  441. return;
  442. }
  443. // 检查URL格式
  444. try {
  445. new URL(currentUrl);
  446. } catch (e) {
  447. console.error(`音频 ${currentIndex + 1} URL格式错误:`, currentUrl);
  448. currentIndex++;
  449. setTimeout(() => {
  450. playNext();
  451. }, 100);
  452. return;
  453. }
  454. // 设置当前音频URL
  455. audioStore.setCurrentAudioUrl(currentUrl);
  456. // 停止当前播放的音频
  457. if (audioStore.nowSound) {
  458. audioStore.nowSound.stop();
  459. }
  460. const sound = new Howl({
  461. src: [currentUrl],
  462. html5: true,
  463. format: ["mp3", "acc"],
  464. rate: 1.2,
  465. onplay: () => {
  466. audioStore.isPlaying = true;
  467. audioStore.isPaused = false;
  468. console.log(`开始播放音频 ${currentIndex + 1}`);
  469. console.log("音频播放状态:", {
  470. duration: sound.duration(),
  471. state: sound.state(),
  472. playing: sound.playing(),
  473. });
  474. },
  475. onpause: () => {
  476. audioStore.isPlaying = false;
  477. audioStore.isPaused = true;
  478. audioStore.playbackPosition = sound.seek() || 0;
  479. console.log(`音频 ${currentIndex + 1} 已暂停`);
  480. },
  481. onend: () => {
  482. audioStore.isPlaying = false;
  483. audioStore.isPaused = false;
  484. audioStore.playbackPosition = 0;
  485. console.log(`音频 ${currentIndex + 1} 播放完成`);
  486. currentIndex++;
  487. // 如果是最后一个音频播放完成,立即清除实例
  488. if (currentIndex >= audioSequence.length) {
  489. console.log("最后一个音频播放完成,清除音频实例");
  490. audioStore.soundInstance = null;
  491. audioStore.nowSound = null;
  492. currentIndex = 0; // 立即重置索引
  493. }
  494. // 播放下一个音频
  495. setTimeout(() => {
  496. playNext();
  497. }, 500); // 间隔500ms播放下一个
  498. },
  499. onstop: () => {
  500. audioStore.isPlaying = false;
  501. audioStore.isPaused = false;
  502. audioStore.playbackPosition = 0;
  503. console.log(`音频 ${currentIndex + 1} 已停止`);
  504. },
  505. onloaderror: (id, err) => {
  506. console.error(`音频 ${currentIndex + 1} 加载失败:`, err);
  507. console.error("失败的音频URL:", currentUrl);
  508. console.error("错误详情:", { id, err });
  509. // 增加重试机制
  510. if (!sound.retryCount) {
  511. sound.retryCount = 0;
  512. }
  513. if (sound.retryCount < 2) {
  514. sound.retryCount++;
  515. console.log(
  516. `音频 ${currentIndex + 1}${sound.retryCount}次重试加载`
  517. );
  518. setTimeout(() => {
  519. sound.load();
  520. }, 1000 * sound.retryCount); // 递增延时重试
  521. } else {
  522. console.warn(`音频 ${currentIndex + 1} 重试失败,跳过该音频`);
  523. currentIndex++;
  524. // 跳过失败的音频,播放下一个
  525. setTimeout(() => {
  526. playNext();
  527. }, 100);
  528. }
  529. },
  530. });
  531. audioStore.nowSound = sound;
  532. audioStore.setAudioInstance(sound);
  533. // 添加播放超时检测
  534. const playTimeout = setTimeout(() => {
  535. if (!audioStore.isPlaying && sound.state() === "loading") {
  536. console.warn(`音频 ${currentIndex + 1} 播放超时,可能网络问题`);
  537. sound.stop();
  538. currentIndex++;
  539. playNext();
  540. }
  541. }, 10000); // 10秒超时
  542. // 播放成功后清除超时
  543. sound.once("play", () => {
  544. clearTimeout(playTimeout);
  545. });
  546. console.log(`尝试播放音频 ${currentIndex + 1},URL: ${currentUrl}`);
  547. sound.play();
  548. };
  549. // 重写togglePlayPause方法以支持音频序列控制
  550. audioStore.togglePlayPause = () => {
  551. console.log("音频控制按钮被点击 11111111111");
  552. console.log("当前播放状态:", audioStore.isPlaying);
  553. console.log("当前暂停状态:", audioStore.isPaused);
  554. console.log("当前音频实例:", audioStore.soundInstance);
  555. console.log(
  556. "当前索引:",
  557. currentIndex,
  558. "音频序列长度:",
  559. audioSequence.length
  560. );
  561. if (audioStore.soundInstance) {
  562. if (audioStore.isPlaying) {
  563. // 暂停当前音频
  564. console.log("暂停当前音频");
  565. audioStore.pause();
  566. } else if (audioStore.isPaused) {
  567. // 从暂停位置继续播放
  568. console.log("从暂停位置继续播放");
  569. audioStore.play();
  570. } else {
  571. // 重新开始播放当前音频或从头开始播放序列
  572. console.log("重新开始播放,当前索引:", currentIndex);
  573. if (currentIndex >= audioSequence.length) {
  574. console.log("所有音频已播放完成,从头开始");
  575. currentIndex = 0; // 重置到第一个音频
  576. }
  577. playNext();
  578. }
  579. } else {
  580. // 没有音频实例时,从头开始播放
  581. console.log("没有音频实例,从头开始播放");
  582. currentIndex = 0;
  583. playNext();
  584. }
  585. };
  586. // 开始播放第一个音频
  587. playNext();
  588. };
  589. // 获取消息
  590. const chatMsg = computed(() => chatStore.messages);
  591. const props = defineProps({
  592. messages: Array,
  593. chartData: {
  594. type: Object,
  595. default: null,
  596. },
  597. index: {
  598. type: Number,
  599. required: true,
  600. },
  601. });
  602. // 打字机效果
  603. const typewriterContent = ref("");
  604. const isTyping = ref(false);
  605. const typeWriter = (text, callback) => {
  606. let index = 0;
  607. isTyping.value = true;
  608. typewriterContent.value = "";
  609. const typingInterval = setInterval(() => {
  610. if (index < text.length) {
  611. typewriterContent.value += text.charAt(index);
  612. index++;
  613. // 自动滚动到底部
  614. nextTick(() => {
  615. const container = document.querySelector(".message-area");
  616. if (container) container.scrollTop = container.scrollHeight;
  617. });
  618. } else {
  619. clearInterval(typingInterval);
  620. isTyping.value = false;
  621. if (callback) callback();
  622. }
  623. }, 50); // 调整速度(毫秒)
  624. };
  625. const typingQueue = ref([]);
  626. const isTypingInProgress = ref(false);
  627. // 创建打字机效果的Promise函数
  628. const createTypingEffect = (message, content, speed) => {
  629. return new Promise((resolve) => {
  630. chatStore.messages.push(message);
  631. if (Array.isArray(content) && content.length > 0) {
  632. message.content = "";
  633. message.isTyping = true;
  634. let currentIndex = 0;
  635. const processNextElement = () => {
  636. if (currentIndex >= content.length) {
  637. if (message.isEnd) {
  638. if (message.isEnd == "1") {
  639. apiStatus.one.isEnd = true;
  640. } else if (message.isEnd == "2") {
  641. apiStatus.two.isEnd = true;
  642. } else if (message.isEnd == "3") {
  643. apiStatus.three.isEnd = true;
  644. }
  645. }
  646. if (message.error) {
  647. chatStore.messages.push({
  648. class: "ing",
  649. type: "ing",
  650. flag: false,
  651. content: "系统正在为您努力加载中,请稍后再试",
  652. });
  653. homepageChatStore.isLoading = false;
  654. homepageChatStore.deepNineInput = false;
  655. emit("enableInput");
  656. if (message.error == "2") {
  657. apiStatus.two.isError = true;
  658. } else if (message.error == "3") {
  659. apiStatus.three.isError = true;
  660. }
  661. }
  662. if (message.end) {
  663. homepageChatStore.getUserCount();
  664. homepageChatStore.isLoading = false;
  665. console.log("打印完毕,解除输入框禁用状态");
  666. homepageChatStore.deepNineInput = false;
  667. emit("enableInput");
  668. }
  669. message.isTyping = false;
  670. nextTick(() => {
  671. resolve(); // 完成后resolve
  672. });
  673. return;
  674. }
  675. if (currentIndex % 2 === 0) {
  676. // 偶数下标:直接加入
  677. message.content += content[currentIndex];
  678. currentIndex++;
  679. processNextElement(); // 立即处理下一个元素
  680. } else {
  681. // 奇数下标:打字机效果
  682. const text = content[currentIndex];
  683. let charIndex = 0;
  684. const typingInterval = setInterval(() => {
  685. if (charIndex < text.length) {
  686. message.content += text.charAt(charIndex);
  687. charIndex++;
  688. } else {
  689. clearInterval(typingInterval);
  690. currentIndex++;
  691. processNextElement(); // 处理下一个元素
  692. }
  693. }, speed);
  694. }
  695. };
  696. processNextElement(); // 开始处理
  697. } else {
  698. if (message.kline) {
  699. if (message.klineType == 2) {
  700. console.log("K线消息已添加到聊天列表");
  701. // 在渲染完成后初始化图表
  702. nextTick(() => {
  703. console.log("nextTick开始 - 准备渲染图表");
  704. console.log("消息列表:", chatStore.messages);
  705. // 寻找最新添加的K线消息索引
  706. let klineIndex = -1;
  707. for (let i = 0; i < chatStore.messages.length; i++) {
  708. if (chatStore.messages[i].messageId === message.messageId) {
  709. klineIndex = i;
  710. break;
  711. }
  712. }
  713. console.log("找到的K线消息索引:", klineIndex);
  714. if (klineIndex !== -1) {
  715. const containerId = `kline-container-${klineIndex}`;
  716. console.log("图表容器ID:", containerId);
  717. // 确保DOM已经渲染完成
  718. setTimeout(() => {
  719. console.log("延时执行,确保DOM已渲染");
  720. KlineCanvsEcharts(containerId);
  721. }, 100); // 短暂延时确保DOM已渲染
  722. } else {
  723. console.warn("未找到K线消息");
  724. }
  725. });
  726. }
  727. if (message.isEnd) {
  728. if (message.isEnd == "1") {
  729. apiStatus.one.isEnd = true;
  730. } else if (message.isEnd == "2") {
  731. apiStatus.two.isEnd = true;
  732. } else if (message.isEnd == "3") {
  733. apiStatus.three.isEnd = true;
  734. }
  735. }
  736. if (message.error) {
  737. chatStore.messages.push({
  738. class: "ing",
  739. type: "ing",
  740. flag: false,
  741. content: "系统正在为您努力加载中,请稍后再试",
  742. });
  743. homepageChatStore.isLoading = false;
  744. homepageChatStore.deepNineInput = false;
  745. emit("enableInput");
  746. if (message.error == "2") {
  747. apiStatus.two.isError = true;
  748. } else if (message.error == "3") {
  749. apiStatus.three.isError = true;
  750. }
  751. }
  752. // 延时1秒后resolve
  753. setTimeout(() => {
  754. resolve();
  755. }, 1000);
  756. } else {
  757. if (message.isEnd) {
  758. if (message.isEnd == "1") {
  759. apiStatus.one.isEnd = true;
  760. } else if (message.isEnd == "2") {
  761. apiStatus.two.isEnd = true;
  762. } else if (message.isEnd == "3") {
  763. apiStatus.three.isEnd = true;
  764. }
  765. }
  766. if (message.error) {
  767. chatStore.messages.push({
  768. class: "ing",
  769. type: "ing",
  770. flag: false,
  771. content: "系统正在为您努力加载中,请稍后再试",
  772. });
  773. homepageChatStore.isLoading = false;
  774. homepageChatStore.deepNineInput = false;
  775. emit("enableInput");
  776. if (message.error == "2") {
  777. apiStatus.two.isError = true;
  778. } else if (message.error == "3") {
  779. apiStatus.three.isError = true;
  780. }
  781. }
  782. // 延时1秒后resolve
  783. setTimeout(() => {
  784. resolve();
  785. }, 1000);
  786. }
  787. }
  788. });
  789. };
  790. let apiStatus = {};
  791. // 队列处理函数
  792. const processTypingQueue = async () => {
  793. if (isTypingInProgress.value || typingQueue.value.length === 0) {
  794. return;
  795. }
  796. isTypingInProgress.value = true;
  797. while (typingQueue.value.length > 0) {
  798. const task = typingQueue.value.shift();
  799. if (chatStore.allowTyping) {
  800. await createTypingEffect(task.message, task.content, task.speed);
  801. }
  802. }
  803. isTypingInProgress.value = false;
  804. };
  805. // 添加打字机任务到队列
  806. const addTypingTask = (message, content, speed) => {
  807. typingQueue.value.push({ message, content, speed });
  808. processTypingQueue();
  809. };
  810. // 显示思考过程
  811. async function showThinkingProcess(stockName = null) {
  812. // 第一步:正在思考
  813. const thinkingMessage1 = reactive({
  814. sender: "ai",
  815. class: "ing",
  816. type: "ing",
  817. flag: true,
  818. content: "深度九大模型正在思考",
  819. gif: thinkingGif,
  820. nowrap: true,
  821. });
  822. chatStore.messages.push(thinkingMessage1);
  823. await new Promise((resolve) => setTimeout(resolve, 1500));
  824. chatStore.messages.pop();
  825. // 第二步:正在解析关键数据(持续显示直到获取到股票名称)
  826. const thinkingMessage2 = reactive({
  827. sender: "ai",
  828. class: "ing",
  829. type: "ing",
  830. flag: true,
  831. content: "正在解析关键数据",
  832. gif: analyzeGif,
  833. nowrap: true,
  834. });
  835. chatStore.messages.push(thinkingMessage2);
  836. // 如果没有股票名称,保持第二步显示
  837. if (!stockName) {
  838. return thinkingMessage2; // 返回消息引用,以便后续更新
  839. }
  840. // 有股票名称后,继续后续步骤
  841. await new Promise((resolve) => setTimeout(resolve, 1500));
  842. chatStore.messages.pop();
  843. // 第三步:生成具体股票的深度共振分析图谱
  844. const thinkingMessage3 = reactive({
  845. sender: "ai",
  846. class: "ing",
  847. type: "ing",
  848. flag: true,
  849. content: `正在生成${stockName}深度共振分析图谱`,
  850. gif: generateGif,
  851. nowrap: true,
  852. });
  853. chatStore.messages.push(thinkingMessage3);
  854. await new Promise((resolve) => setTimeout(resolve, 1500));
  855. chatStore.messages.pop();
  856. // 第四步:报告已生成
  857. const thinkingMessage4 = reactive({
  858. sender: "ai",
  859. class: "ing",
  860. type: "ing",
  861. content: "报告已生成!",
  862. nowrap: true,
  863. });
  864. chatStore.messages.push(thinkingMessage4);
  865. await new Promise((resolve) => setTimeout(resolve, 1500));
  866. chatStore.messages.pop();
  867. return null;
  868. }
  869. // 继续思考过程(当获取到股票名称后调用)
  870. async function continueThinkingProcess(thinkingMessageRef, stockName) {
  871. if (!thinkingMessageRef || !stockName) return;
  872. // 等待一段时间后继续
  873. await new Promise((resolve) => setTimeout(resolve, 1500));
  874. // 移除第二步消息
  875. const index = chatStore.messages.indexOf(thinkingMessageRef);
  876. if (index > -1) {
  877. chatStore.messages.splice(index, 1);
  878. }
  879. // 第三步:生成具体股票的深度共振分析图谱
  880. const thinkingMessage3 = reactive({
  881. sender: "ai",
  882. class: "ing",
  883. type: "ing",
  884. flag: true,
  885. content: `正在生成${stockName}深度共振分析图谱`,
  886. gif: generateGif,
  887. });
  888. chatStore.messages.push(thinkingMessage3);
  889. await new Promise((resolve) => setTimeout(resolve, 1500));
  890. chatStore.messages.pop();
  891. // 第四步:报告已生成
  892. const thinkingMessage4 = reactive({
  893. sender: "ai",
  894. class: "ing",
  895. type: "ing",
  896. content: "报告已生成!",
  897. });
  898. chatStore.messages.push(thinkingMessage4);
  899. await new Promise((resolve) => setTimeout(resolve, 1500));
  900. chatStore.messages.pop();
  901. }
  902. const hasValidData = ref(false);
  903. // 创建一个非响应式的对象来存储图表实例
  904. const chartInstancesMap = {};
  905. // 存储上一次的消息的length
  906. const previousMessagesLength = ref(0);
  907. watch(
  908. () => props.messages,
  909. async (newVal, oldVal) => {
  910. // // 添加空值判断
  911. if (!newVal?.length || newVal === previousMessagesLength.value) return;
  912. chatStore.firstAPICall = true;
  913. console.log("第一阶段,意图识别,获取回复,历史记录禁止点击");
  914. previousMessagesLength.value = newVal.length;
  915. if (newVal.length > 0) {
  916. // 清理语音下标
  917. console.log("chatStore.currentUserIndex", chatStore.currentUserIndex);
  918. if (chatStore.currentUserIndex != null) {
  919. chatStore.messages[chatStore.currentUserIndex].audioStatus = false;
  920. }
  921. chatStore.currentUserIndex = null;
  922. audioStore.stop(); // 暂停语音
  923. // 🔧 新增:重置音频队列状态,确保新音频能够自动播放
  924. audioQueue.value = [];
  925. isPlayingAudio.value = false;
  926. currentPlayIndex = 0;
  927. isCallingPlayNext = false;
  928. // 重置音频预加载状态
  929. audioPreloadStatus.one = { loaded: false, url: null };
  930. audioPreloadStatus.two = { loaded: false, url: null };
  931. audioPreloadStatus.three = { loaded: false, url: null };
  932. audioPreloadStatus.four = { loaded: false, url: null };
  933. // 清除音频实例
  934. audioStore.soundInstance = null;
  935. audioStore.nowSound = null;
  936. audioStore.isPlaying = false;
  937. audioStore.isPaused = false;
  938. audioStore.playbackPosition = 0;
  939. console.log("消息列表已更新,最新消息:", newVal[newVal.length - 1]);
  940. chatStore.messages.push(newVal[newVal.length - 1]);
  941. chatStore.currentUserIndex = chatStore.messages.length - 1;
  942. chatStore.inputUserIndex = chatStore.messages.length - 1;
  943. console.log(
  944. "消息列表已更新,最新消息:",
  945. chatStore.messages[chatStore.messages.length - 1],
  946. "最新用户坐标",
  947. chatStore.currentUserIndex
  948. );
  949. // 获取权限
  950. const userStore = useUserStore();
  951. const params1 = {
  952. language: "cn",
  953. marketList: "usa,sg,my,hk,cn,can,vi,th,in",
  954. content: newVal[newVal.length - 1].content,
  955. token: localStorage.getItem("localToken"),
  956. model: 1,
  957. // language: "cn",
  958. // marketList: "hk,cn,usa,my,sg,vi,in,gb"
  959. // token: "+SsksARQgUHIbIG3rRnnbZi0+fEeMx8pywnIlrmTxo5EOPR/wjWDV7w7+ZUseiBtf9kFa/atmNx6QfSpv5w",
  960. };
  961. // 标志
  962. let flag = true;
  963. const codeData = ref();
  964. // 开始思考过程(不带股票名称)
  965. const thinkingMessageRef = await showThinkingProcess();
  966. // 第一阶段,意图识别
  967. try {
  968. chatStore.allowTyping = true;
  969. // 调用工作流获取回复
  970. const result = await deepNineFirstAPI(params1);
  971. codeData.value = result.data;
  972. console.log(codeData.value, "codeData");
  973. // 根据意图识别结果判断
  974. if (result.code == 200) {
  975. // 意图识别成功后,更新历史记录状态
  976. chatStore.searchRecord = true;
  977. // 获取到股票名称后,继续思考过程
  978. if (thinkingMessageRef && codeData.value.name) {
  979. await continueThinkingProcess(
  980. thinkingMessageRef,
  981. codeData.value.name
  982. );
  983. }
  984. // for (let i = chatStore.messages.length - 1; i >= 0; --i) {
  985. // if (chatStore.messages[i].sender == "user") {
  986. // chatStore.messages[i].audioStatus = true;
  987. // break;
  988. // }
  989. // }
  990. chatStore.messages.push({
  991. // class: "ing",
  992. // type: "ing",
  993. // flag: flag,
  994. // content: result.data.kaishi,
  995. });
  996. } else {
  997. // 意图识别失败,先清理思考过程消息
  998. if (thinkingMessageRef) {
  999. const index = chatStore.messages.indexOf(thinkingMessageRef);
  1000. if (index > -1) {
  1001. chatStore.messages.splice(index, 1);
  1002. }
  1003. }
  1004. flag = false;
  1005. console.log("执行回绝话术");
  1006. const AIcontent = ref(result.msg);
  1007. // 修改后的消息处理逻辑
  1008. const processedContent = marked(AIcontent.value);
  1009. const katexRegex = /\$\$(.*?)\$\$/g;
  1010. let aiContent = processedContent.replace(
  1011. katexRegex,
  1012. (match, formula) => {
  1013. try {
  1014. return katex.renderToString(formula, { throwOnError: false });
  1015. } catch (error) {
  1016. console.error("KaTeX 渲染错误:", error);
  1017. return match;
  1018. }
  1019. }
  1020. );
  1021. console.log(AIcontent, "AIcontent");
  1022. if (result.code == 406) {
  1023. AIcontent.value = `<p>尊敬的用户您好,您当前的“深度九大模型专属Token”数量为0,无法进行股票查询,可联系客服团队进行充值,感谢您的理解与支持</p>`;
  1024. }
  1025. const aiMsg = {
  1026. class: "ing",
  1027. type: "ing",
  1028. flag: flag,
  1029. content: AIcontent,
  1030. };
  1031. chatStore.messages.push(aiMsg);
  1032. homepageChatStore.isLoading = false;
  1033. homepageChatStore.deepNineInput = false;
  1034. chatStore.firstAPICall = false;
  1035. console.log("历史记录可以点击");
  1036. emit("enableInput");
  1037. }
  1038. } catch (e) {
  1039. // 意图识别异常,先清理思考过程消息
  1040. if (thinkingMessageRef) {
  1041. const index = chatStore.messages.indexOf(thinkingMessageRef);
  1042. if (index > -1) {
  1043. chatStore.messages.splice(index, 1);
  1044. }
  1045. }
  1046. console.log(e, "意图识别失败");
  1047. chatStore.messages.push({
  1048. class: "ing",
  1049. type: "ing",
  1050. flag: false,
  1051. content: "系统正在为您努力加载中,请稍后再试",
  1052. });
  1053. homepageChatStore.isLoading = false;
  1054. homepageChatStore.deepNineInput = false;
  1055. chatStore.firstAPICall = false;
  1056. console.log("历史记录可以点击");
  1057. emit("enableInput");
  1058. }
  1059. if (flag) {
  1060. const params2 = {
  1061. language: "cn",
  1062. token: localStorage.getItem("localToken"),
  1063. parentId: codeData.value.parentId,
  1064. stockId: codeData.value.stockId,
  1065. recordId: codeData.value.recordId,
  1066. // content: newVal[newVal.length - 1].content,
  1067. // marketList: "usa,sg,my,hk,cn,can,vi,th,in",
  1068. // name: codeData.value.name,
  1069. // code: codeData.value.code,
  1070. // market: codeData.value.market,
  1071. // language: "cn",
  1072. // marketList: "hk,cn,usa,my,sg,vi,in,gb"
  1073. // token: "+SsksARQgUHIbIG3rRnnbZi0+fEeMx8pywnIlrmTxo5EOPR/wjWDV7w7+ZUseiBtf9kFa/atmNx6QfSpv5w",
  1074. };
  1075. try {
  1076. const env = import.meta.env.VITE_ENV;
  1077. const result20 = await getNineTurnsAPI(
  1078. {
  1079. token:
  1080. env == "development" || env == "test"
  1081. ? "8Csj5VVX1UbIb4C3oxrnbZi0+fEeMx8pywnIlrmTm45Cb/EllzWACLto9J9+fCFsfdgBOvKvyY94FvqlvM0"
  1082. : "8nkj4QBV1RPIb4CzoRTnbZi0+fEeMx8pywnIlrmTxdwROKkuwWqAWu9orpkpeXVqL98DPfeonNYpHv+mucA",
  1083. },
  1084. {
  1085. market: codeData.value.market,
  1086. language: "cn",
  1087. code: codeData.value.code,
  1088. }
  1089. );
  1090. // 添加空值检查防止访问null对象的属性
  1091. const nineTurns = result20.data ? result20.data : null;
  1092. const isNineTurns =
  1093. nineTurns &&
  1094. nineTurns.DXT &&
  1095. nineTurns.JZJG &&
  1096. nineTurns.KLine20 &&
  1097. nineTurns.StockInformation &&
  1098. nineTurns.ZJQS
  1099. ? true
  1100. : false;
  1101. const katexRegex = /\$\$(.*?)\$\$/g;
  1102. let result21;
  1103. let result22;
  1104. let result23;
  1105. let result24;
  1106. // 用于跟踪API完成状态和结果
  1107. apiStatus = {
  1108. one: {
  1109. completed: false,
  1110. result: null,
  1111. error: null,
  1112. isError: false,
  1113. isEnd: false,
  1114. },
  1115. two: {
  1116. completed: false,
  1117. result: null,
  1118. error: null,
  1119. isError: false,
  1120. isEnd: false,
  1121. },
  1122. three: {
  1123. completed: false,
  1124. result: null,
  1125. error: null,
  1126. isError: false,
  1127. isEnd: false,
  1128. },
  1129. four: {
  1130. completed: false,
  1131. result: null,
  1132. error: null,
  1133. isError: false,
  1134. isEnd: false,
  1135. },
  1136. };
  1137. // 预加载音频函数
  1138. const preloadAudio = (url, apiKey) => {
  1139. if (!url || !audioStore.isVoiceEnabled) {
  1140. audioPreloadStatus[apiKey].loaded = true;
  1141. return Promise.resolve();
  1142. }
  1143. // 立即设置URL,确保即使预加载失败也能使用
  1144. audioPreloadStatus[apiKey].url = url;
  1145. console.log(`设置音频${apiKey}的URL:`, url);
  1146. return new Promise((resolve) => {
  1147. const audio = new Howl({
  1148. src: [url],
  1149. html5: true,
  1150. format: ["mp3", "acc"],
  1151. rate: 1.2,
  1152. preload: true,
  1153. onload: () => {
  1154. console.log(`音频${apiKey}预加载完成:`, url);
  1155. audioPreloadStatus[apiKey].loaded = true;
  1156. resolve();
  1157. },
  1158. onloaderror: (id, err) => {
  1159. console.error(`音频${apiKey}预加载失败:`, err);
  1160. audioPreloadStatus[apiKey].loaded = true; // 标记为已处理,避免阻塞
  1161. // URL已经在上面设置了,即使预加载失败也保留URL
  1162. resolve();
  1163. },
  1164. });
  1165. });
  1166. };
  1167. // 检查第一个接口是否可以开始输出(文本和音频都准备好)
  1168. const canStartFirstOutput = () => {
  1169. return apiStatus.one.completed && audioPreloadStatus.one.loaded;
  1170. };
  1171. // 检查并按顺序执行代码的函数
  1172. const checkAndExecuteInOrder = () => {
  1173. // 检查OneAPI - 只有当文本和音频都准备好时才开始输出
  1174. if (canStartFirstOutput() && !apiStatus.one.executed) {
  1175. if (apiStatus.one.result) {
  1176. apiStatus.one.executed = true;
  1177. console.log(
  1178. "执行OneAPI代码(文本和音频同步开始):",
  1179. apiStatus.one.result
  1180. );
  1181. // 将第一个音频添加到播放队列(确保顺序:API1)
  1182. if (audioPreloadStatus.one.url) {
  1183. chatStore.messages[chatStore.inputUserIndex].audioArray.push(
  1184. audioPreloadStatus.one.url
  1185. );
  1186. if (chatStore.currentUserIndex == chatStore.inputUserIndex) {
  1187. chatStore.messages[
  1188. chatStore.inputUserIndex
  1189. ].audioStatus = true;
  1190. addToAudioQueue(audioPreloadStatus.one.url, "API1-第一个");
  1191. } else {
  1192. chatStore.messages[
  1193. chatStore.inputUserIndex
  1194. ].audioStatus = false;
  1195. }
  1196. console.log(
  1197. "音频队列:添加API1-1音频(link1),当前队列长度:",
  1198. audioQueue.value.length
  1199. );
  1200. }
  1201. // 添加第二个音频(link)到队列
  1202. if (audioPreloadStatus.two.url) {
  1203. chatStore.messages[chatStore.inputUserIndex].audioArray.push(
  1204. audioPreloadStatus.two.url
  1205. );
  1206. if (chatStore.currentUserIndex == chatStore.inputUserIndex) {
  1207. addToAudioQueue(audioPreloadStatus.two.url, "API1-第二个");
  1208. } else {
  1209. chatStore.messages[
  1210. chatStore.inputUserIndex
  1211. ].audioStatus = false;
  1212. }
  1213. console.log(
  1214. "音频队列:添加API1-2音频(link),当前队列长度:",
  1215. audioQueue.value.length
  1216. );
  1217. }
  1218. // 在这里添加OneAPI成功后需要执行的代码
  1219. // 删除正在为您生成信息
  1220. chatStore.messages.pop();
  1221. // 添加报告头和时间
  1222. addTypingTask(
  1223. {
  1224. sender: "ai",
  1225. class: "title1",
  1226. type: "title1",
  1227. content: codeData.value.name + "深度共振分析图谱",
  1228. date: result21.data.date,
  1229. },
  1230. "",
  1231. 50
  1232. );
  1233. chatStore.firstAPICall = false;
  1234. console.log("历史记录可以点击");
  1235. const pc1 = marked(
  1236. result21.data.name +
  1237. "\n" +
  1238. result21.data.price +
  1239. "\n" +
  1240. result21.data.date
  1241. );
  1242. const ac1 = pc1.replace(katexRegex, (match, formula) => {
  1243. try {
  1244. return katex.renderToString(formula, {
  1245. throwOnError: false,
  1246. });
  1247. } catch (error) {
  1248. console.error("KaTeX 渲染错误:", error);
  1249. return match;
  1250. }
  1251. });
  1252. // 先推送初始消息
  1253. const aiMessage1 = reactive({
  1254. sender: "ai",
  1255. class: "content1",
  1256. type: "content1",
  1257. content: "",
  1258. isTyping: true,
  1259. });
  1260. addTypingTask(aiMessage1, ["", ac1], 130);
  1261. // 九转结构K线图
  1262. if (
  1263. nineTurns &&
  1264. nineTurns.DXT &&
  1265. nineTurns.JZJG &&
  1266. nineTurns.KLine20 &&
  1267. nineTurns.StockInformation &&
  1268. nineTurns.ZJQS
  1269. ) {
  1270. const nineTurnsData = JSON.parse(
  1271. JSON.stringify(toRaw(nineTurns))
  1272. );
  1273. console.log("处理 K 线数据 - 开始");
  1274. console.log("nineTurnsData", nineTurnsData);
  1275. const Kline20 = {
  1276. name: nineTurnsData.StockInformation.Name,
  1277. Kline: nineTurnsData,
  1278. };
  1279. // 打印K线数据结构
  1280. console.log("K线数据结构:", Kline20);
  1281. console.log("K线数据名称:", Kline20.name);
  1282. console.log("K线数据:", Kline20.Kline ? Kline20.Kline : null);
  1283. // 设置数据有效标志
  1284. hasValidData.value = true;
  1285. console.log("hasValidData设置为:", hasValidData.value);
  1286. // 先推送K线图消息
  1287. const klineMessageId2 = `kline-${Date.now() + 1}`;
  1288. console.log("生成K线消息ID:", klineMessageId2);
  1289. // 添加九转结构图表
  1290. addTypingTask(
  1291. {
  1292. sender: "ai",
  1293. class: "content2",
  1294. type: "content2",
  1295. kline: true,
  1296. chartData: Kline20,
  1297. messageId: klineMessageId2,
  1298. hasValidData: true, // 添加hasValidData标志
  1299. klineType: 2,
  1300. },
  1301. "",
  1302. 50
  1303. );
  1304. // 添加标题-数据分析时代下的认知变现
  1305. addTypingTask(
  1306. {
  1307. sender: "ai",
  1308. class: "title2",
  1309. type: "title2",
  1310. content: "",
  1311. },
  1312. "",
  1313. 50
  1314. );
  1315. // 添加图片-数据分析时代下的认知变现
  1316. addTypingTask(
  1317. {
  1318. sender: "ai",
  1319. class: "content3",
  1320. type: "img1",
  1321. content:
  1322. "https://d31zlh4on95l9h.cloudfront.net/images/5baa0a449cf74fb6a1afb1c909a21194.png",
  1323. },
  1324. "",
  1325. 50
  1326. );
  1327. // 添加标题-结构框架分析
  1328. addTypingTask(
  1329. {
  1330. sender: "ai",
  1331. class: "title3",
  1332. type: "title3",
  1333. content:
  1334. "https://d31zlh4on95l9h.cloudfront.net/images/9ab9d76b6906eb914fa1842dbcd56841.png",
  1335. },
  1336. "",
  1337. 50
  1338. );
  1339. // 添加内容框1
  1340. const ac2 = `<p>${result21.data.jgkjfx}</p>`;
  1341. // 先推送初始消息
  1342. const aiMessage2 = reactive({
  1343. sender: "ai",
  1344. class: "content3",
  1345. type: "content3",
  1346. content: "",
  1347. isTyping: true,
  1348. error: apiStatus.two.error ? "2" : "",
  1349. isEnd: "1",
  1350. });
  1351. addTypingTask(aiMessage2, ["", ac2], 130);
  1352. }
  1353. } else {
  1354. chatStore.messages.push({
  1355. class: "ing",
  1356. type: "ing",
  1357. flag: false,
  1358. content: "系统正在为您努力加载中,请稍后再试",
  1359. });
  1360. homepageChatStore.isLoading = false;
  1361. homepageChatStore.deepNineInput = false;
  1362. emit("enableInput");
  1363. }
  1364. }
  1365. // 检查TwoAPI(需要OneAPI已执行)
  1366. if (
  1367. apiStatus.one.executed &&
  1368. apiStatus.two.completed &&
  1369. !apiStatus.two.executed
  1370. ) {
  1371. if (apiStatus.two.result) {
  1372. apiStatus.two.executed = true;
  1373. console.log("执行TwoAPI代码:", apiStatus.two.result);
  1374. // 将第二个接口的音频添加到播放队列(确保顺序:API2)
  1375. if (audioPreloadStatus.three.url) {
  1376. chatStore.messages[chatStore.inputUserIndex].audioArray.push(
  1377. audioPreloadStatus.three.url
  1378. );
  1379. if (chatStore.currentUserIndex == chatStore.inputUserIndex) {
  1380. addToAudioQueue(
  1381. audioPreloadStatus.three.url,
  1382. "API2-第一个"
  1383. );
  1384. } else {
  1385. chatStore.messages[
  1386. chatStore.inputUserIndex
  1387. ].audioStatus = false;
  1388. }
  1389. console.log(
  1390. "音频队列:添加API2-1音频(link3),当前队列长度:",
  1391. audioQueue.value.length
  1392. );
  1393. }
  1394. if (audioPreloadStatus.four.url) {
  1395. chatStore.messages[chatStore.inputUserIndex].audioArray.push(
  1396. audioPreloadStatus.four.url
  1397. );
  1398. if (chatStore.currentUserIndex == chatStore.inputUserIndex) {
  1399. addToAudioQueue(audioPreloadStatus.four.url, "API2-第二个");
  1400. } else {
  1401. chatStore.messages[
  1402. chatStore.inputUserIndex
  1403. ].audioStatus = false;
  1404. }
  1405. console.log(
  1406. "音频队列:添加API2-2音频(link1),当前队列长度:",
  1407. audioQueue.value.length
  1408. );
  1409. }
  1410. // 在这里添加TwoAPI成功后需要执行的代码
  1411. // 添加标题-资金动向监控
  1412. addTypingTask(
  1413. {
  1414. sender: "ai",
  1415. class: "title3",
  1416. type: "title3",
  1417. content:
  1418. " https://d31zlh4on95l9h.cloudfront.net/images/f95c44f83b3e3c52e88964631c199060.png",
  1419. },
  1420. "",
  1421. 50
  1422. );
  1423. const ac31 = `<p style="margin:0;color:#FFD700;font-weight:bold;display:flex;justify-content:center;font-size:22px">【资金异动信号】</p><p>`;
  1424. const ac32 = result22.data.dxtsc;
  1425. // const ac33 = result22.data.zjqssc1;
  1426. const ac34 = `<p style="margin:0;color:#FFD700;font-weight:bold;display:flex;justify-content:center;font-size:22px">【资金趋势导航】</p><p>`;
  1427. const ac35 = result22.data.zjqssc1;
  1428. // const ac3 = `<p>${result23.data.DXTSC}</p><p>${result23.data.DXTSC2}</p><p>${result23.data.ZJQSSC1}</p>`;
  1429. const ac3Arr = [];
  1430. ac3Arr.push(ac31);
  1431. if (ac32 != "") {
  1432. ac3Arr.push(`<p>${ac32}</p>`);
  1433. }
  1434. // if (ac33 != "") {
  1435. // ac3Arr.push("");
  1436. // ac3Arr.push(`<p>${ac33}</p>`);
  1437. // }
  1438. ac3Arr.push(ac34);
  1439. if (ac35 != "") {
  1440. ac3Arr.push(`<p>${ac35}</p>`);
  1441. }
  1442. // 先推送初始消息
  1443. const aiMessage3 = reactive({
  1444. sender: "ai",
  1445. class: "content3",
  1446. type: "content3",
  1447. content: "",
  1448. isTyping: true,
  1449. error: apiStatus.three.error ? "3" : "",
  1450. isEnd: "2",
  1451. });
  1452. addTypingTask(aiMessage3, ac3Arr, 200);
  1453. } else {
  1454. if (
  1455. apiStatus.one.isEnd &&
  1456. apiStatus.two.error &&
  1457. !apiStatus.two.isError
  1458. ) {
  1459. apiStatus.two.isError = true;
  1460. chatStore.messages.push({
  1461. class: "ing",
  1462. type: "ing",
  1463. flag: false,
  1464. content: "系统正在为您努力加载中,请稍后再试",
  1465. });
  1466. homepageChatStore.isLoading = false;
  1467. homepageChatStore.deepNineInput = false;
  1468. emit("enableInput");
  1469. }
  1470. }
  1471. }
  1472. // 检查ThreeAPI(需要TwoAPI已执行)
  1473. if (
  1474. apiStatus.two.executed &&
  1475. apiStatus.three.completed &&
  1476. !apiStatus.three.executed
  1477. ) {
  1478. if (apiStatus.three.result) {
  1479. apiStatus.three.executed = true;
  1480. console.log("执行ThreeAPI代码:", apiStatus.three.result);
  1481. // 将第三个接口的音频添加到播放队列(确保顺序:API3)
  1482. if (audioPreloadStatus.five.url) {
  1483. chatStore.messages[chatStore.inputUserIndex].audioArray.push(
  1484. audioPreloadStatus.five.url
  1485. );
  1486. if (chatStore.currentUserIndex == chatStore.inputUserIndex) {
  1487. addToAudioQueue(audioPreloadStatus.five.url, "API3-第一个");
  1488. } else {
  1489. chatStore.messages[
  1490. chatStore.inputUserIndex
  1491. ].audioStatus = false;
  1492. }
  1493. console.log(
  1494. "音频队列:添加API3音频(link),当前队列长度:",
  1495. audioQueue.value.length
  1496. );
  1497. }
  1498. // 在这里添加ThreeAPI成功后需要执行的代码
  1499. // 添加标题-策略共振决策模型
  1500. addTypingTask(
  1501. {
  1502. sender: "ai",
  1503. class: "title3",
  1504. type: "title3",
  1505. content:
  1506. "https://d31zlh4on95l9h.cloudfront.net/images/d1fa1f4cbd6452796a4c5368d9f57c4d.png",
  1507. },
  1508. "",
  1509. 50
  1510. );
  1511. // 添加内容框4
  1512. const ac5 = `<p>${result23.data.zjqssc2}</p>`;
  1513. // 先推送初始消息
  1514. const aiMessage5 = reactive({
  1515. sender: "ai",
  1516. class: "content3",
  1517. type: "content3",
  1518. content: "",
  1519. isTyping: true,
  1520. });
  1521. addTypingTask(aiMessage5, ["", ac5], 240);
  1522. const ac6 = "该内容由AI生成,请注意甄别";
  1523. // 先推送初始消息
  1524. const aiMessage6 = reactive({
  1525. sender: "ai",
  1526. class: "mianze",
  1527. type: "mianze",
  1528. content: "",
  1529. isTyping: true,
  1530. end: true,
  1531. });
  1532. addTypingTask(aiMessage6, ["", ac6], 210);
  1533. } else {
  1534. if (
  1535. apiStatus.two.isEnd &&
  1536. apiStatus.three.error &&
  1537. !apiStatus.three.isError
  1538. ) {
  1539. apiStatus.three.isError = true;
  1540. chatStore.messages.push({
  1541. class: "ing",
  1542. type: "ing",
  1543. flag: false,
  1544. content: "系统正在为您努力加载中,请稍后再试",
  1545. });
  1546. homepageChatStore.isLoading = false;
  1547. homepageChatStore.deepNineInput = false;
  1548. emit("enableInput");
  1549. }
  1550. }
  1551. }
  1552. // 检查是否所有API都已完成并执行
  1553. if (
  1554. apiStatus.one.completed &&
  1555. apiStatus.two.completed &&
  1556. apiStatus.three.completed
  1557. ) {
  1558. console.log("所有API已完成,开始收集预加载的音频URL");
  1559. // 收集所有预加载的音频URL
  1560. const audioUrls = [];
  1561. console.log("预加载音频状态检查:");
  1562. console.log("audioPreloadStatus:", audioPreloadStatus);
  1563. if (audioPreloadStatus.one.url) {
  1564. console.log(
  1565. "添加预加载音频URL one:",
  1566. audioPreloadStatus.one.url
  1567. );
  1568. audioUrls.push(audioPreloadStatus.one.url);
  1569. }
  1570. if (audioPreloadStatus.two.url) {
  1571. console.log(
  1572. "添加预加载音频URL two:",
  1573. audioPreloadStatus.two.url
  1574. );
  1575. audioUrls.push(audioPreloadStatus.two.url);
  1576. }
  1577. if (audioPreloadStatus.three.url) {
  1578. console.log(
  1579. "添加预加载音频URL three:",
  1580. audioPreloadStatus.three.url
  1581. );
  1582. audioUrls.push(audioPreloadStatus.three.url);
  1583. }
  1584. if (audioPreloadStatus.four.url) {
  1585. console.log(
  1586. "添加预加载音频URL four:",
  1587. audioPreloadStatus.four.url
  1588. );
  1589. audioUrls.push(audioPreloadStatus.four.url);
  1590. }
  1591. console.log("收集到的预加载音频URLs:", audioUrls);
  1592. console.log("语音是否启用:", audioStore.isVoiceEnabled);
  1593. // 音频播放逻辑已移至各个接口的执行代码中
  1594. console.log("所有接口执行完成,音频已在各接口中单独播放");
  1595. }
  1596. };
  1597. const handleOneAPI = async () => {
  1598. try {
  1599. result21 = await deepNineSecondOneAPI(params2);
  1600. if (result21.code == 400) {
  1601. throw new Error("API返回错误码400,请求失败");
  1602. }
  1603. console.log("OneAPI成功返回:", result21);
  1604. apiStatus.one.completed = true;
  1605. apiStatus.one.result = result21;
  1606. // 预加载第一个接口的音频 - link1和link
  1607. if (result21?.data?.link1) {
  1608. await preloadAudio(result21.data.link1.trim(), "one");
  1609. } else {
  1610. audioPreloadStatus.one.loaded = true;
  1611. }
  1612. if (result21?.data?.link) {
  1613. await preloadAudio(result21.data.link.trim(), "two");
  1614. } else {
  1615. audioPreloadStatus.two.loaded = true;
  1616. }
  1617. // 检查是否可以执行
  1618. checkAndExecuteInOrder();
  1619. } catch (error) {
  1620. console.error("OneAPI失败:", error);
  1621. apiStatus.one.completed = true;
  1622. apiStatus.one.error = error;
  1623. audioPreloadStatus.one.loaded = true; // 失败时也标记为已处理
  1624. audioPreloadStatus.two.loaded = true; // 失败时也标记为已处理
  1625. // 即使失败也要检查后续执行
  1626. checkAndExecuteInOrder();
  1627. }
  1628. };
  1629. const handleTwoAPI = async () => {
  1630. try {
  1631. result22 = await deepNineSecondTwoAPI(params2);
  1632. if (result22.code == 400) {
  1633. throw new Error("API返回错误码400,请求失败");
  1634. }
  1635. console.log("TwoAPI成功返回:", result22);
  1636. apiStatus.two.completed = true;
  1637. apiStatus.two.result = result22;
  1638. // 预加载第二个接口的音频 - link3和link1
  1639. if (result22?.data?.link3) {
  1640. await preloadAudio(result22.data.link3.trim(), "three");
  1641. } else {
  1642. audioPreloadStatus.three.loaded = true;
  1643. }
  1644. if (result22?.data?.link1) {
  1645. await preloadAudio(result22.data.link1.trim(), "four");
  1646. } else {
  1647. audioPreloadStatus.four.loaded = true;
  1648. }
  1649. // 检查是否可以执行
  1650. checkAndExecuteInOrder();
  1651. } catch (error) {
  1652. console.error("TwoAPI失败:", error);
  1653. apiStatus.two.completed = true;
  1654. apiStatus.two.error = error;
  1655. audioPreloadStatus.three.loaded = true;
  1656. audioPreloadStatus.four.loaded = true;
  1657. checkAndExecuteInOrder();
  1658. }
  1659. };
  1660. const handleThreeAPI = async () => {
  1661. try {
  1662. result23 = await deepNineSecondThreeAPI(params2);
  1663. if (result23.code == 400) {
  1664. throw new Error("API返回错误码400,请求失败");
  1665. }
  1666. // result23 = await dbqbSecondThreeAPI();
  1667. console.log("ThreeAPI成功返回:", result23);
  1668. apiStatus.three.completed = true;
  1669. apiStatus.three.result = result23;
  1670. // 预加载第三个接口的音频 - 只有link字段
  1671. if (result23?.data?.link) {
  1672. await preloadAudio(result23.data.link.trim(), "five");
  1673. } else {
  1674. audioPreloadStatus.three.loaded = true;
  1675. }
  1676. // 检查是否可以执行
  1677. checkAndExecuteInOrder();
  1678. } catch (error) {
  1679. console.error("ThreeAPI失败:", error);
  1680. apiStatus.three.completed = true;
  1681. apiStatus.three.error = error;
  1682. audioPreloadStatus.three.loaded = true;
  1683. checkAndExecuteInOrder();
  1684. }
  1685. };
  1686. if (isNineTurns) {
  1687. handleOneAPI();
  1688. handleTwoAPI();
  1689. handleThreeAPI();
  1690. } else {
  1691. chatStore.messages.pop();
  1692. chatStore.messages.push({
  1693. class: "ing",
  1694. type: "ing",
  1695. flag: false,
  1696. content: "数据缺失,请稍后重试",
  1697. });
  1698. homepageChatStore.isLoading = false;
  1699. homepageChatStore.deepNineInput = false;
  1700. chatStore.firstAPICall = false;
  1701. emit("enableInput");
  1702. }
  1703. } catch (e) {
  1704. console.error("请求失败:", e);
  1705. chatStore.firstAPICall = false;
  1706. hasValidData.value = false; // 请求失败时设置数据无效
  1707. } finally {
  1708. // chatStore.setLoading(false);
  1709. await homepageChatStore.getUserCount();
  1710. }
  1711. }
  1712. }
  1713. },
  1714. { deep: false }
  1715. );
  1716. // 点击历史记录
  1717. watch(
  1718. () => chatStore.dbqbClickRecord,
  1719. (newValue, oldValue) => {
  1720. console.log("new", newValue);
  1721. if (!newValue || Object.keys(newValue).length === 0) {
  1722. return;
  1723. }
  1724. const clickRecord = ref(newValue);
  1725. console.log("dbqbClickRecord 发生变化:", clickRecord.value);
  1726. // 🔧 新增:完整的任务停止逻辑
  1727. try {
  1728. // 1. 停止所有音频相关任务
  1729. chatStore.currentUserIndex = null;
  1730. audioStore.stop(); // 暂停语音
  1731. // 🔧 新增:重置音频队列状态,确保新音频能够自动播放
  1732. audioQueue.value = [];
  1733. isPlayingAudio.value = false;
  1734. currentPlayIndex = 0;
  1735. isCallingPlayNext = false;
  1736. // 🔧 新增:重置音频预加载状态
  1737. audioPreloadStatus.one = { loaded: false, url: null };
  1738. audioPreloadStatus.two = { loaded: false, url: null };
  1739. audioPreloadStatus.three = { loaded: false, url: null };
  1740. audioPreloadStatus.four = { loaded: false, url: null };
  1741. audioPreloadStatus.five = { loaded: false, url: null };
  1742. // 🔧 新增:清理音频实例
  1743. if (audioStore.soundInstance) {
  1744. audioStore.soundInstance.stop();
  1745. audioStore.soundInstance.unload();
  1746. audioStore.soundInstance = null;
  1747. }
  1748. audioStore.nowSound = null;
  1749. // 2. 停止API调用和状态重置
  1750. // 🔧 新增:重置API状态
  1751. apiStatus.one = {
  1752. completed: false,
  1753. result: null,
  1754. error: null,
  1755. isError: false,
  1756. isEnd: false,
  1757. };
  1758. apiStatus.two = {
  1759. completed: false,
  1760. result: null,
  1761. error: null,
  1762. isError: false,
  1763. isEnd: false,
  1764. };
  1765. apiStatus.three = {
  1766. completed: false,
  1767. result: null,
  1768. error: null,
  1769. isError: false,
  1770. isEnd: false,
  1771. };
  1772. // 🔧 新增:重置数据有效性标志
  1773. hasValidData.value = false;
  1774. // 3. 停止打字机效果
  1775. typingQueue.value = [];
  1776. isTypingInProgress.value = false;
  1777. chatStore.allowTyping = false;
  1778. // 4. 重置加载状态
  1779. homepageChatStore.isLoading = false;
  1780. homepageChatStore.deepNineInput = false;
  1781. emit("enableInput");
  1782. // 在下一个事件循环中清空 dbqbClickRecord
  1783. setTimeout(() => {
  1784. chatStore.dbqbClickRecord = {};
  1785. console.log("dbqbClickRecord 已清空");
  1786. }, 0);
  1787. } catch (error) {
  1788. console.error("停止任务时发生错误:", error);
  1789. }
  1790. if (
  1791. !clickRecord.value.wokeFlowData.One ||
  1792. !clickRecord.value.wokeFlowData.Two ||
  1793. !clickRecord.value.wokeFlowData.Three
  1794. ) {
  1795. return;
  1796. }
  1797. try {
  1798. // 清空聊天框内容
  1799. chatStore.messages = [];
  1800. const userAudioArray = [
  1801. clickRecord.value.wokeFlowData.One.link1,
  1802. clickRecord.value.wokeFlowData.One.link,
  1803. clickRecord.value.wokeFlowData.Two.link3,
  1804. ];
  1805. // if (clickRecord.value.wokeFlowData.Two.link2) {
  1806. // userAudioArray.push(clickRecord.value.wokeFlowData.Two.link2);
  1807. // }
  1808. userAudioArray.push(clickRecord.value.wokeFlowData.Two.link1);
  1809. userAudioArray.push(clickRecord.value.wokeFlowData.Three.link);
  1810. const userContent = {
  1811. sender: "user",
  1812. timestamp: clickRecord.value.createdTime,
  1813. content: clickRecord.value.keyword,
  1814. audioArray: userAudioArray,
  1815. audioStatus: false,
  1816. };
  1817. chatStore.messages.push(userContent);
  1818. chatStore.messages.push({
  1819. sender: "ai",
  1820. class: "title1",
  1821. type: "title1",
  1822. content: clickRecord.value.stockName + "深度共振分析图谱",
  1823. date: clickRecord.value.wokeFlowData.One.date,
  1824. });
  1825. const pc1 = marked(
  1826. clickRecord.value.wokeFlowData.One.name +
  1827. "\n" +
  1828. clickRecord.value.wokeFlowData.One.price +
  1829. "\n" +
  1830. clickRecord.value.wokeFlowData.One.date
  1831. );
  1832. chatStore.messages.push({
  1833. sender: "ai",
  1834. class: "content1",
  1835. type: "content1",
  1836. content: pc1,
  1837. });
  1838. const nineTurns = clickRecord.value.stockData;
  1839. // 度牛尺K线图
  1840. if (
  1841. nineTurns &&
  1842. nineTurns.DXT &&
  1843. nineTurns.JZJG &&
  1844. nineTurns.KLine20 &&
  1845. nineTurns.StockInformation &&
  1846. nineTurns.ZJQS
  1847. ) {
  1848. const nineTurnsData = JSON.parse(JSON.stringify(toRaw(nineTurns)));
  1849. console.log("处理 K 线数据 - 开始");
  1850. console.log("nineTurnsData", nineTurnsData);
  1851. const Kline20 = {
  1852. name: nineTurnsData.StockInformation.Name,
  1853. Kline: nineTurnsData,
  1854. };
  1855. // 打印K线数据结构
  1856. console.log("K线数据结构:", Kline20);
  1857. console.log("K线数据名称:", Kline20.name);
  1858. console.log("K线数据:", Kline20.Kline ? Kline20.Kline : null);
  1859. // 设置数据有效标志
  1860. hasValidData.value = true;
  1861. console.log("hasValidData设置为:", hasValidData.value);
  1862. // chatStore.messages.pop();
  1863. // 先推送K线图消息
  1864. const klineMessageId2 = `kline-${Date.now() + 1}`;
  1865. console.log("生成K线消息ID:", klineMessageId2);
  1866. chatStore.messages.push({
  1867. sender: "ai",
  1868. class: "content2",
  1869. type: "content2",
  1870. kline: true,
  1871. chartData: Kline20,
  1872. messageId: klineMessageId2,
  1873. hasValidData: true, // 添加hasValidData标志
  1874. klineType: 2,
  1875. });
  1876. // 在渲染完成后初始化图表
  1877. nextTick(() => {
  1878. console.log("nextTick开始 - 准备渲染图表");
  1879. console.log("消息列表:", chatStore.messages);
  1880. // 寻找最新添加的K线消息索引
  1881. let klineIndex = -1;
  1882. for (let i = 0; i < chatStore.messages.length; i++) {
  1883. if (chatStore.messages[i].messageId === klineMessageId2) {
  1884. klineIndex = i;
  1885. break;
  1886. }
  1887. }
  1888. console.log("找到的K线消息索引:", klineIndex);
  1889. if (klineIndex !== -1) {
  1890. const containerId = `kline-container-${klineIndex}`;
  1891. console.log("图表容器ID:", containerId);
  1892. // 确保DOM已经渲染完成
  1893. setTimeout(() => {
  1894. console.log("延时执行,确保DOM已渲染");
  1895. KlineCanvsEcharts(containerId);
  1896. }, 100); // 短暂延时确保DOM已渲染
  1897. } else {
  1898. console.warn("未找到K线消息");
  1899. }
  1900. });
  1901. }
  1902. // 添加标题-数据分析时代下的认知变现
  1903. chatStore.messages.push({
  1904. sender: "ai",
  1905. class: "title2",
  1906. type: "title2",
  1907. content: "",
  1908. });
  1909. // 添加图片-数据分析时代下的认知变现
  1910. chatStore.messages.push({
  1911. sender: "ai",
  1912. class: "content3",
  1913. type: "img1",
  1914. content:
  1915. "https://d31zlh4on95l9h.cloudfront.net/images/5baa0a449cf74fb6a1afb1c909a21194.png",
  1916. });
  1917. // 添加标题-结构框架分析
  1918. chatStore.messages.push({
  1919. sender: "ai",
  1920. class: "title3",
  1921. type: "title3",
  1922. content:
  1923. "https://d31zlh4on95l9h.cloudfront.net/images/9ab9d76b6906eb914fa1842dbcd56841.png",
  1924. });
  1925. // 添加内容框1
  1926. const pc2 = marked(clickRecord.value.wokeFlowData.One.jgkjfx);
  1927. // 先推送初始消息
  1928. chatStore.messages.push({
  1929. sender: "ai",
  1930. class: "content3",
  1931. type: "content3",
  1932. content: pc2,
  1933. });
  1934. // 添加标题-资金动向监控
  1935. chatStore.messages.push({
  1936. sender: "ai",
  1937. class: "title3",
  1938. type: "title3",
  1939. content:
  1940. " https://d31zlh4on95l9h.cloudfront.net/images/f95c44f83b3e3c52e88964631c199060.png",
  1941. });
  1942. const ac3 = `<p style="margin:0;color:#FFD700;font-weight:bold;display:flex;justify-content:center;font-size:22px">【资金异动信号】</p><p>${clickRecord.value.wokeFlowData.Two.dxtsc}</p><p style="margin:0;color:#FFD700;font-weight:bold;display:flex;justify-content:center;font-size:22px">【资金趋势导航】</p><p>${clickRecord.value.wokeFlowData.Two.zjqssc1}</p>`;
  1943. // 先推送初始消息
  1944. chatStore.messages.push({
  1945. sender: "ai",
  1946. class: "content3",
  1947. type: "content3",
  1948. content: ac3,
  1949. isTyping: true,
  1950. });
  1951. // 添加标题-策略共振决策模型
  1952. chatStore.messages.push({
  1953. sender: "ai",
  1954. class: "title3",
  1955. type: "title3",
  1956. content:
  1957. "https://d31zlh4on95l9h.cloudfront.net/images/d1fa1f4cbd6452796a4c5368d9f57c4d.png",
  1958. });
  1959. // 添加内容框4
  1960. const ac5 = `<p>${clickRecord.value.wokeFlowData.Three.zjqssc2}</p>`;
  1961. // 先推送初始消息
  1962. chatStore.messages.push({
  1963. sender: "ai",
  1964. class: "content3",
  1965. type: "content3",
  1966. content: ac5,
  1967. });
  1968. chatStore.messages.push({
  1969. sender: "ai",
  1970. class: "mianze",
  1971. type: "mianze",
  1972. content: "该内容由AI生成,请注意甄别",
  1973. end: true,
  1974. });
  1975. } catch (e) {
  1976. ElMessage.error("历史数据获取出错!");
  1977. console.error("e", e);
  1978. }
  1979. },
  1980. {
  1981. deep: true, // 深度监听对象内部属性的变化
  1982. immediate: true, // 立即执行一次回调
  1983. }
  1984. );
  1985. function KlineCanvsEcharts(containerId) {
  1986. function vwToPx(vw) {
  1987. console.log((window.innerWidth * vw) / 100, "vwToPx");
  1988. return (window.innerWidth * vw) / 100;
  1989. }
  1990. // console.log("KLine渲染: 开始处理数据, 容器ID:", containerId);
  1991. // 从 chatStore 中获取数据
  1992. const messages = chatStore.messages;
  1993. // console.log("KLine渲染: 获取到的消息:", messages);
  1994. let klineMessageIndex = -1;
  1995. let klineData = null;
  1996. klineMessageIndex = containerId.split("-")[2];
  1997. // console.log("KLine渲染: 找到K线消息索引:", klineMessageIndex);
  1998. if (
  1999. messages[klineMessageIndex].kline &&
  2000. messages[klineMessageIndex].chartData
  2001. ) {
  2002. klineData = messages[klineMessageIndex].chartData;
  2003. }
  2004. var KlineOption = {};
  2005. // 检测设备类型
  2006. const isMobile = window.innerWidth < 768;
  2007. const isTablet = window.innerWidth >= 768 && window.innerWidth < 1024;
  2008. console.log(
  2009. "KLine渲染: 设备类型",
  2010. isMobile ? "移动设备" : isTablet ? "平板设备" : "桌面设备"
  2011. );
  2012. if (messages[klineMessageIndex].klineType == 2) {
  2013. if (!klineData || !klineData.Kline) {
  2014. // console.warn("KLine渲染: 数据无效 - 在chatStore中找不到有效的K线数据");
  2015. return;
  2016. }
  2017. // 获取容器元素
  2018. const container = document.getElementById(containerId);
  2019. if (!container) {
  2020. // console.error("KLine渲染: 找不到容器元素:", containerId);
  2021. return;
  2022. }
  2023. // 创建图表实例
  2024. // console.log("KLine渲染: 创建图表实例");
  2025. try {
  2026. // 如果已有实例,先销毁
  2027. if (chartInstancesMap[containerId]) {
  2028. // console.log("KLine渲染: 销毁已有图表实例");
  2029. chartInstancesMap[containerId].dispose();
  2030. delete chartInstancesMap[containerId];
  2031. }
  2032. // 使用普通变量存储实例
  2033. chartInstancesMap[containerId] = echarts.init(container);
  2034. // console.log("KLine渲染: 图表实例创建成功");
  2035. } catch (error) {
  2036. // console.error("KLine渲染: 图表实例创建失败:", error);
  2037. return;
  2038. }
  2039. const nineTurns = klineData.Kline;
  2040. console.log("KLine渲染: Kline数据", nineTurns);
  2041. // 拿到相应的数据
  2042. const splitData = (b) => {
  2043. const a = JSON.parse(JSON.stringify(b));
  2044. let categoryData = [];
  2045. let values = [];
  2046. for (let i = 0; i < a.length; i++) {
  2047. categoryData.push(a[i].splice(0, 1)[0]);
  2048. values.push(a[i]);
  2049. }
  2050. return {
  2051. categoryData,
  2052. values,
  2053. };
  2054. };
  2055. function vwToPx(vw) {
  2056. return (window.innerWidth * vw) / 100;
  2057. }
  2058. // k线的数据
  2059. var dealData = splitData(nineTurns.KLine20);
  2060. var markPointData = [];
  2061. const getNineNum = (KLine20, JZJG) => {
  2062. JZJG.forEach((item, index) => {
  2063. let low = KLine20[index][3];
  2064. let high = KLine20[index][4];
  2065. if (item[1] != -1) {
  2066. if (item[1] == 9) {
  2067. markPointData.push({
  2068. name: "low",
  2069. coord: [index, low],
  2070. itemStyle: {
  2071. normal: {
  2072. color: "rgba(0,0,0,0)", // 标记点透明
  2073. },
  2074. },
  2075. label: {
  2076. normal: {
  2077. show: true,
  2078. position: "bottom",
  2079. formatter: `${item[1]}`,
  2080. textStyle: {
  2081. color: "green",
  2082. fontSize: window.innerWidth > 769 ? 18 : 15,
  2083. textBorderColor: "#FFFFFF",
  2084. textBorderWidth: 2,
  2085. fontWeight: "bold",
  2086. },
  2087. },
  2088. },
  2089. });
  2090. } else {
  2091. markPointData.push({
  2092. name: "low",
  2093. coord: [index, low],
  2094. itemStyle: {
  2095. normal: {
  2096. color: "rgba(0,0,0,0)", // 标记点透明
  2097. },
  2098. },
  2099. label: {
  2100. normal: {
  2101. show: true,
  2102. position: "bottom",
  2103. formatter: `${item[1]}`,
  2104. textStyle: {
  2105. color: "green",
  2106. fontSize: window.innerWidth > 769 ? 12 : 9,
  2107. textBorderColor: "#FFFFFF",
  2108. textBorderWidth: 2,
  2109. fontWeight: "bold",
  2110. },
  2111. },
  2112. },
  2113. });
  2114. }
  2115. }
  2116. if (item[2] != -1) {
  2117. if (item[2] == 9) {
  2118. markPointData.push({
  2119. name: "high",
  2120. coord: [index, high],
  2121. itemStyle: {
  2122. normal: {
  2123. color: "rgba(0,0,0,0)", // 标记点透明
  2124. },
  2125. },
  2126. label: {
  2127. normal: {
  2128. show: true,
  2129. position: "top",
  2130. formatter: `${item[2]}`,
  2131. textStyle: {
  2132. color: "#0099FF",
  2133. fontSize: window.innerWidth > 769 ? 18 : 15,
  2134. textBorderColor: "#FFFFFF",
  2135. textBorderWidth: 2,
  2136. fontWeight: "bold",
  2137. },
  2138. },
  2139. },
  2140. });
  2141. } else {
  2142. markPointData.push({
  2143. name: "high",
  2144. coord: [index, high],
  2145. itemStyle: {
  2146. normal: {
  2147. color: "rgba(0,0,0,0)", // 标记点透明
  2148. },
  2149. },
  2150. label: {
  2151. normal: {
  2152. show: true,
  2153. position: "top",
  2154. formatter: `${item[2]}`,
  2155. textStyle: {
  2156. color: "#0099FF",
  2157. fontSize: window.innerWidth > 769 ? 12 : 9,
  2158. textBorderColor: "#FFFFFF",
  2159. textBorderWidth: 2,
  2160. fontWeight: "bold",
  2161. },
  2162. },
  2163. },
  2164. });
  2165. }
  2166. }
  2167. });
  2168. };
  2169. getNineNum(nineTurns.KLine20, nineTurns.JZJG);
  2170. // console.log("markPointData", markPointData);
  2171. var arrRange = [];
  2172. var arrSwing = [];
  2173. var arrDXTBar = [];
  2174. var arrInvisibleBar = [];
  2175. var markPointDXT = [];
  2176. var arr5DXTBar = [];
  2177. var arr6DXTBar = [];
  2178. var arr7DXTBar = [];
  2179. var DXTmin = 0;
  2180. var DXTmax = 100;
  2181. const getDXT = (DXT) => {
  2182. DXT.forEach((item, index) => {
  2183. arrRange.push(item[1]);
  2184. arrSwing.push(item[2]);
  2185. if (item[2] > 0) {
  2186. arrDXTBar.push(item[2] * 2);
  2187. arrInvisibleBar.push(50);
  2188. DXTmax = Math.max(DXTmax, item[2] * 2 + 50);
  2189. } else {
  2190. arrDXTBar.push(-item[2] * 2);
  2191. arrInvisibleBar.push(item[2] * 2 + 50);
  2192. }
  2193. if (item[5] == 1) {
  2194. arr5DXTBar.push(100);
  2195. } else {
  2196. arr5DXTBar.push(0);
  2197. }
  2198. if (item[6] == 1) {
  2199. arr6DXTBar.push(70);
  2200. } else {
  2201. arr6DXTBar.push(0);
  2202. }
  2203. if (item[7] == 1) {
  2204. arr7DXTBar.push(40);
  2205. } else {
  2206. arr7DXTBar.push(0);
  2207. }
  2208. if (item[8] == 1) {
  2209. markPointDXT.push({
  2210. name: "DTX-8",
  2211. coord: [index, 30],
  2212. symbol: "triangle", // 三角形符号
  2213. symbolSize: 10, // 符号大小
  2214. symbolRotate: 0, // 向上的三角形(0度)
  2215. itemStyle: {
  2216. normal: {
  2217. color: "#FFFF00", // 标记点透明
  2218. borderColor: "#000000", // 边框颜色
  2219. borderWidth: 1,
  2220. },
  2221. },
  2222. label: {
  2223. normal: {
  2224. show: false,
  2225. },
  2226. },
  2227. });
  2228. }
  2229. if (item[9] == 1) {
  2230. markPointDXT.push({
  2231. name: "DTX-9",
  2232. coord: [index, 20],
  2233. symbolSize: 7, // 正方形大小
  2234. itemStyle: {
  2235. normal: {
  2236. color: "red", // 标记点透明
  2237. // borderColor: "#000000", // 边框颜色
  2238. // borderWidth: 1,
  2239. },
  2240. },
  2241. label: {
  2242. normal: {
  2243. show: false,
  2244. },
  2245. },
  2246. });
  2247. }
  2248. if (item[10] == 1) {
  2249. markPointDXT.push({
  2250. name: "DTX-10",
  2251. coord: [index, 15],
  2252. symbol: "rect", // 设置为正方形
  2253. symbolSize: 7, // 正方形大小
  2254. itemStyle: {
  2255. normal: {
  2256. color: "grey", // 标记点透明
  2257. // borderColor: "#000000", // 边框颜色
  2258. // borderWidth: 1,
  2259. },
  2260. },
  2261. label: {
  2262. normal: {
  2263. show: false,
  2264. },
  2265. },
  2266. });
  2267. }
  2268. });
  2269. };
  2270. getDXT(nineTurns.DXT);
  2271. var arrBlue = [];
  2272. var arrRed = [];
  2273. var arrWhite = [];
  2274. var arrYellow = [];
  2275. const getZJQS = (ZJQS) => {
  2276. ZJQS.forEach((item, index) => {
  2277. arrBlue.push(item[1]);
  2278. arrRed.push(item[2]);
  2279. arrWhite.push(item[3]);
  2280. arrYellow.push(item[4]);
  2281. });
  2282. };
  2283. getZJQS(nineTurns.ZJQS);
  2284. // console.log("arrBlue", arrBlue);
  2285. // console.log("arrRed", arrRed);
  2286. // console.log("arrWhite", arrWhite);
  2287. // console.log("arrYellow", arrYellow);
  2288. KlineOption = {
  2289. // 手放上去显示的内容
  2290. tooltip: {
  2291. position: function (point, params) {
  2292. if (params[0].seriesIndex == 1) {
  2293. return window.innerWidth > 768 ? ["12%", "42%"] : ["18%", "40%"];
  2294. }
  2295. },
  2296. // 调用接口之后方法
  2297. formatter: function (a, b, d) {
  2298. if (a[0].seriesIndex == 0) {
  2299. const KlineTag = ref([]); // 判断几根K线
  2300. const AIBullTag = ref([]);
  2301. // 找到第一个满足条件的数据
  2302. KlineTag.value = a.find((item) => item.data[1])?.data || [];
  2303. // 找到第一个满足条件的非 '-' 数据
  2304. AIBullTag.value =
  2305. a.slice(4).find((item) => item.data[1] !== "-")?.data || [];
  2306. return (
  2307. a[0].name +
  2308. "<br/>" +
  2309. "开" +
  2310. ":" +
  2311. KlineTag.value[1] +
  2312. "<br/>" +
  2313. "收" +
  2314. ":" +
  2315. KlineTag.value[2] +
  2316. "<br/>" +
  2317. "低" +
  2318. ":" +
  2319. KlineTag.value[3] +
  2320. "<br/>" +
  2321. "高" +
  2322. ":" +
  2323. KlineTag.value[4]
  2324. );
  2325. } else if (a[0].seriesIndex == 1) {
  2326. return (
  2327. `<span style='color:red;'>RANGE: </span>` +
  2328. a[0].data +
  2329. " <span style='color:yellow'>SWING: </span>" +
  2330. a[1].data
  2331. );
  2332. } else {
  2333. return null;
  2334. // 格式化成交量显示
  2335. let formattedVolume;
  2336. if (a[0].data.value >= 10000) {
  2337. formattedVolume = (a[0].data.value / 10000).toFixed(2) + "w";
  2338. } else {
  2339. formattedVolume = a[0].data.value;
  2340. }
  2341. return a[0].name + "<br/>" + "量" + ":" + formattedVolume;
  2342. }
  2343. },
  2344. trigger: "axis",
  2345. axisPointer: {
  2346. //坐标轴指示器配置项
  2347. type: "cross", //‘line’直线指示器,‘cross’十字准星指示器,‘shadow’阴影指示器
  2348. },
  2349. backgroundColor: "rgba(119, 120, 125, 0.6)", // 提示框浮层的边框颜色。
  2350. borderWidth: 1, // 提示框浮层的边框宽。
  2351. borderColor: "#77787D", // 提示框浮层的边框颜色。
  2352. padding: 10, // 提示框浮层内边距,
  2353. textStyle: {
  2354. fontSize: window.innerWidth > 768 ? 12 : 8,
  2355. //提示框浮层上的文字样式
  2356. color: "#fff",
  2357. },
  2358. },
  2359. // 手放上去时拉的框
  2360. axisPointer: {
  2361. link: [
  2362. {
  2363. xAxisIndex: "all", // 同时触发所有图形的 x 坐标轴指示器
  2364. },
  2365. ],
  2366. label: {
  2367. backgroundColor: "#77787D", // 文本标签的背景颜色
  2368. },
  2369. },
  2370. toolbox: {
  2371. show: false,
  2372. },
  2373. grid: [
  2374. {
  2375. left: window.innerWidth > 768 ? "12%" : "18%",
  2376. right: window.innerWidth > 768 ? "10%" : "12%",
  2377. top: window.innerWidth > 768 ? "8%" : "8%",
  2378. height: window.innerWidth > 768 ? "34%" : "32%",
  2379. containLabel: false,
  2380. },
  2381. {
  2382. left: window.innerWidth > 768 ? "12%" : "18%",
  2383. right: window.innerWidth > 768 ? "10%" : "12%",
  2384. top: window.innerWidth > 768 ? "48%" : "46%",
  2385. height: window.innerWidth > 768 ? "18%" : "20%",
  2386. containLabel: false,
  2387. },
  2388. {
  2389. left: window.innerWidth > 768 ? "12%" : "18%",
  2390. right: window.innerWidth > 768 ? "10%" : "12%",
  2391. top: window.innerWidth > 768 ? "68%" : "68%",
  2392. height: window.innerWidth > 768 ? "18%" : "20%",
  2393. containLabel: false,
  2394. },
  2395. {
  2396. left: window.innerWidth > 768 ? "12%" : "18%",
  2397. right: window.innerWidth > 768 ? "10%" : "12%",
  2398. top: window.innerWidth > 768 ? "48%" : "46%",
  2399. height: window.innerWidth > 768 ? "18%" : "20%",
  2400. containLabel: false,
  2401. },
  2402. ],
  2403. xAxis: [
  2404. {
  2405. type: "category",
  2406. data: dealData.categoryData,
  2407. boundaryGap: true, // 坐标轴两边是否留空,false表示不留空(通常用于K线图)
  2408. axisLine: { onZero: false }, // 设置坐标轴是否通过零点,onZero:false表示不强制穿过零点
  2409. splitLine: { show: false }, // 是否显示分隔线,false表示不显示
  2410. min: "dataMin", // 坐标轴最小值,'dataMin'表示从数据的最小值开始
  2411. max: "dataMax", // 坐标轴最大值,'dataMax'表示从数据的最大值开始
  2412. axisPointer: {
  2413. label: {
  2414. show: false,
  2415. },
  2416. z: 100, // 坐标轴指示器的层级,较大的值会让它显示在其他元素上方
  2417. },
  2418. axisLine: {
  2419. lineStyle: {
  2420. normal: {
  2421. color: "black", // 坐标轴线的颜色
  2422. },
  2423. },
  2424. }, //
  2425. axisLabel: { show: false }, // 隐藏刻度标签
  2426. axisTick: { show: false }, // 隐藏刻度线
  2427. },
  2428. // 短线通1
  2429. {
  2430. type: "category",
  2431. gridIndex: 1,
  2432. data: dealData.categoryData,
  2433. boundaryGap: true,
  2434. axisPointer: {
  2435. label: {
  2436. show: false,
  2437. },
  2438. },
  2439. axisLine: { lineStyle: { normal: { color: "black" } } },
  2440. axisLabel: {
  2441. show: false,
  2442. interval: "auto",
  2443. },
  2444. axisTick: { show: true }, // 隐藏刻度线
  2445. },
  2446. // 下方成交量图的X轴
  2447. {
  2448. type: "category",
  2449. gridIndex: 2,
  2450. data: dealData.categoryData,
  2451. boundaryGap: true,
  2452. axisLine: { lineStyle: { normal: { color: "black" } } },
  2453. axisLabel: {
  2454. show: true,
  2455. fontSize: window.innerWidth > 768 ? 12 : 9,
  2456. interval: "auto",
  2457. },
  2458. axisTick: { show: false }, // 隐藏刻度线
  2459. },
  2460. // 短线通2
  2461. {
  2462. type: "category",
  2463. gridIndex: 3,
  2464. data: dealData.categoryData,
  2465. boundaryGap: true,
  2466. axisPointer: {
  2467. label: {
  2468. show: false,
  2469. },
  2470. },
  2471. axisLine: { show: false },
  2472. axisLabel: { show: false },
  2473. axisTick: { show: false }, // 隐藏刻度线
  2474. },
  2475. ],
  2476. // 控制纵坐标展示数据
  2477. yAxis: [
  2478. {
  2479. scale: true,
  2480. gridIndex: 0,
  2481. position: "left",
  2482. axisLabel: {
  2483. inside: false,
  2484. align: "right",
  2485. fontSize: window.innerWidth > 768 ? 12 : 9,
  2486. },
  2487. axisLine: {
  2488. show: true,
  2489. lineStyle: {
  2490. normal: {
  2491. color: "black",
  2492. },
  2493. },
  2494. },
  2495. axisTick: { show: false },
  2496. splitLine: { show: false },
  2497. },
  2498. {
  2499. scale: true,
  2500. gridIndex: 1,
  2501. min: DXTmin,
  2502. max: DXTmax,
  2503. axisLabel: {
  2504. show: true,
  2505. fontSize: window.innerWidth > 768 ? 12 : 9,
  2506. margin: 8, // 添加边距以获得更好的间距
  2507. },
  2508. axisLine: { show: true, lineStyle: { normal: { color: "black" } } },
  2509. axisTick: { show: false },
  2510. splitLine: { show: true, lineStyle: { normal: { type: "dashed" } } }, // 添加分割线以提高可读性
  2511. boundaryGap: ["20%", "20%"], // 为坐标轴边界添加内边距
  2512. },
  2513. {
  2514. scale: true,
  2515. gridIndex: 2,
  2516. splitNumber: 4, // 增加分割数以获得更好的间距
  2517. minInterval: 1, // 确保标签之间的最小间隔
  2518. axisLabel: {
  2519. show: true,
  2520. fontSize: window.innerWidth > 768 ? 12 : 9,
  2521. margin: 8, // 添加边距以获得更好的间距
  2522. },
  2523. axisLine: { show: true, lineStyle: { normal: { color: "black" } } },
  2524. axisTick: { show: false },
  2525. splitLine: { show: true, lineStyle: { normal: { type: "dashed" } } }, // 添加分割线以提高可读性
  2526. boundaryGap: ["20%", "20%"], // 为坐标轴边界添加内边距
  2527. },
  2528. {
  2529. scale: true,
  2530. gridIndex: 3,
  2531. min: DXTmin,
  2532. max: DXTmax,
  2533. axisLabel: { show: false },
  2534. axisLine: { show: false },
  2535. axisTick: { show: false },
  2536. splitLine: { show: false }, // 添加分割线以提高可读性
  2537. boundaryGap: ["20%", "20%"], // 为坐标轴边界添加内边距
  2538. },
  2539. ],
  2540. // 下拉条
  2541. dataZoom: [
  2542. {
  2543. type: "inside",
  2544. xAxisIndex: [0, 1, 2, 3],
  2545. },
  2546. {
  2547. show: true,
  2548. xAxisIndex: [0, 1, 2, 3],
  2549. type: "slider",
  2550. top: window.innerWidth > 768 ? "90%" : "92%",
  2551. height: window.innerWidth > 768 ? "25" : "20",
  2552. // left: window.innerWidth > 768 ? "10%" : "8%",
  2553. start: 98,
  2554. end: 100,
  2555. },
  2556. ],
  2557. series: [
  2558. {
  2559. name: "九转结构",
  2560. type: "candlestick",
  2561. barWidth: "50%", // 设置和上方图表一致的柱子宽度
  2562. data: dealData.values,
  2563. xAxisIndex: 0, // 使用第一个 X 轴
  2564. yAxisIndex: 0, // 使用第一个 Y 轴
  2565. markPoint: {
  2566. symbol: "circle",
  2567. symbolSize: 10,
  2568. data: markPointData,
  2569. z: 5, // 确保标记显示在最上层
  2570. },
  2571. itemStyle: {
  2572. normal: {
  2573. color: "red", // 默认颜色
  2574. color0: "green",
  2575. borderColor: "red",
  2576. borderColor0: "green",
  2577. },
  2578. },
  2579. gridIndex: 0,
  2580. },
  2581. {
  2582. name: "短线通-RANGE",
  2583. type: "line",
  2584. xAxisIndex: 1,
  2585. yAxisIndex: 1,
  2586. data: arrRange,
  2587. smooth: false,
  2588. symbol: "none",
  2589. itemStyle: {
  2590. normal: {
  2591. color: "#FA0096",
  2592. },
  2593. },
  2594. lineStyle: {
  2595. normal: {
  2596. width: 2,
  2597. type: "solid",
  2598. },
  2599. },
  2600. },
  2601. {
  2602. name: "短线通-SWING",
  2603. type: "line",
  2604. xAxisIndex: 1,
  2605. yAxisIndex: 1,
  2606. data: arrSwing,
  2607. smooth: false,
  2608. symbol: "none",
  2609. show: false,
  2610. itemStyle: {
  2611. normal: {
  2612. color: "transparent", // 设置为透明
  2613. opacity: 0, // 透明度为0
  2614. },
  2615. },
  2616. lineStyle: {
  2617. normal: {
  2618. width: 0, // 线宽为0
  2619. opacity: 0, // 透明度为0
  2620. },
  2621. },
  2622. },
  2623. {
  2624. name: "短线通-隐形柱",
  2625. type: "bar",
  2626. stack: "Total",
  2627. xAxisIndex: 1,
  2628. yAxisIndex: 1,
  2629. data: arrInvisibleBar,
  2630. barWidth: "2", // 设置柱子宽度
  2631. // barGap: "-100%", // 完全重叠
  2632. z: 5, // 确保标记显示在最上层
  2633. itemStyle: {
  2634. normal: {
  2635. color: "transparent",
  2636. // color: "#000",
  2637. },
  2638. },
  2639. lineStyle: {
  2640. normal: {
  2641. width: 2,
  2642. type: "solid",
  2643. },
  2644. },
  2645. },
  2646. {
  2647. name: "短线通-红蓝柱",
  2648. type: "bar",
  2649. stack: "Total",
  2650. xAxisIndex: 1,
  2651. yAxisIndex: 1,
  2652. data: arrDXTBar,
  2653. barWidth: "20%", // 设置柱子宽度
  2654. barGap: "-40%", // 完全重叠
  2655. z: 5, // 确保标记显示在最上层
  2656. itemStyle: {
  2657. normal: {
  2658. color: function (params) {
  2659. // console.log(params.dataIndex);
  2660. if (nineTurns.DXT[params.dataIndex][4] == 1) {
  2661. return "#FA0096";
  2662. } else if (nineTurns.DXT[params.dataIndex][4] == 2) {
  2663. return "#0099FF";
  2664. }
  2665. return "transparent";
  2666. },
  2667. },
  2668. },
  2669. lineStyle: {
  2670. normal: {
  2671. width: 2,
  2672. type: "solid",
  2673. },
  2674. },
  2675. },
  2676. {
  2677. name: "短线通-黄柱",
  2678. type: "bar",
  2679. xAxisIndex: 3,
  2680. yAxisIndex: 3,
  2681. data: arr5DXTBar,
  2682. barWidth: "40%", // 设置柱子宽度
  2683. z: 6, // 确保标记显示在最上层
  2684. itemStyle: {
  2685. normal: {
  2686. color: "rgb(154,154,16)",
  2687. },
  2688. },
  2689. lineStyle: {
  2690. normal: {
  2691. width: 2,
  2692. type: "solid",
  2693. },
  2694. },
  2695. },
  2696. {
  2697. name: "短线通-灰柱",
  2698. type: "bar",
  2699. xAxisIndex: 3,
  2700. yAxisIndex: 3,
  2701. data: arr6DXTBar,
  2702. barWidth: "40%", // 设置柱子宽度
  2703. z: 6, // 确保标记显示在最上层
  2704. itemStyle: {
  2705. normal: {
  2706. color: "rgb(140,140,140)",
  2707. },
  2708. },
  2709. lineStyle: {
  2710. normal: {
  2711. width: 2,
  2712. type: "solid",
  2713. },
  2714. },
  2715. },
  2716. {
  2717. name: "短线通-蓝柱",
  2718. type: "bar",
  2719. xAxisIndex: 3,
  2720. yAxisIndex: 3,
  2721. data: arr7DXTBar,
  2722. barWidth: "40%", // 设置柱子宽度
  2723. barGap: "-100%", // 完全重叠
  2724. z: 6, // 确保标记显示在最上层
  2725. itemStyle: {
  2726. normal: {
  2727. color: "rgb(110,200,255)",
  2728. },
  2729. },
  2730. lineStyle: {
  2731. normal: {
  2732. width: 2,
  2733. type: "solid",
  2734. },
  2735. },
  2736. },
  2737. {
  2738. name: "短线通-其他指标",
  2739. type: "line",
  2740. xAxisIndex: 1,
  2741. yAxisIndex: 1,
  2742. markPoint: {
  2743. symbol: "circle",
  2744. symbolSize: 10,
  2745. data: markPointDXT,
  2746. z: 7, // 确保标记显示在最上层
  2747. },
  2748. data: [],
  2749. smooth: false,
  2750. symbol: "none",
  2751. itemStyle: {
  2752. normal: {
  2753. color: function (params) {
  2754. // params.value 是当前数据点的值
  2755. // params.dataIndex 是当前数据点的索引
  2756. return params.value > 0 ? "#FA0096" : "#0099FF";
  2757. },
  2758. },
  2759. },
  2760. lineStyle: {
  2761. normal: {
  2762. width: 2,
  2763. type: "solid",
  2764. },
  2765. },
  2766. },
  2767. {
  2768. name: "资金趋势-蓝色线",
  2769. type: "line",
  2770. xAxisIndex: 2,
  2771. yAxisIndex: 2,
  2772. data: arrBlue,
  2773. smooth: false,
  2774. symbol: "none",
  2775. itemStyle: {
  2776. normal: {
  2777. color: "#00A2A2",
  2778. },
  2779. },
  2780. lineStyle: {
  2781. normal: {
  2782. width: 2,
  2783. type: "solid",
  2784. },
  2785. },
  2786. },
  2787. {
  2788. name: "资金趋势-红色线",
  2789. type: "line",
  2790. xAxisIndex: 2,
  2791. yAxisIndex: 2,
  2792. data: arrRed,
  2793. smooth: false,
  2794. symbol: "none",
  2795. itemStyle: {
  2796. normal: {
  2797. color: "#FF0000",
  2798. },
  2799. },
  2800. lineStyle: {
  2801. normal: {
  2802. width: 2,
  2803. type: "solid",
  2804. },
  2805. },
  2806. },
  2807. {
  2808. name: "资金趋势-白色线",
  2809. type: "line",
  2810. xAxisIndex: 2,
  2811. yAxisIndex: 2,
  2812. data: arrWhite,
  2813. smooth: false,
  2814. symbol: "none",
  2815. itemStyle: {
  2816. normal: {
  2817. color: "grey",
  2818. },
  2819. },
  2820. lineStyle: {
  2821. normal: {
  2822. width: 2,
  2823. type: "solid",
  2824. },
  2825. },
  2826. },
  2827. {
  2828. name: "资金趋势-黄色线",
  2829. type: "line",
  2830. xAxisIndex: 2,
  2831. yAxisIndex: 2,
  2832. data: arrYellow,
  2833. smooth: false,
  2834. symbol: "none",
  2835. itemStyle: {
  2836. normal: {
  2837. color: "#FFFF00",
  2838. },
  2839. },
  2840. lineStyle: {
  2841. normal: {
  2842. width: 2,
  2843. type: "solid",
  2844. },
  2845. },
  2846. },
  2847. ],
  2848. };
  2849. }
  2850. // console.log("KLine渲染: 图表配置完成");
  2851. try {
  2852. // 应用配置
  2853. // console.log("KLine渲染: 开始设置图表选项");
  2854. chartInstancesMap[containerId].setOption(KlineOption);
  2855. // console.log("KLine渲染: 图表选项设置成功");
  2856. // 窗口大小变化时重新渲染图表
  2857. const resizeFunc = _.throttle(
  2858. function () {
  2859. console.log("窗口大小改变,调整图表大小");
  2860. if (
  2861. chartInstancesMap[containerId] &&
  2862. !chartInstancesMap[containerId].isDisposed()
  2863. ) {
  2864. // 如果设备类型发生变化,重新渲染
  2865. const newIsMobile = window.innerWidth < 768;
  2866. const newIsTablet =
  2867. window.innerWidth >= 768 && window.innerWidth < 1024;
  2868. if (newIsMobile !== isMobile || newIsTablet !== isTablet) {
  2869. console.log("设备类型变化,重新渲染图表");
  2870. KlineCanvsEcharts(containerId);
  2871. return;
  2872. }
  2873. chartInstancesMap[containerId].resize();
  2874. }
  2875. },
  2876. 1000,
  2877. { trailing: false }
  2878. );
  2879. // 给resize事件绑定一个特定的函数名,便于后续移除
  2880. window[`resize_${containerId}`] = resizeFunc;
  2881. // 绑定resize事件
  2882. window.removeEventListener("resize", window[`resize_${containerId}`]);
  2883. window.addEventListener("resize", window[`resize_${containerId}`]);
  2884. // console.log("KLine渲染: 图表渲染完成");
  2885. } catch (error) {
  2886. // console.error("KLine渲染: 图表渲染出错", error);
  2887. }
  2888. }
  2889. watch(
  2890. () => audioStore.isVoiceEnabled,
  2891. (newVal) => {
  2892. // 添加状态锁定逻辑
  2893. if (newVal === audioStore.lastVoiceState) return;
  2894. audioStore.lastVoiceState = newVal;
  2895. if (newVal) {
  2896. console.log("开启语音播放");
  2897. // 添加重试机制
  2898. const tryPlay = () => {
  2899. if (!audioStore.ttsUrl) return; // 新增空值判断
  2900. if (audioStore.soundInstance?.playing()) return;
  2901. playAudio(audioStore.ttsUrl);
  2902. setTimeout(() => {
  2903. if (!audioStore.soundInstance?.playing()) {
  2904. Howler.unload();
  2905. }
  2906. }, 1000);
  2907. };
  2908. tryPlay();
  2909. } else {
  2910. console.log("关闭语音播放");
  2911. pauseAudio();
  2912. }
  2913. },
  2914. { immediate: true }
  2915. );
  2916. watch(
  2917. () => dataStore.activeTabIndex,
  2918. (newVal) => {
  2919. setTimeout(() => {
  2920. console.log("activeTabIndex变化:", newVal);
  2921. // 当标签页切换回来时,重新渲染所有图表
  2922. if (newVal === 0) {
  2923. console.log("切换到AI聊天页,重新渲染图表");
  2924. // 延迟执行以确保DOM已渲染
  2925. renderAllKlineCharts();
  2926. }
  2927. }, 1000);
  2928. },
  2929. { immediate: true } // 添加immediate属性,确保初始化时执行一次
  2930. );
  2931. const scrollToTop = () => {
  2932. homepageChatStore.dbqbScrollToTop = !homepageChatStore.dbqbScrollToTop;
  2933. };
  2934. // 添加渲染所有K线图的方法
  2935. async function renderAllKlineCharts() {
  2936. console.log("重新渲染所有K线图");
  2937. // 查找所有K线消息
  2938. const messages = chatStore.messages;
  2939. for (let i = 0; i < messages.length; i++) {
  2940. if (messages[i].kline && messages[i].chartData) {
  2941. const containerId = `kline-container-${i}`;
  2942. console.log(`尝试渲染K线图: ${containerId}`);
  2943. // 确保DOM已经渲染
  2944. const container = document.getElementById(containerId);
  2945. console.log("container", container);
  2946. await nextTick();
  2947. if (container) {
  2948. // 渲染图表
  2949. KlineCanvsEcharts(containerId);
  2950. } else {
  2951. console.warn(`找不到容器: ${containerId}`);
  2952. }
  2953. }
  2954. }
  2955. }
  2956. const clearAudio = () => {
  2957. // 停止音频播放
  2958. if (audioStore.isPlaying) {
  2959. audioStore.stop();
  2960. console.log("组件卸载,音频已停止");
  2961. }
  2962. // 清理队列系统
  2963. audioQueue.value = [];
  2964. isPlayingAudio.value = false;
  2965. currentPlayIndex = 0;
  2966. isCallingPlayNext = false;
  2967. // 清理音频实例
  2968. audioStore.soundInstance = null;
  2969. audioStore.nowSound = null;
  2970. // 停止所有 Howler 实例
  2971. Howler.stop();
  2972. Howler.unload();
  2973. // 重置音频状态
  2974. audioStore.isPlaying = false;
  2975. audioStore.isPaused = false;
  2976. audioStore.playbackPosition = 0;
  2977. // 清理预加载状态
  2978. Object.keys(audioPreloadStatus).forEach((key) => {
  2979. audioPreloadStatus[key] = { loaded: false, url: null };
  2980. });
  2981. chatStore.currentUserIndex = -1;
  2982. };
  2983. // 初始化随机GIF
  2984. onMounted(() => {
  2985. clearAudio();
  2986. // 检测移动设备
  2987. const isMobile =
  2988. /Android|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
  2989. navigator.userAgent
  2990. );
  2991. if (isMobile) {
  2992. // 强制移动设备使用 Web Audio API
  2993. Howler.html5PoolSize = 1; // 限制HTML5音频池大小
  2994. Howler.autoSuspend = false; // 禁用自动挂起
  2995. Howler.usingWebAudio = true; // 强制使用Web Audio API
  2996. // 激活音频上下文
  2997. const activateAudioContext = () => {
  2998. if (Howler.ctx && Howler.ctx.state === "suspended") {
  2999. Howler.ctx.resume();
  3000. console.log("音频上下文已激活");
  3001. }
  3002. };
  3003. // 监听用户交互以激活音频上下文
  3004. document.addEventListener("touchstart", activateAudioContext, {
  3005. once: true,
  3006. });
  3007. document.addEventListener("click", activateAudioContext, { once: true });
  3008. }
  3009. // 初始化marked组件
  3010. marked.setOptions({
  3011. breaks: true, // 支持换行符转换为 <br>
  3012. gfm: true, // 启用 GitHub Flavored Markdown
  3013. sanitize: false, // 不清理 HTML(谨慎使用)
  3014. smartLists: true, // 智能列表
  3015. smartypants: true, // 智能标点符号
  3016. xhtml: false, // 不使用 XHTML 输出
  3017. renderer: renderer,
  3018. });
  3019. renderAllKlineCharts();
  3020. console.log("组件挂载完成");
  3021. // 重置音频下标
  3022. chatStore.currentUserIndex = null;
  3023. chatStore.messages.forEach((item) => {
  3024. if (item.sender == "user") {
  3025. item.audioStatus = false;
  3026. }
  3027. });
  3028. // 添加页面可见性变化监听器
  3029. document.addEventListener("visibilitychange", handleVisibilityChange);
  3030. // 添加DOM变化监听器
  3031. const observer = new MutationObserver((mutations) => {
  3032. mutations.forEach((mutation) => {
  3033. if (mutation.type === "childList" && mutation.addedNodes.length) {
  3034. // 检查是否添加了图表容器
  3035. const containers = document.querySelectorAll(
  3036. '[id^="kline-container-"]'
  3037. );
  3038. if (containers.length) {
  3039. // console.log("DOM变化监听到K线容器:", Array.from(containers).map(el => el.id));
  3040. }
  3041. }
  3042. });
  3043. });
  3044. // 开始监听DOM变化
  3045. observer.observe(document.body, { childList: true, subtree: true });
  3046. });
  3047. // 页面可见性变化处理
  3048. let wasPlayingBeforeHidden = false;
  3049. const handleVisibilityChange = () => {
  3050. if (document.hidden) {
  3051. // 页面被隐藏时,如果音频正在播放,则暂停并记录状态
  3052. if (audioStore.isPlaying) {
  3053. wasPlayingBeforeHidden = true;
  3054. audioStore.pause();
  3055. console.log("页面切换离开,音频已暂停");
  3056. } else {
  3057. wasPlayingBeforeHidden = false;
  3058. }
  3059. } else {
  3060. // 页面重新可见时,如果之前在播放,则恢复播放
  3061. if (wasPlayingBeforeHidden && !audioStore.isPlaying) {
  3062. audioStore.play();
  3063. console.log("页面切换回来,音频已恢复播放");
  3064. wasPlayingBeforeHidden = false;
  3065. }
  3066. }
  3067. };
  3068. // 组件卸载时清理所有图表实例和事件监听器
  3069. onUnmounted(() => {
  3070. // 移除页面可见性变化监听器
  3071. document.removeEventListener("visibilitychange", handleVisibilityChange);
  3072. clearAudio();
  3073. // 清理所有图表实例
  3074. Object.keys(chartInstancesMap).forEach((key) => {
  3075. if (chartInstancesMap[key]) {
  3076. // 移除resize事件监听
  3077. if (window[`resize_${key}`]) {
  3078. window.removeEventListener("resize", window[`resize_${key}`]);
  3079. delete window[`resize_${key}`];
  3080. }
  3081. // 销毁图表实例
  3082. chartInstancesMap[key].dispose();
  3083. delete chartInstancesMap[key];
  3084. }
  3085. });
  3086. });
  3087. </script>
  3088. <template>
  3089. <div class="chat-container">
  3090. <div id="deepNine-top-anchor"></div>
  3091. <!-- GIF区域 -->
  3092. <div class="gif-area">
  3093. <img
  3094. src="https://d31zlh4on95l9h.cloudfront.net/images/a686991d0a26bdbafd938a15da93d5b4.png"
  3095. alt="深度九大模型logo"
  3096. class="bgc"
  3097. />
  3098. <img
  3099. src="https://d31zlh4on95l9h.cloudfront.net/images/35bf808538183be0062e4647570a9abd.png"
  3100. alt="深度九大模型logo"
  3101. class="logo1"
  3102. />
  3103. <img
  3104. src="https://d31zlh4on95l9h.cloudfront.net/images/0c09c892051e7ae16cbff6091075aee9.png"
  3105. alt="深度九大模型标题logo"
  3106. class="logo2"
  3107. />
  3108. </div>
  3109. <div v-for="(msg, index) in chatMsg" :key="index">
  3110. <!-- 用户消息容器包含喇叭按钮 -->
  3111. <div v-if="msg.sender === 'user'" class="user-message-container">
  3112. <div class="user-msg">
  3113. <div class="user-content">
  3114. <img
  3115. :src="msg.audioStatus ? voice : voiceNoActive"
  3116. class="user-message-speaker"
  3117. :class="{
  3118. 'speaker-active': msg.audioStatus,
  3119. }"
  3120. @click="toggleVoiceForUser(index)"
  3121. alt="喇叭"
  3122. />
  3123. <div
  3124. :class="{
  3125. 'message-bubble': true,
  3126. [msg.sender]: msg.sender,
  3127. [msg.class]: msg.class,
  3128. }"
  3129. >
  3130. <div v-html="msg.content"></div>
  3131. </div>
  3132. </div>
  3133. <div v-if="msg.timestamp" class="user-sendTime">
  3134. {{ moment(msg.timestamp).format("YYYY-MM-DD HH:mm:ss") }}
  3135. </div>
  3136. </div>
  3137. </div>
  3138. <!-- AI消息和其他类型消息 -->
  3139. <div
  3140. v-else
  3141. :class="{
  3142. 'message-bubble': true,
  3143. [msg.sender]: msg.sender,
  3144. [msg.class]: msg.class,
  3145. }"
  3146. >
  3147. <div v-if="msg.type === 'kline'" class="kline-container">
  3148. <div :id="'kline-container-' + index" class="chart-mount-point">
  3149. <div v-if="!msg.hasValidData" class="no-data-message">
  3150. <p>暂无K线数据</p>
  3151. </div>
  3152. </div>
  3153. </div>
  3154. <div v-else-if="msg.type == 'ing'" class="ai-message-container">
  3155. <img
  3156. v-if="msg.gif"
  3157. :src="msg.gif"
  3158. alt="思考过程"
  3159. class="thinking-gif"
  3160. />
  3161. <div class="ai-message-content" :class="{ fourStep: msg.nowrap }">
  3162. <div v-if="msg.flag">
  3163. <span>{{ msg.content }}</span>
  3164. <span class="loading-dots">
  3165. <span class="dot">.</span>
  3166. <span class="dot">.</span>
  3167. <span class="dot">.</span>
  3168. <span class="dot">.</span>
  3169. <span class="dot">.</span>
  3170. <span class="dot">.</span>
  3171. </span>
  3172. </div>
  3173. <div v-else v-html="msg.content"></div>
  3174. </div>
  3175. </div>
  3176. <div
  3177. v-else-if="msg.type == 'title1'"
  3178. style="display: flex; width: 100%"
  3179. >
  3180. <div class="mainTitle">
  3181. {{ msg.content }}
  3182. </div>
  3183. <div class="date">
  3184. {{ msg.date }}
  3185. </div>
  3186. </div>
  3187. <div v-else-if="msg.type == 'title2'" class="title2">
  3188. <img
  3189. class="title1Img"
  3190. src="https://d31zlh4on95l9h.cloudfront.net/images/c5c2887c56cde033c362cecae4cda4b4.png"
  3191. alt="出错了"
  3192. />
  3193. </div>
  3194. <div v-else-if="msg.type == 'title3'" class="title3">
  3195. <img class="title2Img" :src="msg.content" alt="出错了" />
  3196. </div>
  3197. <div v-else-if="msg.type == 'content1'" class="content1">
  3198. <div v-if="msg.kline" class="kline-container content1chart">
  3199. <div :id="'kline-container-' + index" class="chart-mount-point">
  3200. <div v-if="!msg.hasValidData" class="no-data-message">
  3201. <p>暂无数据</p>
  3202. </div>
  3203. </div>
  3204. </div>
  3205. <div v-else class="content1Text">
  3206. <div v-html="msg.content" class="text1"></div>
  3207. </div>
  3208. </div>
  3209. <div v-else-if="msg.type == 'content2'" class="content2">
  3210. <div class="kline-container content2chart">
  3211. <div :id="'kline-container-' + index" class="chart-mount-pointJN">
  3212. <div v-if="!msg.hasValidData" class="no-data-message">
  3213. <p>暂无数据</p>
  3214. </div>
  3215. </div>
  3216. </div>
  3217. </div>
  3218. <div v-else-if="msg.type == 'img1'" class="img1">
  3219. <div class="img1Bk">
  3220. <img class="img1Img" :src="msg.content" alt="出错了" />
  3221. </div>
  3222. </div>
  3223. <div v-else-if="msg.type == 'content3'" class="content3">
  3224. <div class="content3Text">
  3225. <div v-html="msg.content" class="text3"></div>
  3226. </div>
  3227. </div>
  3228. <div v-else-if="msg.type == 'mianze'" class="mianze">
  3229. <div v-html="msg.content"></div>
  3230. </div>
  3231. <div v-else v-html="msg.content"></div>
  3232. </div>
  3233. </div>
  3234. </div>
  3235. <!-- 全局返回顶部按钮 -->
  3236. <div v-if="chatMsg.length > 0" class="back-to-top" @click="scrollToTop">
  3237. <svg
  3238. width="24"
  3239. height="24"
  3240. viewBox="0 0 24 24"
  3241. fill="none"
  3242. xmlns="http://www.w3.org/2000/svg"
  3243. >
  3244. <path
  3245. d="M12 4L12 20M12 4L6 10M12 4L18 10"
  3246. stroke="currentColor"
  3247. stroke-width="2"
  3248. stroke-linecap="round"
  3249. stroke-linejoin="round"
  3250. />
  3251. </svg>
  3252. </div>
  3253. </template>
  3254. <style scoped>
  3255. p {
  3256. font-size: 20px;
  3257. }
  3258. .bgc {
  3259. position: absolute;
  3260. z-index: -1;
  3261. max-width: 440px;
  3262. min-width: 300px;
  3263. top: -15px;
  3264. width: 40%;
  3265. height: auto;
  3266. /* 添加旋转动画 */
  3267. animation: rotate 10s linear infinite reverse;
  3268. }
  3269. /* 定义旋转动画 */
  3270. @keyframes rotate {
  3271. from {
  3272. transform: rotate(0deg);
  3273. }
  3274. to {
  3275. transform: rotate(360deg);
  3276. }
  3277. }
  3278. .logo1 {
  3279. max-width: 350px;
  3280. min-width: 200px;
  3281. width: 15%;
  3282. }
  3283. .logo2 {
  3284. margin-top: 20px;
  3285. max-width: 350px;
  3286. min-width: 200px;
  3287. width: 30%;
  3288. /* position: relative; */
  3289. }
  3290. .chat-container {
  3291. display: flex;
  3292. flex-direction: column;
  3293. overflow: hidden;
  3294. }
  3295. .gif-area {
  3296. padding: 100px 0px;
  3297. position: relative;
  3298. /* height: 30vh; */
  3299. display: flex;
  3300. flex-direction: column;
  3301. justify-content: center;
  3302. align-items: center;
  3303. flex-shrink: 0;
  3304. /* 防止GIF区域被压缩 */
  3305. }
  3306. .message-area {
  3307. margin-top: 2%;
  3308. flex: 1;
  3309. /* 消息区域占据剩余空间 */
  3310. overflow-y: auto;
  3311. padding: 20px;
  3312. display: flex;
  3313. flex-direction: column;
  3314. gap: 15px;
  3315. }
  3316. .marquee-container {
  3317. /* position: absolute; */
  3318. bottom: 0;
  3319. width: 100%;
  3320. /* ga */
  3321. }
  3322. .marquee-row {
  3323. white-space: nowrap;
  3324. overflow: visible;
  3325. padding: 8px 0;
  3326. width: 100%;
  3327. }
  3328. .marquee-item {
  3329. display: inline-block;
  3330. margin: 0 15px;
  3331. padding: 8px 20px;
  3332. background: rgba(255, 255, 255, 0.9);
  3333. /* 白色背景 */
  3334. border-radius: 10px;
  3335. /* 圆角矩形 */
  3336. color: #333;
  3337. /* 文字颜色改为深色 */
  3338. box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  3339. /* 添加阴影 */
  3340. transition: all 0.3s;
  3341. transition: color 0.3s;
  3342. }
  3343. .top {
  3344. animation: marquee 25s linear infinite;
  3345. /* 默认动画是运行状态 */
  3346. animation-play-state: running;
  3347. }
  3348. .bottom {
  3349. animation: marquee 15s linear infinite reverse;
  3350. /* 默认动画是运行状态 */
  3351. animation-play-state: running;
  3352. }
  3353. /* 返回顶部按钮样式 */
  3354. .back-to-top {
  3355. position: sticky !important;
  3356. bottom: 20px !important;
  3357. left: calc(100% - 70px) !important;
  3358. width: 50px !important;
  3359. height: 50px !important;
  3360. background: linear-gradient(135deg, #00d4ff 0%, #0066cc 100%) !important;
  3361. border-radius: 50% !important;
  3362. display: flex !important;
  3363. align-items: center !important;
  3364. justify-content: center !important;
  3365. cursor: pointer !important;
  3366. transition: all 0.3s ease !important;
  3367. z-index: 100 !important;
  3368. color: white !important;
  3369. opacity: 1 !important;
  3370. visibility: visible !important;
  3371. margin-top: 20px !important;
  3372. margin-bottom: 20px !important;
  3373. }
  3374. .back-to-top:hover {
  3375. transform: translateY(-3px);
  3376. box-shadow: 0 6px 20px rgba(0, 212, 255, 0.5);
  3377. background: linear-gradient(135deg, #00e6ff 0%, #0077dd 100%);
  3378. }
  3379. .back-to-top:active {
  3380. transform: translateY(-1px);
  3381. }
  3382. /* 添加PC端专用速度 */
  3383. @media (min-width: 768px) {
  3384. .top {
  3385. animation-duration: 35s;
  3386. /* PC端改为35秒 */
  3387. }
  3388. .bottom {
  3389. animation-duration: 35s;
  3390. /* PC端改为35秒 */
  3391. }
  3392. }
  3393. @keyframes marquee {
  3394. 0% {
  3395. transform: translateX(100%);
  3396. }
  3397. 100% {
  3398. transform: translateX(-250%);
  3399. }
  3400. }
  3401. .loading-dots {
  3402. display: inline-block;
  3403. }
  3404. .dot {
  3405. opacity: 0.4;
  3406. animation: loading 1.4s infinite;
  3407. }
  3408. .dot:nth-child(1) {
  3409. animation-delay: 0s;
  3410. }
  3411. .dot:nth-child(2) {
  3412. animation-delay: 0.2s;
  3413. }
  3414. .dot:nth-child(3) {
  3415. animation-delay: 0.4s;
  3416. }
  3417. .dot:nth-child(4) {
  3418. animation-delay: 0.6s;
  3419. }
  3420. .dot:nth-child(5) {
  3421. animation-delay: 0.8s;
  3422. }
  3423. .dot:nth-child(6) {
  3424. animation-delay: 1s;
  3425. }
  3426. @keyframes loading {
  3427. 0%,
  3428. 60%,
  3429. 100% {
  3430. opacity: 0.4;
  3431. }
  3432. 30% {
  3433. opacity: 1;
  3434. }
  3435. }
  3436. .message-bubble {
  3437. max-width: 80%;
  3438. margin: 10px 0px;
  3439. padding: 15px 20px;
  3440. position: relative;
  3441. }
  3442. /* 用户消息容器样式 */
  3443. .user-message-container {
  3444. display: flex;
  3445. align-items: flex-end;
  3446. margin: 10px 0px;
  3447. justify-content: flex-end;
  3448. gap: 10px;
  3449. /* align-items: center; */
  3450. flex-direction: column;
  3451. }
  3452. .user-msg {
  3453. margin-left: auto;
  3454. display: flex;
  3455. flex-direction: column;
  3456. }
  3457. .user-content {
  3458. display: flex;
  3459. height: 100%;
  3460. align-items: center;
  3461. margin-right: 5px;
  3462. justify-content: flex-end;
  3463. padding: 0 20px;
  3464. }
  3465. .user-sendTime {
  3466. width: 100%;
  3467. text-align: center;
  3468. color: rgba(255, 255, 255, 0.6);
  3469. font-size: 0.8rem;
  3470. }
  3471. .user-message-speaker {
  3472. width: 32px;
  3473. height: 32px;
  3474. object-fit: contain;
  3475. margin-right: 5px;
  3476. cursor: pointer;
  3477. transition: all 0.3s ease;
  3478. }
  3479. .user-message-speaker:hover {
  3480. transform: scale(1.1);
  3481. }
  3482. .user-message-speaker.speaker-active {
  3483. animation: pulse 1.5s infinite;
  3484. }
  3485. @keyframes pulse {
  3486. 0% {
  3487. transform: scale(1);
  3488. }
  3489. 50% {
  3490. transform: scale(1.1);
  3491. }
  3492. 100% {
  3493. transform: scale(1);
  3494. }
  3495. }
  3496. .message-bubble.user {
  3497. color: #6d22f8;
  3498. background: white;
  3499. font-weight: bold;
  3500. border-radius: 10px;
  3501. margin: 0;
  3502. display: flex;
  3503. align-items: center;
  3504. word-break: break-word; /* 启用强制换行 */
  3505. }
  3506. .message-bubble.ai {
  3507. background: #2b378d;
  3508. color: #ffffff;
  3509. margin: 0 auto;
  3510. /* border-bottom-left-radius: 5px; */
  3511. }
  3512. .message-bubble.ing {
  3513. background: #ffffff;
  3514. color: #000000;
  3515. font-weight: bold;
  3516. border-radius: 10px;
  3517. margin-left: 20px;
  3518. margin-right: auto;
  3519. display: flex;
  3520. align-items: center;
  3521. width: fit-content;
  3522. }
  3523. .message-bubble.ai.title1 {
  3524. width: 100%;
  3525. display: flex;
  3526. border-radius: 10px 10px 0px 0px;
  3527. /* border-bottom-left-radius: 5px; */
  3528. }
  3529. .mainTitle {
  3530. font-size: 16px;
  3531. font-weight: bold;
  3532. background-image: url("@/assets/img/AiEmotion/bk01.png");
  3533. background-repeat: no-repeat;
  3534. background-size: 100% 100%;
  3535. min-width: 200px;
  3536. width: 20vw;
  3537. max-width: 50%;
  3538. height: 50px;
  3539. padding: 15px 10px;
  3540. text-align: center;
  3541. line-height: 20px;
  3542. overflow: hidden;
  3543. text-overflow: ellipsis;
  3544. white-space: nowrap;
  3545. box-sizing: border-box;
  3546. }
  3547. .date {
  3548. font-size: 1.5rem;
  3549. font-weight: bold;
  3550. margin-left: auto;
  3551. /* width: 100px; */
  3552. display: flex;
  3553. justify-content: center;
  3554. align-items: center;
  3555. }
  3556. .message-bubble.ai.title2 {
  3557. width: 100%;
  3558. display: flex;
  3559. justify-content: center;
  3560. align-items: center;
  3561. }
  3562. .title1Img {
  3563. max-width: 500px;
  3564. width: 90vw;
  3565. }
  3566. .message-bubble.ai.title3 {
  3567. width: 100%;
  3568. display: flex;
  3569. justify-content: center;
  3570. align-items: center;
  3571. }
  3572. .title2Img {
  3573. max-width: 500px;
  3574. width: 90vw;
  3575. }
  3576. .message-bubble.ai.content1 {
  3577. width: 100%;
  3578. display: flex;
  3579. justify-content: center;
  3580. align-items: center;
  3581. }
  3582. .content1chart {
  3583. background-image: url("@/assets/img/AIchat/罗盘边框.png");
  3584. background-repeat: no-repeat;
  3585. background-size: 100% 100%;
  3586. width: 50vw;
  3587. min-width: 350px;
  3588. display: flex;
  3589. justify-content: center;
  3590. align-items: center;
  3591. }
  3592. .content1Text {
  3593. background-image: url("@/assets/img/AIchat/框.png");
  3594. background-repeat: no-repeat;
  3595. background-size: 100% 100%;
  3596. width: 50vw;
  3597. min-width: 350px;
  3598. /* height: 20vw; */
  3599. /* max-height: 400px; */
  3600. padding: 5% 0;
  3601. }
  3602. .text1 {
  3603. font-weight: bold;
  3604. /* margin-left: 6%; */
  3605. /* margin-bottom: 10px; */
  3606. margin: 0px 6% 10px 6%;
  3607. font-size: 20px;
  3608. }
  3609. .message-bubble.ai.content2 {
  3610. width: 100%;
  3611. display: flex;
  3612. justify-content: center;
  3613. align-items: center;
  3614. }
  3615. .content2chart {
  3616. background-image: url("@/assets/img/AIchat/PCbackPic.png");
  3617. background-repeat: no-repeat;
  3618. background-size: 100% 100%;
  3619. width: 50vw;
  3620. min-width: 350px;
  3621. display: flex;
  3622. justify-content: center;
  3623. align-items: center;
  3624. height: calc(500px + 10vw) !important;
  3625. }
  3626. .message-bubble.ai.img1 {
  3627. width: 100%;
  3628. display: flex;
  3629. justify-content: center;
  3630. align-items: center;
  3631. }
  3632. .img1Bk {
  3633. background-image: url("@/assets/img/AIchat/边框.png");
  3634. background-repeat: no-repeat;
  3635. background-size: 100% 100%;
  3636. width: 50vw;
  3637. min-width: 350px;
  3638. /* height: 20vw; */
  3639. /* max-height: 400px; */
  3640. padding: 5% 0px;
  3641. display: flex;
  3642. justify-content: center;
  3643. align-items: center;
  3644. }
  3645. .img1Img {
  3646. width: 90%;
  3647. }
  3648. .message-bubble.ai.content3 {
  3649. width: 100%;
  3650. display: flex;
  3651. justify-content: center;
  3652. align-items: center;
  3653. }
  3654. .content3Text {
  3655. background-image: url("@/assets/img/AIchat/边框.png");
  3656. background-repeat: no-repeat;
  3657. background-size: 100% 100%;
  3658. width: 50vw;
  3659. min-width: 350px;
  3660. /* height: 20vw; */
  3661. /* max-height: 400px; */
  3662. padding: 5% 0px;
  3663. }
  3664. .text3 {
  3665. /* font-weight: bold; */
  3666. /* margin-left: 6%; */
  3667. /* margin-bottom: 10px; */
  3668. margin: 0px 6% 10px 6%;
  3669. font-size: 20px;
  3670. }
  3671. .message-bubble.ai.mianze {
  3672. width: 100%;
  3673. text-align: center;
  3674. font-weight: bold;
  3675. font-size: 24px;
  3676. border-radius: 0px 0px 10px 10px;
  3677. }
  3678. .kline-container {
  3679. margin-top: 10px;
  3680. /* 最小高度 */
  3681. min-height: 320px;
  3682. /* 视口高度单位 */
  3683. height: 40vh;
  3684. width: 50vw;
  3685. }
  3686. @media (max-width: 768px) {
  3687. .gif-area {
  3688. padding: 40px 0px;
  3689. position: relative;
  3690. /* height: 30vh; */
  3691. display: flex;
  3692. flex-direction: column;
  3693. justify-content: center;
  3694. align-items: center;
  3695. flex-shrink: 0;
  3696. }
  3697. .logo1 {
  3698. max-width: 350px;
  3699. min-width: 200px;
  3700. width: 15%;
  3701. scale: 0.8;
  3702. }
  3703. .logo2 {
  3704. margin-top: 20px;
  3705. max-width: 350px;
  3706. min-width: 200px;
  3707. width: 80%;
  3708. /* position: relative; */
  3709. }
  3710. .kline-container {
  3711. min-width: 75vw;
  3712. }
  3713. .content1Text {
  3714. width: 77vw;
  3715. min-width: 0px;
  3716. /* height: 20vw; */
  3717. /* min-height: 150px; */
  3718. }
  3719. .date {
  3720. font-size: 14px;
  3721. text-align: end;
  3722. }
  3723. .text1 {
  3724. font-size: 20px;
  3725. }
  3726. .content2chart {
  3727. background-image: url("@/assets/img/AIchat/new-app-bgc.png") !important;
  3728. height: 100vw;
  3729. }
  3730. .img1Bk {
  3731. width: 77vw;
  3732. min-width: 0px;
  3733. /* height: 20vw; */
  3734. /* min-height: 150px; */
  3735. }
  3736. .content3Text {
  3737. width: 77vw;
  3738. min-width: 0px;
  3739. /* height: 20vw; */
  3740. /* min-height: 150px; */
  3741. }
  3742. .text3 {
  3743. font-size: 20px;
  3744. }
  3745. .message-bubble.ai.mianze {
  3746. font-size: 18px;
  3747. }
  3748. .back-to-top {
  3749. left: calc(100% - 65px) !important;
  3750. width: 45px !important;
  3751. height: 45px !important;
  3752. }
  3753. }
  3754. .kline-container .chart-mount-point {
  3755. display: flex;
  3756. justify-content: center;
  3757. align-items: center;
  3758. height: 80%;
  3759. width: 90%;
  3760. }
  3761. .kline-container .chart-mount-pointJN {
  3762. display: flex;
  3763. justify-content: center;
  3764. align-items: center;
  3765. height: 100%;
  3766. width: 100%;
  3767. }
  3768. /* AI消息容器样式 */
  3769. .ai-message-container {
  3770. display: flex;
  3771. align-items: center;
  3772. gap: 10px;
  3773. margin-right: auto;
  3774. /* max-width: 80%; */
  3775. }
  3776. /* 思考过程动图样式 */
  3777. .thinking-gif {
  3778. width: 40px;
  3779. height: 40px;
  3780. object-fit: contain;
  3781. margin-top: 5px;
  3782. border-radius: 8px;
  3783. animation: float 2s ease-in-out infinite;
  3784. }
  3785. @keyframes float {
  3786. 0%,
  3787. 100% {
  3788. transform: translateY(0px);
  3789. }
  3790. 50% {
  3791. transform: translateY(-5px);
  3792. }
  3793. }
  3794. /* AI消息内容样式 */
  3795. .ai-message-content {
  3796. display: flex;
  3797. align-items: center;
  3798. /* white-space: nowrap; */
  3799. width: fit-content;
  3800. overflow: visible;
  3801. }
  3802. .fourStep {
  3803. white-space: nowrap;
  3804. }
  3805. @media only screen and (max-width: 480px) {
  3806. .back-to-top {
  3807. left: calc(100% - 60px) !important;
  3808. width: 40px !important;
  3809. height: 40px !important;
  3810. }
  3811. .back-to-top svg {
  3812. width: 20px;
  3813. height: 20px;
  3814. }
  3815. }
  3816. </style>