"use strict";const e=require("../common/vendor.js");let o="";o="https://api.valuefrontier.cn:5002",exports.get=function(n,i){return new Promise(((t,a)=>{let r=e.index.getStorageSync("token");e.index.showLoading({title:"加载中"});let d=o;(n.indexOf("concept-api")>-1||n.indexOf("news-api")>-1||n.indexOf("report-api")>-1)&&(d="https://api.valuefrontier.cn"),e.index.request({url:d+n,data:i,header:{Accept:"application/json","Content-Type":"application/x-www-form-urlencoded",Authorization:r?"Bearer "+r:""},method:"GET",success:o=>{console.log(o),e.index.hideLoading(),401==o.data.code?(e.index.removeStorageSync("token"),e.index.navigateTo({url:"/pages/login/login"})):t(o.data)},fail:o=>{e.index.hideLoading(),e.index.showToast({title:"请求失败",icon:"error"}),a(o.response)}})}))},exports.post=function(n,i){return new Promise(((t,a)=>{let r=e.index.getStorageSync("token"),d=0,s=0;if(i&&(d=i.isJson),i&&(s=i.isFile),e.index.showLoading({title:"加载中"}),s){let r=e.index.getStorageSync("token");e.index.uploadFile({url:o+n,filePath:i.avatar,name:"avatar",header:{Authorization:r?"Bearer "+r:""},formData:i,success:o=>{console.log(o),e.index.hideLoading(),401==o.data.code?(e.index.removeStorageSync("token"),e.index.navigateTo({url:"/pages/login/login"}),a(o.data)):t(o.data)},fail:o=>{console.log("上传失败"+o.errMsg),e.index.hideLoading(),e.index.showToast({title:"请求失败",icon:"error"}),a()}})}else{let l=o;n.indexOf("concept-api")>-1&&(l="https://api.valuefrontier.cn"),e.index.request({url:l+n,data:i,header:{Accept:"application/json","Content-Type":d?"application/json":s?"multipart/form-data":"application/x-www-form-urlencoded",Authorization:r?"Bearer "+r:""},method:"POST",success:o=>{e.index.hideLoading(),i&&i.isNotNeedLogin||(console.log(o.data),401==o.data.code?(e.index.removeStorageSync("token"),e.index.navigateTo({url:"/pages/login/login"}),a(o.data)):t(o.data))},fail:o=>{e.index.hideLoading(),e.index.showToast({title:"请求失败",icon:"error"}),a(o.response)}})}}))};
