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.

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