n20-project-component 1.0.3 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,847 @@
1
+ <script>
2
+ import asciiWidth from 'n20-common-lib/src/utils/asciiWidth'
3
+ import axios from 'n20-common-lib/src/utils/axios'
4
+ import forEachs from 'n20-common-lib/src/utils/forEachs'
5
+ import { $lc } from 'n20-common-lib/src/utils/i18n/index.js'
6
+ import datePickerPor from 'n20-common-lib/src/components/DatePicker/por.vue'
7
+ import inputNumber from 'n20-common-lib/src/components/InputNumber/index.vue'
8
+ import InputNumberRange from 'n20-common-lib/src/components/InputNumber/numberRange.vue'
9
+ import selectTree from 'n20-common-lib/src/components/SelectTree/index.vue'
10
+ import selectTreePro from 'n20-common-lib/src/components/SelectTree/pro.vue'
11
+
12
+ const canvas = document.createElement('canvas')
13
+ const context = canvas.getContext('2d')
14
+ context.font = '14px Ping Fang SC'
15
+ export default {
16
+ name: 'FormItemRender',
17
+ components: {
18
+ inputNumber,
19
+ selectTree,
20
+ selectTreePro,
21
+ InputNumberRange,
22
+ datePickerPor
23
+ },
24
+ inject: {
25
+ nFilter: { default: null }
26
+ },
27
+ props: {
28
+ form: {
29
+ type: Object,
30
+ default: undefined
31
+ },
32
+ item: {
33
+ type: Object,
34
+ default: undefined
35
+ }
36
+ },
37
+ data() {
38
+ return {
39
+ context
40
+ }
41
+ },
42
+
43
+ created() {
44
+ if (this.item.reqOptions) {
45
+ this.getOptions()
46
+ }
47
+ },
48
+ methods: {
49
+ handleBlur() {
50
+ this.$emit('blur')
51
+ },
52
+ handleClear() {
53
+ this.$emit('clean')
54
+ },
55
+ handleFilter() {
56
+ this.$emit('filter')
57
+ },
58
+ handleEnter() {
59
+ this.$emit('enter')
60
+ },
61
+ handleChange(value) {
62
+ this.$emit('change', { field: this.item.value, value, item: this.item })
63
+ },
64
+ handleVisibleChange(value) {
65
+ if (!value) {
66
+ this.handleFilter()
67
+ }
68
+ },
69
+ getOptions() {
70
+ let reqOptions = this.item.reqOptions
71
+ let url = reqOptions.url || ''
72
+ url = url.includes('?') ? `${url}r=${Math.random()}` : `${url}?r=${Math.random()}`
73
+ axios({
74
+ ...reqOptions,
75
+ url: url,
76
+ loading: false,
77
+ noMsg: true,
78
+ resList: undefined
79
+ }).then((res) => {
80
+ let resKeys = reqOptions.resList ? reqOptions.resList.split('.') : ['data', 'list']
81
+
82
+ let list = res
83
+ resKeys.forEach((key) => {
84
+ list = list[key]
85
+ })
86
+ this.$set(this.item, 'options', list)
87
+ // 同步更新 filterList 中的 options,确保两者一致,
88
+ // 防止 AdvancedFilter 的 filterList watcher 用旧数据覆盖 reqOptions 结果
89
+ const nf = this.nFilter
90
+ if (nf) {
91
+ const filterItem = nf.filterList.find((f) => f[nf.onlyKey] === this.item[nf.onlyKey])
92
+ if (filterItem) {
93
+ this.$set(filterItem, 'options', list)
94
+ }
95
+ }
96
+ })
97
+ }
98
+ },
99
+ render(h) {
100
+ const { item, form, context } = this
101
+
102
+ let elementDom = null
103
+
104
+ let typeEnum = (type) => {
105
+ switch (type) {
106
+ case 'text':
107
+ case 'number':
108
+ case 'text':
109
+ case 'numberrange':
110
+ return $lc('请输入')
111
+ case 'select':
112
+ case 'search':
113
+ case 'date':
114
+ case 'datetime':
115
+ case 'year':
116
+ case 'month':
117
+ case 'week':
118
+ case 'daterange':
119
+ case 'datetimerange':
120
+ case 'monthrange':
121
+ case 'checkbox':
122
+ case 'radio':
123
+ return $lc('请选择')
124
+ }
125
+ }
126
+
127
+ // 获取文本宽度
128
+ const getWidth = (label, type) => {
129
+ if (!label) {
130
+ return 0
131
+ }
132
+ if (!type) {
133
+ return context.measureText(label).width
134
+ }
135
+ return (context.measureText(label).width * 1.4 + 100) * 2
136
+ }
137
+
138
+ let w = 76
139
+ if (item.placeholder) {
140
+ w = asciiWidth(item.placeholder || typeEnum(item.type)) + 34
141
+ if (/px$/.test(item.width)) {
142
+ w = item.width.replace(/px$/, '')
143
+ }
144
+ }
145
+
146
+ // 计算text框内容宽度
147
+ const calcTextWidth = (item, value) => {
148
+ let textMaxWidth,
149
+ textMinWidth = 76
150
+ if (item.required) {
151
+ textMaxWidth = 426 - getWidth(item.label) - 33
152
+ } else {
153
+ textMaxWidth = 426 - getWidth(item.label) - 14
154
+ }
155
+
156
+ // 没有内容时
157
+ if (!value) {
158
+ return textMinWidth + 'px'
159
+ }
160
+ // 输入内容+边距小于最小默认值时
161
+ if (getWidth(value) + 32 < textMinWidth) {
162
+ return textMinWidth + 'px'
163
+ }
164
+ // 输入内容+边距大于最大默认值时
165
+ if (getWidth(value) + 32 > textMaxWidth) {
166
+ return textMaxWidth + 'px'
167
+ }
168
+
169
+ return getWidth(value) + 32 + 'px'
170
+ }
171
+
172
+ const calcWidth = (value, type, label) => {
173
+ let MAX_WIDTH = 426 - getWidth(label) - 16
174
+ let W = null
175
+ if (!Array.isArray(value)) {
176
+ if (!value) {
177
+ if (type) {
178
+ return Number(w) + 110 + 'px'
179
+ }
180
+ return w + 'px'
181
+ }
182
+ if (getWidth(value, type) > w) {
183
+ if (getWidth(value, type) > MAX_WIDTH) {
184
+ W = MAX_WIDTH
185
+ } else {
186
+ W = getWidth(value, type)
187
+ }
188
+ } else {
189
+ if (type) {
190
+ W = w || asciiWidth(item.placeholder || typeEnum[item.type]) + 150
191
+ } else {
192
+ W = w || asciiWidth(item.placeholder || typeEnum[item.type]) + 40
193
+ }
194
+ }
195
+ } else {
196
+ if (!value[0] && !value[1]) {
197
+ return Number(w) + 110 + 'px'
198
+ }
199
+ let widthMax = getWidth(value[0]) + getWidth(value[1]) + 35
200
+ if (widthMax > w) {
201
+ if (widthMax > MAX_WIDTH) {
202
+ W = MAX_WIDTH
203
+ } else {
204
+ W = widthMax
205
+ }
206
+ }
207
+ }
208
+
209
+ return W + 'px'
210
+ }
211
+ const recursionFind = (data, value, key, name) => {
212
+ let found
213
+ forEachs(data, (item) => {
214
+ if (item[key] === value) {
215
+ found = item[name]
216
+ }
217
+ if (item.children && !found) {
218
+ found = recursionFind(item.children, value, key, name)
219
+ }
220
+ })
221
+
222
+ return found
223
+ }
224
+
225
+ // 计算selectTree内容宽度
226
+ const calcSelectTreeWidth = (item, value) => {
227
+ let textMaxWidth = 346 - getWidth(item.label) - 16
228
+ const multiple = item?.props?.multiple
229
+ const textMinWidth = 76
230
+
231
+ if (!multiple) {
232
+ if (!value) {
233
+ return textMinWidth + 'px'
234
+ } else {
235
+ let selectedName = ''
236
+ selectedName = recursionFind(
237
+ item.options,
238
+ value,
239
+ item?.props?.props?.value || item?.props?.defineProps?.value || 'value',
240
+ item?.props?.props?.label || item?.props?.defineProps?.label || 'label'
241
+ )
242
+
243
+ return getWidth(selectedName) + 'px'
244
+ }
245
+ } else {
246
+ if (!value?.length) {
247
+ return textMinWidth + 'px'
248
+ } else {
249
+ let selectedName = recursionFind(
250
+ item.options,
251
+ value[0],
252
+ item?.props?.props?.value || item?.props?.defineProps?.value || 'value',
253
+ item?.props?.props?.label || item?.props?.defineProps?.label || 'label'
254
+ )
255
+ if (value?.length > 1) {
256
+ return getWidth(selectedName) + 32 > textMaxWidth
257
+ ? textMaxWidth + 'px'
258
+ : getWidth(selectedName) + 110 + 'px'
259
+ } else {
260
+ return getWidth(selectedName) + 32 < textMinWidth ? textMinWidth + 'px' : getWidth(selectedName) + 84 + 'px'
261
+ }
262
+ }
263
+ }
264
+ }
265
+ // 计算select内容宽度
266
+ const calcSelectWidth = (item, value) => {
267
+ let textMaxWidth = 426 - getWidth(item.label) - 16
268
+ let textMinWidth = 76
269
+ const multiple = item.props?.multiple || item?.multiple || false
270
+ if (!multiple) {
271
+ if (!value) {
272
+ return textMinWidth + 'px'
273
+ } else {
274
+ let selectedName = recursionFind(
275
+ item.options,
276
+ value,
277
+ item.props?.valueKey || 'value',
278
+ item.props?.labelKey || 'label'
279
+ )
280
+ if (getWidth(selectedName) + 32 > textMaxWidth) {
281
+ return textMaxWidth + 'px'
282
+ }
283
+ if (getWidth(selectedName) + 32 < textMinWidth) {
284
+ return textMinWidth + 'px'
285
+ }
286
+ return getWidth(selectedName) + 32 + 'px'
287
+ }
288
+ } else {
289
+ if (!value?.length) {
290
+ return textMinWidth + 'px'
291
+ } else {
292
+ let selectedName = recursionFind(
293
+ item.options,
294
+ value[0],
295
+ item.props?.valueKey || 'value',
296
+ item.props?.labelKey || 'label'
297
+ )
298
+ if (value?.length > 1) {
299
+ return getWidth(selectedName) + 32 > textMaxWidth
300
+ ? textMaxWidth + 'px'
301
+ : getWidth(selectedName) > 88
302
+ ? '170px'
303
+ : getWidth(selectedName) + 110 + 'px'
304
+ } else {
305
+ return getWidth(selectedName) > 88
306
+ ? '128px'
307
+ : getWidth(selectedName) + 32 < textMinWidth
308
+ ? textMinWidth + 'px'
309
+ : getWidth(selectedName) + 84 + 'px'
310
+ }
311
+ }
312
+ }
313
+ }
314
+ // 计算区间内容宽度
315
+ const calcRangeWidth = (item, value, value2) => {
316
+ let textMaxWidth = 426 - getWidth(item.label) - 16
317
+ let textMinWidth = 160
318
+ if (!value && !value2) {
319
+ return textMinWidth + 'px'
320
+ } else {
321
+ if (!value || !value2) {
322
+ let widthMax = (getWidth(value) + getWidth(value2) + 72) * 2
323
+ if (widthMax < textMinWidth) {
324
+ return textMinWidth + 'px'
325
+ }
326
+ if (widthMax > textMaxWidth) {
327
+ return textMaxWidth + 'px'
328
+ }
329
+ return widthMax + 'px'
330
+ } else {
331
+ let widthMax = getWidth(value) + getWidth(value2) + 140
332
+ if (widthMax < textMinWidth) {
333
+ return textMinWidth + 'px'
334
+ }
335
+ if (widthMax > textMaxWidth) {
336
+ return textMaxWidth + 'px'
337
+ }
338
+ return widthMax + 'px'
339
+ }
340
+ }
341
+ }
342
+
343
+ const calcDateWidth = (item, value) => {
344
+ let textMaxWidth = 382 - getWidth(item.label) - 16
345
+ let textMinWidth = 76
346
+ if (!value) {
347
+ return textMinWidth + 'px'
348
+ } else {
349
+ if (getWidth(value) + 32 < textMinWidth) {
350
+ return textMinWidth + 'px'
351
+ }
352
+ if (getWidth(value) + 32 > textMaxWidth) {
353
+ return textMaxWidth + 'px'
354
+ }
355
+ return getWidth(value) + 32 + 'px'
356
+ }
357
+ }
358
+
359
+ const keyup = (ev) => {
360
+ if (ev.keyCode === 13) {
361
+ ev.target.blur()
362
+ this.handleEnter()
363
+ }
364
+ }
365
+
366
+ switch (item.type) {
367
+ case 'search':
368
+ case 'text':
369
+ elementDom = h(
370
+ 'el-input',
371
+ {
372
+ attrs: {
373
+ style: {
374
+ width: calcTextWidth(item, form[item.value])
375
+ },
376
+ title: form[item.value],
377
+ ruleField: true,
378
+ 'rule-form': 'ruleValidate',
379
+ ruleErrorHide: item.ruleErrorHide,
380
+ rules: item.rules,
381
+ readonly: item.type === 'search',
382
+ placeholder: item.props && item.props.placeholder ? item.props.placeholder : $lc('请输入'),
383
+ maxlength: item.props && item.props.maxlength,
384
+ minlength: item.props && item.props.minlength
385
+ },
386
+
387
+ directives: [
388
+ {
389
+ name: 'rule-key'
390
+ }
391
+ ],
392
+ props: {
393
+ clearable: (item.props && item.props.clearable) ?? true,
394
+ ...item.props
395
+ },
396
+ model: {
397
+ value: form[item.value],
398
+ callback: (value) => {
399
+ this.$set(form, item.value, value)
400
+ this.handleChange(value)
401
+ }
402
+ },
403
+ on: {
404
+ blur: this.handleBlur,
405
+ clear: this.handleClear,
406
+ ...item.on
407
+ },
408
+ nativeOn: {
409
+ keyup
410
+ }
411
+ },
412
+ item.type === 'search'
413
+ ? [
414
+ h('i', {
415
+ slot: 'suffix',
416
+ class: 'el-input__icon el-icon-zoom-in',
417
+ on: {
418
+ click: () => {
419
+ if (item.on && item.on.focus) {
420
+ item.on.focus()
421
+ }
422
+ }
423
+ }
424
+ })
425
+ ]
426
+ : []
427
+ )
428
+ break
429
+ case 'select':
430
+ let selectOptions = null
431
+ if (item.props && item.props.labelKey && item.props.valueKey) {
432
+ selectOptions = item.options.map((c, i) => {
433
+ return h('el-option', {
434
+ key: i,
435
+ props: {
436
+ label: c[item.props.labelKey],
437
+ value: c[item.props.valueKey],
438
+ disabled: c.disabled
439
+ }
440
+ })
441
+ })
442
+ } else {
443
+ selectOptions = item.options.map((c, j) => {
444
+ return h('el-option', {
445
+ key: j,
446
+ props: {
447
+ label: c.label,
448
+ value: c.value,
449
+ disabled: c.disabled
450
+ }
451
+ })
452
+ })
453
+ }
454
+
455
+ const selectProps = {
456
+ placeholder: item.props && item.props.placeholder ? item.props.placeholder : $lc('请选择'),
457
+ clearable: (item.props && this.item.props.clearable) ?? true,
458
+ multiple: item.multiple || item.props?.multiple,
459
+ ...item.props
460
+ }
461
+ elementDom = h(
462
+ 'el-select',
463
+ {
464
+ directives: [{ name: 'rule-key' }],
465
+ attrs: {
466
+ ruleField: true,
467
+ 'rule-form': 'ruleValidate',
468
+ ruleErrorHide: item.ruleErrorHide,
469
+ rules: item.rules,
470
+ collapseTags: true
471
+ },
472
+ style: {
473
+ width: calcSelectWidth(item, form[item.value])
474
+ },
475
+ props: selectProps,
476
+
477
+ model: {
478
+ value: form[item.value],
479
+ callback: (value) => {
480
+ this.$set(form, item.value, value)
481
+ this.handleChange(value)
482
+ }
483
+ },
484
+ on: {
485
+ clear: this.handleClear,
486
+ 'visible-change': this.handleVisibleChange,
487
+ ...item.on
488
+ }
489
+ },
490
+ selectOptions
491
+ )
492
+ break
493
+ case 'number':
494
+ const inputProps = {
495
+ value: form[this.item.value],
496
+ // 将 props 对象中的属性应用到 input 上
497
+ ...item.props
498
+ }
499
+ elementDom = h('inputNumber', {
500
+ directives: [{ name: 'rule-key' }],
501
+ ruleField: true,
502
+ attrs: {
503
+ 'rule-form': 'ruleValidate',
504
+ title: form[item.value],
505
+ rules: item.rules,
506
+ ruleErrorHide: item.ruleErrorHide
507
+ },
508
+ style: {
509
+ width: calcWidth(form[item.value])
510
+ },
511
+ props: inputProps,
512
+ on: {
513
+ input: (value) => {
514
+ this.$set(form, item.value, value)
515
+ this.handleChange(value)
516
+ },
517
+ clear: this.handleClear,
518
+ blur: this.handleBlur,
519
+ ...item.on
520
+ },
521
+ nativeOn: {
522
+ keyup
523
+ }
524
+ })
525
+ break
526
+ case 'numberrange':
527
+ const inputRangeProps = {
528
+ startValue: form[item.startValue],
529
+ endValue: form[item.endValue],
530
+
531
+ // 将 props 对象中的属性应用到 inputRange 上
532
+ ...item.props
533
+ }
534
+ elementDom = h('InputNumberRange', {
535
+ directives: [{ name: 'rule-key', value: 'startValue' }],
536
+ attrs: {
537
+ ...item.props,
538
+ ruleField: true,
539
+ 'rule-form': 'ruleValidate',
540
+ rules: item.rules,
541
+ isClearable: (item.props && item.props.isClearable) ?? true,
542
+ ruleErrorHide: item.ruleErrorHide
543
+ },
544
+ style: {
545
+ width: calcRangeWidth(item, form[item.startValue], form[item.endValue])
546
+ },
547
+ props: inputRangeProps,
548
+ on: {
549
+ 'update:start-value': (value) => {
550
+ this.$set(form, item.startValue, value)
551
+ this.handleChange(value)
552
+ },
553
+ 'update:end-value': (value) => {
554
+ this.$set(form, item.endValue, value)
555
+ this.handleChange(value)
556
+ },
557
+ clear: this.handleClear,
558
+ blur: this.handleBlur,
559
+ ...item.on
560
+ },
561
+ nativeOn: {
562
+ keyup
563
+ }
564
+ })
565
+ break
566
+ case 'date':
567
+ case 'datetime':
568
+ case 'year':
569
+ case 'month':
570
+ case 'week':
571
+ const datePickerProps = {
572
+ value: form[item.value],
573
+ type: item.type,
574
+ 'prefix-icon': (item.props && item.props.prefixIcon) ?? '',
575
+ clearable: (item.props && item.props.clearable) ?? true,
576
+ // 将 props 对象中的属性应用到 datePicker 上
577
+ ...item.props
578
+ }
579
+ elementDom = h('el-date-picker', {
580
+ directives: [{ name: 'rule-key' }],
581
+ attrs: {
582
+ 'rule-form': 'ruleValidate',
583
+ ruleField: true,
584
+ class: `n20-date-editor`,
585
+ 'value-format': (item.props && item.props.valueFormat) ?? 'yyyy-MM-dd',
586
+ placeholder: (item.props && item.props.placeholder) ?? $lc('请选择'),
587
+ rules: item.rules,
588
+ ruleErrorHide: item.ruleErrorHide
589
+ },
590
+ style: {
591
+ width: calcDateWidth(item, form[item.value])
592
+ },
593
+ props: datePickerProps,
594
+ model: {
595
+ value: form[item.value],
596
+ callback: (value) => {
597
+ this.$set(form, item.value, value)
598
+ }
599
+ },
600
+ on: {
601
+ input: (value) => {
602
+ this.$set(form, item.value, value)
603
+ this.handleChange(value)
604
+ },
605
+ change: this.handleFilter,
606
+ clear: this.handleClear
607
+ }
608
+ })
609
+ break
610
+ case 'daterange':
611
+ case 'datetimerange':
612
+ case 'monthrange':
613
+ const pickerProps = {
614
+ type: item.type,
615
+ startDate: form[item.startDate] || null,
616
+ endDate: form[item.endDate] || null,
617
+ rules: item.rules,
618
+ clearable: (item.props && item.props.clearable) ?? true,
619
+ ...item.props
620
+ }
621
+ elementDom = h('datePickerPor', {
622
+ directives: [{ name: 'rule-key', value: 'startDate' }],
623
+ attrs: {
624
+ ruleField: true,
625
+ 'rule-form': 'ruleValidate',
626
+ ruleErrorHide: item.ruleErrorHide,
627
+ rules: item.rules,
628
+ ...item.props
629
+ },
630
+ props: pickerProps,
631
+ style: {
632
+ width: calcRangeWidth(item, form[item.startDate], form[item.endDate])
633
+ },
634
+ on: {
635
+ 'update:start-date': (val) => {
636
+ this.$set(form, item.startDate, val)
637
+ this.handleChange(val)
638
+ },
639
+ 'update:end-date': (val) => {
640
+ this.$set(form, item.endDate, val)
641
+ this.handleChange(val)
642
+ },
643
+ clear: this.handleClear,
644
+ change: () => {
645
+ this.handleFilter()
646
+ }
647
+ },
648
+ nativeOn: {
649
+ keyup
650
+ }
651
+ })
652
+ break
653
+
654
+ case 'checkbox':
655
+ elementDom = h(
656
+ 'el-checkbox-group',
657
+ {
658
+ directives: [{ name: 'rule-key' }],
659
+ attrs: {
660
+ 'rule-form': 'ruleValidate',
661
+ ruleField: true,
662
+ rules: item.rules,
663
+ ruleErrorHide: item.ruleErrorHide
664
+ },
665
+ props: { ...item.props },
666
+ model: {
667
+ value: form[item.value],
668
+ callback: (value) => {
669
+ this.$set(form, item.value, value)
670
+ this.handleChange(value)
671
+ }
672
+ },
673
+ on: {
674
+ ...item.on
675
+ },
676
+ nativeOn: {
677
+ keyup
678
+ }
679
+ },
680
+ item.options.map((option) => {
681
+ return h(
682
+ 'el-checkbox',
683
+ { key: option.value, props: { label: option.value, disabled: option.disabled } },
684
+ option.label
685
+ )
686
+ })
687
+ )
688
+ break
689
+ case 'radio':
690
+ elementDom = h(
691
+ 'el-radio-group',
692
+ {
693
+ directives: [{ name: 'rule-key' }],
694
+ attrs: {
695
+ 'rule-form': 'ruleValidate',
696
+ ruleField: true,
697
+ rules: item.rules,
698
+ ruleErrorHide: item.ruleErrorHide
699
+ },
700
+ props: { ...item.props },
701
+ model: {
702
+ value: form[item.value],
703
+ callback: (value) => {
704
+ this.$set(form, item.value, value)
705
+ this.handleChange(value)
706
+ }
707
+ },
708
+ on: {
709
+ ...item.on
710
+ },
711
+ nativeOn: {
712
+ keyup
713
+ }
714
+ },
715
+ item.options.map((option) => {
716
+ return h(
717
+ 'el-radio',
718
+ { key: option.value, props: { label: option.value, disabled: option.disabled } },
719
+ option.label
720
+ )
721
+ })
722
+ )
723
+ break
724
+
725
+ case 'selectTree':
726
+ elementDom = h('selectTree', {
727
+ directives: [{ name: 'rule-key' }],
728
+ style: {
729
+ width: calcSelectTreeWidth(item, form[item.value])
730
+ },
731
+ attrs: {
732
+ ruleField: true,
733
+ 'rule-form': 'ruleValidate',
734
+ rules: item.rules,
735
+ ruleErrorHide: item.ruleErrorHide,
736
+ collapseTags: true
737
+ },
738
+ props: {
739
+ data: item.options,
740
+ props: {
741
+ ...item.props.props
742
+ },
743
+ clearable: (item.props && item.props.clearable) ?? true,
744
+ ...item.props
745
+ },
746
+ model: {
747
+ value: form[item.value],
748
+ callback: (value) => {
749
+ this.$set(form, item.value, value)
750
+ }
751
+ },
752
+ on: {
753
+ clear: this.handleClear,
754
+ 'visible-change': this.handleVisibleChange,
755
+ change: this.handleClear
756
+ },
757
+ nativeOn: {
758
+ keyup
759
+ }
760
+ })
761
+ break
762
+ case 'selectTreePro':
763
+ elementDom = h('selectTreePro', {
764
+ directives: [{ name: 'rule-key' }],
765
+ attrs: {
766
+ ruleField: true,
767
+ 'rule-form': 'ruleValidate',
768
+ rules: item.rules,
769
+ ruleErrorHide: item.ruleErrorHide,
770
+ collapseTags: true,
771
+ clearable: (item.props && item.props.clearable) ?? true
772
+ },
773
+ style: {
774
+ width: calcSelectTreeWidth(item, form[item.value])
775
+ },
776
+ model: {
777
+ value: form[item.value],
778
+ callback: (value) => {
779
+ this.$set(form, item.value, value)
780
+ }
781
+ },
782
+ props: {
783
+ data: item.options,
784
+ 'node-key': item.props['nodeKey' ?? 'node-key'],
785
+ defineProps: item.props.defineProps,
786
+
787
+ ...item.props
788
+ },
789
+ on: {
790
+ clear: this.handleClear,
791
+ 'visible-change': this.handleVisibleChange
792
+ },
793
+ nativeOn: {
794
+ keyup
795
+ }
796
+ })
797
+ break
798
+ default:
799
+ elementDom = h('el-input', {
800
+ attrs: {
801
+ style: {
802
+ width: calcTextWidth(item.label, form[item.value])
803
+ },
804
+ ruleField: true,
805
+ 'rule-form': 'ruleValidate',
806
+ rules: item.rules,
807
+ ruleErrorHide: item.ruleErrorHide,
808
+ placeholder: item.props && item.props.placeholder ? item.props.placeholder : $lc('请输入'),
809
+ maxlength: item.props && item.props.maxlength,
810
+ minlength: item.props && item.props.minlength
811
+ },
812
+ on: {
813
+ blur: this.handleBlur,
814
+ clear: this.handleClear
815
+ },
816
+ directives: [
817
+ {
818
+ name: 'rule-key'
819
+ }
820
+ ],
821
+ props: {
822
+ rules: item.rules,
823
+ clearable: (item.props && item.props.clearable) ?? true
824
+ },
825
+ domProps: {
826
+ value: form[item.value]
827
+ },
828
+ model: {
829
+ value: form[item.value],
830
+ callback: (value) => {
831
+ this.$set(form, item.value, value)
832
+ }
833
+ },
834
+ nativeOn: {
835
+ input: (event) => {
836
+ form[item.value] = event.target.value
837
+ },
838
+ keyup
839
+ }
840
+ })
841
+ break
842
+ }
843
+
844
+ return elementDom
845
+ }
846
+ }
847
+ </script>