@yuku123/z-frontend-common 0.2.0 → 0.2.2

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.
@@ -1,4 +1,4 @@
1
- (function(B,r){typeof exports=="object"&&typeof module<"u"?r(exports,require("react"),require("antd"),require("@ant-design/icons"),require("react-router-dom"),require("axios"),require("@ant-design/pro-components")):typeof define=="function"&&define.amd?define(["exports","react","antd","@ant-design/icons","react-router-dom","axios","@ant-design/pro-components"],r):(B=typeof globalThis<"u"?globalThis:B||self,r(B.ZFrontendCommon={},B.React,B.antd,B.icons,B.ReactRouterDOM,B.axios,B.ProComponents))})(this,(function(B,r,s,i,se,Ve,me){"use strict";var qt=Object.defineProperty;var Gt=(B,r,s)=>r in B?qt(B,r,{enumerable:!0,configurable:!0,writable:!0,value:s}):B[r]=s;var vs=(B,r,s)=>Gt(B,typeof r!="symbol"?r+"":r,s);var Oe={exports:{}},we={};/**
1
+ (function(q,p){typeof exports=="object"&&typeof module<"u"?p(exports,require("react"),require("antd"),require("@ant-design/icons"),require("react-router-dom"),require("@ant-design/pro-components")):typeof define=="function"&&define.amd?define(["exports","react","antd","@ant-design/icons","react-router-dom","@ant-design/pro-components"],p):(q=typeof globalThis<"u"?globalThis:q||self,p(q.ZFrontendCommon={},q.React,q.antd,q.icons,q.ReactRouterDOM,q.ProComponents))})(this,(function(q,p,t,g,ue,Fe){"use strict";var yl=Object.defineProperty;var jl=(q,p,t)=>p in q?yl(q,p,{enumerable:!0,configurable:!0,writable:!0,value:t}):q[p]=t;var lr=(q,p,t)=>jl(q,typeof p!="symbol"?p+"":p,t);var ot={exports:{}},Ve={};/**
2
2
  * @license React
3
3
  * react-jsx-runtime.production.js
4
4
  *
@@ -6,7 +6,7 @@
6
6
  *
7
7
  * This source code is licensed under the MIT license found in the
8
8
  * LICENSE file in the root directory of this source tree.
9
- */var Xe;function Es(){if(Xe)return we;Xe=1;var t=Symbol.for("react.transitional.element"),a=Symbol.for("react.fragment");function l(j,I,C){var d=null;if(C!==void 0&&(d=""+C),I.key!==void 0&&(d=""+I.key),"key"in I){C={};for(var g in I)g!=="key"&&(C[g]=I[g])}else C=I;return I=C.ref,{$$typeof:t,type:j,key:d,ref:I!==void 0?I:null,props:C}}return we.Fragment=a,we.jsx=l,we.jsxs=l,we}var Ie={};/**
9
+ */var Ht;function cr(){if(Ht)return Ve;Ht=1;var s=Symbol.for("react.transitional.element"),r=Symbol.for("react.fragment");function n(o,l,a){var i=null;if(a!==void 0&&(i=""+a),l.key!==void 0&&(i=""+l.key),"key"in l){a={};for(var c in l)c!=="key"&&(a[c]=l[c])}else a=l;return l=a.ref,{$$typeof:s,type:o,key:i,ref:l!==void 0?l:null,props:a}}return Ve.Fragment=r,Ve.jsx=n,Ve.jsxs=n,Ve}var Ke={};/**
10
10
  * @license React
11
11
  * react-jsx-runtime.development.js
12
12
  *
@@ -14,27 +14,35 @@
14
14
  *
15
15
  * This source code is licensed under the MIT license found in the
16
16
  * LICENSE file in the root directory of this source tree.
17
- */var Ze;function Os(){return Ze||(Ze=1,process.env.NODE_ENV!=="production"&&(function(){function t(c){if(c==null)return null;if(typeof c=="function")return c.$$typeof===n?null:c.displayName||c.name||null;if(typeof c=="string")return c;switch(c){case E:return"Fragment";case T:return"Profiler";case N:return"StrictMode";case M:return"Suspense";case U:return"SuspenseList";case o:return"Activity"}if(typeof c=="object")switch(typeof c.tag=="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),c.$$typeof){case $:return"Portal";case P:return c.displayName||"Context";case w:return(c._context.displayName||"Context")+".Consumer";case S:var D=c.render;return c=c.displayName,c||(c=D.displayName||D.name||"",c=c!==""?"ForwardRef("+c+")":"ForwardRef"),c;case J:return D=c.displayName||null,D!==null?D:t(c.type)||"Memo";case H:D=c._payload,c=c._init;try{return t(c(D))}catch{}}return null}function a(c){return""+c}function l(c){try{a(c);var D=!1}catch{D=!0}if(D){D=console;var R=D.error,W=typeof Symbol=="function"&&Symbol.toStringTag&&c[Symbol.toStringTag]||c.constructor.name||"Object";return R.call(D,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",W),a(c)}}function j(c){if(c===E)return"<>";if(typeof c=="object"&&c!==null&&c.$$typeof===H)return"<...>";try{var D=t(c);return D?"<"+D+">":"<...>"}catch{return"<...>"}}function I(){var c=L.A;return c===null?null:c.getOwner()}function C(){return Error("react-stack-top-frame")}function d(c){if(b.call(c,"key")){var D=Object.getOwnPropertyDescriptor(c,"key").get;if(D&&D.isReactWarning)return!1}return c.key!==void 0}function g(c,D){function R(){re||(re=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",D))}R.isReactWarning=!0,Object.defineProperty(c,"key",{get:R,configurable:!0})}function v(){var c=t(this.type);return ae[c]||(ae[c]=!0,console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")),c=this.props.ref,c!==void 0?c:null}function f(c,D,R,W,te,ce){var Z=R.ref;return c={$$typeof:y,type:c,key:D,props:R,_owner:W},(Z!==void 0?Z:null)!==null?Object.defineProperty(c,"ref",{enumerable:!1,get:v}):Object.defineProperty(c,"ref",{enumerable:!1,value:null}),c._store={},Object.defineProperty(c._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(c,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(c,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:te}),Object.defineProperty(c,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:ce}),Object.freeze&&(Object.freeze(c.props),Object.freeze(c)),c}function O(c,D,R,W,te,ce){var Z=D.children;if(Z!==void 0)if(W)if(A(Z)){for(W=0;W<Z.length;W++)m(Z[W]);Object.freeze&&Object.freeze(Z)}else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else m(Z);if(b.call(D,"key")){Z=t(c);var de=Object.keys(D).filter(function(he){return he!=="key"});W=0<de.length?"{key: someKey, "+de.join(": ..., ")+": ...}":"{key: someKey}",p[Z+W]||(de=0<de.length?"{"+de.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
17
+ */var Wt;function dr(){return Wt||(Wt=1,process.env.NODE_ENV!=="production"&&(function(){function s(j){if(j==null)return null;if(typeof j=="function")return j.$$typeof===f?null:j.displayName||j.name||null;if(typeof j=="string")return j;switch(j){case C:return"Fragment";case w:return"Profiler";case S:return"StrictMode";case R:return"Suspense";case H:return"SuspenseList";case m:return"Activity"}if(typeof j=="object")switch(typeof j.tag=="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),j.$$typeof){case _:return"Portal";case A:return j.displayName||"Context";case T:return(j._context.displayName||"Context")+".Consumer";case k:var L=j.render;return j=j.displayName,j||(j=L.displayName||L.name||"",j=j!==""?"ForwardRef("+j+")":"ForwardRef"),j;case Y:return L=j.displayName||null,L!==null?L:s(j.type)||"Memo";case K:L=j._payload,j=j._init;try{return s(j(L))}catch{}}return null}function r(j){return""+j}function n(j){try{r(j);var L=!1}catch{L=!0}if(L){L=console;var $=L.error,V=typeof Symbol=="function"&&Symbol.toStringTag&&j[Symbol.toStringTag]||j.constructor.name||"Object";return $.call(L,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",V),r(j)}}function o(j){if(j===C)return"<>";if(typeof j=="object"&&j!==null&&j.$$typeof===K)return"<...>";try{var L=s(j);return L?"<"+L+">":"<...>"}catch{return"<...>"}}function l(){var j=z.A;return j===null?null:j.getOwner()}function a(){return Error("react-stack-top-frame")}function i(j){if(P.call(j,"key")){var L=Object.getOwnPropertyDescriptor(j,"key").get;if(L&&L.isReactWarning)return!1}return j.key!==void 0}function c(j,L){function $(){oe||(oe=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",L))}$.isReactWarning=!0,Object.defineProperty(j,"key",{get:$,configurable:!0})}function x(){var j=s(this.type);return ge[j]||(ge[j]=!0,console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")),j=this.props.ref,j!==void 0?j:null}function h(j,L,$,V,ie,X){var Z=$.ref;return j={$$typeof:E,type:j,key:L,props:$,_owner:V},(Z!==void 0?Z:null)!==null?Object.defineProperty(j,"ref",{enumerable:!1,get:x}):Object.defineProperty(j,"ref",{enumerable:!1,value:null}),j._store={},Object.defineProperty(j._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(j,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(j,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:ie}),Object.defineProperty(j,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:X}),Object.freeze&&(Object.freeze(j.props),Object.freeze(j)),j}function y(j,L,$,V,ie,X){var Z=L.children;if(Z!==void 0)if(V)if(D(Z)){for(V=0;V<Z.length;V++)d(Z[V]);Object.freeze&&Object.freeze(Z)}else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else d(Z);if(P.call(L,"key")){Z=s(j);var fe=Object.keys(L).filter(function(Ie){return Ie!=="key"});V=0<fe.length?"{key: someKey, "+fe.join(": ..., ")+": ...}":"{key: someKey}",O[Z+V]||(fe=0<fe.length?"{"+fe.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
18
18
  let props = %s;
19
19
  <%s {...props} />
20
20
  React keys must be passed directly to JSX without using spread:
21
21
  let props = %s;
22
- <%s key={someKey} {...props} />`,W,Z,de,Z),p[Z+W]=!0)}if(Z=null,R!==void 0&&(l(R),Z=""+R),d(D)&&(l(D.key),Z=""+D.key),"key"in D){R={};for(var fe in D)fe!=="key"&&(R[fe]=D[fe])}else R=D;return Z&&g(R,typeof c=="function"?c.displayName||c.name||"Unknown":c),f(c,Z,R,I(),te,ce)}function m(c){h(c)?c._store&&(c._store.validated=1):typeof c=="object"&&c!==null&&c.$$typeof===H&&(c._payload.status==="fulfilled"?h(c._payload.value)&&c._payload.value._store&&(c._payload.value._store.validated=1):c._store&&(c._store.validated=1))}function h(c){return typeof c=="object"&&c!==null&&c.$$typeof===y}var z=r,y=Symbol.for("react.transitional.element"),$=Symbol.for("react.portal"),E=Symbol.for("react.fragment"),N=Symbol.for("react.strict_mode"),T=Symbol.for("react.profiler"),w=Symbol.for("react.consumer"),P=Symbol.for("react.context"),S=Symbol.for("react.forward_ref"),M=Symbol.for("react.suspense"),U=Symbol.for("react.suspense_list"),J=Symbol.for("react.memo"),H=Symbol.for("react.lazy"),o=Symbol.for("react.activity"),n=Symbol.for("react.client.reference"),L=z.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,b=Object.prototype.hasOwnProperty,A=Array.isArray,V=console.createTask?console.createTask:function(){return null};z={react_stack_bottom_frame:function(c){return c()}};var re,ae={},oe=z.react_stack_bottom_frame.bind(z,C)(),k=V(j(C)),p={};Ie.Fragment=E,Ie.jsx=function(c,D,R){var W=1e4>L.recentlyCreatedOwnerStacks++;return O(c,D,R,!1,W?Error("react-stack-top-frame"):oe,W?V(j(c)):k)},Ie.jsxs=function(c,D,R){var W=1e4>L.recentlyCreatedOwnerStacks++;return O(c,D,R,!0,W?Error("react-stack-top-frame"):oe,W?V(j(c)):k)}})()),Ie}var Qe;function Fs(){return Qe||(Qe=1,process.env.NODE_ENV==="production"?Oe.exports=Es():Oe.exports=Os()),Oe.exports}var e=Fs();const{Header:Ps,Sider:Ns,Content:As}=s.Layout;function Ds({menuItems:t=[],appTitle:a="One Company",appShort:l="OC",headerExtra:j,loading:I=!1}){const[C,d]=r.useState(!1),g=se.useNavigate(),v=se.useLocation(),f=({key:O})=>{g(O)};return e.jsxs(s.Layout,{style:{minHeight:"100vh"},children:[e.jsxs(Ns,{trigger:null,collapsible:!0,collapsed:C,children:[e.jsx("div",{style:{height:64,display:"flex",alignItems:"center",justifyContent:"center",color:"white",fontSize:C?14:18,fontWeight:"bold"},children:C?l:a}),I?e.jsx("div",{style:{padding:16,textAlign:"center"},children:e.jsx(s.Spin,{size:"small"})}):e.jsx(s.Menu,{theme:"dark",mode:"inline",selectedKeys:[v.pathname],items:t,onClick:f})]}),e.jsxs(s.Layout,{children:[e.jsxs(Ps,{style:{padding:"0 16px",background:"#fff",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsx("span",{onClick:()=>d(!C),style:{fontSize:18,cursor:"pointer"},children:C?e.jsx(i.MenuUnfoldOutlined,{}):e.jsx(i.MenuFoldOutlined,{})}),j]}),e.jsx(As,{style:{margin:16,padding:24,background:"#fff",minHeight:280},children:e.jsx(se.Outlet,{})})]})]})}const es={1:{color:"green",text:"正常"},0:{color:"red",text:"禁用"},pending:{color:"orange",text:"待处理"},approved:{color:"blue",text:"已通过"},rejected:{color:"red",text:"已拒绝"}};function zs({status:t,map:a}){const l=(a==null?void 0:a[t])||es[t]||{color:"default",text:String(t)};return e.jsx(s.Tag,{color:l.color,children:l.text})}function Ms(t){if(t&&typeof t=="object"&&"code"in t&&"data"in t){const a=t;return a.code!==200?Promise.reject(new Error(a.message||"请求失败")):a.data}return t}function ss(t,a={}){const{tokenKey:l="token",userInfoKey:j="userInfo",unauthorizedRedirect:I="/login"}=a;t.interceptors.request.use(C=>{const d=localStorage.getItem(l);return d&&(C.headers.Authorization=`Bearer ${d}`),C}),t.interceptors.response.use(C=>Ms(C.data),C=>{var d,g,v;return((d=C.response)==null?void 0:d.status)===401?(localStorage.removeItem(l),localStorage.removeItem(j),window.location.href=I):((g=C.response)==null?void 0:g.status)===403?console.error("没有权限访问该资源"):((v=C.response)==null?void 0:v.status)===500&&console.error("服务器内部错误"),Promise.reject(C)})}function Re(t={}){const a=Ve.create({baseURL:t.baseURL??"/api",timeout:t.timeout??1e4});return ss(a,{tokenKey:t.tokenKey,userInfoKey:t.userInfoKey,unauthorizedRedirect:t.unauthorizedRedirect}),a}const Y=Re(),Ue=Re();function Ls({title:t="统一管理平台",loginApi:a="/auth/login",redirectUrl:l="/",onSuccess:j}){const[I,C]=r.useState(!1),d=async g=>{var v,f;C(!0);try{const O=await Y.post(a,g);O.token?(localStorage.setItem("token",O.token),localStorage.setItem("userInfo",JSON.stringify(O.user||O)),s.message.success("登录成功"),j?j(O):window.location.href=l):s.message.error("登录失败:未获取到 token")}catch(O){s.message.error(((f=(v=O.response)==null?void 0:v.data)==null?void 0:f.message)||O.message||"登录失败")}finally{C(!1)}};return e.jsx("div",{style:{height:"100vh",display:"flex",justifyContent:"center",alignItems:"center",background:"#f0f2f5"},children:e.jsx(s.Card,{title:t,style:{width:400},children:e.jsxs(s.Form,{onFinish:d,size:"large",children:[e.jsx(s.Form.Item,{name:"username",rules:[{required:!0,message:"请输入用户名"}],children:e.jsx(s.Input,{prefix:e.jsx(i.UserOutlined,{}),placeholder:"用户名"})}),e.jsx(s.Form.Item,{name:"password",rules:[{required:!0,message:"请输入密码"}],children:e.jsx(s.Input.Password,{prefix:e.jsx(i.LockOutlined,{}),placeholder:"密码"})}),e.jsx(s.Form.Item,{children:e.jsx(s.Button,{type:"primary",htmlType:"submit",loading:I,block:!0,children:"登 录"})})]})})})}class _s extends r.Component{constructor(l){super(l);vs(this,"handleReset",()=>{this.setState({hasError:!1,error:null,errorInfo:null}),typeof this.props.onReset=="function"&&this.props.onReset()});this.state={hasError:!1,error:null,errorInfo:null}}static getDerivedStateFromError(l){return{hasError:!0,error:l}}componentDidCatch(l,j){console.error("[ErrorBoundary] caught error:",l,j),this.setState({errorInfo:j})}render(){if(!this.state.hasError)return this.props.children;const{fallbackTitle:l="组件加载失败",fallbackDescription:j,showReload:I=!0}=this.props,C=this.state.error&&(this.state.error.message||String(this.state.error))||"未知错误";return e.jsxs("div",{style:{padding:24,background:"#fff2f0",border:"1px solid #ffccc7",borderRadius:8,minHeight:200},children:[e.jsx(s.Alert,{type:"error",showIcon:!0,icon:e.jsx(i.BugOutlined,{}),message:l,description:e.jsxs("div",{children:[e.jsx("div",{style:{marginBottom:8},children:j||"当前组件发生了异常,已被错误边界捕获。其他功能仍可正常使用。"}),e.jsx("div",{style:{fontFamily:"Menlo, Monaco, Consolas, monospace",fontSize:12,color:"#cf1322",background:"#fff",padding:8,borderRadius:4,border:"1px solid #ffccc7",wordBreak:"break-word",whiteSpace:"pre-wrap"},children:C})]})}),I&&e.jsx(s.Space,{style:{marginTop:16},children:e.jsx(s.Button,{icon:e.jsx(i.ReloadOutlined,{}),onClick:this.handleReset,children:"重试"})})]})}}const{Title:Bs,Text:$s,Paragraph:ts}=s.Typography,Rs=()=>e.jsxs("div",{style:{padding:"0"},children:[e.jsxs("div",{style:{marginBottom:24},children:[e.jsx(Bs,{level:2,style:{margin:0},children:"Z-One Company 统一管理平台"}),e.jsx($s,{type:"secondary",children:"一站式企业级应用管理平台"})]}),e.jsxs(s.Row,{gutter:16,style:{marginBottom:24},children:[e.jsx(s.Col,{span:6,children:e.jsx(s.Card,{children:e.jsx(s.Statistic,{title:"配置中心",value:0,prefix:e.jsx(i.SettingOutlined,{})})})}),e.jsx(s.Col,{span:6,children:e.jsx(s.Card,{children:e.jsx(s.Statistic,{title:"任务中心",value:0,prefix:e.jsx(i.FileTextOutlined,{})})})}),e.jsx(s.Col,{span:6,children:e.jsx(s.Card,{children:e.jsx(s.Statistic,{title:"工作流",value:0,prefix:e.jsx(i.AuditOutlined,{})})})}),e.jsx(s.Col,{span:6,children:e.jsx(s.Card,{children:e.jsx(s.Statistic,{title:"用户中心",value:0,prefix:e.jsx(i.UserOutlined,{})})})})]}),e.jsxs(s.Card,{title:"关于 Z-One Company",children:[e.jsx(ts,{children:"Z-One Company 是一站式企业级应用管理平台,整合了配置中心、任务中心、工作流、用户中心等多个模块。"}),e.jsx(ts,{children:e.jsx("strong",{children:"核心模块:"})}),e.jsxs("ul",{children:[e.jsx("li",{children:"配置中心 - 集中管理应用配置"}),e.jsx("li",{children:"任务中心 - 任务调度与执行"}),e.jsx("li",{children:"工作流 - 流程审批与管理"}),e.jsx("li",{children:"用户中心 - 统一身份认证与权限管理"}),e.jsx("li",{children:"调度中心 - 定时任务管理"}),e.jsx("li",{children:"Mist - 密钥管理"}),e.jsx("li",{children:"元数据 - API与应用管理"})]})]})]}),Us=Ue,ne={layout:"_layout_1puwg_1",header:"_header_1puwg_5",logo:"_logo_1puwg_15",logoText:"_logoText_1puwg_20",headerRight:"_headerRight_1puwg_26",userInfo:"_userInfo_1puwg_31",userName:"_userName_1puwg_38",mainLayout:"_mainLayout_1puwg_43",sider:"_sider_1puwg_48",menu:"_menu_1puwg_53",collapsedBtn:"_collapsedBtn_1puwg_57",content:"_content_1puwg_74"};let qs="/api";function rs(){return Ve.create({baseURL:qs,timeout:15e3})}const xe=rs();rs(),xe.interceptors.request.use(t=>{const a=localStorage.getItem("token");return a&&(t.headers.Authorization=`Bearer ${a}`),t});const Gs=t=>xe.post("/ctc/auth/login",t).then(a=>a.data),Hs=()=>{try{const t=localStorage.getItem("userInfo");return Promise.resolve(t?JSON.parse(t):null)}catch{return Promise.resolve(null)}};function Ws(t){return{list:a=>xe.get(`/${t}/list`,{params:a}).then(l=>l.data),page:a=>xe.get(`/${t}/page`,{params:a}).then(l=>l.data),get:a=>xe.get(`/${t}/${a}`).then(l=>l.data),create:a=>xe.post(`/${t}`,a).then(l=>l.data),update:(a,l)=>xe.put(`/${t}/${a}`,l).then(j=>j.data),delete:a=>xe.delete(`/${t}/${a}`).then(l=>l.data)}}const q=Ws("mock"),{Header:Js,Sider:Ks,Content:Ys}=s.Layout,{Text:Vs}=s.Typography,Xs=({compact:t=!1}={})=>{const a=se.useLocation(),l=se.useNavigate(),[j,I]=r.useState(!1),[C,d]=r.useState("管理员"),[g,v]=r.useState(null),[f,O]=r.useState([]),[m,h]=r.useState([]),z=r.useRef(l);z.current=l,r.useEffect(()=>{if(!localStorage.getItem("token")){z.current("/login");return}const T=localStorage.getItem("userInfo");if(T)try{const w=JSON.parse(T);d(w.userName||"管理员"),v(w),w.tenantCode&&h([w.tenantCode])}catch{}Hs().then(w=>{w&&(v(w),d(w.userName||"管理员"),localStorage.setItem("userInfo",JSON.stringify(w)))}).catch(()=>{}),O([{value:"tenant1",label:"租户1",children:[{value:"domain1-1",label:"域1-1"},{value:"domain1-2",label:"域1-2"}]},{value:"tenant2",label:"租户2",children:[{value:"domain2-1",label:"域2-1"},{value:"domain2-2",label:"域2-2"}]}])},[]);const y=()=>{var T;const N=a.pathname;if(N.includes("/user"))return["user"];if(N.includes("/role"))return["role"];if(N.includes("/permission"))return["permission"];if(N.includes("/app"))return["app"];if(N.includes("/dict"))return["dict"];if(N.includes("/audit"))return["audit"];if(N.includes("/tenant"))return["tenant"];if(N.includes("/domain"))return["domain"];if(N.includes("/org"))return["org"];if(N.includes("/dept"))return["dept"];if(N.includes("/group"))return["group"];if(N.includes("/4a/")){const w=((T=N.split("/4a/")[1])==null?void 0:T.split("/"))||[];if(w.length>0)return[`4a/${w[0]}`]}return N.includes("/webide")?["webide"]:N.includes("/agent-team")?["agent-team"]:["4a/account"]},$=[{key:"4a/account",icon:e.jsx(i.TeamOutlined,{}),label:"账号管理"},{key:"4a/role",icon:e.jsx(i.SafetyOutlined,{}),label:"角色管理"},{key:"4a/application",icon:e.jsx(i.AppstoreOutlined,{}),label:"应用管理"},{key:"4a/tenant",icon:e.jsx(i.TeamOutlined,{}),label:"租户管理"},{key:"4a/org",icon:e.jsx(i.ClusterOutlined,{}),label:"组织管理"},{key:"4a/permission",icon:e.jsx(i.SafetyCertificateOutlined,{}),label:"权限管理"},{key:"4a/surl",icon:e.jsx(i.LinkOutlined,{}),label:"短链管理"},{key:"webide",icon:e.jsx(i.CodeOutlined,{}),label:"WebIDE 容器"},{key:"agent-team",icon:e.jsx(i.RobotOutlined,{}),label:"Agent 群组 IM"},{type:"divider"},{key:"settings",icon:e.jsx(i.SettingOutlined,{}),label:"系统设置"}],E=({key:N})=>{l(`/ctc/${N}`)};return e.jsxs(s.Layout,{className:ne.layout,children:[t?null:e.jsx(e.Fragment,{children:e.jsxs(Js,{className:ne.header,children:[e.jsx("div",{className:ne.logo,children:e.jsx("span",{className:ne.logoText,children:"Z-CTC 统一用户中心"})}),e.jsx("div",{className:ne.headerRight,children:e.jsx(s.Space,{size:24,children:e.jsx(s.Dropdown,{overlay:e.jsxs("div",{style:{background:"#fff",borderRadius:"8px",boxShadow:"0 6px 16px rgba(0, 0, 0, 0.12)",padding:"16px",width:"360px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"12px",marginBottom:"12px"},children:[e.jsx("span",{style:{fontSize:"14px",color:"#666"},children:"租户域"}),e.jsx(s.Cascader,{value:m,onChange:N=>h(N),options:f,placeholder:"请选择租户域",style:{flex:1}})]}),e.jsx(s.Divider,{style:{margin:"12px 0"}}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[e.jsxs("div",{style:{display:"flex",fontSize:"14px"},children:[e.jsx("span",{style:{color:"#999",width:"70px"},children:"用户名:"}),e.jsx("span",{children:(g==null?void 0:g.userName)||"-"})]}),e.jsxs("div",{style:{display:"flex",fontSize:"14px"},children:[e.jsx("span",{style:{color:"#999",width:"70px"},children:"真实姓名:"}),e.jsx("span",{children:(g==null?void 0:g.realName)||"-"})]}),e.jsxs("div",{style:{display:"flex",fontSize:"14px"},children:[e.jsx("span",{style:{color:"#999",width:"70px"},children:"邮箱:"}),e.jsx("span",{children:(g==null?void 0:g.email)||"-"})]}),e.jsxs("div",{style:{display:"flex",fontSize:"14px"},children:[e.jsx("span",{style:{color:"#999",width:"70px"},children:"手机号:"}),e.jsx("span",{children:(g==null?void 0:g.phone)||"-"})]}),e.jsxs("div",{style:{display:"flex",fontSize:"14px"},children:[e.jsx("span",{style:{color:"#999",width:"70px"},children:"状态:"}),e.jsx("span",{children:(g==null?void 0:g.status)===1?"正常":"停用"})]})]}),e.jsx(s.Divider,{style:{margin:"12px 0"}}),e.jsxs("div",{style:{display:"flex",flexDirection:"column"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",cursor:"pointer",borderRadius:"4px",fontSize:"14px"},onClick:()=>{},children:[e.jsx(i.UserOutlined,{})," 个人中心"]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",cursor:"pointer",borderRadius:"4px",fontSize:"14px"},onClick:()=>{},children:[e.jsx(i.SettingOutlined,{})," 系统设置"]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",cursor:"pointer",borderRadius:"4px",fontSize:"14px"},onClick:()=>{localStorage.removeItem("token"),localStorage.removeItem("userInfo"),l("/ctc/login")},children:[e.jsx(i.LogoutOutlined,{})," 退出登录"]})]})]}),placement:"bottomRight",trigger:["click"],children:e.jsxs("div",{className:ne.userInfo,children:[e.jsx(s.Avatar,{icon:e.jsx(i.UserOutlined,{}),size:"small"}),e.jsx(Vs,{className:ne.userName,children:C}),e.jsx(i.DownOutlined,{})]})})})})]})}),e.jsxs(s.Layout,{className:ne.mainLayout,children:[e.jsxs(Ks,{trigger:null,collapsible:!0,collapsed:j,className:ne.sider,width:200,children:[e.jsx(s.Menu,{mode:"inline",selectedKeys:y(),defaultOpenKeys:["user","role","permission","audit","tenant","domain","org","dept","group"],className:ne.menu,items:$,onClick:E}),e.jsx("div",{className:ne.collapsedBtn,onClick:()=>I(!j),children:j?e.jsx(i.MenuUnfoldOutlined,{}):e.jsx(i.MenuFoldOutlined,{})})]}),e.jsx(Ys,{className:ne.content,children:e.jsx(se.Outlet,{})})]})]})},Fe={container:"_container_tti32_1",content:"_content_tti32_9",card:"_card_tti32_14",header:"_header_tti32_19"},{Title:Zs,Text:ir}=s.Typography,Qs=t=>Ue.post("/ctc/auth/login",t),et=()=>Promise.resolve({code:0,message:"功能暂未开放"}),st=()=>{const t=se.useNavigate(),[a,l]=r.useState("login"),[j,I]=r.useState("account"),[C,d]=r.useState(!1),[g,v]=r.useState(0),[f]=s.Form.useForm(),O=async()=>{s.message.info("验证码功能暂未开放")},m=async y=>{try{let $;if(a==="login"&&j==="account"){if($=await Qs({identifier:y.username,password:y.password}),$&&$.token){s.message.success("登录成功!"),localStorage.setItem("token",$.token);const E=$.account||{};localStorage.setItem("userInfo",JSON.stringify({userId:E.id,userName:E.username,nickname:E.nickname,tenantCode:E.tenantCode})),t("/ctc");return}s.message.error(($==null?void 0:$.message)||"登录失败")}else{await et(),s.message.info("该功能暂未开放");return}}catch($){s.message.error($.message||"操作失败,请重试")}},h=()=>{const y=[{key:"account",label:"账户密码"}];return a==="register"?(y.push({key:"phone",label:"手机注册"}),y.push({key:"email",label:"邮箱注册"})):y.push({key:"phone",label:"手机验证码"}),y},z=()=>{const y=a==="login";return e.jsxs(e.Fragment,{children:[j==="account"&&e.jsxs(e.Fragment,{children:[e.jsx(s.Form.Item,{name:"username",rules:[{required:!0,message:"请输入用户名!"}],children:e.jsx(s.Input,{size:"large",prefix:e.jsx(i.UserOutlined,{}),placeholder:"用户名"})}),e.jsx(s.Form.Item,{name:"password",rules:[{required:!0,message:"请输入密码!"}],children:e.jsx(s.Input.Password,{size:"large",prefix:e.jsx(i.LockOutlined,{}),placeholder:"密码"})})]}),(j==="phone"||j==="email")&&e.jsxs(e.Fragment,{children:[e.jsx(s.Form.Item,{name:"receiver",rules:[{required:!0,message:j==="phone"?"请输入手机号!":"请输入邮箱!"}],children:e.jsx(s.Input,{size:"large",prefix:j==="phone"?e.jsx(i.MobileOutlined,{}):e.jsx(i.MailOutlined,{}),placeholder:j==="phone"?"手机号":"邮箱",disabled:g>0})}),e.jsx(s.Form.Item,{children:e.jsxs("div",{style:{display:"flex",gap:8},children:[e.jsx(s.Input,{size:"large",prefix:e.jsx(i.LockOutlined,{}),placeholder:"验证码",style:{flex:1}}),e.jsx(s.Button,{type:"primary",onClick:O,loading:C,disabled:g>0,style:{minWidth:100},children:g>0?`${g}秒`:"获取验证码"})]})}),!y&&e.jsx(s.Form.Item,{name:"password",rules:[{required:!0,message:"请输入密码!"}],children:e.jsx(s.Input.Password,{size:"large",prefix:e.jsx(i.LockOutlined,{}),placeholder:"设置密码"})})]})]})};return e.jsx("div",{className:Fe.container,children:e.jsx("div",{className:Fe.content,children:e.jsxs(s.Card,{className:Fe.card,children:[e.jsxs("div",{className:Fe.header,style:{textAlign:"center"},children:[e.jsxs("svg",{width:"48",height:"48",viewBox:"0 0 56 56",fill:"none","aria-label":"logo",style:{marginBottom:8},children:[e.jsx("defs",{children:e.jsxs("linearGradient",{id:"brandGradAuth",x1:"0",y1:"0",x2:"56",y2:"56",gradientUnits:"userSpaceOnUse",children:[e.jsx("stop",{offset:"0%",stopColor:"#1677ff"}),e.jsx("stop",{offset:"100%",stopColor:"#0958d9"})]})}),e.jsx("rect",{x:"2",y:"2",width:"52",height:"52",rx:"14",fill:"url(#brandGradAuth)"}),e.jsx("path",{d:"M18 18 H40 L18 38 H40",stroke:"#ffffff",strokeWidth:"3.5",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"})]}),e.jsx(Zs,{level:4,style:{margin:0},children:a==="register"?"用户注册":"欢迎登录"})]}),e.jsxs(s.Form,{form:f,layout:"vertical",onFinish:m,initialValues:{autoLogin:!0},children:[a!=="forgot"&&e.jsx(s.Tabs,{activeKey:j,onChange:y=>I(y),centered:!0,items:h()}),z(),e.jsx(s.Form.Item,{children:e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[a==="login"&&e.jsx(s.Form.Item,{name:"autoLogin",valuePropName:"checked",noStyle:!0,children:e.jsx(s.Checkbox,{children:"自动登录"})}),e.jsx("a",{onClick:()=>{l(a==="login"?"register":"login")},children:a==="login"?"没有账号?立即注册":"已有账号?立即登录"})]})}),e.jsx(s.Form.Item,{children:e.jsx(s.Button,{type:"primary",htmlType:"submit",block:!0,size:"large",children:a==="login"?"登录":"注册"})})]})]})})})},tt={display:"flex",flexDirection:"column",height:"100vh",overflow:"auto",background:"#f0f2f5",backgroundImage:"url('https://gw.alipayobjects.com/zos/rmsportal/TVYTbAXWheQpRcWDaDMu.svg')",backgroundRepeat:"no-repeat",backgroundPosition:"center 110px",backgroundSize:"100%"},rt={flex:1,padding:"32px 0",maxWidth:400,margin:"0 auto",width:"100%"},lt=()=>{const[t,a]=r.useState({}),[l]=r.useState("account"),[j,I]=r.useState(!1),C=se.useNavigate(),d=async v=>{I(!0);try{const f=await Gs({identifier:v.userName,password:v.password});if(f&&f.token){localStorage.setItem("token",f.token);const O=f.account||{};localStorage.setItem("userInfo",JSON.stringify({userId:O.id,userName:O.username,nickname:O.nickname,tenantCode:O.tenantCode})),s.message.success("登录成功!"),C("/");return}a(f)}catch{s.message.error("登录失败,请重试!")}finally{I(!1)}},{status:g}=t;return e.jsx("div",{style:tt,children:e.jsxs("div",{style:rt,children:[e.jsx("div",{style:{textAlign:"center",marginBottom:24},children:e.jsxs("svg",{width:"56",height:"56",viewBox:"0 0 56 56",fill:"none","aria-label":"logo",children:[e.jsx("defs",{children:e.jsxs("linearGradient",{id:"brandGrad",x1:"0",y1:"0",x2:"56",y2:"56",gradientUnits:"userSpaceOnUse",children:[e.jsx("stop",{offset:"0%",stopColor:"#1677ff"}),e.jsx("stop",{offset:"100%",stopColor:"#0958d9"})]})}),e.jsx("rect",{x:"2",y:"2",width:"52",height:"52",rx:"14",fill:"url(#brandGrad)"}),e.jsx("path",{d:"M18 18 H40 L18 38 H40",stroke:"#ffffff",strokeWidth:"3.5",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"})]})}),e.jsx(s.Tabs,{activeKey:l,centered:!0,items:[{key:"account",label:"账户密码登录"}]}),g==="error"&&e.jsx(s.Alert,{message:"账户或密码错误",type:"error",showIcon:!0,style:{marginBottom:16}}),e.jsxs(s.Form,{onFinish:d,initialValues:{autoLogin:!0},layout:"vertical",children:[e.jsx(s.Form.Item,{name:"userName",rules:[{required:!0,message:"请输入用户名!"}],children:e.jsx(s.Input,{size:"large",prefix:e.jsx(i.UserOutlined,{}),placeholder:"用户名"})}),e.jsx(s.Form.Item,{name:"password",rules:[{required:!0,message:"请输入密码!"}],children:e.jsx(s.Input.Password,{size:"large",prefix:e.jsx(i.LockOutlined,{}),placeholder:"密码"})}),e.jsx(s.Form.Item,{name:"autoLogin",valuePropName:"checked",children:e.jsx(s.Checkbox,{children:"自动登录"})}),e.jsx(s.Form.Item,{children:e.jsx(s.Button,{type:"primary",htmlType:"submit",size:"large",block:!0,loading:j,children:"登录"})})]}),e.jsxs("div",{style:{textAlign:"center",marginTop:16,color:"#888",fontSize:14},children:[e.jsx(se.Link,{to:"/uc/register",style:{marginRight:16},children:"用户注册"}),e.jsx("span",{style:{margin:"0 8px",color:"#ddd"},children:"|"}),e.jsx(se.Link,{to:"/uc/reset-password",style:{marginRight:16},children:"找回密码"}),e.jsx("span",{style:{margin:"0 8px",color:"#ddd"},children:"|"}),e.jsx(se.Link,{to:"/uc/login",children:"手机验证码登录"})]})]})})},Pe={health:()=>Y.get("/agentTeam/health").then(t=>t.data)},ot={LEADER:"red",WORKER:"blue",OBSERVER:"default"};function nt(){const[t,a]=r.useState([]),[l,j]=r.useState(null),[I,C]=r.useState([]),[d,g]=r.useState(!1),[v,f]=r.useState(!1),[O,m]=r.useState("disconnected"),[h,z]=r.useState([]),[y,$]=r.useState(""),[E,N]=r.useState([]),T=r.useRef(null),w=async()=>{g(!0);try{const o=await Pe.listTeams();a(o||[])}catch(o){s.message.warning("加载团队失败:"+((o==null?void 0:o.message)||"未知错误")),a([])}finally{g(!1)}},P=async o=>{f(!0);try{const n=await Pe.listMembers(o);C(n||[])}catch(n){s.message.warning("加载成员失败:"+((n==null?void 0:n.message)||"未知错误")),C([])}finally{f(!1)}},S=()=>{if(T.current){s.message.warning("已连接");return}const o=Pe.buildWsUrl();m("connecting"),z(n=>[...n,`[${new Date().toLocaleTimeString()}] 连接到 ${o}...`]);try{const n=new WebSocket(o);n.onopen=()=>{m("connected"),z(L=>[...L,`[${new Date().toLocaleTimeString()}] ✅ 连接已建立`])},n.onmessage=L=>{const b=typeof L.data=="string"?L.data:"[binary]";z(V=>[...V,`[${new Date().toLocaleTimeString()}] ← ${b}`]);const A=b.match(/^([^|]+)\|(.+)$/);A&&N(V=>[...V,{from:A[1],text:A[2],time:new Date().toLocaleTimeString()}])},n.onerror=()=>{m("error"),z(L=>[...L,`[${new Date().toLocaleTimeString()}] ❌ 连接错误`])},n.onclose=()=>{m("disconnected"),z(L=>[...L,`[${new Date().toLocaleTimeString()}] 🔌 连接已关闭`]),T.current=null},T.current=n}catch(n){m("error"),s.message.error("WS 连接失败:"+((n==null?void 0:n.message)||"未知错误"))}},M=()=>{T.current&&(T.current.close(),T.current=null)},U=()=>{if(!T.current||T.current.readyState!==WebSocket.OPEN){s.message.error("WebSocket 未连接");return}if(!y.trim())return;const o=`${localStorage.getItem("userInfo")?JSON.parse(localStorage.getItem("userInfo")).userName:"me"}|${y}`;T.current.send(o),z(n=>[...n,`[${new Date().toLocaleTimeString()}] → ${y}`]),N(n=>[...n,{from:"me",text:y,time:new Date().toLocaleTimeString()}]),$("")};r.useEffect(()=>(w(),()=>{M()}),[]),r.useEffect(()=>{l&&P(l.teamCode)},[l]);const J={disconnected:"default",connecting:"processing",connected:"success",error:"error"},H={disconnected:"未连接",connecting:"连接中",connected:"已连接",error:"错误"};return e.jsxs(me.PageContainer,{header:{title:"Agent 群组 IM (z-agent-team)",subTitle:"团队协作 + 实时通讯",breadcrumb:{}},children:[e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"300px 1fr",gap:16},children:[e.jsx(me.ProCard,{title:e.jsxs(s.Space,{children:[e.jsx(i.TeamOutlined,{})," 团队列表"]}),loading:d,headerBordered:!0,children:t.length===0?e.jsx(s.Empty,{image:s.Empty.PRESENTED_IMAGE_SIMPLE,description:"暂无团队",children:e.jsx(s.Button,{type:"primary",size:"small",onClick:w,children:"刷新"})}):e.jsx(s.List,{dataSource:t,renderItem:o=>e.jsx(s.List.Item,{onClick:()=>j(o),style:{cursor:"pointer",padding:"8px 12px",background:(l==null?void 0:l.teamCode)===o.teamCode?"#e6f7ff":void 0,borderRadius:4},children:e.jsx(s.List.Item.Meta,{title:o.teamName,description:e.jsxs(s.Space,{size:4,children:[e.jsx(s.Tag,{children:o.teamCode}),o.status==="ENABLE"?e.jsx(s.Tag,{color:"green",children:"启用"}):e.jsx(s.Tag,{children:"停用"})]})})})})}),e.jsxs(me.ProCard,{title:l?e.jsxs(s.Space,{children:[e.jsx(i.TeamOutlined,{})," ",l.teamName," (",l.teamCode,")"]}):"请选择团队",headerBordered:!0,extra:e.jsxs(s.Space,{children:[O==="connected"?e.jsx(s.Button,{icon:e.jsx(i.PoweroffOutlined,{}),onClick:M,children:"断开"}):e.jsx(s.Button,{type:"primary",icon:e.jsx(i.CheckCircleOutlined,{}),onClick:S,children:"连接"}),e.jsx(s.Tag,{color:J[O],children:H[O]})]}),children:[l?e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:16},children:[e.jsx(me.ProCard,{title:"成员",loading:v,size:"small",children:e.jsx(s.List,{dataSource:I,renderItem:o=>e.jsx(s.List.Item,{children:e.jsx(s.List.Item.Meta,{title:e.jsxs(s.Space,{children:[o.appCode,e.jsx(s.Tag,{color:ot[o.role||"WORKER"],children:o.role})]}),description:`优先级: ${o.priority??0} · ${o.enabled===1?"✅ 启用":"❌ 停用"}`})})})}),e.jsxs(me.ProCard,{title:"实时消息",size:"small",styles:{body:{padding:0,display:"flex",flexDirection:"column",height:400}},children:[e.jsx("div",{style:{flex:1,overflow:"auto",padding:12},children:E.length===0?e.jsx(s.Empty,{image:s.Empty.PRESENTED_IMAGE_SIMPLE,description:"暂无消息"}):E.map((o,n)=>e.jsxs("div",{style:{marginBottom:8},children:[e.jsx(s.Tag,{color:o.from==="me"?"blue":"green",children:o.from}),e.jsx("span",{style:{marginLeft:8},children:o.text}),e.jsx("span",{style:{marginLeft:8,color:"#999",fontSize:11},children:o.time})]},n))}),e.jsxs("div",{style:{padding:8,borderTop:"1px solid #f0f0f0",display:"flex",gap:8},children:[e.jsx(s.Input,{value:y,onChange:o=>$(o.target.value),onPressEnter:U,placeholder:O==="connected"?"输入消息...":"请先连接 WebSocket",disabled:O!=="connected"}),e.jsx(s.Button,{type:"primary",icon:e.jsx(i.SendOutlined,{}),onClick:U,disabled:O!=="connected",children:"发送"})]})]})]}):e.jsx(s.Empty,{description:"请从左侧选择一个团队"}),h.length>0&&e.jsx(me.ProCard,{title:"WebSocket 日志",size:"small",style:{marginTop:16},children:e.jsx("pre",{style:{background:"#1e1e1e",color:"#d4d4d4",padding:8,borderRadius:4,fontFamily:"Menlo, monospace",fontSize:11,maxHeight:180,overflow:"auto",margin:0},children:h.join(`
23
- `)})})]})]}),e.jsx(s.Alert,{style:{marginTop:16},type:"info",showIcon:!0,message:"说明",description:e.jsxs("span",{children:["完整 STOMP 客户端 (含订阅 Topic、ACK、消息历史) 见 ",e.jsx("code",{children:"z-agent/z-agent-team/z-agent-team-frontend"}),"。 本页提供轻量级 WS 连接 + 群组管理 REST 端点示例。"]})})]})}const ke={list:()=>Y.get("/agent/team/workspace/list").then(t=>t.data),create:t=>Y.post("/agent/team/workspace",t).then(a=>a.data),update:(t,a)=>Y.put(`/agent/team/workspace/${t}`,a).then(l=>l.data),delete:t=>Y.delete(`/agent/team/workspace/${t}`).then(a=>a.data),getFileTree:t=>Y.get("/agent/team/workspace/file-tree-by-path",{params:{path:t}}).then(a=>a.data),getFileContent:t=>Y.get("/agent/team/workspace/file-content",{params:{path:t}}).then(a=>a.data)},Ne={list:t=>Y.get(`/agent/team/conversation/${t}/work-items`).then(a=>a.data),create:t=>Y.post("/agent/team/work-item",t).then(a=>a.data),update:(t,a)=>Y.put(`/agent/team/work-item/${t}`,a).then(l=>l.data),delete:t=>Y.delete(`/agent/team/work-item/${t}`).then(a=>a.data)},ls={OPEN:"green",DONE:"blue",ARCHIVED:"default"};function it(){var Q,ks;const{message:t}=s.App.useApp(),a=localStorage.getItem("userInfo")||"{}";let l={};try{l=JSON.parse(a)}catch{}const j=l!=null&&l.userId?String(l.userId):"anonymous",I=(l==null?void 0:l.userName)||(l==null?void 0:l.name)||"我",[C,d]=r.useState([]),[g,v]=r.useState(!1),[f,O]=r.useState(null),[m,h]=r.useState([]),[z,y]=r.useState(!1),[$,E]=r.useState([]),[N,T]=r.useState(!1),[w,P]=r.useState(null),[S,M]=r.useState(!1),[U,J]=r.useState([]),[H,o]=r.useState(""),[n,L]=r.useState("disconnected"),b=r.useRef(null),A=r.useRef(null),[V,re]=r.useState(""),[ae,oe]=r.useState(""),[k,p]=r.useState(!1),[c,D]=r.useState(!1),[R]=s.Form.useForm(),[W]=s.Form.useForm(),[te,ce]=r.useState(null),[Z,de]=r.useState("z-one-company-default");r.useEffect(()=>{fe(),he(),Ce()},[]),r.useEffect(()=>{A.current&&A.current.scrollIntoView({behavior:"smooth"})},[U,V]);const fe=async()=>{try{const x=await Pe.listTeams();x&&x.length>0&&de(x[0].teamCode)}catch{}},he=async()=>{y(!0);try{const x=await ke.list(j);h(x||[])}catch{h([])}finally{y(!1)}},Ce=async()=>{v(!0);try{const x=await Ne.listAllByOwner(j,100);d(x||[])}catch{d([])}finally{v(!1)}},ge=async x=>{if(!x){E([]);return}T(!0);try{const _=await ke.fileTree(x);E(_?[le(_)]:[])}catch(_){t.error("加载文件树失败:"+((_==null?void 0:_.message)||"未知错误")),E([])}finally{T(!1)}},Je=async x=>{try{const X=(await Ne.messages(x,200)||[]).map(ee=>({msgCode:ee.msgCode,senderType:ee.senderType,senderCode:ee.senderCode,senderName:ee.senderName,content:ee.content,messageType:ee.messageType,timestamp:ee.gmtCreate?new Date(ee.gmtCreate).getTime():Date.now()}));J(X)}catch{J([])}},Ke=x=>{Le();const X=`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}/api/agent/team/ws?convCode=${encodeURIComponent(x)}&userId=${encodeURIComponent(j)}&userName=${encodeURIComponent(I)}`;L("connecting");try{const ee=new WebSocket(X);ee.onopen=()=>{L("connected")},ee.onmessage=Rt=>{try{const Ut=JSON.parse(Rt.data);Ye(Ut)}catch{}},ee.onerror=()=>{L("error")},ee.onclose=()=>{L("disconnected"),b.current=null},b.current=ee}catch(ee){L("error"),t.error("WS 连接失败:"+((ee==null?void 0:ee.message)||"未知错误"))}},Le=()=>{if(b.current){try{b.current.close()}catch{}b.current=null,L("disconnected"),re("")}},Ye=x=>{const _=x.type;_==="AGENT_RESPONSE_DELTA"||_==="AGENT_THINKING_DELTA"?(oe(x.senderName||x.senderCode||"Agent"),re(X=>X+(x.content||""))):_==="AGENT_RESPONSE"||_==="AGENT_THINKING"?(J(X=>[...X,{msgCode:x.eventId||`evt-${Date.now()}`,senderType:x.senderType||"AGENT",senderCode:x.senderCode||"",senderName:x.senderName||"Agent",content:x.content||"",messageType:_,timestamp:x.timestamp||Date.now()}]),re(""),oe("")):_==="SYSTEM"||_==="PARTICIPANT_JOIN"||_==="PARTICIPANT_LEAVE"?x.content&&x.content!=="HEARTBEAT_ACK"&&x.content!=="PONG"&&J(X=>[...X,{msgCode:x.eventId||`evt-${Date.now()}`,senderType:"SYSTEM",senderCode:x.senderCode||"system",senderName:"系统",content:x.content,messageType:_,timestamp:x.timestamp||Date.now()}]):_==="ERROR"?(J(X=>[...X,{msgCode:x.eventId||`err-${Date.now()}`,senderType:"SYSTEM",senderCode:"system",senderName:"错误",content:x.content||"未知错误",messageType:_,timestamp:x.timestamp||Date.now()}]),re(""),oe("")):_==="MESSAGE_END"&&(re(""),oe(""))},_e=()=>{const x=H.trim();if(!x)return;if(!b.current||b.current.readyState!==WebSocket.OPEN){t.warning("IM 未连接");return}if(!f){t.warning("请先选择一个工作项");return}const _=JSON.stringify({type:"USER_MESSAGE",content:x});b.current.send(_),J(X=>[...X,{msgCode:`local-${Date.now()}`,senderType:"USER",senderCode:j,senderName:I,content:x,messageType:"TEXT",timestamp:Date.now()}]),o("")},Be=x=>{O(x),Je(x.convCode),Ke(x.convCode),x.workspaceCode?(ce(x.workspaceCode),ge(x.workspaceCode)):(ce(null),E([]))},$e=async()=>{try{const x=await W.validateFields(),_=await Ne.create({teamCode:Z,userId:j,userName:I,title:x.title,workspaceCode:x.workspaceCode||void 0});t.success("工作项已创建"),D(!1),W.resetFields(),await Ce(),_&&Be(_)}catch(x){t.error("创建失败:"+((x==null?void 0:x.message)||"未知错误"))}},u=async()=>{var x,_;try{const X=await R.validateFields();await ke.create({workspaceName:X.workspaceName,localPath:X.localPath,ownerId:j,ownerName:I,description:X.description}),t.success("工作空间已创建"),p(!1),R.resetFields(),await he()}catch(X){const ee=((_=(x=X==null?void 0:X.response)==null?void 0:x.data)==null?void 0:_.message)||(X==null?void 0:X.message)||"未知错误";t.error("创建失败:"+ee)}},F=async x=>{M(!0);try{const _=await ke.fileContent(x);P({path:x,content:(_==null?void 0:_.content)||""})}catch(_){t.error("读取文件失败:"+((_==null?void 0:_.message)||"未知错误"))}finally{M(!1)}},G=async x=>{try{await Ne.close(x,"DONE"),t.success("已关闭工作项"),await Ce(),(f==null?void 0:f.convCode)===x&&(O(null),Le(),J([]),E([]))}catch(_){t.error("关闭失败:"+((_==null?void 0:_.message)||"未知错误"))}},K=async x=>{try{await ke.delete(x),t.success("已删除"),await he(),te===x&&(ce(null),E([]))}catch(_){t.error("删除失败:"+((_==null?void 0:_.message)||"未知错误"))}},le=x=>{var _;return{key:x.absolutePath,title:e.jsxs("span",{children:[x.isDirectory?e.jsx(i.FolderOutlined,{style:{marginRight:4,color:"#faad14"}}):e.jsx(i.FileOutlined,{style:{marginRight:4,color:"#8c8c8c"}}),x.name,x.isDirectory&&x.totalDescendants>0?e.jsxs("span",{style:{color:"#bfbfbf",marginLeft:6,fontSize:11},children:["(",x.totalDescendants,")"]}):null]}),children:((_=x.children)==null?void 0:_.map(le))||[],isLeaf:!x.isDirectory,disabled:!1}};return e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"240px 280px 1fr",height:"calc(100vh - 130px)",background:"#fff",border:"1px solid #f0f0f0",borderRadius:8,overflow:"hidden"},children:[e.jsxs("div",{style:{borderRight:"1px solid #f0f0f0",display:"flex",flexDirection:"column",background:"#fafafa"},children:[e.jsxs("div",{style:{padding:12,borderBottom:"1px solid #f0f0f0",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsxs(s.Space,{size:4,children:[e.jsx(i.MessageOutlined,{style:{color:"#1677ff"}}),e.jsx("strong",{children:"工作项"})]}),e.jsxs(s.Space,{size:4,children:[e.jsx(s.Tooltip,{title:"刷新",children:e.jsx(s.Button,{size:"small",type:"text",icon:e.jsx(i.ReloadOutlined,{}),onClick:Ce})}),e.jsx(s.Tooltip,{title:"新建工作项",children:e.jsx(s.Button,{size:"small",type:"text",icon:e.jsx(i.PlusOutlined,{}),onClick:()=>D(!0)})})]})]}),e.jsx("div",{style:{flex:1,overflow:"auto"},children:g?e.jsx("div",{style:{padding:24,textAlign:"center"},children:e.jsx(s.Spin,{size:"small"})}):C.length===0?e.jsx(s.Empty,{image:s.Empty.PRESENTED_IMAGE_SIMPLE,description:"暂无工作项",style:{padding:24,marginTop:24},children:e.jsx(s.Button,{size:"small",type:"primary",onClick:()=>D(!0),children:"新建工作项"})}):C.map(x=>e.jsxs("div",{onClick:()=>Be(x),style:{padding:"10px 12px",cursor:"pointer",borderBottom:"1px solid #f5f5f5",background:(f==null?void 0:f.convCode)===x.convCode?"#e6f7ff":"transparent",transition:"background 0.2s"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:4},children:[e.jsx("strong",{style:{fontSize:13,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",maxWidth:150},children:x.title||"未命名"}),e.jsx(s.Badge,{count:x.unreadCount||0,size:"small"})]}),e.jsx("div",{style:{fontSize:11,color:"#8c8c8c",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:x.lastMsgPreview||"暂无消息"}),e.jsxs("div",{style:{marginTop:4,fontSize:11,color:"#bfbfbf"},children:[e.jsx(s.Tag,{color:ls[x.status||"OPEN"],style:{marginRight:4,fontSize:10,padding:"0 4px"},children:x.status||"OPEN"}),x.workspaceCode?e.jsx(s.Tag,{color:"purple",style:{fontSize:10,padding:"0 4px"},children:"有工作空间"}):null]})]},x.convCode))})]}),e.jsxs("div",{style:{borderRight:"1px solid #f0f0f0",display:"flex",flexDirection:"column",background:"#fff"},children:[e.jsxs("div",{style:{padding:12,borderBottom:"1px solid #f0f0f0",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsxs(s.Space,{size:4,children:[e.jsx(i.FolderOpenOutlined,{style:{color:"#faad14"}}),e.jsx("strong",{children:"工作空间"})]}),e.jsx(s.Space,{size:4,children:e.jsx(s.Tooltip,{title:"新建工作空间",children:e.jsx(s.Button,{size:"small",type:"text",icon:e.jsx(i.PlusOutlined,{}),onClick:()=>p(!0)})})})]}),f!=null&&f.workspaceCode?e.jsx("div",{style:{padding:"8px 12px",background:"#f0f5ff",borderBottom:"1px solid #f0f0f0",fontSize:12},children:e.jsxs(s.Space,{size:4,children:[e.jsx(s.Tag,{color:"blue",children:"当前工作项"}),e.jsx("span",{style:{color:"#1677ff"},children:((Q=m.find(x=>x.workspaceCode===f.workspaceCode))==null?void 0:Q.workspaceName)||f.workspaceCode}),e.jsx(s.Button,{size:"small",type:"text",icon:e.jsx(i.ReloadOutlined,{}),onClick:()=>ge(f.workspaceCode)})]})}):null,e.jsx("div",{style:{maxHeight:200,overflow:"auto",borderBottom:"1px solid #f0f0f0"},children:z?e.jsx("div",{style:{padding:12,textAlign:"center"},children:e.jsx(s.Spin,{size:"small"})}):m.length===0?e.jsx("div",{style:{padding:12,color:"#8c8c8c",fontSize:12,textAlign:"center"},children:"暂无工作空间"}):m.map(x=>e.jsxs("div",{onClick:()=>{ce(x.workspaceCode),ge(x.workspaceCode)},style:{padding:"6px 12px",cursor:"pointer",fontSize:12,background:te===x.workspaceCode?"#e6f7ff":"transparent",borderLeft:te===x.workspaceCode?"3px solid #1677ff":"3px solid transparent",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsxs(s.Space,{size:4,style:{overflow:"hidden"},children:[e.jsx(i.FolderOutlined,{style:{color:"#faad14",fontSize:12}}),e.jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:x.workspaceName})]}),e.jsx(s.Popconfirm,{title:"删除此工作空间?",onConfirm:_=>{_==null||_.stopPropagation(),K(x.workspaceCode)},onCancel:_=>_==null?void 0:_.stopPropagation(),children:e.jsx(s.Button,{size:"small",type:"text",danger:!0,icon:e.jsx(i.DeleteOutlined,{}),onClick:_=>_.stopPropagation()})})]},x.workspaceCode))}),e.jsx("div",{style:{flex:1,overflow:"auto",padding:8},children:N?e.jsx("div",{style:{padding:24,textAlign:"center"},children:e.jsx(s.Spin,{})}):te?$.length===0?e.jsx(s.Empty,{image:s.Empty.PRESENTED_IMAGE_SIMPLE,description:"空目录或无文件",style:{marginTop:40}}):e.jsx(s.Tree,{treeData:$,defaultExpandAll:!1,showLine:!0,showIcon:!1,onSelect:(x,_)=>{const X=_.node;!X.isLeaf&&x.length>0||X.isLeaf&&_.node.key&&F(String(_.node.key))}}):e.jsx(s.Empty,{image:s.Empty.PRESENTED_IMAGE_SIMPLE,description:"请选择工作空间",style:{marginTop:40}})}),w?e.jsxs("div",{style:{borderTop:"1px solid #f0f0f0",maxHeight:240,overflow:"hidden",display:"flex",flexDirection:"column"},children:[e.jsxs("div",{style:{padding:"6px 12px",background:"#fafafa",borderBottom:"1px solid #f0f0f0",display:"flex",alignItems:"center",justifyContent:"space-between",fontSize:11},children:[e.jsxs(s.Space,{size:4,children:[e.jsx(i.FileTextOutlined,{}),e.jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",maxWidth:180},children:w.path.split("/").pop()})]}),e.jsx(s.Button,{size:"small",type:"text",onClick:()=>P(null),children:"关闭"})]}),e.jsx("pre",{style:{flex:1,margin:0,padding:8,overflow:"auto",fontSize:11,background:"#1e1e1e",color:"#d4d4d4",fontFamily:"Menlo, monospace",whiteSpace:"pre-wrap",wordBreak:"break-all"},children:S?"加载中...":w.content||"(空)"})]}):null]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",background:"#f5f5f5"},children:[e.jsxs("div",{style:{padding:"12px 16px",background:"#fff",borderBottom:"1px solid #f0f0f0",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[f?e.jsxs(s.Space,{size:8,children:[e.jsx(i.TeamOutlined,{style:{color:"#1677ff"}}),e.jsx("strong",{style:{fontSize:14},children:f.title||"未命名"}),e.jsx(s.Tag,{color:ls[f.status||"OPEN"],style:{marginLeft:4},children:f.status||"OPEN"}),f.workspaceCode?e.jsx(s.Tag,{color:"purple",icon:e.jsx(i.FolderOpenOutlined,{}),children:((ks=m.find(x=>x.workspaceCode===f.workspaceCode))==null?void 0:ks.workspaceName)||"工作空间"}):null,e.jsxs("span",{style:{color:"#8c8c8c",fontSize:12},children:[f.messageCount||0," 条消息"]})]}):e.jsx("span",{style:{color:"#8c8c8c"},children:"请从左侧选择一个工作项"}),f?e.jsxs(s.Space,{size:4,children:[e.jsx(s.Tag,{color:n==="connected"?"green":n==="error"?"red":"default",children:n==="connected"?"已连接":n==="connecting"?"连接中":n==="error"?"错误":"未连接"}),e.jsx(s.Popconfirm,{title:"关闭此工作项?",onConfirm:()=>G(f.convCode),children:e.jsx(s.Button,{size:"small",type:"text",danger:!0,icon:e.jsx(i.CheckCircleOutlined,{}),children:"完成"})})]}):null]}),e.jsx("div",{style:{flex:1,overflow:"auto",padding:16,display:"flex",flexDirection:"column",gap:12},children:f?U.length===0&&!V?e.jsx(s.Empty,{image:s.Empty.PRESENTED_IMAGE_SIMPLE,description:"暂无消息,开始聊吧",style:{marginTop:80}}):e.jsxs(e.Fragment,{children:[U.map(x=>e.jsx(os,{msg:x,currentUserId:j},x.msgCode)),V?e.jsx(os,{msg:{msgCode:"streaming",senderType:"AGENT",senderCode:"agent",senderName:ae,content:V,timestamp:Date.now(),messageType:"STREAMING"},currentUserId:j}):null,e.jsx("div",{ref:A})]}):e.jsx(s.Empty,{image:s.Empty.PRESENTED_IMAGE_SIMPLE,description:"从左侧选择工作项开始聊天",style:{marginTop:80}})}),e.jsxs("div",{style:{padding:12,background:"#fff",borderTop:"1px solid #f0f0f0",display:"flex",gap:8},children:[e.jsx(s.Input.TextArea,{value:H,onChange:x=>o(x.target.value),onPressEnter:x=>{x.shiftKey||(x.preventDefault(),_e())},placeholder:f?n==="connected"?"输入消息... (Enter 发送, Shift+Enter 换行)":"正在连接 IM...":"请先选择工作项",autoSize:{minRows:1,maxRows:4},disabled:!f||n!=="connected"}),e.jsx(s.Button,{type:"primary",icon:e.jsx(i.SendOutlined,{}),onClick:_e,disabled:!f||n!=="connected"||!H.trim(),children:"发送"})]})]}),e.jsx(s.Modal,{title:"新建工作空间",open:k,onCancel:()=>p(!1),onOk:u,okText:"创建",cancelText:"取消",children:e.jsxs(s.Form,{form:R,layout:"vertical",children:[e.jsx(s.Form.Item,{label:"名称",name:"workspaceName",rules:[{required:!0,message:"请输入工作空间名称"}],children:e.jsx(s.Input,{placeholder:"例如:z-opc 主项目"})}),e.jsx(s.Form.Item,{label:"本地路径",name:"localPath",rules:[{required:!0,message:"请输入本地路径"}],extra:"服务器侧的文件系统绝对路径 (例: /Users/zifang/workplace)",children:e.jsx(s.Input,{placeholder:"/Users/zifang/workplace"})}),e.jsx(s.Form.Item,{label:"描述",name:"description",children:e.jsx(s.Input.TextArea,{rows:2,placeholder:"可选:工作空间用途说明"})})]})}),e.jsx(s.Modal,{title:"新建工作项",open:c,onCancel:()=>D(!1),onOk:$e,okText:"创建",cancelText:"取消",children:e.jsxs(s.Form,{form:W,layout:"vertical",children:[e.jsx(s.Form.Item,{label:"标题",name:"title",rules:[{required:!0,message:"请输入工作项标题"}],children:e.jsx(s.Input,{placeholder:"例如:完成 z-opc 用户面板"})}),e.jsx(s.Form.Item,{label:"关联工作空间 (可选)",name:"workspaceCode",extra:"绑定后,工作项右侧会显示对应工作空间的文件树",children:e.jsxs("select",{style:{width:"100%",height:32,border:"1px solid #d9d9d9",borderRadius:6,padding:"0 11px"},children:[e.jsx("option",{value:"",children:"无 (仅 IM 群聊)"}),m.map(x=>e.jsxs("option",{value:x.workspaceCode,children:[x.workspaceName," (",x.localPath,")"]},x.workspaceCode))]})})]})})]})}function os({msg:t,currentUserId:a}){const l=t.senderType==="USER"&&t.senderCode===a;if(t.senderType==="SYSTEM")return e.jsx("div",{style:{textAlign:"center",color:"#8c8c8c",fontSize:11},children:e.jsx(s.Tag,{color:"default",children:t.content})});const I=l?"#1677ff":"#fff",C=l?"#fff":"#333",d=l?"#1677ff":"#87d068";return e.jsxs("div",{style:{display:"flex",flexDirection:l?"row-reverse":"row",alignItems:"flex-start",gap:8},children:[e.jsx(s.Avatar,{style:{background:d,flexShrink:0},children:(t.senderName||"?").charAt(0).toUpperCase()}),e.jsxs("div",{style:{maxWidth:"70%"},children:[e.jsxs("div",{style:{fontSize:11,color:"#8c8c8c",marginBottom:2,textAlign:l?"right":"left"},children:[t.senderName," · ",new Date(t.timestamp).toLocaleTimeString(),t.messageType&&t.messageType!=="TEXT"?e.jsx(s.Tag,{style:{marginLeft:4,fontSize:10},children:t.messageType}):null]}),e.jsx("div",{style:{padding:"8px 12px",background:I,color:C,borderRadius:8,border:l?"none":"1px solid #e8e8e8",wordBreak:"break-word",whiteSpace:"pre-wrap",boxShadow:"0 1px 2px rgba(0,0,0,0.04)"},children:t.content||(t.messageType==="STREAMING"?"...":"")})]})]})}const Se={health:()=>Y.get("/webide/health").then(t=>t.data)},at={CREATING:{text:"创建中",color:"processing"},RUNNING:{text:"运行中",color:"success"},STOPPED:{text:"已停止",color:"default"},ERROR:{text:"错误",color:"error"}},ct={GIT:{text:"GIT 模式",color:"blue"},SHARED:{text:"SHARED 模式",color:"purple"}};function dt(){const t=r.useRef(void 0),[a,l]=r.useState(!1),[j,I]=r.useState(!1),[C,d]=r.useState([]),[g,v]=r.useState(null),[f,O]=r.useState(!1),[m]=s.Form.useForm(),h=async()=>{try{const w=await Se.listContainers();return{data:w||[],success:!0,total:(w||[]).length}}catch(w){return s.message.warning("后端未就绪,显示空列表:"+((w==null?void 0:w.message)||"未知错误")),{data:[],success:!1,total:0}}},z=async()=>{var w;try{const P=await m.validateFields();O(!0);const S=await Se.inspect(P);s.message.success(`WebIDE 创建成功:${S.url}`),l(!1),m.resetFields(),(w=t.current)==null||w.reload(),S.url&&window.open(S.url,"_blank")}catch(P){if(P!=null&&P.errorFields)return;s.message.error("创建失败:"+((P==null?void 0:P.message)||"未知错误"))}finally{O(!1)}},y=async w=>{var P;try{await Se.startContainer(w),s.message.success("已启动"),(P=t.current)==null||P.reload()}catch(S){s.message.error("启动失败:"+((S==null?void 0:S.message)||"未知错误"))}},$=async w=>{var P;try{await Se.stopContainer(w),s.message.success("已停止"),(P=t.current)==null||P.reload()}catch(S){s.message.error("停止失败:"+((S==null?void 0:S.message)||"未知错误"))}},E=async w=>{var P;try{await Se.removeContainer(w),s.message.success("已删除"),(P=t.current)==null||P.reload()}catch(S){s.message.error("删除失败:"+((S==null?void 0:S.message)||"未知错误"))}},N=async w=>{v(w),I(!0),d(["加载中..."]);try{const P=await Se.getLogs(w.containerId,200);d((P==null?void 0:P.lines)||[])}catch(P){d([`加载日志失败:${(P==null?void 0:P.message)||"未知错误"}`])}},T=[{title:"容器ID",dataIndex:"containerId",width:200,fixed:"left",ellipsis:!0},{title:"模式",dataIndex:"mode",width:110,render:(w,P)=>{const S=ct[P.mode]||{text:P.mode,color:"default"};return e.jsx(s.Tag,{color:S.color,children:S.text})}},{title:"Git URL",dataIndex:"gitUrl",width:200,ellipsis:!0},{title:"分支",dataIndex:"branch",width:100},{title:"状态",dataIndex:"status",width:100,render:(w,P)=>{const S=at[P.status]||{text:P.status,color:"default"};return e.jsx(s.Tag,{color:S.color,children:S.text})}},{title:"URL",dataIndex:"url",width:200,ellipsis:!0,render:(w,P)=>P.url?e.jsx("a",{href:P.url,target:"_blank",rel:"noreferrer",children:P.url}):"-"},{title:"CPU%",dataIndex:"cpuUsage",width:80,render:w=>typeof w=="number"?`${w.toFixed(1)}%`:"-"},{title:"内存%",dataIndex:"memoryUsage",width:80,render:w=>typeof w=="number"?`${w.toFixed(1)}%`:"-"},{title:"创建时间",dataIndex:"createdAt",width:170,valueType:"dateTime"},{title:"操作",valueType:"option",width:240,fixed:"right",render:(w,P)=>[e.jsx(s.Tooltip,{title:"启动",children:e.jsx(s.Button,{type:"text",size:"small",icon:e.jsx(i.PlayCircleOutlined,{}),onClick:()=>y(P.containerId),children:"启动"})},"start"),e.jsx(s.Tooltip,{title:"停止",children:e.jsx(s.Button,{type:"text",size:"small",icon:e.jsx(i.PauseOutlined,{}),onClick:()=>$(P.containerId),children:"停止"})},"stop"),e.jsx(s.Tooltip,{title:"查看日志",children:e.jsx(s.Button,{type:"text",size:"small",icon:e.jsx(i.FileTextOutlined,{}),onClick:()=>N(P),children:"日志"})},"logs"),e.jsx(s.Tooltip,{title:"删除",children:e.jsx(s.Button,{type:"text",danger:!0,size:"small",icon:e.jsx(i.DeleteOutlined,{}),onClick:()=>E(P.containerId),children:"删除"})},"remove")]}];return e.jsxs(me.PageContainer,{header:{title:"WebIDE 容器管理 (z-webide)",subTitle:"基于 code-server 的容器化 WebIDE",breadcrumb:{}},children:[e.jsx(me.ProTable,{actionRef:t,rowKey:"containerId",columns:T,request:h,search:!1,pagination:{pageSize:20},headerTitle:"容器列表",toolBarRender:()=>[e.jsx(s.Button,{type:"primary",icon:e.jsx(i.PlusOutlined,{}),onClick:()=>l(!0),children:"新建 WebIDE"},"add"),e.jsx(s.Button,{icon:e.jsx(i.ReloadOutlined,{}),onClick:()=>{var w;return(w=t.current)==null?void 0:w.reload()},children:"刷新"},"reload")]}),e.jsx(s.Drawer,{title:e.jsxs(s.Space,{children:[e.jsx(i.CodeOutlined,{})," 新建 WebIDE"]}),open:a,onClose:()=>l(!1),width:520,extra:e.jsxs(s.Space,{children:[e.jsx(s.Button,{onClick:()=>l(!1),children:"取消"}),e.jsx(s.Button,{type:"primary",loading:f,onClick:z,children:"创建并打开"})]}),children:e.jsx(ut,{form:m})}),e.jsx(s.Drawer,{title:g?`容器日志 — ${g.containerId}`:"容器日志",open:j,onClose:()=>I(!1),width:720,children:e.jsx("pre",{style:{background:"#1e1e1e",color:"#d4d4d4",padding:12,borderRadius:4,fontFamily:"Menlo, Consolas, monospace",fontSize:12,maxHeight:"70vh",overflow:"auto",whiteSpace:"pre-wrap"},children:C.join(`
24
- `)})})]})}function ut({form:t}){const{mode:a,setMode:l}=pt();return e.jsxs(s.Form,{form:t,layout:"vertical",style:{marginTop:16},initialValues:{mode:"GIT"},children:[e.jsx(s.Form.Item,{name:"mode",label:"模式",rules:[{required:!0}],children:e.jsx(s.Select,{onChange:j=>l(j),options:[{value:"GIT",label:"GIT 模式 (从仓库克隆)"},{value:"SHARED",label:"SHARED 模式 (共享工作区)"}]})}),a==="GIT"&&e.jsxs(e.Fragment,{children:[e.jsx(s.Form.Item,{name:"gitUrl",label:"Git URL",rules:[{required:!0,type:"url"}],extra:"支持 https://github.com/xxx/yyy.git",children:e.jsx(s.Input,{placeholder:"https://github.com/your/repo.git"})}),e.jsx(s.Form.Item,{name:"branch",label:"分支",children:e.jsx(s.Input,{placeholder:"main (默认)"})})]}),a==="SHARED"&&e.jsx(s.Form.Item,{name:"shareKey",label:"共享 Key",rules:[{required:!0}],children:e.jsx(s.Input,{placeholder:"SHARED-XXXXXX"})}),e.jsx(s.Form.Item,{name:"tenantCode",label:"租户编码 (可选)",children:e.jsx(s.Input,{placeholder:"default"})})]})}function pt(){const[t,a]=r.useState("GIT");return{mode:t,setMode:a}}const mt=()=>e.jsx(se.Outlet,{}),xt=()=>{const[t]=s.Form.useForm(),a=l=>{console.log("UC login:",l),s.message.info("UC 账号密码登录占位组件 — 实际登录逻辑接 z-ctc-ac")};return e.jsx(s.Card,{title:"账号密码登录",style:{maxWidth:420,margin:"40px auto"},children:e.jsxs(s.Form,{form:t,onFinish:a,layout:"vertical",children:[e.jsx(s.Form.Item,{name:"username",label:"账号",rules:[{required:!0}],children:e.jsx(s.Input,{prefix:e.jsx(i.UserOutlined,{}),placeholder:"请输入账号"})}),e.jsx(s.Form.Item,{name:"password",label:"密码",rules:[{required:!0}],children:e.jsx(s.Input.Password,{prefix:e.jsx(i.LockOutlined,{}),placeholder:"请输入密码"})}),e.jsx(s.Form.Item,{children:e.jsx(s.Button,{type:"primary",htmlType:"submit",block:!0,children:"登录"})})]})})},ht=()=>{const[t]=s.Form.useForm(),[a,l]=r.useState(!1),[j,I]=r.useState(0),C=async()=>{try{const g=t.getFieldValue("phone");if(!g||!/^1\d{10}$/.test(g)){s.message.warning("请输入正确的手机号");return}l(!0),I(60);const v=setInterval(()=>I(f=>f>0?f-1:(clearInterval(v),0)),1e3);s.message.success("验证码已发送 (mock 通道: 123456)")}catch{s.message.error("发送失败")}finally{l(!1)}},d=g=>{if(g.code!=="123456"){s.message.error("验证码错误,固定码 123456");return}s.message.success("手机登录成功 (占位)")};return e.jsx(s.Card,{title:"手机验证码登录",style:{maxWidth:420,margin:"40px auto"},children:e.jsxs(s.Form,{form:t,onFinish:d,layout:"vertical",children:[e.jsx(s.Form.Item,{name:"phone",label:"手机号",rules:[{required:!0,pattern:/^1\d{10}$/}],children:e.jsx(s.Input,{prefix:e.jsx(i.MobileOutlined,{}),placeholder:"11 位手机号",maxLength:11})}),e.jsx(s.Form.Item,{name:"code",label:"验证码",rules:[{required:!0}],children:e.jsx(s.Input,{prefix:e.jsx(i.SafetyOutlined,{}),placeholder:"固定码 123456",maxLength:6,addonAfter:e.jsx(s.Button,{type:"link",disabled:a||j>0,onClick:C,children:j>0?`${j}s`:"获取验证码"})})}),e.jsx(s.Form.Item,{children:e.jsx(s.Button,{type:"primary",htmlType:"submit",block:!0,children:"登录"})})]})})},gt=()=>{const[t]=s.Form.useForm(),a=l=>{console.log("UC register:",l),s.message.success("注册成功 (占位)")};return e.jsx(s.Card,{title:"新用户注册",style:{maxWidth:420,margin:"40px auto"},children:e.jsxs(s.Form,{form:t,onFinish:a,layout:"vertical",children:[e.jsx(s.Form.Item,{name:"username",label:"账号",rules:[{required:!0,min:3}],children:e.jsx(s.Input,{prefix:e.jsx(i.UserOutlined,{}),placeholder:"3 位以上"})}),e.jsx(s.Form.Item,{name:"phone",label:"手机号",rules:[{required:!0,pattern:/^1\d{10}$/}],children:e.jsx(s.Input,{prefix:e.jsx(i.MobileOutlined,{}),placeholder:"11 位手机号",maxLength:11})}),e.jsx(s.Form.Item,{name:"code",label:"验证码",rules:[{required:!0}],children:e.jsx(s.Input,{prefix:e.jsx(i.SafetyOutlined,{}),placeholder:"固定码 123456",maxLength:6})}),e.jsx(s.Form.Item,{name:"password",label:"密码",rules:[{required:!0,min:6}],children:e.jsx(s.Input.Password,{prefix:e.jsx(i.LockOutlined,{}),placeholder:"6 位以上"})}),e.jsx(s.Form.Item,{children:e.jsx(s.Button,{type:"primary",htmlType:"submit",block:!0,children:"注册"})})]})})},jt=()=>{const[t,a]=r.useState(0),[l]=s.Form.useForm(),j=async()=>{try{await l.validateFields(),t<2?a(t+1):s.message.success("密码重置成功 (占位)")}catch{}};return e.jsxs(s.Card,{title:"找回密码",style:{maxWidth:480,margin:"40px auto"},children:[e.jsx(s.Steps,{current:t,items:[{title:"验证手机号"},{title:"输入验证码"},{title:"重置密码"}],style:{marginBottom:24}}),e.jsxs(s.Form,{form:l,layout:"vertical",children:[t===0&&e.jsx(s.Form.Item,{name:"phone",label:"手机号",rules:[{required:!0,pattern:/^1\d{10}$/}],children:e.jsx(s.Input,{prefix:e.jsx(i.MobileOutlined,{}),placeholder:"注册时的手机号",maxLength:11})}),t===1&&e.jsx(s.Form.Item,{name:"code",label:"验证码",rules:[{required:!0}],children:e.jsx(s.Input,{prefix:e.jsx(i.SafetyOutlined,{}),placeholder:"固定码 123456",maxLength:6})}),t===2&&e.jsxs(e.Fragment,{children:[e.jsx(s.Form.Item,{name:"password",label:"新密码",rules:[{required:!0,min:6}],children:e.jsx(s.Input.Password,{prefix:e.jsx(i.LockOutlined,{}),placeholder:"6 位以上"})}),e.jsx(s.Form.Item,{name:"confirm",label:"确认密码",rules:[{required:!0},({getFieldValue:I})=>({validator(C,d){return!d||I("password")===d?Promise.resolve():Promise.reject(new Error("两次输入不一致"))}})],children:e.jsx(s.Input.Password,{prefix:e.jsx(i.LockOutlined,{}),placeholder:"再输一次"})})]}),e.jsx(s.Form.Item,{children:e.jsx(s.Button,{type:"primary",onClick:j,block:!0,children:t<2?"下一步":"提交"})})]})]})},{Option:ns}=s.Select,{TextArea:is}=s.Input,Ae=[{type:"STRING",label:"字符串",icon:e.jsx(i.FileTextOutlined,{}),color:"#1677ff",desc:"短文本 (默认 VARCHAR 255)"},{type:"TEXT",label:"长文本",icon:e.jsx(i.FileTextOutlined,{}),color:"#13c2c2",desc:"TEXT 类型, 无长度限制"},{type:"INT",label:"整数",icon:"#",color:"#722ed1",desc:"INT 整数"},{type:"LONG",label:"长整数",icon:"#",color:"#722ed1",desc:"BIGINT 长整数"},{type:"DECIMAL",label:"小数",icon:"0.00",color:"#eb2f96",desc:"DECIMAL 精确小数"},{type:"BOOLEAN",label:"布尔",icon:e.jsx(i.CheckCircleOutlined,{}),color:"#52c41a",desc:"TINYINT(1) 是/否"},{type:"DATE",label:"日期",icon:"📅",color:"#fa8c16",desc:"DATE yyyy-MM-dd"},{type:"DATETIME",label:"日期时间",icon:"🕐",color:"#fa8c16",desc:"DATETIME yyyy-MM-dd HH:mm:ss"},{type:"JSON",label:"JSON",icon:"{}",color:"#2f54eb",desc:"JSON 字符串"},{type:"REF",label:"引用",icon:"🔗",color:"#8c8c8c",desc:"外键引用 BIGINT"}],De=Object.fromEntries(Ae.map(t=>[t.type,t])),qe="application/x-lc-field-type",Ge="application/x-lc-field-idx";function as(){const[t]=se.useSearchParams(),[a,l]=r.useState(t.get("appCode")||"demo"),[j,I]=r.useState(t.get("tenant")||localStorage.getItem("z_tenant")||"default"),[C,d]=r.useState([]),[g,v]=r.useState(null),[f,O]=r.useState(!1),[m,h]=r.useState(null),[z,y]=r.useState(!1),[$]=s.Form.useForm(),[E,N]=r.useState(null),[T,w]=r.useState(null),[P,S]=r.useState(null),[M,U]=r.useState([]),[J,H]=r.useState(null),[o,n]=r.useState(!1),[L,b]=r.useState(!1),A=r.useCallback(async()=>{if(a){O(!0);try{const u=await Y.get(`/lc/app/${a}/schema`,{params:{tenantCode:j}});d(Array.isArray(u)?u:[]),v(null)}catch(u){s.message.error("加载 schema 失败: "+((u==null?void 0:u.message)||"未知错误")),d([])}finally{O(!1)}}},[a,j]);r.useEffect(()=>{A()},[A]);const V=async(u,F,G)=>{var K;try{const le={tenantCode:j,entityCode:F,eventType:u,eventData:typeof G=="string"?G:JSON.stringify(G),source:"USER",parentEventId:g},Q=await Y.post(`/lc/app/${a}/event`,le);s.message.success(`事件 ${u} 已提交 (eventId=${(K=Q==null?void 0:Q.eventId)==null?void 0:K.slice(0,8)}…)`),v((Q==null?void 0:Q.eventId)||null),await A()}catch(le){s.message.error("提交事件失败: "+((le==null?void 0:le.message)||"未知错误"))}},re=()=>{h(null),$.resetFields(),$.setFieldsValue({entityCode:"",entityName:"",tableName:"",description:"",fields:[]}),y(!0)},ae=u=>{h(u),$.setFieldsValue({entityCode:u.entityCode,entityName:u.entityName,tableName:u.tableName||u.entityCode,description:u.description,fields:u.fields||[]}),y(!0)},oe=u=>{U((u.fields||[]).map((F,G)=>({...F,sortOrder:F.sortOrder??G}))),H(null),n(!1),b(!0),h(u)},k=u=>{s.Modal.confirm({title:`删除实体 ${u.entityName||u.entityCode}?`,content:"此操作会发出 DELETE 事件, 所有字段一起删除.",okType:"danger",onOk:()=>V("DELETE",u.entityCode,{entityCode:u.entityCode})})},p=async()=>{try{const u=await $.validateFields(),F=m?"UPDATE":"CREATE",G={entityCode:u.entityCode,entityName:u.entityName,tableName:u.tableName||u.entityCode,description:u.description,fields:(u.fields||[]).map(K=>({fieldCode:K.fieldCode,fieldName:K.fieldName,fieldType:K.fieldType||"STRING",required:!!K.required,defaultValue:K.defaultValue||null,dictCode:K.dictCode||null,refEntity:K.refEntity||null,fieldLength:K.fieldLength||null,scale:K.scale||null,sortOrder:K.sortOrder||0}))};y(!1),await V(F,u.entityCode,G)}catch(u){u!=null&&u.errorFields?s.message.error("请补全必填字段"):s.message.error("提交失败: "+((u==null?void 0:u.message)||"未知错误"))}},c=(u,F)=>{u.dataTransfer.setData(qe,F),u.dataTransfer.setData("text/plain",F),u.dataTransfer.effectAllowed="copy",N(F)},D=()=>{N(null),S(null)},R=(u,F)=>{u.dataTransfer.setData(Ge,String(F)),u.dataTransfer.effectAllowed="move",w(F)},W=()=>{w(null),S(null)},te=u=>{u.preventDefault(),u.dataTransfer.dropEffect=E?"copy":"move"},ce=()=>{S(null)},Z=u=>{u.preventDefault();const F=u.dataTransfer.getData(qe),G=u.dataTransfer.getData(Ge);if(F)he(F,M.length);else if(G){const K=Number(G);Ce(K,M.length)}S(null),N(null),w(null)},de=(u,F)=>{u.preventDefault(),u.stopPropagation(),S(F)},fe=(u,F)=>{u.preventDefault(),u.stopPropagation();const G=u.dataTransfer.getData(qe),K=u.dataTransfer.getData(Ge);G?he(G,F):K&&Ce(Number(K),F),S(null),N(null),w(null)},he=(u,F)=>{const G=De[u];if(!G)return;const le={fieldCode:`field_${M.length+1}`,fieldName:`新${G.label}字段`,fieldType:u,required:!1,defaultValue:null,dictCode:null,refEntity:null,fieldLength:u==="STRING"?255:null,scale:u==="DECIMAL"?2:null,sortOrder:F},Q=[...M];Q.splice(F,0,le),ge(Q),U(Q),H(F),n(!0)},Ce=(u,F)=>{if(u===F||u<0||F<0)return;const G=[...M],[K]=G.splice(u,1),le=F>u?F-1:F;G.splice(le,0,K),ge(G),U(G),n(!0)},ge=u=>{u.forEach((F,G)=>{F.sortOrder=G})},Je=(u,F)=>{const G=[...M];G[u]={...G[u],...F},U(G),n(!0)},Ke=u=>{const F=M.filter((G,K)=>K!==u);ge(F),U(F),H(null),n(!0)},Le=u=>{const F=M[u],G={...F,fieldCode:`${F.fieldCode}_copy`,fieldName:`${F.fieldName} (副本)`},K=[...M];K.splice(u+1,0,G),ge(K),U(K),H(u+1),n(!0)},Ye=async()=>{if(!m)return;const u={entityCode:m.entityCode,entityName:m.entityName,tableName:m.tableName,description:m.description,fields:M.map(F=>({fieldCode:F.fieldCode,fieldName:F.fieldName,fieldType:F.fieldType||"STRING",required:!!F.required,defaultValue:F.defaultValue||null,dictCode:F.dictCode||null,refEntity:F.refEntity||null,fieldLength:F.fieldLength||null,scale:F.scale||null,sortOrder:F.sortOrder??0}))};await V("UPDATE",m.entityCode,u),n(!1)},_e=async()=>{if(m)try{const u=await Y.post(`/lc/admin/entity/${m.id}/provision?tenant=${j}`);s.message.success(`已建表 (${M.length} 字段)`),console.log("DDL:",u)}catch(u){s.message.error("建表失败: "+((u==null?void 0:u.message)||"未知错误"))}},Be=[{title:"编码",dataIndex:"entityCode",key:"entityCode",width:140},{title:"名称",dataIndex:"entityName",key:"entityName",width:140},{title:"物理表",dataIndex:"tableName",key:"tableName",width:160},{title:"字段数",key:"fields",width:80,render:(u,F)=>{var G;return e.jsx(s.Badge,{count:((G=F.fields)==null?void 0:G.length)||0,showZero:!0,color:"blue"})}},{title:"描述",dataIndex:"description",key:"description",ellipsis:!0},{title:"操作",key:"action",width:260,render:(u,F)=>e.jsxs(s.Space,{children:[e.jsx(s.Button,{type:"link",size:"small",icon:e.jsx(i.FormatPainterOutlined,{}),onClick:()=>oe(F),children:"画布编辑"}),e.jsx(s.Button,{type:"link",size:"small",icon:e.jsx(i.EditOutlined,{}),onClick:()=>ae(F),children:"表单编辑"}),e.jsx(s.Popconfirm,{title:"确定删除?",onConfirm:()=>k(F),children:e.jsx(s.Button,{type:"link",size:"small",danger:!0,icon:e.jsx(i.DeleteOutlined,{}),children:"删除"})})]})}],$e=J!=null?M[J]:null;return e.jsxs("div",{children:[e.jsxs(s.Card,{title:e.jsxs(e.Fragment,{children:[e.jsx(i.ThunderboltOutlined,{})," z-lc 模型编辑器 (拖拽版)"]}),extra:e.jsxs(s.Space,{children:[e.jsx(s.Input,{addonBefore:"appCode",value:a,onChange:u=>l(u.target.value.trim()),style:{width:200}}),e.jsx(s.Input,{addonBefore:"tenant",value:j,onChange:u=>I(u.target.value.trim()),style:{width:160}}),e.jsx(s.Button,{icon:e.jsx(i.ReloadOutlined,{}),onClick:A,children:"刷新"}),e.jsx(s.Button,{type:"primary",icon:e.jsx(i.PlusOutlined,{}),onClick:re,children:"新建实体"})]}),children:[e.jsx(s.Alert,{type:"info",showIcon:!0,message:"提示: 点击实体的「画布编辑」进入拖拽式建模: 从左侧面板拖字段类型到中间, 拖拽字段行可重排, 右侧编辑属性。",style:{marginBottom:16}}),e.jsx(s.Spin,{spinning:f,children:C.length===0?e.jsx(s.Empty,{description:"暂无实体, 点击右上角 「新建实体」 开始"}):e.jsx(s.Table,{rowKey:"entityCode",columns:Be,dataSource:C,pagination:!1,size:"small",expandable:{expandedRowRender:u=>e.jsx(yt,{entity:u})}})})]}),e.jsx(s.Modal,{title:m?`编辑实体 ${m.entityCode}`:"新建实体",open:z,onCancel:()=>y(!1),onOk:p,width:760,destroyOnClose:!0,children:e.jsx(ft,{form:$,editing:m})}),e.jsx(s.Drawer,{title:e.jsxs(s.Space,{children:[e.jsx(i.FormatPainterOutlined,{}),m?`画布编辑 - ${m.entityName||m.entityCode}`:"画布编辑",o&&e.jsx(s.Tag,{color:"orange",children:"未保存"})]}),open:L,onClose:()=>{o?s.Modal.confirm({title:"有未保存的修改, 确定关闭?",onOk:()=>{b(!1),n(!1)}}):b(!1)},width:"85%",destroyOnClose:!0,extra:e.jsxs(s.Space,{children:[e.jsx(s.Button,{onClick:_e,icon:e.jsx(i.DatabaseOutlined,{}),children:"自动建表"}),e.jsx(s.Button,{type:"primary",icon:e.jsx(i.ThunderboltOutlined,{}),disabled:!o,onClick:Ye,children:"提交 (UPDATE 事件)"})]}),children:e.jsxs(s.Row,{gutter:16,style:{height:"calc(100vh - 200px)"},children:[e.jsx(s.Col,{span:5,children:e.jsxs(s.Card,{size:"small",title:e.jsxs(e.Fragment,{children:[e.jsx(i.HolderOutlined,{})," 字段类型面板"]}),style:{height:"100%"},bodyStyle:{padding:12,overflowY:"auto",height:"calc(100% - 40px)"},children:[e.jsx("div",{style:{fontSize:12,color:"#999",marginBottom:8},children:"拖拽字段类型到右侧"}),Ae.map(u=>e.jsxs("div",{draggable:!0,onDragStart:F=>c(F,u.type),onDragEnd:D,style:{padding:"8px 12px",marginBottom:8,background:E===u.type?"#e6f4ff":"#fafafa",border:`1px dashed ${u.color}`,borderRadius:6,cursor:"grab",opacity:E===u.type?.5:1,transition:"all 0.2s"},children:[e.jsxs(s.Space,{children:[e.jsx("span",{style:{display:"inline-block",width:22,height:22,borderRadius:4,background:u.color,color:"#fff",textAlign:"center",lineHeight:"22px",fontSize:11,fontWeight:"bold"},children:u.type.slice(0,2)}),e.jsx("span",{style:{fontWeight:500},children:u.label})]}),e.jsx("div",{style:{fontSize:11,color:"#888",marginTop:4},children:u.desc})]},u.type))]})}),e.jsx(s.Col,{span:12,children:e.jsx(s.Card,{size:"small",title:e.jsxs(s.Space,{children:[e.jsx(i.DatabaseOutlined,{}),"字段列表 (",M.length,")"]}),style:{height:"100%"},bodyStyle:{padding:8,overflowY:"auto",height:"calc(100% - 40px)"},children:e.jsx("div",{onDragOver:te,onDragLeave:ce,onDrop:Z,style:{minHeight:"100%",padding:4,border:"2px dashed transparent",borderRadius:6},children:M.length===0?e.jsx(s.Empty,{description:"从左侧拖拽字段类型到这里",style:{marginTop:80}}):e.jsxs(e.Fragment,{children:[M.map((u,F)=>{const G=De[u.fieldType]||De.STRING,K=J===F,le=T===F;return e.jsxs(r.Fragment,{children:[P===F&&e.jsx("div",{style:{height:4,background:"#1677ff",borderRadius:2,margin:"4px 0"}}),e.jsx("div",{draggable:!0,onDragStart:Q=>R(Q,F),onDragEnd:W,onDragOver:Q=>de(Q,F),onDrop:Q=>fe(Q,F),onClick:()=>H(F),style:{padding:"10px 12px",marginBottom:6,background:K?"#e6f4ff":"#fff",border:`1px solid ${K?"#1677ff":"#d9d9d9"}`,borderRadius:6,cursor:"grab",opacity:le?.4:1,transition:"all 0.15s"},children:e.jsxs(s.Space,{style:{width:"100%",justifyContent:"space-between"},children:[e.jsxs(s.Space,{children:[e.jsx(i.HolderOutlined,{style:{color:"#999"}}),e.jsx("span",{style:{display:"inline-block",width:20,height:20,borderRadius:3,background:G.color,color:"#fff",textAlign:"center",lineHeight:"20px",fontSize:10},children:u.fieldType.slice(0,2)}),e.jsx("span",{style:{fontFamily:"monospace",fontWeight:500},children:u.fieldCode}),e.jsx("span",{children:u.fieldName}),u.required&&e.jsx(s.Tag,{color:"red",style:{margin:0},children:"必填"}),u.dictCode&&e.jsxs(s.Tag,{color:"blue",style:{margin:0},children:["dict:",u.dictCode]}),u.refEntity&&e.jsxs(s.Tag,{color:"purple",style:{margin:0},children:["ref:",u.refEntity]})]}),e.jsxs(s.Space,{size:4,onClick:Q=>Q.stopPropagation(),children:[e.jsx(s.Tooltip,{title:"复制",children:e.jsx(s.Button,{type:"text",size:"small",icon:e.jsx(i.CopyOutlined,{}),onClick:()=>Le(F)})}),e.jsx(s.Tooltip,{title:"删除",children:e.jsx(s.Button,{type:"text",size:"small",danger:!0,icon:e.jsx(i.DeleteOutlined,{}),onClick:()=>Ke(F)})})]})]})})]},`${u.fieldCode}-${F}`)}),P===M.length&&e.jsx("div",{style:{height:4,background:"#1677ff",borderRadius:2,margin:"4px 0"}})]})})})}),e.jsx(s.Col,{span:7,children:e.jsx(s.Card,{size:"small",title:e.jsxs(e.Fragment,{children:[e.jsx(i.CodeOutlined,{})," 字段属性"]}),style:{height:"100%"},bodyStyle:{padding:12,overflowY:"auto",height:"calc(100% - 40px)"},children:$e?e.jsx(Ct,{field:$e,onChange:u=>Je(J,u)}):e.jsx(s.Empty,{description:"点击中间列表中的字段以编辑属性",style:{marginTop:80}})})})]})})]})}function yt({entity:t}){const a=t.fields||[];return a.length===0?e.jsx("span",{style:{color:"#999"},children:"无字段"}):e.jsx(s.Space,{wrap:!0,size:[4,4],children:a.map(l=>e.jsxs(s.Tag,{color:(De[l.fieldType]||{}).color||"default",children:[l.fieldCode," : ",l.fieldType,l.required?" *":""]},l.fieldCode))})}function ft({form:t,editing:a}){return e.jsxs(s.Form,{form:t,layout:"vertical",children:[e.jsxs(s.Space,{style:{width:"100%"},size:"middle",children:[e.jsx(s.Form.Item,{name:"entityCode",label:"实体编码",rules:[{required:!0,pattern:/^[A-Za-z][A-Za-z0-9_]*$/,message:"字母数字下划线"}],children:e.jsx(s.Input,{disabled:!!a,placeholder:"如 user"})}),e.jsx(s.Form.Item,{name:"entityName",label:"实体名称",children:e.jsx(s.Input,{placeholder:"如 用户"})}),e.jsx(s.Form.Item,{name:"tableName",label:"物理表名",rules:[{required:!0,pattern:/^[A-Za-z][A-Za-z0-9_]*$/,message:"字母数字下划线"}],children:e.jsx(s.Input,{placeholder:"默认 = entityCode"})})]}),e.jsx(s.Form.Item,{name:"description",label:"描述",children:e.jsx(is,{rows:2})}),e.jsx(s.Form.List,{name:"fields",children:(l,{add:j,remove:I})=>e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{marginBottom:8},children:e.jsx(s.Button,{type:"dashed",onClick:()=>j({fieldType:"STRING",required:!1}),icon:e.jsx(i.PlusOutlined,{}),children:"添加字段"})}),e.jsx(s.Table,{rowKey:C=>C.fieldCode||Math.random(),columns:[{title:"编码",dataIndex:"fieldCode",render:(C,d,g)=>e.jsx(s.Form.Item,{name:[g,"fieldCode"],noStyle:!0,rules:[{required:!0,pattern:/^[A-Za-z][A-Za-z0-9_]*$/,message:"字母数字下划线"}],children:e.jsx(s.Input,{size:"small",placeholder:"userName"})})},{title:"名称",dataIndex:"fieldName",render:(C,d,g)=>e.jsx(s.Form.Item,{name:[g,"fieldName"],noStyle:!0,children:e.jsx(s.Input,{size:"small",placeholder:"用户名"})})},{title:"类型",dataIndex:"fieldType",width:120,render:(C,d,g)=>e.jsx(s.Form.Item,{name:[g,"fieldType"],noStyle:!0,children:e.jsx(s.Select,{size:"small",children:Ae.map(v=>e.jsx(ns,{value:v.type,children:v.type},v.type))})})},{title:"必填",dataIndex:"required",width:60,render:(C,d,g)=>e.jsx(s.Form.Item,{name:[g,"required"],noStyle:!0,valuePropName:"checked",children:e.jsx(s.Switch,{size:"small"})})},{title:"字典",dataIndex:"dictCode",width:110,render:(C,d,g)=>e.jsx(s.Form.Item,{name:[g,"dictCode"],noStyle:!0,children:e.jsx(s.Input,{size:"small",placeholder:"可选"})})},{title:"引用",dataIndex:"refEntity",width:110,render:(C,d,g)=>e.jsx(s.Form.Item,{name:[g,"refEntity"],noStyle:!0,children:e.jsx(s.Input,{size:"small",placeholder:"可选"})})},{title:"操作",width:60,render:(C,d,g)=>e.jsx(s.Button,{size:"small",danger:!0,type:"link",onClick:()=>I(g),children:"移除"})}],dataSource:l,pagination:!1,size:"small"})]})})]})}function Ct({field:t,onChange:a}){return e.jsx("div",{children:e.jsxs(s.Form,{layout:"vertical",size:"small",children:[e.jsx(s.Form.Item,{label:"字段编码 (物理列名)",required:!0,children:e.jsx(s.Input,{value:t.fieldCode||"",onChange:l=>a({fieldCode:l.target.value}),placeholder:"如 userName"})}),e.jsx(s.Form.Item,{label:"显示名称",children:e.jsx(s.Input,{value:t.fieldName||"",onChange:l=>a({fieldName:l.target.value}),placeholder:"如 用户名"})}),e.jsx(s.Form.Item,{label:"字段类型",children:e.jsx(s.Select,{value:t.fieldType||"STRING",onChange:l=>a({fieldType:l}),style:{width:"100%"},children:Ae.map(l=>e.jsxs(ns,{value:l.type,children:[l.label," (",l.type,")"]},l.type))})}),e.jsx(s.Form.Item,{label:"必填",children:e.jsx(s.Switch,{checked:!!t.required,onChange:l=>a({required:l})})}),(t.fieldType==="STRING"||t.fieldType==="TEXT")&&e.jsx(s.Form.Item,{label:"字段长度",children:e.jsx(s.InputNumber,{value:t.fieldLength,onChange:l=>a({fieldLength:l}),min:1,max:65535,style:{width:"100%"}})}),t.fieldType==="DECIMAL"&&e.jsx(s.Form.Item,{label:"小数位数",children:e.jsx(s.InputNumber,{value:t.scale,onChange:l=>a({scale:l}),min:0,max:10,style:{width:"100%"}})}),e.jsx(s.Form.Item,{label:"默认值",children:e.jsx(s.Input,{value:t.defaultValue||"",onChange:l=>a({defaultValue:l.target.value}),placeholder:"可选"})}),e.jsx(s.Form.Item,{label:"字典编码 (dictCode)",children:e.jsx(s.Input,{value:t.dictCode||"",onChange:l=>a({dictCode:l.target.value}),placeholder:"如 user_status"})}),e.jsx(s.Form.Item,{label:"引用实体 (refEntity)",children:e.jsx(s.Input,{value:t.refEntity||"",onChange:l=>a({refEntity:l.target.value}),placeholder:"如 其他 entity 的 entityCode"})}),e.jsx(s.Form.Item,{label:"排序号",children:e.jsx(s.InputNumber,{value:t.sortOrder??0,onChange:l=>a({sortOrder:l}),style:{width:"100%"}})}),e.jsx(s.Form.Item,{label:"备注",children:e.jsx(is,{rows:2,value:t.description||"",onChange:l=>a({description:l.target.value})})})]})})}const{Option:St}=s.Select,cs={STRING:{component:s.Input,props:{}},TEXT:{component:s.Input.TextArea,props:{rows:3}},INT:{component:s.InputNumber,props:{}},LONG:{component:s.InputNumber,props:{}},DECIMAL:{component:s.InputNumber,props:{step:.01}},BOOLEAN:{component:s.Switch,props:{}},DATE:{component:s.DatePicker,props:{format:"YYYY-MM-DD"}},DATETIME:{component:s.DatePicker,props:{format:"YYYY-MM-DD HH:mm:ss",showTime:!0}},JSON:{component:s.Input.TextArea,props:{rows:3,placeholder:"JSON 字符串"}},REF:{component:s.InputNumber,props:{}}};function ds(){const{entity:t}=se.useParams(),[a]=se.useSearchParams(),l=a.get("appCode")||"demo",j=a.get("tenant")||localStorage.getItem("z_tenant")||"default",[I,C]=r.useState([]),[d,g]=r.useState(null),[v,f]=r.useState([]),[O,m]=r.useState(0),[h,z]=r.useState(1),[y,$]=r.useState(10),[E,N]=r.useState(!1),[T,w]=r.useState(!1),[P,S]=r.useState(null),[M]=s.Form.useForm(),[U,J]=r.useState({}),H=r.useCallback(async()=>{try{const p=await Y.get(`/lc/app/${l}/schema`,{params:{tenantCode:j}});C(Array.isArray(p)?p:[]);const c=(p||[]).find(D=>D.entityCode===t);g(c||null)}catch(p){s.message.error("加载 schema 失败: "+((p==null?void 0:p.message)||"未知错误")),C([]),g(null)}},[l,j,t]),o=r.useCallback(async p=>{if(!p||U[p])return U[p]||[];try{const c=await Y.get("/dict/items/get",{params:{dictCode:p}}),R=(Array.isArray(c)?c:[]).map(W=>({value:W.itemValue??W.itemCode,label:W.itemName??W.itemLabel??W.itemCode}));return J(W=>({...W,[p]:R})),R}catch{return[]}},[U]),n=r.useCallback(async()=>{if(d){N(!0);try{const p=await Y.post(`/lc/runtime/${d.entityCode}/list`,{tenantCode:j,appCode:l,entityCode:d.entityCode,page:h,size:y});f((p==null?void 0:p.records)||[]),m((p==null?void 0:p.total)||0)}catch(p){s.message.error("查询失败: "+((p==null?void 0:p.message)||"未知错误")),f([]),m(0)}finally{N(!1)}}},[d,j,l,h,y]);if(r.useEffect(()=>{H()},[H]),r.useEffect(()=>{n()},[n]),r.useEffect(()=>{!d||!d.fields||d.fields.forEach(p=>{p.dictCode&&o(p.dictCode)})},[d,o]),!t)return e.jsx(s.Empty,{description:"缺少实体编码 (路径变量 :entity)"});if(!d)return e.jsx(s.Card,{title:e.jsxs(e.Fragment,{children:[e.jsx(i.DatabaseOutlined,{})," z-lc 运行时"]}),children:e.jsx(s.Alert,{type:"warning",showIcon:!0,message:`实体 ${t} 未定义`,description:`请先在 模型编辑器 (路径 /form/_model?appCode=${l}) 中定义实体, 然后刷新此页.`})});const L=d.fields||[],b=()=>{S(null),M.resetFields(),w(!0)},A=async p=>{S(p);try{const c=await Y.post(`/lc/runtime/${d.entityCode}/get`,{tenantCode:j,appCode:l,entityCode:d.entityCode,id:p.id});M.resetFields(),M.setFieldsValue(c||p)}catch{M.resetFields(),M.setFieldsValue(p)}w(!0)},V=p=>{s.Modal.confirm({title:"确定删除?",content:`id=${p.id}`,okType:"danger",onOk:async()=>{try{await Y.post(`/lc/runtime/${d.entityCode}/delete`,{tenantCode:j,appCode:l,entityCode:d.entityCode,id:p.id}),s.message.success("删除成功"),n()}catch(c){s.message.error("删除失败: "+((c==null?void 0:c.message)||"未知错误"))}}})},re=async()=>{try{const p=await M.validateFields(),c={tenantCode:j,appCode:l,entityCode:d.entityCode,fieldValues:{...p}};P?(c.fieldValues.id=P.id,await Y.post(`/lc/runtime/${d.entityCode}/update`,c),s.message.success("更新成功")):(await Y.post(`/lc/runtime/${d.entityCode}/create`,c),s.message.success("创建成功")),w(!1),n()}catch(p){p!=null&&p.errorFields?s.message.error("请补全必填字段"):s.message.error("提交失败: "+((p==null?void 0:p.message)||"未知错误"))}},ae=(p,c)=>{const D=c[p.fieldCode],R=p.fieldCode+"_label";if(c[R]!=null)return e.jsx(s.Tag,{children:c[R]});if(D==null)return"-";if(p.fieldType==="BOOLEAN")return D?"是":"否";if(p.fieldType==="DATETIME"||p.fieldType==="DATE")try{return new Date(D).toLocaleString()}catch{return String(D)}return String(D)},oe=[{title:"ID",dataIndex:"id",key:"id",width:80},...L.map(p=>({title:p.fieldName||p.fieldCode,dataIndex:p.fieldCode,key:p.fieldCode,render:(c,D)=>ae(p,D)})),{title:"操作",key:"action",width:180,fixed:"right",render:(p,c)=>e.jsxs(s.Space,{children:[e.jsx(s.Button,{type:"link",icon:e.jsx(i.EditOutlined,{}),onClick:()=>A(c),children:"编辑"}),e.jsx(s.Button,{type:"link",danger:!0,icon:e.jsx(i.DeleteOutlined,{}),onClick:()=>V(c),children:"删除"})]})}],k=p=>{const c=(p.fieldType||"STRING").toUpperCase();if(p.dictCode){const W=U[p.dictCode]||[];return e.jsx(s.Select,{placeholder:`选择 ${p.fieldName||p.fieldCode}`,allowClear:!0,showSearch:!0,optionFilterProp:"label",children:W.map(te=>e.jsx(St,{value:te.value,label:te.label,children:te.label},te.value))})}const D=cs[c]||cs.STRING,R=D.component;return e.jsx(R,{...D.props,placeholder:p.fieldName||p.fieldCode})};return e.jsxs(s.Card,{title:e.jsxs(e.Fragment,{children:[e.jsx(i.DatabaseOutlined,{})," ",d.entityName||d.entityCode," (运行时 CRUD)"]}),extra:e.jsxs(s.Space,{children:[e.jsx(s.Button,{icon:e.jsx(i.ReloadOutlined,{}),onClick:n,children:"刷新"}),e.jsx(s.Button,{type:"primary",icon:e.jsx(i.PlusOutlined,{}),onClick:b,children:"新增"})]}),children:[e.jsx(s.Alert,{type:"info",showIcon:!0,message:`App=${l} · Tenant=${j} · 字段数=${L.length}`,style:{marginBottom:16}}),e.jsx(s.Spin,{spinning:E,children:e.jsx(s.Table,{rowKey:"id",columns:oe,dataSource:v,pagination:{current:h,pageSize:y,total:O,showSizeChanger:!0,showTotal:p=>`共 ${p} 条`,onChange:(p,c)=>{z(p),$(c)}},scroll:{x:"max-content"},size:"small"})}),e.jsx(s.Modal,{title:P?`编辑 #${P.id}`:"新增记录",open:T,onCancel:()=>w(!1),onOk:re,width:680,destroyOnClose:!0,children:e.jsx(s.Form,{form:M,layout:"vertical",children:L.map(p=>e.jsx(s.Form.Item,{name:p.fieldCode,label:e.jsxs("span",{children:[p.fieldName||p.fieldCode,p.required&&e.jsx("span",{style:{color:"red"},children:" *"}),e.jsx(s.Tag,{style:{marginLeft:8},children:p.fieldType})]}),rules:p.required?[{required:!0,message:"必填"}]:[],children:k(p)},p.fieldCode))})})]})}const bt=()=>{const{entity:t}=se.useParams();return t?t==="_model"?e.jsx(as,{}):e.jsx(ds,{}):e.jsxs("div",{style:{padding:24},children:["缺少实体编码. 请访问 ",e.jsx("code",{children:"/form/_model"})," 编辑模型, 或 ",e.jsx("code",{children:"/form/{entityCode}"})," 运行时 CRUD."]})},{Text:ve,Paragraph:ar}=s.Typography,{TextArea:Tt}=s.Input,us={PENDING:"default",GENERATING:"processing",READY:"success",FAILED:"error"},ps={Entity:"blue",Mapper:"cyan",Service:"green",ServiceImpl:"lime",Controller:"orange",ReactPage:"purple",File:"default"};function wt(){const a=new URLSearchParams(window.location.search).get("appCode")||"demo",[l]=r.useState(a),[j,I]=r.useState([]),[C,d]=r.useState(!1),[g,v]=r.useState(!1),[f,O]=r.useState(!1),[m,h]=r.useState([]),[z,y]=r.useState(null),[$,E]=r.useState([]),[N]=s.Form.useForm();r.useEffect(()=>{T(),w()},[l]);const T=async()=>{d(!0);try{const o=await Y.get(`/lc/app/${l}/materialize/list`,{params:{limit:50}});I((o==null?void 0:o.data)||[])}catch{s.message.warning("加载批次列表失败")}finally{d(!1)}},w=async()=>{var o;try{const n=await Y.get(`/lc/app/${l}/schema`),L=((o=n==null?void 0:n.data)==null?void 0:o.entities)||(n==null?void 0:n.data)||[];E(L)}catch{}},P=async()=>{var o;try{const n=await N.validateFields(),L={appCode:l,materializationPath:n.materializationPath,entityCodes:(o=n.entityCodes)!=null&&o.length?n.entityCodes:null,description:n.description,triggerSource:"USER"};await Y.post(`/lc/app/${l}/materialize`,L),s.message.success("物化已触发,请稍后查看状态"),v(!1),N.resetFields(),T()}catch(n){n!=null&&n.errorFields||s.message.error("触发失败:"+((n==null?void 0:n.message)||"未知错误"))}},S=async o=>{try{const n=await Y.get(`/lc/app/${l}/materialize/diff`,{params:{id:o.id}}),L=(n==null?void 0:n.data)||[];h(L),O(!0),y(null)}catch{s.message.error("加载文件清单失败")}},M=o=>{var n;try{(n=navigator.clipboard)==null||n.writeText(o),s.message.success("已复制到剪贴板")}catch{s.message.warning("复制失败")}},U=o=>{const n=new Blob([o.content],{type:"text/plain;charset=utf-8"}),L=URL.createObjectURL(n),b=document.createElement("a");b.href=L,b.download=o.relativePath.split("/").pop(),b.click(),URL.revokeObjectURL(L)},J=[{title:"批次号",dataIndex:"exportVersion",width:180,render:o=>e.jsx(ve,{code:!0,children:o})},{title:"状态",dataIndex:"status",width:100,render:o=>e.jsx(s.Badge,{status:us[o]==="success"?"success":us[o]==="error"?"error":"processing",text:o})},{title:"文件数",dataIndex:"fileCount",width:80,align:"center",render:o=>o||0},{title:"来源",dataIndex:"triggerSource",width:80,render:o=>e.jsx(s.Tag,{children:o})},{title:"路径",dataIndex:"materializationPath",ellipsis:!0,render:o=>e.jsx(ve,{type:"secondary",style:{fontSize:12},children:o})},{title:"创建时间",dataIndex:"createTime",width:170},{title:"操作",key:"action",width:200,fixed:"right",render:(o,n)=>e.jsx(s.Space,{size:"small",children:e.jsx(s.Button,{size:"small",type:"link",icon:e.jsx(i.FileTextOutlined,{}),onClick:()=>S(n),disabled:n.status!=="READY"&&n.status!=="GENERATING",children:"查看文件"})})}],H=[{title:"类型",dataIndex:"type",width:100,render:o=>e.jsx(s.Tag,{color:ps[o]||"default",children:o})},{title:"Entity",dataIndex:"entityCode",width:120,render:o=>o?e.jsx(ve,{code:!0,children:o}):"-"},{title:"相对路径",dataIndex:"relativePath",ellipsis:!0,render:o=>e.jsx(ve,{code:!0,style:{fontSize:12},children:o})},{title:"大小",dataIndex:"sizeBytes",width:90,render:o=>`${(o/1024).toFixed(1)}KB`},{title:"操作",key:"action",width:200,fixed:"right",render:(o,n)=>e.jsxs(s.Space,{size:"small",children:[e.jsx(s.Button,{size:"small",type:"link",onClick:()=>y(n),children:"预览"}),e.jsx(s.Button,{size:"small",type:"link",icon:e.jsx(i.CopyOutlined,{}),onClick:()=>M(n.content),children:"复制"}),e.jsx(s.Button,{size:"small",type:"link",icon:e.jsx(i.DownloadOutlined,{}),onClick:()=>U(n),children:"下载"})]})}];return e.jsxs("div",{style:{padding:16},children:[e.jsxs(s.Card,{children:[e.jsx(s.Alert,{type:"info",showIcon:!0,icon:e.jsx(i.CodeOutlined,{}),style:{marginBottom:16},message:`z-lc 代码物化 (FEATURE006 T1) — App: ${l}`,description:"将低代码定义的 entity/field 渲染为可编译的 Java (Entity/Mapper/Service/Controller) + React 页面代码。导出是异步的, 完成后可在此查看文件清单。"}),e.jsxs(s.Space,{style:{marginBottom:16},children:[e.jsx(s.Button,{icon:e.jsx(i.ReloadOutlined,{}),onClick:T,children:"刷新"}),e.jsx(s.Button,{type:"primary",icon:e.jsx(i.ExportOutlined,{}),onClick:()=>v(!0),children:"导出代码"}),e.jsx(s.Button,{icon:e.jsx(i.HistoryOutlined,{}),onClick:()=>s.message.info(`共 ${j.length} 个历史批次`),children:"历史"})]}),e.jsx(s.Table,{dataSource:j,columns:J,rowKey:"id",loading:C,pagination:{pageSize:10},size:"small",scroll:{x:1e3}})]}),e.jsx(s.Modal,{title:"触发代码物化",open:g,onCancel:()=>v(!1),onOk:P,okText:"开始导出",width:600,children:e.jsxs(s.Form,{form:N,layout:"vertical",style:{marginTop:16},initialValues:{materializationPath:`app-${l}/v1`},children:[e.jsx(s.Form.Item,{name:"materializationPath",label:"导出根路径 (相对沙箱默认根)",rules:[{required:!0,message:"请输入路径"}],extra:"默认根: ${user.home}/z-lc-materialized. 如需写入绝对路径, 服务端需配置 z-lc.materialize.allow-absolute-path=true",children:e.jsx(s.Input,{placeholder:`app-${l}/v1`})}),e.jsx(s.Form.Item,{name:"entityCodes",label:"导出的 entity (留空 = 全量)",children:e.jsx(s.Select,{mode:"multiple",placeholder:"选择 entity",allowClear:!0,options:$.map(o=>({value:o.entityCode,label:`${o.entityCode} (${o.tableName})`}))})}),e.jsx(s.Form.Item,{name:"description",label:"备注",children:e.jsx(Tt,{rows:2,placeholder:"本次导出的业务说明"})})]})}),e.jsx(s.Modal,{title:`物化文件清单 (${m.length} 个)`,open:f,onCancel:()=>{O(!1),y(null)},footer:e.jsx(s.Button,{onClick:()=>{O(!1),y(null)},children:"关闭"}),width:z?1100:800,children:z?e.jsxs("div",{children:[e.jsxs(s.Space,{style:{marginBottom:8},children:[e.jsx(s.Button,{onClick:()=>y(null),children:"← 返回清单"}),e.jsx(ve,{strong:!0,children:z.relativePath}),e.jsx(s.Tag,{color:ps[z.type]||"default",children:z.type}),e.jsx(s.Button,{size:"small",icon:e.jsx(i.CopyOutlined,{}),onClick:()=>M(z.content),children:"复制"}),e.jsx(s.Button,{size:"small",icon:e.jsx(i.DownloadOutlined,{}),onClick:()=>U(z),children:"下载"})]}),e.jsx("pre",{style:{background:"#1e1e1e",color:"#d4d4d4",padding:16,borderRadius:8,maxHeight:500,overflow:"auto",fontSize:12,fontFamily:"Menlo, Monaco, monospace"},children:z.content})]}):e.jsx(s.Table,{dataSource:m,columns:H,rowKey:"relativePath",pagination:{pageSize:20},size:"small",scroll:{x:700}})})]})}const{TextArea:ms}=s.Input;function xs({open:t,onClose:a,onSuccess:l,envOptions:j=[]}){const[I,C]=r.useState("paste"),[d,g]=r.useState(""),[v,f]=r.useState(null),[O,m]=r.useState(null),[h,z]=r.useState(!1),[y,$]=r.useState([]),[E,N]=r.useState(!1),[T]=s.Form.useForm(),w=r.useRef(null),P=()=>{g(""),f(null),m(null),$([]),T.resetFields()},S=()=>{P(),a()},M=async()=>{if(!d.trim()){s.message.warning("请先粘贴或上传 API 规约");return}m(null),z(!0);try{const n=await q.openapi.parse(d);n.success?(f(n),$((n.endpoints||[]).map((L,b)=>b)),T.setFieldsValue({envCode:j[0]||"default",projectCode:"default",defaultResponse:`{
22
+ <%s key={someKey} {...props} />`,V,Z,fe,Z),O[Z+V]=!0)}if(Z=null,$!==void 0&&(n($),Z=""+$),i(L)&&(n(L.key),Z=""+L.key),"key"in L){$={};for(var Ee in L)Ee!=="key"&&($[Ee]=L[Ee])}else $=L;return Z&&c($,typeof j=="function"?j.displayName||j.name||"Unknown":j),h(j,Z,$,l(),ie,X)}function d(j){b(j)?j._store&&(j._store.validated=1):typeof j=="object"&&j!==null&&j.$$typeof===K&&(j._payload.status==="fulfilled"?b(j._payload.value)&&j._payload.value._store&&(j._payload.value._store.validated=1):j._store&&(j._store.validated=1))}function b(j){return typeof j=="object"&&j!==null&&j.$$typeof===E}var F=p,E=Symbol.for("react.transitional.element"),_=Symbol.for("react.portal"),C=Symbol.for("react.fragment"),S=Symbol.for("react.strict_mode"),w=Symbol.for("react.profiler"),T=Symbol.for("react.consumer"),A=Symbol.for("react.context"),k=Symbol.for("react.forward_ref"),R=Symbol.for("react.suspense"),H=Symbol.for("react.suspense_list"),Y=Symbol.for("react.memo"),K=Symbol.for("react.lazy"),m=Symbol.for("react.activity"),f=Symbol.for("react.client.reference"),z=F.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,P=Object.prototype.hasOwnProperty,D=Array.isArray,Q=console.createTask?console.createTask:function(){return null};F={react_stack_bottom_frame:function(j){return j()}};var oe,ge={},he=F.react_stack_bottom_frame.bind(F,a)(),N=Q(o(a)),O={};Ke.Fragment=C,Ke.jsx=function(j,L,$){var V=1e4>z.recentlyCreatedOwnerStacks++;return y(j,L,$,!1,V?Error("react-stack-top-frame"):he,V?Q(o(j)):N)},Ke.jsxs=function(j,L,$){var V=1e4>z.recentlyCreatedOwnerStacks++;return y(j,L,$,!0,V?Error("react-stack-top-frame"):he,V?Q(o(j)):N)}})()),Ke}var Gt;function ur(){return Gt||(Gt=1,process.env.NODE_ENV==="production"?ot.exports=cr():ot.exports=dr()),ot.exports}var e=ur();const{Header:pr,Sider:mr,Content:hr}=t.Layout;function fr({menuItems:s=[],appTitle:r="One Company",appShort:n="OC",headerExtra:o,loading:l=!1}){const[a,i]=p.useState(!1),c=ue.useNavigate(),x=ue.useLocation(),h=({key:y})=>{c(y)};return e.jsxs(t.Layout,{style:{minHeight:"100vh"},children:[e.jsxs(mr,{trigger:null,collapsible:!0,collapsed:a,children:[e.jsx("div",{style:{height:64,display:"flex",alignItems:"center",justifyContent:"center",color:"white",fontSize:a?14:18,fontWeight:"bold"},children:a?n:r}),l?e.jsx("div",{style:{padding:16,textAlign:"center"},children:e.jsx(t.Spin,{size:"small"})}):e.jsx(t.Menu,{theme:"dark",mode:"inline",selectedKeys:[x.pathname],items:s,onClick:h})]}),e.jsxs(t.Layout,{children:[e.jsxs(pr,{style:{padding:"0 16px",background:"#fff",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsx("span",{onClick:()=>i(!a),style:{fontSize:18,cursor:"pointer"},children:a?e.jsx(g.MenuUnfoldOutlined,{}):e.jsx(g.MenuFoldOutlined,{})}),o]}),e.jsx(hr,{style:{margin:16,padding:24,background:"#fff",minHeight:280},children:e.jsx(ue.Outlet,{})})]})]})}const Jt={1:{color:"green",text:"正常"},0:{color:"red",text:"禁用"},pending:{color:"orange",text:"待处理"},approved:{color:"blue",text:"已通过"},rejected:{color:"red",text:"已拒绝"}};function xr({status:s,map:r}){const n=(r==null?void 0:r[s])||Jt[s]||{color:"default",text:String(s)};return e.jsx(t.Tag,{color:n.color,children:n.text})}function Vt(s,r){return function(){return s.apply(r,arguments)}}const{toString:gr}=Object.prototype,{getPrototypeOf:Me}=Object,{iterator:Xe,toStringTag:Kt}=Symbol,lt=(({hasOwnProperty:s})=>(r,n)=>s.call(r,n))(Object.prototype),Ye=(s,r)=>{let n=s;const o=[];for(;n!=null&&n!==Object.prototype;){if(o.indexOf(n)!==-1)return!1;if(o.push(n),lt(n,r))return!0;n=Me(n)}return!1},yr=(s,r)=>s!=null&&Ye(s,r)?s[r]:void 0,Ct=(s=>r=>{const n=gr.call(r);return s[n]||(s[n]=n.slice(8,-1).toLowerCase())})(Object.create(null)),Ce=s=>(s=s.toLowerCase(),r=>Ct(r)===s),it=s=>r=>typeof r===s,{isArray:Pe}=Array,ze=it("undefined");function Ue(s){return s!==null&&!ze(s)&&s.constructor!==null&&!ze(s.constructor)&&xe(s.constructor.isBuffer)&&s.constructor.isBuffer(s)}const Xt=Ce("ArrayBuffer");function jr(s){let r;return typeof ArrayBuffer<"u"&&ArrayBuffer.isView?r=ArrayBuffer.isView(s):r=s&&s.buffer&&Xt(s.buffer),r}const br=it("string"),xe=it("function"),Yt=it("number"),$e=s=>s!==null&&typeof s=="object",Sr=s=>s===!0||s===!1,at=s=>{if(!$e(s))return!1;const r=Me(s);return(r===null||r===Object.prototype||Me(r)===null)&&!Ye(s,Kt)&&!Ye(s,Xe)},wr=s=>{if(!$e(s)||Ue(s))return!1;try{return Object.keys(s).length===0&&Object.getPrototypeOf(s)===Object.prototype}catch{return!1}},Cr=Ce("Date"),Tr=Ce("File"),Er=s=>!!(s&&typeof s.uri<"u"),Ir=s=>s&&typeof s.getParts<"u",Or=Ce("Blob"),kr=Ce("FileList"),vr=s=>$e(s)&&xe(s.pipe);function Fr(){return typeof globalThis<"u"?globalThis:typeof self<"u"?self:typeof window<"u"?window:typeof global<"u"?global:{}}const Zt=Fr(),Qt=typeof Zt.FormData<"u"?Zt.FormData:void 0,Ar=s=>{if(!s)return!1;if(Qt&&s instanceof Qt)return!0;const r=Me(s);if(!r||r===Object.prototype||!xe(s.append))return!1;const n=Ct(s);return n==="formdata"||n==="object"&&xe(s.toString)&&s.toString()==="[object FormData]"},Pr=Ce("URLSearchParams"),[Rr,Nr,_r,Dr]=["ReadableStream","Request","Response","Headers"].map(Ce),Lr=s=>s.trim?s.trim():s.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"");function Ze(s,r,{allOwnKeys:n=!1}={}){if(s===null||typeof s>"u")return;let o,l;if(typeof s!="object"&&(s=[s]),Pe(s))for(o=0,l=s.length;o<l;o++)r.call(null,s[o],o,s);else{if(Ue(s))return;const a=n?Object.getOwnPropertyNames(s):Object.keys(s),i=a.length;let c;for(o=0;o<i;o++)c=a[o],r.call(null,s[c],c,s)}}function es(s,r){if(Ue(s))return null;r=r.toLowerCase();const n=Object.keys(s);let o=n.length,l;for(;o-- >0;)if(l=n[o],r===l.toLowerCase())return l;return null}const Re=typeof globalThis<"u"?globalThis:typeof self<"u"?self:typeof window<"u"?window:global,ts=s=>!ze(s)&&s!==Re;function Tt(...s){const{caseless:r,skipUndefined:n}=ts(this)&&this||{},o={},l=(a,i)=>{if(i==="__proto__"||i==="constructor"||i==="prototype")return;const c=r&&typeof i=="string"&&es(o,i)||i,x=lt(o,c)?o[c]:void 0;at(x)&&at(a)?o[c]=Tt(x,a):at(a)?o[c]=Tt({},a):Pe(a)?o[c]=a.slice():(!n||!ze(a))&&(o[c]=a)};for(let a=0,i=s.length;a<i;a++){const c=s[a];if(!c||Ue(c)||(Ze(c,l),typeof c!="object"||Pe(c)))continue;const x=Object.getOwnPropertySymbols(c);for(let h=0;h<x.length;h++){const y=x[h];Kr.call(c,y)&&l(c[y],y)}}return o}const Br=(s,r,n,{allOwnKeys:o}={})=>(Ze(r,(l,a)=>{n&&xe(l)?Object.defineProperty(s,a,{__proto__:null,value:Vt(l,n),writable:!0,enumerable:!0,configurable:!0}):Object.defineProperty(s,a,{__proto__:null,value:l,writable:!0,enumerable:!0,configurable:!0})},{allOwnKeys:o}),s),Mr=s=>(s.charCodeAt(0)===65279&&(s=s.slice(1)),s),zr=(s,r,n,o)=>{s.prototype=Object.create(r.prototype,o),Object.defineProperty(s.prototype,"constructor",{__proto__:null,value:s,writable:!0,enumerable:!1,configurable:!0}),Object.defineProperty(s,"super",{__proto__:null,value:r.prototype}),n&&Object.assign(s.prototype,n)},Ur=(s,r,n,o)=>{let l,a,i;const c={};if(r=r||{},s==null)return r;do{for(l=Object.getOwnPropertyNames(s),a=l.length;a-- >0;)i=l[a],(!o||o(i,s,r))&&!c[i]&&(r[i]=s[i],c[i]=!0);s=n!==!1&&Me(s)}while(s&&(!n||n(s,r))&&s!==Object.prototype);return r},$r=(s,r,n)=>{s=String(s),(n===void 0||n>s.length)&&(n=s.length),n-=r.length;const o=s.indexOf(r,n);return o!==-1&&o===n},qr=s=>{if(!s)return null;if(Pe(s))return s;let r=s.length;if(!Yt(r))return null;const n=new Array(r);for(;r-- >0;)n[r]=s[r];return n},Hr=(s=>r=>s&&r instanceof s)(typeof Uint8Array<"u"&&Me(Uint8Array)),Wr=(s,r)=>{const o=(s&&s[Xe]).call(s);let l;for(;(l=o.next())&&!l.done;){const a=l.value;r.call(s,a[0],a[1])}},Gr=(s,r)=>{let n;const o=[];for(;(n=s.exec(r))!==null;)o.push(n);return o},Jr=Ce("HTMLFormElement"),Vr=s=>s.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g,function(n,o,l){return o.toUpperCase()+l}),{propertyIsEnumerable:Kr}=Object.prototype,Xr=Ce("RegExp"),ss=(s,r)=>{const n=Object.getOwnPropertyDescriptors(s),o={};Ze(n,(l,a)=>{let i;(i=r(l,a,s))!==!1&&(o[a]=i||l)}),Object.defineProperties(s,o)},Yr=s=>{ss(s,(r,n)=>{if(xe(s)&&["arguments","caller","callee"].includes(n))return!1;const o=s[n];if(xe(o)){if(r.enumerable=!1,"writable"in r){r.writable=!1;return}r.set||(r.set=()=>{throw Error("Can not rewrite read-only method '"+n+"'")})}})},Zr=(s,r)=>{const n={},o=l=>{l.forEach(a=>{n[a]=!0})};return Pe(s)?o(s):o(String(s).split(r)),n},Qr=()=>{},en=(s,r)=>s!=null&&Number.isFinite(s=+s)?s:r;function tn(s){return!!(s&&xe(s.append)&&s[Kt]==="FormData"&&s[Xe])}const sn=s=>{const r=new WeakSet,n=o=>{if($e(o)){if(r.has(o))return;if(Ue(o))return o;if(!("toJSON"in o)){r.add(o);const l=Pe(o)?[]:{};return Ze(o,(a,i)=>{const c=n(a);!ze(c)&&(l[i]=c)}),r.delete(o),l}}return o};return n(s)},rn=Ce("AsyncFunction"),nn=s=>s&&($e(s)||xe(s))&&xe(s.then)&&xe(s.catch),rs=((s,r)=>s?setImmediate:r?((n,o)=>(Re.addEventListener("message",({source:l,data:a})=>{l===Re&&a===n&&o.length&&o.shift()()},!1),l=>{o.push(l),Re.postMessage(n,"*")}))(`axios@${Math.random()}`,[]):n=>setTimeout(n))(typeof setImmediate=="function",xe(Re.postMessage)),on=typeof queueMicrotask<"u"?queueMicrotask.bind(Re):typeof process<"u"&&process.nextTick||rs,ns=s=>s!=null&&xe(s[Xe]),u={isArray:Pe,isArrayBuffer:Xt,isBuffer:Ue,isFormData:Ar,isArrayBufferView:jr,isString:br,isNumber:Yt,isBoolean:Sr,isObject:$e,isPlainObject:at,isEmptyObject:wr,isReadableStream:Rr,isRequest:Nr,isResponse:_r,isHeaders:Dr,isUndefined:ze,isDate:Cr,isFile:Tr,isReactNativeBlob:Er,isReactNative:Ir,isBlob:Or,isRegExp:Xr,isFunction:xe,isStream:vr,isURLSearchParams:Pr,isTypedArray:Hr,isFileList:kr,forEach:Ze,merge:Tt,extend:Br,trim:Lr,stripBOM:Mr,inherits:zr,toFlatObject:Ur,kindOf:Ct,kindOfTest:Ce,endsWith:$r,toArray:qr,forEachEntry:Wr,matchAll:Gr,isHTMLForm:Jr,hasOwnProperty:lt,hasOwnProp:lt,hasOwnInPrototypeChain:Ye,getSafeProp:yr,reduceDescriptors:ss,freezeMethods:Yr,toObjectSet:Zr,toCamelCase:Vr,noop:Qr,toFiniteNumber:en,findKey:es,global:Re,isContextDefined:ts,isSpecCompliantForm:tn,toJSONObject:sn,isAsyncFn:rn,isThenable:nn,setImmediate:rs,asap:on,isIterable:ns,isSafeIterable:s=>s!=null&&Ye(s,Xe)&&ns(s)},ln=u.toObjectSet(["age","authorization","content-length","content-type","etag","expires","from","host","if-modified-since","if-unmodified-since","last-modified","location","max-forwards","proxy-authorization","referer","retry-after","user-agent"]),an=s=>{const r={};let n,o,l;return s&&s.split(`
23
+ `).forEach(function(i){l=i.indexOf(":"),n=i.substring(0,l).trim().toLowerCase(),o=i.substring(l+1).trim(),!(!n||r[n]&&ln[n])&&(n==="set-cookie"?r[n]?r[n].push(o):r[n]=[o]:r[n]=r[n]?r[n]+", "+o:o)}),r};function cn(s){let r=0,n=s.length;for(;r<n;){const o=s.charCodeAt(r);if(o!==9&&o!==32)break;r+=1}for(;n>r;){const o=s.charCodeAt(n-1);if(o!==9&&o!==32)break;n-=1}return r===0&&n===s.length?s:s.slice(r,n)}const dn=new RegExp("[\\u0000-\\u0008\\u000a-\\u001f\\u007f]+","g"),un=new RegExp("[^\\u0009\\u0020-\\u007e\\u0080-\\u00ff]+","g");function Et(s,r){return u.isArray(s)?s.map(n=>Et(n,r)):cn(String(s).replace(r,""))}const pn=s=>Et(s,dn),mn=s=>Et(s,un);function os(s){const r=Object.create(null);return u.forEach(s.toJSON(),(n,o)=>{r[o]=mn(n)}),r}const ls=Symbol("internals");function Qe(s){return s&&String(s).trim().toLowerCase()}function ct(s){return s===!1||s==null?s:u.isArray(s)?s.map(ct):pn(String(s))}function hn(s){const r=Object.create(null),n=/([^\s,;=]+)\s*(?:=\s*([^,;]+))?/g;let o;for(;o=n.exec(s);)r[o[1]]=o[2];return r}const fn=s=>/^[-_a-zA-Z0-9^`|~,!#$%&'*+.]+$/.test(s.trim());function It(s,r,n,o,l){if(u.isFunction(o))return o.call(this,r,n);if(l&&(r=n),!!u.isString(r)){if(u.isString(o))return r.indexOf(o)!==-1;if(u.isRegExp(o))return o.test(r)}}function xn(s){return s.trim().toLowerCase().replace(/([a-z\d])(\w*)/g,(r,n,o)=>n.toUpperCase()+o)}function gn(s,r){const n=u.toCamelCase(" "+r);["get","set","has"].forEach(o=>{Object.defineProperty(s,o+n,{__proto__:null,value:function(l,a,i){return this[o].call(this,r,l,a,i)},configurable:!0})})}let pe=class{constructor(r){r&&this.set(r)}set(r,n,o){const l=this;function a(c,x,h){const y=Qe(x);if(!y)return;const d=u.findKey(l,y);(!d||l[d]===void 0||h===!0||h===void 0&&l[d]!==!1)&&(l[d||x]=ct(c))}const i=(c,x)=>u.forEach(c,(h,y)=>a(h,y,x));if(u.isPlainObject(r)||r instanceof this.constructor)i(r,n);else if(u.isString(r)&&(r=r.trim())&&!fn(r))i(an(r),n);else if(u.isObject(r)&&u.isSafeIterable(r)){let c=Object.create(null),x,h;for(const y of r){if(!u.isArray(y))throw new TypeError("Object iterator must return a key-value pair");h=y[0],u.hasOwnProp(c,h)?(x=c[h],c[h]=u.isArray(x)?[...x,y[1]]:[x,y[1]]):c[h]=y[1]}i(c,n)}else r!=null&&a(n,r,o);return this}get(r,n){if(r=Qe(r),r){const o=u.findKey(this,r);if(o){const l=this[o];if(!n)return l;if(n===!0)return hn(l);if(u.isFunction(n))return n.call(this,l,o);if(u.isRegExp(n))return n.exec(l);throw new TypeError("parser must be boolean|regexp|function")}}}has(r,n){if(r=Qe(r),r){const o=u.findKey(this,r);return!!(o&&this[o]!==void 0&&(!n||It(this,this[o],o,n)))}return!1}delete(r,n){const o=this;let l=!1;function a(i){if(i=Qe(i),i){const c=u.findKey(o,i);c&&(!n||It(o,o[c],c,n))&&(delete o[c],l=!0)}}return u.isArray(r)?r.forEach(a):a(r),l}clear(r){const n=Object.keys(this);let o=n.length,l=!1;for(;o--;){const a=n[o];(!r||It(this,this[a],a,r,!0))&&(delete this[a],l=!0)}return l}normalize(r){const n=this,o={};return u.forEach(this,(l,a)=>{const i=u.findKey(o,a);if(i){n[i]=ct(l),delete n[a];return}const c=r?xn(a):String(a).trim();c!==a&&delete n[a],n[c]=ct(l),o[c]=!0}),this}concat(...r){return this.constructor.concat(this,...r)}toJSON(r){const n=Object.create(null);return u.forEach(this,(o,l)=>{o!=null&&o!==!1&&(n[l]=r&&u.isArray(o)?o.join(", "):o)}),n}[Symbol.iterator](){return Object.entries(this.toJSON())[Symbol.iterator]()}toString(){return Object.entries(this.toJSON()).map(([r,n])=>r+": "+n).join(`
24
+ `)}getSetCookie(){return this.get("set-cookie")||[]}get[Symbol.toStringTag](){return"AxiosHeaders"}static from(r){return r instanceof this?r:new this(r)}static concat(r,...n){const o=new this(r);return n.forEach(l=>o.set(l)),o}static accessor(r){const o=(this[ls]=this[ls]={accessors:{}}).accessors,l=this.prototype;function a(i){const c=Qe(i);o[c]||(gn(l,i),o[c]=!0)}return u.isArray(r)?r.forEach(a):a(r),this}};pe.accessor(["Content-Type","Content-Length","Accept","Accept-Encoding","User-Agent","Authorization"]),u.reduceDescriptors(pe.prototype,({value:s},r)=>{let n=r[0].toUpperCase()+r.slice(1);return{get:()=>s,set(o){this[n]=o}}}),u.freezeMethods(pe);const yn="[REDACTED ****]";function jn(s){if(u.hasOwnProp(s,"toJSON"))return!0;let r=Object.getPrototypeOf(s);for(;r&&r!==Object.prototype;){if(u.hasOwnProp(r,"toJSON"))return!0;r=Object.getPrototypeOf(r)}return!1}function bn(s,r){const n=new Set(r.map(a=>String(a).toLowerCase())),o=[],l=a=>{if(a===null||typeof a!="object"||u.isBuffer(a))return a;if(o.indexOf(a)!==-1)return;a instanceof pe&&(a=a.toJSON()),o.push(a);let i;if(u.isArray(a))i=[],a.forEach((c,x)=>{const h=l(c);u.isUndefined(h)||(i[x]=h)});else{if(!u.isPlainObject(a)&&jn(a))return o.pop(),a;i=Object.create(null);for(const[c,x]of Object.entries(a)){const h=n.has(c.toLowerCase())?yn:l(x);u.isUndefined(h)||(i[c]=h)}}return o.pop(),i};return l(s)}let M=class ir extends Error{static from(r,n,o,l,a,i){const c=new ir(r.message,n||r.code,o,l,a);return c.cause=r,c.name=r.name,r.status!=null&&c.status==null&&(c.status=r.status),i&&Object.assign(c,i),c}constructor(r,n,o,l,a){super(r),Object.defineProperty(this,"message",{__proto__:null,value:r,enumerable:!0,writable:!0,configurable:!0}),this.name="AxiosError",this.isAxiosError=!0,n&&(this.code=n),o&&(this.config=o),l&&(this.request=l),a&&(this.response=a,this.status=a.status)}toJSON(){const r=this.config,n=r&&u.hasOwnProp(r,"redact")?r.redact:void 0,o=u.isArray(n)&&n.length>0?bn(r,n):u.toJSONObject(r);return{message:this.message,name:this.name,description:this.description,number:this.number,fileName:this.fileName,lineNumber:this.lineNumber,columnNumber:this.columnNumber,stack:this.stack,config:o,code:this.code,status:this.status}}};M.ERR_BAD_OPTION_VALUE="ERR_BAD_OPTION_VALUE",M.ERR_BAD_OPTION="ERR_BAD_OPTION",M.ECONNABORTED="ECONNABORTED",M.ETIMEDOUT="ETIMEDOUT",M.ECONNREFUSED="ECONNREFUSED",M.ERR_NETWORK="ERR_NETWORK",M.ERR_FR_TOO_MANY_REDIRECTS="ERR_FR_TOO_MANY_REDIRECTS",M.ERR_DEPRECATED="ERR_DEPRECATED",M.ERR_BAD_RESPONSE="ERR_BAD_RESPONSE",M.ERR_BAD_REQUEST="ERR_BAD_REQUEST",M.ERR_CANCELED="ERR_CANCELED",M.ERR_NOT_SUPPORT="ERR_NOT_SUPPORT",M.ERR_INVALID_URL="ERR_INVALID_URL",M.ERR_FORM_DATA_DEPTH_EXCEEDED="ERR_FORM_DATA_DEPTH_EXCEEDED";const Sn=null,is=100;function Ot(s){return u.isPlainObject(s)||u.isArray(s)}function as(s){return u.endsWith(s,"[]")?s.slice(0,-2):s}function kt(s,r,n){return s?s.concat(r).map(function(l,a){return l=as(l),!n&&a?"["+l+"]":l}).join(n?".":""):r}function wn(s){return u.isArray(s)&&!s.some(Ot)}const Cn=u.toFlatObject(u,{},null,function(r){return/^is[A-Z]/.test(r)});function dt(s,r,n){if(!u.isObject(s))throw new TypeError("target must be an object");r=r||new FormData,n=u.toFlatObject(n,{metaTokens:!0,dots:!1,indexes:!1},!1,function(w,T){return!u.isUndefined(T[w])});const o=n.metaTokens,l=n.visitor||E,a=n.dots,i=n.indexes,c=n.Blob||typeof Blob<"u"&&Blob,x=n.maxDepth===void 0?is:n.maxDepth,h=c&&u.isSpecCompliantForm(r),y=[];if(!u.isFunction(l))throw new TypeError("visitor must be a function");function d(S){if(S===null)return"";if(u.isDate(S))return S.toISOString();if(u.isBoolean(S))return S.toString();if(!h&&u.isBlob(S))throw new M("Blob is not supported. Use a Buffer instead.");return u.isArrayBuffer(S)||u.isTypedArray(S)?h&&typeof Blob=="function"?new Blob([S]):Buffer.from(S):S}function b(S){if(S>x)throw new M("Object is too deeply nested ("+S+" levels). Max depth: "+x,M.ERR_FORM_DATA_DEPTH_EXCEEDED)}function F(S,w){if(x===1/0)return JSON.stringify(S);const T=[];return JSON.stringify(S,function(k,R){if(!u.isObject(R))return R;for(;T.length&&T[T.length-1]!==this;)T.pop();return T.push(R),b(w+T.length-1),R})}function E(S,w,T){let A=S;if(u.isReactNative(r)&&u.isReactNativeBlob(S))return r.append(kt(T,w,a),d(S)),!1;if(S&&!T&&typeof S=="object"){if(u.endsWith(w,"{}"))w=o?w:w.slice(0,-2),S=F(S,1);else if(u.isArray(S)&&wn(S)||(u.isFileList(S)||u.endsWith(w,"[]"))&&(A=u.toArray(S)))return w=as(w),A.forEach(function(R,H){!(u.isUndefined(R)||R===null)&&r.append(i===!0?kt([w],H,a):i===null?w:w+"[]",d(R))}),!1}return Ot(S)?!0:(r.append(kt(T,w,a),d(S)),!1)}const _=Object.assign(Cn,{defaultVisitor:E,convertValue:d,isVisitable:Ot});function C(S,w,T=0){if(!u.isUndefined(S)){if(b(T),y.indexOf(S)!==-1)throw new Error("Circular reference detected in "+w.join("."));y.push(S),u.forEach(S,function(k,R){(!(u.isUndefined(k)||k===null)&&l.call(r,k,u.isString(R)?R.trim():R,w,_))===!0&&C(k,w?w.concat(R):[R],T+1)}),y.pop()}}if(!u.isObject(s))throw new TypeError("data must be an object");return C(s),r}function cs(s){const r={"!":"%21","'":"%27","(":"%28",")":"%29","~":"%7E","%20":"+"};return encodeURIComponent(s).replace(/[!'()~]|%20/g,function(o){return r[o]})}function vt(s,r){this._pairs=[],s&&dt(s,this,r)}const ds=vt.prototype;ds.append=function(r,n){this._pairs.push([r,n])},ds.toString=function(r){const n=r?function(o){return r.call(this,o,cs)}:cs;return this._pairs.map(function(l){return n(l[0])+"="+n(l[1])},"").join("&")};function Tn(s){return encodeURIComponent(s).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+")}function us(s,r,n){if(!r)return s;const o=u.isFunction(n)?{serialize:n}:n,l=u.getSafeProp(o,"encode")||Tn,a=u.getSafeProp(o,"serialize");let i;if(a?i=a(r,o):i=u.isURLSearchParams(r)?r.toString():new vt(r,o).toString(l),i){const c=s.indexOf("#");c!==-1&&(s=s.slice(0,c)),s+=(s.indexOf("?")===-1?"?":"&")+i}return s}class ps{constructor(){this.handlers=[]}use(r,n,o){return this.handlers.push({fulfilled:r,rejected:n,synchronous:o?o.synchronous:!1,runWhen:o?o.runWhen:null}),this.handlers.length-1}eject(r){this.handlers[r]&&(this.handlers[r]=null)}clear(){this.handlers&&(this.handlers=[])}forEach(r){u.forEach(this.handlers,function(o){o!==null&&r(o)})}}const Ft={silentJSONParsing:!0,forcedJSONParsing:!0,clarifyTimeoutError:!1,legacyInterceptorReqResOrdering:!0,advertiseZstdAcceptEncoding:!1,validateStatusUndefinedResolves:!0},En={isBrowser:!0,classes:{URLSearchParams:typeof URLSearchParams<"u"?URLSearchParams:vt,FormData:typeof FormData<"u"?FormData:null,Blob:typeof Blob<"u"?Blob:null},protocols:["http","https","file","blob","url","data"]},At=typeof window<"u"&&typeof document<"u",Pt=typeof navigator=="object"&&navigator||void 0,In=At&&(!Pt||["ReactNative","NativeScript","NS"].indexOf(Pt.product)<0),On=typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope&&typeof self.importScripts=="function",kn=At&&window.location.href||"http://localhost",de={...Object.freeze(Object.defineProperty({__proto__:null,hasBrowserEnv:At,hasStandardBrowserEnv:In,hasStandardBrowserWebWorkerEnv:On,navigator:Pt,origin:kn},Symbol.toStringTag,{value:"Module"})),...En};function vn(s,r){return dt(s,new de.classes.URLSearchParams,{visitor:function(n,o,l,a){return de.isNode&&u.isBuffer(n)?(this.append(o,n.toString("base64")),!1):a.defaultVisitor.apply(this,arguments)},...r})}const ms=is;function hs(s){if(s>ms)throw new M("FormData field is too deeply nested ("+s+" levels). Max depth: "+ms,M.ERR_FORM_DATA_DEPTH_EXCEEDED)}function Fn(s){const r=[],n=/\w+|\[(\w*)]/g;let o;for(;(o=n.exec(s))!==null;)hs(r.length),r.push(o[0]==="[]"?"":o[1]||o[0]);return r}function An(s){const r={},n=Object.keys(s);let o;const l=n.length;let a;for(o=0;o<l;o++)a=n[o],r[a]=s[a];return r}function fs(s){function r(n,o,l,a){hs(a);let i=n[a++];if(i==="__proto__")return!0;const c=Number.isFinite(+i),x=a>=n.length;return i=!i&&u.isArray(l)?l.length:i,x?(u.hasOwnProp(l,i)?l[i]=u.isArray(l[i])?l[i].concat(o):[l[i],o]:l[i]=o,!c):((!u.hasOwnProp(l,i)||!u.isObject(l[i]))&&(l[i]=[]),r(n,o,l[i],a)&&u.isArray(l[i])&&(l[i]=An(l[i])),!c)}if(u.isFormData(s)&&u.isFunction(s.entries)){const n={};return u.forEachEntry(s,(o,l)=>{r(Fn(o),l,n,0)}),n}return null}const qe=(s,r)=>s!=null&&u.hasOwnProp(s,r)?s[r]:void 0;function Pn(s,r,n){if(u.isString(s))try{return(r||JSON.parse)(s),u.trim(s)}catch(o){if(o.name!=="SyntaxError")throw o}return(n||JSON.stringify)(s)}const et={transitional:Ft,adapter:["xhr","http","fetch"],transformRequest:[function(r,n){const o=n.getContentType()||"",l=o.indexOf("application/json")>-1,a=u.isObject(r);if(a&&u.isHTMLForm(r)&&(r=new FormData(r)),u.isFormData(r))return l?JSON.stringify(fs(r)):r;if(u.isArrayBuffer(r)||u.isBuffer(r)||u.isStream(r)||u.isFile(r)||u.isBlob(r)||u.isReadableStream(r))return r;if(u.isArrayBufferView(r))return r.buffer;if(u.isURLSearchParams(r))return n.setContentType("application/x-www-form-urlencoded;charset=utf-8",!1),r.toString();let c;if(a){const x=qe(this,"formSerializer");if(o.indexOf("application/x-www-form-urlencoded")>-1)return vn(r,x).toString();if((c=u.isFileList(r))||o.indexOf("multipart/form-data")>-1){const h=qe(this,"env"),y=h&&h.FormData;return dt(c?{"files[]":r}:r,y&&new y,x)}}return a||l?(n.setContentType("application/json",!1),Pn(r)):r}],transformResponse:[function(r){const n=qe(this,"transitional")||et.transitional,o=n&&n.forcedJSONParsing,l=qe(this,"responseType"),a=l==="json";if(u.isResponse(r)||u.isReadableStream(r))return r;if(r&&u.isString(r)&&(o&&!l||a)){const c=!(n&&n.silentJSONParsing)&&a;try{return JSON.parse(r,qe(this,"parseReviver"))}catch(x){if(c)throw x.name==="SyntaxError"?M.from(x,M.ERR_BAD_RESPONSE,this,null,qe(this,"response")):x}}return r}],timeout:0,xsrfCookieName:"XSRF-TOKEN",xsrfHeaderName:"X-XSRF-TOKEN",maxContentLength:-1,maxBodyLength:-1,env:{FormData:de.classes.FormData,Blob:de.classes.Blob},validateStatus:function(r){return r>=200&&r<300},headers:{common:{Accept:"application/json, text/plain, */*","Content-Type":void 0}}};u.forEach(["delete","get","head","post","put","patch","query"],s=>{et.headers[s]={}});function Rt(s,r){const n=this||et,o=r||n,l=pe.from(o.headers);let a=o.data;return u.forEach(s,function(c){a=c.call(n,a,l.normalize(),r?r.status:void 0)}),l.normalize(),a}function xs(s){return!!(s&&s.__CANCEL__)}let tt=class extends M{constructor(r,n,o){super(r??"canceled",M.ERR_CANCELED,n,o),this.name="CanceledError",this.__CANCEL__=!0}};function gs(s,r,n){const o=n.config.validateStatus;!n.status||!o||o(n.status)?s(n):r(new M("Request failed with status code "+n.status,n.status>=400&&n.status<500?M.ERR_BAD_REQUEST:M.ERR_BAD_RESPONSE,n.config,n.request,n))}function Rn(s){const r=/^([-+\w]{1,25}):(?:\/\/)?/.exec(s);return r&&r[1]||""}function Nn(s,r){s=s||10;const n=new Array(s),o=new Array(s);let l=0,a=0,i;return r=r!==void 0?r:1e3,function(x){const h=Date.now(),y=o[a];i||(i=h),n[l]=x,o[l]=h;let d=a,b=0;for(;d!==l;)b+=n[d++],d=d%s;if(l=(l+1)%s,l===a&&(a=(a+1)%s),h-i<r)return;const F=y&&h-y;return F?Math.round(b*1e3/F):void 0}}function _n(s,r){let n=0,o=1e3/r,l,a;const i=(h,y=Date.now())=>{n=y,l=null,a&&(clearTimeout(a),a=null),s(...h)};return[(...h)=>{const y=Date.now(),d=y-n;d>=o?i(h,y):(l=h,a||(a=setTimeout(()=>{a=null,i(l)},o-d)))},()=>l&&i(l)]}const ut=(s,r,n=3)=>{let o=0;const l=Nn(50,250);return _n(a=>{if(!a||typeof a.loaded!="number")return;const i=a.loaded,c=a.lengthComputable?a.total:void 0,x=c!=null?Math.min(i,c):i,h=Math.max(0,x-o),y=l(h);o=Math.max(o,x);const d={loaded:x,total:c,progress:c?x/c:void 0,bytes:h,rate:y||void 0,estimated:y&&c?(c-x)/y:void 0,event:a,lengthComputable:c!=null,[r?"download":"upload"]:!0};s(d)},n)},ys=(s,r)=>{const n=s!=null;return[o=>r[0]({lengthComputable:n,total:s,loaded:o}),r[1]]},js=s=>(...r)=>u.asap(()=>s(...r)),Dn=de.hasStandardBrowserEnv?((s,r)=>n=>(n=new URL(n,de.origin),s.protocol===n.protocol&&s.host===n.host&&(r||s.port===n.port)))(new URL(de.origin),de.navigator&&/(msie|trident)/i.test(de.navigator.userAgent)):()=>!0,Ln=de.hasStandardBrowserEnv?{write(s,r,n,o,l,a,i){if(typeof document>"u")return;const c=[`${s}=${encodeURIComponent(r)}`];u.isNumber(n)&&c.push(`expires=${new Date(n).toUTCString()}`),u.isString(o)&&c.push(`path=${o}`),u.isString(l)&&c.push(`domain=${l}`),a===!0&&c.push("secure"),u.isString(i)&&c.push(`SameSite=${i}`),document.cookie=c.join("; ")},read(s){if(typeof document>"u")return null;const r=document.cookie.split(";");for(let n=0;n<r.length;n++){const o=r[n].replace(/^\s+/,""),l=o.indexOf("=");if(l!==-1&&o.slice(0,l)===s)return decodeURIComponent(o.slice(l+1))}return null},remove(s){this.write(s,"",Date.now()-864e5,"/")}}:{write(){},read(){return null},remove(){}};function Bn(s){return typeof s!="string"?!1:/^([a-z][a-z\d+\-.]*:)?\/\//i.test(s)}function Mn(s,r){return r?s.replace(/\/?\/$/,"")+"/"+r.replace(/^\/+/,""):s}const zn=/^https?:(?!\/\/)/i,Un=/[\t\n\r]/g;function $n(s){let r=0;for(;r<s.length&&s.charCodeAt(r)<=32;)r++;return s.slice(r)}function qn(s){return $n(s).replace(Un,"")}function bs(s,r){if(typeof s=="string"&&zn.test(qn(s)))throw new M('Invalid URL: missing "//" after protocol',M.ERR_INVALID_URL,r)}function Ss(s,r,n,o){bs(r,o);let l=!Bn(r);return s&&(l||n===!1)?(bs(s,o),Mn(s,r)):r}const ws=s=>s instanceof pe?{...s}:s;function Ne(s,r){r=r||{};const n=Object.create(null);Object.defineProperty(n,"hasOwnProperty",{__proto__:null,value:Object.prototype.hasOwnProperty,enumerable:!1,writable:!0,configurable:!0});function o(y,d,b,F){return u.isPlainObject(y)&&u.isPlainObject(d)?u.merge.call({caseless:F},y,d):u.isPlainObject(d)?u.merge({},d):u.isArray(d)?d.slice():d}function l(y,d,b,F){if(u.isUndefined(d)){if(!u.isUndefined(y))return o(void 0,y,b,F)}else return o(y,d,b,F)}function a(y,d){if(!u.isUndefined(d))return o(void 0,d)}function i(y,d){if(u.isUndefined(d)){if(!u.isUndefined(y))return o(void 0,y)}else return o(void 0,d)}function c(y){const d=u.hasOwnProp(r,"transitional")?r.transitional:void 0;if(!u.isUndefined(d))if(u.isPlainObject(d)){if(u.hasOwnProp(d,y))return d[y]}else return;const b=u.hasOwnProp(s,"transitional")?s.transitional:void 0;if(u.isPlainObject(b)&&u.hasOwnProp(b,y))return b[y]}function x(y,d,b){if(u.hasOwnProp(r,b))return o(y,d);if(u.hasOwnProp(s,b))return o(void 0,y)}const h={url:a,method:a,data:a,baseURL:i,transformRequest:i,transformResponse:i,paramsSerializer:i,timeout:i,timeoutMessage:i,withCredentials:i,withXSRFToken:i,adapter:i,responseType:i,xsrfCookieName:i,xsrfHeaderName:i,onUploadProgress:i,onDownloadProgress:i,decompress:i,maxContentLength:i,maxBodyLength:i,beforeRedirect:i,transport:i,httpAgent:i,httpsAgent:i,cancelToken:i,socketPath:i,allowedSocketPaths:i,responseEncoding:i,validateStatus:x,headers:(y,d,b)=>l(ws(y),ws(d),b,!0)};return u.forEach(Object.keys({...s,...r}),function(d){if(d==="__proto__"||d==="constructor"||d==="prototype")return;const b=u.hasOwnProp(h,d)?h[d]:l,F=u.hasOwnProp(s,d)?s[d]:void 0,E=u.hasOwnProp(r,d)?r[d]:void 0,_=b(F,E,d);u.isUndefined(_)&&b!==x||(n[d]=_)}),u.hasOwnProp(r,"validateStatus")&&u.isUndefined(r.validateStatus)&&c("validateStatusUndefinedResolves")===!1&&(u.hasOwnProp(s,"validateStatus")?n.validateStatus=o(void 0,s.validateStatus):delete n.validateStatus),n}const Hn=["content-type","content-length"];function Wn(s,r,n){if(n!=="content-only"){s.set(r);return}Object.entries(r).forEach(([o,l])=>{Hn.includes(o.toLowerCase())&&s.set(o,l)})}const Gn=s=>encodeURIComponent(s).replace(/%([0-9A-F]{2})/gi,(r,n)=>String.fromCharCode(parseInt(n,16)));function Cs(s){const r=Ne({},s),n=b=>u.hasOwnProp(r,b)?r[b]:void 0,o=n("data");let l=n("withXSRFToken");const a=n("xsrfHeaderName"),i=n("xsrfCookieName");let c=n("headers");const x=n("auth"),h=n("baseURL"),y=n("allowAbsoluteUrls"),d=n("url");if(r.headers=c=pe.from(c),r.url=us(Ss(h,d,y,r),n("params"),n("paramsSerializer")),x){const b=u.getSafeProp(x,"username")||"",F=u.getSafeProp(x,"password")||"";c.set("Authorization","Basic "+btoa(b+":"+(F?Gn(F):"")))}if(u.isFormData(o)&&(de.hasStandardBrowserEnv||de.hasStandardBrowserWebWorkerEnv||u.isReactNative(o)?c.setContentType(void 0):u.isFunction(o.getHeaders)&&Wn(c,o.getHeaders(),n("formDataHeaderPolicy"))),de.hasStandardBrowserEnv&&(u.isFunction(l)&&(l=l(r)),l===!0||l==null&&Dn(r.url))){const F=a&&i&&Ln.read(i);F&&c.set(a,F)}return r}const Jn=typeof XMLHttpRequest<"u"&&function(s){return new Promise(function(n,o){const l=Cs(s);let a=l.data;const i=pe.from(l.headers).normalize();let{responseType:c,onUploadProgress:x,onDownloadProgress:h}=l,y,d,b,F,E;function _(){F&&F(),E&&E(),l.cancelToken&&l.cancelToken.unsubscribe(y),l.signal&&l.signal.removeEventListener("abort",y)}let C=new XMLHttpRequest;C.open(l.method.toUpperCase(),l.url,!0),C.timeout=l.timeout;function S(){if(!C)return;const T=pe.from("getAllResponseHeaders"in C&&C.getAllResponseHeaders()),k={data:!c||c==="text"||c==="json"?C.responseText:C.response,status:C.status,statusText:C.statusText,headers:T,config:s,request:C};gs(function(H){n(H),_()},function(H){o(H),_()},k),C=null}"onloadend"in C?C.onloadend=S:C.onreadystatechange=function(){!C||C.readyState!==4||C.status===0&&!(C.responseURL&&C.responseURL.startsWith("file:"))||setTimeout(S)},C.onabort=function(){C&&(o(new M("Request aborted",M.ECONNABORTED,s,C)),_(),C=null)},C.onerror=function(A){const k=A&&A.message?A.message:"Network Error",R=new M(k,M.ERR_NETWORK,s,C);R.event=A||null,o(R),_(),C=null},C.ontimeout=function(){let A=l.timeout?"timeout of "+l.timeout+"ms exceeded":"timeout exceeded";const k=l.transitional||Ft;l.timeoutErrorMessage&&(A=l.timeoutErrorMessage),o(new M(A,k.clarifyTimeoutError?M.ETIMEDOUT:M.ECONNABORTED,s,C)),_(),C=null},a===void 0&&i.setContentType(null),"setRequestHeader"in C&&u.forEach(os(i),function(A,k){C.setRequestHeader(k,A)}),u.isUndefined(l.withCredentials)||(C.withCredentials=!!l.withCredentials),c&&c!=="json"&&(C.responseType=l.responseType),h&&([b,E]=ut(h,!0),C.addEventListener("progress",b)),x&&C.upload&&([d,F]=ut(x),C.upload.addEventListener("progress",d),C.upload.addEventListener("loadend",F)),(l.cancelToken||l.signal)&&(y=T=>{C&&(o(!T||T.type?new tt(null,s,C):T),C.abort(),_(),C=null)},l.cancelToken&&l.cancelToken.subscribe(y),l.signal&&(l.signal.aborted?y():l.signal.addEventListener("abort",y)));const w=Rn(l.url);if(w&&!de.protocols.includes(w)){o(new M("Unsupported protocol "+w+":",M.ERR_BAD_REQUEST,s));return}C.send(a||null)})},Vn=(s,r)=>{if(s=s?s.filter(Boolean):[],!r&&!s.length)return;const n=new AbortController;let o=!1;const l=function(x){if(!o){o=!0,i();const h=x instanceof Error?x:this.reason;n.abort(h instanceof M?h:new tt(h instanceof Error?h.message:h))}};let a=r&&setTimeout(()=>{a=null,l(new M(`timeout of ${r}ms exceeded`,M.ETIMEDOUT))},r);const i=()=>{s&&(a&&clearTimeout(a),a=null,s.forEach(x=>{x.unsubscribe?x.unsubscribe(l):x.removeEventListener("abort",l)}),s=null)};s.forEach(x=>x.addEventListener("abort",l));const{signal:c}=n;return c.unsubscribe=()=>u.asap(i),c},Kn=function*(s,r){let n=s.byteLength;if(n<r){yield s;return}let o=0,l;for(;o<n;)l=o+r,yield s.slice(o,l),o=l},Xn=async function*(s,r){for await(const n of Yn(s))yield*Kn(n,r)},Yn=async function*(s){if(s[Symbol.asyncIterator]){yield*s;return}const r=s.getReader();try{for(;;){const{done:n,value:o}=await r.read();if(n)break;yield o}}finally{await r.cancel()}},Ts=(s,r,n,o)=>{const l=Xn(s,r);let a=0,i,c=x=>{i||(i=!0,o&&o(x))};return new ReadableStream({async pull(x){try{const{done:h,value:y}=await l.next();if(h){c(),x.close();return}let d=y.byteLength;if(n){let b=a+=d;n(b)}x.enqueue(new Uint8Array(y))}catch(h){throw c(h),h}},cancel(x){return c(x),l.return()}},{highWaterMark:2})},pt=s=>s>=48&&s<=57||s>=65&&s<=70||s>=97&&s<=102,Zn=(s,r,n)=>r+2<n&&pt(s.charCodeAt(r+1))&&pt(s.charCodeAt(r+2));function Qn(s){if(!s||typeof s!="string"||!s.startsWith("data:"))return 0;const r=s.indexOf(",");if(r<0)return 0;const n=s.slice(5,r),o=s.slice(r+1);if(/;base64/i.test(n)){let i=o.length;const c=o.length;for(let F=0;F<c;F++)if(o.charCodeAt(F)===37&&F+2<c){const E=o.charCodeAt(F+1),_=o.charCodeAt(F+2);pt(E)&&pt(_)&&(i-=2,F+=2)}let x=0,h=c-1;const y=F=>F>=2&&o.charCodeAt(F-2)===37&&o.charCodeAt(F-1)===51&&(o.charCodeAt(F)===68||o.charCodeAt(F)===100);h>=0&&(o.charCodeAt(h)===61?(x++,h--):y(h)&&(x++,h-=3)),x===1&&h>=0&&(o.charCodeAt(h)===61||y(h))&&x++;const b=Math.floor(i/4)*3-(x||0);return b>0?b:0}let a=0;for(let i=0,c=o.length;i<c;i++){const x=o.charCodeAt(i);if(x===37&&Zn(o,i,c))a+=1,i+=2;else if(x<128)a+=1;else if(x<2048)a+=2;else if(x>=55296&&x<=56319&&i+1<c){const h=o.charCodeAt(i+1);h>=56320&&h<=57343?(a+=4,i++):a+=3}else a+=3}return a}const Nt="1.18.0",Es=64*1024,{isFunction:mt}=u,eo=s=>encodeURIComponent(s).replace(/%([0-9A-F]{2})/gi,(r,n)=>String.fromCharCode(parseInt(n,16))),Is=s=>{if(!u.isString(s))return s;try{return decodeURIComponent(s)}catch{return s}},Os=(s,...r)=>{try{return!!s(...r)}catch{return!1}},to=s=>{const r=s.indexOf("://");let n=s;return r!==-1&&(n=n.slice(r+3)),n.includes("@")||n.includes(":")},so=s=>{const r=u.global!==void 0&&u.global!==null?u.global:globalThis,{ReadableStream:n,TextEncoder:o}=r;s=u.merge.call({skipUndefined:!0},{Request:r.Request,Response:r.Response},s);const{fetch:l,Request:a,Response:i}=s,c=l?mt(l):typeof fetch=="function",x=mt(a),h=mt(i);if(!c)return!1;const y=c&&mt(n),d=c&&(typeof o=="function"?(S=>w=>S.encode(w))(new o):async S=>new Uint8Array(await new a(S).arrayBuffer())),b=x&&y&&Os(()=>{let S=!1;const w=new a(de.origin,{body:new n,method:"POST",get duplex(){return S=!0,"half"}}),T=w.headers.has("Content-Type");return w.body!=null&&w.body.cancel(),S&&!T}),F=h&&y&&Os(()=>u.isReadableStream(new i("").body)),E={stream:F&&(S=>S.body)};c&&["text","arrayBuffer","blob","formData","stream"].forEach(S=>{!E[S]&&(E[S]=(w,T)=>{let A=w&&w[S];if(A)return A.call(w);throw new M(`Response type '${S}' is not supported`,M.ERR_NOT_SUPPORT,T)})});const _=async S=>{if(S==null)return 0;if(u.isBlob(S))return S.size;if(u.isSpecCompliantForm(S))return(await new a(de.origin,{method:"POST",body:S}).arrayBuffer()).byteLength;if(u.isArrayBufferView(S)||u.isArrayBuffer(S))return S.byteLength;if(u.isURLSearchParams(S)&&(S=S+""),u.isString(S))return(await d(S)).byteLength},C=async(S,w)=>{const T=u.toFiniteNumber(S.getContentLength());return T??_(w)};return async S=>{let{url:w,method:T,data:A,signal:k,cancelToken:R,timeout:H,onDownloadProgress:Y,onUploadProgress:K,responseType:m,headers:f,withCredentials:z="same-origin",fetchOptions:P,maxContentLength:D,maxBodyLength:Q}=Cs(S);const oe=u.isNumber(D)&&D>-1,ge=u.isNumber(Q)&&Q>-1,he=X=>u.hasOwnProp(S,X)?S[X]:void 0;let N=l||fetch;m=m?(m+"").toLowerCase():"text";let O=Vn([k,R&&R.toAbortSignal()],H),j=null;const L=O&&O.unsubscribe&&(()=>{O.unsubscribe()});let $,V=null;const ie=()=>new M("Request body larger than maxBodyLength limit",M.ERR_BAD_REQUEST,S,j);try{let X;const Z=he("auth");if(Z){const W=u.getSafeProp(Z,"username")||"",ce=u.getSafeProp(Z,"password")||"";X={username:W,password:ce}}if(to(w)){const W=new URL(w,de.origin);if(!X&&(W.username||W.password)){const ce=Is(W.username),be=Is(W.password);X={username:ce,password:be}}(W.username||W.password)&&(W.username="",W.password="",w=W.href)}if(X&&(f.delete("authorization"),f.set("Authorization","Basic "+btoa(eo((X.username||"")+":"+(X.password||""))))),oe&&typeof w=="string"&&w.startsWith("data:")&&Qn(w)>D)throw new M("maxContentLength size of "+D+" exceeded",M.ERR_BAD_RESPONSE,S,j);if(ge&&T!=="get"&&T!=="head"){const W=await _(A);if(typeof W=="number"&&isFinite(W)&&($=W,W>Q))throw ie()}const fe=ge&&(u.isReadableStream(A)||u.isStream(A)),Ee=(W,ce,be)=>Ts(W,Es,we=>{if(ge&&we>Q)throw V=ie();ce&&ce(we)},be);if(b&&T!=="get"&&T!=="head"&&(K||fe)){if($=$??await C(f,A),$!==0||fe){let W=new a(w,{method:"POST",body:A,duplex:"half"}),ce;if(u.isFormData(A)&&(ce=W.headers.get("content-type"))&&f.setContentType(ce),W.body){const[be,we]=K&&ys($,ut(js(K)))||[];A=Ee(W.body,be,we)}}}else if(fe&&!x&&y&&T!=="get"&&T!=="head")A=Ee(A);else if(fe&&x&&!b&&T!=="get"&&T!=="head")throw new M("Stream request bodies are not supported by the current fetch implementation",M.ERR_NOT_SUPPORT,S,j);u.isString(z)||(z=z?"include":"omit");const Ie=x&&"credentials"in a.prototype;if(u.isFormData(A)){const W=f.getContentType();W&&/^multipart\/form-data/i.test(W)&&!/boundary=/i.test(W)&&f.delete("content-type")}f.set("User-Agent","axios/"+Nt,!1);const Oe={...P,signal:O,method:T.toUpperCase(),headers:os(f.normalize()),body:A,duplex:"half",credentials:Ie?z:void 0};j=x&&new a(w,Oe);let ae=await(x?N(j,P):N(w,Oe));const Je=pe.from(ae.headers);if(oe){const W=u.toFiniteNumber(Je.getContentLength());if(W!=null&&W>D)throw new M("maxContentLength size of "+D+" exceeded",M.ERR_BAD_RESPONSE,S,j)}const Be=F&&(m==="stream"||m==="response");if(F&&ae.body&&(Y||oe||Be&&L)){const W={};["status","statusText","headers"].forEach(G=>{W[G]=ae[G]});const ce=u.toFiniteNumber(Je.getContentLength()),[be,we]=Y&&ys(ce,ut(js(Y),!0))||[];let I=0;const B=G=>{if(oe&&(I=G,I>D))throw new M("maxContentLength size of "+D+" exceeded",M.ERR_BAD_RESPONSE,S,j);be&&be(G)};ae=new i(Ts(ae.body,Es,B,()=>{we&&we(),L&&L()}),W)}m=m||"text";let ye=await E[u.findKey(E,m)||"text"](ae,S);if(oe&&!F&&!Be){let W;if(ye!=null&&(typeof ye.byteLength=="number"?W=ye.byteLength:typeof ye.size=="number"?W=ye.size:typeof ye=="string"&&(W=typeof o=="function"?new o().encode(ye).byteLength:ye.length)),typeof W=="number"&&W>D)throw new M("maxContentLength size of "+D+" exceeded",M.ERR_BAD_RESPONSE,S,j)}return!Be&&L&&L(),await new Promise((W,ce)=>{gs(W,ce,{data:ye,headers:pe.from(ae.headers),status:ae.status,statusText:ae.statusText,config:S,request:j})})}catch(X){if(L&&L(),O&&O.aborted&&O.reason instanceof M){const Z=O.reason;throw Z.config=S,j&&(Z.request=j),X!==Z&&(Z.cause=X),Z}throw V?(j&&!V.request&&(V.request=j),V):X instanceof M?(j&&!X.request&&(X.request=j),X):X&&X.name==="TypeError"&&/Load failed|fetch/i.test(X.message)?Object.assign(new M("Network Error",M.ERR_NETWORK,S,j,X&&X.response),{cause:X.cause||X}):M.from(X,X&&X.code,S,j,X&&X.response)}}},ro=new Map,ks=s=>{let r=s&&s.env||{};const{fetch:n,Request:o,Response:l}=r,a=[o,l,n];let i=a.length,c=i,x,h,y=ro;for(;c--;)x=a[c],h=y.get(x),h===void 0&&y.set(x,h=c?new Map:so(r)),y=h;return h};ks();const _t={http:Sn,xhr:Jn,fetch:{get:ks}};u.forEach(_t,(s,r)=>{if(s){try{Object.defineProperty(s,"name",{__proto__:null,value:r})}catch{}Object.defineProperty(s,"adapterName",{__proto__:null,value:r})}});const vs=s=>`- ${s}`,no=s=>u.isFunction(s)||s===null||s===!1;function oo(s,r){s=u.isArray(s)?s:[s];const{length:n}=s;let o,l;const a={};for(let i=0;i<n;i++){o=s[i];let c;if(l=o,!no(o)&&(l=_t[(c=String(o)).toLowerCase()],l===void 0))throw new M(`Unknown adapter '${c}'`);if(l&&(u.isFunction(l)||(l=l.get(r))))break;a[c||"#"+i]=l}if(!l){const i=Object.entries(a).map(([x,h])=>`adapter ${x} `+(h===!1?"is not supported by the environment":"is not available in the build"));let c=n?i.length>1?`since :
25
+ `+i.map(vs).join(`
26
+ `):" "+vs(i[0]):"as no adapter specified";throw new M("There is no suitable adapter to dispatch the request "+c,"ERR_NOT_SUPPORT")}return l}const Fs={getAdapter:oo,adapters:_t};function Dt(s){if(s.cancelToken&&s.cancelToken.throwIfRequested(),s.signal&&s.signal.aborted)throw new tt(null,s)}function As(s){return Dt(s),s.headers=pe.from(s.headers),s.data=Rt.call(s,s.transformRequest),["post","put","patch"].indexOf(s.method)!==-1&&s.headers.setContentType("application/x-www-form-urlencoded",!1),Fs.getAdapter(s.adapter||et.adapter,s)(s).then(function(o){Dt(s),s.response=o;try{o.data=Rt.call(s,s.transformResponse,o)}finally{delete s.response}return o.headers=pe.from(o.headers),o},function(o){if(!xs(o)&&(Dt(s),o&&o.response)){s.response=o.response;try{o.response.data=Rt.call(s,s.transformResponse,o.response)}finally{delete s.response}o.response.headers=pe.from(o.response.headers)}return Promise.reject(o)})}const ht={};["object","boolean","number","function","string","symbol"].forEach((s,r)=>{ht[s]=function(o){return typeof o===s||"a"+(r<1?"n ":" ")+s}});const Ps={};ht.transitional=function(r,n,o){function l(a,i){return"[Axios v"+Nt+"] Transitional option '"+a+"'"+i+(o?". "+o:"")}return(a,i,c)=>{if(r===!1)throw new M(l(i," has been removed"+(n?" in "+n:"")),M.ERR_DEPRECATED);return n&&!Ps[i]&&(Ps[i]=!0,console.warn(l(i," has been deprecated since v"+n+" and will be removed in the near future"))),r?r(a,i,c):!0}},ht.spelling=function(r){return(n,o)=>(console.warn(`${o} is likely a misspelling of ${r}`),!0)};function lo(s,r,n){if(typeof s!="object")throw new M("options must be an object",M.ERR_BAD_OPTION_VALUE);const o=Object.keys(s);let l=o.length;for(;l-- >0;){const a=o[l],i=Object.prototype.hasOwnProperty.call(r,a)?r[a]:void 0;if(i){const c=s[a],x=c===void 0||i(c,a,s);if(x!==!0)throw new M("option "+a+" must be "+x,M.ERR_BAD_OPTION_VALUE);continue}if(n!==!0)throw new M("Unknown option "+a,M.ERR_BAD_OPTION)}}const ft={assertOptions:lo,validators:ht},me=ft.validators;let _e=class{constructor(r){this.defaults=r||{},this.interceptors={request:new ps,response:new ps}}async request(r,n){try{return await this._request(r,n)}catch(o){if(o instanceof Error){let l={};Error.captureStackTrace?Error.captureStackTrace(l):l=new Error;const a=(()=>{if(!l.stack)return"";const i=l.stack.indexOf(`
27
+ `);return i===-1?"":l.stack.slice(i+1)})();try{if(!o.stack)o.stack=a;else if(a){const i=a.indexOf(`
28
+ `),c=i===-1?-1:a.indexOf(`
29
+ `,i+1),x=c===-1?"":a.slice(c+1);String(o.stack).endsWith(x)||(o.stack+=`
30
+ `+a)}}catch{}}throw o}}_request(r,n){typeof r=="string"?(n=n||{},n.url=r):n=r||{},n=Ne(this.defaults,n);const{transitional:o,paramsSerializer:l,headers:a}=n;o!==void 0&&ft.assertOptions(o,{silentJSONParsing:me.transitional(me.boolean),forcedJSONParsing:me.transitional(me.boolean),clarifyTimeoutError:me.transitional(me.boolean),legacyInterceptorReqResOrdering:me.transitional(me.boolean),advertiseZstdAcceptEncoding:me.transitional(me.boolean),validateStatusUndefinedResolves:me.transitional(me.boolean)},!1),l!=null&&(u.isFunction(l)?n.paramsSerializer={serialize:l}:ft.assertOptions(l,{encode:me.function,serialize:me.function},!0)),n.allowAbsoluteUrls!==void 0||(this.defaults.allowAbsoluteUrls!==void 0?n.allowAbsoluteUrls=this.defaults.allowAbsoluteUrls:n.allowAbsoluteUrls=!0),ft.assertOptions(n,{baseUrl:me.spelling("baseURL"),withXsrfToken:me.spelling("withXSRFToken")},!0),n.method=(n.method||this.defaults.method||"get").toLowerCase();let i=a&&u.merge(a.common,a[n.method]);a&&u.forEach(["delete","get","head","post","put","patch","query","common"],E=>{delete a[E]}),n.headers=pe.concat(i,a);const c=[];let x=!0;this.interceptors.request.forEach(function(_){if(typeof _.runWhen=="function"&&_.runWhen(n)===!1)return;x=x&&_.synchronous;const C=n.transitional||Ft;C&&C.legacyInterceptorReqResOrdering?c.unshift(_.fulfilled,_.rejected):c.push(_.fulfilled,_.rejected)});const h=[];this.interceptors.response.forEach(function(_){h.push(_.fulfilled,_.rejected)});let y,d=0,b;if(!x){const E=[As.bind(this),void 0];for(E.unshift(...c),E.push(...h),b=E.length,y=Promise.resolve(n);d<b;)y=y.then(E[d++],E[d++]);return y}b=c.length;let F=n;for(;d<b;){const E=c[d++],_=c[d++];try{F=E(F)}catch(C){_.call(this,C);break}}try{y=As.call(this,F)}catch(E){return Promise.reject(E)}for(d=0,b=h.length;d<b;)y=y.then(h[d++],h[d++]);return y}getUri(r){r=Ne(this.defaults,r);const n=Ss(r.baseURL,r.url,r.allowAbsoluteUrls,r);return us(n,r.params,r.paramsSerializer)}};u.forEach(["delete","get","head","options"],function(r){_e.prototype[r]=function(n,o){return this.request(Ne(o||{},{method:r,url:n,data:o&&u.hasOwnProp(o,"data")?o.data:void 0}))}}),u.forEach(["post","put","patch","query"],function(r){function n(o){return function(a,i,c){return this.request(Ne(c||{},{method:r,headers:o?{"Content-Type":"multipart/form-data"}:{},url:a,data:i}))}}_e.prototype[r]=n(),r!=="query"&&(_e.prototype[r+"Form"]=n(!0))});let io=class ar{constructor(r){if(typeof r!="function")throw new TypeError("executor must be a function.");let n;this.promise=new Promise(function(a){n=a});const o=this;this.promise.then(l=>{if(!o._listeners)return;let a=o._listeners.length;for(;a-- >0;)o._listeners[a](l);o._listeners=null}),this.promise.then=l=>{let a;const i=new Promise(c=>{o.subscribe(c),a=c}).then(l);return i.cancel=function(){o.unsubscribe(a)},i},r(function(a,i,c){o.reason||(o.reason=new tt(a,i,c),n(o.reason))})}throwIfRequested(){if(this.reason)throw this.reason}subscribe(r){if(this.reason){r(this.reason);return}this._listeners?this._listeners.push(r):this._listeners=[r]}unsubscribe(r){if(!this._listeners)return;const n=this._listeners.indexOf(r);n!==-1&&this._listeners.splice(n,1)}toAbortSignal(){const r=new AbortController,n=o=>{r.abort(o)};return this.subscribe(n),r.signal.unsubscribe=()=>this.unsubscribe(n),r.signal}static source(){let r;return{token:new ar(function(l){r=l}),cancel:r}}};function ao(s){return function(n){return s.apply(null,n)}}function co(s){return u.isObject(s)&&s.isAxiosError===!0}const Lt={Continue:100,SwitchingProtocols:101,Processing:102,EarlyHints:103,Ok:200,Created:201,Accepted:202,NonAuthoritativeInformation:203,NoContent:204,ResetContent:205,PartialContent:206,MultiStatus:207,AlreadyReported:208,ImUsed:226,MultipleChoices:300,MovedPermanently:301,Found:302,SeeOther:303,NotModified:304,UseProxy:305,Unused:306,TemporaryRedirect:307,PermanentRedirect:308,BadRequest:400,Unauthorized:401,PaymentRequired:402,Forbidden:403,NotFound:404,MethodNotAllowed:405,NotAcceptable:406,ProxyAuthenticationRequired:407,RequestTimeout:408,Conflict:409,Gone:410,LengthRequired:411,PreconditionFailed:412,PayloadTooLarge:413,UriTooLong:414,UnsupportedMediaType:415,RangeNotSatisfiable:416,ExpectationFailed:417,ImATeapot:418,MisdirectedRequest:421,UnprocessableEntity:422,Locked:423,FailedDependency:424,TooEarly:425,UpgradeRequired:426,PreconditionRequired:428,TooManyRequests:429,RequestHeaderFieldsTooLarge:431,UnavailableForLegalReasons:451,InternalServerError:500,NotImplemented:501,BadGateway:502,ServiceUnavailable:503,GatewayTimeout:504,HttpVersionNotSupported:505,VariantAlsoNegotiates:506,InsufficientStorage:507,LoopDetected:508,NotExtended:510,NetworkAuthenticationRequired:511,WebServerIsDown:521,ConnectionTimedOut:522,OriginIsUnreachable:523,TimeoutOccurred:524,SslHandshakeFailed:525,InvalidSslCertificate:526};Object.entries(Lt).forEach(([s,r])=>{Lt[r]=s});function Rs(s){const r=new _e(s),n=Vt(_e.prototype.request,r);return u.extend(n,_e.prototype,r,{allOwnKeys:!0}),u.extend(n,r,null,{allOwnKeys:!0}),n.create=function(l){return Rs(Ne(s,l))},n}const re=Rs(et);re.Axios=_e,re.CanceledError=tt,re.CancelToken=io,re.isCancel=xs,re.VERSION=Nt,re.toFormData=dt,re.AxiosError=M,re.Cancel=re.CanceledError,re.all=function(r){return Promise.all(r)},re.spread=ao,re.isAxiosError=co,re.mergeConfig=Ne,re.AxiosHeaders=pe,re.formToJSON=s=>fs(u.isHTMLForm(s)?new FormData(s):s),re.getAdapter=Fs.getAdapter,re.HttpStatusCode=Lt,re.default=re;const{Axios:Il,AxiosError:Ol,CanceledError:kl,isCancel:vl,CancelToken:Fl,VERSION:Al,all:Pl,Cancel:Rl,isAxiosError:Nl,spread:_l,toFormData:Dl,AxiosHeaders:Ll,HttpStatusCode:Bl,formToJSON:Ml,getAdapter:zl,mergeConfig:Ul,create:$l}=re;function uo(s){if(s&&typeof s=="object"&&"code"in s&&"data"in s){const r=s;return r.code!==200?Promise.reject(new Error(r.message||"请求失败")):r.data}return s}function Ns(s,r={}){const{tokenKey:n="token",userInfoKey:o="userInfo",unauthorizedRedirect:l="/login"}=r;s.interceptors.request.use(a=>{const i=localStorage.getItem(n);return i&&(a.headers.Authorization=`Bearer ${i}`),a}),s.interceptors.response.use(a=>uo(a.data),a=>{var i,c,x;return((i=a.response)==null?void 0:i.status)===401?(localStorage.removeItem(n),localStorage.removeItem(o),window.location.href=l):((c=a.response)==null?void 0:c.status)===403?console.error("没有权限访问该资源"):((x=a.response)==null?void 0:x.status)===500&&console.error("服务器内部错误"),Promise.reject(a)})}function Bt(s={}){const r=re.create({baseURL:s.baseURL??"/api",timeout:s.timeout??1e4});return Ns(r,{tokenKey:s.tokenKey,userInfoKey:s.userInfoKey,unauthorizedRedirect:s.unauthorizedRedirect}),r}const te=Bt(),Mt=Bt();function po({title:s="统一管理平台",loginApi:r="/auth/login",redirectUrl:n="/",onSuccess:o}){const[l,a]=p.useState(!1),i=async c=>{var x,h;a(!0);try{const y=await te.post(r,c);y.token?(localStorage.setItem("token",y.token),localStorage.setItem("userInfo",JSON.stringify(y.user||y)),t.message.success("登录成功"),o?o(y):window.location.href=n):t.message.error("登录失败:未获取到 token")}catch(y){t.message.error(((h=(x=y.response)==null?void 0:x.data)==null?void 0:h.message)||y.message||"登录失败")}finally{a(!1)}};return e.jsx("div",{style:{height:"100vh",display:"flex",justifyContent:"center",alignItems:"center",background:"#f0f2f5"},children:e.jsx(t.Card,{title:s,style:{width:400},children:e.jsxs(t.Form,{onFinish:i,size:"large",children:[e.jsx(t.Form.Item,{name:"username",rules:[{required:!0,message:"请输入用户名"}],children:e.jsx(t.Input,{prefix:e.jsx(g.UserOutlined,{}),placeholder:"用户名"})}),e.jsx(t.Form.Item,{name:"password",rules:[{required:!0,message:"请输入密码"}],children:e.jsx(t.Input.Password,{prefix:e.jsx(g.LockOutlined,{}),placeholder:"密码"})}),e.jsx(t.Form.Item,{children:e.jsx(t.Button,{type:"primary",htmlType:"submit",loading:l,block:!0,children:"登 录"})})]})})})}class mo extends p.Component{constructor(n){super(n);lr(this,"handleReset",()=>{this.setState({hasError:!1,error:null,errorInfo:null}),typeof this.props.onReset=="function"&&this.props.onReset()});this.state={hasError:!1,error:null,errorInfo:null}}static getDerivedStateFromError(n){return{hasError:!0,error:n}}componentDidCatch(n,o){console.error("[ErrorBoundary] caught error:",n,o),this.setState({errorInfo:o})}render(){if(!this.state.hasError)return this.props.children;const{fallbackTitle:n="组件加载失败",fallbackDescription:o,showReload:l=!0}=this.props,a=this.state.error&&(this.state.error.message||String(this.state.error))||"未知错误";return e.jsxs("div",{style:{padding:24,background:"#fff2f0",border:"1px solid #ffccc7",borderRadius:8,minHeight:200},children:[e.jsx(t.Alert,{type:"error",showIcon:!0,icon:e.jsx(g.BugOutlined,{}),message:n,description:e.jsxs("div",{children:[e.jsx("div",{style:{marginBottom:8},children:o||"当前组件发生了异常,已被错误边界捕获。其他功能仍可正常使用。"}),e.jsx("div",{style:{fontFamily:"Menlo, Monaco, Consolas, monospace",fontSize:12,color:"#cf1322",background:"#fff",padding:8,borderRadius:4,border:"1px solid #ffccc7",wordBreak:"break-word",whiteSpace:"pre-wrap"},children:a})]})}),l&&e.jsx(t.Space,{style:{marginTop:16},children:e.jsx(t.Button,{icon:e.jsx(g.ReloadOutlined,{}),onClick:this.handleReset,children:"重试"})})]})}}const{Title:ho,Text:fo,Paragraph:_s}=t.Typography,xo=()=>e.jsxs("div",{style:{padding:"0"},children:[e.jsxs("div",{style:{marginBottom:24},children:[e.jsx(ho,{level:2,style:{margin:0},children:"Z-One Company 统一管理平台"}),e.jsx(fo,{type:"secondary",children:"一站式企业级应用管理平台"})]}),e.jsxs(t.Row,{gutter:16,style:{marginBottom:24},children:[e.jsx(t.Col,{span:6,children:e.jsx(t.Card,{children:e.jsx(t.Statistic,{title:"配置中心",value:0,prefix:e.jsx(g.SettingOutlined,{})})})}),e.jsx(t.Col,{span:6,children:e.jsx(t.Card,{children:e.jsx(t.Statistic,{title:"任务中心",value:0,prefix:e.jsx(g.FileTextOutlined,{})})})}),e.jsx(t.Col,{span:6,children:e.jsx(t.Card,{children:e.jsx(t.Statistic,{title:"工作流",value:0,prefix:e.jsx(g.AuditOutlined,{})})})}),e.jsx(t.Col,{span:6,children:e.jsx(t.Card,{children:e.jsx(t.Statistic,{title:"用户中心",value:0,prefix:e.jsx(g.UserOutlined,{})})})})]}),e.jsxs(t.Card,{title:"关于 Z-One Company",children:[e.jsx(_s,{children:"Z-One Company 是一站式企业级应用管理平台,整合了配置中心、任务中心、工作流、用户中心等多个模块。"}),e.jsx(_s,{children:e.jsx("strong",{children:"核心模块:"})}),e.jsxs("ul",{children:[e.jsx("li",{children:"配置中心 - 集中管理应用配置"}),e.jsx("li",{children:"任务中心 - 任务调度与执行"}),e.jsx("li",{children:"工作流 - 流程审批与管理"}),e.jsx("li",{children:"用户中心 - 统一身份认证与权限管理"}),e.jsx("li",{children:"调度中心 - 定时任务管理"}),e.jsx("li",{children:"Mist - 密钥管理"}),e.jsx("li",{children:"元数据 - API与应用管理"})]})]})]}),go=Mt,Se={layout:"_layout_1puwg_1",header:"_header_1puwg_5",logo:"_logo_1puwg_15",logoText:"_logoText_1puwg_20",headerRight:"_headerRight_1puwg_26",userInfo:"_userInfo_1puwg_31",userName:"_userName_1puwg_38",mainLayout:"_mainLayout_1puwg_43",sider:"_sider_1puwg_48",menu:"_menu_1puwg_53",collapsedBtn:"_collapsedBtn_1puwg_57",content:"_content_1puwg_74"};let yo="/api";function Ds(){return re.create({baseURL:yo,timeout:15e3})}const Ae=Ds();Ds(),Ae.interceptors.request.use(s=>{const r=localStorage.getItem("token");return r&&(s.headers.Authorization=`Bearer ${r}`),s});const jo=s=>Ae.post("/ctc/auth/login",s).then(r=>r.data),bo=()=>{try{const s=localStorage.getItem("userInfo");return Promise.resolve(s?JSON.parse(s):null)}catch{return Promise.resolve(null)}};function So(s){return{list:r=>Ae.get(`/${s}/list`,{params:r}).then(n=>n.data),page:r=>Ae.get(`/${s}/page`,{params:r}).then(n=>n.data),get:r=>Ae.get(`/${s}/${r}`).then(n=>n.data),create:r=>Ae.post(`/${s}`,r).then(n=>n.data),update:(r,n)=>Ae.put(`/${s}/${r}`,n).then(o=>o.data),delete:r=>Ae.delete(`/${s}/${r}`).then(n=>n.data)}}const J=So("mock"),{Header:wo,Sider:Co,Content:To}=t.Layout,{Text:Eo}=t.Typography,Io=({compact:s=!1}={})=>{const r=ue.useLocation(),n=ue.useNavigate(),[o,l]=p.useState(!1),[a,i]=p.useState("管理员"),[c,x]=p.useState(null),[h,y]=p.useState([]),[d,b]=p.useState([]),F=p.useRef(n);F.current=n,p.useEffect(()=>{if(!localStorage.getItem("token")){F.current("/login");return}const w=localStorage.getItem("userInfo");if(w)try{const T=JSON.parse(w);i(T.userName||"管理员"),x(T),T.tenantCode&&b([T.tenantCode])}catch{}bo().then(T=>{T&&(x(T),i(T.userName||"管理员"),localStorage.setItem("userInfo",JSON.stringify(T)))}).catch(()=>{}),y([{value:"tenant1",label:"租户1",children:[{value:"domain1-1",label:"域1-1"},{value:"domain1-2",label:"域1-2"}]},{value:"tenant2",label:"租户2",children:[{value:"domain2-1",label:"域2-1"},{value:"domain2-2",label:"域2-2"}]}])},[]);const E=()=>{var w;const S=r.pathname;if(S.includes("/user"))return["user"];if(S.includes("/role"))return["role"];if(S.includes("/permission"))return["permission"];if(S.includes("/app"))return["app"];if(S.includes("/dict"))return["dict"];if(S.includes("/audit"))return["audit"];if(S.includes("/tenant"))return["tenant"];if(S.includes("/domain"))return["domain"];if(S.includes("/org"))return["org"];if(S.includes("/dept"))return["dept"];if(S.includes("/group"))return["group"];if(S.includes("/4a/")){const T=((w=S.split("/4a/")[1])==null?void 0:w.split("/"))||[];if(T.length>0)return[`4a/${T[0]}`]}return S.includes("/webide")?["webide"]:S.includes("/agent-team")?["agent-team"]:["4a/account"]},_=[{key:"4a/account",icon:e.jsx(g.TeamOutlined,{}),label:"账号管理"},{key:"4a/role",icon:e.jsx(g.SafetyOutlined,{}),label:"角色管理"},{key:"4a/application",icon:e.jsx(g.AppstoreOutlined,{}),label:"应用管理"},{key:"4a/tenant",icon:e.jsx(g.TeamOutlined,{}),label:"租户管理"},{key:"4a/org",icon:e.jsx(g.ClusterOutlined,{}),label:"组织管理"},{key:"4a/permission",icon:e.jsx(g.SafetyCertificateOutlined,{}),label:"权限管理"},{key:"4a/surl",icon:e.jsx(g.LinkOutlined,{}),label:"短链管理"},{key:"webide",icon:e.jsx(g.CodeOutlined,{}),label:"WebIDE 容器"},{key:"agent-team",icon:e.jsx(g.RobotOutlined,{}),label:"Agent 群组 IM"},{type:"divider"},{key:"settings",icon:e.jsx(g.SettingOutlined,{}),label:"系统设置"}],C=({key:S})=>{n(`/ctc/${S}`)};return e.jsxs(t.Layout,{className:Se.layout,children:[s?null:e.jsx(e.Fragment,{children:e.jsxs(wo,{className:Se.header,children:[e.jsx("div",{className:Se.logo,children:e.jsx("span",{className:Se.logoText,children:"Z-CTC 统一用户中心"})}),e.jsx("div",{className:Se.headerRight,children:e.jsx(t.Space,{size:24,children:e.jsx(t.Dropdown,{overlay:e.jsxs("div",{style:{background:"#fff",borderRadius:"8px",boxShadow:"0 6px 16px rgba(0, 0, 0, 0.12)",padding:"16px",width:"360px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"12px",marginBottom:"12px"},children:[e.jsx("span",{style:{fontSize:"14px",color:"#666"},children:"租户域"}),e.jsx(t.Cascader,{value:d,onChange:S=>b(S),options:h,placeholder:"请选择租户域",style:{flex:1}})]}),e.jsx(t.Divider,{style:{margin:"12px 0"}}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[e.jsxs("div",{style:{display:"flex",fontSize:"14px"},children:[e.jsx("span",{style:{color:"#999",width:"70px"},children:"用户名:"}),e.jsx("span",{children:(c==null?void 0:c.userName)||"-"})]}),e.jsxs("div",{style:{display:"flex",fontSize:"14px"},children:[e.jsx("span",{style:{color:"#999",width:"70px"},children:"真实姓名:"}),e.jsx("span",{children:(c==null?void 0:c.realName)||"-"})]}),e.jsxs("div",{style:{display:"flex",fontSize:"14px"},children:[e.jsx("span",{style:{color:"#999",width:"70px"},children:"邮箱:"}),e.jsx("span",{children:(c==null?void 0:c.email)||"-"})]}),e.jsxs("div",{style:{display:"flex",fontSize:"14px"},children:[e.jsx("span",{style:{color:"#999",width:"70px"},children:"手机号:"}),e.jsx("span",{children:(c==null?void 0:c.phone)||"-"})]}),e.jsxs("div",{style:{display:"flex",fontSize:"14px"},children:[e.jsx("span",{style:{color:"#999",width:"70px"},children:"状态:"}),e.jsx("span",{children:(c==null?void 0:c.status)===1?"正常":"停用"})]})]}),e.jsx(t.Divider,{style:{margin:"12px 0"}}),e.jsxs("div",{style:{display:"flex",flexDirection:"column"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",cursor:"pointer",borderRadius:"4px",fontSize:"14px"},onClick:()=>{},children:[e.jsx(g.UserOutlined,{})," 个人中心"]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",cursor:"pointer",borderRadius:"4px",fontSize:"14px"},onClick:()=>{},children:[e.jsx(g.SettingOutlined,{})," 系统设置"]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",cursor:"pointer",borderRadius:"4px",fontSize:"14px"},onClick:()=>{localStorage.removeItem("token"),localStorage.removeItem("userInfo"),n("/ctc/login")},children:[e.jsx(g.LogoutOutlined,{})," 退出登录"]})]})]}),placement:"bottomRight",trigger:["click"],children:e.jsxs("div",{className:Se.userInfo,children:[e.jsx(t.Avatar,{icon:e.jsx(g.UserOutlined,{}),size:"small"}),e.jsx(Eo,{className:Se.userName,children:a}),e.jsx(g.DownOutlined,{})]})})})})]})}),e.jsxs(t.Layout,{className:Se.mainLayout,children:[e.jsxs(Co,{trigger:null,collapsible:!0,collapsed:o,className:Se.sider,width:200,children:[e.jsx(t.Menu,{mode:"inline",selectedKeys:E(),defaultOpenKeys:["user","role","permission","audit","tenant","domain","org","dept","group"],className:Se.menu,items:_,onClick:C}),e.jsx("div",{className:Se.collapsedBtn,onClick:()=>l(!o),children:o?e.jsx(g.MenuUnfoldOutlined,{}):e.jsx(g.MenuFoldOutlined,{})})]}),e.jsx(To,{className:Se.content,children:e.jsx(ue.Outlet,{})})]})]})},xt={container:"_container_tti32_1",content:"_content_tti32_9",card:"_card_tti32_14",header:"_header_tti32_19"},{Title:Oo,Text:oi}=t.Typography,ko=s=>Mt.post("/ctc/auth/login",s),vo=()=>Promise.resolve({code:0,message:"功能暂未开放"}),Fo=()=>{const s=ue.useNavigate(),[r,n]=p.useState("login"),[o,l]=p.useState("account"),[a,i]=p.useState(!1),[c,x]=p.useState(0),[h]=t.Form.useForm(),y=async()=>{t.message.info("验证码功能暂未开放")},d=async E=>{try{let _;if(r==="login"&&o==="account"){if(_=await ko({identifier:E.username,password:E.password}),_&&_.token){t.message.success("登录成功!"),localStorage.setItem("token",_.token);const C=_.account||{};localStorage.setItem("userInfo",JSON.stringify({userId:C.id,userName:C.username,nickname:C.nickname,tenantCode:C.tenantCode})),s("/ctc");return}t.message.error((_==null?void 0:_.message)||"登录失败")}else{await vo(),t.message.info("该功能暂未开放");return}}catch(_){t.message.error(_.message||"操作失败,请重试")}},b=()=>{const E=[{key:"account",label:"账户密码"}];return r==="register"?(E.push({key:"phone",label:"手机注册"}),E.push({key:"email",label:"邮箱注册"})):E.push({key:"phone",label:"手机验证码"}),E},F=()=>{const E=r==="login";return e.jsxs(e.Fragment,{children:[o==="account"&&e.jsxs(e.Fragment,{children:[e.jsx(t.Form.Item,{name:"username",rules:[{required:!0,message:"请输入用户名!"}],children:e.jsx(t.Input,{size:"large",prefix:e.jsx(g.UserOutlined,{}),placeholder:"用户名"})}),e.jsx(t.Form.Item,{name:"password",rules:[{required:!0,message:"请输入密码!"}],children:e.jsx(t.Input.Password,{size:"large",prefix:e.jsx(g.LockOutlined,{}),placeholder:"密码"})})]}),(o==="phone"||o==="email")&&e.jsxs(e.Fragment,{children:[e.jsx(t.Form.Item,{name:"receiver",rules:[{required:!0,message:o==="phone"?"请输入手机号!":"请输入邮箱!"}],children:e.jsx(t.Input,{size:"large",prefix:o==="phone"?e.jsx(g.MobileOutlined,{}):e.jsx(g.MailOutlined,{}),placeholder:o==="phone"?"手机号":"邮箱",disabled:c>0})}),e.jsx(t.Form.Item,{children:e.jsxs("div",{style:{display:"flex",gap:8},children:[e.jsx(t.Input,{size:"large",prefix:e.jsx(g.LockOutlined,{}),placeholder:"验证码",style:{flex:1}}),e.jsx(t.Button,{type:"primary",onClick:y,loading:a,disabled:c>0,style:{minWidth:100},children:c>0?`${c}秒`:"获取验证码"})]})}),!E&&e.jsx(t.Form.Item,{name:"password",rules:[{required:!0,message:"请输入密码!"}],children:e.jsx(t.Input.Password,{size:"large",prefix:e.jsx(g.LockOutlined,{}),placeholder:"设置密码"})})]})]})};return e.jsx("div",{className:xt.container,children:e.jsx("div",{className:xt.content,children:e.jsxs(t.Card,{className:xt.card,children:[e.jsxs("div",{className:xt.header,style:{textAlign:"center"},children:[e.jsxs("svg",{width:"48",height:"48",viewBox:"0 0 56 56",fill:"none","aria-label":"logo",style:{marginBottom:8},children:[e.jsx("defs",{children:e.jsxs("linearGradient",{id:"brandGradAuth",x1:"0",y1:"0",x2:"56",y2:"56",gradientUnits:"userSpaceOnUse",children:[e.jsx("stop",{offset:"0%",stopColor:"#1677ff"}),e.jsx("stop",{offset:"100%",stopColor:"#0958d9"})]})}),e.jsx("rect",{x:"2",y:"2",width:"52",height:"52",rx:"14",fill:"url(#brandGradAuth)"}),e.jsx("path",{d:"M18 18 H40 L18 38 H40",stroke:"#ffffff",strokeWidth:"3.5",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"})]}),e.jsx(Oo,{level:4,style:{margin:0},children:r==="register"?"用户注册":"欢迎登录"})]}),e.jsxs(t.Form,{form:h,layout:"vertical",onFinish:d,initialValues:{autoLogin:!0},children:[r!=="forgot"&&e.jsx(t.Tabs,{activeKey:o,onChange:E=>l(E),centered:!0,items:b()}),F(),e.jsx(t.Form.Item,{children:e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[r==="login"&&e.jsx(t.Form.Item,{name:"autoLogin",valuePropName:"checked",noStyle:!0,children:e.jsx(t.Checkbox,{children:"自动登录"})}),e.jsx("a",{onClick:()=>{n(r==="login"?"register":"login")},children:r==="login"?"没有账号?立即注册":"已有账号?立即登录"})]})}),e.jsx(t.Form.Item,{children:e.jsx(t.Button,{type:"primary",htmlType:"submit",block:!0,size:"large",children:r==="login"?"登录":"注册"})})]})]})})})},Ao={display:"flex",flexDirection:"column",height:"100vh",overflow:"auto",background:"#f0f2f5",backgroundImage:"url('https://gw.alipayobjects.com/zos/rmsportal/TVYTbAXWheQpRcWDaDMu.svg')",backgroundRepeat:"no-repeat",backgroundPosition:"center 110px",backgroundSize:"100%"},Po={flex:1,padding:"32px 0",maxWidth:400,margin:"0 auto",width:"100%"},Ro=()=>{const[s,r]=p.useState({}),[n]=p.useState("account"),[o,l]=p.useState(!1),a=ue.useNavigate(),i=async x=>{l(!0);try{const h=await jo({identifier:x.userName,password:x.password});if(h&&h.token){localStorage.setItem("token",h.token);const y=h.account||{};localStorage.setItem("userInfo",JSON.stringify({userId:y.id,userName:y.username,nickname:y.nickname,tenantCode:y.tenantCode})),t.message.success("登录成功!"),a("/");return}r(h)}catch{t.message.error("登录失败,请重试!")}finally{l(!1)}},{status:c}=s;return e.jsx("div",{style:Ao,children:e.jsxs("div",{style:Po,children:[e.jsx("div",{style:{textAlign:"center",marginBottom:24},children:e.jsxs("svg",{width:"56",height:"56",viewBox:"0 0 56 56",fill:"none","aria-label":"logo",children:[e.jsx("defs",{children:e.jsxs("linearGradient",{id:"brandGrad",x1:"0",y1:"0",x2:"56",y2:"56",gradientUnits:"userSpaceOnUse",children:[e.jsx("stop",{offset:"0%",stopColor:"#1677ff"}),e.jsx("stop",{offset:"100%",stopColor:"#0958d9"})]})}),e.jsx("rect",{x:"2",y:"2",width:"52",height:"52",rx:"14",fill:"url(#brandGrad)"}),e.jsx("path",{d:"M18 18 H40 L18 38 H40",stroke:"#ffffff",strokeWidth:"3.5",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"})]})}),e.jsx(t.Tabs,{activeKey:n,centered:!0,items:[{key:"account",label:"账户密码登录"}]}),c==="error"&&e.jsx(t.Alert,{message:"账户或密码错误",type:"error",showIcon:!0,style:{marginBottom:16}}),e.jsxs(t.Form,{onFinish:i,initialValues:{autoLogin:!0},layout:"vertical",children:[e.jsx(t.Form.Item,{name:"userName",rules:[{required:!0,message:"请输入用户名!"}],children:e.jsx(t.Input,{size:"large",prefix:e.jsx(g.UserOutlined,{}),placeholder:"用户名"})}),e.jsx(t.Form.Item,{name:"password",rules:[{required:!0,message:"请输入密码!"}],children:e.jsx(t.Input.Password,{size:"large",prefix:e.jsx(g.LockOutlined,{}),placeholder:"密码"})}),e.jsx(t.Form.Item,{name:"autoLogin",valuePropName:"checked",children:e.jsx(t.Checkbox,{children:"自动登录"})}),e.jsx(t.Form.Item,{children:e.jsx(t.Button,{type:"primary",htmlType:"submit",size:"large",block:!0,loading:o,children:"登录"})})]}),e.jsxs("div",{style:{textAlign:"center",marginTop:16,color:"#888",fontSize:14},children:[e.jsx(ue.Link,{to:"/uc/register",style:{marginRight:16},children:"用户注册"}),e.jsx("span",{style:{margin:"0 8px",color:"#ddd"},children:"|"}),e.jsx(ue.Link,{to:"/uc/reset-password",style:{marginRight:16},children:"找回密码"}),e.jsx("span",{style:{margin:"0 8px",color:"#ddd"},children:"|"}),e.jsx(ue.Link,{to:"/uc/login",children:"手机验证码登录"})]})]})})},gt={health:()=>te.get("/agentTeam/health").then(s=>s.data)},No={LEADER:"red",WORKER:"blue",OBSERVER:"default"};function _o(){const[s,r]=p.useState([]),[n,o]=p.useState(null),[l,a]=p.useState([]),[i,c]=p.useState(!1),[x,h]=p.useState(!1),[y,d]=p.useState("disconnected"),[b,F]=p.useState([]),[E,_]=p.useState(""),[C,S]=p.useState([]),w=p.useRef(null),T=async()=>{c(!0);try{const m=await gt.listTeams();r(m||[])}catch(m){t.message.warning("加载团队失败:"+((m==null?void 0:m.message)||"未知错误")),r([])}finally{c(!1)}},A=async m=>{h(!0);try{const f=await gt.listMembers(m);a(f||[])}catch(f){t.message.warning("加载成员失败:"+((f==null?void 0:f.message)||"未知错误")),a([])}finally{h(!1)}},k=()=>{if(w.current){t.message.warning("已连接");return}const m=gt.buildWsUrl();d("connecting"),F(f=>[...f,`[${new Date().toLocaleTimeString()}] 连接到 ${m}...`]);try{const f=new WebSocket(m);f.onopen=()=>{d("connected"),F(z=>[...z,`[${new Date().toLocaleTimeString()}] ✅ 连接已建立`])},f.onmessage=z=>{const P=typeof z.data=="string"?z.data:"[binary]";F(Q=>[...Q,`[${new Date().toLocaleTimeString()}] ← ${P}`]);const D=P.match(/^([^|]+)\|(.+)$/);D&&S(Q=>[...Q,{from:D[1],text:D[2],time:new Date().toLocaleTimeString()}])},f.onerror=()=>{d("error"),F(z=>[...z,`[${new Date().toLocaleTimeString()}] ❌ 连接错误`])},f.onclose=()=>{d("disconnected"),F(z=>[...z,`[${new Date().toLocaleTimeString()}] 🔌 连接已关闭`]),w.current=null},w.current=f}catch(f){d("error"),t.message.error("WS 连接失败:"+((f==null?void 0:f.message)||"未知错误"))}},R=()=>{w.current&&(w.current.close(),w.current=null)},H=()=>{if(!w.current||w.current.readyState!==WebSocket.OPEN){t.message.error("WebSocket 未连接");return}if(!E.trim())return;const m=`${localStorage.getItem("userInfo")?JSON.parse(localStorage.getItem("userInfo")).userName:"me"}|${E}`;w.current.send(m),F(f=>[...f,`[${new Date().toLocaleTimeString()}] → ${E}`]),S(f=>[...f,{from:"me",text:E,time:new Date().toLocaleTimeString()}]),_("")};p.useEffect(()=>(T(),()=>{R()}),[]),p.useEffect(()=>{n&&A(n.teamCode)},[n]);const Y={disconnected:"default",connecting:"processing",connected:"success",error:"error"},K={disconnected:"未连接",connecting:"连接中",connected:"已连接",error:"错误"};return e.jsxs(Fe.PageContainer,{header:{title:"Agent 群组 IM (z-agent-team)",subTitle:"团队协作 + 实时通讯",breadcrumb:{}},children:[e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"300px 1fr",gap:16},children:[e.jsx(Fe.ProCard,{title:e.jsxs(t.Space,{children:[e.jsx(g.TeamOutlined,{})," 团队列表"]}),loading:i,headerBordered:!0,children:s.length===0?e.jsx(t.Empty,{image:t.Empty.PRESENTED_IMAGE_SIMPLE,description:"暂无团队",children:e.jsx(t.Button,{type:"primary",size:"small",onClick:T,children:"刷新"})}):e.jsx(t.List,{dataSource:s,renderItem:m=>e.jsx(t.List.Item,{onClick:()=>o(m),style:{cursor:"pointer",padding:"8px 12px",background:(n==null?void 0:n.teamCode)===m.teamCode?"#e6f7ff":void 0,borderRadius:4},children:e.jsx(t.List.Item.Meta,{title:m.teamName,description:e.jsxs(t.Space,{size:4,children:[e.jsx(t.Tag,{children:m.teamCode}),m.status==="ENABLE"?e.jsx(t.Tag,{color:"green",children:"启用"}):e.jsx(t.Tag,{children:"停用"})]})})})})}),e.jsxs(Fe.ProCard,{title:n?e.jsxs(t.Space,{children:[e.jsx(g.TeamOutlined,{})," ",n.teamName," (",n.teamCode,")"]}):"请选择团队",headerBordered:!0,extra:e.jsxs(t.Space,{children:[y==="connected"?e.jsx(t.Button,{icon:e.jsx(g.PoweroffOutlined,{}),onClick:R,children:"断开"}):e.jsx(t.Button,{type:"primary",icon:e.jsx(g.CheckCircleOutlined,{}),onClick:k,children:"连接"}),e.jsx(t.Tag,{color:Y[y],children:K[y]})]}),children:[n?e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:16},children:[e.jsx(Fe.ProCard,{title:"成员",loading:x,size:"small",children:e.jsx(t.List,{dataSource:l,renderItem:m=>e.jsx(t.List.Item,{children:e.jsx(t.List.Item.Meta,{title:e.jsxs(t.Space,{children:[m.appCode,e.jsx(t.Tag,{color:No[m.role||"WORKER"],children:m.role})]}),description:`优先级: ${m.priority??0} · ${m.enabled===1?"✅ 启用":"❌ 停用"}`})})})}),e.jsxs(Fe.ProCard,{title:"实时消息",size:"small",styles:{body:{padding:0,display:"flex",flexDirection:"column",height:400}},children:[e.jsx("div",{style:{flex:1,overflow:"auto",padding:12},children:C.length===0?e.jsx(t.Empty,{image:t.Empty.PRESENTED_IMAGE_SIMPLE,description:"暂无消息"}):C.map((m,f)=>e.jsxs("div",{style:{marginBottom:8},children:[e.jsx(t.Tag,{color:m.from==="me"?"blue":"green",children:m.from}),e.jsx("span",{style:{marginLeft:8},children:m.text}),e.jsx("span",{style:{marginLeft:8,color:"#999",fontSize:11},children:m.time})]},f))}),e.jsxs("div",{style:{padding:8,borderTop:"1px solid #f0f0f0",display:"flex",gap:8},children:[e.jsx(t.Input,{value:E,onChange:m=>_(m.target.value),onPressEnter:H,placeholder:y==="connected"?"输入消息...":"请先连接 WebSocket",disabled:y!=="connected"}),e.jsx(t.Button,{type:"primary",icon:e.jsx(g.SendOutlined,{}),onClick:H,disabled:y!=="connected",children:"发送"})]})]})]}):e.jsx(t.Empty,{description:"请从左侧选择一个团队"}),b.length>0&&e.jsx(Fe.ProCard,{title:"WebSocket 日志",size:"small",style:{marginTop:16},children:e.jsx("pre",{style:{background:"#1e1e1e",color:"#d4d4d4",padding:8,borderRadius:4,fontFamily:"Menlo, monospace",fontSize:11,maxHeight:180,overflow:"auto",margin:0},children:b.join(`
31
+ `)})})]})]}),e.jsx(t.Alert,{style:{marginTop:16},type:"info",showIcon:!0,message:"说明",description:e.jsxs("span",{children:["完整 STOMP 客户端 (含订阅 Topic、ACK、消息历史) 见 ",e.jsx("code",{children:"z-agent/z-agent-team/z-agent-team-frontend"}),"。 本页提供轻量级 WS 连接 + 群组管理 REST 端点示例。"]})})]})}const st={list:()=>te.get("/agent/team/workspace/list").then(s=>s.data),create:s=>te.post("/agent/team/workspace",s).then(r=>r.data),update:(s,r)=>te.put(`/agent/team/workspace/${s}`,r).then(n=>n.data),delete:s=>te.delete(`/agent/team/workspace/${s}`).then(r=>r.data),getFileTree:s=>te.get("/agent/team/workspace/file-tree-by-path",{params:{path:s}}).then(r=>r.data),getFileContent:s=>te.get("/agent/team/workspace/file-content",{params:{path:s}}).then(r=>r.data)},yt={list:s=>te.get(`/agent/team/conversation/${s}/work-items`).then(r=>r.data),create:s=>te.post("/agent/team/work-item",s).then(r=>r.data),update:(s,r)=>te.put(`/agent/team/work-item/${s}`,r).then(n=>n.data),delete:s=>te.delete(`/agent/team/work-item/${s}`).then(r=>r.data)},Ls={OPEN:"green",DONE:"blue",ARCHIVED:"default"};function Do(){var ne,or;const{message:s}=t.App.useApp(),r=localStorage.getItem("userInfo")||"{}";let n={};try{n=JSON.parse(r)}catch{}const o=n!=null&&n.userId?String(n.userId):"anonymous",l=(n==null?void 0:n.userName)||(n==null?void 0:n.name)||"我",[a,i]=p.useState([]),[c,x]=p.useState(!1),[h,y]=p.useState(null),[d,b]=p.useState([]),[F,E]=p.useState(!1),[_,C]=p.useState([]),[S,w]=p.useState(!1),[T,A]=p.useState(null),[k,R]=p.useState(!1),[H,Y]=p.useState([]),[K,m]=p.useState(""),[f,z]=p.useState("disconnected"),P=p.useRef(null),D=p.useRef(null),[Q,oe]=p.useState(""),[ge,he]=p.useState(""),[N,O]=p.useState(!1),[j,L]=p.useState(!1),[$]=t.Form.useForm(),[V]=t.Form.useForm(),[ie,X]=p.useState(null),[Z,fe]=p.useState("z-one-company-default");p.useEffect(()=>{Ee(),Ie(),Oe()},[]),p.useEffect(()=>{D.current&&D.current.scrollIntoView({behavior:"smooth"})},[H,Q]);const Ee=async()=>{try{const v=await gt.listTeams();v&&v.length>0&&fe(v[0].teamCode)}catch{}},Ie=async()=>{E(!0);try{const v=await st.list(o);b(v||[])}catch{b([])}finally{E(!1)}},Oe=async()=>{x(!0);try{const v=await yt.listAllByOwner(o,100);i(v||[])}catch{i([])}finally{x(!1)}},ae=async v=>{if(!v){C([]);return}w(!0);try{const U=await st.fileTree(v);C(U?[je(U)]:[])}catch(U){s.error("加载文件树失败:"+((U==null?void 0:U.message)||"未知错误")),C([])}finally{w(!1)}},Je=async v=>{try{const se=(await yt.messages(v,200)||[]).map(le=>({msgCode:le.msgCode,senderType:le.senderType,senderCode:le.senderCode,senderName:le.senderName,content:le.content,messageType:le.messageType,timestamp:le.gmtCreate?new Date(le.gmtCreate).getTime():Date.now()}));Y(se)}catch{Y([])}},Be=v=>{ye();const se=`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}/api/agent/team/ws?convCode=${encodeURIComponent(v)}&userId=${encodeURIComponent(o)}&userName=${encodeURIComponent(l)}`;z("connecting");try{const le=new WebSocket(se);le.onopen=()=>{z("connected")},le.onmessage=xl=>{try{const gl=JSON.parse(xl.data);W(gl)}catch{}},le.onerror=()=>{z("error")},le.onclose=()=>{z("disconnected"),P.current=null},P.current=le}catch(le){z("error"),s.error("WS 连接失败:"+((le==null?void 0:le.message)||"未知错误"))}},ye=()=>{if(P.current){try{P.current.close()}catch{}P.current=null,z("disconnected"),oe("")}},W=v=>{const U=v.type;U==="AGENT_RESPONSE_DELTA"||U==="AGENT_THINKING_DELTA"?(he(v.senderName||v.senderCode||"Agent"),oe(se=>se+(v.content||""))):U==="AGENT_RESPONSE"||U==="AGENT_THINKING"?(Y(se=>[...se,{msgCode:v.eventId||`evt-${Date.now()}`,senderType:v.senderType||"AGENT",senderCode:v.senderCode||"",senderName:v.senderName||"Agent",content:v.content||"",messageType:U,timestamp:v.timestamp||Date.now()}]),oe(""),he("")):U==="SYSTEM"||U==="PARTICIPANT_JOIN"||U==="PARTICIPANT_LEAVE"?v.content&&v.content!=="HEARTBEAT_ACK"&&v.content!=="PONG"&&Y(se=>[...se,{msgCode:v.eventId||`evt-${Date.now()}`,senderType:"SYSTEM",senderCode:v.senderCode||"system",senderName:"系统",content:v.content,messageType:U,timestamp:v.timestamp||Date.now()}]):U==="ERROR"?(Y(se=>[...se,{msgCode:v.eventId||`err-${Date.now()}`,senderType:"SYSTEM",senderCode:"system",senderName:"错误",content:v.content||"未知错误",messageType:U,timestamp:v.timestamp||Date.now()}]),oe(""),he("")):U==="MESSAGE_END"&&(oe(""),he(""))},ce=()=>{const v=K.trim();if(!v)return;if(!P.current||P.current.readyState!==WebSocket.OPEN){s.warning("IM 未连接");return}if(!h){s.warning("请先选择一个工作项");return}const U=JSON.stringify({type:"USER_MESSAGE",content:v});P.current.send(U),Y(se=>[...se,{msgCode:`local-${Date.now()}`,senderType:"USER",senderCode:o,senderName:l,content:v,messageType:"TEXT",timestamp:Date.now()}]),m("")},be=v=>{y(v),Je(v.convCode),Be(v.convCode),v.workspaceCode?(X(v.workspaceCode),ae(v.workspaceCode)):(X(null),C([]))},we=async()=>{try{const v=await V.validateFields(),U=await yt.create({teamCode:Z,userId:o,userName:l,title:v.title,workspaceCode:v.workspaceCode||void 0});s.success("工作项已创建"),L(!1),V.resetFields(),await Oe(),U&&be(U)}catch(v){s.error("创建失败:"+((v==null?void 0:v.message)||"未知错误"))}},I=async()=>{var v,U;try{const se=await $.validateFields();await st.create({workspaceName:se.workspaceName,localPath:se.localPath,ownerId:o,ownerName:l,description:se.description}),s.success("工作空间已创建"),O(!1),$.resetFields(),await Ie()}catch(se){const le=((U=(v=se==null?void 0:se.response)==null?void 0:v.data)==null?void 0:U.message)||(se==null?void 0:se.message)||"未知错误";s.error("创建失败:"+le)}},B=async v=>{R(!0);try{const U=await st.fileContent(v);A({path:v,content:(U==null?void 0:U.content)||""})}catch(U){s.error("读取文件失败:"+((U==null?void 0:U.message)||"未知错误"))}finally{R(!1)}},G=async v=>{try{await yt.close(v,"DONE"),s.success("已关闭工作项"),await Oe(),(h==null?void 0:h.convCode)===v&&(y(null),ye(),Y([]),C([]))}catch(U){s.error("关闭失败:"+((U==null?void 0:U.message)||"未知错误"))}},ee=async v=>{try{await st.delete(v),s.success("已删除"),await Ie(),ie===v&&(X(null),C([]))}catch(U){s.error("删除失败:"+((U==null?void 0:U.message)||"未知错误"))}},je=v=>{var U;return{key:v.absolutePath,title:e.jsxs("span",{children:[v.isDirectory?e.jsx(g.FolderOutlined,{style:{marginRight:4,color:"#faad14"}}):e.jsx(g.FileOutlined,{style:{marginRight:4,color:"#8c8c8c"}}),v.name,v.isDirectory&&v.totalDescendants>0?e.jsxs("span",{style:{color:"#bfbfbf",marginLeft:6,fontSize:11},children:["(",v.totalDescendants,")"]}):null]}),children:((U=v.children)==null?void 0:U.map(je))||[],isLeaf:!v.isDirectory,disabled:!1}};return e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"240px 280px 1fr",height:"calc(100vh - 130px)",background:"#fff",border:"1px solid #f0f0f0",borderRadius:8,overflow:"hidden"},children:[e.jsxs("div",{style:{borderRight:"1px solid #f0f0f0",display:"flex",flexDirection:"column",background:"#fafafa"},children:[e.jsxs("div",{style:{padding:12,borderBottom:"1px solid #f0f0f0",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsxs(t.Space,{size:4,children:[e.jsx(g.MessageOutlined,{style:{color:"#1677ff"}}),e.jsx("strong",{children:"工作项"})]}),e.jsxs(t.Space,{size:4,children:[e.jsx(t.Tooltip,{title:"刷新",children:e.jsx(t.Button,{size:"small",type:"text",icon:e.jsx(g.ReloadOutlined,{}),onClick:Oe})}),e.jsx(t.Tooltip,{title:"新建工作项",children:e.jsx(t.Button,{size:"small",type:"text",icon:e.jsx(g.PlusOutlined,{}),onClick:()=>L(!0)})})]})]}),e.jsx("div",{style:{flex:1,overflow:"auto"},children:c?e.jsx("div",{style:{padding:24,textAlign:"center"},children:e.jsx(t.Spin,{size:"small"})}):a.length===0?e.jsx(t.Empty,{image:t.Empty.PRESENTED_IMAGE_SIMPLE,description:"暂无工作项",style:{padding:24,marginTop:24},children:e.jsx(t.Button,{size:"small",type:"primary",onClick:()=>L(!0),children:"新建工作项"})}):a.map(v=>e.jsxs("div",{onClick:()=>be(v),style:{padding:"10px 12px",cursor:"pointer",borderBottom:"1px solid #f5f5f5",background:(h==null?void 0:h.convCode)===v.convCode?"#e6f7ff":"transparent",transition:"background 0.2s"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:4},children:[e.jsx("strong",{style:{fontSize:13,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",maxWidth:150},children:v.title||"未命名"}),e.jsx(t.Badge,{count:v.unreadCount||0,size:"small"})]}),e.jsx("div",{style:{fontSize:11,color:"#8c8c8c",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:v.lastMsgPreview||"暂无消息"}),e.jsxs("div",{style:{marginTop:4,fontSize:11,color:"#bfbfbf"},children:[e.jsx(t.Tag,{color:Ls[v.status||"OPEN"],style:{marginRight:4,fontSize:10,padding:"0 4px"},children:v.status||"OPEN"}),v.workspaceCode?e.jsx(t.Tag,{color:"purple",style:{fontSize:10,padding:"0 4px"},children:"有工作空间"}):null]})]},v.convCode))})]}),e.jsxs("div",{style:{borderRight:"1px solid #f0f0f0",display:"flex",flexDirection:"column",background:"#fff"},children:[e.jsxs("div",{style:{padding:12,borderBottom:"1px solid #f0f0f0",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsxs(t.Space,{size:4,children:[e.jsx(g.FolderOpenOutlined,{style:{color:"#faad14"}}),e.jsx("strong",{children:"工作空间"})]}),e.jsx(t.Space,{size:4,children:e.jsx(t.Tooltip,{title:"新建工作空间",children:e.jsx(t.Button,{size:"small",type:"text",icon:e.jsx(g.PlusOutlined,{}),onClick:()=>O(!0)})})})]}),h!=null&&h.workspaceCode?e.jsx("div",{style:{padding:"8px 12px",background:"#f0f5ff",borderBottom:"1px solid #f0f0f0",fontSize:12},children:e.jsxs(t.Space,{size:4,children:[e.jsx(t.Tag,{color:"blue",children:"当前工作项"}),e.jsx("span",{style:{color:"#1677ff"},children:((ne=d.find(v=>v.workspaceCode===h.workspaceCode))==null?void 0:ne.workspaceName)||h.workspaceCode}),e.jsx(t.Button,{size:"small",type:"text",icon:e.jsx(g.ReloadOutlined,{}),onClick:()=>ae(h.workspaceCode)})]})}):null,e.jsx("div",{style:{maxHeight:200,overflow:"auto",borderBottom:"1px solid #f0f0f0"},children:F?e.jsx("div",{style:{padding:12,textAlign:"center"},children:e.jsx(t.Spin,{size:"small"})}):d.length===0?e.jsx("div",{style:{padding:12,color:"#8c8c8c",fontSize:12,textAlign:"center"},children:"暂无工作空间"}):d.map(v=>e.jsxs("div",{onClick:()=>{X(v.workspaceCode),ae(v.workspaceCode)},style:{padding:"6px 12px",cursor:"pointer",fontSize:12,background:ie===v.workspaceCode?"#e6f7ff":"transparent",borderLeft:ie===v.workspaceCode?"3px solid #1677ff":"3px solid transparent",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsxs(t.Space,{size:4,style:{overflow:"hidden"},children:[e.jsx(g.FolderOutlined,{style:{color:"#faad14",fontSize:12}}),e.jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:v.workspaceName})]}),e.jsx(t.Popconfirm,{title:"删除此工作空间?",onConfirm:U=>{U==null||U.stopPropagation(),ee(v.workspaceCode)},onCancel:U=>U==null?void 0:U.stopPropagation(),children:e.jsx(t.Button,{size:"small",type:"text",danger:!0,icon:e.jsx(g.DeleteOutlined,{}),onClick:U=>U.stopPropagation()})})]},v.workspaceCode))}),e.jsx("div",{style:{flex:1,overflow:"auto",padding:8},children:S?e.jsx("div",{style:{padding:24,textAlign:"center"},children:e.jsx(t.Spin,{})}):ie?_.length===0?e.jsx(t.Empty,{image:t.Empty.PRESENTED_IMAGE_SIMPLE,description:"空目录或无文件",style:{marginTop:40}}):e.jsx(t.Tree,{treeData:_,defaultExpandAll:!1,showLine:!0,showIcon:!1,onSelect:(v,U)=>{const se=U.node;!se.isLeaf&&v.length>0||se.isLeaf&&U.node.key&&B(String(U.node.key))}}):e.jsx(t.Empty,{image:t.Empty.PRESENTED_IMAGE_SIMPLE,description:"请选择工作空间",style:{marginTop:40}})}),T?e.jsxs("div",{style:{borderTop:"1px solid #f0f0f0",maxHeight:240,overflow:"hidden",display:"flex",flexDirection:"column"},children:[e.jsxs("div",{style:{padding:"6px 12px",background:"#fafafa",borderBottom:"1px solid #f0f0f0",display:"flex",alignItems:"center",justifyContent:"space-between",fontSize:11},children:[e.jsxs(t.Space,{size:4,children:[e.jsx(g.FileTextOutlined,{}),e.jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",maxWidth:180},children:T.path.split("/").pop()})]}),e.jsx(t.Button,{size:"small",type:"text",onClick:()=>A(null),children:"关闭"})]}),e.jsx("pre",{style:{flex:1,margin:0,padding:8,overflow:"auto",fontSize:11,background:"#1e1e1e",color:"#d4d4d4",fontFamily:"Menlo, monospace",whiteSpace:"pre-wrap",wordBreak:"break-all"},children:k?"加载中...":T.content||"(空)"})]}):null]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",background:"#f5f5f5"},children:[e.jsxs("div",{style:{padding:"12px 16px",background:"#fff",borderBottom:"1px solid #f0f0f0",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[h?e.jsxs(t.Space,{size:8,children:[e.jsx(g.TeamOutlined,{style:{color:"#1677ff"}}),e.jsx("strong",{style:{fontSize:14},children:h.title||"未命名"}),e.jsx(t.Tag,{color:Ls[h.status||"OPEN"],style:{marginLeft:4},children:h.status||"OPEN"}),h.workspaceCode?e.jsx(t.Tag,{color:"purple",icon:e.jsx(g.FolderOpenOutlined,{}),children:((or=d.find(v=>v.workspaceCode===h.workspaceCode))==null?void 0:or.workspaceName)||"工作空间"}):null,e.jsxs("span",{style:{color:"#8c8c8c",fontSize:12},children:[h.messageCount||0," 条消息"]})]}):e.jsx("span",{style:{color:"#8c8c8c"},children:"请从左侧选择一个工作项"}),h?e.jsxs(t.Space,{size:4,children:[e.jsx(t.Tag,{color:f==="connected"?"green":f==="error"?"red":"default",children:f==="connected"?"已连接":f==="connecting"?"连接中":f==="error"?"错误":"未连接"}),e.jsx(t.Popconfirm,{title:"关闭此工作项?",onConfirm:()=>G(h.convCode),children:e.jsx(t.Button,{size:"small",type:"text",danger:!0,icon:e.jsx(g.CheckCircleOutlined,{}),children:"完成"})})]}):null]}),e.jsx("div",{style:{flex:1,overflow:"auto",padding:16,display:"flex",flexDirection:"column",gap:12},children:h?H.length===0&&!Q?e.jsx(t.Empty,{image:t.Empty.PRESENTED_IMAGE_SIMPLE,description:"暂无消息,开始聊吧",style:{marginTop:80}}):e.jsxs(e.Fragment,{children:[H.map(v=>e.jsx(Bs,{msg:v,currentUserId:o},v.msgCode)),Q?e.jsx(Bs,{msg:{msgCode:"streaming",senderType:"AGENT",senderCode:"agent",senderName:ge,content:Q,timestamp:Date.now(),messageType:"STREAMING"},currentUserId:o}):null,e.jsx("div",{ref:D})]}):e.jsx(t.Empty,{image:t.Empty.PRESENTED_IMAGE_SIMPLE,description:"从左侧选择工作项开始聊天",style:{marginTop:80}})}),e.jsxs("div",{style:{padding:12,background:"#fff",borderTop:"1px solid #f0f0f0",display:"flex",gap:8},children:[e.jsx(t.Input.TextArea,{value:K,onChange:v=>m(v.target.value),onPressEnter:v=>{v.shiftKey||(v.preventDefault(),ce())},placeholder:h?f==="connected"?"输入消息... (Enter 发送, Shift+Enter 换行)":"正在连接 IM...":"请先选择工作项",autoSize:{minRows:1,maxRows:4},disabled:!h||f!=="connected"}),e.jsx(t.Button,{type:"primary",icon:e.jsx(g.SendOutlined,{}),onClick:ce,disabled:!h||f!=="connected"||!K.trim(),children:"发送"})]})]}),e.jsx(t.Modal,{title:"新建工作空间",open:N,onCancel:()=>O(!1),onOk:I,okText:"创建",cancelText:"取消",children:e.jsxs(t.Form,{form:$,layout:"vertical",children:[e.jsx(t.Form.Item,{label:"名称",name:"workspaceName",rules:[{required:!0,message:"请输入工作空间名称"}],children:e.jsx(t.Input,{placeholder:"例如:z-opc 主项目"})}),e.jsx(t.Form.Item,{label:"本地路径",name:"localPath",rules:[{required:!0,message:"请输入本地路径"}],extra:"服务器侧的文件系统绝对路径 (例: /Users/zifang/workplace)",children:e.jsx(t.Input,{placeholder:"/Users/zifang/workplace"})}),e.jsx(t.Form.Item,{label:"描述",name:"description",children:e.jsx(t.Input.TextArea,{rows:2,placeholder:"可选:工作空间用途说明"})})]})}),e.jsx(t.Modal,{title:"新建工作项",open:j,onCancel:()=>L(!1),onOk:we,okText:"创建",cancelText:"取消",children:e.jsxs(t.Form,{form:V,layout:"vertical",children:[e.jsx(t.Form.Item,{label:"标题",name:"title",rules:[{required:!0,message:"请输入工作项标题"}],children:e.jsx(t.Input,{placeholder:"例如:完成 z-opc 用户面板"})}),e.jsx(t.Form.Item,{label:"关联工作空间 (可选)",name:"workspaceCode",extra:"绑定后,工作项右侧会显示对应工作空间的文件树",children:e.jsxs("select",{style:{width:"100%",height:32,border:"1px solid #d9d9d9",borderRadius:6,padding:"0 11px"},children:[e.jsx("option",{value:"",children:"无 (仅 IM 群聊)"}),d.map(v=>e.jsxs("option",{value:v.workspaceCode,children:[v.workspaceName," (",v.localPath,")"]},v.workspaceCode))]})})]})})]})}function Bs({msg:s,currentUserId:r}){const n=s.senderType==="USER"&&s.senderCode===r;if(s.senderType==="SYSTEM")return e.jsx("div",{style:{textAlign:"center",color:"#8c8c8c",fontSize:11},children:e.jsx(t.Tag,{color:"default",children:s.content})});const l=n?"#1677ff":"#fff",a=n?"#fff":"#333",i=n?"#1677ff":"#87d068";return e.jsxs("div",{style:{display:"flex",flexDirection:n?"row-reverse":"row",alignItems:"flex-start",gap:8},children:[e.jsx(t.Avatar,{style:{background:i,flexShrink:0},children:(s.senderName||"?").charAt(0).toUpperCase()}),e.jsxs("div",{style:{maxWidth:"70%"},children:[e.jsxs("div",{style:{fontSize:11,color:"#8c8c8c",marginBottom:2,textAlign:n?"right":"left"},children:[s.senderName," · ",new Date(s.timestamp).toLocaleTimeString(),s.messageType&&s.messageType!=="TEXT"?e.jsx(t.Tag,{style:{marginLeft:4,fontSize:10},children:s.messageType}):null]}),e.jsx("div",{style:{padding:"8px 12px",background:l,color:a,borderRadius:8,border:n?"none":"1px solid #e8e8e8",wordBreak:"break-word",whiteSpace:"pre-wrap",boxShadow:"0 1px 2px rgba(0,0,0,0.04)"},children:s.content||(s.messageType==="STREAMING"?"...":"")})]})]})}const He={health:()=>te.get("/webide/health").then(s=>s.data)},Lo={CREATING:{text:"创建中",color:"processing"},RUNNING:{text:"运行中",color:"success"},STOPPED:{text:"已停止",color:"default"},ERROR:{text:"错误",color:"error"}},Bo={GIT:{text:"GIT 模式",color:"blue"},SHARED:{text:"SHARED 模式",color:"purple"}};function Mo(){const s=p.useRef(void 0),[r,n]=p.useState(!1),[o,l]=p.useState(!1),[a,i]=p.useState([]),[c,x]=p.useState(null),[h,y]=p.useState(!1),[d]=t.Form.useForm(),b=async()=>{try{const T=await He.listContainers();return{data:T||[],success:!0,total:(T||[]).length}}catch(T){return t.message.warning("后端未就绪,显示空列表:"+((T==null?void 0:T.message)||"未知错误")),{data:[],success:!1,total:0}}},F=async()=>{var T;try{const A=await d.validateFields();y(!0);const k=await He.inspect(A);t.message.success(`WebIDE 创建成功:${k.url}`),n(!1),d.resetFields(),(T=s.current)==null||T.reload(),k.url&&window.open(k.url,"_blank")}catch(A){if(A!=null&&A.errorFields)return;t.message.error("创建失败:"+((A==null?void 0:A.message)||"未知错误"))}finally{y(!1)}},E=async T=>{var A;try{await He.startContainer(T),t.message.success("已启动"),(A=s.current)==null||A.reload()}catch(k){t.message.error("启动失败:"+((k==null?void 0:k.message)||"未知错误"))}},_=async T=>{var A;try{await He.stopContainer(T),t.message.success("已停止"),(A=s.current)==null||A.reload()}catch(k){t.message.error("停止失败:"+((k==null?void 0:k.message)||"未知错误"))}},C=async T=>{var A;try{await He.removeContainer(T),t.message.success("已删除"),(A=s.current)==null||A.reload()}catch(k){t.message.error("删除失败:"+((k==null?void 0:k.message)||"未知错误"))}},S=async T=>{x(T),l(!0),i(["加载中..."]);try{const A=await He.getLogs(T.containerId,200);i((A==null?void 0:A.lines)||[])}catch(A){i([`加载日志失败:${(A==null?void 0:A.message)||"未知错误"}`])}},w=[{title:"容器ID",dataIndex:"containerId",width:200,fixed:"left",ellipsis:!0},{title:"模式",dataIndex:"mode",width:110,render:(T,A)=>{const k=Bo[A.mode]||{text:A.mode,color:"default"};return e.jsx(t.Tag,{color:k.color,children:k.text})}},{title:"Git URL",dataIndex:"gitUrl",width:200,ellipsis:!0},{title:"分支",dataIndex:"branch",width:100},{title:"状态",dataIndex:"status",width:100,render:(T,A)=>{const k=Lo[A.status]||{text:A.status,color:"default"};return e.jsx(t.Tag,{color:k.color,children:k.text})}},{title:"URL",dataIndex:"url",width:200,ellipsis:!0,render:(T,A)=>A.url?e.jsx("a",{href:A.url,target:"_blank",rel:"noreferrer",children:A.url}):"-"},{title:"CPU%",dataIndex:"cpuUsage",width:80,render:T=>typeof T=="number"?`${T.toFixed(1)}%`:"-"},{title:"内存%",dataIndex:"memoryUsage",width:80,render:T=>typeof T=="number"?`${T.toFixed(1)}%`:"-"},{title:"创建时间",dataIndex:"createdAt",width:170,valueType:"dateTime"},{title:"操作",valueType:"option",width:240,fixed:"right",render:(T,A)=>[e.jsx(t.Tooltip,{title:"启动",children:e.jsx(t.Button,{type:"text",size:"small",icon:e.jsx(g.PlayCircleOutlined,{}),onClick:()=>E(A.containerId),children:"启动"})},"start"),e.jsx(t.Tooltip,{title:"停止",children:e.jsx(t.Button,{type:"text",size:"small",icon:e.jsx(g.PauseOutlined,{}),onClick:()=>_(A.containerId),children:"停止"})},"stop"),e.jsx(t.Tooltip,{title:"查看日志",children:e.jsx(t.Button,{type:"text",size:"small",icon:e.jsx(g.FileTextOutlined,{}),onClick:()=>S(A),children:"日志"})},"logs"),e.jsx(t.Tooltip,{title:"删除",children:e.jsx(t.Button,{type:"text",danger:!0,size:"small",icon:e.jsx(g.DeleteOutlined,{}),onClick:()=>C(A.containerId),children:"删除"})},"remove")]}];return e.jsxs(Fe.PageContainer,{header:{title:"WebIDE 容器管理 (z-webide)",subTitle:"基于 code-server 的容器化 WebIDE",breadcrumb:{}},children:[e.jsx(Fe.ProTable,{actionRef:s,rowKey:"containerId",columns:w,request:b,search:!1,pagination:{pageSize:20},headerTitle:"容器列表",toolBarRender:()=>[e.jsx(t.Button,{type:"primary",icon:e.jsx(g.PlusOutlined,{}),onClick:()=>n(!0),children:"新建 WebIDE"},"add"),e.jsx(t.Button,{icon:e.jsx(g.ReloadOutlined,{}),onClick:()=>{var T;return(T=s.current)==null?void 0:T.reload()},children:"刷新"},"reload")]}),e.jsx(t.Drawer,{title:e.jsxs(t.Space,{children:[e.jsx(g.CodeOutlined,{})," 新建 WebIDE"]}),open:r,onClose:()=>n(!1),width:520,extra:e.jsxs(t.Space,{children:[e.jsx(t.Button,{onClick:()=>n(!1),children:"取消"}),e.jsx(t.Button,{type:"primary",loading:h,onClick:F,children:"创建并打开"})]}),children:e.jsx(zo,{form:d})}),e.jsx(t.Drawer,{title:c?`容器日志 — ${c.containerId}`:"容器日志",open:o,onClose:()=>l(!1),width:720,children:e.jsx("pre",{style:{background:"#1e1e1e",color:"#d4d4d4",padding:12,borderRadius:4,fontFamily:"Menlo, Consolas, monospace",fontSize:12,maxHeight:"70vh",overflow:"auto",whiteSpace:"pre-wrap"},children:a.join(`
32
+ `)})})]})}function zo({form:s}){const{mode:r,setMode:n}=Uo();return e.jsxs(t.Form,{form:s,layout:"vertical",style:{marginTop:16},initialValues:{mode:"GIT"},children:[e.jsx(t.Form.Item,{name:"mode",label:"模式",rules:[{required:!0}],children:e.jsx(t.Select,{onChange:o=>n(o),options:[{value:"GIT",label:"GIT 模式 (从仓库克隆)"},{value:"SHARED",label:"SHARED 模式 (共享工作区)"}]})}),r==="GIT"&&e.jsxs(e.Fragment,{children:[e.jsx(t.Form.Item,{name:"gitUrl",label:"Git URL",rules:[{required:!0,type:"url"}],extra:"支持 https://github.com/xxx/yyy.git",children:e.jsx(t.Input,{placeholder:"https://github.com/your/repo.git"})}),e.jsx(t.Form.Item,{name:"branch",label:"分支",children:e.jsx(t.Input,{placeholder:"main (默认)"})})]}),r==="SHARED"&&e.jsx(t.Form.Item,{name:"shareKey",label:"共享 Key",rules:[{required:!0}],children:e.jsx(t.Input,{placeholder:"SHARED-XXXXXX"})}),e.jsx(t.Form.Item,{name:"tenantCode",label:"租户编码 (可选)",children:e.jsx(t.Input,{placeholder:"default"})})]})}function Uo(){const[s,r]=p.useState("GIT");return{mode:s,setMode:r}}const $o=()=>e.jsx(ue.Outlet,{}),qo=()=>{const[s]=t.Form.useForm(),r=n=>{console.log("UC login:",n),t.message.info("UC 账号密码登录占位组件 — 实际登录逻辑接 z-ctc-ac")};return e.jsx(t.Card,{title:"账号密码登录",style:{maxWidth:420,margin:"40px auto"},children:e.jsxs(t.Form,{form:s,onFinish:r,layout:"vertical",children:[e.jsx(t.Form.Item,{name:"username",label:"账号",rules:[{required:!0}],children:e.jsx(t.Input,{prefix:e.jsx(g.UserOutlined,{}),placeholder:"请输入账号"})}),e.jsx(t.Form.Item,{name:"password",label:"密码",rules:[{required:!0}],children:e.jsx(t.Input.Password,{prefix:e.jsx(g.LockOutlined,{}),placeholder:"请输入密码"})}),e.jsx(t.Form.Item,{children:e.jsx(t.Button,{type:"primary",htmlType:"submit",block:!0,children:"登录"})})]})})},Ho=()=>{const[s]=t.Form.useForm(),[r,n]=p.useState(!1),[o,l]=p.useState(0),a=async()=>{try{const c=s.getFieldValue("phone");if(!c||!/^1\d{10}$/.test(c)){t.message.warning("请输入正确的手机号");return}n(!0),l(60);const x=setInterval(()=>l(h=>h>0?h-1:(clearInterval(x),0)),1e3);t.message.success("验证码已发送 (mock 通道: 123456)")}catch{t.message.error("发送失败")}finally{n(!1)}},i=c=>{if(c.code!=="123456"){t.message.error("验证码错误,固定码 123456");return}t.message.success("手机登录成功 (占位)")};return e.jsx(t.Card,{title:"手机验证码登录",style:{maxWidth:420,margin:"40px auto"},children:e.jsxs(t.Form,{form:s,onFinish:i,layout:"vertical",children:[e.jsx(t.Form.Item,{name:"phone",label:"手机号",rules:[{required:!0,pattern:/^1\d{10}$/}],children:e.jsx(t.Input,{prefix:e.jsx(g.MobileOutlined,{}),placeholder:"11 位手机号",maxLength:11})}),e.jsx(t.Form.Item,{name:"code",label:"验证码",rules:[{required:!0}],children:e.jsx(t.Input,{prefix:e.jsx(g.SafetyOutlined,{}),placeholder:"固定码 123456",maxLength:6,addonAfter:e.jsx(t.Button,{type:"link",disabled:r||o>0,onClick:a,children:o>0?`${o}s`:"获取验证码"})})}),e.jsx(t.Form.Item,{children:e.jsx(t.Button,{type:"primary",htmlType:"submit",block:!0,children:"登录"})})]})})},Wo=()=>{const[s]=t.Form.useForm(),r=n=>{console.log("UC register:",n),t.message.success("注册成功 (占位)")};return e.jsx(t.Card,{title:"新用户注册",style:{maxWidth:420,margin:"40px auto"},children:e.jsxs(t.Form,{form:s,onFinish:r,layout:"vertical",children:[e.jsx(t.Form.Item,{name:"username",label:"账号",rules:[{required:!0,min:3}],children:e.jsx(t.Input,{prefix:e.jsx(g.UserOutlined,{}),placeholder:"3 位以上"})}),e.jsx(t.Form.Item,{name:"phone",label:"手机号",rules:[{required:!0,pattern:/^1\d{10}$/}],children:e.jsx(t.Input,{prefix:e.jsx(g.MobileOutlined,{}),placeholder:"11 位手机号",maxLength:11})}),e.jsx(t.Form.Item,{name:"code",label:"验证码",rules:[{required:!0}],children:e.jsx(t.Input,{prefix:e.jsx(g.SafetyOutlined,{}),placeholder:"固定码 123456",maxLength:6})}),e.jsx(t.Form.Item,{name:"password",label:"密码",rules:[{required:!0,min:6}],children:e.jsx(t.Input.Password,{prefix:e.jsx(g.LockOutlined,{}),placeholder:"6 位以上"})}),e.jsx(t.Form.Item,{children:e.jsx(t.Button,{type:"primary",htmlType:"submit",block:!0,children:"注册"})})]})})},Go=()=>{const[s,r]=p.useState(0),[n]=t.Form.useForm(),o=async()=>{try{await n.validateFields(),s<2?r(s+1):t.message.success("密码重置成功 (占位)")}catch{}};return e.jsxs(t.Card,{title:"找回密码",style:{maxWidth:480,margin:"40px auto"},children:[e.jsx(t.Steps,{current:s,items:[{title:"验证手机号"},{title:"输入验证码"},{title:"重置密码"}],style:{marginBottom:24}}),e.jsxs(t.Form,{form:n,layout:"vertical",children:[s===0&&e.jsx(t.Form.Item,{name:"phone",label:"手机号",rules:[{required:!0,pattern:/^1\d{10}$/}],children:e.jsx(t.Input,{prefix:e.jsx(g.MobileOutlined,{}),placeholder:"注册时的手机号",maxLength:11})}),s===1&&e.jsx(t.Form.Item,{name:"code",label:"验证码",rules:[{required:!0}],children:e.jsx(t.Input,{prefix:e.jsx(g.SafetyOutlined,{}),placeholder:"固定码 123456",maxLength:6})}),s===2&&e.jsxs(e.Fragment,{children:[e.jsx(t.Form.Item,{name:"password",label:"新密码",rules:[{required:!0,min:6}],children:e.jsx(t.Input.Password,{prefix:e.jsx(g.LockOutlined,{}),placeholder:"6 位以上"})}),e.jsx(t.Form.Item,{name:"confirm",label:"确认密码",rules:[{required:!0},({getFieldValue:l})=>({validator(a,i){return!i||l("password")===i?Promise.resolve():Promise.reject(new Error("两次输入不一致"))}})],children:e.jsx(t.Input.Password,{prefix:e.jsx(g.LockOutlined,{}),placeholder:"再输一次"})})]}),e.jsx(t.Form.Item,{children:e.jsx(t.Button,{type:"primary",onClick:o,block:!0,children:s<2?"下一步":"提交"})})]})]})},{Option:Ms}=t.Select,{TextArea:zs}=t.Input,jt=[{type:"STRING",label:"字符串",icon:e.jsx(g.FileTextOutlined,{}),color:"#1677ff",desc:"短文本 (默认 VARCHAR 255)"},{type:"TEXT",label:"长文本",icon:e.jsx(g.FileTextOutlined,{}),color:"#13c2c2",desc:"TEXT 类型, 无长度限制"},{type:"INT",label:"整数",icon:"#",color:"#722ed1",desc:"INT 整数"},{type:"LONG",label:"长整数",icon:"#",color:"#722ed1",desc:"BIGINT 长整数"},{type:"DECIMAL",label:"小数",icon:"0.00",color:"#eb2f96",desc:"DECIMAL 精确小数"},{type:"BOOLEAN",label:"布尔",icon:e.jsx(g.CheckCircleOutlined,{}),color:"#52c41a",desc:"TINYINT(1) 是/否"},{type:"DATE",label:"日期",icon:"📅",color:"#fa8c16",desc:"DATE yyyy-MM-dd"},{type:"DATETIME",label:"日期时间",icon:"🕐",color:"#fa8c16",desc:"DATETIME yyyy-MM-dd HH:mm:ss"},{type:"JSON",label:"JSON",icon:"{}",color:"#2f54eb",desc:"JSON 字符串"},{type:"REF",label:"引用",icon:"🔗",color:"#8c8c8c",desc:"外键引用 BIGINT"}],bt=Object.fromEntries(jt.map(s=>[s.type,s])),zt="application/x-lc-field-type",Ut="application/x-lc-field-idx";function Us(){const[s]=ue.useSearchParams(),[r,n]=p.useState(s.get("appCode")||"demo"),[o,l]=p.useState(s.get("tenant")||localStorage.getItem("z_tenant")||"default"),[a,i]=p.useState([]),[c,x]=p.useState(null),[h,y]=p.useState(!1),[d,b]=p.useState(null),[F,E]=p.useState(!1),[_]=t.Form.useForm(),[C,S]=p.useState(null),[w,T]=p.useState(null),[A,k]=p.useState(null),[R,H]=p.useState([]),[Y,K]=p.useState(null),[m,f]=p.useState(!1),[z,P]=p.useState(!1),D=p.useCallback(async()=>{if(r){y(!0);try{const I=await te.get(`/lc/app/${r}/schema`,{params:{tenantCode:o}});i(Array.isArray(I)?I:[]),x(null)}catch(I){t.message.error("加载 schema 失败: "+((I==null?void 0:I.message)||"未知错误")),i([])}finally{y(!1)}}},[r,o]);p.useEffect(()=>{D()},[D]);const Q=async(I,B,G)=>{var ee;try{const je={tenantCode:o,entityCode:B,eventType:I,eventData:typeof G=="string"?G:JSON.stringify(G),source:"USER",parentEventId:c},ne=await te.post(`/lc/app/${r}/event`,je);t.message.success(`事件 ${I} 已提交 (eventId=${(ee=ne==null?void 0:ne.eventId)==null?void 0:ee.slice(0,8)}…)`),x((ne==null?void 0:ne.eventId)||null),await D()}catch(je){t.message.error("提交事件失败: "+((je==null?void 0:je.message)||"未知错误"))}},oe=()=>{b(null),_.resetFields(),_.setFieldsValue({entityCode:"",entityName:"",tableName:"",description:"",fields:[]}),E(!0)},ge=I=>{b(I),_.setFieldsValue({entityCode:I.entityCode,entityName:I.entityName,tableName:I.tableName||I.entityCode,description:I.description,fields:I.fields||[]}),E(!0)},he=I=>{H((I.fields||[]).map((B,G)=>({...B,sortOrder:B.sortOrder??G}))),K(null),f(!1),P(!0),b(I)},N=I=>{t.Modal.confirm({title:`删除实体 ${I.entityName||I.entityCode}?`,content:"此操作会发出 DELETE 事件, 所有字段一起删除.",okType:"danger",onOk:()=>Q("DELETE",I.entityCode,{entityCode:I.entityCode})})},O=async()=>{try{const I=await _.validateFields(),B=d?"UPDATE":"CREATE",G={entityCode:I.entityCode,entityName:I.entityName,tableName:I.tableName||I.entityCode,description:I.description,fields:(I.fields||[]).map(ee=>({fieldCode:ee.fieldCode,fieldName:ee.fieldName,fieldType:ee.fieldType||"STRING",required:!!ee.required,defaultValue:ee.defaultValue||null,dictCode:ee.dictCode||null,refEntity:ee.refEntity||null,fieldLength:ee.fieldLength||null,scale:ee.scale||null,sortOrder:ee.sortOrder||0}))};E(!1),await Q(B,I.entityCode,G)}catch(I){I!=null&&I.errorFields?t.message.error("请补全必填字段"):t.message.error("提交失败: "+((I==null?void 0:I.message)||"未知错误"))}},j=(I,B)=>{I.dataTransfer.setData(zt,B),I.dataTransfer.setData("text/plain",B),I.dataTransfer.effectAllowed="copy",S(B)},L=()=>{S(null),k(null)},$=(I,B)=>{I.dataTransfer.setData(Ut,String(B)),I.dataTransfer.effectAllowed="move",T(B)},V=()=>{T(null),k(null)},ie=I=>{I.preventDefault(),I.dataTransfer.dropEffect=C?"copy":"move"},X=()=>{k(null)},Z=I=>{I.preventDefault();const B=I.dataTransfer.getData(zt),G=I.dataTransfer.getData(Ut);if(B)Ie(B,R.length);else if(G){const ee=Number(G);Oe(ee,R.length)}k(null),S(null),T(null)},fe=(I,B)=>{I.preventDefault(),I.stopPropagation(),k(B)},Ee=(I,B)=>{I.preventDefault(),I.stopPropagation();const G=I.dataTransfer.getData(zt),ee=I.dataTransfer.getData(Ut);G?Ie(G,B):ee&&Oe(Number(ee),B),k(null),S(null),T(null)},Ie=(I,B)=>{const G=bt[I];if(!G)return;const je={fieldCode:`field_${R.length+1}`,fieldName:`新${G.label}字段`,fieldType:I,required:!1,defaultValue:null,dictCode:null,refEntity:null,fieldLength:I==="STRING"?255:null,scale:I==="DECIMAL"?2:null,sortOrder:B},ne=[...R];ne.splice(B,0,je),ae(ne),H(ne),K(B),f(!0)},Oe=(I,B)=>{if(I===B||I<0||B<0)return;const G=[...R],[ee]=G.splice(I,1),je=B>I?B-1:B;G.splice(je,0,ee),ae(G),H(G),f(!0)},ae=I=>{I.forEach((B,G)=>{B.sortOrder=G})},Je=(I,B)=>{const G=[...R];G[I]={...G[I],...B},H(G),f(!0)},Be=I=>{const B=R.filter((G,ee)=>ee!==I);ae(B),H(B),K(null),f(!0)},ye=I=>{const B=R[I],G={...B,fieldCode:`${B.fieldCode}_copy`,fieldName:`${B.fieldName} (副本)`},ee=[...R];ee.splice(I+1,0,G),ae(ee),H(ee),K(I+1),f(!0)},W=async()=>{if(!d)return;const I={entityCode:d.entityCode,entityName:d.entityName,tableName:d.tableName,description:d.description,fields:R.map(B=>({fieldCode:B.fieldCode,fieldName:B.fieldName,fieldType:B.fieldType||"STRING",required:!!B.required,defaultValue:B.defaultValue||null,dictCode:B.dictCode||null,refEntity:B.refEntity||null,fieldLength:B.fieldLength||null,scale:B.scale||null,sortOrder:B.sortOrder??0}))};await Q("UPDATE",d.entityCode,I),f(!1)},ce=async()=>{if(d)try{const I=await te.post(`/lc/admin/entity/${d.id}/provision?tenant=${o}`);t.message.success(`已建表 (${R.length} 字段)`),console.log("DDL:",I)}catch(I){t.message.error("建表失败: "+((I==null?void 0:I.message)||"未知错误"))}},be=[{title:"编码",dataIndex:"entityCode",key:"entityCode",width:140},{title:"名称",dataIndex:"entityName",key:"entityName",width:140},{title:"物理表",dataIndex:"tableName",key:"tableName",width:160},{title:"字段数",key:"fields",width:80,render:(I,B)=>{var G;return e.jsx(t.Badge,{count:((G=B.fields)==null?void 0:G.length)||0,showZero:!0,color:"blue"})}},{title:"描述",dataIndex:"description",key:"description",ellipsis:!0},{title:"操作",key:"action",width:260,render:(I,B)=>e.jsxs(t.Space,{children:[e.jsx(t.Button,{type:"link",size:"small",icon:e.jsx(g.FormatPainterOutlined,{}),onClick:()=>he(B),children:"画布编辑"}),e.jsx(t.Button,{type:"link",size:"small",icon:e.jsx(g.EditOutlined,{}),onClick:()=>ge(B),children:"表单编辑"}),e.jsx(t.Popconfirm,{title:"确定删除?",onConfirm:()=>N(B),children:e.jsx(t.Button,{type:"link",size:"small",danger:!0,icon:e.jsx(g.DeleteOutlined,{}),children:"删除"})})]})}],we=Y!=null?R[Y]:null;return e.jsxs("div",{children:[e.jsxs(t.Card,{title:e.jsxs(e.Fragment,{children:[e.jsx(g.ThunderboltOutlined,{})," z-lc 模型编辑器 (拖拽版)"]}),extra:e.jsxs(t.Space,{children:[e.jsx(t.Input,{addonBefore:"appCode",value:r,onChange:I=>n(I.target.value.trim()),style:{width:200}}),e.jsx(t.Input,{addonBefore:"tenant",value:o,onChange:I=>l(I.target.value.trim()),style:{width:160}}),e.jsx(t.Button,{icon:e.jsx(g.ReloadOutlined,{}),onClick:D,children:"刷新"}),e.jsx(t.Button,{type:"primary",icon:e.jsx(g.PlusOutlined,{}),onClick:oe,children:"新建实体"})]}),children:[e.jsx(t.Alert,{type:"info",showIcon:!0,message:"提示: 点击实体的「画布编辑」进入拖拽式建模: 从左侧面板拖字段类型到中间, 拖拽字段行可重排, 右侧编辑属性。",style:{marginBottom:16}}),e.jsx(t.Spin,{spinning:h,children:a.length===0?e.jsx(t.Empty,{description:"暂无实体, 点击右上角 「新建实体」 开始"}):e.jsx(t.Table,{rowKey:"entityCode",columns:be,dataSource:a,pagination:!1,size:"small",expandable:{expandedRowRender:I=>e.jsx(Jo,{entity:I})}})})]}),e.jsx(t.Modal,{title:d?`编辑实体 ${d.entityCode}`:"新建实体",open:F,onCancel:()=>E(!1),onOk:O,width:760,destroyOnClose:!0,children:e.jsx(Vo,{form:_,editing:d})}),e.jsx(t.Drawer,{title:e.jsxs(t.Space,{children:[e.jsx(g.FormatPainterOutlined,{}),d?`画布编辑 - ${d.entityName||d.entityCode}`:"画布编辑",m&&e.jsx(t.Tag,{color:"orange",children:"未保存"})]}),open:z,onClose:()=>{m?t.Modal.confirm({title:"有未保存的修改, 确定关闭?",onOk:()=>{P(!1),f(!1)}}):P(!1)},width:"85%",destroyOnClose:!0,extra:e.jsxs(t.Space,{children:[e.jsx(t.Button,{onClick:ce,icon:e.jsx(g.DatabaseOutlined,{}),children:"自动建表"}),e.jsx(t.Button,{type:"primary",icon:e.jsx(g.ThunderboltOutlined,{}),disabled:!m,onClick:W,children:"提交 (UPDATE 事件)"})]}),children:e.jsxs(t.Row,{gutter:16,style:{height:"calc(100vh - 200px)"},children:[e.jsx(t.Col,{span:5,children:e.jsxs(t.Card,{size:"small",title:e.jsxs(e.Fragment,{children:[e.jsx(g.HolderOutlined,{})," 字段类型面板"]}),style:{height:"100%"},bodyStyle:{padding:12,overflowY:"auto",height:"calc(100% - 40px)"},children:[e.jsx("div",{style:{fontSize:12,color:"#999",marginBottom:8},children:"拖拽字段类型到右侧"}),jt.map(I=>e.jsxs("div",{draggable:!0,onDragStart:B=>j(B,I.type),onDragEnd:L,style:{padding:"8px 12px",marginBottom:8,background:C===I.type?"#e6f4ff":"#fafafa",border:`1px dashed ${I.color}`,borderRadius:6,cursor:"grab",opacity:C===I.type?.5:1,transition:"all 0.2s"},children:[e.jsxs(t.Space,{children:[e.jsx("span",{style:{display:"inline-block",width:22,height:22,borderRadius:4,background:I.color,color:"#fff",textAlign:"center",lineHeight:"22px",fontSize:11,fontWeight:"bold"},children:I.type.slice(0,2)}),e.jsx("span",{style:{fontWeight:500},children:I.label})]}),e.jsx("div",{style:{fontSize:11,color:"#888",marginTop:4},children:I.desc})]},I.type))]})}),e.jsx(t.Col,{span:12,children:e.jsx(t.Card,{size:"small",title:e.jsxs(t.Space,{children:[e.jsx(g.DatabaseOutlined,{}),"字段列表 (",R.length,")"]}),style:{height:"100%"},bodyStyle:{padding:8,overflowY:"auto",height:"calc(100% - 40px)"},children:e.jsx("div",{onDragOver:ie,onDragLeave:X,onDrop:Z,style:{minHeight:"100%",padding:4,border:"2px dashed transparent",borderRadius:6},children:R.length===0?e.jsx(t.Empty,{description:"从左侧拖拽字段类型到这里",style:{marginTop:80}}):e.jsxs(e.Fragment,{children:[R.map((I,B)=>{const G=bt[I.fieldType]||bt.STRING,ee=Y===B,je=w===B;return e.jsxs(p.Fragment,{children:[A===B&&e.jsx("div",{style:{height:4,background:"#1677ff",borderRadius:2,margin:"4px 0"}}),e.jsx("div",{draggable:!0,onDragStart:ne=>$(ne,B),onDragEnd:V,onDragOver:ne=>fe(ne,B),onDrop:ne=>Ee(ne,B),onClick:()=>K(B),style:{padding:"10px 12px",marginBottom:6,background:ee?"#e6f4ff":"#fff",border:`1px solid ${ee?"#1677ff":"#d9d9d9"}`,borderRadius:6,cursor:"grab",opacity:je?.4:1,transition:"all 0.15s"},children:e.jsxs(t.Space,{style:{width:"100%",justifyContent:"space-between"},children:[e.jsxs(t.Space,{children:[e.jsx(g.HolderOutlined,{style:{color:"#999"}}),e.jsx("span",{style:{display:"inline-block",width:20,height:20,borderRadius:3,background:G.color,color:"#fff",textAlign:"center",lineHeight:"20px",fontSize:10},children:I.fieldType.slice(0,2)}),e.jsx("span",{style:{fontFamily:"monospace",fontWeight:500},children:I.fieldCode}),e.jsx("span",{children:I.fieldName}),I.required&&e.jsx(t.Tag,{color:"red",style:{margin:0},children:"必填"}),I.dictCode&&e.jsxs(t.Tag,{color:"blue",style:{margin:0},children:["dict:",I.dictCode]}),I.refEntity&&e.jsxs(t.Tag,{color:"purple",style:{margin:0},children:["ref:",I.refEntity]})]}),e.jsxs(t.Space,{size:4,onClick:ne=>ne.stopPropagation(),children:[e.jsx(t.Tooltip,{title:"复制",children:e.jsx(t.Button,{type:"text",size:"small",icon:e.jsx(g.CopyOutlined,{}),onClick:()=>ye(B)})}),e.jsx(t.Tooltip,{title:"删除",children:e.jsx(t.Button,{type:"text",size:"small",danger:!0,icon:e.jsx(g.DeleteOutlined,{}),onClick:()=>Be(B)})})]})]})})]},`${I.fieldCode}-${B}`)}),A===R.length&&e.jsx("div",{style:{height:4,background:"#1677ff",borderRadius:2,margin:"4px 0"}})]})})})}),e.jsx(t.Col,{span:7,children:e.jsx(t.Card,{size:"small",title:e.jsxs(e.Fragment,{children:[e.jsx(g.CodeOutlined,{})," 字段属性"]}),style:{height:"100%"},bodyStyle:{padding:12,overflowY:"auto",height:"calc(100% - 40px)"},children:we?e.jsx(Ko,{field:we,onChange:I=>Je(Y,I)}):e.jsx(t.Empty,{description:"点击中间列表中的字段以编辑属性",style:{marginTop:80}})})})]})})]})}function Jo({entity:s}){const r=s.fields||[];return r.length===0?e.jsx("span",{style:{color:"#999"},children:"无字段"}):e.jsx(t.Space,{wrap:!0,size:[4,4],children:r.map(n=>e.jsxs(t.Tag,{color:(bt[n.fieldType]||{}).color||"default",children:[n.fieldCode," : ",n.fieldType,n.required?" *":""]},n.fieldCode))})}function Vo({form:s,editing:r}){return e.jsxs(t.Form,{form:s,layout:"vertical",children:[e.jsxs(t.Space,{style:{width:"100%"},size:"middle",children:[e.jsx(t.Form.Item,{name:"entityCode",label:"实体编码",rules:[{required:!0,pattern:/^[A-Za-z][A-Za-z0-9_]*$/,message:"字母数字下划线"}],children:e.jsx(t.Input,{disabled:!!r,placeholder:"如 user"})}),e.jsx(t.Form.Item,{name:"entityName",label:"实体名称",children:e.jsx(t.Input,{placeholder:"如 用户"})}),e.jsx(t.Form.Item,{name:"tableName",label:"物理表名",rules:[{required:!0,pattern:/^[A-Za-z][A-Za-z0-9_]*$/,message:"字母数字下划线"}],children:e.jsx(t.Input,{placeholder:"默认 = entityCode"})})]}),e.jsx(t.Form.Item,{name:"description",label:"描述",children:e.jsx(zs,{rows:2})}),e.jsx(t.Form.List,{name:"fields",children:(n,{add:o,remove:l})=>e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{marginBottom:8},children:e.jsx(t.Button,{type:"dashed",onClick:()=>o({fieldType:"STRING",required:!1}),icon:e.jsx(g.PlusOutlined,{}),children:"添加字段"})}),e.jsx(t.Table,{rowKey:a=>a.fieldCode||Math.random(),columns:[{title:"编码",dataIndex:"fieldCode",render:(a,i,c)=>e.jsx(t.Form.Item,{name:[c,"fieldCode"],noStyle:!0,rules:[{required:!0,pattern:/^[A-Za-z][A-Za-z0-9_]*$/,message:"字母数字下划线"}],children:e.jsx(t.Input,{size:"small",placeholder:"userName"})})},{title:"名称",dataIndex:"fieldName",render:(a,i,c)=>e.jsx(t.Form.Item,{name:[c,"fieldName"],noStyle:!0,children:e.jsx(t.Input,{size:"small",placeholder:"用户名"})})},{title:"类型",dataIndex:"fieldType",width:120,render:(a,i,c)=>e.jsx(t.Form.Item,{name:[c,"fieldType"],noStyle:!0,children:e.jsx(t.Select,{size:"small",children:jt.map(x=>e.jsx(Ms,{value:x.type,children:x.type},x.type))})})},{title:"必填",dataIndex:"required",width:60,render:(a,i,c)=>e.jsx(t.Form.Item,{name:[c,"required"],noStyle:!0,valuePropName:"checked",children:e.jsx(t.Switch,{size:"small"})})},{title:"字典",dataIndex:"dictCode",width:110,render:(a,i,c)=>e.jsx(t.Form.Item,{name:[c,"dictCode"],noStyle:!0,children:e.jsx(t.Input,{size:"small",placeholder:"可选"})})},{title:"引用",dataIndex:"refEntity",width:110,render:(a,i,c)=>e.jsx(t.Form.Item,{name:[c,"refEntity"],noStyle:!0,children:e.jsx(t.Input,{size:"small",placeholder:"可选"})})},{title:"操作",width:60,render:(a,i,c)=>e.jsx(t.Button,{size:"small",danger:!0,type:"link",onClick:()=>l(c),children:"移除"})}],dataSource:n,pagination:!1,size:"small"})]})})]})}function Ko({field:s,onChange:r}){return e.jsx("div",{children:e.jsxs(t.Form,{layout:"vertical",size:"small",children:[e.jsx(t.Form.Item,{label:"字段编码 (物理列名)",required:!0,children:e.jsx(t.Input,{value:s.fieldCode||"",onChange:n=>r({fieldCode:n.target.value}),placeholder:"如 userName"})}),e.jsx(t.Form.Item,{label:"显示名称",children:e.jsx(t.Input,{value:s.fieldName||"",onChange:n=>r({fieldName:n.target.value}),placeholder:"如 用户名"})}),e.jsx(t.Form.Item,{label:"字段类型",children:e.jsx(t.Select,{value:s.fieldType||"STRING",onChange:n=>r({fieldType:n}),style:{width:"100%"},children:jt.map(n=>e.jsxs(Ms,{value:n.type,children:[n.label," (",n.type,")"]},n.type))})}),e.jsx(t.Form.Item,{label:"必填",children:e.jsx(t.Switch,{checked:!!s.required,onChange:n=>r({required:n})})}),(s.fieldType==="STRING"||s.fieldType==="TEXT")&&e.jsx(t.Form.Item,{label:"字段长度",children:e.jsx(t.InputNumber,{value:s.fieldLength,onChange:n=>r({fieldLength:n}),min:1,max:65535,style:{width:"100%"}})}),s.fieldType==="DECIMAL"&&e.jsx(t.Form.Item,{label:"小数位数",children:e.jsx(t.InputNumber,{value:s.scale,onChange:n=>r({scale:n}),min:0,max:10,style:{width:"100%"}})}),e.jsx(t.Form.Item,{label:"默认值",children:e.jsx(t.Input,{value:s.defaultValue||"",onChange:n=>r({defaultValue:n.target.value}),placeholder:"可选"})}),e.jsx(t.Form.Item,{label:"字典编码 (dictCode)",children:e.jsx(t.Input,{value:s.dictCode||"",onChange:n=>r({dictCode:n.target.value}),placeholder:"如 user_status"})}),e.jsx(t.Form.Item,{label:"引用实体 (refEntity)",children:e.jsx(t.Input,{value:s.refEntity||"",onChange:n=>r({refEntity:n.target.value}),placeholder:"如 其他 entity 的 entityCode"})}),e.jsx(t.Form.Item,{label:"排序号",children:e.jsx(t.InputNumber,{value:s.sortOrder??0,onChange:n=>r({sortOrder:n}),style:{width:"100%"}})}),e.jsx(t.Form.Item,{label:"备注",children:e.jsx(zs,{rows:2,value:s.description||"",onChange:n=>r({description:n.target.value})})})]})})}const{Option:Xo}=t.Select,$s={STRING:{component:t.Input,props:{}},TEXT:{component:t.Input.TextArea,props:{rows:3}},INT:{component:t.InputNumber,props:{}},LONG:{component:t.InputNumber,props:{}},DECIMAL:{component:t.InputNumber,props:{step:.01}},BOOLEAN:{component:t.Switch,props:{}},DATE:{component:t.DatePicker,props:{format:"YYYY-MM-DD"}},DATETIME:{component:t.DatePicker,props:{format:"YYYY-MM-DD HH:mm:ss",showTime:!0}},JSON:{component:t.Input.TextArea,props:{rows:3,placeholder:"JSON 字符串"}},REF:{component:t.InputNumber,props:{}}};function qs(){const{entity:s}=ue.useParams(),[r]=ue.useSearchParams(),n=r.get("appCode")||"demo",o=r.get("tenant")||localStorage.getItem("z_tenant")||"default",[l,a]=p.useState([]),[i,c]=p.useState(null),[x,h]=p.useState([]),[y,d]=p.useState(0),[b,F]=p.useState(1),[E,_]=p.useState(10),[C,S]=p.useState(!1),[w,T]=p.useState(!1),[A,k]=p.useState(null),[R]=t.Form.useForm(),[H,Y]=p.useState({}),K=p.useCallback(async()=>{try{const O=await te.get(`/lc/app/${n}/schema`,{params:{tenantCode:o}});a(Array.isArray(O)?O:[]);const j=(O||[]).find(L=>L.entityCode===s);c(j||null)}catch(O){t.message.error("加载 schema 失败: "+((O==null?void 0:O.message)||"未知错误")),a([]),c(null)}},[n,o,s]),m=p.useCallback(async O=>{if(!O||H[O])return H[O]||[];try{const j=await te.get("/dict/items/get",{params:{dictCode:O}}),$=(Array.isArray(j)?j:[]).map(V=>({value:V.itemValue??V.itemCode,label:V.itemName??V.itemLabel??V.itemCode}));return Y(V=>({...V,[O]:$})),$}catch{return[]}},[H]),f=p.useCallback(async()=>{if(i){S(!0);try{const O=await te.post(`/lc/runtime/${i.entityCode}/list`,{tenantCode:o,appCode:n,entityCode:i.entityCode,page:b,size:E});h((O==null?void 0:O.records)||[]),d((O==null?void 0:O.total)||0)}catch(O){t.message.error("查询失败: "+((O==null?void 0:O.message)||"未知错误")),h([]),d(0)}finally{S(!1)}}},[i,o,n,b,E]);if(p.useEffect(()=>{K()},[K]),p.useEffect(()=>{f()},[f]),p.useEffect(()=>{!i||!i.fields||i.fields.forEach(O=>{O.dictCode&&m(O.dictCode)})},[i,m]),!s)return e.jsx(t.Empty,{description:"缺少实体编码 (路径变量 :entity)"});if(!i)return e.jsx(t.Card,{title:e.jsxs(e.Fragment,{children:[e.jsx(g.DatabaseOutlined,{})," z-lc 运行时"]}),children:e.jsx(t.Alert,{type:"warning",showIcon:!0,message:`实体 ${s} 未定义`,description:`请先在 模型编辑器 (路径 /form/_model?appCode=${n}) 中定义实体, 然后刷新此页.`})});const z=i.fields||[],P=()=>{k(null),R.resetFields(),T(!0)},D=async O=>{k(O);try{const j=await te.post(`/lc/runtime/${i.entityCode}/get`,{tenantCode:o,appCode:n,entityCode:i.entityCode,id:O.id});R.resetFields(),R.setFieldsValue(j||O)}catch{R.resetFields(),R.setFieldsValue(O)}T(!0)},Q=O=>{t.Modal.confirm({title:"确定删除?",content:`id=${O.id}`,okType:"danger",onOk:async()=>{try{await te.post(`/lc/runtime/${i.entityCode}/delete`,{tenantCode:o,appCode:n,entityCode:i.entityCode,id:O.id}),t.message.success("删除成功"),f()}catch(j){t.message.error("删除失败: "+((j==null?void 0:j.message)||"未知错误"))}}})},oe=async()=>{try{const O=await R.validateFields(),j={tenantCode:o,appCode:n,entityCode:i.entityCode,fieldValues:{...O}};A?(j.fieldValues.id=A.id,await te.post(`/lc/runtime/${i.entityCode}/update`,j),t.message.success("更新成功")):(await te.post(`/lc/runtime/${i.entityCode}/create`,j),t.message.success("创建成功")),T(!1),f()}catch(O){O!=null&&O.errorFields?t.message.error("请补全必填字段"):t.message.error("提交失败: "+((O==null?void 0:O.message)||"未知错误"))}},ge=(O,j)=>{const L=j[O.fieldCode],$=O.fieldCode+"_label";if(j[$]!=null)return e.jsx(t.Tag,{children:j[$]});if(L==null)return"-";if(O.fieldType==="BOOLEAN")return L?"是":"否";if(O.fieldType==="DATETIME"||O.fieldType==="DATE")try{return new Date(L).toLocaleString()}catch{return String(L)}return String(L)},he=[{title:"ID",dataIndex:"id",key:"id",width:80},...z.map(O=>({title:O.fieldName||O.fieldCode,dataIndex:O.fieldCode,key:O.fieldCode,render:(j,L)=>ge(O,L)})),{title:"操作",key:"action",width:180,fixed:"right",render:(O,j)=>e.jsxs(t.Space,{children:[e.jsx(t.Button,{type:"link",icon:e.jsx(g.EditOutlined,{}),onClick:()=>D(j),children:"编辑"}),e.jsx(t.Button,{type:"link",danger:!0,icon:e.jsx(g.DeleteOutlined,{}),onClick:()=>Q(j),children:"删除"})]})}],N=O=>{const j=(O.fieldType||"STRING").toUpperCase();if(O.dictCode){const V=H[O.dictCode]||[];return e.jsx(t.Select,{placeholder:`选择 ${O.fieldName||O.fieldCode}`,allowClear:!0,showSearch:!0,optionFilterProp:"label",children:V.map(ie=>e.jsx(Xo,{value:ie.value,label:ie.label,children:ie.label},ie.value))})}const L=$s[j]||$s.STRING,$=L.component;return e.jsx($,{...L.props,placeholder:O.fieldName||O.fieldCode})};return e.jsxs(t.Card,{title:e.jsxs(e.Fragment,{children:[e.jsx(g.DatabaseOutlined,{})," ",i.entityName||i.entityCode," (运行时 CRUD)"]}),extra:e.jsxs(t.Space,{children:[e.jsx(t.Button,{icon:e.jsx(g.ReloadOutlined,{}),onClick:f,children:"刷新"}),e.jsx(t.Button,{type:"primary",icon:e.jsx(g.PlusOutlined,{}),onClick:P,children:"新增"})]}),children:[e.jsx(t.Alert,{type:"info",showIcon:!0,message:`App=${n} · Tenant=${o} · 字段数=${z.length}`,style:{marginBottom:16}}),e.jsx(t.Spin,{spinning:C,children:e.jsx(t.Table,{rowKey:"id",columns:he,dataSource:x,pagination:{current:b,pageSize:E,total:y,showSizeChanger:!0,showTotal:O=>`共 ${O} 条`,onChange:(O,j)=>{F(O),_(j)}},scroll:{x:"max-content"},size:"small"})}),e.jsx(t.Modal,{title:A?`编辑 #${A.id}`:"新增记录",open:w,onCancel:()=>T(!1),onOk:oe,width:680,destroyOnClose:!0,children:e.jsx(t.Form,{form:R,layout:"vertical",children:z.map(O=>e.jsx(t.Form.Item,{name:O.fieldCode,label:e.jsxs("span",{children:[O.fieldName||O.fieldCode,O.required&&e.jsx("span",{style:{color:"red"},children:" *"}),e.jsx(t.Tag,{style:{marginLeft:8},children:O.fieldType})]}),rules:O.required?[{required:!0,message:"必填"}]:[],children:N(O)},O.fieldCode))})})]})}const Yo=()=>{const{entity:s}=ue.useParams();return s?s==="_model"?e.jsx(Us,{}):e.jsx(qs,{}):e.jsxs("div",{style:{padding:24},children:["缺少实体编码. 请访问 ",e.jsx("code",{children:"/form/_model"})," 编辑模型, 或 ",e.jsx("code",{children:"/form/{entityCode}"})," 运行时 CRUD."]})},{Text:rt,Paragraph:li}=t.Typography,{TextArea:Zo}=t.Input,Hs={PENDING:"default",GENERATING:"processing",READY:"success",FAILED:"error"},Ws={Entity:"blue",Mapper:"cyan",Service:"green",ServiceImpl:"lime",Controller:"orange",ReactPage:"purple",File:"default"};function Qo(){const r=new URLSearchParams(window.location.search).get("appCode")||"demo",[n]=p.useState(r),[o,l]=p.useState([]),[a,i]=p.useState(!1),[c,x]=p.useState(!1),[h,y]=p.useState(!1),[d,b]=p.useState([]),[F,E]=p.useState(null),[_,C]=p.useState([]),[S]=t.Form.useForm();p.useEffect(()=>{w(),T()},[n]);const w=async()=>{i(!0);try{const m=await te.get(`/lc/app/${n}/materialize/list`,{params:{limit:50}});l((m==null?void 0:m.data)||[])}catch{t.message.warning("加载批次列表失败")}finally{i(!1)}},T=async()=>{var m;try{const f=await te.get(`/lc/app/${n}/schema`),z=((m=f==null?void 0:f.data)==null?void 0:m.entities)||(f==null?void 0:f.data)||[];C(z)}catch{}},A=async()=>{var m;try{const f=await S.validateFields(),z={appCode:n,materializationPath:f.materializationPath,entityCodes:(m=f.entityCodes)!=null&&m.length?f.entityCodes:null,description:f.description,triggerSource:"USER"};await te.post(`/lc/app/${n}/materialize`,z),t.message.success("物化已触发,请稍后查看状态"),x(!1),S.resetFields(),w()}catch(f){f!=null&&f.errorFields||t.message.error("触发失败:"+((f==null?void 0:f.message)||"未知错误"))}},k=async m=>{try{const f=await te.get(`/lc/app/${n}/materialize/diff`,{params:{id:m.id}}),z=(f==null?void 0:f.data)||[];b(z),y(!0),E(null)}catch{t.message.error("加载文件清单失败")}},R=m=>{var f;try{(f=navigator.clipboard)==null||f.writeText(m),t.message.success("已复制到剪贴板")}catch{t.message.warning("复制失败")}},H=m=>{const f=new Blob([m.content],{type:"text/plain;charset=utf-8"}),z=URL.createObjectURL(f),P=document.createElement("a");P.href=z,P.download=m.relativePath.split("/").pop(),P.click(),URL.revokeObjectURL(z)},Y=[{title:"批次号",dataIndex:"exportVersion",width:180,render:m=>e.jsx(rt,{code:!0,children:m})},{title:"状态",dataIndex:"status",width:100,render:m=>e.jsx(t.Badge,{status:Hs[m]==="success"?"success":Hs[m]==="error"?"error":"processing",text:m})},{title:"文件数",dataIndex:"fileCount",width:80,align:"center",render:m=>m||0},{title:"来源",dataIndex:"triggerSource",width:80,render:m=>e.jsx(t.Tag,{children:m})},{title:"路径",dataIndex:"materializationPath",ellipsis:!0,render:m=>e.jsx(rt,{type:"secondary",style:{fontSize:12},children:m})},{title:"创建时间",dataIndex:"createTime",width:170},{title:"操作",key:"action",width:200,fixed:"right",render:(m,f)=>e.jsx(t.Space,{size:"small",children:e.jsx(t.Button,{size:"small",type:"link",icon:e.jsx(g.FileTextOutlined,{}),onClick:()=>k(f),disabled:f.status!=="READY"&&f.status!=="GENERATING",children:"查看文件"})})}],K=[{title:"类型",dataIndex:"type",width:100,render:m=>e.jsx(t.Tag,{color:Ws[m]||"default",children:m})},{title:"Entity",dataIndex:"entityCode",width:120,render:m=>m?e.jsx(rt,{code:!0,children:m}):"-"},{title:"相对路径",dataIndex:"relativePath",ellipsis:!0,render:m=>e.jsx(rt,{code:!0,style:{fontSize:12},children:m})},{title:"大小",dataIndex:"sizeBytes",width:90,render:m=>`${(m/1024).toFixed(1)}KB`},{title:"操作",key:"action",width:200,fixed:"right",render:(m,f)=>e.jsxs(t.Space,{size:"small",children:[e.jsx(t.Button,{size:"small",type:"link",onClick:()=>E(f),children:"预览"}),e.jsx(t.Button,{size:"small",type:"link",icon:e.jsx(g.CopyOutlined,{}),onClick:()=>R(f.content),children:"复制"}),e.jsx(t.Button,{size:"small",type:"link",icon:e.jsx(g.DownloadOutlined,{}),onClick:()=>H(f),children:"下载"})]})}];return e.jsxs("div",{style:{padding:16},children:[e.jsxs(t.Card,{children:[e.jsx(t.Alert,{type:"info",showIcon:!0,icon:e.jsx(g.CodeOutlined,{}),style:{marginBottom:16},message:`z-lc 代码物化 (FEATURE006 T1) — App: ${n}`,description:"将低代码定义的 entity/field 渲染为可编译的 Java (Entity/Mapper/Service/Controller) + React 页面代码。导出是异步的, 完成后可在此查看文件清单。"}),e.jsxs(t.Space,{style:{marginBottom:16},children:[e.jsx(t.Button,{icon:e.jsx(g.ReloadOutlined,{}),onClick:w,children:"刷新"}),e.jsx(t.Button,{type:"primary",icon:e.jsx(g.ExportOutlined,{}),onClick:()=>x(!0),children:"导出代码"}),e.jsx(t.Button,{icon:e.jsx(g.HistoryOutlined,{}),onClick:()=>t.message.info(`共 ${o.length} 个历史批次`),children:"历史"})]}),e.jsx(t.Table,{dataSource:o,columns:Y,rowKey:"id",loading:a,pagination:{pageSize:10},size:"small",scroll:{x:1e3}})]}),e.jsx(t.Modal,{title:"触发代码物化",open:c,onCancel:()=>x(!1),onOk:A,okText:"开始导出",width:600,children:e.jsxs(t.Form,{form:S,layout:"vertical",style:{marginTop:16},initialValues:{materializationPath:`app-${n}/v1`},children:[e.jsx(t.Form.Item,{name:"materializationPath",label:"导出根路径 (相对沙箱默认根)",rules:[{required:!0,message:"请输入路径"}],extra:"默认根: ${user.home}/z-lc-materialized. 如需写入绝对路径, 服务端需配置 z-lc.materialize.allow-absolute-path=true",children:e.jsx(t.Input,{placeholder:`app-${n}/v1`})}),e.jsx(t.Form.Item,{name:"entityCodes",label:"导出的 entity (留空 = 全量)",children:e.jsx(t.Select,{mode:"multiple",placeholder:"选择 entity",allowClear:!0,options:_.map(m=>({value:m.entityCode,label:`${m.entityCode} (${m.tableName})`}))})}),e.jsx(t.Form.Item,{name:"description",label:"备注",children:e.jsx(Zo,{rows:2,placeholder:"本次导出的业务说明"})})]})}),e.jsx(t.Modal,{title:`物化文件清单 (${d.length} 个)`,open:h,onCancel:()=>{y(!1),E(null)},footer:e.jsx(t.Button,{onClick:()=>{y(!1),E(null)},children:"关闭"}),width:F?1100:800,children:F?e.jsxs("div",{children:[e.jsxs(t.Space,{style:{marginBottom:8},children:[e.jsx(t.Button,{onClick:()=>E(null),children:"← 返回清单"}),e.jsx(rt,{strong:!0,children:F.relativePath}),e.jsx(t.Tag,{color:Ws[F.type]||"default",children:F.type}),e.jsx(t.Button,{size:"small",icon:e.jsx(g.CopyOutlined,{}),onClick:()=>R(F.content),children:"复制"}),e.jsx(t.Button,{size:"small",icon:e.jsx(g.DownloadOutlined,{}),onClick:()=>H(F),children:"下载"})]}),e.jsx("pre",{style:{background:"#1e1e1e",color:"#d4d4d4",padding:16,borderRadius:8,maxHeight:500,overflow:"auto",fontSize:12,fontFamily:"Menlo, Monaco, monospace"},children:F.content})]}):e.jsx(t.Table,{dataSource:d,columns:K,rowKey:"relativePath",pagination:{pageSize:20},size:"small",scroll:{x:700}})})]})}const{TextArea:Gs}=t.Input;function Js({open:s,onClose:r,onSuccess:n,envOptions:o=[]}){const[l,a]=p.useState("paste"),[i,c]=p.useState(""),[x,h]=p.useState(null),[y,d]=p.useState(null),[b,F]=p.useState(!1),[E,_]=p.useState([]),[C,S]=p.useState(!1),[w]=t.Form.useForm(),T=p.useRef(null),A=()=>{c(""),h(null),d(null),_([]),w.resetFields()},k=()=>{A(),r()},R=async()=>{if(!i.trim()){t.message.warning("请先粘贴或上传 API 规约");return}d(null),F(!0);try{const f=await J.openapi.parse(i);f.success?(h(f),_((f.endpoints||[]).map((z,P)=>P)),w.setFieldsValue({envCode:o[0]||"default",projectCode:"default",defaultResponse:`{
25
33
  "code": 0,
26
34
  "message": "ok",
27
35
  "data": {}
28
- }`,defaultStatus:200,priority:5,tagPrefix:"openapi-import"}),s.message.success(`识别为 ${n.format},共 ${n.count} 个端点`)):m(n.message||"解析失败")}catch(n){m(String((n==null?void 0:n.message)||n))}finally{z(!1)}},U=async n=>{try{const L=await q.openapi.sample(n);L.success&&(g(L.content),s.message.success(`已加载 ${L.format} 示例`))}catch(L){s.message.error("加载示例失败: "+L.message)}},J=n=>{const L=new FileReader;return L.onload=b=>{var A;g(String(((A=b.target)==null?void 0:A.result)||"")),s.message.success(`已读取 ${n.name}(${(n.size/1024).toFixed(1)}KB)`)},L.onerror=()=>s.message.error("文件读取失败"),L.readAsText(n),!1},H=async()=>{if(!v){s.message.warning("请先解析");return}let n;try{n=await T.validateFields()}catch{return}N(!0);try{const L=(v.endpoints||[]).map((A,V)=>({method:A.method,path:A.path})).filter((A,V)=>y.includes(V)),b=await q.openapi.importBatch({content:d,selected:L,envCode:n.envCode,projectCode:n.projectCode,defaultResponse:n.defaultResponse,defaultStatus:n.defaultStatus,priority:n.priority,tagPrefix:n.tagPrefix});b.success?(s.message.success(`已导入 ${b.imported} 个 Mock 端点${b.failed>0?`,失败 ${b.failed}`:""}`),l&&l(b),S()):s.message.error(b.message||"导入失败")}catch(L){s.message.error(String((L==null?void 0:L.message)||L))}finally{N(!1)}},o=[{title:"Method",dataIndex:"method",width:90,render:n=>e.jsx(s.Tag,{color:It(n),children:n})},{title:"Path",dataIndex:"path",width:240,ellipsis:!0},{title:"Summary",dataIndex:"summary",ellipsis:!0},{title:"Tags",dataIndex:"tags",width:160,render:n=>(n||[]).map(L=>e.jsx(s.Tag,{children:L},L))},{title:"Params",dataIndex:"parameters",width:80,render:n=>(n==null?void 0:n.length)||0,align:"center"},{title:"示例",dataIndex:"responseExample",width:80,render:n=>n?e.jsx(s.Tag,{color:"green",children:"有"}):e.jsx(s.Tag,{children:"无"})}];return e.jsxs(s.Modal,{title:e.jsxs(s.Space,{children:[e.jsx(i.CloudUploadOutlined,{})," 批量导入 API 规约"]}),open:t,onCancel:S,footer:null,width:1100,destroyOnClose:!0,children:[e.jsx(s.Tabs,{activeKey:I,onChange:C,items:[{key:"paste",label:e.jsxs("span",{children:[e.jsx(i.FileTextOutlined,{})," 粘贴 JSON"]}),children:e.jsxs("div",{children:[e.jsx(ms,{value:d,onChange:n=>g(n.target.value),placeholder:"粘贴 OpenAPI 3.x / Swagger 2.0 / Postman v2.1 JSON 内容…",autoSize:{minRows:6,maxRows:16},style:{fontFamily:"Menlo, Monaco, monospace",fontSize:12}}),e.jsxs(s.Space,{style:{marginTop:8},children:[e.jsx(s.Button,{size:"small",onClick:()=>U("openapi3"),children:"加载 OpenAPI 3 示例"}),e.jsx(s.Button,{size:"small",onClick:()=>U("swagger2"),children:"加载 Swagger 2 示例"}),e.jsx(s.Button,{size:"small",onClick:()=>U("postman"),children:"加载 Postman 示例"})]})]})},{key:"upload",label:e.jsxs("span",{children:[e.jsx(i.FileAddOutlined,{})," 上传文件"]}),children:e.jsxs(s.Upload.Dragger,{ref:w,accept:".json,.yaml,.yml,application/json,text/yaml",beforeUpload:J,showUploadList:!1,style:{padding:24},children:[e.jsx("p",{className:"ant-upload-drag-icon",children:e.jsx(i.CloudUploadOutlined,{style:{fontSize:48,color:"#1890ff"}})}),e.jsx("p",{className:"ant-upload-text",children:"点击或拖拽 JSON / YAML 文件到此处"}),e.jsx("p",{className:"ant-upload-hint",children:"支持 OpenAPI 3.x / Swagger 2.0 / Postman v2.1"})]})}]}),e.jsxs(s.Space,{style:{marginTop:12},children:[e.jsx(s.Button,{type:"primary",icon:e.jsx(i.ThunderboltOutlined,{}),onClick:M,loading:h,children:"解析"}),v&&e.jsx(s.Tag,{color:"blue",children:v.format}),v&&e.jsxs(s.Tag,{children:["共 ",v.count," 个端点,已选 ",y.length]})]}),O&&e.jsx(s.Alert,{type:"error",showIcon:!0,style:{marginTop:12},message:"解析失败",description:O}),v&&e.jsx(s.Card,{size:"small",style:{marginTop:16},title:"预览(可勾选要导入的)",children:e.jsx(s.Table,{size:"small",dataSource:v.endpoints||[],columns:o,rowKey:(n,L)=>L,rowSelection:{selectedRowKeys:y,onChange:$},pagination:{pageSize:8},scroll:{y:280}})}),v&&e.jsx(s.Card,{size:"small",style:{marginTop:16},title:"导入配置",children:e.jsxs(s.Form,{form:T,layout:"vertical",children:[e.jsxs(s.Row,{gutter:16,children:[e.jsx(s.Col,{span:6,children:e.jsx(s.Form.Item,{name:"envCode",label:"环境",rules:[{required:!0}],children:j.length>0?e.jsx(s.Select,{options:j.map(n=>({value:n,label:n}))}):e.jsx(s.Input,{})})}),e.jsx(s.Col,{span:6,children:e.jsx(s.Form.Item,{name:"projectCode",label:"项目",children:e.jsx(s.Input,{})})}),e.jsx(s.Col,{span:4,children:e.jsx(s.Form.Item,{name:"defaultStatus",label:"默认状态码",children:e.jsx(s.Input,{type:"number"})})}),e.jsx(s.Col,{span:4,children:e.jsx(s.Form.Item,{name:"priority",label:"优先级",children:e.jsx(s.Input,{type:"number"})})}),e.jsx(s.Col,{span:4,children:e.jsx(s.Form.Item,{name:"tagPrefix",label:"Tag 前缀",children:e.jsx(s.Input,{})})})]}),e.jsx(s.Form.Item,{name:"defaultResponse",label:"默认响应(无 example 时使用)",children:e.jsx(ms,{autoSize:{minRows:3,maxRows:6},style:{fontFamily:"Menlo, Monaco, monospace"}})}),e.jsxs(s.Button,{type:"primary",size:"large",icon:e.jsx(i.ImportOutlined,{}),onClick:H,loading:E,disabled:y.length===0,children:["批量导入 ",y.length," 个端点"]})]})})]})}function It(t){return{GET:"blue",POST:"green",PUT:"orange",DELETE:"red",PATCH:"purple"}[t]||"default"}const{Text:Ee,Paragraph:cr}=s.Typography,hs=[{group:"基础数据",icon:e.jsx(i.CodeOutlined,{}),items:[{syntax:"@uuid",desc:"随机 UUID",example:"a3f2e1b7-8c4d-4e6f-9a1b-2c3d4e5f6a7b"},{syntax:"@int(1, 100)",desc:"随机整数(含边界)",example:"42"},{syntax:"@int",desc:"随机整数(0-1000)",example:"731"},{syntax:"@boolean",desc:"随机布尔",example:"true"},{syntax:'@pick("a","b","c")',desc:"从列表随机取一项",example:'"b"'}]},{group:"时间相关",icon:e.jsx(i.FunctionOutlined,{}),items:[{syntax:"@datetime",desc:"当前时间 (yyyy-MM-dd HH:mm:ss)",example:"2026-06-17 22:30:15"},{syntax:"@date",desc:"当前日期 (yyyy-MM-dd)",example:"2026-06-17"},{syntax:"@time",desc:"当前时间戳 (毫秒)",example:"1718639415000"},{syntax:"@timestamp",desc:"Unix 秒级时间戳",example:"1718639415"}]},{group:"文本生成",icon:e.jsx(i.FunctionOutlined,{}),items:[{syntax:"@name",desc:"随机中文姓名",example:"张伟"},{syntax:"@firstName",desc:"随机名",example:"伟"},{syntax:"@lastName",desc:"随机姓",example:"张"},{syntax:"@email",desc:"随机邮箱",example:"zhangwei@example.com"},{syntax:"@phone",desc:"随机手机号(中国)",example:"13812345678"},{syntax:"@idCard",desc:"随机身份证号",example:"110101199003078234"},{syntax:"@word",desc:"随机英文单词",example:"horizon"},{syntax:"@sentence(5, 10)",desc:"随机句子 (5-10 词)",example:"The quick brown fox jumps."},{syntax:"@paragraph(3, 5)",desc:"随机段落 (3-5 句)",example:"..."}]},{group:"序列与状态",icon:e.jsx(i.FunctionOutlined,{}),items:[{syntax:"@sequence(1)",desc:"自增序号(每次调用 +1,1 起始)",example:"1, 2, 3, ..."},{syntax:"@sequence(100, 5)",desc:"自增序号(100 起始,步长 5)",example:"100, 105, 110, ..."}]},{group:"请求上下文",icon:e.jsx(i.FunctionOutlined,{}),items:[{syntax:"#path.id",desc:"从 URL 路径取值 /users/123 → 123",example:"123"},{syntax:"#query.page",desc:"从 query string 取值 ?page=2",example:"2"},{syntax:"#header.X-Token",desc:"从请求头取值",example:"abc.def.ghi"},{syntax:"#body.username",desc:"从请求体 JSON 取值",example:'"alice"'}]}];function gs({onInsert:t,form:a,formField:l="responseTemplate"}){const[j,I]=r.useState(""),C=m=>{var h;try{(h=navigator.clipboard)==null||h.writeText(m)}catch{}if(t)t(m);else if(a){const z=a.getFieldValue(l)||"";a.setFieldsValue({[l]:z+(z.endsWith(`
29
- `)||!z?"":" ")+m})}s.message.success(`已插入: ${m}`)},d=m=>{var h;try{(h=navigator.clipboard)==null||h.writeText(m),s.message.success("已复制到剪贴板")}catch{s.message.warning("复制失败,请手动选择")}},g=j.toLowerCase(),v=hs.map(m=>({...m,items:m.items.filter(h=>!g||h.syntax.toLowerCase().includes(g)||h.desc.toLowerCase().includes(g)||h.example.toLowerCase().includes(g))})).filter(m=>m.items.length>0),f=hs.reduce((m,h)=>m+h.items.length,0),O=v.reduce((m,h)=>m+h.items.length,0);return e.jsxs(s.Card,{size:"small",title:e.jsxs(s.Space,{children:[e.jsx(i.CodeOutlined,{}),e.jsx(Ee,{strong:!0,children:"模板表达式"}),e.jsxs(s.Tag,{color:"blue",children:[O,"/",f]}),e.jsx(s.Tooltip,{title:"点击按钮即可插入到上方响应模板;点击 syntax 文本可复制",children:e.jsx(i.InfoCircleOutlined,{style:{color:"#999"}})})]}),extra:e.jsx(s.Input,{size:"small",placeholder:"搜索 @ 表达式",prefix:e.jsx(i.SearchOutlined,{}),value:j,onChange:m=>I(m.target.value),style:{width:180},allowClear:!0}),style:{marginTop:8,background:"#fafafa"},styles:{body:{padding:12,maxHeight:320,overflow:"auto"}},children:[v.length===0&&e.jsx(Ee,{type:"secondary",style:{display:"block",textAlign:"center",padding:16},children:"没有匹配的表达式"}),v.map(m=>e.jsxs("div",{style:{marginBottom:12},children:[e.jsxs(s.Space,{size:4,style:{marginBottom:6},children:[m.icon,e.jsx(Ee,{strong:!0,style:{fontSize:13},children:m.group}),e.jsx(s.Tag,{children:m.items.length})]}),e.jsx(s.Row,{gutter:[8,8],children:m.items.map(h=>e.jsx(s.Col,{span:24,children:e.jsxs("div",{style:{display:"flex",alignItems:"center",padding:"6px 8px",background:"#fff",border:"1px solid #f0f0f0",borderRadius:4,gap:8},children:[e.jsx(s.Tooltip,{title:"点击复制",children:e.jsx(Ee,{code:!0,style:{cursor:"pointer",minWidth:140,fontSize:12},onClick:()=>d(h.syntax),children:h.syntax})}),e.jsx(Ee,{type:"secondary",style:{fontSize:12,flex:1},children:h.desc}),e.jsx(s.Tag,{color:"default",style:{margin:0,fontFamily:"monospace"},children:h.example}),e.jsx(s.Tooltip,{title:"插入到响应模板",children:e.jsx(s.Button,{size:"small",type:"text",icon:e.jsx(i.CopyOutlined,{}),onClick:()=>C(h.syntax)})})]})},h.syntax))})]},m.group))]})}const{TextArea:je}=s.Input,{Text:ue,Paragraph:kt}=s.Typography,vt=[{value:"GET",label:"GET"},{value:"POST",label:"POST"},{value:"PUT",label:"PUT"},{value:"DELETE",label:"DELETE"},{value:"PATCH",label:"PATCH"}],js={GET:"green",POST:"blue",PUT:"orange",DELETE:"red",PATCH:"purple"},Et=[{value:"NONE",label:"无故障"},{value:"TIMEOUT",label:"超时 (TIMEOUT)"},{value:"EMPTY_RESPONSE",label:"空响应 (EMPTY)"},{value:"RANDOM_DROP",label:"随机丢弃 (RANDOM_DROP)"},{value:"MALFORMED",label:"畸形响应 (MALFORMED)"},{value:"500_ERROR",label:"500 错误"},{value:"RATE_LIMIT",label:"限流 (RATE_LIMIT)"}],Ot=[{value:"JSON",label:"JSON"},{value:"JSONPATH",label:"JSONPath"},{value:"REGEX",label:"正则"},{value:"TEXT",label:"纯文本"}];function ze({activeEnvCode:t}){const[a,l]=r.useState([]),[j,I]=r.useState(!1),[C,d]=r.useState(null),[g,v]=r.useState(!1),[f,O]=r.useState(null),[m]=s.Form.useForm(),[h,z]=r.useState(!1),[y,$]=r.useState(null),[E,N]=r.useState(!1);r.useEffect(()=>{T()},[t]);const T=async()=>{I(!0),d(null);try{const o=await q.endpoints.list(t);l(Array.isArray(o)?o:[])}catch(o){d((o==null?void 0:o.message)||"API unavailable"),l([])}finally{I(!1)}},w=()=>{O(null),m.resetFields(),m.setFieldsValue({method:"GET",statusCode:200,delayMs:0,priority:5,envCode:t||"default",matchBodyType:"JSON",faultType:"NONE",status:1}),v(!0)},P=o=>{O(o),m.setFieldsValue(o),v(!0)},S=async()=>{try{const o=await m.validateFields();f?(await q.endpoints.update(f.mockCode,o),s.message.success("更新成功")):(await q.endpoints.create(o),s.message.success("创建成功")),v(!1),T()}catch(o){if(o!=null&&o.errorFields)return;s.message.error("保存失败: "+((o==null?void 0:o.message)||""))}},M=async o=>{try{await q.endpoints.delete(o),s.message.success("删除成功"),T()}catch{s.message.error("删除失败")}},U=async o=>{const n=o.status===1?0:1;try{await q.endpoints.toggle(o.mockCode,n),s.message.success(n===1?"已启用":"已禁用"),T()}catch{s.message.error("操作失败")}},J=o=>`${window.location.origin}/api/mock/${o.envCode||t||"default"}${o.path||""}`,H=[{title:"路径",dataIndex:"path",key:"path",width:280,render:(o,n)=>e.jsxs(s.Space,{children:[e.jsx(s.Tag,{color:js[n.method]||"default",children:n.method}),e.jsx(ue,{code:!0,copyable:{text:o},children:o})]})},{title:"编码",dataIndex:"mockCode",key:"mockCode",width:160},{title:"优先级",dataIndex:"priority",key:"priority",width:80,align:"center",render:o=>e.jsxs(s.Tag,{color:"blue",children:["P",o||5]})},{title:"状态码",dataIndex:"statusCode",key:"statusCode",width:80,align:"center"},{title:"延迟",dataIndex:"delayMs",key:"delayMs",width:80,align:"center",render:o=>o>0?e.jsxs(ue,{type:"warning",children:[o,"ms"]}):e.jsx(ue,{type:"secondary",children:"-"})},{title:"故障",dataIndex:"faultType",key:"faultType",width:110,render:o=>o&&o!=="NONE"?e.jsx(s.Tag,{color:"red",children:o}):e.jsx(ue,{type:"secondary",children:"-"})},{title:"场景",dataIndex:"scenarioCode",key:"scenarioCode",width:130,render:o=>o?e.jsx(s.Tag,{color:"purple",children:o}):e.jsx(ue,{type:"secondary",children:"-"})},{title:"命中",dataIndex:"hitCount",key:"hitCount",width:80,align:"center",render:o=>e.jsx(ue,{strong:!0,children:o||0})},{title:"状态",key:"status",width:100,align:"center",render:(o,n)=>e.jsx(s.Switch,{checked:n.status===1,onChange:()=>U(n),checkedChildren:"启用",unCheckedChildren:"禁用",size:"small"})},{title:"操作",key:"action",width:220,fixed:"right",render:(o,n)=>e.jsxs(s.Space,{size:"small",children:[e.jsx(s.Tooltip,{title:"预览响应",children:e.jsx(s.Button,{size:"small",type:"link",icon:e.jsx(i.PlayCircleOutlined,{}),onClick:()=>{$(n),z(!0)},children:"预览"})}),e.jsx(s.Tooltip,{title:"复制URL",children:e.jsx(s.Button,{size:"small",type:"link",icon:e.jsx(i.CopyOutlined,{}),onClick:()=>{navigator.clipboard.writeText(J(n)),s.message.success("已复制")}})}),e.jsx(s.Tooltip,{title:"编辑",children:e.jsx(s.Button,{size:"small",type:"link",icon:e.jsx(i.EditOutlined,{}),onClick:()=>P(n)})}),e.jsx(s.Popconfirm,{title:"确认删除?",onConfirm:()=>M(n.mockCode),children:e.jsx(s.Button,{size:"small",type:"link",danger:!0,icon:e.jsx(i.DeleteOutlined,{})})})]})}];return e.jsxs("div",{children:[C&&e.jsx(s.Alert,{type:"warning",showIcon:!0,style:{marginBottom:16},message:"后端 API 暂未连接",description:C}),e.jsxs(s.Row,{gutter:16,style:{marginBottom:16},children:[e.jsx(s.Col,{span:6,children:e.jsxs(s.Card,{children:[e.jsx("strong",{children:"总端点"}),e.jsx("div",{style:{fontSize:22},children:a.length})]})}),e.jsx(s.Col,{span:6,children:e.jsxs(s.Card,{children:[e.jsx("strong",{children:"已启用"}),e.jsx("div",{style:{fontSize:22,color:"#52c41a"},children:a.filter(o=>o.status===1).length})]})}),e.jsx(s.Col,{span:6,children:e.jsxs(s.Card,{children:[e.jsx("strong",{children:"已禁用"}),e.jsx("div",{style:{fontSize:22,color:"#ff4d4f"},children:a.filter(o=>o.status===0).length})]})}),e.jsx(s.Col,{span:6,children:e.jsxs(s.Card,{children:[e.jsx("strong",{children:"总命中"}),e.jsx("div",{style:{fontSize:22,color:"#1890ff"},children:a.reduce((o,n)=>o+(n.hitCount||0),0)})]})})]}),e.jsxs(s.Space,{style:{marginBottom:16},children:[e.jsx(s.Button,{icon:e.jsx(i.PlayCircleOutlined,{}),onClick:T,children:"刷新"}),e.jsx(s.Button,{type:"primary",icon:e.jsx(i.PlusOutlined,{}),onClick:w,children:"新建 Mock 端点"}),e.jsx(s.Button,{icon:e.jsx(i.CloudUploadOutlined,{}),onClick:()=>N(!0),children:"批量导入 (OpenAPI / Swagger / Postman)"})]}),e.jsx(s.Table,{dataSource:a,columns:H,rowKey:"id",loading:j,pagination:{pageSize:10},scroll:{x:1300},size:"small"}),e.jsx(s.Modal,{title:f?`编辑 Mock 端点: ${f.mockCode}`:"新建 Mock 端点",open:g,onCancel:()=>v(!1),onOk:S,width:900,okText:"保存",cancelText:"取消",children:e.jsx(s.Form,{form:m,layout:"vertical",style:{marginTop:16},children:e.jsx(s.Tabs,{items:[{key:"basic",label:"基本信息",children:e.jsxs(e.Fragment,{children:[e.jsxs(s.Row,{gutter:16,children:[e.jsx(s.Col,{span:8,children:e.jsx(s.Form.Item,{name:"mockCode",label:"Mock 编码",rules:[{required:!0}],children:e.jsx(s.Input,{placeholder:"mock-user-list",disabled:!!f})})}),e.jsx(s.Col,{span:8,children:e.jsx(s.Form.Item,{name:"mockName",label:"名称",children:e.jsx(s.Input,{placeholder:"User List Endpoint"})})}),e.jsx(s.Col,{span:8,children:e.jsx(s.Form.Item,{name:"envCode",label:"环境编码",children:e.jsx(s.Input,{placeholder:"default"})})})]}),e.jsxs(s.Row,{gutter:16,children:[e.jsx(s.Col,{span:12,children:e.jsx(s.Form.Item,{name:"path",label:"路径",rules:[{required:!0}],children:e.jsx(s.Input,{placeholder:"/api/user/list"})})}),e.jsx(s.Col,{span:4,children:e.jsx(s.Form.Item,{name:"method",label:"方法",children:e.jsx(s.Select,{options:vt})})}),e.jsx(s.Col,{span:4,children:e.jsx(s.Form.Item,{name:"priority",label:"优先级",children:e.jsx(s.InputNumber,{min:0,max:99,style:{width:"100%"}})})}),e.jsx(s.Col,{span:4,children:e.jsx(s.Form.Item,{name:"statusCode",label:"状态码",children:e.jsx(s.InputNumber,{min:100,max:599,style:{width:"100%"}})})})]}),e.jsxs(s.Row,{gutter:16,children:[e.jsx(s.Col,{span:8,children:e.jsx(s.Form.Item,{name:"delayMs",label:"延迟(ms)",children:e.jsx(s.InputNumber,{min:0,max:6e4,style:{width:"100%"}})})}),e.jsx(s.Col,{span:8,children:e.jsx(s.Form.Item,{name:"projectCode",label:"项目",children:e.jsx(s.Input,{placeholder:"default"})})}),e.jsx(s.Col,{span:8,children:e.jsx(s.Form.Item,{name:"moduleCode",label:"模块",children:e.jsx(s.Input,{placeholder:"user"})})})]}),e.jsx(s.Form.Item,{name:"description",label:"描述",children:e.jsx(je,{rows:2})})]})},{key:"match",label:"请求匹配",children:e.jsxs(e.Fragment,{children:[e.jsx(s.Form.Item,{name:"matchUrlPattern",label:"URL 匹配模式 (Ant风格)",extra:"支持 /api/users/{id} 通配符,留空则按 path 精确匹配",children:e.jsx(s.Input,{placeholder:"/api/users/{id}"})}),e.jsxs(s.Row,{gutter:16,children:[e.jsx(s.Col,{span:12,children:e.jsx(s.Form.Item,{name:"matchHeaders",label:"Header 匹配 (JSON)",extra:'例: {"Authorization": "Bearer *", "Content-Type": "application/json"}',children:e.jsx(je,{rows:3,placeholder:'{"Authorization": "Bearer *"}'})})}),e.jsx(s.Col,{span:12,children:e.jsx(s.Form.Item,{name:"matchQuery",label:"Query 匹配 (JSON)",extra:'例: {"page": "1", "size": "10"}',children:e.jsx(je,{rows:3,placeholder:'{"page": "1"}'})})})]}),e.jsx(s.Form.Item,{name:"matchBodyType",label:"Body 匹配类型",children:e.jsx(s.Select,{options:Ot})}),e.jsx(s.Form.Item,{name:"matchBody",label:"Body 匹配表达式",extra:"JSON 类型支持 JSONPath,REGEX 类型为正则表达式",children:e.jsx(je,{rows:3,placeholder:'$.user.id == "100"'})})]})},{key:"scenario",label:"场景状态机",children:e.jsxs(e.Fragment,{children:[e.jsx(s.Form.Item,{name:"scenarioCode",label:"场景编码",extra:"关联场景实现状态机驱动 (如 user-flow, payment-flow)",children:e.jsx(s.Input,{placeholder:"user-flow"})}),e.jsxs(s.Row,{gutter:16,children:[e.jsx(s.Col,{span:12,children:e.jsx(s.Form.Item,{name:"requiredState",label:"匹配所需状态",extra:"仅当实例处于此状态时才匹配 (留空 = 不限制)",children:e.jsx(s.Input,{placeholder:"started"})})}),e.jsx(s.Col,{span:12,children:e.jsx(s.Form.Item,{name:"newState",label:"匹配后新状态",extra:"匹配成功后自动切换",children:e.jsx(s.Input,{placeholder:"logged-in"})})})]})]})},{key:"fault",label:"故障注入",children:e.jsxs(e.Fragment,{children:[e.jsx(s.Form.Item,{name:"faultType",label:"故障类型",extra:"模拟网络异常,验证客户端容错",children:e.jsx(s.Select,{options:Et})}),e.jsx(s.Form.Item,{name:"faultConfig",label:"故障配置 (JSON)",extra:'例: {"errorRate": 0.5, "rateLimitQps": 10, "timeoutMs": 30000}',children:e.jsx(je,{rows:4,placeholder:'{"errorRate": 0.5}'})}),e.jsx(s.Form.Item,{name:"proxyTo",label:"代理目标 URL",extra:"未匹配时转发到真实服务 (MockEnvironment 模式)",children:e.jsx(s.Input,{placeholder:"http://real-service:8080"})})]})},{key:"response",label:"响应",children:e.jsxs(e.Fragment,{children:[e.jsx(s.Form.Item,{name:"responseHeaders",label:"响应头 (JSON)",extra:'例: {"Content-Type": "application/json", "X-Trace-Id": "..."}',children:e.jsx(je,{rows:2,placeholder:'{"Content-Type": "application/json"}'})}),e.jsx(s.Form.Item,{name:"responseTemplate",label:"响应模板 (JSON)",rules:[{required:!0}],extra:e.jsxs("div",{children:[e.jsxs(ue,{type:"secondary",style:{display:"block",marginBottom:4},children:["支持 ",e.jsx("code",{children:"@int(1,100)"})," / ",e.jsx("code",{children:"@uuid"})," / ",e.jsx("code",{children:"@datetime"})," / ",e.jsx("code",{children:"#path.id"})," 等动态表达式"]}),e.jsx(gs,{form:m,formField:"responseTemplate"})]}),children:e.jsx(je,{rows:14,placeholder:`{
36
+ }`,defaultStatus:200,priority:5,tagPrefix:"openapi-import"}),t.message.success(`识别为 ${f.format},共 ${f.count} 个端点`)):d(f.message||"解析失败")}catch(f){d(String((f==null?void 0:f.message)||f))}finally{F(!1)}},H=async f=>{try{const z=await J.openapi.sample(f);z.success&&(c(z.content),t.message.success(`已加载 ${z.format} 示例`))}catch(z){t.message.error("加载示例失败: "+z.message)}},Y=f=>{const z=new FileReader;return z.onload=P=>{var D;c(String(((D=P.target)==null?void 0:D.result)||"")),t.message.success(`已读取 ${f.name}(${(f.size/1024).toFixed(1)}KB)`)},z.onerror=()=>t.message.error("文件读取失败"),z.readAsText(f),!1},K=async()=>{if(!x){t.message.warning("请先解析");return}let f;try{f=await w.validateFields()}catch{return}S(!0);try{const z=(x.endpoints||[]).map((D,Q)=>({method:D.method,path:D.path})).filter((D,Q)=>E.includes(Q)),P=await J.openapi.importBatch({content:i,selected:z,envCode:f.envCode,projectCode:f.projectCode,defaultResponse:f.defaultResponse,defaultStatus:f.defaultStatus,priority:f.priority,tagPrefix:f.tagPrefix});P.success?(t.message.success(`已导入 ${P.imported} 个 Mock 端点${P.failed>0?`,失败 ${P.failed}`:""}`),n&&n(P),k()):t.message.error(P.message||"导入失败")}catch(z){t.message.error(String((z==null?void 0:z.message)||z))}finally{S(!1)}},m=[{title:"Method",dataIndex:"method",width:90,render:f=>e.jsx(t.Tag,{color:el(f),children:f})},{title:"Path",dataIndex:"path",width:240,ellipsis:!0},{title:"Summary",dataIndex:"summary",ellipsis:!0},{title:"Tags",dataIndex:"tags",width:160,render:f=>(f||[]).map(z=>e.jsx(t.Tag,{children:z},z))},{title:"Params",dataIndex:"parameters",width:80,render:f=>(f==null?void 0:f.length)||0,align:"center"},{title:"示例",dataIndex:"responseExample",width:80,render:f=>f?e.jsx(t.Tag,{color:"green",children:"有"}):e.jsx(t.Tag,{children:"无"})}];return e.jsxs(t.Modal,{title:e.jsxs(t.Space,{children:[e.jsx(g.CloudUploadOutlined,{})," 批量导入 API 规约"]}),open:s,onCancel:k,footer:null,width:1100,destroyOnClose:!0,children:[e.jsx(t.Tabs,{activeKey:l,onChange:a,items:[{key:"paste",label:e.jsxs("span",{children:[e.jsx(g.FileTextOutlined,{})," 粘贴 JSON"]}),children:e.jsxs("div",{children:[e.jsx(Gs,{value:i,onChange:f=>c(f.target.value),placeholder:"粘贴 OpenAPI 3.x / Swagger 2.0 / Postman v2.1 JSON 内容…",autoSize:{minRows:6,maxRows:16},style:{fontFamily:"Menlo, Monaco, monospace",fontSize:12}}),e.jsxs(t.Space,{style:{marginTop:8},children:[e.jsx(t.Button,{size:"small",onClick:()=>H("openapi3"),children:"加载 OpenAPI 3 示例"}),e.jsx(t.Button,{size:"small",onClick:()=>H("swagger2"),children:"加载 Swagger 2 示例"}),e.jsx(t.Button,{size:"small",onClick:()=>H("postman"),children:"加载 Postman 示例"})]})]})},{key:"upload",label:e.jsxs("span",{children:[e.jsx(g.FileAddOutlined,{})," 上传文件"]}),children:e.jsxs(t.Upload.Dragger,{ref:T,accept:".json,.yaml,.yml,application/json,text/yaml",beforeUpload:Y,showUploadList:!1,style:{padding:24},children:[e.jsx("p",{className:"ant-upload-drag-icon",children:e.jsx(g.CloudUploadOutlined,{style:{fontSize:48,color:"#1890ff"}})}),e.jsx("p",{className:"ant-upload-text",children:"点击或拖拽 JSON / YAML 文件到此处"}),e.jsx("p",{className:"ant-upload-hint",children:"支持 OpenAPI 3.x / Swagger 2.0 / Postman v2.1"})]})}]}),e.jsxs(t.Space,{style:{marginTop:12},children:[e.jsx(t.Button,{type:"primary",icon:e.jsx(g.ThunderboltOutlined,{}),onClick:R,loading:b,children:"解析"}),x&&e.jsx(t.Tag,{color:"blue",children:x.format}),x&&e.jsxs(t.Tag,{children:["共 ",x.count," 个端点,已选 ",E.length]})]}),y&&e.jsx(t.Alert,{type:"error",showIcon:!0,style:{marginTop:12},message:"解析失败",description:y}),x&&e.jsx(t.Card,{size:"small",style:{marginTop:16},title:"预览(可勾选要导入的)",children:e.jsx(t.Table,{size:"small",dataSource:x.endpoints||[],columns:m,rowKey:(f,z)=>z,rowSelection:{selectedRowKeys:E,onChange:_},pagination:{pageSize:8},scroll:{y:280}})}),x&&e.jsx(t.Card,{size:"small",style:{marginTop:16},title:"导入配置",children:e.jsxs(t.Form,{form:w,layout:"vertical",children:[e.jsxs(t.Row,{gutter:16,children:[e.jsx(t.Col,{span:6,children:e.jsx(t.Form.Item,{name:"envCode",label:"环境",rules:[{required:!0}],children:o.length>0?e.jsx(t.Select,{options:o.map(f=>({value:f,label:f}))}):e.jsx(t.Input,{})})}),e.jsx(t.Col,{span:6,children:e.jsx(t.Form.Item,{name:"projectCode",label:"项目",children:e.jsx(t.Input,{})})}),e.jsx(t.Col,{span:4,children:e.jsx(t.Form.Item,{name:"defaultStatus",label:"默认状态码",children:e.jsx(t.Input,{type:"number"})})}),e.jsx(t.Col,{span:4,children:e.jsx(t.Form.Item,{name:"priority",label:"优先级",children:e.jsx(t.Input,{type:"number"})})}),e.jsx(t.Col,{span:4,children:e.jsx(t.Form.Item,{name:"tagPrefix",label:"Tag 前缀",children:e.jsx(t.Input,{})})})]}),e.jsx(t.Form.Item,{name:"defaultResponse",label:"默认响应(无 example 时使用)",children:e.jsx(Gs,{autoSize:{minRows:3,maxRows:6},style:{fontFamily:"Menlo, Monaco, monospace"}})}),e.jsxs(t.Button,{type:"primary",size:"large",icon:e.jsx(g.ImportOutlined,{}),onClick:K,loading:C,disabled:E.length===0,children:["批量导入 ",E.length," 个端点"]})]})})]})}function el(s){return{GET:"blue",POST:"green",PUT:"orange",DELETE:"red",PATCH:"purple"}[s]||"default"}const{Text:nt,Paragraph:ii}=t.Typography,Vs=[{group:"基础数据",icon:e.jsx(g.CodeOutlined,{}),items:[{syntax:"@uuid",desc:"随机 UUID",example:"a3f2e1b7-8c4d-4e6f-9a1b-2c3d4e5f6a7b"},{syntax:"@int(1, 100)",desc:"随机整数(含边界)",example:"42"},{syntax:"@int",desc:"随机整数(0-1000)",example:"731"},{syntax:"@boolean",desc:"随机布尔",example:"true"},{syntax:'@pick("a","b","c")',desc:"从列表随机取一项",example:'"b"'}]},{group:"时间相关",icon:e.jsx(g.FunctionOutlined,{}),items:[{syntax:"@datetime",desc:"当前时间 (yyyy-MM-dd HH:mm:ss)",example:"2026-06-17 22:30:15"},{syntax:"@date",desc:"当前日期 (yyyy-MM-dd)",example:"2026-06-17"},{syntax:"@time",desc:"当前时间戳 (毫秒)",example:"1718639415000"},{syntax:"@timestamp",desc:"Unix 秒级时间戳",example:"1718639415"}]},{group:"文本生成",icon:e.jsx(g.FunctionOutlined,{}),items:[{syntax:"@name",desc:"随机中文姓名",example:"张伟"},{syntax:"@firstName",desc:"随机名",example:"伟"},{syntax:"@lastName",desc:"随机姓",example:"张"},{syntax:"@email",desc:"随机邮箱",example:"zhangwei@example.com"},{syntax:"@phone",desc:"随机手机号(中国)",example:"13812345678"},{syntax:"@idCard",desc:"随机身份证号",example:"110101199003078234"},{syntax:"@word",desc:"随机英文单词",example:"horizon"},{syntax:"@sentence(5, 10)",desc:"随机句子 (5-10 词)",example:"The quick brown fox jumps."},{syntax:"@paragraph(3, 5)",desc:"随机段落 (3-5 句)",example:"..."}]},{group:"序列与状态",icon:e.jsx(g.FunctionOutlined,{}),items:[{syntax:"@sequence(1)",desc:"自增序号(每次调用 +1,1 起始)",example:"1, 2, 3, ..."},{syntax:"@sequence(100, 5)",desc:"自增序号(100 起始,步长 5)",example:"100, 105, 110, ..."}]},{group:"请求上下文",icon:e.jsx(g.FunctionOutlined,{}),items:[{syntax:"#path.id",desc:"从 URL 路径取值 /users/123 → 123",example:"123"},{syntax:"#query.page",desc:"从 query string 取值 ?page=2",example:"2"},{syntax:"#header.X-Token",desc:"从请求头取值",example:"abc.def.ghi"},{syntax:"#body.username",desc:"从请求体 JSON 取值",example:'"alice"'}]}];function Ks({onInsert:s,form:r,formField:n="responseTemplate"}){const[o,l]=p.useState(""),a=d=>{var b;try{(b=navigator.clipboard)==null||b.writeText(d)}catch{}if(s)s(d);else if(r){const F=r.getFieldValue(n)||"";r.setFieldsValue({[n]:F+(F.endsWith(`
37
+ `)||!F?"":" ")+d})}t.message.success(`已插入: ${d}`)},i=d=>{var b;try{(b=navigator.clipboard)==null||b.writeText(d),t.message.success("已复制到剪贴板")}catch{t.message.warning("复制失败,请手动选择")}},c=o.toLowerCase(),x=Vs.map(d=>({...d,items:d.items.filter(b=>!c||b.syntax.toLowerCase().includes(c)||b.desc.toLowerCase().includes(c)||b.example.toLowerCase().includes(c))})).filter(d=>d.items.length>0),h=Vs.reduce((d,b)=>d+b.items.length,0),y=x.reduce((d,b)=>d+b.items.length,0);return e.jsxs(t.Card,{size:"small",title:e.jsxs(t.Space,{children:[e.jsx(g.CodeOutlined,{}),e.jsx(nt,{strong:!0,children:"模板表达式"}),e.jsxs(t.Tag,{color:"blue",children:[y,"/",h]}),e.jsx(t.Tooltip,{title:"点击按钮即可插入到上方响应模板;点击 syntax 文本可复制",children:e.jsx(g.InfoCircleOutlined,{style:{color:"#999"}})})]}),extra:e.jsx(t.Input,{size:"small",placeholder:"搜索 @ 表达式",prefix:e.jsx(g.SearchOutlined,{}),value:o,onChange:d=>l(d.target.value),style:{width:180},allowClear:!0}),style:{marginTop:8,background:"#fafafa"},styles:{body:{padding:12,maxHeight:320,overflow:"auto"}},children:[x.length===0&&e.jsx(nt,{type:"secondary",style:{display:"block",textAlign:"center",padding:16},children:"没有匹配的表达式"}),x.map(d=>e.jsxs("div",{style:{marginBottom:12},children:[e.jsxs(t.Space,{size:4,style:{marginBottom:6},children:[d.icon,e.jsx(nt,{strong:!0,style:{fontSize:13},children:d.group}),e.jsx(t.Tag,{children:d.items.length})]}),e.jsx(t.Row,{gutter:[8,8],children:d.items.map(b=>e.jsx(t.Col,{span:24,children:e.jsxs("div",{style:{display:"flex",alignItems:"center",padding:"6px 8px",background:"#fff",border:"1px solid #f0f0f0",borderRadius:4,gap:8},children:[e.jsx(t.Tooltip,{title:"点击复制",children:e.jsx(nt,{code:!0,style:{cursor:"pointer",minWidth:140,fontSize:12},onClick:()=>i(b.syntax),children:b.syntax})}),e.jsx(nt,{type:"secondary",style:{fontSize:12,flex:1},children:b.desc}),e.jsx(t.Tag,{color:"default",style:{margin:0,fontFamily:"monospace"},children:b.example}),e.jsx(t.Tooltip,{title:"插入到响应模板",children:e.jsx(t.Button,{size:"small",type:"text",icon:e.jsx(g.CopyOutlined,{}),onClick:()=>a(b.syntax)})})]})},b.syntax))})]},d.group))]})}const{TextArea:De}=t.Input,{Text:ke,Paragraph:tl}=t.Typography,sl=[{value:"GET",label:"GET"},{value:"POST",label:"POST"},{value:"PUT",label:"PUT"},{value:"DELETE",label:"DELETE"},{value:"PATCH",label:"PATCH"}],Xs={GET:"green",POST:"blue",PUT:"orange",DELETE:"red",PATCH:"purple"},rl=[{value:"NONE",label:"无故障"},{value:"TIMEOUT",label:"超时 (TIMEOUT)"},{value:"EMPTY_RESPONSE",label:"空响应 (EMPTY)"},{value:"RANDOM_DROP",label:"随机丢弃 (RANDOM_DROP)"},{value:"MALFORMED",label:"畸形响应 (MALFORMED)"},{value:"500_ERROR",label:"500 错误"},{value:"RATE_LIMIT",label:"限流 (RATE_LIMIT)"}],nl=[{value:"JSON",label:"JSON"},{value:"JSONPATH",label:"JSONPath"},{value:"REGEX",label:"正则"},{value:"TEXT",label:"纯文本"}];function St({activeEnvCode:s}){const[r,n]=p.useState([]),[o,l]=p.useState(!1),[a,i]=p.useState(null),[c,x]=p.useState(!1),[h,y]=p.useState(null),[d]=t.Form.useForm(),[b,F]=p.useState(!1),[E,_]=p.useState(null),[C,S]=p.useState(!1);p.useEffect(()=>{w()},[s]);const w=async()=>{l(!0),i(null);try{const m=await J.endpoints.list(s);n(Array.isArray(m)?m:[])}catch(m){i((m==null?void 0:m.message)||"API unavailable"),n([])}finally{l(!1)}},T=()=>{y(null),d.resetFields(),d.setFieldsValue({method:"GET",statusCode:200,delayMs:0,priority:5,envCode:s||"default",matchBodyType:"JSON",faultType:"NONE",status:1}),x(!0)},A=m=>{y(m),d.setFieldsValue(m),x(!0)},k=async()=>{try{const m=await d.validateFields();h?(await J.endpoints.update(h.mockCode,m),t.message.success("更新成功")):(await J.endpoints.create(m),t.message.success("创建成功")),x(!1),w()}catch(m){if(m!=null&&m.errorFields)return;t.message.error("保存失败: "+((m==null?void 0:m.message)||""))}},R=async m=>{try{await J.endpoints.delete(m),t.message.success("删除成功"),w()}catch{t.message.error("删除失败")}},H=async m=>{const f=m.status===1?0:1;try{await J.endpoints.toggle(m.mockCode,f),t.message.success(f===1?"已启用":"已禁用"),w()}catch{t.message.error("操作失败")}},Y=m=>`${window.location.origin}/api/mock/${m.envCode||s||"default"}${m.path||""}`,K=[{title:"路径",dataIndex:"path",key:"path",width:280,render:(m,f)=>e.jsxs(t.Space,{children:[e.jsx(t.Tag,{color:Xs[f.method]||"default",children:f.method}),e.jsx(ke,{code:!0,copyable:{text:m},children:m})]})},{title:"编码",dataIndex:"mockCode",key:"mockCode",width:160},{title:"优先级",dataIndex:"priority",key:"priority",width:80,align:"center",render:m=>e.jsxs(t.Tag,{color:"blue",children:["P",m||5]})},{title:"状态码",dataIndex:"statusCode",key:"statusCode",width:80,align:"center"},{title:"延迟",dataIndex:"delayMs",key:"delayMs",width:80,align:"center",render:m=>m>0?e.jsxs(ke,{type:"warning",children:[m,"ms"]}):e.jsx(ke,{type:"secondary",children:"-"})},{title:"故障",dataIndex:"faultType",key:"faultType",width:110,render:m=>m&&m!=="NONE"?e.jsx(t.Tag,{color:"red",children:m}):e.jsx(ke,{type:"secondary",children:"-"})},{title:"场景",dataIndex:"scenarioCode",key:"scenarioCode",width:130,render:m=>m?e.jsx(t.Tag,{color:"purple",children:m}):e.jsx(ke,{type:"secondary",children:"-"})},{title:"命中",dataIndex:"hitCount",key:"hitCount",width:80,align:"center",render:m=>e.jsx(ke,{strong:!0,children:m||0})},{title:"状态",key:"status",width:100,align:"center",render:(m,f)=>e.jsx(t.Switch,{checked:f.status===1,onChange:()=>H(f),checkedChildren:"启用",unCheckedChildren:"禁用",size:"small"})},{title:"操作",key:"action",width:220,fixed:"right",render:(m,f)=>e.jsxs(t.Space,{size:"small",children:[e.jsx(t.Tooltip,{title:"预览响应",children:e.jsx(t.Button,{size:"small",type:"link",icon:e.jsx(g.PlayCircleOutlined,{}),onClick:()=>{_(f),F(!0)},children:"预览"})}),e.jsx(t.Tooltip,{title:"复制URL",children:e.jsx(t.Button,{size:"small",type:"link",icon:e.jsx(g.CopyOutlined,{}),onClick:()=>{navigator.clipboard.writeText(Y(f)),t.message.success("已复制")}})}),e.jsx(t.Tooltip,{title:"编辑",children:e.jsx(t.Button,{size:"small",type:"link",icon:e.jsx(g.EditOutlined,{}),onClick:()=>A(f)})}),e.jsx(t.Popconfirm,{title:"确认删除?",onConfirm:()=>R(f.mockCode),children:e.jsx(t.Button,{size:"small",type:"link",danger:!0,icon:e.jsx(g.DeleteOutlined,{})})})]})}];return e.jsxs("div",{children:[a&&e.jsx(t.Alert,{type:"warning",showIcon:!0,style:{marginBottom:16},message:"后端 API 暂未连接",description:a}),e.jsxs(t.Row,{gutter:16,style:{marginBottom:16},children:[e.jsx(t.Col,{span:6,children:e.jsxs(t.Card,{children:[e.jsx("strong",{children:"总端点"}),e.jsx("div",{style:{fontSize:22},children:r.length})]})}),e.jsx(t.Col,{span:6,children:e.jsxs(t.Card,{children:[e.jsx("strong",{children:"已启用"}),e.jsx("div",{style:{fontSize:22,color:"#52c41a"},children:r.filter(m=>m.status===1).length})]})}),e.jsx(t.Col,{span:6,children:e.jsxs(t.Card,{children:[e.jsx("strong",{children:"已禁用"}),e.jsx("div",{style:{fontSize:22,color:"#ff4d4f"},children:r.filter(m=>m.status===0).length})]})}),e.jsx(t.Col,{span:6,children:e.jsxs(t.Card,{children:[e.jsx("strong",{children:"总命中"}),e.jsx("div",{style:{fontSize:22,color:"#1890ff"},children:r.reduce((m,f)=>m+(f.hitCount||0),0)})]})})]}),e.jsxs(t.Space,{style:{marginBottom:16},children:[e.jsx(t.Button,{icon:e.jsx(g.PlayCircleOutlined,{}),onClick:w,children:"刷新"}),e.jsx(t.Button,{type:"primary",icon:e.jsx(g.PlusOutlined,{}),onClick:T,children:"新建 Mock 端点"}),e.jsx(t.Button,{icon:e.jsx(g.CloudUploadOutlined,{}),onClick:()=>S(!0),children:"批量导入 (OpenAPI / Swagger / Postman)"})]}),e.jsx(t.Table,{dataSource:r,columns:K,rowKey:"id",loading:o,pagination:{pageSize:10},scroll:{x:1300},size:"small"}),e.jsx(t.Modal,{title:h?`编辑 Mock 端点: ${h.mockCode}`:"新建 Mock 端点",open:c,onCancel:()=>x(!1),onOk:k,width:900,okText:"保存",cancelText:"取消",children:e.jsx(t.Form,{form:d,layout:"vertical",style:{marginTop:16},children:e.jsx(t.Tabs,{items:[{key:"basic",label:"基本信息",children:e.jsxs(e.Fragment,{children:[e.jsxs(t.Row,{gutter:16,children:[e.jsx(t.Col,{span:8,children:e.jsx(t.Form.Item,{name:"mockCode",label:"Mock 编码",rules:[{required:!0}],children:e.jsx(t.Input,{placeholder:"mock-user-list",disabled:!!h})})}),e.jsx(t.Col,{span:8,children:e.jsx(t.Form.Item,{name:"mockName",label:"名称",children:e.jsx(t.Input,{placeholder:"User List Endpoint"})})}),e.jsx(t.Col,{span:8,children:e.jsx(t.Form.Item,{name:"envCode",label:"环境编码",children:e.jsx(t.Input,{placeholder:"default"})})})]}),e.jsxs(t.Row,{gutter:16,children:[e.jsx(t.Col,{span:12,children:e.jsx(t.Form.Item,{name:"path",label:"路径",rules:[{required:!0}],children:e.jsx(t.Input,{placeholder:"/api/user/list"})})}),e.jsx(t.Col,{span:4,children:e.jsx(t.Form.Item,{name:"method",label:"方法",children:e.jsx(t.Select,{options:sl})})}),e.jsx(t.Col,{span:4,children:e.jsx(t.Form.Item,{name:"priority",label:"优先级",children:e.jsx(t.InputNumber,{min:0,max:99,style:{width:"100%"}})})}),e.jsx(t.Col,{span:4,children:e.jsx(t.Form.Item,{name:"statusCode",label:"状态码",children:e.jsx(t.InputNumber,{min:100,max:599,style:{width:"100%"}})})})]}),e.jsxs(t.Row,{gutter:16,children:[e.jsx(t.Col,{span:8,children:e.jsx(t.Form.Item,{name:"delayMs",label:"延迟(ms)",children:e.jsx(t.InputNumber,{min:0,max:6e4,style:{width:"100%"}})})}),e.jsx(t.Col,{span:8,children:e.jsx(t.Form.Item,{name:"projectCode",label:"项目",children:e.jsx(t.Input,{placeholder:"default"})})}),e.jsx(t.Col,{span:8,children:e.jsx(t.Form.Item,{name:"moduleCode",label:"模块",children:e.jsx(t.Input,{placeholder:"user"})})})]}),e.jsx(t.Form.Item,{name:"description",label:"描述",children:e.jsx(De,{rows:2})})]})},{key:"match",label:"请求匹配",children:e.jsxs(e.Fragment,{children:[e.jsx(t.Form.Item,{name:"matchUrlPattern",label:"URL 匹配模式 (Ant风格)",extra:"支持 /api/users/{id} 通配符,留空则按 path 精确匹配",children:e.jsx(t.Input,{placeholder:"/api/users/{id}"})}),e.jsxs(t.Row,{gutter:16,children:[e.jsx(t.Col,{span:12,children:e.jsx(t.Form.Item,{name:"matchHeaders",label:"Header 匹配 (JSON)",extra:'例: {"Authorization": "Bearer *", "Content-Type": "application/json"}',children:e.jsx(De,{rows:3,placeholder:'{"Authorization": "Bearer *"}'})})}),e.jsx(t.Col,{span:12,children:e.jsx(t.Form.Item,{name:"matchQuery",label:"Query 匹配 (JSON)",extra:'例: {"page": "1", "size": "10"}',children:e.jsx(De,{rows:3,placeholder:'{"page": "1"}'})})})]}),e.jsx(t.Form.Item,{name:"matchBodyType",label:"Body 匹配类型",children:e.jsx(t.Select,{options:nl})}),e.jsx(t.Form.Item,{name:"matchBody",label:"Body 匹配表达式",extra:"JSON 类型支持 JSONPath,REGEX 类型为正则表达式",children:e.jsx(De,{rows:3,placeholder:'$.user.id == "100"'})})]})},{key:"scenario",label:"场景状态机",children:e.jsxs(e.Fragment,{children:[e.jsx(t.Form.Item,{name:"scenarioCode",label:"场景编码",extra:"关联场景实现状态机驱动 (如 user-flow, payment-flow)",children:e.jsx(t.Input,{placeholder:"user-flow"})}),e.jsxs(t.Row,{gutter:16,children:[e.jsx(t.Col,{span:12,children:e.jsx(t.Form.Item,{name:"requiredState",label:"匹配所需状态",extra:"仅当实例处于此状态时才匹配 (留空 = 不限制)",children:e.jsx(t.Input,{placeholder:"started"})})}),e.jsx(t.Col,{span:12,children:e.jsx(t.Form.Item,{name:"newState",label:"匹配后新状态",extra:"匹配成功后自动切换",children:e.jsx(t.Input,{placeholder:"logged-in"})})})]})]})},{key:"fault",label:"故障注入",children:e.jsxs(e.Fragment,{children:[e.jsx(t.Form.Item,{name:"faultType",label:"故障类型",extra:"模拟网络异常,验证客户端容错",children:e.jsx(t.Select,{options:rl})}),e.jsx(t.Form.Item,{name:"faultConfig",label:"故障配置 (JSON)",extra:'例: {"errorRate": 0.5, "rateLimitQps": 10, "timeoutMs": 30000}',children:e.jsx(De,{rows:4,placeholder:'{"errorRate": 0.5}'})}),e.jsx(t.Form.Item,{name:"proxyTo",label:"代理目标 URL",extra:"未匹配时转发到真实服务 (MockEnvironment 模式)",children:e.jsx(t.Input,{placeholder:"http://real-service:8080"})})]})},{key:"response",label:"响应",children:e.jsxs(e.Fragment,{children:[e.jsx(t.Form.Item,{name:"responseHeaders",label:"响应头 (JSON)",extra:'例: {"Content-Type": "application/json", "X-Trace-Id": "..."}',children:e.jsx(De,{rows:2,placeholder:'{"Content-Type": "application/json"}'})}),e.jsx(t.Form.Item,{name:"responseTemplate",label:"响应模板 (JSON)",rules:[{required:!0}],extra:e.jsxs("div",{children:[e.jsxs(ke,{type:"secondary",style:{display:"block",marginBottom:4},children:["支持 ",e.jsx("code",{children:"@int(1,100)"})," / ",e.jsx("code",{children:"@uuid"})," / ",e.jsx("code",{children:"@datetime"})," / ",e.jsx("code",{children:"#path.id"})," 等动态表达式"]}),e.jsx(Ks,{form:d,formField:"responseTemplate"})]}),children:e.jsx(De,{rows:14,placeholder:`{
30
38
  "success": true,
31
39
  "data": [],
32
40
  "code": 200
33
- }`,style:{fontFamily:"monospace",fontSize:13}})})]})}]})})}),e.jsx(s.Drawer,{title:e.jsxs(s.Space,{children:[e.jsx(i.ExperimentOutlined,{}),"端点详情: ",y==null?void 0:y.mockCode]}),open:h,onClose:()=>z(!1),width:650,children:y&&e.jsxs("div",{children:[e.jsxs(s.Descriptions,{column:2,size:"small",bordered:!0,style:{marginBottom:16},children:[e.jsx(s.Descriptions.Item,{label:"编码",children:y.mockCode}),e.jsx(s.Descriptions.Item,{label:"名称",children:y.mockName}),e.jsx(s.Descriptions.Item,{label:"方法",children:e.jsx(s.Tag,{color:js[y.method],children:y.method})}),e.jsx(s.Descriptions.Item,{label:"环境",children:y.envCode}),e.jsx(s.Descriptions.Item,{label:"路径",span:2,children:y.path}),e.jsx(s.Descriptions.Item,{label:"状态码",children:y.statusCode}),e.jsxs(s.Descriptions.Item,{label:"延迟",children:[y.delayMs,"ms"]}),e.jsxs(s.Descriptions.Item,{label:"优先级",children:["P",y.priority]}),e.jsx(s.Descriptions.Item,{label:"命中",children:y.hitCount||0}),e.jsx(s.Descriptions.Item,{label:"故障",children:y.faultType&&y.faultType!=="NONE"?e.jsx(s.Tag,{color:"red",children:y.faultType}):e.jsx(ue,{type:"secondary",children:"-"})}),e.jsx(s.Descriptions.Item,{label:"场景",children:y.scenarioCode||"-"}),e.jsx(s.Descriptions.Item,{label:"状态",span:2,children:y.status===1?e.jsx(s.Tag,{color:"green",children:"启用"}):e.jsx(s.Tag,{children:"禁用"})}),e.jsx(s.Descriptions.Item,{label:"完整 URL",span:2,children:e.jsx(ue,{copyable:!0,children:J(y)})})]}),e.jsx(kt,{strong:!0,children:"响应模板:"}),e.jsx("pre",{style:{background:"#f5f5f5",padding:12,borderRadius:4,maxHeight:350,overflow:"auto",fontSize:13,fontFamily:"monospace",whiteSpace:"pre-wrap",wordBreak:"break-all"},children:y.responseTemplate})]})}),e.jsx(xs,{open:E,onClose:()=>N(!1),onSuccess:()=>{s.message.success("已刷新列表"),T()}})]})}const{Text:He}=s.Typography,Ft=[{value:"MOCK",label:"MOCK (纯 Mock 拦截)",color:"green"},{value:"REAL",label:"REAL (全部代理到真实)",color:"blue"},{value:"MIXED",label:"MIXED (匹配失败时转发)",color:"orange"}],Pt={MOCK:"green",REAL:"blue",MIXED:"orange"};function Me({onEnvChange:t}){const[a,l]=r.useState([]),[j,I]=r.useState(!1),[C,d]=r.useState(!1),[g,v]=r.useState(null),[f]=s.Form.useForm();r.useEffect(()=>{O()},[]);const O=async()=>{I(!0);try{const E=await q.environments.list();l(Array.isArray(E)?E:[])}catch(E){s.message.warning("加载环境列表失败: "+(E==null?void 0:E.message))}finally{I(!1)}},m=()=>{v(null),f.resetFields(),f.setFieldsValue({envType:"MOCK",isDefault:0,mockPriority:1}),d(!0)},h=E=>{v(E),f.setFieldsValue(E),d(!0)},z=async()=>{try{const E=await f.validateFields();g?(await q.environments.update(g.envCode,E),s.message.success("更新成功")):(await q.environments.create(E),s.message.success("创建成功")),d(!1),O()}catch(E){if(E!=null&&E.errorFields)return;s.message.error("保存失败")}},y=async E=>{try{await q.environments.delete(E),s.message.success("删除成功"),O()}catch(N){s.message.error("删除失败: "+((N==null?void 0:N.message)||""))}},$=[{title:"环境编码",dataIndex:"envCode",key:"envCode",width:140,render:E=>e.jsx(He,{code:!0,children:E})},{title:"环境名称",dataIndex:"envName",key:"envName",width:160},{title:"类型",dataIndex:"envType",key:"envType",width:240,render:E=>e.jsx(s.Tag,{color:Pt[E]||"default",children:E})},{title:"真实服务地址",dataIndex:"baseUrl",key:"baseUrl",render:E=>E?e.jsx(He,{copyable:!0,children:E}):e.jsx(He,{type:"secondary",children:"-"})},{title:"默认",dataIndex:"isDefault",key:"isDefault",width:90,align:"center",render:E=>E===1?e.jsx(s.Tag,{color:"gold",children:"默认"}):"-"},{title:"描述",dataIndex:"description",key:"description",width:220,render:E=>E||"-"},{title:"操作",key:"action",width:180,render:(E,N)=>e.jsxs(s.Space,{size:"small",children:[e.jsx(s.Button,{size:"small",type:"link",icon:e.jsx(i.GlobalOutlined,{}),onClick:()=>{t&&t(N.envCode)},children:"切换"}),e.jsx(s.Button,{size:"small",type:"link",icon:e.jsx(i.EditOutlined,{}),onClick:()=>h(N)}),N.isDefault!==1&&e.jsx(s.Popconfirm,{title:`确认删除环境 ${N.envCode}?`,onConfirm:()=>y(N.envCode),children:e.jsx(s.Button,{size:"small",type:"link",danger:!0,icon:e.jsx(i.DeleteOutlined,{})})})]})}];return e.jsxs("div",{children:[e.jsx(s.Alert,{type:"info",showIcon:!0,style:{marginBottom:16},message:"环境隔离 - 控制 Mock 与真实服务的切换",description:e.jsxs("div",{children:[e.jsxs("div",{children:[e.jsx(s.Tag,{color:"green",children:"MOCK"})," 完全拦截,仅返回 Mock 数据"]}),e.jsxs("div",{children:[e.jsx(s.Tag,{color:"blue",children:"REAL"})," 全部代理到 baseUrl(适合压测、回归测试)"]}),e.jsxs("div",{children:[e.jsx(s.Tag,{color:"orange",children:"MIXED"})," Mock 优先,未匹配时转发到 baseUrl(开发联调)"]})]})}),e.jsxs(s.Space,{style:{marginBottom:16},children:[e.jsx(s.Button,{icon:e.jsx(i.ReloadOutlined,{}),onClick:O,children:"刷新"}),e.jsx(s.Button,{type:"primary",icon:e.jsx(i.PlusOutlined,{}),onClick:m,children:"新建环境"})]}),e.jsx(s.Table,{dataSource:a,columns:$,rowKey:"id",loading:j,pagination:{pageSize:10},size:"small"}),e.jsx(s.Modal,{title:g?`编辑环境: ${g.envCode}`:"新建环境",open:C,onCancel:()=>d(!1),onOk:z,width:650,children:e.jsxs(s.Form,{form:f,layout:"vertical",style:{marginTop:16},children:[e.jsxs(s.Row,{gutter:16,children:[e.jsx(s.Col,{span:12,children:e.jsx(s.Form.Item,{name:"envCode",label:"环境编码",rules:[{required:!0}],children:e.jsx(s.Input,{placeholder:"dev / staging / prod",disabled:!!g})})}),e.jsx(s.Col,{span:12,children:e.jsx(s.Form.Item,{name:"envName",label:"环境名称",rules:[{required:!0}],children:e.jsx(s.Input,{placeholder:"开发环境"})})})]}),e.jsx(s.Form.Item,{name:"envType",label:"环境类型",rules:[{required:!0}],children:e.jsx(s.Select,{options:Ft})}),e.jsx(s.Form.Item,{name:"baseUrl",label:"真实服务地址",extra:"REAL/MIXED 时使用。MIXED 时未匹配的请求会转发到这里",children:e.jsx(s.Input,{placeholder:"https://api.staging.example.com"})}),e.jsxs(s.Row,{gutter:16,children:[e.jsx(s.Col,{span:12,children:e.jsx(s.Form.Item,{name:"mockPriority",label:"Mock 优先级",children:e.jsx(s.InputNumber,{min:0,max:10,style:{width:"100%"}})})}),e.jsx(s.Col,{span:12,children:e.jsx(s.Form.Item,{name:"isDefault",label:"是否默认",valuePropName:"checked",children:e.jsx(s.Switch,{checkedChildren:"是",unCheckedChildren:"否"})})})]}),e.jsx(s.Form.Item,{name:"description",label:"描述",children:e.jsx(s.Input.TextArea,{rows:3,placeholder:"环境的用途说明"})})]})})]})}const{Text:Nt}=s.Typography;function ys(){const[t,a]=r.useState([]),[l,j]=r.useState(!1),[I,C]=r.useState(!1),[d,g]=r.useState(null),[v,f]=r.useState(!1),[O,m]=r.useState(null),[h]=s.Form.useForm();r.useEffect(()=>{z()},[]);const z=async()=>{j(!0);try{const S=await q.scenarios.list();a(Array.isArray(S)?S:[])}catch{s.message.warning("加载场景列表失败")}finally{j(!1)}},y=()=>{g(null),h.resetFields(),h.setFieldsValue({initialState:"started"}),C(!0)},$=S=>{g(S),h.setFieldsValue(S),C(!0)},E=async()=>{try{const S=await h.validateFields();let M;try{M=S.statesJson?JSON.parse(S.statesJson):null}catch{s.message.error("状态列表 JSON 格式错误");return}const U={...S,states:M};delete U.statesJson,d?(await q.scenarios.update(d.scenarioCode,U),s.message.success("更新成功")):(await q.scenarios.create(U),s.message.success("创建成功")),C(!1),z()}catch(S){S!=null&&S.errorFields||s.message.error("保存失败")}},N=async S=>{try{await q.scenarios.delete(S),s.message.success("删除成功"),z()}catch{s.message.error("删除失败")}},T=async S=>{try{await q.scenarios.reset(S),s.message.success("已重置所有实例状态")}catch{s.message.error("重置失败")}},w=async S=>{try{const M=await q.scenarios.instances(S);m({code:S,list:M}),f(!0)}catch{s.message.error("加载失败")}},P=[{title:"场景编码",dataIndex:"scenarioCode",key:"scenarioCode",width:160,render:S=>e.jsx(Nt,{code:!0,children:S})},{title:"场景名称",dataIndex:"scenarioName",key:"scenarioName",width:200},{title:"初始状态",dataIndex:"initialState",key:"initialState",width:140,render:S=>e.jsx(s.Tag,{color:"blue",children:S})},{title:"状态列表",dataIndex:"states",key:"states",render:S=>{if(!S)return"-";try{const M=typeof S=="string"?JSON.parse(S):S;return Array.isArray(M)?M.map(U=>e.jsx(s.Tag,{children:U},U)):"-"}catch{return"-"}}},{title:"描述",dataIndex:"description",key:"description",width:240,render:S=>S||"-"},{title:"操作",key:"action",width:280,fixed:"right",render:(S,M)=>e.jsxs(s.Space,{size:"small",children:[e.jsx(s.Button,{size:"small",type:"link",icon:e.jsx(i.NodeIndexOutlined,{}),onClick:()=>w(M.scenarioCode),children:"实例"}),e.jsx(s.Button,{size:"small",type:"link",icon:e.jsx(i.UndoOutlined,{}),onClick:()=>T(M.scenarioCode),children:"重置"}),e.jsx(s.Button,{size:"small",type:"link",icon:e.jsx(i.EditOutlined,{}),onClick:()=>$(M)}),e.jsx(s.Popconfirm,{title:`删除场景 ${M.scenarioCode}?`,onConfirm:()=>N(M.scenarioCode),children:e.jsx(s.Button,{size:"small",type:"link",danger:!0,icon:e.jsx(i.DeleteOutlined,{})})})]})}];return e.jsxs("div",{children:[e.jsx(s.Alert,{type:"info",showIcon:!0,style:{marginBottom:16},message:"场景状态机 (Scenario)",description:"用状态机驱动 Mock 集合,模拟完整业务流程(如:未登录→登录中→已登录→下单→已支付→完成)。实例通过 X-Session-Id 或 X-Trace-Id 区分,每个实例独立维护当前状态。"}),e.jsxs(s.Space,{style:{marginBottom:16},children:[e.jsx(s.Button,{icon:e.jsx(i.ReloadOutlined,{}),onClick:z,children:"刷新"}),e.jsx(s.Button,{type:"primary",icon:e.jsx(i.PlusOutlined,{}),onClick:y,children:"新建场景"})]}),e.jsx(s.Table,{dataSource:t,columns:P,rowKey:"id",loading:l,pagination:{pageSize:10},scroll:{x:1100},size:"small"}),e.jsx(s.Modal,{title:d?`编辑场景: ${d.scenarioCode}`:"新建场景",open:I,onCancel:()=>C(!1),onOk:E,width:650,children:e.jsxs(s.Form,{form:h,layout:"vertical",style:{marginTop:16},children:[e.jsxs(s.Row,{gutter:16,children:[e.jsx(s.Col,{span:12,children:e.jsx(s.Form.Item,{name:"scenarioCode",label:"场景编码",rules:[{required:!0}],children:e.jsx(s.Input,{placeholder:"user-login-flow",disabled:!!d})})}),e.jsx(s.Col,{span:12,children:e.jsx(s.Form.Item,{name:"scenarioName",label:"场景名称",children:e.jsx(s.Input,{placeholder:"用户登录流程"})})})]}),e.jsx(s.Form.Item,{name:"initialState",label:"初始状态",rules:[{required:!0}],children:e.jsx(s.Input,{placeholder:"started"})}),e.jsx(s.Form.Item,{name:"statesJson",label:"状态列表 (JSON 数组)",extra:'例: ["started", "logged-in", "checkout", "paid", "completed"]',children:e.jsx(s.Input.TextArea,{rows:3,placeholder:'["started", "logged-in", "checkout", "paid"]'})}),e.jsx(s.Form.Item,{name:"description",label:"描述",children:e.jsx(s.Input.TextArea,{rows:3,placeholder:"场景的业务说明"})})]})}),e.jsx(s.Modal,{title:`场景实例: ${O==null?void 0:O.code}`,open:v,onCancel:()=>f(!1),footer:e.jsx(s.Button,{onClick:()=>f(!1),children:"关闭"}),width:700,children:O&&e.jsx(s.Table,{dataSource:Array.isArray(O.list)?O.list:[],columns:[{title:"实例标识",dataIndex:"instanceKey",key:"instanceKey"},{title:"当前状态",dataIndex:"currentState",key:"currentState",render:S=>e.jsx(s.Tag,{color:"blue",children:S})},{title:"最后变更",dataIndex:"lastUpdateTime",key:"lastUpdateTime"}],rowKey:(S,M)=>S.instanceKey||M,pagination:!1,size:"small"})})]})}const{TextArea:fs}=s.Input,{Text:be,Paragraph:At}=s.Typography;function Cs({open:t,onClose:a,onSuccess:l,envOptions:j=[]}){const[I,C]=r.useState(""),[d,g]=r.useState(null),[v,f]=r.useState(null),[O,m]=r.useState(!1),[h,z]=r.useState(null),[y,$]=r.useState(!1),[E,N]=r.useState("import"),[T]=s.Form.useForm(),[w]=s.Form.useForm(),P=()=>{C(""),g(null),f(null),z(null),T.resetFields(),w.resetFields()},S=()=>{P(),a()},M=async()=>{var o,n,L,b;if(!I.trim()){s.message.warning("请先粘贴 curl 命令");return}f(null),g(null),z(null);try{const A=await q.curl.parse(I);A.success?(g(A.data),T.setFieldsValue({caseName:`from-curl-${((o=A.data)==null?void 0:o.method)||"GET"}-${(((n=A.data)==null?void 0:n.path)||"").replace(/\W+/g,"-")}`,caseGroup:"imported",envCode:j[0]||"default"}),w.setFieldsValue({mockName:`mock-${((L=A.data)==null?void 0:L.method)||"GET"}-${(((b=A.data)==null?void 0:b.path)||"").replace(/\W+/g,"-")}`,envCode:j[0]||"default",projectCode:"default",responseTemplate:`{
41
+ }`,style:{fontFamily:"monospace",fontSize:13}})})]})}]})})}),e.jsx(t.Drawer,{title:e.jsxs(t.Space,{children:[e.jsx(g.ExperimentOutlined,{}),"端点详情: ",E==null?void 0:E.mockCode]}),open:b,onClose:()=>F(!1),width:650,children:E&&e.jsxs("div",{children:[e.jsxs(t.Descriptions,{column:2,size:"small",bordered:!0,style:{marginBottom:16},children:[e.jsx(t.Descriptions.Item,{label:"编码",children:E.mockCode}),e.jsx(t.Descriptions.Item,{label:"名称",children:E.mockName}),e.jsx(t.Descriptions.Item,{label:"方法",children:e.jsx(t.Tag,{color:Xs[E.method],children:E.method})}),e.jsx(t.Descriptions.Item,{label:"环境",children:E.envCode}),e.jsx(t.Descriptions.Item,{label:"路径",span:2,children:E.path}),e.jsx(t.Descriptions.Item,{label:"状态码",children:E.statusCode}),e.jsxs(t.Descriptions.Item,{label:"延迟",children:[E.delayMs,"ms"]}),e.jsxs(t.Descriptions.Item,{label:"优先级",children:["P",E.priority]}),e.jsx(t.Descriptions.Item,{label:"命中",children:E.hitCount||0}),e.jsx(t.Descriptions.Item,{label:"故障",children:E.faultType&&E.faultType!=="NONE"?e.jsx(t.Tag,{color:"red",children:E.faultType}):e.jsx(ke,{type:"secondary",children:"-"})}),e.jsx(t.Descriptions.Item,{label:"场景",children:E.scenarioCode||"-"}),e.jsx(t.Descriptions.Item,{label:"状态",span:2,children:E.status===1?e.jsx(t.Tag,{color:"green",children:"启用"}):e.jsx(t.Tag,{children:"禁用"})}),e.jsx(t.Descriptions.Item,{label:"完整 URL",span:2,children:e.jsx(ke,{copyable:!0,children:Y(E)})})]}),e.jsx(tl,{strong:!0,children:"响应模板:"}),e.jsx("pre",{style:{background:"#f5f5f5",padding:12,borderRadius:4,maxHeight:350,overflow:"auto",fontSize:13,fontFamily:"monospace",whiteSpace:"pre-wrap",wordBreak:"break-all"},children:E.responseTemplate})]})}),e.jsx(Js,{open:C,onClose:()=>S(!1),onSuccess:()=>{t.message.success("已刷新列表"),w()}})]})}const{Text:$t}=t.Typography,ol=[{value:"MOCK",label:"MOCK (纯 Mock 拦截)",color:"green"},{value:"REAL",label:"REAL (全部代理到真实)",color:"blue"},{value:"MIXED",label:"MIXED (匹配失败时转发)",color:"orange"}],ll={MOCK:"green",REAL:"blue",MIXED:"orange"};function wt({onEnvChange:s}){const[r,n]=p.useState([]),[o,l]=p.useState(!1),[a,i]=p.useState(!1),[c,x]=p.useState(null),[h]=t.Form.useForm();p.useEffect(()=>{y()},[]);const y=async()=>{l(!0);try{const C=await J.environments.list();n(Array.isArray(C)?C:[])}catch(C){t.message.warning("加载环境列表失败: "+(C==null?void 0:C.message))}finally{l(!1)}},d=()=>{x(null),h.resetFields(),h.setFieldsValue({envType:"MOCK",isDefault:0,mockPriority:1}),i(!0)},b=C=>{x(C),h.setFieldsValue(C),i(!0)},F=async()=>{try{const C=await h.validateFields();c?(await J.environments.update(c.envCode,C),t.message.success("更新成功")):(await J.environments.create(C),t.message.success("创建成功")),i(!1),y()}catch(C){if(C!=null&&C.errorFields)return;t.message.error("保存失败")}},E=async C=>{try{await J.environments.delete(C),t.message.success("删除成功"),y()}catch(S){t.message.error("删除失败: "+((S==null?void 0:S.message)||""))}},_=[{title:"环境编码",dataIndex:"envCode",key:"envCode",width:140,render:C=>e.jsx($t,{code:!0,children:C})},{title:"环境名称",dataIndex:"envName",key:"envName",width:160},{title:"类型",dataIndex:"envType",key:"envType",width:240,render:C=>e.jsx(t.Tag,{color:ll[C]||"default",children:C})},{title:"真实服务地址",dataIndex:"baseUrl",key:"baseUrl",render:C=>C?e.jsx($t,{copyable:!0,children:C}):e.jsx($t,{type:"secondary",children:"-"})},{title:"默认",dataIndex:"isDefault",key:"isDefault",width:90,align:"center",render:C=>C===1?e.jsx(t.Tag,{color:"gold",children:"默认"}):"-"},{title:"描述",dataIndex:"description",key:"description",width:220,render:C=>C||"-"},{title:"操作",key:"action",width:180,render:(C,S)=>e.jsxs(t.Space,{size:"small",children:[e.jsx(t.Button,{size:"small",type:"link",icon:e.jsx(g.GlobalOutlined,{}),onClick:()=>{s&&s(S.envCode)},children:"切换"}),e.jsx(t.Button,{size:"small",type:"link",icon:e.jsx(g.EditOutlined,{}),onClick:()=>b(S)}),S.isDefault!==1&&e.jsx(t.Popconfirm,{title:`确认删除环境 ${S.envCode}?`,onConfirm:()=>E(S.envCode),children:e.jsx(t.Button,{size:"small",type:"link",danger:!0,icon:e.jsx(g.DeleteOutlined,{})})})]})}];return e.jsxs("div",{children:[e.jsx(t.Alert,{type:"info",showIcon:!0,style:{marginBottom:16},message:"环境隔离 - 控制 Mock 与真实服务的切换",description:e.jsxs("div",{children:[e.jsxs("div",{children:[e.jsx(t.Tag,{color:"green",children:"MOCK"})," 完全拦截,仅返回 Mock 数据"]}),e.jsxs("div",{children:[e.jsx(t.Tag,{color:"blue",children:"REAL"})," 全部代理到 baseUrl(适合压测、回归测试)"]}),e.jsxs("div",{children:[e.jsx(t.Tag,{color:"orange",children:"MIXED"})," Mock 优先,未匹配时转发到 baseUrl(开发联调)"]})]})}),e.jsxs(t.Space,{style:{marginBottom:16},children:[e.jsx(t.Button,{icon:e.jsx(g.ReloadOutlined,{}),onClick:y,children:"刷新"}),e.jsx(t.Button,{type:"primary",icon:e.jsx(g.PlusOutlined,{}),onClick:d,children:"新建环境"})]}),e.jsx(t.Table,{dataSource:r,columns:_,rowKey:"id",loading:o,pagination:{pageSize:10},size:"small"}),e.jsx(t.Modal,{title:c?`编辑环境: ${c.envCode}`:"新建环境",open:a,onCancel:()=>i(!1),onOk:F,width:650,children:e.jsxs(t.Form,{form:h,layout:"vertical",style:{marginTop:16},children:[e.jsxs(t.Row,{gutter:16,children:[e.jsx(t.Col,{span:12,children:e.jsx(t.Form.Item,{name:"envCode",label:"环境编码",rules:[{required:!0}],children:e.jsx(t.Input,{placeholder:"dev / staging / prod",disabled:!!c})})}),e.jsx(t.Col,{span:12,children:e.jsx(t.Form.Item,{name:"envName",label:"环境名称",rules:[{required:!0}],children:e.jsx(t.Input,{placeholder:"开发环境"})})})]}),e.jsx(t.Form.Item,{name:"envType",label:"环境类型",rules:[{required:!0}],children:e.jsx(t.Select,{options:ol})}),e.jsx(t.Form.Item,{name:"baseUrl",label:"真实服务地址",extra:"REAL/MIXED 时使用。MIXED 时未匹配的请求会转发到这里",children:e.jsx(t.Input,{placeholder:"https://api.staging.example.com"})}),e.jsxs(t.Row,{gutter:16,children:[e.jsx(t.Col,{span:12,children:e.jsx(t.Form.Item,{name:"mockPriority",label:"Mock 优先级",children:e.jsx(t.InputNumber,{min:0,max:10,style:{width:"100%"}})})}),e.jsx(t.Col,{span:12,children:e.jsx(t.Form.Item,{name:"isDefault",label:"是否默认",valuePropName:"checked",children:e.jsx(t.Switch,{checkedChildren:"是",unCheckedChildren:"否"})})})]}),e.jsx(t.Form.Item,{name:"description",label:"描述",children:e.jsx(t.Input.TextArea,{rows:3,placeholder:"环境的用途说明"})})]})})]})}const{Text:il}=t.Typography;function Ys(){const[s,r]=p.useState([]),[n,o]=p.useState(!1),[l,a]=p.useState(!1),[i,c]=p.useState(null),[x,h]=p.useState(!1),[y,d]=p.useState(null),[b]=t.Form.useForm();p.useEffect(()=>{F()},[]);const F=async()=>{o(!0);try{const k=await J.scenarios.list();r(Array.isArray(k)?k:[])}catch{t.message.warning("加载场景列表失败")}finally{o(!1)}},E=()=>{c(null),b.resetFields(),b.setFieldsValue({initialState:"started"}),a(!0)},_=k=>{c(k),b.setFieldsValue(k),a(!0)},C=async()=>{try{const k=await b.validateFields();let R;try{R=k.statesJson?JSON.parse(k.statesJson):null}catch{t.message.error("状态列表 JSON 格式错误");return}const H={...k,states:R};delete H.statesJson,i?(await J.scenarios.update(i.scenarioCode,H),t.message.success("更新成功")):(await J.scenarios.create(H),t.message.success("创建成功")),a(!1),F()}catch(k){k!=null&&k.errorFields||t.message.error("保存失败")}},S=async k=>{try{await J.scenarios.delete(k),t.message.success("删除成功"),F()}catch{t.message.error("删除失败")}},w=async k=>{try{await J.scenarios.reset(k),t.message.success("已重置所有实例状态")}catch{t.message.error("重置失败")}},T=async k=>{try{const R=await J.scenarios.instances(k);d({code:k,list:R}),h(!0)}catch{t.message.error("加载失败")}},A=[{title:"场景编码",dataIndex:"scenarioCode",key:"scenarioCode",width:160,render:k=>e.jsx(il,{code:!0,children:k})},{title:"场景名称",dataIndex:"scenarioName",key:"scenarioName",width:200},{title:"初始状态",dataIndex:"initialState",key:"initialState",width:140,render:k=>e.jsx(t.Tag,{color:"blue",children:k})},{title:"状态列表",dataIndex:"states",key:"states",render:k=>{if(!k)return"-";try{const R=typeof k=="string"?JSON.parse(k):k;return Array.isArray(R)?R.map(H=>e.jsx(t.Tag,{children:H},H)):"-"}catch{return"-"}}},{title:"描述",dataIndex:"description",key:"description",width:240,render:k=>k||"-"},{title:"操作",key:"action",width:280,fixed:"right",render:(k,R)=>e.jsxs(t.Space,{size:"small",children:[e.jsx(t.Button,{size:"small",type:"link",icon:e.jsx(g.NodeIndexOutlined,{}),onClick:()=>T(R.scenarioCode),children:"实例"}),e.jsx(t.Button,{size:"small",type:"link",icon:e.jsx(g.UndoOutlined,{}),onClick:()=>w(R.scenarioCode),children:"重置"}),e.jsx(t.Button,{size:"small",type:"link",icon:e.jsx(g.EditOutlined,{}),onClick:()=>_(R)}),e.jsx(t.Popconfirm,{title:`删除场景 ${R.scenarioCode}?`,onConfirm:()=>S(R.scenarioCode),children:e.jsx(t.Button,{size:"small",type:"link",danger:!0,icon:e.jsx(g.DeleteOutlined,{})})})]})}];return e.jsxs("div",{children:[e.jsx(t.Alert,{type:"info",showIcon:!0,style:{marginBottom:16},message:"场景状态机 (Scenario)",description:"用状态机驱动 Mock 集合,模拟完整业务流程(如:未登录→登录中→已登录→下单→已支付→完成)。实例通过 X-Session-Id 或 X-Trace-Id 区分,每个实例独立维护当前状态。"}),e.jsxs(t.Space,{style:{marginBottom:16},children:[e.jsx(t.Button,{icon:e.jsx(g.ReloadOutlined,{}),onClick:F,children:"刷新"}),e.jsx(t.Button,{type:"primary",icon:e.jsx(g.PlusOutlined,{}),onClick:E,children:"新建场景"})]}),e.jsx(t.Table,{dataSource:s,columns:A,rowKey:"id",loading:n,pagination:{pageSize:10},scroll:{x:1100},size:"small"}),e.jsx(t.Modal,{title:i?`编辑场景: ${i.scenarioCode}`:"新建场景",open:l,onCancel:()=>a(!1),onOk:C,width:650,children:e.jsxs(t.Form,{form:b,layout:"vertical",style:{marginTop:16},children:[e.jsxs(t.Row,{gutter:16,children:[e.jsx(t.Col,{span:12,children:e.jsx(t.Form.Item,{name:"scenarioCode",label:"场景编码",rules:[{required:!0}],children:e.jsx(t.Input,{placeholder:"user-login-flow",disabled:!!i})})}),e.jsx(t.Col,{span:12,children:e.jsx(t.Form.Item,{name:"scenarioName",label:"场景名称",children:e.jsx(t.Input,{placeholder:"用户登录流程"})})})]}),e.jsx(t.Form.Item,{name:"initialState",label:"初始状态",rules:[{required:!0}],children:e.jsx(t.Input,{placeholder:"started"})}),e.jsx(t.Form.Item,{name:"statesJson",label:"状态列表 (JSON 数组)",extra:'例: ["started", "logged-in", "checkout", "paid", "completed"]',children:e.jsx(t.Input.TextArea,{rows:3,placeholder:'["started", "logged-in", "checkout", "paid"]'})}),e.jsx(t.Form.Item,{name:"description",label:"描述",children:e.jsx(t.Input.TextArea,{rows:3,placeholder:"场景的业务说明"})})]})}),e.jsx(t.Modal,{title:`场景实例: ${y==null?void 0:y.code}`,open:x,onCancel:()=>h(!1),footer:e.jsx(t.Button,{onClick:()=>h(!1),children:"关闭"}),width:700,children:y&&e.jsx(t.Table,{dataSource:Array.isArray(y.list)?y.list:[],columns:[{title:"实例标识",dataIndex:"instanceKey",key:"instanceKey"},{title:"当前状态",dataIndex:"currentState",key:"currentState",render:k=>e.jsx(t.Tag,{color:"blue",children:k})},{title:"最后变更",dataIndex:"lastUpdateTime",key:"lastUpdateTime"}],rowKey:(k,R)=>k.instanceKey||R,pagination:!1,size:"small"})})]})}const{TextArea:Zs}=t.Input,{Text:We,Paragraph:al}=t.Typography;function Qs({open:s,onClose:r,onSuccess:n,envOptions:o=[]}){const[l,a]=p.useState(""),[i,c]=p.useState(null),[x,h]=p.useState(null),[y,d]=p.useState(!1),[b,F]=p.useState(null),[E,_]=p.useState(!1),[C,S]=p.useState("import"),[w]=t.Form.useForm(),[T]=t.Form.useForm(),A=()=>{a(""),c(null),h(null),F(null),w.resetFields(),T.resetFields()},k=()=>{A(),r()},R=async()=>{var m,f,z,P;if(!l.trim()){t.message.warning("请先粘贴 curl 命令");return}h(null),c(null),F(null);try{const D=await J.curl.parse(l);D.success?(c(D.data),w.setFieldsValue({caseName:`from-curl-${((m=D.data)==null?void 0:m.method)||"GET"}-${(((f=D.data)==null?void 0:f.path)||"").replace(/\W+/g,"-")}`,caseGroup:"imported",envCode:o[0]||"default"}),T.setFieldsValue({mockName:`mock-${((z=D.data)==null?void 0:z.method)||"GET"}-${(((P=D.data)==null?void 0:P.path)||"").replace(/\W+/g,"-")}`,envCode:o[0]||"default",projectCode:"default",responseTemplate:`{
34
42
  "code": 0,
35
43
  "message": "ok",
36
44
  "data": {}
37
- }`})):f(A.message||"解析失败")}catch(A){f(String((A==null?void 0:A.message)||A))}},U=async()=>{if(!I.trim()){s.message.warning("请先粘贴 curl 命令");return}m(!0),z(null);try{const o=await q.curl.run(I);z(o)}catch(o){z({success:!1,error:String((o==null?void 0:o.message)||o)})}finally{m(!1)}},J=async()=>{if(!d){s.message.warning("请先解析");return}let o;try{o=await T.validateFields()}catch{return}$(!0);try{const n=await q.curl.importAsCase({curl:I,caseName:o.caseName,caseGroup:o.caseGroup,envCode:o.envCode});n.success?(s.message.success(`已导入测试用例: ${n.caseCode}`),l&&l("case",n),S()):s.message.error(n.message||"导入失败")}catch(n){s.message.error(String((n==null?void 0:n.message)||n))}finally{$(!1)}},H=async()=>{if(!d){s.message.warning("请先解析");return}let o;try{o=await w.validateFields()}catch{return}$(!0);try{const n=await q.curl.importAsEndpoint({curl:I,mockName:o.mockName,envCode:o.envCode,projectCode:o.projectCode,responseTemplate:o.responseTemplate});n.success?(s.message.success(`已导入 Mock 端点: ${n.mockCode}`),l&&l("endpoint",n),S()):s.message.error(n.message||"导入失败")}catch(n){s.message.error(String((n==null?void 0:n.message)||n))}finally{$(!1)}};return e.jsxs(s.Modal,{title:e.jsxs(s.Space,{children:[e.jsx(i.CodeOutlined,{})," 粘贴 curl 一键导入"]}),open:t,onCancel:S,footer:null,width:900,destroyOnClose:!0,children:[e.jsx(At,{type:"secondary",style:{marginBottom:12},children:"从浏览器 DevTools / Postman / 终端复制 curl 命令,粘贴到下方即可解析、试跑、入库。"}),e.jsx(fs,{value:I,onChange:o=>C(o.target.value),placeholder:`curl -X POST 'https://api.example.com/v1/users/login' \\
45
+ }`})):h(D.message||"解析失败")}catch(D){h(String((D==null?void 0:D.message)||D))}},H=async()=>{if(!l.trim()){t.message.warning("请先粘贴 curl 命令");return}d(!0),F(null);try{const m=await J.curl.run(l);F(m)}catch(m){F({success:!1,error:String((m==null?void 0:m.message)||m)})}finally{d(!1)}},Y=async()=>{if(!i){t.message.warning("请先解析");return}let m;try{m=await w.validateFields()}catch{return}_(!0);try{const f=await J.curl.importAsCase({curl:l,caseName:m.caseName,caseGroup:m.caseGroup,envCode:m.envCode});f.success?(t.message.success(`已导入测试用例: ${f.caseCode}`),n&&n("case",f),k()):t.message.error(f.message||"导入失败")}catch(f){t.message.error(String((f==null?void 0:f.message)||f))}finally{_(!1)}},K=async()=>{if(!i){t.message.warning("请先解析");return}let m;try{m=await T.validateFields()}catch{return}_(!0);try{const f=await J.curl.importAsEndpoint({curl:l,mockName:m.mockName,envCode:m.envCode,projectCode:m.projectCode,responseTemplate:m.responseTemplate});f.success?(t.message.success(`已导入 Mock 端点: ${f.mockCode}`),n&&n("endpoint",f),k()):t.message.error(f.message||"导入失败")}catch(f){t.message.error(String((f==null?void 0:f.message)||f))}finally{_(!1)}};return e.jsxs(t.Modal,{title:e.jsxs(t.Space,{children:[e.jsx(g.CodeOutlined,{})," 粘贴 curl 一键导入"]}),open:s,onCancel:k,footer:null,width:900,destroyOnClose:!0,children:[e.jsx(al,{type:"secondary",style:{marginBottom:12},children:"从浏览器 DevTools / Postman / 终端复制 curl 命令,粘贴到下方即可解析、试跑、入库。"}),e.jsx(Zs,{value:l,onChange:m=>a(m.target.value),placeholder:`curl -X POST 'https://api.example.com/v1/users/login' \\
38
46
  -H 'Content-Type: application/json' \\
39
47
  -H 'Authorization: Bearer xxx' \\
40
- -d '{"username":"alice","password":"123456"}'`,autoSize:{minRows:4,maxRows:10},style:{fontFamily:"Menlo, Monaco, monospace",fontSize:12}}),e.jsxs(s.Space,{style:{marginTop:12},children:[e.jsx(s.Button,{icon:e.jsx(i.FileTextOutlined,{}),onClick:M,type:"primary",ghost:!0,children:"解析"}),e.jsx(s.Button,{icon:e.jsx(i.ThunderboltOutlined,{}),onClick:U,loading:O,children:"直接执行(试跑)"})]}),v&&e.jsx(s.Alert,{type:"error",showIcon:!0,style:{marginTop:12},message:"解析失败",description:v}),d&&e.jsx(s.Card,{size:"small",style:{marginTop:16},title:"解析结果",children:e.jsxs(s.Descriptions,{column:1,size:"small",bordered:!0,children:[e.jsx(s.Descriptions.Item,{label:"Method",children:e.jsx(s.Tag,{color:Dt(d.method),children:d.method})}),e.jsx(s.Descriptions.Item,{label:"URL",children:e.jsx(be,{code:!0,copyable:!0,children:d.url})}),e.jsx(s.Descriptions.Item,{label:"Path",children:e.jsx(be,{code:!0,children:d.path})}),d.query&&e.jsx(s.Descriptions.Item,{label:"Query",children:e.jsx(be,{code:!0,children:d.query})}),e.jsx(s.Descriptions.Item,{label:"Headers",children:Object.keys(d.headers||{}).length===0?e.jsx(be,{type:"secondary",children:"(无)"}):e.jsx("div",{children:Object.entries(d.headers).map(([o,n])=>e.jsxs("div",{children:[e.jsxs(be,{strong:!0,children:[o,":"]})," ",e.jsx(be,{code:!0,children:n})]},o))})}),d.body&&e.jsx(s.Descriptions.Item,{label:"Body",children:e.jsx("pre",{style:{background:"#f5f5f5",padding:8,margin:0,fontSize:12,maxHeight:200,overflow:"auto"},children:d.body})})]})}),h&&e.jsxs(s.Card,{size:"small",style:{marginTop:16},title:e.jsxs(s.Space,{children:[e.jsx(i.ThunderboltOutlined,{}),e.jsx("span",{children:"试跑结果"}),h.success?e.jsxs(s.Tag,{color:"green",children:[h.status," · ",h.durationMs,"ms · ",h.bodySize,"B"]}):e.jsx(s.Tag,{color:"red",children:"FAILED"})]}),children:[h.error&&e.jsx(s.Alert,{type:"error",showIcon:!0,message:h.error}),h.body!=null&&e.jsx("pre",{style:{background:"#f5f5f5",padding:8,margin:0,fontSize:12,maxHeight:240,overflow:"auto"},children:h.body})]}),d&&e.jsx(s.Tabs,{activeKey:E,onChange:N,style:{marginTop:16},items:[{key:"import",label:e.jsxs("span",{children:[e.jsx(i.ImportOutlined,{})," 导入为测试用例"]}),children:e.jsxs(s.Form,{form:T,layout:"vertical",children:[e.jsxs(s.Row,{gutter:16,children:[e.jsx(s.Col,{span:12,children:e.jsx(s.Form.Item,{name:"caseName",label:"用例名称",rules:[{required:!0}],children:e.jsx(s.Input,{})})}),e.jsx(s.Col,{span:6,children:e.jsx(s.Form.Item,{name:"caseGroup",label:"用例分组",children:e.jsx(s.Input,{})})}),e.jsx(s.Col,{span:6,children:e.jsx(s.Form.Item,{name:"envCode",label:"环境",children:j.length>0?e.jsx(s.Select,{options:j.map(o=>({value:o,label:o}))}):e.jsx(s.Input,{})})})]}),e.jsx(s.Button,{type:"primary",onClick:J,loading:y,icon:e.jsx(i.ImportOutlined,{}),children:"保存为测试用例"})]})},{key:"mock",label:e.jsxs("span",{children:[e.jsx(i.CodeOutlined,{})," 导入为 Mock 端点"]}),children:e.jsxs(s.Form,{form:w,layout:"vertical",children:[e.jsxs(s.Row,{gutter:16,children:[e.jsx(s.Col,{span:12,children:e.jsx(s.Form.Item,{name:"mockName",label:"Mock 名称",rules:[{required:!0}],children:e.jsx(s.Input,{})})}),e.jsx(s.Col,{span:6,children:e.jsx(s.Form.Item,{name:"envCode",label:"环境",children:j.length>0?e.jsx(s.Select,{options:j.map(o=>({value:o,label:o}))}):e.jsx(s.Input,{})})}),e.jsx(s.Col,{span:6,children:e.jsx(s.Form.Item,{name:"projectCode",label:"项目",children:e.jsx(s.Input,{})})})]}),e.jsx(s.Form.Item,{name:"responseTemplate",label:"响应模板 (JSON)",children:e.jsx(fs,{autoSize:{minRows:3,maxRows:8},style:{fontFamily:"Menlo, Monaco, monospace"}})}),e.jsx(s.Button,{type:"primary",onClick:H,loading:y,icon:e.jsx(i.CodeOutlined,{}),children:"保存为 Mock 端点"})]})}]})]})}function Dt(t){return{GET:"blue",POST:"green",PUT:"orange",DELETE:"red",PATCH:"purple"}[t]||"default"}const{Text:ye}=s.Typography,zt=[{value:"P0",label:"P0 (最高)"},{value:"P1",label:"P1 (高)"},{value:"P2",label:"P2 (中)"},{value:"P3",label:"P3 (低)"}],Mt={P0:"red",P1:"orange",P2:"blue",P3:"default"},We={PASS:"green",FAIL:"red",SKIP:"default"},Lt=[{value:"EXACT",label:"完全匹配"},{value:"CONTAINS",label:"包含"},{value:"REGEX",label:"正则"},{value:"JSONPATH",label:"JSONPath"}];function Ss(){const[t,a]=r.useState([]),[l,j]=r.useState(!1),[I,C]=r.useState([]),[d,g]=r.useState(!1),[v,f]=r.useState(null),[O,m]=r.useState(!1),[h,z]=r.useState(null),[y,$]=r.useState(null),[E,N]=r.useState(!1),[T,w]=r.useState(!1),[P]=s.Form.useForm();r.useEffect(()=>{S()},[]);const S=async()=>{j(!0);try{const b=await q.cases.list();a(Array.isArray(b)?b:[])}catch{s.message.warning("加载用例列表失败")}finally{j(!1)}},M=()=>{f(null),P.resetFields(),P.setFieldsValue({requestMethod:"GET",expectedStatus:200,priority:"P1",status:1,expectedBodyMatchType:"EXACT"}),g(!0)},U=b=>{f(b),P.setFieldsValue(b),g(!0)},J=async()=>{try{const b=await P.validateFields();let A;try{A=b.assertionsJson?JSON.parse(b.assertionsJson):null}catch{s.message.error("断言 JSON 格式错误");return}const V={...b,assertions:A};delete V.assertionsJson,v?(await q.cases.update(v.caseCode,V),s.message.success("更新成功")):(await q.cases.create(V),s.message.success("创建成功")),g(!1),S()}catch(b){b!=null&&b.errorFields||s.message.error("保存失败")}},H=async b=>{try{await q.cases.delete(b),s.message.success("删除成功"),S()}catch{s.message.error("删除失败")}},o=async b=>{try{const A=await q.cases.run(b.caseCode);z(A),m(!0),(A==null?void 0:A.status)==="PASS"?s.message.success("用例通过"):s.message.error("用例失败: "+((A==null?void 0:A.error)||(A==null?void 0:A.actualStatus))),S()}catch(A){s.message.error("执行失败: "+(A==null?void 0:A.message))}},n=async()=>{if(I.length===0){s.message.warning("请先选择用例");return}try{const b=await q.cases.runBatch(I);$(b),N(!0),s.message.success(`批量执行完成: ${b==null?void 0:b.pass} 通过, ${b==null?void 0:b.fail} 失败`),S()}catch{s.message.error("批量执行失败")}},L=[{title:"用例编码",dataIndex:"caseCode",key:"caseCode",width:180,render:b=>e.jsx(ye,{code:!0,children:b})},{title:"名称",dataIndex:"caseName",key:"caseName",width:220},{title:"分组",dataIndex:"caseGroup",key:"caseGroup",width:130,render:b=>b?e.jsx(s.Tag,{children:b}):"-"},{title:"方法",dataIndex:"requestMethod",key:"requestMethod",width:80,render:b=>e.jsx(s.Tag,{color:"blue",children:b})},{title:"路径",dataIndex:"requestUrl",key:"requestUrl",ellipsis:!0,render:b=>e.jsx(ye,{code:!0,children:b})},{title:"优先级",dataIndex:"priority",key:"priority",width:80,align:"center",render:b=>e.jsx(s.Tag,{color:Mt[b],children:b||"P1"})},{title:"上次结果",dataIndex:"lastRunResult",key:"lastRunResult",width:100,align:"center",render:b=>b?e.jsx(s.Tag,{color:We[b],children:b}):"-"},{title:"统计",key:"stats",width:130,align:"center",render:(b,A)=>e.jsxs(s.Space,{size:"small",children:[e.jsx(ye,{type:"success",children:A.passCount||0}),"/",e.jsx(ye,{type:"danger",children:A.failCount||0}),e.jsxs(ye,{type:"secondary",children:["(",A.runCount||0,")"]})]})},{title:"操作",key:"action",width:220,fixed:"right",render:(b,A)=>e.jsxs(s.Space,{size:"small",children:[e.jsx(s.Button,{size:"small",type:"link",icon:e.jsx(i.PlayCircleOutlined,{}),onClick:()=>o(A),children:"运行"}),e.jsx(s.Button,{size:"small",type:"link",icon:e.jsx(i.EditOutlined,{}),onClick:()=>U(A)}),e.jsx(s.Popconfirm,{title:`删除用例 ${A.caseCode}?`,onConfirm:()=>H(A.caseCode),children:e.jsx(s.Button,{size:"small",type:"link",danger:!0,icon:e.jsx(i.DeleteOutlined,{})})})]})}];return e.jsxs("div",{children:[e.jsx(s.Alert,{type:"info",showIcon:!0,style:{marginBottom:16},message:"测试用例库",description:"对 Mock 接口进行断言验证。支持 7 种断言类型:STATUS / HEADER / BODY / JSON_PATH / REGEX / SCHEMA / RESPONSE_TIME。支持单条运行与批量运行,自动统计通过/失败次数。"}),e.jsxs(s.Space,{style:{marginBottom:16},children:[e.jsx(s.Button,{icon:e.jsx(i.ReloadOutlined,{}),onClick:S,children:"刷新"}),e.jsx(s.Button,{type:"primary",icon:e.jsx(i.PlusOutlined,{}),onClick:M,children:"新建用例"}),e.jsx(s.Button,{icon:e.jsx(i.CodeOutlined,{}),onClick:()=>w(!0),children:"粘贴 curl 导入"}),e.jsxs(s.Button,{type:"primary",icon:e.jsx(i.PlayCircleOutlined,{}),onClick:n,disabled:I.length===0,children:["批量运行 (",I.length,")"]})]}),e.jsx(s.Table,{dataSource:t,columns:L,rowKey:"id",loading:l,rowSelection:{selectedRowKeys:I,onChange:C},pagination:{pageSize:10},scroll:{x:1300},size:"small"}),e.jsx(s.Modal,{title:v?`编辑用例: ${v.caseCode}`:"新建测试用例",open:d,onCancel:()=>g(!1),onOk:J,width:750,children:e.jsxs(s.Form,{form:P,layout:"vertical",style:{marginTop:16},children:[e.jsxs(s.Row,{gutter:16,children:[e.jsx(s.Col,{span:12,children:e.jsx(s.Form.Item,{name:"caseCode",label:"用例编码",rules:[{required:!0}],children:e.jsx(s.Input,{placeholder:"case-user-login",disabled:!!v})})}),e.jsx(s.Col,{span:12,children:e.jsx(s.Form.Item,{name:"caseName",label:"用例名称",children:e.jsx(s.Input,{placeholder:"用户登录成功用例"})})})]}),e.jsxs(s.Row,{gutter:16,children:[e.jsx(s.Col,{span:8,children:e.jsx(s.Form.Item,{name:"caseGroup",label:"用例分组",children:e.jsx(s.Input,{placeholder:"login"})})}),e.jsx(s.Col,{span:8,children:e.jsx(s.Form.Item,{name:"priority",label:"优先级",children:e.jsx(s.Select,{options:zt})})}),e.jsx(s.Col,{span:8,children:e.jsx(s.Form.Item,{name:"envCode",label:"环境",children:e.jsx(s.Input,{placeholder:"default"})})})]}),e.jsxs(s.Row,{gutter:16,children:[e.jsx(s.Col,{span:6,children:e.jsx(s.Form.Item,{name:"requestMethod",label:"方法",children:e.jsx(s.Select,{options:[{value:"GET",label:"GET"},{value:"POST",label:"POST"},{value:"PUT",label:"PUT"},{value:"DELETE",label:"DELETE"}]})})}),e.jsx(s.Col,{span:18,children:e.jsx(s.Form.Item,{name:"requestUrl",label:"请求 URL",rules:[{required:!0}],children:e.jsx(s.Input,{placeholder:"/api/mock/default/user/login"})})})]}),e.jsxs(s.Row,{gutter:16,children:[e.jsx(s.Col,{span:12,children:e.jsx(s.Form.Item,{name:"requestQuery",label:"查询参数",children:e.jsx(s.Input,{placeholder:"debug=true"})})}),e.jsx(s.Col,{span:12,children:e.jsx(s.Form.Item,{name:"expectedStatus",label:"期望状态码",children:e.jsx(s.Select,{options:[{value:200,label:"200 OK"},{value:201,label:"201 Created"},{value:400,label:"400 Bad Request"},{value:401,label:"401 Unauthorized"},{value:404,label:"404 Not Found"},{value:500,label:"500 Server Error"}]})})})]}),e.jsx(s.Form.Item,{name:"requestHeaders",label:"请求头 (JSON)",extra:'例: {"Authorization": "Bearer xxx"}',children:e.jsx(s.Input.TextArea,{rows:2,placeholder:'{"X-Trace-Id": "abc"}'})}),e.jsx(s.Form.Item,{name:"requestBody",label:"请求体",children:e.jsx(s.Input.TextArea,{rows:3,placeholder:'{"username":"test","password":"xxx"}'})}),e.jsx(s.Form.Item,{name:"expectedBodyMatchType",label:"Body 匹配方式",children:e.jsx(s.Select,{options:Lt})}),e.jsx(s.Form.Item,{name:"expectedBody",label:"期望 Body",children:e.jsx(s.Input.TextArea,{rows:3,placeholder:'{"code": 200, "success": true}'})}),e.jsx(s.Form.Item,{name:"assertionsJson",label:"断言列表 (JSON 数组)",extra:'例: [{"assertType":"STATUS","expected":200,"comparator":"EQUALS"}]',children:e.jsx(s.Input.TextArea,{rows:4,placeholder:'[{"assertType":"STATUS","expected":200}]'})}),e.jsx(s.Form.Item,{name:"description",label:"描述",children:e.jsx(s.Input.TextArea,{rows:2})})]})}),e.jsx(s.Drawer,{title:e.jsxs(s.Space,{children:[e.jsx(i.FileSearchOutlined,{}),"用例执行结果"]}),open:O,onClose:()=>m(!1),width:650,children:h&&e.jsxs("div",{children:[e.jsxs(s.Row,{gutter:16,style:{marginBottom:16},children:[e.jsx(s.Col,{span:8,children:e.jsx(s.Card,{children:e.jsx(s.Statistic,{title:"结果",value:h.status,valueStyle:{color:We[h.status]==="green"?"#52c41a":"#ff4d4f"}})})}),e.jsx(s.Col,{span:8,children:e.jsx(s.Card,{children:e.jsx(s.Statistic,{title:"实际状态码",value:h.actualStatus||"-"})})}),e.jsx(s.Col,{span:8,children:e.jsx(s.Card,{children:e.jsx(s.Statistic,{title:"耗时(ms)",value:h.durationMs||0})})})]}),e.jsxs(s.Descriptions,{column:1,size:"small",bordered:!0,style:{marginBottom:16},children:[e.jsx(s.Descriptions.Item,{label:"用例编码",children:h.caseCode}),e.jsx(s.Descriptions.Item,{label:"用例名称",children:h.caseName}),e.jsx(s.Descriptions.Item,{label:"错误信息",children:h.error||"-"})]}),h.assertionResults&&e.jsxs(e.Fragment,{children:[e.jsx(ye,{strong:!0,children:"断言详情:"}),e.jsx(s.Table,{style:{marginTop:8},dataSource:h.assertionResults,columns:[{title:"断言类型",dataIndex:"assertType",key:"assertType",width:110},{title:"表达式",dataIndex:"expression",key:"expression"},{title:"期望值",dataIndex:"expected",key:"expected"},{title:"实际值",dataIndex:"actual",key:"actual"},{title:"结果",dataIndex:"passed",key:"passed",width:80,render:b=>b?e.jsx(s.Tag,{color:"green",children:"PASS"}):e.jsx(s.Tag,{color:"red",children:"FAIL"})}],pagination:!1,size:"small"})]}),e.jsx(ye,{strong:!0,style:{marginTop:16,display:"block"},children:"响应体:"}),e.jsx("pre",{style:{background:"#f5f5f5",padding:12,borderRadius:4,maxHeight:250,overflow:"auto",fontSize:12,fontFamily:"monospace",whiteSpace:"pre-wrap",wordBreak:"break-all"},children:h.responseBody||"(empty)"})]})}),e.jsx(s.Modal,{title:`批量执行结果 (${(y==null?void 0:y.total)||0} 条)`,open:E,onCancel:()=>N(!1),footer:e.jsx(s.Button,{onClick:()=>N(!1),children:"关闭"}),width:800,children:y&&e.jsxs(e.Fragment,{children:[e.jsxs(s.Row,{gutter:16,style:{marginBottom:16},children:[e.jsx(s.Col,{span:6,children:e.jsx(s.Card,{children:e.jsx(s.Statistic,{title:"总数",value:y.total})})}),e.jsx(s.Col,{span:6,children:e.jsx(s.Card,{children:e.jsx(s.Statistic,{title:"通过",value:y.pass,valueStyle:{color:"#52c41a"}})})}),e.jsx(s.Col,{span:6,children:e.jsx(s.Card,{children:e.jsx(s.Statistic,{title:"失败",value:y.fail,valueStyle:{color:"#ff4d4f"}})})}),e.jsx(s.Col,{span:6,children:e.jsx(s.Card,{children:e.jsx(s.Statistic,{title:"通过率",value:`${y.total>0?Math.round(y.pass/y.total*100):0}%`})})})]}),e.jsx(s.Table,{dataSource:y.results||[],columns:[{title:"编码",dataIndex:"caseCode",key:"caseCode",width:180},{title:"名称",dataIndex:"caseName",key:"caseName"},{title:"结果",dataIndex:"status",key:"status",width:80,render:b=>e.jsx(s.Tag,{color:We[b],children:b})},{title:"耗时",dataIndex:"durationMs",key:"durationMs",width:80,align:"center"},{title:"错误",dataIndex:"error",key:"error",ellipsis:!0}],pagination:!1,size:"small",rowKey:"caseCode"})]})}),e.jsx(Cs,{open:T,onClose:()=>w(!1),onSuccess:(b,A)=>{s.message.success(b==="case"?"测试用例已导入,正在刷新列表":"Mock 端点已导入"),S()}})]})}const{Text:pe}=s.Typography,bs={IDLE:"default",RECORDING:"red",STOPPED:"green",EXPIRED:"gray"};function Ts(){const[t,a]=r.useState([]),[l,j]=r.useState(!1),[I,C]=r.useState(!1),[d,g]=r.useState(!1),[v,f]=r.useState(!1),[O,m]=r.useState(!1),[h,z]=r.useState(null),[y,$]=r.useState([]),[E]=s.Form.useForm(),[N]=s.Form.useForm(),[T]=s.Form.useForm(),[w,P]=r.useState([]),[S,M]=r.useState(!1),[U,J]=r.useState([]);r.useEffect(()=>{H()},[]);const H=async()=>{j(!0);try{const k=await q.recordings.list();a(Array.isArray(k)?k:[])}catch{s.message.warning("加载录制列表失败")}finally{j(!1)}},o=async()=>{try{const k=await E.validateFields();await q.recordings.start(k.recordingCode,k.recordingName,k.targetUrl),s.message.success("录制已开启"),C(!1),E.resetFields(),H()}catch(k){k!=null&&k.errorFields||s.message.error("开启失败")}},n=async k=>{try{await q.recordings.stop(k),s.message.success("录制已停止"),H()}catch{s.message.error("停止失败")}},L=async k=>{try{await q.recordings.delete(k),s.message.success("删除成功"),H()}catch{s.message.error("删除失败")}},b=async k=>{try{const p=await q.recordings.requests(k.recordingCode);z(k),$(Array.isArray(p)?p:[]),m(!0)}catch{s.message.error("加载失败")}},A=async k=>{s.Modal.confirm({title:"导入录制为 Mock",content:`将把录制 "${k.recordingCode}" 转换为 Mock endpoints 并入库。`,okText:"确认导入",onOk:async()=>{try{const p=await q.recordings.import(k.recordingCode,"default");s.message.success(`导入成功: ${(p==null?void 0:p.imported)||0} 个 Mock endpoint`)}catch{s.message.error("导入失败")}}})},V=async()=>{var k,p,c;try{const D=await N.validateFields(),R=await q.recordings.playback(h.recordingCode,D.targetUrl);s.Modal.info({title:"回放结果",width:700,content:e.jsxs("div",{children:[e.jsxs(pe,{children:["总数: ",((k=R==null?void 0:R[0])==null?void 0:k.total)||0," 通过: ",((p=R==null?void 0:R[0])==null?void 0:p.pass)||0," 失败: ",((c=R==null?void 0:R[0])==null?void 0:c.fail)||0]}),e.jsx("pre",{style:{marginTop:12,background:"#f5f5f5",padding:12,maxHeight:400,overflow:"auto",fontSize:12},children:JSON.stringify(R,null,2)})]})}),g(!1)}catch(D){D!=null&&D.errorFields||s.message.error("回放失败")}},re=async()=>{try{M(!0);const k=await T.validateFields().catch(()=>({})),p=await q.recordings.export(h.recordingCode,k==null?void 0:k.projectCode),c=Array.isArray(p==null?void 0:p.drafts)?p.drafts:[];P(c),J(c.map(D=>D.mockCode||D.id)),f(!0)}catch(k){k!=null&&k.errorFields||s.message.error("生成草稿失败")}finally{M(!1)}},ae=async()=>{try{const k=await T.validateFields().catch(()=>({})),p=U;if(p.length===0){s.message.warning("请至少选择一个 Mock");return}const c=await q.recordings.import(h.recordingCode,k==null?void 0:k.envCode,k==null?void 0:k.projectCode);s.message.success(`已导入 ${(c==null?void 0:c.imported)||p.length} 个 Mock`),f(!1),H()}catch(k){s.message.error("导入失败:"+((k==null?void 0:k.message)||"未知错误"))}},oe=[{title:"编码",dataIndex:"recordingCode",key:"recordingCode",width:180,render:k=>e.jsx(pe,{code:!0,children:k})},{title:"名称",dataIndex:"recordingName",key:"recordingName",width:200},{title:"状态",dataIndex:"recordStatus",key:"recordStatus",width:110,render:k=>e.jsx(s.Tag,{color:bs[k],children:k})},{title:"请求数",dataIndex:"totalRequests",key:"totalRequests",width:90,align:"center"},{title:"目标 URL",dataIndex:"targetUrl",key:"targetUrl",ellipsis:!0,render:k=>k?e.jsx(pe,{copyable:{text:k},children:k}):"-"},{title:"开始时间",dataIndex:"startTime",key:"startTime",width:170},{title:"结束时间",dataIndex:"endTime",key:"endTime",width:170},{title:"操作",key:"action",width:280,fixed:"right",render:(k,p)=>e.jsxs(s.Space,{size:"small",children:[e.jsx(s.Button,{size:"small",type:"link",icon:e.jsx(i.VideoCameraOutlined,{}),onClick:()=>b(p),children:"详情"}),p.recordStatus==="RECORDING"&&e.jsx(s.Button,{size:"small",type:"link",danger:!0,icon:e.jsx(i.StopOutlined,{}),onClick:()=>n(p.recordingCode),children:"停止"}),p.recordStatus==="STOPPED"&&e.jsx(s.Button,{size:"small",type:"link",icon:e.jsx(i.ImportOutlined,{}),onClick:()=>A(p),children:"导入为 Mock"}),e.jsx(s.Popconfirm,{title:`删除录制 ${p.recordingCode}?`,onConfirm:()=>L(p.recordingCode),children:e.jsx(s.Button,{size:"small",type:"link",danger:!0,icon:e.jsx(i.DeleteOutlined,{})})})]})}];return e.jsxs("div",{children:[e.jsx(s.Alert,{type:"info",showIcon:!0,style:{marginBottom:16},message:"流量录制与回放",description:e.jsxs("div",{children:[e.jsxs("div",{children:["• 开启录制后,所有 ",e.jsx(pe,{code:!0,children:"/api/mock/{envCode}/**"})," 请求会被捕获到数据库"]}),e.jsx("div",{children:"• 停止录制后,可一键转为 Mock endpoints(用于离线测试)"}),e.jsx("div",{children:"• 支持回放录制到目标服务(验证录制有效 / 跨环境验证)"})]})}),e.jsxs(s.Space,{style:{marginBottom:16},children:[e.jsx(s.Button,{icon:e.jsx(i.ReloadOutlined,{}),onClick:H,children:"刷新"}),e.jsx(s.Button,{type:"primary",icon:e.jsx(i.VideoCameraOutlined,{}),onClick:()=>C(!0),children:"开启录制"})]}),e.jsx(s.Table,{dataSource:t,columns:oe,rowKey:"id",loading:l,pagination:{pageSize:10},scroll:{x:1300},size:"small"}),e.jsx(s.Modal,{title:"开启录制",open:I,onCancel:()=>C(!1),onOk:o,okText:"开启",cancelText:"取消",children:e.jsxs(s.Form,{form:E,layout:"vertical",style:{marginTop:16},children:[e.jsx(s.Form.Item,{name:"recordingCode",label:"录制编码",rules:[{required:!0}],children:e.jsx(s.Input,{placeholder:"prod-trace-2026-06"})}),e.jsx(s.Form.Item,{name:"recordingName",label:"录制名称",rules:[{required:!0}],children:e.jsx(s.Input,{placeholder:"生产环境订单流程"})}),e.jsx(s.Form.Item,{name:"targetUrl",label:"目标服务地址",children:e.jsx(s.Input,{placeholder:"http://prod-api.example.com"})})]})}),e.jsx(s.Drawer,{title:e.jsxs(s.Space,{children:[e.jsx(i.VideoCameraOutlined,{}),"录制详情: ",h==null?void 0:h.recordingCode]}),open:O,onClose:()=>m(!1),width:800,children:h&&e.jsxs("div",{children:[e.jsxs(s.Descriptions,{column:2,size:"small",bordered:!0,style:{marginBottom:16},children:[e.jsx(s.Descriptions.Item,{label:"编码",children:h.recordingCode}),e.jsx(s.Descriptions.Item,{label:"名称",children:h.recordingName}),e.jsx(s.Descriptions.Item,{label:"状态",children:e.jsx(s.Tag,{color:bs[h.recordStatus],children:h.recordStatus})}),e.jsx(s.Descriptions.Item,{label:"请求数",children:h.totalRequests}),e.jsx(s.Descriptions.Item,{label:"目标 URL",span:2,children:e.jsx(pe,{copyable:!0,children:h.targetUrl})}),e.jsx(s.Descriptions.Item,{label:"开始",children:h.startTime}),e.jsx(s.Descriptions.Item,{label:"结束",children:h.endTime||"(录制中)"})]}),e.jsxs(s.Space,{style:{marginBottom:16},children:[e.jsx(s.Button,{icon:e.jsx(i.PlayCircleOutlined,{}),onClick:()=>g(!0),disabled:h.recordStatus!=="STOPPED",children:"回放"}),e.jsx(s.Button,{icon:e.jsx(i.ExportOutlined,{}),onClick:re,loading:S,disabled:h.recordStatus!=="STOPPED",children:"导出 Mock 草稿"}),e.jsx(s.Button,{type:"primary",icon:e.jsx(i.ImportOutlined,{}),onClick:()=>A(h),disabled:h.recordStatus!=="STOPPED",children:"导入为 Mock"})]}),e.jsxs(pe,{strong:!0,children:["请求列表 (共 ",y.length," 条):"]}),e.jsx(s.Table,{style:{marginTop:8},dataSource:y,columns:[{title:"#",dataIndex:"sequence",key:"sequence",width:50},{title:"方法",dataIndex:"requestMethod",key:"requestMethod",width:80,render:k=>e.jsx(s.Tag,{color:"blue",children:k})},{title:"URL",dataIndex:"requestUrl",key:"requestUrl",ellipsis:!0,render:k=>e.jsx(pe,{code:!0,children:k})},{title:"响应",dataIndex:"responseStatus",key:"responseStatus",width:80,render:k=>e.jsx(s.Tag,{color:k>=400?"red":"green",children:k})},{title:"耗时",dataIndex:"responseTime",key:"responseTime",width:80,render:k=>`${k||0}ms`}],pagination:{pageSize:10},size:"small",rowKey:"id"})]})}),e.jsx(s.Modal,{title:"回放录制",open:d,onCancel:()=>g(!1),onOk:V,children:e.jsx(s.Form,{form:N,layout:"vertical",style:{marginTop:16},children:e.jsx(s.Form.Item,{name:"targetUrl",label:"目标服务地址",rules:[{required:!0}],children:e.jsx(s.Input,{placeholder:"http://staging-api.example.com"})})})}),e.jsxs(s.Modal,{title:"导出 Mock 草稿",open:v,onCancel:()=>f(!1),onOk:ae,okText:`导入 ${U.length} 个`,width:900,children:[e.jsx(s.Form,{form:T,layout:"vertical",style:{marginTop:8},children:e.jsxs(s.Space,{size:16,style:{width:"100%"},children:[e.jsx(s.Form.Item,{name:"projectCode",label:"项目编码",style:{flex:1,marginBottom:8},children:e.jsx(s.Input,{placeholder:"default"})}),e.jsx(s.Form.Item,{name:"envCode",label:"目标环境",style:{flex:1,marginBottom:8},children:e.jsx(s.Input,{placeholder:"default"})})]})}),e.jsx(s.Alert,{type:"info",showIcon:!0,style:{marginBottom:12},message:`从录制中识别出 ${w.length} 个去重后的 Mock endpoint,已默认全选`}),e.jsx(s.Table,{size:"small",dataSource:w,rowKey:k=>k.mockCode||k.id,pagination:{pageSize:8},scroll:{y:300},rowSelection:{selectedRowKeys:U,onChange:k=>J(k)},columns:[{title:"方法",dataIndex:"method",width:80,render:k=>e.jsx(s.Tag,{color:"blue",children:k})},{title:"URL 模式",dataIndex:"urlPattern",ellipsis:!0,render:k=>e.jsx(pe,{code:!0,children:k})},{title:"状态码",dataIndex:"statusCode",width:80},{title:"响应模板",dataIndex:"responseTemplate",ellipsis:!0,render:k=>e.jsx(pe,{type:"secondary",style:{fontSize:11},children:(k||"").slice(0,80)})},{title:"请求数",dataIndex:"requestCount",width:80,align:"center"}]})]})]})}const{Text:Te}=s.Typography,_t={MOCK:"green",PROXY:"blue",404:"red",502:"orange"};function ws(){const[t,a]=r.useState([]),[l,j]=r.useState(null),[I,C]=r.useState(!1),[d,g]=r.useState(null),[v,f]=r.useState(!1),[O,m]=r.useState(""),[h,z]=r.useState();r.useEffect(()=>{y()},[]);const y=async()=>{C(!0);try{const[T,w]=await Promise.all([q.requestLogs.list({path:O||void 0,matched:h,limit:100}),q.requestLogs.stats().catch(()=>null)]);a(Array.isArray(T)?T:[]),j(w)}catch{s.message.warning("加载失败")}finally{C(!1)}},$=T=>{g(T),f(!0)},E=async()=>{try{await q.requestLogs.clear(1e3),s.message.success("已清理"),y()}catch{s.message.error("清理失败")}},N=[{title:"时间",dataIndex:"createTime",key:"createTime",width:170,render:T=>T?new Date(T).toLocaleString():"-"},{title:"环境",dataIndex:"envCode",key:"envCode",width:100,render:T=>e.jsx(s.Tag,{children:T})},{title:"方法",dataIndex:"requestMethod",key:"requestMethod",width:80,render:T=>e.jsx(s.Tag,{color:"blue",children:T})},{title:"路径",dataIndex:"requestPath",key:"requestPath",ellipsis:!0,render:T=>e.jsx(Te,{code:!0,children:T})},{title:"状态",dataIndex:"responseStatus",key:"responseStatus",width:90,align:"center",render:T=>T?e.jsx(s.Tag,{color:T>=400?"red":"green",children:T}):"-"},{title:"匹配",dataIndex:"matched",key:"matched",width:90,align:"center",render:T=>T===1?e.jsx(s.Tag,{color:"green",children:"命中"}):e.jsx(s.Tag,{color:"red",children:"未匹配"})},{title:"回退",dataIndex:"fallbackType",key:"fallbackType",width:100,render:T=>T?e.jsx(s.Tag,{color:_t[T],children:T}):"-"},{title:"耗时",dataIndex:"durationMs",key:"durationMs",width:80,align:"center",render:T=>`${T||0}ms`},{title:"Mock",dataIndex:"mockCode",key:"mockCode",width:160,ellipsis:!0,render:T=>T?e.jsx(Te,{code:!0,children:T}):"-"},{title:"操作",key:"action",width:80,render:(T,w)=>e.jsx(s.Button,{size:"small",type:"link",icon:e.jsx(i.EyeOutlined,{}),onClick:()=>$(w),children:"详情"})}];return e.jsxs("div",{children:[e.jsx(s.Alert,{type:"info",showIcon:!0,style:{marginBottom:16},message:"Mock 请求日志 - 排查未匹配请求",description:"每一次请求都会留痕。包括请求/响应体、是否匹配 Mock、回退类型、耗时、场景状态等。便于排查“为什么这个请求没有 Mock 命中”问题。"}),l&&e.jsxs(s.Row,{gutter:16,style:{marginBottom:16},children:[e.jsx(s.Col,{span:6,children:e.jsx(s.Card,{children:e.jsx(s.Statistic,{title:"总请求数",value:l.total||0})})}),e.jsx(s.Col,{span:6,children:e.jsx(s.Card,{children:e.jsx(s.Statistic,{title:"Mock 命中",value:l.matched||0,valueStyle:{color:"#52c41a"}})})}),e.jsx(s.Col,{span:6,children:e.jsx(s.Card,{children:e.jsx(s.Statistic,{title:"未匹配",value:l.unmatched||0,valueStyle:{color:"#ff4d4f"}})})}),e.jsx(s.Col,{span:6,children:e.jsx(s.Card,{children:e.jsx(s.Statistic,{title:"命中率",value:`${l.total>0?Math.round(l.matched/l.total*100):0}%`})})})]}),e.jsxs(s.Space,{style:{marginBottom:16},children:[e.jsx(s.Input,{placeholder:"搜索路径",prefix:e.jsx(i.SearchOutlined,{}),allowClear:!0,style:{width:240},value:O,onChange:T=>m(T.target.value),onPressEnter:y}),e.jsx(s.Select,{placeholder:"匹配状态",allowClear:!0,style:{width:140},value:h,onChange:z,options:[{value:1,label:"已命中"},{value:0,label:"未匹配"}]}),e.jsx(s.Button,{icon:e.jsx(i.ReloadOutlined,{}),onClick:y,children:"查询"}),e.jsx(s.Popconfirm,{title:"确认清理,保留最近 1000 条?",onConfirm:E,children:e.jsx(s.Button,{icon:e.jsx(i.DeleteOutlined,{}),danger:!0,children:"清理"})})]}),e.jsx(s.Table,{dataSource:t,columns:N,rowKey:"id",loading:I,pagination:{pageSize:20},scroll:{x:1300},size:"small"}),e.jsx(s.Drawer,{title:"请求详情",open:v,onClose:()=>f(!1),width:750,children:d&&e.jsxs("div",{children:[e.jsxs(s.Descriptions,{column:2,size:"small",bordered:!0,style:{marginBottom:16},children:[e.jsx(s.Descriptions.Item,{label:"环境",children:d.envCode}),e.jsx(s.Descriptions.Item,{label:"方法",children:e.jsx(s.Tag,{color:"blue",children:d.requestMethod})}),e.jsx(s.Descriptions.Item,{label:"路径",span:2,children:e.jsx(Te,{code:!0,children:d.requestPath})}),e.jsx(s.Descriptions.Item,{label:"状态码",children:e.jsx(s.Tag,{color:d.responseStatus>=400?"red":"green",children:d.responseStatus})}),e.jsxs(s.Descriptions.Item,{label:"耗时",children:[d.durationMs,"ms"]}),e.jsx(s.Descriptions.Item,{label:"匹配",children:d.matched===1?e.jsx(s.Tag,{color:"green",children:"命中"}):e.jsx(s.Tag,{color:"red",children:"未匹配"})}),e.jsx(s.Descriptions.Item,{label:"回退",children:d.fallbackType||"-"}),e.jsx(s.Descriptions.Item,{label:"Mock",span:2,children:d.mockCode||"-"}),e.jsx(s.Descriptions.Item,{label:"场景状态",span:2,children:d.scenarioState||"-"}),e.jsx(s.Descriptions.Item,{label:"客户端 IP",children:d.clientIp||"-"}),e.jsx(s.Descriptions.Item,{label:"User-Agent",ellipsis:!0,children:d.userAgent||"-"}),e.jsx(s.Descriptions.Item,{label:"时间",span:2,children:d.createTime?new Date(d.createTime).toLocaleString():"-"})]}),e.jsx(Te,{strong:!0,children:"请求头:"}),e.jsx("pre",{style:{background:"#f5f5f5",padding:12,borderRadius:4,maxHeight:150,overflow:"auto",fontSize:12,fontFamily:"monospace",whiteSpace:"pre-wrap"},children:d.requestHeaders||"(无)"}),e.jsx(Te,{strong:!0,style:{marginTop:12,display:"block"},children:"请求体:"}),e.jsx("pre",{style:{background:"#f5f5f5",padding:12,borderRadius:4,maxHeight:200,overflow:"auto",fontSize:12,fontFamily:"monospace",whiteSpace:"pre-wrap",wordBreak:"break-all"},children:d.requestBody||"(无)"}),e.jsx(Te,{strong:!0,style:{marginTop:12,display:"block"},children:"响应体:"}),e.jsx("pre",{style:{background:"#f5f5f5",padding:12,borderRadius:4,maxHeight:300,overflow:"auto",fontSize:12,fontFamily:"monospace",whiteSpace:"pre-wrap",wordBreak:"break-all"},children:d.responseBody||"(无)"})]})})]})}const{Text:ie}=s.Typography,Is=[{key:"endpoints",label:"Mock 端点",component:ze},{key:"environments",label:"环境 (MOCK/REAL/MIXED)",component:Me},{key:"scenarios",label:"场景状态机",component:ys},{key:"cases",label:"测试用例",component:Ss},{key:"recordings",label:"录制回放",component:Ts},{key:"request-logs",label:"请求日志",component:ws}];function Bt(){var O;const[t,a]=r.useState("endpoints"),[l,j]=r.useState([]),[I,C]=r.useState("default"),[d,g]=r.useState(null);r.useEffect(()=>{v(),f()},[]);const v=async()=>{try{const m=await q.environments.list(),h=Array.isArray(m)?m:[];if(j(h),h.length>0&&!h.find(z=>z.envCode===I)){const z=h.find(y=>y.isDefault===1)||h[0];C(z.envCode)}}catch{}},f=async()=>{try{const m=await q.stats();g(m)}catch{}};return(O=Is.find(m=>m.key===t))==null||O.component,e.jsxs("div",{children:[e.jsx(s.Card,{style:{marginBottom:16},bodyStyle:{padding:16},children:e.jsxs(s.Space,{size:"large",wrap:!0,children:[e.jsxs(s.Space,{children:[e.jsx(i.DashboardOutlined,{style:{fontSize:18,color:"#1890ff"}}),e.jsx(ie,{strong:!0,style:{fontSize:16},children:"Mock 平台"}),e.jsx(s.Tag,{color:"blue",children:"WireMock 级"})]}),e.jsxs(s.Space,{children:[e.jsx(i.GlobalOutlined,{}),e.jsx(ie,{children:"当前环境:"}),e.jsx(s.Select,{value:I,onChange:C,style:{width:200},options:l.map(m=>({value:m.envCode,label:`${m.envName||m.envCode} (${m.envType})`}))})]}),d&&e.jsxs(s.Space,{size:"large",children:[e.jsxs(ie,{type:"secondary",children:["端点: ",e.jsx(ie,{strong:!0,children:d.totalEndpoints})]}),e.jsxs(ie,{type:"secondary",children:["启用: ",e.jsx(ie,{strong:!0,style:{color:"#52c41a"},children:d.activeEndpoints})]}),e.jsxs(ie,{type:"secondary",children:["场景: ",e.jsx(ie,{strong:!0,children:d.totalScenarios})]}),e.jsxs(ie,{type:"secondary",children:["用例: ",e.jsx(ie,{strong:!0,children:d.totalCases})]})]}),e.jsx(s.Button,{icon:e.jsx(i.ReloadOutlined,{}),onClick:()=>{v(),f()},children:"刷新"})]})}),e.jsx(s.Tabs,{activeKey:t,onChange:a,type:"card",items:Is.map(m=>({key:m.key,label:m.label,children:m.component===ze?e.jsx(ze,{activeEnvCode:I}):m.component===Me?e.jsx(Me,{onEnvChange:h=>{C(h),s.message.success(`已切换到环境: ${h}`)}}):e.jsx(m.component,{})}))})]})}const $t=common;B.AgentTeamIM=nt,B.AppLayout=Ds,B.CtcAuthPage=st,B.CtcLayout=Xs,B.CtcLogin=lt,B.CurlImportModal=Cs,B.EndpointsTab=ze,B.EnvironmentsTab=Me,B.ErrorBoundary=_s,B.LoginPage=Ls,B.LowCodeModel=as,B.LowCodePage=bt,B.LowCodeRuntime=ds,B.MaterializePage=wt,B.MockPlatform=Bt,B.MockTemplateHelper=gs,B.OpenApiImportModal=xs,B.Overview=Rs,B.RecordingsTab=Ts,B.RequestLogsTab=ws,B.ScenariosTab=ys,B.StatusTag=zs,B.TestCasesTab=Ss,B.UCLayout=mt,B.UCLogin=xt,B.UCPhoneLogin=ht,B.UCRegister=gt,B.UCResetPassword=jt,B.UserPanel=it,B.Webide=dt,B.authRequest=Ue,B.createRequest=Re,B.ctcRequest=Us,B.default=$t,B.defaultStatusMap=es,B.request=Y,B.setupInterceptors=ss,Object.defineProperties(B,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
48
+ -d '{"username":"alice","password":"123456"}'`,autoSize:{minRows:4,maxRows:10},style:{fontFamily:"Menlo, Monaco, monospace",fontSize:12}}),e.jsxs(t.Space,{style:{marginTop:12},children:[e.jsx(t.Button,{icon:e.jsx(g.FileTextOutlined,{}),onClick:R,type:"primary",ghost:!0,children:"解析"}),e.jsx(t.Button,{icon:e.jsx(g.ThunderboltOutlined,{}),onClick:H,loading:y,children:"直接执行(试跑)"})]}),x&&e.jsx(t.Alert,{type:"error",showIcon:!0,style:{marginTop:12},message:"解析失败",description:x}),i&&e.jsx(t.Card,{size:"small",style:{marginTop:16},title:"解析结果",children:e.jsxs(t.Descriptions,{column:1,size:"small",bordered:!0,children:[e.jsx(t.Descriptions.Item,{label:"Method",children:e.jsx(t.Tag,{color:cl(i.method),children:i.method})}),e.jsx(t.Descriptions.Item,{label:"URL",children:e.jsx(We,{code:!0,copyable:!0,children:i.url})}),e.jsx(t.Descriptions.Item,{label:"Path",children:e.jsx(We,{code:!0,children:i.path})}),i.query&&e.jsx(t.Descriptions.Item,{label:"Query",children:e.jsx(We,{code:!0,children:i.query})}),e.jsx(t.Descriptions.Item,{label:"Headers",children:Object.keys(i.headers||{}).length===0?e.jsx(We,{type:"secondary",children:"(无)"}):e.jsx("div",{children:Object.entries(i.headers).map(([m,f])=>e.jsxs("div",{children:[e.jsxs(We,{strong:!0,children:[m,":"]})," ",e.jsx(We,{code:!0,children:f})]},m))})}),i.body&&e.jsx(t.Descriptions.Item,{label:"Body",children:e.jsx("pre",{style:{background:"#f5f5f5",padding:8,margin:0,fontSize:12,maxHeight:200,overflow:"auto"},children:i.body})})]})}),b&&e.jsxs(t.Card,{size:"small",style:{marginTop:16},title:e.jsxs(t.Space,{children:[e.jsx(g.ThunderboltOutlined,{}),e.jsx("span",{children:"试跑结果"}),b.success?e.jsxs(t.Tag,{color:"green",children:[b.status," · ",b.durationMs,"ms · ",b.bodySize,"B"]}):e.jsx(t.Tag,{color:"red",children:"FAILED"})]}),children:[b.error&&e.jsx(t.Alert,{type:"error",showIcon:!0,message:b.error}),b.body!=null&&e.jsx("pre",{style:{background:"#f5f5f5",padding:8,margin:0,fontSize:12,maxHeight:240,overflow:"auto"},children:b.body})]}),i&&e.jsx(t.Tabs,{activeKey:C,onChange:S,style:{marginTop:16},items:[{key:"import",label:e.jsxs("span",{children:[e.jsx(g.ImportOutlined,{})," 导入为测试用例"]}),children:e.jsxs(t.Form,{form:w,layout:"vertical",children:[e.jsxs(t.Row,{gutter:16,children:[e.jsx(t.Col,{span:12,children:e.jsx(t.Form.Item,{name:"caseName",label:"用例名称",rules:[{required:!0}],children:e.jsx(t.Input,{})})}),e.jsx(t.Col,{span:6,children:e.jsx(t.Form.Item,{name:"caseGroup",label:"用例分组",children:e.jsx(t.Input,{})})}),e.jsx(t.Col,{span:6,children:e.jsx(t.Form.Item,{name:"envCode",label:"环境",children:o.length>0?e.jsx(t.Select,{options:o.map(m=>({value:m,label:m}))}):e.jsx(t.Input,{})})})]}),e.jsx(t.Button,{type:"primary",onClick:Y,loading:E,icon:e.jsx(g.ImportOutlined,{}),children:"保存为测试用例"})]})},{key:"mock",label:e.jsxs("span",{children:[e.jsx(g.CodeOutlined,{})," 导入为 Mock 端点"]}),children:e.jsxs(t.Form,{form:T,layout:"vertical",children:[e.jsxs(t.Row,{gutter:16,children:[e.jsx(t.Col,{span:12,children:e.jsx(t.Form.Item,{name:"mockName",label:"Mock 名称",rules:[{required:!0}],children:e.jsx(t.Input,{})})}),e.jsx(t.Col,{span:6,children:e.jsx(t.Form.Item,{name:"envCode",label:"环境",children:o.length>0?e.jsx(t.Select,{options:o.map(m=>({value:m,label:m}))}):e.jsx(t.Input,{})})}),e.jsx(t.Col,{span:6,children:e.jsx(t.Form.Item,{name:"projectCode",label:"项目",children:e.jsx(t.Input,{})})})]}),e.jsx(t.Form.Item,{name:"responseTemplate",label:"响应模板 (JSON)",children:e.jsx(Zs,{autoSize:{minRows:3,maxRows:8},style:{fontFamily:"Menlo, Monaco, monospace"}})}),e.jsx(t.Button,{type:"primary",onClick:K,loading:E,icon:e.jsx(g.CodeOutlined,{}),children:"保存为 Mock 端点"})]})}]})]})}function cl(s){return{GET:"blue",POST:"green",PUT:"orange",DELETE:"red",PATCH:"purple"}[s]||"default"}const{Text:Le}=t.Typography,dl=[{value:"P0",label:"P0 (最高)"},{value:"P1",label:"P1 (高)"},{value:"P2",label:"P2 (中)"},{value:"P3",label:"P3 (低)"}],ul={P0:"red",P1:"orange",P2:"blue",P3:"default"},qt={PASS:"green",FAIL:"red",SKIP:"default"},pl=[{value:"EXACT",label:"完全匹配"},{value:"CONTAINS",label:"包含"},{value:"REGEX",label:"正则"},{value:"JSONPATH",label:"JSONPath"}];function er(){const[s,r]=p.useState([]),[n,o]=p.useState(!1),[l,a]=p.useState([]),[i,c]=p.useState(!1),[x,h]=p.useState(null),[y,d]=p.useState(!1),[b,F]=p.useState(null),[E,_]=p.useState(null),[C,S]=p.useState(!1),[w,T]=p.useState(!1),[A]=t.Form.useForm();p.useEffect(()=>{k()},[]);const k=async()=>{o(!0);try{const P=await J.cases.list();r(Array.isArray(P)?P:[])}catch{t.message.warning("加载用例列表失败")}finally{o(!1)}},R=()=>{h(null),A.resetFields(),A.setFieldsValue({requestMethod:"GET",expectedStatus:200,priority:"P1",status:1,expectedBodyMatchType:"EXACT"}),c(!0)},H=P=>{h(P),A.setFieldsValue(P),c(!0)},Y=async()=>{try{const P=await A.validateFields();let D;try{D=P.assertionsJson?JSON.parse(P.assertionsJson):null}catch{t.message.error("断言 JSON 格式错误");return}const Q={...P,assertions:D};delete Q.assertionsJson,x?(await J.cases.update(x.caseCode,Q),t.message.success("更新成功")):(await J.cases.create(Q),t.message.success("创建成功")),c(!1),k()}catch(P){P!=null&&P.errorFields||t.message.error("保存失败")}},K=async P=>{try{await J.cases.delete(P),t.message.success("删除成功"),k()}catch{t.message.error("删除失败")}},m=async P=>{try{const D=await J.cases.run(P.caseCode);F(D),d(!0),(D==null?void 0:D.status)==="PASS"?t.message.success("用例通过"):t.message.error("用例失败: "+((D==null?void 0:D.error)||(D==null?void 0:D.actualStatus))),k()}catch(D){t.message.error("执行失败: "+(D==null?void 0:D.message))}},f=async()=>{if(l.length===0){t.message.warning("请先选择用例");return}try{const P=await J.cases.runBatch(l);_(P),S(!0),t.message.success(`批量执行完成: ${P==null?void 0:P.pass} 通过, ${P==null?void 0:P.fail} 失败`),k()}catch{t.message.error("批量执行失败")}},z=[{title:"用例编码",dataIndex:"caseCode",key:"caseCode",width:180,render:P=>e.jsx(Le,{code:!0,children:P})},{title:"名称",dataIndex:"caseName",key:"caseName",width:220},{title:"分组",dataIndex:"caseGroup",key:"caseGroup",width:130,render:P=>P?e.jsx(t.Tag,{children:P}):"-"},{title:"方法",dataIndex:"requestMethod",key:"requestMethod",width:80,render:P=>e.jsx(t.Tag,{color:"blue",children:P})},{title:"路径",dataIndex:"requestUrl",key:"requestUrl",ellipsis:!0,render:P=>e.jsx(Le,{code:!0,children:P})},{title:"优先级",dataIndex:"priority",key:"priority",width:80,align:"center",render:P=>e.jsx(t.Tag,{color:ul[P],children:P||"P1"})},{title:"上次结果",dataIndex:"lastRunResult",key:"lastRunResult",width:100,align:"center",render:P=>P?e.jsx(t.Tag,{color:qt[P],children:P}):"-"},{title:"统计",key:"stats",width:130,align:"center",render:(P,D)=>e.jsxs(t.Space,{size:"small",children:[e.jsx(Le,{type:"success",children:D.passCount||0}),"/",e.jsx(Le,{type:"danger",children:D.failCount||0}),e.jsxs(Le,{type:"secondary",children:["(",D.runCount||0,")"]})]})},{title:"操作",key:"action",width:220,fixed:"right",render:(P,D)=>e.jsxs(t.Space,{size:"small",children:[e.jsx(t.Button,{size:"small",type:"link",icon:e.jsx(g.PlayCircleOutlined,{}),onClick:()=>m(D),children:"运行"}),e.jsx(t.Button,{size:"small",type:"link",icon:e.jsx(g.EditOutlined,{}),onClick:()=>H(D)}),e.jsx(t.Popconfirm,{title:`删除用例 ${D.caseCode}?`,onConfirm:()=>K(D.caseCode),children:e.jsx(t.Button,{size:"small",type:"link",danger:!0,icon:e.jsx(g.DeleteOutlined,{})})})]})}];return e.jsxs("div",{children:[e.jsx(t.Alert,{type:"info",showIcon:!0,style:{marginBottom:16},message:"测试用例库",description:"对 Mock 接口进行断言验证。支持 7 种断言类型:STATUS / HEADER / BODY / JSON_PATH / REGEX / SCHEMA / RESPONSE_TIME。支持单条运行与批量运行,自动统计通过/失败次数。"}),e.jsxs(t.Space,{style:{marginBottom:16},children:[e.jsx(t.Button,{icon:e.jsx(g.ReloadOutlined,{}),onClick:k,children:"刷新"}),e.jsx(t.Button,{type:"primary",icon:e.jsx(g.PlusOutlined,{}),onClick:R,children:"新建用例"}),e.jsx(t.Button,{icon:e.jsx(g.CodeOutlined,{}),onClick:()=>T(!0),children:"粘贴 curl 导入"}),e.jsxs(t.Button,{type:"primary",icon:e.jsx(g.PlayCircleOutlined,{}),onClick:f,disabled:l.length===0,children:["批量运行 (",l.length,")"]})]}),e.jsx(t.Table,{dataSource:s,columns:z,rowKey:"id",loading:n,rowSelection:{selectedRowKeys:l,onChange:a},pagination:{pageSize:10},scroll:{x:1300},size:"small"}),e.jsx(t.Modal,{title:x?`编辑用例: ${x.caseCode}`:"新建测试用例",open:i,onCancel:()=>c(!1),onOk:Y,width:750,children:e.jsxs(t.Form,{form:A,layout:"vertical",style:{marginTop:16},children:[e.jsxs(t.Row,{gutter:16,children:[e.jsx(t.Col,{span:12,children:e.jsx(t.Form.Item,{name:"caseCode",label:"用例编码",rules:[{required:!0}],children:e.jsx(t.Input,{placeholder:"case-user-login",disabled:!!x})})}),e.jsx(t.Col,{span:12,children:e.jsx(t.Form.Item,{name:"caseName",label:"用例名称",children:e.jsx(t.Input,{placeholder:"用户登录成功用例"})})})]}),e.jsxs(t.Row,{gutter:16,children:[e.jsx(t.Col,{span:8,children:e.jsx(t.Form.Item,{name:"caseGroup",label:"用例分组",children:e.jsx(t.Input,{placeholder:"login"})})}),e.jsx(t.Col,{span:8,children:e.jsx(t.Form.Item,{name:"priority",label:"优先级",children:e.jsx(t.Select,{options:dl})})}),e.jsx(t.Col,{span:8,children:e.jsx(t.Form.Item,{name:"envCode",label:"环境",children:e.jsx(t.Input,{placeholder:"default"})})})]}),e.jsxs(t.Row,{gutter:16,children:[e.jsx(t.Col,{span:6,children:e.jsx(t.Form.Item,{name:"requestMethod",label:"方法",children:e.jsx(t.Select,{options:[{value:"GET",label:"GET"},{value:"POST",label:"POST"},{value:"PUT",label:"PUT"},{value:"DELETE",label:"DELETE"}]})})}),e.jsx(t.Col,{span:18,children:e.jsx(t.Form.Item,{name:"requestUrl",label:"请求 URL",rules:[{required:!0}],children:e.jsx(t.Input,{placeholder:"/api/mock/default/user/login"})})})]}),e.jsxs(t.Row,{gutter:16,children:[e.jsx(t.Col,{span:12,children:e.jsx(t.Form.Item,{name:"requestQuery",label:"查询参数",children:e.jsx(t.Input,{placeholder:"debug=true"})})}),e.jsx(t.Col,{span:12,children:e.jsx(t.Form.Item,{name:"expectedStatus",label:"期望状态码",children:e.jsx(t.Select,{options:[{value:200,label:"200 OK"},{value:201,label:"201 Created"},{value:400,label:"400 Bad Request"},{value:401,label:"401 Unauthorized"},{value:404,label:"404 Not Found"},{value:500,label:"500 Server Error"}]})})})]}),e.jsx(t.Form.Item,{name:"requestHeaders",label:"请求头 (JSON)",extra:'例: {"Authorization": "Bearer xxx"}',children:e.jsx(t.Input.TextArea,{rows:2,placeholder:'{"X-Trace-Id": "abc"}'})}),e.jsx(t.Form.Item,{name:"requestBody",label:"请求体",children:e.jsx(t.Input.TextArea,{rows:3,placeholder:'{"username":"test","password":"xxx"}'})}),e.jsx(t.Form.Item,{name:"expectedBodyMatchType",label:"Body 匹配方式",children:e.jsx(t.Select,{options:pl})}),e.jsx(t.Form.Item,{name:"expectedBody",label:"期望 Body",children:e.jsx(t.Input.TextArea,{rows:3,placeholder:'{"code": 200, "success": true}'})}),e.jsx(t.Form.Item,{name:"assertionsJson",label:"断言列表 (JSON 数组)",extra:'例: [{"assertType":"STATUS","expected":200,"comparator":"EQUALS"}]',children:e.jsx(t.Input.TextArea,{rows:4,placeholder:'[{"assertType":"STATUS","expected":200}]'})}),e.jsx(t.Form.Item,{name:"description",label:"描述",children:e.jsx(t.Input.TextArea,{rows:2})})]})}),e.jsx(t.Drawer,{title:e.jsxs(t.Space,{children:[e.jsx(g.FileSearchOutlined,{}),"用例执行结果"]}),open:y,onClose:()=>d(!1),width:650,children:b&&e.jsxs("div",{children:[e.jsxs(t.Row,{gutter:16,style:{marginBottom:16},children:[e.jsx(t.Col,{span:8,children:e.jsx(t.Card,{children:e.jsx(t.Statistic,{title:"结果",value:b.status,valueStyle:{color:qt[b.status]==="green"?"#52c41a":"#ff4d4f"}})})}),e.jsx(t.Col,{span:8,children:e.jsx(t.Card,{children:e.jsx(t.Statistic,{title:"实际状态码",value:b.actualStatus||"-"})})}),e.jsx(t.Col,{span:8,children:e.jsx(t.Card,{children:e.jsx(t.Statistic,{title:"耗时(ms)",value:b.durationMs||0})})})]}),e.jsxs(t.Descriptions,{column:1,size:"small",bordered:!0,style:{marginBottom:16},children:[e.jsx(t.Descriptions.Item,{label:"用例编码",children:b.caseCode}),e.jsx(t.Descriptions.Item,{label:"用例名称",children:b.caseName}),e.jsx(t.Descriptions.Item,{label:"错误信息",children:b.error||"-"})]}),b.assertionResults&&e.jsxs(e.Fragment,{children:[e.jsx(Le,{strong:!0,children:"断言详情:"}),e.jsx(t.Table,{style:{marginTop:8},dataSource:b.assertionResults,columns:[{title:"断言类型",dataIndex:"assertType",key:"assertType",width:110},{title:"表达式",dataIndex:"expression",key:"expression"},{title:"期望值",dataIndex:"expected",key:"expected"},{title:"实际值",dataIndex:"actual",key:"actual"},{title:"结果",dataIndex:"passed",key:"passed",width:80,render:P=>P?e.jsx(t.Tag,{color:"green",children:"PASS"}):e.jsx(t.Tag,{color:"red",children:"FAIL"})}],pagination:!1,size:"small"})]}),e.jsx(Le,{strong:!0,style:{marginTop:16,display:"block"},children:"响应体:"}),e.jsx("pre",{style:{background:"#f5f5f5",padding:12,borderRadius:4,maxHeight:250,overflow:"auto",fontSize:12,fontFamily:"monospace",whiteSpace:"pre-wrap",wordBreak:"break-all"},children:b.responseBody||"(empty)"})]})}),e.jsx(t.Modal,{title:`批量执行结果 (${(E==null?void 0:E.total)||0} 条)`,open:C,onCancel:()=>S(!1),footer:e.jsx(t.Button,{onClick:()=>S(!1),children:"关闭"}),width:800,children:E&&e.jsxs(e.Fragment,{children:[e.jsxs(t.Row,{gutter:16,style:{marginBottom:16},children:[e.jsx(t.Col,{span:6,children:e.jsx(t.Card,{children:e.jsx(t.Statistic,{title:"总数",value:E.total})})}),e.jsx(t.Col,{span:6,children:e.jsx(t.Card,{children:e.jsx(t.Statistic,{title:"通过",value:E.pass,valueStyle:{color:"#52c41a"}})})}),e.jsx(t.Col,{span:6,children:e.jsx(t.Card,{children:e.jsx(t.Statistic,{title:"失败",value:E.fail,valueStyle:{color:"#ff4d4f"}})})}),e.jsx(t.Col,{span:6,children:e.jsx(t.Card,{children:e.jsx(t.Statistic,{title:"通过率",value:`${E.total>0?Math.round(E.pass/E.total*100):0}%`})})})]}),e.jsx(t.Table,{dataSource:E.results||[],columns:[{title:"编码",dataIndex:"caseCode",key:"caseCode",width:180},{title:"名称",dataIndex:"caseName",key:"caseName"},{title:"结果",dataIndex:"status",key:"status",width:80,render:P=>e.jsx(t.Tag,{color:qt[P],children:P})},{title:"耗时",dataIndex:"durationMs",key:"durationMs",width:80,align:"center"},{title:"错误",dataIndex:"error",key:"error",ellipsis:!0}],pagination:!1,size:"small",rowKey:"caseCode"})]})}),e.jsx(Qs,{open:w,onClose:()=>T(!1),onSuccess:(P,D)=>{t.message.success(P==="case"?"测试用例已导入,正在刷新列表":"Mock 端点已导入"),k()}})]})}const{Text:ve}=t.Typography,tr={IDLE:"default",RECORDING:"red",STOPPED:"green",EXPIRED:"gray"};function sr(){const[s,r]=p.useState([]),[n,o]=p.useState(!1),[l,a]=p.useState(!1),[i,c]=p.useState(!1),[x,h]=p.useState(!1),[y,d]=p.useState(!1),[b,F]=p.useState(null),[E,_]=p.useState([]),[C]=t.Form.useForm(),[S]=t.Form.useForm(),[w]=t.Form.useForm(),[T,A]=p.useState([]),[k,R]=p.useState(!1),[H,Y]=p.useState([]);p.useEffect(()=>{K()},[]);const K=async()=>{o(!0);try{const N=await J.recordings.list();r(Array.isArray(N)?N:[])}catch{t.message.warning("加载录制列表失败")}finally{o(!1)}},m=async()=>{try{const N=await C.validateFields();await J.recordings.start(N.recordingCode,N.recordingName,N.targetUrl),t.message.success("录制已开启"),a(!1),C.resetFields(),K()}catch(N){N!=null&&N.errorFields||t.message.error("开启失败")}},f=async N=>{try{await J.recordings.stop(N),t.message.success("录制已停止"),K()}catch{t.message.error("停止失败")}},z=async N=>{try{await J.recordings.delete(N),t.message.success("删除成功"),K()}catch{t.message.error("删除失败")}},P=async N=>{try{const O=await J.recordings.requests(N.recordingCode);F(N),_(Array.isArray(O)?O:[]),d(!0)}catch{t.message.error("加载失败")}},D=async N=>{t.Modal.confirm({title:"导入录制为 Mock",content:`将把录制 "${N.recordingCode}" 转换为 Mock endpoints 并入库。`,okText:"确认导入",onOk:async()=>{try{const O=await J.recordings.import(N.recordingCode,"default");t.message.success(`导入成功: ${(O==null?void 0:O.imported)||0} 个 Mock endpoint`)}catch{t.message.error("导入失败")}}})},Q=async()=>{var N,O,j;try{const L=await S.validateFields(),$=await J.recordings.playback(b.recordingCode,L.targetUrl);t.Modal.info({title:"回放结果",width:700,content:e.jsxs("div",{children:[e.jsxs(ve,{children:["总数: ",((N=$==null?void 0:$[0])==null?void 0:N.total)||0," 通过: ",((O=$==null?void 0:$[0])==null?void 0:O.pass)||0," 失败: ",((j=$==null?void 0:$[0])==null?void 0:j.fail)||0]}),e.jsx("pre",{style:{marginTop:12,background:"#f5f5f5",padding:12,maxHeight:400,overflow:"auto",fontSize:12},children:JSON.stringify($,null,2)})]})}),c(!1)}catch(L){L!=null&&L.errorFields||t.message.error("回放失败")}},oe=async()=>{try{R(!0);const N=await w.validateFields().catch(()=>({})),O=await J.recordings.export(b.recordingCode,N==null?void 0:N.projectCode),j=Array.isArray(O==null?void 0:O.drafts)?O.drafts:[];A(j),Y(j.map(L=>L.mockCode||L.id)),h(!0)}catch(N){N!=null&&N.errorFields||t.message.error("生成草稿失败")}finally{R(!1)}},ge=async()=>{try{const N=await w.validateFields().catch(()=>({})),O=H;if(O.length===0){t.message.warning("请至少选择一个 Mock");return}const j=await J.recordings.import(b.recordingCode,N==null?void 0:N.envCode,N==null?void 0:N.projectCode);t.message.success(`已导入 ${(j==null?void 0:j.imported)||O.length} 个 Mock`),h(!1),K()}catch(N){t.message.error("导入失败:"+((N==null?void 0:N.message)||"未知错误"))}},he=[{title:"编码",dataIndex:"recordingCode",key:"recordingCode",width:180,render:N=>e.jsx(ve,{code:!0,children:N})},{title:"名称",dataIndex:"recordingName",key:"recordingName",width:200},{title:"状态",dataIndex:"recordStatus",key:"recordStatus",width:110,render:N=>e.jsx(t.Tag,{color:tr[N],children:N})},{title:"请求数",dataIndex:"totalRequests",key:"totalRequests",width:90,align:"center"},{title:"目标 URL",dataIndex:"targetUrl",key:"targetUrl",ellipsis:!0,render:N=>N?e.jsx(ve,{copyable:{text:N},children:N}):"-"},{title:"开始时间",dataIndex:"startTime",key:"startTime",width:170},{title:"结束时间",dataIndex:"endTime",key:"endTime",width:170},{title:"操作",key:"action",width:280,fixed:"right",render:(N,O)=>e.jsxs(t.Space,{size:"small",children:[e.jsx(t.Button,{size:"small",type:"link",icon:e.jsx(g.VideoCameraOutlined,{}),onClick:()=>P(O),children:"详情"}),O.recordStatus==="RECORDING"&&e.jsx(t.Button,{size:"small",type:"link",danger:!0,icon:e.jsx(g.StopOutlined,{}),onClick:()=>f(O.recordingCode),children:"停止"}),O.recordStatus==="STOPPED"&&e.jsx(t.Button,{size:"small",type:"link",icon:e.jsx(g.ImportOutlined,{}),onClick:()=>D(O),children:"导入为 Mock"}),e.jsx(t.Popconfirm,{title:`删除录制 ${O.recordingCode}?`,onConfirm:()=>z(O.recordingCode),children:e.jsx(t.Button,{size:"small",type:"link",danger:!0,icon:e.jsx(g.DeleteOutlined,{})})})]})}];return e.jsxs("div",{children:[e.jsx(t.Alert,{type:"info",showIcon:!0,style:{marginBottom:16},message:"流量录制与回放",description:e.jsxs("div",{children:[e.jsxs("div",{children:["• 开启录制后,所有 ",e.jsx(ve,{code:!0,children:"/api/mock/{envCode}/**"})," 请求会被捕获到数据库"]}),e.jsx("div",{children:"• 停止录制后,可一键转为 Mock endpoints(用于离线测试)"}),e.jsx("div",{children:"• 支持回放录制到目标服务(验证录制有效 / 跨环境验证)"})]})}),e.jsxs(t.Space,{style:{marginBottom:16},children:[e.jsx(t.Button,{icon:e.jsx(g.ReloadOutlined,{}),onClick:K,children:"刷新"}),e.jsx(t.Button,{type:"primary",icon:e.jsx(g.VideoCameraOutlined,{}),onClick:()=>a(!0),children:"开启录制"})]}),e.jsx(t.Table,{dataSource:s,columns:he,rowKey:"id",loading:n,pagination:{pageSize:10},scroll:{x:1300},size:"small"}),e.jsx(t.Modal,{title:"开启录制",open:l,onCancel:()=>a(!1),onOk:m,okText:"开启",cancelText:"取消",children:e.jsxs(t.Form,{form:C,layout:"vertical",style:{marginTop:16},children:[e.jsx(t.Form.Item,{name:"recordingCode",label:"录制编码",rules:[{required:!0}],children:e.jsx(t.Input,{placeholder:"prod-trace-2026-06"})}),e.jsx(t.Form.Item,{name:"recordingName",label:"录制名称",rules:[{required:!0}],children:e.jsx(t.Input,{placeholder:"生产环境订单流程"})}),e.jsx(t.Form.Item,{name:"targetUrl",label:"目标服务地址",children:e.jsx(t.Input,{placeholder:"http://prod-api.example.com"})})]})}),e.jsx(t.Drawer,{title:e.jsxs(t.Space,{children:[e.jsx(g.VideoCameraOutlined,{}),"录制详情: ",b==null?void 0:b.recordingCode]}),open:y,onClose:()=>d(!1),width:800,children:b&&e.jsxs("div",{children:[e.jsxs(t.Descriptions,{column:2,size:"small",bordered:!0,style:{marginBottom:16},children:[e.jsx(t.Descriptions.Item,{label:"编码",children:b.recordingCode}),e.jsx(t.Descriptions.Item,{label:"名称",children:b.recordingName}),e.jsx(t.Descriptions.Item,{label:"状态",children:e.jsx(t.Tag,{color:tr[b.recordStatus],children:b.recordStatus})}),e.jsx(t.Descriptions.Item,{label:"请求数",children:b.totalRequests}),e.jsx(t.Descriptions.Item,{label:"目标 URL",span:2,children:e.jsx(ve,{copyable:!0,children:b.targetUrl})}),e.jsx(t.Descriptions.Item,{label:"开始",children:b.startTime}),e.jsx(t.Descriptions.Item,{label:"结束",children:b.endTime||"(录制中)"})]}),e.jsxs(t.Space,{style:{marginBottom:16},children:[e.jsx(t.Button,{icon:e.jsx(g.PlayCircleOutlined,{}),onClick:()=>c(!0),disabled:b.recordStatus!=="STOPPED",children:"回放"}),e.jsx(t.Button,{icon:e.jsx(g.ExportOutlined,{}),onClick:oe,loading:k,disabled:b.recordStatus!=="STOPPED",children:"导出 Mock 草稿"}),e.jsx(t.Button,{type:"primary",icon:e.jsx(g.ImportOutlined,{}),onClick:()=>D(b),disabled:b.recordStatus!=="STOPPED",children:"导入为 Mock"})]}),e.jsxs(ve,{strong:!0,children:["请求列表 (共 ",E.length," 条):"]}),e.jsx(t.Table,{style:{marginTop:8},dataSource:E,columns:[{title:"#",dataIndex:"sequence",key:"sequence",width:50},{title:"方法",dataIndex:"requestMethod",key:"requestMethod",width:80,render:N=>e.jsx(t.Tag,{color:"blue",children:N})},{title:"URL",dataIndex:"requestUrl",key:"requestUrl",ellipsis:!0,render:N=>e.jsx(ve,{code:!0,children:N})},{title:"响应",dataIndex:"responseStatus",key:"responseStatus",width:80,render:N=>e.jsx(t.Tag,{color:N>=400?"red":"green",children:N})},{title:"耗时",dataIndex:"responseTime",key:"responseTime",width:80,render:N=>`${N||0}ms`}],pagination:{pageSize:10},size:"small",rowKey:"id"})]})}),e.jsx(t.Modal,{title:"回放录制",open:i,onCancel:()=>c(!1),onOk:Q,children:e.jsx(t.Form,{form:S,layout:"vertical",style:{marginTop:16},children:e.jsx(t.Form.Item,{name:"targetUrl",label:"目标服务地址",rules:[{required:!0}],children:e.jsx(t.Input,{placeholder:"http://staging-api.example.com"})})})}),e.jsxs(t.Modal,{title:"导出 Mock 草稿",open:x,onCancel:()=>h(!1),onOk:ge,okText:`导入 ${H.length} 个`,width:900,children:[e.jsx(t.Form,{form:w,layout:"vertical",style:{marginTop:8},children:e.jsxs(t.Space,{size:16,style:{width:"100%"},children:[e.jsx(t.Form.Item,{name:"projectCode",label:"项目编码",style:{flex:1,marginBottom:8},children:e.jsx(t.Input,{placeholder:"default"})}),e.jsx(t.Form.Item,{name:"envCode",label:"目标环境",style:{flex:1,marginBottom:8},children:e.jsx(t.Input,{placeholder:"default"})})]})}),e.jsx(t.Alert,{type:"info",showIcon:!0,style:{marginBottom:12},message:`从录制中识别出 ${T.length} 个去重后的 Mock endpoint,已默认全选`}),e.jsx(t.Table,{size:"small",dataSource:T,rowKey:N=>N.mockCode||N.id,pagination:{pageSize:8},scroll:{y:300},rowSelection:{selectedRowKeys:H,onChange:N=>Y(N)},columns:[{title:"方法",dataIndex:"method",width:80,render:N=>e.jsx(t.Tag,{color:"blue",children:N})},{title:"URL 模式",dataIndex:"urlPattern",ellipsis:!0,render:N=>e.jsx(ve,{code:!0,children:N})},{title:"状态码",dataIndex:"statusCode",width:80},{title:"响应模板",dataIndex:"responseTemplate",ellipsis:!0,render:N=>e.jsx(ve,{type:"secondary",style:{fontSize:11},children:(N||"").slice(0,80)})},{title:"请求数",dataIndex:"requestCount",width:80,align:"center"}]})]})]})}const{Text:Ge}=t.Typography,ml={MOCK:"green",PROXY:"blue",404:"red",502:"orange"};function rr(){const[s,r]=p.useState([]),[n,o]=p.useState(null),[l,a]=p.useState(!1),[i,c]=p.useState(null),[x,h]=p.useState(!1),[y,d]=p.useState(""),[b,F]=p.useState();p.useEffect(()=>{E()},[]);const E=async()=>{a(!0);try{const[w,T]=await Promise.all([J.requestLogs.list({path:y||void 0,matched:b,limit:100}),J.requestLogs.stats().catch(()=>null)]);r(Array.isArray(w)?w:[]),o(T)}catch{t.message.warning("加载失败")}finally{a(!1)}},_=w=>{c(w),h(!0)},C=async()=>{try{await J.requestLogs.clear(1e3),t.message.success("已清理"),E()}catch{t.message.error("清理失败")}},S=[{title:"时间",dataIndex:"createTime",key:"createTime",width:170,render:w=>w?new Date(w).toLocaleString():"-"},{title:"环境",dataIndex:"envCode",key:"envCode",width:100,render:w=>e.jsx(t.Tag,{children:w})},{title:"方法",dataIndex:"requestMethod",key:"requestMethod",width:80,render:w=>e.jsx(t.Tag,{color:"blue",children:w})},{title:"路径",dataIndex:"requestPath",key:"requestPath",ellipsis:!0,render:w=>e.jsx(Ge,{code:!0,children:w})},{title:"状态",dataIndex:"responseStatus",key:"responseStatus",width:90,align:"center",render:w=>w?e.jsx(t.Tag,{color:w>=400?"red":"green",children:w}):"-"},{title:"匹配",dataIndex:"matched",key:"matched",width:90,align:"center",render:w=>w===1?e.jsx(t.Tag,{color:"green",children:"命中"}):e.jsx(t.Tag,{color:"red",children:"未匹配"})},{title:"回退",dataIndex:"fallbackType",key:"fallbackType",width:100,render:w=>w?e.jsx(t.Tag,{color:ml[w],children:w}):"-"},{title:"耗时",dataIndex:"durationMs",key:"durationMs",width:80,align:"center",render:w=>`${w||0}ms`},{title:"Mock",dataIndex:"mockCode",key:"mockCode",width:160,ellipsis:!0,render:w=>w?e.jsx(Ge,{code:!0,children:w}):"-"},{title:"操作",key:"action",width:80,render:(w,T)=>e.jsx(t.Button,{size:"small",type:"link",icon:e.jsx(g.EyeOutlined,{}),onClick:()=>_(T),children:"详情"})}];return e.jsxs("div",{children:[e.jsx(t.Alert,{type:"info",showIcon:!0,style:{marginBottom:16},message:"Mock 请求日志 - 排查未匹配请求",description:"每一次请求都会留痕。包括请求/响应体、是否匹配 Mock、回退类型、耗时、场景状态等。便于排查“为什么这个请求没有 Mock 命中”问题。"}),n&&e.jsxs(t.Row,{gutter:16,style:{marginBottom:16},children:[e.jsx(t.Col,{span:6,children:e.jsx(t.Card,{children:e.jsx(t.Statistic,{title:"总请求数",value:n.total||0})})}),e.jsx(t.Col,{span:6,children:e.jsx(t.Card,{children:e.jsx(t.Statistic,{title:"Mock 命中",value:n.matched||0,valueStyle:{color:"#52c41a"}})})}),e.jsx(t.Col,{span:6,children:e.jsx(t.Card,{children:e.jsx(t.Statistic,{title:"未匹配",value:n.unmatched||0,valueStyle:{color:"#ff4d4f"}})})}),e.jsx(t.Col,{span:6,children:e.jsx(t.Card,{children:e.jsx(t.Statistic,{title:"命中率",value:`${n.total>0?Math.round(n.matched/n.total*100):0}%`})})})]}),e.jsxs(t.Space,{style:{marginBottom:16},children:[e.jsx(t.Input,{placeholder:"搜索路径",prefix:e.jsx(g.SearchOutlined,{}),allowClear:!0,style:{width:240},value:y,onChange:w=>d(w.target.value),onPressEnter:E}),e.jsx(t.Select,{placeholder:"匹配状态",allowClear:!0,style:{width:140},value:b,onChange:F,options:[{value:1,label:"已命中"},{value:0,label:"未匹配"}]}),e.jsx(t.Button,{icon:e.jsx(g.ReloadOutlined,{}),onClick:E,children:"查询"}),e.jsx(t.Popconfirm,{title:"确认清理,保留最近 1000 条?",onConfirm:C,children:e.jsx(t.Button,{icon:e.jsx(g.DeleteOutlined,{}),danger:!0,children:"清理"})})]}),e.jsx(t.Table,{dataSource:s,columns:S,rowKey:"id",loading:l,pagination:{pageSize:20},scroll:{x:1300},size:"small"}),e.jsx(t.Drawer,{title:"请求详情",open:x,onClose:()=>h(!1),width:750,children:i&&e.jsxs("div",{children:[e.jsxs(t.Descriptions,{column:2,size:"small",bordered:!0,style:{marginBottom:16},children:[e.jsx(t.Descriptions.Item,{label:"环境",children:i.envCode}),e.jsx(t.Descriptions.Item,{label:"方法",children:e.jsx(t.Tag,{color:"blue",children:i.requestMethod})}),e.jsx(t.Descriptions.Item,{label:"路径",span:2,children:e.jsx(Ge,{code:!0,children:i.requestPath})}),e.jsx(t.Descriptions.Item,{label:"状态码",children:e.jsx(t.Tag,{color:i.responseStatus>=400?"red":"green",children:i.responseStatus})}),e.jsxs(t.Descriptions.Item,{label:"耗时",children:[i.durationMs,"ms"]}),e.jsx(t.Descriptions.Item,{label:"匹配",children:i.matched===1?e.jsx(t.Tag,{color:"green",children:"命中"}):e.jsx(t.Tag,{color:"red",children:"未匹配"})}),e.jsx(t.Descriptions.Item,{label:"回退",children:i.fallbackType||"-"}),e.jsx(t.Descriptions.Item,{label:"Mock",span:2,children:i.mockCode||"-"}),e.jsx(t.Descriptions.Item,{label:"场景状态",span:2,children:i.scenarioState||"-"}),e.jsx(t.Descriptions.Item,{label:"客户端 IP",children:i.clientIp||"-"}),e.jsx(t.Descriptions.Item,{label:"User-Agent",ellipsis:!0,children:i.userAgent||"-"}),e.jsx(t.Descriptions.Item,{label:"时间",span:2,children:i.createTime?new Date(i.createTime).toLocaleString():"-"})]}),e.jsx(Ge,{strong:!0,children:"请求头:"}),e.jsx("pre",{style:{background:"#f5f5f5",padding:12,borderRadius:4,maxHeight:150,overflow:"auto",fontSize:12,fontFamily:"monospace",whiteSpace:"pre-wrap"},children:i.requestHeaders||"(无)"}),e.jsx(Ge,{strong:!0,style:{marginTop:12,display:"block"},children:"请求体:"}),e.jsx("pre",{style:{background:"#f5f5f5",padding:12,borderRadius:4,maxHeight:200,overflow:"auto",fontSize:12,fontFamily:"monospace",whiteSpace:"pre-wrap",wordBreak:"break-all"},children:i.requestBody||"(无)"}),e.jsx(Ge,{strong:!0,style:{marginTop:12,display:"block"},children:"响应体:"}),e.jsx("pre",{style:{background:"#f5f5f5",padding:12,borderRadius:4,maxHeight:300,overflow:"auto",fontSize:12,fontFamily:"monospace",whiteSpace:"pre-wrap",wordBreak:"break-all"},children:i.responseBody||"(无)"})]})})]})}const{Text:Te}=t.Typography,nr=[{key:"endpoints",label:"Mock 端点",component:St},{key:"environments",label:"环境 (MOCK/REAL/MIXED)",component:wt},{key:"scenarios",label:"场景状态机",component:Ys},{key:"cases",label:"测试用例",component:er},{key:"recordings",label:"录制回放",component:sr},{key:"request-logs",label:"请求日志",component:rr}];function hl(){var y;const[s,r]=p.useState("endpoints"),[n,o]=p.useState([]),[l,a]=p.useState("default"),[i,c]=p.useState(null);p.useEffect(()=>{x(),h()},[]);const x=async()=>{try{const d=await J.environments.list(),b=Array.isArray(d)?d:[];if(o(b),b.length>0&&!b.find(F=>F.envCode===l)){const F=b.find(E=>E.isDefault===1)||b[0];a(F.envCode)}}catch{}},h=async()=>{try{const d=await J.stats();c(d)}catch{}};return(y=nr.find(d=>d.key===s))==null||y.component,e.jsxs("div",{children:[e.jsx(t.Card,{style:{marginBottom:16},bodyStyle:{padding:16},children:e.jsxs(t.Space,{size:"large",wrap:!0,children:[e.jsxs(t.Space,{children:[e.jsx(g.DashboardOutlined,{style:{fontSize:18,color:"#1890ff"}}),e.jsx(Te,{strong:!0,style:{fontSize:16},children:"Mock 平台"}),e.jsx(t.Tag,{color:"blue",children:"WireMock 级"})]}),e.jsxs(t.Space,{children:[e.jsx(g.GlobalOutlined,{}),e.jsx(Te,{children:"当前环境:"}),e.jsx(t.Select,{value:l,onChange:a,style:{width:200},options:n.map(d=>({value:d.envCode,label:`${d.envName||d.envCode} (${d.envType})`}))})]}),i&&e.jsxs(t.Space,{size:"large",children:[e.jsxs(Te,{type:"secondary",children:["端点: ",e.jsx(Te,{strong:!0,children:i.totalEndpoints})]}),e.jsxs(Te,{type:"secondary",children:["启用: ",e.jsx(Te,{strong:!0,style:{color:"#52c41a"},children:i.activeEndpoints})]}),e.jsxs(Te,{type:"secondary",children:["场景: ",e.jsx(Te,{strong:!0,children:i.totalScenarios})]}),e.jsxs(Te,{type:"secondary",children:["用例: ",e.jsx(Te,{strong:!0,children:i.totalCases})]})]}),e.jsx(t.Button,{icon:e.jsx(g.ReloadOutlined,{}),onClick:()=>{x(),h()},children:"刷新"})]})}),e.jsx(t.Tabs,{activeKey:s,onChange:r,type:"card",items:nr.map(d=>({key:d.key,label:d.label,children:d.component===St?e.jsx(St,{activeEnvCode:l}):d.component===wt?e.jsx(wt,{onEnvChange:b=>{a(b),t.message.success(`已切换到环境: ${b}`)}}):e.jsx(d.component,{})}))})]})}const fl=common;q.AgentTeamIM=_o,q.AppLayout=fr,q.CtcAuthPage=Fo,q.CtcLayout=Io,q.CtcLogin=Ro,q.CurlImportModal=Qs,q.EndpointsTab=St,q.EnvironmentsTab=wt,q.ErrorBoundary=mo,q.LoginPage=po,q.LowCodeModel=Us,q.LowCodePage=Yo,q.LowCodeRuntime=qs,q.MaterializePage=Qo,q.MockPlatform=hl,q.MockTemplateHelper=Ks,q.OpenApiImportModal=Js,q.Overview=xo,q.RecordingsTab=sr,q.RequestLogsTab=rr,q.ScenariosTab=Ys,q.StatusTag=xr,q.TestCasesTab=er,q.UCLayout=$o,q.UCLogin=qo,q.UCPhoneLogin=Ho,q.UCRegister=Wo,q.UCResetPassword=Go,q.UserPanel=Do,q.Webide=Mo,q.authRequest=Mt,q.createRequest=Bt,q.ctcRequest=go,q.default=fl,q.defaultStatusMap=Jt,q.request=te,q.setupInterceptors=Ns,Object.defineProperties(q,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));