add journal-detail-panel

This commit is contained in:
Timi
2025-12-10 16:45:29 +08:00
parent a5fb1d752b
commit 1e54782600
12 changed files with 496 additions and 527 deletions

View File

@ -27,9 +27,7 @@ interface JournalDateData {
journalMap: Record<string, number[]>; // 存储每个日期的日记 id 列表
selectedDate: SelectedDateInfo | null;
isLoading: boolean;
currentJournalIndex: number; // 当前日记索引
popupVisible: boolean; // popup 显示状态
swiperNextMargin: string; // swiper 的 next-margin 值
}
Page({
@ -37,9 +35,7 @@ Page({
journalMap: {},
selectedDate: null,
isLoading: true,
currentJournalIndex: 0,
popupVisible: false,
swiperNextMargin: "0"
popupVisible: false
},
async onLoad() {
@ -170,9 +166,7 @@ Page({
displayDate,
journals
},
currentJournalIndex: 0, // 重置索引
popupVisible: true, // 显示 popup
swiperNextMargin: journals.length > 1 ? "128rpx" : "0" // 设置初始 margin
popupVisible: true // 显示 popup
});
wx.hideLoading();
@ -188,57 +182,8 @@ Page({
/** 关闭详情 */
closeDetail() {
this.setData({
popupVisible: false
});
},
/** popup 显示状态变化 */
onPopupVisibleChange(e: WechatMiniprogram.CustomEvent) {
const { visible } = e.detail;
this.setData({
popupVisible: visible
});
// 关闭时清空数据
if (!visible) {
this.setData({
selectedDate: null,
currentJournalIndex: 0
});
}
},
/** swiper 切换事件 */
onSwiperChange(e: WechatMiniprogram.SwiperChange) {
this.setData({
currentJournalIndex: e.detail.current
});
},
/** swiper 动画完成事件 */
onSwiperAnimationFinish(e: WechatMiniprogram.SwiperAnimationFinish) {
if (!this.data.selectedDate) return;
const current = e.detail.current;
const total = this.data.selectedDate.journals.length;
// 动画完成后更新 margin确保过渡流畅
const nextMargin = total > 1 && current < total - 1 ? "128rpx" : "0";
this.setData({
swiperNextMargin: nextMargin
});
},
/** 预览媒体 */
previewMedia(e: WechatMiniprogram.BaseEvent) {
const { mediaIndex } = e.currentTarget.dataset;
if (!this.data.selectedDate) return;
// 使用当前 swiper 的索引
const journal = this.data.selectedDate.journals[this.data.currentJournalIndex];
const sources = journal.items.map((item: any) => ({
url: item.sourceURL,
type: item.type === 0 ? "image" : "video"
}));
wx.previewMedia({
current: mediaIndex,
sources: sources as WechatMiniprogram.MediaSource[]
popupVisible: false,
selectedDate: null
});
}
});