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.

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