|
| 1 | +function getParseSpecialCharacter() { |
| 2 | + // 特殊字符字典 |
| 3 | + const directory = ['(', ')', '(', ')', ',', ',']; |
| 4 | + const res = {}; |
| 5 | + directory.forEach((item, index) => { |
| 6 | + res[item] = `$${index}` |
| 7 | + }); |
| 8 | + return res; |
| 9 | +} |
| 10 | + |
| 11 | +function parseSpecialCharacter(str) { |
| 12 | + const directory = getParseSpecialCharacter(); |
| 13 | + for (let key in directory) { |
| 14 | + const replaceValue = directory[key]; |
| 15 | + const pattern = new RegExp(`\\${key}`, 'g'); |
| 16 | + // eslint-disable-next-line |
| 17 | + while (pattern.test(str)) { |
| 18 | + str = str.replace(pattern, replaceValue); |
| 19 | + } |
| 20 | + } |
| 21 | + return str; |
| 22 | +} |
| 23 | + |
1 | 24 | function parseCondition(filterCondition, keys) { |
2 | 25 | const str = filterCondition.replace(/&|\||>|<|=|!/g, ' '); |
3 | 26 | const arr = str.split(' ').filter((item) => item); |
4 | 27 | let result = filterCondition; |
5 | 28 | arr.forEach((item) => { |
6 | | - const key = startsWithNumber(item) && keys.find((val) => val === item); |
7 | | - if (key) { |
| 29 | + const key = keys.find((val) => val === item); |
| 30 | + if (startsWithNumber(item) && key) { |
8 | 31 | result = result.replace(key, '$' + key); |
9 | 32 | } |
| 33 | + if (key) { |
| 34 | + const res = parseSpecialCharacter(key); |
| 35 | + result = result.replace(key, res); |
| 36 | + } |
10 | 37 | }); |
11 | 38 | return result; |
12 | 39 | } |
13 | 40 |
|
14 | 41 | // 处理jsonsqlfeature, 加前缀 |
15 | 42 | function parseConditionFeature(feature) { |
16 | | - const copyValue = {}; |
17 | | - for (const key in feature) { |
| 43 | + let copyValue = {}; |
| 44 | + for (let key in feature) { |
18 | 45 | let copyKey = key; |
19 | 46 | if (startsWithNumber(key)) { |
20 | 47 | copyKey = '$' + key; |
21 | 48 | } |
| 49 | + copyKey = parseSpecialCharacter(copyKey); |
22 | 50 | copyValue[copyKey] = feature[key]; |
23 | 51 | } |
24 | 52 | return copyValue; |
|
0 commit comments