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.

507 lines
11 KiB

4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
  1. <template>
  2. <view class="titleContent">
  3. <view class="left">
  4. <uni-icons
  5. @click="handleBack"
  6. type="back"
  7. size="23"
  8. color="#111"
  9. ></uni-icons>
  10. </view>
  11. <view class="title">深度探索</view>
  12. <view class="right">
  13. <image
  14. class="notice"
  15. src="/static/deepExploration-images/notice.png"
  16. mode="aspectFill"
  17. ></image>
  18. <image
  19. @click="openHistoryDrawer"
  20. class="history"
  21. src="/static/deepExploration-images/history.png"
  22. mode="aspectFill"
  23. ></image>
  24. </view>
  25. </view>
  26. <view class="drawer-overlay" v-show="showHistoryDrawer"></view>
  27. <view
  28. class="drawer-panel"
  29. v-show="showHistoryDrawer"
  30. @click.stop
  31. @touchmove.stop.prevent
  32. :style="{ transform: 'translateY(' + drawerOffsetY + 'px)' }"
  33. >
  34. <view class="drawer-header">
  35. <text class="drawer-title">历史对话</text>
  36. <view class="drawer-actions">
  37. <view class="delete-all-container">
  38. <image
  39. class="delete-icon"
  40. src="/static/icons/Group_48095481.svg"
  41. ></image>
  42. <text class="delete-all" @click="clearAllHistory">删除全部</text>
  43. </view>
  44. <view class="drawer-close" @click="onDrawerBackClick"
  45. ><text class="drawer-close-icon"></text
  46. ></view>
  47. </view>
  48. </view>
  49. <scroll-view scroll-y="true" class="drawer-content">
  50. <view class="drawer-inner">
  51. <view v-if="groupedHistory.length === 0" class="empty-history">
  52. <text>暂无历史记录</text>
  53. </view>
  54. <view
  55. v-for="(section, sIdx) in groupedHistory"
  56. :key="sIdx"
  57. class="history-section"
  58. >
  59. <text class="section-title">{{ section.title }}</text>
  60. <view
  61. v-for="(item, idx) in section.items"
  62. :key="idx"
  63. class="history-item"
  64. >
  65. <view class="history-left">
  66. <view class="flag-circle"
  67. ><text class="flag-emoji">🇺🇸</text></view
  68. >
  69. </view>
  70. <view class="history-main" @click="itemClick(item)">
  71. <text class="history-query">{{ item.stockName }}</text>
  72. <text class="history-query">{{ item.stockCode }}</text>
  73. </view>
  74. <text class="history-time">{{
  75. formatTimeForHistory(item.createdTime)
  76. }}</text>
  77. </view>
  78. </view>
  79. </view>
  80. </scroll-view>
  81. </view>
  82. </template>
  83. <script setup>
  84. import {
  85. RecordListApi,
  86. RecordInfoApi,
  87. } from "../api/deepExploration/deepExploration";
  88. import { ref, onMounted, computed } from "vue";
  89. import { useDeepExplorationStore } from "../stores/modules/deepExploration";
  90. const props = defineProps({
  91. name: {
  92. type: String,
  93. default: "",
  94. },
  95. });
  96. const showHistoryDrawer = ref(false);
  97. const drawerOffsetY = ref(0);
  98. // const handleHistory = () => {
  99. // showHistoryDrawer.value = true;
  100. // };
  101. // 历史记录
  102. const openHistoryDrawer = async () => {
  103. const res = await RecordListApi({
  104. model: 1,
  105. });
  106. if (res.code === 200) {
  107. historyList.value = res.data;
  108. }
  109. console.log("historyList.value", historyList.value);
  110. const hideDistance = uni.upx2px(900);
  111. drawerOffsetY.value = hideDistance;
  112. showHistoryDrawer.value = true;
  113. setTimeout(() => {
  114. drawerOffsetY.value = 0;
  115. }, 10);
  116. };
  117. const clearAllHistory = () => {
  118. searchHistory.value = [];
  119. // uni.setStorageSync("search_history", []);
  120. };
  121. //返回上一页
  122. const handleBack = () => {
  123. uni.navigateBack();
  124. };
  125. const closeHistoryDrawer = () => {
  126. showHistoryDrawer.value = false;
  127. };
  128. const onDrawerBackClick = () => {
  129. const hideDistance = uni.upx2px(900);
  130. drawerOffsetY.value = hideDistance;
  131. setTimeout(() => {
  132. closeHistoryDrawer();
  133. drawerOffsetY.value = 0;
  134. }, 180);
  135. };
  136. // 历史记录详情
  137. async function itemClick(item) {
  138. const res = await RecordInfoApi({
  139. recordId: item.id,
  140. parentId: item.parentId,
  141. model: 5,
  142. });
  143. if (res.code == 200) {
  144. const message = res.data;
  145. const deepExplorationStore = useDeepExplorationStore();
  146. deepExplorationStore.setDeepExplorationInfo(message);
  147. onDrawerBackClick();
  148. console.log(deepExplorationStore.deepExplorationInfo);
  149. }
  150. }
  151. const historyList = ref([]);
  152. // 为历史记录格式化时间:YYYY-MM-DD HH:mm
  153. const formatTimeForHistory = (timeString) => {
  154. // 假设 timeString 格式为 "YYYY-MM-DD HH:mm:ss"
  155. const parts = timeString.split(" ");
  156. if (parts.length >= 2) {
  157. const datePart = parts[0];
  158. const timePart = parts[1];
  159. const timeParts = timePart.split(":");
  160. if (timeParts.length >= 2) {
  161. return `${datePart} ${timeParts[0]}:${timeParts[1]}`;
  162. }
  163. }
  164. return timeString;
  165. };
  166. // 历史分组(今天/昨天/近一周/按月)
  167. const groupedHistory = computed(() => {
  168. const sections = [];
  169. // 从缓存获取今天日期,如果没有则使用当前日期
  170. const now = new Date();
  171. const startOfDay = (d) =>
  172. new Date(d.getFullYear(), d.getMonth(), d.getDate());
  173. const isSameDay = (a, b) =>
  174. startOfDay(a).getTime() === startOfDay(b).getTime();
  175. const isYesterday = (d) => {
  176. const y = new Date(now.getFullYear(), now.getMonth(), now.getDate() - 1);
  177. return isSameDay(d, y);
  178. };
  179. const isToday = (d) => isSameDay(d, now);
  180. const withinLast7Days = (d) => {
  181. const seven = new Date(
  182. now.getFullYear(),
  183. now.getMonth(),
  184. now.getDate() - 7
  185. );
  186. return d >= seven && !isToday(d) && !isYesterday(d);
  187. };
  188. const monthLabel = (d) => `${d.getMonth() + 1}`;
  189. const today = [];
  190. const yesterday = [];
  191. const last7 = [];
  192. const byMonth = new Map();
  193. // 使用 historyList.value 替代 searchHistory.value
  194. historyList.value.forEach((item) => {
  195. // 根据你的数据结构,使用 createdTime 字段
  196. const dt = new Date(item.createdTime);
  197. if (isToday(dt)) {
  198. today.push(item);
  199. } else if (isYesterday(dt)) {
  200. yesterday.push(item);
  201. } else if (withinLast7Days(dt)) {
  202. last7.push(item);
  203. } else {
  204. const year = dt.getFullYear();
  205. const month = dt.getMonth() + 1;
  206. const key = `${year}-${month}`;
  207. if (!byMonth.has(key))
  208. byMonth.set(key, {
  209. title: `${year}${month}`,
  210. year,
  211. month,
  212. items: [],
  213. });
  214. byMonth.get(key).items.push(item);
  215. }
  216. });
  217. if (today.length) sections.push({ title: "今天", items: today });
  218. if (yesterday.length) sections.push({ title: "昨天", items: yesterday });
  219. if (last7.length) sections.push({ title: "近一周", items: last7 });
  220. const monthSections = Array.from(byMonth.values()).sort((a, b) => {
  221. if (a.year !== b.year) return b.year - a.year;
  222. return b.month - a.month; // 月份倒序,如 10月 在 9月 之前
  223. });
  224. sections.push(...monthSections);
  225. return sections;
  226. });
  227. onMounted(() => {});
  228. </script>
  229. <style scoped lang="scss">
  230. * {
  231. box-sizing: border-box;
  232. }
  233. .titleContent {
  234. display: flex;
  235. align-items: center;
  236. justify-content: space-between;
  237. padding: 30rpx 60rpx 40rpx 35rpx;
  238. box-shadow: 2rpx 2rpx 8rpx rgba(0, 0, 0, 0.1);
  239. .left {
  240. display: flex;
  241. align-items: center;
  242. width: 36rpx;
  243. height: 36rpx;
  244. }
  245. .title {
  246. position: absolute;
  247. left: 50%;
  248. transform: translateX(-50%);
  249. color: #000000;
  250. font-family: "PingFang SC";
  251. font-size: 19px;
  252. font-style: normal;
  253. font-weight: 400;
  254. line-height: 25px;
  255. }
  256. .right {
  257. display: flex;
  258. align-items: center;
  259. gap: 20rpx;
  260. .notice {
  261. width: 35rpx;
  262. height: 35rpx;
  263. gap: 20rpx;
  264. }
  265. .history {
  266. width: 32rpx;
  267. height: 32rpx;
  268. align-items: center;
  269. }
  270. }
  271. }
  272. /* 搜索历史侧拉框样式 */
  273. .drawer-overlay {
  274. position: fixed;
  275. left: 0;
  276. top: 0;
  277. right: 0;
  278. bottom: 0;
  279. background-color: rgba(0, 0, 0, 0.35);
  280. z-index: 900;
  281. }
  282. .drawer-panel {
  283. position: fixed;
  284. left: 0;
  285. right: 0;
  286. bottom: 0;
  287. height: 75vh;
  288. max-height: 80vh;
  289. width: 100%;
  290. background: #ffffff;
  291. box-shadow: 0 -8rpx 20rpx rgba(0, 0, 0, 0.06);
  292. z-index: 1000;
  293. display: flex;
  294. flex-direction: column;
  295. border-top-left-radius: 20rpx;
  296. border-top-right-radius: 20rpx;
  297. transition: transform 0.22s ease;
  298. }
  299. .drawer-back {
  300. position: absolute;
  301. left: 50%;
  302. top: -14px;
  303. transform: translateX(-50%);
  304. width: 28px;
  305. height: 48px;
  306. border-radius: 12px;
  307. background: #fff;
  308. box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
  309. display: flex;
  310. align-items: center;
  311. justify-content: center;
  312. }
  313. .drawer-back-icon {
  314. font-size: 16px;
  315. color: #8a8a8a;
  316. }
  317. .drawer-actions {
  318. display: flex;
  319. align-items: center;
  320. gap: 40rpx;
  321. }
  322. .delete-all-container {
  323. display: flex;
  324. align-items: center;
  325. gap: 14rpx;
  326. }
  327. .delete-icon {
  328. width: 28rpx;
  329. height: 32rpx;
  330. }
  331. .delete-all {
  332. font-size: 28rpx;
  333. }
  334. .drawer-close {
  335. background: url("../static/icons/关闭2.svg");
  336. width: 48rpx;
  337. height: 48rpx;
  338. border-radius: 24rpx;
  339. /* background: #f5f5f5; */
  340. /* box-shadow: 0 2px 8px rgba(0,0,0,0.08); */
  341. display: flex;
  342. align-items: center;
  343. justify-content: center;
  344. image {
  345. width: 100%;
  346. height: 100%;
  347. }
  348. }
  349. .drawer-header {
  350. display: flex;
  351. align-items: center;
  352. justify-content: space-between;
  353. padding: 52rpx 28rpx 0rpx 28rpx;
  354. /* border-bottom: 2rpx solid #f0f0f0; */
  355. }
  356. .drawer-title {
  357. font-size: 32rpx;
  358. font-weight: 600;
  359. color: #333333;
  360. }
  361. .drawer-content {
  362. flex: 1;
  363. min-height: 0;
  364. /* 让 flex 子元素可在容器内收缩以启用滚动 */
  365. height: 100%;
  366. overscroll-behavior-y: contain;
  367. /* 防止滚动串联到页面 */
  368. -webkit-overflow-scrolling: touch;
  369. /* iOS 惯性滚动 */
  370. touch-action: pan-y;
  371. /* 优化触控滚动,仅垂直 */
  372. }
  373. .drawer-inner {
  374. padding: 20rpx 24rpx 20rpx 24rpx;
  375. }
  376. .history-section {
  377. margin-bottom: 20rpx;
  378. /* margin: 0 24rpx; */
  379. }
  380. .section-title {
  381. font-size: 26rpx;
  382. color: #888;
  383. margin: 10rpx 6rpx 16rpx;
  384. }
  385. .history-item {
  386. display: flex;
  387. align-items: center;
  388. padding: 19rpx 18rpx;
  389. background-color: #f6f7f9;
  390. border-radius: 12rpx;
  391. margin-bottom: 12rpx;
  392. }
  393. .history-left {
  394. margin-right: 20rpx;
  395. width: 50rpx;
  396. height: 50rpx;
  397. }
  398. .flag-circle {
  399. width: 50rpx;
  400. height: 50rpx;
  401. border-radius: 50%;
  402. background: #fff;
  403. border: 2rpx solid #eee;
  404. display: flex;
  405. align-items: center;
  406. justify-content: center;
  407. image {
  408. width: 50rpx;
  409. height: 50rpx;
  410. border-radius: 50%;
  411. }
  412. }
  413. .history-main {
  414. flex: 1;
  415. }
  416. .history-query {
  417. color: #000000;
  418. text-align: center;
  419. font-size: 24rpx;
  420. font-weight: 400;
  421. line-height: 40rpx;
  422. }
  423. .history-time {
  424. font-size: 22rpx;
  425. color: #999;
  426. }
  427. .history-card {
  428. background-color: #fff;
  429. border: 2rpx solid #f2f2f2;
  430. border-left: 8rpx solid rgb(220, 31, 29);
  431. border-radius: 12rpx;
  432. padding: 18rpx 20rpx;
  433. margin-bottom: 16rpx;
  434. box-shadow: 0 4rpx 10rpx rgba(0, 0, 0, 0.03);
  435. }
  436. .history-query {
  437. font-size: 28rpx;
  438. color: #333333;
  439. font-weight: 500;
  440. }
  441. .history-time {
  442. margin-top: 8rpx;
  443. font-size: 22rpx;
  444. color: #888888;
  445. }
  446. .empty-history {
  447. padding: 40rpx;
  448. color: #999999;
  449. text-align: center;
  450. }
  451. </style>