mirror of
https://gitee.com/baidu/amis.git
synced 2024-12-02 20:09:08 +08:00
fix(amis-saas-8898): 组件搜索兼容特殊字符
Change-Id: Ie5c922713a002b52be1aff20e3037d09dd6a0a40
This commit is contained in:
parent
f353639ab5
commit
d293cdeaf2
@ -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)) {
|
||||
|
@ -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()
|
||||
|
@ -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, '');
|
||||
}
|
Loading…
Reference in New Issue
Block a user