//请求头 import { baseUrl } from '@/https/url.js' export default(url, method, params) => { // 传参: 接口url, method类型, params参数 const header = { 'accept':'application/json, text/plain, */*', 'Content-type': 'application/json', 'Token':uni.getStorageSync('token')?uni.getStorageSync('token'):"", } function getParamet(data){ data = data || {}; if(uni.getStorageSync('chanId')){ if(uni.getStorageSync('chanId')!='lh'){ data.chanId = uni.getStorageSync('chanId') } } return data } return new Promise((resolve, reject) => { uni.request({ method: method, url: url.indexOf('http') !== -1 ? url : baseUrl + url, data: method=='GET'?getParamet(params):JSON.stringify(getParamet(params)), header: header }) .then((response) => { console.log('成功的请求') console.log(url) // 请求成功后的处理 if(response[1].data.code==401){ uni.removeStorageSync('token'); // uni.showToast({ // title: '登录失效,请刷新界面.', // duration: 2000, // icon: 'none' // }); } resolve(response[1]) // if(response[1].) }).catch((reject) => { // 请求失败后的处理 console.log('失败的请求') console.log(url) console.log('请求失败') reject(reject) }) }) }