一、附件中有图片也有pdf,需要进行预览,图片可直接预览,而pdf是下载后再预览
二、主要代码
<view class="fj-row" v-for="(item,index) in formDetail.attachmentRespVOS" :key="index"><view class="drow" @click="preViewImg2(item)"> <view class="fjtitle">{{item.title}}</view></view><view class="fj-line"></view>
</view>
//预览图片preViewImg2(row){ var imgArr = [];//给整个数组的文件列表都加上apifor (var i = 0; i < this.formDetail.attachmentRespVOS.length; i++) {imgArr[i] = config.imgBaseUrl + this.formDetail.attachmentRespVOS[i].fileUrl}var nowUrl=config.imgBaseUrl+row.fileUrl;//当前的预览路径var arr1 = nowUrl.split(".");var len1=arr1.length-1;var type1=arr1[len1];if(type1=='pdf'){this.Download(nowUrl)}else{uni.previewImage({current: nowUrl,urls: imgArr})}},
//下载Download(urls) {uni.downloadFile({url: urls,//下载地址接口返回success: (data) => {if (data.statusCode === 200) {//文件保存到本地uni.saveFile({tempFilePath: data.tempFilePath, //临时路径success: function(res) {uni.showToast({icon:'loading',mask: true,title: '正在下载中...', //保存路径duration: 2000,});setTimeout(() => {//打开文档查看uni.openDocument({filePath: res.savedFilePath,success: function(res) {// console.log('打开文档成功');}});}, 2000)}});}},fail: (err) => {console.log(err);uni.showToast({icon: 'none',mask: true,title: '失败请重新下载',});},});},