"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const g=require("vue"),D=require("axios"),h="STARTLOADING",p="ENDLOADING",P={namespaced:!0,state:()=>({loadingStatus:{}}),mutations:{[h](e,t){const{fwbm:n}=t;g.set(e.loadingStatus,n,!0)},[p](e,t){const{fwbm:n}=t;g.set(e.loadingStatus,n,!1)}},actions:{startLoading(e,t){e.commit(h,t||[])},endLoading(e,t){e.commit(p,t||[])}}},r={axiosConfig:{timeout:60*1e3,withCredentials:!0},showRequestErr(e){if(this.vue)return this.vue.$message.error(e);console.error("Vue instance not available:",e)},logoutHandle(){this.vue&&this.vue.$store?this.vue.$store.dispatch("logout"):console.warn("Logout handler called but Vue instance or store not available")},install(e,{axiosConfig:t}){this.vue=e,this.axiosConfig={...this.axiosConfig,...t},e.prototype.$request=u}},d=D.create(r.axiosConfig);d.interceptors.request.use(e=>{const t=e,{url:n}=t;if(n.indexOf("?")!==-1?t.url=`${n}&t=${new Date().getTime()}`:t.url=`${n}?t=${new Date().getTime()}`,t.method==="get"&&t.params){let o=`${t.url}&`;for(const a of Object.keys(t.params)){const s=t.params[a],c=`${encodeURIComponent(a)}=`;if(s!==null&&typeof s<"u")if(typeof s=="object")for(const f of Object.keys(s)){const q=`${a}[${f}]`,y=`${encodeURIComponent(q)}=`;o+=`${y}${encodeURIComponent(s[f])}&`}else o+=`${c}${encodeURIComponent(s)}&`}o=o.slice(0,-1),t.params={},t.url=o}return t},e=>(console.log("====>> req err",e),Promise.reject(e)));d.interceptors.response.use(async e=>{const{code:t}=e.data;return t===401?S():t!==1&&t!==0?(e.config.noTips!==!0&&e.data.msg&&r.showRequestErr(e.data.msg),Promise.reject(t)):e.data},e=>{if(e.config.noTips!==!0){let{message:t}=e;t==="Network Error"?t="后端接口连接异常":t.includes("timeout")?t="系统接口请求超时":t.includes("Request failed with status code")&&(t=`系统接口${t.substr(t.length-3)}异常`),r.showRequestErr(t)}return Promise.reject(e)});function S(){return r.showRequestErr("无效的会话,或者会话已过期,请重新登录。").then(()=>{r.logoutHandle()}),Promise.reject("无效的会话,或者会话已过期,请重新登录。")}const l=(e,t)=>d({...e},t),i={store:null,setStore(e){this.store=e},getStore(){return this.store},dispatch(e,t){this.store&&this.store.dispatch(e,t)}},m=(e,t)=>e.then(n=>{console.log("请求返回",n);const o=[null,n];return t&&t(o),o}).catch(n=>{console.error("请求出错",n);const o=[n,null];return t&&t(o),o}),u={async post(e,t,n,o){const a=`${e}/${t}`,s=JSON.stringify(n)||"{}";await i.dispatch("LoadingManager/startLoading",{fwbm:t}),console.log("发起请求",a,"data:",s);const c=l({...o,url:a,data:s,method:"post",headers:{"Content-Type":"application/json"}},o);return m(c,()=>{i.dispatch("LoadingManager/endLoading",{fwbm:t})})},async get(e,t,n,o){const a=`${e}/${t}`;await i.dispatch("LoadingManager/startLoading",{fwbm:t});const s=l({...o,url:a,params:n,method:"get",headers:{"Content-Type":"application/json"}});return m(s,()=>{i.dispatch("LoadingManager/endLoading",{fwbm:t})})},async _fetch(e,t){return console.log("发起请求:",e.method,",",e.url,",data:",e.params),l(e,t)}},C={install(e,{store:t}){i.setStore(t),t.registerModule("LoadingManager",P)}},j="/config",T={async getDefaultConfig(){const[,e]=await u.get(j,"config.json",null,{noTips:!0});return e?e.data||{}:{}}},$="LOAD_CONFIG",w={namespaced:!0,state:()=>({}),mutations:{[$](e,t){Object.entries(t).forEach(([n,o])=>{g.set(e,n,o)})}},actions:{loadConfig(e,t){e.commit($,typeof t=="object"?t:{})}}},O={install(e,{store:t,extSettings:n}){t.registerModule("settings",w),T.getDefaultConfig().then(o=>{const a={...n,...o};t.dispatch("settings/loadConfig",a)})}},R={request:u},L={RequestPlugin:r,LoadingManagerPlugin:C,ExtSettingsPlugin:O},v={install:function(e,t){Object.values(L).forEach(n=>{e.use(n,t)})},...R,...L};exports.ExtSettingsPlugin=O;exports.LoadingManagerPlugin=C;exports.RequestPlugin=r;exports.default=v;exports.request=u;