fix(amis-saas-8898): 组件搜索兼容特殊字符

Change-Id: Ie5c922713a002b52be1aff20e3037d09dd6a0a40
This commit is contained in:
wibetter 2022-12-23 14:35:56 +08:00
parent f353639ab5
commit d293cdeaf2
3 changed files with 18 additions and 6 deletions

View File

@ -2,7 +2,7 @@ import React from 'react';
import {observer} from 'mobx-react';
import {Icon, InputBox} from 'amis';
import cx from 'classnames';
import {autobind} from '../../util';
import {autobind, stringRegExp} from '../../util';
import isString from 'lodash/isString';
/**
@ -188,12 +188,12 @@ export default class SearchPanel extends React.Component<
let curSearchResultByTag: {
[propName: string]: any[];
} = {};
const curKeyword = keywords ? keywords : this.state.curKeyword;
let curKeyword = keywords ? keywords : this.state.curKeyword;
const curTagKey = this.props.tagKey || 'tags';
const grouped: {
[propName: string]: any[];
} = {};
const regular = curKeyword ? new RegExp(curKeyword, 'i') : null;
const regular = curKeyword ? new RegExp(stringRegExp(curKeyword), 'i') : null;
allResult.forEach(item => {
if (isString(item) && regular && regular.test(item)) {

View File

@ -8,6 +8,7 @@ import {
JSONTraverse,
patchDiff,
unitFormula,
stringRegExp,
guid,
reGenerateID
} from '../../src/util';
@ -634,7 +635,8 @@ export const MainStore = types
const grouped: {
[propName: string]: Array<SubRendererInfo>;
} = {};
const regular = keywords ? new RegExp(keywords, 'i') : null;
const regular = keywords ? new RegExp(stringRegExp(keywords), 'i') : null;
subRenderers.forEach(item => {
if (
@ -746,8 +748,11 @@ export const MainStore = types
} = {
: []
};
const keywords = self.insertRenderersKeywords;
const r = new RegExp(keywords, 'i');
let keywords = self.insertRenderersKeywords;
if (keywords) {
keywords = keywords.replace(/[|\\{}()[\]^$+*?.]/g, '');
}
const r = new RegExp(stringRegExp(keywords), 'i');
self.insertRenderers
.concat()

View File

@ -933,3 +933,10 @@ export function unitFormula(insetStr: string, offsetVal: number) {
const newOffsetVal = insetNum + curOffsetVal;
return `${newOffsetVal >= 0 ? newOffsetVal : '0'}${insetUnit}`;
}
/**
*
*/
export function stringRegExp(keyword: string) {
return keyword.replace(/[|\\{}()[\]^$+*?.]/g, '');
}