arco-crud-plus
Version:
基于arco-design-vue的配置化表格表单组件
2 lines (1 loc) • 11.2 kB
JavaScript
;Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("vue"),k=require("../utils/validate.js"),U={key:0,class:"left-bot"},j=e.defineComponent({name:"aFormPlus",__name:"main",props:e.mergeModels({option:{}},{modelValue:{},modelModifiers:{}}),emits:e.mergeModels(["submit","reset","form-change"],["update:modelValue"]),setup(h,{expose:$,emit:T}){const s=e.useSlots(),E=e.useAttrs(),D=h,i={colGap:1,rowGap:1,span:8,marginTop:"10px",autoLabelWidth:!0,scrollToFirstError:!0,layout:"horizontal",gutter:10,size:"medium",labelAlign:"right",columns:[],justify:"start",align:"start",wrap:!0},f=e.useModel(h,"modelValue"),y=e.ref(null),g=T,z=e.reactive({}),a=e.reactive({submit:!1,reset:!1});function C(){a.submit=!1}const L=({values:o,errors:t})=>{t===void 0&&(a.submit=!0,g("submit",o,C))};function v(){y.value.resetFields(),y.value.clearValidate(),g("reset")}function w(o){return D.option.disabled??o??!1}function F(){}function B(o,t){g("form-change",o,t,C)}$(new Proxy({},{get(o,t){var r;return(r=y.value)==null?void 0:r[t]},has(o,t){return t in y.value}}));function V(o){return k.validataNull(o.bind)?Reflect.get(f.value,o.field):G(f.value,o.bind)}function S(o,t){k.validataNull(o.bind)?Reflect.set(f.value,o.field,t):(f[o.field]=t,M(f.value,o.bind,t))}const G=(o,t)=>t.split(".").reduce((r,d)=>r&&r[d],o),M=(o,t,r)=>{const d=t.split("."),m=d.pop(),u=d.reduce((p,c)=>p[c]=p[c]||{},o);u[m]=r},N=(o,t)=>{const r={};if((t.type==="input"||t.type===void 0)&&(r.allowClear=!0,r.placeholder=`请输入${t.label}`),t.type==="input-password"){const d=k.deepCopy(t);return delete d.type,{...r,...d,msg:null}}return t.type==="input-number"&&(r.placeholder=`请输入${t.label}`),t.type==="textarea"&&(r.allowClear=!0,r.showWordLimit=t.showWordLimit??!0,r.placeholder=`请输入${t.label}`),t.type==="select"&&(r.allowClear=!0,r.placeholder=`请选择${t.label}`,r.options=[],r.options=o[t.field]||t.dicData),t.type==="cascader"&&(r.allowClear=!0,r.placeholder=`请选择${t.label}`,r.options=o[t.field]||t.dicData),t.type==="radio"&&(r.options=o[t.field]||t.dicData),t.type==="radio-group"&&(r.options=o[t.field]||t.dicData),t.type==="checkbox-group"&&(r.options=o[t.field]||t.dicData),t.type==="checkbox"&&(r.options=o[t.field]||t.dicData),t.type==="date-picker"&&(r.placeholder="请选择日期"),t.type==="time-picker"&&(r.allowClear=!0,r.placeholder="请选择时间"),{...r,...t,msg:null,field:null,type:null}};return(o,t)=>{const r=e.resolveComponent("icon-question-circle-fill"),d=e.resolveComponent("a-tooltip"),m=e.resolveComponent("a-form-item"),u=e.resolveComponent("a-col"),p=e.resolveComponent("a-button"),c=e.resolveComponent("a-row"),P=e.resolveComponent("a-space"),A=e.resolveComponent("a-form");return e.openBlock(),e.createBlock(A,e.mergeProps({ref_key:"formRef",ref:y,"auto-label-width":o.option.autoLabelWidth??i.autoLabelWidth,layout:o.option.layout??i.layout??"horizontal",scrollToFirstError:o.option.scrollToFirstError??i.scrollToFirstError,size:o.option.size??i.size,"label-align":o.option.labelAlign??i.labelAlign,model:f.value,onSubmit:L,onKeyup:e.withKeys(F,["enter"]),disabled:!0},e.unref(E)),{default:e.withCtx(()=>[e.createVNode(c,{class:"form-row__container",justify:o.option.justify??i.justify,align:o.option.align??i.align,wrap:o.option.wrap??i.wrap,cols:24,gutter:o.option.gutter||i.gutter,colGap:o.option.colGap??i.colGap,rowGap:o.option.rowGap??i.rowGap},{default:e.withCtx(()=>[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(o.option.columns,l=>(e.openBlock(),e.createElementBlock(e.Fragment,{key:l.field},[l.display??!0?(e.openBlock(),e.createBlock(u,{key:0,style:e.normalizeStyle({marginTop:o.option.marginTop??i.marginTop}),span:l.span??o.option.span??i.span,offset:l.offset??0,order:l.order??0},{default:e.withCtx(()=>[e.createVNode(m,e.normalizeProps({[(a.submit?"":"disabled")||""]:w(l.disabled),label:l.label,field:l.bind??l.field,rules:l.rules}),e.createSlots({default:e.withCtx(()=>[e.unref(s)[l.field]?e.renderSlot(o.$slots,l.field,{key:0,item:l,size:o.option.size??i.size},void 0,!0):(e.openBlock(),e.createBlock(e.resolveDynamicComponent(l.component?l.component:`a-${l.type||"input"}`),e.mergeProps({key:1,style:{width:l.type==="switch"?"":"100%"},size:o.option.size??i.size,disabled:o.option.detail??l.disabled??!1,modelValue:V(l),"onUpdate:modelValue":n=>S(l,n),visibility:l.visibility,"onUpdate:visibility":n=>l.visibility=n,ref_for:!0},N(z,l),{onChange:n=>B(n,l)}),null,16,["style","size","disabled","modelValue","onUpdate:modelValue","visibility","onUpdate:visibility","onChange"]))]),_:2},[e.unref(s)[l.field+"Label"]?{name:"label",fn:e.withCtx(()=>[e.renderSlot(o.$slots,l.field+"Label",{},void 0,!0)]),key:"0"}:void 0,e.unref(s)[l.field+"Label"]?void 0:{name:"label",fn:e.withCtx(()=>[e.createTextVNode(e.toDisplayString(l.label)+" ",1),l.helpIconText?(e.openBlock(),e.createBlock(d,{key:0,content:l.helpIconText},{default:e.withCtx(()=>[e.createVNode(r,{size:o.option.size??i.size},null,8,["size"])]),_:2},1032,["content"])):e.createCommentVNode("",!0)]),key:"1"},e.unref(s)[l.field+"Help"]||l.help?{name:"help",fn:e.withCtx(()=>[e.renderSlot(o.$slots,l.field+"Help",{},void 0,!0),e.createElementVNode("span",null,e.toDisplayString(l.help),1)]),key:"2"}:void 0,e.unref(s)[l.field+"Extra"]||l.extra?{name:"extra",fn:e.withCtx(()=>[e.renderSlot(o.$slots,l.field+"Extra",{},void 0,!0),e.createElementVNode("span",null,e.toDisplayString(l.extra),1)]),key:"3"}:void 0]),1040,["label","field","rules"])]),_:2},1032,["style","span","offset","order"])):e.createCommentVNode("",!0)],64))),128)),o.option.search===!0?(e.openBlock(),e.createBlock(u,{key:0,order:11,span:o.option.searchMenuSpan??8,style:e.normalizeStyle({textAlign:o.option.searchMenuAlign??"left",marginTop:o.option.searchMenuMargintop??"10px"})},{default:e.withCtx(()=>[e.unref(s).menu?e.renderSlot(o.$slots,"menu",{key:0,size:o.option.size??i.size,loading:a.submit},void 0,!0):e.createCommentVNode("",!0),e.renderSlot(o.$slots,"menuLeft",{size:o.option.size??i.size,loading:a.submit},void 0,!0),e.renderSlot(o.$slots,"suffix",{loading:a.submit},()=>[o.option.menuBtn??o.option.submitBtn??!0?(e.openBlock(),e.createBlock(p,{key:0,size:o.option.size??i.size,type:"primary",loading:a.submit,"html-type":"submit"},{default:e.withCtx(()=>[e.createTextVNode(e.toDisplayString(o.option.submitBtnText??"提交"),1)]),_:1},8,["size","loading"])):e.createCommentVNode("",!0),o.option.menuBtn??o.option.resetBtn??!0?(e.openBlock(),e.createBlock(p,{key:1,size:o.option.size??i.size,onClick:t[0]||(t[0]=l=>v())},{default:e.withCtx(()=>[e.createTextVNode(e.toDisplayString(o.option.resetBtnText??"重置"),1)]),_:1},8,["size"])):e.createCommentVNode("",!0)],!0),e.renderSlot(o.$slots,"menuright",{size:o.option.size??i.size,loading:a.submit},void 0,!0)]),_:3},8,["span","style"])):e.createCommentVNode("",!0)]),_:3},8,["justify","align","wrap","gutter","colGap","rowGap"]),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(o.option.groups,l=>(e.openBlock(),e.createElementBlock(e.Fragment,null,[(l.display,e.openBlock(),e.createBlock(c,{key:0,style:e.normalizeStyle(o.option.groupContainerStyle??{})},{default:e.withCtx(()=>[e.createVNode(u,{span:24},{default:e.withCtx(()=>[!e.unref(s)[l.field+"GroupHeader"]&&!e.unref(k.validataNull)(l.label)?(e.openBlock(),e.createElementBlock("div",U,e.toDisplayString(l.label),1)):e.renderSlot(o.$slots,l.field+"GroupHeader",{key:1,label:l.label,record:l},void 0,!0)]),_:2},1024),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(l.columns,n=>(e.openBlock(),e.createElementBlock(e.Fragment,{key:n.field},[n.display??!0?(e.openBlock(),e.createBlock(u,{key:0,span:n.span??o.option.span??i.span,offset:n.offset??0,order:n.order??100},{default:e.withCtx(()=>[e.createVNode(m,e.normalizeProps({"label-col-style":{width:"100px"},[(a.submit?"":"disabled")||""]:w(n.disabled),label:n.label,field:n.field,rules:n.rules}),e.createSlots({default:e.withCtx(()=>[e.unref(s)[n.field]?e.renderSlot(o.$slots,n.field,{key:0,item:n,size:o.option.size??i.size},void 0,!0):(e.openBlock(),e.createBlock(e.resolveDynamicComponent(n.component?n.component:`a-${n.type||"input"}`),e.mergeProps({key:1,style:{width:n.type==="switch"?"":"100%"},size:o.option.size??i.size,disabled:o.option.detail??n.disabled??!1,modelValue:V(n),"onUpdate:modelValue":b=>S(n,b),visibility:n.visibility,"onUpdate:visibility":b=>n.visibility=b,ref_for:!0},N(z,n),{onChange:b=>B(b,n)}),null,16,["style","size","disabled","modelValue","onUpdate:modelValue","visibility","onUpdate:visibility","onChange"]))]),_:2},[e.unref(s)[n.field+"Label"]?{name:"label",fn:e.withCtx(()=>[e.renderSlot(o.$slots,n.field+"Label",{},void 0,!0)]),key:"0"}:void 0,e.unref(s)[n.field+"Label"]?void 0:{name:"label",fn:e.withCtx(()=>[e.createTextVNode(e.toDisplayString(n.label)+" ",1),n.helpIconText?(e.openBlock(),e.createBlock(d,{key:0,content:n.helpIconText},{default:e.withCtx(()=>[e.createVNode(r,{size:o.option.size??i.size},null,8,["size"])]),_:2},1032,["content"])):e.createCommentVNode("",!0)]),key:"1"},e.unref(s)[n.field+"Help"]||n.help?{name:"help",fn:e.withCtx(()=>[e.renderSlot(o.$slots,n.field+"Help",{},void 0,!0),e.createElementVNode("span",null,e.toDisplayString(n.help),1)]),key:"2"}:void 0,e.unref(s)[n.field+"Extra"]||n.extra?{name:"extra",fn:e.withCtx(()=>[e.renderSlot(o.$slots,n.field+"Extra",{},void 0,!0),e.createElementVNode("span",null,e.toDisplayString(n.extra),1)]),key:"3"}:void 0]),1040,["label","field","rules"])]),_:2},1032,["span","offset","order"])):e.createCommentVNode("",!0)],64))),128))]),_:2},1032,["style"]))],64))),256)),o.option.search?e.createCommentVNode("",!0):(e.openBlock(),e.createBlock(c,{key:0,class:e.normalizeClass({formMenuContainer:o.option.menu??!o.option.detail??!0})},{default:e.withCtx(()=>[o.option.menu??!o.option.detail??!0?(e.openBlock(),e.createBlock(u,{key:0,order:1e4,span:o.option.menuSpan??24,style:e.normalizeStyle({textAlign:o.option.menuAlign??"center"})},{default:e.withCtx(()=>[e.unref(s).menu?e.renderSlot(o.$slots,"menu",{key:0,size:o.option.size??i.size,loading:a.submit},void 0,!0):e.createCommentVNode("",!0),e.createVNode(P,{wrap:""},{default:e.withCtx(()=>[e.renderSlot(o.$slots,"menuLeft",{size:o.option.size??i.size,loading:a.submit},void 0,!0),e.renderSlot(o.$slots,"suffix",{loading:a.submit},()=>[o.option.menuBtn??o.option.submitBtn??!0?(e.openBlock(),e.createBlock(p,{key:0,size:o.option.size??i.size,type:"primary",loading:a.submit,"html-type":"submit"},{default:e.withCtx(()=>[e.createTextVNode(e.toDisplayString(o.option.submitBtnText??"提交"),1)]),_:1},8,["size","loading"])):e.createCommentVNode("",!0),o.option.menuBtn??o.option.resetBtn??!0?(e.openBlock(),e.createBlock(p,{key:1,size:o.option.size??i.size,onClick:t[1]||(t[1]=l=>v())},{default:e.withCtx(()=>[e.createTextVNode(e.toDisplayString(o.option.resetBtnText??"重置"),1)]),_:1},8,["size"])):e.createCommentVNode("",!0)],!0),e.renderSlot(o.$slots,"menuright",{size:o.option.size??i.size,loading:a.submit},void 0,!0)]),_:3})]),_:3},8,["span","style"])):e.createCommentVNode("",!0)]),_:3},8,["class"]))]),_:3},16,["auto-label-width","layout","scrollToFirstError","size","label-align","model"])}}});exports.default=j;