previewFile(item) {
// this.previewFileBtn(item.url, item.fileName, (err) => { this.$api.msg(err) })
const _self = this
upload.previewFile(item.fileUrl, function(err) {
_self.$api.msg(err)
}, item.fileName)
}
const previewFile = (url, fail, fileName = '附件文件') => {
const fileType = url.substring(url.lastIndexOf('.') + 1, url.length)
// #ifdef APP-PLUS
const name = fileName.indexOf('.') > -1 ? fileName : `${fileName}.${fileType}`
const dtask = plus.downloader.createDownload(url, { filename: name }, function(d, status) {
if (status === 200) {
const filePath = d.filename
console.log(fileType, { filePath, name, url })
if (/\.(png|jpg|gif|jpeg|webp)$/i.test(url)) {
uni.previewImage({
urls: [filePath]
})
} else {
uni.openDocument({
filePath,
fileType,
fail
})
}
} else {
fail('Download failed: ' + status)
}
})
dtask.start()
// #endif
// #ifndef APP-PLUS
uni.downloadFile({
url,
success: (res) => {
const filePath = res.tempFilePath
if (/\.(png|jpg|gif|jpeg|webp)$/i.test(url)) {
uni.previewImage({
urls: [filePath]
})
} else {
uni.openDocument({
filePath,
fileType,
fail
})
}
}
})
// #endif
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)