@mineadmin/form
Version:
基于element plus的form组件,进行封装,提供方便、灵活的配置和使用方式
2 lines (1 loc) • 12.3 kB
JavaScript
(function(m,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("vue"),require("element-plus")):typeof define=="function"&&define.amd?define(["exports","vue","element-plus"],a):a((m=typeof globalThis<"u"?globalThis:m||self).MaTable={},m.Vue,m.ElementPlus)})(this,function(m,a,s){"use strict";var ye=typeof global=="object"&&global&&global.Object===Object&&global,ge=typeof self=="object"&&self&&self.Object===Object&&self,D=ye||ge||Function("return this")(),E=D.Symbol,X=Object.prototype,_e=X.hasOwnProperty,be=X.toString,T=E?E.toStringTag:void 0,we=Object.prototype.toString,je="[object Null]",Se="[object Undefined]",Y=E?E.toStringTag:void 0;function Z(e){return e==null?e===void 0?Se:je:Y&&Y in Object(e)?function(t){var n=_e.call(t,T),o=t[T];try{t[T]=void 0;var l=!0}catch{}var u=be.call(t);return l&&(n?t[T]=o:delete t[T]),u}(e):function(t){return we.call(t)}(e)}var Oe="[object Symbol]";function B(e){return typeof e=="symbol"||function(t){return t!=null&&typeof t=="object"}(e)&&Z(e)==Oe}var G=Array.isArray,Ee=1/0,ee=E?E.prototype:void 0,te=ee?ee.toString:void 0;function ne(e){if(typeof e=="string")return e;if(G(e))return function(n,o){for(var l=-1,u=n==null?0:n.length,c=Array(u);++l<u;)c[l]=o(n[l],l,n);return c}(e,ne)+"";if(B(e))return te?te.call(e):"";var t=e+"";return t=="0"&&1/e==-Ee?"-0":t}function I(e){var t=typeof e;return e!=null&&(t=="object"||t=="function")}var Pe="[object AsyncFunction]",Ce="[object Function]",xe="[object GeneratorFunction]",Ve="[object Proxy]",oe,U=D["__core-js_shared__"],re=(oe=/[^.]+$/.exec(U&&U.keys&&U.keys.IE_PROTO||""))?"Symbol(src)_1."+oe:"",Te=Function.prototype.toString,Fe=/^\[object .+?Constructor\]$/,Me=Function.prototype,ke=Object.prototype,ze=Me.toString,Ie=ke.hasOwnProperty,Ne=RegExp("^"+ze.call(Ie).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function $e(e){if(!I(e)||(t=e,re&&re in t))return!1;var t,n=function(o){if(!I(o))return!1;var l=Z(o);return l==Ce||l==xe||l==Pe||l==Ve}(e)?Ne:Fe;return n.test(function(o){if(o!=null){try{return Te.call(o)}catch{}try{return o+""}catch{}}return""}(e))}function q(e,t){var n=function(o,l){return o==null?void 0:o[l]}(e,t);return $e(n)?n:void 0}var le=function(){try{var e=q(Object,"defineProperty");return e({},"",{}),e}catch{}}(),Le=9007199254740991,Re=/^(?:0|[1-9]\d*)$/;function Ae(e,t){var n=typeof e;return!!(t=t??Le)&&(n=="number"||n!="symbol"&&Re.test(e))&&e>-1&&e%1==0&&e<t}function ae(e,t){return e===t||e!=e&&t!=t}var De=Object.prototype.hasOwnProperty;function Be(e,t,n){var o=e[t];De.call(e,t)&&ae(o,n)&&(n!==void 0||t in e)||function(l,u,c){u=="__proto__"&&le?le(l,u,{configurable:!0,enumerable:!0,value:c,writable:!0}):l[u]=c}(e,t,n)}var Ge=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,Ue=/^\w*$/,F=q(Object,"create"),qe=Object.prototype.hasOwnProperty,He=Object.prototype.hasOwnProperty;function b(e){var t=-1,n=e==null?0:e.length;for(this.clear();++t<n;){var o=e[t];this.set(o[0],o[1])}}function N(e,t){for(var n=e.length;n--;)if(ae(e[n][0],t))return n;return-1}b.prototype.clear=function(){this.__data__=F?F(null):{},this.size=0},b.prototype.delete=function(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t},b.prototype.get=function(e){var t=this.__data__;if(F){var n=t[e];return n==="__lodash_hash_undefined__"?void 0:n}return qe.call(t,e)?t[e]:void 0},b.prototype.has=function(e){var t=this.__data__;return F?t[e]!==void 0:He.call(t,e)},b.prototype.set=function(e,t){var n=this.__data__;return this.size+=this.has(e)?0:1,n[e]=F&&t===void 0?"__lodash_hash_undefined__":t,this};var We=Array.prototype.splice;function P(e){var t=-1,n=e==null?0:e.length;for(this.clear();++t<n;){var o=e[t];this.set(o[0],o[1])}}P.prototype.clear=function(){this.__data__=[],this.size=0},P.prototype.delete=function(e){var t=this.__data__,n=N(t,e);return!(n<0)&&(n==t.length-1?t.pop():We.call(t,n,1),--this.size,!0)},P.prototype.get=function(e){var t=this.__data__,n=N(t,e);return n<0?void 0:t[n][1]},P.prototype.has=function(e){return N(this.__data__,e)>-1},P.prototype.set=function(e,t){var n=this.__data__,o=N(n,e);return o<0?(++this.size,n.push([e,t])):n[o][1]=t,this};var Je=q(D,"Map");function $(e,t){var n,o,l=e.__data__;return((o=typeof(n=t))=="string"||o=="number"||o=="symbol"||o=="boolean"?n!=="__proto__":n===null)?l[typeof t=="string"?"string":"hash"]:l.map}function w(e){var t=-1,n=e==null?0:e.length;for(this.clear();++t<n;){var o=e[t];this.set(o[0],o[1])}}w.prototype.clear=function(){this.size=0,this.__data__={hash:new b,map:new(Je||P),string:new b}},w.prototype.delete=function(e){var t=$(this,e).delete(e);return this.size-=t?1:0,t},w.prototype.get=function(e){return $(this,e).get(e)},w.prototype.has=function(e){return $(this,e).has(e)},w.prototype.set=function(e,t){var n=$(this,e),o=n.size;return n.set(e,t),this.size+=n.size==o?0:1,this};var Ke="Expected a function";function H(e,t){if(typeof e!="function"||t!=null&&typeof t!="function")throw new TypeError(Ke);var n=function(){var o=arguments,l=t?t.apply(this,o):o[0],u=n.cache;if(u.has(l))return u.get(l);var c=e.apply(this,o);return n.cache=u.set(l,c)||u,c};return n.cache=new(H.Cache||w),n}H.Cache=w;var ie,W,J,Qe=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,Xe=/\\(\\)?/g,Ye=(ie=function(e){var t=[];return e.charCodeAt(0)===46&&t.push(""),e.replace(Qe,function(n,o,l,u){t.push(l?u.replace(Xe,"$1"):o||n)}),t},W=H(ie,function(e){return J.size===500&&J.clear(),e}),J=W.cache,W);function ue(e,t){return G(e)?e:function(n,o){if(G(n))return!1;var l=typeof n;return!(l!="number"&&l!="symbol"&&l!="boolean"&&n!=null&&!B(n))||Ue.test(n)||!Ge.test(n)||o!=null&&n in Object(o)}(e,t)?[e]:Ye(function(n){return n==null?"":ne(n)}(e))}var Ze=1/0;function ce(e){if(typeof e=="string"||B(e))return e;var t=e+"";return t=="0"&&1/e==-Ze?"-0":t}function et(e,t,n){var o=e==null?void 0:function(l,u){for(var c=0,j=(u=ue(u,l)).length;l!=null&&c<j;)l=l[ce(u[c++])];return c&&c==j?l:void 0}(e,t);return o===void 0?n:o}function tt(e,t,n){return e==null?e:function(o,l,u){if(!I(o))return o;for(var c=-1,j=(l=ue(l,o)).length,M=j-1,_=o;_!=null&&++c<j;){var h=ce(l[c]),C=u;if(h==="__proto__"||h==="constructor"||h==="prototype")return o;if(c!=M){var x=_[h];(C=void 0)==void 0&&(C=I(x)?x:Ae(l[c+1])?[]:{})}Be(_,h,C),_=_[h]}return o}(e,t,n)}const se={Radio:s.ElRadioGroup,Checkbox:s.ElCheckboxGroup,CheckboxButton:s.ElCheckboxGroup,Input:s.ElInput,Mention:s.ElMention,Autocomplete:s.ElAutocomplete,InputNumber:s.ElInputNumber,Select:s.ElSelect,Cascader:s.ElCascader,Switch:s.ElSwitch,Slider:s.ElSlider,TimePicker:s.ElTimePicker,DatePicker:s.ElDatePicker,Rate:s.ElRate,ColorPicker:s.ElColorPicker,Transfer:s.ElTransfer,TimeSelect:s.ElTimeSelect,SelectV2:s.ElSelectV2,TreeSelect:s.ElTreeSelect,RadioButton:s.ElRadioGroup};function K(e){return typeof e=="function"||Object.prototype.toString.call(e)==="[object Object]"&&!a.isVNode(e)}const fe=a.defineComponent({name:"MaForm",props:{modelValue:{type:Object,default:()=>({})},options:{type:Object,default:()=>({})},items:{type:Array,default:()=>[]}},directives:{Loading:s.ElLoadingDirective},setup(e,{slots:t,attrs:n,expose:o}){const l=a.ref(e.modelValue),u=a.ref(e.options),c=a.ref(e.items),j=a.inject("MaFormOptions"),M=a.ref(!1),_=a.ref(),h=a.ref(!1),C=()=>{h.value=window.innerWidth<768};a.onMounted(async()=>{M.value=!0,window.addEventListener("resize",C)}),a.onBeforeUnmount(()=>{M.value=!1,window.removeEventListener("resize",C)});const x=(i,r)=>{var y,S,k,O,g;const d=typeof r.prop=="function"?r.prop():r.prop;let v=null;return(y=i==null?void 0:i.children)!=null&&y.default?v=(S=i==null?void 0:i.children)==null?void 0:S.default:(k=r==null?void 0:r.renderSlots)!=null&&k.default?v=(O=r.renderSlots)==null?void 0:O.default:r!=null&&r.children&&(v=Q((r==null?void 0:r.children)??[])),a.h(i,{ref:"formItem-{$prop}",modelValue:et(l.value,d),"onUpdate:modelValue":z=>tt(l.value,d,z),...r==null?void 0:r.renderProps},{...(r==null?void 0:r.renderSlots)??null,default:r!=null&&r.children&&!((g=r.renderSlots)!=null&&g.default)&&typeof i.type=="string"?()=>v:v})},Q=i=>{const{layout:r}=u.value;return i==null?void 0:i.map(d=>{let v;const{label:y,prop:S,itemProps:k,hide:O,show:g,cols:z,itemSlots:f}=d,L=typeof O=="function"?O:()=>O===!0,R=typeof g=="function"?g:()=>g!==!1,he=typeof S=="function"?S():S,me=()=>a.withDirectives(a.createVNode(s.ElFormItem,a.mergeProps({ref:`formItemRef-${he}`,label:typeof y=="function"?y():y,prop:he},k),{default:()=>{var V;return((V=f==null?void 0:f.default)==null?void 0:V.call(f))??(p=>{if(typeof p.render=="string"){const A=p.render[0].toUpperCase().concat(p.render.substring(1,p.render.length));if(se[A])return x(se[A],p)}else{if(typeof p.render=="function"){const A=p.render;return x(A({item:p,formData:l.value}),p)}if(!p.render)return x((l.value,a.createVNode("div",null,null)),p)}})(d)},label:f!=null&&f.label?V=>{var p;return((p=f==null?void 0:f.label)==null?void 0:p.call(f,V))??null}:void 0,error:f!=null&&f.error?V=>{var p;return((p=f==null?void 0:f.error)==null?void 0:p.call(f,V))??null}:void 0}),[[a.vShow,L(d,l.value)!==!0]]);return a.createVNode(a.Fragment,null,[R(d,l.value)&&(r===void 0||r==="flex"?a.createVNode(a.resolveComponent("el-col"),z,K(v=me())?v:{default:()=>[v]}):me())])})},nt=()=>{var L;let i,r;const{layout:d,flex:v,grid:y,loading:S,loadingConfig:k,containerClass:O,footerSlot:g,...z}=u.value,{style:f}=y??{};return a.createVNode(a.Fragment,null,[a.createVNode(s.ElForm,a.mergeProps({model:l,ref:_},z,n),{default:()=>{var R;return[((R=t.default)==null?void 0:R.call(t))??(d===void 0||d==="flex"?a.createVNode(a.resolveComponent("el-row"),a.mergeProps({gutter:h.value?0:15},v),K(i=Q(c.value??[]))?i:{default:()=>[i]}):a.createVNode(a.resolveComponent("el-space"),a.mergeProps({style:f??"width: 100%"},y),K(r=Q(c.value??[]))?r:{default:()=>[r]}))]}}),((L=t.footer)==null?void 0:L.call(t))??(g?a.h(g):null)])},de=()=>{const{loading:i,loadingConfig:r,containerClass:d}=u.value;return a.withDirectives(a.createVNode("div",{className:["mineadmin-form",d],"element-loading-svg":(r==null?void 0:r.svg)??'<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 1024 1024"><path fill="currentColor" d="M512 64a32 32 0 0 1 32 32v192a32 32 0 0 1-64 0V96a32 32 0 0 1 32-32m0 640a32 32 0 0 1 32 32v192a32 32 0 1 1-64 0V736a32 32 0 0 1 32-32m448-192a32 32 0 0 1-32 32H736a32 32 0 1 1 0-64h192a32 32 0 0 1 32 32m-640 0a32 32 0 0 1-32 32H96a32 32 0 0 1 0-64h192a32 32 0 0 1 32 32M195.2 195.2a32 32 0 0 1 45.248 0L376.32 331.008a32 32 0 0 1-45.248 45.248L195.2 240.448a32 32 0 0 1 0-45.248m452.544 452.544a32 32 0 0 1 45.248 0L828.8 783.552a32 32 0 0 1-45.248 45.248L647.744 692.992a32 32 0 0 1 0-45.248M828.8 195.264a32 32 0 0 1 0 45.184L692.992 376.32a32 32 0 0 1-45.248-45.248l135.808-135.808a32 32 0 0 1 45.248 0m-452.544 452.48a32 32 0 0 1 0 45.248L240.448 828.8a32 32 0 0 1-45.248-45.248l135.808-135.808a32 32 0 0 1 45.248 0"/></svg>',"element-loading-svg-view-box":(r==null?void 0:r.viewBox)??"-9, -9, 50, 50","element-loading-text":(r==null?void 0:r.text)??null,"element-loading-spinner":(r==null?void 0:r.spinner)??null,"element-loading-background":(r==null?void 0:r.spinner)??null,"element-loading-custom-class":(r==null?void 0:r.customClass)??null},[nt()]),[[a.resolveDirective("loading"),i]])},ve=i=>c.value=i;return o({setLoadingState:i=>u.value.loading=i,setOptions:i=>u.value=Object.assign(u.value,i),getOptions:()=>u.value,setItems:ve,getItems:()=>c.value,appendItem:i=>c.value.push(i),removeItem:i=>ve(c.value.filter(r=>(typeof r.prop=="function"?r.prop():r.prop)!==i)),getItemByProp:i=>{var r;return((r=c.value.filter(d=>(typeof d.prop=="function"?d.prop():d.prop)===i))==null?void 0:r[0])??null},isMobileState:()=>h.value,getElFormRef:()=>_.value}),()=>j.ssr?M.value&&de():de()}}),pe={install(e,t){e.component(fe.name,fe),e.provide("MaFormOptions",t??{ssr:!1})}};m.MaForm=pe,m.default=pe,m.useForm=function(e){return new Promise((t,n)=>{const o=a.getCurrentInstance();a.onMounted(async()=>{await a.nextTick(()=>{if(o&&o.refs[e]){const l=o.refs[e];t({...l})}else n("[@mineadmin/form]: not found ref for ma-form component")})})})},Object.defineProperties(m,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});