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.

513 lines
11 KiB

4 weeks ago
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. console.log('点击了历史数据',deepExplorationStore.deepExplorationInfo);
  148. onDrawerBackClick();
  149. setTimeout(() => {
  150. uni.navigateTo({
  151. url: '/pages/deepExploration/MainForceActions'
  152. });
  153. }, 200);
  154. }
  155. }
  156. const historyList = ref([]);
  157. // 为历史记录格式化时间:YYYY-MM-DD HH:mm
  158. const formatTimeForHistory = (timeString) => {
  159. // 假设 timeString 格式为 "YYYY-MM-DD HH:mm:ss"
  160. const parts = timeString.split(" ");
  161. if (parts.length >= 2) {
  162. const datePart = parts[0];
  163. const timePart = parts[1];
  164. const timeParts = timePart.split(":");
  165. if (timeParts.length >= 2) {
  166. return `${datePart} ${timeParts[0]}:${timeParts[1]}`;
  167. }
  168. }
  169. return timeString;
  170. };
  171. // 历史分组(今天/昨天/近一周/按月)
  172. const groupedHistory = computed(() => {
  173. const sections = [];
  174. // 从缓存获取今天日期,如果没有则使用当前日期
  175. const now = new Date();
  176. const startOfDay = (d) =>
  177. new Date(d.getFullYear(), d.getMonth(), d.getDate());
  178. const isSameDay = (a, b) =>
  179. startOfDay(a).getTime() === startOfDay(b).getTime();
  180. const isYesterday = (d) => {
  181. const y = new Date(now.getFullYear(), now.getMonth(), now.getDate() - 1);
  182. return isSameDay(d, y);
  183. };
  184. const isToday = (d) => isSameDay(d, now);
  185. const withinLast7Days = (d) => {
  186. const seven = new Date(
  187. now.getFullYear(),
  188. now.getMonth(),
  189. now.getDate() - 7
  190. );
  191. return d >= seven && !isToday(d) && !isYesterday(d);
  192. };
  193. const monthLabel = (d) => `${d.getMonth() + 1}`;
  194. const today = [];
  195. const yesterday = [];
  196. const last7 = [];
  197. const byMonth = new Map();
  198. // 使用 historyList.value 替代 searchHistory.value
  199. historyList.value.forEach((item) => {
  200. // 根据你的数据结构,使用 createdTime 字段
  201. const dt = new Date(item.createdTime);
  202. if (isToday(dt)) {
  203. today.push(item);
  204. } else if (isYesterday(dt)) {
  205. yesterday.push(item);
  206. } else if (withinLast7Days(dt)) {
  207. last7.push(item);
  208. } else {
  209. const year = dt.getFullYear();
  210. const month = dt.getMonth() + 1;
  211. const key = `${year}-${month}`;
  212. if (!byMonth.has(key))
  213. byMonth.set(key, {
  214. title: `${year}${month}`,
  215. year,
  216. month,
  217. items: [],
  218. });
  219. byMonth.get(key).items.push(item);
  220. }
  221. });
  222. if (today.length) sections.push({ title: "今天", items: today });
  223. if (yesterday.length) sections.push({ title: "昨天", items: yesterday });
  224. if (last7.length) sections.push({ title: "近一周", items: last7 });
  225. const monthSections = Array.from(byMonth.values()).sort((a, b) => {
  226. if (a.year !== b.year) return b.year - a.year;
  227. return b.month - a.month; // 月份倒序,如 10月 在 9月 之前
  228. });
  229. sections.push(...monthSections);
  230. return sections;
  231. });
  232. onMounted(() => {});
  233. </script>
  234. <style scoped lang="scss">
  235. * {
  236. box-sizing: border-box;
  237. }
  238. .titleContent {
  239. display: flex;
  240. align-items: center;
  241. justify-content: space-between;
  242. padding: 30rpx 60rpx 40rpx 35rpx;
  243. box-shadow: 2rpx 2rpx 8rpx rgba(0, 0, 0, 0.1);
  244. .left {
  245. display: flex;
  246. align-items: center;
  247. width: 36rpx;
  248. height: 36rpx;
  249. }
  250. .title {
  251. position: absolute;
  252. left: 50%;
  253. transform: translateX(-50%);
  254. color: #000000;
  255. font-family: "PingFang SC";
  256. font-size: 19px;
  257. font-style: normal;
  258. font-weight: 400;
  259. line-height: 25px;
  260. }
  261. .right {
  262. display: flex;
  263. align-items: center;
  264. gap: 20rpx;
  265. .notice {
  266. width: 35rpx;
  267. height: 35rpx;
  268. gap: 20rpx;
  269. }
  270. .history {
  271. width: 32rpx;
  272. height: 32rpx;
  273. align-items: center;
  274. }
  275. }
  276. }
  277. /* 搜索历史侧拉框样式 */
  278. .drawer-overlay {
  279. position: fixed;
  280. left: 0;
  281. top: 0;
  282. right: 0;
  283. bottom: 0;
  284. background-color: rgba(0, 0, 0, 0.35);
  285. z-index: 900;
  286. }
  287. .drawer-panel {
  288. position: fixed;
  289. left: 0;
  290. right: 0;
  291. bottom: 0;
  292. height: 75vh;
  293. max-height: 80vh;
  294. width: 100%;
  295. background: #ffffff;
  296. box-shadow: 0 -8rpx 20rpx rgba(0, 0, 0, 0.06);
  297. z-index: 1000;
  298. display: flex;
  299. flex-direction: column;
  300. border-top-left-radius: 20rpx;
  301. border-top-right-radius: 20rpx;
  302. transition: transform 0.22s ease;
  303. }
  304. .drawer-back {
  305. position: absolute;
  306. left: 50%;
  307. top: -14px;
  308. transform: translateX(-50%);
  309. width: 28px;
  310. height: 48px;
  311. border-radius: 12px;
  312. background: #fff;
  313. box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
  314. display: flex;
  315. align-items: center;
  316. justify-content: center;
  317. }
  318. .drawer-back-icon {
  319. font-size: 16px;
  320. color: #8a8a8a;
  321. }
  322. .drawer-actions {
  323. display: flex;
  324. align-items: center;
  325. gap: 40rpx;
  326. }
  327. .delete-all-container {
  328. display: flex;
  329. align-items: center;
  330. gap: 14rpx;
  331. }
  332. .delete-icon {
  333. width: 28rpx;
  334. height: 32rpx;
  335. }
  336. .delete-all {
  337. font-size: 28rpx;
  338. }
  339. .drawer-close {
  340. background: url("../static/icons/关闭2.svg");
  341. width: 48rpx;
  342. height: 48rpx;
  343. border-radius: 24rpx;
  344. /* background: #f5f5f5; */
  345. /* box-shadow: 0 2px 8px rgba(0,0,0,0.08); */
  346. display: flex;
  347. align-items: center;
  348. justify-content: center;
  349. image {
  350. width: 100%;
  351. height: 100%;
  352. }
  353. }
  354. .drawer-header {
  355. display: flex;
  356. align-items: center;
  357. justify-content: space-between;
  358. padding: 52rpx 28rpx 0rpx 28rpx;
  359. /* border-bottom: 2rpx solid #f0f0f0; */
  360. }
  361. .drawer-title {
  362. font-size: 32rpx;
  363. font-weight: 600;
  364. color: #333333;
  365. }
  366. .drawer-content {
  367. flex: 1;
  368. min-height: 0;
  369. /* 让 flex 子元素可在容器内收缩以启用滚动 */
  370. height: 100%;
  371. overscroll-behavior-y: contain;
  372. /* 防止滚动串联到页面 */
  373. -webkit-overflow-scrolling: touch;
  374. /* iOS 惯性滚动 */
  375. touch-action: pan-y;
  376. /* 优化触控滚动,仅垂直 */
  377. }
  378. .drawer-inner {
  379. padding: 20rpx 24rpx 20rpx 24rpx;
  380. }
  381. .history-section {
  382. margin-bottom: 20rpx;
  383. /* margin: 0 24rpx; */
  384. }
  385. .section-title {
  386. font-size: 26rpx;
  387. color: #888;
  388. margin: 10rpx 6rpx 16rpx;
  389. }
  390. .history-item {
  391. display: flex;
  392. align-items: center;
  393. padding: 19rpx 18rpx;
  394. background-color: #f6f7f9;
  395. border-radius: 12rpx;
  396. margin-bottom: 12rpx;
  397. }
  398. .history-left {
  399. margin-right: 20rpx;
  400. width: 50rpx;
  401. height: 50rpx;
  402. }
  403. .flag-circle {
  404. width: 50rpx;
  405. height: 50rpx;
  406. border-radius: 50%;
  407. background: #fff;
  408. border: 2rpx solid #eee;
  409. display: flex;
  410. align-items: center;
  411. justify-content: center;
  412. image {
  413. width: 50rpx;
  414. height: 50rpx;
  415. border-radius: 50%;
  416. }
  417. }
  418. .history-main {
  419. flex: 1;
  420. }
  421. .history-query {
  422. color: #000000;
  423. text-align: center;
  424. font-size: 24rpx;
  425. font-weight: 400;
  426. line-height: 40rpx;
  427. }
  428. .history-time {
  429. font-size: 22rpx;
  430. color: #999;
  431. }
  432. .history-card {
  433. background-color: #fff;
  434. border: 2rpx solid #f2f2f2;
  435. border-left: 8rpx solid rgb(220, 31, 29);
  436. border-radius: 12rpx;
  437. padding: 18rpx 20rpx;
  438. margin-bottom: 16rpx;
  439. box-shadow: 0 4rpx 10rpx rgba(0, 0, 0, 0.03);
  440. }
  441. .history-query {
  442. font-size: 28rpx;
  443. color: #333333;
  444. font-weight: 500;
  445. }
  446. .history-time {
  447. margin-top: 8rpx;
  448. font-size: 22rpx;
  449. color: #888888;
  450. }
  451. .empty-history {
  452. padding: 40rpx;
  453. color: #999999;
  454. text-align: center;
  455. }
  456. </style>