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.

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