70 lines
2.0 KiB
JavaScript
70 lines
2.0 KiB
JavaScript
|
|
const baseUrl = "http://219.157.255.213:9007/"; //这里放置url域名32044
|
|
// const baseUrl = "http://api.crm.hnxinyouhe.com/"; //这里放置url域名32044
|
|
// const baseUrl = "http://192.168.50.9:8787/"; //这里放置url域名32044
|
|
// const baseUrl = "http://219.157.255.213:25329/"; //这里放置url域名32044
|
|
// const baseUrl = "/api/"; //这里放置url域名32044
|
|
export function request(options){//封装的requset
|
|
let { url,data,method } = options;
|
|
data = data || {},
|
|
uni.showLoading({
|
|
title: ''
|
|
});
|
|
|
|
return new Promise((resolve,rejext)=>{
|
|
uni.request({//这里是uniapp网络请求的api
|
|
url: baseUrl + url, //仅为示例,并非真实接口地址。
|
|
data,
|
|
header:{'content-type': 'application/x-www-form-urlencoded','Authorization': 'Bearer ' + uni.getStorageSync('token')},
|
|
method:method||"GET",//默认请求方式是get
|
|
success: (res) => {
|
|
if(res.data.code==401){
|
|
uni.showToast({
|
|
title: res.data.message,
|
|
icon: 'none'
|
|
});
|
|
uni.clearStorageSync();
|
|
setTimeout(() => {
|
|
uni.reLaunch({
|
|
url: '/pages/login/index',// 替换为你要跳转的页面路径
|
|
});
|
|
}, 1000);
|
|
}else{
|
|
resolve(res)
|
|
}
|
|
},
|
|
complete: (data)=>{
|
|
|
|
console.log(data.code)
|
|
uni.hideLoading();
|
|
}
|
|
});
|
|
})
|
|
}
|
|
export function requestx(options){//封装的requset
|
|
let { url,data,method } = options;
|
|
data = data || {};
|
|
return new Promise((resolve,rejext)=>{
|
|
uni.request({//这里是uniapp网络请求的api
|
|
url: baseUrl + url, //仅为示例,并非真实接口地址。
|
|
data,
|
|
header:{'content-type': 'application/x-www-form-urlencoded','Authorization': 'Bearer ' + uni.getStorageSync('openid')},
|
|
method:method||"GET",//默认请求方式是get
|
|
success: (res) => {
|
|
resolve(res)
|
|
},
|
|
complete: (data)=>{
|
|
|
|
}
|
|
});
|
|
})
|
|
}
|
|
export function showToast(options){//封装Toast
|
|
let { title,duration,icon } = options;
|
|
uni.showToast({
|
|
title:title,
|
|
duration: 2000,
|
|
icon:icon || "none"
|
|
});
|
|
}
|