refactor pages struct
This commit is contained in:
8
miniprogram/pages/main/journal/date/index.json
Normal file
8
miniprogram/pages/main/journal/date/index.json
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
"usingComponents": {
|
||||
"calendar": "/components/calendar/index",
|
||||
"t-navbar": "tdesign-miniprogram/navbar/navbar",
|
||||
"journal-detail-popup": "/components/journal-detail-popup/index"
|
||||
},
|
||||
"navigationStyle": "custom"
|
||||
}
|
||||
24
miniprogram/pages/main/journal/date/index.less
Normal file
24
miniprogram/pages/main/journal/date/index.less
Normal file
@ -0,0 +1,24 @@
|
||||
/* pages/main/journal/date/index.less */
|
||||
.container {
|
||||
width: 100%;
|
||||
height: 100vh;
|
||||
position: fixed;
|
||||
overflow: hidden;
|
||||
background: var(--theme-bg);
|
||||
|
||||
.loading {
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
z-index: 1000;
|
||||
position: fixed;
|
||||
transform: translate(-50%, -50%);
|
||||
|
||||
.loading-text {
|
||||
color: var(--theme-text-secondary);
|
||||
padding: 24rpx 48rpx;
|
||||
background: var(--theme-bg-card);
|
||||
border-radius: 8rpx;
|
||||
box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, .15);
|
||||
}
|
||||
}
|
||||
}
|
||||
90
miniprogram/pages/main/journal/date/index.ts
Normal file
90
miniprogram/pages/main/journal/date/index.ts
Normal file
@ -0,0 +1,90 @@
|
||||
// pages/main/journal/date/index.ts
|
||||
import { Journal, JournalPageType } from "../../../../types/Journal";
|
||||
import Time from "../../../../utils/Time";
|
||||
import { JournalApi } from "../../../../api/JournalApi";
|
||||
|
||||
interface JournalDateData {
|
||||
// 存储每个日期的日记 id 列表
|
||||
isLoading: boolean;
|
||||
journalMap: Record<string, number[]>;
|
||||
|
||||
popupIds: number[];
|
||||
popupVisible: boolean;
|
||||
}
|
||||
|
||||
Page({
|
||||
data: <JournalDateData>{
|
||||
isLoading: true,
|
||||
journalMap: {},
|
||||
|
||||
popupIds: [],
|
||||
popupVisible: false,
|
||||
},
|
||||
async onLoad() {
|
||||
await this.loadJournals();
|
||||
},
|
||||
/** 加载所有日记 */
|
||||
async loadJournals() {
|
||||
this.setData({ isLoading: true });
|
||||
try {
|
||||
const pageResult = await JournalApi.getList({
|
||||
index: 0,
|
||||
size: 9007199254740992,
|
||||
type: JournalPageType.PREVIEW
|
||||
});
|
||||
const list: Journal[] = pageResult.list || [];
|
||||
// 按日期分组,只存储 id
|
||||
const journalMap: Record<string, number[]> = {};
|
||||
list.forEach((journal: any) => {
|
||||
const dateKey = Time.toDate(journal.createdAt);
|
||||
if (!journalMap[dateKey]) {
|
||||
journalMap[dateKey] = [];
|
||||
}
|
||||
journalMap[dateKey].push(journal.id);
|
||||
});
|
||||
// 按 id 倒序排序每天的日记
|
||||
Object.keys(journalMap).forEach(dateKey => {
|
||||
journalMap[dateKey].sort((a, b) => b - a);
|
||||
});
|
||||
this.setData({
|
||||
journalMap,
|
||||
isLoading: false
|
||||
});
|
||||
} catch (err: any) {
|
||||
wx.showToast({
|
||||
title: err.message || "加载失败",
|
||||
icon: "error"
|
||||
});
|
||||
this.setData({ isLoading: false });
|
||||
}
|
||||
},
|
||||
/** 日期选择事件(来自 calendar 组件) */
|
||||
onDateSelect(e: WechatMiniprogram.CustomEvent) {
|
||||
const { date } = e.detail;
|
||||
const journalIds = this.data.journalMap[date];
|
||||
if (!journalIds || journalIds.length === 0) {
|
||||
wx.showToast({
|
||||
title: "该日期无日记",
|
||||
icon: "none"
|
||||
});
|
||||
return;
|
||||
}
|
||||
// 调用接口获取详情
|
||||
this.loadJournalsByIds(journalIds);
|
||||
},
|
||||
/** 根据 id 列表加载日记详情 */
|
||||
async loadJournalsByIds(ids: number[]) {
|
||||
this.setData({
|
||||
popupIds: ids,
|
||||
popupVisible: true
|
||||
});
|
||||
wx.hideLoading();
|
||||
},
|
||||
/** 关闭详情 */
|
||||
closeDetail() {
|
||||
this.setData({
|
||||
popupVisible: false,
|
||||
popupIds: []
|
||||
});
|
||||
}
|
||||
});
|
||||
17
miniprogram/pages/main/journal/date/index.wxml
Normal file
17
miniprogram/pages/main/journal/date/index.wxml
Normal file
@ -0,0 +1,17 @@
|
||||
<!--pages/main/journal/date/index.wxml-->
|
||||
<t-navbar title="日期查找" placeholder left-arrow />
|
||||
<view class="container">
|
||||
<!-- 日历视图 -->
|
||||
<calendar journal-map="{{journalMap}}" bind:dateselect="onDateSelect" />
|
||||
<!-- 加载状态 -->
|
||||
<view wx:if="{{isLoading}}" class="loading">
|
||||
<view class="loading-text">加载中...</view>
|
||||
</view>
|
||||
</view>
|
||||
<!-- 详情面板 -->
|
||||
<journal-detail-popup
|
||||
visible="{{popupVisible}}"
|
||||
ids="{{popupIds}}"
|
||||
mode="DATE"
|
||||
bind:close="closeDetail"
|
||||
/>
|
||||
Reference in New Issue
Block a user