12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- var app = getApp();
- var requestnum = 0;
- const addnum = function(){
- if (requestnum==0){
- wx.showLoading({
- title:"加载中...",
- // mask:true
- })
- }
- requestnum++;
- }
- const reducenum = function(){
- requestnum--;
- if (requestnum==0){
- wx.hideLoading();
- }
- }
- export const get=(url,data,callback,failback)=>{
- addnum();
- var authorization = wx.getStorageSync("authorization");
- wx.request({
- url: app.globalData.serverpath+url,
- method: "GET",
- header: {
- "Content-Type": "json",
- "Authorization":authorization
- },
- data:data,
- success: function (res){
- console.debug(res);
- callback && callback(res);
- },
- fail: function (error){
- failback && failback(error);
- },
- complete: function () {
- reducenum();
- }
- })
- }
- export const post=(url,data,header,callback,failback,noauth)=>{
- var authorization = wx.getStorageSync("authorization")
- if(typeof header=="function"){
- noauth = failback;
- failback = callback;
- callback = header;
- header = {};
- }
- if(authorization){
- addnum();
- wx.request({
- url: app.globalData.serverpath+url,
- method: "POST",
- header: Object.assign({
- "Content-Type": "application/json",
- "Authorization":authorization,
- "Accept": "application/vnd.vpgame.v1+json"
- },header),
- data:data,
- success: function (res){
- //console.debug(res);
- callback && callback(res);
- },
- fail: function (error){
- failback && failback(error);
- },
- complete: function () {
- reducenum();
- }
- })
- }else{
- if(typeof noauth=="function"){
- noauth();
- }
- }
- }
|