From e1754866923f9573039cc0462910525ecaedc6d2 Mon Sep 17 00:00:00 2001 From: xingyu4j Date: Thu, 17 Nov 2022 13:31:27 +0800 Subject: [PATCH] perf: form inputnumber --- .../src/hooks/web/useCrudSchemas.ts | 11 ++++++++++- .../src/hooks/web/useVxeCrudSchemas.ts | 16 ++++++++++------ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/yudao-ui-admin-vue3/src/hooks/web/useCrudSchemas.ts b/yudao-ui-admin-vue3/src/hooks/web/useCrudSchemas.ts index 8ca9097be..d9efaa7b8 100644 --- a/yudao-ui-admin-vue3/src/hooks/web/useCrudSchemas.ts +++ b/yudao-ui-admin-vue3/src/hooks/web/useCrudSchemas.ts @@ -142,9 +142,17 @@ const filterFormSchema = (crudSchema: CrudSchema[]): FormSchema[] => { // 判断是否显示 if (schemaItem?.form?.show !== false) { let component = schemaItem?.form?.component || 'Input' - const options: ComponentOptions[] = [] + let defaultValue: any = '' + if (schemaItem.form?.value) { + defaultValue = schemaItem.form?.value + } else { + if (component === 'InputNumber') { + defaultValue = 0 + } + } let comonentProps = {} if (schemaItem.dictType) { + const options: ComponentOptions[] = [] if (schemaItem.dictData && schemaItem.dictData === 'number') { getIntDictOptions(schemaItem.dictType).forEach((dict) => { options.push(dict) @@ -167,6 +175,7 @@ const filterFormSchema = (crudSchema: CrudSchema[]): FormSchema[] => { // 默认为 input component: component, componentProps: comonentProps, + value: defaultValue, ...schemaItem.form, field: schemaItem.field, label: schemaItem.form?.label || schemaItem.label diff --git a/yudao-ui-admin-vue3/src/hooks/web/useVxeCrudSchemas.ts b/yudao-ui-admin-vue3/src/hooks/web/useVxeCrudSchemas.ts index 43a44edcb..3c1b36483 100644 --- a/yudao-ui-admin-vue3/src/hooks/web/useVxeCrudSchemas.ts +++ b/yudao-ui-admin-vue3/src/hooks/web/useVxeCrudSchemas.ts @@ -228,8 +228,12 @@ const filterFormSchema = (crudSchema: VxeCrudSchema): FormSchema[] => { // 默认为 input let component = schemaItem?.form?.component || 'Input' let defaultValue: any = '' - if (component === 'InputNumber') { - defaultValue = 0 + if (schemaItem.form?.value) { + defaultValue = schemaItem.form?.value + } else { + if (component === 'InputNumber') { + defaultValue = 0 + } } let comonentProps = {} if (schemaItem.dictType) { @@ -253,12 +257,12 @@ const filterFormSchema = (crudSchema: VxeCrudSchema): FormSchema[] => { if (!(schemaItem.form && schemaItem.form.component)) component = 'Select' } const formSchemaItem = { - ...schemaItem.form, - field: schemaItem.field, - label: schemaItem.form?.label || schemaItem.title, component: component, componentProps: comonentProps, - value: defaultValue + value: defaultValue, + ...schemaItem.form, + field: schemaItem.field, + label: schemaItem.form?.label || schemaItem.title } formSchema.push(formSchemaItem)