import type { Menu as MenuType } from '/@/router/types'; import type { PropType } from 'vue'; import { defineComponent } from 'vue'; import Icon from '/@/components/Icon/index'; export default defineComponent({ name: 'MenuContent', props: { searchValue: { type: String as PropType, default: '', }, item: { type: Object as PropType, default: null, }, showTitle: { type: Boolean as PropType, default: true, }, level: { type: Number as PropType, default: 0, }, }, setup(props) { /** * @description: 渲染图标 */ function renderIcon(icon: string) { return icon ? : null; } return () => { if (!props.item) { return null; } const { showTitle } = props; const { name, icon } = props.item; const searchValue = props.searchValue || ''; const index = name.indexOf(searchValue); const beforeStr = name.substr(0, index); const afterStr = name.substr(index + searchValue.length); return ( <> {renderIcon(icon!)} {index > -1 && searchValue ? ( {beforeStr} {searchValue} {afterStr} ) : ( {name} )} ); }; }, });