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
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
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);
}
});

View File

@ -291,6 +291,12 @@ const [CustomLayoutForm] = useVbenForm({
formItemClass: 'col-start-1',
label: '字符串',
},
{
component: 'Input',
defaultValue: 'field4.path',
fieldName: 'field4.path',
label: 'field4.path',
},
],
//
wrapperClass: 'grid-cols-3',

24
pnpm-lock.yaml generated
View File

@ -90,6 +90,9 @@ catalogs:
'@types/lodash.clonedeep':
specifier: ^4.5.9
version: 4.5.9
'@types/lodash.set':
specifier: ^4.3.9
version: 4.3.9
'@types/node':
specifier: ^22.10.0
version: 22.10.0
@ -291,6 +294,9 @@ catalogs:
lodash.clonedeep:
specifier: ^4.5.0
version: 4.5.0
lodash.set:
specifier: ^4.3.2
version: 4.3.2
lucide-vue-next:
specifier: ^0.461.0
version: 0.461.0
@ -1209,6 +1215,9 @@ importers:
lodash.clonedeep:
specifier: 'catalog:'
version: 4.5.0
lodash.set:
specifier: 'catalog:'
version: 4.3.2
nprogress:
specifier: 'catalog:'
version: 0.2.0
@ -1222,6 +1231,9 @@ importers:
'@types/lodash.clonedeep':
specifier: 'catalog:'
version: 4.5.9
'@types/lodash.set':
specifier: 'catalog:'
version: 4.3.9
'@types/nprogress':
specifier: 'catalog:'
version: 0.2.3
@ -4303,6 +4315,9 @@ packages:
'@types/lodash.clonedeep@4.5.9':
resolution: {integrity: sha512-19429mWC+FyaAhOLzsS8kZUsI+/GmBAQ0HFiCPsKGU+7pBXOQWhyrY6xNNDwUSX8SMZMJvuFVMF9O5dQOlQK9Q==}
'@types/lodash.set@4.3.9':
resolution: {integrity: sha512-KOxyNkZpbaggVmqbpr82N2tDVTx05/3/j0f50Es1prxrWB0XYf9p3QNxqcbWb7P1Q9wlvsUSlCFnwlPCIJ46PQ==}
'@types/lodash@4.17.13':
resolution: {integrity: sha512-lfx+dftrEZcdBPczf9d0Qv0x+j/rfNCMuC6OcfXmO8gkfeNAY88PgKUbvG56whcN23gc27yenwF6oJZXGFpYxg==}
@ -7298,6 +7313,9 @@ packages:
lodash.once@4.1.1:
resolution: {integrity: sha512-Sb487aTOCr9drQVL8pIxOzVhafOjZN9UU54hiN8PU3uAiSV7lx1yYNpbNmex2PK6dSJoNTSJUUswT651yww3Mg==}
lodash.set@4.3.2:
resolution: {integrity: sha512-4hNPN5jlm/N/HLMCO43v8BXKq9Z7QdAGc/VGrRD61w8gN9g/6jF9A4L1pbUgBLCffi0w9VsXfTOij5x8iTyFvg==}
lodash.snakecase@4.1.1:
resolution: {integrity: sha512-QZ1d4xoBHYUeuouhEq3lk3Uq7ldgyFXGBhg04+oRLnIz8o9T65Eh+8YdroUwn846zchkA9yDsDl5CVVaV2nqYw==}
@ -13085,6 +13103,10 @@ snapshots:
dependencies:
'@types/lodash': 4.17.13
'@types/lodash.set@4.3.9':
dependencies:
'@types/lodash': 4.17.13
'@types/lodash@4.17.13': {}
'@types/markdown-it@14.1.2':
@ -16498,6 +16520,8 @@ snapshots:
lodash.once@4.1.1: {}
lodash.set@4.3.2: {}
lodash.snakecase@4.1.1: {}
lodash.sortby@4.7.0: {}

View File

@ -43,6 +43,7 @@ catalog:
'@types/html-minifier-terser': ^7.0.2
'@types/jsonwebtoken': ^9.0.7
'@types/lodash.clonedeep': ^4.5.9
'@types/lodash.set': ^4.3.9
'@types/node': ^22.10.0
'@types/nprogress': ^0.2.3
'@types/postcss-import': ^14.0.3
@ -112,6 +113,7 @@ catalog:
jsonwebtoken: ^9.0.2
lint-staged: ^15.2.10
lodash.clonedeep: ^4.5.0
lodash.set: ^4.3.2
lucide-vue-next: ^0.461.0
medium-zoom: ^1.1.0
naive-ui: ^2.40.2