配置 add.formData 修复 Object.assign 把个别属性去掉的问题

This commit is contained in:
吕金泽 2022-08-09 16:26:02 +08:00
parent 7554372850
commit 9478c2e960
2 changed files with 8 additions and 3 deletions

View File

@ -25,6 +25,7 @@
<script setup>
import { ref, reactive, getCurrentInstance, watch } from 'vue'
import common from '@/scripts/common'
const { proxy } = getCurrentInstance()
const rules = reactive(getRules())
const formData = ref(initFormData())
@ -51,7 +52,7 @@
watch(() => [props.detail && props.detail.formData, props.add && props.add.formData], (value) => {
value.forEach(it => {
if(it){
Object.assign(formData.value, it)
formData.value = common.objectAssign(formData.value, it)
}
})
},{ deep: true })
@ -61,7 +62,7 @@
proxy.$common.setDefaultValue(props.form.props, 'labelWidth', '120px')
if(props.add && props.add.formData){
Object.assign(formData.value, props.add.formData)
formData.value = common.objectAssign(formData.value, props.add.formData)
}
function getRules(){
@ -122,7 +123,7 @@
}
}
if(formData.value){
formData.value = Object.assign(_formData, formData.value)
formData.value = common.objectAssign(_formData, formData.value)
} else {
formData.value = _formData
}

View File

@ -229,4 +229,8 @@ common.exportExcel = (options) => {
writeFile(wb, `${options.fileName}.${options.suffix || 'xlsx'}`);
}
common.objectAssign = (target, source) => {
return Object.assign({}, JSON.parse(JSON.stringify(target)), JSON.parse(JSON.stringify(source)))
}
export default common