Skip to content

Commit

Permalink
fix(FormDialog): loading not working during submitting (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
yikoyu authored Jul 1, 2024
1 parent 31cc4d4 commit 036cba8
Showing 1 changed file with 117 additions and 122 deletions.
239 changes: 117 additions & 122 deletions packages/components/src/form-dialog/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,131 +162,126 @@ export function FormDialog(

const render = (visible = true, resolve?: () => any, reject?: () => any) => {
if (!env.instance) {
const ComponentConstructor = defineComponent({
props: { dialogProps: Object as PropType<typeof ElDialogProps> },
data() {
return {
visible: false,
}
},
render() {
const {
onClose,
onClosed,
onOpen,
onOpend,
onOK,
onCancel,
title,
footer,
okText,
cancelText,
okButtonProps,
cancelButtonProps,
...dialogProps
} = this.dialogProps

return h(
FormProvider,
{ form: env.form },
{
default: () =>
h(
ElDialog,
{
class: [`${prefixCls}`],
...dialogProps,
modelValue: this.visible,
'onUpdate:modelValue': (val) => {
this.visible = val
},
onClose: () => {
onClose?.()
},
onClosed: () => {
onClosed?.()
},
onOpen: () => {
onOpen?.()
},
onOpened: () => {
onOpend?.()
},
},
{
default: () => h(component, {}, {}),
title: () =>
h('div', {}, { default: () => resolveComponent(title) }),
footer: () =>
h(
'div',
{},
{
default: () => {
const FooterPortalTarget = h(
'span',
{
id: PORTAL_TARGET_NAME,
},
{}
)
if (footer === null) {
return [null, FooterPortalTarget]
} else if (footer) {
return [
resolveComponent(footer),
FooterPortalTarget,
]
}
const ComponentConstructor = observer(
defineComponent({
props: { dialogProps: Object as PropType<typeof ElDialogProps> },
data() {
return {
visible: false,
}
},
render() {
const {
onClose,
onClosed,
onOpen,
onOpend,
onOK,
onCancel,
title,
footer,
okText,
cancelText,
okButtonProps,
cancelButtonProps,
...dialogProps
} = this.dialogProps

return [
h(
ElButton,
{
...cancelButtonProps,
onClick: (e) => {
onCancel?.(e)
reject()
},
},
{
default: () =>
resolveComponent(
cancelText || '取消'
// t('el.popconfirm.cancelButtonText')
),
}
),
h(
ElButton,
{
type: 'primary',
...okButtonProps,
loading: env.form.submitting,
onClick: (e) => {
onOK?.(e)
resolve()
},
},
{
default: () =>
resolveComponent(
okText || '确定'
// t('el.popconfirm.confirmButtonText')
),
}
),
FooterPortalTarget,
]
return h(
ElDialog,
{
class: [`${prefixCls}`],
...dialogProps,
modelValue: this.visible,
'onUpdate:modelValue': (val) => {
this.visible = val
},
onClose: () => {
onClose?.()
},
onClosed: () => {
onClosed?.()
},
onOpen: () => {
onOpen?.()
},
onOpened: () => {
onOpend?.()
},
},
{
default: () =>
h(FormProvider, { form: env.form }, () =>
h(component, {}, {})
),
title: () =>
h('div', {}, { default: () => resolveComponent(title) }),
footer: () =>
h(
'div',
{},
{
default: () => {
const FooterPortalTarget = h(
'span',
{
id: PORTAL_TARGET_NAME,
},
{}
)
if (footer === null) {
return [null, FooterPortalTarget]
} else if (footer) {
return [resolveComponent(footer), FooterPortalTarget]
}
),
}
),
}
)
},
})

return [
h(
ElButton,
{
...cancelButtonProps,
onClick: (e) => {
onCancel?.(e)
reject()
},
},
{
default: () =>
resolveComponent(
cancelText || '取消'
// t('el.popconfirm.cancelButtonText')
),
}
),
h(
ElButton,
{
type: 'primary',
...okButtonProps,
loading: env.form.submitting,
onClick: (e) => {
onOK?.(e)
resolve()
},
},
{
default: () =>
resolveComponent(
okText || '确定'
// t('el.popconfirm.confirmButtonText')
),
}
),
FooterPortalTarget,
]
},
}
),
}
)
},
})
)

env.app = createApp(ComponentConstructor, {
dialogProps,
Expand Down

0 comments on commit 036cba8

Please sign in to comment.