Skip to content

Commit

Permalink
fix: Invalid parameter saving display
Browse files Browse the repository at this point in the history
  • Loading branch information
shaohuzhang1 committed Dec 25, 2024
1 parent 28ceb94 commit c25c00e
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 36 deletions.
3 changes: 3 additions & 0 deletions ui/src/components/dynamics-form/constructor/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ onMounted(() => {
const rander = (data: any) => {
form_data.value.required = data.required ? data.required : false
form_data.value.field = data.field
if (data.show_default_value !== undefined) {
form_data.value.show_default_value = data.show_default_value
}
if (data.input_type) {
form_data.value.input_type = data.input_type + 'Constructor'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,21 +97,22 @@ const getData = () => {
'value-format': formValue.value.format
},
default_value: formValue.value.default_value,
show_default_value: formValue.value.show_default_value,
show_default_value: formValue.value.show_default_value
}
}
const rander = (form_data: any) => {
formValue.value.type = form_data.attrs.type
formValue.value.format = form_data.attrs?.format
formValue.value.default_value = form_data.default_value || ''
formValue.value.show_default_value = form_data.show_default_value
}
defineExpose({ getData, rander })
onBeforeMount(() => {
formValue.value.type = 'datetime'
formValue.value.format = 'YYYY-MM-DD HH:mm:ss'
formValue.value.default_value = ''
formValue.value.show_default_value = true
if (formValue.value.show_default_value === undefined) {
formValue.value.show_default_value = true
}
})
</script>
<style lang="scss"></style>
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
<template>
<el-form-item
:required="formValue.required"
prop="default_value"
:rules="[default_value_rule]"
>
<el-form-item :required="formValue.required" prop="default_value" :rules="[default_value_rule]">
<template #label>
<div class="flex-between">
默认值
Expand Down Expand Up @@ -46,7 +42,7 @@ const getData = () => {
]
},
default_value: formValue.value.default_value,
show_default_value: formValue.value.show_default_value,
show_default_value: formValue.value.show_default_value
}
}
Expand All @@ -61,12 +57,13 @@ const default_value_rule = {
const rander = (form_data: any) => {
formValue.value.default_value = form_data.default_value
formValue.value.show_default_value = form_data.show_default_value
}
defineExpose({ getData, rander })
onMounted(() => {
formValue.value.default_value = {}
formValue.value.show_default_value = true
if (formValue.value.show_default_value === undefined) {
formValue.value.show_default_value = true
}
})
</script>
<style lang="scss"></style>
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,15 @@ const getData = () => {
const rander = (form_data: any) => {
formValue.value.option_list = form_data.option_list || []
formValue.value.default_value = form_data.default_value
formValue.value.show_default_value = form_data.show_default_value
}
defineExpose({ getData, rander })
onMounted(() => {
formValue.value.option_list = []
formValue.value.default_value = ''
formValue.value.show_default_value = true
if (formValue.value.show_default_value === undefined) {
formValue.value.show_default_value = true
}
addOption()
})
</script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,15 @@ const getData = () => {
const rander = (form_data: any) => {
formValue.value.option_list = form_data.option_list || []
formValue.value.default_value = form_data.default_value
formValue.value.show_default_value = form_data.show_default_value
}
defineExpose({ getData, rander })
onMounted(() => {
formValue.value.option_list = []
formValue.value.default_value = ''
formValue.value.show_default_value = true
if (formValue.value.show_default_value === undefined) {
formValue.value.show_default_value = true
}
addOption()
})
</script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@
prop="default_value"
:rules="formValue.required ? [{ required: true, message: '默认值 为必填属性' }] : []"
>
<template #label>
<div class="flex-between">
默认值
<el-checkbox v-model="formValue.show_default_value" label="显示默认值" />
</div>
</template>
<RadioRow
:form-field="formField"
v-model="formValue.default_value"
Expand Down Expand Up @@ -111,7 +117,9 @@ defineExpose({ getData, rander })
onMounted(() => {
formValue.value.option_list = []
formValue.value.default_value = ''
if (formValue.value.show_default_value === undefined) {
formValue.value.show_default_value = true
}
addOption()
})
</script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,9 @@ defineExpose({ getData, rander })
onMounted(() => {
formValue.value.option_list = []
formValue.value.default_value = ''
formValue.value.show_default_value = true
if (formValue.value.show_default_value === undefined) {
formValue.value.show_default_value = true
}
addOption()
})
</script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,10 @@ onMounted(() => {
formValue.value.minlength = 0
formValue.value.maxlength = 20
formValue.value.default_value = ''
formValue.value.show_default_value = true
console.log(formValue.value.show_default_value)
if (formValue.value.show_default_value === undefined) {
formValue.value.show_default_value = true
}
})
</script>
<style lang="scss"></style>
15 changes: 7 additions & 8 deletions ui/src/components/dynamics-form/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,9 @@ const initDefaultData = (formField: FormField) => {
!formValue.value[formField.field]) &&
formValue.value[formField.field] != false
) {
formValue.value[formField.field] = formField.default_value
}
// 配置不展示默认值,则设置为undefined
if (formField.show_default_value === false) {
formValue.value[formField.field] = undefined
console.log(formField.show_default_value, formValue.value[formField.field])
if (formField.show_default_value === true) {
formValue.value[formField.field] = formField.default_value
}
}
}
Expand Down Expand Up @@ -185,7 +181,10 @@ const render = (
if (form_data[item.field] !== undefined) {
return { [item.field]: form_data[item.field] }
}
return { [item.field]: item.default_value }
if (item.show_default_value) {
return { [item.field]: item.default_value }
}
return {}
})
.reduce((x, y) => ({ ...x, ...y }), {})
formValue.value = _.cloneDeep(value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import type { FormField } from '@/components/dynamics-form/type'
import modelAPi from '@/api/model'
import applicationApi from '@/api/application'
import DynamicsForm from '@/components/dynamics-form/index.vue'
import { keys } from 'lodash'
const model_form_field = ref<Array<FormField>>([])
const emit = defineEmits(['refresh'])
const dynamicsFormRef = ref<InstanceType<typeof DynamicsForm>>()
Expand All @@ -55,12 +54,6 @@ const open = (model_id: string, application_id?: string, model_setting_data?: an
const api = getApi(model_id, application_id)
api.then((ok) => {
model_form_field.value = ok.data
model_setting_data =
model_setting_data && keys(model_setting_data).length > 0
? model_setting_data
: ok.data
.map((item: any) => ({ [item.field]: item.default_value }))
.reduce((x, y) => ({ ...x, ...y }), {})
// 渲染动态表单
dynamicsFormRef.value?.render(model_form_field.value, model_setting_data)
})
Expand Down

0 comments on commit c25c00e

Please sign in to comment.