| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 | // 允许打开的文件类型const typeList = ['doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'pdf']// 文件预览export function preview (url) {  uni.showLoading({    title: '文件加载中...'  })  wx.downloadFile({    url,    success: function (res) {      const filePath = res.tempFilePath      const arr = res.tempFilePath.split('.')      const fileType = arr[1]      if (!typeList.includes(fileType)) {        uni.showToast({          icon: "none",          title: '暂未支持此类型的文件查看',          duration: 2000,        })        return      }       wx.openDocument({        filePath: filePath,        fileType,        showMenu: true, //显示右上角菜单        success: function (res) {          console.log(res, "openDocument")          console.log("打开文档成功")        },        fail: res => {          uni.showToast({            icon: 'none',            title: res.errMsg,            duration: 5000          })        }      })    },    fail: (res) => {      uni.showToast({        icon: 'none',        title: res.errMsg,        duration: 5000      })    },    complete: res => {      uni.hideLoading()    }  })}
 |