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.

5006 lines
145 KiB

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