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.

5036 lines
140 KiB

2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
1 month ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
  1. <template>
  2. <!-- 顶部锚点 -->
  3. <div id="top-anchor" class="top-anchor"></div>
  4. <!-- 主容器包含对话框和main容器 -->
  5. <div class="page-container">
  6. <!-- 对话框区域 -->
  7. <div class="ai-emotion-container" ref="userInputDisplayRef">
  8. <!-- 金轮 -->
  9. <div class="golden-wheel">
  10. <img
  11. src="@/assets/img/AiEmotion/金轮.png"
  12. class="golden-wheel-img"
  13. alt="金轮图标"
  14. :class="{ 'rotating-image': isRotating }"
  15. />
  16. </div>
  17. <!-- 对话消息显示区域 -->
  18. <div
  19. class="conversation-area"
  20. v-if="messages.length > 0 && !isHistoryMode"
  21. >
  22. <div class="message-list">
  23. <div
  24. v-for="(message, index) in messages"
  25. :key="index"
  26. class="message-item"
  27. :class="{
  28. 'user-message-item': message.sender === 'user',
  29. 'ai-message-item': message.sender === 'ai',
  30. }"
  31. >
  32. <!-- 用户消息 -->
  33. <div v-if="message.sender === 'user'" class="user-message-wrapper">
  34. <div class="message-bubble user-message">
  35. {{ message.text }}
  36. </div>
  37. </div>
  38. <!-- AI消息包括思考过程 -->
  39. <div v-else class="ai-message-wrapper">
  40. <div class="ai-message-container">
  41. <img
  42. v-if="message.gif"
  43. :src="message.gif"
  44. alt="思考过程"
  45. class="thinking-gif"
  46. />
  47. <div class="message-bubble ai-message">
  48. <div v-if="message.flag">
  49. <span>{{ message.text }}</span>
  50. <span class="loading-dots">
  51. <span class="dot">.</span>
  52. <span class="dot">.</span>
  53. <span class="dot">.</span>
  54. <span class="dot">.</span>
  55. <span class="dot">.</span>
  56. <span class="dot">.</span>
  57. </span>
  58. </div>
  59. <div v-else>{{ message.text }}</div>
  60. </div>
  61. </div>
  62. </div>
  63. </div>
  64. </div>
  65. </div>
  66. </div>
  67. <!-- 加载提示 -->
  68. <div v-if="isLoading" class="loading-container">
  69. <div class="loading-content">
  70. <div class="loading-spinner"></div>
  71. <div class="loading-text">AI情绪大模型正在努力为您加载请稍候...</div>
  72. </div>
  73. </div>
  74. <!-- main容器区域 -->
  75. <!-- 移除股票标签页改为对话形式展示 -->
  76. <!-- 渲染整个页面 - 遍历过滤后的股票列表显示所有股票 -->
  77. <div
  78. class="master"
  79. v-for="(stock, stockIndex) in filteredStockList"
  80. :key="`stock-${stockIndex}-${stock.timestamp}`"
  81. v-if="isPageLoaded"
  82. >
  83. <!-- 对应股票的消息显示区域 -->
  84. <div class="user-input-display">
  85. <div class="message-container">
  86. <!-- 显示该股票对应的用户输入内容 -->
  87. <div class="user-message-container">
  88. <div class="user-content">
  89. <img
  90. :src="
  91. isVoice && getStockAudioState(stock).isPlaying
  92. ? voice
  93. : voiceNoActive
  94. "
  95. class="user-message-speaker"
  96. :class="{
  97. 'speaker-active':
  98. isVoice && getStockAudioState(stock).isPlaying,
  99. }"
  100. @click="() => toggleVoiceForUser(stock)"
  101. alt="喇叭"
  102. />
  103. <div class="message-bubble user-message">
  104. {{ stock.queryText }}
  105. </div>
  106. </div>
  107. <div class="user-sendTime">
  108. {{ moment(stock.timestamp).format("YYYY-MM-DD HH:mm:ss") }}
  109. </div>
  110. </div>
  111. </div>
  112. </div>
  113. <div class="main">
  114. <div class="main-content-wrapper">
  115. <!-- 四维矩阵图 -->
  116. <div class="matrix-header">
  117. <!-- <img class="item" :src="item" alt="思维矩阵图片" /> -->
  118. <div class="market-temperature-label">
  119. {{ stock.stockInfo.name
  120. }}{{ stock.stockInfo.name ? "量子四维矩阵图" : "" }}
  121. </div>
  122. <div class="market-temperature-value">
  123. {{ getDisplayDate(stock) }}
  124. </div>
  125. </div>
  126. <div
  127. class="market-temperature-icon"
  128. v-if="chartVisibility.marketTemperature"
  129. >
  130. <img src="@/assets/img/AiEmotion/L1.png" alt="情绪监控图标" />
  131. </div>
  132. <!-- 温度计图表 -->
  133. <div
  134. class="market-temperature-section"
  135. v-if="chartVisibility.marketTemperature"
  136. >
  137. <div class="temperature-content">
  138. <div class="content1">
  139. <img src="@/assets/img/AiEmotion/温度计.png" alt="温度计图标" />
  140. <span class="matrix-main-title">股市温度计</span>
  141. </div>
  142. <div class="temperature-display">
  143. <div class="temperature-cold">
  144. 股票温度{{ getStockData2(stock) ?? "NA" }}
  145. </div>
  146. <div class="temperature-hot">
  147. 市场温度{{ getStockData1(stock) }}
  148. </div>
  149. </div>
  150. </div>
  151. <marketTemperature
  152. :ref="(el) => (marketTemperatureRef[stockIndex] = el)"
  153. :companyName="stock.stockInfo.name"
  154. :stockCode="stock.stockInfo.code"
  155. />
  156. </div>
  157. </div>
  158. <div class="emotion-decoder-icon" v-if="chartVisibility.emotionDecod">
  159. <img src="@/assets/img/AiEmotion/L2.png" alt="情绪解码图标" />
  160. </div>
  161. <!-- 情绪解码器图表 -->
  162. <div
  163. class="emotion-decoder-section"
  164. v-if="chartVisibility.emotionDecod"
  165. >
  166. <div class="emotion-decoder-header">
  167. <img
  168. src="@/assets/img/AiEmotion/emotionDecod.png"
  169. alt="情绪解码器图标"
  170. />
  171. <span class="emotion-decoder-text">情绪解码器</span>
  172. </div>
  173. <div class="emotion-decoder-content">
  174. <emotionDecod
  175. :ref="(el) => (emotionDecodRef[stockIndex] = el)"
  176. ></emotionDecod>
  177. </div>
  178. </div>
  179. <div
  180. class="bottom-radar-icon"
  181. v-if="chartVisibility.emotionalBottomRadar"
  182. >
  183. <img src="@/assets/img/AiEmotion/L3.png" alt="情绪推演图标" />
  184. </div>
  185. <!-- 情绪探底雷达图表 -->
  186. <div
  187. class="bottom-radar-section"
  188. v-if="chartVisibility.emotionalBottomRadar"
  189. >
  190. <div class="bottom-radar-header">
  191. <img src="@/assets/img/AiEmotion/探底雷达.png" alt="探底雷达图表" />
  192. <span class="bottom-radar-text">情绪探底雷达</span>
  193. </div>
  194. <div class="bottom-radar-content">
  195. <emotionalBottomRadar
  196. :ref="(el) => (emotionalBottomRadarRef[stockIndex] = el)"
  197. ></emotionalBottomRadar>
  198. </div>
  199. </div>
  200. <div
  201. class="energy-converter-icon"
  202. v-if="chartVisibility.emoEnergyConverter"
  203. >
  204. <img src="@/assets/img/AiEmotion/L4.png" alt="情绪套利" />
  205. </div>
  206. <!-- 情绪能量转化器图表 -->
  207. <div
  208. class="energy-converter-section"
  209. v-if="chartVisibility.emoEnergyConverter"
  210. >
  211. <div class="energy-converter-header">
  212. <img
  213. src="@/assets/img/AiEmotion/能量转化器.png"
  214. alt="能量转化器图标"
  215. />
  216. <span class="energy-converter-text">情绪能量转化器</span>
  217. </div>
  218. <div class="energy-converter-content">
  219. <emoEnergyConverter
  220. :ref="(el) => (emoEnergyConverterRef[stockIndex] = el)"
  221. ></emoEnergyConverter>
  222. </div>
  223. </div>
  224. <!-- 核心看点 -->
  225. <div class="core-highlights-header">
  226. <img src="@/assets/img/AiEmotion/核心看点.png" alt="核心看点字样" />
  227. </div>
  228. <div class="bk-image">
  229. <div class="text-container">
  230. <p>
  231. <span class="title">情绪监控-金融宇宙的量子检测网络</span>
  232. <span class="content"
  233. >核心任务:构建全市场情绪引力场雷达实时监测资金流向和情绪波动</span
  234. >
  235. </p>
  236. <p>
  237. <span class="title">情绪解码-主力思维的神经破译矩阵</span>
  238. <span class="content"
  239. >核心任务:解构资金行为的量子密码破译主力操盘意图和策略布局</span
  240. >
  241. </p>
  242. <p>
  243. <span class="title">情绪推演-未来战争的时空推演舱</span>
  244. <span class="content"
  245. >核心任务:基于情绪数据推演未来走势预测市场转折点和机会窗口</span
  246. >
  247. </p>
  248. <p>
  249. <span class="title">情绪套利-财富裂变的粒子对撞机</span>
  250. <span class="content"
  251. >核心任务:将情绪差转化为收益粒子流实现情绪能量的价值转换</span
  252. >
  253. </p>
  254. </div>
  255. </div>
  256. <!-- 核心逻辑 -->
  257. <div class="core-logic-header">
  258. <img src="@/assets/img/AiEmotion/核心逻辑.png" alt="核心逻辑字样" />
  259. </div>
  260. <div class="decision-tree-section">
  261. <div class="lz-img">
  262. <img src="@/assets/img/AiEmotion/量子神经决策树.png" alt="树标题" />
  263. </div>
  264. <div class="scaled-img">
  265. <!-- <img src="@/assets/img/AiEmotion/tree02.jpg" alt="树图片"> -->
  266. </div>
  267. </div>
  268. <!-- 场景应用 -->
  269. <div class="scenario-application-section" ref="scenarioApplicationRef">
  270. <img src="@/assets/img/AiEmotion/场景应用.png" alt="场景应用标题" />
  271. <div class="bk-image">
  272. <div class="conclusion-container">
  273. <!-- 使用打字机效果显示结论内容 -->
  274. <div class="conclusion-item" v-if="moduleVisibility.one">
  275. <h4 class="conclusion-title">{{ displayedTitles.one }}</h4>
  276. <p class="conclusion-text" v-if="displayedTexts.one1">
  277. {{ displayedTexts.one1 }}
  278. </p>
  279. <p class="conclusion-text" v-if="displayedTexts.one2">
  280. {{ displayedTexts.one2 }}
  281. </p>
  282. </div>
  283. <div class="conclusion-item" v-if="moduleVisibility.two">
  284. <h4 class="conclusion-title">{{ displayedTitles.two }}</h4>
  285. <p class="conclusion-text">{{ displayedTexts.two }}</p>
  286. </div>
  287. <div class="conclusion-item" v-if="moduleVisibility.three">
  288. <h4 class="conclusion-title">{{ displayedTitles.three }}</h4>
  289. <p class="conclusion-text">{{ displayedTexts.three }}</p>
  290. </div>
  291. <div class="conclusion-item" v-if="moduleVisibility.four">
  292. <h4 class="conclusion-title">{{ displayedTitles.four }}</h4>
  293. <p class="conclusion-text">{{ displayedTexts.four }}</p>
  294. </div>
  295. <!-- AI生成内容免责声明 -->
  296. <div class="disclaimer-item" v-if="moduleVisibility.disclaimer">
  297. <p class="disclaimer-text">{{ displayedTexts.disclaimer }}</p>
  298. </div>
  299. </div>
  300. <div
  301. class="conclusion-placeholder"
  302. v-if="
  303. !moduleVisibility.one &&
  304. !moduleVisibility.two &&
  305. !moduleVisibility.three &&
  306. !moduleVisibility.four
  307. "
  308. >
  309. <p>等待股票分析结论...</p>
  310. </div>
  311. </div>
  312. </div>
  313. <!-- 返回顶部按钮 -->
  314. <div class="back-to-top" @click="scrollToTop" v-show="isPageLoaded">
  315. <svg
  316. width="24"
  317. height="24"
  318. viewBox="0 0 24 24"
  319. fill="none"
  320. xmlns="http://www.w3.org/2000/svg"
  321. >
  322. <path
  323. d="M12 4L12 20M12 4L6 10M12 4L18 10"
  324. stroke="currentColor"
  325. stroke-width="2"
  326. stroke-linecap="round"
  327. stroke-linejoin="round"
  328. />
  329. </svg>
  330. </div>
  331. </div>
  332. </div>
  333. </div>
  334. </template>
  335. <script setup>
  336. import { ref, computed, watch, nextTick, onMounted, onUnmounted } from "vue";
  337. import { getReplyAPI, getConclusionAPI } from "@/api/AiEmotionApi.js"; // 导入工作流接口方法
  338. import axios from "axios";
  339. import moment from "moment";
  340. import item from "@/assets/img/AiEmotion/bk01.png"; // 导入思维矩阵图片
  341. import emotionDecod from "@/views/components/emotionDecod.vue"; // 导入情绪解码组件
  342. import emotionalBottomRadar from "@/views/components/emotionalBottomRadar.vue"; // 导入情绪探底雷达图组件
  343. import emoEnergyConverter from "@/views/components/emoEnergyConverter.vue"; // 导入情绪能量转化器组件
  344. import marketTemperature from "@/views/components/marketTemperature.vue";
  345. import StockTabs from "@/views/components/StockTabs.vue"; // 导入股票标签页组件
  346. import blueBorderImg from "@/assets/img/AiEmotion/blueBorder.png"; //导入蓝色背景框图片
  347. import { ElMessage } from "element-plus"; // 接口失败提示已改为对话形式,保留用于输入验证
  348. import { useEmotionStore } from "@/store/emotion"; // 导入Pinia store
  349. import { useEmotionAudioStore } from "@/store/emotionAudio.js"; // 导入音频store
  350. import { useChatStore } from "@/store/chat.js"; // 导入聊天store
  351. // 导入思考过程GIF
  352. import thinkingGif from "@/assets/img/gif/思考.gif";
  353. import analyzeGif from "@/assets/img/gif/解析.gif";
  354. import generateGif from "@/assets/img/gif/生成.gif";
  355. import getCountAll from "../assets/img/homePage/get-count-all.png";
  356. import voice from "../assets/img/homePage/tail/voice.png";
  357. import voiceNoActive from "../assets/img/homePage/tail/voice-no-active.png";
  358. import { Howl, Howler } from "howler"; // 导入音频播放库
  359. import { reactive } from "vue";
  360. import { marked } from "marked"; // 引入marked库
  361. import { useUserStore } from "../store/userPessionCode";
  362. const APIurl = import.meta.env.VITE_APP_API_BASE_URL;
  363. // 使用Pinia store
  364. const emotionStore = useEmotionStore();
  365. const emotionAudioStore = useEmotionAudioStore();
  366. // 语音播放控制函数
  367. const toggleVoiceForUser = (stock) => {
  368. if (!emotionAudioStore.isVoiceEnabled) {
  369. // 如果语音功能关闭,先开启语音功能
  370. emotionAudioStore.toggleVoice();
  371. } else {
  372. // 获取该股票的结论数据和当前状态
  373. const stockConclusion = getStockConclusion(stock);
  374. const currentState = getStockAudioState(stock);
  375. // 检查是否有任何音频正在播放(包括全局播放状态和当前股票状态)
  376. const isAnyAudioPlaying =
  377. emotionAudioStore.isPlaying || currentState.isPlaying;
  378. // 如果当前点击的股票正在播放,则暂停
  379. if (currentState.isPlaying) {
  380. console.log("暂停当前股票音频:", stock.stockInfo?.name);
  381. // 暂停音频而不是停止
  382. if (emotionAudioStore.nowSound && emotionAudioStore.nowSound.playing()) {
  383. emotionAudioStore.nowSound.pause();
  384. emotionAudioStore.isPaused = true;
  385. emotionAudioStore.isPlaying = false;
  386. }
  387. setStockAudioState(stock, { isPlaying: false, isPaused: true });
  388. } else if (currentState.isPaused) {
  389. // 如果当前股票处于暂停状态,则继续播放
  390. console.log("继续播放当前股票音频:", stock.stockInfo?.name);
  391. if (emotionAudioStore.nowSound) {
  392. emotionAudioStore.nowSound.play();
  393. emotionAudioStore.isPaused = false;
  394. emotionAudioStore.isPlaying = true;
  395. }
  396. setStockAudioState(stock, { isPlaying: true, isPaused: false });
  397. } else {
  398. // 如果有其他音频正在播放,先停止
  399. if (isAnyAudioPlaying) {
  400. console.log(
  401. "停止其他正在播放的音频,准备播放新音频:",
  402. stock.stockInfo?.name
  403. );
  404. stopAudio();
  405. emotionAudioStore.resetAudioState();
  406. }
  407. // 清除所有股票的播放状态
  408. clearAllStockAudioStates();
  409. // 如果有音频数据,开始播放
  410. if (
  411. stockConclusion &&
  412. (stockConclusion.one1_url ||
  413. stockConclusion.two_url ||
  414. stockConclusion.three_url ||
  415. stockConclusion.four_url)
  416. ) {
  417. console.log("开始播放股票音频:", stock.stockInfo?.name);
  418. setStockAudioState(stock, { isPlaying: true, isPaused: false });
  419. // 播放音频队列
  420. playAudioQueue(stockConclusion, false, () => {
  421. // 音频播放完成后重置状态
  422. setStockAudioState(stock, { isPlaying: false, isPaused: false });
  423. });
  424. } else {
  425. console.log("该股票没有可播放的音频数据");
  426. }
  427. }
  428. }
  429. };
  430. // 计算属性:判断语音是否启用
  431. const isVoice = computed(() => {
  432. return emotionAudioStore.isVoiceEnabled;
  433. });
  434. const chatStore = useChatStore();
  435. // 获取权限
  436. const userStore = useUserStore();
  437. // 处理refuse数据的函数
  438. function processRefuseMessage(refuseData) {
  439. if (!refuseData) return "未知错误";
  440. // 如果refuse数据包含Markdown格式,进行转换
  441. try {
  442. // 配置marked选项
  443. marked.setOptions({
  444. breaks: true, // 支持换行符转换为 <br>
  445. gfm: true, // 启用 GitHub Flavored Markdown
  446. sanitize: false, // 不清理 HTML
  447. smartLists: true, // 智能列表
  448. smartypants: true, // 智能标点符号
  449. xhtml: false, // 不使用 XHTML 输出
  450. });
  451. // 将Markdown转换为HTML
  452. const htmlContent = marked(refuseData);
  453. // 移除HTML标签,只保留纯文本用于ElMessage显示
  454. const tempDiv = document.createElement("div");
  455. tempDiv.innerHTML = htmlContent;
  456. return tempDiv.textContent || tempDiv.innerText || refuseData;
  457. } catch (error) {
  458. console.error("处理refuse消息时出错:", error);
  459. return refuseData;
  460. }
  461. }
  462. // 组件引用 - 修改为数组形式支持多个股票
  463. const marketTemperatureRef = ref([]); // 引用市场温度计组件数组
  464. const emoEnergyConverterRef = ref([]);
  465. const emotionDecodRef = ref([]);
  466. const emotionalBottomRadarRef = ref([]);
  467. const userInputDisplayRef = ref(null); //消息区域的引用
  468. // 响应式数据
  469. const messages = ref([]);
  470. // 从emotion store中恢复对话记录
  471. const loadConversationsFromStore = () => {
  472. const storedConversations = emotionStore.getConversations();
  473. messages.value = storedConversations.map((conv) => ({
  474. sender: conv.sender,
  475. text: conv.text,
  476. }));
  477. };
  478. // 记录已经添加到对话中的股票,避免重复添加
  479. const addedStocks = ref(new Set());
  480. // 从stockList生成对话历史
  481. const loadConversationsFromStockList = () => {
  482. // 检查是否有新的股票需要添加到对话中
  483. emotionStore.stockList.forEach((stock) => {
  484. const stockKey = `${stock.stockInfo.code}_${stock.timestamp}`;
  485. // 如果这个股票还没有添加到对话中
  486. if (!addedStocks.value.has(stockKey)) {
  487. // 检查messages中是否已经存在相同的用户消息
  488. const existingMessage = messages.value.find(
  489. (msg) => msg.sender === "user" && msg.text === stock.queryText
  490. );
  491. // 只有当messages中不存在相同消息时才添加
  492. if (!existingMessage) {
  493. // 只添加用户输入消息,不添加AI回复
  494. const userMessage = {
  495. sender: "user",
  496. text: stock.queryText,
  497. };
  498. messages.value.push(userMessage);
  499. // 只将用户消息添加到emotion store中(如果store中也不存在)
  500. const storeConversations = emotionStore.getConversations();
  501. const existingInStore = storeConversations.find(
  502. (conv) => conv.sender === "user" && conv.text === stock.queryText
  503. );
  504. if (!existingInStore) {
  505. emotionStore.addConversation(userMessage);
  506. }
  507. }
  508. // 将这个股票标记为已添加
  509. addedStocks.value.add(stockKey);
  510. }
  511. });
  512. };
  513. // 清空对话记录
  514. const clearConversations = () => {
  515. messages.value = [];
  516. emotionStore.clearConversations();
  517. // 清空已添加股票的记录
  518. addedStocks.value.clear();
  519. };
  520. // 添加股票数据的包装方法
  521. const addStock = (stockData) => {
  522. console.log("AiEmotion组件接收到股票数据:", stockData);
  523. // 设置为历史记录模式,并重置用户主动搜索标志
  524. isHistoryMode.value = true;
  525. isUserInitiated.value = false;
  526. // 1. 先清空页面显示节点和stockList中的数据
  527. isPageLoaded.value = false; // 隐藏页面显示节点
  528. emotionStore.clearAllStocks(); // 清空stockList中的数据
  529. emotionStore.clearConversations(); // 清空对话记录
  530. messages.value = []; // 清空页面对话显示
  531. // 清理已添加股票的记录
  532. addedStocks.value.clear();
  533. // 停止音频播放和清理状态
  534. stopAudio();
  535. audioUrl.value = "";
  536. emotionAudioStore.resetAudioState();
  537. clearTypewriterTimers();
  538. hasTriggeredAudio.value = false;
  539. hasTriggeredTypewriter.value = false;
  540. stockTypewriterShown.value.clear();
  541. stockAudioPlayed.value.clear();
  542. // 清理显示的文本和标题
  543. displayedTexts.value = {
  544. one1: "",
  545. one2: "",
  546. two: "",
  547. three: "",
  548. four: "",
  549. disclaimer: "",
  550. };
  551. displayedTitles.value = {
  552. one: "",
  553. two: "",
  554. three: "",
  555. four: "",
  556. };
  557. // 隐藏所有模块
  558. moduleVisibility.value = {
  559. one: false,
  560. two: false,
  561. three: false,
  562. four: false,
  563. disclaimer: false,
  564. };
  565. // 隐藏所有图表组件
  566. chartVisibility.value = {
  567. marketTemperature: false,
  568. emotionDecod: false,
  569. emotionalBottomRadar: false,
  570. emoEnergyConverter: false,
  571. };
  572. // 2. 将新的数据存储到stockList中
  573. emotionStore.addStock(stockData);
  574. // 3. 设置页面为已加载状态,重新渲染页面
  575. isPageLoaded.value = true;
  576. // 4. 立即显示历史记录的结论文本
  577. if (stockData.conclusionData) {
  578. try {
  579. const conclusion =
  580. typeof stockData.conclusionData === "object"
  581. ? stockData.conclusionData
  582. : JSON.parse(stockData.conclusionData);
  583. displayedTexts.value = {
  584. one1: conclusion.one1 || "",
  585. one2: conclusion.one2 || "",
  586. two: conclusion.two || "",
  587. three: conclusion.three || "",
  588. four: conclusion.four || "",
  589. disclaimer: "该内容由AI生成,请注意甄别",
  590. };
  591. displayedTitles.value = {
  592. one: "L1: 情绪监控",
  593. two: "L2: 情绪解码",
  594. three: "L3: 情绪推演",
  595. four: "L4: 情绪套利",
  596. };
  597. moduleVisibility.value = {
  598. one: !!(conclusion.one1 || conclusion.one2),
  599. two: !!conclusion.two,
  600. three: !!conclusion.three,
  601. four: !!conclusion.four,
  602. disclaimer: true,
  603. };
  604. // 标记该股票已显示过,避免重复触发
  605. const stockCode =
  606. stockData.stockInfo?.code || stockData.stockInfo?.symbol;
  607. if (stockCode) {
  608. stockTypewriterShown.value.set(stockCode, true);
  609. stockAudioPlayed.value.set(stockCode, true);
  610. }
  611. console.log("历史记录结论文本已立即显示:", conclusion);
  612. } catch (error) {
  613. console.error("解析历史记录结论数据失败:", error);
  614. }
  615. }
  616. // 5. 使用nextTick确保DOM更新后启动高度监听器并滚动到底部
  617. nextTick(() => {
  618. // 启动页面高度监听器,实时监听内容变化并自动滚动
  619. startHeightObserver();
  620. // 立即滚动到底部
  621. scrollToBottom();
  622. });
  623. };
  624. // 暴露方法给父组件
  625. defineExpose({
  626. handleSendMessage,
  627. clearConversations,
  628. addStock,
  629. });
  630. const isPageLoaded = ref(false); // 控制页面是否显示
  631. const isHistoryMode = ref(false); // 控制是否为历史记录模式
  632. // const isLoading = ref(false); // 控制加载状态
  633. const isRotating = ref(false); //控制旋转
  634. const version1 = ref(1); // 版本号
  635. const conclusionData = ref(""); // 存储第二个工作流接口返回的结论数据
  636. // 自动滚动相关数据
  637. const isAutoScrolling = ref(false);
  638. const currentSection = ref(0);
  639. const sectionRefs = ref([]);
  640. const scenarioApplicationRef = ref(null); // 场景应用部分的引用
  641. const hasTriggeredAudio = ref(false); // 是否已触发音频播放
  642. const hasTriggeredTypewriter = ref(false); // 是否已触发打字机效果
  643. const intersectionObserver = ref(null); // 存储observer实例
  644. const isUserInitiated = ref(false); // 标记是否为用户主动搜索
  645. // 显示的文本内容(用于打字机效果)
  646. const displayedTexts = ref({
  647. one1: "",
  648. one2: "",
  649. two: "",
  650. three: "",
  651. four: "",
  652. disclaimer: "",
  653. });
  654. // 显示的标题内容(用于打字机效果)
  655. const displayedTitles = ref({
  656. one: "",
  657. two: "",
  658. three: "",
  659. four: "",
  660. });
  661. // 模块显示状态
  662. const moduleVisibility = ref({
  663. one: false,
  664. two: false,
  665. three: false,
  666. four: false,
  667. disclaimer: false,
  668. });
  669. // 图表组件显示状态
  670. const chartVisibility = ref({
  671. marketTemperature: true,
  672. emotionDecod: true,
  673. emotionalBottomRadar: true,
  674. emoEnergyConverter: true,
  675. });
  676. const typewriterTimers = ref([]);
  677. // 记录每个股票是否已经显示过打字机效果
  678. const stockTypewriterShown = ref(new Map());
  679. // 记录每个股票是否已经播放过音频
  680. const stockAudioPlayed = ref(new Map());
  681. // 跟踪每个股票的音频播放状态
  682. const stockAudioStates = ref(new Map());
  683. // 存储当前的完成回调函数
  684. const currentOnCompleteCallback = ref(null);
  685. // 音频播放相关数据
  686. const audioUrl = ref("");
  687. const isAudioPlaying = ref(false);
  688. // 获取股票的音频播放状态
  689. const getStockAudioState = (stock) => {
  690. const stockCode = stock.stockInfo?.code || stock.stockInfo?.symbol;
  691. if (!stockCode) return { isPlaying: false, isPaused: false };
  692. return (
  693. stockAudioStates.value.get(stockCode) || {
  694. isPlaying: false,
  695. isPaused: false,
  696. }
  697. );
  698. };
  699. // 设置股票的音频播放状态
  700. const setStockAudioState = (stock, state) => {
  701. const stockCode = stock.stockInfo?.code || stock.stockInfo?.symbol;
  702. if (!stockCode) return;
  703. stockAudioStates.value.set(stockCode, { ...state });
  704. };
  705. // 清除所有股票的播放状态(当开始播放新音频时)
  706. const clearAllStockAudioStates = () => {
  707. for (const [key, value] of stockAudioStates.value.entries()) {
  708. stockAudioStates.value.set(key, { isPlaying: false, isPaused: false });
  709. }
  710. };
  711. // 返回顶部按钮相关数据
  712. const showBackToTop = ref(false);
  713. // 计算属性 - 从store获取当前股票数据
  714. const currentStock = computed(() => emotionStore.activeStock);
  715. const stockName = computed(() => currentStock.value?.stockInfo.name || "");
  716. const stockCode = computed(
  717. () =>
  718. currentStock.value?.stockInfo.code ||
  719. currentStock.value?.stockInfo.symbol ||
  720. ""
  721. );
  722. const displayDate = computed(() => {
  723. if (!currentStock.value?.apiData) return "";
  724. const lastData = currentStock.value.apiData.GSWDJ?.at(-1);
  725. if (!lastData || !lastData[0]) return "";
  726. const dateStr = lastData[0];
  727. // 假设原格式为 YYYY-MM-DD 或 YYYY/MM/DD
  728. const dateMatch = dateStr.match(/(\d{4})[\-\/](\d{1,2})[\-\/](\d{1,2})/);
  729. if (dateMatch) {
  730. const [, year, month, day] = dateMatch;
  731. // 转换为 DD/MM/YYYY 格式
  732. return `更新时间:${day.padStart(2, "0")}/${month.padStart(
  733. 2,
  734. "0"
  735. )}/${year}`;
  736. }
  737. // 如果不匹配预期格式,返回原始值
  738. return dateStr;
  739. });
  740. const data1 = computed(() => {
  741. if (!currentStock.value?.apiData) return null;
  742. const lastData = currentStock.value.apiData.GSWDJ?.at(-1);
  743. return lastData ? Math.round(lastData[1]) : null;
  744. });
  745. const data2 = computed(() => {
  746. if (!currentStock.value?.apiData) return null;
  747. const lastData = currentStock.value.apiData.GSWDJ?.at(-1);
  748. return lastData ? Math.round(lastData[2]) : null;
  749. });
  750. const currentConclusion = computed(() => {
  751. return currentStock.value?.conclusionData || "";
  752. });
  753. const parsedConclusion = computed(() => {
  754. if (!currentConclusion.value) return null;
  755. // 如果conclusionData已经是对象,直接返回
  756. if (typeof currentConclusion.value === "object") {
  757. return currentConclusion.value;
  758. }
  759. // 如果是字符串,尝试解析JSON
  760. try {
  761. return JSON.parse(currentConclusion.value);
  762. } catch (error) {
  763. console.error("解析结论数据失败:", error);
  764. return null;
  765. }
  766. });
  767. // 多股票数据显示的计算属性
  768. // 过滤和排序后的股票列表
  769. const filteredStockList = computed(() => {
  770. return emotionStore.stockList
  771. .filter((stock) => {
  772. // 过滤掉数据不完整的股票
  773. return stock.stockInfo?.name && stock.apiData && stock.queryText;
  774. })
  775. .sort((a, b) => {
  776. // 按时间戳降序排序,最新的在前
  777. return new Date(a.timestamp) - new Date(b.timestamp);
  778. });
  779. });
  780. // 辅助函数:获取股票的显示日期
  781. const getDisplayDate = (stock) => {
  782. if (!stock?.apiData) return "";
  783. const lastData = stock.apiData.GSWDJ?.at(-1);
  784. if (!lastData || !lastData[0]) return "";
  785. const dateStr = lastData[0];
  786. // 假设原格式为 YYYY-MM-DD 或 YYYY/MM/DD
  787. const dateMatch = dateStr.match(/(\d{4})[\-\/](\d{1,2})[\-\/](\d{1,2})/);
  788. if (dateMatch) {
  789. const [, year, month, day] = dateMatch;
  790. // 转换为 DD/MM/YYYY 格式
  791. return `更新时间:${day.padStart(2, "0")}/${month.padStart(
  792. 2,
  793. "0"
  794. )}/${year}`;
  795. }
  796. // 如果不匹配预期格式,返回原始值
  797. return dateStr;
  798. };
  799. // 辅助函数:获取股票的市场温度数据
  800. const getStockData1 = (stock) => {
  801. if (!stock?.apiData) return null;
  802. const lastData = stock.apiData.GSWDJ?.at(-1);
  803. return lastData ? Math.round(lastData[1]) : null;
  804. };
  805. // 辅助函数:获取股票的股票温度数据
  806. const getStockData2 = (stock) => {
  807. if (!stock?.apiData) return null;
  808. const lastData = stock.apiData.GSWDJ?.at(-1);
  809. return lastData ? Math.round(lastData[2]) : null;
  810. };
  811. // 辅助函数:获取股票的结论数据
  812. const getStockConclusion = (stock) => {
  813. if (!stock?.conclusionData) return null;
  814. // 如果conclusionData已经是对象,直接返回
  815. if (typeof stock.conclusionData === "object") {
  816. return stock.conclusionData;
  817. }
  818. // 如果是字符串,尝试解析JSON
  819. try {
  820. return JSON.parse(stock.conclusionData);
  821. } catch (error) {
  822. console.error("解析股票结论数据失败:", error);
  823. return null;
  824. }
  825. };
  826. // 监听股票列表变化,当列表为空时隐藏页面数据
  827. watch(
  828. () => emotionStore.stockList,
  829. (newStockList) => {
  830. if (newStockList.length === 0) {
  831. // 当股票列表为空时,隐藏页面数据
  832. isPageLoaded.value = false;
  833. // 停止音频播放
  834. stopAudio();
  835. // 清理音频URL
  836. audioUrl.value = "";
  837. emotionAudioStore.resetAudioState();
  838. // 清理打字机效果
  839. clearTypewriterTimers();
  840. // 重置所有状态
  841. hasTriggeredAudio.value = false;
  842. hasTriggeredTypewriter.value = false;
  843. stockTypewriterShown.value.clear();
  844. stockAudioPlayed.value.clear();
  845. // 清理已添加股票的记录
  846. addedStocks.value.clear();
  847. // 清理显示的文本和标题
  848. displayedTexts.value = {
  849. one1: "",
  850. one2: "",
  851. two: "",
  852. three: "",
  853. four: "",
  854. disclaimer: "",
  855. };
  856. displayedTitles.value = {
  857. one: "",
  858. two: "",
  859. three: "",
  860. four: "",
  861. };
  862. // 隐藏所有模块
  863. moduleVisibility.value = {
  864. one: false,
  865. two: false,
  866. three: false,
  867. four: false,
  868. disclaimer: false,
  869. };
  870. // 隐藏所有图表组件
  871. chartVisibility.value = {
  872. marketTemperature: false,
  873. emotionDecod: false,
  874. emotionalBottomRadar: false,
  875. emoEnergyConverter: false,
  876. };
  877. console.log("股票列表已清空,页面数据已隐藏");
  878. } else {
  879. // 当stockList有数据时,更新对话记录
  880. loadConversationsFromStockList();
  881. }
  882. },
  883. { deep: true }
  884. );
  885. // 监听当前股票变化,重新渲染图表
  886. watch(
  887. currentStock,
  888. (newStock) => {
  889. if (newStock && newStock.apiData) {
  890. // 页面加载状态现在由 handleSendMessage 统一控制
  891. // 停止当前播放的音频
  892. stopAudio();
  893. // 清理音频URL,确保不会播放之前股票的音频
  894. audioUrl.value = "";
  895. // 清理store中的音频URL,确保不会播放之前股票的音频
  896. emotionAudioStore.resetAudioState();
  897. // 清理正在进行的打字机效果定时器
  898. clearTypewriterTimers();
  899. // 重置触发状态,让每个股票都能独立触发效果
  900. hasTriggeredAudio.value = false;
  901. hasTriggeredTypewriter.value = false;
  902. // 获取股票代码作为唯一标识
  903. const stockCode = newStock.stockInfo?.code || newStock.stockInfo?.symbol;
  904. // 检查该股票是否已经显示过打字机效果
  905. if (stockCode && stockTypewriterShown.value.has(stockCode)) {
  906. // 如果已经显示过,直接显示完整文本和标题
  907. if (newStock.conclusionData) {
  908. try {
  909. // 如果conclusionData已经是对象,直接使用;否则解析JSON
  910. const conclusion =
  911. typeof newStock.conclusionData === "object"
  912. ? newStock.conclusionData
  913. : JSON.parse(newStock.conclusionData);
  914. displayedTexts.value = {
  915. one1: conclusion.one1 || "",
  916. one2: conclusion.one2 || "",
  917. two: conclusion.two || "",
  918. three: conclusion.three || "",
  919. four: conclusion.four || "",
  920. disclaimer: "该内容由AI生成,请注意甄别",
  921. };
  922. displayedTitles.value = {
  923. one: "L1: 情绪监控",
  924. two: "L2: 情绪解码",
  925. three: "L3: 情绪推演",
  926. four: "L4: 情绪套利",
  927. };
  928. // 显示所有有内容的模块
  929. moduleVisibility.value = {
  930. one: !!(conclusion.one1 || conclusion.one2),
  931. two: !!conclusion.two,
  932. three: !!conclusion.three,
  933. four: !!conclusion.four,
  934. disclaimer: true,
  935. };
  936. // 提取音频URL但不自动播放,等待用户手动点击
  937. let voiceUrl = null;
  938. // 优先使用one1_url,如果没有则尝试其他音频URL
  939. if (conclusion.one1_url) {
  940. voiceUrl = conclusion.one1_url
  941. .toString()
  942. .trim()
  943. .replace(/[`\s]/g, "");
  944. } else if (conclusion.one2_url) {
  945. voiceUrl = conclusion.one2_url
  946. .toString()
  947. .trim()
  948. .replace(/[`\s]/g, "");
  949. } else if (conclusion.two_url) {
  950. voiceUrl = conclusion.two_url
  951. .toString()
  952. .trim()
  953. .replace(/[`\s]/g, "");
  954. } else if (conclusion.three_url) {
  955. voiceUrl = conclusion.three_url
  956. .toString()
  957. .trim()
  958. .replace(/[`\s]/g, "");
  959. } else if (conclusion.four_url) {
  960. voiceUrl = conclusion.four_url
  961. .toString()
  962. .trim()
  963. .replace(/[`\s]/g, "");
  964. } else if (conclusion.url) {
  965. voiceUrl = conclusion.url.toString().trim().replace(/[`\s]/g, "");
  966. } else if (conclusion.audioUrl) {
  967. voiceUrl = conclusion.audioUrl
  968. .toString()
  969. .trim()
  970. .replace(/[`\s]/g, "");
  971. } else if (conclusion.voice_url) {
  972. voiceUrl = conclusion.voice_url
  973. .toString()
  974. .trim()
  975. .replace(/[`\s]/g, "");
  976. } else if (conclusion.audio) {
  977. voiceUrl = conclusion.audio
  978. .toString()
  979. .trim()
  980. .replace(/[`\s]/g, "");
  981. } else if (conclusion.tts_url) {
  982. voiceUrl = conclusion.tts_url
  983. .toString()
  984. .trim()
  985. .replace(/[`\s]/g, "");
  986. }
  987. if (voiceUrl && voiceUrl.startsWith("http")) {
  988. console.log(
  989. "切换到已显示股票,准备音频URL但不自动播放:",
  990. voiceUrl
  991. );
  992. audioUrl.value = voiceUrl;
  993. // 同时更新store中的音频URL
  994. emotionAudioStore.setCurrentAudioUrl(voiceUrl);
  995. // 不自动播放,等待用户手动点击
  996. }
  997. } catch (error) {
  998. console.error("解析股票结论数据失败:", error);
  999. }
  1000. }
  1001. } else {
  1002. // 如果没有显示过,清空显示文本,等待打字机效果
  1003. displayedTexts.value = {
  1004. one1: "",
  1005. one2: "",
  1006. two: "",
  1007. three: "",
  1008. four: "",
  1009. disclaimer: "",
  1010. };
  1011. displayedTitles.value = {
  1012. one: "",
  1013. two: "",
  1014. three: "",
  1015. four: "",
  1016. };
  1017. moduleVisibility.value = {
  1018. one: false,
  1019. two: false,
  1020. three: false,
  1021. four: false,
  1022. disclaimer: false,
  1023. };
  1024. // 即使没有显示过,也需要设置音频URL以便用户手动播放
  1025. if (newStock.conclusionData) {
  1026. try {
  1027. // 如果conclusionData已经是对象,直接使用;否则解析JSON
  1028. const conclusion =
  1029. typeof newStock.conclusionData === "object"
  1030. ? newStock.conclusionData
  1031. : JSON.parse(newStock.conclusionData);
  1032. let voiceUrl = null;
  1033. // 优先使用one1_url,如果没有则尝试其他音频URL
  1034. if (conclusion.one1_url) {
  1035. voiceUrl = conclusion.one1_url
  1036. .toString()
  1037. .trim()
  1038. .replace(/[`\s]/g, "");
  1039. } else if (conclusion.one2_url) {
  1040. voiceUrl = conclusion.one2_url
  1041. .toString()
  1042. .trim()
  1043. .replace(/[`\s]/g, "");
  1044. } else if (conclusion.two_url) {
  1045. voiceUrl = conclusion.two_url
  1046. .toString()
  1047. .trim()
  1048. .replace(/[`\s]/g, "");
  1049. } else if (conclusion.three_url) {
  1050. voiceUrl = conclusion.three_url
  1051. .toString()
  1052. .trim()
  1053. .replace(/[`\s]/g, "");
  1054. } else if (conclusion.four_url) {
  1055. voiceUrl = conclusion.four_url
  1056. .toString()
  1057. .trim()
  1058. .replace(/[`\s]/g, "");
  1059. } else if (conclusion.url) {
  1060. voiceUrl = conclusion.url.toString().trim().replace(/[`\s]/g, "");
  1061. } else if (conclusion.audioUrl) {
  1062. voiceUrl = conclusion.audioUrl
  1063. .toString()
  1064. .trim()
  1065. .replace(/[`\s]/g, "");
  1066. } else if (conclusion.voice_url) {
  1067. voiceUrl = conclusion.voice_url
  1068. .toString()
  1069. .trim()
  1070. .replace(/[`\s]/g, "");
  1071. } else if (conclusion.audio) {
  1072. voiceUrl = conclusion.audio
  1073. .toString()
  1074. .trim()
  1075. .replace(/[`\s]/g, "");
  1076. } else if (conclusion.tts_url) {
  1077. voiceUrl = conclusion.tts_url
  1078. .toString()
  1079. .trim()
  1080. .replace(/[`\s]/g, "");
  1081. }
  1082. if (voiceUrl && voiceUrl.startsWith("http")) {
  1083. console.log("切换到未显示股票,准备音频URL:", voiceUrl);
  1084. audioUrl.value = voiceUrl;
  1085. // 同时更新store中的音频URL
  1086. emotionAudioStore.setCurrentAudioUrl(voiceUrl);
  1087. }
  1088. } catch (error) {
  1089. console.error("解析股票结论数据失败:", error);
  1090. }
  1091. }
  1092. }
  1093. // 只有在页面已加载的情况下才渲染图表
  1094. if (isPageLoaded.value) {
  1095. nextTick(() => {
  1096. renderCharts(newStock.apiData);
  1097. console.log("图表数据已准备完成,开始渲染:", newStock.apiData);
  1098. // 检查场景应用部分是否已经在视口中,如果是则立即触发效果
  1099. setTimeout(() => {
  1100. // 检查 scenarioApplicationRef.value 是否存在且是有效的 DOM 元素
  1101. if (
  1102. !scenarioApplicationRef.value ||
  1103. !(scenarioApplicationRef.value instanceof Element)
  1104. ) {
  1105. console.warn(
  1106. "scenarioApplicationRef.value 不是有效的 DOM 元素,跳过处理"
  1107. );
  1108. return;
  1109. }
  1110. if (parsedConclusion.value) {
  1111. const stockCode =
  1112. newStock.stockInfo?.code || newStock.stockInfo?.symbol;
  1113. // 如果该股票已经显示过,不需要再处理
  1114. if (stockCode && stockTypewriterShown.value.has(stockCode)) {
  1115. return;
  1116. }
  1117. const rect = scenarioApplicationRef.value.getBoundingClientRect();
  1118. const isInViewport =
  1119. rect.top < window.innerHeight && rect.bottom > 0;
  1120. if (isInViewport) {
  1121. console.log("股票切换后检测到场景应用部分在视口中");
  1122. if (stockCode) {
  1123. // 检查该股票是否是第一次触发
  1124. if (!stockTypewriterShown.value.has(stockCode)) {
  1125. // 如果是用户主动搜索,启动打字机效果和音频播放
  1126. if (isUserInitiated.value && audioUrl.value) {
  1127. console.log(
  1128. "用户主动搜索,该股票第一次进入场景应用,开始打字机效果和音频播放"
  1129. );
  1130. hasTriggeredTypewriter.value = true;
  1131. hasTriggeredAudio.value = true;
  1132. if (!stockAudioPlayed.value.has(stockCode)) {
  1133. console.log("开始音频播放和打字机效果");
  1134. stockAudioPlayed.value.set(stockCode, true);
  1135. playAudioQueue(parsedConclusion.value, true);
  1136. } else {
  1137. // 如果音频已播放过,只启动打字机效果
  1138. startTypewriterEffect(parsedConclusion.value);
  1139. }
  1140. stockTypewriterShown.value.set(stockCode, true);
  1141. } else if (isUserInitiated.value && !audioUrl.value) {
  1142. console.log(
  1143. "音频尚未准备好,等待音频加载完成后再触发效果(股票切换后)"
  1144. );
  1145. return;
  1146. } else {
  1147. // 非用户主动搜索(如历史记录恢复),直接显示完整内容
  1148. console.log(
  1149. "非用户主动搜索,该股票第一次进入场景应用,直接显示完整内容"
  1150. );
  1151. const conclusion = parsedConclusion.value;
  1152. displayedTexts.value = {
  1153. one1: conclusion.one1 || "",
  1154. one2: conclusion.one2 || "",
  1155. two: conclusion.two || "",
  1156. three: conclusion.three || "",
  1157. four: conclusion.four || "",
  1158. disclaimer: "该内容由AI生成,请注意甄别",
  1159. };
  1160. displayedTitles.value = {
  1161. one: "L1: 情绪监控",
  1162. two: "L2: 情绪解码",
  1163. three: "L3: 情绪推演",
  1164. four: "L4: 情绪套利",
  1165. };
  1166. moduleVisibility.value = {
  1167. one: !!(conclusion.one1 || conclusion.one2),
  1168. two: !!conclusion.two,
  1169. three: !!conclusion.three,
  1170. four: !!conclusion.four,
  1171. disclaimer: true,
  1172. };
  1173. stockTypewriterShown.value.set(stockCode, true);
  1174. stockAudioPlayed.value.set(stockCode, true);
  1175. }
  1176. } else {
  1177. // 非第一次或已经触发过:直接显示完整内容,不播放音频和打字机效果
  1178. console.log("非第一次股票切换或已触发过,直接显示完整内容");
  1179. // 直接显示完整内容
  1180. const conclusion = parsedConclusion.value;
  1181. displayedTexts.value = {
  1182. one1: conclusion.one1 || "",
  1183. one2: conclusion.one2 || "",
  1184. two: conclusion.two || "",
  1185. three: conclusion.three || "",
  1186. four: conclusion.four || "",
  1187. disclaimer: "该内容由AI生成,请注意甄别",
  1188. };
  1189. displayedTitles.value = {
  1190. one: "L1: 情绪监控",
  1191. two: "L2: 情绪解码",
  1192. three: "L3: 情绪推演",
  1193. four: "L4: 情绪套利",
  1194. };
  1195. moduleVisibility.value = {
  1196. one: !!(conclusion.one1 || conclusion.one2),
  1197. two: !!conclusion.two,
  1198. three: !!conclusion.three,
  1199. four: !!conclusion.four,
  1200. disclaimer: true,
  1201. };
  1202. }
  1203. }
  1204. }
  1205. }
  1206. }, 500); // 延迟500ms确保数据完全加载
  1207. });
  1208. } else {
  1209. console.log("页面尚未加载完成,等待数据加载完成后再渲染图表");
  1210. }
  1211. } else {
  1212. console.log("股票数据不存在或API数据未加载");
  1213. // 隐藏所有图表组件
  1214. chartVisibility.value = {
  1215. marketTemperature: false,
  1216. emotionDecod: false,
  1217. emotionalBottomRadar: false,
  1218. emoEnergyConverter: false,
  1219. };
  1220. }
  1221. },
  1222. { immediate: true }
  1223. );
  1224. // 监听parsedConclusion变化,准备数据但不立即触发打字机效果
  1225. watch(
  1226. parsedConclusion,
  1227. (newConclusion) => {
  1228. if (newConclusion) {
  1229. console.log("场景应用结论数据:", newConclusion);
  1230. // 不再立即开始打字机效果,等待滚动到场景应用部分时触发
  1231. // 尝试多种可能的语音URL字段名,优先使用新的数据结构
  1232. let voiceUrl = null;
  1233. if (newConclusion.one1_url) {
  1234. voiceUrl = newConclusion.one1_url
  1235. .toString()
  1236. .trim()
  1237. .replace(/[`\s]/g, "");
  1238. } else if (newConclusion.one2_url) {
  1239. voiceUrl = newConclusion.one2_url
  1240. .toString()
  1241. .trim()
  1242. .replace(/[`\s]/g, "");
  1243. } else if (newConclusion.two_url) {
  1244. voiceUrl = newConclusion.two_url
  1245. .toString()
  1246. .trim()
  1247. .replace(/[`\s]/g, "");
  1248. } else if (newConclusion.three_url) {
  1249. voiceUrl = newConclusion.three_url
  1250. .toString()
  1251. .trim()
  1252. .replace(/[`\s]/g, "");
  1253. } else if (newConclusion.four_url) {
  1254. voiceUrl = newConclusion.four_url
  1255. .toString()
  1256. .trim()
  1257. .replace(/[`\s]/g, "");
  1258. } else if (newConclusion.url) {
  1259. // 清理URL字符串,去除空格、反引号等特殊字符
  1260. voiceUrl = newConclusion.url.toString().trim().replace(/[`\s]/g, "");
  1261. } else if (newConclusion.audioUrl) {
  1262. voiceUrl = newConclusion.audioUrl
  1263. .toString()
  1264. .trim()
  1265. .replace(/[`\s]/g, "");
  1266. } else if (newConclusion.voice_url) {
  1267. voiceUrl = newConclusion.voice_url
  1268. .toString()
  1269. .trim()
  1270. .replace(/[`\s]/g, "");
  1271. } else if (newConclusion.audio) {
  1272. voiceUrl = newConclusion.audio.toString().trim().replace(/[`\s]/g, "");
  1273. } else if (newConclusion.tts_url) {
  1274. voiceUrl = newConclusion.tts_url
  1275. .toString()
  1276. .trim()
  1277. .replace(/[`\s]/g, "");
  1278. }
  1279. if (voiceUrl && voiceUrl.startsWith("http")) {
  1280. console.log("找到并清理后的语音URL:", voiceUrl);
  1281. audioUrl.value = voiceUrl;
  1282. // 同时更新store中的音频URL
  1283. emotionAudioStore.setCurrentAudioUrl(voiceUrl);
  1284. console.log("音频URL已准备,检查是否需要立即触发效果");
  1285. // 音频准备好后,只有在用户主动搜索时才自动触发效果
  1286. // 数据恢复时不自动播放音频和打字机效果
  1287. console.log("音频URL已准备完成,等待用户手动触发播放");
  1288. } else {
  1289. console.log("未找到有效的语音URL,原始URL:", newConclusion.url);
  1290. console.log("结论数据中的所有字段:", Object.keys(newConclusion));
  1291. }
  1292. }
  1293. },
  1294. { immediate: true }
  1295. );
  1296. // 打字机效果函数
  1297. function startTypewriterEffect(conclusion, onComplete) {
  1298. console.log("开始打字机效果,结论数据:", conclusion);
  1299. // 保存当前的完成回调函数
  1300. currentOnCompleteCallback.value = onComplete;
  1301. // 详细调试各个字段
  1302. console.log("L1字段 - one1:", conclusion.one1);
  1303. console.log("L1字段 - one2:", conclusion.one2);
  1304. console.log("L2字段 - two:", conclusion.two);
  1305. console.log("L3字段 - three:", conclusion.three);
  1306. console.log("L4字段 - four:", conclusion.four);
  1307. // 清除之前的定时器
  1308. typewriterTimers.value.forEach((timer) => clearTimeout(timer));
  1309. typewriterTimers.value = [];
  1310. // 重置显示文本和状态
  1311. displayedTexts.value = {
  1312. one1: "",
  1313. one2: "",
  1314. two: "",
  1315. three: "",
  1316. four: "",
  1317. disclaimer: "",
  1318. };
  1319. displayedTitles.value = {
  1320. one: "",
  1321. two: "",
  1322. three: "",
  1323. four: "",
  1324. };
  1325. moduleVisibility.value = {
  1326. one: false,
  1327. two: false,
  1328. three: false,
  1329. four: false,
  1330. disclaimer: false,
  1331. };
  1332. // 定义打字速度(毫秒)
  1333. const typeSpeed = 200;
  1334. let totalDelay = 0;
  1335. // 定义模块配置
  1336. const modules = [
  1337. {
  1338. key: "one",
  1339. title: "L1: 情绪监控",
  1340. contents: [
  1341. { key: "one1", text: conclusion.one1 },
  1342. { key: "one2", text: conclusion.one2 },
  1343. ],
  1344. },
  1345. {
  1346. key: "two",
  1347. title: "L2: 情绪解码",
  1348. contents: [{ key: "two", text: conclusion.two }],
  1349. },
  1350. {
  1351. key: "three",
  1352. title: "L3: 情绪推演",
  1353. contents: [{ key: "three", text: conclusion.three }],
  1354. },
  1355. {
  1356. key: "four",
  1357. title: "L4: 情绪套利",
  1358. contents: [{ key: "four", text: conclusion.four }],
  1359. },
  1360. ];
  1361. // 按模块顺序处理
  1362. modules.forEach((module) => {
  1363. // 检查模块是否有内容
  1364. const hasContent = module.contents.some(
  1365. (content) => content.text && content.text.trim()
  1366. );
  1367. console.log(
  1368. `模块 ${module.key} 是否有内容:`,
  1369. hasContent,
  1370. "内容:",
  1371. module.contents.map((c) => c.text)
  1372. );
  1373. if (!hasContent) return;
  1374. console.log(`开始显示模块 ${module.key}`);
  1375. // 显示模块
  1376. const showModuleTimer = setTimeout(() => {
  1377. moduleVisibility.value[module.key] = true;
  1378. console.log(`模块 ${module.key} 已设置为可见`);
  1379. }, totalDelay);
  1380. typewriterTimers.value.push(showModuleTimer);
  1381. totalDelay += 100;
  1382. // 打字机效果显示标题
  1383. const title = module.title;
  1384. for (let i = 0; i <= title.length; i++) {
  1385. const timer = setTimeout(() => {
  1386. displayedTitles.value[module.key] = title.substring(0, i);
  1387. }, totalDelay + i * typeSpeed);
  1388. typewriterTimers.value.push(timer);
  1389. }
  1390. totalDelay += title.length * typeSpeed + 300; // 标题完成后间隔
  1391. // 打字机效果显示内容
  1392. module.contents.forEach((content) => {
  1393. if (content.text && content.text.trim()) {
  1394. const text = content.text;
  1395. for (let i = 0; i <= text.length; i++) {
  1396. const timer = setTimeout(() => {
  1397. displayedTexts.value[content.key] = text.substring(0, i);
  1398. }, totalDelay + i * typeSpeed);
  1399. typewriterTimers.value.push(timer);
  1400. }
  1401. totalDelay += text.length * typeSpeed + 500; // 内容完成后间隔
  1402. }
  1403. });
  1404. totalDelay += 800; // 模块间间隔
  1405. });
  1406. // 添加免责声明的打字机效果(在所有模块显示完成后)
  1407. const disclaimerText = "该内容由AI生成,请注意甄别";
  1408. // 显示免责声明模块
  1409. const showDisclaimerTimer = setTimeout(() => {
  1410. moduleVisibility.value.disclaimer = true;
  1411. }, totalDelay);
  1412. typewriterTimers.value.push(showDisclaimerTimer);
  1413. totalDelay += 100;
  1414. // 打字机效果显示免责声明
  1415. for (let i = 0; i <= disclaimerText.length; i++) {
  1416. const timer = setTimeout(() => {
  1417. displayedTexts.value.disclaimer = disclaimerText.substring(0, i);
  1418. // 在免责声明打字机效果完成后调用回调函数
  1419. if (i === disclaimerText.length) {
  1420. console.log("打字机效果完成,调用onComplete回调");
  1421. if (onComplete && typeof onComplete === "function") {
  1422. onComplete();
  1423. // 清除保存的回调函数
  1424. currentOnCompleteCallback.value = null;
  1425. }
  1426. }
  1427. }, totalDelay + i * typeSpeed);
  1428. typewriterTimers.value.push(timer);
  1429. }
  1430. }
  1431. // 清理定时器的函数
  1432. function clearTypewriterTimers() {
  1433. typewriterTimers.value.forEach((timer) => clearTimeout(timer));
  1434. typewriterTimers.value = [];
  1435. }
  1436. // 音频队列管理
  1437. const audioQueue = ref([]);
  1438. const isPlayingQueueAudio = ref(false);
  1439. let currentPlayIndex = 0;
  1440. let isCallingPlayNext = false;
  1441. // 音频队列顺序管理
  1442. const audioQueueOrder = {
  1443. one1_url: 1,
  1444. one2_url: 2,
  1445. two_url: 3,
  1446. three_url: 4,
  1447. four_url: 5,
  1448. url: 6,
  1449. audioUrl: 7,
  1450. voice_url: 8,
  1451. audio: 9,
  1452. tts_url: 10,
  1453. };
  1454. // 播放音频队列中的下一个音频
  1455. const playNextAudio = () => {
  1456. console.log("=== playNextAudio 被调用 ===");
  1457. console.log("当前队列状态:", {
  1458. queueLength: audioQueue.value.length,
  1459. queueItems: audioQueue.value.map((item) => item.name),
  1460. currentPlayIndex: currentPlayIndex,
  1461. isPlayingQueueAudio: isPlayingQueueAudio.value,
  1462. isCallingPlayNext: isCallingPlayNext,
  1463. audioStoreIsPlaying: emotionAudioStore.isPlaying,
  1464. });
  1465. if (
  1466. audioQueue.value.length === 0 ||
  1467. isPlayingQueueAudio.value ||
  1468. isCallingPlayNext
  1469. ) {
  1470. console.log(
  1471. "❌ 播放条件不满足 - 队列长度:",
  1472. audioQueue.value.length,
  1473. "正在播放:",
  1474. isPlayingQueueAudio.value,
  1475. "正在调用:",
  1476. isCallingPlayNext
  1477. );
  1478. return;
  1479. }
  1480. // 检查是否已播放完所有音频
  1481. if (
  1482. currentPlayIndex >= audioQueue.value.length &&
  1483. audioQueue.value.length > 0
  1484. ) {
  1485. console.log("🔄 所有音频播放完成,重置索引从第一个开始");
  1486. currentPlayIndex = 0;
  1487. isCallingPlayNext = false; // 重置调用标志
  1488. }
  1489. isCallingPlayNext = true;
  1490. isPlayingQueueAudio.value = true;
  1491. const audioInfo = audioQueue.value[currentPlayIndex];
  1492. console.log(
  1493. `✅ 开始播放${audioInfo.name}音频 (索引:${currentPlayIndex}),队列总长度:`,
  1494. audioQueue.value.length
  1495. );
  1496. // 停止之前的音频
  1497. if (emotionAudioStore.nowSound && emotionAudioStore.nowSound.playing()) {
  1498. emotionAudioStore.nowSound.stop();
  1499. }
  1500. // 创建新的音频实例
  1501. const audio = new Howl({
  1502. src: [audioInfo.url],
  1503. html5: true,
  1504. format: ["mp3", "wav"],
  1505. onplay: () => {
  1506. isAudioPlaying.value = true;
  1507. isPlayingQueueAudio.value = true;
  1508. emotionAudioStore.isPlaying = true;
  1509. console.log(`开始播放${audioInfo.name}音频`);
  1510. // 如果是第一个音频且需要启动打字机效果,则启动
  1511. if (
  1512. currentPlayIndex === 0 &&
  1513. audioInfo.shouldStartTypewriter &&
  1514. parsedConclusion.value
  1515. ) {
  1516. console.log("🎬 第一个音频开始播放,同时启动打字机效果");
  1517. startTypewriterEffect(parsedConclusion.value, audioInfo.onComplete);
  1518. }
  1519. },
  1520. onpause: () => {
  1521. emotionAudioStore.isPaused = true;
  1522. console.log(`${audioInfo.name}音频暂停播放`);
  1523. },
  1524. onresume: () => {
  1525. emotionAudioStore.isPaused = false;
  1526. console.log(`${audioInfo.name}音频继续播放`);
  1527. },
  1528. onend: () => {
  1529. console.log(`${audioInfo.name}音频播放完成,准备播放下一个`);
  1530. emotionAudioStore.isPlaying = false;
  1531. emotionAudioStore.isPaused = false;
  1532. emotionAudioStore.playbackPosition = 0;
  1533. isAudioPlaying.value = false;
  1534. isPlayingQueueAudio.value = false;
  1535. // 移动到下一个音频索引
  1536. currentPlayIndex++;
  1537. // 确保只有在音频真正播放完成时才播放下一个
  1538. if (currentPlayIndex < audioQueue.value.length) {
  1539. console.log(
  1540. `队列中还有音频,500ms后播放下一个 (索引:${currentPlayIndex})`
  1541. );
  1542. setTimeout(() => {
  1543. isCallingPlayNext = false;
  1544. playNextAudio();
  1545. }, 500);
  1546. } else {
  1547. console.log("🎉 所有音频播放完成");
  1548. emotionAudioStore.nowSound = null;
  1549. isCallingPlayNext = false;
  1550. // 调用完成回调(如果有的话)
  1551. if (
  1552. audioInfo.onComplete &&
  1553. typeof audioInfo.onComplete === "function"
  1554. ) {
  1555. console.log("调用音频播放完成回调");
  1556. audioInfo.onComplete();
  1557. }
  1558. }
  1559. },
  1560. onstop: () => {
  1561. console.log(`${audioInfo.name}音频被停止`);
  1562. emotionAudioStore.isPlaying = false;
  1563. emotionAudioStore.isPaused = false;
  1564. emotionAudioStore.playbackPosition = 0;
  1565. isAudioPlaying.value = false;
  1566. isPlayingQueueAudio.value = false;
  1567. },
  1568. onerror: (error) => {
  1569. console.error(`${audioInfo.name}音频播放失败:`, error);
  1570. isAudioPlaying.value = false;
  1571. isPlayingQueueAudio.value = false;
  1572. isCallingPlayNext = false;
  1573. // 播放下一个音频
  1574. setTimeout(() => {
  1575. playNextAudio();
  1576. }, 100);
  1577. },
  1578. onload: () => {
  1579. emotionAudioStore.duration = audio.duration();
  1580. console.log(
  1581. `${audioInfo.name}音频加载完成,时长:`,
  1582. emotionAudioStore.duration
  1583. );
  1584. },
  1585. });
  1586. // 设置当前音频URL到store
  1587. emotionAudioStore.setCurrentAudioUrl(audioInfo.url);
  1588. emotionAudioStore.nowSound = audio;
  1589. emotionAudioStore.setAudioInstance(audio);
  1590. console.log(`尝试播放${audioInfo.name}音频`);
  1591. audio.play();
  1592. };
  1593. // 添加音频到播放队列
  1594. const addToAudioQueue = (
  1595. url,
  1596. name,
  1597. shouldStartTypewriter = false,
  1598. onComplete = null
  1599. ) => {
  1600. console.log(`=== 添加音频到队列 ===`);
  1601. console.log("URL:", url);
  1602. console.log("Name:", name);
  1603. console.log("是否启动打字机效果:", shouldStartTypewriter);
  1604. console.log("音频启用状态:", emotionAudioStore.isVoiceEnabled);
  1605. if (url && emotionAudioStore.isVoiceEnabled) {
  1606. const audioItem = {
  1607. url,
  1608. name,
  1609. order: audioQueueOrder[name] || 999,
  1610. shouldStartTypewriter, // 添加打字机效果标志
  1611. onComplete, // 添加完成回调
  1612. };
  1613. audioQueue.value.push(audioItem);
  1614. // 按顺序排序队列
  1615. audioQueue.value.sort((a, b) => a.order - b.order);
  1616. console.log(`音频${name}已添加到播放队列,顺序:${audioItem.order}`);
  1617. console.log(
  1618. "当前队列顺序:",
  1619. audioQueue.value.map((item) => `${item.name}(${item.order})`)
  1620. );
  1621. // 只有在确实没有音频在播放且这是第一个音频时才开始播放
  1622. if (
  1623. !isPlayingQueueAudio.value &&
  1624. !emotionAudioStore.isPlaying &&
  1625. audioQueue.value.length === 1
  1626. ) {
  1627. console.log("✅ 条件满足:没有音频在播放且这是第一个音频,立即开始播放");
  1628. playNextAudio();
  1629. } else {
  1630. console.log("⏳ 等待条件:", {
  1631. isPlayingQueueAudio: isPlayingQueueAudio.value,
  1632. audioStoreIsPlaying: emotionAudioStore.isPlaying,
  1633. queueLength: audioQueue.value.length,
  1634. reason:
  1635. audioQueue.value.length > 1 ? "队列中已有其他音频" : "有音频正在播放",
  1636. });
  1637. }
  1638. } else {
  1639. console.log("❌ 跳过添加音频:", {
  1640. hasUrl: !!url,
  1641. voiceEnabled: emotionAudioStore.isVoiceEnabled,
  1642. });
  1643. }
  1644. };
  1645. // 修改后的音频播放函数 - 支持多音频播放和同步打字机效果
  1646. function playAudioQueue(
  1647. conclusionData,
  1648. shouldStartTypewriter = false,
  1649. onComplete = null
  1650. ) {
  1651. if (!conclusionData) {
  1652. console.log("没有结论数据,跳过播放");
  1653. return;
  1654. }
  1655. // 检查是否启用了语音功能
  1656. console.log("语音功能状态:", emotionAudioStore.isVoiceEnabled);
  1657. if (!emotionAudioStore.isVoiceEnabled) {
  1658. console.log("语音功能已关闭,跳过播放");
  1659. return;
  1660. }
  1661. console.log(
  1662. "开始处理多音频播放...",
  1663. shouldStartTypewriter ? "同时启动打字机效果" : ""
  1664. );
  1665. try {
  1666. // 解析结论数据
  1667. const conclusion =
  1668. typeof conclusionData === "object"
  1669. ? conclusionData
  1670. : JSON.parse(conclusionData);
  1671. // 清空之前的音频队列
  1672. audioQueue.value = [];
  1673. currentPlayIndex = 0;
  1674. isCallingPlayNext = false;
  1675. isPlayingQueueAudio.value = false;
  1676. // 按优先级顺序检查并添加所有可用的音频URL
  1677. const audioSources = [
  1678. { key: "one1_url", name: "one1_url" },
  1679. { key: "one2_url", name: "one2_url" },
  1680. { key: "two_url", name: "two_url" },
  1681. { key: "three_url", name: "three_url" },
  1682. { key: "four_url", name: "four_url" },
  1683. { key: "url", name: "url" },
  1684. { key: "audioUrl", name: "audioUrl" },
  1685. { key: "voice_url", name: "voice_url" },
  1686. { key: "audio", name: "audio" },
  1687. { key: "tts_url", name: "tts_url" },
  1688. ];
  1689. audioSources.forEach((source) => {
  1690. if (conclusion[source.key]) {
  1691. const voiceUrl = conclusion[source.key]
  1692. .toString()
  1693. .trim()
  1694. .replace(/[`\s]/g, "");
  1695. if (voiceUrl && voiceUrl.startsWith("http")) {
  1696. console.log(`找到音频URL: ${source.name} = ${voiceUrl}`);
  1697. addToAudioQueue(
  1698. voiceUrl,
  1699. source.name,
  1700. shouldStartTypewriter && audioQueue.value.length === 0,
  1701. onComplete
  1702. );
  1703. }
  1704. }
  1705. });
  1706. if (audioQueue.value.length === 0) {
  1707. console.log("未找到有效的音频URL");
  1708. // 如果没有音频但需要启动打字机效果,直接启动
  1709. if (shouldStartTypewriter) {
  1710. console.log("没有音频但需要启动打字机效果");
  1711. startTypewriterEffect(conclusion, onComplete);
  1712. }
  1713. } else {
  1714. console.log(`总共找到 ${audioQueue.value.length} 个音频,准备播放`);
  1715. }
  1716. } catch (error) {
  1717. console.error("处理音频播放失败:", error);
  1718. }
  1719. }
  1720. // 原有的单音频播放函数(保持兼容性)
  1721. function playAudio(url) {
  1722. console.log("尝试播放音频:", url);
  1723. if (!url) {
  1724. console.warn("音频URL为空,跳过播放");
  1725. isAudioPlaying.value = false;
  1726. return;
  1727. }
  1728. // 检查是否启用了语音功能
  1729. console.log("语音功能状态:", emotionAudioStore.isVoiceEnabled);
  1730. if (!emotionAudioStore.isVoiceEnabled) {
  1731. console.log("语音功能已关闭,跳过播放");
  1732. return;
  1733. }
  1734. console.log("开始创建音频实例...");
  1735. try {
  1736. // 设置当前音频URL
  1737. emotionAudioStore.setCurrentAudioUrl(url);
  1738. // 停止之前的音频
  1739. if (emotionAudioStore.nowSound && emotionAudioStore.nowSound.playing()) {
  1740. emotionAudioStore.nowSound.stop();
  1741. }
  1742. // 创建新的音频实例
  1743. const newSound = new Howl({
  1744. src: [url],
  1745. html5: true,
  1746. format: ["mp3", "wav"],
  1747. onplay: () => {
  1748. isAudioPlaying.value = true;
  1749. emotionAudioStore.isPlaying = true;
  1750. console.log("开始播放场景应用语音");
  1751. // 音频开始播放时的自动滚动已移除
  1752. },
  1753. onend: () => {
  1754. isAudioPlaying.value = false;
  1755. emotionAudioStore.isPlaying = false;
  1756. emotionAudioStore.isPaused = false;
  1757. emotionAudioStore.playbackPosition = 0;
  1758. console.log("场景应用语音播放结束");
  1759. },
  1760. onstop: () => {
  1761. isAudioPlaying.value = false;
  1762. emotionAudioStore.isPlaying = false;
  1763. console.log("场景应用语音播放停止");
  1764. },
  1765. onpause: () => {
  1766. isAudioPlaying.value = false;
  1767. emotionAudioStore.isPlaying = false;
  1768. console.log("场景应用语音播放暂停");
  1769. },
  1770. onerror: (error) => {
  1771. isAudioPlaying.value = false;
  1772. emotionAudioStore.isPlaying = false;
  1773. console.error("音频播放错误:", error);
  1774. },
  1775. onload: () => {
  1776. // 音频加载完成,获取时长
  1777. emotionAudioStore.duration = newSound.duration();
  1778. console.log("音频加载完成,时长:", emotionAudioStore.duration);
  1779. },
  1780. });
  1781. // 保存音频实例到store
  1782. emotionAudioStore.nowSound = newSound;
  1783. emotionAudioStore.setAudioInstance(newSound);
  1784. // 播放音频
  1785. newSound.play();
  1786. } catch (error) {
  1787. console.error("创建音频实例失败:", error);
  1788. isAudioPlaying.value = false;
  1789. }
  1790. }
  1791. // 停止音频播放
  1792. function stopAudio() {
  1793. if (emotionAudioStore.nowSound) {
  1794. emotionAudioStore.nowSound.stop();
  1795. }
  1796. isAudioPlaying.value = false;
  1797. }
  1798. // 触发图片旋转的方法
  1799. function startImageRotation() {
  1800. isRotating.value = true;
  1801. // 如果你想在一段时间后停止旋转,可以添加以下代码
  1802. setTimeout(() => {
  1803. isRotating.value = false;
  1804. }, 5000); // 5 秒后停止旋转
  1805. }
  1806. // 显示思考过程
  1807. async function showThinkingProcess(stockName = null) {
  1808. // 第一步:正在思考
  1809. const thinkingMessage1 = reactive({
  1810. sender: "ai",
  1811. text: "AI情绪大模型正在思考",
  1812. gif: thinkingGif,
  1813. flag: true, // 添加flag属性以显示动态加载点
  1814. });
  1815. messages.value.push(thinkingMessage1);
  1816. await new Promise((resolve) => setTimeout(resolve, 1500));
  1817. messages.value.pop();
  1818. // 第二步:正在解析关键数据(持续显示直到获取到股票名称)
  1819. const thinkingMessage2 = reactive({
  1820. sender: "ai",
  1821. text: "正在解析关键数据",
  1822. gif: analyzeGif,
  1823. flag: true, // 添加flag属性以显示动态加载点
  1824. });
  1825. messages.value.push(thinkingMessage2);
  1826. // 如果没有股票名称,保持第二步显示
  1827. if (!stockName) {
  1828. return thinkingMessage2; // 返回消息引用,以便后续更新
  1829. }
  1830. // 有股票名称后,继续后续步骤
  1831. await new Promise((resolve) => setTimeout(resolve, 1500));
  1832. messages.value.pop();
  1833. // 第三步:生成具体股票的量子四维矩阵图
  1834. const thinkingMessage3 = reactive({
  1835. sender: "ai",
  1836. text: `正在生成${stockName}量子四维矩阵图`,
  1837. gif: generateGif,
  1838. flag: true, // 添加flag属性以显示动态加载点
  1839. });
  1840. messages.value.push(thinkingMessage3);
  1841. await new Promise((resolve) => setTimeout(resolve, 1500));
  1842. messages.value.pop();
  1843. // 第四步:报告已生成
  1844. const thinkingMessage4 = reactive({ sender: "ai", text: "报告已生成!" });
  1845. messages.value.push(thinkingMessage4);
  1846. await new Promise((resolve) => setTimeout(resolve, 1500));
  1847. messages.value.pop();
  1848. return null;
  1849. }
  1850. // 继续思考过程(当获取到股票名称后调用)
  1851. async function continueThinkingProcess(thinkingMessageRef, stockName) {
  1852. if (!thinkingMessageRef || !stockName) return;
  1853. // 等待一段时间后继续
  1854. await new Promise((resolve) => setTimeout(resolve, 1500));
  1855. // 移除第二步消息
  1856. const index = messages.value.indexOf(thinkingMessageRef);
  1857. if (index > -1) {
  1858. messages.value.splice(index, 1);
  1859. }
  1860. // 第三步:生成具体股票的量子四维矩阵图
  1861. const thinkingMessage3 = reactive({
  1862. sender: "ai",
  1863. text: `正在生成${stockName}量子四维矩阵图`,
  1864. gif: generateGif,
  1865. flag: true, // 添加flag属性以显示动态加载点
  1866. });
  1867. messages.value.push(thinkingMessage3);
  1868. // 返回第三步消息的引用,以便后续处理
  1869. return thinkingMessage3;
  1870. }
  1871. // 完成思考过程(当第二个工作流接口成功后调用)
  1872. async function finishThinkingProcess(thinkingMessage3Ref) {
  1873. if (!thinkingMessage3Ref) return;
  1874. // 等待一段时间
  1875. await new Promise((resolve) => setTimeout(resolve, 1500));
  1876. // 移除第三步消息
  1877. const index = messages.value.indexOf(thinkingMessage3Ref);
  1878. if (index > -1) {
  1879. messages.value.splice(index, 1);
  1880. }
  1881. // 第四步:报告已生成
  1882. const thinkingMessage4 = reactive({ sender: "ai", text: "报告已生成!" });
  1883. messages.value.push(thinkingMessage4);
  1884. await new Promise((resolve) => setTimeout(resolve, 1500));
  1885. messages.value.pop();
  1886. }
  1887. // 发送消息方法
  1888. async function handleSendMessage(input, onComplete) {
  1889. console.log("发送内容:", input);
  1890. // 标记为用户主动搜索
  1891. isUserInitiated.value = true;
  1892. // 重置历史记录模式状态,确保正常对话时显示conversation-area
  1893. isHistoryMode.value = false;
  1894. // 检查用户输入内容是否为空
  1895. if (!input || !input.trim()) {
  1896. ElMessage.warning("输入内容不能为空");
  1897. // 调用完成回调,重新启用输入框
  1898. if (onComplete && typeof onComplete === "function") {
  1899. onComplete();
  1900. // 清除保存的回调函数
  1901. currentOnCompleteCallback.value = null;
  1902. }
  1903. return;
  1904. }
  1905. // 用户输入不为空,立即清空页面内容并触发图片旋转逻辑
  1906. isPageLoaded.value = false; // 立即隐藏页面内容
  1907. isRotating.value = true;
  1908. const previousMessages = [...messages.value]; // 保存历史消息
  1909. messages.value = []; // 清空历史数据
  1910. // 添加用户消息(只添加一次)
  1911. const userMessage = reactive({ sender: "user", text: input });
  1912. messages.value.push(userMessage);
  1913. // 将用户消息添加到emotion store中
  1914. emotionStore.addConversation({
  1915. sender: "user",
  1916. text: input,
  1917. timestamp: new Date().toISOString(),
  1918. });
  1919. // 检查用户剩余次数
  1920. await chatStore.getUserCount(); // 获取最新的用户次数
  1921. if (chatStore.UserCount <= 0) {
  1922. const aiMessage = reactive({
  1923. sender: "ai",
  1924. text: "您的剩余次数为0,无法使用情绪大模型,请联系客服或购买服务包。",
  1925. });
  1926. messages.value.push(aiMessage);
  1927. // 将AI消息添加到emotion store中
  1928. emotionStore.addConversation({
  1929. sender: "ai",
  1930. text: "您的剩余次数为0,无法使用情绪大模型,请联系客服或购买服务包。",
  1931. timestamp: new Date().toISOString(),
  1932. });
  1933. // 停止图片旋转,恢复历史数据
  1934. isRotating.value = false;
  1935. messages.value = [...previousMessages, ...messages.value];
  1936. // 调用完成回调,重新启用输入框
  1937. if (onComplete && typeof onComplete === "function") {
  1938. onComplete();
  1939. // 清除保存的回调函数
  1940. currentOnCompleteCallback.value = null;
  1941. }
  1942. return;
  1943. }
  1944. // 开始思考过程(不带股票名称)
  1945. const thinkingMessageRef = await showThinkingProcess();
  1946. let thinkingMessage3Ref = null;
  1947. try {
  1948. // 第一步:调用第一个接口验证用户输入内容是否合法
  1949. // const params = {
  1950. // content: userMessage.text,
  1951. // userData: {
  1952. // token: localStorage.getItem('localToken'),
  1953. // language: "cn",
  1954. // brainPrivilegeState: '1',
  1955. // swordPrivilegeState: '1',
  1956. // stockForecastPrivilegeState: '1',
  1957. // spaceForecastPrivilegeState: '1',
  1958. // aibullPrivilegeState: '1',
  1959. // aigoldBullPrivilegeState: '1',
  1960. // airadarPrivilegeState: '1',
  1961. // marketList: "hk,cn,usa,my,sg,vi,in,gb",
  1962. // },
  1963. // };
  1964. const result = await getReplyAPI({
  1965. token: localStorage.getItem("localToken"),
  1966. language: "cn",
  1967. marketList: "hk,cn,usa,my,sg,vi,in,gb",
  1968. content: userMessage.text,
  1969. });
  1970. const response = result;
  1971. const parsedData = response.data;
  1972. console.log("第一个接口返回的完整数据:", parsedData);
  1973. // 检查用户输入是否合法
  1974. if (!parsedData || !parsedData.market || !parsedData.code) {
  1975. // 输入不合法,先清理思考过程消息
  1976. if (thinkingMessageRef) {
  1977. const index = messages.value.indexOf(thinkingMessageRef);
  1978. if (index > -1) {
  1979. messages.value.splice(index, 1);
  1980. }
  1981. }
  1982. // 关闭加载状态和等待提示,返回refuse信息,停止图片旋转,恢复历史数据
  1983. // isLoading.value = false;
  1984. isPageLoaded.value = false;
  1985. const aiMessage = reactive({
  1986. sender: "ai",
  1987. text: processRefuseMessage(parsedData.refuse),
  1988. });
  1989. messages.value.push(aiMessage);
  1990. // 将AI消息添加到emotion store中
  1991. emotionStore.addConversation({
  1992. sender: "ai",
  1993. text: processRefuseMessage(parsedData.refuse),
  1994. timestamp: new Date().toISOString(),
  1995. });
  1996. isRotating.value = false;
  1997. messages.value = [...previousMessages, ...messages.value];
  1998. // 调用完成回调,重新启用输入框
  1999. if (onComplete && typeof onComplete === "function") {
  2000. onComplete();
  2001. // 清除保存的回调函数
  2002. currentOnCompleteCallback.value = null;
  2003. }
  2004. return;
  2005. }
  2006. // 输入合法,继续执行后续处理
  2007. // 获取到股票名称后,继续思考过程
  2008. if (thinkingMessageRef && parsedData.name) {
  2009. thinkingMessage3Ref = await continueThinkingProcess(
  2010. thinkingMessageRef,
  2011. parsedData.name
  2012. );
  2013. }
  2014. // 设置加载状态,隐藏图表页面
  2015. // isLoading.value = true;
  2016. isPageLoaded.value = false;
  2017. // 调用第二个工作流接口
  2018. const conclusionParams = {
  2019. recordId: parsedData.recordId,
  2020. parentId: parsedData.parentId,
  2021. stockId: parsedData.stockId,
  2022. token: localStorage.getItem("localToken"),
  2023. language: "cn",
  2024. };
  2025. console.log("第二个接口参数:", conclusionParams);
  2026. // 同时调用第二个数据流接口和fetchData方法
  2027. const [conclusionResult, fetchDataResult] = await Promise.all([
  2028. getConclusionAPI(conclusionParams),
  2029. fetchData(
  2030. parsedData.code,
  2031. parsedData.market,
  2032. parsedData.name || "未知股票",
  2033. input.trim(),
  2034. parsedData.stockId
  2035. ),
  2036. ]);
  2037. // 处理结论接口返回的数据
  2038. const conclusionResponse = conclusionResult;
  2039. // 检查所有数据是否都加载成功
  2040. if (conclusionResponse && conclusionResponse.data && fetchDataResult) {
  2041. // 第二个工作流接口成功,完成思考过程
  2042. if (thinkingMessage3Ref) {
  2043. await finishThinkingProcess(thinkingMessage3Ref);
  2044. }
  2045. // 将结论数据存储到响应式变量和store中
  2046. conclusionData.value = conclusionResponse.data;
  2047. console.log("第二个接口返回的完整数据结构:", conclusionResponse.data);
  2048. // 将结论数据存储到store中的当前激活股票
  2049. emotionStore.updateActiveStockConclusion(conclusionResponse.data);
  2050. // 所有数据加载完成,关闭加载状态,显示页面
  2051. // isLoading.value = false;
  2052. isPageLoaded.value = true;
  2053. // 使用nextTick确保DOM更新后清空对话显示并启动高度监听器
  2054. nextTick(() => {
  2055. messages.value = [];
  2056. // 启动页面高度监听器,实时监听内容变化并自动滚动
  2057. startHeightObserver();
  2058. // 立即滚动到底部
  2059. scrollToBottom();
  2060. });
  2061. // 数据获取成功后,重新获取用户次数以实现实时更新
  2062. try {
  2063. await chatStore.getUserCount();
  2064. console.log("数据获取成功后,用户次数已更新");
  2065. } catch (error) {
  2066. console.error("更新用户次数失败:", error);
  2067. }
  2068. // 重新调用获取历史记录的接口
  2069. try {
  2070. chatStore.searchRecord = true;
  2071. console.log("getConclusionAPI成功后,已触发历史记录更新");
  2072. } catch (error) {
  2073. console.error("触发历史记录更新失败:", error);
  2074. }
  2075. // 确保页面状态更新后触发图表渲染和音频文本
  2076. nextTick(() => {
  2077. if (currentStock.value && currentStock.value.apiData) {
  2078. renderCharts(currentStock.value.apiData);
  2079. // 只有在用户主动搜索时才自动触发音频和文本
  2080. if (
  2081. isUserInitiated.value &&
  2082. parsedConclusion.value &&
  2083. audioUrl.value
  2084. ) {
  2085. const stockCode =
  2086. currentStock.value.stockInfo?.code ||
  2087. currentStock.value.stockInfo?.symbol;
  2088. if (stockCode && !stockTypewriterShown.value.has(stockCode)) {
  2089. if (!stockAudioPlayed.value.has(stockCode)) {
  2090. stockAudioPlayed.value.set(stockCode, true);
  2091. playAudioQueue(parsedConclusion.value, true, onComplete);
  2092. } else {
  2093. // 如果音频已播放过,只启动打字机效果
  2094. startTypewriterEffect(parsedConclusion.value, onComplete);
  2095. }
  2096. stockTypewriterShown.value.set(stockCode, true);
  2097. } else {
  2098. // 如果不需要打字机效果,直接调用完成回调
  2099. if (onComplete && typeof onComplete === "function") {
  2100. onComplete();
  2101. // 清除保存的回调函数
  2102. currentOnCompleteCallback.value = null;
  2103. }
  2104. }
  2105. }
  2106. // 重置用户主动搜索标志
  2107. isUserInitiated.value = false;
  2108. }
  2109. });
  2110. } else {
  2111. // 数据加载失败,清理第三步思考过程消息
  2112. if (thinkingMessage3Ref) {
  2113. const index = messages.value.indexOf(thinkingMessage3Ref);
  2114. if (index > -1) {
  2115. messages.value.splice(index, 1);
  2116. }
  2117. }
  2118. // 数据加载失败,停止图片旋转,恢复历史数据
  2119. // isLoading.value = false;
  2120. // 如果 fetchDataResult 为 false,说明数据不完整的错误信息已经在 fetchData 中添加到 messages
  2121. // 只有在 conclusionResponse 有问题时才添加通用错误信息
  2122. if (!conclusionResponse || !conclusionResponse.data) {
  2123. const aiMessage = reactive({
  2124. sender: "ai",
  2125. text: "网络加载失败,请重试",
  2126. });
  2127. messages.value.push(aiMessage);
  2128. }
  2129. isRotating.value = false;
  2130. messages.value = [...previousMessages, ...messages.value];
  2131. // 如果有之前的股票数据且页面已加载,重新渲染图表
  2132. if (
  2133. isPageLoaded.value &&
  2134. emotionStore.activeStock &&
  2135. emotionStore.activeStock.apiData
  2136. ) {
  2137. nextTick(() => {
  2138. renderCharts(emotionStore.activeStock.apiData);
  2139. console.log(
  2140. "搜索失败,恢复显示之前股票的图表:",
  2141. emotionStore.activeStock.stockInfo.name
  2142. );
  2143. });
  2144. }
  2145. // 调用完成回调,重新启用输入框
  2146. if (onComplete && typeof onComplete === "function") {
  2147. onComplete();
  2148. // 清除保存的回调函数
  2149. currentOnCompleteCallback.value = null;
  2150. }
  2151. return;
  2152. }
  2153. } catch (error) {
  2154. // 请求失败,清理第三步思考过程消息
  2155. if (thinkingMessage3Ref) {
  2156. const index = messages.value.indexOf(thinkingMessage3Ref);
  2157. if (index > -1) {
  2158. messages.value.splice(index, 1);
  2159. }
  2160. }
  2161. // 请求失败时关闭加载状态
  2162. // isLoading.value = false;
  2163. // 如果有之前的股票数据,恢复显示状态;否则设置为false
  2164. if (emotionStore.stockList.length > 0 && emotionStore.activeStock) {
  2165. isPageLoaded.value = true;
  2166. // 使用nextTick确保DOM更新后清空对话显示并启动高度监听器
  2167. nextTick(() => {
  2168. messages.value = [];
  2169. // 启动页面高度监听器,实时监听内容变化并自动滚动
  2170. startHeightObserver();
  2171. // 立即滚动到底部
  2172. scrollToBottom();
  2173. });
  2174. console.log("请求工作流接口失败,但恢复显示之前的股票数据");
  2175. // 立即渲染之前股票的图表,提升用户体验
  2176. nextTick(() => {
  2177. renderCharts(emotionStore.activeStock.apiData);
  2178. console.log(
  2179. "立即恢复显示之前股票的图表:",
  2180. emotionStore.activeStock.stockInfo.name
  2181. );
  2182. });
  2183. } else {
  2184. isPageLoaded.value = false;
  2185. }
  2186. const aiMessage = reactive({
  2187. sender: "ai",
  2188. text: "请求工作流接口失败,请检查网络连接",
  2189. });
  2190. messages.value.push(aiMessage);
  2191. // 将AI消息添加到emotion store中
  2192. emotionStore.addConversation({
  2193. sender: "ai",
  2194. text: "请求工作流接口失败,请检查网络连接",
  2195. timestamp: new Date().toISOString(),
  2196. });
  2197. // 请求失败时停止图片旋转,恢复历史数据
  2198. isRotating.value = false;
  2199. messages.value = [...previousMessages, ...messages.value];
  2200. // 如果有之前的股票数据且页面已加载,重新渲染图表
  2201. if (
  2202. isPageLoaded.value &&
  2203. emotionStore.activeStock &&
  2204. emotionStore.activeStock.apiData
  2205. ) {
  2206. nextTick(() => {
  2207. renderCharts(emotionStore.activeStock.apiData);
  2208. console.log(
  2209. "请求失败,恢复显示之前股票的图表:",
  2210. emotionStore.activeStock.stockInfo.name
  2211. );
  2212. });
  2213. }
  2214. // 调用完成回调,重新启用输入框
  2215. if (onComplete && typeof onComplete === "function") {
  2216. onComplete();
  2217. // 清除保存的回调函数
  2218. currentOnCompleteCallback.value = null;
  2219. }
  2220. return;
  2221. } finally {
  2222. // 停止图片旋转(只有在设置了旋转状态时才需要停止)
  2223. if (isRotating.value) {
  2224. isRotating.value = false;
  2225. }
  2226. }
  2227. }
  2228. // 请求数据接口
  2229. async function fetchData(code, market, stockName, queryText, stockId) {
  2230. try {
  2231. const stockDataParams = {
  2232. stockId: stockId,
  2233. };
  2234. const stockDataResult = await axios.post(
  2235. // "http://39.101.133.168:8828/link/api/aiEmotion/client/getAiEmotionData",
  2236. `${APIurl}/api/workflow/getStockData`,
  2237. stockDataParams,
  2238. {
  2239. headers: {
  2240. "Content-Type": "application/json",
  2241. },
  2242. }
  2243. );
  2244. const stockDataResponse = stockDataResult.data; // 获取返回所有的数据
  2245. if (stockDataResponse.code === 200 && stockDataResponse.data) {
  2246. // 检查关键数据字段是否完整
  2247. const validation = validateRequiredFields(stockDataResponse.data);
  2248. // 如果有关键数据缺失,返回失败,不添加到StockTabs
  2249. if (!validation.isValid) {
  2250. console.log("API返回数据不完整,缺失字段:", validation.missingFields);
  2251. // 关闭加载状态
  2252. // isLoading.value = false;
  2253. // 如果有之前的股票数据,恢复显示状态;否则设置为false
  2254. if (emotionStore.stockList.length > 0 && emotionStore.activeStock) {
  2255. isPageLoaded.value = true;
  2256. // 使用nextTick确保DOM更新后清空对话显示并启动高度监听器
  2257. nextTick(() => {
  2258. messages.value = [];
  2259. // 启动页面高度监听器,实时监听内容变化并自动滚动
  2260. startHeightObserver();
  2261. // 立即滚动到底部
  2262. scrollToBottom();
  2263. });
  2264. console.log("数据验证失败,但恢复显示之前的股票数据");
  2265. // 立即渲染之前股票的图表,提升用户体验
  2266. nextTick(() => {
  2267. renderCharts(emotionStore.activeStock.apiData);
  2268. console.log(
  2269. "立即恢复显示之前股票的图表:",
  2270. emotionStore.activeStock.stockInfo.name
  2271. );
  2272. });
  2273. } else {
  2274. isPageLoaded.value = false;
  2275. }
  2276. const aiMessage = reactive({
  2277. sender: "ai",
  2278. text: `数据丢失了,请稍后重试。`,
  2279. });
  2280. messages.value.push(aiMessage);
  2281. // 将AI消息添加到emotion store中
  2282. emotionStore.addConversation({
  2283. sender: "ai",
  2284. text: "数据丢失了,请稍后重试。",
  2285. timestamp: new Date().toISOString(),
  2286. });
  2287. return false; // 返回失败标识,不添加股票到标签
  2288. }
  2289. // 只有数据完整时才创建股票数据对象并添加到store
  2290. const stockData = {
  2291. queryText: queryText,
  2292. stockInfo: {
  2293. name: stockName,
  2294. code: code,
  2295. market: market,
  2296. },
  2297. apiData: stockDataResponse.data,
  2298. conclusionData: conclusionData.value, // 包含结论数据
  2299. timestamp: new Date().toISOString(),
  2300. };
  2301. // 将股票数据添加到store中,显示在StockTabs中
  2302. emotionStore.addStock(stockData);
  2303. return true; // 返回成功标识
  2304. } else {
  2305. // 关闭加载状态
  2306. // isLoading.value = false;
  2307. // 如果有之前的股票数据,恢复显示状态;否则设置为false
  2308. if (emotionStore.stockList.length > 0 && emotionStore.activeStock) {
  2309. isPageLoaded.value = true;
  2310. // 使用nextTick确保DOM更新后清空对话显示并启动高度监听器
  2311. nextTick(() => {
  2312. messages.value = [];
  2313. // 启动页面高度监听器,实时监听内容变化并自动滚动
  2314. startHeightObserver();
  2315. // 立即滚动到底部
  2316. scrollToBottom();
  2317. });
  2318. console.log("API请求失败,但恢复显示之前的股票数据");
  2319. // 立即渲染之前股票的图表,提升用户体验
  2320. nextTick(() => {
  2321. renderCharts(emotionStore.activeStock.apiData);
  2322. console.log(
  2323. "立即恢复显示之前股票的图表:",
  2324. emotionStore.activeStock.stockInfo.name
  2325. );
  2326. });
  2327. } else {
  2328. isPageLoaded.value = false;
  2329. }
  2330. const aiMessage = reactive({
  2331. sender: "ai",
  2332. text: "图表数据请求失败,请检查网络连接",
  2333. });
  2334. messages.value.push(aiMessage);
  2335. // 将AI消息添加到emotion store中
  2336. emotionStore.addConversation({
  2337. sender: "ai",
  2338. text: "图表数据请求失败,请检查网络连接",
  2339. timestamp: new Date().toISOString(),
  2340. });
  2341. return false; // 返回失败标识
  2342. }
  2343. } catch (error) {
  2344. // 关闭加载状态
  2345. // isLoading.value = false;
  2346. // 如果有之前的股票数据,恢复显示状态;否则设置为false
  2347. if (emotionStore.stockList.length > 0 && emotionStore.activeStock) {
  2348. isPageLoaded.value = true;
  2349. // 使用nextTick确保DOM更新后清空对话显示并启动高度监听器
  2350. nextTick(() => {
  2351. messages.value = [];
  2352. // 启动页面高度监听器,实时监听内容变化并自动滚动
  2353. startHeightObserver();
  2354. // 立即滚动到底部
  2355. scrollToBottom();
  2356. });
  2357. console.log("网络异常,但恢复显示之前的股票数据");
  2358. // 立即渲染之前股票的图表,提升用户体验
  2359. nextTick(() => {
  2360. renderCharts(emotionStore.activeStock.apiData);
  2361. console.log(
  2362. "立即恢复显示之前股票的图表:",
  2363. emotionStore.activeStock.stockInfo.name
  2364. );
  2365. });
  2366. } else {
  2367. isPageLoaded.value = false;
  2368. }
  2369. const aiMessage = reactive({
  2370. sender: "ai",
  2371. text: "图表数据请求失败,请检查网络连接",
  2372. });
  2373. messages.value.push(aiMessage);
  2374. // 将AI消息添加到emotion store中
  2375. emotionStore.addConversation({
  2376. sender: "ai",
  2377. text: "图表数据请求失败,请检查网络连接",
  2378. timestamp: new Date().toISOString(),
  2379. });
  2380. return false; // 返回失败标识
  2381. }
  2382. }
  2383. // 检查关键数据字段是否完整的函数
  2384. function validateRequiredFields(data) {
  2385. const requiredFields = ["GSWDJ", "KLine20", "QXJMQ", "QXTDLD", "WDRL"];
  2386. const missingFields = [];
  2387. for (const field of requiredFields) {
  2388. if (
  2389. !data[field] ||
  2390. (Array.isArray(data[field]) && data[field].length === 0) ||
  2391. (typeof data[field] === "object" && !hasValidData(data[field]))
  2392. ) {
  2393. missingFields.push(field);
  2394. }
  2395. }
  2396. return {
  2397. isValid: missingFields.length === 0,
  2398. missingFields: missingFields,
  2399. };
  2400. }
  2401. // 检查对象是否包含有效数据的辅助函数
  2402. function hasValidData(obj) {
  2403. if (!obj || typeof obj !== "object") {
  2404. return false;
  2405. }
  2406. // 定义可以为空的数组字段
  2407. const allowedEmptyArrays = ["lowxh", "qixh", "topxh"];
  2408. // 检查对象的所有属性值
  2409. for (const key in obj) {
  2410. if (obj.hasOwnProperty(key)) {
  2411. const value = obj[key];
  2412. // 如果是字符串字段
  2413. if (typeof value === "string") {
  2414. // 字符串字段必须有内容,为空则表示异常
  2415. if (value.trim() !== "") {
  2416. return true;
  2417. }
  2418. }
  2419. // 如果是数组字段
  2420. else if (Array.isArray(value)) {
  2421. // 数组字段可以为空,但如果有内容则表示有效
  2422. if (value.length > 0) {
  2423. return true;
  2424. }
  2425. }
  2426. // 如果是数字且不为0
  2427. else if (typeof value === "number" && value !== 0) {
  2428. return true;
  2429. }
  2430. // 如果是布尔值且为true
  2431. else if (typeof value === "boolean" && value === true) {
  2432. return true;
  2433. }
  2434. // 如果是对象且包含有效数据(递归检查)
  2435. else if (typeof value === "object" && value !== null) {
  2436. if (hasValidData(value)) {
  2437. return true;
  2438. }
  2439. }
  2440. }
  2441. }
  2442. return false;
  2443. }
  2444. // 依次渲染图表的方法 - 支持多个股票
  2445. async function renderChartsSequentially(clonedData, stockIndex = 0) {
  2446. console.log(`开始渲染第${stockIndex}个股票的图表`);
  2447. // 定义图表渲染顺序和配置
  2448. const chartConfigs = [
  2449. {
  2450. name: "股市温度计",
  2451. ref: marketTemperatureRef.value[stockIndex],
  2452. visibility: chartVisibility.value.marketTemperature,
  2453. method: "initChart",
  2454. params: [clonedData.GSWDJ, clonedData.KLine20, clonedData.WDRL],
  2455. },
  2456. {
  2457. name: "情绪解码器",
  2458. ref: emotionDecodRef.value[stockIndex],
  2459. visibility: chartVisibility.value.emotionDecod,
  2460. method: "initQXNLZHEcharts",
  2461. params: [clonedData.KLine20, clonedData.QXJMQ],
  2462. },
  2463. {
  2464. name: "情绪探底雷达",
  2465. ref: emotionalBottomRadarRef.value[stockIndex],
  2466. visibility: chartVisibility.value.emotionalBottomRadar,
  2467. method: "initEmotionalBottomRadar",
  2468. params: [clonedData.KLine20, clonedData.QXTDLD],
  2469. },
  2470. {
  2471. name: "情绪能量转化器",
  2472. ref: emoEnergyConverterRef.value[stockIndex],
  2473. visibility: chartVisibility.value.emoEnergyConverter,
  2474. method: "initQXNLZHEcharts",
  2475. params: [clonedData.KLine20, clonedData.QXNLZHQ],
  2476. },
  2477. ];
  2478. // 依次渲染每个图表
  2479. for (const config of chartConfigs) {
  2480. if (config.ref && config.visibility) {
  2481. console.log(`开始渲染第${stockIndex}个股票的${config.name}图表`);
  2482. console.log(`${config.name}Ref方法:`, typeof config.ref[config.method]);
  2483. if (typeof config.ref[config.method] === "function") {
  2484. try {
  2485. // 等待DOM元素完全渲染
  2486. await new Promise((resolve) => setTimeout(resolve, 100));
  2487. config.ref[config.method](...config.params);
  2488. console.log(`${stockIndex}个股票的${config.name}图表渲染成功`);
  2489. // 每个图表渲染完成后等待一段时间再渲染下一个
  2490. await new Promise((resolve) => setTimeout(resolve, 800));
  2491. } catch (error) {
  2492. console.error(
  2493. `${stockIndex}个股票的${config.name}图表渲染失败:`,
  2494. error
  2495. );
  2496. }
  2497. } else {
  2498. console.error(
  2499. `${stockIndex}个股票的${config.name}Ref.${config.method} 方法不存在`
  2500. );
  2501. }
  2502. } else {
  2503. console.log(
  2504. `${stockIndex}个股票的${config.name}图表未渲染,ref存在:`,
  2505. !!config.ref,
  2506. "数据存在:",
  2507. config.visibility
  2508. );
  2509. }
  2510. }
  2511. console.log(`${stockIndex}个股票的所有图表依次渲染完成`);
  2512. }
  2513. // 渲染组件图表的方法
  2514. function renderCharts(data) {
  2515. console.log("开始渲染图表,数据:", data);
  2516. // 深拷贝数据避免污染原始数据
  2517. const clonedData = JSON.parse(JSON.stringify(data));
  2518. // 检查关键数据字段是否完整
  2519. const validation = validateRequiredFields(clonedData);
  2520. // 如果有任何关键数据缺失,不渲染页面并返回提示
  2521. if (!validation.isValid) {
  2522. console.log("关键数据缺失:", validation.missingFields);
  2523. const aiMessage = reactive({
  2524. sender: "ai",
  2525. text: `数据不完整,缺少以下关键数据:${validation.missingFields.join(
  2526. "、"
  2527. )}请稍后重试或联系客服`,
  2528. });
  2529. messages.value.push(aiMessage);
  2530. // 将AI消息添加到emotion store中
  2531. emotionStore.addConversation({
  2532. sender: "ai",
  2533. text: `数据不完整,缺少以下关键数据:${validation.missingFields.join(
  2534. "、"
  2535. )}请稍后重试或联系客服`,
  2536. timestamp: new Date().toISOString(),
  2537. });
  2538. // 隐藏页面内容
  2539. isPageLoaded.value = false;
  2540. // isLoading.value = false;
  2541. return; // 直接返回,不进行后续渲染
  2542. }
  2543. // 先设置图表组件显示状态
  2544. chartVisibility.value = {
  2545. marketTemperature: !!(clonedData.GSWDJ && clonedData.GSWDJ.length > 0),
  2546. emotionDecod: !!(clonedData.QXJMQ && clonedData.QXJMQ.length > 0),
  2547. emotionalBottomRadar: !!(clonedData.QXTDLD && clonedData.QXTDLD.length > 0),
  2548. emoEnergyConverter: !!(
  2549. clonedData.QXNLZHQ &&
  2550. (Array.isArray(clonedData.QXNLZHQ)
  2551. ? clonedData.QXNLZHQ.length > 0
  2552. : hasValidData(clonedData.QXNLZHQ))
  2553. ),
  2554. };
  2555. console.log("图表显示状态:", chartVisibility.value);
  2556. console.log("数据检查:", {
  2557. GSWDJ: !!(clonedData.GSWDJ && clonedData.GSWDJ.length > 0),
  2558. QXJMQ: !!(clonedData.QXJMQ && clonedData.QXJMQ.length > 0),
  2559. QXTDLD: !!(clonedData.QXTDLD && clonedData.QXTDLD.length > 0),
  2560. QXNLZHQ: !!(
  2561. clonedData.QXNLZHQ &&
  2562. (Array.isArray(clonedData.QXNLZHQ)
  2563. ? clonedData.QXNLZHQ.length > 0
  2564. : hasValidData(clonedData.QXNLZHQ))
  2565. ),
  2566. });
  2567. console.log("QXNLZHQ数据详情:", clonedData.QXNLZHQ);
  2568. nextTick(() => {
  2569. // 增加延迟确保DOM完全更新和组件完全挂载
  2570. setTimeout(() => {
  2571. try {
  2572. console.log("图表组件ref状态:", {
  2573. marketTemperatureRef: !!marketTemperatureRef.value,
  2574. emotionDecodRef: !!emotionDecodRef.value,
  2575. emotionalBottomRadarRef: !!emotionalBottomRadarRef.value,
  2576. emoEnergyConverterRef: !!emoEnergyConverterRef.value,
  2577. });
  2578. // 检查DOM元素是否存在
  2579. console.log("DOM元素检查:", {
  2580. marketTemperatureDOM: !!document.querySelector(
  2581. ".market-temperature-section"
  2582. ),
  2583. emotionDecodDOM: !!document.querySelector(".emotion-decoder-section"),
  2584. emotionalBottomRadarDOM: !!document.querySelector(
  2585. ".bottom-radar-section"
  2586. ),
  2587. emoEnergyConverterDOM: !!document.querySelector(
  2588. ".energy-converter-section"
  2589. ),
  2590. });
  2591. // 检查具体的组件元素
  2592. const emoEnergyElement = document.querySelector("emo-energy-converter");
  2593. console.log("emoEnergyConverter元素:", emoEnergyElement);
  2594. // 等待更长时间再次检查ref
  2595. setTimeout(() => {
  2596. console.log(
  2597. "延迟检查emoEnergyConverterRef:",
  2598. !!emoEnergyConverterRef.value
  2599. );
  2600. if (emoEnergyConverterRef.value) {
  2601. console.log(
  2602. "emoEnergyConverter方法:",
  2603. typeof emoEnergyConverterRef.value.initQXNLZHEcharts
  2604. );
  2605. }
  2606. }, 1000);
  2607. // 开始依次渲染图表 - 为每个股票渲染
  2608. emotionStore.stockList.forEach((stock, index) => {
  2609. if (stock.apiData) {
  2610. renderChartsSequentially(stock.apiData, index);
  2611. }
  2612. });
  2613. console.log("图表渲染完成");
  2614. } catch (error) {
  2615. console.error("图表渲染错误:", error);
  2616. const aiMessage = reactive({
  2617. sender: "ai",
  2618. text: "图表渲染失败,请重试",
  2619. });
  2620. messages.value.push(aiMessage);
  2621. // 将AI消息添加到emotion store中
  2622. emotionStore.addConversation({
  2623. sender: "ai",
  2624. text: "图表渲染失败,请重试",
  2625. timestamp: new Date().toISOString(),
  2626. });
  2627. }
  2628. }, 500); // 增加延迟到500ms确保DOM和组件完全稳定
  2629. });
  2630. }
  2631. // scrollToBottom函数已移除
  2632. // 处理用户滚动事件(用于其他滚动相关功能)
  2633. const handleUserScroll = () => {
  2634. // 用户滚动事件处理逻辑已简化,因为自动滚动功能已移除
  2635. };
  2636. // 处理滚轮事件
  2637. const handleWheel = (event) => {
  2638. handleUserScroll();
  2639. };
  2640. // 处理触摸滚动事件
  2641. const handleTouchMove = (event) => {
  2642. handleUserScroll();
  2643. };
  2644. // 检查数据是否已加载完成
  2645. function isDataLoaded() {
  2646. // 检查页面是否已加载
  2647. if (!isPageLoaded.value) {
  2648. console.log("页面数据尚未加载完成");
  2649. return false;
  2650. }
  2651. // 检查当前股票数据是否存在
  2652. if (!currentStock.value || !currentStock.value.apiData) {
  2653. console.log("股票数据尚未加载完成");
  2654. return false;
  2655. }
  2656. // 检查图表组件是否已渲染 - 检查所有股票的组件
  2657. const stockCount = emotionStore.stockList.length;
  2658. if (stockCount === 0) {
  2659. console.log("没有股票数据");
  2660. return false;
  2661. }
  2662. // 检查每个股票的图表组件是否都已加载
  2663. for (let i = 0; i < stockCount; i++) {
  2664. const requiredRefs = [
  2665. marketTemperatureRef.value[i],
  2666. emotionDecodRef.value[i],
  2667. emotionalBottomRadarRef.value[i],
  2668. emoEnergyConverterRef.value[i],
  2669. ];
  2670. const allRefsLoaded = requiredRefs.every((ref) => ref !== null);
  2671. if (!allRefsLoaded) {
  2672. console.log(`${i}个股票的图表组件尚未完全加载`);
  2673. return false;
  2674. }
  2675. }
  2676. console.log("所有数据和组件已加载完成");
  2677. return true;
  2678. }
  2679. // 自动滚动函数已移除
  2680. // 设置Intersection Observer监听场景应用部分
  2681. function setupIntersectionObserver() {
  2682. // 检查 scenarioApplicationRef.value 是否存在且是有效的 DOM 元素
  2683. if (
  2684. !scenarioApplicationRef.value ||
  2685. !(scenarioApplicationRef.value instanceof Element)
  2686. ) {
  2687. console.warn(
  2688. "scenarioApplicationRef.value 不是有效的 DOM 元素,跳过 IntersectionObserver 设置"
  2689. );
  2690. return;
  2691. }
  2692. const observer = new IntersectionObserver(
  2693. (entries) => {
  2694. entries.forEach((entry) => {
  2695. if (entry.isIntersecting) {
  2696. console.log("场景应用部分进入视口");
  2697. // 获取当前股票代码
  2698. const stockCode =
  2699. currentStock.value?.stockInfo?.code ||
  2700. currentStock.value?.stockInfo?.symbol;
  2701. if (parsedConclusion.value && stockCode) {
  2702. // 检查该股票是否是第一次触发
  2703. if (!stockTypewriterShown.value.has(stockCode)) {
  2704. // 如果是用户主动搜索,启动打字机效果和音频播放
  2705. if (isUserInitiated.value && audioUrl.value) {
  2706. console.log(
  2707. "用户主动搜索,该股票第一次进入场景应用,开始打字机效果和音频播放"
  2708. );
  2709. if (!stockAudioPlayed.value.has(stockCode)) {
  2710. console.log("开始音频播放和打字机效果");
  2711. stockAudioPlayed.value.set(stockCode, true);
  2712. playAudioQueue(parsedConclusion.value, true);
  2713. } else {
  2714. // 如果音频已播放过,只启动打字机效果
  2715. startTypewriterEffect(parsedConclusion.value);
  2716. }
  2717. stockTypewriterShown.value.set(stockCode, true);
  2718. } else {
  2719. // 非用户主动搜索(如历史记录恢复),直接显示完整内容
  2720. console.log(
  2721. "非用户主动搜索,该股票第一次进入场景应用,直接显示完整内容"
  2722. );
  2723. const conclusion = parsedConclusion.value;
  2724. displayedTexts.value = {
  2725. one1: conclusion.one1 || "",
  2726. one2: conclusion.one2 || "",
  2727. two: conclusion.two || "",
  2728. three: conclusion.three || "",
  2729. four: conclusion.four || "",
  2730. disclaimer: "该内容由AI生成,请注意甄别",
  2731. };
  2732. displayedTitles.value = {
  2733. one: "L1: 情绪监控",
  2734. two: "L2: 情绪解码",
  2735. three: "L3: 情绪推演",
  2736. four: "L4: 情绪套利",
  2737. };
  2738. // 显示所有有内容的模块
  2739. moduleVisibility.value = {
  2740. one: !!(conclusion.one1 || conclusion.one2),
  2741. two: !!conclusion.two,
  2742. three: !!conclusion.three,
  2743. four: !!conclusion.four,
  2744. disclaimer: true,
  2745. };
  2746. // 记录该股票已显示过
  2747. stockTypewriterShown.value.set(stockCode, true);
  2748. stockAudioPlayed.value.set(stockCode, true);
  2749. }
  2750. } else {
  2751. // 非第一次或已经触发过:直接显示完整内容,不播放音频和打字机效果
  2752. console.log("非第一次进入场景应用或已触发过,直接显示完整内容");
  2753. // 直接显示完整内容
  2754. const conclusion = parsedConclusion.value;
  2755. displayedTexts.value = {
  2756. one1: conclusion.one1 || "",
  2757. one2: conclusion.one2 || "",
  2758. two: conclusion.two || "",
  2759. three: conclusion.three || "",
  2760. four: conclusion.four || "",
  2761. disclaimer: "该内容由AI生成,请注意甄别",
  2762. };
  2763. displayedTitles.value = {
  2764. one: "L1: 情绪监控",
  2765. two: "L2: 情绪解码",
  2766. three: "L3: 情绪推演",
  2767. four: "L4: 情绪套利",
  2768. };
  2769. // 显示所有有内容的模块
  2770. moduleVisibility.value = {
  2771. one: !!(conclusion.one1 || conclusion.one2),
  2772. two: !!conclusion.two,
  2773. three: !!conclusion.three,
  2774. four: !!conclusion.four,
  2775. disclaimer: true,
  2776. };
  2777. }
  2778. }
  2779. }
  2780. });
  2781. },
  2782. {
  2783. threshold: 0.3, // 当30%的元素进入视口时触发
  2784. rootMargin: "0px 0px -100px 0px", // 提前100px触发
  2785. }
  2786. );
  2787. observer.observe(scenarioApplicationRef.value);
  2788. intersectionObserver.value = observer;
  2789. }
  2790. // 手动触发自动滚动函数已移除
  2791. // 返回顶部功能
  2792. const scrollToTop = () => {
  2793. const topAnchor = document.getElementById("top-anchor");
  2794. if (topAnchor) {
  2795. topAnchor.scrollIntoView({
  2796. behavior: "smooth",
  2797. block: "start",
  2798. inline: "nearest",
  2799. });
  2800. } else {
  2801. window.scrollTo({ top: 0, behavior: "smooth" });
  2802. }
  2803. // 备用方案:直接滚动到页面顶部
  2804. setTimeout(() => {
  2805. const currentScrollTop =
  2806. window.pageYOffset || document.documentElement.scrollTop;
  2807. if (currentScrollTop > 50) {
  2808. document.documentElement.scrollTop = 0;
  2809. document.body.scrollTop = 0;
  2810. }
  2811. }, 1000);
  2812. };
  2813. // 页面高度监听器
  2814. const heightObserver = ref(null);
  2815. const isAutoScrollEnabled = ref(false);
  2816. // 滚动到底部功能
  2817. const scrollToBottom = () => {
  2818. // 使用nextTick确保DOM已更新
  2819. nextTick(() => {
  2820. // 获取页面的总高度
  2821. const documentHeight = Math.max(
  2822. document.body.scrollHeight,
  2823. document.body.offsetHeight,
  2824. document.documentElement.clientHeight,
  2825. document.documentElement.scrollHeight,
  2826. document.documentElement.offsetHeight
  2827. );
  2828. // 平滑滚动到页面底部
  2829. window.scrollTo({
  2830. top: documentHeight,
  2831. behavior: "smooth",
  2832. });
  2833. // 备用方案:直接设置滚动位置
  2834. setTimeout(() => {
  2835. document.documentElement.scrollTop = documentHeight;
  2836. document.body.scrollTop = documentHeight;
  2837. }, 1000);
  2838. });
  2839. };
  2840. // 防抖滚动函数
  2841. const debouncedScrollToBottom = (() => {
  2842. let timeoutId = null;
  2843. return () => {
  2844. if (timeoutId) {
  2845. clearTimeout(timeoutId);
  2846. }
  2847. timeoutId = setTimeout(() => {
  2848. if (isAutoScrollEnabled.value && isPageLoaded.value) {
  2849. scrollToBottom();
  2850. }
  2851. }, 150);
  2852. };
  2853. })();
  2854. // 启动页面高度监听器
  2855. const startHeightObserver = () => {
  2856. // 先停止之前的监听器
  2857. stopHeightObserver();
  2858. isAutoScrollEnabled.value = true;
  2859. // 创建ResizeObserver监听页面内容变化
  2860. heightObserver.value = new ResizeObserver((entries) => {
  2861. if (isAutoScrollEnabled.value && isPageLoaded.value) {
  2862. debouncedScrollToBottom();
  2863. }
  2864. });
  2865. // 监听document.body的尺寸变化
  2866. if (document.body) {
  2867. heightObserver.value.observe(document.body);
  2868. }
  2869. // 创建MutationObserver监听DOM结构变化
  2870. const mutationObserver = new MutationObserver((mutations) => {
  2871. let shouldScroll = false;
  2872. mutations.forEach((mutation) => {
  2873. if (mutation.type === "childList" && mutation.addedNodes.length > 0) {
  2874. // 检查新增的节点是否包含实际内容
  2875. const hasContent = Array.from(mutation.addedNodes).some((node) => {
  2876. if (node.nodeType === Node.ELEMENT_NODE) {
  2877. return node.offsetHeight > 0 || node.scrollHeight > 0;
  2878. }
  2879. return (
  2880. node.nodeType === Node.TEXT_NODE &&
  2881. node.textContent.trim().length > 0
  2882. );
  2883. });
  2884. if (hasContent) {
  2885. shouldScroll = true;
  2886. }
  2887. }
  2888. });
  2889. if (shouldScroll && isAutoScrollEnabled.value && isPageLoaded.value) {
  2890. debouncedScrollToBottom();
  2891. }
  2892. });
  2893. // 监听主要内容区域的DOM变化
  2894. const mainContainer = document.querySelector(".main") || document.body;
  2895. if (mainContainer) {
  2896. mutationObserver.observe(mainContainer, {
  2897. childList: true,
  2898. subtree: true,
  2899. attributes: false,
  2900. characterData: true,
  2901. });
  2902. }
  2903. // 保存mutationObserver引用以便清理
  2904. heightObserver.value.mutationObserver = mutationObserver;
  2905. console.log("页面高度监听器已启动");
  2906. };
  2907. // 停止页面高度监听器
  2908. const stopHeightObserver = () => {
  2909. isAutoScrollEnabled.value = false;
  2910. if (heightObserver.value) {
  2911. // 清理ResizeObserver
  2912. heightObserver.value.disconnect();
  2913. // 清理MutationObserver
  2914. if (heightObserver.value.mutationObserver) {
  2915. heightObserver.value.mutationObserver.disconnect();
  2916. heightObserver.value.mutationObserver = null;
  2917. }
  2918. heightObserver.value = null;
  2919. }
  2920. console.log("页面高度监听器已停止");
  2921. };
  2922. // 监听页面滚动,控制返回顶部按钮显示
  2923. const handlePageScroll = () => {
  2924. const scrollTop =
  2925. window.pageYOffset ||
  2926. document.documentElement.scrollTop ||
  2927. document.body.scrollTop;
  2928. showBackToTop.value = scrollTop > 200;
  2929. };
  2930. // 监听容器滚动(备用方案)
  2931. const handleContainerScroll = () => {
  2932. const container = userInputDisplayRef.value;
  2933. if (container) {
  2934. const scrollTop = container.scrollTop;
  2935. if (scrollTop > 200) {
  2936. showBackToTop.value = true;
  2937. }
  2938. }
  2939. };
  2940. // 页面挂载完成后触发图片旋转和设置滚动监听
  2941. onMounted(async () => {
  2942. // 恢复对话记录
  2943. loadConversationsFromStore();
  2944. // 从stockList加载对话记录
  2945. loadConversationsFromStockList();
  2946. // 确保获取用户次数
  2947. // try {
  2948. // await chatStore.getUserCount();
  2949. // console.log('情绪大模型页面:用户次数获取成功');
  2950. // } catch (error) {
  2951. // console.error('情绪大模型页面:获取用户次数失败', error);
  2952. // }
  2953. // 添加全局resize监听器,确保所有图表和容器响应页面宽度变化
  2954. const globalResizeHandler = debounce(() => {
  2955. console.log("AiEmotion页面:窗口大小变化,触发容器和图表resize");
  2956. // 强制重新计算容器布局
  2957. const mainContainer = document.querySelector(".main");
  2958. if (mainContainer) {
  2959. // 触发重排,确保容器尺寸正确更新
  2960. mainContainer.style.display = "none";
  2961. mainContainer.offsetHeight; // 强制重排
  2962. mainContainer.style.display = "";
  2963. }
  2964. // 触发所有图表组件的resize
  2965. const resizeHandlers = [
  2966. window.emoEnergyConverterResizeHandler,
  2967. window.marketTempResizeHandler,
  2968. window.emotionalBottomRadarResizeHandler,
  2969. window.emotionDecodResizeHandler,
  2970. ];
  2971. resizeHandlers.forEach((handler) => {
  2972. if (typeof handler === "function") {
  2973. try {
  2974. handler();
  2975. } catch (error) {
  2976. console.error("AiEmotion页面:图表resize失败", error);
  2977. }
  2978. }
  2979. });
  2980. // 延迟再次触发图表resize,确保容器尺寸稳定后图表能正确适配
  2981. setTimeout(() => {
  2982. resizeHandlers.forEach((handler) => {
  2983. if (typeof handler === "function") {
  2984. try {
  2985. handler();
  2986. } catch (error) {
  2987. console.error("AiEmotion页面:延迟图表resize失败", error);
  2988. }
  2989. }
  2990. });
  2991. }, 100);
  2992. }, 150); // 150ms防抖延迟
  2993. // 移除之前的监听器(如果存在)
  2994. if (window.aiEmotionGlobalResizeHandler) {
  2995. window.removeEventListener("resize", window.aiEmotionGlobalResizeHandler);
  2996. }
  2997. // 添加新的监听器
  2998. window.addEventListener("resize", globalResizeHandler);
  2999. window.aiEmotionGlobalResizeHandler = globalResizeHandler;
  3000. // 添加滚动事件监听器
  3001. const container = userInputDisplayRef.value;
  3002. if (container) {
  3003. container.addEventListener("wheel", handleWheel, { passive: true });
  3004. container.addEventListener("touchmove", handleTouchMove, { passive: true });
  3005. container.addEventListener("scroll", handleUserScroll, { passive: true });
  3006. // 添加容器滚动监听器用于返回顶部按钮
  3007. container.addEventListener("scroll", handleContainerScroll, {
  3008. passive: true,
  3009. });
  3010. }
  3011. // 添加页面滚动监听器,控制返回顶部按钮显示
  3012. window.addEventListener("scroll", handlePageScroll, { passive: true });
  3013. // 添加document滚动监听器(备用方案)
  3014. document.addEventListener("scroll", handlePageScroll, { passive: true });
  3015. // 防抖函数定义
  3016. function debounce(func, wait) {
  3017. let timeout;
  3018. return function executedFunction(...args) {
  3019. const later = () => {
  3020. clearTimeout(timeout);
  3021. func(...args);
  3022. };
  3023. clearTimeout(timeout);
  3024. timeout = setTimeout(later, wait);
  3025. };
  3026. }
  3027. startImageRotation();
  3028. // 检查是否有已保存的股票数据需要恢复
  3029. if (emotionStore.stockList.length > 0 && emotionStore.activeStock) {
  3030. console.log("检测到已保存的股票数据,开始恢复页面状态(不自动播放音频)");
  3031. // 恢复页面加载状态
  3032. isPageLoaded.value = true;
  3033. // 使用nextTick确保DOM更新后清空对话显示并启动高度监听器
  3034. nextTick(() => {
  3035. messages.value = [];
  3036. // 启动页面高度监听器,实时监听内容变化并自动滚动
  3037. startHeightObserver();
  3038. // 立即滚动到底部
  3039. scrollToBottom();
  3040. });
  3041. // 等待DOM渲染后恢复图表和数据
  3042. nextTick(() => {
  3043. const currentStockData = emotionStore.activeStock;
  3044. if (currentStockData && currentStockData.apiData) {
  3045. console.log("恢复图表数据:", currentStockData.stockInfo.name);
  3046. renderCharts(currentStockData.apiData);
  3047. // 恢复结论数据并显示内容
  3048. if (currentStockData.conclusionData) {
  3049. conclusionData.value = currentStockData.conclusionData;
  3050. // 直接显示所有内容,不使用打字机效果
  3051. const conclusion = currentStockData.conclusionData;
  3052. displayedTexts.value = {
  3053. one1: conclusion.one1 || "",
  3054. one2: conclusion.one2 || "",
  3055. two: conclusion.two || "",
  3056. three: conclusion.three || "",
  3057. four: conclusion.four || "",
  3058. disclaimer: "该内容由AI生成,请注意甄别",
  3059. };
  3060. displayedTitles.value = {
  3061. one: conclusion.one1 || conclusion.one2 ? "L1: 情绪监控" : "",
  3062. two: conclusion.two ? "L2: 情绪解码" : "",
  3063. three: conclusion.three ? "L3: 情绪推演" : "",
  3064. four: conclusion.four ? "L4: 情绪套利" : "",
  3065. };
  3066. moduleVisibility.value = {
  3067. one: !!(conclusion.one1 || conclusion.one2),
  3068. two: !!conclusion.two,
  3069. three: !!conclusion.three,
  3070. four: !!conclusion.four,
  3071. disclaimer: true,
  3072. };
  3073. // 标记该股票的打字机效果和音频已经显示过,避免后续自动触发
  3074. const stockCode =
  3075. currentStockData.stockInfo?.code ||
  3076. currentStockData.stockInfo?.symbol;
  3077. if (stockCode) {
  3078. stockTypewriterShown.value.set(stockCode, true);
  3079. stockAudioPlayed.value.set(stockCode, true);
  3080. }
  3081. }
  3082. }
  3083. setupIntersectionObserver();
  3084. });
  3085. } else {
  3086. // 没有保存的数据,正常设置监听器
  3087. nextTick(() => {
  3088. setupIntersectionObserver();
  3089. });
  3090. }
  3091. });
  3092. // 组件卸载时清理定时器、音频和observer
  3093. onUnmounted(() => {
  3094. clearTypewriterTimers();
  3095. // 如果有未完成的回调函数,调用它来重新启用输入框
  3096. if (
  3097. currentOnCompleteCallback.value &&
  3098. typeof currentOnCompleteCallback.value === "function"
  3099. ) {
  3100. currentOnCompleteCallback.value();
  3101. currentOnCompleteCallback.value = null;
  3102. }
  3103. stopAudio();
  3104. // 重置触发状态
  3105. hasTriggeredAudio.value = false;
  3106. hasTriggeredTypewriter.value = false;
  3107. // 清理页面高度监听器
  3108. stopHeightObserver();
  3109. // 清理Intersection Observer
  3110. if (intersectionObserver.value) {
  3111. intersectionObserver.value.disconnect();
  3112. intersectionObserver.value = null;
  3113. }
  3114. // 清理全局resize监听器
  3115. if (window.aiEmotionGlobalResizeHandler) {
  3116. window.removeEventListener("resize", window.aiEmotionGlobalResizeHandler);
  3117. window.aiEmotionGlobalResizeHandler = null;
  3118. }
  3119. // 清理滚动事件监听器
  3120. const container = userInputDisplayRef.value;
  3121. if (container) {
  3122. container.removeEventListener("wheel", handleWheel);
  3123. container.removeEventListener("touchmove", handleTouchMove);
  3124. container.removeEventListener("scroll", handleUserScroll);
  3125. container.removeEventListener("scroll", handleContainerScroll);
  3126. }
  3127. // 清理页面滚动监听器
  3128. window.removeEventListener("scroll", handlePageScroll);
  3129. document.removeEventListener("scroll", handlePageScroll);
  3130. // 滚动相关清理已简化
  3131. });
  3132. // 声明组件可以触发的事件
  3133. const emit = defineEmits(["updateMessage", "sendMessage", "ensureAIchat"]);
  3134. // 导出方法供外部使用(已在上方定义)
  3135. </script>
  3136. <style scoped>
  3137. /* 股票统计概览样式 */
  3138. .stock-statistics-overview {
  3139. background: rgba(255, 255, 255, 0.95);
  3140. border-radius: 15px;
  3141. padding: 20px;
  3142. margin-bottom: 20px;
  3143. box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
  3144. backdrop-filter: blur(10px);
  3145. border: 1px solid rgba(255, 255, 255, 0.2);
  3146. }
  3147. .statistics-header {
  3148. display: flex;
  3149. justify-content: space-between;
  3150. align-items: center;
  3151. margin-bottom: 15px;
  3152. padding-bottom: 10px;
  3153. border-bottom: 2px solid #f0f0f0;
  3154. }
  3155. .statistics-header h3 {
  3156. margin: 0;
  3157. color: #333;
  3158. font-size: 18px;
  3159. font-weight: 600;
  3160. }
  3161. .stock-count {
  3162. background: linear-gradient(45deg, #667eea, #764ba2);
  3163. color: white;
  3164. padding: 5px 12px;
  3165. border-radius: 20px;
  3166. font-size: 12px;
  3167. font-weight: 500;
  3168. }
  3169. .statistics-content {
  3170. display: grid;
  3171. grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  3172. gap: 15px;
  3173. margin-bottom: 20px;
  3174. }
  3175. .stat-item {
  3176. display: flex;
  3177. justify-content: space-between;
  3178. align-items: center;
  3179. padding: 10px 15px;
  3180. background: rgba(102, 126, 234, 0.1);
  3181. border-radius: 8px;
  3182. border-left: 4px solid #667eea;
  3183. }
  3184. .stat-label {
  3185. color: #666;
  3186. font-size: 14px;
  3187. font-weight: 500;
  3188. }
  3189. .stat-value {
  3190. color: #333;
  3191. font-size: 16px;
  3192. font-weight: 600;
  3193. }
  3194. .stat-value.hot-temp {
  3195. color: #ff4757;
  3196. }
  3197. .stat-value.cold-temp {
  3198. color: #3742fa;
  3199. }
  3200. .temperature-distribution {
  3201. display: flex;
  3202. flex-wrap: wrap;
  3203. gap: 10px;
  3204. }
  3205. .distribution-item {
  3206. display: flex;
  3207. align-items: center;
  3208. gap: 8px;
  3209. padding: 8px 12px;
  3210. background: rgba(255, 255, 255, 0.8);
  3211. border-radius: 20px;
  3212. border: 1px solid #e0e0e0;
  3213. }
  3214. .temp-level {
  3215. font-size: 12px;
  3216. font-weight: 500;
  3217. padding: 2px 8px;
  3218. border-radius: 10px;
  3219. color: white;
  3220. }
  3221. .temp-level.hot {
  3222. background: #ff4757;
  3223. }
  3224. .temp-level.warm {
  3225. background: #ff6b35;
  3226. }
  3227. .temp-level.normal {
  3228. background: #26de81;
  3229. }
  3230. .temp-level.cool {
  3231. background: #45aaf2;
  3232. }
  3233. .temp-level.cold {
  3234. background: #3742fa;
  3235. }
  3236. .temp-count {
  3237. color: #666;
  3238. font-size: 12px;
  3239. font-weight: 500;
  3240. }
  3241. .matrix-header {
  3242. width: 100%;
  3243. display: flex;
  3244. align-items: center;
  3245. }
  3246. .disclaimer-item p {
  3247. color: #ffffff !important;
  3248. font-size: 24px;
  3249. font-weight: bold;
  3250. }
  3251. .temperature-content {
  3252. padding-top: 8%;
  3253. display: flex;
  3254. align-items: center;
  3255. justify-content: center;
  3256. gap: 10rem;
  3257. }
  3258. .temperature-content .content1 {
  3259. display: flex;
  3260. flex-direction: column;
  3261. align-items: center;
  3262. }
  3263. .temperature-content .content1 img {
  3264. scale: 0.5;
  3265. }
  3266. .temperature-display {
  3267. display: flex;
  3268. flex-direction: column;
  3269. /* 竖向排列元素 */
  3270. /* margin-left: 15%; */
  3271. gap: 30px;
  3272. /* margin-top: -12%; */
  3273. /* width: 100%; */
  3274. /* height: auto; */
  3275. }
  3276. .temperature-display::after {
  3277. content: "";
  3278. display: table;
  3279. clear: both;
  3280. }
  3281. .temperature-content .temperature-hot {
  3282. background-image: url("@/assets/img/AiEmotion/redBorder.png");
  3283. background-repeat: no-repeat;
  3284. background-size: 100% 100%;
  3285. /* width: 50%; */
  3286. width: 22vw;
  3287. max-width: 400px;
  3288. min-width: 200px;
  3289. text-align: center;
  3290. font-size: 24px;
  3291. color: white;
  3292. display: flex;
  3293. justify-content: center;
  3294. align-items: center;
  3295. flex-shrink: 0;
  3296. }
  3297. .temperature-content .temperature-cold {
  3298. background-image: url("@/assets/img/AiEmotion/blueBorder.png");
  3299. background-repeat: no-repeat;
  3300. background-size: 100% 100%;
  3301. /* width: 35%; */
  3302. width: 22vw;
  3303. max-width: 400px;
  3304. min-width: 200px;
  3305. text-align: center;
  3306. font-size: 24px;
  3307. color: white;
  3308. display: flex;
  3309. justify-content: center;
  3310. align-items: center;
  3311. flex-shrink: 0;
  3312. }
  3313. .golden-wheel {
  3314. width: 100%;
  3315. display: flex;
  3316. justify-content: center;
  3317. }
  3318. .golden-wheel-img {
  3319. width: 60%;
  3320. max-width: 500px;
  3321. height: auto;
  3322. }
  3323. /* 定义旋转动画 */
  3324. @keyframes rotate {
  3325. from {
  3326. transform: rotate(0deg);
  3327. }
  3328. to {
  3329. transform: rotate(360deg);
  3330. }
  3331. }
  3332. /* 应用动画到图片 */
  3333. .rotating-image {
  3334. animation: rotate 5s linear;
  3335. /* 5 秒完成一次旋转,线性速度*/
  3336. will-change: transform;
  3337. /* 优化动画性能 */
  3338. }
  3339. .bk-image {
  3340. background-image: url("@/assets/img/AiEmotion/bk00000.png");
  3341. background-size: 100% 100%;
  3342. background-repeat: no-repeat;
  3343. width: 50vw;
  3344. height: auto;
  3345. margin: 0 auto;
  3346. margin-top: 20px;
  3347. }
  3348. .bk-image .conclusion-container {
  3349. padding: 20px;
  3350. border-radius: 15px;
  3351. margin: 20px;
  3352. }
  3353. .bk-image .conclusion-container .conclusion-item {
  3354. border-radius: 12px;
  3355. transition: all 0.3s ease;
  3356. overflow: hidden;
  3357. }
  3358. .bk-image .conclusion-container .conclusion-item:last-child {
  3359. margin-bottom: 0;
  3360. }
  3361. .bk-image .conclusion-container .conclusion-item .conclusion-title {
  3362. color: #ffd700;
  3363. font-size: 22px;
  3364. font-weight: bold;
  3365. margin: 0 0 15px 0;
  3366. text-align: center;
  3367. letter-spacing: 2px;
  3368. margin-top: 22px;
  3369. }
  3370. .bk-image .conclusion-container .conclusion-item .conclusion-text {
  3371. color: #ffffff;
  3372. font-size: 20px;
  3373. line-height: 1.8;
  3374. margin: 0 0 12px 0;
  3375. text-align: center;
  3376. word-wrap: break-word;
  3377. position: relative;
  3378. }
  3379. .bk-image .conclusion-container .conclusion-item .conclusion-text:last-child {
  3380. margin-bottom: 0;
  3381. }
  3382. .bk-image .conclusion-placeholder {
  3383. padding: 30px;
  3384. text-align: center;
  3385. border-radius: 12px;
  3386. }
  3387. .bk-image .conclusion-placeholder p {
  3388. color: #999999;
  3389. font-size: 16px;
  3390. margin: 0;
  3391. font-style: italic;
  3392. }
  3393. /* 最后文字的颜色 */
  3394. .text-container {
  3395. position: relative;
  3396. color: white;
  3397. text-align: left;
  3398. padding: 20px;
  3399. border-radius: 15px;
  3400. }
  3401. /* .text-container p {
  3402. margin: 0 auto;
  3403. font-size: 40px;
  3404. margin-left: 0%;
  3405. border-radius: 12px;
  3406. transition: all 0.3s ease;
  3407. overflow: hidden;
  3408. letter-spacing: 2px;
  3409. } */
  3410. .text-container .title {
  3411. display: block;
  3412. color: #ffd700;
  3413. font-weight: bold;
  3414. margin-top: 0px;
  3415. margin-bottom: 20px;
  3416. font-size: 22px;
  3417. text-align: center;
  3418. }
  3419. .text-container .content {
  3420. display: block;
  3421. color: white;
  3422. text-align: center;
  3423. font-size: 22px;
  3424. }
  3425. .core-logic-section {
  3426. background-image: url("@/assets/img/AiEmotion/bk00000.png");
  3427. background-size: cover;
  3428. background-repeat: no-repeat;
  3429. width: 95%;
  3430. height: auto;
  3431. min-height: 70rem;
  3432. margin: 0 auto;
  3433. }
  3434. .core-logic-header {
  3435. margin: 0 auto;
  3436. width: fit-content;
  3437. margin-top: 2%;
  3438. margin-bottom: 1%;
  3439. }
  3440. .core-highlights-header {
  3441. margin: 0 auto;
  3442. /* width: fit-content; */
  3443. margin-top: 2%;
  3444. margin-bottom: 1%;
  3445. display: flex;
  3446. align-items: center;
  3447. justify-content: center;
  3448. }
  3449. .emotion-decoder-content {
  3450. /* width: 80vw; */
  3451. margin: 0 auto;
  3452. }
  3453. .energy-converter-content {
  3454. min-width: 100%;
  3455. margin-top: 3%;
  3456. }
  3457. .bottom-radar-header {
  3458. display: flex;
  3459. justify-content: center;
  3460. align-items: center;
  3461. flex-direction: column;
  3462. }
  3463. .bottom-radar-header img {
  3464. scale: 0.5;
  3465. }
  3466. .energy-converter-header {
  3467. display: flex;
  3468. justify-content: center;
  3469. align-items: center;
  3470. flex-direction: column;
  3471. }
  3472. .energy-converter-header img {
  3473. scale: 0.5;
  3474. }
  3475. .bottom-radar-icon {
  3476. width: fit-content;
  3477. height: auto;
  3478. margin: 0 auto;
  3479. margin-top: 2%;
  3480. margin-bottom: 1%;
  3481. display: flex;
  3482. align-items: center;
  3483. justify-content: center;
  3484. }
  3485. .energy-converter-icon {
  3486. width: fit-content;
  3487. height: auto;
  3488. margin: 0 auto;
  3489. margin-top: 2%;
  3490. margin-bottom: 1%;
  3491. display: flex;
  3492. align-items: center;
  3493. justify-content: center;
  3494. }
  3495. .core-logic-content {
  3496. margin: 0 auto;
  3497. width: fit-content;
  3498. }
  3499. .market-temperature-icon {
  3500. width: fit-content;
  3501. height: auto;
  3502. margin: 0 auto;
  3503. margin-top: 2%;
  3504. margin-bottom: 1%;
  3505. display: flex;
  3506. align-items: center;
  3507. justify-content: center;
  3508. }
  3509. .bottom-radar-title {
  3510. margin: 0 auto;
  3511. width: fit-content;
  3512. margin-top: 2%;
  3513. margin-bottom: 1%;
  3514. }
  3515. .emotion-decoder-title {
  3516. margin: 0 auto;
  3517. width: fit-content;
  3518. margin-top: 2%;
  3519. margin-bottom: 1%;
  3520. }
  3521. .temperature-title {
  3522. margin: 0 auto;
  3523. width: fit-content;
  3524. margin-top: 2%;
  3525. margin-bottom: 1%;
  3526. }
  3527. .matrix-title {
  3528. margin: 0 auto;
  3529. width: fit-content;
  3530. margin-bottom: 1%;
  3531. }
  3532. .emotion-decoder-header {
  3533. display: flex;
  3534. flex-direction: column;
  3535. justify-content: center;
  3536. align-items: center;
  3537. }
  3538. .emotion-decoder-header img {
  3539. scale: 0.5;
  3540. }
  3541. .emotion-decoder-icon {
  3542. width: fit-content;
  3543. height: auto;
  3544. margin: 0 auto;
  3545. margin-top: 2%;
  3546. margin-bottom: 1%;
  3547. display: flex;
  3548. align-items: center;
  3549. justify-content: center;
  3550. }
  3551. .emotion-decoder-text {
  3552. color: white;
  3553. font-size: 20px;
  3554. font-weight: bold;
  3555. /* margin-left: 45%; */
  3556. }
  3557. .bottom-radar-text {
  3558. color: white;
  3559. font-size: 20px;
  3560. font-weight: bold;
  3561. /* margin-left: 44.6%; */
  3562. }
  3563. .energy-converter-text {
  3564. color: white;
  3565. font-size: 20px;
  3566. font-weight: bold;
  3567. /* margin-left: 44%; */
  3568. }
  3569. .scenario-application-section {
  3570. text-align: center;
  3571. margin-top: 2%;
  3572. margin-bottom: 1%;
  3573. }
  3574. /* 为需要放大的图片添加样式 */
  3575. .scaled-img {
  3576. background-image: url("@/assets/img/AiEmotion/tree00000.jpg");
  3577. background-size: 100% 100%;
  3578. background-position: center;
  3579. background-repeat: no-repeat;
  3580. width: 80%;
  3581. height: 350px;
  3582. margin: 0 auto;
  3583. margin-top: 2%;
  3584. margin-bottom: 3%;
  3585. }
  3586. .lz-img {
  3587. text-align: center;
  3588. padding-top: 30px;
  3589. }
  3590. .decision-tree-section {
  3591. background-image: url("@/assets/img/AiEmotion/bk00000.png");
  3592. background-size: 100% 100%;
  3593. background-repeat: no-repeat;
  3594. width: 50vw;
  3595. height: auto;
  3596. min-height: 30rem;
  3597. margin: 0 auto;
  3598. }
  3599. .energy-converter-section {
  3600. background-image: url("@/assets/img/AiEmotion/bk00000.png");
  3601. background-size: 100% 100%;
  3602. background-repeat: no-repeat;
  3603. width: 50vw;
  3604. height: auto;
  3605. margin: 0 auto;
  3606. box-sizing: border-box;
  3607. transition: all 0.3s ease;
  3608. min-height: 85vh;
  3609. }
  3610. .bottom-radar-section {
  3611. background-image: url("@/assets/img/AiEmotion/bk00000.png");
  3612. background-size: 100% 100%;
  3613. background-repeat: no-repeat;
  3614. width: 50vw;
  3615. max-width: 100%;
  3616. height: auto;
  3617. margin: 0 auto;
  3618. box-sizing: border-box;
  3619. transition: all 0.3s ease;
  3620. }
  3621. .emotion-decoder-section {
  3622. background-image: url("@/assets/img/AiEmotion/bk00000.png");
  3623. background-size: 100% 100%;
  3624. background-repeat: no-repeat;
  3625. width: 50vw;
  3626. max-width: 100%;
  3627. height: auto;
  3628. margin: 0 auto;
  3629. box-sizing: border-box;
  3630. transition: all 0.3s ease;
  3631. padding-bottom: 1rem;
  3632. }
  3633. .market-temperature-section {
  3634. background-image: url("@/assets/img/AiEmotion/bk00000.png");
  3635. background-size: 100% 100%;
  3636. background-repeat: no-repeat;
  3637. width: 50vw;
  3638. max-width: 100%;
  3639. height: auto;
  3640. min-height: 70rem;
  3641. margin: 0 auto;
  3642. box-sizing: border-box;
  3643. transition: all 0.3s ease;
  3644. }
  3645. .main-content-wrapper {
  3646. background-size: 100% 100%;
  3647. background-repeat: no-repeat;
  3648. width: 77vw;
  3649. max-width: 100%;
  3650. height: auto;
  3651. margin: 0 auto;
  3652. box-sizing: border-box;
  3653. transition: all 0.3s ease;
  3654. }
  3655. .matrix-content {
  3656. display: flex;
  3657. flex-direction: column;
  3658. align-items: center;
  3659. /* 竖向排列元素 */
  3660. /* gap: 1rem; */
  3661. /* margin-left: 10%; */
  3662. }
  3663. .matrix-main-title {
  3664. color: white;
  3665. font-size: 20px;
  3666. font-weight: bold;
  3667. margin-left: 0%;
  3668. }
  3669. .market-temperature-value {
  3670. font-size: 1.5rem;
  3671. font-weight: bold;
  3672. color: white;
  3673. margin-left: auto;
  3674. }
  3675. .market-temperature-label {
  3676. background-image: url("@/assets/img/AiEmotion/bk01.png");
  3677. background-size: 100% 100%;
  3678. background-repeat: no-repeat;
  3679. padding: 10px;
  3680. color: #fff;
  3681. font-size: 20px;
  3682. font-weight: bold;
  3683. text-align: center;
  3684. margin-left: 0;
  3685. width: 30%;
  3686. min-width: 200px;
  3687. max-width: 50%;
  3688. height: auto;
  3689. overflow: hidden;
  3690. text-overflow: ellipsis;
  3691. white-space: nowrap;
  3692. box-sizing: border-box;
  3693. }
  3694. .main {
  3695. width: 83%;
  3696. max-width: 1400px;
  3697. min-width: 320px;
  3698. min-height: 100px;
  3699. height: auto;
  3700. padding: 1rem;
  3701. box-sizing: border-box;
  3702. background-color: #2b378d;
  3703. margin: 0 auto;
  3704. transition: width 0.3s ease;
  3705. margin-bottom: 10rem;
  3706. }
  3707. .ai-emotion-container {
  3708. display: flex;
  3709. flex-direction: column;
  3710. align-items: center;
  3711. justify-content: center;
  3712. padding: 20px;
  3713. position: relative;
  3714. }
  3715. .user-input-display {
  3716. margin-top: 20px;
  3717. display: flex;
  3718. flex-direction: column;
  3719. width: 100%;
  3720. }
  3721. .message-container {
  3722. display: flex;
  3723. margin-bottom: 30px;
  3724. width: 100%;
  3725. }
  3726. /* 用户消息容器样式 */
  3727. .user-message-container {
  3728. align-items: center;
  3729. margin-left: auto;
  3730. gap: 10px;
  3731. margin-right: 5px;
  3732. }
  3733. .user-content {
  3734. display: flex;
  3735. height: 100%;
  3736. align-items: center;
  3737. margin-right: 5px;
  3738. }
  3739. .user-message-speaker {
  3740. width: 32px;
  3741. height: 32px;
  3742. object-fit: contain;
  3743. margin-right: 5px;
  3744. cursor: pointer;
  3745. transition: all 0.3s ease;
  3746. }
  3747. .user-sendTime {
  3748. width: 100%;
  3749. text-align: center;
  3750. color: rgba(255, 255, 255, 0.6);
  3751. font-size: 0.8rem;
  3752. }
  3753. .user-message-speaker:hover {
  3754. transform: scale(1.1);
  3755. }
  3756. .user-message-speaker.speaker-active {
  3757. animation: pulse 1.5s infinite;
  3758. }
  3759. @keyframes pulse {
  3760. 0% {
  3761. transform: scale(1);
  3762. }
  3763. 50% {
  3764. transform: scale(1.1);
  3765. }
  3766. 100% {
  3767. transform: scale(1);
  3768. }
  3769. }
  3770. .user-message {
  3771. color: #6d22f8;
  3772. background: white;
  3773. font-weight: bold;
  3774. padding: 15px 20px;
  3775. border-radius: 15px;
  3776. max-width: 60%;
  3777. text-align: left;
  3778. box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
  3779. margin: 0;
  3780. /* 将用户消息推到右边 */
  3781. }
  3782. /* AI消息容器样式 */
  3783. .ai-message-container {
  3784. background-color: #f1f1f1;
  3785. border-radius: 15px;
  3786. align-items: flex-start;
  3787. gap: 10px;
  3788. margin-right: auto;
  3789. /* max-width: 80%; */
  3790. white-space: normal;
  3791. width: fit-content;
  3792. overflow: visible;
  3793. align-items: center;
  3794. display: flex;
  3795. }
  3796. /* 思考过程动图样式 */
  3797. .thinking-gif {
  3798. width: 40px;
  3799. height: 40px;
  3800. object-fit: contain;
  3801. margin-top: 5px;
  3802. border-radius: 8px;
  3803. animation: float 2s ease-in-out infinite;
  3804. }
  3805. @keyframes float {
  3806. 0%,
  3807. 100% {
  3808. transform: translateY(0px);
  3809. }
  3810. 50% {
  3811. transform: translateY(-5px);
  3812. }
  3813. }
  3814. /* 动态加载点样式 */
  3815. .loading-dots {
  3816. display: inline-block;
  3817. }
  3818. .dot {
  3819. opacity: 0.4;
  3820. animation: loading 1.4s infinite;
  3821. }
  3822. .dot:nth-child(1) {
  3823. animation-delay: 0s;
  3824. }
  3825. .dot:nth-child(2) {
  3826. animation-delay: 0.2s;
  3827. }
  3828. .dot:nth-child(3) {
  3829. animation-delay: 0.4s;
  3830. }
  3831. .dot:nth-child(4) {
  3832. animation-delay: 0.6s;
  3833. }
  3834. .dot:nth-child(5) {
  3835. animation-delay: 0.8s;
  3836. }
  3837. .dot:nth-child(6) {
  3838. animation-delay: 1s;
  3839. }
  3840. @keyframes loading {
  3841. 0%,
  3842. 60%,
  3843. 100% {
  3844. opacity: 0.4;
  3845. }
  3846. 30% {
  3847. opacity: 1;
  3848. }
  3849. }
  3850. .ai-message {
  3851. /* background-color: #f1f1f1; */
  3852. color: #000000;
  3853. font-weight: bold;
  3854. padding: 20px 30px;
  3855. border-radius: 15px;
  3856. text-align: left;
  3857. margin-right: auto;
  3858. /* 将AI消息保持在左边 */
  3859. white-space: nowrap;
  3860. width: fit-content;
  3861. overflow: visible;
  3862. align-items: center;
  3863. display: flex;
  3864. }
  3865. .input-container {
  3866. display: flex;
  3867. align-items: center;
  3868. gap: 10px;
  3869. }
  3870. .fixed-bottom {
  3871. position: fixed;
  3872. bottom: 100px;
  3873. left: 0;
  3874. width: 100%;
  3875. background-color: #f8f9fa;
  3876. padding: 10px 20px;
  3877. box-shadow: 0 -2px 5px rgba(0, 0, 0, 0.1);
  3878. }
  3879. .input-box {
  3880. padding: 10px;
  3881. font-size: 16px;
  3882. border: 1px solid #ccc;
  3883. border-radius: 5px;
  3884. width: calc(100% - 120px);
  3885. }
  3886. .send-button {
  3887. padding: 10px 20px;
  3888. font-size: 16px;
  3889. color: #fff;
  3890. background-color: #007bff;
  3891. border: none;
  3892. border-radius: 5px;
  3893. cursor: pointer;
  3894. }
  3895. .send-button:hover {
  3896. background-color: #0056b3;
  3897. }
  3898. /* 响应式布局媒体查询 */
  3899. @media only screen and (max-width: 1200px) {
  3900. .main {
  3901. width: 95%;
  3902. padding: 0.8rem;
  3903. }
  3904. .market-temperature-label {
  3905. width: 40%;
  3906. min-width: 170px;
  3907. max-width: 60%;
  3908. font-size: 1.3rem;
  3909. overflow: hidden;
  3910. text-overflow: ellipsis;
  3911. white-space: nowrap;
  3912. }
  3913. .market-temperature-value {
  3914. font-size: 1.3rem;
  3915. }
  3916. /* 调整图表容器高度 */
  3917. /* .class00 {
  3918. min-height: 45rem;
  3919. } */
  3920. .market-temperature-section {
  3921. min-height: 60rem;
  3922. }
  3923. .decision-tree-section {
  3924. min-height: 42rem;
  3925. }
  3926. .scaled-img {
  3927. height: 350px;
  3928. min-height: 30rem;
  3929. }
  3930. }
  3931. @media only screen and (max-width: 992px) {
  3932. .main {
  3933. width: 98%;
  3934. padding: 0.6rem;
  3935. }
  3936. /* 调整图表容器高度 */
  3937. /* .class00 {
  3938. min-height: 40rem;
  3939. } */
  3940. .market-temperature-section {
  3941. min-height: 55rem;
  3942. }
  3943. .decision-tree-section {
  3944. min-height: 35rem;
  3945. }
  3946. .scaled-img {
  3947. height: 300px;
  3948. min-height: 25rem;
  3949. background-size: contain;
  3950. }
  3951. }
  3952. /* 手机端适配样式 */
  3953. @media only screen and (max-width: 768px) {
  3954. .text-container .content {
  3955. display: block;
  3956. color: white;
  3957. text-align: center;
  3958. font-size: 20px;
  3959. }
  3960. .market-temperature-icon {
  3961. width: auto;
  3962. height: auto;
  3963. display: flex;
  3964. align-items: center;
  3965. justify-content: center;
  3966. scale: 0.5;
  3967. }
  3968. .matrix-header {
  3969. display: flex;
  3970. align-items: center;
  3971. }
  3972. .main {
  3973. width: 100%;
  3974. padding: 0.5rem;
  3975. margin-bottom: 5rem;
  3976. }
  3977. .energy-converter-text {
  3978. color: white;
  3979. font-size: 20px;
  3980. font-weight: bold;
  3981. margin-left: 28%;
  3982. }
  3983. .energy-converter-content {
  3984. min-width: 100%;
  3985. /* margin-top: 25%; */
  3986. }
  3987. .scaled-img {
  3988. background-image: url("@/assets/img/AiEmotion/tree00000.jpg");
  3989. background-size: 100% 100%;
  3990. background-position: center;
  3991. background-repeat: no-repeat;
  3992. background-size: contain;
  3993. text-align: center;
  3994. width: 90%;
  3995. margin-top: 4%;
  3996. height: 200px;
  3997. min-height: 200px;
  3998. }
  3999. .bottom-radar-text {
  4000. color: white;
  4001. font-size: 20px;
  4002. font-weight: bold;
  4003. margin-left: 30%;
  4004. }
  4005. .emotion-decoder-text {
  4006. color: white;
  4007. font-size: 20px;
  4008. font-weight: bold;
  4009. margin-left: 30%;
  4010. }
  4011. /* 图片样式 */
  4012. .golden-wheel img {
  4013. width: 50%;
  4014. }
  4015. .matrix-title img {
  4016. width: 100%;
  4017. }
  4018. .temperature-title img {
  4019. width: 100%;
  4020. margin: 10px 10px;
  4021. }
  4022. .emotion-decoder-title img {
  4023. width: 100%;
  4024. margin: 10px 10px;
  4025. }
  4026. .bottom-radar-title img {
  4027. width: 100%;
  4028. margin: 10px 10px;
  4029. }
  4030. .core-highlights-header img {
  4031. scale: 0.5;
  4032. }
  4033. .core-logic-header img {
  4034. width: 100%;
  4035. margin: 10px 10px;
  4036. }
  4037. .scaled-img img {
  4038. width: 30%;
  4039. height: auto;
  4040. }
  4041. .scenario-application-section img {
  4042. width: 100%;
  4043. margin: 10px 10px;
  4044. }
  4045. .matrix-main-title {
  4046. font-size: 20px;
  4047. margin-left: 5%;
  4048. }
  4049. /* .span01 {
  4050. width: 50%;
  4051. min-width: 150px;
  4052. max-width: 70%;
  4053. font-size: 16px;
  4054. overflow: hidden;
  4055. text-overflow: ellipsis;
  4056. white-space: nowrap;
  4057. padding: 8px;
  4058. } */
  4059. .matrix-header .market-temperature-value {
  4060. font-size: 14px;
  4061. color: white;
  4062. float: right;
  4063. }
  4064. .market-temperature-section {
  4065. background-image: url("@/assets/img/AiEmotion/bk00000.png");
  4066. background-size: 100% 100%;
  4067. background-repeat: no-repeat;
  4068. width: 100%;
  4069. /* margin-left: -45px; */
  4070. height: auto;
  4071. }
  4072. .main {
  4073. min-height: 100px;
  4074. height: auto;
  4075. box-sizing: border-box;
  4076. background-color: #02107d;
  4077. margin-bottom: 10rem;
  4078. }
  4079. .emotion-decoder-section {
  4080. width: 80%;
  4081. height: auto;
  4082. margin: 0 auto;
  4083. /* min-height: 38rem; */
  4084. /* min-height: 51rem; */
  4085. /* margin-left: -39px; */
  4086. /* min-height: 38rem; */
  4087. }
  4088. /* 调整其他图表容器高度 */
  4089. /* .class00 {
  4090. min-height: 35rem;
  4091. } */
  4092. .market-temperature-section {
  4093. min-height: 45rem;
  4094. }
  4095. .matrix-header img {
  4096. width: 68%;
  4097. height: auto;
  4098. /* margin-top: 5%; */
  4099. margin-left: 0%;
  4100. }
  4101. .emotion-decoder-icon {
  4102. width: 25%;
  4103. height: auto;
  4104. scale: 0.5;
  4105. }
  4106. .bottom-radar-icon,
  4107. .energy-converter-icon {
  4108. width: 25%;
  4109. height: auto;
  4110. scale: 0.5;
  4111. }
  4112. .lz-img {
  4113. margin-bottom: 0;
  4114. padding-top: 0;
  4115. img {
  4116. width: 30%;
  4117. height: auto;
  4118. margin-top: 5%;
  4119. }
  4120. }
  4121. .decision-tree-section {
  4122. background-size: 100% 100%;
  4123. background-repeat: no-repeat;
  4124. width: 80vw;
  4125. height: auto;
  4126. min-height: 20rem;
  4127. margin: 0 auto;
  4128. }
  4129. .bk-image {
  4130. .conclusion-container {
  4131. padding: 15px;
  4132. border-radius: 8px;
  4133. margin: 8px;
  4134. .conclusion-item {
  4135. &:last-child {
  4136. margin-bottom: 0;
  4137. }
  4138. .conclusion-title {
  4139. color: #ffd700;
  4140. font-size: 16px;
  4141. font-weight: bold;
  4142. margin: 0 0 8px 0;
  4143. text-align: center;
  4144. }
  4145. .conclusion-text {
  4146. color: #ffffff;
  4147. font-size: 14px;
  4148. line-height: 1.5;
  4149. margin: 0 0 6px 0;
  4150. text-align: left;
  4151. word-wrap: break-word;
  4152. &:last-child {
  4153. margin-bottom: 0;
  4154. }
  4155. }
  4156. }
  4157. }
  4158. .conclusion-placeholder {
  4159. padding: 15px;
  4160. text-align: center;
  4161. p {
  4162. color: #999999;
  4163. font-size: 12px;
  4164. margin: 0;
  4165. }
  4166. }
  4167. }
  4168. .bk-image {
  4169. background-size: 100% 100%;
  4170. background-repeat: no-repeat;
  4171. width: 80vw;
  4172. height: auto;
  4173. margin: 0 auto;
  4174. .conclusion-container {
  4175. padding-top: 20px;
  4176. border-radius: 15px;
  4177. margin: 20px;
  4178. .conclusion-item {
  4179. border-radius: 12px;
  4180. transition: all 0.3s ease;
  4181. overflow: hidden;
  4182. }
  4183. .conclusion-item:last-child {
  4184. margin-bottom: 0;
  4185. }
  4186. .conclusion-item .conclusion-title {
  4187. color: #ffd700;
  4188. font-size: 22px;
  4189. font-weight: bold;
  4190. text-align: center;
  4191. letter-spacing: 2px;
  4192. margin-top: 22px;
  4193. }
  4194. .conclusion-item .conclusion-text {
  4195. color: #ffffff;
  4196. font-size: 20px;
  4197. line-height: 1.8;
  4198. margin: 0 0 12px 0;
  4199. text-align: center;
  4200. word-wrap: break-word;
  4201. position: relative;
  4202. }
  4203. .conclusion-item .conclusion-text:last-child {
  4204. margin-bottom: 0;
  4205. }
  4206. }
  4207. .conclusion-placeholder {
  4208. padding: 30px;
  4209. text-align: center;
  4210. border-radius: 12px;
  4211. background: rgba(255, 255, 255, 0.05);
  4212. border: 1px dashed rgba(153, 153, 153, 0.3);
  4213. }
  4214. .conclusion-placeholder p {
  4215. color: #999999;
  4216. font-size: 16px;
  4217. margin: 0;
  4218. font-style: italic;
  4219. }
  4220. .disclaimer-item {
  4221. /* margin-top: 30px; */
  4222. padding-bottom: 15%;
  4223. text-align: center;
  4224. }
  4225. .disclaimer-item p {
  4226. color: #ffffff !important;
  4227. font-size: 18px;
  4228. margin: 0;
  4229. letter-spacing: 1px;
  4230. }
  4231. }
  4232. .bottom-radar-section {
  4233. background-size: 100% 100%;
  4234. background-repeat: no-repeat;
  4235. width: 80%;
  4236. height: auto;
  4237. /* min-height: 48rem; */
  4238. }
  4239. .energy-converter-section {
  4240. background-size: 100% 100%;
  4241. background-repeat: no-repeat;
  4242. width: 80%;
  4243. height: auto;
  4244. margin: 0 auto;
  4245. min-height: 55vh;
  4246. }
  4247. .temperature-display {
  4248. display: flex;
  4249. flex-direction: column;
  4250. /* margin-left: 5rem; */
  4251. gap: 0;
  4252. /* margin-top: -6rem; */
  4253. /* width: 100%; */
  4254. height: auto;
  4255. }
  4256. .temperature-content .temperature-cold,
  4257. .temperature-content .temperature-hot {
  4258. min-width: 200px;
  4259. font-size: 16px;
  4260. }
  4261. .temperature-content {
  4262. padding-top: 8%;
  4263. display: flex;
  4264. align-items: center;
  4265. justify-content: center;
  4266. gap: 0rem;
  4267. }
  4268. .market-temperature-label {
  4269. background-image: url("@/assets/img/AiEmotion/bk01.png");
  4270. background-size: 100% 100%;
  4271. background-repeat: no-repeat;
  4272. display: inline-block;
  4273. padding: 10px;
  4274. color: #fff;
  4275. font-size: 14px;
  4276. text-align: center;
  4277. width: 50%;
  4278. }
  4279. .temperature-display {
  4280. flex-direction: column;
  4281. gap: 1rem;
  4282. align-items: center;
  4283. }
  4284. /* .span01 {
  4285. width: 60%;
  4286. font-size: 1.2rem;
  4287. padding: 8px;
  4288. } */
  4289. .market-temperature-value {
  4290. font-size: 1.2rem;
  4291. }
  4292. .matrix-main-title,
  4293. .emotion-decoder-text,
  4294. .bottom-radar-text,
  4295. .energy-converter-text {
  4296. font-size: 18px;
  4297. margin-left: 0;
  4298. }
  4299. }
  4300. /* 超小屏幕设备 */
  4301. @media only screen and (max-width: 480px) {
  4302. .main {
  4303. width: 100%;
  4304. padding: 0.3rem;
  4305. margin-bottom: 3rem;
  4306. }
  4307. .temperature-display {
  4308. flex-direction: column;
  4309. gap: 0.8rem;
  4310. align-items: center;
  4311. }
  4312. .temperature-content .temperature-cold,
  4313. .temperature-content .temperature-hot {
  4314. /* width: 90%; */
  4315. width: 10vw;
  4316. min-width: 120px;
  4317. font-size: 14px;
  4318. }
  4319. /* .span01 {
  4320. width: 50%;
  4321. font-size: 1rem;
  4322. padding: 6px;
  4323. } */
  4324. .market-temperature-value {
  4325. font-size: 1rem;
  4326. }
  4327. .golden-wheel-img {
  4328. width: 80%;
  4329. }
  4330. /* 调整图表容器高度适配超小屏幕 */
  4331. /* .class00 {
  4332. min-height: 25rem;
  4333. } */
  4334. .market-temperature-section {
  4335. min-height: 35rem;
  4336. }
  4337. .decision-tree-section {
  4338. min-height: 15rem;
  4339. }
  4340. .scaled-img {
  4341. height: 150px;
  4342. min-height: 150px;
  4343. }
  4344. }
  4345. /* 加载提示样式 */
  4346. /* .loading-container {
  4347. display: flex;
  4348. justify-content: center;
  4349. align-items: center;
  4350. min-height: 20vh;
  4351. padding: 20px 10px;
  4352. } */
  4353. /* .loading-content {
  4354. text-align: center;
  4355. background: linear-gradient(135deg, rgba(0, 212, 255, 0.15) 0%, rgba(0, 100, 200, 0.15) 100%);
  4356. border: 2px solid rgba(0, 212, 255, 0.4);
  4357. border-radius: 20px;
  4358. padding: 40px;
  4359. box-shadow: 0 8px 25px rgba(0, 212, 255, 0.3);
  4360. } */
  4361. /* .loading-spinner {
  4362. width: 60px;
  4363. height: 60px;
  4364. border: 4px solid rgba(0, 212, 255, 0.3);
  4365. border-top: 4px solid #00d4ff;
  4366. border-radius: 50%;
  4367. animation: spin 1s linear infinite;
  4368. margin: 0 auto 20px;
  4369. } */
  4370. @keyframes spin {
  4371. 0% {
  4372. transform: rotate(0deg);
  4373. }
  4374. 100% {
  4375. transform: rotate(360deg);
  4376. }
  4377. }
  4378. /* .loading-text {
  4379. color: #00d4ff;
  4380. font-size: 18px;
  4381. font-weight: bold;
  4382. text-shadow: 0 2px 8px rgba(0, 212, 255, 0.5);
  4383. letter-spacing: 1px;
  4384. } */
  4385. /* 对话区域样式 */
  4386. .conversation-area {
  4387. width: 100%;
  4388. padding: 0 20px;
  4389. }
  4390. .message-list {
  4391. display: flex;
  4392. flex-direction: column;
  4393. gap: 15px;
  4394. }
  4395. .message-item {
  4396. width: 100%;
  4397. display: flex;
  4398. }
  4399. .user-message-item {
  4400. justify-content: flex-end;
  4401. }
  4402. .ai-message-item {
  4403. justify-content: flex-start;
  4404. }
  4405. .user-message-wrapper {
  4406. display: flex;
  4407. justify-content: flex-end;
  4408. max-width: 70%;
  4409. }
  4410. .ai-message-wrapper {
  4411. display: flex;
  4412. justify-content: flex-start;
  4413. max-width: 80%;
  4414. }
  4415. /* 顶部锚点样式 */
  4416. .top-anchor {
  4417. position: relative;
  4418. top: 0;
  4419. left: 0;
  4420. width: 100%;
  4421. height: 1px;
  4422. display: block;
  4423. visibility: visible;
  4424. opacity: 0;
  4425. pointer-events: none;
  4426. }
  4427. /* 返回顶部按钮样式 */
  4428. .back-to-top {
  4429. position: sticky !important;
  4430. bottom: 20px !important;
  4431. left: calc(100% - 70px) !important;
  4432. width: 50px !important;
  4433. height: 50px !important;
  4434. background: linear-gradient(135deg, #00d4ff 0%, #0066cc 100%) !important;
  4435. border-radius: 50% !important;
  4436. display: flex !important;
  4437. align-items: center !important;
  4438. justify-content: center !important;
  4439. cursor: pointer !important;
  4440. transition: all 0.3s ease !important;
  4441. z-index: 100 !important;
  4442. color: white !important;
  4443. opacity: 1 !important;
  4444. visibility: visible !important;
  4445. margin-top: 20px !important;
  4446. margin-bottom: 20px !important;
  4447. }
  4448. .back-to-top:hover {
  4449. transform: translateY(-3px);
  4450. box-shadow: 0 6px 20px rgba(0, 212, 255, 0.5);
  4451. background: linear-gradient(135deg, #00e6ff 0%, #0077dd 100%);
  4452. }
  4453. .back-to-top:active {
  4454. transform: translateY(-1px);
  4455. }
  4456. /* 页面主容器样式 */
  4457. .page-container {
  4458. position: relative;
  4459. width: 100%;
  4460. min-height: 100vh;
  4461. }
  4462. .master:last-child {
  4463. border-bottom: none;
  4464. margin-bottom: 0;
  4465. }
  4466. /* class01容器样式 */
  4467. .main {
  4468. position: relative;
  4469. }
  4470. /* 移动端适配 */
  4471. @media only screen and (max-width: 768px) {
  4472. .back-to-top {
  4473. left: calc(100% - 65px) !important;
  4474. width: 45px !important;
  4475. height: 45px !important;
  4476. }
  4477. }
  4478. @media only screen and (max-width: 480px) {
  4479. .back-to-top {
  4480. left: calc(100% - 60px) !important;
  4481. width: 40px !important;
  4482. height: 40px !important;
  4483. }
  4484. .back-to-top svg {
  4485. width: 20px;
  4486. height: 20px;
  4487. }
  4488. }
  4489. </style>