diff --git a/packages/amis-core/src/store/crud.ts b/packages/amis-core/src/store/crud.ts index f89d4dcb0..3eb535c6d 100644 --- a/packages/amis-core/src/store/crud.ts +++ b/packages/amis-core/src/store/crud.ts @@ -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); } diff --git a/packages/amis-core/src/utils/helper.ts b/packages/amis-core/src/utils/helper.ts index a91b06203..c399e9155 100644 --- a/packages/amis-core/src/utils/helper.ts +++ b/packages/amis-core/src/utils/helper.ts @@ -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 = [] ): 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 )