|
|
@ -1,5 +1,6 @@ |
|
|
|
const baseURL = 'https://yoursairdata.com/api/' |
|
|
|
const baseURL = 'https://yoursairdata.com/api/' |
|
|
|
// const baseURL = 'http://192.168.209.210:9002/'
|
|
|
|
// const baseURL = 'http://192.168.209.210:9002/'
|
|
|
|
|
|
|
|
const defaultCity = '重庆' |
|
|
|
const GET = 'GET'; |
|
|
|
const GET = 'GET'; |
|
|
|
const POST = 'POST'; |
|
|
|
const POST = 'POST'; |
|
|
|
const PUT = 'PUT'; |
|
|
|
const PUT = 'PUT'; |
|
|
@ -8,14 +9,17 @@ const DELETE = 'DELETE'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function request(method, url, data, hasToke = true) { |
|
|
|
function request(method, url, data, hasToke = true) { |
|
|
|
|
|
|
|
|
|
|
|
let token = wx.getStorageSync('access_token') |
|
|
|
let token = wx.getStorageSync('access_token') |
|
|
|
let Authorization = token && hasToke ? `Bearer ${token}` : 'Basic YXBwOmFwcA=='; |
|
|
|
let Authorization = token && hasToke ? `Bearer ${token}` : 'Basic YXBwOmFwcA=='; |
|
|
|
|
|
|
|
if (method === GET) { |
|
|
|
|
|
|
|
let city = wx.getStorageSync('city') |
|
|
|
// console.log(Authorization)
|
|
|
|
city = city ? city : defaultCity |
|
|
|
// console.log(method,url, data,hasToke)
|
|
|
|
if (url.indexOf('?') !== -1) { |
|
|
|
|
|
|
|
url += `&city=${city}` |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
url += `?city=${city}` |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
return new Promise(function (resolve, reject) { |
|
|
|
return new Promise(function (resolve, reject) { |
|
|
|
let header = { |
|
|
|
let header = { |
|
|
|
'content-type': 'application/json', |
|
|
|
'content-type': 'application/json', |
|
|
@ -27,7 +31,6 @@ function request(method, url, data, hasToke = true) { |
|
|
|
data: method === POST ? JSON.stringify(data) : data, |
|
|
|
data: method === POST ? JSON.stringify(data) : data, |
|
|
|
header: header, |
|
|
|
header: header, |
|
|
|
success(res) { |
|
|
|
success(res) { |
|
|
|
// console.log(res);
|
|
|
|
|
|
|
|
if (res.statusCode == 401) { |
|
|
|
if (res.statusCode == 401) { |
|
|
|
wx.showToast({ |
|
|
|
wx.showToast({ |
|
|
|
title: '登录过期,请重新登录', |
|
|
|
title: '登录过期,请重新登录', |
|
|
@ -38,9 +41,6 @@ function request(method, url, data, hasToke = true) { |
|
|
|
wx.navigateTo({ |
|
|
|
wx.navigateTo({ |
|
|
|
url: "/pages/auth/auth", |
|
|
|
url: "/pages/auth/auth", |
|
|
|
}) |
|
|
|
}) |
|
|
|
// setTimeout(() => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// }, 1500)
|
|
|
|
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
resolve(res.data); |
|
|
|
resolve(res.data); |
|
|
|
} |
|
|
|
} |
|
|
@ -54,14 +54,10 @@ function request(method, url, data, hasToke = true) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 登录方法
|
|
|
|
// 登录方法
|
|
|
|
|
|
|
|
|
|
|
|
function requestLogin(method, url, data) { |
|
|
|
function requestLogin(method, url, data) { |
|
|
|
|
|
|
|
|
|
|
|
let Authorization = 'Basic YXBwOmFwcA=='; |
|
|
|
let Authorization = 'Basic YXBwOmFwcA=='; |
|
|
|
|
|
|
|
|
|
|
|
return new Promise(function (resolve, reject) { |
|
|
|
return new Promise(function (resolve, reject) { |
|
|
|
let header = { |
|
|
|
let header = { |
|
|
|
// 'content-type': 'application/json',
|
|
|
|
|
|
|
|
'content-type': 'application/x-www-form-urlencoded', |
|
|
|
'content-type': 'application/x-www-form-urlencoded', |
|
|
|
'Authorization': Authorization, |
|
|
|
'Authorization': Authorization, |
|
|
|
}; |
|
|
|
}; |
|
|
@ -109,9 +105,11 @@ const API = { |
|
|
|
measureData: (data) => request(POST, `applets/measuredata`, data, true), //保存测算数据
|
|
|
|
measureData: (data) => request(POST, `applets/measuredata`, data, true), //保存测算数据
|
|
|
|
AJAX: (GET, url, data, is_toke) => request(GET, url, data, is_toke), |
|
|
|
AJAX: (GET, url, data, is_toke) => request(GET, url, data, is_toke), |
|
|
|
Login: (GET, url, data) => requestLogin(GET, url, data), |
|
|
|
Login: (GET, url, data) => requestLogin(GET, url, data), |
|
|
|
|
|
|
|
getCityList:()=>request(GET, '/cityArea/city'), |
|
|
|
|
|
|
|
getAreaList:(city)=>request(GET,`/cityArea/getArea/${city}`) |
|
|
|
}; |
|
|
|
}; |
|
|
|
module.exports = { |
|
|
|
module.exports = { |
|
|
|
API: API, |
|
|
|
API: API, |
|
|
|
baseURL:baseURL |
|
|
|
baseURL: baseURL, |
|
|
|
|
|
|
|
request: request |
|
|
|
} |
|
|
|
} |