|
9 | 9 | -->
|
10 | 10 | <template>
|
11 | 11 | <el-form-item :rules="widget.rules || []"
|
12 |
| - :prop="widget.type == 'button' ? undefined : widget.model" |
| 12 | + :prop="formElement.includes(widget.type) ? widget.model : undefined" |
13 | 13 | :label-width="widget.options.hiddenLabel ? '0' : labelWidth"
|
14 | 14 | :class="widget.options.className">
|
15 | 15 | <template #label>
|
|
31 | 31 | <el-input
|
32 | 32 | v-if="['number', 'integer', 'float'].includes(widget.options.dataType)"
|
33 | 33 | :type="widget.options.dataType"
|
34 |
| - v-model.number="dataModel" |
| 34 | + v-model.number="models[widget.model]" |
35 | 35 | :placeholder="widget.options.placeholder"
|
36 | 36 | :readonly="readOnly || widget.options.readonly"
|
37 | 37 | :disabled="readOnly || widget.options.disabled"
|
|
40 | 40 | <el-input
|
41 | 41 | v-else
|
42 | 42 | type="text"
|
43 |
| - v-model="dataModel" |
| 43 | + v-model="models[widget.model]" |
44 | 44 | :show-word-limit="widget.options.showWordLimit"
|
45 | 45 | :maxlength="widget.options.maxLength"
|
46 | 46 | :placeholder="widget.options.placeholder"
|
|
82 | 82 | </h3>
|
83 | 83 | </template>
|
84 | 84 | <template v-if="widget.type == 'label'">
|
85 |
| - <p>{{ dataModel }}</p> |
| 85 | + <p>{{ models[widget.model] }}</p> |
86 | 86 | </template>
|
87 | 87 | <template v-if="widget.type == 'select'">
|
88 | 88 | <el-select
|
89 |
| - v-model="dataModel" |
| 89 | + v-model="models[widget.model]" |
90 | 90 | default-first-option
|
91 | 91 | :disabled="readOnly || widget.options.disabled"
|
92 | 92 | :readonly="readOnly || widget.options.readonly"
|
|
107 | 107 | <el-input
|
108 | 108 | type="textarea"
|
109 | 109 | :autosize="{ minRows: 5 }"
|
110 |
| - v-model="dataModel" |
| 110 | + v-model="models[widget.model]" |
111 | 111 | :show-word-limit="widget.options.showWordLimit"
|
112 | 112 | :maxlength="widget.options.maxLength"
|
113 | 113 | :disabled="readOnly || widget.options.disabled"
|
|
119 | 119 |
|
120 | 120 | <template v-if="widget.type == 'number'">
|
121 | 121 | <el-input-number
|
122 |
| - v-model="dataModel" |
| 122 | + v-model="models[widget.model]" |
123 | 123 | :style="{ width: widget.options.width }"
|
124 | 124 | :step="widget.options.step"
|
125 | 125 | :disabled="readOnly || widget.options.disabled"
|
|
129 | 129 | </template>
|
130 | 130 |
|
131 | 131 | <template v-if="widget.type == 'radio'">
|
132 |
| - <el-radio-group v-model="dataModel" :style="{ width: widget.options.width }" :disabled="readOnly || widget.options.disabled"> |
| 132 | + <el-radio-group v-model="models[widget.model]" :style="{ width: widget.options.width }" :disabled="readOnly || widget.options.disabled"> |
133 | 133 | <el-radio :style="{ display: widget.options.inline ? 'inline-block' : 'block' }" :label="item.value" v-for="(item, index) in optionsList" :key="index">
|
134 | 134 | <template v-if="widget.options.showLabel">{{ item.label }}</template>
|
135 | 135 | </el-radio>
|
136 | 136 | </el-radio-group>
|
137 | 137 | </template>
|
138 | 138 |
|
139 | 139 | <template v-if="widget.type == 'checkbox'">
|
140 |
| - <el-checkbox-group v-model="dataModel" :style="{ width: widget.options.width }"> |
| 140 | + <el-checkbox-group v-model="models[widget.model]" :style="{ width: widget.options.width }"> |
141 | 141 | <template v-if="!widget.options.buttonStyle">
|
142 | 142 | <el-checkbox
|
143 | 143 | :style="{ display: widget.options.inline ? 'inline-block' : 'block' }"
|
|
158 | 158 |
|
159 | 159 | <template v-if="widget.type == 'time'">
|
160 | 160 | <el-time-picker
|
161 |
| - v-model="dataModel" |
| 161 | + v-model="models[widget.model]" |
162 | 162 | :is-range="widget.options.isRange"
|
163 | 163 | :placeholder="widget.options.placeholder"
|
164 | 164 | :start-placeholder="widget.options.startPlaceholder"
|
|
176 | 176 |
|
177 | 177 | <template v-if="widget.type == 'date'">
|
178 | 178 | <el-date-picker
|
179 |
| - v-model="dataModel" |
| 179 | + v-model="models[widget.model]" |
180 | 180 | :type="widget.options.type"
|
181 | 181 | :placeholder="widget.options.placeholder"
|
182 | 182 | :start-placeholder="widget.options.startPlaceholder"
|
|
195 | 195 | </template>
|
196 | 196 |
|
197 | 197 | <template v-if="widget.type == 'rate'">
|
198 |
| - <el-rate v-model="dataModel" :max="widget.options.max" :disabled="readOnly || widget.options.disabled" :allow-half="widget.options.allowHalf"></el-rate> |
| 198 | + <el-rate v-model="models[widget.model]" :max="widget.options.max" :disabled="readOnly || widget.options.disabled" :allow-half="widget.options.allowHalf"></el-rate> |
199 | 199 | </template>
|
200 | 200 |
|
201 | 201 | <template v-if="widget.type == 'color'">
|
202 |
| - <el-color-picker v-model="dataModel" :disabled="readOnly || widget.options.disabled" :show-alpha="widget.options.showAlpha"></el-color-picker> |
| 202 | + <el-color-picker v-model="models[widget.model]" :disabled="readOnly || widget.options.disabled" :show-alpha="widget.options.showAlpha"></el-color-picker> |
203 | 203 | </template>
|
204 | 204 |
|
205 | 205 | <template v-if="widget.type == 'switch'">
|
206 |
| - <el-switch v-model="dataModel" :disabled="readOnly || widget.options.disabled"> </el-switch> |
| 206 | + <el-switch v-model="models[widget.model]" :disabled="readOnly || widget.options.disabled"> </el-switch> |
207 | 207 | </template>
|
208 | 208 |
|
209 | 209 | <template v-if="widget.type == 'slider'">
|
210 | 210 | <el-slider
|
211 |
| - v-model="dataModel" |
| 211 | + v-model="models[widget.model]" |
212 | 212 | :min="widget.options.min"
|
213 | 213 | :max="widget.options.max"
|
214 | 214 | :disabled="readOnly || widget.options.disabled"
|
|
221 | 221 | <template v-if="widget.type == 'cascader'">
|
222 | 222 | <el-cascader
|
223 | 223 | ref="cascader"
|
| 224 | + v-model="models[widget.model]" |
224 | 225 | @visible-change="elCascaderOnlick"
|
225 | 226 | @expand-change="elCascaderOnlick"
|
226 |
| - v-model="dataModel" |
227 | 227 | :disabled="readOnly || widget.options.disabled"
|
228 | 228 | :clearable="widget.options.clearable"
|
229 | 229 | :placeholder="widget.options.placeholder"
|
230 | 230 | :style="{ width: widget.options.width }"
|
231 | 231 | :separator="widget.options.separator == null ? '/' : widget.options.separator"
|
232 | 232 | :options="optionsList"
|
233 | 233 | filterable
|
234 |
| - :props="{ checkStrictly: widget.options.checkStrictly, multiple: widget.options.multiple }" |
| 234 | + :props="{ checkStrictly: widget.options.checkStrictly, multiple: widget.options.multiple,expandTrigger: 'hover' }" |
235 | 235 | >
|
236 | 236 | </el-cascader>
|
237 | 237 | </template>
|
|
258 | 258 | <!-- 目前暂时提供了几个常用props,有更多需要自行拓展 -->
|
259 | 259 | <!-- 官网:https://vue-treeselect.js.org -->
|
260 | 260 | <TreeSelect
|
261 |
| - v-model="dataModel" |
| 261 | + v-model="models[widget.model]" |
262 | 262 | v-if="visible"
|
263 | 263 | :placeholder="widget.options.placeholder"
|
264 | 264 | :maxHeight="+widget.options.maxHeight"
|
|
286 | 286 | </TreeSelect>
|
287 | 287 | </template>
|
288 | 288 | <template v-if="widget.type == 'richtext'">
|
289 |
| - <Tinymce :height="400" v-model="dataModel" :readonly="readOnly || widget.options.readonly"></Tinymce> |
| 289 | + <Tinymce :height="400" v-model="models[widget.model]" :readonly="readOnly || widget.options.readonly"></Tinymce> |
290 | 290 | </template>
|
291 | 291 | <template v-if="widget.type == 'upload'">
|
292 | 292 | <!-- 附件上传(注意初始值prefill必须传入id) -->
|
|
299 | 299 | ></FileUpload>
|
300 | 300 | </template>
|
301 | 301 | <template v-if="widget.type === 'avatar'">
|
302 |
| - <AvatarUpload :readOnly="readOnly" :widget="widget" v-model="dataModel"></AvatarUpload> |
| 302 | + <AvatarUpload :readOnly="readOnly" :widget="widget" v-model="models[widget.model]"></AvatarUpload> |
303 | 303 | </template>
|
304 | 304 | <template v-if="widget.type === 'form'">
|
305 | 305 | <GenerateSubForm :widget="widget"></GenerateSubForm>
|
@@ -356,6 +356,7 @@ import pieChart from './components/Charts/pieChart.vue';
|
356 | 356 | import Echarts from './components/Charts/Echarts.vue';
|
357 | 357 | import GenerateTabs from './components/Tabs/GenerateTabs.vue';
|
358 | 358 | import AvatarUpload from './components/AvatarUpload/AvatarUpload.vue';
|
| 359 | +import { formElement } from './componentsConfig'; |
359 | 360 |
|
360 | 361 | @Component({
|
361 | 362 | components: {
|
@@ -412,27 +413,16 @@ export default class GenerateFormItem extends Vue {
|
412 | 413 | })
|
413 | 414 | readOnly!: boolean
|
414 | 415 |
|
415 |
| - |
416 |
| - // 当前组件对象 |
417 |
| - dataModel: string | number | null | object = this.models[this.widget.model] || null |
418 |
| - |
419 | 416 | copyOption: any = [] // 备份一份初始选项
|
420 | 417 |
|
421 | 418 | visible = false
|
422 | 419 |
|
423 | 420 | normalizer: any
|
424 | 421 |
|
| 422 | + formElement = formElement |
| 423 | + |
425 | 424 | initData() {
|
426 | 425 | const { type, model } = this.widget;
|
427 |
| - // if (this.model) { |
428 |
| - // // 多选组件需要初始化值为数组 |
429 |
| - // if (this.widget.options.multiple || 'cascader,checkbox'.includes(type)) { |
430 |
| - // this.dataModel = typeof this.model === 'string' ? this.model.split(',') : this.model; |
431 |
| - // } else { |
432 |
| - // this.dataModel = this.model; |
433 |
| - // } |
434 |
| - // return; |
435 |
| - // } |
436 | 426 | let normalizer;
|
437 | 427 | // tree-select组件初始化
|
438 | 428 | if (type === 'treeselect') {
|
@@ -463,7 +453,6 @@ export default class GenerateFormItem extends Vue {
|
463 | 453 | }
|
464 | 454 | }
|
465 | 455 | this.normalizer = normalizer;
|
466 |
| - this.dataModel = this.models[model]; |
467 | 456 | }
|
468 | 457 |
|
469 | 458 | created() {
|
@@ -680,7 +669,9 @@ export default class GenerateFormItem extends Vue {
|
680 | 669 | document.querySelectorAll('.el-cascader-node__label').forEach((el) => {
|
681 | 670 | // eslint-disable-next-line func-names
|
682 | 671 | (el as any).onclick = function () {
|
683 |
| - this.previousElementSibling.click(); |
| 672 | + if (this.previousElementSibling) { |
| 673 | + this.previousElementSibling.click(); |
| 674 | + } |
684 | 675 | that.$refs.cascader.dropDownVisible = false;
|
685 | 676 | };
|
686 | 677 | });
|
@@ -709,27 +700,6 @@ export default class GenerateFormItem extends Vue {
|
709 | 700 | this.$emit('selection-change', selection);
|
710 | 701 | }
|
711 | 702 |
|
712 |
| - @Watch('dataModel') |
713 |
| - dataModelHandler(val) { |
714 |
| - this.$set(this.models, this.widget.model, val); |
715 |
| - this.$emit('change', val); |
716 |
| - } |
717 |
| - |
718 |
| - @Watch('models', { |
719 |
| - deep: true, |
720 |
| - }) |
721 |
| - modelsHandler(val) { |
722 |
| - const updateVal = val[this.widget.model]; |
723 |
| - if (updateVal !== this.dataModel) { |
724 |
| - if (this.widget.options.multiple || 'cascader,checkbox'.includes(this.widget.type)) { |
725 |
| - const value = val[this.widget.model]; |
726 |
| - this.dataModel = typeof value === 'string' ? value.split(',') : value; |
727 |
| - } else { |
728 |
| - this.dataModel = val[this.widget.model]; |
729 |
| - } |
730 |
| - } |
731 |
| - } |
732 |
| - |
733 | 703 | // 如果表格预设参数发生变化 自动刷新表格
|
734 | 704 | @Watch('getTableParams', {
|
735 | 705 | deep: true,
|
|
0 commit comments