fix preview overflow

This commit is contained in:
Timi
2025-12-11 00:27:58 +08:00
parent 980d0e1431
commit 2cb8f16ccc
2 changed files with 21 additions and 14 deletions

View File

@ -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
})
}
}
});

View File

@ -41,13 +41,13 @@
<scroll-view wx:if="{{item.items && item.items.length > 0}}" scroll-y class="items-scroll">
<view class="items">
<view class="wrapper">
<block wx:for="{{item.items}}" wx:key="mongoId" wx:for-item="media" wx:for-index="mediaIndex">
<block wx:for="{{item.items}}" wx:key="mongoId" wx:for-item="media" wx:for-index="itemIndex">
<image
class="item thumbnail {{media.type === 1 ? 'video' : 'image'}}"
src="{{media.thumbURL}}"
mode="widthFix"
catchtap="previewMedia"
data-media-index="{{mediaIndex}}"
data-item-index="{{itemIndex}}"
/>
</block>
</view>