import { use } from '../utils'; import { emit, inherit } from '../utils/functional'; import Icon from '../icon'; // Types import { CreateElement, RenderContext } from 'vue/types'; import { DefaultSlots } from '../utils/use/sfc'; export type TreeSelectItem = { text: string; disabled?: boolean; children: TreeSelectChildren[]; }; export type TreeSelectChildren = { id: number; text: string; disabled?: boolean; }; export type TreeSelectProps = { height: number; items: TreeSelectItem[]; activeId: number | string; mainActiveIndex: number; }; const [sfc, bem] = use('tree-select'); function TreeSelect( h: CreateElement, props: TreeSelectProps, slots: DefaultSlots, ctx: RenderContext ) { const { height, items, mainActiveIndex, activeId } = props; const selectedItem = items[mainActiveIndex] || {}; const subItems = selectedItem.children || []; return (
{items.map((item, index) => (
{ if (!item.disabled) { emit(ctx, 'navclick', index); } }} > {item.text}
))}
{subItems.map(item => (
{ if (!item.disabled) { emit(ctx, 'itemclick', item); } }} > {item.text} {activeId === item.id && ( )}
))}
); } TreeSelect.props = { items: Array, mainActiveIndex: Number, activeId: { type: [Number, String], default: 0 }, height: { type: Number, default: 300 } }; export default sfc(TreeSelect);