/** * @description vue version tree * @author Jobin * @date 2023/6/24 23:27 * @version v1.0.0 */ import { defineComponent, h, resolveComponent } from 'vue'; import MCheckbox from '../checkbox/MCheckbox'; import { treeNodeProps } from './api.ts'; import { TreeNodeProps } from './treeNode'; type TreeChildren = any; // todo fix this type,maybe use generics export default defineComponent((_props: TreeNodeProps, { attrs }) => { const props = _props as Required; return () => { const { label: l, key: k, children: c } = props.config; const MTreeNode = resolveComponent('MTreeNode'); return <> { props.data.map(d => { const children = d[c] ?? []; const cKeys = children.map((it: TreeChildren) => it[k]); const childNodes = props.getNodesByKeys(cKeys); const icon = childNodes.length > 0 ? props.handleExpand(d, e)}> : null; const checkbox = props.checkbox ? // @ts-ignore todo fix this type props.handleCheck(d, checked)}> props.handleItemClick(d, e)}>{d[l]} : props.handleItemClick(d, e)}>{d[l]} ; return
{icon} {checkbox} {(childNodes.length > 0 && d.expand) ?
{h(MTreeNode, { ...props, data: childNodes })}
: null}
; }) } ; }; }, { name: 'MTreeNode', props: treeNodeProps, inheritAttrs: false, });