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.

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