前端爱码士
4 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with
13 additions and
13 deletions
-
src/components/Form/src/BasicForm.vue
-
src/components/Form/src/hooks/useForm.ts
-
src/components/Form/src/hooks/useFormEvents.ts
-
src/components/Form/src/types/form.ts
-
src/views/demo/form/AppendForm.vue
-
src/views/demo/form/DynamicForm.vue
|
|
|
@ -174,7 +174,7 @@ |
|
|
|
updateSchema, |
|
|
|
resetSchema, |
|
|
|
appendSchemaByField, |
|
|
|
removeSchemaByFiled, |
|
|
|
removeSchemaByFeild, |
|
|
|
resetFields, |
|
|
|
scrollToField, |
|
|
|
} = useFormEvents({ |
|
|
|
@ -268,7 +268,7 @@ |
|
|
|
updateSchema, |
|
|
|
resetSchema, |
|
|
|
setProps, |
|
|
|
removeSchemaByFiled, |
|
|
|
removeSchemaByFeild, |
|
|
|
appendSchemaByField, |
|
|
|
clearValidate, |
|
|
|
validateFields, |
|
|
|
|
|
|
|
@ -79,8 +79,8 @@ export function useForm(props?: Props): UseFormReturnType { |
|
|
|
}); |
|
|
|
}, |
|
|
|
|
|
|
|
removeSchemaByFiled: async (field: string | string[]) => { |
|
|
|
unref(formRef)?.removeSchemaByFiled(field); |
|
|
|
removeSchemaByFeild: async (field: string | string[]) => { |
|
|
|
unref(formRef)?.removeSchemaByFeild(field); |
|
|
|
}, |
|
|
|
|
|
|
|
// TODO promisify
|
|
|
|
|
|
|
|
@ -112,7 +112,7 @@ export function useFormEvents({ |
|
|
|
/** |
|
|
|
* @description: Delete based on field name |
|
|
|
*/ |
|
|
|
async function removeSchemaByFiled(fields: string | string[]): Promise<void> { |
|
|
|
async function removeSchemaByFeild(fields: string | string[]): Promise<void> { |
|
|
|
const schemaList: FormSchema[] = cloneDeep(unref(getSchema)); |
|
|
|
if (!fields) { |
|
|
|
return; |
|
|
|
@ -123,7 +123,7 @@ export function useFormEvents({ |
|
|
|
fieldList = [fields]; |
|
|
|
} |
|
|
|
for (const field of fieldList) { |
|
|
|
_removeSchemaByFiled(field, schemaList); |
|
|
|
_removeSchemaByFeild(field, schemaList); |
|
|
|
} |
|
|
|
schemaRef.value = schemaList; |
|
|
|
} |
|
|
|
@ -131,7 +131,7 @@ export function useFormEvents({ |
|
|
|
/** |
|
|
|
* @description: Delete based on field name |
|
|
|
*/ |
|
|
|
function _removeSchemaByFiled(field: string, schemaList: FormSchema[]): void { |
|
|
|
function _removeSchemaByFeild(field: string, schemaList: FormSchema[]): void { |
|
|
|
if (isString(field)) { |
|
|
|
const index = schemaList.findIndex((schema) => schema.field === field); |
|
|
|
if (index !== -1) { |
|
|
|
@ -306,7 +306,7 @@ export function useFormEvents({ |
|
|
|
updateSchema, |
|
|
|
resetSchema, |
|
|
|
appendSchemaByField, |
|
|
|
removeSchemaByFiled, |
|
|
|
removeSchemaByFeild, |
|
|
|
resetFields, |
|
|
|
setFieldsValue, |
|
|
|
scrollToField, |
|
|
|
|
|
|
|
@ -33,7 +33,7 @@ export interface FormActionType { |
|
|
|
updateSchema: (data: Partial<FormSchema> | Partial<FormSchema>[]) => Promise<void>; |
|
|
|
resetSchema: (data: Partial<FormSchema> | Partial<FormSchema>[]) => Promise<void>; |
|
|
|
setProps: (formProps: Partial<FormProps>) => Promise<void>; |
|
|
|
removeSchemaByFiled: (field: string | string[]) => Promise<void>; |
|
|
|
removeSchemaByFeild: (field: string | string[]) => Promise<void>; |
|
|
|
appendSchemaByField: ( |
|
|
|
schema: FormSchema, |
|
|
|
prefixField: string | undefined, |
|
|
|
|
|
|
|
@ -21,7 +21,7 @@ |
|
|
|
export default defineComponent({ |
|
|
|
components: { BasicForm, CollapseContainer, PageWrapper, [Input.name]: Input, Button }, |
|
|
|
setup() { |
|
|
|
const [register, { appendSchemaByField, removeSchemaByFiled, validate }] = useForm({ |
|
|
|
const [register, { appendSchemaByField, removeSchemaByFeild, validate }] = useForm({ |
|
|
|
schemas: [ |
|
|
|
{ |
|
|
|
field: 'field0a', |
|
|
|
@ -108,7 +108,7 @@ |
|
|
|
} |
|
|
|
|
|
|
|
function del(field) { |
|
|
|
removeSchemaByFiled([`field${field}a`, `field${field}b`, `${field}`]); |
|
|
|
removeSchemaByFeild([`field${field}a`, `field${field}b`, `${field}`]); |
|
|
|
n.value--; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -181,7 +181,7 @@ |
|
|
|
export default defineComponent({ |
|
|
|
components: { BasicForm, CollapseContainer, PageWrapper }, |
|
|
|
setup() { |
|
|
|
const [register, { setProps, updateSchema, appendSchemaByField, removeSchemaByFiled }] = |
|
|
|
const [register, { setProps, updateSchema, appendSchemaByField, removeSchemaByFeild }] = |
|
|
|
useForm({ |
|
|
|
labelWidth: 120, |
|
|
|
schemas, |
|
|
|
@ -229,7 +229,7 @@ |
|
|
|
); |
|
|
|
} |
|
|
|
function deleteField() { |
|
|
|
removeSchemaByFiled('field11'); |
|
|
|
removeSchemaByFeild('field11'); |
|
|
|
} |
|
|
|
return { |
|
|
|
register, |
|
|
|
|