From f8454f0e3056095e0d7d55a37d0dfda3df6fa815 Mon Sep 17 00:00:00 2001 From: K <1175047471@qq.com> Date: Tue, 16 Jul 2024 16:50:12 +0800 Subject: [PATCH] =?UTF-8?q?feat(BasicTable/Form):=20register=20=E6=94=B9?= =?UTF-8?q?=E4=B8=BA=20props=20=E4=BC=A0=E9=80=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit BasicTable register 改为 props 以便获得更好的 TS 泛型执行 --- src/components/Form/src/BasicForm.vue | 7 ++++++- src/components/Form/src/props.ts | 3 ++- src/components/Table/src/BasicTable.vue | 9 +++++++-- src/components/Table/src/hooks/useTable.ts | 10 +++------- src/components/Table/src/props.ts | 4 +++- 5 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/components/Form/src/BasicForm.vue b/src/components/Form/src/BasicForm.vue index 3947f95a..09d2b3c5 100644 --- a/src/components/Form/src/BasicForm.vue +++ b/src/components/Form/src/BasicForm.vue @@ -254,7 +254,12 @@ const formActionType: FormActionType = { onMounted(() => { initDefault() - emit('register', formActionType) + if (props.register) { + props.register(formActionType) + } + else { + emit('register', formActionType) + } }) const getFormActionBindProps = computed(() => ({ ...getProps.value, ...advanceState }) as InstanceType['$props']) diff --git a/src/components/Form/src/props.ts b/src/components/Form/src/props.ts index 7bf32f65..eb881c78 100644 --- a/src/components/Form/src/props.ts +++ b/src/components/Form/src/props.ts @@ -1,12 +1,13 @@ import type { CSSProperties, PropType } from 'vue' import type { ButtonProps } from 'ant-design-vue/es/button/buttonTypes' import type { RowProps } from 'ant-design-vue/lib/grid/Row' -import type { FieldMapToTime, FormSchema } from './types/form' +import type { FieldMapToTime, FormActionType, FormSchema } from './types/form' import type { ColEx } from './types' import type { TableActionType } from '@/components/Table' import { propTypes } from '@/utils/propTypes' export const basicProps = { + register: Function as PropType<(instance: FormActionType) => void>, model: { type: Object as PropType, default: () => ({}), diff --git a/src/components/Table/src/BasicTable.vue b/src/components/Table/src/BasicTable.vue index 33ad9b2a..4f783422 100644 --- a/src/components/Table/src/BasicTable.vue +++ b/src/components/Table/src/BasicTable.vue @@ -286,7 +286,12 @@ createTableContext({ ...tableAction, wrapRef, getBindValues }) defineExpose(tableAction) -emit('register', tableAction, formActions) +if (props.register) { + props.register(tableAction, formActions) +} +else { + emit('register', tableAction, formActions) +}