// Utils import { createNamespace, addUnit } from '../utils'; // Components import Icon from '../icon'; import Sidebar from '../sidebar'; import SidebarItem from '../sidebar-item'; const [createComponent, bem] = createNamespace('tree-select'); export default createComponent({ props: { max: { type: [Number, String], default: Infinity, }, items: { type: Array, default: () => [], }, height: { type: [Number, String], default: 300, }, activeId: { type: [Number, String, Array], default: 0, }, selectedIcon: { type: String, default: 'success', }, mainActiveIndex: { type: [Number, String], default: 0, }, }, emits: [ 'click-nav', 'click-item', 'update:activeId', 'update:mainActiveIndex', ], setup(props, { emit, slots }) { const isMultiple = () => Array.isArray(props.activeId); const isActiveItem = (id) => { return isMultiple() ? props.activeId.indexOf(id) !== -1 : props.activeId === id; }; const renderSubItem = (item) => { const onClick = () => { if (item.disabled) { return; } let activeId; if (isMultiple()) { activeId = props.activeId.slice(); const index = activeId.indexOf(item.id); if (index !== -1) { activeId.splice(index, 1); } else if (activeId.length < props.max) { activeId.push(item.id); } } else { activeId = item.id; } emit('update:activeId', activeId); emit('click-item', item); }; return (