Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 日期组件:已选中默认值,显示类型在由 dates 切换 到其他类型,或其他类型切换到 dates 时 的报错导致整个设计器无响应 #33

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<form-item-wrapper :designer="designer" :field="field" :rules="rules" :design-state="designState"
:parent-widget="parentWidget" :parent-list="parentList" :index-of-parent-list="indexOfParentList"
:sub-form-row-index="subFormRowIndex" :sub-form-col-index="subFormColIndex" :sub-form-row-id="subFormRowId">
<el-date-picker ref="fieldEditor" :type="field.options.type" v-model="fieldModel"
<el-date-picker ref="fieldEditor" :key="field.options.type" :type="field.options.type" v-model="fieldModel"
:class="[!!field.options.autoFullWidth ? 'auto-full-width' : '']"
:readonly="field.options.readonly" :disabled="field.options.disabled"
:size="widgetSize"
Expand Down Expand Up @@ -63,6 +63,19 @@
},
computed: {

},
watch: {
'field.options.type': {
deep: true,
handler(val, oldVal){
if (val === 'dates' && oldVal !== 'dates'){
this.fieldModel = [this.fieldModel]
}
if (val !== 'dates' && oldVal === 'dates'){
this.fieldModel = this.fieldModel ? this.fieldModel[0] : null
}
},
}
},
beforeCreate() {
/* 这里不能访问方法和属性!! */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<el-form-item :label="i18nt('designer.setting.defaultValue')">
<el-date-picker :type="optionModel.type" v-model="optionModel.defaultValue" @change="emitDefaultValueChange"
<el-date-picker :key="optionModel.type" :type="optionModel.type" v-model="optionModel.defaultValue" @change="emitDefaultValueChange"
:format="optionModel.format" :value-format="optionModel.valueFormat" style="width: 100%">
</el-date-picker>
</el-form-item>
Expand All @@ -18,6 +18,19 @@
selectedWidget: Object,
optionModel: Object,
},
watch: {
'optionModel.type': {
deep: true,
handler(val, oldVal){
if (val === 'dates' && oldVal !== 'dates'){
this.optionModel.defaultValue = [this.optionModel.defaultValue]
}
if (val !== 'dates' && oldVal === 'dates'){
this.optionModel.defaultValue = this.optionModel.defaultValue ? this.optionModel.defaultValue[0] : null
}
},
}
},
}
</script>

Expand Down