fix preview overflow
This commit is contained in:
@ -96,21 +96,28 @@ Component({
|
||||
|
||||
/** 预览媒体 */
|
||||
previewMedia(e: WechatMiniprogram.BaseEvent) {
|
||||
const { mediaIndex } = e.currentTarget.dataset;
|
||||
const journals = this.properties.journals as JournalInfo[];
|
||||
if (!journals || journals.length === 0) return;
|
||||
|
||||
// 使用当前 swiper 的索引
|
||||
const journal = journals[this.data.currentJournalIndex];
|
||||
const sources = journal.items.map((item: any) => ({
|
||||
url: item.sourceURL,
|
||||
type: item.type === 0 ? "image" : "video"
|
||||
}));
|
||||
if (!journals || journals.length === 0) {
|
||||
return;
|
||||
}
|
||||
const { itemIndex } = e.currentTarget.dataset;
|
||||
const items = journals[this.data.currentJournalIndex].items;
|
||||
const total = items.length;
|
||||
|
||||
const startIndex = Math.max(0, itemIndex - 25);
|
||||
const endIndex = Math.min(total, startIndex + 50);
|
||||
const newCurrentIndex = itemIndex - startIndex;
|
||||
|
||||
const sources = items.slice(startIndex, endIndex).map((item) => {
|
||||
return {
|
||||
url: item.sourceURL,
|
||||
type: item.type === 0 ? "image" : "video"
|
||||
}
|
||||
}) as any;
|
||||
wx.previewMedia({
|
||||
current: mediaIndex,
|
||||
sources: sources as WechatMiniprogram.MediaSource[]
|
||||
});
|
||||
current: newCurrentIndex,
|
||||
sources
|
||||
})
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user