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.

1401 lines
34 KiB

4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
  1. <template>
  2. <view class="deepMate-page">
  3. <!-- 顶部导航栏 -->
  4. <view class="header" :style="{ paddingTop: safeAreaInsets?.top + 'px' }">
  5. <view class="header-left">
  6. <image
  7. src="https://d31zlh4on95l9h.cloudfront.net/images/f91e09b5987802185e7679055dafd272.svg"
  8. class="icon"
  9. >
  10. </image>
  11. </view>
  12. <view class="header-center">
  13. <text class="title" :style="{ paddingTop: safeAreaInsets?.top + 'px' }"
  14. >DeepMate</text
  15. >
  16. </view>
  17. <view class="header-right">
  18. <image
  19. src="https://d31zlh4on95l9h.cloudfront.net/images/d7c4e74201213a25dd9574e908233928.svg"
  20. class="icon"
  21. >
  22. </image>
  23. <image
  24. style="margin-left: 10px"
  25. src="https://d31zlh4on95l9h.cloudfront.net/images/099903c4aabf5713488b5cb60815e3f7.svg"
  26. class="icon"
  27. @click="openHistoryDrawer"
  28. ></image>
  29. <!-- 新增新会话按钮
  30. <button class="new-chat-button" @click="newChat">
  31. <text class="new-chat-text">新会话</text>
  32. </button> -->
  33. </view>
  34. </view>
  35. <!-- 主要内容区域 -->
  36. <view class="main-content">
  37. <view class="banner-panel" v-if="messages.length === 0">
  38. <image
  39. src="https://d31zlh4on95l9h.cloudfront.net/images/42e18bd7fe97d4f4f37aa70439a0990b.svg"
  40. class="pray-banner"
  41. ></image>
  42. <view class="contain">
  43. <!-- 机器人头像和欢迎语 -->
  44. <view class="robot-container" v-if="messages.length === 0">
  45. <image
  46. src="https://d31zlh4on95l9h.cloudfront.net/images/61fa384381c88ad80be28f41827fe0e5.svg"
  47. class="robot-avatar"
  48. ></image>
  49. <view class="welcome-message">
  50. <text class="greeting">Hi, 我是您的股市随身顾问~</text>
  51. <text class="description"
  52. >个股诊断市场情绪解读都可以找我</text
  53. >
  54. </view>
  55. </view>
  56. <!-- 功能标签栏 -->
  57. <!-- <view class="function-tabs" v-if="messages.length === 0">
  58. <view ref="tabsTrack" class="tabs-track" :style="{ transform: 'translate3d(-' + marqueeOffset + 'px,0,0)' }">
  59. <view class="tab-item" v-for="(tab, idx) in marqueeList" :key="idx">{{ tab }}</view>
  60. </view>
  61. </view> -->
  62. <!-- 特斯拉推荐卡片 -->
  63. <view class="recommend-card" v-if="messages.length === 0">
  64. <view class="arrow" v-if="messages.length === 0"></view>
  65. <view class="card-content">
  66. <image
  67. src="../../static/images/tesla-logo.png"
  68. class="logo"
  69. ></image>
  70. <view class="card-text">
  71. <text class="main-question">当前特斯拉该如何布局</text>
  72. <text class="stock-code">TSLA</text>
  73. </view>
  74. <image
  75. src="https://d31zlh4on95l9h.cloudfront.net/images/40d94054644f6e3f1c366751f07f0010.svg"
  76. class="arrow-icon"
  77. @click="goBlank"
  78. ></image>
  79. </view>
  80. </view>
  81. </view>
  82. </view>
  83. <!-- 可能感兴趣的话题 -->
  84. <!-- <view v-if="messages.length === 0" class="interest-section">
  85. <text class="section-title">- 您可能感兴趣 -</text>
  86. <view class="topics-list">
  87. <view class="topic-item" v-for="topic in hotTopics" :key="topic.id">
  88. <image :src="topic.icon" class="tag-icon"></image>
  89. <text class="topic-text" @click="sendMessageList(topic.text)">{{
  90. topic.text
  91. }}</text>
  92. </view>
  93. </view>
  94. </view> -->
  95. <!-- 聊天区域 -->
  96. <!-- 顶部粘性欢迎块始终保留在聊天上方 -->
  97. <view class="chat-header" v-if="messages.length > 0">
  98. <view class="robot-container">
  99. <image
  100. src="https://d31zlh4on95l9h.cloudfront.net/images/61fa384381c88ad80be28f41827fe0e5.svg"
  101. class="robot-avatar"
  102. ></image>
  103. <view class="welcome-message">
  104. <text class="greeting">Hi, 我是您的股市随身顾问~</text>
  105. <text class="description"
  106. >个股诊断市场情绪解读都可以找我</text
  107. >
  108. </view>
  109. </view>
  110. </view>
  111. <scroll-view
  112. class="chat-container"
  113. scroll-y="true"
  114. :scroll-top="chatScrollTop"
  115. @scroll="onChatScroll"
  116. v-if="messages.length > 0"
  117. >
  118. <view class="message-list" id="messageList">
  119. <view
  120. v-for="(message, index) in messages"
  121. :key="index"
  122. :class="
  123. message.isUser ? 'message user-message' : 'message bot-message'
  124. "
  125. >
  126. <!-- 会话图标 -->
  127. <text
  128. :class="
  129. message.isUser
  130. ? 'fa-solid fa-user message-icon'
  131. : 'fa-solid fa-robot message-icon'
  132. "
  133. ></text>
  134. <!-- 会话内容 -->
  135. <view class="message-content">
  136. <!-- <text class="message-text">{{ message.content }}</text> -->
  137. <!-- loading -->
  138. <view
  139. class="loading-dots"
  140. v-if="message.isThinking || !message.isUser"
  141. >
  142. <view class="thinking-process">
  143. <view class="thinking-header">
  144. <view class="thinking-icon"></view>
  145. <view class="thinking-title">{{
  146. message.isTyping ? "正在思考" : "思考完成"
  147. }}</view>
  148. <view class="thinking-count"> </view>
  149. <view
  150. class="thinking-toggle"
  151. @click="message.isThinking = !message.isThinking"
  152. >
  153. <span v-if="message.isThinking"></span>
  154. <span v-else></span>
  155. </view>
  156. </view>
  157. <view v-show="message.isThinking" class="thinking-content">
  158. <view class="thinking-item">
  159. <view class="item-status">
  160. <span class="checkmark"></span>
  161. </view>
  162. <view class="item-text">问题分析完成</view>
  163. </view>
  164. <view class="thinking-item">
  165. <view class="item-status">
  166. <span class="checkmark"></span>
  167. </view>
  168. <view class="item-text">收集相关信息</view>
  169. </view>
  170. </view>
  171. </view>
  172. </view>
  173. <!-- 使用 rich-text 渲染 Markdown 内容 -->
  174. <rich-text
  175. v-if="!message.isUser"
  176. class="message-text"
  177. :nodes="renderMarkdown(message.content)"
  178. ></rich-text>
  179. <text v-else class="message-text">{{ message.content }}</text>
  180. </view>
  181. </view>
  182. </view>
  183. </scroll-view>
  184. </view>
  185. <!-- 输入框区域 -->
  186. <view class="input-area">
  187. <view class="input-wrapper">
  188. <input
  189. type="text"
  190. placeholder="请输入股票代码/名称,获取AI洞察"
  191. placeholder-style="color:#fff;opacity:1"
  192. class="input-field"
  193. v-model="inputMessage"
  194. @confirm="sendMessage"
  195. />
  196. <image class="send-button" @click="sendMessage" :disabled="isSending">
  197. <!-- <image
  198. src="https://d31zlh4on95l9h.cloudfront.net/images/95f1ea2262e9157db13c93c0dc1c5d96.svg"
  199. class="send-icon"
  200. ></image> -->
  201. </image>
  202. </view>
  203. <text class="disclaimer"
  204. >以上数据由AI生成不作为最终投资建议决策需独立</text
  205. >
  206. </view>
  207. <image
  208. class="back-to-top"
  209. src="https://d31zlh4on95l9h.cloudfront.net/images/ba357635d2bb480241952bb1cabacd73.svg"
  210. :style="{
  211. transform: 'translate3d(' + backTopX + 'px,' + backTopY + 'px,0)',
  212. }"
  213. @touchstart="onBackTopTouchStart"
  214. @touchmove="onBackTopTouchMove"
  215. @touchend="onBackTopTouchEnd"
  216. @click="onBackTopClick"
  217. ></image>
  218. <!-- 搜索历史侧拉框 -->
  219. <view class="drawer-overlay" v-show="showHistoryDrawer"></view>
  220. <view
  221. class="drawer-panel"
  222. v-show="showHistoryDrawer"
  223. @click.stop
  224. :style="{ transform: 'translateX(' + drawerOffsetX + 'px)' }"
  225. >
  226. <view class="drawer-back" @click="onDrawerBackClick"
  227. ><text class="drawer-back-icon">></text></view
  228. >
  229. <view class="drawer-header">
  230. <text class="drawer-title">搜索历史</text>
  231. <!-- <text class="drawer-close" @click="closeHistoryDrawer">×</text> -->
  232. </view>
  233. <scroll-view scroll-y="true" class="drawer-content">
  234. <view v-if="searchHistory.length === 0" class="empty-history">
  235. <text>暂无搜索历史</text>
  236. </view>
  237. <view
  238. v-for="(item, idx) in searchHistory"
  239. :key="idx"
  240. class="history-card"
  241. >
  242. <text class="history-query">{{ item.query }}</text>
  243. <text class="history-time">{{ formatTime(item.time) }}</text>
  244. </view>
  245. </scroll-view>
  246. </view>
  247. <footerBar class="static-footer" :type="type"></footerBar>
  248. </view>
  249. </template>
  250. <script setup>
  251. const { safeAreaInsets } = uni.getSystemInfoSync();
  252. import { ref, computed, onMounted, onUnmounted, watch, nextTick } from "vue";
  253. import footerBar from "../../components/footerBar-cn";
  254. import marked from "marked"; // 引入 marked 库
  255. import { onPageScroll } from "@dcloudio/uni-app";
  256. import { postStock, postIntent } from "../../api/deepMate/deepMate";
  257. // 设置 marked 选项
  258. marked.setOptions({
  259. renderer: new marked.Renderer(),
  260. highlight: null, // 如果需要代码高亮,可以设置适当的函数
  261. langPrefix: "language-",
  262. pedantic: false,
  263. gfm: true,
  264. breaks: false,
  265. sanitize: false,
  266. smartLists: true,
  267. smartypants: false,
  268. xhtml: false,
  269. });
  270. // 创建一个用于渲染 Markdown 的函数
  271. const renderMarkdown = (content) => {
  272. if (!content) return "";
  273. return marked.parse(content);
  274. };
  275. // 本地假数据:Tesla 报告(Markdown)
  276. const FAKE_MARKDOWN = `# <font color="#1890ff">Tesla Inc.全景作战报告</font>
  277. ## 📊 股票分析报告
  278. ### 📈 股票基本信息
  279. - **股票名称**: <font color="#52c41a">Tesla Inc.</font>
  280. - **股票代码**: <font color="#1890ff">TSLA</font>
  281. - **当前价格**: <font color="#ff4d4f">433.720</font>
  282. - **更新时间**: 2025年10月24日
  283. - **时间节点**: 今日无变盘点
  284. ### 🎯 核心价值评估
  285. - **安全边际**: <font color="#13c2c2">419.978 ~ 445.364</font>
  286. - **黄金价域**: <font color="#faad14">439.711 ~ 452.902</font>
  287. - **核心证据链**:
  288. - 🟢 **资金共识**: 当日多方资金<font color="#52c41a">流入</font>
  289. - 🔥 **趋势动能**: 该股中长期处于<b><font color='#FF0000'>上升趋势</font></b>短期处于<b><font color='#FF0000'>强势状态</font></b>
  290. ### 🕵 主力作战分析
  291. - **主力行为**:
  292. 1. 📊 该股庄家中长期筹码成本价格为 357.272短期资金成本价格为 408.076该股筹码分散当日筹码成本价格为 439.788
  293. 2. 🔍 近日没有出现主力集中吸筹
  294. 3. 📈 近期主力持仓比例大于散户持仓比例 当日主力持仓减少 当日散户持仓增加
  295. ### 📊 技术分析
  296. - **空间维度**:
  297. - 📉 预测低一值: <font color="#13c2c2">423.964</font>
  298. - 📈 预测高一值: <font color="#ff4d4f">469.696</font>
  299. - 📉 预测低二值: <font color="#13c2c2">433.213</font>
  300. - 📈 预测高二值: <font color="#ff4d4f">458.396</font>
  301. - **能量分析**: <font color="#722ed1">AI智能均线非多头排列当前卖盘大于买盘</font>
  302. ### 综合作战分析
  303. - **触发条件**: <font color="#fa8c16">当前股票处于安全区牵牛绳为红色出现蓝色推进K线</font>
  304. - **攻防指令**: <font color="#eb2f96">该股整体趋势相对较强个股正处于推进上涨的关键阶段若当前持有该股票建议继续持有进行持续跟踪若当前无该股票建议持续跟踪等待适当时机再进行介入</font>
  305. ---
  306. <font color="#8c8c8c">*该内容由AI生成仅供参考投资有风险请注意甄别*</font>`;
  307. const type = ref("member");
  308. const inputMessage = ref("");
  309. const showThinking = ref(true);
  310. const isSending = ref(false);
  311. const chatScrollTop = ref(0);
  312. const chatContainerHeight = ref(0);
  313. const uuid = ref("");
  314. const messages = ref([]);
  315. const showHistoryDrawer = ref(false);
  316. const drawerOffsetX = ref(0);
  317. const searchHistory = ref([]);
  318. const hotTopics = ref([
  319. {
  320. id: 1,
  321. text: "英伟达(NVDA)股票情绪温度?",
  322. icon: "https://d31zlh4on95l9h.cloudfront.net/images/7ed58be0f4b81aeb398d9ba2534a624b.svg",
  323. },
  324. {
  325. id: 2,
  326. text: "博通(AVGO)明天还能涨吗?",
  327. icon: "https://d31zlh4on95l9h.cloudfront.net/images/7ed58be0f4b81aeb398d9ba2534a624b.svg",
  328. },
  329. {
  330. id: 3,
  331. text: "为什么Fluence Energy(FLNC)会暴涨?",
  332. icon: "https://d31zlh4on95l9h.cloudfront.net/images/7ed58be0f4b81aeb398d9ba2534a624b.svg",
  333. },
  334. {
  335. id: 4,
  336. text: "为什么Fluence Energy(FLNC)会暴涨?",
  337. icon: "https://d31zlh4on95l9h.cloudfront.net/images/7ed58be0f4b81aeb398d9ba2534a624b.svg",
  338. },
  339. ]);
  340. // 统一 raf/caf(小程序端可能没有 rAF)
  341. // const hasRAF = typeof requestAnimationFrame === 'function';
  342. // const startFrame = (fn) => hasRAF ? requestAnimationFrame(fn) : setTimeout(fn, 16);
  343. // const stopFrame = (id) => hasRAF ? cancelAnimationFrame(id) : clearTimeout(id);
  344. // 初始化
  345. onMounted(() => {
  346. const sys = uni.getSystemInfoSync();
  347. const iconSize = uni.upx2px(100); // 和样式保持一致
  348. const reserveBottom = uni.upx2px(260); // 预留底部输入区域空间
  349. const initX = Math.max(0, sys.windowWidth - iconSize - uni.upx2px(30));
  350. const initY = Math.max(0, Math.floor(sys.windowHeight * 0.65) - iconSize);
  351. backTopTargetX.value = initX;
  352. backTopTargetY.value = initY;
  353. backTopX.value = initX;
  354. backTopY.value = initY;
  355. initUUID();
  356. if (messages.value.length === 0) {
  357. // nextTick(startTabsMarquee);
  358. }
  359. if (messages.value.length > 0) {
  360. nextTick(() => {
  361. measureChatContainer();
  362. scrollToBottom();
  363. });
  364. }
  365. // 载入历史
  366. const hist = uni.getStorageSync("search_history") || [];
  367. searchHistory.value = Array.isArray(hist) ? hist : [];
  368. });
  369. // 初始化 UUID
  370. const initUUID = () => {
  371. let storedUUID = uni.getStorageSync("user_uuid");
  372. if (!storedUUID) {
  373. storedUUID = generateUUID();
  374. uni.setStorageSync("user_uuid", storedUUID);
  375. }
  376. uuid.value = storedUUID;
  377. };
  378. // 生成简单UUID
  379. const generateUUID = () => {
  380. return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
  381. var r = (Math.random() * 16) | 0,
  382. v = c == "x" ? r : (r & 0x3) | 0x8;
  383. return v.toString(16);
  384. });
  385. };
  386. // 计算聊天容器可视高度
  387. const measureChatContainer = () => {
  388. const q = uni.createSelectorQuery();
  389. q.select(".chat-container").boundingClientRect();
  390. q.exec((res) => {
  391. chatContainerHeight.value = res[0]?.height || 0;
  392. });
  393. };
  394. // 新会话
  395. const newChat = () => {
  396. messages.value = [];
  397. uni.removeStorageSync("user_uuid");
  398. initUUID();
  399. };
  400. // 跳转到空白页
  401. const goBlank = () => {
  402. uni.navigateTo({
  403. url: "/pages/blank/blank",
  404. });
  405. };
  406. // 历史抽屉控制
  407. const openHistoryDrawer = () => {
  408. showHistoryDrawer.value = true;
  409. };
  410. const closeHistoryDrawer = () => {
  411. showHistoryDrawer.value = false;
  412. };
  413. const onDrawerBackClick = () => {
  414. drawerOffsetX.value = 500;
  415. setTimeout(() => {
  416. closeHistoryDrawer();
  417. drawerOffsetX.value = 0;
  418. }, 180);
  419. };
  420. // 时间格式化:YYYY-MM-DD HH:mm
  421. const pad2 = (n) => (n < 10 ? "0" + n : "" + n);
  422. const formatTime = (t) => {
  423. const d = new Date(t);
  424. const y = d.getFullYear();
  425. const m = pad2(d.getMonth() + 1);
  426. const day = pad2(d.getDate());
  427. const hh = pad2(d.getHours());
  428. const mm = pad2(d.getMinutes());
  429. return `${y}-${m}-${day} ${hh}:${mm}`;
  430. };
  431. // 发送消息
  432. const sendMessage = () => {
  433. if (inputMessage.value.trim() === "" || isSending.value) return;
  434. const userMessage = {
  435. content: inputMessage.value,
  436. isUser: true,
  437. isThinking: false,
  438. isTyping: false,
  439. };
  440. messages.value.push(userMessage);
  441. inputMessage.value = "";
  442. // 记录搜索历史
  443. const entry = { query: userMessage.content, time: Date.now() };
  444. searchHistory.value.unshift(entry);
  445. uni.setStorageSync("search_history", searchHistory.value);
  446. // 发送后强制恢复并滚到底部
  447. shouldAutoScroll.value = true;
  448. nextTick(() => {
  449. scrollToBottom();
  450. });
  451. // 模拟机器人回复
  452. simulateBotResponse(userMessage.content);
  453. };
  454. // 模拟机器人回复
  455. const simulateBotResponse = async (userMessage) => {
  456. isSending.value = true;
  457. // 添加机器人加载消息
  458. const botMsg = {
  459. content: "",
  460. isUser: false,
  461. isTyping: true,
  462. isThinking: true,
  463. };
  464. messages.value.push(botMsg);
  465. await new Promise((resolve) => setTimeout(resolve, 2000));
  466. // 首先进行意图识别
  467. const res = await postIntent({
  468. content: "森那美",
  469. language: "cn",
  470. marketlist: "hk,cn,usa,my,sg,vi,in,gb",
  471. token:
  472. "9ior41AF0xTIbIG2pRnnbZi0+fEeMx8pywnilrmTwo5FbqJ91WrSWOxp9MkpKiNtedtUafqvzIwpFKrwuMs",
  473. model: "1",
  474. });
  475. console.log("res" + res);
  476. // 意图识别不通过
  477. if (res.code !== 200) {
  478. return;
  479. }
  480. // 获取意图识别结果
  481. const recordId = res.data.recordId;
  482. const parentId = res.data.parentId;
  483. const stockId = res.data.stockId;
  484. await new Promise((resolve) => setTimeout(resolve, 2000));
  485. // 获取股票信息
  486. const StockInfo = await postStock({
  487. recordId,
  488. parentId,
  489. stockId,
  490. token:
  491. "9ior41AF0xTIbIG2pRnnbZi0+fEeMx8pywnilrmTwo5FbqJ91WrSWOxp9MkpKiNtedtUafqvzIwpFKrwuMs",
  492. language: "cn",
  493. });
  494. console.log("StockInfo", StockInfo);
  495. // if (StockInfo.code !== 200) {
  496. // return ;
  497. // }
  498. const markdown = StockInfo.markdown;
  499. console.log("StockInfo", StockInfo);
  500. // 添加请求延迟
  501. // const toDataInfo = await getData();
  502. // console.log(toDataInfo);
  503. // dataInfo.value = toDataInfo.data;
  504. // console.log(dataInfo.value);
  505. messages.value[messages.value.length - 1].isThinking = false;
  506. // 滚动到底部
  507. nextTick(() => {
  508. scrollToBottom();
  509. });
  510. // 模拟流式响应
  511. let responseText = `我已经收到您的消息: "${userMessage}"。+"${markdown}" `;
  512. let index = 0;
  513. const botIndex = messages.value.length - 1;
  514. const baseDelay = 5; // 普通字符基础延迟(毫秒)
  515. const slowPunct = /[。!?!?;;]/; // 句号、感叹号、分号等较长停顿
  516. const midPunct = /[,、,::]/; // 逗号、顿号、冒号等中等停顿
  517. const typeWriter = () => {
  518. if (index < responseText.length) {
  519. const ch = responseText.charAt(index);
  520. const current = messages.value[botIndex];
  521. // 通过数组替换触发渲染,避免部分平台对子项属性变更不响应
  522. messages.value.splice(botIndex, 1, {
  523. ...current,
  524. content: current.content + ch,
  525. isTyping: true,
  526. });
  527. index++;
  528. scrollToBottom();
  529. const delay = slowPunct.test(ch)
  530. ? 220
  531. : midPunct.test(ch)
  532. ? 120
  533. : baseDelay;
  534. setTimeout(typeWriter, delay);
  535. } else {
  536. const current = messages.value[botIndex];
  537. messages.value.splice(botIndex, 1, { ...current, isTyping: false });
  538. isSending.value = false;
  539. nextTick(() => {
  540. scrollToBottom();
  541. });
  542. }
  543. };
  544. // 启动前稍作停顿,避免过快开始
  545. setTimeout(typeWriter, 500);
  546. console.log("messages", messages);
  547. };
  548. // 当消息出现或变化时,测量容器并滚到底部
  549. watch(messages, (arr) => {
  550. if (arr.length > 0) {
  551. nextTick(() => {
  552. measureChatContainer();
  553. scrollToBottom();
  554. });
  555. }
  556. });
  557. // 滚动到底部(仅聊天区域滚动)
  558. const scrollToBottom = () => {
  559. if (!shouldAutoScroll.value) return;
  560. const query = uni.createSelectorQuery();
  561. query.select("#messageList").boundingClientRect();
  562. query.exec((res) => {
  563. if (res[0]) {
  564. latestContentHeight.value = res[0].height;
  565. chatScrollTop.value = res[0].height; // scroll-view 会自动夹紧到最大位置
  566. }
  567. });
  568. };
  569. const scrollToTop = () => {
  570. chatScrollTop.value = 0;
  571. };
  572. // 自动滚动控制:用户向上滚动时暂停自动滚到底部
  573. const shouldAutoScroll = ref(true);
  574. const latestContentHeight = ref(0);
  575. const lastScrollTop = ref(0);
  576. const windowHeight = uni.getSystemInfoSync().windowHeight;
  577. const AUTO_SCROLL_REENABLE_THRESHOLD = 40000; // px,接近底部时恢复自动滚动
  578. const onChatScroll = (e) => {
  579. const st = e.detail?.scrollTop || 0;
  580. const delta = st - lastScrollTop.value;
  581. lastScrollTop.value = st;
  582. if (delta < 0) {
  583. shouldAutoScroll.value = false;
  584. return;
  585. }
  586. const distanceToBottom =
  587. latestContentHeight.value - st - chatContainerHeight.value;
  588. if (distanceToBottom <= AUTO_SCROLL_REENABLE_THRESHOLD) {
  589. shouldAutoScroll.value = true;
  590. }
  591. };
  592. // 回到顶部图标拖拽状态
  593. const backTopX = ref(0);
  594. const backTopY = ref(0);
  595. const backTopDragging = ref(false);
  596. const backTopDragOffset = ref({ x: 0, y: 0 });
  597. const backTopTargetX = ref(0);
  598. const backTopTargetY = ref(0);
  599. let backTopRAF = 0;
  600. const backTopSmoothing = 0.15; // 越大越跟手,越小越顺滑
  601. const backTopEpsilon = 0.5; // 收敛阈值
  602. const raf =
  603. typeof requestAnimationFrame === "function"
  604. ? requestAnimationFrame
  605. : (fn) => setTimeout(fn, 16);
  606. const caf =
  607. typeof cancelAnimationFrame === "function"
  608. ? cancelAnimationFrame
  609. : (id) => clearTimeout(id);
  610. function stepBackTop() {
  611. const dx = backTopTargetX.value - backTopX.value;
  612. const dy = backTopTargetY.value - backTopY.value;
  613. // 插值缓动,避免每帧重排
  614. backTopX.value += dx * backTopSmoothing;
  615. backTopY.value += dy * backTopSmoothing;
  616. if (Math.abs(dx) > backTopEpsilon || Math.abs(dy) > backTopEpsilon) {
  617. backTopRAF = raf(stepBackTop);
  618. } else {
  619. backTopX.value = backTopTargetX.value;
  620. backTopY.value = backTopTargetY.value;
  621. backTopRAF = 0;
  622. }
  623. }
  624. function ensureBackTopRAF() {
  625. if (!backTopRAF) {
  626. backTopRAF = raf(stepBackTop);
  627. }
  628. }
  629. const clamp = (val, min, max) => Math.max(min, Math.min(val, max));
  630. const onBackTopTouchStart = (e) => {
  631. const t = e.touches && e.touches[0];
  632. if (!t) return;
  633. backTopDragging.value = false;
  634. backTopDragOffset.value = {
  635. x: t.pageX - backTopX.value,
  636. y: t.pageY - backTopY.value,
  637. };
  638. };
  639. const onBackTopTouchMove = (e) => {
  640. const t = e.touches && e.touches[0];
  641. if (!t) return;
  642. const sys = uni.getSystemInfoSync();
  643. const iconSize = uni.upx2px(100);
  644. const reserveBottom = uni.upx2px(260);
  645. const nx = t.pageX - backTopDragOffset.value.x;
  646. const ny = t.pageY - backTopDragOffset.value.y;
  647. const clampedX = clamp(nx, 0, sys.windowWidth - iconSize);
  648. const clampedY = clamp(ny, 0, sys.windowHeight - reserveBottom - iconSize);
  649. if (
  650. Math.abs(clampedX - backTopX.value) + Math.abs(clampedY - backTopY.value) >
  651. 3
  652. ) {
  653. backTopDragging.value = true;
  654. }
  655. backTopTargetX.value = clampedX;
  656. backTopTargetY.value = clampedY;
  657. ensureBackTopRAF();
  658. };
  659. const onBackTopTouchEnd = () => {
  660. // 结束拖拽即可
  661. };
  662. const onBackTopClick = () => {
  663. if (backTopDragging.value) return; // 拖拽时不触发点击回到顶部
  664. scrollToTop();
  665. };
  666. </script>
  667. <style scoped>
  668. .deepMate-page {
  669. display: flex;
  670. flex-direction: column;
  671. position: fixed;
  672. /* 充满视口,彻底禁用页面滚动 */
  673. top: 0;
  674. left: 0;
  675. right: 0;
  676. bottom: 0;
  677. height: 100vh;
  678. overflow: hidden;
  679. /* 锁定页面滚动 */
  680. background-color: #ffffff;
  681. padding: 20rpx 0rpx;
  682. }
  683. .header {
  684. display: flex;
  685. justify-content: space-between;
  686. align-items: center;
  687. padding: 20rpx 30rpx;
  688. background-color: #ffffff;
  689. box-shadow: 0 2rpx rgba(0, 0, 0, 0.1);
  690. }
  691. .header-left,
  692. .header-right {
  693. display: flex;
  694. align-items: center;
  695. }
  696. .header-left .icon,
  697. .header-right .icon {
  698. width: 40rpx;
  699. height: 40rpx;
  700. /* margin-right: 20rpx; */
  701. }
  702. .header-center .title {
  703. position: fixed;
  704. top: 10rpx;
  705. left: 50%;
  706. transform: translateX(-50%);
  707. font-size: 36rpx;
  708. font-weight: bold;
  709. color: #333333;
  710. }
  711. .new-chat-button {
  712. background-color: #ff6600;
  713. border: none;
  714. border-radius: 8rpx;
  715. padding: 10rpx 20rpx;
  716. }
  717. .new-chat-text {
  718. color: white;
  719. font-size: 24rpx;
  720. }
  721. .main-content {
  722. background-color: #fff;
  723. flex: 1;
  724. display: flex;
  725. flex-direction: column;
  726. overflow: hidden;
  727. /* 内部滚动交给聊天容器 */
  728. padding: 20rpx;
  729. margin-top: 1rpx;
  730. margin-bottom: 280rpx;
  731. }
  732. /* 聊天顶部粘性欢迎块样式 */
  733. .chat-header {
  734. position: sticky;
  735. top: 0;
  736. /* 在页面滚动时始终贴顶 */
  737. z-index: 50;
  738. background-color: #ffffff;
  739. padding: 3rpx 20rpx;
  740. }
  741. .robot-container {
  742. display: flex;
  743. align-items: center;
  744. margin-top: 30rpx;
  745. }
  746. .robot-avatar {
  747. width: 130rpx;
  748. height: 130rpx;
  749. border-radius: 50%;
  750. margin-left: 20rpx;
  751. }
  752. .welcome-message {
  753. flex: 1;
  754. }
  755. .greeting {
  756. font-size: 32rpx;
  757. margin-left: 50rpx;
  758. top: 40rpx;
  759. font-weight: bold;
  760. color: #333333;
  761. line-height: 48rpx;
  762. }
  763. .description {
  764. display: block;
  765. font-size: 24rpx;
  766. color: #666666;
  767. line-height: 36rpx;
  768. margin-top: 10rpx;
  769. margin-left: 45rpx;
  770. }
  771. .function-tabs {
  772. display: block;
  773. overflow: hidden;
  774. margin-bottom: 30rpx;
  775. }
  776. .tabs-track {
  777. display: inline-flex;
  778. white-space: nowrap;
  779. will-change: transform;
  780. }
  781. .tab-item {
  782. padding: 5rpx 20rpx;
  783. border-radius: 20rpx;
  784. font-size: 20rpx;
  785. font-weight: 700;
  786. color: #666666;
  787. background-color: #fffefe;
  788. margin-right: 20rpx;
  789. transition: all 0.3s;
  790. }
  791. .tab-item.active {
  792. color: #ff6600;
  793. background-color: #fff;
  794. border: 1rpx solid #ff6600;
  795. }
  796. .recommend-card {
  797. background: url("https://d31zlh4on95l9h.cloudfront.net/images/4da1d629a55c307c3605ca15bf15189a.svg");
  798. background-repeat: no-repeat;
  799. background-position: center bottom;
  800. background-size: contain;
  801. /* min-height: 20rpx; */
  802. /* border-radius: 20rpx; */
  803. padding: 40rpx;
  804. margin-top: 20rpx;
  805. margin-bottom: 10rpx;
  806. /* box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.05); */
  807. }
  808. .card-content {
  809. display: flex;
  810. align-items: center;
  811. justify-content: space-between;
  812. margin-left: 40rpx;
  813. }
  814. .logo {
  815. width: 80rpx;
  816. height: 80rpx;
  817. background-color: #ff0000;
  818. border-radius: 10rpx;
  819. display: flex;
  820. align-items: center;
  821. justify-content: center;
  822. margin-right: 20rpx;
  823. }
  824. .card-text {
  825. flex: 1;
  826. margin-left: 20rpx;
  827. }
  828. .main-question {
  829. font-size: 32rpx;
  830. color: #333333;
  831. line-height: 48rpx;
  832. }
  833. .stock-code {
  834. display: block;
  835. font-size: 24rpx;
  836. color: #ff3b30;
  837. background-color: #ffffff;
  838. padding: 2rpx 15rpx;
  839. border-radius: 12rpx;
  840. margin-top: 8rpx;
  841. width: fit-content;
  842. border: 1rpx solid #ff3b30;
  843. }
  844. .arrow-icon {
  845. background: url("https://d31zlh4on95l9h.cloudfront.net/images/40d94054644f6e3f1c366751f07f0010.svg");
  846. background-repeat: no-repeat;
  847. left: 0.5rem;
  848. top: 1.8rem;
  849. background-size: 100% 100%;
  850. width: 60rpx;
  851. height: 60rpx;
  852. }
  853. .interest-section {
  854. margin-bottom: 30rpx;
  855. }
  856. .section-title {
  857. display: block;
  858. text-align: center;
  859. font-size: 26rpx;
  860. color: #666666;
  861. margin-bottom: 20rpx;
  862. }
  863. .topics-list {
  864. display: flex;
  865. flex-direction: column;
  866. gap: 15rpx;
  867. }
  868. .topic-item {
  869. display: flex;
  870. align-items: center;
  871. padding: 15rpx 20rpx;
  872. background-color: #f0f0f0;
  873. border-radius: 15rpx;
  874. width: fit-content;
  875. }
  876. .tag-icon {
  877. width: 24rpx;
  878. height: 24rpx;
  879. margin-right: 10rpx;
  880. }
  881. .topic-text {
  882. font-size: 28rpx;
  883. color: #333333;
  884. flex: 1;
  885. }
  886. /* 聊天区域样式 */
  887. .chat-container {
  888. margin-top: 30rpx;
  889. border-radius: 10rpx;
  890. height: calc(100vh - 50rpx);
  891. /* 缩短滚动区域,避免被输入框覆盖 */
  892. overflow-y: auto;
  893. -webkit-overflow-scrolling: touch;
  894. }
  895. .message-list {
  896. background-color: #fff;
  897. margin-bottom: 400rpx;
  898. /* padding: 20rpx; */
  899. }
  900. .message {
  901. display: flex;
  902. align-items: flex-start;
  903. margin-bottom: 30rpx;
  904. }
  905. /* .user-message {
  906. flex-direction: row-reverse;
  907. } */
  908. .message-icon {
  909. font-size: 24rpx;
  910. margin: 0 10rpx;
  911. padding: 10rpx;
  912. border-radius: 50%;
  913. background-color: #ddd;
  914. width: 40rpx;
  915. height: 40rpx;
  916. display: flex;
  917. align-items: center;
  918. justify-content: center;
  919. }
  920. .user-message .message-icon {
  921. background-color: transparent;
  922. border-radius: 40rpx;
  923. /* padding: 0;
  924. width: auto;
  925. height: auto; */
  926. color: #333;
  927. }
  928. .bot-message .message-icon {
  929. background: url("https://d31zlh4on95l9h.cloudfront.net/images/61fa384381c88ad80be28f41827fe0e5.svg");
  930. color: white;
  931. }
  932. .message-content {
  933. max-width: 70%;
  934. position: relative;
  935. }
  936. .user-message .message-content {
  937. background-color: #007aff;
  938. border-radius: 10rpx;
  939. padding: 15rpx;
  940. }
  941. .bot-message .message-content {
  942. background-color: #f0f0f0;
  943. border-radius: 10rpx;
  944. padding: 15rpx;
  945. }
  946. .message-text {
  947. font-size: 28rpx;
  948. line-height: 40rpx;
  949. }
  950. .user-message .message-text {
  951. color: white;
  952. }
  953. .bot-message .message-text {
  954. color: #333;
  955. }
  956. .loading-dots {
  957. display: flex;
  958. align-items: center;
  959. /* padding-top: 10rpx; */
  960. }
  961. .dot {
  962. width: 10rpx;
  963. height: 10rpx;
  964. background-color: #666;
  965. border-radius: 50%;
  966. margin: 0 4rpx;
  967. animation: loading 1.4s infinite ease-in-out both;
  968. }
  969. .user-message .dot {
  970. background-color: white;
  971. }
  972. .dot:nth-child(1) {
  973. animation-delay: -0.32s;
  974. }
  975. .dot:nth-child(2) {
  976. animation-delay: -0.16s;
  977. }
  978. @keyframes loading {
  979. 0%,
  980. 80%,
  981. 100% {
  982. transform: scale(0);
  983. }
  984. 40% {
  985. transform: scale(1);
  986. }
  987. }
  988. .input-area {
  989. position: fixed;
  990. margin-top: 20rpx;
  991. bottom: 70rpx;
  992. left: 0;
  993. right: 0;
  994. padding: 0 40rpx 80rpx 40rpx;
  995. background-color: #ffffff;
  996. }
  997. .input-wrapper {
  998. position: relative;
  999. display: flex;
  1000. align-items: center;
  1001. padding: 15rpx 20rpx;
  1002. background-color: rgb(220, 31, 29);
  1003. border-radius: 100rpx;
  1004. display: flex;
  1005. align-items: center;
  1006. justify-content: center;
  1007. height: 50rpx;
  1008. }
  1009. .mic-icon {
  1010. width: 36rpx;
  1011. height: 36rpx;
  1012. margin-right: 20rpx;
  1013. }
  1014. .input-field {
  1015. flex: 1;
  1016. font-size: 28rpx;
  1017. color: #fff;
  1018. display: flex;
  1019. align-items: center;
  1020. justify-content: center;
  1021. margin-left: 60rpx;
  1022. background: none;
  1023. border: none;
  1024. outline: none;
  1025. }
  1026. .input-field::placeholder {
  1027. color: #ffffff !important;
  1028. opacity: 1;
  1029. }
  1030. /* .uni-scroll-view{
  1031. height: 92%;
  1032. } */
  1033. .send-button {
  1034. background: url("https://d31zlh4on95l9h.cloudfront.net/images/95f1ea2262e9157db13c93c0dc1c5d96.svg");
  1035. background-repeat: no-repeat;
  1036. background-size: 100% 100%;
  1037. height: 50rpx;
  1038. width: 50rpx;
  1039. padding: 0;
  1040. border: 1rpx solid transparent;
  1041. margin-left: 20rpx;
  1042. }
  1043. .send-icon {
  1044. width: 36rpx;
  1045. height: 36rpx;
  1046. }
  1047. .disclaimer {
  1048. font-size: 15rpx;
  1049. color: #4d4c4c;
  1050. display: flex;
  1051. align-items: center;
  1052. justify-content: center;
  1053. margin-top: 15rpx;
  1054. }
  1055. .banner-panel {
  1056. position: relative;
  1057. height: 480rpx;
  1058. /* 拉长容器,灰色背景跟随变高 */
  1059. overflow: hidden;
  1060. /* 让圆角和内部层剪裁一致 */
  1061. border-radius: 15rpx;
  1062. }
  1063. .panelShow {
  1064. height: 12%;
  1065. }
  1066. .pray-banner {
  1067. position: absolute;
  1068. /* background-size: 100% 100%; */
  1069. inset: 0;
  1070. /* 顶部、底部、左、右都贴合容器 */
  1071. width: 100%;
  1072. height: 81%;
  1073. border-radius: 15rpx;
  1074. z-index: 1;
  1075. /* 在灰底之上、内容之下 */
  1076. }
  1077. .contain {
  1078. margin: 0 20rpx;
  1079. gap: 5rpx;
  1080. }
  1081. .banner-panel .robot-container,
  1082. .banner-panel .function-tabs,
  1083. .banner-panel .recommend-card {
  1084. position: relative;
  1085. z-index: 2;
  1086. }
  1087. .back-to-top {
  1088. position: fixed;
  1089. left: 0;
  1090. top: 0;
  1091. width: 100rpx;
  1092. height: 100rpx;
  1093. z-index: 1000;
  1094. }
  1095. .back-to-top:active {
  1096. transform: scale(0.96);
  1097. }
  1098. .static-footer {
  1099. position: fixed;
  1100. bottom: 0;
  1101. }
  1102. /* 搜索历史侧拉框样式 */
  1103. .drawer-overlay {
  1104. position: fixed;
  1105. left: 0;
  1106. top: 0;
  1107. right: 0;
  1108. bottom: 0;
  1109. background-color: rgba(0, 0, 0, 0.35);
  1110. z-index: 900;
  1111. }
  1112. .drawer-panel {
  1113. position: fixed;
  1114. top: 0;
  1115. right: 0;
  1116. bottom: 0;
  1117. width: 600rpx;
  1118. max-width: 75%;
  1119. background: #ffffff;
  1120. box-shadow: -8rpx 0 20rpx rgba(0, 0, 0, 0.08);
  1121. z-index: 901;
  1122. display: flex;
  1123. flex-direction: column;
  1124. transition: transform 0.2s ease;
  1125. }
  1126. .drawer-back {
  1127. position: absolute;
  1128. left: -14px;
  1129. top: 50%;
  1130. transform: translateY(-50%);
  1131. width: 28px;
  1132. height: 28px;
  1133. border-radius: 14px;
  1134. background: #fff;
  1135. box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  1136. border: 1px solid #eee;
  1137. display: flex;
  1138. align-items: center;
  1139. justify-content: center;
  1140. }
  1141. .drawer-back-icon {
  1142. font-size: 16px;
  1143. color: #666;
  1144. }
  1145. .drawer-header {
  1146. display: flex;
  1147. align-items: center;
  1148. justify-content: space-between;
  1149. padding: 24rpx 28rpx;
  1150. border-bottom: 2rpx solid #f0f0f0;
  1151. }
  1152. .drawer-title {
  1153. font-size: 32rpx;
  1154. font-weight: 600;
  1155. color: #333333;
  1156. }
  1157. /* .drawer-close {
  1158. font-size: 42rpx;
  1159. color: #999999;
  1160. } */
  1161. .drawer-content {
  1162. flex: 1;
  1163. padding: 20rpx 24rpx;
  1164. }
  1165. .history-card {
  1166. background-color: #fff;
  1167. border: 2rpx solid #f2f2f2;
  1168. border-left: 8rpx solid rgb(220, 31, 29);
  1169. border-radius: 12rpx;
  1170. padding: 18rpx 20rpx;
  1171. margin-bottom: 16rpx;
  1172. box-shadow: 0 4rpx 10rpx rgba(0, 0, 0, 0.03);
  1173. }
  1174. .history-query {
  1175. font-size: 28rpx;
  1176. color: #333333;
  1177. font-weight: 500;
  1178. }
  1179. .history-time {
  1180. margin-top: 8rpx;
  1181. font-size: 22rpx;
  1182. color: #888888;
  1183. }
  1184. .empty-history {
  1185. padding: 40rpx;
  1186. color: #999999;
  1187. text-align: center;
  1188. }
  1189. .thinking-process {
  1190. margin: 10rpx 0;
  1191. border: 2rpx solid #e5e5e5;
  1192. border-radius: 20rpx;
  1193. background-color: #f9f9f9;
  1194. }
  1195. .thinking-header {
  1196. display: flex;
  1197. align-items: center;
  1198. padding: 20rpx 30rpx;
  1199. cursor: pointer;
  1200. background-color: #fff;
  1201. border-radius: 20rpx;
  1202. border-bottom: 2rpx solid #e5e5e5;
  1203. }
  1204. .thinking-icon {
  1205. font-size: 32rpx;
  1206. margin-right: 16rpx;
  1207. color: #d47c45;
  1208. }
  1209. .thinking-title {
  1210. font-size: 28rpx;
  1211. font-weight: 500;
  1212. color: #d47c45;
  1213. margin-right: 16rpx;
  1214. }
  1215. .thinking-count {
  1216. font-size: 24rpx;
  1217. color: #666;
  1218. margin-right: 16rpx;
  1219. }
  1220. .thinking-toggle {
  1221. font-size: 24rpx;
  1222. color: #999;
  1223. }
  1224. .thinking-content {
  1225. padding: 20rpx 30rpx;
  1226. }
  1227. .thinking-item {
  1228. display: flex;
  1229. align-items: center;
  1230. margin-bottom: 16rpx;
  1231. padding: 8rpx 0;
  1232. }
  1233. .item-status {
  1234. width: 32rpx;
  1235. height: 32rpx;
  1236. border-radius: 50%;
  1237. background-color: #f0f0f0;
  1238. display: flex;
  1239. justify-content: center;
  1240. align-items: center;
  1241. margin-right: 16rpx;
  1242. }
  1243. .checkmark {
  1244. font-size: 20rpx;
  1245. color: #ff0000;
  1246. }
  1247. .item-text {
  1248. font-size: 24rpx;
  1249. color: #333;
  1250. }
  1251. </style>