|
@@ -57,8 +57,8 @@ export default {
|
|
|
downloadFile(url) {
|
|
|
console.log(url)
|
|
|
return new Promise((resolve, reject) => {
|
|
|
- // window.open(url, '_blank')
|
|
|
- // resolve(true)
|
|
|
+ window.open(url)
|
|
|
+ resolve(true)
|
|
|
// ----------------------------------------------------------------------------
|
|
|
// // H5环境下下载
|
|
|
// const link = document.createElement('a')
|
|
@@ -68,37 +68,34 @@ export default {
|
|
|
// link.click()
|
|
|
// document.body.removeChild(link)
|
|
|
// ----------------------------------------------------------------------------
|
|
|
- // 提取文件名和类型
|
|
|
- const filename = url.split('/').pop().split('?')[0] // 获取文件名
|
|
|
- const fileExtension = filename.split('.').pop().toLowerCase() // 获取文件扩展名
|
|
|
- // 判断当前平台
|
|
|
- const platform = uni.getSystemInfoSync().platform
|
|
|
- // 使用uni.downloadFile进行文件下载
|
|
|
- uni.downloadFile({
|
|
|
- url: url,
|
|
|
- header: {
|
|
|
- 'Content-Type': 'application/x-www-form-urlencoded'
|
|
|
- },
|
|
|
- success: res => {
|
|
|
- alert(JSON.stringify(res))
|
|
|
- if (res.statusCode === 200) {
|
|
|
- window.open(res.tempFilePath, '_blank')
|
|
|
- // // H5环境下下载
|
|
|
- // const link = document.createElement('a')
|
|
|
- // link.href = res.tempFilePath
|
|
|
- // link.download = `${filename}.${fileExtension}` // 设置下载文件名
|
|
|
- // document.body.appendChild(link)
|
|
|
- // link.click()
|
|
|
- // document.body.removeChild(link)
|
|
|
- } else {
|
|
|
- reject('Download failed: ' + res.statusCode)
|
|
|
- }
|
|
|
- },
|
|
|
- fail: err => {
|
|
|
- alert(err)
|
|
|
- reject('Download error: ' + err)
|
|
|
- }
|
|
|
- })
|
|
|
+ // // 提取文件名和类型
|
|
|
+ // const filename = url.split('/').pop().split('?')[0] // 获取文件名
|
|
|
+ // const fileExtension = filename.split('.').pop().toLowerCase() // 获取文件扩展名
|
|
|
+ // // 判断当前平台
|
|
|
+ // const platform = uni.getSystemInfoSync().platform
|
|
|
+ // // 使用uni.downloadFile进行文件下载
|
|
|
+ // uni.downloadFile({
|
|
|
+ // url: url,
|
|
|
+ // header: {
|
|
|
+ // 'Content-Type': 'application/x-www-form-urlencoded'
|
|
|
+ // },
|
|
|
+ // success: res => {
|
|
|
+ // if (res.statusCode === 200) {
|
|
|
+ // // // H5环境下下载
|
|
|
+ // // const link = document.createElement('a')
|
|
|
+ // // link.href = res.tempFilePath
|
|
|
+ // // link.download = `${filename}.${fileExtension}` // 设置下载文件名
|
|
|
+ // // document.body.appendChild(link)
|
|
|
+ // // link.click()
|
|
|
+ // // document.body.removeChild(link)
|
|
|
+ // } else {
|
|
|
+ // reject('Download failed: ' + res.statusCode)
|
|
|
+ // }
|
|
|
+ // },
|
|
|
+ // fail: err => {
|
|
|
+ // reject('Download error: ' + err)
|
|
|
+ // }
|
|
|
+ // })
|
|
|
})
|
|
|
}
|
|
|
}
|