From b0ac53f737ca2ec499fd9775fb679d416a950341 Mon Sep 17 00:00:00 2001 From: vermilionAnd <61216850+zhuzilv@users.noreply.github.com> Date: Mon, 6 Nov 2023 11:57:19 +0800 Subject: [PATCH] feat(table): table filter add match-pinyin (#2210) Co-authored-by: vermilionAnd --- src/table/FilterPopover.tsx | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/table/FilterPopover.tsx b/src/table/FilterPopover.tsx index 83aa81a746..18a253660b 100644 --- a/src/table/FilterPopover.tsx +++ b/src/table/FilterPopover.tsx @@ -1,6 +1,7 @@ import React, { useState, useContext, useEffect } from 'react'; import { invoke, isFunction, isObject } from 'lodash'; import { useLocale } from '@gio-design/utils'; +import pinyinMatch from 'pinyin-match'; import Button from '../button'; import Popover from '../popover'; import FilterList from './FilterList'; @@ -25,6 +26,13 @@ interface FilterPopoverProps { singleSelectDefaultValue?: string; } +function isContain(target = '', source = ''): boolean { + if (source === '') { + return true; + } + return !!pinyinMatch.match(target, source); +} + const FilterPopover = (props: FilterPopoverProps): React.ReactElement => { const locale = useLocale('Table'); const { clearText, okText, searchText }: typeof defaultLocale = { @@ -116,9 +124,9 @@ const FilterPopover = (props: FilterPopoverProps): React.ReactElement => { dataSource={filters .filter((item) => { if (isObject(item)) { - return item.label.includes(searchValue); + return isContain(item.label, searchValue); } - return item.toString().includes(searchValue); + return isContain(item.toString(), searchValue); }) .map((item) => { if (isObject(item)) {