//测试地址 //const baseURL = 'http://192.168.0.122:8002/' //正式 const baseURL='https://leiman.66km.com/' //66正式 /* const baseURL = 'https://apidms.66km.com/' const burl2='https://apidms.66km.com/' */ //欧洲维修 //const baseURL = 'http://oil.66km.com.cn/' // const burl2='http://edms.eurorepar.cn/ ' // import md5 from './MD5.js' const ajax = (url = '', date = {}, type = 'POST', header = { }) => { return new Promise((resolve, reject) => { header={}; header['Content-Type']='application/x-www-form-urlencoded'; //console.log(header) uni.request({ method: type, url: 'http://api.dms.66km.com.cn/' + url, data: date, header: header, dataType: 'json', }).then((response) => { console.log(response) //let [error, res] = response; resolve(response.data); }).catch(error => { let [err, res] = error; reject(err) }) }); } var that=this; const http = (url = '', date = {}, type = 'POST', header = { }) => { return new Promise((resolve, reject) => { header={}; if(uni.getStorageSync("wxdata")){ //console.log(uni.getStorageSync("wxdata")) var openId = uni.getStorageSync("wxdata").openid; }else{ var openId = ''; } //console.log(that.$store) //header['token']='98A9FED8814B457288166BDF623F33D1'; header['openId']=openId; header['Content-Type']='application/x-www-form-urlencoded'; console.log(baseURL + url) uni.request({ method: type, url: baseURL+'search?action=' + url, data: date, header: header, dataType: 'json', }).then((response) => { //console.log(response) //let [error, res] = response; if(response.data.code!=0){ //console.log('??') uni.showToast({ title: response.data.msg, icon:'none', duration: 4000, }); } resolve(response.data); // resolve(res.data); }).catch(error => { let [err, res] = error; reject(err) }) }); } const http2 = (url = '', date = {}, type = 'POST', header = { }) => { return new Promise((resolve, reject) => { header={}; if(uni.getStorageSync("wxdata")){ //console.log(uni.getStorageSync("wxdata")) var openId = uni.getStorageSync("wxdata").openid; }else{ var openId = ''; } header['openId']=openId; header['Content-Type']='application/x-www-form-urlencoded'; //console.log(baseURL + url) uni.request({ method: type, url: baseURL + url, data: date, header: header, dataType: 'json', }).then((response) => { //console.log(response) //let [error, res] = response; if(response.data.code!=0){ //console.log('??') uni.showToast({ title: response.data.msg, icon:'none', duration: 4000, }); } resolve(response.data); // resolve(res.data); }).catch(error => { let [err, res] = error; reject(err) }) }); } function refresh(url,date,type,header){ uni.request({ method: type, url: baseURL + url, data: date, header: header, dataType: 'json', }).then((response) => { setTimeout(function() { uni.hideLoading(); }, 200); let [error, res] = response; if(res.data.code==403){ uni.showToast({ title: res.data.msg, icon:'none', duration: 3000, }); } resolve(res.data); }).catch(error => { let [err, res] = error; reject(err) }) } export default { http,baseURL,ajax,http2 }