|
|
@@ -35,10 +35,19 @@ Component({
|
|
|
index,
|
|
|
type
|
|
|
} = e.currentTarget.dataset;
|
|
|
- wx.previewMedia({
|
|
|
- current: index,
|
|
|
- sources: type == 'image' ? this.data.files.viewImages : this.data.files.viewVideos,
|
|
|
- })
|
|
|
+ if (type == 'image') {
|
|
|
+ // 用 localPath(如有)替代原始 url,确保真机预览正常
|
|
|
+ const sources = this.data.files.viewImages.map(v => {
|
|
|
+ const img = this.data.files.images.find(i => i.url === v.url);
|
|
|
+ return { url: (img && img.localPath) || v.url, type: 'image' };
|
|
|
+ });
|
|
|
+ wx.previewMedia({ current: index, sources });
|
|
|
+ } else {
|
|
|
+ wx.previewMedia({
|
|
|
+ current: index,
|
|
|
+ sources: this.data.files.viewVideos,
|
|
|
+ });
|
|
|
+ }
|
|
|
},
|
|
|
/* 预览文档 */
|
|
|
viewFlies(e) {
|
|
|
@@ -229,5 +238,31 @@ Component({
|
|
|
attachmentids: this.getFiles().attachmentids
|
|
|
})
|
|
|
},
|
|
|
+ /* 图片加载失败 - 通过原生通道下载到本地临时路径(绕过 iOS ATS 对 HTTP 的限制) */
|
|
|
+ onImageError(e) {
|
|
|
+ const { index } = e.currentTarget.dataset;
|
|
|
+ const item = this.data.files.images[index];
|
|
|
+ if (!item || item._retrying || item.localPath) return;
|
|
|
+ item._retrying = true;
|
|
|
+ wx.getImageInfo({
|
|
|
+ src: item.url,
|
|
|
+ success: (res) => {
|
|
|
+ if (res.path) {
|
|
|
+ this.setData({ [`files.images[${index}].localPath`]: res.path });
|
|
|
+ }
|
|
|
+ },
|
|
|
+ fail: () => {
|
|
|
+ // getImageInfo 也失败时,尝试 downloadFile
|
|
|
+ wx.downloadFile({
|
|
|
+ url: item.url,
|
|
|
+ success: (res) => {
|
|
|
+ if (res.statusCode === 200) {
|
|
|
+ this.setData({ [`files.images[${index}].localPath`]: res.tempFilePath });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
}
|
|
|
})
|