12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- var app=getApp();
- function request(url, method,header, data, success) {
- let promise = new Promise(function(resolve, reject) {
- wx.request({
- url,
- header,
- data,
- method,
- success: res => {
- if (typeof res.data === "object") {
- if(!!res.header.Authorization){
- app.globalData.token=res.header.Authorization.split(" ")[1];
- }
- if(!!res.data.token){
- app.globalData.token=res.data.token;
- }
- if (res.data.code === 403) {
- wx.reLaunch({
- url: '/pages/index/index',
- })
- reject(res.data.msg);
-
- }else if(res.data.code === 601){
- wx.reLaunch({
- url: '/pages/other/other?type=32',
- })
- reject(res.data.msg);
- }else if(res.data.code != 0&&!data.alertshow&&res.data.code!=undefined) {
- wx.showToast({
- title: res.data.msg,
- icon: "none",
- duration: 2000
- });
- reject(res.data.msg);
- }
- }
- success(res)
- },
- fail: res => {
- reject(res)
- },
- complete: res => {
- // wx.hideLoading()
-
- }
- })
- })
- return promise
- }
- let fn = function() {}
- module.exports = {
- $get: function({
- url,
- header,
- data = {},
- success = fn
- }) {
- data.client_type = app.globalData.clientype;
- data.client="wxd621d357ca76c526";
- return request(url, 'GET',header, data, success)
- },
- $post: function({
- url,
- header,
- data = {},
- success = fn
- }) {
- data.client_type = app.globalData.clientype;
- data.client="wxd621d357ca76c526";
- return request(url, 'POST',header, data, success)
- }
- }
|