fix: type check error
parent
bea5189943
commit
21e1cee4ce
|
@ -101,7 +101,7 @@ export function useForm(props?: Props): UseFormReturnType {
|
||||||
return form.submit()
|
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()
|
const form = await getForm()
|
||||||
return form.validate(nameList)
|
return form.validate(nameList)
|
||||||
},
|
},
|
||||||
|
|
|
@ -35,7 +35,7 @@ export interface FormActionType {
|
||||||
removeSchemaByField: (field: string | string[]) => Promise<void>
|
removeSchemaByField: (field: string | string[]) => Promise<void>
|
||||||
appendSchemaByField: (schema: FormSchema | FormSchema[], prefixField: string | undefined, first?: boolean | undefined) => Promise<void>
|
appendSchemaByField: (schema: FormSchema | FormSchema[], prefixField: string | undefined, first?: boolean | undefined) => Promise<void>
|
||||||
validateFields: (nameList?: NamePath[]) => Promise<any>
|
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>
|
scrollToField: (name: NamePath, options?: ScrollOptions) => Promise<void>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -47,16 +47,23 @@ export default defineComponent({
|
||||||
const noHiddenList = computed(() => {
|
const noHiddenList = computed(() => {
|
||||||
return (
|
return (
|
||||||
props.formConfig.schemas
|
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 fApi = useVModel(props, 'fApi', emit)
|
||||||
|
|
||||||
const { submit, validate, clearValidate, resetFields, validateField }
|
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,
|
{ formConfig: props.formConfig, formData: props.formModel } as unknown as IProps,
|
||||||
context,
|
context,
|
||||||
eFormModel,
|
eFormModel,
|
||||||
|
@ -122,21 +129,12 @@ export default defineComponent({
|
||||||
<AntForm ref="eFormModel" class="overflow-hidden" :model="formModel" v-bind="formModelProps">
|
<AntForm ref="eFormModel" class="overflow-hidden" :model="formModel" v-bind="formModelProps">
|
||||||
<Row>
|
<Row>
|
||||||
<FormRender
|
<FormRender
|
||||||
v-for="(schema, index) of noHiddenList"
|
v-for="(schema, index) of noHiddenList" :key="index" :schema="schema" :form-config="formConfig"
|
||||||
:key="index"
|
:form-data="formModelNew" :set-form-model="setFormModel" @change="handleChange" @submit="handleSubmit"
|
||||||
:schema="schema"
|
|
||||||
:form-config="formConfig"
|
|
||||||
:form-data="formModelNew"
|
|
||||||
:set-form-model="setFormModel"
|
|
||||||
@change="handleChange"
|
|
||||||
@submit="handleSubmit"
|
|
||||||
@reset="resetFields"
|
@reset="resetFields"
|
||||||
>
|
>
|
||||||
<template v-if="schema && schema.componentProps" #[`schema.componentProps!.slotName`]>
|
<template v-if="schema && schema.componentProps" #[`schema.componentProps!.slotName`]>
|
||||||
<slot
|
<slot :name="schema.componentProps!.slotName" v-bind="{ formModel, field: schema.field, schema }" />
|
||||||
:name="schema.componentProps!.slotName"
|
|
||||||
v-bind="{ formModel, field: schema.field, schema }"
|
|
||||||
/>
|
|
||||||
</template>
|
</template>
|
||||||
</FormRender>
|
</FormRender>
|
||||||
</Row>
|
</Row>
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
import type { Ref, SetupContext } from 'vue'
|
import type { EmitsOptions, Ref, SetupContext } from 'vue'
|
||||||
import { getCurrentInstance, toRaw } from 'vue'
|
import { getCurrentInstance, toRaw } from 'vue'
|
||||||
import { cloneDeep, forOwn, isFunction } from 'lodash-es'
|
import { cloneDeep, forOwn, isFunction } from 'lodash-es'
|
||||||
import { Form } from 'ant-design-vue'
|
import { Form } from 'ant-design-vue'
|
||||||
import type { AForm, IVFormComponent } from '../typings/v-form-component'
|
import type { AForm, IVFormComponent } from '../typings/v-form-component'
|
||||||
import type { IAnyObject } from '../typings/base-type'
|
import type { IAnyObject } from '../typings/base-type'
|
||||||
|
|
||||||
export function useFormInstanceMethods(
|
export function useFormInstanceMethods<E extends EmitsOptions = EmitsOptions>(
|
||||||
props: IAnyObject,
|
props: IAnyObject,
|
||||||
formdata,
|
formdata,
|
||||||
context: Partial<SetupContext>,
|
context: SetupContext<E>,
|
||||||
_formInstance: Ref<AForm | null>,
|
_formInstance: Ref<AForm | null>,
|
||||||
) {
|
) {
|
||||||
/**
|
/**
|
||||||
|
@ -44,7 +44,7 @@ export function useFormInstanceMethods(
|
||||||
const submit = async () => {
|
const submit = async () => {
|
||||||
// const _result = await validate();
|
// const _result = await validate();
|
||||||
|
|
||||||
const data = cloneDeep(toRaw(formdata.value))
|
const data = await cloneDeep(toRaw(formdata.value))
|
||||||
emit?.('submit', data)
|
emit?.('submit', data)
|
||||||
props.formConfig.submit?.(data)
|
props.formConfig.submit?.(data)
|
||||||
return data
|
return data
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import type { Ref, SetupContext } from 'vue'
|
import type { EmitsOptions, Ref, SetupContext } from 'vue'
|
||||||
import { cloneDeep, isFunction } from 'lodash-es'
|
import { cloneDeep, isFunction } from 'lodash-es'
|
||||||
import type { AForm, IFormConfig, IVFormComponent } from '../typings/v-form-component'
|
import type { AForm, IFormConfig, IVFormComponent } from '../typings/v-form-component'
|
||||||
import { findFormItem, formItemsForEach } from '../utils'
|
import { findFormItem, formItemsForEach } from '../utils'
|
||||||
|
@ -52,9 +52,9 @@ export interface IVFormMethods extends Partial<IFormInstanceMethods> {
|
||||||
getData: IGetData
|
getData: IGetData
|
||||||
disable: IDisable
|
disable: IDisable
|
||||||
}
|
}
|
||||||
export function useVFormMethods(
|
export function useVFormMethods<E extends EmitsOptions = EmitsOptions>(
|
||||||
props: IProps,
|
props: IProps,
|
||||||
_context: Partial<SetupContext>,
|
_context: SetupContext<E>,
|
||||||
formInstance: Ref<AForm | null>,
|
formInstance: Ref<AForm | null>,
|
||||||
formInstanceMethods: Partial<IFormInstanceMethods>,
|
formInstanceMethods: Partial<IFormInstanceMethods>,
|
||||||
): IVFormMethods {
|
): IVFormMethods {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { ref } from 'vue'
|
import { ref } from 'vue'
|
||||||
|
import type { MenuProps } from 'ant-design-vue'
|
||||||
import { Dropdown, Menu, Tooltip } from 'ant-design-vue'
|
import { Dropdown, Menu, Tooltip } from 'ant-design-vue'
|
||||||
import { ColumnHeightOutlined } from '@ant-design/icons-vue'
|
import { ColumnHeightOutlined } from '@ant-design/icons-vue'
|
||||||
import type { SizeType } from '../../types/table'
|
import type { SizeType } from '../../types/table'
|
||||||
|
@ -14,10 +15,10 @@ const { t } = useI18n()
|
||||||
|
|
||||||
const selectedKeysRef = ref<SizeType[]>([table.getSize()])
|
const selectedKeysRef = ref<SizeType[]>([table.getSize()])
|
||||||
|
|
||||||
function handleTitleClick({ key }: { key: any }) {
|
const handleTitleClick: MenuProps['onClick'] = ({ key }) => {
|
||||||
selectedKeysRef.value = [key]
|
selectedKeysRef.value = [key as SizeType]
|
||||||
table.setProps({
|
table.setProps({
|
||||||
size: key,
|
size: key as SizeType,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -65,7 +65,7 @@ export function useTree(treeDataRef: Ref<TreeDataItem[]>, getFieldNames: Compute
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update node
|
// Update node
|
||||||
function updateNodeByKey(key: string, node: TreeDataItem, list?: TreeDataItem[]) {
|
function updateNodeByKey(key: string, node: Omit<TreeDataItem, 'key'>, list?: TreeDataItem[]) {
|
||||||
if (!key)
|
if (!key)
|
||||||
return
|
return
|
||||||
const treeData = list || unref(treeDataRef)
|
const treeData = list || unref(treeDataRef)
|
||||||
|
@ -192,7 +192,7 @@ export function useTree(treeDataRef: Ref<TreeDataItem[]>, getFieldNames: Compute
|
||||||
const treeData = treeList || unref(treeDataRef)
|
const treeData = treeList || unref(treeDataRef)
|
||||||
const { key: keyField, children: childrenField } = unref(getFieldNames)
|
const { key: keyField, children: childrenField } = unref(getFieldNames)
|
||||||
if (!keyField)
|
if (!keyField)
|
||||||
return
|
return null
|
||||||
treeData.forEach((item) => {
|
treeData.forEach((item) => {
|
||||||
if (selectedNode?.key || selectedNode?.key === 0)
|
if (selectedNode?.key || selectedNode?.key === 0)
|
||||||
return selectedNode
|
return selectedNode
|
||||||
|
|
|
@ -15,6 +15,12 @@ declare global {
|
||||||
// __APP__: App<Element>;
|
// __APP__: App<Element>;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
interface Document {
|
||||||
|
mozFullScreenElement?: Element
|
||||||
|
msFullscreenElement?: Element
|
||||||
|
webkitFullscreenElement?: Element
|
||||||
|
}
|
||||||
|
|
||||||
// vue
|
// vue
|
||||||
declare type PropType<T> = VuePropType<T>
|
declare type PropType<T> = VuePropType<T>
|
||||||
declare type VueNode = VNodeChild | JSX.Element
|
declare type VueNode = VNodeChild | JSX.Element
|
||||||
|
|
Loading…
Reference in New Issue