|
|
@@ -129,6 +129,11 @@ const props = defineProps({
|
|
|
type: Number,
|
|
|
default: 1
|
|
|
},
|
|
|
+ // 不设置默认数据
|
|
|
+ noData: {
|
|
|
+ type: Boolean,
|
|
|
+ default: false
|
|
|
+ },
|
|
|
// 表单初始值 / v-model 绑定值
|
|
|
modelValue: {
|
|
|
type: Object,
|
|
|
@@ -207,28 +212,32 @@ const selectChip = (key, value) => {
|
|
|
// 初始化表单数据
|
|
|
const initFormData = () => {
|
|
|
const initial = {}
|
|
|
+ if (!props.noData) {
|
|
|
props.fields.forEach(field => {
|
|
|
- // 1. 优先使用外部传入的 modelValue(如果值不为 null 或 undefined)
|
|
|
- if (props.modelValue && props.modelValue[field.key] != null) {
|
|
|
- initial[field.key] = props.modelValue[field.key]
|
|
|
- }
|
|
|
- // 2. 其次使用字段配置的 defaultValue
|
|
|
- else if (field.defaultValue !== undefined) {
|
|
|
- initial[field.key] = field.defaultValue
|
|
|
- }
|
|
|
- // 3. 日期字段特殊处理:默认当前月(即使 modelValue 中存在但为 null/undefined)
|
|
|
- else if (field.type === 'date' || field.type === 'daterange') {
|
|
|
- initial[field.key] = getDefaultDateValue(field)
|
|
|
- }
|
|
|
- // 4. select 类型字段如果没有默认值,默认置空,不强制选第一个
|
|
|
- else if (field.type === 'select') {
|
|
|
- initial[field.key] = null
|
|
|
- }
|
|
|
- // 5. 其他字段默认为空字符串
|
|
|
- else {
|
|
|
- initial[field.key] = ''
|
|
|
- }
|
|
|
+ // 1. 优先使用外部传入的 modelValue(如果值不为 null 或 undefined)
|
|
|
+ if (props.modelValue && props.modelValue[field.key] != null) {
|
|
|
+ initial[field.key] = props.modelValue[field.key]
|
|
|
+ }
|
|
|
+ // 2. 其次使用字段配置的 defaultValue
|
|
|
+ else if (field.defaultValue !== undefined) {
|
|
|
+ initial[field.key] = field.defaultValue
|
|
|
+ return
|
|
|
+ }
|
|
|
+ // 3. 日期字段特殊处理:默认当前月(即使 modelValue 中存在但为 null/undefined)
|
|
|
+ else if (field.type === 'date' || field.type === 'daterange') {
|
|
|
+ initial[field.key] = getDefaultDateValue(field)
|
|
|
+ }
|
|
|
+ // 4. select 类型字段如果没有默认值,默认置空,不强制选第一个
|
|
|
+ else if (field.type === 'select') {
|
|
|
+ initial[field.key] = null
|
|
|
+ }
|
|
|
+ // 5. 其他字段默认为空字符串
|
|
|
+ else {
|
|
|
+ initial[field.key] = ''
|
|
|
+ }
|
|
|
})
|
|
|
+ }
|
|
|
+
|
|
|
formData.value = initial
|
|
|
tempFormData.value = JSON.parse(JSON.stringify(initial))
|
|
|
handleSearch()
|