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.

1497 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-cn";
  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. recordId,
  447. parentId,
  448. stockId,
  449. token: memberStore.userInfo?.token || '',
  450. language: "cn",
  451. });
  452. console.log("StockInfo", StockInfo);
  453. // if (StockInfo.code !== 200) {
  454. // return ;
  455. // }
  456. const markdown = StockInfo.markdown;
  457. console.log("StockInfo", StockInfo);
  458. // 添加请求延迟
  459. // const toDataInfo = await getData();
  460. // console.log(toDataInfo);
  461. // dataInfo.value = toDataInfo.data;
  462. // console.log(dataInfo.value);
  463. messages.value[messages.value.length - 1].isThinking = false;
  464. // 滚动到底部
  465. nextTick(() => {
  466. scrollToBottom();
  467. });
  468. // 模拟流式响应
  469. let responseText = `我已经收到您的消息: "${userMessage}"。+"${markdown}" `;
  470. let index = 0;
  471. const botIndex = messages.value.length - 1;
  472. const baseDelay = 5; // 普通字符基础延迟(毫秒)
  473. const slowPunct = /[。!?!?;;]/; // 句号、感叹号、分号等较长停顿
  474. const midPunct = /[,、,::]/; // 逗号、顿号、冒号等中等停顿
  475. const typeWriter = () => {
  476. if (index < responseText.length) {
  477. const ch = responseText.charAt(index);
  478. const current = messages.value[botIndex];
  479. // 通过数组替换触发渲染,避免部分平台对子项属性变更不响应
  480. messages.value.splice(botIndex, 1, {
  481. ...current,
  482. content: current.content + ch,
  483. isTyping: true,
  484. });
  485. index++;
  486. scrollToBottom();
  487. const delay = slowPunct.test(ch)
  488. ? 220
  489. : midPunct.test(ch)
  490. ? 120
  491. : baseDelay;
  492. setTimeout(typeWriter, delay);
  493. } else {
  494. const current = messages.value[botIndex];
  495. messages.value.splice(botIndex, 1, { ...current, isTyping: false });
  496. isSending.value = false;
  497. nextTick(() => {
  498. scrollToBottom();
  499. });
  500. }
  501. };
  502. // 启动前稍作停顿,避免过快开始
  503. setTimeout(typeWriter, 500);
  504. console.log("messages", messages);
  505. };
  506. // 当消息出现或变化时,测量容器并滚到底部
  507. watch(messages, (arr) => {
  508. if (arr.length > 0) {
  509. nextTick(() => {
  510. measureChatContainer();
  511. scrollToBottom();
  512. });
  513. }
  514. });
  515. // 滚动到底部(仅聊天区域滚动)
  516. const scrollToBottom = () => {
  517. if (!shouldAutoScroll.value) return;
  518. const query = uni.createSelectorQuery();
  519. query.select("#messageList").boundingClientRect();
  520. query.exec((res) => {
  521. if (res[0]) {
  522. latestContentHeight.value = res[0].height;
  523. chatScrollTop.value = res[0].height; // scroll-view 会自动夹紧到最大位置
  524. }
  525. });
  526. };
  527. const scrollToTop = () => {
  528. chatScrollTop.value = 0;
  529. };
  530. // 自动滚动控制:用户向上滚动时暂停自动滚到底部
  531. const shouldAutoScroll = ref(true);
  532. const latestContentHeight = ref(0);
  533. const lastScrollTop = ref(0);
  534. const windowHeight = uni.getSystemInfoSync().windowHeight;
  535. const AUTO_SCROLL_REENABLE_THRESHOLD = 40000; // px,接近底部时恢复自动滚动
  536. const onChatScroll = (e) => {
  537. const st = e.detail?.scrollTop || 0;
  538. const delta = st - lastScrollTop.value;
  539. lastScrollTop.value = st;
  540. if (delta < 0) {
  541. shouldAutoScroll.value = false;
  542. return;
  543. }
  544. const distanceToBottom =
  545. latestContentHeight.value - st - chatContainerHeight.value;
  546. if (distanceToBottom <= AUTO_SCROLL_REENABLE_THRESHOLD) {
  547. shouldAutoScroll.value = true;
  548. }
  549. };
  550. // 回到顶部图标拖拽状态
  551. const backTopX = ref(0);
  552. const backTopY = ref(0);
  553. const backTopDragging = ref(false);
  554. const backTopDragOffset = ref({ x: 0, y: 0 });
  555. const backTopTargetX = ref(0);
  556. const backTopTargetY = ref(0);
  557. let backTopRAF = 0;
  558. const backTopSmoothing = 0.15; // 越大越跟手,越小越顺滑
  559. const backTopEpsilon = 0.5; // 收敛阈值
  560. const raf =
  561. typeof requestAnimationFrame === "function"
  562. ? requestAnimationFrame
  563. : (fn) => setTimeout(fn, 16);
  564. const caf =
  565. typeof cancelAnimationFrame === "function"
  566. ? cancelAnimationFrame
  567. : (id) => clearTimeout(id);
  568. function stepBackTop() {
  569. const dx = backTopTargetX.value - backTopX.value;
  570. const dy = backTopTargetY.value - backTopY.value;
  571. // 插值缓动,避免每帧重排
  572. backTopX.value += dx * backTopSmoothing;
  573. backTopY.value += dy * backTopSmoothing;
  574. if (Math.abs(dx) > backTopEpsilon || Math.abs(dy) > backTopEpsilon) {
  575. backTopRAF = raf(stepBackTop);
  576. } else {
  577. backTopX.value = backTopTargetX.value;
  578. backTopY.value = backTopTargetY.value;
  579. backTopRAF = 0;
  580. }
  581. }
  582. function ensureBackTopRAF() {
  583. if (!backTopRAF) {
  584. backTopRAF = raf(stepBackTop);
  585. }
  586. }
  587. const clamp = (val, min, max) => Math.max(min, Math.min(val, max));
  588. const onBackTopTouchStart = (e) => {
  589. const t = e.touches && e.touches[0];
  590. if (!t) return;
  591. backTopDragging.value = false;
  592. backTopDragOffset.value = {
  593. x: t.pageX - backTopX.value,
  594. y: t.pageY - backTopY.value,
  595. };
  596. };
  597. const onBackTopTouchMove = (e) => {
  598. const t = e.touches && e.touches[0];
  599. if (!t) return;
  600. const sys = uni.getSystemInfoSync();
  601. const iconSize = uni.upx2px(100);
  602. const reserveBottom = uni.upx2px(260);
  603. const nx = t.pageX - backTopDragOffset.value.x;
  604. const ny = t.pageY - backTopDragOffset.value.y;
  605. const clampedX = clamp(nx, 0, sys.windowWidth - iconSize);
  606. const clampedY = clamp(ny, 0, sys.windowHeight - reserveBottom - iconSize);
  607. if (
  608. Math.abs(clampedX - backTopX.value) + Math.abs(clampedY - backTopY.value) >
  609. 3
  610. ) {
  611. backTopDragging.value = true;
  612. }
  613. backTopTargetX.value = clampedX;
  614. backTopTargetY.value = clampedY;
  615. ensureBackTopRAF();
  616. };
  617. const onBackTopTouchEnd = () => {
  618. // 结束拖拽即可
  619. };
  620. const onBackTopClick = () => {
  621. if (backTopDragging.value) return; // 拖拽时不触发点击回到顶部
  622. scrollToTop();
  623. };
  624. </script>
  625. <style scoped>
  626. .deepMate-page {
  627. display: flex;
  628. flex-direction: column;
  629. position: fixed;
  630. /* 充满视口,彻底禁用页面滚动 */
  631. top: 0;
  632. left: 0;
  633. right: 0;
  634. bottom: 0;
  635. height: 100vh;
  636. overflow: hidden;
  637. /* 锁定页面滚动 */
  638. background-color: #ffffff;
  639. padding: 20rpx 0rpx;
  640. }
  641. .header {
  642. display: flex;
  643. justify-content: space-between;
  644. align-items: center;
  645. padding: 20rpx 30rpx;
  646. background-color: #ffffff;
  647. box-shadow: 0 2rpx rgba(0, 0, 0, 0.1);
  648. }
  649. .header-left,
  650. .header-right {
  651. display: flex;
  652. align-items: center;
  653. }
  654. .header-left .icon,
  655. .header-right .icon {
  656. width: 40rpx;
  657. height: 40rpx;
  658. /* margin-right: 20rpx; */
  659. }
  660. .header-center .title {
  661. position: fixed;
  662. top: 10rpx;
  663. left: 50%;
  664. transform: translateX(-50%);
  665. font-size: 36rpx;
  666. font-weight: bold;
  667. color: #333333;
  668. }
  669. .new-chat-button {
  670. background-color: #ff6600;
  671. border: none;
  672. border-radius: 8rpx;
  673. padding: 10rpx 20rpx;
  674. }
  675. .new-chat-text {
  676. color: white;
  677. font-size: 24rpx;
  678. }
  679. .main-content {
  680. background-color: #fff;
  681. flex: 1;
  682. display: flex;
  683. flex-direction: column;
  684. overflow: hidden;
  685. /* 内部滚动交给聊天容器 */
  686. padding: 20rpx;
  687. margin-top: 1rpx;
  688. margin-bottom: 280rpx;
  689. }
  690. /* 聊天顶部粘性欢迎块样式 */
  691. .chat-header {
  692. position: sticky;
  693. top: 0;
  694. /* 在页面滚动时始终贴顶 */
  695. z-index: 50;
  696. background-color: #ffffff;
  697. padding: 3rpx 20rpx;
  698. }
  699. .robot-container {
  700. display: flex;
  701. align-items: center;
  702. margin-top: 30rpx;
  703. }
  704. .robot-avatar {
  705. width: 130rpx;
  706. height: 130rpx;
  707. border-radius: 50%;
  708. margin-left: 20rpx;
  709. }
  710. .welcome-message {
  711. flex: 1;
  712. }
  713. .greeting {
  714. font-size: 32rpx;
  715. margin-left: 50rpx;
  716. top: 40rpx;
  717. font-weight: bold;
  718. color: #333333;
  719. line-height: 48rpx;
  720. }
  721. .description {
  722. display: block;
  723. font-size: 24rpx;
  724. color: #666666;
  725. line-height: 36rpx;
  726. margin-top: 10rpx;
  727. margin-left: 45rpx;
  728. }
  729. .function-tabs {
  730. display: block;
  731. overflow: hidden;
  732. margin-bottom: 30rpx;
  733. }
  734. .tabs-track {
  735. display: inline-flex;
  736. white-space: nowrap;
  737. will-change: transform;
  738. }
  739. .tab-item {
  740. padding: 5rpx 20rpx;
  741. border-radius: 20rpx;
  742. font-size: 20rpx;
  743. font-weight: 700;
  744. color: #666666;
  745. background-color: #fffefe;
  746. margin-right: 20rpx;
  747. transition: all 0.3s;
  748. }
  749. .tab-item.active {
  750. color: #ff6600;
  751. background-color: #fff;
  752. border: 1rpx solid #ff6600;
  753. }
  754. .recommend-card {
  755. background: url("https://d31zlh4on95l9h.cloudfront.net/images/4da1d629a55c307c3605ca15bf15189a.svg");
  756. background-repeat: no-repeat;
  757. background-position: center bottom;
  758. background-size: contain;
  759. /* min-height: 20rpx; */
  760. /* border-radius: 20rpx; */
  761. padding: 40rpx;
  762. margin-top: 20rpx;
  763. margin-bottom: 10rpx;
  764. /* box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.05); */
  765. }
  766. .welcome-section {
  767. /* 灰色卡片(recommend-card)之后展示背景图 */
  768. margin-top: 10rpx;
  769. display: flex;
  770. align-items: center;
  771. justify-content: center;
  772. background: url('https://d31zlh4on95l9h.cloudfront.net/images/eca84d9fb54712cb3bc6c6174773b83b.svg');
  773. background-repeat: no-repeat;
  774. background-position: center top;
  775. /* 放在容器顶部,正好在灰色卡片下方 */
  776. background-size: 80% auto;
  777. /* 缩放以适配宽度 */
  778. height: 460rpx;
  779. /* 提供可视高度,让背景图可见 */
  780. }
  781. .card-content {
  782. display: flex;
  783. align-items: center;
  784. justify-content: space-between;
  785. margin-left: 40rpx;
  786. }
  787. .logo {
  788. width: 80rpx;
  789. height: 80rpx;
  790. background-color: #ff0000;
  791. border-radius: 10rpx;
  792. display: flex;
  793. align-items: center;
  794. justify-content: center;
  795. margin-right: 20rpx;
  796. }
  797. .card-text {
  798. flex: 1;
  799. margin-left: 20rpx;
  800. }
  801. .main-question {
  802. font-size: 32rpx;
  803. color: #333333;
  804. line-height: 48rpx;
  805. }
  806. .stock-code {
  807. display: block;
  808. font-size: 24rpx;
  809. color: #ff3b30;
  810. background-color: #ffffff;
  811. padding: 2rpx 15rpx;
  812. border-radius: 12rpx;
  813. margin-top: 8rpx;
  814. width: fit-content;
  815. border: 1rpx solid #ff3b30;
  816. }
  817. .arrow-icon {
  818. background: url("https://d31zlh4on95l9h.cloudfront.net/images/40d94054644f6e3f1c366751f07f0010.svg");
  819. background-repeat: no-repeat;
  820. left: 0.5rem;
  821. top: 1.8rem;
  822. background-size: 100% 100%;
  823. width: 60rpx;
  824. height: 60rpx;
  825. }
  826. .interest-section {
  827. margin-bottom: 30rpx;
  828. }
  829. .section-title {
  830. display: block;
  831. text-align: left;
  832. font-size: 26rpx;
  833. color: #666666;
  834. margin-bottom: 20rpx;
  835. }
  836. .topics-list {
  837. display: flex;
  838. flex-direction: column;
  839. gap: 15rpx;
  840. }
  841. .topic-item {
  842. display: flex;
  843. align-items: center;
  844. padding: 15rpx 20rpx;
  845. background-color: #f0f0f0;
  846. border-radius: 15rpx;
  847. width: fit-content;
  848. }
  849. .tag-icon {
  850. width: 24rpx;
  851. height: 24rpx;
  852. margin-right: 10rpx;
  853. }
  854. .topic-text {
  855. font-size: 28rpx;
  856. color: #333333;
  857. flex: 1;
  858. }
  859. /* 聊天区域样式 */
  860. .chat-container {
  861. margin-top: 30rpx;
  862. border-radius: 10rpx;
  863. height: calc(100vh - 50rpx);
  864. /* 缩短滚动区域,避免被输入框覆盖 */
  865. overflow-y: auto;
  866. -webkit-overflow-scrolling: touch;
  867. }
  868. .message-list {
  869. background-color: #fff;
  870. margin-bottom: 400rpx;
  871. /* padding: 20rpx; */
  872. }
  873. .message {
  874. display: flex;
  875. align-items: flex-start;
  876. margin-bottom: 30rpx;
  877. }
  878. .user-message {
  879. flex-direction: row-reverse;
  880. justify-content: flex-start;
  881. }
  882. .message-icon {
  883. font-size: 24rpx;
  884. margin: 0 10rpx;
  885. padding: 10rpx;
  886. border-radius: 50%;
  887. background-color: #ddd;
  888. width: 40rpx;
  889. height: 40rpx;
  890. display: flex;
  891. align-items: center;
  892. justify-content: center;
  893. }
  894. .user-message .message-icon {
  895. background-color: #007aff;
  896. border-radius: 50%;
  897. color: #fff;
  898. /* box-shadow: 0 0 12rpx rgba(0, 122, 255, 0.4); */
  899. }
  900. .bot-message .message-icon {
  901. background: url('/static/images/机器人 (1).svg');
  902. color: white;
  903. }
  904. .message-content {
  905. max-width: 70%;
  906. position: relative;
  907. word-wrap: break-word;
  908. word-break: break-all;
  909. overflow-wrap: break-word;
  910. }
  911. .user-message .message-content {
  912. /* background-color: #007aff; */
  913. border: 2rpx solid #f3908f;
  914. border-radius: 20rpx;
  915. padding: 10rpx;
  916. }
  917. .bot-message .message-content {
  918. background-color: #f0f0f0;
  919. border-radius: 10rpx;
  920. padding: 15rpx;
  921. }
  922. .message-text {
  923. font-size: 28rpx;
  924. line-height: 40rpx;
  925. }
  926. .user-message .message-text {
  927. color: black;
  928. }
  929. .bot-message .message-text {
  930. color: #333;
  931. }
  932. .loading-dots {
  933. display: flex;
  934. align-items: center;
  935. /* padding-top: 10rpx; */
  936. }
  937. .dot {
  938. width: 10rpx;
  939. height: 10rpx;
  940. background-color: #666;
  941. border-radius: 50%;
  942. margin: 0 4rpx;
  943. animation: loading 1.4s infinite ease-in-out both;
  944. }
  945. .user-message .dot {
  946. background-color: white;
  947. }
  948. .dot:nth-child(1) {
  949. animation-delay: -0.32s;
  950. }
  951. .dot:nth-child(2) {
  952. animation-delay: -0.16s;
  953. }
  954. @keyframes loading {
  955. 0%,
  956. 80%,
  957. 100% {
  958. transform: scale(0);
  959. }
  960. 40% {
  961. transform: scale(1);
  962. }
  963. }
  964. .input-area {
  965. position: fixed;
  966. margin-top: 20rpx;
  967. bottom: 70rpx;
  968. left: 0;
  969. right: 0;
  970. padding: 0 40rpx 80rpx 40rpx;
  971. background-color: #ffffff;
  972. }
  973. .input-wrapper {
  974. position: relative;
  975. display: flex;
  976. align-items: center;
  977. padding: 15rpx 20rpx;
  978. background-color: rgb(220, 31, 29);
  979. border-radius: 100rpx;
  980. display: flex;
  981. align-items: center;
  982. justify-content: center;
  983. height: 50rpx;
  984. }
  985. .mic-icon {
  986. width: 36rpx;
  987. height: 36rpx;
  988. margin-right: 20rpx;
  989. }
  990. .input-field {
  991. flex: 1;
  992. font-size: 28rpx;
  993. color: #fff;
  994. display: flex;
  995. align-items: center;
  996. justify-content: center;
  997. margin-left: 60rpx;
  998. background: none;
  999. border: none;
  1000. outline: none;
  1001. }
  1002. .input-field::placeholder {
  1003. color: #ffffff !important;
  1004. opacity: 1;
  1005. }
  1006. /* .uni-scroll-view{
  1007. height: 92%;
  1008. } */
  1009. .send-button {
  1010. background: url("https://d31zlh4on95l9h.cloudfront.net/images/95f1ea2262e9157db13c93c0dc1c5d96.svg");
  1011. background-repeat: no-repeat;
  1012. background-size: 100% 100%;
  1013. height: 50rpx;
  1014. width: 50rpx;
  1015. padding: 0;
  1016. border: 1rpx solid transparent;
  1017. margin-left: 20rpx;
  1018. }
  1019. .send-icon {
  1020. width: 36rpx;
  1021. height: 36rpx;
  1022. }
  1023. .disclaimer {
  1024. font-size: 15rpx;
  1025. color: #4d4c4c;
  1026. display: flex;
  1027. align-items: center;
  1028. justify-content: center;
  1029. margin-top: 15rpx;
  1030. }
  1031. .banner-panel {
  1032. position: relative;
  1033. height: 480rpx;
  1034. /* 拉长容器,灰色背景跟随变高 */
  1035. overflow: hidden;
  1036. /* 让圆角和内部层剪裁一致 */
  1037. border-radius: 15rpx;
  1038. }
  1039. .panelShow {
  1040. height: 12%;
  1041. }
  1042. .pray-banner {
  1043. position: absolute;
  1044. /* background-size: 100% 100%; */
  1045. inset: 0;
  1046. /* 顶部、底部、左、右都贴合容器 */
  1047. width: 100%;
  1048. height: 81%;
  1049. border-radius: 15rpx;
  1050. z-index: 1;
  1051. /* 在灰底之上、内容之下 */
  1052. }
  1053. .contain {
  1054. margin: 0 20rpx;
  1055. gap: 5rpx;
  1056. }
  1057. .banner-panel .robot-container,
  1058. .banner-panel .function-tabs,
  1059. .banner-panel .recommend-card {
  1060. position: relative;
  1061. z-index: 2;
  1062. }
  1063. .back-to-top {
  1064. position: fixed;
  1065. left: 0;
  1066. top: 0;
  1067. width: 100rpx;
  1068. height: 100rpx;
  1069. z-index: 1000;
  1070. }
  1071. .back-to-top:active {
  1072. transform: scale(0.96);
  1073. }
  1074. .static-footer {
  1075. position: fixed;
  1076. bottom: 0;
  1077. }
  1078. /* 搜索历史侧拉框样式 */
  1079. .drawer-overlay {
  1080. position: fixed;
  1081. left: 0;
  1082. top: 0;
  1083. right: 0;
  1084. bottom: 0;
  1085. background-color: rgba(0, 0, 0, 0.35);
  1086. z-index: 900;
  1087. }
  1088. .drawer-panel {
  1089. position: fixed;
  1090. left: 0;
  1091. right: 0;
  1092. bottom: 0;
  1093. height: 75vh;
  1094. max-height: 80vh;
  1095. width: 100%;
  1096. background: #ffffff;
  1097. box-shadow: 0 -8rpx 20rpx rgba(0, 0, 0, 0.06);
  1098. z-index: 1000;
  1099. display: flex;
  1100. flex-direction: column;
  1101. border-top-left-radius: 20rpx;
  1102. border-top-right-radius: 20rpx;
  1103. transition: transform 0.22s ease;
  1104. }
  1105. .drawer-back {
  1106. position: absolute;
  1107. left: 50%;
  1108. top: -14px;
  1109. transform: translateX(-50%);
  1110. width: 28px;
  1111. height: 48px;
  1112. border-radius: 12px;
  1113. background: #fff;
  1114. box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
  1115. display: flex;
  1116. align-items: center;
  1117. justify-content: center;
  1118. }
  1119. .drawer-back-icon {
  1120. font-size: 16px;
  1121. color: #8a8a8a;
  1122. }
  1123. .drawer-actions {
  1124. display: flex;
  1125. align-items: center;
  1126. gap: 40rpx;
  1127. }
  1128. .delete-all-container {
  1129. display: flex;
  1130. align-items: center;
  1131. gap: 14rpx;
  1132. }
  1133. .delete-icon {
  1134. width: 45rpx;
  1135. height: 40rpx;
  1136. }
  1137. .delete-all {
  1138. font-size: 28rpx;
  1139. }
  1140. .drawer-close {
  1141. background: url('/static/icons/关闭2.svg');
  1142. width: 48rpx;
  1143. height: 48rpx;
  1144. border-radius: 24rpx;
  1145. /* background: #f5f5f5; */
  1146. /* box-shadow: 0 2px 8px rgba(0,0,0,0.08); */
  1147. display: flex;
  1148. align-items: center;
  1149. justify-content: center;
  1150. }
  1151. .drawer-close-icon {
  1152. font-size: 24rpx;
  1153. color: #8a8a8a;
  1154. }
  1155. .drawer-header {
  1156. display: flex;
  1157. align-items: center;
  1158. justify-content: space-between;
  1159. padding: 52rpx 28rpx 0rpx 28rpx;
  1160. /* border-bottom: 2rpx solid #f0f0f0; */
  1161. }
  1162. .drawer-title {
  1163. font-size: 32rpx;
  1164. font-weight: 600;
  1165. color: #333333;
  1166. }
  1167. /* .drawer-close {
  1168. font-size: 42rpx;
  1169. color: #999999;
  1170. } */
  1171. .drawer-content {
  1172. flex: 1;
  1173. min-height: 0;
  1174. /* 让 flex 子元素可在容器内收缩以启用滚动 */
  1175. height: 100%;
  1176. overscroll-behavior-y: contain;
  1177. /* 防止滚动串联到页面 */
  1178. -webkit-overflow-scrolling: touch;
  1179. /* iOS 惯性滚动 */
  1180. touch-action: pan-y;
  1181. /* 优化触控滚动,仅垂直 */
  1182. }
  1183. .drawer-inner {
  1184. padding: 20rpx 24rpx 20rpx 24rpx;
  1185. }
  1186. .history-section {
  1187. margin-bottom: 20rpx;
  1188. /* margin: 0 24rpx; */
  1189. }
  1190. .section-title {
  1191. font-size: 26rpx;
  1192. color: #888;
  1193. margin: 10rpx 6rpx 16rpx;
  1194. }
  1195. .history-item {
  1196. display: flex;
  1197. align-items: center;
  1198. padding: 19rpx 18rpx;
  1199. background-color: #f6f7f9;
  1200. border-radius: 12rpx;
  1201. margin-bottom: 12rpx;
  1202. }
  1203. .history-left {
  1204. margin-right: 12rpx;
  1205. }
  1206. .flag-circle {
  1207. width: 36rpx;
  1208. height: 36rpx;
  1209. border-radius: 50%;
  1210. background: #fff;
  1211. border: 2rpx solid #eee;
  1212. display: flex;
  1213. align-items: center;
  1214. justify-content: center;
  1215. }
  1216. .flag-emoji {
  1217. font-size: 24rpx;
  1218. }
  1219. .history-main {
  1220. flex: 1;
  1221. }
  1222. .history-query {
  1223. font-size: 28rpx;
  1224. color: #333;
  1225. }
  1226. .history-time {
  1227. font-size: 22rpx;
  1228. color: #999;
  1229. }
  1230. .history-card {
  1231. background-color: #fff;
  1232. border: 2rpx solid #f2f2f2;
  1233. border-left: 8rpx solid rgb(220, 31, 29);
  1234. border-radius: 12rpx;
  1235. padding: 18rpx 20rpx;
  1236. margin-bottom: 16rpx;
  1237. box-shadow: 0 4rpx 10rpx rgba(0, 0, 0, 0.03);
  1238. }
  1239. .history-query {
  1240. font-size: 28rpx;
  1241. color: #333333;
  1242. font-weight: 500;
  1243. }
  1244. .history-time {
  1245. margin-top: 8rpx;
  1246. font-size: 22rpx;
  1247. color: #888888;
  1248. }
  1249. .empty-history {
  1250. padding: 40rpx;
  1251. color: #999999;
  1252. text-align: center;
  1253. }
  1254. .thinking-process {
  1255. margin: 10rpx 0;
  1256. border: 2rpx solid #e5e5e5;
  1257. border-radius: 20rpx;
  1258. background-color: #f9f9f9;
  1259. }
  1260. .thinking-header {
  1261. display: flex;
  1262. align-items: center;
  1263. padding: 20rpx 30rpx;
  1264. cursor: pointer;
  1265. background-color: #fff;
  1266. border-radius: 20rpx;
  1267. border-bottom: 2rpx solid #e5e5e5;
  1268. }
  1269. .thinking-icon {
  1270. font-size: 32rpx;
  1271. margin-right: 16rpx;
  1272. color: #d47c45;
  1273. }
  1274. .thinking-title {
  1275. font-size: 28rpx;
  1276. font-weight: 500;
  1277. color: #d47c45;
  1278. margin-right: 16rpx;
  1279. }
  1280. .thinking-count {
  1281. font-size: 24rpx;
  1282. color: #666;
  1283. margin-right: 16rpx;
  1284. }
  1285. .thinking-toggle {
  1286. font-size: 24rpx;
  1287. color: #999;
  1288. }
  1289. .thinking-content {
  1290. padding: 20rpx 30rpx;
  1291. }
  1292. .thinking-item {
  1293. display: flex;
  1294. align-items: center;
  1295. margin-bottom: 16rpx;
  1296. padding: 8rpx 0;
  1297. }
  1298. .item-status {
  1299. width: 32rpx;
  1300. height: 32rpx;
  1301. border-radius: 50%;
  1302. background-color: #f0f0f0;
  1303. display: flex;
  1304. justify-content: center;
  1305. align-items: center;
  1306. margin-right: 16rpx;
  1307. }
  1308. .checkmark {
  1309. font-size: 20rpx;
  1310. color: #ff0000;
  1311. }
  1312. .item-text {
  1313. font-size: 24rpx;
  1314. color: #333;
  1315. }
  1316. </style>