diff --git a/packages/amis-core/src/WithStore.tsx b/packages/amis-core/src/WithStore.tsx index bb57467ca..165ef001d 100644 --- a/packages/amis-core/src/WithStore.tsx +++ b/packages/amis-core/src/WithStore.tsx @@ -245,8 +245,12 @@ export function HocStoreFactory(renderer: { ...store.data, ...props.data } + : // combo 不需要同步,如果要同步,在 Combo.tsx 里面已经实现了相关逻辑 + // 目前主要的问题是,如果 combo 中表单项名字和 combo 本身的名字一样,会导致里面的值会被覆盖成数组 + props.store?.storeType === 'ComboStore' + ? undefined : syncDataFromSuper( - props.data, + store.data, (props.data as any).__super, (prevProps.data as any).__super, store, diff --git a/packages/amis/__tests__/renderers/Form/combo.test.tsx b/packages/amis/__tests__/renderers/Form/combo.test.tsx index 524657ef4..eb602857e 100644 --- a/packages/amis/__tests__/renderers/Form/combo.test.tsx +++ b/packages/amis/__tests__/renderers/Form/combo.test.tsx @@ -970,3 +970,35 @@ test('Renderer:select autofill in combo', async () => { combo: [{type: '1', a: 'a'}] }); }); + +// 10. combo 内部表单项与 combo 同名时,原来会出现内部表单项的值变成数组的情况 +test('Renderer:combo 内部表单项与 combo 同名', async () => { + const {container, submitBtn, findByText, onSubmit, baseElement} = await setup( + [ + { + type: 'combo', + name: 'a', + label: 'combo', + className: 'removableFalse', + removable: false, + multiple: true, + items: [ + { + name: 'a', + type: 'input-text', + label: 'A' + } + ], + value: [{}] + } + ] + ); + + const input = container.querySelector('input[name="a"]') as HTMLInputElement; + fireEvent.change(input, {target: {value: '1'}}); + await wait(400); + + fireEvent.change(input, {target: {value: '123'}}); + await wait(400); + expect(input.value).toBe('123'); +}); diff --git a/packages/amis/src/renderers/Form/InputTable.tsx b/packages/amis/src/renderers/Form/InputTable.tsx index e3719b625..820bfd8aa 100644 --- a/packages/amis/src/renderers/Form/InputTable.tsx +++ b/packages/amis/src/renderers/Form/InputTable.tsx @@ -1527,11 +1527,14 @@ export default class FormTable extends React.Component { let items = this.state.items; let showPager = false; - const page = this.state.page || 1; + let page = this.state.page || 1; let offset = 0; let lastPage = 1; if (typeof perPage === 'number' && perPage && items.length > perPage) { lastPage = Math.ceil(items.length / perPage); + if (page > lastPage) { + page = lastPage; + } items = items.slice((page - 1) * perPage, page * perPage); showPager = true; offset = (page - 1) * perPage; @@ -1611,7 +1614,8 @@ export default class FormTable extends React.Component { }, { activePage: page, - lastPage: lastPage, + perPage, + total: this.state.items.length, onPageChange: this.handlePageChange, className: 'InputTable-pager' } diff --git a/vite.config.ts b/vite.config.ts index ea9fdb7f3..17c70cc06 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -62,7 +62,8 @@ export default defineConfig({ }), monacoEditorPlugin({}), replace({ - __editor_i18n: !!I18N + __editor_i18n: !!I18N, + preventAssignment: true }) ].filter(n => n), optimizeDeps: {