fix: form 表单不支持field.xxx.xx格式的defaultValue配置 (#4965)

* fix: form 表单不支持field.xxx.xx格式的defaultValue配置

* chore: 修复代码规范问题
This commit is contained in:
leizhiyou
2024-12-01 21:48:54 +08:00
committed by GitHub
parent ae3f7cb909
commit 12f216c0e7
6 changed files with 38 additions and 3 deletions

View File

@@ -86,12 +86,14 @@
"dayjs": "catalog:",
"defu": "catalog:",
"lodash.clonedeep": "catalog:",
"lodash.set": "catalog:",
"nprogress": "catalog:",
"tailwind-merge": "catalog:",
"theme-colors": "catalog:"
},
"devDependencies": {
"@types/lodash.clonedeep": "catalog:",
"@types/lodash.set": "catalog:",
"@types/nprogress": "catalog:"
}
}

View File

@@ -15,3 +15,4 @@ export * from './update-css-variables';
export * from './util';
export * from './window';
export { default as cloneDeep } from 'lodash.clonedeep';
export { default as set } from 'lodash.set';

View File

@@ -3,7 +3,7 @@ import type { FormActions, VbenFormProps } from './types';
import { computed, type ComputedRef, unref, useSlots } from 'vue';
import { createContext } from '@vben-core/shadcn-ui';
import { isString } from '@vben-core/shared/utils';
import { isString, set } from '@vben-core/shared/utils';
import { useForm } from 'vee-validate';
import { object, type ZodRawShape } from 'zod';
@@ -41,9 +41,9 @@ export function useFormInitial(
const zodObject: ZodRawShape = {};
(unref(props).schema || []).forEach((item) => {
if (Reflect.has(item, 'defaultValue')) {
initialValues[item.fieldName] = item.defaultValue;
set(initialValues, item.fieldName, item.defaultValue);
} else if (item.rules && !isString(item.rules)) {
zodObject[item.fieldName] = item.rules;
set(zodObject, item.fieldName, item.defaultValue);
}
});