You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2 lines
739 B

"use strict";const e=require("../common/vendor.js"),t=require("../config/env.js"),s=require("../constants/storage.js");function n(n,o,r,a={}){return new Promise((c,i)=>{const u=e.index.getStorageSync(s.STORAGE_KEYS.accessToken),d={"Content-Type":"application/json",...a.header};!1!==a.withAuth&&u&&(d.Authorization=`Bearer ${u}`),e.index.request({...a,url:`${t.APP_CONFIG.apiBaseUrl}${o}`,method:n,data:r,header:d,success:t=>{const n=t.statusCode||0;n>=200&&n<300?c(t.data):(401===n&&e.index.removeStorageSync(s.STORAGE_KEYS.accessToken),i(t.data||{message:"请求失败"}))},fail:e=>i(e)})})}const o={get:(e,t,s)=>n("GET",e,t,s),post:(e,t,s)=>n("POST",e,t,s),put:(e,t,s)=>n("PUT",e,t,s),delete:(e,t,s)=>n("DELETE",e,t,s)};exports.http=o;