From 285d4ab7798675204fb900d9079135a6649332c7 Mon Sep 17 00:00:00 2001 From: xingyu Date: Tue, 10 Oct 2023 12:06:35 +0800 Subject: [PATCH] fix: Fix ts type error --- src/components/Form/src/BasicForm.vue | 14 ++++++++++++-- src/components/Form/src/hooks/useForm.ts | 4 ++-- src/components/Scrollbar/src/util.ts | 4 ++-- src/utils/bem.ts | 3 +-- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/components/Form/src/BasicForm.vue b/src/components/Form/src/BasicForm.vue index 520b6d1..652da6b 100644 --- a/src/components/Form/src/BasicForm.vue +++ b/src/components/Form/src/BasicForm.vue @@ -77,11 +77,21 @@ const getBindValue = computed(() => ({ ...attrs, ...props, ...unref(getProps) }) const getSchema = computed((): FormSchema[] => { const schemas: FormSchema[] = unref(schemaRef) || (unref(getProps).schemas as any) for (const schema of schemas) { - const { defaultValue, component, isHandleDateDefaultValue = true } = schema + const { + defaultValue, + component, + componentProps, + isHandleDateDefaultValue = true, + } = schema + + // eslint-disable-next-line dot-notation + const valueFormat = componentProps ? componentProps['valueFormat'] : null // handle date type if (isHandleDateDefaultValue && defaultValue && dateItemType.includes(component)) { if (!Array.isArray(defaultValue)) { - schema.defaultValue = dateUtil(defaultValue) + schema.defaultValue = valueFormat + ? dateUtil(defaultValue).format(valueFormat) + : dateUtil(defaultValue) } else { const def: any[] = [] diff --git a/src/components/Form/src/hooks/useForm.ts b/src/components/Form/src/hooks/useForm.ts index 0103244..f9cb8d3 100644 --- a/src/components/Form/src/hooks/useForm.ts +++ b/src/components/Form/src/hooks/useForm.ts @@ -91,7 +91,7 @@ export function useForm(props?: Props): UseFormReturnType { form.setFieldsValue(values) }, - appendSchemaByField: async (schema: FormSchema | FormSchema[], prefixField: string | undefined, first: boolean) => { + appendSchemaByField: async (schema: FormSchema | FormSchema[], prefixField: string | undefined, first?: boolean) => { const form = await getForm() form.appendSchemaByField(schema, prefixField, first) }, @@ -101,7 +101,7 @@ export function useForm(props?: Props): UseFormReturnType { return form.submit() }, - validate: async (nameList?: NamePath[]): Promise => { + validate: async (nameList?: NamePath[] | false): Promise => { const form = await getForm() return form.validate(nameList) }, diff --git a/src/components/Scrollbar/src/util.ts b/src/components/Scrollbar/src/util.ts index 935a487..65d6d98 100644 --- a/src/components/Scrollbar/src/util.ts +++ b/src/components/Scrollbar/src/util.ts @@ -35,11 +35,11 @@ export function renderThumbStyle({ move, size, bar }) { return style } -function extend(to: T, _from: K): T & K { +function extend(to: T, _from: K): T & K { return Object.assign(to as any, _from) } -export function toObject(arr: Array): Recordable { +export function toObject(arr: Array): Recordable { const res = {} for (let i = 0; i < arr.length; i++) { if (arr[i]) diff --git a/src/utils/bem.ts b/src/utils/bem.ts index c62539e..1521fa7 100644 --- a/src/utils/bem.ts +++ b/src/utils/bem.ts @@ -13,8 +13,7 @@ function genBem(name: string, mods?: Mods): string { return ` ${name}--${mods}` if (Array.isArray(mods)) - // eslint-disable-next-line @typescript-eslint/restrict-plus-operands - return mods.reduce((ret, item) => ret + genBem(name, item), '') + return (mods as Mod[]).reduce((ret, item) => ret + genBem(name, item), '') return Object.keys(mods).reduce((ret, key) => ret + (mods[key] ? genBem(name, key) : ''), '') }