| | |
| | | }); |
| | | }, |
| | | previewImage(index) { |
| | | // uni.previewImage({ |
| | | // current: index, // 设置当前显示图片的链接 |
| | | // urls: this.qsImage.map(s=>s.img), // 需要预览的图片链接列表 |
| | | // loop: false, // 是否开启图片轮播,默认为 false |
| | | // indicator: 'default',// 图片指示器类型,可选值为 "default"、"number"、"pointer",默认为 "default" |
| | | // }); |
| | | // 检查当前图片是否存在 |
| | | const currentImage = this.qsImage[index]; |
| | | if (!currentImage || !currentImage.img) { |
| | | uni.showToast({ |
| | | title: '图片数据异常', |
| | | icon: 'none' |
| | | }); |
| | | return; |
| | | } |
| | | |
| | | // 显示加载提示 |
| | | uni.showLoading({ |
| | | title: '加载中...' |
| | | }); |
| | | |
| | | // 如果是base64格式,需要转换为临时文件路径 |
| | | if (currentImage.img.startsWith('data:')) { |
| | | // 转换所有base64图片为临时文件路径 |
| | | const convertPromises = this.qsImage.map(item => { |
| | | if (item.img.startsWith('data:')) { |
| | | return base64ToPath(item.img); |
| | | } |
| | | return Promise.resolve(item.img); |
| | | }); |
| | | |
| | | Promise.all(convertPromises) |
| | | .then(tempFilePaths => { |
| | | uni.hideLoading(); |
| | | uni.previewImage({ |
| | | current: tempFilePaths[index], |
| | | urls: tempFilePaths, |
| | | loop: false, |
| | | indicator: 'default', |
| | | fail: (err) => { |
| | | console.error('预览失败:', err); |
| | | uni.showToast({ |
| | | title: '预览失败', |
| | | icon: 'none' |
| | | }); |
| | | } |
| | | }); |
| | | }) |
| | | .catch(error => { |
| | | uni.hideLoading(); |
| | | console.error('转换失败:', error); |
| | | uni.showToast({ |
| | | title: '图片转换失败', |
| | | icon: 'none' |
| | | }); |
| | | }); |
| | | } else { |
| | | // 如果不是base64格式,直接预览 |
| | | uni.hideLoading(); |
| | | uni.previewImage({ |
| | | current: index, |
| | | urls: this.qsImage.map(s => s.img), |
| | | loop: false, |
| | | indicator: 'default', |
| | | fail: (err) => { |
| | | console.error('预览失败:', err); |
| | | uni.showToast({ |
| | | title: '预览失败', |
| | | icon: 'none' |
| | | }); |
| | | } |
| | | }); |
| | | } |
| | | }, |
| | | init() { |
| | | this.$post({ |
| | |
| | | let tableData = res.data.tbBillList; |
| | | this.qsImage = tableData; |
| | | this.qsImage.forEach(s => { |
| | | s.img = 'data:image/png;base64,' + s.base64Date; |
| | | // 根据文件扩展名判断图片类型,默认为jpeg |
| | | let imageType = 'jpeg'; |
| | | if (s.Picturename) { |
| | | const ext = s.Picturename.toLowerCase().split('.').pop(); |
| | | if (ext === 'png') { |
| | | imageType = 'png'; |
| | | } else if (ext === 'gif') { |
| | | imageType = 'gif'; |
| | | } else if (ext === 'webp') { |
| | | imageType = 'webp'; |
| | | } |
| | | } |
| | | s.img = `data:image/${imageType};base64,${s.base64Date}`; |
| | | }); |
| | | }); |
| | | }, |