json-api-mocker 2.0.4 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +1 -3
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/package.json +1 -1
- package/web/assets/{index-BP5BNwqW.js → index-DWg8IDX3.js} +1 -1
- package/web/index.html +1 -1
package/dist/cli.js
CHANGED
@@ -15,14 +15,12 @@ const WS_PORT = 35730; // WebSocket 端口
|
|
15
15
|
commander_1.program
|
16
16
|
.version(require('../package.json').version)
|
17
17
|
.option('-c, --config <path>', '配置文件路径', 'data.json')
|
18
|
-
.option('-p, --port <number>', '服务器端口', '8080')
|
19
18
|
.option('-o, --open', '自动打开浏览器', false)
|
20
19
|
.parse(process.argv);
|
21
20
|
const options = commander_1.program.opts();
|
22
|
-
// 启动 API Mock
|
21
|
+
// 启动 API Mock 服务器,不再传入端口参数,使用配置文件中的端口
|
23
22
|
(0, index_1.startServer)({
|
24
23
|
config: options.config,
|
25
|
-
port: parseInt(options.port),
|
26
24
|
wsPort: WS_PORT
|
27
25
|
});
|
28
26
|
// 创建静态文件服务器来托管前端页面
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
@@ -29,7 +29,6 @@ function startServer(options = {}) {
|
|
29
29
|
const config = JSON.parse(configContent);
|
30
30
|
const serverConfig = {
|
31
31
|
...config.server,
|
32
|
-
port: options.port || config.server.port || 3000,
|
33
32
|
wsPort: options.wsPort
|
34
33
|
};
|
35
34
|
const server = new server_1.MockServer(serverConfig, configPath);
|
package/package.json
CHANGED
@@ -22,4 +22,4 @@
|
|
22
22
|
* vue-router v4.5.0
|
23
23
|
* (c) 2024 Eduardo San Martin Morote
|
24
24
|
* @license MIT
|
25
|
-
*/const kt=typeof document<"u";function vi(e){return typeof e=="object"||"displayName"in e||"props"in e||"__vccOpts"in e}function ru(e){return e.__esModule||e[Symbol.toStringTag]==="Module"||e.default&&vi(e.default)}const X=Object.assign;function ps(e,t){const n={};for(const s in t){const r=t[s];n[s]=Ue(r)?r.map(e):e(r)}return n}const ln=()=>{},Ue=Array.isArray,_i=/#/g,ou=/&/g,iu=/\//g,lu=/=/g,cu=/\?/g,yi=/\+/g,uu=/%5B/g,au=/%5D/g,bi=/%5E/g,fu=/%60/g,xi=/%7B/g,du=/%7C/g,Si=/%7D/g,hu=/%20/g;function er(e){return encodeURI(""+e).replace(du,"|").replace(uu,"[").replace(au,"]")}function pu(e){return er(e).replace(xi,"{").replace(Si,"}").replace(bi,"^")}function Ts(e){return er(e).replace(yi,"%2B").replace(hu,"+").replace(_i,"%23").replace(ou,"%26").replace(fu,"`").replace(xi,"{").replace(Si,"}").replace(bi,"^")}function gu(e){return Ts(e).replace(lu,"%3D")}function mu(e){return er(e).replace(_i,"%23").replace(cu,"%3F")}function vu(e){return e==null?"":mu(e).replace(iu,"%2F")}function mn(e){try{return decodeURIComponent(""+e)}catch{}return""+e}const _u=/\/$/,yu=e=>e.replace(_u,"");function gs(e,t,n="/"){let s,r={},o="",i="";const l=t.indexOf("#");let c=t.indexOf("?");return l<c&&l>=0&&(c=-1),c>-1&&(s=t.slice(0,c),o=t.slice(c+1,l>-1?l:t.length),r=e(o)),l>-1&&(s=s||t.slice(0,l),i=t.slice(l,t.length)),s=wu(s??t,n),{fullPath:s+(o&&"?")+o+i,path:s,query:r,hash:mn(i)}}function bu(e,t){const n=t.query?e(t.query):"";return t.path+(n&&"?")+n+(t.hash||"")}function Vr(e,t){return!t||!e.toLowerCase().startsWith(t.toLowerCase())?e:e.slice(t.length)||"/"}function xu(e,t,n){const s=t.matched.length-1,r=n.matched.length-1;return s>-1&&s===r&&Ut(t.matched[s],n.matched[r])&&wi(t.params,n.params)&&e(t.query)===e(n.query)&&t.hash===n.hash}function Ut(e,t){return(e.aliasOf||e)===(t.aliasOf||t)}function wi(e,t){if(Object.keys(e).length!==Object.keys(t).length)return!1;for(const n in e)if(!Su(e[n],t[n]))return!1;return!0}function Su(e,t){return Ue(e)?Ur(e,t):Ue(t)?Ur(t,e):e===t}function Ur(e,t){return Ue(t)?e.length===t.length&&e.every((n,s)=>n===t[s]):e.length===1&&e[0]===t}function wu(e,t){if(e.startsWith("/"))return e;if(!e)return t;const n=t.split("/"),s=e.split("/"),r=s[s.length-1];(r===".."||r===".")&&s.push("");let o=n.length-1,i,l;for(i=0;i<s.length;i++)if(l=s[i],l!==".")if(l==="..")o>1&&o--;else break;return n.slice(0,o).join("/")+"/"+s.slice(i).join("/")}const ct={path:"/",name:void 0,params:{},query:{},hash:"",fullPath:"/",matched:[],meta:{},redirectedFrom:void 0};var vn;(function(e){e.pop="pop",e.push="push"})(vn||(vn={}));var cn;(function(e){e.back="back",e.forward="forward",e.unknown=""})(cn||(cn={}));function Eu(e){if(!e)if(kt){const t=document.querySelector("base");e=t&&t.getAttribute("href")||"/",e=e.replace(/^\w+:\/\/[^\/]+/,"")}else e="/";return e[0]!=="/"&&e[0]!=="#"&&(e="/"+e),yu(e)}const Cu=/^[^#]+#/;function Ru(e,t){return e.replace(Cu,"#")+t}function Pu(e,t){const n=document.documentElement.getBoundingClientRect(),s=e.getBoundingClientRect();return{behavior:t.behavior,left:s.left-n.left-(t.left||0),top:s.top-n.top-(t.top||0)}}const Zn=()=>({left:window.scrollX,top:window.scrollY});function Au(e){let t;if("el"in e){const n=e.el,s=typeof n=="string"&&n.startsWith("#"),r=typeof n=="string"?s?document.getElementById(n.slice(1)):document.querySelector(n):n;if(!r)return;t=Pu(r,e)}else t=e;"scrollBehavior"in document.documentElement.style?window.scrollTo(t):window.scrollTo(t.left!=null?t.left:window.scrollX,t.top!=null?t.top:window.scrollY)}function Br(e,t){return(history.state?history.state.position-t:-1)+e}const Is=new Map;function Ou(e,t){Is.set(e,t)}function Tu(e){const t=Is.get(e);return Is.delete(e),t}let Iu=()=>location.protocol+"//"+location.host;function Ei(e,t){const{pathname:n,search:s,hash:r}=t,o=e.indexOf("#");if(o>-1){let l=r.includes(e.slice(o))?e.slice(o).length:1,c=r.slice(l);return c[0]!=="/"&&(c="/"+c),Vr(c,"")}return Vr(n,e)+s+r}function $u(e,t,n,s){let r=[],o=[],i=null;const l=({state:p})=>{const g=Ei(e,location),R=n.value,E=t.value;let A=0;if(p){if(n.value=g,t.value=p,i&&i===R){i=null;return}A=E?p.position-E.position:0}else s(g);r.forEach(M=>{M(n.value,R,{delta:A,type:vn.pop,direction:A?A>0?cn.forward:cn.back:cn.unknown})})};function c(){i=n.value}function d(p){r.push(p);const g=()=>{const R=r.indexOf(p);R>-1&&r.splice(R,1)};return o.push(g),g}function a(){const{history:p}=window;p.state&&p.replaceState(X({},p.state,{scroll:Zn()}),"")}function h(){for(const p of o)p();o=[],window.removeEventListener("popstate",l),window.removeEventListener("beforeunload",a)}return window.addEventListener("popstate",l),window.addEventListener("beforeunload",a,{passive:!0}),{pauseListeners:c,listen:d,destroy:h}}function Kr(e,t,n,s=!1,r=!1){return{back:e,current:t,forward:n,replaced:s,position:window.history.length,scroll:r?Zn():null}}function Mu(e){const{history:t,location:n}=window,s={value:Ei(e,n)},r={value:t.state};r.value||o(s.value,{back:null,current:s.value,forward:null,position:t.length-1,replaced:!0,scroll:null},!0);function o(c,d,a){const h=e.indexOf("#"),p=h>-1?(n.host&&document.querySelector("base")?e:e.slice(h))+c:Iu()+e+c;try{t[a?"replaceState":"pushState"](d,"",p),r.value=d}catch(g){console.error(g),n[a?"replace":"assign"](p)}}function i(c,d){const a=X({},t.state,Kr(r.value.back,c,r.value.forward,!0),d,{position:r.value.position});o(c,a,!0),s.value=c}function l(c,d){const a=X({},r.value,t.state,{forward:c,scroll:Zn()});o(a.current,a,!0);const h=X({},Kr(s.value,c,null),{position:a.position+1},d);o(c,h,!1),s.value=c}return{location:s,state:r,push:l,replace:i}}function ju(e){e=Eu(e);const t=Mu(e),n=$u(e,t.state,t.location,t.replace);function s(o,i=!0){i||n.pauseListeners(),history.go(o)}const r=X({location:"",base:e,go:s,createHref:Ru.bind(null,e)},t,n);return Object.defineProperty(r,"location",{enumerable:!0,get:()=>t.location.value}),Object.defineProperty(r,"state",{enumerable:!0,get:()=>t.state.value}),r}function ku(e){return typeof e=="string"||e&&typeof e=="object"}function Ci(e){return typeof e=="string"||typeof e=="symbol"}const Ri=Symbol("");var Wr;(function(e){e[e.aborted=4]="aborted",e[e.cancelled=8]="cancelled",e[e.duplicated=16]="duplicated"})(Wr||(Wr={}));function Bt(e,t){return X(new Error,{type:e,[Ri]:!0},t)}function tt(e,t){return e instanceof Error&&Ri in e&&(t==null||!!(e.type&t))}const qr="[^/]+?",Nu={sensitive:!1,strict:!1,start:!0,end:!0},Fu=/[.+*?^${}()[\]/\\]/g;function Lu(e,t){const n=X({},Nu,t),s=[];let r=n.start?"^":"";const o=[];for(const d of e){const a=d.length?[]:[90];n.strict&&!d.length&&(r+="/");for(let h=0;h<d.length;h++){const p=d[h];let g=40+(n.sensitive?.25:0);if(p.type===0)h||(r+="/"),r+=p.value.replace(Fu,"\\$&"),g+=40;else if(p.type===1){const{value:R,repeatable:E,optional:A,regexp:M}=p;o.push({name:R,repeatable:E,optional:A});const F=M||qr;if(F!==qr){g+=10;try{new RegExp(`(${F})`)}catch(N){throw new Error(`Invalid custom RegExp for param "${R}" (${F}): `+N.message)}}let D=E?`((?:${F})(?:/(?:${F}))*)`:`(${F})`;h||(D=A&&d.length<2?`(?:/${D})`:"/"+D),A&&(D+="?"),r+=D,g+=20,A&&(g+=-8),E&&(g+=-20),F===".*"&&(g+=-50)}a.push(g)}s.push(a)}if(n.strict&&n.end){const d=s.length-1;s[d][s[d].length-1]+=.7000000000000001}n.strict||(r+="/?"),n.end?r+="$":n.strict&&!r.endsWith("/")&&(r+="(?:/|$)");const i=new RegExp(r,n.sensitive?"":"i");function l(d){const a=d.match(i),h={};if(!a)return null;for(let p=1;p<a.length;p++){const g=a[p]||"",R=o[p-1];h[R.name]=g&&R.repeatable?g.split("/"):g}return h}function c(d){let a="",h=!1;for(const p of e){(!h||!a.endsWith("/"))&&(a+="/"),h=!1;for(const g of p)if(g.type===0)a+=g.value;else if(g.type===1){const{value:R,repeatable:E,optional:A}=g,M=R in d?d[R]:"";if(Ue(M)&&!E)throw new Error(`Provided param "${R}" is an array but it is not repeatable (* or + modifiers)`);const F=Ue(M)?M.join("/"):M;if(!F)if(A)p.length<2&&(a.endsWith("/")?a=a.slice(0,-1):h=!0);else throw new Error(`Missing required param "${R}"`);a+=F}}return a||"/"}return{re:i,score:s,keys:o,parse:l,stringify:c}}function Du(e,t){let n=0;for(;n<e.length&&n<t.length;){const s=t[n]-e[n];if(s)return s;n++}return e.length<t.length?e.length===1&&e[0]===80?-1:1:e.length>t.length?t.length===1&&t[0]===80?1:-1:0}function Pi(e,t){let n=0;const s=e.score,r=t.score;for(;n<s.length&&n<r.length;){const o=Du(s[n],r[n]);if(o)return o;n++}if(Math.abs(r.length-s.length)===1){if(Gr(s))return 1;if(Gr(r))return-1}return r.length-s.length}function Gr(e){const t=e[e.length-1];return e.length>0&&t[t.length-1]<0}const Hu={type:0,value:""},Vu=/[a-zA-Z0-9_]/;function Uu(e){if(!e)return[[]];if(e==="/")return[[Hu]];if(!e.startsWith("/"))throw new Error(`Invalid path "${e}"`);function t(g){throw new Error(`ERR (${n})/"${d}": ${g}`)}let n=0,s=n;const r=[];let o;function i(){o&&r.push(o),o=[]}let l=0,c,d="",a="";function h(){d&&(n===0?o.push({type:0,value:d}):n===1||n===2||n===3?(o.length>1&&(c==="*"||c==="+")&&t(`A repeatable param (${d}) must be alone in its segment. eg: '/:ids+.`),o.push({type:1,value:d,regexp:a,repeatable:c==="*"||c==="+",optional:c==="*"||c==="?"})):t("Invalid state to consume buffer"),d="")}function p(){d+=c}for(;l<e.length;){if(c=e[l++],c==="\\"&&n!==2){s=n,n=4;continue}switch(n){case 0:c==="/"?(d&&h(),i()):c===":"?(h(),n=1):p();break;case 4:p(),n=s;break;case 1:c==="("?n=2:Vu.test(c)?p():(h(),n=0,c!=="*"&&c!=="?"&&c!=="+"&&l--);break;case 2:c===")"?a[a.length-1]=="\\"?a=a.slice(0,-1)+c:n=3:a+=c;break;case 3:h(),n=0,c!=="*"&&c!=="?"&&c!=="+"&&l--,a="";break;default:t("Unknown state");break}}return n===2&&t(`Unfinished custom RegExp for param "${d}"`),h(),i(),r}function Bu(e,t,n){const s=Lu(Uu(e.path),n),r=X(s,{record:e,parent:t,children:[],alias:[]});return t&&!r.record.aliasOf==!t.record.aliasOf&&t.children.push(r),r}function Ku(e,t){const n=[],s=new Map;t=Yr({strict:!1,end:!0,sensitive:!1},t);function r(h){return s.get(h)}function o(h,p,g){const R=!g,E=Jr(h);E.aliasOf=g&&g.record;const A=Yr(t,h),M=[E];if("alias"in h){const N=typeof h.alias=="string"?[h.alias]:h.alias;for(const q of N)M.push(Jr(X({},E,{components:g?g.record.components:E.components,path:q,aliasOf:g?g.record:E})))}let F,D;for(const N of M){const{path:q}=N;if(p&&q[0]!=="/"){const pe=p.record.path,z=pe[pe.length-1]==="/"?"":"/";N.path=p.record.path+(q&&z+q)}if(F=Bu(N,p,A),g?g.alias.push(F):(D=D||F,D!==F&&D.alias.push(F),R&&h.name&&!Qr(F)&&i(h.name)),Ai(F)&&c(F),E.children){const pe=E.children;for(let z=0;z<pe.length;z++)o(pe[z],F,g&&g.children[z])}g=g||F}return D?()=>{i(D)}:ln}function i(h){if(Ci(h)){const p=s.get(h);p&&(s.delete(h),n.splice(n.indexOf(p),1),p.children.forEach(i),p.alias.forEach(i))}else{const p=n.indexOf(h);p>-1&&(n.splice(p,1),h.record.name&&s.delete(h.record.name),h.children.forEach(i),h.alias.forEach(i))}}function l(){return n}function c(h){const p=Gu(h,n);n.splice(p,0,h),h.record.name&&!Qr(h)&&s.set(h.record.name,h)}function d(h,p){let g,R={},E,A;if("name"in h&&h.name){if(g=s.get(h.name),!g)throw Bt(1,{location:h});A=g.record.name,R=X(zr(p.params,g.keys.filter(D=>!D.optional).concat(g.parent?g.parent.keys.filter(D=>D.optional):[]).map(D=>D.name)),h.params&&zr(h.params,g.keys.map(D=>D.name))),E=g.stringify(R)}else if(h.path!=null)E=h.path,g=n.find(D=>D.re.test(E)),g&&(R=g.parse(E),A=g.record.name);else{if(g=p.name?s.get(p.name):n.find(D=>D.re.test(p.path)),!g)throw Bt(1,{location:h,currentLocation:p});A=g.record.name,R=X({},p.params,h.params),E=g.stringify(R)}const M=[];let F=g;for(;F;)M.unshift(F.record),F=F.parent;return{name:A,path:E,params:R,matched:M,meta:qu(M)}}e.forEach(h=>o(h));function a(){n.length=0,s.clear()}return{addRoute:o,resolve:d,removeRoute:i,clearRoutes:a,getRoutes:l,getRecordMatcher:r}}function zr(e,t){const n={};for(const s of t)s in e&&(n[s]=e[s]);return n}function Jr(e){const t={path:e.path,redirect:e.redirect,name:e.name,meta:e.meta||{},aliasOf:e.aliasOf,beforeEnter:e.beforeEnter,props:Wu(e),children:e.children||[],instances:{},leaveGuards:new Set,updateGuards:new Set,enterCallbacks:{},components:"components"in e?e.components||null:e.component&&{default:e.component}};return Object.defineProperty(t,"mods",{value:{}}),t}function Wu(e){const t={},n=e.props||!1;if("component"in e)t.default=n;else for(const s in e.components)t[s]=typeof n=="object"?n[s]:n;return t}function Qr(e){for(;e;){if(e.record.aliasOf)return!0;e=e.parent}return!1}function qu(e){return e.reduce((t,n)=>X(t,n.meta),{})}function Yr(e,t){const n={};for(const s in e)n[s]=s in t?t[s]:e[s];return n}function Gu(e,t){let n=0,s=t.length;for(;n!==s;){const o=n+s>>1;Pi(e,t[o])<0?s=o:n=o+1}const r=zu(e);return r&&(s=t.lastIndexOf(r,s-1)),s}function zu(e){let t=e;for(;t=t.parent;)if(Ai(t)&&Pi(e,t)===0)return t}function Ai({record:e}){return!!(e.name||e.components&&Object.keys(e.components).length||e.redirect)}function Ju(e){const t={};if(e===""||e==="?")return t;const s=(e[0]==="?"?e.slice(1):e).split("&");for(let r=0;r<s.length;++r){const o=s[r].replace(yi," "),i=o.indexOf("="),l=mn(i<0?o:o.slice(0,i)),c=i<0?null:mn(o.slice(i+1));if(l in t){let d=t[l];Ue(d)||(d=t[l]=[d]),d.push(c)}else t[l]=c}return t}function Xr(e){let t="";for(let n in e){const s=e[n];if(n=gu(n),s==null){s!==void 0&&(t+=(t.length?"&":"")+n);continue}(Ue(s)?s.map(o=>o&&Ts(o)):[s&&Ts(s)]).forEach(o=>{o!==void 0&&(t+=(t.length?"&":"")+n,o!=null&&(t+="="+o))})}return t}function Qu(e){const t={};for(const n in e){const s=e[n];s!==void 0&&(t[n]=Ue(s)?s.map(r=>r==null?null:""+r):s==null?s:""+s)}return t}const Yu=Symbol(""),Zr=Symbol(""),es=Symbol(""),tr=Symbol(""),$s=Symbol("");function Jt(){let e=[];function t(s){return e.push(s),()=>{const r=e.indexOf(s);r>-1&&e.splice(r,1)}}function n(){e=[]}return{add:t,list:()=>e.slice(),reset:n}}function dt(e,t,n,s,r,o=i=>i()){const i=s&&(s.enterCallbacks[r]=s.enterCallbacks[r]||[]);return()=>new Promise((l,c)=>{const d=p=>{p===!1?c(Bt(4,{from:n,to:t})):p instanceof Error?c(p):ku(p)?c(Bt(2,{from:t,to:p})):(i&&s.enterCallbacks[r]===i&&typeof p=="function"&&i.push(p),l())},a=o(()=>e.call(s&&s.instances[r],t,n,d));let h=Promise.resolve(a);e.length<3&&(h=h.then(d)),h.catch(p=>c(p))})}function ms(e,t,n,s,r=o=>o()){const o=[];for(const i of e)for(const l in i.components){let c=i.components[l];if(!(t!=="beforeRouteEnter"&&!i.instances[l]))if(vi(c)){const a=(c.__vccOpts||c)[t];a&&o.push(dt(a,n,s,i,l,r))}else{let d=c();o.push(()=>d.then(a=>{if(!a)throw new Error(`Couldn't resolve component "${l}" at "${i.path}"`);const h=ru(a)?a.default:a;i.mods[l]=a,i.components[l]=h;const g=(h.__vccOpts||h)[t];return g&&dt(g,n,s,i,l,r)()}))}}return o}function eo(e){const t=Le(es),n=Le(tr),s=Ne(()=>{const c=ve(e.to);return t.resolve(c)}),r=Ne(()=>{const{matched:c}=s.value,{length:d}=c,a=c[d-1],h=n.matched;if(!a||!h.length)return-1;const p=h.findIndex(Ut.bind(null,a));if(p>-1)return p;const g=to(c[d-2]);return d>1&&to(a)===g&&h[h.length-1].path!==g?h.findIndex(Ut.bind(null,c[d-2])):p}),o=Ne(()=>r.value>-1&&ta(n.params,s.value.params)),i=Ne(()=>r.value>-1&&r.value===n.matched.length-1&&wi(n.params,s.value.params));function l(c={}){if(ea(c)){const d=t[ve(e.replace)?"replace":"push"](ve(e.to)).catch(ln);return e.viewTransition&&typeof document<"u"&&"startViewTransition"in document&&document.startViewTransition(()=>d),d}return Promise.resolve()}return{route:s,href:Ne(()=>s.value.href),isActive:o,isExactActive:i,navigate:l}}function Xu(e){return e.length===1?e[0]:e}const Zu=yt({name:"RouterLink",compatConfig:{MODE:3},props:{to:{type:[String,Object],required:!0},replace:Boolean,activeClass:String,exactActiveClass:String,custom:Boolean,ariaCurrentValue:{type:String,default:"page"}},useLink:eo,setup(e,{slots:t}){const n=bn(eo(e)),{options:s}=Le(es),r=Ne(()=>({[no(e.activeClass,s.linkActiveClass,"router-link-active")]:n.isActive,[no(e.exactActiveClass,s.linkExactActiveClass,"router-link-exact-active")]:n.isExactActive}));return()=>{const o=t.default&&Xu(t.default(n));return e.custom?o:ai("a",{"aria-current":n.isExactActive?e.ariaCurrentValue:null,href:n.href,onClick:n.navigate,class:r.value},o)}}}),Ms=Zu;function ea(e){if(!(e.metaKey||e.altKey||e.ctrlKey||e.shiftKey)&&!e.defaultPrevented&&!(e.button!==void 0&&e.button!==0)){if(e.currentTarget&&e.currentTarget.getAttribute){const t=e.currentTarget.getAttribute("target");if(/\b_blank\b/i.test(t))return}return e.preventDefault&&e.preventDefault(),!0}}function ta(e,t){for(const n in t){const s=t[n],r=e[n];if(typeof s=="string"){if(s!==r)return!1}else if(!Ue(r)||r.length!==s.length||s.some((o,i)=>o!==r[i]))return!1}return!0}function to(e){return e?e.aliasOf?e.aliasOf.path:e.path:""}const no=(e,t,n)=>e??t??n,na=yt({name:"RouterView",inheritAttrs:!1,props:{name:{type:String,default:"default"},route:Object},compatConfig:{MODE:3},setup(e,{attrs:t,slots:n}){const s=Le($s),r=Ne(()=>e.route||s.value),o=Le(Zr,0),i=Ne(()=>{let d=ve(o);const{matched:a}=r.value;let h;for(;(h=a[d])&&!h.components;)d++;return d}),l=Ne(()=>r.value.matched[i.value]);On(Zr,Ne(()=>i.value+1)),On(Yu,l),On($s,r);const c=de();return nn(()=>[c.value,l.value,e.name],([d,a,h],[p,g,R])=>{a&&(a.instances[h]=d,g&&g!==a&&d&&d===p&&(a.leaveGuards.size||(a.leaveGuards=g.leaveGuards),a.updateGuards.size||(a.updateGuards=g.updateGuards))),d&&a&&(!g||!Ut(a,g)||!p)&&(a.enterCallbacks[h]||[]).forEach(E=>E(d))},{flush:"post"}),()=>{const d=r.value,a=e.name,h=l.value,p=h&&h.components[a];if(!p)return so(n.default,{Component:p,route:d});const g=h.props[a],R=g?g===!0?d.params:typeof g=="function"?g(d):g:null,A=ai(p,X({},R,t,{onVnodeUnmounted:M=>{M.component.isUnmounted&&(h.instances[a]=null)},ref:c}));return so(n.default,{Component:A,route:d})||A}}});function so(e,t){if(!e)return null;const n=e(t);return n.length===1?n[0]:n}const Oi=na;function sa(e){const t=Ku(e.routes,e),n=e.parseQuery||Ju,s=e.stringifyQuery||Xr,r=e.history,o=Jt(),i=Jt(),l=Jt(),c=ul(ct);let d=ct;kt&&e.scrollBehavior&&"scrollRestoration"in history&&(history.scrollRestoration="manual");const a=ps.bind(null,_=>""+_),h=ps.bind(null,vu),p=ps.bind(null,mn);function g(_,k){let I,L;return Ci(_)?(I=t.getRecordMatcher(_),L=k):L=_,t.addRoute(L,I)}function R(_){const k=t.getRecordMatcher(_);k&&t.removeRoute(k)}function E(){return t.getRoutes().map(_=>_.record)}function A(_){return!!t.getRecordMatcher(_)}function M(_,k){if(k=X({},k||c.value),typeof _=="string"){const f=gs(n,_,k.path),m=t.resolve({path:f.path},k),b=r.createHref(f.fullPath);return X(f,m,{params:p(m.params),hash:mn(f.hash),redirectedFrom:void 0,href:b})}let I;if(_.path!=null)I=X({},_,{path:gs(n,_.path,k.path).path});else{const f=X({},_.params);for(const m in f)f[m]==null&&delete f[m];I=X({},_,{params:h(f)}),k.params=h(k.params)}const L=t.resolve(I,k),ee=_.hash||"";L.params=a(p(L.params));const ae=bu(s,X({},_,{hash:pu(ee),path:L.path})),u=r.createHref(ae);return X({fullPath:ae,hash:ee,query:s===Xr?Qu(_.query):_.query||{}},L,{redirectedFrom:void 0,href:u})}function F(_){return typeof _=="string"?gs(n,_,c.value.path):X({},_)}function D(_,k){if(d!==_)return Bt(8,{from:k,to:_})}function N(_){return z(_)}function q(_){return N(X(F(_),{replace:!0}))}function pe(_){const k=_.matched[_.matched.length-1];if(k&&k.redirect){const{redirect:I}=k;let L=typeof I=="function"?I(_):I;return typeof L=="string"&&(L=L.includes("?")||L.includes("#")?L=F(L):{path:L},L.params={}),X({query:_.query,hash:_.hash,params:L.path!=null?{}:_.params},L)}}function z(_,k){const I=d=M(_),L=c.value,ee=_.state,ae=_.force,u=_.replace===!0,f=pe(I);if(f)return z(X(F(f),{state:typeof f=="object"?X({},ee,f.state):ee,force:ae,replace:u}),k||I);const m=I;m.redirectedFrom=k;let b;return!ae&&xu(s,L,I)&&(b=Bt(16,{to:m,from:L}),Ke(L,L,!0,!1)),(b?Promise.resolve(b):O(m,L)).catch(v=>tt(v)?tt(v,2)?v:lt(v):Y(v,m,L)).then(v=>{if(v){if(tt(v,2))return z(X({replace:u},F(v.to),{state:typeof v.to=="object"?X({},ee,v.to.state):ee,force:ae}),k||m)}else v=Q(m,L,!0,u,ee);return re(m,L,v),v})}function j(_,k){const I=D(_,k);return I?Promise.reject(I):Promise.resolve()}function S(_){const k=Tt.values().next().value;return k&&typeof k.runWithContext=="function"?k.runWithContext(_):_()}function O(_,k){let I;const[L,ee,ae]=ra(_,k);I=ms(L.reverse(),"beforeRouteLeave",_,k);for(const f of L)f.leaveGuards.forEach(m=>{I.push(dt(m,_,k))});const u=j.bind(null,_,k);return I.push(u),ke(I).then(()=>{I=[];for(const f of o.list())I.push(dt(f,_,k));return I.push(u),ke(I)}).then(()=>{I=ms(ee,"beforeRouteUpdate",_,k);for(const f of ee)f.updateGuards.forEach(m=>{I.push(dt(m,_,k))});return I.push(u),ke(I)}).then(()=>{I=[];for(const f of ae)if(f.beforeEnter)if(Ue(f.beforeEnter))for(const m of f.beforeEnter)I.push(dt(m,_,k));else I.push(dt(f.beforeEnter,_,k));return I.push(u),ke(I)}).then(()=>(_.matched.forEach(f=>f.enterCallbacks={}),I=ms(ae,"beforeRouteEnter",_,k,S),I.push(u),ke(I))).then(()=>{I=[];for(const f of i.list())I.push(dt(f,_,k));return I.push(u),ke(I)}).catch(f=>tt(f,8)?f:Promise.reject(f))}function re(_,k,I){l.list().forEach(L=>S(()=>L(_,k,I)))}function Q(_,k,I,L,ee){const ae=D(_,k);if(ae)return ae;const u=k===ct,f=kt?history.state:{};I&&(L||u?r.replace(_.fullPath,X({scroll:u&&f&&f.scroll},ee)):r.push(_.fullPath,ee)),c.value=_,Ke(_,k,I,u),lt()}let fe;function Xe(){fe||(fe=r.listen((_,k,I)=>{if(!wn.listening)return;const L=M(_),ee=pe(L);if(ee){z(X(ee,{replace:!0,force:!0}),L).catch(ln);return}d=L;const ae=c.value;kt&&Ou(Br(ae.fullPath,I.delta),Zn()),O(L,ae).catch(u=>tt(u,12)?u:tt(u,2)?(z(X(F(u.to),{force:!0}),L).then(f=>{tt(f,20)&&!I.delta&&I.type===vn.pop&&r.go(-1,!1)}).catch(ln),Promise.reject()):(I.delta&&r.go(-I.delta,!1),Y(u,L,ae))).then(u=>{u=u||Q(L,ae,!1),u&&(I.delta&&!tt(u,8)?r.go(-I.delta,!1):I.type===vn.pop&&tt(u,20)&&r.go(-1,!1)),re(L,ae,u)}).catch(ln)}))}let Be=Jt(),oe=Jt(),W;function Y(_,k,I){lt(_);const L=oe.list();return L.length?L.forEach(ee=>ee(_,k,I)):console.error(_),Promise.reject(_)}function Ze(){return W&&c.value!==ct?Promise.resolve():new Promise((_,k)=>{Be.add([_,k])})}function lt(_){return W||(W=!_,Xe(),Be.list().forEach(([k,I])=>_?I(_):k()),Be.reset()),_}function Ke(_,k,I,L){const{scrollBehavior:ee}=e;if(!kt||!ee)return Promise.resolve();const ae=!I&&Tu(Br(_.fullPath,0))||(L||!I)&&history.state&&history.state.scroll||null;return qn().then(()=>ee(_,k,ae)).then(u=>u&&Au(u)).catch(u=>Y(u,_,k))}const Ae=_=>r.go(_);let Ot;const Tt=new Set,wn={currentRoute:c,listening:!0,addRoute:g,removeRoute:R,clearRoutes:t.clearRoutes,hasRoute:A,getRoutes:E,resolve:M,options:e,push:N,replace:q,go:Ae,back:()=>Ae(-1),forward:()=>Ae(1),beforeEach:o.add,beforeResolve:i.add,afterEach:l.add,onError:oe.add,isReady:Ze,install(_){const k=this;_.component("RouterLink",Ms),_.component("RouterView",Oi),_.config.globalProperties.$router=k,Object.defineProperty(_.config.globalProperties,"$route",{enumerable:!0,get:()=>ve(c)}),kt&&!Ot&&c.value===ct&&(Ot=!0,N(r.location).catch(ee=>{}));const I={};for(const ee in ct)Object.defineProperty(I,ee,{get:()=>c.value[ee],enumerable:!0});_.provide(es,k),_.provide(tr,Io(I)),_.provide($s,c);const L=_.unmount;Tt.add(_),_.unmount=function(){Tt.delete(_),Tt.size<1&&(d=ct,fe&&fe(),fe=null,c.value=ct,Ot=!1,W=!1),L()}}};function ke(_){return _.reduce((k,I)=>k.then(()=>S(I)),Promise.resolve())}return wn}function ra(e,t){const n=[],s=[],r=[],o=Math.max(t.matched.length,e.matched.length);for(let i=0;i<o;i++){const l=t.matched[i];l&&(e.matched.find(d=>Ut(d,l))?s.push(l):n.push(l));const c=e.matched[i];c&&(t.matched.find(d=>Ut(d,c))||r.push(c))}return[n,s,r]}function nr(){return Le(es)}function Ti(e){return Le(tr)}const oa={class:"sidebar"},ia=yt({__name:"NavSidebar",setup(e){const t=Ti();return(n,s)=>(ne(),se("nav",oa,[_e(ve(Ms),{to:"/",class:Dt(["nav-item",{active:ve(t).path==="/"}])},{default:xs(()=>s[0]||(s[0]=[hn(" 仪表盘 ")])),_:1},8,["class"]),_e(ve(Ms),{to:"/apis",class:Dt(["nav-item",{active:ve(t).path.startsWith("/apis")}])},{default:xs(()=>s[1]||(s[1]=[hn(" API管理 ")])),_:1},8,["class"])]))}}),Wt=(e,t)=>{const n=e.__vccOpts||e;for(const[s,r]of t)n[s]=r;return n},la=Wt(ia,[["__scopeId","data-v-333258da"]]),ca={class:"app-header"},ua=yt({__name:"AppHeader",setup(e){const t=nr(),n=()=>{t.push("/")};return(s,r)=>(ne(),se("header",ca,[y("div",{class:"logo",onClick:n},r[0]||(r[0]=[y("h1",null,"JSON API Mocker",-1)])),r[1]||(r[1]=y("div",{class:"right"},[y("a",{href:"https://github.com/Selteve/json-api-mocker",target:"_blank",class:"github-link"}," GitHub ")],-1))]))}}),aa=Wt(ua,[["__scopeId","data-v-ecbe1cbc"]]),fa={class:"app-container"},da={class:"main-container"},ha={class:"content"},pa=yt({__name:"App",setup(e){return(t,n)=>(ne(),se("div",fa,[_e(aa),y("div",da,[_e(la),y("main",ha,[_e(ve(Oi))])])]))}}),ga=Wt(pa,[["__scopeId","data-v-32f4c818"]]),Pn=`http://${window.location.hostname}:8080`,sr=su("api",()=>{const e=de([]),t=de(!1),n=de(null);async function s(){t.value=!0;try{const i=await fetch(`${Pn}/api/_config`);e.value=await i.json()}catch(i){n.value=i instanceof Error?i.message:"获取API配置失败"}finally{t.value=!1}}async function r(i){var l,c;t.value=!0;try{const d=i.id?`${Pn}/api/_config/${i.id}`:`${Pn}/api/_config`,a={route:{path:((l=i.route)==null?void 0:l.path)||"",methods:((c=i.route)==null?void 0:c.methods)||{}}};if(!(await fetch(d,{method:i.id?"PUT":"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)})).ok)throw new Error("保存失败");await s()}catch(d){n.value=d instanceof Error?d.message:"保存API配置失败"}finally{t.value=!1}}async function o(i){t.value=!0;try{if(!(await fetch(`${Pn}/api/_config/${i}`,{method:"DELETE"})).ok)throw new Error("删除失败");await s()}catch(l){n.value=l instanceof Error?l.message:"删除API配置失败"}finally{t.value=!1}}return{apis:e,loading:t,error:n,fetchApis:s,saveApi:r,deleteApi:o}}),ma={class:"api-list"},va={key:0,class:"loading"},_a={key:1,class:"error"},ya={key:2,class:"list"},ba={key:0,class:"empty"},xa={key:0,class:"api-info"},Sa={key:0,class:"methods"},wa={class:"actions"},Ea=["onClick"],Ca=["onClick"],Ra=yt({__name:"ApiList",setup(e){const t=nr(),n=sr();zn(()=>{n.fetchApis()});const s=i=>{t.push(`/apis/${i}`)},r=()=>{t.push("/apis/new")},o=async i=>{confirm("确定要删除这个API吗?")&&await n.deleteApi(i)};return(i,l)=>(ne(),se("div",ma,[y("div",{class:"header"},[l[0]||(l[0]=y("h1",null,"API列表",-1)),y("button",{onClick:r,class:"create-btn"},"创建新API")]),ve(n).loading?(ne(),se("div",va," 加载中... ")):ve(n).error?(ne(),se("div",_a,ge(ve(n).error),1)):(ne(),se("div",ya,[!ve(n).apis||ve(n).apis.length===0?(ne(),se("div",ba," 暂无API配置,点击上方按钮创建 ")):(ne(!0),se(we,{key:1},wt(ve(n).apis,c=>(ne(),se("div",{key:c.id,class:"api-item"},[c&&c.route?(ne(),se("div",xa,[y("h3",null,ge(c.route.path),1),c.route.methods?(ne(),se("div",Sa,[(ne(!0),se(we,null,wt(Object.keys(c.route.methods),d=>(ne(),se("span",{key:d,class:"method-tag"},ge(d.toUpperCase()),1))),128))])):rn("",!0)])):rn("",!0),y("div",wa,[y("button",{onClick:d=>s(c.id),class:"edit-btn"},"编辑",8,Ea),y("button",{onClick:d=>o(c.id),class:"delete-btn"},"删除",8,Ca)])]))),128))]))]))}}),Pa=Wt(Ra,[["__scopeId","data-v-f00969e3"]]),Aa={class:"api-editor"},Oa={class:"header"},Ta={class:"form"},Ia={class:"form-group"},$a={class:"form-group"},Ma=["value"],ja={class:"form-group"},ka=["value"],Na={class:"form-group"},Fa={key:0,class:"pagination-settings"},La={key:0,class:"form-group"},Da={key:0,class:"data-count-settings"},Ha={class:"form-group"},Va=["onUpdate:modelValue"],Ua=["onUpdate:modelValue"],Ba=["value"],Ka=["onUpdate:modelValue","placeholder"],Wa=["onClick"],qa={class:"form-group"},Ga=["value"],za={class:"actions"},Ja=yt({__name:"ApiEditor",setup(e){const t=Ti(),n=nr(),s=sr(),r=de({id:"",route:{path:"",methods:{}}}),o=t.params.id!==void 0,i=["get","post","put","delete","patch","options"],l=de("get"),c=[{label:"默认JSON格式",value:{"Content-Type":"application/json"}},{label:"允许跨域",value:{"Access-Control-Allow-Origin":"*"}},{label:"文件上传",value:{"Content-Type":"multipart/form-data"}}],d=[{label:"文本",value:"string"},{label:"数字",value:"number"},{label:"布尔值",value:"boolean"},{label:"日期时间",value:"datetime"},{label:"图片URL",value:"image"},{label:"邮箱",value:"email"},{label:"手机机号",value:"phone"},{label:"中文名",value:"cname"},{label:"英文名",value:"name"},{label:"地址",value:"address"},{label:"ID",value:"id"}],a=de([]),h=de(!1),p=de(10),g=de(100),R=de(1),E=de(!1),A=()=>{a.value.push({name:"",type:"string",mock:""})},M=j=>{a.value.splice(j,1)},F=j=>{switch(j){case"string":return"@string(5,10)";case"number":return"@integer(1,100)";case"boolean":return"@boolean";case"datetime":return"@datetime";case"image":return'@image("200x200")';case"email":return"@email";case"phone":return"@phone";case"cname":return"@cname";case"name":return"@name";case"address":return"@county(true)";case"id":return"@id";default:return"@string"}},D=()=>{const j={code:200,message:"success",data:{}};return h.value?j.data={total:`@integer(${g.value}, ${g.value+100})`,[`list|${p.value}`]:[{...a.value.length>0?a.value.reduce((S,O)=>({...S,[O.name]:O.mock||F(O.type)}),{}):{id:"@id",name:"@name",created_at:"@datetime"}}]}:E.value?j.data={[`list|${R.value}`]:[{...a.value.length>0?a.value.reduce((S,O)=>({...S,[O.name]:O.mock||F(O.type)}),{}):{id:"@id",name:"@name",created_at:"@datetime"}}]}:j.data=a.value.length>0?a.value.reduce((S,O)=>({...S,[O.name]:O.mock||F(O.type)}),{}):{id:"@id",name:"@name",created_at:"@datetime"},JSON.stringify(j,null,2)},N=de(c[0].value),q=j=>{r.value.route.methods[l.value]?r.value.route.methods[l.value].headers=j:r.value.route.methods[l.value]={status:200,response:"",headers:j}},pe=async()=>{r.value.route.methods[l.value]={status:200,response:D(),headers:N.value},console.log("Saving API config:",r.value),await s.saveApi(r.value),n.push("/apis")};zn(async()=>{if(o){await s.fetchApis();const j=s.apis.find(S=>S.id===t.params.id);if(j){r.value=JSON.parse(JSON.stringify(j));const S=Object.keys(j.route.methods);if(S.length>0){l.value=S[0];const O=j.route.methods[l.value];N.value=O.headers||c[0].value;try{const re=JSON.parse(O.response);if(re.data.list){const Q=Object.keys(re.data).find(fe=>fe.startsWith("list|"));if(Q){const fe=parseInt(Q.split("|")[1]);re.data.total?(h.value=!0,p.value=fe,g.value=parseInt(re.data.total)||100):(E.value=!0,R.value=fe);const Xe=re.data[Q][0];a.value=Object.entries(Xe).map(([Be,oe])=>({name:Be,type:z(oe),mock:oe}))}}else a.value=Object.entries(re.data).map(([Q,fe])=>({name:Q,type:z(fe),mock:fe}))}catch(re){console.error("Error parsing response data:",re)}}}}});const z=j=>typeof j!="string"?"string":j.includes("@cname")?"cname":j.includes("@name")?"name":j.includes("@email")?"email":j.includes("@phone")?"phone":j.includes("@integer")?"number":j.includes("@datetime")?"datetime":j.includes("@image")?"image":j.includes("@id")?"id":j.includes("@county")?"address":j.includes("@boolean")?"boolean":"string";return(j,S)=>(ne(),se("div",Aa,[y("div",Oa,[y("h1",null,ge(o?"编辑":"创建")+"API",1)]),y("div",Ta,[y("div",Ia,[S[10]||(S[10]=y("label",null,"API路径",-1)),He(y("input",{"onUpdate:modelValue":S[0]||(S[0]=O=>r.value.route.path=O),placeholder:"/your-path",class:"input"},null,512),[[$t,r.value.route.path]]),S[11]||(S[11]=y("div",{class:"helper-text"}," 不需要输入基础路径(/api),它会自动添加 ",-1))]),y("div",$a,[S[12]||(S[12]=y("label",null,"HTTP方法",-1)),He(y("select",{"onUpdate:modelValue":S[1]||(S[1]=O=>l.value=O),class:"input"},[(ne(),se(we,null,wt(i,O=>y("option",{key:O,value:O},ge(O.toUpperCase()),9,Ma)),64))],512),[[ds,l.value]])]),y("div",ja,[S[13]||(S[13]=y("label",null,"响应头",-1)),He(y("select",{"onUpdate:modelValue":S[2]||(S[2]=O=>N.value=O),class:"input",onChange:S[3]||(S[3]=O=>q(O.target.value))},[(ne(),se(we,null,wt(c,O=>y("option",{key:O.label,value:O.value},ge(O.label),9,ka)),64))],544),[[ds,N.value]])]),y("div",Na,[y("label",null,[He(y("input",{type:"checkbox","onUpdate:modelValue":S[4]||(S[4]=O=>h.value=O)},null,512),[[kr,h.value]]),S[14]||(S[14]=hn(" 启用分页 "))]),h.value?(ne(),se("div",Fa,[y("div",null,[S[15]||(S[15]=y("label",null,"每页数量",-1)),He(y("input",{type:"number","onUpdate:modelValue":S[5]||(S[5]=O=>p.value=O),class:"input"},null,512),[[$t,p.value]])]),y("div",null,[S[16]||(S[16]=y("label",null,"总数范围",-1)),He(y("input",{type:"number","onUpdate:modelValue":S[6]||(S[6]=O=>g.value=O),class:"input"},null,512),[[$t,g.value]])])])):rn("",!0)]),h.value?rn("",!0):(ne(),se("div",La,[y("label",null,[He(y("input",{type:"checkbox","onUpdate:modelValue":S[7]||(S[7]=O=>E.value=O)},null,512),[[kr,E.value]]),S[17]||(S[17]=hn(" 生成多条数据 "))]),E.value?(ne(),se("div",Da,[y("div",null,[S[18]||(S[18]=y("label",null,"数据条数",-1)),He(y("input",{type:"number","onUpdate:modelValue":S[8]||(S[8]=O=>R.value=O),class:"input",min:"1",max:1e3},null,512),[[$t,R.value]])]),S[19]||(S[19]=y("div",{class:"helper-text"}," 设置要生成的数据条数(1-1000) ",-1))])):rn("",!0)])),y("div",Ha,[y("div",{class:"fields-header"},[S[20]||(S[20]=y("label",null,"响应字段",-1)),y("button",{onClick:A,class:"add-btn"},"添加字段")]),(ne(!0),se(we,null,wt(a.value,(O,re)=>(ne(),se("div",{key:re,class:"field-item"},[He(y("input",{"onUpdate:modelValue":Q=>O.name=Q,placeholder:"字段名",class:"input field-name"},null,8,Va),[[$t,O.name]]),He(y("select",{"onUpdate:modelValue":Q=>O.type=Q,class:"input field-type"},[(ne(),se(we,null,wt(d,Q=>y("option",{key:Q.value,value:Q.value},ge(Q.label),9,Ba)),64))],8,Ua),[[ds,O.type]]),He(y("input",{"onUpdate:modelValue":Q=>O.mock=Q,placeholder:F(O.type),class:"input field-mock"},null,8,Ka),[[$t,O.mock]]),y("button",{onClick:Q=>M(re),class:"remove-btn"},"删除",8,Wa)]))),128))]),y("div",qa,[S[21]||(S[21]=y("label",null,"响应数据预览",-1)),y("textarea",{value:D(),readonly:"",class:"preview-textarea"},null,8,Ga)]),y("div",za,[y("button",{onClick:S[9]||(S[9]=O=>ve(n).push("/apis")),class:"cancel-btn"},"取消"),y("button",{onClick:pe,class:"save-btn"},"保存")])])]))}}),ro=Wt(Ja,[["__scopeId","data-v-d5d7a1e1"]]),Qa={class:"dashboard"},Ya={class:"stats"},Xa={class:"stat-card"},Za={class:"stat-value"},ef={class:"stat-card"},tf={class:"stat-value"},nf={class:"stat-card"},sf={class:"stat-value"},rf={class:"stat-card"},of={class:"stat-value"},lf={class:"logs-section"},cf={key:0,class:"logs-table"},uf={class:"params"},af={class:"pagination"},ff=["disabled"],df=["disabled"],hf={key:1,class:"empty-logs"},pf=yt({__name:"Dashboard",setup(e){const t=sr(),n=de([]),s=de(null),r=de(!1),o=de(1),i=de(20),l=de(0),c=de({totalApis:0,totalRequests:0,averageResponseTime:0,successRate:0}),d=async()=>{r.value=!0;try{const A=await(await fetch(`http://localhost:8080/api/_logs?page=${o.value}&size=${i.value}`)).json();n.value=A.list,l.value=A.total}catch(E){console.error("Failed to fetch logs:",E)}finally{r.value=!1}},a=async()=>{if(confirm("确定要清除所有日志吗?"))try{await fetch("http://localhost:8080/api/_logs",{method:"DELETE"}),await d()}catch(E){console.error("Failed to clear logs:",E)}},h=()=>{c.value={totalApis:t.apis.length,totalRequests:l.value,averageResponseTime:n.value.reduce((E,A)=>E+A.duration,0)/n.value.length||0,successRate:n.value.filter(E=>E.status<400).length/n.value.length*100||0}},p=E=>new Date(E).toLocaleString(),g=E=>{o.value=E,d()},R=()=>{s.value=new WebSocket(`ws://${window.location.hostname}:35730`),s.value.onmessage=E=>{const A=JSON.parse(E.data);A.type==="init"?(n.value=A.data,l.value=A.data.length,h()):A.type==="log"&&(n.value.unshift(A.data),l.value++,h())},s.value.onclose=()=>{setTimeout(R,3e3)}};return zn(async()=>{await t.fetchApis(),R()}),Qs(()=>{s.value&&s.value.close()}),(E,A)=>(ne(),se("div",Qa,[A[8]||(A[8]=y("h1",null,"仪表盘",-1)),y("div",Ya,[y("div",Xa,[A[2]||(A[2]=y("h3",null,"API总数",-1)),y("div",Za,ge(c.value.totalApis),1)]),y("div",ef,[A[3]||(A[3]=y("h3",null,"总请求数",-1)),y("div",tf,ge(c.value.totalRequests),1)]),y("div",nf,[A[4]||(A[4]=y("h3",null,"平均响应时间",-1)),y("div",sf,ge(c.value.averageResponseTime.toFixed(2))+"ms",1)]),y("div",rf,[A[5]||(A[5]=y("h3",null,"成功率",-1)),y("div",of,ge(c.value.successRate.toFixed(2))+"%",1)])]),y("div",lf,[y("div",{class:"logs-header"},[A[6]||(A[6]=y("h2",null,"请求日志",-1)),y("button",{onClick:a,class:"clear-btn"},"清除日志")]),n.value.length>0?(ne(),se("div",cf,[y("table",null,[A[7]||(A[7]=y("thead",null,[y("tr",null,[y("th",null,"时间"),y("th",null,"路径"),y("th",null,"方法"),y("th",null,"参数"),y("th",null,"状态"),y("th",null,"耗时")])],-1)),y("tbody",null,[(ne(!0),se(we,null,wt(n.value,M=>(ne(),se("tr",{key:M.id},[y("td",null,ge(p(M.timestamp)),1),y("td",null,ge(M.path),1),y("td",null,ge(M.method),1),y("td",null,[y("pre",uf,ge(JSON.stringify(M.params,null,2)),1)]),y("td",{class:Dt({success:M.status<400,error:M.status>=400})},ge(M.status),3),y("td",null,ge(M.duration)+"ms",1)]))),128))])]),y("div",af,[y("button",{disabled:o.value===1,onClick:A[0]||(A[0]=M=>g(o.value-1))}," 上一页 ",8,ff),y("span",null,ge(o.value)+" / "+ge(Math.ceil(l.value/i.value)),1),y("button",{disabled:o.value>=Math.ceil(l.value/i.value),onClick:A[1]||(A[1]=M=>g(o.value+1))}," 下一页 ",8,df)])])):(ne(),se("div",hf," 暂无请求日志 "))])]))}}),gf=Wt(pf,[["__scopeId","data-v-affa5733"]]),mf=sa({history:ju(),routes:[{path:"/",name:"dashboard",component:gf},{path:"/apis",name:"api-list",component:Pa},{path:"/apis/new",name:"api-new",component:ro},{path:"/apis/:id",name:"api-edit",component:ro}]}),rr=Gc(ga);rr.use(Yc());rr.use(mf);rr.mount("#app");
|
25
|
+
*/const kt=typeof document<"u";function vi(e){return typeof e=="object"||"displayName"in e||"props"in e||"__vccOpts"in e}function ru(e){return e.__esModule||e[Symbol.toStringTag]==="Module"||e.default&&vi(e.default)}const X=Object.assign;function ps(e,t){const n={};for(const s in t){const r=t[s];n[s]=Ue(r)?r.map(e):e(r)}return n}const ln=()=>{},Ue=Array.isArray,_i=/#/g,ou=/&/g,iu=/\//g,lu=/=/g,cu=/\?/g,yi=/\+/g,uu=/%5B/g,au=/%5D/g,bi=/%5E/g,fu=/%60/g,xi=/%7B/g,du=/%7C/g,Si=/%7D/g,hu=/%20/g;function er(e){return encodeURI(""+e).replace(du,"|").replace(uu,"[").replace(au,"]")}function pu(e){return er(e).replace(xi,"{").replace(Si,"}").replace(bi,"^")}function Ts(e){return er(e).replace(yi,"%2B").replace(hu,"+").replace(_i,"%23").replace(ou,"%26").replace(fu,"`").replace(xi,"{").replace(Si,"}").replace(bi,"^")}function gu(e){return Ts(e).replace(lu,"%3D")}function mu(e){return er(e).replace(_i,"%23").replace(cu,"%3F")}function vu(e){return e==null?"":mu(e).replace(iu,"%2F")}function mn(e){try{return decodeURIComponent(""+e)}catch{}return""+e}const _u=/\/$/,yu=e=>e.replace(_u,"");function gs(e,t,n="/"){let s,r={},o="",i="";const l=t.indexOf("#");let c=t.indexOf("?");return l<c&&l>=0&&(c=-1),c>-1&&(s=t.slice(0,c),o=t.slice(c+1,l>-1?l:t.length),r=e(o)),l>-1&&(s=s||t.slice(0,l),i=t.slice(l,t.length)),s=wu(s??t,n),{fullPath:s+(o&&"?")+o+i,path:s,query:r,hash:mn(i)}}function bu(e,t){const n=t.query?e(t.query):"";return t.path+(n&&"?")+n+(t.hash||"")}function Vr(e,t){return!t||!e.toLowerCase().startsWith(t.toLowerCase())?e:e.slice(t.length)||"/"}function xu(e,t,n){const s=t.matched.length-1,r=n.matched.length-1;return s>-1&&s===r&&Ut(t.matched[s],n.matched[r])&&wi(t.params,n.params)&&e(t.query)===e(n.query)&&t.hash===n.hash}function Ut(e,t){return(e.aliasOf||e)===(t.aliasOf||t)}function wi(e,t){if(Object.keys(e).length!==Object.keys(t).length)return!1;for(const n in e)if(!Su(e[n],t[n]))return!1;return!0}function Su(e,t){return Ue(e)?Ur(e,t):Ue(t)?Ur(t,e):e===t}function Ur(e,t){return Ue(t)?e.length===t.length&&e.every((n,s)=>n===t[s]):e.length===1&&e[0]===t}function wu(e,t){if(e.startsWith("/"))return e;if(!e)return t;const n=t.split("/"),s=e.split("/"),r=s[s.length-1];(r===".."||r===".")&&s.push("");let o=n.length-1,i,l;for(i=0;i<s.length;i++)if(l=s[i],l!==".")if(l==="..")o>1&&o--;else break;return n.slice(0,o).join("/")+"/"+s.slice(i).join("/")}const ct={path:"/",name:void 0,params:{},query:{},hash:"",fullPath:"/",matched:[],meta:{},redirectedFrom:void 0};var vn;(function(e){e.pop="pop",e.push="push"})(vn||(vn={}));var cn;(function(e){e.back="back",e.forward="forward",e.unknown=""})(cn||(cn={}));function Eu(e){if(!e)if(kt){const t=document.querySelector("base");e=t&&t.getAttribute("href")||"/",e=e.replace(/^\w+:\/\/[^\/]+/,"")}else e="/";return e[0]!=="/"&&e[0]!=="#"&&(e="/"+e),yu(e)}const Cu=/^[^#]+#/;function Ru(e,t){return e.replace(Cu,"#")+t}function Pu(e,t){const n=document.documentElement.getBoundingClientRect(),s=e.getBoundingClientRect();return{behavior:t.behavior,left:s.left-n.left-(t.left||0),top:s.top-n.top-(t.top||0)}}const Zn=()=>({left:window.scrollX,top:window.scrollY});function Au(e){let t;if("el"in e){const n=e.el,s=typeof n=="string"&&n.startsWith("#"),r=typeof n=="string"?s?document.getElementById(n.slice(1)):document.querySelector(n):n;if(!r)return;t=Pu(r,e)}else t=e;"scrollBehavior"in document.documentElement.style?window.scrollTo(t):window.scrollTo(t.left!=null?t.left:window.scrollX,t.top!=null?t.top:window.scrollY)}function Br(e,t){return(history.state?history.state.position-t:-1)+e}const Is=new Map;function Ou(e,t){Is.set(e,t)}function Tu(e){const t=Is.get(e);return Is.delete(e),t}let Iu=()=>location.protocol+"//"+location.host;function Ei(e,t){const{pathname:n,search:s,hash:r}=t,o=e.indexOf("#");if(o>-1){let l=r.includes(e.slice(o))?e.slice(o).length:1,c=r.slice(l);return c[0]!=="/"&&(c="/"+c),Vr(c,"")}return Vr(n,e)+s+r}function $u(e,t,n,s){let r=[],o=[],i=null;const l=({state:p})=>{const g=Ei(e,location),R=n.value,E=t.value;let A=0;if(p){if(n.value=g,t.value=p,i&&i===R){i=null;return}A=E?p.position-E.position:0}else s(g);r.forEach(M=>{M(n.value,R,{delta:A,type:vn.pop,direction:A?A>0?cn.forward:cn.back:cn.unknown})})};function c(){i=n.value}function d(p){r.push(p);const g=()=>{const R=r.indexOf(p);R>-1&&r.splice(R,1)};return o.push(g),g}function a(){const{history:p}=window;p.state&&p.replaceState(X({},p.state,{scroll:Zn()}),"")}function h(){for(const p of o)p();o=[],window.removeEventListener("popstate",l),window.removeEventListener("beforeunload",a)}return window.addEventListener("popstate",l),window.addEventListener("beforeunload",a,{passive:!0}),{pauseListeners:c,listen:d,destroy:h}}function Kr(e,t,n,s=!1,r=!1){return{back:e,current:t,forward:n,replaced:s,position:window.history.length,scroll:r?Zn():null}}function Mu(e){const{history:t,location:n}=window,s={value:Ei(e,n)},r={value:t.state};r.value||o(s.value,{back:null,current:s.value,forward:null,position:t.length-1,replaced:!0,scroll:null},!0);function o(c,d,a){const h=e.indexOf("#"),p=h>-1?(n.host&&document.querySelector("base")?e:e.slice(h))+c:Iu()+e+c;try{t[a?"replaceState":"pushState"](d,"",p),r.value=d}catch(g){console.error(g),n[a?"replace":"assign"](p)}}function i(c,d){const a=X({},t.state,Kr(r.value.back,c,r.value.forward,!0),d,{position:r.value.position});o(c,a,!0),s.value=c}function l(c,d){const a=X({},r.value,t.state,{forward:c,scroll:Zn()});o(a.current,a,!0);const h=X({},Kr(s.value,c,null),{position:a.position+1},d);o(c,h,!1),s.value=c}return{location:s,state:r,push:l,replace:i}}function ju(e){e=Eu(e);const t=Mu(e),n=$u(e,t.state,t.location,t.replace);function s(o,i=!0){i||n.pauseListeners(),history.go(o)}const r=X({location:"",base:e,go:s,createHref:Ru.bind(null,e)},t,n);return Object.defineProperty(r,"location",{enumerable:!0,get:()=>t.location.value}),Object.defineProperty(r,"state",{enumerable:!0,get:()=>t.state.value}),r}function ku(e){return typeof e=="string"||e&&typeof e=="object"}function Ci(e){return typeof e=="string"||typeof e=="symbol"}const Ri=Symbol("");var Wr;(function(e){e[e.aborted=4]="aborted",e[e.cancelled=8]="cancelled",e[e.duplicated=16]="duplicated"})(Wr||(Wr={}));function Bt(e,t){return X(new Error,{type:e,[Ri]:!0},t)}function tt(e,t){return e instanceof Error&&Ri in e&&(t==null||!!(e.type&t))}const qr="[^/]+?",Nu={sensitive:!1,strict:!1,start:!0,end:!0},Fu=/[.+*?^${}()[\]/\\]/g;function Lu(e,t){const n=X({},Nu,t),s=[];let r=n.start?"^":"";const o=[];for(const d of e){const a=d.length?[]:[90];n.strict&&!d.length&&(r+="/");for(let h=0;h<d.length;h++){const p=d[h];let g=40+(n.sensitive?.25:0);if(p.type===0)h||(r+="/"),r+=p.value.replace(Fu,"\\$&"),g+=40;else if(p.type===1){const{value:R,repeatable:E,optional:A,regexp:M}=p;o.push({name:R,repeatable:E,optional:A});const F=M||qr;if(F!==qr){g+=10;try{new RegExp(`(${F})`)}catch(N){throw new Error(`Invalid custom RegExp for param "${R}" (${F}): `+N.message)}}let D=E?`((?:${F})(?:/(?:${F}))*)`:`(${F})`;h||(D=A&&d.length<2?`(?:/${D})`:"/"+D),A&&(D+="?"),r+=D,g+=20,A&&(g+=-8),E&&(g+=-20),F===".*"&&(g+=-50)}a.push(g)}s.push(a)}if(n.strict&&n.end){const d=s.length-1;s[d][s[d].length-1]+=.7000000000000001}n.strict||(r+="/?"),n.end?r+="$":n.strict&&!r.endsWith("/")&&(r+="(?:/|$)");const i=new RegExp(r,n.sensitive?"":"i");function l(d){const a=d.match(i),h={};if(!a)return null;for(let p=1;p<a.length;p++){const g=a[p]||"",R=o[p-1];h[R.name]=g&&R.repeatable?g.split("/"):g}return h}function c(d){let a="",h=!1;for(const p of e){(!h||!a.endsWith("/"))&&(a+="/"),h=!1;for(const g of p)if(g.type===0)a+=g.value;else if(g.type===1){const{value:R,repeatable:E,optional:A}=g,M=R in d?d[R]:"";if(Ue(M)&&!E)throw new Error(`Provided param "${R}" is an array but it is not repeatable (* or + modifiers)`);const F=Ue(M)?M.join("/"):M;if(!F)if(A)p.length<2&&(a.endsWith("/")?a=a.slice(0,-1):h=!0);else throw new Error(`Missing required param "${R}"`);a+=F}}return a||"/"}return{re:i,score:s,keys:o,parse:l,stringify:c}}function Du(e,t){let n=0;for(;n<e.length&&n<t.length;){const s=t[n]-e[n];if(s)return s;n++}return e.length<t.length?e.length===1&&e[0]===80?-1:1:e.length>t.length?t.length===1&&t[0]===80?1:-1:0}function Pi(e,t){let n=0;const s=e.score,r=t.score;for(;n<s.length&&n<r.length;){const o=Du(s[n],r[n]);if(o)return o;n++}if(Math.abs(r.length-s.length)===1){if(Gr(s))return 1;if(Gr(r))return-1}return r.length-s.length}function Gr(e){const t=e[e.length-1];return e.length>0&&t[t.length-1]<0}const Hu={type:0,value:""},Vu=/[a-zA-Z0-9_]/;function Uu(e){if(!e)return[[]];if(e==="/")return[[Hu]];if(!e.startsWith("/"))throw new Error(`Invalid path "${e}"`);function t(g){throw new Error(`ERR (${n})/"${d}": ${g}`)}let n=0,s=n;const r=[];let o;function i(){o&&r.push(o),o=[]}let l=0,c,d="",a="";function h(){d&&(n===0?o.push({type:0,value:d}):n===1||n===2||n===3?(o.length>1&&(c==="*"||c==="+")&&t(`A repeatable param (${d}) must be alone in its segment. eg: '/:ids+.`),o.push({type:1,value:d,regexp:a,repeatable:c==="*"||c==="+",optional:c==="*"||c==="?"})):t("Invalid state to consume buffer"),d="")}function p(){d+=c}for(;l<e.length;){if(c=e[l++],c==="\\"&&n!==2){s=n,n=4;continue}switch(n){case 0:c==="/"?(d&&h(),i()):c===":"?(h(),n=1):p();break;case 4:p(),n=s;break;case 1:c==="("?n=2:Vu.test(c)?p():(h(),n=0,c!=="*"&&c!=="?"&&c!=="+"&&l--);break;case 2:c===")"?a[a.length-1]=="\\"?a=a.slice(0,-1)+c:n=3:a+=c;break;case 3:h(),n=0,c!=="*"&&c!=="?"&&c!=="+"&&l--,a="";break;default:t("Unknown state");break}}return n===2&&t(`Unfinished custom RegExp for param "${d}"`),h(),i(),r}function Bu(e,t,n){const s=Lu(Uu(e.path),n),r=X(s,{record:e,parent:t,children:[],alias:[]});return t&&!r.record.aliasOf==!t.record.aliasOf&&t.children.push(r),r}function Ku(e,t){const n=[],s=new Map;t=Yr({strict:!1,end:!0,sensitive:!1},t);function r(h){return s.get(h)}function o(h,p,g){const R=!g,E=Jr(h);E.aliasOf=g&&g.record;const A=Yr(t,h),M=[E];if("alias"in h){const N=typeof h.alias=="string"?[h.alias]:h.alias;for(const q of N)M.push(Jr(X({},E,{components:g?g.record.components:E.components,path:q,aliasOf:g?g.record:E})))}let F,D;for(const N of M){const{path:q}=N;if(p&&q[0]!=="/"){const pe=p.record.path,z=pe[pe.length-1]==="/"?"":"/";N.path=p.record.path+(q&&z+q)}if(F=Bu(N,p,A),g?g.alias.push(F):(D=D||F,D!==F&&D.alias.push(F),R&&h.name&&!Qr(F)&&i(h.name)),Ai(F)&&c(F),E.children){const pe=E.children;for(let z=0;z<pe.length;z++)o(pe[z],F,g&&g.children[z])}g=g||F}return D?()=>{i(D)}:ln}function i(h){if(Ci(h)){const p=s.get(h);p&&(s.delete(h),n.splice(n.indexOf(p),1),p.children.forEach(i),p.alias.forEach(i))}else{const p=n.indexOf(h);p>-1&&(n.splice(p,1),h.record.name&&s.delete(h.record.name),h.children.forEach(i),h.alias.forEach(i))}}function l(){return n}function c(h){const p=Gu(h,n);n.splice(p,0,h),h.record.name&&!Qr(h)&&s.set(h.record.name,h)}function d(h,p){let g,R={},E,A;if("name"in h&&h.name){if(g=s.get(h.name),!g)throw Bt(1,{location:h});A=g.record.name,R=X(zr(p.params,g.keys.filter(D=>!D.optional).concat(g.parent?g.parent.keys.filter(D=>D.optional):[]).map(D=>D.name)),h.params&&zr(h.params,g.keys.map(D=>D.name))),E=g.stringify(R)}else if(h.path!=null)E=h.path,g=n.find(D=>D.re.test(E)),g&&(R=g.parse(E),A=g.record.name);else{if(g=p.name?s.get(p.name):n.find(D=>D.re.test(p.path)),!g)throw Bt(1,{location:h,currentLocation:p});A=g.record.name,R=X({},p.params,h.params),E=g.stringify(R)}const M=[];let F=g;for(;F;)M.unshift(F.record),F=F.parent;return{name:A,path:E,params:R,matched:M,meta:qu(M)}}e.forEach(h=>o(h));function a(){n.length=0,s.clear()}return{addRoute:o,resolve:d,removeRoute:i,clearRoutes:a,getRoutes:l,getRecordMatcher:r}}function zr(e,t){const n={};for(const s of t)s in e&&(n[s]=e[s]);return n}function Jr(e){const t={path:e.path,redirect:e.redirect,name:e.name,meta:e.meta||{},aliasOf:e.aliasOf,beforeEnter:e.beforeEnter,props:Wu(e),children:e.children||[],instances:{},leaveGuards:new Set,updateGuards:new Set,enterCallbacks:{},components:"components"in e?e.components||null:e.component&&{default:e.component}};return Object.defineProperty(t,"mods",{value:{}}),t}function Wu(e){const t={},n=e.props||!1;if("component"in e)t.default=n;else for(const s in e.components)t[s]=typeof n=="object"?n[s]:n;return t}function Qr(e){for(;e;){if(e.record.aliasOf)return!0;e=e.parent}return!1}function qu(e){return e.reduce((t,n)=>X(t,n.meta),{})}function Yr(e,t){const n={};for(const s in e)n[s]=s in t?t[s]:e[s];return n}function Gu(e,t){let n=0,s=t.length;for(;n!==s;){const o=n+s>>1;Pi(e,t[o])<0?s=o:n=o+1}const r=zu(e);return r&&(s=t.lastIndexOf(r,s-1)),s}function zu(e){let t=e;for(;t=t.parent;)if(Ai(t)&&Pi(e,t)===0)return t}function Ai({record:e}){return!!(e.name||e.components&&Object.keys(e.components).length||e.redirect)}function Ju(e){const t={};if(e===""||e==="?")return t;const s=(e[0]==="?"?e.slice(1):e).split("&");for(let r=0;r<s.length;++r){const o=s[r].replace(yi," "),i=o.indexOf("="),l=mn(i<0?o:o.slice(0,i)),c=i<0?null:mn(o.slice(i+1));if(l in t){let d=t[l];Ue(d)||(d=t[l]=[d]),d.push(c)}else t[l]=c}return t}function Xr(e){let t="";for(let n in e){const s=e[n];if(n=gu(n),s==null){s!==void 0&&(t+=(t.length?"&":"")+n);continue}(Ue(s)?s.map(o=>o&&Ts(o)):[s&&Ts(s)]).forEach(o=>{o!==void 0&&(t+=(t.length?"&":"")+n,o!=null&&(t+="="+o))})}return t}function Qu(e){const t={};for(const n in e){const s=e[n];s!==void 0&&(t[n]=Ue(s)?s.map(r=>r==null?null:""+r):s==null?s:""+s)}return t}const Yu=Symbol(""),Zr=Symbol(""),es=Symbol(""),tr=Symbol(""),$s=Symbol("");function Jt(){let e=[];function t(s){return e.push(s),()=>{const r=e.indexOf(s);r>-1&&e.splice(r,1)}}function n(){e=[]}return{add:t,list:()=>e.slice(),reset:n}}function dt(e,t,n,s,r,o=i=>i()){const i=s&&(s.enterCallbacks[r]=s.enterCallbacks[r]||[]);return()=>new Promise((l,c)=>{const d=p=>{p===!1?c(Bt(4,{from:n,to:t})):p instanceof Error?c(p):ku(p)?c(Bt(2,{from:t,to:p})):(i&&s.enterCallbacks[r]===i&&typeof p=="function"&&i.push(p),l())},a=o(()=>e.call(s&&s.instances[r],t,n,d));let h=Promise.resolve(a);e.length<3&&(h=h.then(d)),h.catch(p=>c(p))})}function ms(e,t,n,s,r=o=>o()){const o=[];for(const i of e)for(const l in i.components){let c=i.components[l];if(!(t!=="beforeRouteEnter"&&!i.instances[l]))if(vi(c)){const a=(c.__vccOpts||c)[t];a&&o.push(dt(a,n,s,i,l,r))}else{let d=c();o.push(()=>d.then(a=>{if(!a)throw new Error(`Couldn't resolve component "${l}" at "${i.path}"`);const h=ru(a)?a.default:a;i.mods[l]=a,i.components[l]=h;const g=(h.__vccOpts||h)[t];return g&&dt(g,n,s,i,l,r)()}))}}return o}function eo(e){const t=Le(es),n=Le(tr),s=Ne(()=>{const c=ve(e.to);return t.resolve(c)}),r=Ne(()=>{const{matched:c}=s.value,{length:d}=c,a=c[d-1],h=n.matched;if(!a||!h.length)return-1;const p=h.findIndex(Ut.bind(null,a));if(p>-1)return p;const g=to(c[d-2]);return d>1&&to(a)===g&&h[h.length-1].path!==g?h.findIndex(Ut.bind(null,c[d-2])):p}),o=Ne(()=>r.value>-1&&ta(n.params,s.value.params)),i=Ne(()=>r.value>-1&&r.value===n.matched.length-1&&wi(n.params,s.value.params));function l(c={}){if(ea(c)){const d=t[ve(e.replace)?"replace":"push"](ve(e.to)).catch(ln);return e.viewTransition&&typeof document<"u"&&"startViewTransition"in document&&document.startViewTransition(()=>d),d}return Promise.resolve()}return{route:s,href:Ne(()=>s.value.href),isActive:o,isExactActive:i,navigate:l}}function Xu(e){return e.length===1?e[0]:e}const Zu=yt({name:"RouterLink",compatConfig:{MODE:3},props:{to:{type:[String,Object],required:!0},replace:Boolean,activeClass:String,exactActiveClass:String,custom:Boolean,ariaCurrentValue:{type:String,default:"page"}},useLink:eo,setup(e,{slots:t}){const n=bn(eo(e)),{options:s}=Le(es),r=Ne(()=>({[no(e.activeClass,s.linkActiveClass,"router-link-active")]:n.isActive,[no(e.exactActiveClass,s.linkExactActiveClass,"router-link-exact-active")]:n.isExactActive}));return()=>{const o=t.default&&Xu(t.default(n));return e.custom?o:ai("a",{"aria-current":n.isExactActive?e.ariaCurrentValue:null,href:n.href,onClick:n.navigate,class:r.value},o)}}}),Ms=Zu;function ea(e){if(!(e.metaKey||e.altKey||e.ctrlKey||e.shiftKey)&&!e.defaultPrevented&&!(e.button!==void 0&&e.button!==0)){if(e.currentTarget&&e.currentTarget.getAttribute){const t=e.currentTarget.getAttribute("target");if(/\b_blank\b/i.test(t))return}return e.preventDefault&&e.preventDefault(),!0}}function ta(e,t){for(const n in t){const s=t[n],r=e[n];if(typeof s=="string"){if(s!==r)return!1}else if(!Ue(r)||r.length!==s.length||s.some((o,i)=>o!==r[i]))return!1}return!0}function to(e){return e?e.aliasOf?e.aliasOf.path:e.path:""}const no=(e,t,n)=>e??t??n,na=yt({name:"RouterView",inheritAttrs:!1,props:{name:{type:String,default:"default"},route:Object},compatConfig:{MODE:3},setup(e,{attrs:t,slots:n}){const s=Le($s),r=Ne(()=>e.route||s.value),o=Le(Zr,0),i=Ne(()=>{let d=ve(o);const{matched:a}=r.value;let h;for(;(h=a[d])&&!h.components;)d++;return d}),l=Ne(()=>r.value.matched[i.value]);On(Zr,Ne(()=>i.value+1)),On(Yu,l),On($s,r);const c=de();return nn(()=>[c.value,l.value,e.name],([d,a,h],[p,g,R])=>{a&&(a.instances[h]=d,g&&g!==a&&d&&d===p&&(a.leaveGuards.size||(a.leaveGuards=g.leaveGuards),a.updateGuards.size||(a.updateGuards=g.updateGuards))),d&&a&&(!g||!Ut(a,g)||!p)&&(a.enterCallbacks[h]||[]).forEach(E=>E(d))},{flush:"post"}),()=>{const d=r.value,a=e.name,h=l.value,p=h&&h.components[a];if(!p)return so(n.default,{Component:p,route:d});const g=h.props[a],R=g?g===!0?d.params:typeof g=="function"?g(d):g:null,A=ai(p,X({},R,t,{onVnodeUnmounted:M=>{M.component.isUnmounted&&(h.instances[a]=null)},ref:c}));return so(n.default,{Component:A,route:d})||A}}});function so(e,t){if(!e)return null;const n=e(t);return n.length===1?n[0]:n}const Oi=na;function sa(e){const t=Ku(e.routes,e),n=e.parseQuery||Ju,s=e.stringifyQuery||Xr,r=e.history,o=Jt(),i=Jt(),l=Jt(),c=ul(ct);let d=ct;kt&&e.scrollBehavior&&"scrollRestoration"in history&&(history.scrollRestoration="manual");const a=ps.bind(null,_=>""+_),h=ps.bind(null,vu),p=ps.bind(null,mn);function g(_,k){let I,L;return Ci(_)?(I=t.getRecordMatcher(_),L=k):L=_,t.addRoute(L,I)}function R(_){const k=t.getRecordMatcher(_);k&&t.removeRoute(k)}function E(){return t.getRoutes().map(_=>_.record)}function A(_){return!!t.getRecordMatcher(_)}function M(_,k){if(k=X({},k||c.value),typeof _=="string"){const f=gs(n,_,k.path),m=t.resolve({path:f.path},k),b=r.createHref(f.fullPath);return X(f,m,{params:p(m.params),hash:mn(f.hash),redirectedFrom:void 0,href:b})}let I;if(_.path!=null)I=X({},_,{path:gs(n,_.path,k.path).path});else{const f=X({},_.params);for(const m in f)f[m]==null&&delete f[m];I=X({},_,{params:h(f)}),k.params=h(k.params)}const L=t.resolve(I,k),ee=_.hash||"";L.params=a(p(L.params));const ae=bu(s,X({},_,{hash:pu(ee),path:L.path})),u=r.createHref(ae);return X({fullPath:ae,hash:ee,query:s===Xr?Qu(_.query):_.query||{}},L,{redirectedFrom:void 0,href:u})}function F(_){return typeof _=="string"?gs(n,_,c.value.path):X({},_)}function D(_,k){if(d!==_)return Bt(8,{from:k,to:_})}function N(_){return z(_)}function q(_){return N(X(F(_),{replace:!0}))}function pe(_){const k=_.matched[_.matched.length-1];if(k&&k.redirect){const{redirect:I}=k;let L=typeof I=="function"?I(_):I;return typeof L=="string"&&(L=L.includes("?")||L.includes("#")?L=F(L):{path:L},L.params={}),X({query:_.query,hash:_.hash,params:L.path!=null?{}:_.params},L)}}function z(_,k){const I=d=M(_),L=c.value,ee=_.state,ae=_.force,u=_.replace===!0,f=pe(I);if(f)return z(X(F(f),{state:typeof f=="object"?X({},ee,f.state):ee,force:ae,replace:u}),k||I);const m=I;m.redirectedFrom=k;let b;return!ae&&xu(s,L,I)&&(b=Bt(16,{to:m,from:L}),Ke(L,L,!0,!1)),(b?Promise.resolve(b):O(m,L)).catch(v=>tt(v)?tt(v,2)?v:lt(v):Y(v,m,L)).then(v=>{if(v){if(tt(v,2))return z(X({replace:u},F(v.to),{state:typeof v.to=="object"?X({},ee,v.to.state):ee,force:ae}),k||m)}else v=Q(m,L,!0,u,ee);return re(m,L,v),v})}function j(_,k){const I=D(_,k);return I?Promise.reject(I):Promise.resolve()}function S(_){const k=Tt.values().next().value;return k&&typeof k.runWithContext=="function"?k.runWithContext(_):_()}function O(_,k){let I;const[L,ee,ae]=ra(_,k);I=ms(L.reverse(),"beforeRouteLeave",_,k);for(const f of L)f.leaveGuards.forEach(m=>{I.push(dt(m,_,k))});const u=j.bind(null,_,k);return I.push(u),ke(I).then(()=>{I=[];for(const f of o.list())I.push(dt(f,_,k));return I.push(u),ke(I)}).then(()=>{I=ms(ee,"beforeRouteUpdate",_,k);for(const f of ee)f.updateGuards.forEach(m=>{I.push(dt(m,_,k))});return I.push(u),ke(I)}).then(()=>{I=[];for(const f of ae)if(f.beforeEnter)if(Ue(f.beforeEnter))for(const m of f.beforeEnter)I.push(dt(m,_,k));else I.push(dt(f.beforeEnter,_,k));return I.push(u),ke(I)}).then(()=>(_.matched.forEach(f=>f.enterCallbacks={}),I=ms(ae,"beforeRouteEnter",_,k,S),I.push(u),ke(I))).then(()=>{I=[];for(const f of i.list())I.push(dt(f,_,k));return I.push(u),ke(I)}).catch(f=>tt(f,8)?f:Promise.reject(f))}function re(_,k,I){l.list().forEach(L=>S(()=>L(_,k,I)))}function Q(_,k,I,L,ee){const ae=D(_,k);if(ae)return ae;const u=k===ct,f=kt?history.state:{};I&&(L||u?r.replace(_.fullPath,X({scroll:u&&f&&f.scroll},ee)):r.push(_.fullPath,ee)),c.value=_,Ke(_,k,I,u),lt()}let fe;function Xe(){fe||(fe=r.listen((_,k,I)=>{if(!wn.listening)return;const L=M(_),ee=pe(L);if(ee){z(X(ee,{replace:!0,force:!0}),L).catch(ln);return}d=L;const ae=c.value;kt&&Ou(Br(ae.fullPath,I.delta),Zn()),O(L,ae).catch(u=>tt(u,12)?u:tt(u,2)?(z(X(F(u.to),{force:!0}),L).then(f=>{tt(f,20)&&!I.delta&&I.type===vn.pop&&r.go(-1,!1)}).catch(ln),Promise.reject()):(I.delta&&r.go(-I.delta,!1),Y(u,L,ae))).then(u=>{u=u||Q(L,ae,!1),u&&(I.delta&&!tt(u,8)?r.go(-I.delta,!1):I.type===vn.pop&&tt(u,20)&&r.go(-1,!1)),re(L,ae,u)}).catch(ln)}))}let Be=Jt(),oe=Jt(),W;function Y(_,k,I){lt(_);const L=oe.list();return L.length?L.forEach(ee=>ee(_,k,I)):console.error(_),Promise.reject(_)}function Ze(){return W&&c.value!==ct?Promise.resolve():new Promise((_,k)=>{Be.add([_,k])})}function lt(_){return W||(W=!_,Xe(),Be.list().forEach(([k,I])=>_?I(_):k()),Be.reset()),_}function Ke(_,k,I,L){const{scrollBehavior:ee}=e;if(!kt||!ee)return Promise.resolve();const ae=!I&&Tu(Br(_.fullPath,0))||(L||!I)&&history.state&&history.state.scroll||null;return qn().then(()=>ee(_,k,ae)).then(u=>u&&Au(u)).catch(u=>Y(u,_,k))}const Ae=_=>r.go(_);let Ot;const Tt=new Set,wn={currentRoute:c,listening:!0,addRoute:g,removeRoute:R,clearRoutes:t.clearRoutes,hasRoute:A,getRoutes:E,resolve:M,options:e,push:N,replace:q,go:Ae,back:()=>Ae(-1),forward:()=>Ae(1),beforeEach:o.add,beforeResolve:i.add,afterEach:l.add,onError:oe.add,isReady:Ze,install(_){const k=this;_.component("RouterLink",Ms),_.component("RouterView",Oi),_.config.globalProperties.$router=k,Object.defineProperty(_.config.globalProperties,"$route",{enumerable:!0,get:()=>ve(c)}),kt&&!Ot&&c.value===ct&&(Ot=!0,N(r.location).catch(ee=>{}));const I={};for(const ee in ct)Object.defineProperty(I,ee,{get:()=>c.value[ee],enumerable:!0});_.provide(es,k),_.provide(tr,Io(I)),_.provide($s,c);const L=_.unmount;Tt.add(_),_.unmount=function(){Tt.delete(_),Tt.size<1&&(d=ct,fe&&fe(),fe=null,c.value=ct,Ot=!1,W=!1),L()}}};function ke(_){return _.reduce((k,I)=>k.then(()=>S(I)),Promise.resolve())}return wn}function ra(e,t){const n=[],s=[],r=[],o=Math.max(t.matched.length,e.matched.length);for(let i=0;i<o;i++){const l=t.matched[i];l&&(e.matched.find(d=>Ut(d,l))?s.push(l):n.push(l));const c=e.matched[i];c&&(t.matched.find(d=>Ut(d,c))||r.push(c))}return[n,s,r]}function nr(){return Le(es)}function Ti(e){return Le(tr)}const oa={class:"sidebar"},ia=yt({__name:"NavSidebar",setup(e){const t=Ti();return(n,s)=>(ne(),se("nav",oa,[_e(ve(Ms),{to:"/",class:Dt(["nav-item",{active:ve(t).path==="/"}])},{default:xs(()=>s[0]||(s[0]=[hn(" 仪表盘 ")])),_:1},8,["class"]),_e(ve(Ms),{to:"/apis",class:Dt(["nav-item",{active:ve(t).path.startsWith("/apis")}])},{default:xs(()=>s[1]||(s[1]=[hn(" API管理 ")])),_:1},8,["class"])]))}}),Wt=(e,t)=>{const n=e.__vccOpts||e;for(const[s,r]of t)n[s]=r;return n},la=Wt(ia,[["__scopeId","data-v-333258da"]]),ca={class:"app-header"},ua=yt({__name:"AppHeader",setup(e){const t=nr(),n=()=>{t.push("/")};return(s,r)=>(ne(),se("header",ca,[y("div",{class:"logo",onClick:n},r[0]||(r[0]=[y("h1",null,"JSON API Mocker",-1)])),r[1]||(r[1]=y("div",{class:"right"},[y("a",{href:"https://github.com/Selteve/json-api-mocker",target:"_blank",class:"github-link"}," GitHub ")],-1))]))}}),aa=Wt(ua,[["__scopeId","data-v-ecbe1cbc"]]),fa={class:"app-container"},da={class:"main-container"},ha={class:"content"},pa=yt({__name:"App",setup(e){return(t,n)=>(ne(),se("div",fa,[_e(aa),y("div",da,[_e(la),y("main",ha,[_e(ve(Oi))])])]))}}),ga=Wt(pa,[["__scopeId","data-v-32f4c818"]]),Pn=`http://${window.location.hostname}:3000`,sr=su("api",()=>{const e=de([]),t=de(!1),n=de(null);async function s(){t.value=!0;try{const i=await fetch(`${Pn}/api/_config`);e.value=await i.json()}catch(i){n.value=i instanceof Error?i.message:"获取API配置失败"}finally{t.value=!1}}async function r(i){var l,c;t.value=!0;try{const d=i.id?`${Pn}/api/_config/${i.id}`:`${Pn}/api/_config`,a={route:{path:((l=i.route)==null?void 0:l.path)||"",methods:((c=i.route)==null?void 0:c.methods)||{}}};if(!(await fetch(d,{method:i.id?"PUT":"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)})).ok)throw new Error("保存失败");await s()}catch(d){n.value=d instanceof Error?d.message:"保存API配置失败"}finally{t.value=!1}}async function o(i){t.value=!0;try{if(!(await fetch(`${Pn}/api/_config/${i}`,{method:"DELETE"})).ok)throw new Error("删除失败");await s()}catch(l){n.value=l instanceof Error?l.message:"删除API配置失败"}finally{t.value=!1}}return{apis:e,loading:t,error:n,fetchApis:s,saveApi:r,deleteApi:o}}),ma={class:"api-list"},va={key:0,class:"loading"},_a={key:1,class:"error"},ya={key:2,class:"list"},ba={key:0,class:"empty"},xa={key:0,class:"api-info"},Sa={key:0,class:"methods"},wa={class:"actions"},Ea=["onClick"],Ca=["onClick"],Ra=yt({__name:"ApiList",setup(e){const t=nr(),n=sr();zn(()=>{n.fetchApis()});const s=i=>{t.push(`/apis/${i}`)},r=()=>{t.push("/apis/new")},o=async i=>{confirm("确定要删除这个API吗?")&&await n.deleteApi(i)};return(i,l)=>(ne(),se("div",ma,[y("div",{class:"header"},[l[0]||(l[0]=y("h1",null,"API列表",-1)),y("button",{onClick:r,class:"create-btn"},"创建新API")]),ve(n).loading?(ne(),se("div",va," 加载中... ")):ve(n).error?(ne(),se("div",_a,ge(ve(n).error),1)):(ne(),se("div",ya,[!ve(n).apis||ve(n).apis.length===0?(ne(),se("div",ba," 暂无API配置,点击上方按钮创建 ")):(ne(!0),se(we,{key:1},wt(ve(n).apis,c=>(ne(),se("div",{key:c.id,class:"api-item"},[c&&c.route?(ne(),se("div",xa,[y("h3",null,ge(c.route.path),1),c.route.methods?(ne(),se("div",Sa,[(ne(!0),se(we,null,wt(Object.keys(c.route.methods),d=>(ne(),se("span",{key:d,class:"method-tag"},ge(d.toUpperCase()),1))),128))])):rn("",!0)])):rn("",!0),y("div",wa,[y("button",{onClick:d=>s(c.id),class:"edit-btn"},"编辑",8,Ea),y("button",{onClick:d=>o(c.id),class:"delete-btn"},"删除",8,Ca)])]))),128))]))]))}}),Pa=Wt(Ra,[["__scopeId","data-v-f00969e3"]]),Aa={class:"api-editor"},Oa={class:"header"},Ta={class:"form"},Ia={class:"form-group"},$a={class:"form-group"},Ma=["value"],ja={class:"form-group"},ka=["value"],Na={class:"form-group"},Fa={key:0,class:"pagination-settings"},La={key:0,class:"form-group"},Da={key:0,class:"data-count-settings"},Ha={class:"form-group"},Va=["onUpdate:modelValue"],Ua=["onUpdate:modelValue"],Ba=["value"],Ka=["onUpdate:modelValue","placeholder"],Wa=["onClick"],qa={class:"form-group"},Ga=["value"],za={class:"actions"},Ja=yt({__name:"ApiEditor",setup(e){const t=Ti(),n=nr(),s=sr(),r=de({id:"",route:{path:"",methods:{}}}),o=t.params.id!==void 0,i=["get","post","put","delete","patch","options"],l=de("get"),c=[{label:"默认JSON格式",value:{"Content-Type":"application/json"}},{label:"允许跨域",value:{"Access-Control-Allow-Origin":"*"}},{label:"文件上传",value:{"Content-Type":"multipart/form-data"}}],d=[{label:"文本",value:"string"},{label:"数字",value:"number"},{label:"布尔值",value:"boolean"},{label:"日期时间",value:"datetime"},{label:"图片URL",value:"image"},{label:"邮箱",value:"email"},{label:"手机机号",value:"phone"},{label:"中文名",value:"cname"},{label:"英文名",value:"name"},{label:"地址",value:"address"},{label:"ID",value:"id"}],a=de([]),h=de(!1),p=de(10),g=de(100),R=de(1),E=de(!1),A=()=>{a.value.push({name:"",type:"string",mock:""})},M=j=>{a.value.splice(j,1)},F=j=>{switch(j){case"string":return"@string(5,10)";case"number":return"@integer(1,100)";case"boolean":return"@boolean";case"datetime":return"@datetime";case"image":return'@image("200x200")';case"email":return"@email";case"phone":return"@phone";case"cname":return"@cname";case"name":return"@name";case"address":return"@county(true)";case"id":return"@id";default:return"@string"}},D=()=>{const j={code:200,message:"success",data:{}};return h.value?j.data={total:`@integer(${g.value}, ${g.value+100})`,[`list|${p.value}`]:[{...a.value.length>0?a.value.reduce((S,O)=>({...S,[O.name]:O.mock||F(O.type)}),{}):{id:"@id",name:"@name",created_at:"@datetime"}}]}:E.value?j.data={[`list|${R.value}`]:[{...a.value.length>0?a.value.reduce((S,O)=>({...S,[O.name]:O.mock||F(O.type)}),{}):{id:"@id",name:"@name",created_at:"@datetime"}}]}:j.data=a.value.length>0?a.value.reduce((S,O)=>({...S,[O.name]:O.mock||F(O.type)}),{}):{id:"@id",name:"@name",created_at:"@datetime"},JSON.stringify(j,null,2)},N=de(c[0].value),q=j=>{r.value.route.methods[l.value]?r.value.route.methods[l.value].headers=j:r.value.route.methods[l.value]={status:200,response:"",headers:j}},pe=async()=>{r.value.route.methods[l.value]={status:200,response:D(),headers:N.value},console.log("Saving API config:",r.value),await s.saveApi(r.value),n.push("/apis")};zn(async()=>{if(o){await s.fetchApis();const j=s.apis.find(S=>S.id===t.params.id);if(j){r.value=JSON.parse(JSON.stringify(j));const S=Object.keys(j.route.methods);if(S.length>0){l.value=S[0];const O=j.route.methods[l.value];N.value=O.headers||c[0].value;try{const re=JSON.parse(O.response);if(re.data.list){const Q=Object.keys(re.data).find(fe=>fe.startsWith("list|"));if(Q){const fe=parseInt(Q.split("|")[1]);re.data.total?(h.value=!0,p.value=fe,g.value=parseInt(re.data.total)||100):(E.value=!0,R.value=fe);const Xe=re.data[Q][0];a.value=Object.entries(Xe).map(([Be,oe])=>({name:Be,type:z(oe),mock:oe}))}}else a.value=Object.entries(re.data).map(([Q,fe])=>({name:Q,type:z(fe),mock:fe}))}catch(re){console.error("Error parsing response data:",re)}}}}});const z=j=>typeof j!="string"?"string":j.includes("@cname")?"cname":j.includes("@name")?"name":j.includes("@email")?"email":j.includes("@phone")?"phone":j.includes("@integer")?"number":j.includes("@datetime")?"datetime":j.includes("@image")?"image":j.includes("@id")?"id":j.includes("@county")?"address":j.includes("@boolean")?"boolean":"string";return(j,S)=>(ne(),se("div",Aa,[y("div",Oa,[y("h1",null,ge(o?"编辑":"创建")+"API",1)]),y("div",Ta,[y("div",Ia,[S[10]||(S[10]=y("label",null,"API路径",-1)),He(y("input",{"onUpdate:modelValue":S[0]||(S[0]=O=>r.value.route.path=O),placeholder:"/your-path",class:"input"},null,512),[[$t,r.value.route.path]]),S[11]||(S[11]=y("div",{class:"helper-text"}," 不需要输入基础路径(/api),它会自动添加 ",-1))]),y("div",$a,[S[12]||(S[12]=y("label",null,"HTTP方法",-1)),He(y("select",{"onUpdate:modelValue":S[1]||(S[1]=O=>l.value=O),class:"input"},[(ne(),se(we,null,wt(i,O=>y("option",{key:O,value:O},ge(O.toUpperCase()),9,Ma)),64))],512),[[ds,l.value]])]),y("div",ja,[S[13]||(S[13]=y("label",null,"响应头",-1)),He(y("select",{"onUpdate:modelValue":S[2]||(S[2]=O=>N.value=O),class:"input",onChange:S[3]||(S[3]=O=>q(O.target.value))},[(ne(),se(we,null,wt(c,O=>y("option",{key:O.label,value:O.value},ge(O.label),9,ka)),64))],544),[[ds,N.value]])]),y("div",Na,[y("label",null,[He(y("input",{type:"checkbox","onUpdate:modelValue":S[4]||(S[4]=O=>h.value=O)},null,512),[[kr,h.value]]),S[14]||(S[14]=hn(" 启用分页 "))]),h.value?(ne(),se("div",Fa,[y("div",null,[S[15]||(S[15]=y("label",null,"每页数量",-1)),He(y("input",{type:"number","onUpdate:modelValue":S[5]||(S[5]=O=>p.value=O),class:"input"},null,512),[[$t,p.value]])]),y("div",null,[S[16]||(S[16]=y("label",null,"总数范围",-1)),He(y("input",{type:"number","onUpdate:modelValue":S[6]||(S[6]=O=>g.value=O),class:"input"},null,512),[[$t,g.value]])])])):rn("",!0)]),h.value?rn("",!0):(ne(),se("div",La,[y("label",null,[He(y("input",{type:"checkbox","onUpdate:modelValue":S[7]||(S[7]=O=>E.value=O)},null,512),[[kr,E.value]]),S[17]||(S[17]=hn(" 生成多条数据 "))]),E.value?(ne(),se("div",Da,[y("div",null,[S[18]||(S[18]=y("label",null,"数据条数",-1)),He(y("input",{type:"number","onUpdate:modelValue":S[8]||(S[8]=O=>R.value=O),class:"input",min:"1",max:1e3},null,512),[[$t,R.value]])]),S[19]||(S[19]=y("div",{class:"helper-text"}," 设置要生成的数据条数(1-1000) ",-1))])):rn("",!0)])),y("div",Ha,[y("div",{class:"fields-header"},[S[20]||(S[20]=y("label",null,"响应字段",-1)),y("button",{onClick:A,class:"add-btn"},"添加字段")]),(ne(!0),se(we,null,wt(a.value,(O,re)=>(ne(),se("div",{key:re,class:"field-item"},[He(y("input",{"onUpdate:modelValue":Q=>O.name=Q,placeholder:"字段名",class:"input field-name"},null,8,Va),[[$t,O.name]]),He(y("select",{"onUpdate:modelValue":Q=>O.type=Q,class:"input field-type"},[(ne(),se(we,null,wt(d,Q=>y("option",{key:Q.value,value:Q.value},ge(Q.label),9,Ba)),64))],8,Ua),[[ds,O.type]]),He(y("input",{"onUpdate:modelValue":Q=>O.mock=Q,placeholder:F(O.type),class:"input field-mock"},null,8,Ka),[[$t,O.mock]]),y("button",{onClick:Q=>M(re),class:"remove-btn"},"删除",8,Wa)]))),128))]),y("div",qa,[S[21]||(S[21]=y("label",null,"响应数据预览",-1)),y("textarea",{value:D(),readonly:"",class:"preview-textarea"},null,8,Ga)]),y("div",za,[y("button",{onClick:S[9]||(S[9]=O=>ve(n).push("/apis")),class:"cancel-btn"},"取消"),y("button",{onClick:pe,class:"save-btn"},"保存")])])]))}}),ro=Wt(Ja,[["__scopeId","data-v-d5d7a1e1"]]),Qa={class:"dashboard"},Ya={class:"stats"},Xa={class:"stat-card"},Za={class:"stat-value"},ef={class:"stat-card"},tf={class:"stat-value"},nf={class:"stat-card"},sf={class:"stat-value"},rf={class:"stat-card"},of={class:"stat-value"},lf={class:"logs-section"},cf={key:0,class:"logs-table"},uf={class:"params"},af={class:"pagination"},ff=["disabled"],df=["disabled"],hf={key:1,class:"empty-logs"},pf=yt({__name:"Dashboard",setup(e){const t=sr(),n=de([]),s=de(null),r=de(!1),o=de(1),i=de(20),l=de(0),c=de({totalApis:0,totalRequests:0,averageResponseTime:0,successRate:0}),d=async()=>{r.value=!0;try{const A=await(await fetch(`http://localhost:8080/api/_logs?page=${o.value}&size=${i.value}`)).json();n.value=A.list,l.value=A.total}catch(E){console.error("Failed to fetch logs:",E)}finally{r.value=!1}},a=async()=>{if(confirm("确定要清除所有日志吗?"))try{await fetch("http://localhost:8080/api/_logs",{method:"DELETE"}),await d()}catch(E){console.error("Failed to clear logs:",E)}},h=()=>{c.value={totalApis:t.apis.length,totalRequests:l.value,averageResponseTime:n.value.reduce((E,A)=>E+A.duration,0)/n.value.length||0,successRate:n.value.filter(E=>E.status<400).length/n.value.length*100||0}},p=E=>new Date(E).toLocaleString(),g=E=>{o.value=E,d()},R=()=>{s.value=new WebSocket(`ws://${window.location.hostname}:35730`),s.value.onmessage=E=>{const A=JSON.parse(E.data);A.type==="init"?(n.value=A.data,l.value=A.data.length,h()):A.type==="log"&&(n.value.unshift(A.data),l.value++,h())},s.value.onclose=()=>{setTimeout(R,3e3)}};return zn(async()=>{await t.fetchApis(),R()}),Qs(()=>{s.value&&s.value.close()}),(E,A)=>(ne(),se("div",Qa,[A[8]||(A[8]=y("h1",null,"仪表盘",-1)),y("div",Ya,[y("div",Xa,[A[2]||(A[2]=y("h3",null,"API总数",-1)),y("div",Za,ge(c.value.totalApis),1)]),y("div",ef,[A[3]||(A[3]=y("h3",null,"总请求数",-1)),y("div",tf,ge(c.value.totalRequests),1)]),y("div",nf,[A[4]||(A[4]=y("h3",null,"平均响应时间",-1)),y("div",sf,ge(c.value.averageResponseTime.toFixed(2))+"ms",1)]),y("div",rf,[A[5]||(A[5]=y("h3",null,"成功率",-1)),y("div",of,ge(c.value.successRate.toFixed(2))+"%",1)])]),y("div",lf,[y("div",{class:"logs-header"},[A[6]||(A[6]=y("h2",null,"请求日志",-1)),y("button",{onClick:a,class:"clear-btn"},"清除日志")]),n.value.length>0?(ne(),se("div",cf,[y("table",null,[A[7]||(A[7]=y("thead",null,[y("tr",null,[y("th",null,"时间"),y("th",null,"路径"),y("th",null,"方法"),y("th",null,"参数"),y("th",null,"状态"),y("th",null,"耗时")])],-1)),y("tbody",null,[(ne(!0),se(we,null,wt(n.value,M=>(ne(),se("tr",{key:M.id},[y("td",null,ge(p(M.timestamp)),1),y("td",null,ge(M.path),1),y("td",null,ge(M.method),1),y("td",null,[y("pre",uf,ge(JSON.stringify(M.params,null,2)),1)]),y("td",{class:Dt({success:M.status<400,error:M.status>=400})},ge(M.status),3),y("td",null,ge(M.duration)+"ms",1)]))),128))])]),y("div",af,[y("button",{disabled:o.value===1,onClick:A[0]||(A[0]=M=>g(o.value-1))}," 上一页 ",8,ff),y("span",null,ge(o.value)+" / "+ge(Math.ceil(l.value/i.value)),1),y("button",{disabled:o.value>=Math.ceil(l.value/i.value),onClick:A[1]||(A[1]=M=>g(o.value+1))}," 下一页 ",8,df)])])):(ne(),se("div",hf," 暂无请求日志 "))])]))}}),gf=Wt(pf,[["__scopeId","data-v-affa5733"]]),mf=sa({history:ju(),routes:[{path:"/",name:"dashboard",component:gf},{path:"/apis",name:"api-list",component:Pa},{path:"/apis/new",name:"api-new",component:ro},{path:"/apis/:id",name:"api-edit",component:ro}]}),rr=Gc(ga);rr.use(Yc());rr.use(mf);rr.mount("#app");
|
package/web/index.html
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
7
7
|
<title>JSON API Mocker</title>
|
8
8
|
<script src="./monaco-editor-worker-loader.js"></script>
|
9
|
-
<script type="module" crossorigin src="./assets/index-
|
9
|
+
<script type="module" crossorigin src="./assets/index-DWg8IDX3.js"></script>
|
10
10
|
<link rel="stylesheet" crossorigin href="./assets/index-txmJK3Dz.css">
|
11
11
|
</head>
|
12
12
|
<body>
|