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.

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