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.

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