fix: form 表单不支持field.xxx.xx格式的defaultValue配置 (#4965)
* fix: form 表单不支持field.xxx.xx格式的defaultValue配置 * chore: 修复代码规范问题
This commit is contained in:
parent
ae3f7cb909
commit
12f216c0e7
@ -86,12 +86,14 @@
|
|||||||
"dayjs": "catalog:",
|
"dayjs": "catalog:",
|
||||||
"defu": "catalog:",
|
"defu": "catalog:",
|
||||||
"lodash.clonedeep": "catalog:",
|
"lodash.clonedeep": "catalog:",
|
||||||
|
"lodash.set": "catalog:",
|
||||||
"nprogress": "catalog:",
|
"nprogress": "catalog:",
|
||||||
"tailwind-merge": "catalog:",
|
"tailwind-merge": "catalog:",
|
||||||
"theme-colors": "catalog:"
|
"theme-colors": "catalog:"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/lodash.clonedeep": "catalog:",
|
"@types/lodash.clonedeep": "catalog:",
|
||||||
|
"@types/lodash.set": "catalog:",
|
||||||
"@types/nprogress": "catalog:"
|
"@types/nprogress": "catalog:"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,3 +15,4 @@ export * from './update-css-variables';
|
|||||||
export * from './util';
|
export * from './util';
|
||||||
export * from './window';
|
export * from './window';
|
||||||
export { default as cloneDeep } from 'lodash.clonedeep';
|
export { default as cloneDeep } from 'lodash.clonedeep';
|
||||||
|
export { default as set } from 'lodash.set';
|
||||||
|
@ -3,7 +3,7 @@ import type { FormActions, VbenFormProps } from './types';
|
|||||||
import { computed, type ComputedRef, unref, useSlots } from 'vue';
|
import { computed, type ComputedRef, unref, useSlots } from 'vue';
|
||||||
|
|
||||||
import { createContext } from '@vben-core/shadcn-ui';
|
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 { useForm } from 'vee-validate';
|
||||||
import { object, type ZodRawShape } from 'zod';
|
import { object, type ZodRawShape } from 'zod';
|
||||||
@ -41,9 +41,9 @@ export function useFormInitial(
|
|||||||
const zodObject: ZodRawShape = {};
|
const zodObject: ZodRawShape = {};
|
||||||
(unref(props).schema || []).forEach((item) => {
|
(unref(props).schema || []).forEach((item) => {
|
||||||
if (Reflect.has(item, 'defaultValue')) {
|
if (Reflect.has(item, 'defaultValue')) {
|
||||||
initialValues[item.fieldName] = item.defaultValue;
|
set(initialValues, item.fieldName, item.defaultValue);
|
||||||
} else if (item.rules && !isString(item.rules)) {
|
} else if (item.rules && !isString(item.rules)) {
|
||||||
zodObject[item.fieldName] = item.rules;
|
set(zodObject, item.fieldName, item.defaultValue);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -291,6 +291,12 @@ const [CustomLayoutForm] = useVbenForm({
|
|||||||
formItemClass: 'col-start-1',
|
formItemClass: 'col-start-1',
|
||||||
label: '字符串',
|
label: '字符串',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
component: 'Input',
|
||||||
|
defaultValue: 'field4.path',
|
||||||
|
fieldName: 'field4.path',
|
||||||
|
label: 'field4.path',
|
||||||
|
},
|
||||||
],
|
],
|
||||||
// 一共三列
|
// 一共三列
|
||||||
wrapperClass: 'grid-cols-3',
|
wrapperClass: 'grid-cols-3',
|
||||||
|
@ -90,6 +90,9 @@ catalogs:
|
|||||||
'@types/lodash.clonedeep':
|
'@types/lodash.clonedeep':
|
||||||
specifier: ^4.5.9
|
specifier: ^4.5.9
|
||||||
version: 4.5.9
|
version: 4.5.9
|
||||||
|
'@types/lodash.set':
|
||||||
|
specifier: ^4.3.9
|
||||||
|
version: 4.3.9
|
||||||
'@types/node':
|
'@types/node':
|
||||||
specifier: ^22.10.0
|
specifier: ^22.10.0
|
||||||
version: 22.10.0
|
version: 22.10.0
|
||||||
@ -291,6 +294,9 @@ catalogs:
|
|||||||
lodash.clonedeep:
|
lodash.clonedeep:
|
||||||
specifier: ^4.5.0
|
specifier: ^4.5.0
|
||||||
version: 4.5.0
|
version: 4.5.0
|
||||||
|
lodash.set:
|
||||||
|
specifier: ^4.3.2
|
||||||
|
version: 4.3.2
|
||||||
lucide-vue-next:
|
lucide-vue-next:
|
||||||
specifier: ^0.461.0
|
specifier: ^0.461.0
|
||||||
version: 0.461.0
|
version: 0.461.0
|
||||||
@ -1209,6 +1215,9 @@ importers:
|
|||||||
lodash.clonedeep:
|
lodash.clonedeep:
|
||||||
specifier: 'catalog:'
|
specifier: 'catalog:'
|
||||||
version: 4.5.0
|
version: 4.5.0
|
||||||
|
lodash.set:
|
||||||
|
specifier: 'catalog:'
|
||||||
|
version: 4.3.2
|
||||||
nprogress:
|
nprogress:
|
||||||
specifier: 'catalog:'
|
specifier: 'catalog:'
|
||||||
version: 0.2.0
|
version: 0.2.0
|
||||||
@ -1222,6 +1231,9 @@ importers:
|
|||||||
'@types/lodash.clonedeep':
|
'@types/lodash.clonedeep':
|
||||||
specifier: 'catalog:'
|
specifier: 'catalog:'
|
||||||
version: 4.5.9
|
version: 4.5.9
|
||||||
|
'@types/lodash.set':
|
||||||
|
specifier: 'catalog:'
|
||||||
|
version: 4.3.9
|
||||||
'@types/nprogress':
|
'@types/nprogress':
|
||||||
specifier: 'catalog:'
|
specifier: 'catalog:'
|
||||||
version: 0.2.3
|
version: 0.2.3
|
||||||
@ -4303,6 +4315,9 @@ packages:
|
|||||||
'@types/lodash.clonedeep@4.5.9':
|
'@types/lodash.clonedeep@4.5.9':
|
||||||
resolution: {integrity: sha512-19429mWC+FyaAhOLzsS8kZUsI+/GmBAQ0HFiCPsKGU+7pBXOQWhyrY6xNNDwUSX8SMZMJvuFVMF9O5dQOlQK9Q==}
|
resolution: {integrity: sha512-19429mWC+FyaAhOLzsS8kZUsI+/GmBAQ0HFiCPsKGU+7pBXOQWhyrY6xNNDwUSX8SMZMJvuFVMF9O5dQOlQK9Q==}
|
||||||
|
|
||||||
|
'@types/lodash.set@4.3.9':
|
||||||
|
resolution: {integrity: sha512-KOxyNkZpbaggVmqbpr82N2tDVTx05/3/j0f50Es1prxrWB0XYf9p3QNxqcbWb7P1Q9wlvsUSlCFnwlPCIJ46PQ==}
|
||||||
|
|
||||||
'@types/lodash@4.17.13':
|
'@types/lodash@4.17.13':
|
||||||
resolution: {integrity: sha512-lfx+dftrEZcdBPczf9d0Qv0x+j/rfNCMuC6OcfXmO8gkfeNAY88PgKUbvG56whcN23gc27yenwF6oJZXGFpYxg==}
|
resolution: {integrity: sha512-lfx+dftrEZcdBPczf9d0Qv0x+j/rfNCMuC6OcfXmO8gkfeNAY88PgKUbvG56whcN23gc27yenwF6oJZXGFpYxg==}
|
||||||
|
|
||||||
@ -7298,6 +7313,9 @@ packages:
|
|||||||
lodash.once@4.1.1:
|
lodash.once@4.1.1:
|
||||||
resolution: {integrity: sha512-Sb487aTOCr9drQVL8pIxOzVhafOjZN9UU54hiN8PU3uAiSV7lx1yYNpbNmex2PK6dSJoNTSJUUswT651yww3Mg==}
|
resolution: {integrity: sha512-Sb487aTOCr9drQVL8pIxOzVhafOjZN9UU54hiN8PU3uAiSV7lx1yYNpbNmex2PK6dSJoNTSJUUswT651yww3Mg==}
|
||||||
|
|
||||||
|
lodash.set@4.3.2:
|
||||||
|
resolution: {integrity: sha512-4hNPN5jlm/N/HLMCO43v8BXKq9Z7QdAGc/VGrRD61w8gN9g/6jF9A4L1pbUgBLCffi0w9VsXfTOij5x8iTyFvg==}
|
||||||
|
|
||||||
lodash.snakecase@4.1.1:
|
lodash.snakecase@4.1.1:
|
||||||
resolution: {integrity: sha512-QZ1d4xoBHYUeuouhEq3lk3Uq7ldgyFXGBhg04+oRLnIz8o9T65Eh+8YdroUwn846zchkA9yDsDl5CVVaV2nqYw==}
|
resolution: {integrity: sha512-QZ1d4xoBHYUeuouhEq3lk3Uq7ldgyFXGBhg04+oRLnIz8o9T65Eh+8YdroUwn846zchkA9yDsDl5CVVaV2nqYw==}
|
||||||
|
|
||||||
@ -13085,6 +13103,10 @@ snapshots:
|
|||||||
dependencies:
|
dependencies:
|
||||||
'@types/lodash': 4.17.13
|
'@types/lodash': 4.17.13
|
||||||
|
|
||||||
|
'@types/lodash.set@4.3.9':
|
||||||
|
dependencies:
|
||||||
|
'@types/lodash': 4.17.13
|
||||||
|
|
||||||
'@types/lodash@4.17.13': {}
|
'@types/lodash@4.17.13': {}
|
||||||
|
|
||||||
'@types/markdown-it@14.1.2':
|
'@types/markdown-it@14.1.2':
|
||||||
@ -16498,6 +16520,8 @@ snapshots:
|
|||||||
|
|
||||||
lodash.once@4.1.1: {}
|
lodash.once@4.1.1: {}
|
||||||
|
|
||||||
|
lodash.set@4.3.2: {}
|
||||||
|
|
||||||
lodash.snakecase@4.1.1: {}
|
lodash.snakecase@4.1.1: {}
|
||||||
|
|
||||||
lodash.sortby@4.7.0: {}
|
lodash.sortby@4.7.0: {}
|
||||||
|
@ -43,6 +43,7 @@ catalog:
|
|||||||
'@types/html-minifier-terser': ^7.0.2
|
'@types/html-minifier-terser': ^7.0.2
|
||||||
'@types/jsonwebtoken': ^9.0.7
|
'@types/jsonwebtoken': ^9.0.7
|
||||||
'@types/lodash.clonedeep': ^4.5.9
|
'@types/lodash.clonedeep': ^4.5.9
|
||||||
|
'@types/lodash.set': ^4.3.9
|
||||||
'@types/node': ^22.10.0
|
'@types/node': ^22.10.0
|
||||||
'@types/nprogress': ^0.2.3
|
'@types/nprogress': ^0.2.3
|
||||||
'@types/postcss-import': ^14.0.3
|
'@types/postcss-import': ^14.0.3
|
||||||
@ -112,6 +113,7 @@ catalog:
|
|||||||
jsonwebtoken: ^9.0.2
|
jsonwebtoken: ^9.0.2
|
||||||
lint-staged: ^15.2.10
|
lint-staged: ^15.2.10
|
||||||
lodash.clonedeep: ^4.5.0
|
lodash.clonedeep: ^4.5.0
|
||||||
|
lodash.set: ^4.3.2
|
||||||
lucide-vue-next: ^0.461.0
|
lucide-vue-next: ^0.461.0
|
||||||
medium-zoom: ^1.1.0
|
medium-zoom: ^1.1.0
|
||||||
naive-ui: ^2.40.2
|
naive-ui: ^2.40.2
|
||||||
|
Loading…
Reference in New Issue
Block a user