import { Show, createSignal } from "solid-js"; import { InnerCheckbox } from "../inner/Checkbox"; import { SubNodes } from "./SubNodes"; import { useTreeContext } from "."; import { Loading } from "../inner/Loading"; export function Node (props: any) { const ctx: any = useTreeContext(); const [loading, setLoading] = createSignal(false); const style = () => ({ 'padding-left': props.level * props.gutter + 'px' }) const opened = () => { return props.store.dataMap[props.data.id]._opened; } const selected = () => { return props.store.dataMap[props.data.id]._selected; } const classList = () => ({ 'cm-tree-item': true, 'cm-tree-item-open': opened(), 'cm-tree-item-selected': selected() }) const icon = () => { let icon = props.directory? (hasChildren() ? : ) : null; if (props.data.icon) { icon = {props.data.icon}; } return icon; } const onSelect = () => { if (props.store.dataMap[props.data.id].disabled) { return; } ctx && ctx.onSelect && ctx.onSelect(props.data); } const onOpenClose = async () => { if (ctx) { // 需要异步加载数据 const item = props.store.dataMap[props.data.id]; if (item.loading && ctx.loadData) { setLoading(true); try { const ret = await ctx.loadData(props.data); if (!(ret instanceof Array)) { ctx.addChildren(item.id, props.data, [ret]); } else { ctx.addChildren(item.id, props.data, ret); } ctx.cancelLoading(item.id); } catch (e) { } finally { setLoading(false); } } ctx.onOpenClose(props.data.id); } } const onChecked = (checked: boolean) => { ctx && ctx.onChecked(props.data.id, checked); } const hasChildren = () => props.data.children && props.data.children.length || props.data.loading; const checkStatus = () => { let checked: number | string = 0; checked = props.store.checkedMap[props.data.id]; if (checked === 2) { return 'indeterminate'; } return checked === 1; } const onContextMenu = (e: any) => { if (ctx && ctx.contextMenu) { // e.stopImmediatePropagation && e.stopImmediatePropagation(); // e.preventDefault && e.preventDefault(); // e.stopPropagation && e.stopPropagation(); ctx.onContextMenu && ctx.onContextMenu({...props.data}); } } return
  • }> {icon()} {props.data.title} {props.data.patch ? {props.data.patch} : null}
  • }