|
|
|
@ -153,9 +153,42 @@
|
|
|
|
},
|
|
|
|
},
|
|
|
|
openFiles(files) {
|
|
|
|
openFiles(files) {
|
|
|
|
console.log("files", files)
|
|
|
|
console.log("files", files)
|
|
|
|
|
|
|
|
if (!files || files.length === 0) {
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const file = files[0]
|
|
|
|
|
|
|
|
const fileUrl = file.url || file.path || ''
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 判断是否为图片文件
|
|
|
|
|
|
|
|
const imageExtensions = ['.jpg', '.jpeg', '.png', '.gif', '.bmp', '.webp', '.svg']
|
|
|
|
|
|
|
|
const isImage = imageExtensions.some(ext => {
|
|
|
|
|
|
|
|
const lowerUrl = fileUrl.toLowerCase()
|
|
|
|
|
|
|
|
return lowerUrl.includes(ext) || lowerUrl.match(/\.(jpg|jpeg|png|gif|bmp|webp|svg)(\?|$)/i)
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (isImage) {
|
|
|
|
|
|
|
|
// 如果是图片,使用预览功能
|
|
|
|
|
|
|
|
const urls = files.map(f => f.url || f.path).filter(Boolean)
|
|
|
|
|
|
|
|
uni.previewImage({
|
|
|
|
|
|
|
|
urls: urls,
|
|
|
|
|
|
|
|
current: fileUrl,
|
|
|
|
|
|
|
|
success: function(res) {
|
|
|
|
|
|
|
|
console.log("预览图片成功");
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
fail: function(err) {
|
|
|
|
|
|
|
|
console.log("预览图片失败", err);
|
|
|
|
|
|
|
|
uni.showToast({
|
|
|
|
|
|
|
|
title: '预览图片失败',
|
|
|
|
|
|
|
|
icon: 'none'
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// 如果是其他文件,下载后打开
|
|
|
|
let that = this
|
|
|
|
let that = this
|
|
|
|
uni.downloadFile({
|
|
|
|
uni.downloadFile({
|
|
|
|
url: files[0].url,
|
|
|
|
url: fileUrl,
|
|
|
|
success: function(res) {
|
|
|
|
success: function(res) {
|
|
|
|
if (res.statusCode === 200) {
|
|
|
|
if (res.statusCode === 200) {
|
|
|
|
console.log("临时路径", res.tempFilePath)
|
|
|
|
console.log("临时路径", res.tempFilePath)
|
|
|
|
@ -169,6 +202,10 @@
|
|
|
|
fail: function(res) {
|
|
|
|
fail: function(res) {
|
|
|
|
console.log("uni.openDocument,fail");
|
|
|
|
console.log("uni.openDocument,fail");
|
|
|
|
console.log(res)
|
|
|
|
console.log(res)
|
|
|
|
|
|
|
|
uni.showToast({
|
|
|
|
|
|
|
|
title: '打开文件失败',
|
|
|
|
|
|
|
|
icon: 'none'
|
|
|
|
|
|
|
|
})
|
|
|
|
},
|
|
|
|
},
|
|
|
|
complete: function(res) {
|
|
|
|
complete: function(res) {
|
|
|
|
console.log("uni.openDocument,complete");
|
|
|
|
console.log("uni.openDocument,complete");
|
|
|
|
@ -179,10 +216,15 @@
|
|
|
|
},
|
|
|
|
},
|
|
|
|
fail: function(err) {
|
|
|
|
fail: function(err) {
|
|
|
|
console.log('文件下载失败', err)
|
|
|
|
console.log('文件下载失败', err)
|
|
|
|
|
|
|
|
uni.showToast({
|
|
|
|
|
|
|
|
title: '文件下载失败',
|
|
|
|
|
|
|
|
icon: 'none'
|
|
|
|
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
</script>
|
|
|
|
|