import React, { FC, useContext, ReactNode } from 'react'; import { ConfigProvider, Input, Dropdown, Tooltip, Button, DataNode as TreeDataNode, Tree as BoxTree, TreeProps as BoxTreeProps, TreeProps, InputProps, DropDownProps, SelectProps, Select } from '@zhst/meta'; import { IconFont } from '@zhst/icon'; import classNames from 'classnames'; import './index.less' import { ButtonProps } from 'antd'; export interface IOption { type?: ButtonProps['type'] & 'dropdown'; label: string key: string icon?: string | ReactNode disabled?: boolean; showTooltip?: boolean; onClick?: () => void className?: string; dropdownConfig?: DropDownProps } export interface ITag { label: string value: string icon?: ReactNode parentNode?: string children?: ITag[] } export interface TreePanelProps { treeType?: 'directory' | 'normal' searchInputProps?: InputProps showOptions?: boolean showSelectBar?: boolean // 显示搜索框 filterSelectProps?: SelectProps onSelect?: SelectProps['onChange'] treeProps?: Partial data: TreeDataNode[] onSearch?: (e: any) => void onItemCheck?: TreeProps['onCheck'] onItemSelect?: TreeProps['onSelect'] customImport?: ReactNode | string // 自定义搜索栏边上的过滤图标 extra?: ReactNode | string // 搜索栏下面的插槽 prefixCls?: string showSearchBar?: boolean // 是否显示搜索栏 noFilter?: boolean // 是否显示搜索拓展 icon filterList?: IOption[] optionList?: IOption[] showTagPanel?: boolean // 标签插槽 tagList?: ITag[] // 标签列表 tagExpandAll?: boolean // 展开所有 onTagCheck?: (value: string, tag: ITag) => void; checkedTags?: string[] onResetTags?: () => void onTagExpand?: (e: any) => void tagFootRender?: ReactNode } const { ConfigContext } = ConfigProvider const { DirectoryTree } = BoxTree const TreePanel: FC = (props) => { const { treeType = 'directory', searchInputProps, showOptions = true, showSelectBar, filterSelectProps, extra, noFilter, data = [], treeProps, onSelect, onSearch, onItemCheck, onItemSelect, showSearchBar = true, optionList = [], filterList = [], showTagPanel, tagList, tagExpandAll, onTagExpand, checkedTags = [], onTagCheck, onResetTags, tagFootRender, prefixCls: customizePrefixCls, customImport: customFilter } = props const { getPrefixCls } = useContext(ConfigContext); const componentName = getPrefixCls('biz-tree-panel', customizePrefixCls); const CurrentTree = treeType === 'directory' ? DirectoryTree : BoxTree /** * 初始化拓展 filter * @param _list * @returns */ const initFilter = (_list?: TreePanelProps['filterList']) => { const WithDropdown = (dom: ReactNode, isShow?: boolean, _config?: DropDownProps) => { if (!isShow) { return dom } return ( {dom} ) } return _list?.map(item => ( {WithDropdown(