| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- import tools from "./tools";
- let BASE_URL =''
- //#ifndef H5
- BASE_URL ='https://demoapi.jhcs888.com/'
- //#endif
- export const request = (url, method, data, show = false) => {
- let token = uni.getStorageSync('token')
- let u_id = uni.getStorageSync('u_id')
- if(token&&u_id){
- data.token = token;
- data.u_id = u_id
- }
- if (show) {
- tools.showLoading();
- }
- if (data === undefined) {
- data = {};
- }
- return new Promise((resolve, reject) => {
- uni.request({
- url:BASE_URL+ url,
- data: data,
- method: method || 'post',
- header: {
- 'content-type': 'application/json',
- 'hversion': '1.0',
- 'Authorization': token
- },
- success: (res) => {
- if (res.statusCode === 200) {
- tools.hideLoading();
- if (res.data.code * 1 === 401) {
- uni.clearStorageSync()
- uni.reLaunch({
- url: '/pages/login/index'
- });
- } else {
- resolve(res.data)
- }
- }else if(res.statusCode === 401){
- uni.clearStorageSync()
- uni.reLaunch({
- url: '/pages/login/index'
- });
- } else{
- tools.error('网络错误!!')
- }
- },
- fail: (err) => {
- tools.error('网络错误!!')
- reject(err)
- tools.hideLoading();
- }
- })
- })
- }
|