"use strict";const common_vendor=require("../common/vendor.js");const config=require("../config.js");require("../uni_modules/uview-plus/index.js");const uni_modules_uviewPlus_libs_function_index=require("../uni_modules/uview-plus/libs/function/index.js");const http=(url,params,method)=>new Promise(((resolve,reject)=>{let Authorization=common_vendor.index.getStorageSync("token")||"";let version=common_vendor.index.getStorageSync("version")||common_vendor.index.getSystemInfoSync();if(!common_vendor.index.getStorageSync("version"))common_vendor.index.setStorageSync("version",version);let{deviceId:deviceId,deviceBrand:deviceBrand,deviceModel:deviceModel,osVersion:osVersion}=version;let header={deviceId:deviceId,deviceBrand:deviceBrand,deviceModel:deviceModel,osVersion:osVersion,platform:1,Authorization:Authorization};common_vendor.index.request({url:config.config.baseUrl+url,data:params||{},method:method||"POST",header:header,success:res=>{if(res.statusCode==401){common_vendor.index.hideLoading();common_vendor.index.showModal({title:"提示",content:"为提供更好的服务，请前往登录",success:res2=>{if(res2.confirm){common_vendor.index.navigateTo({url:"/pages/login/login"})}else if(res2.cancel){console.log("用户点击取消")}}});return}const data=res.data;if(data.code==10&&!data.success){reject(data);return}if(data.code!==1&&!data.success){uni_modules_uviewPlus_libs_function_index.toast(data.msg);reject(data);return}resolve(data.data||null)},fail:err=>{if(err.statusCode==401){common_vendor.index.hideLoading();common_vendor.index.showModal({title:"提示",content:"为提供更好的服务，请前往登录",success:res=>{if(res.confirm){common_vendor.index.navigateTo({url:"/pages/login/login"})}else if(res.cancel){console.log("用户点击取消")}}});return}const data=err.data;if(data.code!==1&&!data.success){uni_modules_uviewPlus_libs_function_index.toast(data.msg);reject(data);return}common_vendor.index.hideLoading();reject(err)}})}));exports.http=http;
