Merge pull request #8631 from lurunze1226/fix-crud-filter-strict

fix: CRUD组件使用非严格比较导致部分场景query无法更新问题
This commit is contained in:
wutong 2023-11-06 17:43:36 +08:00 committed by GitHub
commit a0135c46ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 5 deletions

View File

@ -141,7 +141,32 @@ export const CRUDStore = ServiceStore.named('CRUDStore')
...values
};
if (isObjectShallowModified(originQuery, query, false)) {
/**
* CASE
* @reference https://tc39.es/ecma262/#sec-islooselyequal
*/
const exceptedLooselyRules: [any, any][] = [
[0, ''],
[false, ''],
[false, '0'],
[false, 0],
[true, 1],
[true, '1']
];
if (
isObjectShallowModified(originQuery, query, (lhs: any, rhs: any) => {
if (
exceptedLooselyRules.some(
rule => rule.includes(lhs) && rule.includes(rhs)
)
) {
return lhs === rhs;
}
return lhs == rhs;
})
) {
if (query[pageField || 'page']) {
self.page = parseInt(query[pageField || 'page'], 10);
}

View File

@ -251,7 +251,7 @@ export function rmUndefined(obj: PlainObject) {
export function isObjectShallowModified(
prev: any,
next: any,
strictMode: boolean = true,
strictModeOrFunc: boolean | ((lhs: any, rhs: any) => boolean) = true,
ignoreUndefined: boolean = false,
statck: Array<any> = []
): boolean {
@ -262,7 +262,7 @@ export function isObjectShallowModified(
isObjectShallowModified(
prev,
next[index],
strictMode,
strictModeOrFunc,
ignoreUndefined,
statck
)
@ -281,7 +281,11 @@ export function isObjectShallowModified(
isObservable(prev) ||
isObservable(next)
) {
return strictMode ? prev !== next : prev != next;
if (strictModeOrFunc && typeof strictModeOrFunc === 'function') {
return strictModeOrFunc(prev, next);
}
return strictModeOrFunc ? prev !== next : prev != next;
}
if (ignoreUndefined) {
@ -311,7 +315,7 @@ export function isObjectShallowModified(
isObjectShallowModified(
prev[key],
next[key],
strictMode,
strictModeOrFunc,
ignoreUndefined,
statck
)