/*! * @form-create/component-elm-tree v3.2.0 * (c) 2018-2024 xaboy * Github https://github.com/xaboy/form-create with tree * Released under the MIT License. */ import { defineComponent, createVNode, resolveComponent, mergeProps } from 'vue'; function toArray(value) { return Array.isArray(value) ? value : [null, undefined, ''].indexOf(value) > -1 ? [] : [value]; } var NAME = 'fcTree'; var Tree = defineComponent({ name: NAME, inheritAttrs: false, formCreateParser: { mergeProp: function mergeProp(ctx) { var props = ctx.prop.props; if (!props.nodeKey) props.nodeKey = 'id'; if (!props.props) props.props = { label: 'title' }; } }, props: { type: String, modelValue: { type: [Array, String, Number], "default": function _default() { return []; } } }, emits: ['update:modelValue', 'fc.el'], watch: { modelValue: function modelValue() { this.setValue(); } }, methods: { updateValue: function updateValue() { if (!this.$refs.tree) return; var value; if (this.type === 'selected') { value = this.$refs.tree.getCurrentKey(); } else { value = this.$refs.tree.getCheckedKeys(); } this.$emit('update:modelValue', value); }, setValue: function setValue() { if (!this.$refs.tree) return; var type = this.type; if (type === 'selected') { this.$refs.tree.setCurrentKey(this.modelValue); } else { this.$refs.tree.setCheckedKeys(toArray(this.modelValue)); } } }, render: function render() { return createVNode(resolveComponent("ElTree"), mergeProps(this.$attrs, { "ref": "tree", "onCheck": this.updateValue, "onNode-click": this.updateValue }), this.$slots); }, mounted: function mounted() { this.setValue(); this.$emit('fc.el', this.$refs.tree); } }); export { Tree as default };