mirror of
https://gitee.com/baidu/amis.git
synced 2024-11-29 18:39:05 +08:00
fix: 页面设计器组件搜索改用matchSorter
This commit is contained in:
parent
6ed6cb89d3
commit
33bc90e828
@ -4,6 +4,7 @@ import {Icon, InputBox, resolveVariable} from 'amis';
|
||||
import cx from 'classnames';
|
||||
import {autobind, stringRegExp} from '../../util';
|
||||
import isString from 'lodash/isString';
|
||||
import {matchSorter} from 'match-sorter';
|
||||
|
||||
/**
|
||||
* 通用搜索功能组件,附带以下功能:
|
||||
@ -182,7 +183,7 @@ export default class SearchPanel extends React.Component<
|
||||
/**
|
||||
* 根据关键字过滤数据,按分组存放
|
||||
*/
|
||||
groupedResultByKeyword(keywords?: string) {
|
||||
groupedResultByKeyword(keywords: string = '') {
|
||||
const {allResult} = this.props;
|
||||
let curSearchResult: any[] = [];
|
||||
let curSearchResultByTag: {
|
||||
@ -194,21 +195,15 @@ export default class SearchPanel extends React.Component<
|
||||
? new RegExp(stringRegExp(curKeyword), 'i')
|
||||
: null;
|
||||
|
||||
allResult.forEach(item => {
|
||||
if (isString(item) && regular && regular.test(item)) {
|
||||
if (allResult.length && isString(allResult[0])) {
|
||||
matchSorter(allResult, keywords).forEach(item => {
|
||||
// 兼容字符串类型
|
||||
curSearchResult.push(item);
|
||||
} else if (
|
||||
!keywords ||
|
||||
['name', 'description', 'scaffold.type', 'searchKeywords'].some(key => {
|
||||
return (
|
||||
resolveVariable(key, item) &&
|
||||
regular &&
|
||||
(regular.test(resolveVariable(key, item)) ||
|
||||
regular.test(resolveVariable(key, item)?.replaceAll('-', '')))
|
||||
);
|
||||
})
|
||||
) {
|
||||
});
|
||||
} else {
|
||||
matchSorter(allResult, keywords, {
|
||||
keys: ['name', 'description', 'scaffold.type', 'searchKeywords']
|
||||
}).forEach(item => {
|
||||
if (item[curTagKey]) {
|
||||
const tags = Array.isArray(item[curTagKey])
|
||||
? item[curTagKey].concat()
|
||||
@ -222,8 +217,8 @@ export default class SearchPanel extends React.Component<
|
||||
} else {
|
||||
curSearchResult.push(item);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// 更新当前搜索结果数据(备注: 附带重置功能)
|
||||
this.setState({
|
||||
|
@ -53,6 +53,7 @@ import isPlainObject from 'lodash/isPlainObject';
|
||||
import {EditorManagerConfig} from '../manager';
|
||||
import {EditorNode, EditorNodeType} from './node';
|
||||
import findIndex from 'lodash/findIndex';
|
||||
import {matchSorter} from 'match-sorter';
|
||||
|
||||
export interface SchemaHistory {
|
||||
versionId: number;
|
||||
@ -684,39 +685,26 @@ export const MainStore = types
|
||||
/** 根据关键字过滤组件 */
|
||||
groupedRenderersByKeyword(
|
||||
_subRenderers: Array<SubRendererInfo>,
|
||||
keywords?: string
|
||||
keywords: string = ''
|
||||
) {
|
||||
const subRenderers = _subRenderers;
|
||||
const grouped: {
|
||||
[propName: string]: Array<SubRendererInfo>;
|
||||
} = {};
|
||||
|
||||
const regular = keywords
|
||||
? new RegExp(stringRegExp(keywords), 'i')
|
||||
: null;
|
||||
matchSorter(subRenderers, keywords, {
|
||||
keys: ['name', 'description', 'scaffold.type', 'searchKeywords']
|
||||
}).forEach(item => {
|
||||
const tags = Array.isArray(item.tags)
|
||||
? item.tags.concat()
|
||||
: item.tags
|
||||
? [item.tags]
|
||||
: ['其他'];
|
||||
|
||||
subRenderers.forEach(item => {
|
||||
if (
|
||||
!keywords ||
|
||||
['name', 'description', 'scaffold.type', 'searchKeywords'].some(
|
||||
key =>
|
||||
resolveVariable(key, item) &&
|
||||
regular &&
|
||||
(regular.test(resolveVariable(key, item)) ||
|
||||
regular.test(resolveVariable(key, item)?.replaceAll('-', '')))
|
||||
)
|
||||
) {
|
||||
const tags = Array.isArray(item.tags)
|
||||
? item.tags.concat()
|
||||
: item.tags
|
||||
? [item.tags]
|
||||
: ['其他'];
|
||||
|
||||
tags.forEach(tag => {
|
||||
grouped[tag] = grouped[tag] || [];
|
||||
grouped[tag].push(item);
|
||||
});
|
||||
}
|
||||
tags.forEach(tag => {
|
||||
grouped[tag] = grouped[tag] || [];
|
||||
grouped[tag].push(item);
|
||||
});
|
||||
});
|
||||
|
||||
return grouped;
|
||||
|
Loading…
Reference in New Issue
Block a user