kaoqin-services
Version:
考勤系统服务库 (重构版 - 支持n8n webhook)
1 lines • 979 B
JavaScript
;const axios=require("axios");class ApiService{constructor(a){this.configManager=a,this.axios=axios.create({baseURL:a.get("API_BASE_URL")||"https://appsy.jbysoft.com",headers:{"Content-Type":"application/json"},proxy:!1}),this.setupInterceptors()}setupInterceptors(){this.axios.interceptors.request.use(a=>(global.loginToken&&(a.headers["login-token"]=global.loginToken),a),a=>Promise.reject(a)),this.axios.interceptors.response.use(a=>a.data,a=>(console.error("API\u8BF7\u6C42\u9519\u8BEF:",a.message),Promise.reject(a)))}async request(a,b,c={}){try{const d={url:a,method:c.method||"POST",headers:c.headers||{}};c.params&&(d.params=c.params),"GET"!==d.method&&b&&(d.data=b);const e=await this.axios(d);return e}catch(a){throw console.error("Request Error:",a.response?.data||a.message),a}}async get(a,b={},c={}){return this.request(a,null,{...c,method:"GET",params:b})}async post(a,b={},c={}){return this.request(a,b,{...c,method:"POST"})}}module.exports=ApiService;