mirror of
https://gitee.com/ssssssss-team/magic-boot.git
synced 2025-03-16 03:51:02 +08:00
mb-form 支持插槽
增加 add.formData属性 设置隐藏值 默认值
This commit is contained in:
parent
4fe228fdcb
commit
c28a347e51
@ -8,7 +8,9 @@
|
|||||||
<el-row v-for="(row,i) in form.rows" :key="i" :gutter="row.gutter">
|
<el-row v-for="(row,i) in form.rows" :key="i" :gutter="row.gutter">
|
||||||
<el-col v-for="(col,j) in row.cols" :key="j" :span="col.span" v-bind="col.colProps">
|
<el-col v-for="(col,j) in row.cols" :key="j" :span="col.span" v-bind="col.colProps">
|
||||||
<el-form-item :label="col.label" :label-width="col.labelWidth" :prop="col.name" v-bind="col.formItemProps">
|
<el-form-item :label="col.label" :label-width="col.labelWidth" :prop="col.name" v-bind="col.formItemProps">
|
||||||
|
<slot v-if="col.component == 'dynamic'" :name="col.name" :form-data="formData" :col="col"></slot>
|
||||||
<component
|
<component
|
||||||
|
v-else
|
||||||
:is="!col.component ? 'mb-input' : col.component.startsWith('el-') || $global.dynamicComponentNames.indexOf(col.component) != -1 ? col.component : 'mb-' + col.component"
|
:is="!col.component ? 'mb-input' : col.component.startsWith('el-') || $global.dynamicComponentNames.indexOf(col.component) != -1 ? col.component : 'mb-' + col.component"
|
||||||
v-model="formData[col.name]"
|
v-model="formData[col.name]"
|
||||||
:item-label="col.label"
|
:item-label="col.label"
|
||||||
@ -25,7 +27,7 @@
|
|||||||
import { ref, reactive, getCurrentInstance, watch } from 'vue'
|
import { ref, reactive, getCurrentInstance, watch } from 'vue'
|
||||||
const { proxy } = getCurrentInstance()
|
const { proxy } = getCurrentInstance()
|
||||||
const rules = reactive(getRules())
|
const rules = reactive(getRules())
|
||||||
const formData = ref({})
|
const formData = ref(initFormData())
|
||||||
const dataForm = ref()
|
const dataForm = ref()
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
form: {
|
form: {
|
||||||
@ -36,29 +38,30 @@
|
|||||||
type: Object,
|
type: Object,
|
||||||
default: () => {}
|
default: () => {}
|
||||||
},
|
},
|
||||||
|
add: {
|
||||||
|
type: Object,
|
||||||
|
default: () => {}
|
||||||
|
},
|
||||||
primaryField: {
|
primaryField: {
|
||||||
type: String,
|
type: String,
|
||||||
default: 'id'
|
default: 'id'
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
const emit = defineEmits(['reload'])
|
const emit = defineEmits(['reload'])
|
||||||
watch(() => props.detail.formData, (value) => {
|
watch(() => [props.detail && props.detail.formData, props.add && props.add.formData], (value) => {
|
||||||
Object.assign(formData.value, value)
|
value.forEach(it => {
|
||||||
|
if(it){
|
||||||
|
Object.assign(formData.value, it)
|
||||||
|
}
|
||||||
|
})
|
||||||
},{ deep: true })
|
},{ deep: true })
|
||||||
|
|
||||||
props.form.props = props.form.props || {}
|
props.form.props = props.form.props || {}
|
||||||
proxy.$common.setDefaultValue(props.form.props, 'labelPosition', 'right')
|
proxy.$common.setDefaultValue(props.form.props, 'labelPosition', 'right')
|
||||||
proxy.$common.setDefaultValue(props.form.props, 'labelWidth', '120px')
|
proxy.$common.setDefaultValue(props.form.props, 'labelWidth', '120px')
|
||||||
|
|
||||||
if(props.detail && props.detail.formData){
|
if(props.add && props.add.formData){
|
||||||
if(props.detail.handlerFormData){
|
Object.assign(formData.value, props.add.formData)
|
||||||
props.detail.handlerFormData(props.detail.formData)
|
|
||||||
}
|
|
||||||
formData.value = props.detail.formData
|
|
||||||
}
|
|
||||||
|
|
||||||
if(props.detail && props.detail.request){
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getRules(){
|
function getRules(){
|
||||||
@ -99,9 +102,6 @@
|
|||||||
type: 'success',
|
type: 'success',
|
||||||
duration: 2000
|
duration: 2000
|
||||||
})
|
})
|
||||||
if(props.detail && props.detail.formData){
|
|
||||||
props.detail.formData = {}
|
|
||||||
}
|
|
||||||
d.hide()
|
d.hide()
|
||||||
emit('reload')
|
emit('reload')
|
||||||
}).catch(() => d.hideLoading())
|
}).catch(() => d.hideLoading())
|
||||||
@ -110,23 +110,28 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getDetail(id) {
|
function getDetail(id) {
|
||||||
|
if(props.detail.handlerFormData && props.detail.formData){
|
||||||
|
props.detail.handlerFormData(props.detail.formData)
|
||||||
|
}
|
||||||
formData.value = props.detail.formData || {}
|
formData.value = props.detail.formData || {}
|
||||||
var detailData = initFormData()
|
if(props.detail && props.detail.request){
|
||||||
detailData[props.primaryField] = id
|
var _formData = initFormData()
|
||||||
|
_formData[props.primaryField] = id
|
||||||
proxy.$get(props.detail.request.url, { [props.primaryField]: id }).then(res => {
|
proxy.$get(props.detail.request.url, { [props.primaryField]: id }).then(res => {
|
||||||
const { data } = res
|
const { data } = res
|
||||||
for (var t in detailData) {
|
for (var t in _formData) {
|
||||||
if ((data[t] || data[t] === 0) && (!props.detail.excludeAssign || props.detail.excludeAssign.indexOf(t) === -1)) {
|
if ((data[t] || data[t] === 0) && (!props.detail.excludeAssign || props.detail.excludeAssign.indexOf(t) === -1)) {
|
||||||
detailData[t] = data[t]
|
_formData[t] = data[t]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(formData.value){
|
if(formData.value){
|
||||||
formData.value = Object.assign(detailData, formData.value)
|
formData.value = Object.assign(_formData, formData.value)
|
||||||
} else {
|
} else {
|
||||||
formData.value = detailData
|
formData.value = _formData
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
defineExpose({ save, getDetail, getFormData })
|
defineExpose({ save, getDetail, getFormData })
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user