zmdms-webui 3.5.1 → 3.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -150,6 +150,38 @@ function useControlled(props, option) {
150
150
  };
151
151
  }
152
152
  var NULL_SIGN = "__null__";
153
+ /** 匹配形似数字的字符串:可选正负号、千分符、小数、尾部百分号 */
154
+ var NUMERIC_LIKE_REGEXP = /^[+-]?(\d{1,3}(,\d{3})+|\d+)(\.\d+)?%?$/;
155
+ /**
156
+ * 将格式化的数值(千分符、百分号)解析为数字,用于过滤时的数值比较。
157
+ * 非形似数字的文本返回 null,不影响文本列的原有匹配逻辑。
158
+ * 百分比按显示值解析("12.5%" -> 12.5),与页面展示口径保持一致。
159
+ */
160
+ function parseNumericLike(value) {
161
+ if (typeof value === "number") {
162
+ return Number.isFinite(value) ? value : null;
163
+ }
164
+ if (typeof value !== "string") {
165
+ return null;
166
+ }
167
+ var str = value.trim();
168
+ if (!NUMERIC_LIKE_REGEXP.test(str)) {
169
+ return null;
170
+ }
171
+ var num = Number(str.replace(/,/g, "").replace(/%$/, ""));
172
+ return Number.isFinite(num) ? num : null;
173
+ }
174
+ /**
175
+ * 数值优先比较:过滤值与当前值都能识别为数字时按数值比较(兼容千分符、百分号格式化值),
176
+ * 否则回退为原有行为(隐式类型比较)
177
+ */
178
+ function compareValues(subStr, currentValue, currentNumeric, comparator) {
179
+ var subNumeric = parseNumericLike(subStr);
180
+ if (currentNumeric != null && subNumeric != null) {
181
+ return comparator(currentNumeric, subNumeric);
182
+ }
183
+ return comparator(currentValue, Number(subStr));
184
+ }
153
185
  var isMessage = false;
