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.

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