const baseUrl = 'http://127.0.0.1:8080/api';
const request = function(options) {
options.url = baseUrl + options.url;
try {
const token = uni.getStorageSync('token');
if (token) {
options.header = {
'Authorization' : 'Bearer ' + token,
'Content-Type' : 'application/json'
};
}else{
uni.navigateTo({
url: '/pages/login/login'
});
return;
}
} catch (err) {
console.log(err)
}
options.complete = (response) => {
if (response.statusCode == 401) {
uni.navigateTo({
url: '/pages/login/login'
});
return;
}
}
return uni.request(options);
}
export default request;
const baseUrl = 'http://127.0.0.1:8080/api';
const baseRequest = (url, param, way, callBack) => {
let options = {
url: baseUrl+url,
data: param,
method: way,
header: way == 'get' ? {'X-Requested-With': 'XMLHttpRequest',"Accept": "application/json","Content-Type": "application/json; charset=UTF-8"} : {'X-Requested-With': 'XMLHttpRequest','Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'},
dataType: 'json',
}
options.complete = (response) => {
if (response.statusCode == 401) {
uni.navigateTo({
url: '/pages/login/login'
});
return;
}
}
return uni.request(options);
};