index.js 2.6 KB

123456789
  1. /*!
  2. * FormCreate 低代码表单渲染器
  3. * @form-create/component-elm-tree v2.6.3
  4. * (c) 2018-2024 xaboy
  5. * Github https://github.com/xaboy/form-create
  6. * Site https://form-create.com/
  7. * Released under the MIT License.
  8. */
  9. (function(i,o){typeof exports=="object"&&typeof module!="undefined"?module.exports=o():typeof define=="function"&&define.amd?define(o):(i=typeof globalThis!="undefined"?globalThis:i||self,i.FcTree=o())})(this,function(){"use strict";function i(r){return r&&r.__esModule&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r}function o(){return o=Object.assign?Object.assign.bind():function(r){for(var t,n=1;n<arguments.length;n++)for(var e in t=arguments[n],t)Object.prototype.hasOwnProperty.call(t,e)&&(r[e]=t[e]);return r},o.apply(this,arguments)}var a=["attrs","props","domProps"],p=["class","style","directives"],f=["on","nativeOn"],l=function(r){return r.reduce(function(t,n){for(var e in n)if(!t[e])t[e]=n[e];else if(a.indexOf(e)!==-1)t[e]=o({},t[e],n[e]);else if(p.indexOf(e)!==-1){var g=t[e]instanceof Array?t[e]:[t[e]],v=n[e]instanceof Array?n[e]:[n[e]];t[e]=[].concat(g,v)}else if(f.indexOf(e)!==-1)for(var s in n[e])if(t[e][s]){var O=t[e][s]instanceof Array?t[e][s]:[t[e][s]],A=n[e][s]instanceof Array?n[e][s]:[n[e][s]];t[e][s]=[].concat(O,A)}else t[e][s]=n[e][s];else if(e==="hook")for(var u in n[e])t[e][u]=t[e][u]?d(t[e][u],n[e][u]):n[e][u];else t[e]=n[e];return t},{})},d=function(r,t){return function(){r&&r.apply(this,arguments),t&&t.apply(this,arguments)}},c=l;const h=i(c);function y(r){return Array.isArray(r)?r:[null,void 0,""].indexOf(r)>-1?[]:[r]}function m(r,t){return Object.keys(r).reduce((n,e)=>(n.push(r[e]),n),[])}return{name:"fcTree",formCreateParser:{mergeProp(r){const t=r.prop.props;t.nodeKey||(t.nodeKey="id"),t.props||(t.props={label:"title"})}},props:{formCreateInject:{type:Object,required:!0},type:{type:String,default:"checked"},value:{type:[Array,String,Number],default:()=>[]}},watch:{value(){this.setValue()}},methods:{onChange(){this.updateValue()},updateValue(){if(!this.$refs.tree)return;const r=this.type.toLocaleLowerCase();let t;r==="selected"?t=this.$refs.tree.getCurrentKey():t=this.$refs.tree.getCheckedKeys(),this.$emit("input",t)},setValue(){this.type.toLocaleLowerCase()==="selected"?this.$refs.tree.setCurrentKey(this.value):this.$refs.tree.setCheckedKeys(y(this.value))}},render(){const r=arguments[0];return r("ElTree",h([{},this.formCreateInject.prop,{ref:"tree",on:{check:()=>this.updateValue(),"node-click":()=>this.updateValue()}}]),[m(this.$slots)])},mounted(){this.setValue(),this.$emit("fc.el",this.$refs.tree)}}});