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.

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