This commit is contained in:
kailong321200875 2024-04-08 13:57:35 +08:00
parent f977fdb05d
commit 08665a35ac
3 changed files with 15 additions and 1 deletions

View File

@ -5,7 +5,7 @@
"source.fixAll.eslint": "explicit"
},
"[vue]": {
"editor.defaultFormatter": "Vue.volar"
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"i18n-ally.localesPaths": ["src/locales"],
"i18n-ally.keystyle": "nested",

View File

@ -143,6 +143,7 @@ export const setItemComponentSlots = (slotsProps: Recordable = {}): Recordable =
*/
export const initModel = (schema: FormSchema[], formModel: Recordable) => {
const model: Recordable = { ...formModel }
console.log('【model】', model)
schema.map((v) => {
if (v.remove) {
delete model[v.field]
@ -158,5 +159,12 @@ export const initModel = (schema: FormSchema[], formModel: Recordable) => {
// model[v.field] = hasField ? model[v.field] : v.value !== void 0 ? v.value : undefined
}
})
// 如果 schema 对应的 field 不存在,则删除 model 中的对应的 field
Object.keys(model).forEach((key) => {
const isExist = schema.some((item) => item.field === key)
if (!isExist) {
delete model[key]
}
})
return model
}

View File

@ -407,6 +407,11 @@ setTimeout(async () => {
const formData = await getFormData()
console.log(formData)
}, 2000)
const getData = async () => {
const formData = await getFormData()
console.log(formData)
}
</script>
<template>
@ -451,6 +456,7 @@ setTimeout(async () => {
<BaseButton @click="inoutValidation">
{{ `${t('formDemo.input')} ${t('formDemo.formValidation')}` }}
</BaseButton>
<BaseButton @click="getData"> 获取值 </BaseButton>
</ContentWrap>
<ContentWrap :title="`UseForm ${t('formDemo.example')}`">
<Form :schema="schema" @register="formRegister" @validate="formValidate" />