1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- // 本地环境
- // const $perfix = 'http://localhost:8090';
- // const $perfix = 'http://10.0.0.153:8099';
- // const $perfix = 'http://114.135.61.188:33334';
- const $perfix = 'https://pension.zoniot.com';
- // 测试环境
- // const $perfix = 'http://114.135.61.188:58082';
- // 演示环境
- // const $perfix = 'https://water.zoniot.com';
- // 正式环境
- // const $perfix = 'https://water.zoniot.com';
- const toLogin = (status = 0) => {
- if (status !== -406) return;
- wx.removeStorageSync('token');
- getApp().token = '';
- };
- const httpFun = (url, data, type, isForm) => {
-
- let token = getApp().token || wx.getStorageSync('token');
- return new Promise(resolve => {
- const filterUrl = [
- '/user/openidLogin',
- ];
- if (token && filterUrl.indexOf(url) == -1) {
- token = 'Bearer ' + token;
- } else {
- token = null;
- }
- wx.request({
- url: `${$perfix}/api${url}`,
- data: data,
- method: type,
- header: {
- [token && "Authorization"]: token,
- [isForm && "Content-Type"]: "application/x-www-form-urlencoded"
- },
- complete(res) {
- if (res.statusCode === 200) {
- toLogin(res.data.status);
- resolve(res.data);
- } else if (res.statusCode >= 500 && res.statusCode < 520) {
- wx.hideLoading();
- wx.showModal({
- title: '提示',
- content: '网络或服务异常,点击“确定”返回当前页',
- showCancel: false,
- success(res) {
- getApp().globalData = {};
- getApp().getUserInfo(getApp().token);
- }
- })
- resolve(res);
- return;
- } else {
- // wx.showToast({
- // title: res.statusCode + '',
- // icon: 'none'
- // })
- resolve(res);
- }
- }
- })
- })
- }
- module.exports = {
- domain: $perfix,
- postForm(url, data) {
- return httpFun(url, data, 'post', true);
- },
- post(url, data) {
- return httpFun(url, data, 'post', false);
- },
- deleteForm(url, data) {
- return httpFun(url, data, 'delete', true);
- },
- get(url, data) {
- return httpFun(url, data, 'get', false);
- }
- }
|