sadais-piui 1.2.7-beta15 → 1.2.7-beta151
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.
- package/.prettierrc +8 -0
- package/components/pi-action-sheet/index.vue +260 -247
- package/components/pi-badge/index.vue +11 -1
- package/components/pi-bottom-bar/index.vue +1 -1
- package/components/pi-calendar/index.vue +207 -182
- package/components/pi-calendar-input/index.vue +61 -30
- package/components/pi-calendar-panel/components/calendar-days/index.vue +91 -52
- package/components/pi-calendar-panel/index.vue +28 -12
- package/components/pi-canvas/index.vue +8 -1
- package/components/pi-cascader/index.vue +601 -0
- package/components/pi-checkbox/index.vue +8 -4
- package/components/pi-checkbox-group/index.vue +12 -11
- package/components/pi-circle-progress/index.vue +53 -16
- package/components/pi-code-input/index.vue +11 -3
- package/components/pi-collapse/index.vue +16 -6
- package/components/pi-collapse-item/index.vue +35 -22
- package/components/pi-date-picker/index.vue +512 -391
- package/components/pi-date-picker-input/index.vue +61 -30
- package/components/pi-dropdown/components/dropdown-tab.vue +33 -23
- package/components/pi-dropdown/index.vue +34 -19
- package/components/pi-dropdown-item/index.vue +70 -58
- package/components/pi-form-item/index.vue +98 -20
- package/components/pi-grid/index.vue +1 -1
- package/components/pi-grid-item/index.vue +4 -4
- package/components/pi-img/index.vue +275 -267
- package/components/pi-img-cropper/index.vue +6 -3
- package/components/pi-input/index.vue +97 -36
- package/components/pi-list-item/index.vue +1 -1
- package/components/pi-marquee/index.vue +322 -310
- package/components/pi-marquee-pure-css/index.vue +267 -0
- package/components/pi-mask/index.vue +3 -1
- package/components/pi-modal/index.vue +311 -303
- package/components/pi-pagination/index.vue +13 -0
- package/components/pi-picker/index.vue +332 -317
- package/components/pi-popup/index.vue +4 -1
- package/components/pi-popup-select/index.vue +13 -4
- package/components/pi-radio/index.vue +12 -11
- package/components/pi-radio-group/index.vue +25 -5
- package/components/pi-regions-select/index.vue +6 -1
- package/components/pi-regions-select-input/index.vue +69 -31
- package/components/pi-search/index.vue +37 -2
- package/components/pi-section/index.vue +1 -1
- package/components/pi-select/index.vue +237 -22
- package/components/pi-select-input/index.vue +106 -41
- package/components/pi-stepper/index.vue +135 -121
- package/components/pi-steps/index.vue +115 -36
- package/components/pi-swiper/index.vue +22 -7
- package/components/pi-switch/index.vue +5 -1
- package/components/pi-table/index.vue +351 -0
- package/components/pi-tabs/index.vue +46 -10
- package/components/pi-upload-img/index.vue +895 -44
- package/components/pi-webview/index.vue +95 -82
- package/config/actionSheet.js +0 -1
- package/config/calendarInput.js +2 -1
- package/config/calendarPanel.js +2 -1
- package/config/cascader.js +22 -0
- package/config/circleProgress.js +12 -4
- package/config/codeInput.js +2 -1
- package/config/datePicker.js +29 -24
- package/config/datePickerInput.js +2 -1
- package/config/dropdown.js +3 -1
- package/config/input.js +5 -3
- package/config/marqueePureCss.js +18 -0
- package/config/regionsSelectInput.js +2 -1
- package/config/select.js +13 -1
- package/config/selectInput.js +2 -1
- package/config/steps.js +1 -1
- package/config/table.js +9 -0
- package/config/uploadImg.js +33 -11
- package/mixin/emitter.js +8 -1
- package/mixin/value-sync.js +5 -0
- package/package.json +5 -2
- package/scss/common.scss +11 -14
- package/scss/icon/icon.scss +2 -1
- package/scss/mixin.scss +5 -5
|
@@ -16,14 +16,53 @@
|
|
|
16
16
|
@close="handlePopupClose"
|
|
17
17
|
@cancel="handleCancel"
|
|
18
18
|
@confirm="handleConfirm"
|
|
19
|
+
@closed="$emit('closed', $event)"
|
|
20
|
+
@show="handleShowEvent"
|
|
21
|
+
@showed="$emit('showed', $event)"
|
|
19
22
|
>
|
|
20
|
-
<view
|
|
23
|
+
<view
|
|
24
|
+
class="pi-select pi-h-100P pi-flex-column"
|
|
25
|
+
:style="[customStyle]"
|
|
26
|
+
:class="[customClass]"
|
|
27
|
+
>
|
|
21
28
|
<slot name="header" />
|
|
29
|
+
<view
|
|
30
|
+
v-if="showSelectAll"
|
|
31
|
+
class="select-item pi-align-center pi-justify-end pi-pd-lr-32"
|
|
32
|
+
:style="[itemStyle, getItemStyle]"
|
|
33
|
+
@tap.stop="handleSelectAll"
|
|
34
|
+
>
|
|
35
|
+
<view>全选</view>
|
|
36
|
+
<view>
|
|
37
|
+
<pi-checkbox
|
|
38
|
+
:value="isSelectAll"
|
|
39
|
+
readonly
|
|
40
|
+
shape="round"
|
|
41
|
+
custom-class="pi-mg-left-32"
|
|
42
|
+
active-mode="fill-circle"
|
|
43
|
+
/>
|
|
44
|
+
</view>
|
|
45
|
+
</view>
|
|
46
|
+
<view
|
|
47
|
+
v-if="getRemoteSearchConfig.enable && getRemoteSearchConfig.filter"
|
|
48
|
+
class="pi-pd-lr-24"
|
|
49
|
+
>
|
|
50
|
+
<pi-search
|
|
51
|
+
v-model="keyword"
|
|
52
|
+
:placeholder="getRemoteSearchConfig.filterPlaceholder"
|
|
53
|
+
show-action
|
|
54
|
+
:action-text="getRemoteSearchConfig.filterAction"
|
|
55
|
+
@search="handleKeywordSearch"
|
|
56
|
+
@clear="handleKeywordSearch"
|
|
57
|
+
@action="handleKeywordSearch"
|
|
58
|
+
/>
|
|
59
|
+
</view>
|
|
22
60
|
<scroll-view
|
|
23
61
|
scroll-y
|
|
24
62
|
class="pi-scroll"
|
|
25
63
|
:scroll-into-view="getFirstSelectedId"
|
|
26
64
|
scroll-with-animation
|
|
65
|
+
@scrolltolower="handleScrolltolower"
|
|
27
66
|
>
|
|
28
67
|
<view
|
|
29
68
|
v-for="item in getItems"
|
|
@@ -38,9 +77,22 @@
|
|
|
38
77
|
@tap.stop="handleSelectItem(item)"
|
|
39
78
|
>
|
|
40
79
|
<!-- 自定义列表项 -->
|
|
41
|
-
<slot
|
|
42
|
-
|
|
43
|
-
|
|
80
|
+
<slot
|
|
81
|
+
name="item"
|
|
82
|
+
:item="item"
|
|
83
|
+
:selected="item.isSelected"
|
|
84
|
+
class="pi-w-100P"
|
|
85
|
+
>
|
|
86
|
+
<view>
|
|
87
|
+
<view class="select-item-title">{{ item[displayField] }}</view>
|
|
88
|
+
<view
|
|
89
|
+
v-if="item[descField]"
|
|
90
|
+
class="pi-light-gray pi-fz-24 pi-mg-top-10 pi-lh-30"
|
|
91
|
+
:style="[item.descStyle || {}]"
|
|
92
|
+
>
|
|
93
|
+
{{ item[descField] }}
|
|
94
|
+
</view>
|
|
95
|
+
</view>
|
|
44
96
|
</slot>
|
|
45
97
|
<!-- 如果配置了图片地址,使用图片 -->
|
|
46
98
|
<pi-img
|
|
@@ -60,7 +112,7 @@
|
|
|
60
112
|
:loading-size="getSelectedImg.loadingSize"
|
|
61
113
|
:show-error="getSelectedImg.showError"
|
|
62
114
|
:webp="getSelectedImg.webp"
|
|
63
|
-
custom-class="pi-mg-left-
|
|
115
|
+
custom-class="pi-mg-left-32"
|
|
64
116
|
/>
|
|
65
117
|
<!-- 默认使用复选框 -->
|
|
66
118
|
<pi-checkbox
|
|
@@ -76,7 +128,7 @@
|
|
|
76
128
|
:icon-size="getSelectedCheckbox.iconSize"
|
|
77
129
|
:active-color="getSelectedCheckbox.activeColor"
|
|
78
130
|
:active-mode="getSelectedCheckbox.activeMode"
|
|
79
|
-
custom-class="pi-mg-left-
|
|
131
|
+
custom-class="pi-mg-left-32"
|
|
80
132
|
/>
|
|
81
133
|
</view>
|
|
82
134
|
</scroll-view>
|
|
@@ -92,6 +144,8 @@ import { getConfig } from '../../config'
|
|
|
92
144
|
const TAG = 'PiSelect'
|
|
93
145
|
const { select } = getConfig()
|
|
94
146
|
|
|
147
|
+
const PI_DEFAULT_FN_FLAG = 'PI_DEFAULT_FN_FLAG'
|
|
148
|
+
|
|
95
149
|
export default {
|
|
96
150
|
name: 'PiSelect',
|
|
97
151
|
// 混入v-model
|
|
@@ -137,6 +191,12 @@ export default {
|
|
|
137
191
|
// 'text'
|
|
138
192
|
default: select.displayField
|
|
139
193
|
},
|
|
194
|
+
// 描述显示字段,默认为desc
|
|
195
|
+
descField: {
|
|
196
|
+
type: String,
|
|
197
|
+
// 'desc'
|
|
198
|
+
default: select.descField
|
|
199
|
+
},
|
|
140
200
|
// 默认值,单选是传Number, String, Object,多选时传Array
|
|
141
201
|
defaultValue: {
|
|
142
202
|
type: [Number, String, Object, Array],
|
|
@@ -154,6 +214,12 @@ export default {
|
|
|
154
214
|
// false
|
|
155
215
|
default: select.isMulti
|
|
156
216
|
},
|
|
217
|
+
// 是否显示全选(多选isMulti开启的情况下)
|
|
218
|
+
showSelectAll: {
|
|
219
|
+
type: Boolean,
|
|
220
|
+
// false
|
|
221
|
+
default: select.showSelectAll
|
|
222
|
+
},
|
|
157
223
|
// 单选模式下,是否可取消选中
|
|
158
224
|
singleCancel: {
|
|
159
225
|
type: Boolean,
|
|
@@ -231,12 +297,39 @@ export default {
|
|
|
231
297
|
// 参照popup
|
|
232
298
|
return select.popup
|
|
233
299
|
}
|
|
300
|
+
},
|
|
301
|
+
// 远程搜索配置
|
|
302
|
+
remoteSearchConfig: {
|
|
303
|
+
type: Object,
|
|
304
|
+
default() {
|
|
305
|
+
return select.remoteSearchConfig
|
|
306
|
+
}
|
|
307
|
+
},
|
|
308
|
+
// 远程搜索结果解析钩子
|
|
309
|
+
parseRemoteSearchResult: {
|
|
310
|
+
type: [Object, Function],
|
|
311
|
+
default() {
|
|
312
|
+
return {
|
|
313
|
+
[PI_DEFAULT_FN_FLAG]: true,
|
|
314
|
+
fn: select.parseRemoteSearchResult
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
},
|
|
318
|
+
// 兼容微信小程序无法属性传递function的问题 传递方法名进来
|
|
319
|
+
remoteMethod: {
|
|
320
|
+
type: String,
|
|
321
|
+
default: ''
|
|
234
322
|
}
|
|
235
323
|
},
|
|
236
324
|
data() {
|
|
237
325
|
return {
|
|
238
326
|
// 当前选中的值
|
|
239
|
-
selected: {}
|
|
327
|
+
selected: {},
|
|
328
|
+
keyword: '',
|
|
329
|
+
remoteItems: [],
|
|
330
|
+
remoteLoading: false,
|
|
331
|
+
pageNo: 1,
|
|
332
|
+
isEnd: false
|
|
240
333
|
}
|
|
241
334
|
},
|
|
242
335
|
computed: {
|
|
@@ -244,10 +337,22 @@ export default {
|
|
|
244
337
|
return this.$pi.lang.mergeDeep(select.selectedImg, this.selectedImg)
|
|
245
338
|
},
|
|
246
339
|
getSelectedCheckbox() {
|
|
247
|
-
return this.$pi.lang.mergeDeep(
|
|
340
|
+
return this.$pi.lang.mergeDeep(
|
|
341
|
+
select.selectedCheckbox,
|
|
342
|
+
this.selectedCheckbox
|
|
343
|
+
)
|
|
344
|
+
},
|
|
345
|
+
getRemoteSearchConfig() {
|
|
346
|
+
return this.$pi.lang.mergeDeep(
|
|
347
|
+
select.remoteSearchConfig,
|
|
348
|
+
this.remoteSearchConfig
|
|
349
|
+
)
|
|
248
350
|
},
|
|
249
351
|
getPopupSelect() {
|
|
250
|
-
const popupSelect = this.$pi.lang.mergeDeep(
|
|
352
|
+
const popupSelect = this.$pi.lang.mergeDeep(
|
|
353
|
+
select.popupSelect,
|
|
354
|
+
this.popupSelect
|
|
355
|
+
)
|
|
251
356
|
if (!this.singleCancel && this.singleConfirm) {
|
|
252
357
|
popupSelect.toolbarPosition = 'none'
|
|
253
358
|
}
|
|
@@ -261,11 +366,17 @@ export default {
|
|
|
261
366
|
return this.$pi.lang.mergeDeep(selectConfirmBtn, this.confirmBtn)
|
|
262
367
|
},
|
|
263
368
|
getCancelBtn() {
|
|
264
|
-
const selectCancelBtn = this.$pi.lang.mergeDeep(
|
|
369
|
+
const selectCancelBtn = this.$pi.lang.mergeDeep(
|
|
370
|
+
select.cancelBtn,
|
|
371
|
+
this.popupSelect.cancelBtn
|
|
372
|
+
)
|
|
265
373
|
return this.$pi.lang.mergeDeep(selectCancelBtn, this.cancelBtn)
|
|
266
374
|
},
|
|
267
375
|
getPopup() {
|
|
268
|
-
const selectPopup = this.$pi.lang.mergeDeep(
|
|
376
|
+
const selectPopup = this.$pi.lang.mergeDeep(
|
|
377
|
+
select.popup,
|
|
378
|
+
this.popupSelect.popup
|
|
379
|
+
)
|
|
269
380
|
return this.$pi.lang.mergeDeep(selectPopup, this.popup)
|
|
270
381
|
},
|
|
271
382
|
getItemStyle() {
|
|
@@ -274,12 +385,17 @@ export default {
|
|
|
274
385
|
}
|
|
275
386
|
},
|
|
276
387
|
getItems() {
|
|
277
|
-
|
|
388
|
+
const targetItems = this.remoteSearchConfig.enable
|
|
389
|
+
? this.remoteItems
|
|
390
|
+
: this.items
|
|
391
|
+
return targetItems.map(item => {
|
|
278
392
|
let isSelected = false
|
|
279
393
|
if (this.isMulti) {
|
|
280
394
|
isSelected =
|
|
281
395
|
this.$pi.lang.isArray(this.selected) &&
|
|
282
|
-
this.selected.findIndex(
|
|
396
|
+
this.selected.findIndex(
|
|
397
|
+
s => s[this.keyField] === item[this.keyField]
|
|
398
|
+
) !== -1
|
|
283
399
|
} else {
|
|
284
400
|
isSelected = this.selected[this.keyField] === item[this.keyField]
|
|
285
401
|
}
|
|
@@ -291,6 +407,9 @@ export default {
|
|
|
291
407
|
const firstSelected = this.selected[0] || this.selected
|
|
292
408
|
const firstSelectedId = firstSelected[this.keyField]
|
|
293
409
|
return firstSelectedId ? `id-${firstSelected[this.keyField]}` : ''
|
|
410
|
+
},
|
|
411
|
+
isSelectAll() {
|
|
412
|
+
return this.getItems.every(item => item.isSelected)
|
|
294
413
|
}
|
|
295
414
|
},
|
|
296
415
|
watch: {
|
|
@@ -310,24 +429,40 @@ export default {
|
|
|
310
429
|
return this.$pi.lang.isObject(item)
|
|
311
430
|
})
|
|
312
431
|
if (this.keyDefaultValue && isArrayObject) {
|
|
313
|
-
console.error(
|
|
432
|
+
console.error(
|
|
433
|
+
TAG,
|
|
434
|
+
'keyDefaultValue模式下defaultValue不能为对象数组类型'
|
|
435
|
+
)
|
|
314
436
|
return false
|
|
315
437
|
}
|
|
316
438
|
if (!this.keyDefaultValue && !isArrayObject) {
|
|
317
|
-
console.error(
|
|
439
|
+
console.error(
|
|
440
|
+
TAG,
|
|
441
|
+
'非keyDefaultValue模式下defaultValue必须为对象数组类型'
|
|
442
|
+
)
|
|
318
443
|
return false
|
|
319
444
|
}
|
|
320
445
|
}
|
|
321
446
|
if (!this.isMulti) {
|
|
322
|
-
if (
|
|
323
|
-
|
|
447
|
+
if (
|
|
448
|
+
this.keyDefaultValue &&
|
|
449
|
+
this.$pi.lang.isObject(this.defaultValue)
|
|
450
|
+
) {
|
|
451
|
+
console.error(
|
|
452
|
+
TAG,
|
|
453
|
+
'keyDefaultValue模式下defaultValue不能为对象类型'
|
|
454
|
+
)
|
|
324
455
|
return false
|
|
325
456
|
}
|
|
326
457
|
if (
|
|
327
458
|
!this.keyDefaultValue &&
|
|
328
|
-
(!this.$pi.lang.isObject(this.defaultValue) ||
|
|
459
|
+
(!this.$pi.lang.isObject(this.defaultValue) ||
|
|
460
|
+
this.$pi.lang.isArray(this.defaultValue))
|
|
329
461
|
) {
|
|
330
|
-
console.error(
|
|
462
|
+
console.error(
|
|
463
|
+
TAG,
|
|
464
|
+
'非keyDefaultValue模式下defaultValue必须为对象类型'
|
|
465
|
+
)
|
|
331
466
|
return false
|
|
332
467
|
}
|
|
333
468
|
}
|
|
@@ -389,9 +524,13 @@ export default {
|
|
|
389
524
|
}
|
|
390
525
|
// 多选
|
|
391
526
|
const hasSelected =
|
|
392
|
-
this.selected.findIndex(
|
|
527
|
+
this.selected.findIndex(
|
|
528
|
+
s => s[this.keyField] === item[this.keyField]
|
|
529
|
+
) !== -1
|
|
393
530
|
if (hasSelected) {
|
|
394
|
-
this.selected = this.selected.filter(
|
|
531
|
+
this.selected = this.selected.filter(
|
|
532
|
+
s => s[this.keyField] !== item[this.keyField]
|
|
533
|
+
)
|
|
395
534
|
} else {
|
|
396
535
|
this.selected.push(item)
|
|
397
536
|
}
|
|
@@ -412,7 +551,10 @@ export default {
|
|
|
412
551
|
const toggleSelect = this.items.filter(item => {
|
|
413
552
|
let toggleNode = true
|
|
414
553
|
if (nodes.length) {
|
|
415
|
-
toggleNode =
|
|
554
|
+
toggleNode =
|
|
555
|
+
nodes.findIndex(
|
|
556
|
+
node => node[this.keyField] === item[this.keyField]
|
|
557
|
+
) !== -1
|
|
416
558
|
}
|
|
417
559
|
return toggleNode && !item.disabled
|
|
418
560
|
})
|
|
@@ -443,6 +585,79 @@ export default {
|
|
|
443
585
|
}
|
|
444
586
|
this.$emit('confirm', selected, this.selected)
|
|
445
587
|
this.getPopupSelect.onConfirmClose && this.handlePopupClose()
|
|
588
|
+
},
|
|
589
|
+
handleSelectAll() {
|
|
590
|
+
if (this.isMulti) {
|
|
591
|
+
this.selected = this.isSelectAll ? [] : [...this.items]
|
|
592
|
+
}
|
|
593
|
+
},
|
|
594
|
+
handleShowEvent() {
|
|
595
|
+
console.log('打开窗口', this.getRemoteSearchConfig.enable)
|
|
596
|
+
this.$emit('show')
|
|
597
|
+
if (!this.getRemoteSearchConfig.enable) return
|
|
598
|
+
this.keyword = ''
|
|
599
|
+
this.handleResetRemoteSearch()
|
|
600
|
+
this.handleRemoteSearch()
|
|
601
|
+
},
|
|
602
|
+
handleResetRemoteSearch() {
|
|
603
|
+
this.pageNo = 1
|
|
604
|
+
this.isEnd = false
|
|
605
|
+
this.remoteItems = []
|
|
606
|
+
},
|
|
607
|
+
handleKeywordSearch() {
|
|
608
|
+
this.handleResetRemoteSearch()
|
|
609
|
+
this.handleRemoteSearch()
|
|
610
|
+
},
|
|
611
|
+
handleScrolltolower() {
|
|
612
|
+
console.log('滚动触底了', this.getRemoteSearchConfig.enable, this.isEnd)
|
|
613
|
+
if (!this.getRemoteSearchConfig.enable) return
|
|
614
|
+
if (this.isEnd) return
|
|
615
|
+
this.handleRemoteSearch()
|
|
616
|
+
},
|
|
617
|
+
async handleRemoteSearch() {
|
|
618
|
+
if (this.remoteLoading) return
|
|
619
|
+
let parseRemoteSearchResult = null
|
|
620
|
+
if (this.remoteMethod) {
|
|
621
|
+
let node = this.$parent
|
|
622
|
+
while (node && !node[this.remoteMethod]) {
|
|
623
|
+
node = node.$parent
|
|
624
|
+
}
|
|
625
|
+
parseRemoteSearchResult = node?.[this.remoteMethod]
|
|
626
|
+
if (!parseRemoteSearchResult) {
|
|
627
|
+
console.error(`pi-select 找不到remoteMethod=${this.remoteMethod}`)
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
if (!parseRemoteSearchResult) {
|
|
631
|
+
parseRemoteSearchResult = this.parseRemoteSearchResult[
|
|
632
|
+
PI_DEFAULT_FN_FLAG
|
|
633
|
+
]
|
|
634
|
+
? this.parseRemoteSearchResult.fn
|
|
635
|
+
: this.parseRemoteSearchResult
|
|
636
|
+
if (!parseRemoteSearchResult) {
|
|
637
|
+
console.error(`pi-select parseRemoteSearchResult不存在`)
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
if (!parseRemoteSearchResult) {
|
|
641
|
+
return
|
|
642
|
+
}
|
|
643
|
+
this.remoteLoading = false
|
|
644
|
+
const items = await parseRemoteSearchResult(
|
|
645
|
+
this.pageNo,
|
|
646
|
+
this.getRemoteSearchConfig.pageSize,
|
|
647
|
+
this.keyword
|
|
648
|
+
)
|
|
649
|
+
this.$hideLoading()
|
|
650
|
+
if (!this.$pi.lang.isArray(items)) {
|
|
651
|
+
console.error(TAG, items, '远程搜索结果必须为数组类型')
|
|
652
|
+
return
|
|
653
|
+
}
|
|
654
|
+
console.log('远程搜索结果', items)
|
|
655
|
+
this.pageNo++
|
|
656
|
+
// 判断页码
|
|
657
|
+
if (items?.length < this.getRemoteSearchConfig.pageSize) {
|
|
658
|
+
this.isEnd = true
|
|
659
|
+
}
|
|
660
|
+
this.remoteItems = this.remoteItems.concat(items)
|
|
446
661
|
}
|
|
447
662
|
}
|
|
448
663
|
}
|
|
@@ -1,52 +1,58 @@
|
|
|
1
1
|
<!--
|
|
2
2
|
* @Author: zhangzhenfei
|
|
3
3
|
* @Date: 2022-05-18 11:08:49
|
|
4
|
-
* @LastEditTime:
|
|
4
|
+
* @LastEditTime: 2024-05-09 16:23:43
|
|
5
5
|
* @LastEditors: zhangzhenfei
|
|
6
6
|
* @Description: 选择输入
|
|
7
|
-
* @FilePath: /
|
|
7
|
+
* @FilePath: /piui-awesome/src/piui/components/pi-select-input/index.vue
|
|
8
8
|
-->
|
|
9
9
|
|
|
10
10
|
<template>
|
|
11
11
|
<view class="pi-select-input">
|
|
12
12
|
<!-- 输入框 -->
|
|
13
|
-
<view
|
|
13
|
+
<view
|
|
14
|
+
v-if="$slots.default || $slots.$default"
|
|
15
|
+
class="pi-w-100P"
|
|
16
|
+
@click="handleShow()"
|
|
17
|
+
>
|
|
14
18
|
<slot />
|
|
15
19
|
</view>
|
|
16
20
|
<pi-input
|
|
17
21
|
v-else
|
|
18
22
|
type="text"
|
|
19
|
-
:value="getInputValue"
|
|
20
|
-
:custom-class="
|
|
21
|
-
:custom-style="
|
|
22
|
-
:placeholder="
|
|
23
|
-
:placeholder-style="
|
|
24
|
-
:placeholder-class="
|
|
25
|
-
:disabled="
|
|
26
|
-
:border="
|
|
27
|
-
:maxlength="
|
|
28
|
-
:password="
|
|
29
|
-
:cursor-spacing="
|
|
30
|
-
:focus="
|
|
31
|
-
:confirm-type="
|
|
32
|
-
:confirm-hold="
|
|
33
|
-
:cursor="
|
|
34
|
-
:selection-start="
|
|
35
|
-
:selection-end="
|
|
36
|
-
:adjust-position="
|
|
37
|
-
:hold-keyboard="
|
|
38
|
-
:auto-blur="
|
|
39
|
-
:show-confirmbar="
|
|
40
|
-
:auto-height="
|
|
41
|
-
:fixed="
|
|
42
|
-
:disable-default-padding="
|
|
43
|
-
:clearable="
|
|
44
|
-
:clear-icon="
|
|
45
|
-
@click="
|
|
23
|
+
:value="getInputValue || remoteVal"
|
|
24
|
+
:custom-class="getInput.customClass"
|
|
25
|
+
:custom-style="getInput.customStyle"
|
|
26
|
+
:placeholder="getInput.placeholder"
|
|
27
|
+
:placeholder-style="getInput.placeholderStyle"
|
|
28
|
+
:placeholder-class="getInput.placeholderClass"
|
|
29
|
+
:disabled="getInput.disabled"
|
|
30
|
+
:border="getInput.border"
|
|
31
|
+
:maxlength="getInput.maxlength"
|
|
32
|
+
:password="getInput.password"
|
|
33
|
+
:cursor-spacing="getInput.cursorSpacing"
|
|
34
|
+
:focus="getInput.focus"
|
|
35
|
+
:confirm-type="getInput.confirmType"
|
|
36
|
+
:confirm-hold="getInput.confirmHold"
|
|
37
|
+
:cursor="getInput.cursor"
|
|
38
|
+
:selection-start="getInput.selectionStart"
|
|
39
|
+
:selection-end="getInput.selectionEnd"
|
|
40
|
+
:adjust-position="getInput.adjustPosition"
|
|
41
|
+
:hold-keyboard="getInput.holdKeyboard"
|
|
42
|
+
:auto-blur="getInput.autoBlur"
|
|
43
|
+
:show-confirmbar="getInput.showConfirmbar"
|
|
44
|
+
:auto-height="getInput.autoHeight"
|
|
45
|
+
:fixed="getInput.fixed"
|
|
46
|
+
:disable-default-padding="getInput.disableDefaultPadding"
|
|
47
|
+
:clearable="getInput.clearable"
|
|
48
|
+
:clear-icon="getInput.clearIcon"
|
|
49
|
+
@click="handleShow()"
|
|
50
|
+
@clear="handleClearValue"
|
|
46
51
|
/>
|
|
47
52
|
|
|
48
53
|
<!-- 选择弹出框 -->
|
|
49
54
|
<pi-select
|
|
55
|
+
ref="pi-select"
|
|
50
56
|
v-model="show"
|
|
51
57
|
:default-value="val"
|
|
52
58
|
:key-default-value="getSelect.keyDefaultValue"
|
|
@@ -55,6 +61,7 @@
|
|
|
55
61
|
:items="getSelect.items"
|
|
56
62
|
:key-field="getSelect.keyField"
|
|
57
63
|
:display-field="getSelect.displayField"
|
|
64
|
+
:desc-field="getSelect.descField"
|
|
58
65
|
:is-multi="getSelect.isMulti"
|
|
59
66
|
:single-cancel="getSelect.singleCancel"
|
|
60
67
|
:single-confirm="getSelect.singleConfirm"
|
|
@@ -67,7 +74,14 @@
|
|
|
67
74
|
:popup="getSelect.popup"
|
|
68
75
|
:confirm-btn="getSelect.confirmBtn"
|
|
69
76
|
:cancel-btn="getSelect.cancelBtn"
|
|
77
|
+
:remote-search-config="getSelect.remoteSearchConfig"
|
|
78
|
+
:parse-remote-search-result="getSelect.parseRemoteSearchResult"
|
|
79
|
+
:remote-method="getSelect.remoteMethod"
|
|
70
80
|
@confirm="handleSelectConfirm"
|
|
81
|
+
@close="$emit('close', $event)"
|
|
82
|
+
@closed="$emit('closed', $event)"
|
|
83
|
+
@show="$emit('show', $event)"
|
|
84
|
+
@showed="$emit('showed', $event)"
|
|
71
85
|
/>
|
|
72
86
|
</view>
|
|
73
87
|
</template>
|
|
@@ -137,18 +151,54 @@ export default {
|
|
|
137
151
|
fn: selectInput.parseValueFn
|
|
138
152
|
}
|
|
139
153
|
}
|
|
154
|
+
},
|
|
155
|
+
disabled: {
|
|
156
|
+
type: Boolean,
|
|
157
|
+
default: selectInput.disabled
|
|
140
158
|
}
|
|
141
159
|
},
|
|
142
160
|
data() {
|
|
143
161
|
return {
|
|
144
|
-
show: false
|
|
162
|
+
show: false,
|
|
163
|
+
remoteVal: ''
|
|
145
164
|
}
|
|
146
165
|
},
|
|
147
166
|
computed: {
|
|
148
167
|
getSelect() {
|
|
149
168
|
return this.$pi.lang.mergeDeep(selectInput.select, this.select)
|
|
150
169
|
},
|
|
170
|
+
getInput() {
|
|
171
|
+
return this.$pi.lang.mergeDeep(selectInput.input, this.input)
|
|
172
|
+
},
|
|
151
173
|
getInputValue() {
|
|
174
|
+
return this.handleGetInputValue()
|
|
175
|
+
},
|
|
176
|
+
getDisabled() {
|
|
177
|
+
const parent = this.$pi.parent(this, 'PiFormItem')
|
|
178
|
+
return this.disabled || (parent && parent.getDisabled)
|
|
179
|
+
}
|
|
180
|
+
},
|
|
181
|
+
created() {
|
|
182
|
+
this.initRemoteSelectData()
|
|
183
|
+
},
|
|
184
|
+
methods: {
|
|
185
|
+
handleShow() {
|
|
186
|
+
if (this.getDisabled) {
|
|
187
|
+
return
|
|
188
|
+
}
|
|
189
|
+
this.show = true
|
|
190
|
+
},
|
|
191
|
+
initRemoteSelectData() {
|
|
192
|
+
// 如果开启了远程搜索 则在创建之初 先触发一次搜索 让代码触发到用户自定义的remoteMethod or parseRemoteSearchResult方法中
|
|
193
|
+
// 目的为了回显数据
|
|
194
|
+
if (this.getSelect.remoteSearchConfig.enable && this.val) {
|
|
195
|
+
this.$nextTick(async () => {
|
|
196
|
+
await this.$refs['pi-select'].handleRemoteSearch()
|
|
197
|
+
this.remoteVal = this.handleGetInputValue()
|
|
198
|
+
})
|
|
199
|
+
}
|
|
200
|
+
},
|
|
201
|
+
handleGetInputValue() {
|
|
152
202
|
const parseValueFn = this.parseValueFn[PI_DEFAULT_FN_FLAG]
|
|
153
203
|
? this.parseValueFn.fn
|
|
154
204
|
: this.parseValueFn
|
|
@@ -157,35 +207,42 @@ export default {
|
|
|
157
207
|
return parseValue
|
|
158
208
|
}
|
|
159
209
|
if (this.$pi.lang.isEmpty(this.val)) return ''
|
|
210
|
+
const getItems =
|
|
211
|
+
this.$refs['pi-select']?.getItems || this.getSelect.items || []
|
|
160
212
|
if (this.getSelect.keyDefaultValue) {
|
|
161
213
|
if (this.getSelect.isMulti) {
|
|
162
|
-
return
|
|
214
|
+
return getItems
|
|
163
215
|
.filter(item => this.val.includes(item[this.getSelect.keyField]))
|
|
164
216
|
.map(item => item[this.getSelect.displayField])
|
|
165
217
|
.join(this.rangeSplit)
|
|
166
218
|
} else {
|
|
167
|
-
const val =
|
|
219
|
+
const val = getItems.find(
|
|
220
|
+
item => item[this.getSelect.keyField] === this.val
|
|
221
|
+
)
|
|
168
222
|
return val ? val[this.getSelect.displayField] : ''
|
|
169
223
|
}
|
|
170
224
|
} else {
|
|
171
225
|
// 这里需要从items再次获取,防止用户设置的默认值没有设置displayField的情况
|
|
172
226
|
if (this.getSelect.isMulti) {
|
|
173
|
-
return
|
|
227
|
+
return getItems
|
|
174
228
|
.filter(item =>
|
|
175
|
-
this.val.some(
|
|
229
|
+
this.val.some(
|
|
230
|
+
v =>
|
|
231
|
+
v[this.getSelect.keyField] === item[this.getSelect.keyField]
|
|
232
|
+
)
|
|
176
233
|
)
|
|
177
234
|
.map(item => item[this.getSelect.displayField])
|
|
178
235
|
.join(this.rangeSplit)
|
|
179
236
|
} else {
|
|
180
|
-
const val =
|
|
181
|
-
item =>
|
|
237
|
+
const val = getItems.find(
|
|
238
|
+
item =>
|
|
239
|
+
item[this.getSelect.keyField] ===
|
|
240
|
+
this.val[this.getSelect.keyField]
|
|
182
241
|
)
|
|
183
242
|
return val ? val[this.getSelect.displayField] : ''
|
|
184
243
|
}
|
|
185
244
|
}
|
|
186
|
-
}
|
|
187
|
-
},
|
|
188
|
-
methods: {
|
|
245
|
+
},
|
|
189
246
|
handlePopupClose() {
|
|
190
247
|
this.val = false
|
|
191
248
|
// 关闭
|
|
@@ -193,9 +250,17 @@ export default {
|
|
|
193
250
|
this.handleEmitChange()
|
|
194
251
|
},
|
|
195
252
|
handleSelectConfirm(value) {
|
|
196
|
-
console.log(value)
|
|
197
253
|
this.val = value
|
|
198
254
|
this.handleEmitChange()
|
|
255
|
+
},
|
|
256
|
+
handleClearValue() {
|
|
257
|
+
if (this.getSelect.isMulti) {
|
|
258
|
+
this.handleSelectConfirm([])
|
|
259
|
+
} else {
|
|
260
|
+
this.$pi.lang.isObject(this.val)
|
|
261
|
+
? this.handleSelectConfirm({ [this.getSelect.keyField]: '' })
|
|
262
|
+
: this.handleSelectConfirm('')
|
|
263
|
+
}
|
|
199
264
|
}
|
|
200
265
|
}
|
|
201
266
|
}
|