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.

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