diff --git a/packages/amis-core/src/store/table.ts b/packages/amis-core/src/store/table.ts index bb490f88c32..4aab0ce9b16 100644 --- a/packages/amis-core/src/store/table.ts +++ b/packages/amis-core/src/store/table.ts @@ -58,7 +58,7 @@ function initChildren( item }; const id = String( - getEntryId ? getEntryId(item, index) : item.__id ?? guid() + getEntryId ? getEntryId(item, index) : (item.__id ?? guid()) ); return { @@ -423,7 +423,7 @@ export const Row = types }, change(values: object, savePristine?: boolean) { - let data = immutableExtends(self.data, values); + let data = immutableExtends(self.data, values, true); Object.isExtensible(data) && !data.__pristine && @@ -653,13 +653,13 @@ export const TableStore = iRendererStore !self.hideCheckToggler && self.rows.length : item.type === '__dragme' - ? self.dragging - : item.type === '__expandme' - ? getFootableColumns().length && !self.dragging - : (item.toggled || !item.toggable) && - (!self.footable || - !item.breakpoint || - !isBreakpoint(item.breakpoint))) + ? self.dragging + : item.type === '__expandme' + ? getFootableColumns().length && !self.dragging + : (item.toggled || !item.toggable) && + (!self.footable || + !item.breakpoint || + !isBreakpoint(item.breakpoint))) ); } @@ -1434,8 +1434,8 @@ export const TableStore = iRendererStore typeof column.pristine.width === 'number' ? `width: ${column.pristine.width}px;` : column.pristine.width - ? `width: ${column.pristine.width};min-width: ${column.pristine.width};` - : '' // todo 可能需要让修改过列宽的保持相应宽度,目前这样相当于重置了 + ? `width: ${column.pristine.width};min-width: ${column.pristine.width};` + : '' // todo 可能需要让修改过列宽的保持相应宽度,目前这样相当于重置了 }`; }); @@ -1582,7 +1582,7 @@ export const TableStore = iRendererStore } let id = String( - getEntryId ? getEntryId(item, index) : item.__id ?? guid() + getEntryId ? getEntryId(item, index) : (item.__id ?? guid()) ); return { // id: getEntryId ? getEntryId(item, key) : String(item && (item as any)[self.primaryField] || `${key}-1-${key}`), diff --git a/packages/amis-core/src/store/table2.ts b/packages/amis-core/src/store/table2.ts index 6853a6c6d08..042abf385fe 100644 --- a/packages/amis-core/src/store/table2.ts +++ b/packages/amis-core/src/store/table2.ts @@ -189,7 +189,7 @@ export const Row = types } }, change(values: object, savePristine?: boolean) { - self.data = immutableExtends(self.data, values); + self.data = immutableExtends(self.data, values, true); savePristine && (self.pristine = self.data); }, reset() { diff --git a/packages/amis-core/src/utils/helper.ts b/packages/amis-core/src/utils/helper.ts index b21f871bb5b..2ffac7116bc 100644 --- a/packages/amis-core/src/utils/helper.ts +++ b/packages/amis-core/src/utils/helper.ts @@ -395,12 +395,15 @@ export function immutableExtends(to: any, from: any, deep = false) { Object.keys(from).forEach(key => { const origin = to[key]; const value = from[key]; + let newValue = value; + if (deep && isObject(origin) && isObject(value)) { + newValue = immutableExtends(origin, value, deep); + } - // todo 支持深度merge - if (origin !== value) { + if (origin !== newValue) { // 一旦有修改,就创建个新对象。 ret = ret !== to ? ret : {...to}; - ret[key] = value; + ret[key] = newValue; } }); @@ -466,7 +469,7 @@ export function isVisible( const name = filter(schema.name, data); const visible = isAlive(statusStore) - ? statusStore.visibleState[id] ?? statusStore.visibleState[name] + ? (statusStore.visibleState[id] ?? statusStore.visibleState[name]) : undefined; if (typeof visible !== 'undefined') { @@ -539,8 +542,11 @@ export function hasAbility( return schema.hasOwnProperty(ability) ? schema[ability] : schema.hasOwnProperty(`${ability}On`) - ? evalExpressionWithConditionBuilder(schema[`${ability}On`], data || schema) - : defaultValue; + ? evalExpressionWithConditionBuilder( + schema[`${ability}On`], + data || schema + ) + : defaultValue; } export function makeHorizontalDeeper( @@ -1675,8 +1681,8 @@ export function chainFunctions( ret === false ? false : typeof fn == 'function' - ? fn(...args) - : undefined, + ? fn(...args) + : undefined, undefined ); }