diff --git a/packages/amis-core/src/store/node.ts b/packages/amis-core/src/store/node.ts index 23ac261c2..35d584611 100644 --- a/packages/amis-core/src/store/node.ts +++ b/packages/amis-core/src/store/node.ts @@ -60,7 +60,7 @@ export const StoreNode = types callback?.(); } else if (!self.childrenIds.length) { const parent = self.parentStore; - parent?.onChildStoreDispose?.(self); + parent && isAlive(parent) && parent.onChildStoreDispose(self); destroy(self); callback?.(); // destroy(self); diff --git a/packages/amis/__tests__/event-action/__snapshots__/dialog.test.tsx.snap b/packages/amis/__tests__/event-action/__snapshots__/dialog.test.tsx.snap index f9a188a7f..b93248763 100644 --- a/packages/amis/__tests__/event-action/__snapshots__/dialog.test.tsx.snap +++ b/packages/amis/__tests__/event-action/__snapshots__/dialog.test.tsx.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`EventAction:dialog 1`] = ` +exports[`1. EventAction:dialog args 1`] = `
`; -exports[`EventAction:dialog 2`] = ` +exports[`1. EventAction:dialog args 2`] = `
`; -exports[`EventAction:dialog 3`] = ` +exports[`1. EventAction:dialog args 3`] = `
`; -exports[`EventAction:dialog 4`] = ` +exports[`1. EventAction:dialog args 4`] = `
`; -exports[`EventAction:dialog 5`] = ` +exports[`1. EventAction:dialog args 5`] = `
`; -exports[`EventAction:dialog 6`] = ` +exports[`1. EventAction:dialog args 6`] = `
`; -exports[`EventAction:dialog 7`] = ` +exports[`1. EventAction:dialog args 7`] = `
`; -exports[`EventAction:dialog args 1`] = ` +exports[`2. EventAction:dialog 1`] = `
`; -exports[`EventAction:dialog args 2`] = ` +exports[`2. EventAction:dialog 2`] = `
`; -exports[`EventAction:dialog args 3`] = ` +exports[`2. EventAction:dialog 3`] = `
`; -exports[`EventAction:dialog args 4`] = ` +exports[`2. EventAction:dialog 4`] = `
`; -exports[`EventAction:dialog args 5`] = ` +exports[`2. EventAction:dialog 5`] = `
`; -exports[`EventAction:dialog args 6`] = ` +exports[`2. EventAction:dialog 6`] = `
`; -exports[`EventAction:dialog args 7`] = ` +exports[`2. EventAction:dialog 7`] = `
{ +test('1. EventAction:dialog args', async () => { const notify = jest.fn(); const {getByText, container}: any = render( amisRender( @@ -220,7 +220,7 @@ test('EventAction:dialog args', async () => { expect(container).toMatchSnapshot(); }, 7000); -test('EventAction:dialog', async () => { +test('2. EventAction:dialog', async () => { const notify = jest.fn(); const {getByText, container}: any = render( amisRender( @@ -433,7 +433,7 @@ test('EventAction:dialog', async () => { expect(container).toMatchSnapshot(); }, 7000); -test('EventAction:dialog data', async () => { +test('3. EventAction:dialog data', async () => { const {getByText, container}: any = render( amisRender( { @@ -490,7 +490,7 @@ test('EventAction:dialog data', async () => { }); }, 7000); -test('EventAction:dialog data2', async () => { +test('4. EventAction:dialog data2', async () => { const {getByText, container}: any = render( amisRender( { @@ -639,3 +639,77 @@ test('EventAction:dialog data2', async () => { // // ); // // expect(confirm.mock.calls[0][1]).toEqual('操作确认'); // // }); + +test('5. EventAction:dialog formitem without form', async () => { + const onAction = jest.fn(); + const {getByText, container}: any = render( + amisRender( + { + type: 'page', + body: [ + { + type: 'button', + label: 'Dialog', + onEvent: { + click: { + actions: [ + { + actionType: 'dialog', + dialog: { + title: '表单页面', + body: [ + { + label: 'A', + type: 'input-text', + name: 'a' + }, + { + label: 'B', + type: 'input-text', + name: 'b' + } + ], + onEvent: { + confirm: { + actions: [ + { + actionType: 'custom', + script: onAction + } + ] + } + } + } + } + ] + } + } + } + ] + }, + {}, + makeEnv({ + getModalContainer: () => container + }) + ) + ); + + const button = getByText('Dialog'); + fireEvent.click(button); + await wait(200); + + fireEvent.change(container.querySelector('[name="a"]')!, { + target: {value: '1'} + }); + + await wait(200); + fireEvent.change(container.querySelector('[name="b"]')!, { + target: {value: '2'} + }); + + await wait(200); + fireEvent.click(getByText('确认')); + await wait(300); + expect(onAction).toHaveBeenCalled(); + expect(onAction.mock.calls[0][2].data).toMatchObject({a: '1', b: '2'}); +}); diff --git a/packages/amis/src/renderers/Dialog.tsx b/packages/amis/src/renderers/Dialog.tsx index 08dd5736e..46311f1e2 100644 --- a/packages/amis/src/renderers/Dialog.tsx +++ b/packages/amis/src/renderers/Dialog.tsx @@ -1,5 +1,10 @@ import React from 'react'; -import {ScopedContext, IScopedContext, filterTarget} from 'amis-core'; +import { + ScopedContext, + IScopedContext, + filterTarget, + setVariable +} from 'amis-core'; import {Renderer, RendererProps} from 'amis-core'; import {SchemaNode, Schema, ActionObject} from 'amis-core'; import {filter} from 'amis-core'; @@ -397,9 +402,11 @@ export default class Dialog extends React.Component { // 如果 dialog 里面不放 form,而是直接放表单项就会进到这里来。 if (typeof name === 'string') { - data = { - [name]: data + const mergedData = { + ...store.form }; + setVariable(mergedData, name, data); + data = mergedData; } store.setFormData(data);