fix creater,editor preview

This commit is contained in:
Timi
2025-12-11 14:26:16 +08:00
parent 61171a6df7
commit fc6edcb5ab
2 changed files with 24 additions and 10 deletions

View File

@ -160,14 +160,22 @@ Page({
})
},
preview(e: WechatMiniprogram.BaseEvent) {
const itemIndex = e.currentTarget.dataset.index;
const total = this.data.mediaList.length;
const startIndex = Math.max(0, itemIndex - 25);
const endIndex = Math.min(total, startIndex + 50);
const newCurrentIndex = itemIndex - startIndex;
const sources = this.data.mediaList.slice(startIndex, endIndex).map(item => {
return {
url: item.path,
type: MediaItemType[item.type].toLowerCase()
} as WechatMiniprogram.MediaSource;
});
wx.previewMedia({
current: e.currentTarget.dataset.index,
sources: this.data.mediaList.map(item => {
return {
url: item.path,
type: MediaItemType[item.type].toLowerCase()
} as WechatMiniprogram.MediaSource;
})
current: newCurrentIndex,
sources
});
},
deleteMedia(e: WechatMiniprogram.BaseEvent) {

View File

@ -196,10 +196,16 @@ Page({
type: MediaItemType[item.type].toLowerCase()
}));
const allSources = [...sources, ...newSources];
const currentIndex = isNewMedia ? this.data.mediaList.length + index : index;
const itemIndex = isNewMedia ? this.data.mediaList.length + index : index;
const total = allSources.length;
const startIndex = Math.max(0, itemIndex - 25);
const endIndex = Math.min(total, startIndex + 50);
const newCurrentIndex = itemIndex - startIndex;
wx.previewMedia({
current: currentIndex,
sources: allSources as WechatMiniprogram.MediaSource[]
current: newCurrentIndex,
sources: allSources.slice(startIndex, endIndex) as WechatMiniprogram.MediaSource[]
});
},
/** 删除附件 */