import validator from '../common/validator';
|
|
const request = (url, options) => {
|
uni.showNavigationBarLoading()
|
return new Promise((resolve, reject) => {
|
uni.request({
|
url: `${url}`,
|
method: options.method,
|
data: options.method === 'GET' || options.header ===
|
'application/x-www-form-urlencoded' ? options.data : JSON.stringify(options.data),
|
header: {
|
'Content-Type': options.header,
|
'Authorization': uni.getStorageSync('token'),
|
'Referer': 'https://drptest.koreano.cn'
|
},
|
//https://servicewechat.com/wx1e7526eb4d9cf91c/devtools/page-frame.html
|
success(request) {
|
uni.stopPullDownRefresh()
|
if (request.data.status == 10 || request.data.status == 11) {
|
uni.setStorageSync('token', '')
|
let token = uni.getStorageSync('token')
|
if (validator.checkEmpty(token)) {
|
refLogin(url, options).then(res => {
|
if (res) {
|
resolve(res)
|
} else {
|
resolve({
|
tokenStatus: false,
|
status: 1
|
})
|
}
|
})
|
}
|
} else {
|
if (request.statusCode === 200 || request.data.status) {
|
resolve(request.data)
|
} else {
|
reject(request.data)
|
}
|
}
|
uni.hideNavigationBarLoading()
|
},
|
fail(error) {
|
console.log('---------网络连接错误------------')
|
uni.showToast({
|
icon: 'none',
|
title: '网络连接错误'
|
})
|
uni.hideNavigationBarLoading()
|
reject({
|
status: 1,
|
data: error.data
|
})
|
},
|
})
|
}).catch(function (reason) {
|
console.log('---------网络调用错误------------' + reason)
|
uni.showToast({
|
icon: 'none',
|
title: '网络调用错误'
|
})
|
uni.redirectTo({
|
url: '/pages/common/code_error/index?code=10002',
|
})
|
uni.hideNavigationBarLoading()
|
});
|
}
|
|
export const get = (url, options = {}) => {
|
return request(url, {
|
method: 'GET',
|
data: options,
|
header: 'application/json; charset=UTF-8'
|
})
|
}
|
|
export const post = (url, options) => {
|
return request(url, {
|
method: 'POST',
|
data: options,
|
header: 'application/json; charset=UTF-8'
|
})
|
}
|
|
export const put = (url, options) => {
|
return request(url, {
|
method: 'PUT',
|
data: options,
|
header: 'application/json; charset=UTF-8'
|
})
|
}
|
|
export const postF = (url, options) => {
|
return request(url, {
|
method: 'POST',
|
data: options,
|
header: 'application/x-www-form-urlencoded'
|
})
|
}
|
|
export const putF = (url, options) => {
|
return request(url, {
|
method: 'PUT',
|
data: options,
|
header: 'application/x-www-form-urlencoded'
|
})
|
}
|
|
export const remove = (url, options) => {
|
return request(url, {
|
method: 'DELETE',
|
data: options,
|
header: 'application/json; charset=UTF-8'
|
})
|
}
|