丰富了,支持更多语义

This commit is contained in:
Xu Chang 2025-06-09 15:42:37 +08:00
parent e36cf430cf
commit ff0fcc8492
4 changed files with 42 additions and 7 deletions

View File

@ -569,11 +569,16 @@ export default class TreeStore extends CascadeStore {
case '$length': {
// json中的数组长度查询
const length = value;
assert(typeof length === 'number');
return (row) => {
const data = path ? get(row, path) : row;
assert(data instanceof Array, '$length operator can only used on array attribute');
return data.length === length;
if (typeof length === 'number') {
return data.length === length;
}
else {
const op = Object.keys(length)[0];
return this.translatePredicate(entity, length, op, length[op], option)(data);
}
};
}
default: {

View File

@ -571,11 +571,16 @@ class TreeStore extends CascadeStore_1.CascadeStore {
case '$length': {
// json中的数组长度查询
const length = value;
(0, assert_1.assert)(typeof length === 'number');
return (row) => {
const data = path ? (0, lodash_1.get)(row, path) : row;
(0, assert_1.assert)(data instanceof Array, '$length operator can only used on array attribute');
return data.length === length;
if (typeof length === 'number') {
return data.length === length;
}
else {
const op = Object.keys(length)[0];
return this.translatePredicate(entity, length, op, length[op], option)(data);
}
};
}
default: {

View File

@ -710,11 +710,16 @@ export default class TreeStore<ED extends EntityDict & BaseEntityDict> extends C
case '$length': {
// json中的数组长度查询
const length = value;
assert (typeof length === 'number');
return (row) => {
const data = path ? get(row, path) : row;
assert(data instanceof Array, '$length operator can only used on array attribute');
return data.length === length;
if (typeof length === 'number') {
return data.length === length;
}
else {
const op = Object.keys(length)[0];
return this.translatePredicate(entity, length, op, length[op], option)(data);
}
}
}
default: {

View File

@ -1317,7 +1317,6 @@ describe('基础测试', function () {
}
}, context, {});
const row12 = store.select('oper', {
data: {
id: 1,
@ -1335,6 +1334,26 @@ describe('基础测试', function () {
}
}
}, context, {});
const row13 = store.select('oper', {
data: {
id: 1,
data: {
name: 1,
price: 1,
},
},
filter: {
id,
data: {
price: {
$length: {
$gt: 3,
},
},
}
}
}, context, {});
context.commit();
assert(row.length === 1);
assert(row2.length === 0);
@ -1348,6 +1367,7 @@ describe('基础测试', function () {
assert(row10.length === 1);
assert(row11.length === 0);
assert(row12.length === 1);
assert(row13.length === 0);
// console.log(JSON.stringify(row7));
});