154
186
  /**
155
187
  * 过滤方法
@@ -162,7 +194,6 @@ function filterHandle(value, record, key, options) {
162
194
  var _a, _b, _c, _d;
163
195
  var _e = options || {}, column = _e.column, _f = _e.recordIndex, recordIndex = _f === void 0 ? 0 : _f, _g = _e.checkbox, checkbox = _g === void 0 ? [] : _g;
164
196
  var newValue = ((_b = (_a = value === null || value === void 0 ? void 0 : value.toString) === null || _a === void 0 ? void 0 : _a.call(value)) === null || _b === void 0 ? void 0 : _b.trim()) || null; // 查询的值
165
- // const currentValue = record && key ? record[key] : null;
166
197
  var currentValue = record && key ? record[key] : null; // 当前遍历的值
167
198
  if (column === null || column === void 0 ? void 0 : column.render) {
168
199
  try {
@@ -190,30 +221,34 @@ function filterHandle(value, record, key, options) {
190
221
  return true;
191
222
  }
192
223
  if (currentValue != null && newValue != null) {
224
+ // render 可能返回千分符/百分比等格式化值,先解析出数值形式再参与比较
225
+ var currentNumeric = parseNumericLike(currentValue);
193
226
  if (newValue.startsWith("大于等于") || newValue.startsWith(">=")) {
194
- var subValue = Number(newValue.substring(newValue.startsWith("大于等于") ? 4 : 2));
195
- return currentValue >= subValue;
227
+ var subStr = newValue.substring(newValue.startsWith("大于等于") ? 4 : 2);
228
+ return compareValues(subStr, currentValue, currentNumeric, function (a, b) { return a >= b; });
196
229
  }
197
230
  if (newValue.startsWith("小于等于") || newValue.startsWith("<=")) {
198
- var subValue = Number(newValue.substring(newValue.startsWith("小于等于") ? 4 : 2));
199
- return currentValue <= subValue;
231
+ var subStr = newValue.substring(newValue.startsWith("小于等于") ? 4 : 2);
232
+ return compareValues(subStr, currentValue, currentNumeric, function (a, b) { return a <= b; });
200
233
  }
201
234
  if (newValue.startsWith("大于") || newValue.startsWith(">")) {
202
- var subValue = Number(newValue.substring(newValue.startsWith("大于") ? 2 : 1));
203
- return currentValue > subValue;
235
+ var subStr = newValue.substring(newValue.startsWith("大于") ? 2 : 1);
236
+ return compareValues(subStr, currentValue, currentNumeric, function (a, b) { return a > b; });
204
237
  }
205
238
  if (newValue.startsWith("小于") || newValue.startsWith("<")) {
206
- var subValue = Number(newValue.substring(newValue.startsWith("小于") ? 2 : 1));
207
- return currentValue < subValue;
239
+ var subStr = newValue.substring(newValue.startsWith("小于") ? 2 : 1);
240
+ return compareValues(subStr, currentValue, currentNumeric, function (a, b) { return a < b; });
208
241
  }
209
242
  if (newValue.startsWith("等于") || newValue.startsWith("=")) {
210
- var subValue = Number(newValue.substring(newValue.startsWith("等于") ? 2 : 1));
243
+ var subStr = newValue.substring(newValue.startsWith("等于") ? 2 : 1);
211
244
  // eslint-disable-next-line eqeqeq
212
- return currentValue == subValue;
245
+ return compareValues(subStr, currentValue, currentNumeric, function (a, b) { return a == b; });
213
246
  }
214
247
  // 使用eval执行代码 长度不能过长。防止一些恶意攻击
215
248
  if (newValue.indexOf("$0") !== -1 && newValue.length <= 100) {
216
- var newEvalStr = newValue.replace(/\$0/g, currentValue);
249
+ // 千分符的逗号、百分号会破坏表达式语法,可识别为数字时替换为其数值形式
250
+ var replacement = currentNumeric != null ? String(currentNumeric) : currentValue;
251
+ var newEvalStr = newValue.replace(/\$0/g, replacement);
217
252
  var result = null;
218
253
  try {
219
254
  // eslint-disable-next-line no-eval
@@ -230,7 +265,18 @@ function filterHandle(value, record, key, options) {
230
265
  }
231
266
  return result;
232
267
  }
233
- return (_d = (_c = currentValue === null || currentValue === void 0 ? void 0 : currentValue.toString()) === null || _c === void 0 ? void 0 : _c.toLowerCase()) === null || _d === void 0 ? void 0 : _d.includes(newValue.toLowerCase());
268
+ // 优先按显示文本匹配;格式化值再按数值形式匹配一次(如输入 1234 命中 1,234.56)
269
+ var currentStr = (_d = (_c = currentValue === null || currentValue === void 0 ? void 0 : currentValue.toString) === null || _c === void 0 ? void 0 : _c.call(currentValue)) !== null && _d !== void 0 ? _d : "";
270
+ if (currentStr.toLowerCase().includes(newValue.toLowerCase())) {
271
+ return true;
272
+ }
273
+ if (currentNumeric != null) {
274
+ return currentNumeric
275
+ .toString()
276
+ .toLowerCase()
277
+ .includes(newValue.toLowerCase());
278
+ }
279
+ return false;
234
280
  }
235
281
  // 空值的话排除
236
282
  if (currentValue == null || currentValue === "") {
@@ -252,4 +298,4 @@ function createFilterValue(input, checkbox) {
252
298
  return filteredValue;
253
299
  }
254
300
 
255
- export { NULL_SIGN, createFilterValue, FilterDropdown as default, filterHandle };
301
+ export { NULL_SIGN, createFilterValue, FilterDropdown as default, filterHandle, parseNumericLike };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zmdms-webui",
3
- "version": "3.5.1",
3
+ "version": "3.5.2",
4
4
  "private": false,
5
5
  "main": "dist/index.es.js",
6
6
  "module": "dist/index.es.js",