import download from '@/utils/dowload'
_download(url,id,name){
download({
url: `${url}/${id}`,
method: 'get'
}).then((res)=>{
wx.getFileSystemManager().saveFile({
tempFilePath: res,
success: function(res) {
var filePath = res.savedFilePath;
uni.showModal({
title: "提示",
content: "文件已保存:" + name?name:filePath ,
cancelText: "关闭",
confirmText: "打开文件",
success: (res2) => {
if (res2.confirm) {
uni.openDocument({
filePath: filePath,
showMenu: true,
});
}
}
})
}
})
})
}
import config from '@/config'
import { getToken } from '@/utils/auth'
import { toast} from '@/utils/common'
let timeout = 10000
const baseUrl = config.baseUrl
let timer = null
const download = config => {
const isToken = (config.headers || {}).isToken === false
config.header = config.header || {}
if (getToken() && !isToken) {
config.header['Authorization'] = 'Bearer ' + getToken()
}
config.header['content-type'] = 'application/json'
return new Promise((resolve, reject) => {
uni.downloadFile({
url: config.baseUrl || baseUrl + config.url,
header: config.header,
}).then(response => {
let [error, res] = response
if (error) {
toast('后端接口连接异常')
reject('后端接口连接异常')
return
}
const code = res.statusCode || 200
resolve(res.tempFilePath)
}) .catch(error => {
let { message } = "下载失败"
toast(message)
reject(error)
})
})
}
export default download
this._download('/out/download',id,`下载文件${id}`)