flex-mcp 1.1.19 → 1.1.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api/backup.d.ts +6 -0
- package/dist/api/backup.d.ts.map +1 -0
- package/dist/api/backup.js +212 -0
- package/dist/api/backup.js.map +1 -0
- package/dist/api/configs.js +3 -6
- package/dist/api/configs.js.map +1 -1
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/index.js +3 -0
- package/dist/api/index.js.map +1 -1
- package/dist/api/prompts.js +37 -7
- package/dist/api/prompts.js.map +1 -1
- package/dist/config.d.ts +4 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +12 -0
- package/dist/config.js.map +1 -1
- package/dist/db/index.d.ts.map +1 -1
- package/dist/db/index.js +61 -0
- package/dist/db/index.js.map +1 -1
- package/dist/db/schema.d.ts +24 -0
- package/dist/db/schema.d.ts.map +1 -1
- package/dist/db/schema.js +2 -0
- package/dist/db/schema.js.map +1 -1
- package/dist/mcp/aggregator.d.ts.map +1 -1
- package/dist/mcp/aggregator.js +128 -74
- package/dist/mcp/aggregator.js.map +1 -1
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/web/assets/Backup-BnJJcJ1y.js +1 -0
- package/dist/web/assets/{Blank-BHJQs5sx.js → Blank-DYHf__-I.js} +1 -1
- package/dist/web/assets/{Configs-BsYYESfj.js → Configs-BhOuA1TR.js} +1 -1
- package/dist/web/assets/Dashboard-XGeMGzfq.js +83 -0
- package/dist/web/assets/InitScriptEditor-tSkIU_zo.js +588 -0
- package/dist/web/assets/Layout-CtytdFcc.js +1 -0
- package/dist/web/assets/{Layout-BmR6ReTO.js → Layout-DoiZawSk.js} +1 -1
- package/dist/web/assets/{Login-CwxdtbCd.js → Login-Cr1ve1cB.js} +1 -1
- package/dist/web/assets/{Login-B12ArZ__.js → Login-DVWgtC9D.js} +1 -1
- package/dist/web/assets/{Users-CyJLDYCZ.js → Users-C4kFgZqa.js} +1 -1
- package/dist/web/assets/index-BBxZKz3O.js +2 -0
- package/dist/web/assets/{monaco-editor-BXWd1EVR.js → monaco-editor-D-KqHnQ9.js} +1 -1
- package/dist/web/assets/{naive-ui-UIL-VU-f.js → naive-ui-C5lXjE56.js} +2 -2
- package/dist/web/assets/style-DyYDoNC5.css +1 -0
- package/dist/web/assets/vendor-D1MaVSrs.js +63 -0
- package/dist/web/index.html +5 -5
- package/package.json +1 -1
- package/dist/web/assets/Dashboard-sRUOp0M_.js +0 -83
- package/dist/web/assets/InitScriptEditor-iTJN-PPD.js +0 -588
- package/dist/web/assets/Layout-DM8EAalA.js +0 -1
- package/dist/web/assets/index-DAevE53R.js +0 -2
- package/dist/web/assets/style-CIoc_HY4.css +0 -1
- package/dist/web/assets/vendor-DpXl860f.js +0 -58
package/dist/web/index.html
CHANGED
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
|
6
6
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
7
|
<title>可运营 MCP 运营端</title>
|
|
8
|
-
<script type="module" crossorigin src="/assets/index-
|
|
9
|
-
<link rel="modulepreload" crossorigin href="/assets/vendor-
|
|
10
|
-
<link rel="modulepreload" crossorigin href="/assets/naive-ui-
|
|
11
|
-
<link rel="modulepreload" crossorigin href="/assets/monaco-editor-
|
|
12
|
-
<link rel="stylesheet" crossorigin href="/assets/style-
|
|
8
|
+
<script type="module" crossorigin src="/assets/index-BBxZKz3O.js"></script>
|
|
9
|
+
<link rel="modulepreload" crossorigin href="/assets/vendor-D1MaVSrs.js">
|
|
10
|
+
<link rel="modulepreload" crossorigin href="/assets/naive-ui-C5lXjE56.js">
|
|
11
|
+
<link rel="modulepreload" crossorigin href="/assets/monaco-editor-D-KqHnQ9.js">
|
|
12
|
+
<link rel="stylesheet" crossorigin href="/assets/style-DyYDoNC5.css">
|
|
13
13
|
</head>
|
|
14
14
|
<body>
|
|
15
15
|
<div id="app"></div>
|
package/package.json
CHANGED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import{q as ze,r as f,s as ee,w as De,c0 as $,c1 as t,bW as l,bV as o,bs as n,bU as b,l as h,G as A,o as Ie,c5 as re,F as we,bN as he,c7 as Q,bm as Ve,bS as Me,Z as Fe,ah as Ye,bT as Qe,aI as Xe,c6 as et,c8 as tt,c3 as at}from"./vendor-DpXl860f.js";import{g as st,p as nt,_ as qe,u as Pe,a as lt,I as ot,C as rt,M as it}from"./InitScriptEditor-iTJN-PPD.js";import{u as Je,a as J,p as ut}from"./index-DAevE53R.js";import{u as _e,B as S,e as H,g as je,h as me,c as $e,d as K,i as Ne,j as Ue,k as We,l as Ae,m as ge,o as Re,p as Be,q as dt,r as Oe,s as Ke,t as Se,v as ct,w as vt,x as pt,y as Ee,z as ft,A as mt,C as He}from"./naive-ui-UIL-VU-f.js";import{_ as Te}from"./_plugin-vue_export-helper-DlAUqK2U.js";import"./monaco-editor-BXWd1EVR.js";const gt={class:"variables-manager"},wt={class:"variables-toolbar"},ht={class:"variables-table-container"},bt={class:"modal-form-wrapper"},yt=ze({__name:"VariablesManager",props:{config:{}},emits:["update"],setup(de,{emit:k}){const C=de,w=k,B=_e(),m=f(!1),L=f(!1),P=f(null),R=f(),F=f(""),T={pageSize:10,showSizePicker:!0,pageSizes:[10,20,50]},te=_=>({style:"cursor: pointer; transition: all 0.2s ease;",onMouseenter:g=>{g.currentTarget.style.backgroundColor="rgba(99, 102, 241, 0.04)"},onMouseleave:g=>{g.currentTarget.style.backgroundColor=""}}),X=[{title:"变量名",key:"name",width:100,render(_){return A("strong",_.name)}},{title:"值",key:"value",width:500,render(_){if(_.isSecret)return A(Ue,{type:"info",depth:3,italic:!0},{default:()=>"****** (敏感信息)"});const g=String(_.value).split(`
|
|
2
|
-
`).map((v,G,ie)=>{const ae=[A("span",{class:"value-line"},v)];return G<ie.length-1&&ae.push(A("br")),ae}).flat();return A("div",{class:"variable-value-cell"},g)}},{title:"描述",key:"description",width:300,render(_){return A(Ue,{depth:3},{default:()=>_.description||"-"})}},{title:"操作",key:"actions",width:150,render(_){return A(We,{size:"small"},{default:()=>[A(S,{size:"small",onClick:()=>j(_)},{default:()=>"编辑"}),A(S,{size:"small",type:"error",onClick:()=>E(_.id)},{default:()=>"删除"})]})}}],U=ee(()=>{if(!F.value)return C.config.variables;const _=F.value.toLowerCase();return C.config.variables.filter(g=>{var v;return g.name.toLowerCase().includes(_)||((v=g.description)==null?void 0:v.toLowerCase().includes(_))})}),M=f({name:"",value:"",description:"",isSecret:!1}),q={name:{required:!0,message:"请输入变量名",trigger:"blur"},value:{required:!0,message:"请输入变量值",trigger:"blur"}};function j(_){P.value=_,M.value={name:_.name,value:_.value,description:_.description||"",isSecret:_.isSecret||!1},m.value=!0}function E(_){const g=C.config.variables.filter(v=>v.id!==_);w("update",{variables:g})}async function le(){var _,g;try{await((_=R.value)==null?void 0:_.validate()),L.value=!0;const v={id:((g=P.value)==null?void 0:g.id)||st(),name:M.value.name,value:M.value.value,description:M.value.description||void 0,isSecret:M.value.isSecret},G=[...C.config.variables],ie=G.findIndex(ae=>ae.id===v.id);ie!==-1?G[ie]=v:G.push(v),w("update",{variables:G}),m.value=!1,Z()}catch(v){B.error(v.message)}finally{L.value=!1}}function Z(){P.value=null,M.value={name:"",value:"",description:"",isSecret:!1}}return De(()=>m.value,_=>{_||Z()}),(_,g)=>(b(),$("div",gt,[t("div",wt,[l(n(S),{type:"primary",size:"large",class:"add-variable-btn",onClick:g[0]||(g[0]=v=>m.value=!0)},{icon:o(()=>[...g[8]||(g[8]=[t("svg",{viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[t("path",{d:"M12 4v16m8-8H4",stroke:"currentColor","stroke-width":"2.5","stroke-linecap":"round","stroke-linejoin":"round"})],-1)])]),default:o(()=>[g[9]||(g[9]=h(" 添加变量 ",-1))]),_:1}),l(n(H),{value:F.value,"onUpdate:value":g[1]||(g[1]=v=>F.value=v),placeholder:"搜索变量名或描述...",size:"large",clearable:"",class:"search-input"},{prefix:o(()=>[...g[10]||(g[10]=[t("svg",{class:"search-icon",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[t("path",{d:"M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"})],-1)])]),_:1},8,["value"])]),t("div",ht,[l(n(je),{columns:X,data:U.value,pagination:T,"row-props":te,class:"modern-table"},null,8,["data"])]),l(n(me),{show:m.value,"onUpdate:show":g[7]||(g[7]=v=>m.value=v),preset:"dialog",title:P.value?"编辑变量":"添加变量",class:"variable-edit-modal",style:{maxHeight:"90vh"}},{action:o(()=>[l(n(S),{onClick:g[6]||(g[6]=v=>m.value=!1)},{default:o(()=>[...g[12]||(g[12]=[h("取消",-1)])]),_:1}),l(n(S),{type:"primary",loading:L.value,onClick:le},{default:o(()=>[...g[13]||(g[13]=[h("保存",-1)])]),_:1},8,["loading"])]),default:o(()=>[t("div",bt,[l(n($e),{ref_key:"formRef",ref:R,model:M.value,rules:q},{default:o(()=>[l(n(K),{path:"name",label:"变量名"},{default:o(()=>[l(n(H),{value:M.value.name,"onUpdate:value":g[2]||(g[2]=v=>M.value.name=v),placeholder:"例如: API_KEY"},null,8,["value"])]),_:1}),l(n(K),{path:"value",label:"值"},{default:o(()=>[l(n(H),{value:M.value.value,"onUpdate:value":g[3]||(g[3]=v=>M.value.value=v),type:M.value.isSecret?"password":"textarea",rows:M.value.isSecret?void 0:3,placeholder:"变量值"},null,8,["value","type","rows"])]),_:1}),l(n(K),{path:"description",label:"描述"},{default:o(()=>[l(n(H),{value:M.value.description,"onUpdate:value":g[4]||(g[4]=v=>M.value.description=v),type:"textarea",rows:2,placeholder:"可选"},null,8,["value"])]),_:1}),l(n(K),{path:"isSecret",label:"敏感信息"},{default:o(()=>[l(n(Ne),{checked:M.value.isSecret,"onUpdate:checked":g[5]||(g[5]=v=>M.value.isSecret=v)},{default:o(()=>[...g[11]||(g[11]=[h("标记为敏感信息(导出时使用占位符)",-1)])]),_:1},8,["checked"])]),_:1})]),_:1},8,["model"])])]),_:1},8,["show","title"])]))}}),kt=Te(yt,[["__scopeId","data-v-f50b6ccd"]]),xt={class:"prompts-manager"},Ct={class:"prompts-toolbar"},$t={class:"prompts-table-container"},St={class:"modal-header"},Mt={class:"modal-title"},zt={class:"modal-subtitle"},Dt={class:"modal-content-wrapper"},_t={class:"tab-pane-content"},Tt={class:"form-section"},Ut={class:"form-grid-2"},jt={class:"form-section"},It={class:"section-header"},Nt={class:"parameters-list"},At={class:"parameter-header"},Bt={class:"parameter-index"},Vt={class:"parameter-fields"},Rt={key:0,class:"empty-parameters"},Ot={class:"tab-pane-content"},Pt={style:{display:"flex","align-items":"center",gap:"8px"}},Et={viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",style:{width:"18px",height:"18px"}},Ht={class:"messages-section"},Lt={class:"message-header"},Ft={class:"save-status-indicator"},qt=["title"],Jt={key:0,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},Wt={key:1,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},Kt={key:0,class:"monaco-wrapper"},Zt={key:0,class:"empty-messages"},Gt={class:"modal-footer"},Yt={class:"test-content"},Qt={class:"test-messages"},Xt={class:"test-message-header"},ea={class:"test-message-content"},ta={key:0,class:"test-message-empty"},aa=ze({__name:"PromptsManager",setup(de){const k=_e(),C=Je(),w=f(!1),B=f(!1),m=f(!1),L=f(!1),P=f(!1),R=f(null),F=f(),T=f(""),te=f([]),X=f("content"),U=f(!1),M=f(-1),q=f(new Map),j=f(!1),E=[{label:"用户",value:"user"},{label:"助手",value:"assistant"}],le={pageSize:10,showSizePicker:!0,pageSizes:[10,20,50]},Z=s=>({style:"cursor: pointer; transition: all 0.2s ease;",onMouseenter:e=>{e.currentTarget.style.backgroundColor="rgba(99, 102, 241, 0.04)"},onMouseleave:e=>{e.currentTarget.style.backgroundColor=""}}),_=[{title:"名称",key:"name",width:200,render(s){return A("strong",s.name)}},{title:"描述",key:"description",render(s){return A(Ue,{depth:3},{default:()=>s.description||"-"})}},{title:"参数数量",key:"arguments",width:120,render(s){return A(Ue,{depth:3},{default:()=>{var e;return`${((e=s.arguments)==null?void 0:e.length)||0} 个`}})}},{title:"消息数量",key:"messages",width:120,render(s){return A(Ue,{depth:3},{default:()=>{var e;return`${((e=s.messages)==null?void 0:e.length)||0} 条`}})}},{title:"操作",key:"actions",width:200,render(s){return A(We,{size:"small"},{default:()=>[A(S,{size:"small",onClick:()=>be(s)},{default:()=>"编辑"}),A(S,{size:"small",type:"info",onClick:()=>O(s)},{default:()=>"测试"}),A(S,{size:"small",type:"error",onClick:()=>ye(s.id)},{default:()=>"删除"})]})}}],g=ee(()=>{if(!T.value)return te.value;const s=T.value.toLowerCase();return te.value.filter(e=>{var a;return e.name.toLowerCase().includes(s)||((a=e.description)==null?void 0:a.toLowerCase().includes(s))})}),v=f({name:"",description:"",arguments:[],messages:[]}),G=f({arguments:{}}),ie=ee(()=>{if(!B.value||!v.value.messages||v.value.messages.length===0)return[];const s=v.value.messages.filter(z=>z.content.text),e=new Date,a=C.user,u=a!=null&&a.id?`.data/fileSystem/${a.id}`:"<not found>",p={...{context:{user:{id:(a==null?void 0:a.id)||"",email:(a==null?void 0:a.email)||"",role:(a==null?void 0:a.role)||"user",createdAt:a!=null&&a.createdAt?new Date(a.createdAt).toISOString():e.toISOString(),updatedAt:a!=null&&a.updatedAt?new Date(a.updatedAt).toISOString():e.toISOString(),root_dir:u},timestamp:e.toISOString(),now:e.toLocaleString("zh-CN",{timeZone:"Asia/Shanghai"})}},...G.value.arguments};return s.map(z=>({...z,content:{...z.content,text:nt(z.content.text,p)}}))}),ae={name:{required:!0,message:"请输入提示词名称",trigger:"blur"},messages:{required:!0,validator:(s,e)=>!e||e.length===0?new Error("至少需要一条消息"):!0,trigger:"blur"}};function se(s){return q.value.get(s)||!1}function oe(s){q.value.set(s,!0)}function ue(s){U.value&&M.value===s?(U.value=!1,M.value=-1):(U.value=!0,M.value=s)}async function ce(){var s,e;try{P.value=!0;const a=await J.get("/prompts");a.data.success&&(te.value=a.data.data)}catch(a){k.error(((e=(s=a.response)==null?void 0:s.data)==null?void 0:e.error)||"加载提示词失败")}finally{P.value=!1}}function pe(){R.value=null,Y(),w.value=!0,X.value="content"}function be(s){R.value=s,v.value={name:s.name,description:s.description||"",arguments:s.arguments?[...s.arguments]:[],messages:s.messages&&s.messages.length>0?[...s.messages]:[{role:"user",content:{type:"text",text:""}}]},q.value.clear(),w.value=!0,X.value="content"}async function ye(s){var e,a;try{await J.delete(`/prompts/${s}`),k.success("删除成功"),await ce()}catch(u){k.error(((a=(e=u.response)==null?void 0:e.data)==null?void 0:a.error)||"删除失败")}}function ve(){v.value.arguments.push({name:"",description:"",required:!1})}function ke(s){v.value.arguments.splice(s,1)}function fe(){v.value.messages.push({role:"user",content:{type:"text",text:""}}),oe(v.value.messages.length-1)}function xe(s){v.value.messages.splice(s,1),q.value.delete(s),M.value===s?(U.value=!1,M.value=-1):M.value>s&&M.value--}async function y(){var s,e,a;try{await((s=F.value)==null?void 0:s.validate()),m.value=!0;const u={name:v.value.name,description:v.value.description||void 0,arguments:v.value.arguments.filter(x=>x.name),messages:v.value.messages.filter(x=>x.content.text)};R.value?(await J.put(`/prompts/${R.value.id}`,u),k.success("更新成功")):(await J.post("/prompts",u),k.success("创建成功")),q.value.clear(),w.value=!1,await ce(),Y()}catch(u){k.error(((a=(e=u.response)==null?void 0:e.data)==null?void 0:a.error)||"保存失败")}finally{m.value=!1}}async function i(){var s,e,a;try{await((s=F.value)==null?void 0:s.validate()),L.value=!0;const u=v.value.arguments.filter(x=>x.name);G.value.arguments=u.reduce((x,p)=>(x[p.name]=G.value.arguments[p.name]||"",x),{}),B.value=!0}catch(u){k.error(((a=(e=u.response)==null?void 0:e.data)==null?void 0:a.error)||"测试失败")}finally{L.value=!1}}async function O(s){R.value=s,v.value={name:s.name,description:s.description||"",arguments:s.arguments?[...s.arguments]:[],messages:s.messages?[...s.messages]:[]};const e=v.value.arguments.filter(a=>a.name);G.value.arguments=e.reduce((a,u)=>(a[u.name]="",a),{}),await i()}function Y(){R.value=null,v.value={name:"",description:"",arguments:[],messages:[{role:"user",content:{type:"text",text:`# 提示词模板
|
|
3
|
-
|
|
4
|
-
## 变量替换
|
|
5
|
-
用户名:{{username}}
|
|
6
|
-
任务类型:{{taskType}}
|
|
7
|
-
|
|
8
|
-
## 条件逻辑
|
|
9
|
-
|
|
10
|
-
{{#if includeDetails}}
|
|
11
|
-
详细信息:{{projectName}} - {{deadline}}
|
|
12
|
-
{{/if}}
|
|
13
|
-
|
|
14
|
-
{{#if urgent}}
|
|
15
|
-
⚠️ 紧急任务
|
|
16
|
-
{{else}}
|
|
17
|
-
普通任务
|
|
18
|
-
{{/if}}
|
|
19
|
-
|
|
20
|
-
{{#ifnot completed}}
|
|
21
|
-
进行中
|
|
22
|
-
{{else}}
|
|
23
|
-
已完成
|
|
24
|
-
{{/ifnot}}`}}]},G.value.arguments={},q.value.clear(),U.value=!1,M.value=-1,j.value=!1}return De(()=>w.value,async s=>{s?(await Fe(),await new Promise(e=>setTimeout(e,150)),j.value=!0):(Y(),j.value=!1)}),Ie(()=>{ce()}),(s,e)=>(b(),$("div",xt,[t("div",Ct,[l(n(S),{type:"primary",size:"large",class:"add-prompt-btn",onClick:pe},{icon:o(()=>[...e[8]||(e[8]=[t("svg",{viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[t("path",{d:"M12 4v16m8-8H4",stroke:"currentColor","stroke-width":"2.5","stroke-linecap":"round","stroke-linejoin":"round"})],-1)])]),default:o(()=>[e[9]||(e[9]=h(" 添加提示词 ",-1))]),_:1}),l(n(H),{value:T.value,"onUpdate:value":e[0]||(e[0]=a=>T.value=a),placeholder:"搜索提示词名称或描述...",size:"large",clearable:"",class:"search-input"},{prefix:o(()=>[...e[10]||(e[10]=[t("svg",{class:"search-icon",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[t("path",{d:"M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"})],-1)])]),_:1},8,["value"])]),t("div",$t,[l(n(je),{columns:_,data:g.value,pagination:le,"row-props":Z,loading:P.value,class:"modern-table"},null,8,["data","loading"])]),l(n(me),{show:w.value,"onUpdate:show":e[5]||(e[5]=a=>w.value=a),preset:"card",bordered:!1,class:"prompt-edit-modal",style:{width:"90vw",maxWidth:"1400px",height:"90vh",maxHeight:"90vh"}},{header:o(()=>[t("div",St,[e[11]||(e[11]=t("div",{class:"modal-icon"},[t("svg",{viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[t("path",{d:"M14 2H6a2 2 0 00-2 2v16a2 2 0 002 2h12a2 2 0 002-2V8l-6-6z",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"}),t("path",{d:"M14 2v6h6",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"}),t("path",{d:"M16 13H8",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round"}),t("path",{d:"M16 17H8",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round"}),t("path",{d:"M10 9H8",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round"})])],-1)),t("div",null,[t("h3",Mt,Q(R.value?"编辑提示词":"创建提示词"),1),t("p",zt,Q(R.value?"修改提示词的内容和参数":"定义提示词模板和参数"),1)])])]),footer:o(()=>[t("div",Gt,[l(n(S),{size:"large",onClick:e[4]||(e[4]=a=>w.value=!1)},{default:o(()=>[...e[30]||(e[30]=[h("取消",-1)])]),_:1}),l(n(S),{type:"info",size:"large",onClick:i,loading:L.value},{default:o(()=>[...e[31]||(e[31]=[h("测试",-1)])]),_:1},8,["loading"]),l(n(S),{type:"primary",size:"large",loading:m.value,onClick:y},{default:o(()=>[h(Q(R.value?"保存修改":"创建提示词"),1)]),_:1},8,["loading"])])]),default:o(()=>[t("div",Dt,[l(n($e),{ref_key:"formRef",ref:F,model:v.value,rules:ae,class:"prompt-form"},{default:o(()=>[l(n(Ae),{value:X.value,"onUpdate:value":e[3]||(e[3]=a=>X.value=a),type:"line",animated:"",size:"large",class:"prompt-config-tabs"},{default:o(()=>[l(n(ge),{name:"config",tab:"参数和描述"},{default:o(()=>[t("div",_t,[t("div",Tt,[e[14]||(e[14]=t("h4",{class:"section-title"},"基础信息",-1)),t("div",Ut,[l(n(K),{path:"name"},{label:o(()=>[...e[12]||(e[12]=[t("div",{class:"form-label"},[t("svg",{class:"label-icon",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[t("path",{d:"M7 7h.01M7 3h5c.512 0 1.024.195 1.414.586l7 7a2 2 0 010 2.828l-7 7a2 2 0 01-2.828 0l-7-7A1.994 1.994 0 013 12V7a4 4 0 014-4z",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"})]),t("span",null,"提示词名称")],-1)])]),default:o(()=>[l(n(H),{value:v.value.name,"onUpdate:value":e[1]||(e[1]=a=>v.value.name=a),placeholder:"例如: code-review",size:"large"},null,8,["value"])]),_:1}),l(n(K),{path:"description"},{label:o(()=>[...e[13]||(e[13]=[t("div",{class:"form-label"},[t("svg",{class:"label-icon",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[t("path",{d:"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"})]),t("span",null,"描述")],-1)])]),default:o(()=>[l(n(H),{value:v.value.description,"onUpdate:value":e[2]||(e[2]=a=>v.value.description=a),placeholder:"提示词的描述信息(可选)",size:"large"},null,8,["value"])]),_:1})])]),t("div",jt,[t("div",It,[e[17]||(e[17]=t("h4",{class:"section-title"},"参数定义",-1)),l(n(S),{dashed:"",onClick:ve,size:"medium"},{icon:o(()=>[...e[15]||(e[15]=[t("svg",{viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[t("path",{d:"M12 4v16m8-8H4",stroke:"currentColor","stroke-width":"2.5","stroke-linecap":"round","stroke-linejoin":"round"})],-1)])]),default:o(()=>[e[16]||(e[16]=h(" 添加参数 ",-1))]),_:1})]),t("div",Nt,[(b(!0),$(we,null,he(v.value.arguments,(a,u)=>(b(),$("div",{key:u,class:"parameter-card"},[t("div",At,[t("span",Bt,"#"+Q(u+1),1),l(n(S),{type:"error",text:"",size:"small",onClick:x=>ke(u)},{icon:o(()=>[...e[18]||(e[18]=[t("svg",{viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[t("path",{d:"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"})],-1)])]),default:o(()=>[e[19]||(e[19]=h(" 删除 ",-1))]),_:1},8,["onClick"])]),t("div",Vt,[l(n(K),{label:"必填",class:"required-field"},{default:o(()=>[l(n(Ne),{checked:a.required,"onUpdate:checked":x=>a.required=x},null,8,["checked","onUpdate:checked"])]),_:2},1024),l(n(K),{label:"参数名",path:`arguments[${u}].name`,rule:{required:!0,message:"必填",trigger:"blur"}},{default:o(()=>[l(n(H),{value:a.name,"onUpdate:value":x=>a.name=x,placeholder:"参数名"},null,8,["value","onUpdate:value"])]),_:2},1032,["path"]),l(n(K),{label:"描述"},{default:o(()=>[l(n(H),{value:a.description,"onUpdate:value":x=>a.description=x,placeholder:"参数描述(可选)"},null,8,["value","onUpdate:value"])]),_:2},1024)])]))),128)),v.value.arguments.length===0?(b(),$("div",Rt,[...e[20]||(e[20]=[t("svg",{viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[t("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor","stroke-width":"2"}),t("path",{d:"M12 16v-4m0-4h.01",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round"})],-1),t("p",null,"暂无参数,点击上方按钮添加参数",-1)])])):re("",!0)])])])]),_:1}),l(n(ge),{name:"content",tab:"提示词内容"},{default:o(()=>[t("div",Ot,[l(n(Re),{type:"info",bordered:!1,class:"template-help-alert"},{header:o(()=>[t("div",Pt,[(b(),$("svg",Et,[...e[21]||(e[21]=[t("path",{d:"M12 22c5.421 0 10-4.579 10-10h-2a8 8 0 11-8-8v2c0 5.421-4.579 10-10 10z",fill:"currentColor",opacity:"0.1"},null,-1),t("path",{d:"M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"},null,-1)])])),e[22]||(e[22]=t("span",{style:{"font-weight":"600"}},"模板语法说明",-1))])]),default:o(()=>[e[23]||(e[23]=t("div",{class:"template-help-content"},[t("p",null,[t("strong",null,"变量替换:"),h("使用 "),t("code",null,"{{变量名}}"),h(" 来替换变量值")]),t("p",null,[t("strong",null,"嵌套属性:"),h("支持访问嵌套属性,如 "),t("code",null,"{{context.user.email}}")]),t("p",null,[t("strong",null,"内置 Context 变量:")]),t("ul",null,[t("li",null,[t("code",null,"{{context.user.email}}"),h(" - 当前用户邮箱")]),t("li",null,[t("code",null,"{{context.user.id}}"),h(" - 当前用户ID")]),t("li",null,[t("code",null,"{{context.user.role}}"),h(" - 当前用户角色")]),t("li",null,[t("code",null,"{{context.user.root_dir}}"),h(" - 用户文件路径根目录(实际路径)")]),t("li",null,[t("code",null,"{{context.now}}"),h(" - 当前时间")]),t("li",null,[t("code",null,"{{context.timestamp}}"),h(" - 时间戳")])]),t("p",null,[t("strong",null,"条件逻辑:")]),t("ul",null,[t("li",null,[t("code",null,"{{#if 变量名}}...{{/if}}"),h(" - 当变量为真值时显示内容")]),t("li",null,[t("code",null,"{{#ifnot 变量名}}...{{/ifnot}}"),h(" - 当变量为假值时显示内容")]),t("li",null,[t("code",null,"{{#if 变量名}}...{{else}}...{{/if}}"),h(" - 支持 else 分支")]),t("li",null,[h("条件逻辑也支持嵌套属性,如 "),t("code",null,"{{#if context.user.email}}...{{/if}}")])]),t("p",null,[t("strong",null,"真值判断:"),h("非空字符串、非零数字、true、非空数组/对象都被视为真值")])],-1))]),_:1}),t("div",Ht,[(b(!0),$(we,null,he(v.value.messages,(a,u)=>(b(),$("div",{key:u,class:"message-editor-wrapper"},[t("div",Lt,[l(n(Be),{value:a.role,"onUpdate:value":x=>a.role=x,options:E,size:"small",class:"role-selector"},null,8,["value","onUpdate:value"]),l(n(S),{text:"",type:"error",size:"small",onClick:x=>xe(u),class:"remove-message-btn"},{icon:o(()=>[...e[24]||(e[24]=[t("svg",{viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[t("path",{d:"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"})],-1)])]),_:1},8,["onClick"])]),t("div",{class:Ve(["editor-container",{fullscreen:U.value&&M.value===u}])},[t("div",Ft,[t("div",{class:Ve(["status-dot",{unsaved:se(u),saved:!se(u)}]),title:se(u)?"未保存":"已保存"},null,10,qt)]),l(n(S),{type:"default",size:"small",class:"fullscreen-btn",onClick:x=>ue(u)},{icon:o(()=>[!U.value||M.value!==u?(b(),$("svg",Jt,[...e[25]||(e[25]=[t("path",{d:"M8 3H5a2 2 0 0 0-2 2v3m18 0V5a2 2 0 0 0-2-2h-3m0 18h3a2 2 0 0 0 2-2v-3M3 16v3a2 2 0 0 0 2 2h3",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"},null,-1)])])):(b(),$("svg",Wt,[...e[26]||(e[26]=[t("path",{d:"M8 3v3a2 2 0 0 1-2 2H3m18 0h-3a2 2 0 0 1-2-2V3m0 18v-3a2 2 0 0 1 2-2h3M3 16h3a2 2 0 0 1 2 2v3",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"},null,-1)])]))]),default:o(()=>[h(" "+Q(U.value&&M.value===u?"退出全屏":"全屏"),1)]),_:2},1032,["onClick"]),w.value&&j.value?(b(),$("div",Kt,[l(qe,{modelValue:a.content.text,"onUpdate:modelValue":x=>a.content.text=x,language:"markdown",theme:"vs",options:{minimap:{enabled:!1},fontSize:14,lineHeight:22,padding:{top:16,bottom:16},scrollBeyondLastLine:!1,automaticLayout:!0,wordWrap:"on"},onChange:()=>oe(u)},null,8,["modelValue","onUpdate:modelValue","onChange"])])):re("",!0)],2)]))),128)),l(n(S),{dashed:"",onClick:fe,class:"add-message-btn",size:"small"},{icon:o(()=>[...e[27]||(e[27]=[t("svg",{viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[t("path",{d:"M12 4v16m8-8H4",stroke:"currentColor","stroke-width":"2.5","stroke-linecap":"round","stroke-linejoin":"round"})],-1)])]),default:o(()=>[e[28]||(e[28]=h(" 添加消息模板 ",-1))]),_:1}),v.value.messages.length===0?(b(),$("div",Zt,[...e[29]||(e[29]=[t("svg",{viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[t("path",{d:"M21 15a2 2 0 01-2 2H7l-4 4V5a2 2 0 012-2h14a2 2 0 012 2z",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"})],-1),t("p",null,"暂无消息,点击下方按钮添加消息模板",-1)])])):re("",!0)])])]),_:1})]),_:1},8,["value"])]),_:1},8,["model"])])]),_:1},8,["show"]),l(n(me),{show:B.value,"onUpdate:show":e[7]||(e[7]=a=>B.value=a),preset:"card",title:"测试提示词",style:{width:"90vw",maxWidth:"800px"}},{action:o(()=>[l(n(S),{onClick:e[6]||(e[6]=a=>B.value=!1)},{default:o(()=>[...e[34]||(e[34]=[h("关闭",-1)])]),_:1})]),default:o(()=>[t("div",Yt,[l(n($e),{model:G.value},{default:o(()=>[(b(!0),$(we,null,he(v.value.arguments,a=>(b(),Me(n(K),{key:a.name,label:a.name,required:a.required},{default:o(()=>[l(n(H),{value:G.value.arguments[a.name],"onUpdate:value":u=>G.value.arguments[a.name]=u,placeholder:a.description||`输入 ${a.name}`,clearable:""},null,8,["value","onUpdate:value","placeholder"])]),_:2},1032,["label","required"]))),128))]),_:1},8,["model"]),l(n(dt),null,{default:o(()=>[...e[32]||(e[32]=[h("生成的消息(实时预览)",-1)])]),_:1}),t("div",Qt,[(b(!0),$(we,null,he(ie.value,(a,u)=>(b(),$("div",{key:u,class:"test-message"},[t("div",Xt,[l(n(Oe),{type:a.role==="user"?"info":"success"},{default:o(()=>[h(Q(a.role==="user"?"用户":"助手"),1)]),_:2},1032,["type"])]),t("pre",ea,Q(a.content.text),1)]))),128)),ie.value.length===0?(b(),$("div",ta,[...e[33]||(e[33]=[t("p",null,"暂无消息内容",-1)])])):re("",!0)])])]),_:1},8,["show"])]))}}),sa=Te(aa,[["__scopeId","data-v-3d6d9bdd"]]),na={class:"table-editor"},la={class:"editor-toolbar"},oa={class:"toolbar-left"},ra={key:0,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},ia={key:1,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},ua={class:"toolbar-right"},da={class:"save-indicator-wrapper"},ca={key:0,class:"table-container"},va={class:"table-wrapper",ref:"tableWrapperRef"},pa={key:1,class:"no-table-message"},fa={class:"import-content"},ma={class:"json-editor-wrapper"},ga={class:"json-editor-actions"},wa={class:"batch-loading-content"},ha={class:"loading-text"},ba=ze({__name:"TableEditor",props:{tableDefinition:{},tableId:{}},emits:["saved"],setup(de,{emit:k}){const C=_e(),w=de,B=k,m=f([]),L=f([]),P=f(!1),R=f(!1),F=f(!1),T=f(!0),te=f(50),X=f(1),U=f(""),M=f(!1),q=f("正在处理..."),j=ee(()=>({page:X.value,pageSize:te.value,showSizePicker:!0,pageSizes:[20,50,100,200],showQuickJumper:!0,onUpdatePage:s=>{X.value=s},onUpdatePageSize:s=>{te.value=s,X.value=1}})),E=ee(()=>w.tableDefinition?[{type:"selection",width:50,fixed:"left"},...w.tableDefinition.columns.map(e=>({title:()=>{const a=A("span",{class:"column-name",title:e.description||void 0},e.name);return A("div",{class:"column-header-cell"},[e.description?A(Ke,{trigger:"hover",placement:"top"},{default:()=>e.description,trigger:()=>a}):a,A(Oe,{size:"tiny",type:xe(e.type),style:"margin-left: 6px"},{default:()=>e.type}),e.nullable?null:A("span",{class:"required-mark"},"*")])},key:e.name,minWidth:120,resizable:!0,render(a){return A("div",{class:"cell-wrapper excel-cell"},[e.type==="string"?A(H,{value:a.rowData[e.name],placeholder:"",size:"tiny",class:"excel-input",disabled:T.value,onUpdateValue:u=>{T.value||(a.rowData[e.name]=u,oe(a))},onBlur:()=>ue(a,e)}):e.type==="number"?A("input",{type:"number",value:a.rowData[e.name]??"",placeholder:"",class:"excel-input-native",disabled:T.value,onInput:u=>{if(T.value)return;const p=u.target.value,z=Number(p);(!isNaN(z)||p==="")&&(a.rowData[e.name]=p===""?null:z,oe(a))},onBlur:()=>ue(a,e)}):e.type==="boolean"?A(Ne,{checked:a.rowData[e.name],disabled:T.value,onUpdateChecked:u=>{T.value||(a.rowData[e.name]=u,oe(a))}}):e.type==="date"?A("input",{type:"datetime-local",value:ce(a.rowData[e.name]),class:"excel-input-native",disabled:T.value,onInput:u=>{if(T.value)return;const p=u.target.value;if(p){const z=new Date(p);a.rowData[e.name]=z.toISOString()}else a.rowData[e.name]=null;oe(a)},onBlur:()=>ue(a,e)}):e.type==="json"?A(H,{type:"textarea",value:typeof a.rowData[e.name]=="string"?a.rowData[e.name]:JSON.stringify(a.rowData[e.name]||{},null,2),placeholder:"",rows:2,size:"tiny",class:"excel-textarea",disabled:T.value,onUpdateValue:u=>{T.value||(a.rowData[e.name]=u)},onBlur:()=>{ue(a,e)}}):null])}}))]:[]),le=ee(()=>{if(w.tableDefinition)return 50+w.tableDefinition.columns.length*120});function Z(s){const e=s.id||`new-${m.value.indexOf(s)}`;return{class:L.value.includes(e)?"row-selected":"",style:"cursor: pointer;"}}De(()=>w.tableId,async s=>{s&&w.tableDefinition?await v():(m.value=[],L.value=[])},{immediate:!0});let _=null;Ie(()=>{_=()=>{be()},window.addEventListener("beforeunload",_)});const g=f(!0);Ye(()=>{g.value=!1,_&&(window.removeEventListener("beforeunload",_),_=null),se.forEach(s=>{clearTimeout(s)}),se.clear()});async function v(){var s,e;if(w.tableId)try{const a=await J.get(`/tables/data/${w.tableId}`);a.data.success&&(m.value=a.data.data)}catch(a){C.error("加载数据失败: "+(((e=(s=a.response)==null?void 0:s.data)==null?void 0:e.error)||a.message))}}async function G(){if(!w.tableDefinition)return;const s={tableId:w.tableId||"",rowData:{}};w.tableDefinition.columns.forEach(e=>{if(e.defaultValue!==void 0)s.rowData[e.name]=e.defaultValue;else if(e.nullable)s.rowData[e.name]=null;else switch(e.type){case"string":s.rowData[e.name]="";break;case"number":s.rowData[e.name]=0;break;case"boolean":s.rowData[e.name]=!1;break;case"date":s.rowData[e.name]=new Date().toISOString();break;case"json":s.rowData[e.name]={};break}}),m.value.push(s),await ve(s)}async function ie(){const s=[...L.value],e=m.value.filter(a=>{const u=a.id||`new-${m.value.indexOf(a)}`;return s.includes(u)});if(e.length!==0){M.value=!0,q.value=`正在删除 ${e.length} 条数据...`;try{let a=0,u=0;for(const x of e)if(x.id&&w.tableId)try{await J.delete(`/tables/data/${w.tableId}/${x.id}`),a++}catch(p){console.error("Delete row failed:",p),u++}m.value=m.value.filter(x=>{const p=x.id||`new-${m.value.indexOf(x)}`;return!s.includes(p)}),L.value=[],B("saved"),u>0?C.warning(`成功删除 ${a} 条,失败 ${u} 条`):C.success(`成功删除 ${a} 条数据`)}finally{M.value=!1}}}function ae(s){L.value=s}const se=new Map;async function oe(s,e){await ye(s)}async function ue(s,e){const a=s.rowData[e.name];if((a==null||a==="")&&!e.nullable&&e.defaultValue===void 0){C.warning(`列 ${e.name} 不能为空`),await ve(s);return}try{switch(e.type){case"number":if(typeof a!="number"&&a!==""&&a!==null){const u=Number(a);isNaN(u)?(C.error(`列 ${e.name} 必须是数字`),s.rowData[e.name]=e.defaultValue??0):s.rowData[e.name]=u}break;case"boolean":typeof a!="boolean"&&a!==null&&a!==void 0&&(s.rowData[e.name]=!!a);break;case"date":if(typeof a=="string"&&a){const u=new Date(a);isNaN(u.getTime())?(C.error(`列 ${e.name} 必须是有效的日期`),s.rowData[e.name]=e.defaultValue??new Date().toISOString()):s.rowData[e.name]=u.toISOString()}break;case"json":if(typeof a=="string"&&a)try{s.rowData[e.name]=JSON.parse(a)}catch{C.error(`列 ${e.name} 必须是有效的 JSON`);return}break}await ve(s)}catch(u){console.error(`列 ${e.name} 数据格式错误:`,u),await ve(s)}}function ce(s){if(!s)return"";const e=new Date(s);if(isNaN(e.getTime()))return"";const a=e.getFullYear(),u=String(e.getMonth()+1).padStart(2,"0"),x=String(e.getDate()).padStart(2,"0"),p=String(e.getHours()).padStart(2,"0"),z=String(e.getMinutes()).padStart(2,"0");return`${a}-${u}-${x}T${p}:${z}`}let pe=!1;async function be(){pe||!w.tableId||!w.tableDefinition||m.value.length===0||await ke()}async function ye(s){if(!w.tableId||!w.tableDefinition)return;const e=se.get(s);e&&clearTimeout(e);const a=setTimeout(async()=>{await ve(s),se.delete(s)},300);se.set(s,a)}async function ve(s){var u,x;if(!w.tableId||!w.tableDefinition||!g.value)return;const e=se.get(s);e&&(clearTimeout(e),se.delete(s));const a={};w.tableDefinition.columns.forEach(p=>{const z=s.rowData[p.name];if(z===void 0)if(p.defaultValue!==void 0)a[p.name]=p.defaultValue;else if(p.nullable)a[p.name]=null;else switch(p.type){case"string":a[p.name]="";break;case"number":a[p.name]=0;break;case"boolean":a[p.name]=!1;break;case"date":a[p.name]=new Date().toISOString();break;case"json":a[p.name]={};break}else a[p.name]=z});try{if(s.id){const p=await J.put(`/tables/data/${w.tableId}/${s.id}`,{rowData:a});if(!g.value)return;if(p.data.success){const z=p.data.data;s.createdAt=z.createdAt,s.updatedAt=z.updatedAt,fe(),B("saved")}else console.error("Save row failed:",p.data.error),g.value&&C.error("保存失败: "+(p.data.error||"未知错误"))}else{const p=await J.post(`/tables/data/${w.tableId}`,{rowData:a});if(!g.value)return;if(p.data.success){const z=p.data.data;s.id=z.id,s.createdAt=z.createdAt,s.updatedAt=z.updatedAt,fe(),B("saved")}else console.error("Create row failed:",p.data.error),g.value&&C.error("保存失败: "+(p.data.error||"未知错误"))}}catch(p){if(console.error("Save single row failed:",p),g.value){const z=((x=(u=p.response)==null?void 0:u.data)==null?void 0:x.error)||p.message||"保存失败";if(z.includes("Row not found")&&!g.value)return;C.error("保存失败: "+z)}}}async function ke(){var s,e,a,u,x;if(!pe&&g.value){if(!w.tableId){console.warn("performSave: tableId is missing");return}if(!w.tableDefinition){console.warn("performSave: tableDefinition is missing");return}if(m.value.length!==0){pe=!0,P.value=!0;try{const p=m.value.map(I=>{const V={};return w.tableDefinition.columns.forEach(N=>{const D=I.rowData[N.name];if(D===void 0)if(N.defaultValue!==void 0)V[N.name]=N.defaultValue;else if(N.nullable)V[N.name]=null;else switch(N.type){case"string":V[N.name]="";break;case"number":V[N.name]=0;break;case"boolean":V[N.name]=!1;break;case"date":V[N.name]=new Date().toISOString();break;case"json":V[N.name]={};break}else V[N.name]=D}),{id:I.id,rowData:V}}),z=await J.put(`/tables/data/${w.tableId}/batch`,{rows:p});if(z.data.success){const I=z.data.data||[];if(I.length>0){const V=new Map;I.forEach(D=>{D.id&&V.set(D.id,D)});const N=new Set;m.value.forEach(D=>{if(D.id&&V.has(D.id)){const c=V.get(D.id);D.createdAt=c.createdAt,D.updatedAt=c.updatedAt,N.add(D.id)}}),m.value.forEach(D=>{if(!D.id){const c=I.find(r=>r.id&&!N.has(r.id));c&&c.id&&(D.id=c.id,D.createdAt=c.createdAt,D.updatedAt=c.updatedAt,N.add(c.id))}})}g.value&&(fe(),B("saved"))}else if(console.error("Save failed:",z.data),g.value){const I=((s=z.data)==null?void 0:s.error)||"未知错误";C.error("保存失败: "+I)}}catch(p){if(console.error("Auto save failed:",p),g.value){const z=((a=(e=p.response)==null?void 0:e.data)==null?void 0:a.error)||p.message||"保存失败";if(z.includes("Row not found")){console.warn("Save failed after component unmount, ignoring error");return}console.error("Error details:",{message:p.message,response:(u=p.response)==null?void 0:u.data,status:(x=p.response)==null?void 0:x.status}),C.error("保存失败: "+z)}}finally{pe=!1,P.value=!1}}}}function fe(){R.value=!0,setTimeout(()=>{R.value=!1},1500)}function xe(s){switch(s){case"string":return"info";case"number":return"success";case"boolean":return"warning";case"date":return"default";case"json":return"error";default:return"default"}}async function y(){if(!w.tableId||!w.tableDefinition){C.error("请先选择要导出的表");return}if(m.value.length===0){C.warning("当前表没有数据可导出");return}try{const s=m.value.map(p=>p.rowData),e=JSON.stringify(s,null,2),a=new Blob([e],{type:"application/json"}),u=URL.createObjectURL(a),x=document.createElement("a");x.href=u,x.download=`${w.tableDefinition.name}_data.json`,document.body.appendChild(x),x.click(),document.body.removeChild(x),URL.revokeObjectURL(u),C.success(`成功导出 ${m.value.length} 条数据`)}catch(s){C.error("导出失败: "+(s.message||"未知错误"))}}async function i(s){var e,a;if(!w.tableId||!w.tableDefinition){C.error("请先选择要导入数据的表");return}try{let u;try{const I=JSON.parse(s);if(Array.isArray(I))u=I;else if(I.data&&Array.isArray(I.data))u=I.data,C.warning("检测到旧格式,将只导入数据部分");else{C.error("JSON 格式错误:需要数据数组格式");return}}catch{C.error("JSON 解析失败:文件格式不正确");return}if(u.length===0){C.warning("导入的数据为空"),F.value=!1;return}const x=w.tableDefinition.columns.map(I=>I.name),p=[],z=[];if(u.forEach((I,V)=>{if(!I||typeof I!="object"||Array.isArray(I)){p.push(`第 ${V+1} 行:数据必须是对象格式`);return}w.tableDefinition.columns.forEach(N=>{const D=I[N.name];if(!N.nullable&&N.defaultValue===void 0&&(D==null||D==="")&&p.push(`第 ${V+1} 行,列 "${N.name}":必填字段不能为空`),D!=null&&D!=="")switch(N.type){case"number":typeof D!="number"&&!(typeof D=="string"&&!isNaN(Number(D)))&&p.push(`第 ${V+1} 行,列 "${N.name}":必须是数字类型`);break;case"boolean":typeof D!="boolean"&&p.push(`第 ${V+1} 行,列 "${N.name}":必须是布尔类型`);break;case"date":(typeof D!="string"||isNaN(new Date(D).getTime()))&&p.push(`第 ${V+1} 行,列 "${N.name}":必须是有效的日期格式`);break;case"json":if(D!==null&&typeof D!="object"&&typeof D!="string"&&p.push(`第 ${V+1} 行,列 "${N.name}":必须是对象、数组或 JSON 字符串`),typeof D=="string")try{JSON.parse(D)}catch{p.push(`第 ${V+1} 行,列 "${N.name}":JSON 字符串格式无效`)}break;case"string":break}}),Object.keys(I).forEach(N=>{x.includes(N)||z.push(`第 ${V+1} 行:包含未知列 "${N}",将被忽略`)})}),z.length>0){const I=z.slice(0,10).join(`
|
|
25
|
-
`),V=z.length>10?`
|
|
26
|
-
... 还有 ${z.length-10} 个警告`:"";C.warning(`导入时将忽略以下额外字段:
|
|
27
|
-
${I}${V}`)}if(p.length>0){const I=p.slice(0,10).join(`
|
|
28
|
-
`),V=p.length>10?`
|
|
29
|
-
... 还有 ${p.length-10} 个错误`:"";C.error(`数据校验失败:
|
|
30
|
-
${I}${V}`);return}P.value=!0,M.value=!0,q.value=`正在导入 ${u.length} 条数据...`;try{const I=u.map(N=>{const D={};return w.tableDefinition.columns.forEach(c=>{const r=N[c.name];let d=r;if(r!=null&&r!=="")switch(c.type){case"number":d=typeof r=="string"?Number(r):r;break;case"boolean":d=typeof r=="boolean"?r:!!r;break;case"date":typeof r=="string"&&(d=new Date(r).toISOString());break;case"json":if(typeof r=="string")try{d=JSON.parse(r)}catch{d=r}break}else if(c.defaultValue!==void 0)d=c.defaultValue;else if(c.nullable)d=null;else switch(c.type){case"string":d="";break;case"number":d=0;break;case"boolean":d=!1;break;case"date":d=new Date().toISOString();break;case"json":d={};break}D[c.name]=d}),{rowData:D}}),V=await J.put(`/tables/data/${w.tableId}/batch`,{rows:I});V.data.success?(fe(),await v(),B("saved"),F.value=!1,C.success(`成功导入 ${u.length} 条数据`)):C.error("导入失败:"+(V.data.error||"未知错误"))}catch(I){C.error("导入失败: "+(((a=(e=I.response)==null?void 0:e.data)==null?void 0:a.error)||I.message))}finally{P.value=!1,M.value=!1}}catch(u){C.error("文件读取失败: "+(u.message||"未知错误"))}}async function O(s){var a;const e=(a=s.fileList[0])==null?void 0:a.file;if(e)try{const u=await e.text();await i(u)}catch(u){C.error("文件读取失败: "+(u.message||"未知错误"))}}async function Y(){if(!U.value.trim()){C.warning("请输入 JSON 数据");return}await i(U.value.trim()),U.value=""}return(s,e)=>(b(),$("div",na,[t("div",la,[t("div",oa,[l(n(S),{size:"large",onClick:e[0]||(e[0]=a=>T.value=!T.value),type:T.value?"warning":"success",ghost:""},{icon:o(()=>[T.value?(b(),$("svg",ra,[...e[6]||(e[6]=[t("path",{d:"M19 11H5a2 2 0 00-2 2v7a2 2 0 002 2h14a2 2 0 002-2v-7a2 2 0 00-2-2zM7 11V7a5 5 0 0110 0v4",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"},null,-1)])])):(b(),$("svg",ia,[...e[7]||(e[7]=[t("path",{d:"M19 11H5a2 2 0 00-2 2v7a2 2 0 002 2h14a2 2 0 002-2v-7a2 2 0 00-2-2zM7 11V7a5 5 0 0110 0v4",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"},null,-1),t("path",{d:"M12 15v2M9 17h6",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"},null,-1)])]))]),default:o(()=>[h(" "+Q(T.value?"解锁编辑":"锁定编辑"),1)]),_:1},8,["type"]),l(n(S),{type:"primary",size:"large",onClick:G,disabled:!de.tableDefinition||T.value},{icon:o(()=>[...e[8]||(e[8]=[t("svg",{viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[t("path",{d:"M12 4v16m8-8H4",stroke:"currentColor","stroke-width":"2.5","stroke-linecap":"round","stroke-linejoin":"round"})],-1)])]),default:o(()=>[e[9]||(e[9]=h(" 添加行 ",-1))]),_:1},8,["disabled"]),l(n(S),{size:"large",onClick:ie,disabled:L.value.length===0||T.value,type:"error",ghost:""},{icon:o(()=>[...e[10]||(e[10]=[t("svg",{viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[t("path",{d:"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"})],-1)])]),default:o(()=>[h(" 删除选中 ("+Q(L.value.length)+") ",1)]),_:1},8,["disabled"]),l(n(S),{size:"large",onClick:y,disabled:!de.tableDefinition||m.value.length===0},{icon:o(()=>[...e[11]||(e[11]=[t("svg",{viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[t("path",{d:"M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"})],-1)])]),default:o(()=>[e[12]||(e[12]=h(" 导出 JSON ",-1))]),_:1},8,["disabled"]),l(n(S),{size:"large",onClick:e[1]||(e[1]=a=>F.value=!0),disabled:!de.tableDefinition},{icon:o(()=>[...e[13]||(e[13]=[t("svg",{viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[t("path",{d:"M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-8l-4-4m0 0L8 8m4-4v12",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"})],-1)])]),default:o(()=>[e[14]||(e[14]=h(" 导入 JSON ",-1))]),_:1},8,["disabled"])]),t("div",ua,[t("div",da,[R.value?(b(),$("div",{key:0,class:Ve(["save-success-indicator",{flash:R.value}])},null,2)):re("",!0)]),l(n(Oe),{type:"info",size:"large"},{default:o(()=>[h(" 共 "+Q(m.value.length)+" 行(编辑即保存) ",1)]),_:1})])]),de.tableDefinition?(b(),$("div",ca,[t("div",va,[l(n(je),{columns:E.value,data:m.value,pagination:j.value,"row-key":a=>a.id||`new-${m.value.indexOf(a)}`,"row-props":Z,"max-height":600,"scroll-x":le.value,bordered:!0,"single-line":!1,"onUpdate:checkedRowKeys":ae,class:"editable-data-table excel-table"},null,8,["columns","data","pagination","row-key","scroll-x"])],512)])):(b(),$("div",pa,[l(n(Se),{description:"请先创建或选择表定义"})])),l(n(me),{show:F.value,"onUpdate:show":e[4]||(e[4]=a=>F.value=a),preset:"card",bordered:!1,class:"import-modal",style:{width:"90vw",maxWidth:"600px"}},{header:o(()=>[...e[15]||(e[15]=[t("div",{class:"modal-header"},[t("div",{class:"modal-icon"},[t("svg",{viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[t("path",{d:"M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-8l-4-4m0 0L8 8m4-4v12",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"})])]),t("div",null,[t("h3",{class:"modal-title"},"导入表数据"),t("p",{class:"modal-subtitle"},"从 JSON 文件导入表数据")])],-1)])]),default:o(()=>[t("div",fa,[l(n(Ae),{"default-value":"file",type:"line"},{default:o(()=>[l(n(ge),{name:"file",tab:"文件上传"},{default:o(()=>[l(n(ct),{"file-list":[],accept:".json",max:1,onChange:O},{default:o(()=>[l(n(vt),null,{default:o(()=>[...e[16]||(e[16]=[t("div",{class:"upload-area"},[t("svg",{class:"upload-icon",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[t("path",{d:"M21 15v4a2 2 0 01-2 2H5a2 2 0 01-2-2v-4m17-7l-5-5m0 0L7 8m9-5v12",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"})]),t("p",{class:"upload-text"},"点击或拖拽 JSON 文件到此处"),t("p",{class:"upload-hint"},"支持导入表数据")],-1)])]),_:1})]),_:1})]),_:1}),l(n(ge),{name:"text",tab:"直接编辑/粘贴"},{default:o(()=>[t("div",ma,[l(n(H),{value:U.value,"onUpdate:value":e[2]||(e[2]=a=>U.value=a),type:"textarea",placeholder:"请粘贴或输入 JSON 数据(数组格式)...",rows:15,class:"json-textarea"},null,8,["value"]),t("div",ga,[l(n(S),{onClick:Y,type:"primary",disabled:!U.value.trim()},{default:o(()=>[...e[17]||(e[17]=[h(" 导入 ",-1)])]),_:1},8,["disabled"]),l(n(S),{onClick:e[3]||(e[3]=a=>U.value="")},{default:o(()=>[...e[18]||(e[18]=[h(" 清空 ",-1)])]),_:1})])])]),_:1})]),_:1})])]),_:1},8,["show"]),l(n(me),{show:M.value,"onUpdate:show":e[5]||(e[5]=a=>M.value=a),"mask-closable":!1,"close-on-esc":!1,"auto-focus":!1,preset:"dialog",closable:!1,"show-icon":!1,style:{width:"400px"}},{default:o(()=>[t("div",wa,[l(n(pt),{size:"large"},{description:o(()=>[t("div",ha,Q(q.value),1)]),_:1})])]),_:1},8,["show"])]))}}),ya=Te(ba,[["__scopeId","data-v-da42254c"]]),ka={class:"tables-page"},xa={class:"tables-toolbar"},Ca={class:"toolbar-left"},$a={class:"table-select-with-icon"},Sa={class:"toolbar-right"},Ma={class:"toolbar-switch"},za={class:"explore-config-panel"},Da={class:"explore-config-list"},_a={key:0,class:"empty-tables-hint"},Ta={class:"explore-config-item-info"},Ua={class:"table-name"},ja={key:0,class:"table-description"},Ia={key:0,class:"tables-table-container"},Na={key:1,class:"no-table-selected"},Aa={class:"columns-section"},Ba={class:"columns-header"},Va={class:"columns-list"},Ra={class:"column-index"},Oa={key:0,class:"empty-columns"},Pa={class:"form-actions"},Ea={class:"modal-header"},Ha={class:"modal-subtitle"},La={class:"column-descriptions-section"},Fa={class:"column-description-label"},qa={class:"column-name-label"},Ja={key:0,class:"empty-columns-hint"},Wa={class:"form-actions"},Ka=ze({__name:"Tables",setup(de){const k=_e(),C=Pe(),w=f([]),B=f(null),m=f(null),L=f(!1),P=f(!1),R=f(!1),F=f(!1),T=f(!1),te=f(!1),X=f(!1),U=f(null),M=f(""),q=f({}),j=f(!0),E=f({}),le=[{label:"字符串",value:"string"},{label:"数字",value:"number"},{label:"布尔值",value:"boolean"},{label:"日期",value:"date"},{label:"JSON",value:"json"}],Z=f({name:"",description:"",columns:[]}),_={name:{required:!0,message:"表名不能为空",trigger:"blur"}},g=ee(()=>w.value.map(y=>({label:y.name,value:y.id,description:y.description})));function v(y){if(y){const i=w.value.find(O=>O.id===y);i&&ce(i)}else B.value=null,m.value=null}const G=ee({get:()=>L.value,set:y=>{L.value=y}});Ie(async()=>{await ue(),await ie()});async function ie(){try{if(await C.fetchConfig(),C.currentConfig){const y=C.currentConfig;j.value=y.enableExploreTable!==!1}}catch(y){console.error("加载配置失败:",y)}}async function ae(y){X.value=!0;try{await C.updateConfig({enableExploreTable:y}),k.success(y?"已允许 AI 探索数据表":"已禁止 AI 探索数据表")}catch(i){k.error("更新配置失败: "+(i.message||"未知错误")),j.value=!y}finally{X.value=!1}}function se(y){return y.allowExplore!==!1}async function oe(y,i){var O,Y;E.value[y]=!0;try{const s=w.value.find(a=>a.id===y);if(!s){k.error("表不存在");return}(await J.put(`/tables/definitions/${y}`,{allowExplore:i})).data.success&&(s.allowExplore=i,k.success(i?`已允许 AI 探索表「${s.name}」`:`已禁止 AI 探索表「${s.name}」`),m.value&&m.value.id===y&&(m.value.allowExplore=i))}catch(s){k.error("更新失败: "+(((Y=(O=s.response)==null?void 0:O.data)==null?void 0:Y.error)||s.message))}finally{E.value[y]=!1}}async function ue(){var y,i;try{const O=await J.get("/tables/definitions");O.data.success&&(w.value=O.data.data,w.value.length>0&&!B.value&&ce(w.value[0]))}catch(O){k.error("加载表列表失败: "+(((i=(y=O.response)==null?void 0:y.data)==null?void 0:i.error)||O.message))}}function ce(y){B.value=y.id,m.value=y}function pe(){Z.value.columns.push({name:"",type:"string",nullable:!0,description:""})}function be(y){Z.value.columns.splice(y,1)}async function ye(){U.value&&await U.value.validate(async y=>{var i,O;if(!y){if(Z.value.columns.length===0){k.warning("至少需要定义一个列");return}T.value=!0;try{const Y=await J.post("/tables/definitions",Z.value);Y.data.success&&(k.success("表创建成功"),L.value=!1,Z.value={name:"",description:"",columns:[]},await ue(),ce(Y.data.data))}catch(Y){k.error("保存失败: "+(((O=(i=Y.response)==null?void 0:i.data)==null?void 0:O.error)||Y.message))}finally{T.value=!1}}})}async function ve(){var y,i;if(m.value){F.value=!0;try{(await J.delete(`/tables/definitions/${m.value.id}`)).data.success&&(k.success("表删除成功"),B.value=null,m.value=null,R.value=!1,await ue())}catch(O){k.error("删除失败: "+(((i=(y=O.response)==null?void 0:y.data)==null?void 0:i.error)||O.message))}finally{F.value=!1}}}function ke(){}De(P,y=>{y&&m.value&&(M.value=m.value.description||"",q.value={},m.value.columns&&m.value.columns.forEach(i=>{q.value[i.name]=i.description||""}))});function fe(y){switch(y){case"string":return"info";case"number":return"success";case"boolean":return"warning";case"date":return"default";case"json":return"error";default:return"default"}}async function xe(){var y,i;if(!m.value||!B.value){k.error("请先选择一个表");return}te.value=!0;try{const O=m.value.columns.map(s=>({...s,description:q.value[s.name]||void 0})),Y=await J.put(`/tables/definitions/${B.value}`,{description:M.value||null,columns:O});Y.data.success&&(k.success("表声明和字段声明更新成功"),P.value=!1,m.value&&(m.value.description=Y.data.data.description,m.value.columns=Y.data.data.columns),await ue())}catch(O){k.error("更新失败: "+(((i=(y=O.response)==null?void 0:y.data)==null?void 0:i.error)||O.message))}finally{te.value=!1}}return(y,i)=>{var Y,s;const O=Qe("n-tag");return b(),$("div",ka,[t("div",xa,[t("div",Ca,[t("div",$a,[l(n(Be),{value:B.value,"onUpdate:value":[i[0]||(i[0]=e=>B.value=e),v],options:g.value,placeholder:"选择表...",size:"large",clearable:"",filterable:"",class:"table-select"},{empty:o(()=>[l(n(Se),{description:"暂无表",size:"small"})]),_:1},8,["value","options"]),(Y=m.value)!=null&&Y.description?(b(),Me(n(Ke),{key:0,trigger:"hover",placement:"top"},{trigger:o(()=>[...i[14]||(i[14]=[t("div",{class:"table-info-icon"},[t("svg",{viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[t("path",{d:"M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"})])],-1)])]),default:o(()=>[h(" "+Q(m.value.description),1)]),_:1})):re("",!0)])]),t("div",Sa,[t("div",Ma,[l(n(Ee),{value:j.value,"onUpdate:value":[i[1]||(i[1]=e=>j.value=e),ae],size:"medium",loading:X.value},{checked:o(()=>[...i[15]||(i[15]=[h("允许 AI 探索数据表",-1)])]),unchecked:o(()=>[...i[16]||(i[16]=[h("禁止 AI 探索数据表",-1)])]),_:1},8,["value","loading"]),l(n(ft),{trigger:"hover",placement:"bottom-end",style:{width:"400px",maxHeight:"500px"}},{trigger:o(()=>[...i[17]||(i[17]=[t("div",{class:"explore-config-icon",title:"配置表探索权限"},[t("svg",{viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[t("path",{d:"M19.14 12.94c.04-.3.06-.61.06-.94 0-.32-.02-.64-.07-.94l2.03-1.58c.18-.14.23-.41.12-.61l-1.92-3.32c-.12-.22-.37-.29-.59-.22l-2.39.96c-.5-.38-1.03-.7-1.62-.94L14.4 2.81c-.04-.24-.24-.41-.48-.41h-3.84c-.24 0-.43.17-.47.41l-.36 2.54c-.59.24-1.13.57-1.62.94l-2.39-.96c-.22-.08-.47 0-.59.22L2.74 8.87c-.12.21-.08.47.12.61l2.03 1.58c-.05.3-.09.63-.09.94s.02.64.07.94l-2.03 1.58c-.18.14-.23.41-.12.61l1.92 3.32c.12.22.37.29.59.22l2.39-.96c.5.38 1.03.7 1.62.94l.36 2.54c.05.24.24.41.48.41h3.84c.24 0 .44-.17.47-.41l.36-2.54c.59-.24 1.13-.56 1.62-.94l2.39.96c.22.08.47 0 .59-.22l1.92-3.32c.12-.22.07-.47-.12-.61l-2.01-1.58zM12 15.6c-1.98 0-3.6-1.62-3.6-3.6s1.62-3.6 3.6-3.6 3.6 1.62 3.6 3.6-1.62 3.6-3.6 3.6z",fill:"currentColor"})])],-1)])]),default:o(()=>[t("div",za,[i[18]||(i[18]=t("div",{class:"explore-config-header"},[t("h4",null,"配置表探索权限"),t("p",{class:"explore-config-hint"},"控制哪些表允许被 AI 探索(默认为允许)")],-1)),t("div",Da,[w.value.length===0?(b(),$("div",_a,[l(n(Se),{description:"暂无表",size:"small"})])):re("",!0),(b(!0),$(we,null,he(w.value,e=>(b(),$("div",{key:e.id,class:"explore-config-item"},[t("div",Ta,[t("span",Ua,Q(e.name),1),e.description?(b(),$("span",ja,Q(e.description),1)):re("",!0)]),l(n(Ee),{value:se(e),"onUpdate:value":a=>oe(e.id,a),size:"small",loading:E.value[e.id]},null,8,["value","onUpdate:value","loading"])]))),128))])])]),_:1})]),m.value?(b(),Me(n(S),{key:0,size:"large",ghost:"",onClick:i[2]||(i[2]=e=>P.value=!0),class:"edit-table-btn"},{icon:o(()=>[...i[19]||(i[19]=[t("svg",{viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[t("path",{d:"M11 4H4a2 2 0 00-2 2v14a2 2 0 002 2h14a2 2 0 002-2v-7",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"}),t("path",{d:"M18.5 2.5a2.121 2.121 0 013 3L12 15l-4 1 1-4 9.5-9.5z",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"})],-1)])]),default:o(()=>[i[20]||(i[20]=h(" 编辑表声明 ",-1))]),_:1})):re("",!0),m.value?(b(),Me(n(S),{key:1,type:"error",size:"large",ghost:"",onClick:i[3]||(i[3]=e=>R.value=!0),class:"delete-table-btn"},{icon:o(()=>[...i[21]||(i[21]=[t("svg",{viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[t("path",{d:"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"})],-1)])]),default:o(()=>[i[22]||(i[22]=h(" 删除表 ",-1))]),_:1})):re("",!0),l(n(S),{type:"primary",size:"large",onClick:i[4]||(i[4]=e=>L.value=!0),class:"create-table-btn"},{icon:o(()=>[...i[23]||(i[23]=[t("svg",{viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[t("path",{d:"M12 4v16m8-8H4",stroke:"currentColor","stroke-width":"2.5","stroke-linecap":"round","stroke-linejoin":"round"})],-1)])]),default:o(()=>[i[24]||(i[24]=h(" 创建新表 ",-1))]),_:1})])]),m.value?(b(),$("div",Ia,[l(ya,{"table-definition":m.value,"table-id":B.value,onSaved:ke},null,8,["table-definition","table-id"])])):(b(),$("div",Na,[l(n(Se),{description:"请选择一个表进行编辑"})])),l(n(me),{show:R.value,"onUpdate:show":i[5]||(i[5]=e=>R.value=e),preset:"dialog",type:"warning",title:"确认删除",content:`确定要删除表「${(s=m.value)==null?void 0:s.name}」吗?此操作将同时删除表中的所有数据,且不可恢复。`,"positive-text":"确认删除","negative-text":"取消","positive-button-props":{type:"error"},loading:F.value,onPositiveClick:ve,onNegativeClick:i[6]||(i[6]=e=>R.value=!1)},null,8,["show","content","loading"]),l(n(me),{show:G.value,"onUpdate:show":i[10]||(i[10]=e=>G.value=e),preset:"card",bordered:!1,class:"table-definition-modal",style:{width:"90vw",maxWidth:"800px"}},{header:o(()=>[...i[25]||(i[25]=[t("div",{class:"modal-header"},[t("div",{class:"modal-icon"},[t("svg",{viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[t("path",{d:"M3 3h18v18H3V3zm2 2v14h14V5H5zm2 2h10v2H7V7zm0 4h10v2H7v-2zm0 4h7v2H7v-2z",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"})])]),t("div",null,[t("h3",{class:"modal-title"}," 创建新表 "),t("p",{class:"modal-subtitle"}," 定义表的结构和列类型(创建后不可修改) ")])],-1)])]),default:o(()=>[l(n($e),{ref_key:"tableFormRef",ref:U,model:Z.value,rules:_,class:"table-form"},{default:o(()=>[l(n(K),{path:"name",label:"表名"},{default:o(()=>[l(n(H),{value:Z.value.name,"onUpdate:value":i[7]||(i[7]=e=>Z.value.name=e),placeholder:"例如: users, products",size:"large"},null,8,["value"])]),_:1}),l(n(K),{path:"description",label:"描述"},{default:o(()=>[l(n(H),{value:Z.value.description,"onUpdate:value":i[8]||(i[8]=e=>Z.value.description=e),placeholder:"表的用途说明",size:"large",type:"textarea",rows:2},null,8,["value"])]),_:1}),l(n(K),{label:"列定义"},{default:o(()=>[t("div",Aa,[t("div",Ba,[i[28]||(i[28]=t("span",null,null,-1)),l(n(S),{dashed:"",onClick:pe,size:"medium"},{icon:o(()=>[...i[26]||(i[26]=[t("svg",{viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[t("path",{d:"M12 4v16m8-8H4",stroke:"currentColor","stroke-width":"2.5","stroke-linecap":"round","stroke-linejoin":"round"})],-1)])]),default:o(()=>[i[27]||(i[27]=h(" 添加列 ",-1))]),_:1})]),t("div",Va,[(b(!0),$(we,null,he(Z.value.columns,(e,a)=>(b(),$("div",{key:a,class:"column-row"},[t("span",Ra,"#"+Q(a+1),1),l(n(K),{path:`columns[${a}].name`,"show-label":!1,rule:{required:!0,message:"必填",trigger:"blur"},class:"column-field-name"},{default:o(()=>[l(n(H),{value:e.name,"onUpdate:value":u=>e.name=u,placeholder:"列名"},null,8,["value","onUpdate:value"])]),_:2},1032,["path"]),l(n(K),{path:`columns[${a}].type`,"show-label":!1,rule:{required:!0,message:"必填",trigger:"change"},class:"column-field-type"},{default:o(()=>[l(n(Be),{value:e.type,"onUpdate:value":u=>e.type=u,options:le},null,8,["value","onUpdate:value"])]),_:2},1032,["path"]),l(n(Ne),{checked:!e.nullable,"onUpdate:checked":u=>e.nullable=!u,class:"column-field-nullable"},{default:o(()=>[...i[29]||(i[29]=[h("必要",-1)])]),_:1},8,["checked","onUpdate:checked"]),l(n(K),{path:`columns[${a}].description`,"show-label":!1,class:"column-field-description"},{default:o(()=>[l(n(H),{value:e.description,"onUpdate:value":u=>e.description=u,placeholder:"列说明(可选)"},null,8,["value","onUpdate:value"])]),_:2},1032,["path"]),l(n(S),{type:"error",text:"",size:"small",onClick:u=>be(a),class:"column-delete-btn"},{default:o(()=>[...i[30]||(i[30]=[h(" 删除 ",-1)])]),_:1},8,["onClick"])]))),128)),Z.value.columns.length===0?(b(),$("div",Oa,[l(n(Se),{description:"暂无列,点击上方添加列按钮添加",size:"small"})])):re("",!0)])])]),_:1}),t("div",Pa,[l(n(S),{size:"large",onClick:i[9]||(i[9]=e=>G.value=!1)},{default:o(()=>[...i[31]||(i[31]=[h(" 取消 ",-1)])]),_:1}),l(n(S),{type:"primary",size:"large",loading:T.value,onClick:ye},{default:o(()=>[...i[32]||(i[32]=[h(" 保存 ",-1)])]),_:1},8,["loading"])])]),_:1},8,["model"])]),_:1},8,["show"]),l(n(me),{show:P.value,"onUpdate:show":i[13]||(i[13]=e=>P.value=e),preset:"card",bordered:!1,class:"edit-table-description-modal",style:{width:"90vw",maxWidth:"600px"}},{header:o(()=>{var e;return[t("div",Ea,[i[34]||(i[34]=t("div",{class:"modal-icon"},[t("svg",{viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[t("path",{d:"M11 4H4a2 2 0 00-2 2v14a2 2 0 002 2h14a2 2 0 002-2v-7",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"}),t("path",{d:"M18.5 2.5a2.121 2.121 0 013 3L12 15l-4 1 1-4 9.5-9.5z",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"})])],-1)),t("div",null,[i[33]||(i[33]=t("h3",{class:"modal-title"}," 编辑表声明 ",-1)),t("p",Ha," 编辑表「"+Q((e=m.value)==null?void 0:e.name)+"」的描述信息 ",1)])])]}),default:o(()=>[l(n($e),{ref:"editTableFormRef",class:"edit-table-form"},{default:o(()=>[l(n(K),{label:"表声明"},{default:o(()=>[l(n(H),{value:M.value,"onUpdate:value":i[11]||(i[11]=e=>M.value=e),placeholder:"表的用途说明",size:"large",type:"textarea",rows:4},null,8,["value"])]),_:1}),l(n(K),{label:"字段声明"},{default:o(()=>{var e,a;return[t("div",La,[(b(!0),$(we,null,he(((e=m.value)==null?void 0:e.columns)||[],u=>(b(),$("div",{key:u.name,class:"column-description-row"},[t("div",Fa,[t("span",qa,Q(u.name),1),l(O,{size:"tiny",type:fe(u.type),style:{"margin-left":"8px"}},{default:o(()=>[h(Q(u.type),1)]),_:2},1032,["type"])]),l(n(H),{value:q.value[u.name],"onUpdate:value":x=>q.value[u.name]=x,placeholder:`${u.name} 字段的说明(可选)`,size:"medium",clearable:""},null,8,["value","onUpdate:value","placeholder"])]))),128)),!((a=m.value)!=null&&a.columns)||m.value.columns.length===0?(b(),$("div",Ja,[l(n(Se),{description:"当前表没有字段",size:"small"})])):re("",!0)])]}),_:1}),t("div",Wa,[l(n(S),{size:"large",onClick:i[12]||(i[12]=e=>P.value=!1)},{default:o(()=>[...i[35]||(i[35]=[h(" 取消 ",-1)])]),_:1}),l(n(S),{type:"primary",size:"large",loading:te.value,onClick:xe},{default:o(()=>[...i[36]||(i[36]=[h(" 保存 ",-1)])]),_:1},8,["loading"])])]),_:1},512)]),_:1},8,["show"])])}}}),Za=Te(Ka,[["__scopeId","data-v-c01436bb"]]),Ga={class:"interfaces-manager"},Ya={class:"pages-section"},Qa={class:"section-toolbar"},Xa={viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",style:{width:"16px",height:"16px"}},es={class:"functions-section"},ts={class:"section-toolbar"},as={viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",style:{width:"16px",height:"16px"}},ss={class:"sdk-section"},ns={style:{"margin-top":"12px"}},ls={style:{display:"flex","align-items":"center",gap:"12px"}},os={viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",style:{width:"24px",height:"24px"}},rs={style:{display:"flex","justify-content":"flex-end",gap:"12px"}},is={style:{display:"flex","align-items":"center",gap:"12px"}},us={viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",style:{width:"24px",height:"24px"}},ds={style:{"margin-top":"24px"}},cs={style:{display:"flex","justify-content":"space-between","align-items":"center","margin-bottom":"12px"}},vs={style:{display:"flex","justify-content":"space-between","margin-bottom":"8px"}},ps={style:{display:"grid","grid-template-columns":"repeat(4, 1fr)",gap:"12px"}},fs={class:"script-editor-section"},ms={viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",style:{width:"16px",height:"16px"}},gs={key:0,class:"monaco-wrapper"},ws={style:{display:"flex","justify-content":"flex-end",gap:"12px"}},Le=`/**
|
|
31
|
-
* 函数脚本
|
|
32
|
-
* @param args 函数参数对象 (类型根据 Schema 声明自动生成)
|
|
33
|
-
* @param context 上下文对象 (提供常用工具方法等)
|
|
34
|
-
*/
|
|
35
|
-
export default async function (args: ToolArgs, context: Context) {
|
|
36
|
-
const { log } = context;
|
|
37
|
-
|
|
38
|
-
log.info('函数执行中');
|
|
39
|
-
|
|
40
|
-
return {
|
|
41
|
-
// 返回结果
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
`,hs=ze({__name:"InterfacesManager",setup(de){const k=_e(),C=mt(),w=Pe(),B=f([]),m=f([]),L=f("pages"),P=f([]),R=f(""),F=f(!1),T=f(null),te=f(!1),X=f(),U=f({name:"",description:"",content:""}),M={name:{required:!0,message:"请输入页面名称",trigger:"blur"},content:{required:!0,message:"请输入页面内容",trigger:"blur"}},q=f([]),j=f(""),E=f(!1),le=f(null),Z=f(!1),_=f(),g=f("basic"),v=f({name:"",description:"",serverScript:Le,parameters:[]}),G={name:{required:!0,message:"请输入函数名称",trigger:"blur"},description:{required:!0,message:"请输入函数描述",trigger:"blur"},serverScript:{required:!0,message:"请输入函数脚本",trigger:"blur"}},ie=[{label:"string",value:"string"},{label:"number",value:"number"},{label:"boolean",value:"boolean"},{label:"object",value:"object"},{label:"array",value:"array"}],ae=f("");async function se(){try{const c=await J.get("/configs/all-tools");c.data.success&&c.data.data.tools?B.value=c.data.data.tools:B.value=[]}catch(c){console.error("Failed to load MCP tools:",c),B.value=[]}}async function oe(){try{const c=await J.get("/tables/definitions");c.data.success&&(m.value=c.data.data||[])}catch(c){console.error("Failed to load tables:",c),m.value=[]}}const ue=ee(()=>{const c=w.currentConfig;return c?lt({config:c,mcpTools:B.value,tables:m.value}):"declare interface Context {}"}),ce=ee(()=>!v.value.parameters||v.value.parameters.length===0?`
|
|
45
|
-
/**
|
|
46
|
-
* 函数参数类型
|
|
47
|
-
*/
|
|
48
|
-
declare interface ToolArgs {
|
|
49
|
-
[key: string]: any;
|
|
50
|
-
}
|
|
51
|
-
`:`
|
|
52
|
-
/**
|
|
53
|
-
* 函数参数类型
|
|
54
|
-
* 根据 Schema 声明自动生成
|
|
55
|
-
*/
|
|
56
|
-
declare interface ToolArgs {
|
|
57
|
-
${v.value.parameters.filter(r=>r.name&&r.name.trim()).map(r=>{const d=r.name.trim(),ne=/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(d)?d:`"${d.replace(/"/g,'\\"')}"`,Ze=r.required?"":"?",Ge=r.description?`/** ${r.description.replace(/\*\//g,"* /")} */
|
|
58
|
-
`:"";let Ce="any";switch(r.type){case"string":Ce="string";break;case"number":Ce="number";break;case"boolean":Ce="boolean";break;case"object":Ce="Record<string, any>";break;case"array":Ce="any[]";break;default:Ce="any"}return`${Ge}${ne}${Ze}: ${Ce};`}).join(`
|
|
59
|
-
`)}
|
|
60
|
-
}
|
|
61
|
-
`),pe=ee(()=>[{content:ue.value,filePath:"file:///context.d.ts"},{content:ce.value,filePath:"file:///tool-args.d.ts"}]),be=ee(()=>"height: 500px; width: 100%; border-radius: 4px; overflow: hidden;");function ye(c){v.value.serverScript=c}const ve=ee(()=>{const c=window.location.origin;return"<script"+' src="'+c+"/api/interfaces/sdk/"+ae.value+'">'+"<\/script>"}),ke=ee(()=>{const c="<script",r="<\/script>";if(q.value.length===0)return`<!-- 示例:调用函数 -->
|
|
62
|
-
<button onclick="callFunction()">调用函数</button>
|
|
63
|
-
`+c+`>
|
|
64
|
-
async function callFunction() {
|
|
65
|
-
try {
|
|
66
|
-
const result = await MCPSDK.myFunction('参数1', 123);
|
|
67
|
-
console.log('结果:', result);
|
|
68
|
-
} catch (error) {
|
|
69
|
-
console.error('调用失败:', error);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
`+r;const d=q.value[0],W=d.parameters.map(ne=>ne.name).join(", ");return"<!-- 示例:调用函数 "+d.name+` -->
|
|
73
|
-
<button onclick="callFunction()">调用函数</button>
|
|
74
|
-
`+c+`>
|
|
75
|
-
async function callFunction() {
|
|
76
|
-
try {
|
|
77
|
-
const result = await MCPSDK.`+d.name+"("+W+`);
|
|
78
|
-
console.log('结果:', result);
|
|
79
|
-
} catch (error) {
|
|
80
|
-
console.error('调用失败:', error);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
`+r}),fe=ee(()=>{if(!R.value)return P.value;const c=R.value.toLowerCase();return P.value.filter(r=>r.name.toLowerCase().includes(c)||r.description&&r.description.toLowerCase().includes(c))}),xe=[{title:"页面名称",key:"name",width:200},{title:"描述",key:"description",width:300},{title:"操作",key:"actions",width:250,render:c=>A("div",{style:"display: flex; gap: 8px;"},[A(S,{size:"small",type:"primary",onClick:r=>{r.stopPropagation(),a(c)}},{default:()=>"打开"}),A(S,{size:"small",onClick:r=>{r.stopPropagation(),u(c)}},{default:()=>"编辑"}),A(S,{size:"small",type:"error",onClick:r=>{r.stopPropagation(),p(c)}},{default:()=>"删除"})])}],y=c=>({style:{cursor:"pointer"},onClick:()=>a(c)}),i=ee(()=>{if(!j.value)return q.value;const c=j.value.toLowerCase();return q.value.filter(r=>r.name.toLowerCase().includes(c)||r.description.toLowerCase().includes(c))}),O=[{title:"函数名称",key:"name",width:200},{title:"描述",key:"description",width:300},{title:"参数",key:"parameters",render:c=>c.parameters.map(r=>`${r.name}: ${r.type}`).join(", ")||"无"},{title:"操作",key:"actions",width:200,render:c=>A("div",{style:"display: flex; gap: 8px;"},[A(S,{size:"small",onClick:()=>I(c)},{default:()=>"编辑"}),A(S,{size:"small",type:"error",onClick:()=>N(c)},{default:()=>"删除"})])}],Y=c=>({style:{cursor:"pointer"},onClick:()=>I(c)});async function s(){var c,r;try{const d=await J.get("/interfaces/pages");d.data.success&&(P.value=d.data.data)}catch(d){k.error("加载页面列表失败: "+(((r=(c=d.response)==null?void 0:c.data)==null?void 0:r.error)||d.message))}}function e(){return{name:"",type:"string",description:"",required:!1}}function a(c){if(!ae.value){k.warning("用户信息未加载,请稍后再试"),D().then(()=>{if(ae.value){const ne=`${window.location.origin}/api/interfaces/page/${ae.value}/${c.id}`;window.open(ne,"_blank")}else k.error("无法获取用户信息")});return}if(!c||!c.id){k.error("页面信息不完整");return}const d=`${window.location.origin}/api/interfaces/page/${ae.value}/${c.id}`;console.log("打开页面:",d),window.open(d,"_blank")}function u(c){T.value=c,U.value={name:c.name,description:c.description||"",content:c.content},F.value=!0}async function x(){X.value&&await X.value.validate(async c=>{var r,d;if(!c){te.value=!0;try{T.value?(await J.put(`/interfaces/pages/${T.value.id}`,U.value),k.success("更新成功")):(await J.post("/interfaces/pages",U.value),k.success("创建成功")),F.value=!1,T.value=null,U.value={name:"",description:"",content:""},await s()}catch(W){k.error("保存失败: "+(((d=(r=W.response)==null?void 0:r.data)==null?void 0:d.error)||W.message))}finally{te.value=!1}}})}function p(c){C.warning({title:"确认删除",content:`确定要删除页面 "${c.name}" 吗?`,positiveText:"删除",negativeText:"取消",onPositiveClick:async()=>{var r,d;try{await J.delete(`/interfaces/pages/${c.id}`),k.success("删除成功"),await s()}catch(W){k.error("删除失败: "+(((d=(r=W.response)==null?void 0:r.data)==null?void 0:d.error)||W.message))}}})}async function z(){var c,r;try{const d=await J.get("/interfaces/functions");d.data.success&&(q.value=d.data.data)}catch(d){k.error("加载函数列表失败: "+(((r=(c=d.response)==null?void 0:c.data)==null?void 0:r.error)||d.message))}}function I(c){le.value=c,v.value={name:c.name,description:c.description,serverScript:c.serverScript||Le,parameters:JSON.parse(JSON.stringify(c.parameters))},g.value="basic",E.value=!0}async function V(){_.value&&await _.value.validate(async c=>{var r,d;if(!c){if(!v.value.serverScript){k.error("请输入函数脚本");return}Z.value=!0;try{const W={name:v.value.name,description:v.value.description,serverScript:v.value.serverScript,parameters:v.value.parameters.filter(ne=>ne.name)};le.value?(await J.put(`/interfaces/functions/${le.value.id}`,W),k.success("更新成功")):(await J.post("/interfaces/functions",W),k.success("创建成功")),E.value=!1,le.value=null,v.value={name:"",description:"",serverScript:"",parameters:[]},await z()}catch(W){k.error("保存失败: "+(((d=(r=W.response)==null?void 0:r.data)==null?void 0:d.error)||W.message))}finally{Z.value=!1}}})}function N(c){C.warning({title:"确认删除",content:`确定要删除函数 "${c.name}" 吗?`,positiveText:"删除",negativeText:"取消",onPositiveClick:async()=>{var r,d;try{await J.delete(`/interfaces/functions/${c.id}`),k.success("删除成功"),await z()}catch(W){k.error("删除失败: "+(((d=(r=W.response)==null?void 0:r.data)==null?void 0:d.error)||W.message))}}})}async function D(){var c,r;try{const d=await J.get("/interfaces/user-hash");d.data.success?(ae.value=d.data.data.userHash,console.log("用户hash加载成功:",ae.value)):(console.error("获取用户hash失败:",d.data.error),k.error("获取用户信息失败: "+(d.data.error||"未知错误")))}catch(d){console.error("获取用户hash失败:",d),k.error("获取用户信息失败: "+(((r=(c=d.response)==null?void 0:c.data)==null?void 0:r.error)||d.message))}}return De(()=>E.value,async c=>{c&&(await Fe(),await se(),await oe(),w.currentConfig||(await w.fetchConfig(),await se(),await oe()))}),Ie(()=>{s(),z(),D(),w.currentConfig?(se(),oe()):w.fetchConfig().then(()=>{se(),oe()})}),(c,r)=>(b(),$("div",Ga,[l(n(Ae),{value:L.value,"onUpdate:value":r[4]||(r[4]=d=>L.value=d),type:"line",animated:"",size:"large"},{default:o(()=>[l(n(ge),{name:"pages",tab:"页面管理"},{default:o(()=>[t("div",Ya,[t("div",Qa,[l(n(S),{type:"primary",size:"large",onClick:r[0]||(r[0]=d=>F.value=!0)},{icon:o(()=>[...r[17]||(r[17]=[t("svg",{viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[t("path",{d:"M12 4v16m8-8H4",stroke:"currentColor","stroke-width":"2.5","stroke-linecap":"round","stroke-linejoin":"round"})],-1)])]),default:o(()=>[r[18]||(r[18]=h(" 创建页面 ",-1))]),_:1}),l(n(H),{value:R.value,"onUpdate:value":r[1]||(r[1]=d=>R.value=d),placeholder:"搜索页面...",size:"large",clearable:"",style:{"max-width":"300px"}},{prefix:o(()=>[(b(),$("svg",Xa,[...r[19]||(r[19]=[t("path",{d:"M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"},null,-1)])]))]),_:1},8,["value"])]),l(n(je),{columns:xe,data:fe.value,pagination:!1,"row-props":y,class:"modern-table"},null,8,["data"])])]),_:1}),l(n(ge),{name:"functions",tab:"函数管理"},{default:o(()=>[t("div",es,[t("div",ts,[l(n(S),{type:"primary",size:"large",onClick:r[2]||(r[2]=d=>E.value=!0)},{icon:o(()=>[...r[20]||(r[20]=[t("svg",{viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[t("path",{d:"M12 4v16m8-8H4",stroke:"currentColor","stroke-width":"2.5","stroke-linecap":"round","stroke-linejoin":"round"})],-1)])]),default:o(()=>[r[21]||(r[21]=h(" 创建函数 ",-1))]),_:1}),l(n(H),{value:j.value,"onUpdate:value":r[3]||(r[3]=d=>j.value=d),placeholder:"搜索函数...",size:"large",clearable:"",style:{"max-width":"300px"}},{prefix:o(()=>[(b(),$("svg",as,[...r[22]||(r[22]=[t("path",{d:"M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"},null,-1)])]))]),_:1},8,["value"])]),l(n(je),{columns:O,data:i.value,pagination:!1,"row-props":Y,class:"modern-table"},null,8,["data"])])]),_:1}),l(n(ge),{name:"sdk",tab:"SDK信息"},{default:o(()=>[t("div",ss,[l(n(Re),{type:"info",bordered:!1,style:{"margin-bottom":"24px"}},{header:o(()=>[...r[23]||(r[23]=[t("strong",null,"SDK使用说明",-1)])]),default:o(()=>[t("div",ns,[r[24]||(r[24]=t("p",null,"在页面中引入以下脚本即可使用SDK调用您创建的函数:",-1)),l(n(He),{code:ve.value,language:"html",style:{margin:"12px 0"}},null,8,["code"]),r[25]||(r[25]=t("p",{style:{"margin-top":"12px"}},"使用示例:",-1)),l(n(He),{code:ke.value,language:"html",style:{margin:"12px 0"}},null,8,["code"])])]),_:1})])]),_:1})]),_:1},8,["value"]),l(n(me),{show:F.value,"onUpdate:show":r[9]||(r[9]=d=>F.value=d),preset:"card",bordered:!1,style:{width:"90vw","max-width":"1200px","max-height":"90vh"}},{header:o(()=>[t("div",ls,[(b(),$("svg",os,[...r[26]||(r[26]=[t("path",{d:"M8 9l3 3-3 3m5 0h3M5 20h14a1 1 0 001-1V5a1 1 0 00-1-1H5a1 1 0 00-1 1v14a1 1 0 001 1z",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"},null,-1)])])),t("span",null,Q(T.value?"编辑页面":"创建页面"),1)])]),footer:o(()=>[t("div",rs,[l(n(S),{onClick:r[8]||(r[8]=d=>F.value=!1)},{default:o(()=>[...r[27]||(r[27]=[h("取消",-1)])]),_:1}),l(n(S),{type:"primary",onClick:x,loading:te.value},{default:o(()=>[...r[28]||(r[28]=[h("保存",-1)])]),_:1},8,["loading"])])]),default:o(()=>[l(n($e),{ref_key:"pageFormRef",ref:X,model:U.value,rules:M},{default:o(()=>[l(n(K),{label:"页面名称",path:"name"},{default:o(()=>[l(n(H),{value:U.value.name,"onUpdate:value":r[5]||(r[5]=d=>U.value.name=d),placeholder:"例如: my-page",size:"large"},null,8,["value"])]),_:1}),l(n(K),{label:"页面描述",path:"description"},{default:o(()=>[l(n(H),{value:U.value.description,"onUpdate:value":r[6]||(r[6]=d=>U.value.description=d),placeholder:"页面描述",size:"large"},null,8,["value"])]),_:1}),l(n(K),{label:"页面内容",path:"content"},{default:o(()=>[l(n(H),{value:U.value.content,"onUpdate:value":r[7]||(r[7]=d=>U.value.content=d),type:"textarea",placeholder:'HTML内容,记得引入SDK脚本:<script src="SDK_URL"><\/script>',rows:15,size:"large"},null,8,["value"])]),_:1})]),_:1},8,["model"])]),_:1},8,["show"]),l(n(me),{show:E.value,"onUpdate:show":r[16]||(r[16]=d=>E.value=d),preset:"card",bordered:!1,style:{width:"90vw","max-width":"1400px","max-height":"90vh"}},{header:o(()=>[t("div",is,[(b(),$("svg",us,[...r[29]||(r[29]=[t("path",{d:"M14.7 6.3a1 1 0 000 1.4l1.6 1.6a1 1 0 001.4 0l3.77-3.77a6 6 0 01-7.94 7.94l-6.91 6.91a2.12 2.12 0 01-3-3l6.91-6.91a6 6 0 017.94-7.94l-3.76 3.76z",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"},null,-1)])])),t("span",null,Q(le.value?"编辑函数":"创建函数"),1)])]),footer:o(()=>[t("div",ws,[l(n(S),{onClick:r[15]||(r[15]=d=>E.value=!1)},{default:o(()=>[...r[36]||(r[36]=[h("取消",-1)])]),_:1}),l(n(S),{type:"primary",onClick:V,loading:Z.value},{default:o(()=>[...r[37]||(r[37]=[h("保存",-1)])]),_:1},8,["loading"])])]),default:o(()=>[l(n(Ae),{value:g.value,"onUpdate:value":r[14]||(r[14]=d=>g.value=d),type:"line",animated:""},{default:o(()=>[l(n(ge),{name:"basic",tab:"基础信息"},{default:o(()=>[l(n($e),{ref_key:"functionFormRef",ref:_,model:v.value,rules:G},{default:o(()=>[l(n(K),{label:"函数名称",path:"name"},{default:o(()=>[l(n(H),{value:v.value.name,"onUpdate:value":r[10]||(r[10]=d=>v.value.name=d),placeholder:"例如: myFunction",size:"large"},null,8,["value"])]),_:1}),l(n(K),{label:"函数描述",path:"description"},{default:o(()=>[l(n(H),{value:v.value.description,"onUpdate:value":r[11]||(r[11]=d=>v.value.description=d),placeholder:"函数描述",size:"large"},null,8,["value"])]),_:1})]),_:1},8,["model"]),t("div",ds,[t("div",cs,[r[31]||(r[31]=t("h4",null,"参数定义",-1)),l(n(S),{dashed:"",onClick:r[12]||(r[12]=d=>v.value.parameters.push(e())),size:"medium"},{default:o(()=>[...r[30]||(r[30]=[h("添加参数",-1)])]),_:1})]),(b(!0),$(we,null,he(v.value.parameters,(d,W)=>(b(),$("div",{key:W,style:{"margin-bottom":"12px",padding:"12px",border:"1px solid #e0e0e0","border-radius":"4px"}},[t("div",vs,[t("span",null,"参数 #"+Q(W+1),1),l(n(S),{type:"error",text:"",size:"small",onClick:ne=>v.value.parameters.splice(W,1)},{default:o(()=>[...r[32]||(r[32]=[h("删除",-1)])]),_:1},8,["onClick"])]),t("div",ps,[l(n(Ne),{checked:d.required,"onUpdate:checked":ne=>d.required=ne},{default:o(()=>[...r[33]||(r[33]=[h("必填",-1)])]),_:1},8,["checked","onUpdate:checked"]),l(n(H),{value:d.name,"onUpdate:value":ne=>d.name=ne,placeholder:"参数名"},null,8,["value","onUpdate:value"]),l(n(Be),{value:d.type,"onUpdate:value":ne=>d.type=ne,options:ie,placeholder:"类型"},null,8,["value","onUpdate:value"]),l(n(H),{value:d.description,"onUpdate:value":ne=>d.description=ne,placeholder:"描述"},null,8,["value","onUpdate:value"])])]))),128))])]),_:1}),l(n(ge),{name:"script",tab:"函数实现"},{default:o(()=>[t("div",fs,[l(n(Re),{type:"info",bordered:!1,style:{"margin-bottom":"16px"}},{icon:o(()=>[(b(),$("svg",ms,[...r[34]||(r[34]=[t("path",{d:"M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"},null,-1)])]))]),default:o(()=>[r[35]||(r[35]=h(" 在函数实现中可以使用 args 和 context 参数,类型定义已自动生成 ",-1))]),_:1}),l(n(K),{label:"函数脚本"},{default:o(()=>{var d;return[E.value&&g.value==="script"?(b(),$("div",gs,[(b(),Me(qe,{key:`function-editor-${((d=le.value)==null?void 0:d.id)||"new"}-${g.value}`,modelValue:v.value.serverScript,"onUpdate:modelValue":r[13]||(r[13]=W=>v.value.serverScript=W),language:"typescript",options:{minimap:{enabled:!0},fontSize:14,lineHeight:22,padding:{top:16,bottom:16},scrollBeyondLastLine:!1,automaticLayout:!0},"extra-libs":pe.value,style:Xe(be.value),onChange:ye},null,8,["modelValue","extra-libs","style"]))])):re("",!0)]}),_:1})])]),_:1})]),_:1},8,["value"])]),_:1},8,["show"])]))}}),bs=Te(hs,[["__scopeId","data-v-162a021f"]]),ys={class:"dashboard-container"},ks={style:{position:"absolute",width:"0",height:"0"}},xs={key:0,class:"loading-state"},Cs={key:1,class:"dashboard-content"},$s=ze({__name:"Dashboard",setup(de){const k=_e(),C=Pe(),w=Je(),B=et(),m=at(),L=f(B.query.section||"components"),P=ee(()=>C.currentConfig),R=ee(()=>C.loading),F=ee(()=>{var j;return((j=w.user)==null?void 0:j.role)==="admin"}),T=["variables","tables"],te={components:it,tools:rt,variables:kt,init:ot,tables:Za,prompts:sa,interfaces:bs},X=ee(()=>te[L.value]);async function U(){try{await C.fetchConfig(),ut().catch(j=>{console.warn("Monaco Editor 预加载失败:",j)})}catch(j){k.error(j.message)}}async function M(j){if(P.value)try{await C.updateConfig(j),k.success("更新成功")}catch(E){k.error(E.message)}}function q(j){return F.value&&T.includes(j)?(k.warning("超级管理员不允许访问此功能"),m.replace({name:"UserDashboard",query:{section:"components"}}),L.value="components",!0):!1}return De(()=>B.query.section,j=>{if(!j)return;const E=j;q(E)||(L.value=E)},{immediate:!0}),Ie(()=>{const j=B.query.section;q(j),U()}),(j,E)=>(b(),$("div",ys,[(b(),$("svg",ks,[...E[0]||(E[0]=[t("defs",null,[t("linearGradient",{id:"loading-gradient",x1:"0%",y1:"0%",x2:"100%",y2:"100%"},[t("stop",{offset:"0%","stop-color":"#6366f1"}),t("stop",{offset:"50%","stop-color":"#8b5cf6"}),t("stop",{offset:"100%","stop-color":"#ec4899"})])],-1)])])),R.value&&!P.value?(b(),$("div",xs,[...E[1]||(E[1]=[t("div",{class:"loading-spinner"},[t("svg",{class:"spinner",viewBox:"0 0 50 50"},[t("circle",{class:"path",cx:"25",cy:"25",r:"20",fill:"none","stroke-width":"4"})])],-1),t("p",{class:"loading-text"},"加载配置中...",-1)])])):P.value?(b(),$("div",Cs,[(b(),Me(tt(X.value),{config:P.value,onUpdate:M},null,40,["config"]))])):re("",!0)]))}}),Us=Te($s,[["__scopeId","data-v-b07c4986"]]);export{Us as default};
|