import Notify from '../miniprogram_npm/@vant/weapp/notify/notify'; const config = { baseURL: 'http://192.168.2.111:8802', // 基础URL // baseURL: 'https://www.xsip.cn', // 基础URL timeout: 30000, // 超时时间(单位ms) header: { 'content-type': 'application/xls', // 默认请求头 // 其他全局请求头... }, // 其他全局配置... tabbar:["pages/index/index","pages/hotProduct/hotProduct","pages/mine/mine"] }; function getPages(){ var obj = { type: 'danger' } var pages = getCurrentPages() var route = pages[pages.length - 1]?.route console.log(config.tabbar,route) if(route && config.tabbar.indexOf(route)==-1){ obj.top = wx.getStorageSync('height') } return obj } function downLoad(url){ return new Promise((resolve, reject)=>{ wx.downloadFile({ url:config.baseURL + '/fileManager/downloadFile?fileId=' + url, // filePath: 'filePath', header: { ...config.header }, // timeout: 0, success: (result) => { wx.hideLoading() var obj = getPages() if(obj.message){ Notify(obj) } console.log(result) if (result.statusCode === 200) { const tempFilePath = result.tempFilePath; // 临时文件路径 wx.openDocument({ filePath: tempFilePath, showMenu:true, success: function (res) { console.log('打开文档成功') } }) // wx.saveFile({ // tempFilePath: tempFilePath, // 传入临时文件路径 // success(saveRes) { // const savedFilePath = saveRes.savedFilePath; // console.log('文件已保存到本地', savedFilePath); // resolve(saveRes) // // 可以在这里做后续操作,如打开文件或通知用户 // }, // fail(error) { // console.error('保存文件失败', error); // reject('保存文件失败') // } // }) } }, fail: (res) => { wx.hideLoading() var obj = getPages() if(obj.message){ Notify(obj) } reject('导出失败') }, complete: (res) => {}, }) }) } // 导出请求方法 module.exports = { downLoadFile: (url) => downLoad(url), };