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.

1282 lines
32 KiB

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