gbformdesign 0.1.0 → 0.1.1
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/LICENSE +21 -21
- package/README.md +84 -84
- package/dist/gbformdesign.css +1 -1
- package/dist/gbformdesign.js +1146 -1051
- package/dist/gbformdesign.js.map +1 -1
- package/dist/gbformdesign.umd.cjs +6 -6
- package/dist/gbformdesign.umd.cjs.map +1 -1
- package/package.json +58 -57
- package/src/core/FormVariable.js +328 -328
- package/src/core/dynamicFormUtils.js +139 -139
- package/src/core/fileIO.js +90 -90
- package/src/core/formVariableTypeSystem.js +327 -327
- package/src/core/index.js +26 -26
- package/src/core/schema.js +192 -192
- package/src/design/composables/useDefaultValue.js +55 -55
- package/src/design/constants/componentTemplates.js +181 -190
- package/src/design/constants/componentTypes.js +70 -70
- package/src/design/utils/componentUtils.js +75 -75
- package/src/designer/fc/FcCanvasField.vue +277 -276
- package/src/designer/fc/FcJsonPanel.vue +113 -113
- package/src/designer/fc/FcPreviewDialog.vue +62 -62
- package/src/designer/fc/FcPropsPanel.vue +373 -373
- package/src/designer/fc/FormDesigner.vue +633 -633
- package/src/designer/fc/codegen.js +120 -120
- package/src/index.js +48 -48
- package/src/styles/config.scss +102 -102
- package/src/styles/fc/designer.css +837 -837
- package/src/styles/fc/icon.css +1053 -1053
- package/src/styles/index.scss +4 -4
- package/src/view/FormField.vue +301 -301
- package/src/view/FormViewer.vue +216 -216
- package/src/view/composables/useFormValidation.js +201 -201
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
(function(E,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("vue"),require("element-plus"),require("@element-plus/icons-vue")):typeof define=="function"&&define.amd?define(["exports","vue","element-plus","@element-plus/icons-vue"],e):(E=typeof globalThis<"u"?globalThis:E||self,e(E.GbFormDesign={},E.Vue,E.ElementPlus,E.ElementPlusIconsVue))})(this,(function(E,e,G,le){"use strict";const d={INPUT:"input",TEXTAREA:"textarea",INPUT_NUMBER:"input-number",RADIO_GROUP:"radio-group",CHECKBOX_GROUP:"checkbox-group",SELECT:"select",SWITCH:"switch",DATE_PICKER:"date-picker",ROW:"row",BUTTON:"button"},Oe={[d.INPUT]:"文本输入框",[d.TEXTAREA]:"多行文本",[d.INPUT_NUMBER]:"数字输入框",[d.RADIO_GROUP]:"单选框",[d.CHECKBOX_GROUP]:"多选框",[d.SELECT]:"下拉选择",[d.SWITCH]:"开关",[d.DATE_PICKER]:"日期选择器",[d.ROW]:"分栏",[d.BUTTON]:"按钮"},he=[d.RADIO_GROUP,d.CHECKBOX_GROUP,d.SELECT],ot={FULL:100,HALF:50,THIRD:33.33,QUARTER:25},lt={MIN_NUMBER:1,MAX_NUMBER:100,DEFAULT_GUTTER:20,DEFAULT_COLUMN_SPAN:12,MIN_COLUMN_SPAN:1,MAX_COLUMN_SPAN:24,MIN_WIDTH:10,MAX_WIDTH:100,WIDTH_STEP:5},Ae={TODAY:"today",TOMORROW:"tomorrow"};function X(){return`component_${Date.now()}_${Math.random().toString(36).substr(2,9)}`}function ye(t){return t.id||(t.id=X()),t}function ie(t){if(t==null||t==="")return null;const l=Number(t);return isNaN(l)?null:l}function Ee(t){return t==null||t===""}function _e(t){return Array.isArray(t)?t.map(l=>typeof l=="string"?{label:l,value:l}:{...l}):[]}function Re(t,l=100){if(t==null)return l;if(typeof t=="number")return t;const o=String(t).replace("%",""),r=parseFloat(o);return isNaN(r)?l:r}function P(t){return t.props?.variableName||`field_${t.id||Date.now()}`}const Be=t=>{const l=t.defaultValue;if(Ee(l))return null;if(t.type===d.DATE_PICKER){if(l===Ae.TODAY)return new Date;if(l===Ae.TOMORROW){const o=new Date;return o.setDate(o.getDate()+1),o}return null}return t.type===d.INPUT_NUMBER?ie(l):t.type===d.CHECKBOX_GROUP?Array.isArray(l)?[...l]:[]:l},xe=(t,l)=>{const o=t.__vccOpts||t;for(const[r,c]of l)o[r]=c;return o},nt={class:"form-viewer"},at={key:0,class:"row-container"},rt={class:"column-wrapper"},De=xe(Object.assign({name:"FormField"},{__name:"FormField",props:{component:{type:Object,required:!0},formData:{type:Object,required:!0},formRules:{type:Object,required:!0},readonly:{type:Boolean,default:!1}},emits:["update:value"],setup(t,{emit:l}){const o=t,r=l,c=e.computed(()=>P(o.component));e.onMounted(()=>{if(!(c.value in o.formData)){const i=Be(o.component);i!=null?o.formData[c.value]=i:o.component.type===d.INPUT_NUMBER?o.formData[c.value]=null:o.component.type===d.RADIO_GROUP||o.component.type===d.SELECT||o.component.type===d.TEXTAREA?o.formData[c.value]="":o.component.type===d.DATE_PICKER?o.formData[c.value]=null:o.component.type===d.CHECKBOX_GROUP?o.formData[c.value]=[]:o.component.type===d.SWITCH?o.formData[c.value]=!1:o.formData[c.value]=""}});const s=e.computed({get(){let i=o.formData[c.value];if(o.component.type===d.INPUT_NUMBER)return ie(i);if(Ee(i)&&o.component.defaultValue!==void 0&&o.component.defaultValue!==null){const h=Be(o.component);if(h!=null)return h}return i},set(i){o.component.type===d.INPUT_NUMBER?o.formData[c.value]=ie(i):o.component.type===d.CHECKBOX_GROUP?o.formData[c.value]=Array.isArray(i)?[...i]:[]:o.component.type===d.SWITCH?o.formData[c.value]=i===!0:o.formData[c.value]=i,r("update:value",c.value,o.formData[c.value])}}),p=i=>{r("update:value",c.value,i)};return(i,h)=>{const y=e.resolveComponent("FormField",!0),g=e.resolveComponent("el-col"),A=e.resolveComponent("el-row"),T=e.resolveComponent("el-input"),k=e.resolveComponent("el-form-item"),O=e.resolveComponent("el-input-number"),b=e.resolveComponent("el-radio"),w=e.resolveComponent("el-radio-group"),R=e.resolveComponent("el-option"),j=e.resolveComponent("el-select"),W=e.resolveComponent("el-checkbox"),F=e.resolveComponent("el-checkbox-group"),$=e.resolveComponent("el-switch"),V=e.resolveComponent("el-date-picker");return e.openBlock(),e.createElementBlock("div",nt,[t.component.type===e.unref(d).ROW?(e.openBlock(),e.createElementBlock("div",at,[e.createVNode(A,{gutter:t.component.props?.gutter||20},{default:e.withCtx(()=>[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(t.component.props?.columns||[],(n,M)=>(e.openBlock(),e.createBlock(g,{key:M,span:n.span||12},{default:e.withCtx(()=>[e.createElementVNode("div",rt,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(t.component.children?.[M]||[],(D,L)=>(e.openBlock(),e.createBlock(y,{key:L,component:D,"form-data":t.formData,"form-rules":t.formRules,readonly:t.readonly},null,8,["component","form-data","form-rules","readonly"]))),128))])]),_:2},1032,["span"]))),128))]),_:1},8,["gutter"])])):t.component.type===e.unref(d).INPUT?(e.openBlock(),e.createBlock(k,{key:1,label:t.component.props?.label||"",prop:e.unref(P)(t.component),required:t.component.required},{default:e.withCtx(()=>[e.createVNode(T,{modelValue:s.value,"onUpdate:modelValue":h[0]||(h[0]=n=>s.value=n),placeholder:t.component.props?.placeholder||"请输入文本",style:{width:"100%"},disabled:t.readonly,onInput:p},null,8,["modelValue","placeholder","disabled"])]),_:1},8,["label","prop","required"])):t.component.type===e.unref(d).TEXTAREA?(e.openBlock(),e.createBlock(k,{key:2,label:t.component.props?.label||"",prop:e.unref(P)(t.component),required:t.component.required},{default:e.withCtx(()=>[e.createVNode(T,{modelValue:s.value,"onUpdate:modelValue":h[1]||(h[1]=n=>s.value=n),type:"textarea",rows:t.component.props?.rows||3,placeholder:t.component.props?.placeholder||"请输入内容",style:{width:"100%"},disabled:t.readonly,onInput:p},null,8,["modelValue","rows","placeholder","disabled"])]),_:1},8,["label","prop","required"])):t.component.type===e.unref(d).INPUT_NUMBER?(e.openBlock(),e.createBlock(k,{key:3,label:t.component.props?.label||"",prop:e.unref(P)(t.component),required:t.component.required},{default:e.withCtx(()=>[e.createVNode(O,{modelValue:s.value,"onUpdate:modelValue":h[2]||(h[2]=n=>s.value=n),min:t.component.min||1,max:t.component.max||100,style:{width:"100%"},disabled:t.readonly,onChange:p},null,8,["modelValue","min","max","disabled"])]),_:1},8,["label","prop","required"])):t.component.type===e.unref(d).RADIO_GROUP?(e.openBlock(),e.createBlock(k,{key:4,label:t.component.props?.label||"",prop:e.unref(P)(t.component),required:t.component.required},{default:e.withCtx(()=>[e.createVNode(w,{modelValue:s.value,"onUpdate:modelValue":h[3]||(h[3]=n=>s.value=n),style:{width:"100%"},disabled:t.readonly,onChange:p},{default:e.withCtx(()=>[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(t.component.props?.options||["选项1","选项2","选项3"],n=>(e.openBlock(),e.createBlock(b,{key:n.value||n,value:n.value||n},{default:e.withCtx(()=>[e.createTextVNode(e.toDisplayString(n.label||n),1)]),_:2},1032,["value"]))),128))]),_:1},8,["modelValue","disabled"])]),_:1},8,["label","prop","required"])):t.component.type===e.unref(d).SELECT?(e.openBlock(),e.createBlock(k,{key:5,label:t.component.props?.label||"",prop:e.unref(P)(t.component),required:t.component.required},{default:e.withCtx(()=>[e.createVNode(j,{modelValue:s.value,"onUpdate:modelValue":h[4]||(h[4]=n=>s.value=n),placeholder:t.component.props?.placeholder||"请选择",style:{width:"100%"},disabled:t.readonly,onChange:p},{default:e.withCtx(()=>[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(t.component.props?.options||[],n=>(e.openBlock(),e.createBlock(R,{key:n.value||n,label:n.label||n,value:n.value||n},null,8,["label","value"]))),128))]),_:1},8,["modelValue","placeholder","disabled"])]),_:1},8,["label","prop","required"])):t.component.type===e.unref(d).CHECKBOX_GROUP?(e.openBlock(),e.createBlock(k,{key:6,label:t.component.props?.label||"",prop:e.unref(P)(t.component),required:t.component.required},{default:e.withCtx(()=>[e.createVNode(F,{modelValue:s.value,"onUpdate:modelValue":h[5]||(h[5]=n=>s.value=n),style:{width:"100%"},disabled:t.readonly,onChange:p},{default:e.withCtx(()=>[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(t.component.props?.options||[],n=>(e.openBlock(),e.createBlock(W,{key:n.value||n,value:n.value||n},{default:e.withCtx(()=>[e.createTextVNode(e.toDisplayString(n.label||n),1)]),_:2},1032,["value"]))),128))]),_:1},8,["modelValue","disabled"])]),_:1},8,["label","prop","required"])):t.component.type===e.unref(d).SWITCH?(e.openBlock(),e.createBlock(k,{key:7,label:t.component.props?.label||"",prop:e.unref(P)(t.component),required:t.component.required},{default:e.withCtx(()=>[e.createVNode($,{modelValue:s.value,"onUpdate:modelValue":h[6]||(h[6]=n=>s.value=n),"active-text":t.component.props?.activeText||"","inactive-text":t.component.props?.inactiveText||"",disabled:t.readonly,onChange:p},null,8,["modelValue","active-text","inactive-text","disabled"])]),_:1},8,["label","prop","required"])):t.component.type===e.unref(d).DATE_PICKER?(e.openBlock(),e.createBlock(k,{key:8,label:t.component.props?.label||"",prop:e.unref(P)(t.component),required:t.component.required},{default:e.withCtx(()=>[e.createVNode(V,{modelValue:s.value,"onUpdate:modelValue":h[7]||(h[7]=n=>s.value=n),type:"date",placeholder:t.component.props?.placeholder||"选择日期",style:{width:"100%"},disabled:t.readonly,onChange:p},null,8,["modelValue","placeholder","disabled"])]),_:1},8,["label","prop","required"])):e.createCommentVNode("",!0)])}}}),[["__scopeId","data-v-63b4f62f"]]),it={key:0,class:"_fd-draggable-drag _fd-drag-box gb-fc-row-box"},st=["onDragover","onDrop"],ct={class:"gb-fc-tools"},dt=["title"],Se=Object.assign({name:"FcCanvasField"},{__name:"FcCanvasField",props:{component:{type:Object,required:!0},path:{type:Array,required:!0},formData:{type:Object,required:!0},formRules:{type:Object,required:!0},activeId:{type:String,default:""},depth:{type:Number,default:0}},setup(t){const l=t,o=e.inject("fcCanvasOps"),r=e.inject("fcDragOver"),c=e.computed(()=>l.component.type===d.ROW),s=e.computed(()=>l.component.props?.columns?.length||2);e.computed(()=>(l.component.children||[]).every(b=>!b||b.length===0));const p={kind:"existing",path:l.path},i=b=>{b.dataTransfer.effectAllowed="move",b.dataTransfer.setData("application/x-gb-field",JSON.stringify(p)),b.dataTransfer.setData("text/plain","gb-field"),o.startDrag(l.path)},h=()=>{o.endDrag()},y=b=>{b.preventDefault();const w=b.currentTarget.getBoundingClientRect(),R=b.clientY-w.top<w.height/2?"top":"bottom";r.value=l.path.join(".")+":"+R,b.dataTransfer.dropEffect="move"},g=()=>{r.value?.startsWith(l.path.join("."))&&(r.value="")},A=b=>{b.preventDefault(),b.stopPropagation();const w=r.value?.endsWith(":top")?"top":"bottom",R=O(b);r.value="",R&&o.dropAt(R,{path:l.path,position:w})},T=b=>{r.value=l.path.join(".")+":col"+b},k=(b,w)=>{const R=O(w);r.value="",R&&o.dropAt(R,{path:l.path,column:b})},O=b=>{const w=b?.dataTransfer?.getData("application/x-gb-field");if(w)try{return JSON.parse(w)}catch{return null}return o.getDragPayload()};return(b,w)=>{const R=e.resolveComponent("FcCanvasField",!0),j=e.resolveComponent("el-col"),W=e.resolveComponent("el-row");return e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass(["_fc-draggable-item _fd-drag-item gb-fc-item",{"is-active":t.activeId===t.component.id,"is-hidden":t.component.hidden,"drag-over-top":e.unref(r)===t.path.join(".")+":top","drag-over-bottom":e.unref(r)===t.path.join(".")+":bottom"}]),onDragover:e.withModifiers(y,["prevent"]),onDragenter:w[3]||(w[3]=e.withModifiers(()=>{},["prevent"])),onDragleave:g,onDrop:e.withModifiers(A,["stop","prevent"])},[c.value?(e.openBlock(),e.createElementBlock("div",it,[e.createVNode(W,{gutter:t.component.props?.gutter||20},{default:e.withCtx(()=>[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(s.value,(F,$)=>(e.openBlock(),e.createBlock(j,{key:$,span:t.component.props?.columns?.[$]?.span||12},{default:e.withCtx(()=>[e.createElementVNode("div",{class:e.normalizeClass(["gb-fc-column",{"_fc-child-empty":!(t.component.children?.[$]||[]).length,"has-child":(t.component.children?.[$]||[]).length}]),onDragover:e.withModifiers(V=>T($),["prevent","stop"]),onDrop:e.withModifiers(V=>k($,V),["stop","prevent"])},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(t.component.children?.[$]||[],(V,n)=>(e.openBlock(),e.createBlock(R,{key:V.id||n,component:V,path:[...t.path,"children",$,n],"form-data":t.formData,"form-rules":t.formRules,"active-id":t.activeId,depth:t.depth+1},null,8,["component","path","form-data","form-rules","active-id","depth"]))),128))],42,st)]),_:2},1032,["span"]))),128))]),_:1},8,["gutter"])])):(e.openBlock(),e.createBlock(De,{key:1,component:t.component,"form-data":t.formData,"form-rules":t.formRules,readonly:!0},null,8,["component","form-data","form-rules"])),e.createElementVNode("div",{class:"gb-fc-mask",onClick:w[2]||(w[2]=e.withModifiers(F=>e.unref(o).active(t.component,t.path),["stop"]))},[e.createElementVNode("div",ct,[e.createElementVNode("i",{class:"gb-fc-tool gb-fc-tool--handle",title:"拖拽"+(t.component.props?.label||t.component.type),draggable:"true",onDragstart:e.withModifiers(i,["stop"]),onDragend:h},[...w[4]||(w[4]=[e.createElementVNode("svg",{viewBox:"0 0 1024 1024",width:"14",height:"14"},[e.createElementVNode("path",{fill:"currentColor",d:"M469.3 256a53.3 53.3 0 1 1-106.6 0 53.3 53.3 0 0 1 106.6 0zm0 170.7a53.3 53.3 0 1 1-106.6 0 53.3 53.3 0 0 1 106.6 0zm0 170.6a53.3 53.3 0 1 1-106.6 0 53.3 53.3 0 0 1 106.6 0zm0 170.7a53.3 53.3 0 1 1-106.6 0 53.3 53.3 0 0 1 106.6 0zM661.3 256a53.3 53.3 0 1 1-106.6 0 53.3 53.3 0 0 1 106.6 0zm0 170.7a53.3 53.3 0 1 1-106.6 0 53.3 53.3 0 0 1 106.6 0zm0 170.6a53.3 53.3 0 1 1-106.6 0 53.3 53.3 0 0 1 106.6 0zm0 170.7a53.3 53.3 0 1 1-106.6 0 53.3 53.3 0 0 1 106.6 0z"})],-1)])],40,dt),e.createElementVNode("i",{class:"gb-fc-tool",title:"复制",onClick:w[0]||(w[0]=e.withModifiers(F=>e.unref(o).copy(t.path),["stop"]))},[...w[5]||(w[5]=[e.createElementVNode("svg",{viewBox:"0 0 1024 1024",width:"14",height:"14"},[e.createElementVNode("path",{fill:"currentColor",d:"M768 832v-576H320v576h448zM320 192h448a64 64 0 0 1 64 64v576a64 64 0 0 1-64 64H320a64 64 0 0 1-64-64V256a64 64 0 0 1 64-64zm-128 64v640h64v64h-64a64 64 0 0 1-64-64V256h64z"})],-1)])]),e.createElementVNode("i",{class:"gb-fc-tool gb-fc-tool--danger",title:"删除",onClick:w[1]||(w[1]=e.withModifiers(F=>e.unref(o).remove(t.path),["stop"]))},[...w[6]||(w[6]=[e.createElementVNode("svg",{viewBox:"0 0 1024 1024",width:"14",height:"14"},[e.createElementVNode("path",{fill:"currentColor",d:"M512 455.1L761 206a15 15 0 0 1 21.2 0l35.8 35.8a15 15 0 0 1 0 21.2L569 512l249 249a15 15 0 0 1 0 21.2l-35.8 35.8a15 15 0 0 1-21.2 0L512 569l-249 249a15 15 0 0 1-21.2 0l-35.8-35.8a15 15 0 0 1 0-21.2L455 512 206 263a15 15 0 0 1 0-21.2l35.8-35.8a15 15 0 0 1 21.2 0z"})],-1)])])])])],34)}}}),mt={class:"_fd-config-item",style:{"margin-top":"12px"}},pt={class:"_fd-ci-head"},ft={class:"_fd-ci-con"},ut={class:"_fc-r-config"},ht={style:{"grid-area":"base"}},yt={key:0,class:"_fd-config-item"},Et={class:"_fd-ci-head"},Nt={class:"_fd-ci-con"},Vt={key:1,class:"_fd-config-item"},gt={class:"_fd-ci-head"},bt={class:"_fd-ci-con"},Tt={key:0,style:{display:"flex","justify-content":"flex-end","margin-top":"6px"}},Ct={key:2,class:"_fd-config-item"},wt={class:"_fd-ci-head"},kt={class:"_fd-ci-con"},Ot={style:{"grid-area":"props"}},At={key:0,class:"_fd-config-item"},_t={class:"_fd-ci-head"},Rt={class:"_fd-ci-con"},Bt={class:"_fd-config-item"},xt={class:"_fd-ci-head"},Dt={class:"_fd-ci-con"},St={class:"_fd-config-item"},It={class:"_fd-ci-head"},Ut={class:"_fd-ci-con"},$t={key:2,class:"_fd-config-item"},Pt={class:"_fd-ci-append",style:{display:"block"}},Ft={class:"_fd-config-item"},Mt={class:"_fd-ci-head"},Lt={class:"_fd-ci-con"},zt={class:"_fd-config-item"},Gt={class:"_fd-ci-append",style:{display:"block"}},jt={style:{"font-size":"12px",color:"#666",width:"60px"}},Ht={class:"_fc-r-config"},Wt={style:{"grid-area":"base"}},qt={class:"_fd-config-item"},Jt={class:"_fd-ci-head"},Yt={class:"_fd-ci-con"},Kt={class:"_fd-config-item"},Qt={class:"_fd-ci-head"},Xt={class:"_fd-ci-con"},Zt={class:"_fd-config-item"},vt={class:"_fd-ci-head"},eo={class:"_fd-ci-con"},to={class:"_fd-config-item"},oo={class:"_fd-ci-head"},lo={class:"_fd-ci-con"},no=Object.assign({name:"FcPropsPanel"},{__name:"FcPropsPanel",props:{component:{type:Object,default:null},formOptions:{type:Object,required:!0}},emits:["close"],setup(t,{emit:l}){const o=t,r=e.ref("props"),c=e.computed(()=>o.component?.type===d.ROW),s=e.computed(()=>he.includes(o.component?.type)),p=e.computed(()=>o.component?.props?(Array.isArray(o.component.props.options)||(o.component.props.options=[]),o.component.props.options):[]),i=Object.entries(Oe).filter(([V])=>V!==d.BUTTON).map(([V,n])=>({value:V,label:n})),h=e.computed({get:()=>o.component?.type,set:V=>{!V||!o.component||(o.component.type=V,o.component.props||(o.component.props={}),he.includes(V)&&!o.component.props.options?.length&&(o.component.props.options=[{label:"选项1",value:"1"},{label:"选项2",value:"2"}]),V===d.ROW&&(o.component.props.columns||(o.component.props.columns=[{span:12},{span:12}]),o.component.children||(o.component.children=[[],[]]),o.component.props.gutter=o.component.props.gutter||20,ye(o.component)))}}),y=e.ref("100%"),g=e.ref(100),A=()=>{const V=o.component?.style?.width,n=["100%","50%","33.33%","25%"];if(!V){y.value="100%";return}y.value=n.includes(V)?V:"custom",y.value==="custom"&&(g.value=Re(V))};A(),e.watch(()=>o.component?.id,A);const T=V=>{o.component&&(o.component.style||(o.component.style={}),V==="custom"?o.component.style.width=`${g.value}%`:o.component.style.width=V)},k=V=>{o.component&&(o.component.style||(o.component.style={}),o.component.style.width=`${V}%`)},O=V=>typeof V=="string"?V:V.label,b=V=>typeof V=="string"?V:V.value,w=()=>{p.value.push({label:`选项${p.value.length+1}`,value:`${p.value.length+1}`})},R=V=>{p.value.splice(V,1)},j=()=>{const V=o.component.props.columns;V.push({span:Math.max(1,Math.round(24/(V.length+1)))}),o.component.children||(o.component.children=[]),o.component.children.push([])},W=V=>{o.component.props.columns.splice(V,1),o.component.children?.splice(V,1)},F=async()=>{const V=o.component?.props?.variableName;if(V)try{await navigator.clipboard.writeText(V),G.ElMessage.success("字段名已复制")}catch{G.ElMessage.warning("复制失败")}},$=()=>{o.component&&(o.component.props.variableName=`field_${X().split("_").pop()}`)};return(V,n)=>{const M=e.resolveComponent("el-header"),D=e.resolveComponent("el-option"),L=e.resolveComponent("el-select"),H=e.resolveComponent("el-input"),v=e.resolveComponent("el-switch"),ee=e.resolveComponent("el-divider"),q=e.resolveComponent("el-input-number"),Q=e.resolveComponent("el-button"),ae=e.resolveComponent("el-main"),pe=e.resolveComponent("el-container");return e.openBlock(),e.createBlock(pe,{style:{height:"100%"}},{default:e.withCtx(()=>[e.createVNode(M,{height:"40px",class:"_fc-r-tabs"},{default:e.withCtx(()=>[t.component?(e.openBlock(),e.createElementBlock("div",{key:0,class:e.normalizeClass(["_fc-r-tab",{active:r.value==="props"}]),onClick:n[0]||(n[0]=f=>r.value="props")}," 组件 ",2)):e.createCommentVNode("",!0),e.createElementVNode("div",{class:e.normalizeClass(["_fc-r-tab",{active:r.value==="form"||!t.component}]),onClick:n[1]||(n[1]=f=>r.value="form")}," 表单 ",2)]),_:1}),r.value==="props"&&t.component?(e.openBlock(),e.createBlock(ae,{key:0,class:"_fc-r-tab-props"},{default:e.withCtx(()=>[e.createElementVNode("div",{class:"_fc-r-tools-close",onClick:n[2]||(n[2]=f=>V.$emit("close"))},[...n[23]||(n[23]=[e.createElementVNode("i",{class:"fc-icon icon-add2"},null,-1)])]),n[38]||(n[38]=e.createElementVNode("p",{class:"_fc-r-title"},"组件类型",-1)),e.createVNode(L,{modelValue:h.value,"onUpdate:modelValue":n[3]||(n[3]=f=>h.value=f),style:{width:"100%"}},{default:e.withCtx(()=>[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(e.unref(i),f=>(e.openBlock(),e.createBlock(D,{key:f.value,label:f.label,value:f.value},null,8,["label","value"]))),128))]),_:1},8,["modelValue"]),n[39]||(n[39]=e.createElementVNode("p",{class:"_fc-r-title"},"字段名",-1)),e.createVNode(H,{modelValue:t.component.props.variableName,"onUpdate:modelValue":n[4]||(n[4]=f=>t.component.props.variableName=f),class:"_fc-r-name-input"},{suffix:e.withCtx(()=>[e.createElementVNode("i",{class:"fc-icon icon-group",title:"复制字段名",onClick:F})]),append:e.withCtx(()=>[e.createElementVNode("i",{class:"fc-icon icon-auto",title:"根据标题生成",onClick:$})]),_:1},8,["modelValue"]),e.createElementVNode("div",mt,[e.createElementVNode("div",pt,[n[24]||(n[24]=e.createElementVNode("div",{class:"_fd-ci-label"},"隐藏",-1)),e.createElementVNode("div",ft,[e.createVNode(v,{modelValue:t.component.hidden,"onUpdate:modelValue":n[5]||(n[5]=f=>t.component.hidden=f),size:"small"},null,8,["modelValue"])])])]),e.createElementVNode("div",ut,[e.createElementVNode("div",ht,[e.createVNode(ee,null,{default:e.withCtx(()=>[...n[25]||(n[25]=[e.createTextVNode("规则",-1)])]),_:1}),c.value?e.createCommentVNode("",!0):(e.openBlock(),e.createElementBlock("div",yt,[e.createElementVNode("div",Et,[n[26]||(n[26]=e.createElementVNode("div",{class:"_fd-ci-label"},[e.createElementVNode("span",null,"必填")],-1)),e.createElementVNode("div",Nt,[e.createVNode(v,{modelValue:t.component.required,"onUpdate:modelValue":n[6]||(n[6]=f=>t.component.required=f),size:"small"},null,8,["modelValue"])])])])),c.value?e.createCommentVNode("",!0):(e.openBlock(),e.createElementBlock("div",Vt,[e.createElementVNode("div",gt,[n[27]||(n[27]=e.createElementVNode("div",{class:"_fd-ci-label"},[e.createElementVNode("span",null,"字段宽度")],-1)),e.createElementVNode("div",bt,[e.createVNode(L,{modelValue:y.value,"onUpdate:modelValue":n[7]||(n[7]=f=>y.value=f),size:"small",style:{width:"120px"},onChange:T},{default:e.withCtx(()=>[e.createVNode(D,{label:"整行",value:"100%"}),e.createVNode(D,{label:"1/2",value:"50%"}),e.createVNode(D,{label:"1/3",value:"33.33%"}),e.createVNode(D,{label:"1/4",value:"25%"}),e.createVNode(D,{label:"自定义",value:"custom"})]),_:1},8,["modelValue"])])]),y.value==="custom"?(e.openBlock(),e.createElementBlock("div",Tt,[e.createVNode(q,{modelValue:g.value,"onUpdate:modelValue":n[8]||(n[8]=f=>g.value=f),min:10,max:100,step:5,size:"small",onChange:k},null,8,["modelValue"])])):e.createCommentVNode("",!0)])),c.value?e.createCommentVNode("",!0):(e.openBlock(),e.createElementBlock("div",Ct,[e.createElementVNode("div",wt,[n[28]||(n[28]=e.createElementVNode("div",{class:"_fd-ci-label"},[e.createElementVNode("span",null,"默认值")],-1)),e.createElementVNode("div",kt,[["radio-group","select"].includes(t.component.type)?(e.openBlock(),e.createBlock(L,{key:0,modelValue:t.component.defaultValue,"onUpdate:modelValue":n[9]||(n[9]=f=>t.component.defaultValue=f),size:"small",clearable:"",style:{width:"180px"}},{default:e.withCtx(()=>[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(p.value,f=>(e.openBlock(),e.createBlock(D,{key:b(f),label:O(f),value:b(f)},null,8,["label","value"]))),128))]),_:1},8,["modelValue"])):t.component.type==="checkbox-group"?(e.openBlock(),e.createBlock(L,{key:1,modelValue:t.component.defaultValue,"onUpdate:modelValue":n[10]||(n[10]=f=>t.component.defaultValue=f),size:"small",multiple:"",clearable:"",style:{width:"180px"}},{default:e.withCtx(()=>[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(p.value,f=>(e.openBlock(),e.createBlock(D,{key:b(f),label:O(f),value:b(f)},null,8,["label","value"]))),128))]),_:1},8,["modelValue"])):t.component.type==="switch"?(e.openBlock(),e.createBlock(v,{key:2,modelValue:t.component.defaultValue,"onUpdate:modelValue":n[11]||(n[11]=f=>t.component.defaultValue=f),size:"small"},null,8,["modelValue"])):t.component.type==="date-picker"?(e.openBlock(),e.createBlock(L,{key:3,modelValue:t.component.defaultValue,"onUpdate:modelValue":n[12]||(n[12]=f=>t.component.defaultValue=f),size:"small",clearable:"",style:{width:"120px"}},{default:e.withCtx(()=>[e.createVNode(D,{label:"今天",value:"today"}),e.createVNode(D,{label:"明天",value:"tomorrow"}),e.createVNode(D,{label:"无",value:""})]),_:1},8,["modelValue"])):t.component.type==="input-number"?(e.openBlock(),e.createBlock(q,{key:4,modelValue:t.component.defaultValue,"onUpdate:modelValue":n[13]||(n[13]=f=>t.component.defaultValue=f),size:"small",style:{width:"140px"}},null,8,["modelValue"])):(e.openBlock(),e.createBlock(H,{key:5,modelValue:t.component.defaultValue,"onUpdate:modelValue":n[14]||(n[14]=f=>t.component.defaultValue=f),size:"small",style:{width:"180px"}},null,8,["modelValue"]))])])]))]),e.createElementVNode("div",Ot,[e.createVNode(ee,null,{default:e.withCtx(()=>[...n[29]||(n[29]=[e.createTextVNode("属性",-1)])]),_:1}),["input","textarea","select"].includes(t.component.type)?(e.openBlock(),e.createElementBlock("div",At,[e.createElementVNode("div",_t,[n[30]||(n[30]=e.createElementVNode("div",{class:"_fd-ci-label"},[e.createElementVNode("span",null,"提示文字")],-1)),e.createElementVNode("div",Rt,[e.createVNode(H,{modelValue:t.component.props.placeholder,"onUpdate:modelValue":n[15]||(n[15]=f=>t.component.props.placeholder=f),size:"small",style:{width:"180px"}},null,8,["modelValue"])])])])):e.createCommentVNode("",!0),t.component.type==="input-number"?(e.openBlock(),e.createElementBlock(e.Fragment,{key:1},[e.createElementVNode("div",Bt,[e.createElementVNode("div",xt,[n[31]||(n[31]=e.createElementVNode("div",{class:"_fd-ci-label"},[e.createElementVNode("span",null,"最小值")],-1)),e.createElementVNode("div",Dt,[e.createVNode(q,{modelValue:t.component.min,"onUpdate:modelValue":n[16]||(n[16]=f=>t.component.min=f),size:"small",style:{width:"140px"}},null,8,["modelValue"])])])]),e.createElementVNode("div",St,[e.createElementVNode("div",It,[n[32]||(n[32]=e.createElementVNode("div",{class:"_fd-ci-label"},[e.createElementVNode("span",null,"最大值")],-1)),e.createElementVNode("div",Ut,[e.createVNode(q,{modelValue:t.component.max,"onUpdate:modelValue":n[17]||(n[17]=f=>t.component.max=f),size:"small",style:{width:"140px"}},null,8,["modelValue"])])])])],64)):e.createCommentVNode("",!0),s.value?(e.openBlock(),e.createElementBlock("div",$t,[n[34]||(n[34]=e.createElementVNode("div",{class:"_fd-ci-head"},[e.createElementVNode("div",{class:"_fd-ci-label"},[e.createElementVNode("span",null,"选项配置")])],-1)),e.createElementVNode("div",Pt,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(p.value,(f,Y)=>(e.openBlock(),e.createElementBlock("div",{key:Y,class:"gb-fc-option"},[e.createVNode(H,{modelValue:f.label,"onUpdate:modelValue":J=>f.label=J,size:"small",placeholder:"选项名称"},null,8,["modelValue","onUpdate:modelValue"]),e.createVNode(H,{modelValue:f.value,"onUpdate:modelValue":J=>f.value=J,size:"small",placeholder:"选项值"},null,8,["modelValue","onUpdate:modelValue"]),e.createVNode(Q,{type:"danger",plain:"",size:"small",icon:e.unref(le.Delete),onClick:J=>R(Y)},null,8,["icon","onClick"])]))),128)),e.createVNode(Q,{type:"primary",plain:"",size:"small",icon:e.unref(le.Plus),style:{width:"100%"},onClick:w},{default:e.withCtx(()=>[...n[33]||(n[33]=[e.createTextVNode(" 添加选项 ",-1)])]),_:1},8,["icon"])])])):e.createCommentVNode("",!0),c.value?(e.openBlock(),e.createElementBlock(e.Fragment,{key:3},[e.createElementVNode("div",Ft,[e.createElementVNode("div",Mt,[n[35]||(n[35]=e.createElementVNode("div",{class:"_fd-ci-label"},[e.createElementVNode("span",null,"列间距")],-1)),e.createElementVNode("div",Lt,[e.createVNode(q,{modelValue:t.component.props.gutter,"onUpdate:modelValue":n[18]||(n[18]=f=>t.component.props.gutter=f),min:0,max:100,size:"small",style:{width:"140px"}},null,8,["modelValue"])])])]),e.createElementVNode("div",zt,[n[37]||(n[37]=e.createElementVNode("div",{class:"_fd-ci-head"},[e.createElementVNode("div",{class:"_fd-ci-label"},[e.createElementVNode("span",null,"列配置")])],-1)),e.createElementVNode("div",Gt,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(t.component.props.columns,(f,Y)=>(e.openBlock(),e.createElementBlock("div",{key:Y,class:"gb-fc-option"},[e.createElementVNode("span",jt,"第"+e.toDisplayString(Y+1)+"列",1),e.createVNode(q,{modelValue:f.span,"onUpdate:modelValue":J=>f.span=J,min:1,max:24,size:"small"},null,8,["modelValue","onUpdate:modelValue"]),e.createVNode(Q,{type:"danger",plain:"",size:"small",icon:e.unref(le.Delete),disabled:(t.component.props.columns||[]).length<=1,onClick:J=>W(Y)},null,8,["icon","disabled","onClick"])]))),128)),e.createVNode(Q,{type:"primary",plain:"",size:"small",icon:e.unref(le.Plus),style:{width:"100%"},onClick:j},{default:e.withCtx(()=>[...n[36]||(n[36]=[e.createTextVNode(" 添加列 ",-1)])]),_:1},8,["icon"])])])],64)):e.createCommentVNode("",!0)])])]),_:1})):e.createCommentVNode("",!0),e.withDirectives(e.createVNode(ae,{class:"_fc-r-tab-form"},{default:e.withCtx(()=>[e.createElementVNode("div",Ht,[e.createElementVNode("div",Wt,[e.createVNode(ee,null,{default:e.withCtx(()=>[...n[40]||(n[40]=[e.createTextVNode("表单配置",-1)])]),_:1}),e.createElementVNode("div",qt,[e.createElementVNode("div",Jt,[n[41]||(n[41]=e.createElementVNode("div",{class:"_fd-ci-label"},[e.createElementVNode("span",null,"表单名称")],-1)),e.createElementVNode("div",Yt,[e.createVNode(H,{modelValue:t.formOptions.name,"onUpdate:modelValue":n[19]||(n[19]=f=>t.formOptions.name=f),size:"small",style:{width:"180px"}},null,8,["modelValue"])])])]),e.createElementVNode("div",Kt,[e.createElementVNode("div",Qt,[n[42]||(n[42]=e.createElementVNode("div",{class:"_fd-ci-label"},[e.createElementVNode("span",null,"表单描述")],-1)),e.createElementVNode("div",Xt,[e.createVNode(H,{modelValue:t.formOptions.description,"onUpdate:modelValue":n[20]||(n[20]=f=>t.formOptions.description=f),size:"small",style:{width:"180px"}},null,8,["modelValue"])])])]),e.createElementVNode("div",Zt,[e.createElementVNode("div",vt,[n[43]||(n[43]=e.createElementVNode("div",{class:"_fd-ci-label"},[e.createElementVNode("span",null,"标签宽度")],-1)),e.createElementVNode("div",eo,[e.createVNode(H,{modelValue:t.formOptions.labelWidth,"onUpdate:modelValue":n[21]||(n[21]=f=>t.formOptions.labelWidth=f),size:"small",style:{width:"120px"}},null,8,["modelValue"])])])]),e.createElementVNode("div",to,[e.createElementVNode("div",oo,[n[44]||(n[44]=e.createElementVNode("div",{class:"_fd-ci-label"},[e.createElementVNode("span",null,"组件尺寸")],-1)),e.createElementVNode("div",lo,[e.createVNode(L,{modelValue:t.formOptions.size,"onUpdate:modelValue":n[22]||(n[22]=f=>t.formOptions.size=f),size:"small",style:{width:"120px"}},{default:e.withCtx(()=>[e.createVNode(D,{label:"较大",value:"large"}),e.createVNode(D,{label:"默认",value:"default"}),e.createVNode(D,{label:"较小",value:"small"})]),_:1},8,["modelValue"])])])])])])]),_:1},512),[[e.vShow,r.value==="form"||!t.component]])]),_:1})}}}),ao={class:"_fc-json-preview-down"},ro={key:0,class:"gb-fc-json-error"},io=Object.assign({name:"FcJsonPanel"},{__name:"FcJsonPanel",props:{components:{type:Array,required:!0},formOptions:{type:Object,required:!0},fileName:{type:String,default:"form"}},emits:["update:components","update:formOptions"],setup(t,{expose:l,emit:o}){const r=t,c=o,s=e.ref("rule"),p=e.ref(JSON.stringify(r.components,null,2)),i=e.ref("");let h="";const y=()=>s.value==="rule"?JSON.stringify(r.components,null,2):JSON.stringify(r.formOptions,null,2),g=O=>{s.value=O,p.value=y(),i.value=""},A=()=>{h=y()},T=()=>{if(i.value="",p.value.trim()!==h.trim())try{const O=JSON.parse(p.value);if(s.value==="rule"){if(!Array.isArray(O))throw new Error("表单规则必须是数组");c("update:components",O)}else c("update:formOptions",O||{});G.ElMessage.success("JSON 已应用")}catch(O){i.value=`JSON 解析失败:${O.message}`}},k=()=>{const O=s.value==="rule"?{rule:r.components,options:r.formOptions}:{options:r.formOptions,rule:r.components},b=new Blob([JSON.stringify(O,null,2)],{type:"application/json"}),w=URL.createObjectURL(b),R=document.createElement("a");R.href=w,R.download=`fc-json-${Date.now()}.json`,R.click(),setTimeout(()=>URL.revokeObjectURL(w),0)};return l({refresh:()=>p.value=y()}),(O,b)=>{const w=e.resolveComponent("el-tooltip"),R=e.resolveComponent("el-header"),j=e.resolveComponent("el-main"),W=e.resolveComponent("el-container");return e.openBlock(),e.createBlock(W,{class:"_fc-json-preview"},{default:e.withCtx(()=>[e.createVNode(R,{height:"40px",class:"_fc-l-tabs"},{default:e.withCtx(()=>[e.createElementVNode("div",{class:e.normalizeClass(["_fc-l-tab",{active:s.value==="rule"}]),onClick:b[0]||(b[0]=F=>g("rule"))},"表单规则",2),e.createElementVNode("div",{class:e.normalizeClass(["_fc-l-tab",{active:s.value==="options"}]),onClick:b[1]||(b[1]=F=>g("options"))},"表单配置",2),e.createElementVNode("div",ao,[e.createVNode(w,{effect:"dark",content:"导出 JSON",placement:"top","hide-after":0},{default:e.withCtx(()=>[e.createElementVNode("i",{class:"fc-icon icon-download",onClick:k})]),_:1})])]),_:1}),e.createVNode(j,{style:{padding:"8px"}},{default:e.withCtx(()=>[e.withDirectives(e.createElementVNode("textarea",{"onUpdate:modelValue":b[2]||(b[2]=F=>p.value=F),class:"gb-fc-json-editor",spellcheck:"false",onFocus:A,onBlur:T},null,544),[[e.vModelText,p.value]]),i.value?(e.openBlock(),e.createElementBlock("div",ro,e.toDisplayString(i.value),1)):e.createCommentVNode("",!0)]),_:1})]),_:1})}}});function so(){const t=s=>{P(s);const p=[];if(s.required){const i=s.type===d.CHECKBOX_GROUP,h=s.type===d.RADIO_GROUP||s.type===d.SELECT;p.push({required:!0,...i?{type:"array"}:{},message:i||h?`请选择${s.props?.label||"该字段"}`:`请输入${s.props?.label||"该字段"}`,trigger:h||i?"change":"blur"})}return s.type===d.INPUT_NUMBER&&(s.min!==void 0&&p.push({type:"number",min:s.min,message:`数值不能小于 ${s.min}`,trigger:"blur"}),s.max!==void 0&&p.push({type:"number",max:s.max,message:`数值不能大于 ${s.max}`,trigger:"blur"})),p.length>0?p:void 0};return{generateFormRules:s=>{const p={},i={},h=y=>{if(y.type===d.ROW){y.children&&y.children.forEach(T=>{Array.isArray(T)&&T.forEach(k=>{h(k)})});return}const g=P(y),A=t(y);if(A&&(i[g]=A),!(g in p))if(y.defaultValue!==void 0&&y.defaultValue!==null)if(y.type===d.DATE_PICKER){const T=y.defaultValue;if(T==="today")p[g]=new Date;else if(T==="tomorrow"){const k=new Date;k.setDate(k.getDate()+1),p[g]=k}else p[g]=T}else p[g]=y.defaultValue;else y.type===d.INPUT_NUMBER?p[g]=null:y.type===d.RADIO_GROUP||y.type===d.SELECT||y.type===d.TEXTAREA?p[g]="":y.type===d.DATE_PICKER?p[g]=null:y.type===d.CHECKBOX_GROUP?p[g]=[]:y.type===d.SWITCH?p[g]=!1:p[g]=""};return Array.isArray(s)&&s.forEach(y=>{h(y)}),{data:p,rules:i}},validateForm:async s=>{if(!s)throw new Error("表单引用不存在");return await s.validate()},resetForm:s=>{s&&s.resetFields()},getFormData:(s,p)=>{const i={},h=y=>{if(y.type===d.ROW){y.children&&y.children.forEach(A=>{Array.isArray(A)&&A.forEach(T=>{h(T)})});return}const g=P(y);g in s&&(i[g]={name:y.props?.label||"",value:s[g],type:y.type})};return Array.isArray(p)&&p.forEach(y=>{h(y)}),i}}}const co={class:"form-view-container"},mo={class:"form-view-content"},po=["data-width"],fo={key:1,class:"empty-state"},uo={key:0,class:"form-result"},Ne=xe(Object.assign({name:"GbFormViewer"},{__name:"FormViewer",props:{formConfig:{type:Array,default:()=>[]},showActions:{type:Boolean,default:!0},readonly:{type:Boolean,default:!1}},setup(t,{expose:l}){const o=t,r=e.ref(null),c=e.reactive({}),s=e.reactive({}),p=e.ref(!1),{generateFormRules:i}=so(),h=A=>{if(A.type===d.ROW)return{width:"100%"};if(A.style?.width){const T=A.style.width;let k=T;return typeof T=="string"&&T.includes("%")?k=T:typeof T=="number"&&(k=`${T}%`),{width:k,"--item-width":k}}return{width:"100%"}},y=()=>{Object.keys(c).forEach(k=>delete c[k]),Object.keys(s).forEach(k=>delete s[k]);const{data:A,rules:T}=i(o.formConfig);Object.assign(c,A),Object.assign(s,T)};e.watch(()=>o.formConfig,()=>{y()},{immediate:!0,deep:!0});const g=(A,T)=>{c[A]=T};return l({formData:c,formRef:r,formRules:s}),(A,T)=>{const k=e.resolveComponent("el-form"),O=e.resolveComponent("el-empty"),b=e.resolveComponent("el-divider");return e.openBlock(),e.createElementBlock("div",co,[e.createElementVNode("div",mo,[t.formConfig&&t.formConfig.length>0?(e.openBlock(),e.createBlock(k,{key:0,ref_key:"formRef",ref:r,model:c,rules:s,disabled:t.readonly,"label-width":"120px",class:"form-wrapper"},{default:e.withCtx(()=>[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(t.formConfig,(w,R)=>(e.openBlock(),e.createElementBlock("div",{key:R,class:e.normalizeClass(["form-item-wrapper",{"is-row":w.type===e.unref(d).ROW}]),style:e.normalizeStyle(h(w)),"data-width":w.style?.width},[e.createVNode(De,{component:w,"form-data":c,"form-rules":s,readonly:t.readonly,"onUpdate:value":g},null,8,["component","form-data","form-rules","readonly"])],14,po))),128))]),_:1},8,["model","rules","disabled"])):(e.openBlock(),e.createElementBlock("div",fo,[e.createVNode(O,{description:"暂无表单配置,请先设计表单"})]))]),p.value?(e.openBlock(),e.createElementBlock("div",uo,[e.createVNode(b,null,{default:e.withCtx(()=>[...T[0]||(T[0]=[e.createTextVNode("提交结果",-1)])]),_:1}),e.createElementVNode("pre",null,e.toDisplayString(JSON.stringify(c,null,2)),1)])):e.createCommentVNode("",!0)])}}}),[["__scopeId","data-v-d4573d59"]]),U=t=>String(t??"").replace(/"/g,""");function ho(t){const l=[],o=t.props?.label||"",r=t.props?.variableName||"";return o&&l.push(`label="${U(o)}"`),r&&l.push(`prop="${U(r)}"`),t.required&&l.push("required"),l.join(" ")}function Ie(t,l){const o=" ".repeat(l),r=ho(t),c=t.props?.variableName||"",s=[];switch(t.type){case d.INPUT:s.push(`${o} <el-input v-model="formData.${c}" placeholder="${U(t.props?.placeholder||"")}" />`);break;case d.TEXTAREA:s.push(`${o} <el-input v-model="formData.${c}" type="textarea" :rows="${t.props?.rows||3}" placeholder="${U(t.props?.placeholder||"")}" />`);break;case d.INPUT_NUMBER:s.push(`${o} <el-input-number v-model="formData.${c}" :min="${t.min??0}" :max="${t.max??100}" />`);break;case d.RADIO_GROUP:(t.props?.options||[]).forEach(p=>{s.push(`${o} <el-radio value="${U(p.value)}">${U(p.label)}</el-radio>`)}),s.unshift(`${o} <el-radio-group v-model="formData.${c}">`),s.push(`${o} </el-radio-group>`);break;case d.CHECKBOX_GROUP:(t.props?.options||[]).forEach(p=>{s.push(`${o} <el-checkbox value="${U(p.value)}">${U(p.label)}</el-checkbox>`)}),s.unshift(`${o} <el-checkbox-group v-model="formData.${c}">`),s.push(`${o} </el-checkbox-group>`);break;case d.SELECT:(t.props?.options||[]).forEach(p=>{s.push(`${o} <el-option label="${U(p.label)}" value="${U(p.value)}" />`)}),s.unshift(`${o} <el-select v-model="formData.${c}" placeholder="${U(t.props?.placeholder||"")}">`),s.push(`${o} </el-select>`);break;case d.SWITCH:s.push(`${o} <el-switch v-model="formData.${c}" />`);break;case d.DATE_PICKER:s.push(`${o} <el-date-picker v-model="formData.${c}" type="date" placeholder="${U(t.props?.placeholder||"")}" />`);break;default:s.push(`${o} <el-input v-model="formData.${c}" />`)}return`${o}<el-form-item ${r}>
|
|
1
|
+
(function(y,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("vue"),require("element-plus")):typeof define=="function"&&define.amd?define(["exports","vue","element-plus"],e):(y=typeof globalThis<"u"?globalThis:y||self,e(y.GbFormDesign={},y.Vue,y.ElementPlus))})(this,(function(y,e,j){"use strict";const nt=[["path",{d:"M18 6l-12 12"}],["path",{d:"M6 6l12 12"}]],lt=e.defineComponent({name:"Close",props:{size:{type:[Number,String],default:void 0},strokeWidth:{type:[Number,String],default:void 0}},setup:(t,{attrs:n})=>()=>e.h("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":Number(t.strokeWidth??2),"stroke-linecap":"round","stroke-linejoin":"round",width:t.size==null?"1em":`${t.size}px`,height:t.size==null?"1em":`${t.size}px`,...n},nt.map(([o,l])=>e.h(o,l)))}),at=[["path",{d:"M7 9.667a2.667 2.667 0 0 1 2.667 -2.667h8.666a2.667 2.667 0 0 1 2.667 2.667v8.666a2.667 2.667 0 0 1 -2.667 2.667h-8.666a2.667 2.667 0 0 1 -2.667 -2.667l0 -8.666"}],["path",{d:"M4.012 16.737a2.005 2.005 0 0 1 -1.012 -1.737v-10c0 -1.1 .9 -2 2 -2h10c.75 0 1.158 .385 1.5 1"}]],rt=e.defineComponent({name:"CopyDocument",props:{size:{type:[Number,String],default:void 0},strokeWidth:{type:[Number,String],default:void 0}},setup:(t,{attrs:n})=>()=>e.h("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":Number(t.strokeWidth??2),"stroke-linecap":"round","stroke-linejoin":"round",width:t.size==null?"1em":`${t.size}px`,height:t.size==null?"1em":`${t.size}px`,...n},at.map(([o,l])=>e.h(o,l)))}),it=[["path",{d:"M4 7l16 0"}],["path",{d:"M10 11l0 6"}],["path",{d:"M14 11l0 6"}],["path",{d:"M5 7l1 12a2 2 0 0 0 2 2h8a2 2 0 0 0 2 -2l1 -12"}],["path",{d:"M9 7v-3a1 1 0 0 1 1 -1h4a1 1 0 0 1 1 1v3"}]],ke=e.defineComponent({name:"Delete",props:{size:{type:[Number,String],default:void 0},strokeWidth:{type:[Number,String],default:void 0}},setup:(t,{attrs:n})=>()=>e.h("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":Number(t.strokeWidth??2),"stroke-linecap":"round","stroke-linejoin":"round",width:t.size==null?"1em":`${t.size}px`,height:t.size==null?"1em":`${t.size}px`,...n},it.map(([o,l])=>e.h(o,l)))}),st=[["path",{d:"M5 12h14"}],["path",{d:"M12 5v14"}]],Oe=e.defineComponent({name:"Plus",props:{size:{type:[Number,String],default:void 0},strokeWidth:{type:[Number,String],default:void 0}},setup:(t,{attrs:n})=>()=>e.h("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":Number(t.strokeWidth??2),"stroke-linecap":"round","stroke-linejoin":"round",width:t.size==null?"1em":`${t.size}px`,height:t.size==null?"1em":`${t.size}px`,...n},st.map(([o,l])=>e.h(o,l)))}),ct=[["path",{d:"M8 5a1 1 0 1 0 2 0a1 1 0 1 0 -2 0"}],["path",{d:"M8 12a1 1 0 1 0 2 0a1 1 0 1 0 -2 0"}],["path",{d:"M8 19a1 1 0 1 0 2 0a1 1 0 1 0 -2 0"}],["path",{d:"M14 5a1 1 0 1 0 2 0a1 1 0 1 0 -2 0"}],["path",{d:"M14 12a1 1 0 1 0 2 0a1 1 0 1 0 -2 0"}],["path",{d:"M14 19a1 1 0 1 0 2 0a1 1 0 1 0 -2 0"}]],dt=e.defineComponent({name:"Rank",props:{size:{type:[Number,String],default:void 0},strokeWidth:{type:[Number,String],default:void 0}},setup:(t,{attrs:n})=>()=>e.h("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":Number(t.strokeWidth??2),"stroke-linecap":"round","stroke-linejoin":"round",width:t.size==null?"1em":`${t.size}px`,height:t.size==null?"1em":`${t.size}px`,...n},ct.map(([o,l])=>e.h(o,l)))}),mt=[["path",{d:"M4 17v2a2 2 0 0 0 2 2h12a2 2 0 0 0 2 -2v-2"}],["path",{d:"M7 9l5 -5l5 5"}],["path",{d:"M12 4l0 12"}]],pt=e.defineComponent({name:"Upload",props:{size:{type:[Number,String],default:void 0},strokeWidth:{type:[Number,String],default:void 0}},setup:(t,{attrs:n})=>()=>e.h("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":Number(t.strokeWidth??2),"stroke-linecap":"round","stroke-linejoin":"round",width:t.size==null?"1em":`${t.size}px`,height:t.size==null?"1em":`${t.size}px`,...n},mt.map(([o,l])=>e.h(o,l)))}),d={INPUT:"input",TEXTAREA:"textarea",INPUT_NUMBER:"input-number",RADIO_GROUP:"radio-group",CHECKBOX_GROUP:"checkbox-group",SELECT:"select",SWITCH:"switch",DATE_PICKER:"date-picker",ROW:"row",BUTTON:"button"},Ae={[d.INPUT]:"文本输入框",[d.TEXTAREA]:"多行文本",[d.INPUT_NUMBER]:"数字输入框",[d.RADIO_GROUP]:"单选框",[d.CHECKBOX_GROUP]:"多选框",[d.SELECT]:"下拉选择",[d.SWITCH]:"开关",[d.DATE_PICKER]:"日期选择器",[d.ROW]:"分栏",[d.BUTTON]:"按钮"},ue=[d.RADIO_GROUP,d.CHECKBOX_GROUP,d.SELECT],ft={FULL:100,HALF:50,THIRD:33.33,QUARTER:25},ut={MIN_NUMBER:1,MAX_NUMBER:100,DEFAULT_GUTTER:20,DEFAULT_COLUMN_SPAN:12,MIN_COLUMN_SPAN:1,MAX_COLUMN_SPAN:24,MIN_WIDTH:10,MAX_WIDTH:100,WIDTH_STEP:5},_e={TODAY:"today",TOMORROW:"tomorrow"};function X(){return`component_${Date.now()}_${Math.random().toString(36).substr(2,9)}`}function he(t){return t.id||(t.id=X()),t}function re(t){if(t==null||t==="")return null;const n=Number(t);return isNaN(n)?null:n}function Ne(t){return t==null||t===""}function Re(t){return Array.isArray(t)?t.map(n=>typeof n=="string"?{label:n,value:n}:{...n}):[]}function Be(t,n=100){if(t==null)return n;if(typeof t=="number")return t;const o=String(t).replace("%",""),l=parseFloat(o);return isNaN(l)?n:l}function M(t){return t.props?.variableName||`field_${t.id||Date.now()}`}const Se=t=>{const n=t.defaultValue;if(Ne(n))return null;if(t.type===d.DATE_PICKER){if(n===_e.TODAY)return new Date;if(n===_e.TOMORROW){const o=new Date;return o.setDate(o.getDate()+1),o}return null}return t.type===d.INPUT_NUMBER?re(n):t.type===d.CHECKBOX_GROUP?Array.isArray(n)?[...n]:[]:n},De=(t,n)=>{const o=t.__vccOpts||t;for(const[l,c]of n)o[l]=c;return o},ht={class:"form-viewer"},Nt={key:0,class:"row-container"},Et={class:"column-wrapper"},xe=De(Object.assign({name:"FormField"},{__name:"FormField",props:{component:{type:Object,required:!0},formData:{type:Object,required:!0},formRules:{type:Object,required:!0},readonly:{type:Boolean,default:!1}},emits:["update:value"],setup(t,{emit:n}){const o=t,l=n,c=e.computed(()=>M(o.component));e.onMounted(()=>{if(!(c.value in o.formData)){const i=Se(o.component);i!=null?o.formData[c.value]=i:o.component.type===d.INPUT_NUMBER?o.formData[c.value]=null:o.component.type===d.RADIO_GROUP||o.component.type===d.SELECT||o.component.type===d.TEXTAREA?o.formData[c.value]="":o.component.type===d.DATE_PICKER?o.formData[c.value]=null:o.component.type===d.CHECKBOX_GROUP?o.formData[c.value]=[]:o.component.type===d.SWITCH?o.formData[c.value]=!1:o.formData[c.value]=""}});const s=e.computed({get(){let i=o.formData[c.value];if(o.component.type===d.INPUT_NUMBER)return re(i);if(Ne(i)&&o.component.defaultValue!==void 0&&o.component.defaultValue!==null){const h=Se(o.component);if(h!=null)return h}return i},set(i){o.component.type===d.INPUT_NUMBER?o.formData[c.value]=re(i):o.component.type===d.CHECKBOX_GROUP?o.formData[c.value]=Array.isArray(i)?[...i]:[]:o.component.type===d.SWITCH?o.formData[c.value]=i===!0:o.formData[c.value]=i,l("update:value",c.value,o.formData[c.value])}}),p=i=>{l("update:value",c.value,i)};return(i,h)=>{const N=e.resolveComponent("FormField",!0),b=e.resolveComponent("el-col"),A=e.resolveComponent("el-row"),C=e.resolveComponent("el-input"),w=e.resolveComponent("el-form-item"),O=e.resolveComponent("el-input-number"),g=e.resolveComponent("el-radio"),k=e.resolveComponent("el-radio-group"),R=e.resolveComponent("el-option"),G=e.resolveComponent("el-select"),H=e.resolveComponent("el-checkbox"),P=e.resolveComponent("el-checkbox-group"),U=e.resolveComponent("el-switch"),V=e.resolveComponent("el-date-picker");return e.openBlock(),e.createElementBlock("div",ht,[t.component.type===e.unref(d).ROW?(e.openBlock(),e.createElementBlock("div",Nt,[e.createVNode(A,{gutter:t.component.props?.gutter||20},{default:e.withCtx(()=>[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(t.component.props?.columns||[],(a,F)=>(e.openBlock(),e.createBlock(b,{key:F,span:a.span||12},{default:e.withCtx(()=>[e.createElementVNode("div",Et,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(t.component.children?.[F]||[],(D,L)=>(e.openBlock(),e.createBlock(N,{key:L,component:D,"form-data":t.formData,"form-rules":t.formRules,readonly:t.readonly},null,8,["component","form-data","form-rules","readonly"]))),128))])]),_:2},1032,["span"]))),128))]),_:1},8,["gutter"])])):t.component.type===e.unref(d).INPUT?(e.openBlock(),e.createBlock(w,{key:1,label:t.component.props?.label||"",prop:e.unref(M)(t.component),required:t.component.required},{default:e.withCtx(()=>[e.createVNode(C,{modelValue:s.value,"onUpdate:modelValue":h[0]||(h[0]=a=>s.value=a),placeholder:t.component.props?.placeholder||"请输入文本",style:{width:"100%"},disabled:t.readonly,onInput:p},null,8,["modelValue","placeholder","disabled"])]),_:1},8,["label","prop","required"])):t.component.type===e.unref(d).TEXTAREA?(e.openBlock(),e.createBlock(w,{key:2,label:t.component.props?.label||"",prop:e.unref(M)(t.component),required:t.component.required},{default:e.withCtx(()=>[e.createVNode(C,{modelValue:s.value,"onUpdate:modelValue":h[1]||(h[1]=a=>s.value=a),type:"textarea",rows:t.component.props?.rows||3,placeholder:t.component.props?.placeholder||"请输入内容",style:{width:"100%"},disabled:t.readonly,onInput:p},null,8,["modelValue","rows","placeholder","disabled"])]),_:1},8,["label","prop","required"])):t.component.type===e.unref(d).INPUT_NUMBER?(e.openBlock(),e.createBlock(w,{key:3,label:t.component.props?.label||"",prop:e.unref(M)(t.component),required:t.component.required},{default:e.withCtx(()=>[e.createVNode(O,{modelValue:s.value,"onUpdate:modelValue":h[2]||(h[2]=a=>s.value=a),min:t.component.min||1,max:t.component.max||100,style:{width:"100%"},disabled:t.readonly,onChange:p},null,8,["modelValue","min","max","disabled"])]),_:1},8,["label","prop","required"])):t.component.type===e.unref(d).RADIO_GROUP?(e.openBlock(),e.createBlock(w,{key:4,label:t.component.props?.label||"",prop:e.unref(M)(t.component),required:t.component.required},{default:e.withCtx(()=>[e.createVNode(k,{modelValue:s.value,"onUpdate:modelValue":h[3]||(h[3]=a=>s.value=a),style:{width:"100%"},disabled:t.readonly,onChange:p},{default:e.withCtx(()=>[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(t.component.props?.options||["选项1","选项2","选项3"],a=>(e.openBlock(),e.createBlock(g,{key:a.value||a,value:a.value||a},{default:e.withCtx(()=>[e.createTextVNode(e.toDisplayString(a.label||a),1)]),_:2},1032,["value"]))),128))]),_:1},8,["modelValue","disabled"])]),_:1},8,["label","prop","required"])):t.component.type===e.unref(d).SELECT?(e.openBlock(),e.createBlock(w,{key:5,label:t.component.props?.label||"",prop:e.unref(M)(t.component),required:t.component.required},{default:e.withCtx(()=>[e.createVNode(G,{modelValue:s.value,"onUpdate:modelValue":h[4]||(h[4]=a=>s.value=a),placeholder:t.component.props?.placeholder||"请选择",style:{width:"100%"},disabled:t.readonly,onChange:p},{default:e.withCtx(()=>[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(t.component.props?.options||[],a=>(e.openBlock(),e.createBlock(R,{key:a.value||a,label:a.label||a,value:a.value||a},null,8,["label","value"]))),128))]),_:1},8,["modelValue","placeholder","disabled"])]),_:1},8,["label","prop","required"])):t.component.type===e.unref(d).CHECKBOX_GROUP?(e.openBlock(),e.createBlock(w,{key:6,label:t.component.props?.label||"",prop:e.unref(M)(t.component),required:t.component.required},{default:e.withCtx(()=>[e.createVNode(P,{modelValue:s.value,"onUpdate:modelValue":h[5]||(h[5]=a=>s.value=a),style:{width:"100%"},disabled:t.readonly,onChange:p},{default:e.withCtx(()=>[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(t.component.props?.options||[],a=>(e.openBlock(),e.createBlock(H,{key:a.value||a,value:a.value||a},{default:e.withCtx(()=>[e.createTextVNode(e.toDisplayString(a.label||a),1)]),_:2},1032,["value"]))),128))]),_:1},8,["modelValue","disabled"])]),_:1},8,["label","prop","required"])):t.component.type===e.unref(d).SWITCH?(e.openBlock(),e.createBlock(w,{key:7,label:t.component.props?.label||"",prop:e.unref(M)(t.component),required:t.component.required},{default:e.withCtx(()=>[e.createVNode(U,{modelValue:s.value,"onUpdate:modelValue":h[6]||(h[6]=a=>s.value=a),"active-text":t.component.props?.activeText||"","inactive-text":t.component.props?.inactiveText||"",disabled:t.readonly,onChange:p},null,8,["modelValue","active-text","inactive-text","disabled"])]),_:1},8,["label","prop","required"])):t.component.type===e.unref(d).DATE_PICKER?(e.openBlock(),e.createBlock(w,{key:8,label:t.component.props?.label||"",prop:e.unref(M)(t.component),required:t.component.required},{default:e.withCtx(()=>[e.createVNode(V,{modelValue:s.value,"onUpdate:modelValue":h[7]||(h[7]=a=>s.value=a),type:"date",placeholder:t.component.props?.placeholder||"选择日期",style:{width:"100%"},disabled:t.readonly,onChange:p},null,8,["modelValue","placeholder","disabled"])]),_:1},8,["label","prop","required"])):e.createCommentVNode("",!0)])}}}),[["__scopeId","data-v-e2eff285"]]),yt={key:0,class:"_fd-draggable-drag _fd-drag-box gb-fc-row-box"},Vt=["onDragover","onDrop"],bt={class:"gb-fc-tools"},gt=["title"],Ie=Object.assign({name:"FcCanvasField"},{__name:"FcCanvasField",props:{component:{type:Object,required:!0},path:{type:Array,required:!0},formData:{type:Object,required:!0},formRules:{type:Object,required:!0},activeId:{type:String,default:""},depth:{type:Number,default:0}},setup(t){const n=t,o=e.inject("fcCanvasOps"),l=e.inject("fcDragOver"),c=e.computed(()=>n.component.type===d.ROW),s=e.computed(()=>n.component.props?.columns?.length||2);e.computed(()=>(n.component.children||[]).every(g=>!g||g.length===0));const p={kind:"existing",path:n.path},i=g=>{g.dataTransfer.effectAllowed="move",g.dataTransfer.setData("application/x-gb-field",JSON.stringify(p)),g.dataTransfer.setData("text/plain","gb-field"),o.startDrag(n.path)},h=()=>{o.endDrag()},N=g=>{g.preventDefault();const k=g.currentTarget.getBoundingClientRect(),R=g.clientY-k.top<k.height/2?"top":"bottom";l.value=n.path.join(".")+":"+R,g.dataTransfer.dropEffect="move"},b=()=>{l.value?.startsWith(n.path.join("."))&&(l.value="")},A=g=>{g.preventDefault(),g.stopPropagation();const k=l.value?.endsWith(":top")?"top":"bottom",R=O(g);l.value="",R&&o.dropAt(R,{path:n.path,position:k})},C=g=>{l.value=n.path.join(".")+":col"+g},w=(g,k)=>{const R=O(k);l.value="",R&&o.dropAt(R,{path:n.path,column:g})},O=g=>{const k=g?.dataTransfer?.getData("application/x-gb-field");if(k)try{return JSON.parse(k)}catch{return null}return o.getDragPayload()};return(g,k)=>{const R=e.resolveComponent("FcCanvasField",!0),G=e.resolveComponent("el-col"),H=e.resolveComponent("el-row");return e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass(["_fc-draggable-item _fd-drag-item gb-fc-item",{"is-active":t.activeId===t.component.id,"is-hidden":t.component.hidden,"drag-over-top":e.unref(l)===t.path.join(".")+":top","drag-over-bottom":e.unref(l)===t.path.join(".")+":bottom"}]),onDragover:e.withModifiers(N,["prevent"]),onDragenter:k[3]||(k[3]=e.withModifiers(()=>{},["prevent"])),onDragleave:b,onDrop:e.withModifiers(A,["stop","prevent"])},[c.value?(e.openBlock(),e.createElementBlock("div",yt,[e.createVNode(H,{gutter:t.component.props?.gutter||20},{default:e.withCtx(()=>[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(s.value,(P,U)=>(e.openBlock(),e.createBlock(G,{key:U,span:t.component.props?.columns?.[U]?.span||12},{default:e.withCtx(()=>[e.createElementVNode("div",{class:e.normalizeClass(["gb-fc-column",{"_fc-child-empty":!(t.component.children?.[U]||[]).length,"has-child":(t.component.children?.[U]||[]).length}]),onDragover:e.withModifiers(V=>C(U),["prevent","stop"]),onDrop:e.withModifiers(V=>w(U,V),["stop","prevent"])},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(t.component.children?.[U]||[],(V,a)=>(e.openBlock(),e.createBlock(R,{key:V.id||a,component:V,path:[...t.path,"children",U,a],"form-data":t.formData,"form-rules":t.formRules,"active-id":t.activeId,depth:t.depth+1},null,8,["component","path","form-data","form-rules","active-id","depth"]))),128))],42,Vt)]),_:2},1032,["span"]))),128))]),_:1},8,["gutter"])])):(e.openBlock(),e.createBlock(xe,{key:1,component:t.component,"form-data":t.formData,"form-rules":t.formRules,readonly:!0},null,8,["component","form-data","form-rules"])),e.createElementVNode("div",{class:"gb-fc-mask",onClick:k[2]||(k[2]=e.withModifiers(P=>e.unref(o).active(t.component,t.path),["stop"]))},[e.createElementVNode("div",bt,[e.createElementVNode("i",{class:"gb-fc-tool gb-fc-tool--handle",title:"拖拽"+(t.component.props?.label||t.component.type),draggable:"true",onDragstart:e.withModifiers(i,["stop"]),onDragend:h},[e.createVNode(e.unref(dt),{style:{width:"14px",height:"14px"}})],40,gt),e.createElementVNode("i",{class:"gb-fc-tool",title:"复制",onClick:k[0]||(k[0]=e.withModifiers(P=>e.unref(o).copy(t.path),["stop"]))},[e.createVNode(e.unref(rt),{style:{width:"14px",height:"14px"}})]),e.createElementVNode("i",{class:"gb-fc-tool gb-fc-tool--danger",title:"删除",onClick:k[1]||(k[1]=e.withModifiers(P=>e.unref(o).remove(t.path),["stop"]))},[e.createVNode(e.unref(lt),{style:{width:"14px",height:"14px"}})])])])],34)}}}),Ct={class:"_fd-config-item",style:{"margin-top":"12px"}},Tt={class:"_fd-ci-head"},wt={class:"_fd-ci-con"},kt={class:"_fc-r-config"},Ot={style:{"grid-area":"base"}},At={key:0,class:"_fd-config-item"},_t={class:"_fd-ci-head"},Rt={class:"_fd-ci-con"},Bt={key:1,class:"_fd-config-item"},St={class:"_fd-ci-head"},Dt={class:"_fd-ci-con"},xt={key:0,style:{display:"flex","justify-content":"flex-end","margin-top":"6px"}},It={key:2,class:"_fd-config-item"},$t={class:"_fd-ci-head"},Ut={class:"_fd-ci-con"},Mt={style:{"grid-area":"props"}},Pt={key:0,class:"_fd-config-item"},Ft={class:"_fd-ci-head"},Lt={class:"_fd-ci-con"},zt={class:"_fd-config-item"},jt={class:"_fd-ci-head"},Gt={class:"_fd-ci-con"},Wt={class:"_fd-config-item"},Ht={class:"_fd-ci-head"},qt={class:"_fd-ci-con"},Jt={key:2,class:"_fd-config-item"},Yt={class:"_fd-ci-append",style:{display:"block"}},Kt={class:"_fd-config-item"},Qt={class:"_fd-ci-head"},Xt={class:"_fd-ci-con"},Zt={class:"_fd-config-item"},vt={class:"_fd-ci-append",style:{display:"block"}},eo={style:{"font-size":"12px",color:"#666",width:"60px"}},to={class:"_fc-r-config"},oo={style:{"grid-area":"base"}},no={class:"_fd-config-item"},lo={class:"_fd-ci-head"},ao={class:"_fd-ci-con"},ro={class:"_fd-config-item"},io={class:"_fd-ci-head"},so={class:"_fd-ci-con"},co={class:"_fd-config-item"},mo={class:"_fd-ci-head"},po={class:"_fd-ci-con"},fo={class:"_fd-config-item"},uo={class:"_fd-ci-head"},ho={class:"_fd-ci-con"},No=Object.assign({name:"FcPropsPanel"},{__name:"FcPropsPanel",props:{component:{type:Object,default:null},formOptions:{type:Object,required:!0}},emits:["close"],setup(t,{emit:n}){const o=t,l=e.ref("props"),c=e.computed(()=>o.component?.type===d.ROW),s=e.computed(()=>ue.includes(o.component?.type)),p=e.computed(()=>o.component?.props?(Array.isArray(o.component.props.options)||(o.component.props.options=[]),o.component.props.options):[]),i=Object.entries(Ae).filter(([V])=>V!==d.BUTTON).map(([V,a])=>({value:V,label:a})),h=e.computed({get:()=>o.component?.type,set:V=>{!V||!o.component||(o.component.type=V,o.component.props||(o.component.props={}),ue.includes(V)&&!o.component.props.options?.length&&(o.component.props.options=[{label:"选项1",value:"1"},{label:"选项2",value:"2"}]),V===d.ROW&&(o.component.props.columns||(o.component.props.columns=[{span:12},{span:12}]),o.component.children||(o.component.children=[[],[]]),o.component.props.gutter=o.component.props.gutter||20,he(o.component)))}}),N=e.ref("100%"),b=e.ref(100),A=()=>{const V=o.component?.style?.width,a=["100%","50%","33.33%","25%"];if(!V){N.value="100%";return}N.value=a.includes(V)?V:"custom",N.value==="custom"&&(b.value=Be(V))};A(),e.watch(()=>o.component?.id,A);const C=V=>{o.component&&(o.component.style||(o.component.style={}),V==="custom"?o.component.style.width=`${b.value}%`:o.component.style.width=V)},w=V=>{o.component&&(o.component.style||(o.component.style={}),o.component.style.width=`${V}%`)},O=V=>typeof V=="string"?V:V.label,g=V=>typeof V=="string"?V:V.value,k=()=>{p.value.push({label:`选项${p.value.length+1}`,value:`${p.value.length+1}`})},R=V=>{p.value.splice(V,1)},G=()=>{const V=o.component.props.columns;V.push({span:Math.max(1,Math.round(24/(V.length+1)))}),o.component.children||(o.component.children=[]),o.component.children.push([])},H=V=>{o.component.props.columns.splice(V,1),o.component.children?.splice(V,1)},P=async()=>{const V=o.component?.props?.variableName;if(V)try{await navigator.clipboard.writeText(V),j.ElMessage.success("字段名已复制")}catch{j.ElMessage.warning("复制失败")}},U=()=>{o.component&&(o.component.props.variableName=`field_${X().split("_").pop()}`)};return(V,a)=>{const F=e.resolveComponent("el-header"),D=e.resolveComponent("el-option"),L=e.resolveComponent("el-select"),W=e.resolveComponent("el-input"),v=e.resolveComponent("el-switch"),ee=e.resolveComponent("el-divider"),q=e.resolveComponent("el-input-number"),Q=e.resolveComponent("el-button"),le=e.resolveComponent("el-main"),me=e.resolveComponent("el-container");return e.openBlock(),e.createBlock(me,{style:{height:"100%"}},{default:e.withCtx(()=>[e.createVNode(F,{height:"40px",class:"_fc-r-tabs"},{default:e.withCtx(()=>[t.component?(e.openBlock(),e.createElementBlock("div",{key:0,class:e.normalizeClass(["_fc-r-tab",{active:l.value==="props"}]),onClick:a[0]||(a[0]=f=>l.value="props")}," 组件 ",2)):e.createCommentVNode("",!0),e.createElementVNode("div",{class:e.normalizeClass(["_fc-r-tab",{active:l.value==="form"||!t.component}]),onClick:a[1]||(a[1]=f=>l.value="form")}," 表单 ",2)]),_:1}),l.value==="props"&&t.component?(e.openBlock(),e.createBlock(le,{key:0,class:"_fc-r-tab-props"},{default:e.withCtx(()=>[e.createElementVNode("div",{class:"_fc-r-tools-close",onClick:a[2]||(a[2]=f=>V.$emit("close"))},[...a[23]||(a[23]=[e.createElementVNode("i",{class:"fc-icon icon-add2"},null,-1)])]),a[38]||(a[38]=e.createElementVNode("p",{class:"_fc-r-title"},"组件类型",-1)),e.createVNode(L,{modelValue:h.value,"onUpdate:modelValue":a[3]||(a[3]=f=>h.value=f),style:{width:"100%"}},{default:e.withCtx(()=>[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(e.unref(i),f=>(e.openBlock(),e.createBlock(D,{key:f.value,label:f.label,value:f.value},null,8,["label","value"]))),128))]),_:1},8,["modelValue"]),a[39]||(a[39]=e.createElementVNode("p",{class:"_fc-r-title"},"字段名",-1)),e.createVNode(W,{modelValue:t.component.props.variableName,"onUpdate:modelValue":a[4]||(a[4]=f=>t.component.props.variableName=f),class:"_fc-r-name-input"},{suffix:e.withCtx(()=>[e.createElementVNode("i",{class:"fc-icon icon-group",title:"复制字段名",onClick:P})]),append:e.withCtx(()=>[e.createElementVNode("i",{class:"fc-icon icon-auto",title:"根据标题生成",onClick:U})]),_:1},8,["modelValue"]),e.createElementVNode("div",Ct,[e.createElementVNode("div",Tt,[a[24]||(a[24]=e.createElementVNode("div",{class:"_fd-ci-label"},"隐藏",-1)),e.createElementVNode("div",wt,[e.createVNode(v,{modelValue:t.component.hidden,"onUpdate:modelValue":a[5]||(a[5]=f=>t.component.hidden=f),size:"small"},null,8,["modelValue"])])])]),e.createElementVNode("div",kt,[e.createElementVNode("div",Ot,[e.createVNode(ee,null,{default:e.withCtx(()=>[...a[25]||(a[25]=[e.createTextVNode("规则",-1)])]),_:1}),c.value?e.createCommentVNode("",!0):(e.openBlock(),e.createElementBlock("div",At,[e.createElementVNode("div",_t,[a[26]||(a[26]=e.createElementVNode("div",{class:"_fd-ci-label"},[e.createElementVNode("span",null,"必填")],-1)),e.createElementVNode("div",Rt,[e.createVNode(v,{modelValue:t.component.required,"onUpdate:modelValue":a[6]||(a[6]=f=>t.component.required=f),size:"small"},null,8,["modelValue"])])])])),c.value?e.createCommentVNode("",!0):(e.openBlock(),e.createElementBlock("div",Bt,[e.createElementVNode("div",St,[a[27]||(a[27]=e.createElementVNode("div",{class:"_fd-ci-label"},[e.createElementVNode("span",null,"字段宽度")],-1)),e.createElementVNode("div",Dt,[e.createVNode(L,{modelValue:N.value,"onUpdate:modelValue":a[7]||(a[7]=f=>N.value=f),size:"small",style:{width:"120px"},onChange:C},{default:e.withCtx(()=>[e.createVNode(D,{label:"整行",value:"100%"}),e.createVNode(D,{label:"1/2",value:"50%"}),e.createVNode(D,{label:"1/3",value:"33.33%"}),e.createVNode(D,{label:"1/4",value:"25%"}),e.createVNode(D,{label:"自定义",value:"custom"})]),_:1},8,["modelValue"])])]),N.value==="custom"?(e.openBlock(),e.createElementBlock("div",xt,[e.createVNode(q,{modelValue:b.value,"onUpdate:modelValue":a[8]||(a[8]=f=>b.value=f),min:10,max:100,step:5,size:"small",onChange:w},null,8,["modelValue"])])):e.createCommentVNode("",!0)])),c.value?e.createCommentVNode("",!0):(e.openBlock(),e.createElementBlock("div",It,[e.createElementVNode("div",$t,[a[28]||(a[28]=e.createElementVNode("div",{class:"_fd-ci-label"},[e.createElementVNode("span",null,"默认值")],-1)),e.createElementVNode("div",Ut,[["radio-group","select"].includes(t.component.type)?(e.openBlock(),e.createBlock(L,{key:0,modelValue:t.component.defaultValue,"onUpdate:modelValue":a[9]||(a[9]=f=>t.component.defaultValue=f),size:"small",clearable:"",style:{width:"180px"}},{default:e.withCtx(()=>[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(p.value,f=>(e.openBlock(),e.createBlock(D,{key:g(f),label:O(f),value:g(f)},null,8,["label","value"]))),128))]),_:1},8,["modelValue"])):t.component.type==="checkbox-group"?(e.openBlock(),e.createBlock(L,{key:1,modelValue:t.component.defaultValue,"onUpdate:modelValue":a[10]||(a[10]=f=>t.component.defaultValue=f),size:"small",multiple:"",clearable:"",style:{width:"180px"}},{default:e.withCtx(()=>[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(p.value,f=>(e.openBlock(),e.createBlock(D,{key:g(f),label:O(f),value:g(f)},null,8,["label","value"]))),128))]),_:1},8,["modelValue"])):t.component.type==="switch"?(e.openBlock(),e.createBlock(v,{key:2,modelValue:t.component.defaultValue,"onUpdate:modelValue":a[11]||(a[11]=f=>t.component.defaultValue=f),size:"small"},null,8,["modelValue"])):t.component.type==="date-picker"?(e.openBlock(),e.createBlock(L,{key:3,modelValue:t.component.defaultValue,"onUpdate:modelValue":a[12]||(a[12]=f=>t.component.defaultValue=f),size:"small",clearable:"",style:{width:"120px"}},{default:e.withCtx(()=>[e.createVNode(D,{label:"今天",value:"today"}),e.createVNode(D,{label:"明天",value:"tomorrow"}),e.createVNode(D,{label:"无",value:""})]),_:1},8,["modelValue"])):t.component.type==="input-number"?(e.openBlock(),e.createBlock(q,{key:4,modelValue:t.component.defaultValue,"onUpdate:modelValue":a[13]||(a[13]=f=>t.component.defaultValue=f),size:"small",style:{width:"140px"}},null,8,["modelValue"])):(e.openBlock(),e.createBlock(W,{key:5,modelValue:t.component.defaultValue,"onUpdate:modelValue":a[14]||(a[14]=f=>t.component.defaultValue=f),size:"small",style:{width:"180px"}},null,8,["modelValue"]))])])]))]),e.createElementVNode("div",Mt,[e.createVNode(ee,null,{default:e.withCtx(()=>[...a[29]||(a[29]=[e.createTextVNode("属性",-1)])]),_:1}),["input","textarea","select"].includes(t.component.type)?(e.openBlock(),e.createElementBlock("div",Pt,[e.createElementVNode("div",Ft,[a[30]||(a[30]=e.createElementVNode("div",{class:"_fd-ci-label"},[e.createElementVNode("span",null,"提示文字")],-1)),e.createElementVNode("div",Lt,[e.createVNode(W,{modelValue:t.component.props.placeholder,"onUpdate:modelValue":a[15]||(a[15]=f=>t.component.props.placeholder=f),size:"small",style:{width:"180px"}},null,8,["modelValue"])])])])):e.createCommentVNode("",!0),t.component.type==="input-number"?(e.openBlock(),e.createElementBlock(e.Fragment,{key:1},[e.createElementVNode("div",zt,[e.createElementVNode("div",jt,[a[31]||(a[31]=e.createElementVNode("div",{class:"_fd-ci-label"},[e.createElementVNode("span",null,"最小值")],-1)),e.createElementVNode("div",Gt,[e.createVNode(q,{modelValue:t.component.min,"onUpdate:modelValue":a[16]||(a[16]=f=>t.component.min=f),size:"small",style:{width:"140px"}},null,8,["modelValue"])])])]),e.createElementVNode("div",Wt,[e.createElementVNode("div",Ht,[a[32]||(a[32]=e.createElementVNode("div",{class:"_fd-ci-label"},[e.createElementVNode("span",null,"最大值")],-1)),e.createElementVNode("div",qt,[e.createVNode(q,{modelValue:t.component.max,"onUpdate:modelValue":a[17]||(a[17]=f=>t.component.max=f),size:"small",style:{width:"140px"}},null,8,["modelValue"])])])])],64)):e.createCommentVNode("",!0),s.value?(e.openBlock(),e.createElementBlock("div",Jt,[a[34]||(a[34]=e.createElementVNode("div",{class:"_fd-ci-head"},[e.createElementVNode("div",{class:"_fd-ci-label"},[e.createElementVNode("span",null,"选项配置")])],-1)),e.createElementVNode("div",Yt,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(p.value,(f,Y)=>(e.openBlock(),e.createElementBlock("div",{key:Y,class:"gb-fc-option"},[e.createVNode(W,{modelValue:f.label,"onUpdate:modelValue":J=>f.label=J,size:"small",placeholder:"选项名称"},null,8,["modelValue","onUpdate:modelValue"]),e.createVNode(W,{modelValue:f.value,"onUpdate:modelValue":J=>f.value=J,size:"small",placeholder:"选项值"},null,8,["modelValue","onUpdate:modelValue"]),e.createVNode(Q,{type:"danger",plain:"",size:"small",icon:e.unref(ke),onClick:J=>R(Y)},null,8,["icon","onClick"])]))),128)),e.createVNode(Q,{type:"primary",plain:"",size:"small",icon:e.unref(Oe),style:{width:"100%"},onClick:k},{default:e.withCtx(()=>[...a[33]||(a[33]=[e.createTextVNode(" 添加选项 ",-1)])]),_:1},8,["icon"])])])):e.createCommentVNode("",!0),c.value?(e.openBlock(),e.createElementBlock(e.Fragment,{key:3},[e.createElementVNode("div",Kt,[e.createElementVNode("div",Qt,[a[35]||(a[35]=e.createElementVNode("div",{class:"_fd-ci-label"},[e.createElementVNode("span",null,"列间距")],-1)),e.createElementVNode("div",Xt,[e.createVNode(q,{modelValue:t.component.props.gutter,"onUpdate:modelValue":a[18]||(a[18]=f=>t.component.props.gutter=f),min:0,max:100,size:"small",style:{width:"140px"}},null,8,["modelValue"])])])]),e.createElementVNode("div",Zt,[a[37]||(a[37]=e.createElementVNode("div",{class:"_fd-ci-head"},[e.createElementVNode("div",{class:"_fd-ci-label"},[e.createElementVNode("span",null,"列配置")])],-1)),e.createElementVNode("div",vt,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(t.component.props.columns,(f,Y)=>(e.openBlock(),e.createElementBlock("div",{key:Y,class:"gb-fc-option"},[e.createElementVNode("span",eo,"第"+e.toDisplayString(Y+1)+"列",1),e.createVNode(q,{modelValue:f.span,"onUpdate:modelValue":J=>f.span=J,min:1,max:24,size:"small"},null,8,["modelValue","onUpdate:modelValue"]),e.createVNode(Q,{type:"danger",plain:"",size:"small",icon:e.unref(ke),disabled:(t.component.props.columns||[]).length<=1,onClick:J=>H(Y)},null,8,["icon","disabled","onClick"])]))),128)),e.createVNode(Q,{type:"primary",plain:"",size:"small",icon:e.unref(Oe),style:{width:"100%"},onClick:G},{default:e.withCtx(()=>[...a[36]||(a[36]=[e.createTextVNode(" 添加列 ",-1)])]),_:1},8,["icon"])])])],64)):e.createCommentVNode("",!0)])])]),_:1})):e.createCommentVNode("",!0),e.withDirectives(e.createVNode(le,{class:"_fc-r-tab-form"},{default:e.withCtx(()=>[e.createElementVNode("div",to,[e.createElementVNode("div",oo,[e.createVNode(ee,null,{default:e.withCtx(()=>[...a[40]||(a[40]=[e.createTextVNode("表单配置",-1)])]),_:1}),e.createElementVNode("div",no,[e.createElementVNode("div",lo,[a[41]||(a[41]=e.createElementVNode("div",{class:"_fd-ci-label"},[e.createElementVNode("span",null,"表单名称")],-1)),e.createElementVNode("div",ao,[e.createVNode(W,{modelValue:t.formOptions.name,"onUpdate:modelValue":a[19]||(a[19]=f=>t.formOptions.name=f),size:"small",style:{width:"180px"}},null,8,["modelValue"])])])]),e.createElementVNode("div",ro,[e.createElementVNode("div",io,[a[42]||(a[42]=e.createElementVNode("div",{class:"_fd-ci-label"},[e.createElementVNode("span",null,"表单描述")],-1)),e.createElementVNode("div",so,[e.createVNode(W,{modelValue:t.formOptions.description,"onUpdate:modelValue":a[20]||(a[20]=f=>t.formOptions.description=f),size:"small",style:{width:"180px"}},null,8,["modelValue"])])])]),e.createElementVNode("div",co,[e.createElementVNode("div",mo,[a[43]||(a[43]=e.createElementVNode("div",{class:"_fd-ci-label"},[e.createElementVNode("span",null,"标签宽度")],-1)),e.createElementVNode("div",po,[e.createVNode(W,{modelValue:t.formOptions.labelWidth,"onUpdate:modelValue":a[21]||(a[21]=f=>t.formOptions.labelWidth=f),size:"small",style:{width:"120px"}},null,8,["modelValue"])])])]),e.createElementVNode("div",fo,[e.createElementVNode("div",uo,[a[44]||(a[44]=e.createElementVNode("div",{class:"_fd-ci-label"},[e.createElementVNode("span",null,"组件尺寸")],-1)),e.createElementVNode("div",ho,[e.createVNode(L,{modelValue:t.formOptions.size,"onUpdate:modelValue":a[22]||(a[22]=f=>t.formOptions.size=f),size:"small",style:{width:"120px"}},{default:e.withCtx(()=>[e.createVNode(D,{label:"较大",value:"large"}),e.createVNode(D,{label:"默认",value:"default"}),e.createVNode(D,{label:"较小",value:"small"})]),_:1},8,["modelValue"])])])])])])]),_:1},512),[[e.vShow,l.value==="form"||!t.component]])]),_:1})}}}),Eo={class:"_fc-json-preview-down"},yo={key:0,class:"gb-fc-json-error"},Vo=Object.assign({name:"FcJsonPanel"},{__name:"FcJsonPanel",props:{components:{type:Array,required:!0},formOptions:{type:Object,required:!0},fileName:{type:String,default:"form"}},emits:["update:components","update:formOptions"],setup(t,{expose:n,emit:o}){const l=t,c=o,s=e.ref("rule"),p=e.ref(JSON.stringify(l.components,null,2)),i=e.ref("");let h="";const N=()=>s.value==="rule"?JSON.stringify(l.components,null,2):JSON.stringify(l.formOptions,null,2),b=O=>{s.value=O,p.value=N(),i.value=""},A=()=>{h=N()},C=()=>{if(i.value="",p.value.trim()!==h.trim())try{const O=JSON.parse(p.value);if(s.value==="rule"){if(!Array.isArray(O))throw new Error("表单规则必须是数组");c("update:components",O)}else c("update:formOptions",O||{});j.ElMessage.success("JSON 已应用")}catch(O){i.value=`JSON 解析失败:${O.message}`}},w=()=>{const O=s.value==="rule"?{rule:l.components,options:l.formOptions}:{options:l.formOptions,rule:l.components},g=new Blob([JSON.stringify(O,null,2)],{type:"application/json"}),k=URL.createObjectURL(g),R=document.createElement("a");R.href=k,R.download=`fc-json-${Date.now()}.json`,R.click(),setTimeout(()=>URL.revokeObjectURL(k),0)};return n({refresh:()=>p.value=N()}),(O,g)=>{const k=e.resolveComponent("el-tooltip"),R=e.resolveComponent("el-header"),G=e.resolveComponent("el-main"),H=e.resolveComponent("el-container");return e.openBlock(),e.createBlock(H,{class:"_fc-json-preview"},{default:e.withCtx(()=>[e.createVNode(R,{height:"40px",class:"_fc-l-tabs"},{default:e.withCtx(()=>[e.createElementVNode("div",{class:e.normalizeClass(["_fc-l-tab",{active:s.value==="rule"}]),onClick:g[0]||(g[0]=P=>b("rule"))},"表单规则",2),e.createElementVNode("div",{class:e.normalizeClass(["_fc-l-tab",{active:s.value==="options"}]),onClick:g[1]||(g[1]=P=>b("options"))},"表单配置",2),e.createElementVNode("div",Eo,[e.createVNode(k,{effect:"dark",content:"导出 JSON",placement:"top","hide-after":0},{default:e.withCtx(()=>[e.createElementVNode("i",{class:"fc-icon icon-download",onClick:w})]),_:1})])]),_:1}),e.createVNode(G,{style:{padding:"8px"}},{default:e.withCtx(()=>[e.withDirectives(e.createElementVNode("textarea",{"onUpdate:modelValue":g[2]||(g[2]=P=>p.value=P),class:"gb-fc-json-editor",spellcheck:"false",onFocus:A,onBlur:C},null,544),[[e.vModelText,p.value]]),i.value?(e.openBlock(),e.createElementBlock("div",yo,e.toDisplayString(i.value),1)):e.createCommentVNode("",!0)]),_:1})]),_:1})}}});function bo(){const t=s=>{M(s);const p=[];if(s.required){const i=s.type===d.CHECKBOX_GROUP,h=s.type===d.RADIO_GROUP||s.type===d.SELECT;p.push({required:!0,...i?{type:"array"}:{},message:i||h?`请选择${s.props?.label||"该字段"}`:`请输入${s.props?.label||"该字段"}`,trigger:h||i?"change":"blur"})}return s.type===d.INPUT_NUMBER&&(s.min!==void 0&&p.push({type:"number",min:s.min,message:`数值不能小于 ${s.min}`,trigger:"blur"}),s.max!==void 0&&p.push({type:"number",max:s.max,message:`数值不能大于 ${s.max}`,trigger:"blur"})),p.length>0?p:void 0};return{generateFormRules:s=>{const p={},i={},h=N=>{if(N.type===d.ROW){N.children&&N.children.forEach(C=>{Array.isArray(C)&&C.forEach(w=>{h(w)})});return}const b=M(N),A=t(N);if(A&&(i[b]=A),!(b in p))if(N.defaultValue!==void 0&&N.defaultValue!==null)if(N.type===d.DATE_PICKER){const C=N.defaultValue;if(C==="today")p[b]=new Date;else if(C==="tomorrow"){const w=new Date;w.setDate(w.getDate()+1),p[b]=w}else p[b]=C}else p[b]=N.defaultValue;else N.type===d.INPUT_NUMBER?p[b]=null:N.type===d.RADIO_GROUP||N.type===d.SELECT||N.type===d.TEXTAREA?p[b]="":N.type===d.DATE_PICKER?p[b]=null:N.type===d.CHECKBOX_GROUP?p[b]=[]:N.type===d.SWITCH?p[b]=!1:p[b]=""};return Array.isArray(s)&&s.forEach(N=>{h(N)}),{data:p,rules:i}},validateForm:async s=>{if(!s)throw new Error("表单引用不存在");return await s.validate()},resetForm:s=>{s&&s.resetFields()},getFormData:(s,p)=>{const i={},h=N=>{if(N.type===d.ROW){N.children&&N.children.forEach(A=>{Array.isArray(A)&&A.forEach(C=>{h(C)})});return}const b=M(N);b in s&&(i[b]={name:N.props?.label||"",value:s[b],type:N.type})};return Array.isArray(p)&&p.forEach(N=>{h(N)}),i}}}const go={class:"form-view-container"},Co={class:"form-view-content"},To=["data-width"],wo={key:1,class:"empty-state"},ko={key:0,class:"form-result"},Ee=De(Object.assign({name:"GbFormViewer"},{__name:"FormViewer",props:{formConfig:{type:Array,default:()=>[]},showActions:{type:Boolean,default:!0},readonly:{type:Boolean,default:!1}},setup(t,{expose:n}){const o=t,l=e.ref(null),c=e.reactive({}),s=e.reactive({}),p=e.ref(!1),{generateFormRules:i}=bo(),h=A=>{if(A.type===d.ROW)return{width:"100%"};if(A.style?.width){const C=A.style.width;let w=C;return typeof C=="string"&&C.includes("%")?w=C:typeof C=="number"&&(w=`${C}%`),{width:w,"--item-width":w}}return{width:"100%"}},N=()=>{Object.keys(c).forEach(w=>delete c[w]),Object.keys(s).forEach(w=>delete s[w]);const{data:A,rules:C}=i(o.formConfig);Object.assign(c,A),Object.assign(s,C)};e.watch(()=>o.formConfig,()=>{N()},{immediate:!0,deep:!0});const b=(A,C)=>{c[A]=C};return n({formData:c,formRef:l,formRules:s}),(A,C)=>{const w=e.resolveComponent("el-form"),O=e.resolveComponent("el-empty"),g=e.resolveComponent("el-divider");return e.openBlock(),e.createElementBlock("div",go,[e.createElementVNode("div",Co,[t.formConfig&&t.formConfig.length>0?(e.openBlock(),e.createBlock(w,{key:0,ref_key:"formRef",ref:l,model:c,rules:s,disabled:t.readonly,"label-width":"120px",class:"form-wrapper"},{default:e.withCtx(()=>[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(t.formConfig,(k,R)=>(e.openBlock(),e.createElementBlock("div",{key:R,class:e.normalizeClass(["form-item-wrapper",{"is-row":k.type===e.unref(d).ROW}]),style:e.normalizeStyle(h(k)),"data-width":k.style?.width},[e.createVNode(xe,{component:k,"form-data":c,"form-rules":s,readonly:t.readonly,"onUpdate:value":b},null,8,["component","form-data","form-rules","readonly"])],14,To))),128))]),_:1},8,["model","rules","disabled"])):(e.openBlock(),e.createElementBlock("div",wo,[e.createVNode(O,{description:"暂无表单配置,请先设计表单"})]))]),p.value?(e.openBlock(),e.createElementBlock("div",ko,[e.createVNode(g,null,{default:e.withCtx(()=>[...C[0]||(C[0]=[e.createTextVNode("提交结果",-1)])]),_:1}),e.createElementVNode("pre",null,e.toDisplayString(JSON.stringify(c,null,2)),1)])):e.createCommentVNode("",!0)])}}}),[["__scopeId","data-v-806779a4"]]),$=t=>String(t??"").replace(/"/g,""");function Oo(t){const n=[],o=t.props?.label||"",l=t.props?.variableName||"";return o&&n.push(`label="${$(o)}"`),l&&n.push(`prop="${$(l)}"`),t.required&&n.push("required"),n.join(" ")}function $e(t,n){const o=" ".repeat(n),l=Oo(t),c=t.props?.variableName||"",s=[];switch(t.type){case d.INPUT:s.push(`${o} <el-input v-model="formData.${c}" placeholder="${$(t.props?.placeholder||"")}" />`);break;case d.TEXTAREA:s.push(`${o} <el-input v-model="formData.${c}" type="textarea" :rows="${t.props?.rows||3}" placeholder="${$(t.props?.placeholder||"")}" />`);break;case d.INPUT_NUMBER:s.push(`${o} <el-input-number v-model="formData.${c}" :min="${t.min??0}" :max="${t.max??100}" />`);break;case d.RADIO_GROUP:(t.props?.options||[]).forEach(p=>{s.push(`${o} <el-radio value="${$(p.value)}">${$(p.label)}</el-radio>`)}),s.unshift(`${o} <el-radio-group v-model="formData.${c}">`),s.push(`${o} </el-radio-group>`);break;case d.CHECKBOX_GROUP:(t.props?.options||[]).forEach(p=>{s.push(`${o} <el-checkbox value="${$(p.value)}">${$(p.label)}</el-checkbox>`)}),s.unshift(`${o} <el-checkbox-group v-model="formData.${c}">`),s.push(`${o} </el-checkbox-group>`);break;case d.SELECT:(t.props?.options||[]).forEach(p=>{s.push(`${o} <el-option label="${$(p.label)}" value="${$(p.value)}" />`)}),s.unshift(`${o} <el-select v-model="formData.${c}" placeholder="${$(t.props?.placeholder||"")}">`),s.push(`${o} </el-select>`);break;case d.SWITCH:s.push(`${o} <el-switch v-model="formData.${c}" />`);break;case d.DATE_PICKER:s.push(`${o} <el-date-picker v-model="formData.${c}" type="date" placeholder="${$(t.props?.placeholder||"")}" />`);break;default:s.push(`${o} <el-input v-model="formData.${c}" />`)}return`${o}<el-form-item ${l}>
|
|
2
2
|
${s.join(`
|
|
3
3
|
`)}
|
|
4
|
-
${o}</el-form-item>`}function
|
|
5
|
-
<el-form :model="formData" label-width="${
|
|
4
|
+
${o}</el-form-item>`}function Ao(t,n={}){const o=[];return(t||[]).forEach(l=>{if(l.type===d.ROW){const c=l.props?.columns||[];o.push('<el-row :gutter="'+(l.props?.gutter||20)+'">'),c.forEach((s,p)=>{o.push(' <el-col :span="'+(s.span||12)+'">'),(l.children?.[p]||[]).forEach(i=>{o.push($e(i,4))}),o.push(" </el-col>")}),o.push("</el-row>")}else o.push($e(l,0))}),`<template>
|
|
5
|
+
<el-form :model="formData" label-width="${n.labelWidth||"120px"}"${n.size&&n.size!=="default"?` size="${n.size}"`:""}>
|
|
6
6
|
${o.join(`
|
|
7
7
|
`).split(`
|
|
8
|
-
`).map(
|
|
8
|
+
`).map(l=>" "+l).join(`
|
|
9
9
|
`)}
|
|
10
10
|
</el-form>
|
|
11
|
-
</template>`}function
|
|
11
|
+
</template>`}function _o(t,n={}){const o=[],l=(c,s)=>{const p=" ".repeat(s),i=$(c.props?.label||""),h=$(c.props?.variableName||"");if(c.type===d.ROW){const N=c.props?.columns||[];o.push(`${p}<div class="row">`),N.forEach((b,A)=>{o.push(`${p} <div class="col-${b.span||12}">`),(c.children?.[A]||[]).forEach(C=>l(C,s+4)),o.push(`${p} </div>`)}),o.push(`${p}</div>`);return}o.push(`${p}<div class="form-item">`),o.push(`${p} <label>${i}${c.required?" <em>*</em>":""}</label>`),o.push(`${p} <div class="form-item-body" data-field="${h}" data-type="${c.type}"></div>`),o.push(`${p}</div>`)};return(t||[]).forEach(c=>l(c,0)),`<form class="gb-flow-form"${n.labelWidth?` style="--label-width:${n.labelWidth}"`:""}>
|
|
12
12
|
${o.join(`
|
|
13
13
|
`)}
|
|
14
|
-
</form>`}const No={class:"_fd-preview-tabs el-tabs"},Vo={class:"el-tabs__header"},go={class:"el-tabs__nav-wrap"},bo={class:"el-tabs__nav"},To=["onClick"],Co={key:2,class:"_fd-preview-code"},wo=Object.assign({name:"FcPreviewDialog"},{__name:"FcPreviewDialog",props:{modelValue:{type:Boolean,default:!1},components:{type:Array,default:()=>[]},formOptions:{type:Object,default:()=>({})}},emits:["update:modelValue"],setup(t){const l=t,o=[{label:"表单模式",value:"form"},{label:"组件模式",value:"component"},{label:"HTML 模式",value:"html"}],r=e.ref("form"),c=e.computed(()=>yo(l.components,l.formOptions)),s=e.computed(()=>Eo(l.components,l.formOptions)),p=async()=>{const i=r.value==="component"?c.value:s.value;try{await navigator.clipboard.writeText(i),G.ElMessage.success("代码已复制")}catch{G.ElMessage.warning("复制失败,请手动复制")}};return(i,h)=>{const y=e.resolveComponent("el-dialog");return e.openBlock(),e.createBlock(y,{"model-value":t.modelValue,width:"80%",class:"_fd-preview-dialog","append-to-body":"","onUpdate:modelValue":h[0]||(h[0]=g=>i.$emit("update:modelValue",g))},{default:e.withCtx(()=>[e.createElementVNode("div",No,[e.createElementVNode("div",Vo,[e.createElementVNode("div",go,[e.createElementVNode("div",bo,[(e.openBlock(),e.createElementBlock(e.Fragment,null,e.renderList(o,g=>e.createElementVNode("div",{key:g.value,class:e.normalizeClass(["el-tabs__item",{"is-active":r.value===g.value}]),onClick:A=>r.value=g.value},e.toDisplayString(g.label),11,To)),64))])])])]),r.value!=="form"?(e.openBlock(),e.createElementBlock("div",{key:0,class:"_fd-preview-copy",onClick:p},[...h[1]||(h[1]=[e.createElementVNode("i",{class:"fc-icon icon-copy"},null,-1)])])):e.createCommentVNode("",!0),r.value==="form"?(e.openBlock(),e.createBlock(Ne,{key:1,"form-config":t.components},null,8,["form-config"])):(e.openBlock(),e.createElementBlock("pre",Co,[e.createElementVNode("code",null,e.toDisplayString(r.value==="component"?c.value:s.value),1)]))]),_:1},8,["model-value"])}}}),ko=[{name:"文本输入框",type:d.INPUT,icon:'<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="3" y="5" width="18" height="14" rx="2"/><line x1="7" y1="12" x2="17" y2="12"/><line x1="7" y1="9" x2="10" y2="9"/></svg>',value:"",required:!0,defaultValue:"",props:{label:"文本输入框",variableName:"",placeholder:"请输入文本"},style:{width:"100%"}},{name:"多行文本",type:d.TEXTAREA,icon:'<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="3" y="4" width="18" height="16" rx="2"/><line x1="7" y1="9" x2="17" y2="9"/><line x1="7" y1="12" x2="17" y2="12"/><line x1="7" y1="15" x2="13" y2="15"/></svg>',value:"",required:!0,defaultValue:"",props:{label:"多行文本",variableName:"",placeholder:"请输入内容",rows:3},style:{width:"100%"}},{name:"数字输入框",type:d.INPUT_NUMBER,icon:'<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="3" y="5" width="18" height="14" rx="2"/><line x1="7" y1="10" x2="7" y2="14"/><line x1="10" y1="10" x2="10" y2="14"/><line x1="13" y1="10" x2="13" y2="14"/></svg>',value:null,required:!0,min:1,max:100,defaultValue:1,props:{label:"数字输入框",variableName:"",placeholder:"请输入数字"},style:{width:"100%"}},{name:"单选框",type:d.RADIO_GROUP,icon:'<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="9"/><circle cx="12" cy="12" r="4" fill="currentColor"/></svg>',value:"",required:!0,defaultValue:"1",props:{label:"单选框",variableName:"",options:[{label:"选项1",value:"1"},{label:"选项2",value:"2"},{label:"选项3",value:"3"}]},style:{width:"100%"}},{name:"下拉选择",type:d.SELECT,icon:'<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="3" y="5" width="18" height="14" rx="2"/><polyline points="8 10 12 14 16 10"/></svg>',value:"",required:!0,defaultValue:"",props:{label:"下拉选择",variableName:"",placeholder:"请选择",options:[{label:"选项1",value:"1"},{label:"选项2",value:"2"},{label:"选项3",value:"3"}]},style:{width:"100%"}},{name:"多选框",type:d.CHECKBOX_GROUP,icon:'<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="3" y="4" width="7" height="7" rx="1"/><polyline points="4.5 7.5 6 9 9 6"/><rect x="3" y="14" width="7" height="7" rx="1"/><rect x="14" y="4" width="7" height="7" rx="1"/><rect x="14" y="14" width="7" height="7" rx="1"/></svg>',value:[],required:!0,defaultValue:[],props:{label:"多选框",variableName:"",options:[{label:"选项1",value:"1"},{label:"选项2",value:"2"},{label:"选项3",value:"3"}]},style:{width:"100%"}},{name:"开关",type:d.SWITCH,icon:'<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="2" y="7" width="20" height="10" rx="5"/><circle cx="16" cy="12" r="3" fill="currentColor"/></svg>',value:!1,required:!1,defaultValue:!1,props:{label:"开关",variableName:"",activeText:"是",inactiveText:"否"},style:{width:"100%"}},{name:"日期选择器",type:d.DATE_PICKER,icon:'<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="3" y="4" width="18" height="18" rx="2"/><line x1="3" y1="10" x2="21" y2="10"/><line x1="8" y1="2" x2="8" y2="6"/><line x1="16" y1="2" x2="16" y2="6"/><circle cx="12" cy="15" r="1.5" fill="currentColor"/></svg>',value:null,required:!0,defaultValue:null,props:{label:"日期选择器",variableName:"",placeholder:"请选择日期"},style:{width:"100%"}}],Oo=[{name:"分栏",type:d.ROW,icon:'<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="2" y="4" width="9" height="16" rx="1"/><rect x="13" y="4" width="9" height="16" rx="1"/></svg>',value:null,required:!1,props:{gutter:20,columns:[{span:12},{span:12}]},style:{width:"100%"},children:[]}],Ve=[{name:"基础组件",key:"basic",templates:ko},{name:"布局组件",key:"layout",templates:Oo}],Ue="1.0.0",$e="gbflow-form";function ne(t){return!!t&&typeof t=="object"&&!Array.isArray(t)}function Ao(t){if(t!==void 0)return JSON.parse(JSON.stringify(t))}function _o(t){if(typeof t!="string")return t;const l=t.replace(/^\uFEFF/,"").trim();if(!l)throw new Error("导入内容为空");try{return JSON.parse(l)}catch(o){throw new Error(`JSON 解析失败:${o.message}`)}}function se(t){const l=Array.isArray(t)?t:t?.components,o=Array.isArray(t)?{}:t?.options||{};if(!Array.isArray(l))return{components:[],options:{...o},repairs:[]};const r=[],c=s=>s.filter(p=>ne(p)?!0:(r.push(`已忽略无效的表单组件配置:${JSON.stringify(p)}`),!1)).map(p=>{const i=Ao(p);if(i.id||(i.id=X()),i.type||(i.type=d.INPUT,r.push("表单组件缺少 type,已按文本输入框处理")),ne(i.props)||(i.props={}),i.props.label===void 0&&(i.props.label=i.type),i.props.variableName===void 0&&(i.props.variableName=""),i.props.options!==void 0&&(i.props.options=_e(i.props.options)),i.type===d.ROW){const h=Array.isArray(i.children)?i.children:[];i.children=h.map(y=>c(Array.isArray(y)?y:[])),i.children.length||(i.children=[[],[]]),i.props.columns||(i.props.columns=i.children.map(()=>({span:24/i.children.length})))}return i});return{components:c(l),options:{name:o.name||"",description:o.description||"",labelWidth:o.labelWidth||"120px",size:o.size||"default",...o},repairs:r}}function ce(t){const l=Array.isArray(t)?t:t?.components||[],o=[],r=[],c=new Set,s=p=>{p.forEach(i=>{if(!i||typeof i!="object")return;if(i.type===d.ROW){i.children?.forEach(s);return}const h=i.props?.variableName;h?(c.has(h)&&o.push({code:"DUPLICATE_VARIABLE",message:`表单变量名重复:${h}`,componentId:i.id}),c.add(h)):r.push({code:"MISSING_VARIABLE",message:`表单项「${i.props?.label||i.type}」尚未设置变量名`,componentId:i.id}),i.props?.label||r.push({code:"MISSING_LABEL",message:`表单项「${i.id}」尚未设置标签`,componentId:i.id}),["select","radio-group","checkbox-group"].includes(i.type)&&(!Array.isArray(i.props?.options)||i.props.options.length===0)&&r.push({code:"MISSING_OPTIONS",message:`选项组件「${i.props?.label||i.type}」还没有选项`,componentId:i.id})})};return s(l),{valid:o.length===0,errors:o,warnings:r}}function Ro(t){return Object.keys(t||{}).reduce((l,o)=>(t[o]!==void 0&&t[o]!==null&&(l[o]=t[o]),l),{})}function ge(t,l={},o={}){const r=se(t),c={schemaVersion:Ue,kind:$e,meta:Ro(l),form:{components:r.components,options:r.options}};return o.raw?c:JSON.stringify(c,null,o.space??2)}function be(t){const l=_o(t);if(Array.isArray(l)){const s=se(l);return{components:s.components,options:s.options,repairs:s.repairs,validation:ce({components:s.components})}}if(!ne(l))throw new Error("无法识别的表单导入内容");const o=l.form||l.formStructure||l.formConfig||l.rule||(l.components?l:null);if(!o)throw new Error("导入内容中未找到表单(components)");const r=se(o),c={...r.options,...ne(l.options)?l.options:{}};return{components:r.components,options:c,repairs:r.repairs,meta:ne(l.meta)?l.meta:void 0,validation:ce({components:r.components})}}function Bo(t,l="flow"){return String(t||l).trim().replace(/[\\/:*?"<>|]/g,"-").replace(/\s+/g,"-")||l}function Pe(t,l,o="application/json;charset=utf-8"){if(typeof document>"u")throw new Error("downloadText 只能在浏览器环境使用");const r=new Blob([t],{type:o}),c=URL.createObjectURL(r),s=document.createElement("a");s.href=c,s.download=l,s.style.display="none",document.body.appendChild(s),s.click(),document.body.removeChild(s),setTimeout(()=>URL.revokeObjectURL(c),1e3)}function Fe(t,l="flow.json",o=2){const r=typeof t=="string"?t:JSON.stringify(t,null,o),c=l.endsWith(".json")?l:`${l}.json`;Pe(r,c)}function Me(t){return t?typeof t.text=="function"?t.text():new Promise((l,o)=>{const r=new FileReader;r.onload=()=>l(String(r.result||"")),r.onerror=()=>o(r.error||new Error("读取文件失败")),r.readAsText(t,"utf-8")}):Promise.reject(new Error("未选择文件"))}function Le(){return new Promise(t=>{if(typeof document>"u"){xo();return}const l=document.createElement("input");l.type="file",l.accept=".json,.gbflow,application/json",l.style.display="none",document.body.appendChild(l);const o=()=>{l.parentNode&&l.parentNode.removeChild(l)};l.addEventListener("change",async()=>{const r=l.files?.[0];if(!r){o(),t(null);return}try{const c=await Me(r);o(),t({file:r,text:c})}catch(c){o(),t({file:r,text:"",error:c})}}),l.addEventListener("cancel",()=>{o(),t(null)}),l.click()})}function xo(){throw new Error("pickJSONFile 只能在浏览器环境使用")}const Do=["onClick"],So={class:"_fc-l-list"},Io=["onDragstart","onClick"],Uo={class:"_fc-l-icon"},$o={class:"_fc-l-name"},Po={class:"_fc-tree-label"},Fo={class:"_fc-m-tools-l"},Mo={class:"devices"},Lo={class:"_fc-m-tools-r"},ze=Object.assign({name:"GbFormDesigner"},{__name:"FormDesigner",props:{modelValue:{type:Array,default:()=>[]},options:{type:Object,default:null},meta:{type:Object,default:()=>({})},fileName:{type:String,default:"form"}},emits:["update:modelValue","update:options","import","export","validate","change"],setup(t,{expose:l,emit:o}){const r=t,c=o,s=m=>JSON.parse(JSON.stringify(m??[])),p=e.reactive({name:"",description:"",labelWidth:"120px",size:"default",...r.options||{}}),i=r.options?e.reactive(r.options):p;e.watch(()=>r.options,m=>{!m||m===i||Object.assign(i,m)},{deep:!0}),e.provide("fcFormOptions",i);const h=e.ref("base"),y=e.ref("menu"),g=e.ref(!1),A=e.ref(!1),T=e.ref("pc"),k=e.ref(!1),O=e.ref(""),b=e.ref(""),w=e.ref(null),R={"--fc-drag-empty":"'拖拽左侧列表中的组件到此处'","--fc-child-empty":"'点击右下角 + 按钮添加一列'"},j=e.reactive({}),W={},F=e.ref(Ve.map(m=>({...m,hidden:!1}))),$={[d.INPUT]:"icon-input",[d.TEXTAREA]:"icon-textarea",[d.INPUT_NUMBER]:"icon-number",[d.RADIO_GROUP]:"icon-radio",[d.CHECKBOX_GROUP]:"icon-checkbox",[d.SELECT]:"icon-select",[d.SWITCH]:"icon-switch",[d.DATE_PICKER]:"icon-date",[d.ROW]:"icon-row"},V=m=>$[m]||"icon-input",n=e.ref([]),M=e.ref(-1);let D=!1,L=null;const H=()=>JSON.stringify({components:r.modelValue,options:{...i}}),v=()=>{const m=H();n.value[M.value]!==m&&(n.value=n.value.slice(0,M.value+1),n.value.push(m),n.value.length>50&&n.value.shift(),M.value=n.value.length-1)},ee=e.computed(()=>M.value>0),q=e.computed(()=>M.value<n.value.length-1),Q=()=>{const{components:m,options:a}=JSON.parse(n.value[M.value]);D=!0,c("update:modelValue",m),Object.assign(i,a),e.nextTick(()=>{D=!1})},ae=()=>{ee.value&&(M.value-=1,Q())},pe=()=>{q.value&&(M.value+=1,Q())};e.watch(()=>[r.modelValue,{...i}],()=>{D||(clearTimeout(L),L=setTimeout(v,300))},{deep:!0}),e.onMounted(()=>{v()});const f=m=>{c("update:modelValue",s(m))},Y=m=>{Object.assign(i,m||{}),c("update:options",{...i})},J=m=>{for(const a of Ve){const C=a.templates.find(B=>B.type===m);if(C)return C}return null},qe=m=>{const a=s(m);return delete a.name,delete a.icon,ye(a),a.props=a.props||{},a.props.variableName||(a.props.variableName=`field_${X().split("_").pop()}`),a.type===d.ROW&&(a.children=[[],[]],a.props.columns=a.props.columns||[{span:12},{span:12}]),a},el=m=>{const a=J(m);return a?qe(a):null},tl=m=>{const a=qe(m),C=[...r.modelValue,a];f(C),O.value=a.id},te=m=>{if(m.length===1)return{list:r.modelValue,index:m[0],node:null};const[a,,C,B]=m,S=r.modelValue[a];return{list:S?.children?.[C]||[],index:B,node:S}},Ce=(m,a)=>{for(const C of m||[]){if(C.id===a)return C;if(C.type===d.ROW)for(const B of C.children||[]){const S=Ce(B,a);if(S)return S}}return null},ol=e.computed(()=>O.value?Ce(r.modelValue,O.value):null),ll=m=>{O.value=m.id},fe=()=>{O.value=""},Je=m=>(m.id=X(),m.type===d.ROW&&(m.children||[]).forEach(a=>a.forEach(Je)),m),Ye=m=>{const a=te(m),C=a.list[m[m.length-1]];if(!C)return;const B=Je(s(C));a.list.splice(a.index+1,0,B),f(r.modelValue),O.value=B.id},Ke=m=>{const a=te(m);a.list.splice(a.index,1),f(r.modelValue),O.value&&(Ce(r.modelValue,O.value)||fe())},K=e.ref(null),nl=()=>K.value?K.value:null,al=(m,a)=>{const C={kind:"new",type:a.type};K.value=C,m.dataTransfer.effectAllowed="copy",m.dataTransfer.setData("application/x-gb-field",JSON.stringify(C)),m.dataTransfer.setData("text/plain",a.type)},rl=m=>{K.value={kind:"existing",path:[...m]}},Qe=()=>{K.value=null,b.value=""},il=m=>{const a=m.dataTransfer?.getData("application/x-gb-field");let C=K.value;if(a)try{C=JSON.parse(a)}catch{C=K.value}b.value="",K.value=null,C&&Xe(C,{path:null,position:"bottom"})},Xe=(m,a)=>{if(!m)return;let C=r.modelValue,B=r.modelValue.length;if(a.column!==void 0&&a.path){const x=te(a.path).list[a.path[a.path.length-1]];if(!x?.children?.[a.column])return;if(m.kind==="existing"&&te(m.path).list[m.path[m.path.length-1]]?.type===d.ROW){G.ElMessage.warning("分栏组件不能放入分栏内");return}C=x.children[a.column],B=C.length}else if(a.path){if(m.kind==="existing"&&m.path.length<=a.path.length&&m.path.every((re,we)=>re===a.path[we]))return;const x=te(a.path);C=x.list,B=a.position==="top"?x.index:x.index+1}let S;if(m.kind==="new"){if(S=el(m.type),!S)return}else{const x=te(m.path);if(S=x.list[x.index],!S)return;x.list===C&&x.index<B&&(B-=1),x.list.splice(x.index,1)}C.splice(B,0,S),f(r.modelValue),O.value=S.id};e.provide("fcDragOver",b),e.provide("fcCanvasOps",{active:ll,copy:Ye,remove:Ke,startDrag:rl,endDrag:Qe,getDragPayload:nl,dropAt:Xe});const Ze=(m,a=[])=>(m||[]).map((C,B)=>{const S=[...a,B],x={id:C.id,label:C.props?.label||C.props?.variableName||C.type,icon:V(C.type),rule:C,path:S};return C.type===d.ROW&&(x.children=(C.children||[]).flatMap((oe,re)=>Ze(oe||[],[...a,B,"children",re]))),x}),sl=e.computed(()=>Ze(r.modelValue)),cl=m=>{m.rule&&(O.value=m.rule.id)},dl=(m,a)=>{a.path&&(m==="copy"?Ye(a.path):m==="delete"&&Ke(a.path))},ml=async()=>{const m=await Le();if(m)try{const a=be(m.text);c("update:modelValue",a.components),Object.assign(i,a.options||{}),c("import",{components:a.components,options:{...i}}),G.ElMessage.success("表单导入成功")}catch(a){G.ElMessage.error(`导入失败:${a.message}`)}},ve=()=>{c("update:modelValue",[]),fe(),G.ElMessage.success("表单已清空")},pl=()=>{const m=ce({components:r.modelValue});return c("validate",m),m},et=()=>s(r.modelValue);return l({getComponents:et,getForm:()=>({components:et(),options:{...i}}),importJSON:m=>{const a=be(m);return c("update:modelValue",a.components),Object.assign(i,a.options||{}),c("import",{components:a.components,options:{...i}}),a},exportJSON:(m=2)=>{const a=ge(r.modelValue,{...r.meta,name:r.meta?.name||r.fileName},{raw:!0});return a.form.options={...i},c("export",a),JSON.stringify(a,null,m)},downloadForm:()=>{const m=ge(r.modelValue,{...r.meta,name:r.meta?.name||r.fileName},{raw:!0});m.form.options={...i},Fe(m,`${r.meta?.name||r.fileName}-form.json`),c("export",m),G.ElMessage.success("表单 JSON 已导出")},validate:pl,clearForm:ve,undo:ae,redo:pe,components:e.computed(()=>r.modelValue),formOptions:i}),(m,a)=>{const C=e.resolveComponent("el-tooltip"),B=e.resolveComponent("el-aside"),S=e.resolveComponent("el-header"),x=e.resolveComponent("el-main"),oe=e.resolveComponent("el-dropdown-item"),re=e.resolveComponent("el-dropdown-menu"),we=e.resolveComponent("el-dropdown"),fl=e.resolveComponent("el-tree"),ue=e.resolveComponent("el-container"),ke=e.resolveComponent("el-button"),ul=e.resolveComponent("el-popconfirm"),hl=e.resolveComponent("el-form");return e.openBlock(),e.createBlock(ue,{class:"_fc-designer gb-fc-designer",style:{height:"100%"}},{default:e.withCtx(()=>[e.createVNode(x,null,{default:e.withCtx(()=>[e.createVNode(ue,{style:{height:"100%"}},{default:e.withCtx(()=>[e.createVNode(B,{class:"_fc-l-menu",width:"40px"},{default:e.withCtx(()=>[e.createVNode(C,{effect:"dark",content:"组件列表",placement:"right","hide-after":0},{default:e.withCtx(()=>[e.createElementVNode("div",{class:e.normalizeClass(["_fc-l-menu-item",{active:h.value==="base"}]),onClick:a[0]||(a[0]=_=>h.value="base")},[...a[15]||(a[15]=[e.createElementVNode("i",{class:"fc-icon icon-menu"},null,-1)])],2)]),_:1}),e.createVNode(C,{effect:"dark",content:"JSON",placement:"right","hide-after":0},{default:e.withCtx(()=>[e.createElementVNode("div",{class:e.normalizeClass(["_fc-l-menu-item",{active:h.value==="json"}]),onClick:a[1]||(a[1]=_=>h.value="json")},[...a[16]||(a[16]=[e.createElementVNode("i",{class:"fc-icon icon-script"},null,-1)])],2)]),_:1})]),_:1}),e.withDirectives(e.createVNode(B,{class:"_fc-l",width:"266px"},{default:e.withCtx(()=>[e.createElementVNode("div",{class:"_fc-l-close",onClick:a[2]||(a[2]=_=>g.value=!0)},[...a[17]||(a[17]=[e.createElementVNode("i",{class:"fc-icon icon-arrow"},null,-1)])]),h.value==="json"?(e.openBlock(),e.createBlock(io,{key:0,ref_key:"jsonPanelRef",ref:w,components:t.modelValue,"form-options":e.unref(i),"onUpdate:components":f,"onUpdate:formOptions":Y},null,8,["components","form-options"])):(e.openBlock(),e.createBlock(ue,{key:1,style:{height:"100%"}},{default:e.withCtx(()=>[e.createVNode(S,{height:"40px",class:"_fc-l-tabs"},{default:e.withCtx(()=>[e.createElementVNode("div",{class:e.normalizeClass(["_fc-l-tab",{active:y.value==="menu"}]),onClick:a[3]||(a[3]=_=>y.value="menu")}," 组件 ",2),e.createElementVNode("div",{class:e.normalizeClass(["_fc-l-tab",{active:y.value==="tree"}]),onClick:a[4]||(a[4]=_=>y.value="tree")}," 大纲 ",2)]),_:1}),e.withDirectives(e.createVNode(x,null,{default:e.withCtx(()=>[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(F.value,_=>(e.openBlock(),e.createElementBlock("div",{key:_.key,class:"_fc-l-group"},[e.createElementVNode("h4",{class:"_fc-l-title",onClick:z=>_.hidden=!_.hidden},[e.createTextVNode(e.toDisplayString(_.name)+" ",1),e.createElementVNode("i",{class:e.normalizeClass(["fc-icon icon-arrow",{down:!_.hidden}])},null,2)],8,Do),e.withDirectives(e.createElementVNode("div",So,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(_.templates,z=>(e.openBlock(),e.createElementBlock("div",{key:z.type,class:"_fc-l-item",draggable:"true",onDragstart:tt=>al(tt,z),onDragend:Qe,onClick:tt=>tl(z)},[e.createElementVNode("div",Uo,[e.createElementVNode("i",{class:e.normalizeClass(["fc-icon",V(z.type)])},null,2)]),e.createElementVNode("span",$o,e.toDisplayString(z.name),1)],40,Io))),128))],512),[[e.vShow,!_.hidden]])]))),128))]),_:1},512),[[e.vShow,y.value==="menu"]]),e.withDirectives(e.createVNode(x,null,{default:e.withCtx(()=>[e.createVNode(fl,{data:sl.value,"node-key":"id","expand-on-click-node":!1,"default-expand-all":"",onNodeClick:cl},{default:e.withCtx(({data:_})=>[e.createElementVNode("div",{class:e.normalizeClass(["_fc-tree-node",{active:O.value===_.rule?.id}])},[e.createElementVNode("div",Po,[e.createElementVNode("i",{class:e.normalizeClass(["fc-icon",_.icon||"icon-cell"])},null,2),e.createElementVNode("span",null,e.toDisplayString(_.label),1)]),e.createElementVNode("div",{class:"_fc-tree-more",onClick:a[5]||(a[5]=e.withModifiers(()=>{},["stop"]))},[e.createVNode(we,{trigger:"click",size:"default",onCommand:z=>dl(z,_)},{dropdown:e.withCtx(()=>[e.createVNode(re,null,{default:e.withCtx(()=>[e.createVNode(oe,{command:"copy"},{default:e.withCtx(()=>[...a[18]||(a[18]=[e.createTextVNode("复制",-1)])]),_:1}),e.createVNode(oe,{command:"delete"},{default:e.withCtx(()=>[...a[19]||(a[19]=[e.createTextVNode("删除",-1)])]),_:1})]),_:1})]),default:e.withCtx(()=>[a[20]||(a[20]=e.createElementVNode("i",{class:"fc-icon icon-more"},null,-1))]),_:1},8,["onCommand"])])],2)]),_:1},8,["data"])]),_:1},512),[[e.vShow,y.value==="tree"]])]),_:1}))]),_:1},512),[[e.vShow,!g.value]]),e.createVNode(ue,{class:"_fc-m"},{default:e.withCtx(()=>[e.createVNode(S,{class:"_fc-m-tools",height:"45"},{default:e.withCtx(()=>[e.createElementVNode("div",Fo,[e.createElementVNode("div",Mo,[e.createElementVNode("i",{class:e.normalizeClass(["fc-icon icon-pc",{active:T.value==="pc"}]),onClick:a[6]||(a[6]=_=>T.value="pc")},null,2),e.createElementVNode("i",{class:e.normalizeClass(["fc-icon icon-pad",{active:T.value==="pad"}]),onClick:a[7]||(a[7]=_=>T.value="pad")},null,2),e.createElementVNode("i",{class:e.normalizeClass(["fc-icon icon-mobile",{active:T.value==="mobile"}]),onClick:a[8]||(a[8]=_=>T.value="mobile")},null,2)]),a[21]||(a[21]=e.createElementVNode("div",{class:"line"},null,-1)),e.createElementVNode("div",null,[e.createElementVNode("i",{class:e.normalizeClass(["fc-icon icon-pre-step",{disabled:!ee.value}]),onClick:ae},null,2),e.createElementVNode("i",{class:e.normalizeClass(["fc-icon icon-next-step",{disabled:!q.value}]),onClick:pe},null,2)])]),e.createElementVNode("div",Lo,[e.createVNode(ke,{icon:e.unref(le.Upload),plain:"",size:"small",onClick:ml},{default:e.withCtx(()=>[...a[22]||(a[22]=[e.createTextVNode("导入",-1)])]),_:1},8,["icon"]),e.createVNode(ke,{type:"primary",plain:"",size:"small",onClick:a[9]||(a[9]=_=>k.value=!0)},{default:e.withCtx(()=>[...a[23]||(a[23]=[e.createElementVNode("i",{class:"fc-icon icon-preview"},null,-1),e.createTextVNode(" 预览 ",-1)])]),_:1}),e.createVNode(ul,{title:"确定清空所有组件?",width:"200px","confirm-button-text":"清空","cancel-button-text":"取消",onConfirm:ve},{reference:e.withCtx(()=>[e.createVNode(ke,{type:"danger",plain:"",size:"small"},{default:e.withCtx(()=>[...a[24]||(a[24]=[e.createElementVNode("i",{class:"fc-icon icon-delete"},null,-1),e.createTextVNode(" 清空",-1)])]),_:1})]),_:1})])]),_:1}),e.createVNode(x,{class:"_fc-m-con"},{default:e.withCtx(()=>[a[25]||(a[25]=e.createElementVNode("a",{class:"gb-fc-watermark",href:"javascript:void(0)"},"GbFlowDesign",-1)),e.createElementVNode("div",{ref:"dragCon",class:e.normalizeClass(["_fc-m-drag",T.value]),style:R,onDragover:a[10]||(a[10]=e.withModifiers(()=>{},["prevent"])),onDrop:e.withModifiers(il,["prevent"])},[t.modelValue.length?(e.openBlock(),e.createBlock(hl,{key:0,model:j,"label-width":e.unref(i).labelWidth||"120px",size:e.unref(i).size==="default"?void 0:e.unref(i).size},{default:e.withCtx(()=>[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(t.modelValue,(_,z)=>(e.openBlock(),e.createBlock(Se,{key:_.id||z,component:_,path:[z],"form-data":j,"form-rules":W,"active-id":O.value},null,8,["component","path","form-data","active-id"]))),128))]),_:1},8,["model","label-width","size"])):(e.openBlock(),e.createElementBlock("div",{key:1,class:"_fd-draggable-drag _fd-drag-box drag-holder",onClick:fe}))],34)]),_:1})]),_:1}),e.withDirectives(e.createVNode(B,{class:"_fc-r",width:"320px"},{default:e.withCtx(()=>[e.createElementVNode("div",{class:"_fc-r-close",onClick:a[11]||(a[11]=_=>A.value=!0)},[...a[26]||(a[26]=[e.createElementVNode("i",{class:"fc-icon icon-arrow"},null,-1)])]),e.createVNode(no,{component:ol.value,"form-options":e.unref(i),onClose:fe},null,8,["component","form-options"])]),_:1},512),[[e.vShow,!A.value]]),g.value?(e.openBlock(),e.createElementBlock("div",{key:0,class:"_fc-l-open",onClick:a[12]||(a[12]=_=>g.value=!1)},[...a[27]||(a[27]=[e.createElementVNode("i",{class:"fc-icon icon-arrow"},null,-1)])])):e.createCommentVNode("",!0),A.value?(e.openBlock(),e.createElementBlock("div",{key:1,class:"_fc-r-open",onClick:a[13]||(a[13]=_=>A.value=!1)},[...a[28]||(a[28]=[e.createElementVNode("i",{class:"fc-icon icon-arrow"},null,-1)])])):e.createCommentVNode("",!0),e.createVNode(wo,{modelValue:k.value,"onUpdate:modelValue":a[14]||(a[14]=_=>k.value=_),components:t.modelValue,"form-options":e.unref(i)},null,8,["modelValue","components","form-options"])]),_:1})]),_:1})]),_:1})}}}),u=Object.freeze({STRING:"string",INTEGER:"integer",DECIMAL:"decimal",DATE:"date",DATETIME:"datetime",ARRAY:"array",BOOLEAN:"boolean"}),I=Object.freeze({INPUT:"input",TEXTAREA:"textarea",INPUT_NUMBER:"input-number",RADIO_GROUP:"radio-group",CHECKBOX_GROUP:"checkbox-group",SELECT:"select",SWITCH:"switch",DATE_PICKER:"date-picker",ROW:"row"}),zo=Object.freeze({[I.INPUT]:u.STRING,[I.TEXTAREA]:u.STRING,[I.INPUT_NUMBER]:null,[I.RADIO_GROUP]:u.STRING,[I.SELECT]:u.STRING,[I.CHECKBOX_GROUP]:u.ARRAY,[I.SWITCH]:u.BOOLEAN,[I.DATE_PICKER]:u.DATE,[I.ROW]:null}),N=Object.freeze({EQUAL:"==",NOT_EQUAL:"!=",GREATER_THAN:">",LESS_THAN:"<",GREATER_THAN_OR_EQUAL:">=",LESS_THAN_OR_EQUAL:"<=",CONTAINS:"contains",NOT_CONTAINS:"not_contains",IS_EMPTY:"is_empty",IS_NOT_EMPTY:"is_not_empty"}),Ge=Object.freeze({[N.EQUAL]:"等于",[N.NOT_EQUAL]:"不等于",[N.GREATER_THAN]:"大于",[N.LESS_THAN]:"小于",[N.GREATER_THAN_OR_EQUAL]:"大于等于",[N.LESS_THAN_OR_EQUAL]:"小于等于",[N.CONTAINS]:"包含",[N.NOT_CONTAINS]:"不包含",[N.IS_EMPTY]:"为空",[N.IS_NOT_EMPTY]:"不为空"}),Te=Object.freeze({[u.STRING]:[N.EQUAL,N.NOT_EQUAL,N.CONTAINS,N.NOT_CONTAINS,N.IS_EMPTY,N.IS_NOT_EMPTY],[u.INTEGER]:[N.EQUAL,N.NOT_EQUAL,N.GREATER_THAN,N.LESS_THAN,N.GREATER_THAN_OR_EQUAL,N.LESS_THAN_OR_EQUAL,N.IS_EMPTY,N.IS_NOT_EMPTY],[u.DECIMAL]:[N.EQUAL,N.NOT_EQUAL,N.GREATER_THAN,N.LESS_THAN,N.GREATER_THAN_OR_EQUAL,N.LESS_THAN_OR_EQUAL,N.IS_EMPTY,N.IS_NOT_EMPTY],[u.DATE]:[N.EQUAL,N.NOT_EQUAL,N.GREATER_THAN,N.LESS_THAN,N.GREATER_THAN_OR_EQUAL,N.LESS_THAN_OR_EQUAL,N.IS_EMPTY,N.IS_NOT_EMPTY],[u.DATETIME]:[N.EQUAL,N.NOT_EQUAL,N.GREATER_THAN,N.LESS_THAN,N.GREATER_THAN_OR_EQUAL,N.LESS_THAN_OR_EQUAL,N.IS_EMPTY,N.IS_NOT_EMPTY],[u.ARRAY]:[N.CONTAINS,N.NOT_CONTAINS,N.IS_EMPTY,N.IS_NOT_EMPTY],[u.BOOLEAN]:[N.EQUAL,N.NOT_EQUAL]});function je(t){if(!t||!t.type)return console.warn("组件配置无效,无法计算数据类型",t),u.STRING;const l=t.type;if(t.props,l.startsWith("internal-")||l.startsWith("text/")||l.startsWith("application/"))return console.warn(`检测到非组件类型: ${l},默认使用STRING类型`,t),u.STRING;if(l===I.INPUT_NUMBER)return u.INTEGER;if(l===I.DATE_PICKER)return u.DATE;const o=zo[l];return o||(console.warn(`未知的组件类型: ${l},默认使用STRING类型`),u.STRING)}function Go(t){const l=Te[t];return l?l.map(o=>({label:Ge[o],value:o})):(console.warn(`未知的数据类型: ${t},返回默认操作符`),Te[u.STRING])}function jo(t){return t!==N.IS_EMPTY&&t!==N.IS_NOT_EMPTY}function de(t){switch(t){case u.INTEGER:case u.DECIMAL:return null;case u.ARRAY:return[];case u.BOOLEAN:return!1;case u.DATE:case u.DATETIME:case u.STRING:default:return""}}function He(t,l){if(t==null||t==="")return!0;switch(l){case u.INTEGER:return Number.isInteger(Number(t))&&isFinite(Number(t));case u.DECIMAL:return typeof t=="number"||!isNaN(Number(t))&&isFinite(Number(t));case u.ARRAY:return Array.isArray(t);case u.BOOLEAN:return typeof t=="boolean";case u.DATE:case u.DATETIME:return typeof t=="string"&&/^\d{4}-\d{2}-\d{2}/.test(t);case u.STRING:return typeof t=="string"||typeof t=="number";default:return!0}}function Ho(t){return{[u.STRING]:"字符串",[u.INTEGER]:"整数",[u.DECIMAL]:"小数",[u.DATE]:"日期",[u.DATETIME]:"日期时间",[u.ARRAY]:"数组",[u.BOOLEAN]:"布尔值"}[t]||t}function Wo(t){return t===u.INTEGER||t===u.DECIMAL}function qo(t){return t===u.DATE||t===u.DATETIME}class Z{constructor(l){if(!l)throw new Error("FormVariable: component参数不能为空");const o=l.props?.variableName;if(!o)throw new Error("FormVariable: 组件必须有props.variableName属性");this.id=l.id,this.variableName=o,this.label=l.props?.label||o,this.componentType=l.type,this.dataType=je(l),this.metadata=this._extractMetadata(l),this.defaultValue=this._normalizeDefaultValue(l),this.component=l}_extractMetadata(l){const o=l.props||{},r={placeholder:o.placeholder||"",required:l.required!==!1};switch(l.type){case I.RADIO_GROUP:r.options=Array.isArray(o.options)?o.options:[];break;case I.INPUT_NUMBER:r.min=l.min!=null?Number(l.min):void 0,r.max=l.max!=null?Number(l.max):void 0;break;case I.DATE_PICKER:r.dateFormat="date";break}return r}_normalizeDefaultValue(l){const o=l.props?.defaultValue;return o==null||o===""?de(this.dataType):He(o,this.dataType)?this._convertValue(o,this.dataType):(console.warn(`FormVariable: 默认值 "${o}" 不符合类型 "${this.dataType}",使用类型默认值`,l),de(this.dataType))}_convertValue(l,o){if(l==null||l==="")return de(o);switch(o){case u.INTEGER:return parseInt(l,10);case u.DECIMAL:return parseFloat(l);case u.ARRAY:return Array.isArray(l)?l:[];case u.BOOLEAN:return!!l;case u.STRING:case u.DATE:case u.DATETIME:default:return String(l)}}getConditionInfo(){return{variableName:this.variableName,label:this.label,dataType:this.dataType,componentType:this.componentType,options:this.metadata.options||null,dateFormat:this.metadata.dateFormat||null,isInteger:this.dataType===u.INTEGER}}hasOptions(){return Array.isArray(this.metadata.options)&&this.metadata.options.length>0}getOptions(){return this.metadata.options||[]}isNumeric(){return this.dataType===u.INTEGER||this.dataType===u.DECIMAL}isDate(){return this.dataType===u.DATE||this.dataType===u.DATETIME}isInteger(){return this.dataType===u.INTEGER}getDateFormat(){return this.metadata.dateFormat||null}toJSON(){return{id:this.id,variableName:this.variableName,label:this.label,componentType:this.componentType,dataType:this.dataType,metadata:this.metadata,defaultValue:this.defaultValue}}static fromJSON(l){const o={id:l.id,type:l.componentType,field:l.variableName,name:l.label,props:{...l.metadata}};return new Z(o)}static fromComponents(l){return Array.isArray(l)?l.filter(o=>!(!o||!o.props?.variableName||o.type===I.ROW)).map(o=>{try{return new Z(o)}catch(r){return console.error("FormVariable.fromComponents: 创建FormVariable失败",r,o),null}}).filter(o=>o!==null):(console.warn("FormVariable.fromComponents: components必须是数组"),[])}static isValid(l){return l?typeof l.variableName=="string"&&typeof l.label=="string"&&typeof l.componentType=="string"&&typeof l.dataType=="string"&&typeof l.metadata=="object":!1}}function Jo(t){return t?.components?t.components.filter(l=>l?.type==="row"||l?.props?.variableName&&l?.props?.label):[]}function me(t){return Array.isArray(t)?t.reduce((l,o)=>(o&&(o.type==="row"&&o.children?o.children.forEach(r=>{Array.isArray(r)&&l.push(...me(r))}):o.props?.variableName&&l.push(o)),l),[]):[]}function Yo(t){if(!Array.isArray(t))return[];if(t.length>0&&t[0]instanceof Z)return t;const l=me(t);return Z.fromComponents(l)}function Ko(t,l){return Array.isArray(t)&&t.find(o=>o.variableName===l)||null}function Qo(t){const l=[];return t?(t.type||l.push("组件类型不能为空"),t.props?(t.props.variableName||l.push("变量名不能为空"),t.props.label||l.push("标签不能为空"),["select","radio","checkbox"].includes(t.type)&&(Array.isArray(t.props.options)&&t.props.options.length>0||l.push(`${t.type}类型必须配置选项列表`))):l.push("组件属性不能为空"),{valid:l.length===0,errors:l}):(l.push("组件配置不能为空"),{valid:!1,errors:l})}function Xo(t){return me(t).length}const Zo=[ze,Ne],We="0.1.0",vo={version:We,install(t){Zo.forEach(l=>{l.name&&t.component(l.name,l)})}};E.BaseDataType=u,E.COMPONENT_CATEGORIES=Ve,E.COMPONENT_TYPES=d,E.COMPONENT_TYPE_LABELS=Oe,E.ComponentType=I,E.ConditionOperator=N,E.DATA_TYPE_OPERATORS_MAP=Te,E.DEFAULT_CONFIG=lt,E.FORM_KIND=$e,E.FcCanvasField=Se,E.FormDesigner=ze,E.FormVariable=Z,E.FormViewer=Ne,E.OPERATOR_LABEL_MAP=Ge,E.OPTION_COMPONENT_TYPES=he,E.SCHEMA_VERSION=Ue,E.WIDTH_PRESETS=ot,E.computeDataType=je,E.countFormComponents=Xo,E.default=vo,E.downloadJSON=Fe,E.downloadText=Pe,E.enrichFormVariables=Yo,E.ensureComponentId=ye,E.exportForm=ge,E.filterValidComponents=Jo,E.findFormVariable=Ko,E.generateComponentId=X,E.getAllFormComponents=me,E.getDataTypeLabel=Ho,E.getFieldName=P,E.getOperatorsForDataType=Go,E.getTypeDefaultValue=de,E.importForm=be,E.isDateType=qo,E.isEmpty=Ee,E.isNumericType=Wo,E.isValidValueForType=He,E.normalizeForm=se,E.normalizeNumberValue=ie,E.normalizeOptions=_e,E.operatorNeedsValue=jo,E.parseWidth=Re,E.pickJSONFile=Le,E.readTextFile=Me,E.sanitizeFileName=Bo,E.validateComponentConfig=Qo,E.validateForm=ce,E.version=We,Object.defineProperties(E,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
|
|
14
|
+
</form>`}const Ro={class:"_fd-preview-tabs el-tabs"},Bo={class:"el-tabs__header"},So={class:"el-tabs__nav-wrap"},Do={class:"el-tabs__nav"},xo=["onClick"],Io={key:2,class:"_fd-preview-code"},$o=Object.assign({name:"FcPreviewDialog"},{__name:"FcPreviewDialog",props:{modelValue:{type:Boolean,default:!1},components:{type:Array,default:()=>[]},formOptions:{type:Object,default:()=>({})}},emits:["update:modelValue"],setup(t){const n=t,o=[{label:"表单模式",value:"form"},{label:"组件模式",value:"component"},{label:"HTML 模式",value:"html"}],l=e.ref("form"),c=e.computed(()=>Ao(n.components,n.formOptions)),s=e.computed(()=>_o(n.components,n.formOptions)),p=async()=>{const i=l.value==="component"?c.value:s.value;try{await navigator.clipboard.writeText(i),j.ElMessage.success("代码已复制")}catch{j.ElMessage.warning("复制失败,请手动复制")}};return(i,h)=>{const N=e.resolveComponent("el-dialog");return e.openBlock(),e.createBlock(N,{"model-value":t.modelValue,width:"80%",class:"_fd-preview-dialog","append-to-body":"","onUpdate:modelValue":h[0]||(h[0]=b=>i.$emit("update:modelValue",b))},{default:e.withCtx(()=>[e.createElementVNode("div",Ro,[e.createElementVNode("div",Bo,[e.createElementVNode("div",So,[e.createElementVNode("div",Do,[(e.openBlock(),e.createElementBlock(e.Fragment,null,e.renderList(o,b=>e.createElementVNode("div",{key:b.value,class:e.normalizeClass(["el-tabs__item",{"is-active":l.value===b.value}]),onClick:A=>l.value=b.value},e.toDisplayString(b.label),11,xo)),64))])])])]),l.value!=="form"?(e.openBlock(),e.createElementBlock("div",{key:0,class:"_fd-preview-copy",onClick:p},[...h[1]||(h[1]=[e.createElementVNode("i",{class:"fc-icon icon-copy"},null,-1)])])):e.createCommentVNode("",!0),l.value==="form"?(e.openBlock(),e.createBlock(Ee,{key:1,"form-config":t.components},null,8,["form-config"])):(e.openBlock(),e.createElementBlock("pre",Io,[e.createElementVNode("code",null,e.toDisplayString(l.value==="component"?c.value:s.value),1)]))]),_:1},8,["model-value"])}}}),Uo=[{name:"文本输入框",type:d.INPUT,value:"",required:!0,defaultValue:"",props:{label:"文本输入框",variableName:"",placeholder:"请输入文本"},style:{width:"100%"}},{name:"多行文本",type:d.TEXTAREA,value:"",required:!0,defaultValue:"",props:{label:"多行文本",variableName:"",placeholder:"请输入内容",rows:3},style:{width:"100%"}},{name:"数字输入框",type:d.INPUT_NUMBER,value:null,required:!0,min:1,max:100,defaultValue:1,props:{label:"数字输入框",variableName:"",placeholder:"请输入数字"},style:{width:"100%"}},{name:"单选框",type:d.RADIO_GROUP,value:"",required:!0,defaultValue:"1",props:{label:"单选框",variableName:"",options:[{label:"选项1",value:"1"},{label:"选项2",value:"2"},{label:"选项3",value:"3"}]},style:{width:"100%"}},{name:"下拉选择",type:d.SELECT,value:"",required:!0,defaultValue:"",props:{label:"下拉选择",variableName:"",placeholder:"请选择",options:[{label:"选项1",value:"1"},{label:"选项2",value:"2"},{label:"选项3",value:"3"}]},style:{width:"100%"}},{name:"多选框",type:d.CHECKBOX_GROUP,value:[],required:!0,defaultValue:[],props:{label:"多选框",variableName:"",options:[{label:"选项1",value:"1"},{label:"选项2",value:"2"},{label:"选项3",value:"3"}]},style:{width:"100%"}},{name:"开关",type:d.SWITCH,value:!1,required:!1,defaultValue:!1,props:{label:"开关",variableName:"",activeText:"是",inactiveText:"否"},style:{width:"100%"}},{name:"日期选择器",type:d.DATE_PICKER,value:null,required:!0,defaultValue:null,props:{label:"日期选择器",variableName:"",placeholder:"请选择日期"},style:{width:"100%"}}],Mo=[{name:"分栏",type:d.ROW,value:null,required:!1,props:{gutter:20,columns:[{span:12},{span:12}]},style:{width:"100%"},children:[]}],ye=[{name:"基础组件",key:"basic",templates:Uo},{name:"布局组件",key:"layout",templates:Mo}],Ue="1.0.0",Me="gbflow-form";function ne(t){return!!t&&typeof t=="object"&&!Array.isArray(t)}function Po(t){if(t!==void 0)return JSON.parse(JSON.stringify(t))}function Fo(t){if(typeof t!="string")return t;const n=t.replace(/^\uFEFF/,"").trim();if(!n)throw new Error("导入内容为空");try{return JSON.parse(n)}catch(o){throw new Error(`JSON 解析失败:${o.message}`)}}function ie(t){const n=Array.isArray(t)?t:t?.components,o=Array.isArray(t)?{}:t?.options||{};if(!Array.isArray(n))return{components:[],options:{...o},repairs:[]};const l=[],c=s=>s.filter(p=>ne(p)?!0:(l.push(`已忽略无效的表单组件配置:${JSON.stringify(p)}`),!1)).map(p=>{const i=Po(p);if(i.id||(i.id=X()),i.type||(i.type=d.INPUT,l.push("表单组件缺少 type,已按文本输入框处理")),ne(i.props)||(i.props={}),i.props.label===void 0&&(i.props.label=i.type),i.props.variableName===void 0&&(i.props.variableName=""),i.props.options!==void 0&&(i.props.options=Re(i.props.options)),i.type===d.ROW){const h=Array.isArray(i.children)?i.children:[];i.children=h.map(N=>c(Array.isArray(N)?N:[])),i.children.length||(i.children=[[],[]]),i.props.columns||(i.props.columns=i.children.map(()=>({span:24/i.children.length})))}return i});return{components:c(n),options:{name:o.name||"",description:o.description||"",labelWidth:o.labelWidth||"120px",size:o.size||"default",...o},repairs:l}}function se(t){const n=Array.isArray(t)?t:t?.components||[],o=[],l=[],c=new Set,s=p=>{p.forEach(i=>{if(!i||typeof i!="object")return;if(i.type===d.ROW){i.children?.forEach(s);return}const h=i.props?.variableName;h?(c.has(h)&&o.push({code:"DUPLICATE_VARIABLE",message:`表单变量名重复:${h}`,componentId:i.id}),c.add(h)):l.push({code:"MISSING_VARIABLE",message:`表单项「${i.props?.label||i.type}」尚未设置变量名`,componentId:i.id}),i.props?.label||l.push({code:"MISSING_LABEL",message:`表单项「${i.id}」尚未设置标签`,componentId:i.id}),["select","radio-group","checkbox-group"].includes(i.type)&&(!Array.isArray(i.props?.options)||i.props.options.length===0)&&l.push({code:"MISSING_OPTIONS",message:`选项组件「${i.props?.label||i.type}」还没有选项`,componentId:i.id})})};return s(n),{valid:o.length===0,errors:o,warnings:l}}function Lo(t){return Object.keys(t||{}).reduce((n,o)=>(t[o]!==void 0&&t[o]!==null&&(n[o]=t[o]),n),{})}function Ve(t,n={},o={}){const l=ie(t),c={schemaVersion:Ue,kind:Me,meta:Lo(n),form:{components:l.components,options:l.options}};return o.raw?c:JSON.stringify(c,null,o.space??2)}function be(t){const n=Fo(t);if(Array.isArray(n)){const s=ie(n);return{components:s.components,options:s.options,repairs:s.repairs,validation:se({components:s.components})}}if(!ne(n))throw new Error("无法识别的表单导入内容");const o=n.form||n.formStructure||n.formConfig||n.rule||(n.components?n:null);if(!o)throw new Error("导入内容中未找到表单(components)");const l=ie(o),c={...l.options,...ne(n.options)?n.options:{}};return{components:l.components,options:c,repairs:l.repairs,meta:ne(n.meta)?n.meta:void 0,validation:se({components:l.components})}}function zo(t,n="flow"){return String(t||n).trim().replace(/[\\/:*?"<>|]/g,"-").replace(/\s+/g,"-")||n}function Pe(t,n,o="application/json;charset=utf-8"){if(typeof document>"u")throw new Error("downloadText 只能在浏览器环境使用");const l=new Blob([t],{type:o}),c=URL.createObjectURL(l),s=document.createElement("a");s.href=c,s.download=n,s.style.display="none",document.body.appendChild(s),s.click(),document.body.removeChild(s),setTimeout(()=>URL.revokeObjectURL(c),1e3)}function Fe(t,n="flow.json",o=2){const l=typeof t=="string"?t:JSON.stringify(t,null,o),c=n.endsWith(".json")?n:`${n}.json`;Pe(l,c)}function Le(t){return t?typeof t.text=="function"?t.text():new Promise((n,o)=>{const l=new FileReader;l.onload=()=>n(String(l.result||"")),l.onerror=()=>o(l.error||new Error("读取文件失败")),l.readAsText(t,"utf-8")}):Promise.reject(new Error("未选择文件"))}function ze(){return new Promise(t=>{if(typeof document>"u"){jo();return}const n=document.createElement("input");n.type="file",n.accept=".json,.gbflow,application/json",n.style.display="none",document.body.appendChild(n);const o=()=>{n.parentNode&&n.parentNode.removeChild(n)};n.addEventListener("change",async()=>{const l=n.files?.[0];if(!l){o(),t(null);return}try{const c=await Le(l);o(),t({file:l,text:c})}catch(c){o(),t({file:l,text:"",error:c})}}),n.addEventListener("cancel",()=>{o(),t(null)}),n.click()})}function jo(){throw new Error("pickJSONFile 只能在浏览器环境使用")}const Go=["onClick"],Wo={class:"_fc-l-list"},Ho=["onDragstart","onClick"],qo={class:"_fc-l-icon"},Jo={class:"_fc-l-name"},Yo={class:"_fc-tree-label"},Ko={class:"_fc-m-tools-l"},Qo={class:"devices"},Xo={class:"_fc-m-tools-r"},je=Object.assign({name:"GbFormDesigner"},{__name:"FormDesigner",props:{modelValue:{type:Array,default:()=>[]},options:{type:Object,default:null},meta:{type:Object,default:()=>({})},fileName:{type:String,default:"form"}},emits:["update:modelValue","update:options","import","export","validate","change"],setup(t,{expose:n,emit:o}){const l=t,c=o,s=m=>JSON.parse(JSON.stringify(m??[])),p=e.reactive({name:"",description:"",labelWidth:"120px",size:"default",...l.options||{}}),i=l.options?e.reactive(l.options):p;e.watch(()=>l.options,m=>{!m||m===i||Object.assign(i,m)},{deep:!0}),e.provide("fcFormOptions",i);const h=e.ref("base"),N=e.ref("menu"),b=e.ref(!1),A=e.ref(!1),C=e.ref("pc"),w=e.ref(!1),O=e.ref(""),g=e.ref(""),k=e.ref(null),R={"--fc-drag-empty":"'拖拽左侧列表中的组件到此处'","--fc-child-empty":"'点击右下角 + 按钮添加一列'"},G=e.reactive({}),H={},P=e.ref(ye.map(m=>({...m,hidden:!1}))),U={[d.INPUT]:"icon-input",[d.TEXTAREA]:"icon-textarea",[d.INPUT_NUMBER]:"icon-number",[d.RADIO_GROUP]:"icon-radio",[d.CHECKBOX_GROUP]:"icon-checkbox",[d.SELECT]:"icon-select",[d.SWITCH]:"icon-switch",[d.DATE_PICKER]:"icon-date",[d.ROW]:"icon-row"},V=m=>U[m]||"icon-input",a=e.ref([]),F=e.ref(-1);let D=!1,L=null;const W=()=>JSON.stringify({components:l.modelValue,options:{...i}}),v=()=>{const m=W();a.value[F.value]!==m&&(a.value=a.value.slice(0,F.value+1),a.value.push(m),a.value.length>50&&a.value.shift(),F.value=a.value.length-1)},ee=e.computed(()=>F.value>0),q=e.computed(()=>F.value<a.value.length-1),Q=()=>{const{components:m,options:r}=JSON.parse(a.value[F.value]);D=!0,c("update:modelValue",m),Object.assign(i,r),e.nextTick(()=>{D=!1})},le=()=>{ee.value&&(F.value-=1,Q())},me=()=>{q.value&&(F.value+=1,Q())};e.watch(()=>[l.modelValue,{...i}],()=>{D||(clearTimeout(L),L=setTimeout(v,300))},{deep:!0}),e.onMounted(()=>{v()});const f=m=>{c("update:modelValue",s(m))},Y=m=>{Object.assign(i,m||{}),c("update:options",{...i})},J=m=>{for(const r of ye){const T=r.templates.find(B=>B.type===m);if(T)return T}return null},Je=m=>{const r=s(m);return delete r.name,delete r.icon,he(r),r.props=r.props||{},r.props.variableName||(r.props.variableName=`field_${X().split("_").pop()}`),r.type===d.ROW&&(r.children=[[],[]],r.props.columns=r.props.columns||[{span:12},{span:12}]),r},pn=m=>{const r=J(m);return r?Je(r):null},fn=m=>{const r=Je(m),T=[...l.modelValue,r];f(T),O.value=r.id},te=m=>{if(m.length===1)return{list:l.modelValue,index:m[0],node:null};const[r,,T,B]=m,x=l.modelValue[r];return{list:x?.children?.[T]||[],index:B,node:x}},Ce=(m,r)=>{for(const T of m||[]){if(T.id===r)return T;if(T.type===d.ROW)for(const B of T.children||[]){const x=Ce(B,r);if(x)return x}}return null},un=e.computed(()=>O.value?Ce(l.modelValue,O.value):null),hn=m=>{O.value=m.id},pe=()=>{O.value=""},Ye=m=>(m.id=X(),m.type===d.ROW&&(m.children||[]).forEach(r=>r.forEach(Ye)),m),Ke=m=>{const r=te(m),T=r.list[m[m.length-1]];if(!T)return;const B=Ye(s(T));r.list.splice(r.index+1,0,B),f(l.modelValue),O.value=B.id},Qe=m=>{const r=te(m);r.list.splice(r.index,1),f(l.modelValue),O.value&&(Ce(l.modelValue,O.value)||pe())},K=e.ref(null),Nn=()=>K.value?K.value:null,En=(m,r)=>{const T={kind:"new",type:r.type};K.value=T,m.dataTransfer.effectAllowed="copy",m.dataTransfer.setData("application/x-gb-field",JSON.stringify(T)),m.dataTransfer.setData("text/plain",r.type)},yn=m=>{K.value={kind:"existing",path:[...m]}},Xe=()=>{K.value=null,g.value=""},Vn=m=>{const r=m.dataTransfer?.getData("application/x-gb-field");let T=K.value;if(r)try{T=JSON.parse(r)}catch{T=K.value}g.value="",K.value=null,T&&Ze(T,{path:null,position:"bottom"})},Ze=(m,r)=>{if(!m)return;let T=l.modelValue,B=l.modelValue.length;if(r.column!==void 0&&r.path){const S=te(r.path).list[r.path[r.path.length-1]];if(!S?.children?.[r.column])return;if(m.kind==="existing"&&te(m.path).list[m.path[m.path.length-1]]?.type===d.ROW){j.ElMessage.warning("分栏组件不能放入分栏内");return}T=S.children[r.column],B=T.length}else if(r.path){if(m.kind==="existing"&&m.path.length<=r.path.length&&m.path.every((ae,Te)=>ae===r.path[Te]))return;const S=te(r.path);T=S.list,B=r.position==="top"?S.index:S.index+1}let x;if(m.kind==="new"){if(x=pn(m.type),!x)return}else{const S=te(m.path);if(x=S.list[S.index],!x)return;S.list===T&&S.index<B&&(B-=1),S.list.splice(S.index,1)}T.splice(B,0,x),f(l.modelValue),O.value=x.id};e.provide("fcDragOver",g),e.provide("fcCanvasOps",{active:hn,copy:Ke,remove:Qe,startDrag:yn,endDrag:Xe,getDragPayload:Nn,dropAt:Ze});const ve=(m,r=[])=>(m||[]).map((T,B)=>{const x=[...r,B],S={id:T.id,label:T.props?.label||T.props?.variableName||T.type,icon:V(T.type),rule:T,path:x};return T.type===d.ROW&&(S.children=(T.children||[]).flatMap((oe,ae)=>ve(oe||[],[...r,B,"children",ae]))),S}),bn=e.computed(()=>ve(l.modelValue)),gn=m=>{m.rule&&(O.value=m.rule.id)},Cn=(m,r)=>{r.path&&(m==="copy"?Ke(r.path):m==="delete"&&Qe(r.path))},Tn=async()=>{const m=await ze();if(m)try{const r=be(m.text);c("update:modelValue",r.components),Object.assign(i,r.options||{}),c("import",{components:r.components,options:{...i}}),j.ElMessage.success("表单导入成功")}catch(r){j.ElMessage.error(`导入失败:${r.message}`)}},et=()=>{c("update:modelValue",[]),pe(),j.ElMessage.success("表单已清空")},wn=()=>{const m=se({components:l.modelValue});return c("validate",m),m},tt=()=>s(l.modelValue);return n({getComponents:tt,getForm:()=>({components:tt(),options:{...i}}),importJSON:m=>{const r=be(m);return c("update:modelValue",r.components),Object.assign(i,r.options||{}),c("import",{components:r.components,options:{...i}}),r},exportJSON:(m=2)=>{const r=Ve(l.modelValue,{...l.meta,name:l.meta?.name||l.fileName},{raw:!0});return r.form.options={...i},c("export",r),JSON.stringify(r,null,m)},downloadForm:()=>{const m=Ve(l.modelValue,{...l.meta,name:l.meta?.name||l.fileName},{raw:!0});m.form.options={...i},Fe(m,`${l.meta?.name||l.fileName}-form.json`),c("export",m),j.ElMessage.success("表单 JSON 已导出")},validate:wn,clearForm:et,undo:le,redo:me,components:e.computed(()=>l.modelValue),formOptions:i}),(m,r)=>{const T=e.resolveComponent("el-tooltip"),B=e.resolveComponent("el-aside"),x=e.resolveComponent("el-header"),S=e.resolveComponent("el-main"),oe=e.resolveComponent("el-dropdown-item"),ae=e.resolveComponent("el-dropdown-menu"),Te=e.resolveComponent("el-dropdown"),kn=e.resolveComponent("el-tree"),fe=e.resolveComponent("el-container"),we=e.resolveComponent("el-button"),On=e.resolveComponent("el-popconfirm"),An=e.resolveComponent("el-form");return e.openBlock(),e.createBlock(fe,{class:"_fc-designer gb-fc-designer",style:{height:"100%"}},{default:e.withCtx(()=>[e.createVNode(S,null,{default:e.withCtx(()=>[e.createVNode(fe,{style:{height:"100%"}},{default:e.withCtx(()=>[e.createVNode(B,{class:"_fc-l-menu",width:"40px"},{default:e.withCtx(()=>[e.createVNode(T,{effect:"dark",content:"组件列表",placement:"right","hide-after":0},{default:e.withCtx(()=>[e.createElementVNode("div",{class:e.normalizeClass(["_fc-l-menu-item",{active:h.value==="base"}]),onClick:r[0]||(r[0]=_=>h.value="base")},[...r[15]||(r[15]=[e.createElementVNode("i",{class:"fc-icon icon-menu"},null,-1)])],2)]),_:1}),e.createVNode(T,{effect:"dark",content:"JSON",placement:"right","hide-after":0},{default:e.withCtx(()=>[e.createElementVNode("div",{class:e.normalizeClass(["_fc-l-menu-item",{active:h.value==="json"}]),onClick:r[1]||(r[1]=_=>h.value="json")},[...r[16]||(r[16]=[e.createElementVNode("i",{class:"fc-icon icon-script"},null,-1)])],2)]),_:1})]),_:1}),e.withDirectives(e.createVNode(B,{class:"_fc-l",width:"266px"},{default:e.withCtx(()=>[e.createElementVNode("div",{class:"_fc-l-close",onClick:r[2]||(r[2]=_=>b.value=!0)},[...r[17]||(r[17]=[e.createElementVNode("i",{class:"fc-icon icon-arrow"},null,-1)])]),h.value==="json"?(e.openBlock(),e.createBlock(Vo,{key:0,ref_key:"jsonPanelRef",ref:k,components:t.modelValue,"form-options":e.unref(i),"onUpdate:components":f,"onUpdate:formOptions":Y},null,8,["components","form-options"])):(e.openBlock(),e.createBlock(fe,{key:1,style:{height:"100%"}},{default:e.withCtx(()=>[e.createVNode(x,{height:"40px",class:"_fc-l-tabs"},{default:e.withCtx(()=>[e.createElementVNode("div",{class:e.normalizeClass(["_fc-l-tab",{active:N.value==="menu"}]),onClick:r[3]||(r[3]=_=>N.value="menu")}," 组件 ",2),e.createElementVNode("div",{class:e.normalizeClass(["_fc-l-tab",{active:N.value==="tree"}]),onClick:r[4]||(r[4]=_=>N.value="tree")}," 大纲 ",2)]),_:1}),e.withDirectives(e.createVNode(S,null,{default:e.withCtx(()=>[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(P.value,_=>(e.openBlock(),e.createElementBlock("div",{key:_.key,class:"_fc-l-group"},[e.createElementVNode("h4",{class:"_fc-l-title",onClick:z=>_.hidden=!_.hidden},[e.createTextVNode(e.toDisplayString(_.name)+" ",1),e.createElementVNode("i",{class:e.normalizeClass(["fc-icon icon-arrow",{down:!_.hidden}])},null,2)],8,Go),e.withDirectives(e.createElementVNode("div",Wo,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(_.templates,z=>(e.openBlock(),e.createElementBlock("div",{key:z.type,class:"_fc-l-item",draggable:"true",onDragstart:ot=>En(ot,z),onDragend:Xe,onClick:ot=>fn(z)},[e.createElementVNode("div",qo,[e.createElementVNode("i",{class:e.normalizeClass(["fc-icon",V(z.type)])},null,2)]),e.createElementVNode("span",Jo,e.toDisplayString(z.name),1)],40,Ho))),128))],512),[[e.vShow,!_.hidden]])]))),128))]),_:1},512),[[e.vShow,N.value==="menu"]]),e.withDirectives(e.createVNode(S,null,{default:e.withCtx(()=>[e.createVNode(kn,{data:bn.value,"node-key":"id","expand-on-click-node":!1,"default-expand-all":"",onNodeClick:gn},{default:e.withCtx(({data:_})=>[e.createElementVNode("div",{class:e.normalizeClass(["_fc-tree-node",{active:O.value===_.rule?.id}])},[e.createElementVNode("div",Yo,[e.createElementVNode("i",{class:e.normalizeClass(["fc-icon",_.icon||"icon-cell"])},null,2),e.createElementVNode("span",null,e.toDisplayString(_.label),1)]),e.createElementVNode("div",{class:"_fc-tree-more",onClick:r[5]||(r[5]=e.withModifiers(()=>{},["stop"]))},[e.createVNode(Te,{trigger:"click",size:"default",onCommand:z=>Cn(z,_)},{dropdown:e.withCtx(()=>[e.createVNode(ae,null,{default:e.withCtx(()=>[e.createVNode(oe,{command:"copy"},{default:e.withCtx(()=>[...r[18]||(r[18]=[e.createTextVNode("复制",-1)])]),_:1}),e.createVNode(oe,{command:"delete"},{default:e.withCtx(()=>[...r[19]||(r[19]=[e.createTextVNode("删除",-1)])]),_:1})]),_:1})]),default:e.withCtx(()=>[r[20]||(r[20]=e.createElementVNode("i",{class:"fc-icon icon-more"},null,-1))]),_:1},8,["onCommand"])])],2)]),_:1},8,["data"])]),_:1},512),[[e.vShow,N.value==="tree"]])]),_:1}))]),_:1},512),[[e.vShow,!b.value]]),e.createVNode(fe,{class:"_fc-m"},{default:e.withCtx(()=>[e.createVNode(x,{class:"_fc-m-tools",height:"45"},{default:e.withCtx(()=>[e.createElementVNode("div",Ko,[e.createElementVNode("div",Qo,[e.createElementVNode("i",{class:e.normalizeClass(["fc-icon icon-pc",{active:C.value==="pc"}]),onClick:r[6]||(r[6]=_=>C.value="pc")},null,2),e.createElementVNode("i",{class:e.normalizeClass(["fc-icon icon-pad",{active:C.value==="pad"}]),onClick:r[7]||(r[7]=_=>C.value="pad")},null,2),e.createElementVNode("i",{class:e.normalizeClass(["fc-icon icon-mobile",{active:C.value==="mobile"}]),onClick:r[8]||(r[8]=_=>C.value="mobile")},null,2)]),r[21]||(r[21]=e.createElementVNode("div",{class:"line"},null,-1)),e.createElementVNode("div",null,[e.createElementVNode("i",{class:e.normalizeClass(["fc-icon icon-pre-step",{disabled:!ee.value}]),onClick:le},null,2),e.createElementVNode("i",{class:e.normalizeClass(["fc-icon icon-next-step",{disabled:!q.value}]),onClick:me},null,2)])]),e.createElementVNode("div",Xo,[e.createVNode(we,{icon:e.unref(pt),plain:"",size:"small",onClick:Tn},{default:e.withCtx(()=>[...r[22]||(r[22]=[e.createTextVNode("导入",-1)])]),_:1},8,["icon"]),e.createVNode(we,{type:"primary",plain:"",size:"small",onClick:r[9]||(r[9]=_=>w.value=!0)},{default:e.withCtx(()=>[...r[23]||(r[23]=[e.createElementVNode("i",{class:"fc-icon icon-preview"},null,-1),e.createTextVNode(" 预览 ",-1)])]),_:1}),e.createVNode(On,{title:"确定清空所有组件?",width:"200px","confirm-button-text":"清空","cancel-button-text":"取消",onConfirm:et},{reference:e.withCtx(()=>[e.createVNode(we,{type:"danger",plain:"",size:"small"},{default:e.withCtx(()=>[...r[24]||(r[24]=[e.createElementVNode("i",{class:"fc-icon icon-delete"},null,-1),e.createTextVNode(" 清空",-1)])]),_:1})]),_:1})])]),_:1}),e.createVNode(S,{class:"_fc-m-con"},{default:e.withCtx(()=>[r[25]||(r[25]=e.createElementVNode("a",{class:"gb-fc-watermark",href:"javascript:void(0)"},"GbFlowDesign",-1)),e.createElementVNode("div",{ref:"dragCon",class:e.normalizeClass(["_fc-m-drag",C.value]),style:R,onDragover:r[10]||(r[10]=e.withModifiers(()=>{},["prevent"])),onDrop:e.withModifiers(Vn,["prevent"])},[t.modelValue.length?(e.openBlock(),e.createBlock(An,{key:0,model:G,"label-width":e.unref(i).labelWidth||"120px",size:e.unref(i).size==="default"?void 0:e.unref(i).size},{default:e.withCtx(()=>[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(t.modelValue,(_,z)=>(e.openBlock(),e.createBlock(Ie,{key:_.id||z,component:_,path:[z],"form-data":G,"form-rules":H,"active-id":O.value},null,8,["component","path","form-data","active-id"]))),128))]),_:1},8,["model","label-width","size"])):(e.openBlock(),e.createElementBlock("div",{key:1,class:"_fd-draggable-drag _fd-drag-box drag-holder",onClick:pe}))],34)]),_:1})]),_:1}),e.withDirectives(e.createVNode(B,{class:"_fc-r",width:"320px"},{default:e.withCtx(()=>[e.createElementVNode("div",{class:"_fc-r-close",onClick:r[11]||(r[11]=_=>A.value=!0)},[...r[26]||(r[26]=[e.createElementVNode("i",{class:"fc-icon icon-arrow"},null,-1)])]),e.createVNode(No,{component:un.value,"form-options":e.unref(i),onClose:pe},null,8,["component","form-options"])]),_:1},512),[[e.vShow,!A.value]]),b.value?(e.openBlock(),e.createElementBlock("div",{key:0,class:"_fc-l-open",onClick:r[12]||(r[12]=_=>b.value=!1)},[...r[27]||(r[27]=[e.createElementVNode("i",{class:"fc-icon icon-arrow"},null,-1)])])):e.createCommentVNode("",!0),A.value?(e.openBlock(),e.createElementBlock("div",{key:1,class:"_fc-r-open",onClick:r[13]||(r[13]=_=>A.value=!1)},[...r[28]||(r[28]=[e.createElementVNode("i",{class:"fc-icon icon-arrow"},null,-1)])])):e.createCommentVNode("",!0),e.createVNode($o,{modelValue:w.value,"onUpdate:modelValue":r[14]||(r[14]=_=>w.value=_),components:t.modelValue,"form-options":e.unref(i)},null,8,["modelValue","components","form-options"])]),_:1})]),_:1})]),_:1})}}}),u=Object.freeze({STRING:"string",INTEGER:"integer",DECIMAL:"decimal",DATE:"date",DATETIME:"datetime",ARRAY:"array",BOOLEAN:"boolean"}),I=Object.freeze({INPUT:"input",TEXTAREA:"textarea",INPUT_NUMBER:"input-number",RADIO_GROUP:"radio-group",CHECKBOX_GROUP:"checkbox-group",SELECT:"select",SWITCH:"switch",DATE_PICKER:"date-picker",ROW:"row"}),Zo=Object.freeze({[I.INPUT]:u.STRING,[I.TEXTAREA]:u.STRING,[I.INPUT_NUMBER]:null,[I.RADIO_GROUP]:u.STRING,[I.SELECT]:u.STRING,[I.CHECKBOX_GROUP]:u.ARRAY,[I.SWITCH]:u.BOOLEAN,[I.DATE_PICKER]:u.DATE,[I.ROW]:null}),E=Object.freeze({EQUAL:"==",NOT_EQUAL:"!=",GREATER_THAN:">",LESS_THAN:"<",GREATER_THAN_OR_EQUAL:">=",LESS_THAN_OR_EQUAL:"<=",CONTAINS:"contains",NOT_CONTAINS:"not_contains",IS_EMPTY:"is_empty",IS_NOT_EMPTY:"is_not_empty"}),Ge=Object.freeze({[E.EQUAL]:"等于",[E.NOT_EQUAL]:"不等于",[E.GREATER_THAN]:"大于",[E.LESS_THAN]:"小于",[E.GREATER_THAN_OR_EQUAL]:"大于等于",[E.LESS_THAN_OR_EQUAL]:"小于等于",[E.CONTAINS]:"包含",[E.NOT_CONTAINS]:"不包含",[E.IS_EMPTY]:"为空",[E.IS_NOT_EMPTY]:"不为空"}),ge=Object.freeze({[u.STRING]:[E.EQUAL,E.NOT_EQUAL,E.CONTAINS,E.NOT_CONTAINS,E.IS_EMPTY,E.IS_NOT_EMPTY],[u.INTEGER]:[E.EQUAL,E.NOT_EQUAL,E.GREATER_THAN,E.LESS_THAN,E.GREATER_THAN_OR_EQUAL,E.LESS_THAN_OR_EQUAL,E.IS_EMPTY,E.IS_NOT_EMPTY],[u.DECIMAL]:[E.EQUAL,E.NOT_EQUAL,E.GREATER_THAN,E.LESS_THAN,E.GREATER_THAN_OR_EQUAL,E.LESS_THAN_OR_EQUAL,E.IS_EMPTY,E.IS_NOT_EMPTY],[u.DATE]:[E.EQUAL,E.NOT_EQUAL,E.GREATER_THAN,E.LESS_THAN,E.GREATER_THAN_OR_EQUAL,E.LESS_THAN_OR_EQUAL,E.IS_EMPTY,E.IS_NOT_EMPTY],[u.DATETIME]:[E.EQUAL,E.NOT_EQUAL,E.GREATER_THAN,E.LESS_THAN,E.GREATER_THAN_OR_EQUAL,E.LESS_THAN_OR_EQUAL,E.IS_EMPTY,E.IS_NOT_EMPTY],[u.ARRAY]:[E.CONTAINS,E.NOT_CONTAINS,E.IS_EMPTY,E.IS_NOT_EMPTY],[u.BOOLEAN]:[E.EQUAL,E.NOT_EQUAL]});function We(t){if(!t||!t.type)return console.warn("组件配置无效,无法计算数据类型",t),u.STRING;const n=t.type;if(t.props,n.startsWith("internal-")||n.startsWith("text/")||n.startsWith("application/"))return console.warn(`检测到非组件类型: ${n},默认使用STRING类型`,t),u.STRING;if(n===I.INPUT_NUMBER)return u.INTEGER;if(n===I.DATE_PICKER)return u.DATE;const o=Zo[n];return o||(console.warn(`未知的组件类型: ${n},默认使用STRING类型`),u.STRING)}function vo(t){const n=ge[t];return n?n.map(o=>({label:Ge[o],value:o})):(console.warn(`未知的数据类型: ${t},返回默认操作符`),ge[u.STRING])}function en(t){return t!==E.IS_EMPTY&&t!==E.IS_NOT_EMPTY}function ce(t){switch(t){case u.INTEGER:case u.DECIMAL:return null;case u.ARRAY:return[];case u.BOOLEAN:return!1;case u.DATE:case u.DATETIME:case u.STRING:default:return""}}function He(t,n){if(t==null||t==="")return!0;switch(n){case u.INTEGER:return Number.isInteger(Number(t))&&isFinite(Number(t));case u.DECIMAL:return typeof t=="number"||!isNaN(Number(t))&&isFinite(Number(t));case u.ARRAY:return Array.isArray(t);case u.BOOLEAN:return typeof t=="boolean";case u.DATE:case u.DATETIME:return typeof t=="string"&&/^\d{4}-\d{2}-\d{2}/.test(t);case u.STRING:return typeof t=="string"||typeof t=="number";default:return!0}}function tn(t){return{[u.STRING]:"字符串",[u.INTEGER]:"整数",[u.DECIMAL]:"小数",[u.DATE]:"日期",[u.DATETIME]:"日期时间",[u.ARRAY]:"数组",[u.BOOLEAN]:"布尔值"}[t]||t}function on(t){return t===u.INTEGER||t===u.DECIMAL}function nn(t){return t===u.DATE||t===u.DATETIME}class Z{constructor(n){if(!n)throw new Error("FormVariable: component参数不能为空");const o=n.props?.variableName;if(!o)throw new Error("FormVariable: 组件必须有props.variableName属性");this.id=n.id,this.variableName=o,this.label=n.props?.label||o,this.componentType=n.type,this.dataType=We(n),this.metadata=this._extractMetadata(n),this.defaultValue=this._normalizeDefaultValue(n),this.component=n}_extractMetadata(n){const o=n.props||{},l={placeholder:o.placeholder||"",required:n.required!==!1};switch(n.type){case I.RADIO_GROUP:l.options=Array.isArray(o.options)?o.options:[];break;case I.INPUT_NUMBER:l.min=n.min!=null?Number(n.min):void 0,l.max=n.max!=null?Number(n.max):void 0;break;case I.DATE_PICKER:l.dateFormat="date";break}return l}_normalizeDefaultValue(n){const o=n.props?.defaultValue;return o==null||o===""?ce(this.dataType):He(o,this.dataType)?this._convertValue(o,this.dataType):(console.warn(`FormVariable: 默认值 "${o}" 不符合类型 "${this.dataType}",使用类型默认值`,n),ce(this.dataType))}_convertValue(n,o){if(n==null||n==="")return ce(o);switch(o){case u.INTEGER:return parseInt(n,10);case u.DECIMAL:return parseFloat(n);case u.ARRAY:return Array.isArray(n)?n:[];case u.BOOLEAN:return!!n;case u.STRING:case u.DATE:case u.DATETIME:default:return String(n)}}getConditionInfo(){return{variableName:this.variableName,label:this.label,dataType:this.dataType,componentType:this.componentType,options:this.metadata.options||null,dateFormat:this.metadata.dateFormat||null,isInteger:this.dataType===u.INTEGER}}hasOptions(){return Array.isArray(this.metadata.options)&&this.metadata.options.length>0}getOptions(){return this.metadata.options||[]}isNumeric(){return this.dataType===u.INTEGER||this.dataType===u.DECIMAL}isDate(){return this.dataType===u.DATE||this.dataType===u.DATETIME}isInteger(){return this.dataType===u.INTEGER}getDateFormat(){return this.metadata.dateFormat||null}toJSON(){return{id:this.id,variableName:this.variableName,label:this.label,componentType:this.componentType,dataType:this.dataType,metadata:this.metadata,defaultValue:this.defaultValue}}static fromJSON(n){const o={id:n.id,type:n.componentType,field:n.variableName,name:n.label,props:{...n.metadata}};return new Z(o)}static fromComponents(n){return Array.isArray(n)?n.filter(o=>!(!o||!o.props?.variableName||o.type===I.ROW)).map(o=>{try{return new Z(o)}catch(l){return console.error("FormVariable.fromComponents: 创建FormVariable失败",l,o),null}}).filter(o=>o!==null):(console.warn("FormVariable.fromComponents: components必须是数组"),[])}static isValid(n){return n?typeof n.variableName=="string"&&typeof n.label=="string"&&typeof n.componentType=="string"&&typeof n.dataType=="string"&&typeof n.metadata=="object":!1}}function ln(t){return t?.components?t.components.filter(n=>n?.type==="row"||n?.props?.variableName&&n?.props?.label):[]}function de(t){return Array.isArray(t)?t.reduce((n,o)=>(o&&(o.type==="row"&&o.children?o.children.forEach(l=>{Array.isArray(l)&&n.push(...de(l))}):o.props?.variableName&&n.push(o)),n),[]):[]}function an(t){if(!Array.isArray(t))return[];if(t.length>0&&t[0]instanceof Z)return t;const n=de(t);return Z.fromComponents(n)}function rn(t,n){return Array.isArray(t)&&t.find(o=>o.variableName===n)||null}function sn(t){const n=[];return t?(t.type||n.push("组件类型不能为空"),t.props?(t.props.variableName||n.push("变量名不能为空"),t.props.label||n.push("标签不能为空"),["select","radio","checkbox"].includes(t.type)&&(Array.isArray(t.props.options)&&t.props.options.length>0||n.push(`${t.type}类型必须配置选项列表`))):n.push("组件属性不能为空"),{valid:n.length===0,errors:n}):(n.push("组件配置不能为空"),{valid:!1,errors:n})}function cn(t){return de(t).length}const dn=[je,Ee],qe="0.1.0",mn={version:qe,install(t){dn.forEach(n=>{n.name&&t.component(n.name,n)})}};y.BaseDataType=u,y.COMPONENT_CATEGORIES=ye,y.COMPONENT_TYPES=d,y.COMPONENT_TYPE_LABELS=Ae,y.ComponentType=I,y.ConditionOperator=E,y.DATA_TYPE_OPERATORS_MAP=ge,y.DEFAULT_CONFIG=ut,y.FORM_KIND=Me,y.FcCanvasField=Ie,y.FormDesigner=je,y.FormVariable=Z,y.FormViewer=Ee,y.OPERATOR_LABEL_MAP=Ge,y.OPTION_COMPONENT_TYPES=ue,y.SCHEMA_VERSION=Ue,y.WIDTH_PRESETS=ft,y.computeDataType=We,y.countFormComponents=cn,y.default=mn,y.downloadJSON=Fe,y.downloadText=Pe,y.enrichFormVariables=an,y.ensureComponentId=he,y.exportForm=Ve,y.filterValidComponents=ln,y.findFormVariable=rn,y.generateComponentId=X,y.getAllFormComponents=de,y.getDataTypeLabel=tn,y.getFieldName=M,y.getOperatorsForDataType=vo,y.getTypeDefaultValue=ce,y.importForm=be,y.isDateType=nn,y.isEmpty=Ne,y.isNumericType=on,y.isValidValueForType=He,y.normalizeForm=ie,y.normalizeNumberValue=re,y.normalizeOptions=Re,y.operatorNeedsValue=en,y.parseWidth=Be,y.pickJSONFile=ze,y.readTextFile=Le,y.sanitizeFileName=zo,y.validateComponentConfig=sn,y.validateForm=se,y.version=qe,Object.defineProperties(y,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
|
|
15
15
|
//# sourceMappingURL=gbformdesign.umd.cjs.map
|