fix: type check error

pull/38/head
xingyu 2023-10-12 15:15:32 +08:00
parent bea5189943
commit 21e1cee4ce
8 changed files with 34 additions and 29 deletions

View File

@ -101,7 +101,7 @@ export function useForm(props?: Props): UseFormReturnType {
return form.submit()
},
validate: async <T = any>(nameList?: NamePath[] | false): Promise<T> => {
validate: async <T = Recordable>(nameList?: NamePath[] | false): Promise<T> => {
const form = await getForm()
return form.validate(nameList)
},

View File

@ -35,7 +35,7 @@ export interface FormActionType {
removeSchemaByField: (field: string | string[]) => Promise<void>
appendSchemaByField: (schema: FormSchema | FormSchema[], prefixField: string | undefined, first?: boolean | undefined) => Promise<void>
validateFields: (nameList?: NamePath[]) => Promise<any>
validate: <T = any>(nameList?: NamePath[] | false) => Promise<T>
validate: <T = Recordable>(nameList?: NamePath[] | false) => Promise<T>
scrollToField: (name: NamePath, options?: ScrollOptions) => Promise<void>
}

View File

@ -47,16 +47,23 @@ export default defineComponent({
const noHiddenList = computed(() => {
return (
props.formConfig.schemas
&& props.formConfig.schemas.filter(item => item.hidden !== true)
&& props.formConfig.schemas.filter(item => item.hidden !== true)
)
})
const fApi = useVModel(props, 'fApi', emit)
const { submit, validate, clearValidate, resetFields, validateField }
= useFormInstanceMethods(props, formModelNew, context, eFormModel)
= useFormInstanceMethods<['submit', 'change', 'update:fApi', 'update:formModel']>(
props,
formModelNew,
context,
eFormModel,
)
const { linkOn, ...methods } = useVFormMethods(
const { linkOn, ...methods } = useVFormMethods<
['submit', 'change', 'update:fApi', 'update:formModel']
>(
{ formConfig: props.formConfig, formData: props.formModel } as unknown as IProps,
context,
eFormModel,
@ -122,21 +129,12 @@ export default defineComponent({
<AntForm ref="eFormModel" class="overflow-hidden" :model="formModel" v-bind="formModelProps">
<Row>
<FormRender
v-for="(schema, index) of noHiddenList"
:key="index"
:schema="schema"
:form-config="formConfig"
:form-data="formModelNew"
:set-form-model="setFormModel"
@change="handleChange"
@submit="handleSubmit"
v-for="(schema, index) of noHiddenList" :key="index" :schema="schema" :form-config="formConfig"
:form-data="formModelNew" :set-form-model="setFormModel" @change="handleChange" @submit="handleSubmit"
@reset="resetFields"
>
<template v-if="schema && schema.componentProps" #[`schema.componentProps!.slotName`]>
<slot
:name="schema.componentProps!.slotName"
v-bind="{ formModel, field: schema.field, schema }"
/>
<slot :name="schema.componentProps!.slotName" v-bind="{ formModel, field: schema.field, schema }" />
</template>
</FormRender>
</Row>

View File

@ -1,14 +1,14 @@
import type { Ref, SetupContext } from 'vue'
import type { EmitsOptions, Ref, SetupContext } from 'vue'
import { getCurrentInstance, toRaw } from 'vue'
import { cloneDeep, forOwn, isFunction } from 'lodash-es'
import { Form } from 'ant-design-vue'
import type { AForm, IVFormComponent } from '../typings/v-form-component'
import type { IAnyObject } from '../typings/base-type'
export function useFormInstanceMethods(
export function useFormInstanceMethods<E extends EmitsOptions = EmitsOptions>(
props: IAnyObject,
formdata,
context: Partial<SetupContext>,
context: SetupContext<E>,
_formInstance: Ref<AForm | null>,
) {
/**
@ -44,7 +44,7 @@ export function useFormInstanceMethods(
const submit = async () => {
// const _result = await validate();
const data = cloneDeep(toRaw(formdata.value))
const data = await cloneDeep(toRaw(formdata.value))
emit?.('submit', data)
props.formConfig.submit?.(data)
return data

View File

@ -1,4 +1,4 @@
import type { Ref, SetupContext } from 'vue'
import type { EmitsOptions, Ref, SetupContext } from 'vue'
import { cloneDeep, isFunction } from 'lodash-es'
import type { AForm, IFormConfig, IVFormComponent } from '../typings/v-form-component'
import { findFormItem, formItemsForEach } from '../utils'
@ -52,9 +52,9 @@ export interface IVFormMethods extends Partial<IFormInstanceMethods> {
getData: IGetData
disable: IDisable
}
export function useVFormMethods(
export function useVFormMethods<E extends EmitsOptions = EmitsOptions>(
props: IProps,
_context: Partial<SetupContext>,
_context: SetupContext<E>,
formInstance: Ref<AForm | null>,
formInstanceMethods: Partial<IFormInstanceMethods>,
): IVFormMethods {

View File

@ -1,5 +1,6 @@
<script lang="ts" setup>
import { ref } from 'vue'
import type { MenuProps } from 'ant-design-vue'
import { Dropdown, Menu, Tooltip } from 'ant-design-vue'
import { ColumnHeightOutlined } from '@ant-design/icons-vue'
import type { SizeType } from '../../types/table'
@ -14,10 +15,10 @@ const { t } = useI18n()
const selectedKeysRef = ref<SizeType[]>([table.getSize()])
function handleTitleClick({ key }: { key: any }) {
selectedKeysRef.value = [key]
const handleTitleClick: MenuProps['onClick'] = ({ key }) => {
selectedKeysRef.value = [key as SizeType]
table.setProps({
size: key,
size: key as SizeType,
})
}
</script>

View File

@ -65,7 +65,7 @@ export function useTree(treeDataRef: Ref<TreeDataItem[]>, getFieldNames: Compute
}
// Update node
function updateNodeByKey(key: string, node: TreeDataItem, list?: TreeDataItem[]) {
function updateNodeByKey(key: string, node: Omit<TreeDataItem, 'key'>, list?: TreeDataItem[]) {
if (!key)
return
const treeData = list || unref(treeDataRef)
@ -192,7 +192,7 @@ export function useTree(treeDataRef: Ref<TreeDataItem[]>, getFieldNames: Compute
const treeData = treeList || unref(treeDataRef)
const { key: keyField, children: childrenField } = unref(getFieldNames)
if (!keyField)
return
return null
treeData.forEach((item) => {
if (selectedNode?.key || selectedNode?.key === 0)
return selectedNode

View File

@ -15,6 +15,12 @@ declare global {
// __APP__: App<Element>;
// }
interface Document {
mozFullScreenElement?: Element
msFullscreenElement?: Element
webkitFullscreenElement?: Element
}
// vue
declare type PropType<T> = VuePropType<T>
declare type VueNode = VNodeChild | JSX.Element