123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- import Notify from '../miniprogram_npm/@vant/weapp/notify/notify';
- const config = {
- // baseURL: 'http://192.168.1.2:8801', // 基础URL
- baseURL: 'https://www.xsip.cn', // 基础URL
- timeout: 30000, // 超时时间(单位ms)
- header: {
- // 'content-type': 'application/json', // 默认请求头
- // 其他全局请求头...
-
- },
- // 其他全局配置...
- 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: 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.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),
- };
|