sadais-piui 1.2.7-beta113 → 1.2.7-beta115
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 +7 -7
- package/CHANGELOG.md +545 -545
- package/LICENSE +20 -20
- package/README.md +166 -166
- package/components/pi-action-sheet/index.vue +247 -247
- package/components/pi-badge/index.vue +146 -146
- package/components/pi-bottom-bar/index.vue +139 -139
- package/components/pi-bubble/index.vue +174 -174
- package/components/pi-button/index.vue +492 -492
- package/components/pi-calendar-input/index.vue +230 -230
- package/components/pi-calendar-panel/components/calendar-days/index.vue +410 -410
- package/components/pi-calendar-panel/index.vue +473 -473
- package/components/pi-canvas/index.vue +407 -407
- package/components/pi-card/index.vue +127 -127
- package/components/pi-cascader/index.vue +601 -601
- package/components/pi-checkbox/index.vue +363 -363
- package/components/pi-checkbox-group/index.vue +222 -222
- package/components/pi-circle-progress/index.vue +311 -311
- package/components/pi-code-input/index.vue +270 -270
- package/components/pi-collapse/index.vue +124 -124
- package/components/pi-collapse-item/index.vue +352 -352
- package/components/pi-count-down/index.vue +245 -245
- package/components/pi-count-up/index.vue +209 -209
- package/components/pi-date-picker-input/index.vue +219 -219
- package/components/pi-divider/index.vue +112 -112
- package/components/pi-dropdown/components/dropdown-tab.vue +71 -71
- package/components/pi-dropdown/index.vue +356 -356
- package/components/pi-dropdown-item/index.vue +252 -252
- package/components/pi-form/index.vue +273 -273
- package/components/pi-form-item/index.vue +603 -590
- package/components/pi-gap/index.vue +72 -72
- package/components/pi-grid/index.vue +92 -92
- package/components/pi-grid-item/index.vue +220 -220
- package/components/pi-icon/index.vue +147 -147
- package/components/pi-img/index.vue +266 -266
- package/components/pi-img-cropper/canvas.js +106 -106
- package/components/pi-img-cropper/index.vue +357 -357
- package/components/pi-img-cropper/touch.js +163 -163
- package/components/pi-img-cropper/vector.js +34 -34
- package/components/pi-input/index.vue +409 -401
- package/components/pi-line/index.vue +78 -78
- package/components/pi-line-progress/index.vue +198 -198
- package/components/pi-list/index.vue +115 -115
- package/components/pi-list-item/index.vue +335 -335
- package/components/pi-loading/index.vue +188 -188
- package/components/pi-marquee/index.vue +310 -310
- package/components/pi-marquee-item/index.vue +47 -47
- package/components/pi-mask/index.vue +198 -198
- package/components/pi-modal/index.vue +303 -303
- package/components/pi-navbar/index.vue +421 -421
- package/components/pi-notify/index.vue +239 -239
- package/components/pi-number-keyboard/index.vue +189 -189
- package/components/pi-opentype-button/index.vue +501 -501
- package/components/pi-pagination/index.vue +290 -290
- package/components/pi-picker/index.vue +317 -317
- package/components/pi-popup/index.vue +356 -356
- package/components/pi-popup-select/index.vue +300 -300
- package/components/pi-radio/index.vue +403 -403
- package/components/pi-radio-group/index.vue +300 -300
- package/components/pi-rate/index.vue +212 -212
- package/components/pi-regions-select/index.vue +349 -349
- package/components/pi-regions-select-input/index.vue +230 -230
- package/components/pi-search/index.vue +386 -386
- package/components/pi-section/index.vue +218 -218
- package/components/pi-select/index.vue +678 -678
- package/components/pi-select-input/index.vue +273 -273
- package/components/pi-skeleton/index.vue +280 -280
- package/components/pi-status-bar/index.vue +56 -56
- package/components/pi-stepper/index.vue +408 -408
- package/components/pi-steps/index.vue +378 -378
- package/components/pi-subsection/index.vue +403 -403
- package/components/pi-swiper/index.vue +344 -344
- package/components/pi-switch/index.vue +231 -231
- package/components/pi-table/index.vue +351 -351
- package/components/pi-tabs/index.vue +435 -435
- package/components/pi-tag/index.vue +488 -488
- package/components/pi-upload-img/index.vue +980 -980
- package/components/pi-waterfall/index.vue +130 -130
- package/config/actionSheet.js +24 -24
- package/config/badge.js +9 -9
- package/config/bottomBar.js +11 -11
- package/config/bubble.js +6 -6
- package/config/button.js +29 -29
- package/config/calendar.js +19 -19
- package/config/calendarInput.js +19 -19
- package/config/calendarPanel.js +27 -27
- package/config/card.js +8 -8
- package/config/cascader.js +22 -22
- package/config/checkbox.js +15 -15
- package/config/checkboxGroup.js +15 -15
- package/config/circleProgress.js +20 -20
- package/config/codeInput.js +13 -13
- package/config/collapse.js +7 -7
- package/config/collapseItem.js +11 -11
- package/config/countDown.js +12 -12
- package/config/countUp.js +13 -13
- package/config/datePickerInput.js +18 -18
- package/config/divider.js +10 -10
- package/config/dropdown.js +25 -25
- package/config/dropdownItem.js +26 -26
- package/config/form.js +29 -29
- package/config/formItem.js +27 -27
- package/config/gap.js +8 -8
- package/config/grid.js +9 -9
- package/config/gridItem.js +12 -12
- package/config/icon.js +11 -11
- package/config/img.js +21 -21
- package/config/imgCropper.js +26 -26
- package/config/index.js +28 -28
- package/config/input.js +37 -36
- package/config/line.js +8 -8
- package/config/lineProgress.js +14 -14
- package/config/list.js +12 -12
- package/config/listItem.js +25 -25
- package/config/loading.js +10 -10
- package/config/marquee.js +10 -10
- package/config/mask.js +12 -12
- package/config/modal.js +36 -36
- package/config/navbar.js +32 -32
- package/config/notify.js +13 -13
- package/config/numberKeyboard.js +21 -21
- package/config/pagination.js +10 -10
- package/config/picker.js +19 -19
- package/config/popup.js +23 -23
- package/config/popupSelect.js +35 -35
- package/config/radio.js +16 -16
- package/config/radioGroup.js +17 -17
- package/config/rate.js +15 -15
- package/config/regionsData.js +58 -58
- package/config/regionsSelect.js +19 -19
- package/config/regionsSelectInput.js +29 -29
- package/config/search.js +27 -27
- package/config/section.js +23 -23
- package/config/select.js +41 -41
- package/config/selectInput.js +29 -29
- package/config/skeleton.js +13 -13
- package/config/statusBar.js +5 -5
- package/config/stepper.js +19 -19
- package/config/steps.js +19 -19
- package/config/subsection.js +14 -14
- package/config/swiper.js +22 -22
- package/config/switch.js +13 -13
- package/config/table.js +8 -8
- package/config/tabs.js +23 -23
- package/config/tag.js +21 -21
- package/config/uploadImg.js +81 -81
- package/config/waterfall.js +6 -6
- package/index.js +41 -41
- package/mixin/component-custom.js +24 -24
- package/mixin/emitter.js +45 -45
- package/mixin/props-sync.js +65 -65
- package/mixin/value-sync.js +32 -32
- package/mixin/wx-code.js +30 -30
- package/package.json +28 -28
- package/plugins/async-validator.js +1511 -1511
- package/scss/animation.scss +260 -260
- package/scss/icon/icon.scss +595 -595
- package/scss/index.scss +5 -5
- package/scss/mixin.scss +47 -47
- package/tools/index.js +19 -19
|
@@ -1,678 +1,678 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<pi-popup-select
|
|
3
|
-
:value="val"
|
|
4
|
-
:custom-style="getPopupSelect.customStyle"
|
|
5
|
-
:custom-class="getPopupSelect.customClass"
|
|
6
|
-
:height="getPopupSelect.height"
|
|
7
|
-
:show-title="getPopupSelect.showTitle"
|
|
8
|
-
:title="getPopupSelect.title"
|
|
9
|
-
:title-padding="getPopupSelect.titlePadding"
|
|
10
|
-
:toolbar-position="getPopupSelect.toolbarPosition"
|
|
11
|
-
:on-confirm-close="getPopupSelect.onConfirmClose"
|
|
12
|
-
:on-cancel-close="getPopupSelect.onCancelClose"
|
|
13
|
-
:confirm-btn="getConfirmBtn"
|
|
14
|
-
:cancel-btn="getCancelBtn"
|
|
15
|
-
:popup="getPopup"
|
|
16
|
-
@close="handlePopupClose"
|
|
17
|
-
@cancel="handleCancel"
|
|
18
|
-
@confirm="handleConfirm"
|
|
19
|
-
@closed="$emit('closed', $event)"
|
|
20
|
-
@show="handleShowEvent"
|
|
21
|
-
@showed="$emit('showed', $event)"
|
|
22
|
-
>
|
|
23
|
-
<view
|
|
24
|
-
class="pi-select pi-h-100P pi-flex-column"
|
|
25
|
-
:style="[customStyle]"
|
|
26
|
-
:class="[customClass]"
|
|
27
|
-
>
|
|
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>
|
|
60
|
-
<scroll-view
|
|
61
|
-
scroll-y
|
|
62
|
-
class="pi-scroll"
|
|
63
|
-
:scroll-into-view="getFirstSelectedId"
|
|
64
|
-
scroll-with-animation
|
|
65
|
-
@scrolltolower="handleScrolltolower"
|
|
66
|
-
>
|
|
67
|
-
<view
|
|
68
|
-
v-for="item in getItems"
|
|
69
|
-
:id="`id-${item[keyField]}`"
|
|
70
|
-
:key="item[keyField]"
|
|
71
|
-
:style="[itemStyle, getItemStyle]"
|
|
72
|
-
:class="{
|
|
73
|
-
'pi-solid-bottom-1': showItemBottomBorder,
|
|
74
|
-
'disabled': item.disabled
|
|
75
|
-
}"
|
|
76
|
-
class="select-item pi-justify-between pi-align-center pi-fz-30 pi-pd-lr-32"
|
|
77
|
-
@tap.stop="handleSelectItem(item)"
|
|
78
|
-
>
|
|
79
|
-
<!-- 自定义列表项 -->
|
|
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>
|
|
96
|
-
</slot>
|
|
97
|
-
<!-- 如果配置了图片地址,使用图片 -->
|
|
98
|
-
<pi-img
|
|
99
|
-
v-if="getSelectedImg.src && item.isSelected"
|
|
100
|
-
:src="getSelectedImg.src"
|
|
101
|
-
:mode="getSelectedImg.mode"
|
|
102
|
-
:width="getSelectedImg.width"
|
|
103
|
-
:height="getSelectedImg.height"
|
|
104
|
-
:dot="getSelectedImg.dot"
|
|
105
|
-
:dot-radius="getSelectedImg.dotRadius"
|
|
106
|
-
:badge="getSelectedImg.badge"
|
|
107
|
-
:shape="getSelectedImg.shape"
|
|
108
|
-
:border-radius="getSelectedImg.borderRadius"
|
|
109
|
-
:show-loading="getSelectedImg.showLoading"
|
|
110
|
-
:loading-color="getSelectedImg.loadingColor"
|
|
111
|
-
:loading-type="getSelectedImg.loadingType"
|
|
112
|
-
:loading-size="getSelectedImg.loadingSize"
|
|
113
|
-
:show-error="getSelectedImg.showError"
|
|
114
|
-
:webp="getSelectedImg.webp"
|
|
115
|
-
custom-class="pi-mg-left-32"
|
|
116
|
-
/>
|
|
117
|
-
<!-- 默认使用复选框 -->
|
|
118
|
-
<pi-checkbox
|
|
119
|
-
v-if="!getSelectedImg.src"
|
|
120
|
-
readonly
|
|
121
|
-
:value="item.isSelected"
|
|
122
|
-
:name="getSelectedCheckbox.name"
|
|
123
|
-
:shape="getSelectedCheckbox.shape"
|
|
124
|
-
:border-radius="getSelectedCheckbox.borderRadius"
|
|
125
|
-
:border="getSelectedCheckbox.border"
|
|
126
|
-
:disabled="getSelectedCheckbox.disabled"
|
|
127
|
-
:size="getSelectedCheckbox.size"
|
|
128
|
-
:icon-size="getSelectedCheckbox.iconSize"
|
|
129
|
-
:active-color="getSelectedCheckbox.activeColor"
|
|
130
|
-
:active-mode="getSelectedCheckbox.activeMode"
|
|
131
|
-
custom-class="pi-mg-left-32"
|
|
132
|
-
/>
|
|
133
|
-
</view>
|
|
134
|
-
</scroll-view>
|
|
135
|
-
<slot name="footer" />
|
|
136
|
-
</view>
|
|
137
|
-
</pi-popup-select>
|
|
138
|
-
</template>
|
|
139
|
-
|
|
140
|
-
<script>
|
|
141
|
-
import ValueSync from '../../mixin/value-sync'
|
|
142
|
-
import { getConfig } from '../../config'
|
|
143
|
-
|
|
144
|
-
const TAG = 'PiSelect'
|
|
145
|
-
const { select } = getConfig()
|
|
146
|
-
|
|
147
|
-
const PI_DEFAULT_FN_FLAG = 'PI_DEFAULT_FN_FLAG'
|
|
148
|
-
|
|
149
|
-
export default {
|
|
150
|
-
name: 'PiSelect',
|
|
151
|
-
// 混入v-model
|
|
152
|
-
mixins: [ValueSync],
|
|
153
|
-
props: {
|
|
154
|
-
// 初始值
|
|
155
|
-
value: {
|
|
156
|
-
required: false
|
|
157
|
-
},
|
|
158
|
-
// 自定义样式
|
|
159
|
-
customStyle: {
|
|
160
|
-
type: Object,
|
|
161
|
-
// {}
|
|
162
|
-
default() {
|
|
163
|
-
return select.customStyle
|
|
164
|
-
}
|
|
165
|
-
},
|
|
166
|
-
// 自定义样式类
|
|
167
|
-
customClass: {
|
|
168
|
-
type: String,
|
|
169
|
-
// ''
|
|
170
|
-
default() {
|
|
171
|
-
return select.customClass
|
|
172
|
-
}
|
|
173
|
-
},
|
|
174
|
-
// 选项列表
|
|
175
|
-
items: {
|
|
176
|
-
type: Array,
|
|
177
|
-
// []
|
|
178
|
-
default() {
|
|
179
|
-
return select.items
|
|
180
|
-
}
|
|
181
|
-
},
|
|
182
|
-
// 列表选项的唯一标识
|
|
183
|
-
keyField: {
|
|
184
|
-
type: String,
|
|
185
|
-
// 'id'
|
|
186
|
-
default: select.keyField
|
|
187
|
-
},
|
|
188
|
-
// 选项显示字段
|
|
189
|
-
displayField: {
|
|
190
|
-
type: String,
|
|
191
|
-
// 'text'
|
|
192
|
-
default: select.displayField
|
|
193
|
-
},
|
|
194
|
-
// 描述显示字段,默认为desc
|
|
195
|
-
descField: {
|
|
196
|
-
type: String,
|
|
197
|
-
// 'desc'
|
|
198
|
-
default: select.descField
|
|
199
|
-
},
|
|
200
|
-
// 默认值,单选是传Number, String, Object,多选时传Array
|
|
201
|
-
defaultValue: {
|
|
202
|
-
type: [Number, String, Object, Array],
|
|
203
|
-
// null
|
|
204
|
-
default: select.defaultValue
|
|
205
|
-
},
|
|
206
|
-
// 是否只绑定keyField的默认值,默认false
|
|
207
|
-
keyDefaultValue: {
|
|
208
|
-
type: Boolean,
|
|
209
|
-
default: select.keyDefaultValue
|
|
210
|
-
},
|
|
211
|
-
// 是否多选
|
|
212
|
-
isMulti: {
|
|
213
|
-
type: Boolean,
|
|
214
|
-
// false
|
|
215
|
-
default: select.isMulti
|
|
216
|
-
},
|
|
217
|
-
// 是否显示全选(多选isMulti开启的情况下)
|
|
218
|
-
showSelectAll: {
|
|
219
|
-
type: Boolean,
|
|
220
|
-
// false
|
|
221
|
-
default: select.showSelectAll
|
|
222
|
-
},
|
|
223
|
-
// 单选模式下,是否可取消选中
|
|
224
|
-
singleCancel: {
|
|
225
|
-
type: Boolean,
|
|
226
|
-
// true
|
|
227
|
-
default: select.singleCancel
|
|
228
|
-
},
|
|
229
|
-
// 单选模式下,是否直接选中,不需要点击确认按钮
|
|
230
|
-
singleConfirm: {
|
|
231
|
-
type: Boolean,
|
|
232
|
-
// false
|
|
233
|
-
default: select.singleConfirm
|
|
234
|
-
},
|
|
235
|
-
// 行高 值为数字,则单位默认rpx
|
|
236
|
-
itemHeight: {
|
|
237
|
-
type: [String, Number],
|
|
238
|
-
// 110
|
|
239
|
-
default: select.itemHeight
|
|
240
|
-
},
|
|
241
|
-
// 是否显示item下边框
|
|
242
|
-
showItemBottomBorder: {
|
|
243
|
-
type: Boolean,
|
|
244
|
-
// true
|
|
245
|
-
default: select.showItemBottomBorder
|
|
246
|
-
},
|
|
247
|
-
// 行样式
|
|
248
|
-
itemStyle: {
|
|
249
|
-
type: Object,
|
|
250
|
-
// {}
|
|
251
|
-
default() {
|
|
252
|
-
return select.itemStyle
|
|
253
|
-
}
|
|
254
|
-
},
|
|
255
|
-
// 选中图标的配置
|
|
256
|
-
selectedImg: {
|
|
257
|
-
type: Object,
|
|
258
|
-
default() {
|
|
259
|
-
// 参照img
|
|
260
|
-
return select.selectedImg
|
|
261
|
-
}
|
|
262
|
-
},
|
|
263
|
-
// 选中checkbox配置
|
|
264
|
-
selectedCheckbox: {
|
|
265
|
-
type: Object,
|
|
266
|
-
default() {
|
|
267
|
-
// 参照checkbox
|
|
268
|
-
return select.selectedCheckbox
|
|
269
|
-
}
|
|
270
|
-
},
|
|
271
|
-
// 弹窗选择参数设置
|
|
272
|
-
popupSelect: {
|
|
273
|
-
type: Object,
|
|
274
|
-
default() {
|
|
275
|
-
// 参照popupSelect
|
|
276
|
-
return select.popupSelect
|
|
277
|
-
}
|
|
278
|
-
},
|
|
279
|
-
// 确认按钮配置
|
|
280
|
-
confirmBtn: {
|
|
281
|
-
type: Object,
|
|
282
|
-
default() {
|
|
283
|
-
return select.confirmBtn
|
|
284
|
-
}
|
|
285
|
-
},
|
|
286
|
-
// 取消按钮配置
|
|
287
|
-
cancelBtn: {
|
|
288
|
-
type: Object,
|
|
289
|
-
default() {
|
|
290
|
-
return select.cancelBtn
|
|
291
|
-
}
|
|
292
|
-
},
|
|
293
|
-
// 弹窗参数设置
|
|
294
|
-
popup: {
|
|
295
|
-
type: Object,
|
|
296
|
-
default() {
|
|
297
|
-
// 参照popup
|
|
298
|
-
return select.popup
|
|
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: ''
|
|
322
|
-
}
|
|
323
|
-
},
|
|
324
|
-
data() {
|
|
325
|
-
return {
|
|
326
|
-
// 当前选中的值
|
|
327
|
-
selected: {},
|
|
328
|
-
keyword: '',
|
|
329
|
-
remoteItems: [],
|
|
330
|
-
remoteLoading: false,
|
|
331
|
-
pageNo: 1,
|
|
332
|
-
isEnd: false
|
|
333
|
-
}
|
|
334
|
-
},
|
|
335
|
-
computed: {
|
|
336
|
-
getSelectedImg() {
|
|
337
|
-
return this.$pi.lang.mergeDeep(select.selectedImg, this.selectedImg)
|
|
338
|
-
},
|
|
339
|
-
getSelectedCheckbox() {
|
|
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
|
-
)
|
|
350
|
-
},
|
|
351
|
-
getPopupSelect() {
|
|
352
|
-
const popupSelect = this.$pi.lang.mergeDeep(
|
|
353
|
-
select.popupSelect,
|
|
354
|
-
this.popupSelect
|
|
355
|
-
)
|
|
356
|
-
if (!this.singleCancel && this.singleConfirm) {
|
|
357
|
-
popupSelect.toolbarPosition = 'none'
|
|
358
|
-
}
|
|
359
|
-
return popupSelect
|
|
360
|
-
},
|
|
361
|
-
getConfirmBtn() {
|
|
362
|
-
const selectConfirmBtn = this.$pi.lang.mergeDeep(
|
|
363
|
-
select.confirmBtn,
|
|
364
|
-
this.popupSelect.confirmBtn
|
|
365
|
-
)
|
|
366
|
-
return this.$pi.lang.mergeDeep(selectConfirmBtn, this.confirmBtn)
|
|
367
|
-
},
|
|
368
|
-
getCancelBtn() {
|
|
369
|
-
const selectCancelBtn = this.$pi.lang.mergeDeep(
|
|
370
|
-
select.cancelBtn,
|
|
371
|
-
this.popupSelect.cancelBtn
|
|
372
|
-
)
|
|
373
|
-
return this.$pi.lang.mergeDeep(selectCancelBtn, this.cancelBtn)
|
|
374
|
-
},
|
|
375
|
-
getPopup() {
|
|
376
|
-
const selectPopup = this.$pi.lang.mergeDeep(
|
|
377
|
-
select.popup,
|
|
378
|
-
this.popupSelect.popup
|
|
379
|
-
)
|
|
380
|
-
return this.$pi.lang.mergeDeep(selectPopup, this.popup)
|
|
381
|
-
},
|
|
382
|
-
getItemStyle() {
|
|
383
|
-
return {
|
|
384
|
-
height: this.$pi.common.addUnit(this.itemHeight)
|
|
385
|
-
}
|
|
386
|
-
},
|
|
387
|
-
getItems() {
|
|
388
|
-
const targetItems = this.remoteSearchConfig.enable
|
|
389
|
-
? this.remoteItems
|
|
390
|
-
: this.items
|
|
391
|
-
return targetItems.map(item => {
|
|
392
|
-
let isSelected = false
|
|
393
|
-
if (this.isMulti) {
|
|
394
|
-
isSelected =
|
|
395
|
-
this.$pi.lang.isArray(this.selected) &&
|
|
396
|
-
this.selected.findIndex(
|
|
397
|
-
s => s[this.keyField] === item[this.keyField]
|
|
398
|
-
) !== -1
|
|
399
|
-
} else {
|
|
400
|
-
isSelected = this.selected[this.keyField] === item[this.keyField]
|
|
401
|
-
}
|
|
402
|
-
item.isSelected = isSelected
|
|
403
|
-
return item
|
|
404
|
-
})
|
|
405
|
-
},
|
|
406
|
-
getFirstSelectedId() {
|
|
407
|
-
const firstSelected = this.selected[0] || this.selected
|
|
408
|
-
const firstSelectedId = firstSelected[this.keyField]
|
|
409
|
-
return firstSelectedId ? `id-${firstSelected[this.keyField]}` : ''
|
|
410
|
-
},
|
|
411
|
-
isSelectAll() {
|
|
412
|
-
return this.getItems.every(item => item.isSelected)
|
|
413
|
-
}
|
|
414
|
-
},
|
|
415
|
-
watch: {
|
|
416
|
-
value(val) {
|
|
417
|
-
val && this.init()
|
|
418
|
-
}
|
|
419
|
-
},
|
|
420
|
-
methods: {
|
|
421
|
-
valid() {
|
|
422
|
-
if (!this.$pi.lang.isEmpty(this.defaultValue)) {
|
|
423
|
-
if (this.isMulti && !this.$pi.lang.isArray(this.defaultValue)) {
|
|
424
|
-
console.error(TAG, '多选模式下defaultValue必须为数组类型')
|
|
425
|
-
return false
|
|
426
|
-
}
|
|
427
|
-
if (this.isMulti && this.$pi.lang.isArray(this.defaultValue)) {
|
|
428
|
-
const isArrayObject = this.defaultValue.every(item => {
|
|
429
|
-
return this.$pi.lang.isObject(item)
|
|
430
|
-
})
|
|
431
|
-
if (this.keyDefaultValue && isArrayObject) {
|
|
432
|
-
console.error(
|
|
433
|
-
TAG,
|
|
434
|
-
'keyDefaultValue模式下defaultValue不能为对象数组类型'
|
|
435
|
-
)
|
|
436
|
-
return false
|
|
437
|
-
}
|
|
438
|
-
if (!this.keyDefaultValue && !isArrayObject) {
|
|
439
|
-
console.error(
|
|
440
|
-
TAG,
|
|
441
|
-
'非keyDefaultValue模式下defaultValue必须为对象数组类型'
|
|
442
|
-
)
|
|
443
|
-
return false
|
|
444
|
-
}
|
|
445
|
-
}
|
|
446
|
-
if (!this.isMulti) {
|
|
447
|
-
if (
|
|
448
|
-
this.keyDefaultValue &&
|
|
449
|
-
this.$pi.lang.isObject(this.defaultValue)
|
|
450
|
-
) {
|
|
451
|
-
console.error(
|
|
452
|
-
TAG,
|
|
453
|
-
'keyDefaultValue模式下defaultValue不能为对象类型'
|
|
454
|
-
)
|
|
455
|
-
return false
|
|
456
|
-
}
|
|
457
|
-
if (
|
|
458
|
-
!this.keyDefaultValue &&
|
|
459
|
-
(!this.$pi.lang.isObject(this.defaultValue) ||
|
|
460
|
-
this.$pi.lang.isArray(this.defaultValue))
|
|
461
|
-
) {
|
|
462
|
-
console.error(
|
|
463
|
-
TAG,
|
|
464
|
-
'非keyDefaultValue模式下defaultValue必须为对象类型'
|
|
465
|
-
)
|
|
466
|
-
return false
|
|
467
|
-
}
|
|
468
|
-
}
|
|
469
|
-
}
|
|
470
|
-
return true
|
|
471
|
-
},
|
|
472
|
-
init() {
|
|
473
|
-
if (!this.valid()) {
|
|
474
|
-
return console.error(TAG, '默认值校验失败,跳过初始化')
|
|
475
|
-
}
|
|
476
|
-
console.log(TAG, '初始化')
|
|
477
|
-
let selected = this.isMulti ? [] : {}
|
|
478
|
-
if (!this.$pi.lang.isEmpty(this.defaultValue)) {
|
|
479
|
-
// 如果有默认值,进行初始化
|
|
480
|
-
if (!this.keyDefaultValue) {
|
|
481
|
-
selected = this.$pi.lang.cloneDeep(this.defaultValue)
|
|
482
|
-
} else {
|
|
483
|
-
// 非对象类型构造成对象类型处理
|
|
484
|
-
if (this.isMulti && this.$pi.lang.isArray(this.defaultValue)) {
|
|
485
|
-
selected = this.defaultValue.map(item => ({
|
|
486
|
-
[this.keyField]: item
|
|
487
|
-
}))
|
|
488
|
-
}
|
|
489
|
-
if (!this.isMulti && !this.$pi.lang.isObject(this.defaultValue)) {
|
|
490
|
-
selected = {
|
|
491
|
-
[this.keyField]: this.defaultValue
|
|
492
|
-
}
|
|
493
|
-
}
|
|
494
|
-
}
|
|
495
|
-
}
|
|
496
|
-
this.selected = selected
|
|
497
|
-
},
|
|
498
|
-
handlePopupClose() {
|
|
499
|
-
this.val = false
|
|
500
|
-
// 关闭弹窗
|
|
501
|
-
this.$emit('close')
|
|
502
|
-
this.handleEmitChange()
|
|
503
|
-
},
|
|
504
|
-
handleSelectItem(item) {
|
|
505
|
-
if (item.disabled) return
|
|
506
|
-
if (!this.isMulti) {
|
|
507
|
-
// 单选
|
|
508
|
-
if (!this.singleCancel) {
|
|
509
|
-
this.selected = item
|
|
510
|
-
if (this.singleConfirm) {
|
|
511
|
-
setTimeout(() => {
|
|
512
|
-
this.handleConfirm()
|
|
513
|
-
}, 300)
|
|
514
|
-
}
|
|
515
|
-
return
|
|
516
|
-
}
|
|
517
|
-
// 如果单选允许取消,需要判断是否点击了同一个选项
|
|
518
|
-
const isSame =
|
|
519
|
-
!this.$pi.lang.isEmpty(this.selected) &&
|
|
520
|
-
this.selected[this.keyField] === item[this.keyField]
|
|
521
|
-
// 如果当前已勾选,比较是否同一个,如果同一个就取消勾选
|
|
522
|
-
this.selected = isSame ? {} : item
|
|
523
|
-
return
|
|
524
|
-
}
|
|
525
|
-
// 多选
|
|
526
|
-
const hasSelected =
|
|
527
|
-
this.selected.findIndex(
|
|
528
|
-
s => s[this.keyField] === item[this.keyField]
|
|
529
|
-
) !== -1
|
|
530
|
-
if (hasSelected) {
|
|
531
|
-
this.selected = this.selected.filter(
|
|
532
|
-
s => s[this.keyField] !== item[this.keyField]
|
|
533
|
-
)
|
|
534
|
-
} else {
|
|
535
|
-
this.selected.push(item)
|
|
536
|
-
}
|
|
537
|
-
},
|
|
538
|
-
/**
|
|
539
|
-
* @vuese
|
|
540
|
-
* 全选或全清选择值
|
|
541
|
-
* @arg selected=true 是否勾选
|
|
542
|
-
* @arg nodes=[] 需要改变的节点,不填默认全部
|
|
543
|
-
*/
|
|
544
|
-
toggleSelect(selected = true, nodes = []) {
|
|
545
|
-
if (!this.isMulti) return
|
|
546
|
-
if (!selected) {
|
|
547
|
-
// 全清
|
|
548
|
-
this.selected = []
|
|
549
|
-
return
|
|
550
|
-
}
|
|
551
|
-
const toggleSelect = this.items.filter(item => {
|
|
552
|
-
let toggleNode = true
|
|
553
|
-
if (nodes.length) {
|
|
554
|
-
toggleNode =
|
|
555
|
-
nodes.findIndex(
|
|
556
|
-
node => node[this.keyField] === item[this.keyField]
|
|
557
|
-
) !== -1
|
|
558
|
-
}
|
|
559
|
-
return toggleNode && !item.disabled
|
|
560
|
-
})
|
|
561
|
-
if (!toggleSelect.length) return
|
|
562
|
-
this.selected = toggleSelect
|
|
563
|
-
},
|
|
564
|
-
/**
|
|
565
|
-
* @vuese
|
|
566
|
-
* 取消选择
|
|
567
|
-
*/
|
|
568
|
-
handleCancel() {
|
|
569
|
-
this.$emit('cancel')
|
|
570
|
-
this.getPopupSelect.onCancelClose && this.handlePopupClose()
|
|
571
|
-
},
|
|
572
|
-
/**
|
|
573
|
-
* @vuese
|
|
574
|
-
* 确认选择
|
|
575
|
-
*/
|
|
576
|
-
handleConfirm() {
|
|
577
|
-
let selected = this.selected
|
|
578
|
-
if (!this.$pi.lang.isEmpty(selected) && this.keyDefaultValue) {
|
|
579
|
-
// 非对象类型返回值,返回值处理成非对象类型
|
|
580
|
-
if (this.$pi.lang.isArray(selected)) {
|
|
581
|
-
selected = selected.map(item => item[this.keyField])
|
|
582
|
-
} else if (this.$pi.lang.isObject(selected)) {
|
|
583
|
-
selected = selected[this.keyField]
|
|
584
|
-
}
|
|
585
|
-
}
|
|
586
|
-
this.$emit('confirm', selected, this.selected)
|
|
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)
|
|
661
|
-
}
|
|
662
|
-
}
|
|
663
|
-
}
|
|
664
|
-
</script>
|
|
665
|
-
|
|
666
|
-
<style lang="scss" scoped>
|
|
667
|
-
.pi-select {
|
|
668
|
-
.select-item.disabled {
|
|
669
|
-
opacity: $pi-disabled-opacity;
|
|
670
|
-
}
|
|
671
|
-
.pi-button-wrap {
|
|
672
|
-
flex: 1;
|
|
673
|
-
&:nth-child(2) {
|
|
674
|
-
margin-left: 24rpx;
|
|
675
|
-
}
|
|
676
|
-
}
|
|
677
|
-
}
|
|
678
|
-
</style>
|
|
1
|
+
<template>
|
|
2
|
+
<pi-popup-select
|
|
3
|
+
:value="val"
|
|
4
|
+
:custom-style="getPopupSelect.customStyle"
|
|
5
|
+
:custom-class="getPopupSelect.customClass"
|
|
6
|
+
:height="getPopupSelect.height"
|
|
7
|
+
:show-title="getPopupSelect.showTitle"
|
|
8
|
+
:title="getPopupSelect.title"
|
|
9
|
+
:title-padding="getPopupSelect.titlePadding"
|
|
10
|
+
:toolbar-position="getPopupSelect.toolbarPosition"
|
|
11
|
+
:on-confirm-close="getPopupSelect.onConfirmClose"
|
|
12
|
+
:on-cancel-close="getPopupSelect.onCancelClose"
|
|
13
|
+
:confirm-btn="getConfirmBtn"
|
|
14
|
+
:cancel-btn="getCancelBtn"
|
|
15
|
+
:popup="getPopup"
|
|
16
|
+
@close="handlePopupClose"
|
|
17
|
+
@cancel="handleCancel"
|
|
18
|
+
@confirm="handleConfirm"
|
|
19
|
+
@closed="$emit('closed', $event)"
|
|
20
|
+
@show="handleShowEvent"
|
|
21
|
+
@showed="$emit('showed', $event)"
|
|
22
|
+
>
|
|
23
|
+
<view
|
|
24
|
+
class="pi-select pi-h-100P pi-flex-column"
|
|
25
|
+
:style="[customStyle]"
|
|
26
|
+
:class="[customClass]"
|
|
27
|
+
>
|
|
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>
|
|
60
|
+
<scroll-view
|
|
61
|
+
scroll-y
|
|
62
|
+
class="pi-scroll"
|
|
63
|
+
:scroll-into-view="getFirstSelectedId"
|
|
64
|
+
scroll-with-animation
|
|
65
|
+
@scrolltolower="handleScrolltolower"
|
|
66
|
+
>
|
|
67
|
+
<view
|
|
68
|
+
v-for="item in getItems"
|
|
69
|
+
:id="`id-${item[keyField]}`"
|
|
70
|
+
:key="item[keyField]"
|
|
71
|
+
:style="[itemStyle, getItemStyle]"
|
|
72
|
+
:class="{
|
|
73
|
+
'pi-solid-bottom-1': showItemBottomBorder,
|
|
74
|
+
'disabled': item.disabled
|
|
75
|
+
}"
|
|
76
|
+
class="select-item pi-justify-between pi-align-center pi-fz-30 pi-pd-lr-32"
|
|
77
|
+
@tap.stop="handleSelectItem(item)"
|
|
78
|
+
>
|
|
79
|
+
<!-- 自定义列表项 -->
|
|
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>
|
|
96
|
+
</slot>
|
|
97
|
+
<!-- 如果配置了图片地址,使用图片 -->
|
|
98
|
+
<pi-img
|
|
99
|
+
v-if="getSelectedImg.src && item.isSelected"
|
|
100
|
+
:src="getSelectedImg.src"
|
|
101
|
+
:mode="getSelectedImg.mode"
|
|
102
|
+
:width="getSelectedImg.width"
|
|
103
|
+
:height="getSelectedImg.height"
|
|
104
|
+
:dot="getSelectedImg.dot"
|
|
105
|
+
:dot-radius="getSelectedImg.dotRadius"
|
|
106
|
+
:badge="getSelectedImg.badge"
|
|
107
|
+
:shape="getSelectedImg.shape"
|
|
108
|
+
:border-radius="getSelectedImg.borderRadius"
|
|
109
|
+
:show-loading="getSelectedImg.showLoading"
|
|
110
|
+
:loading-color="getSelectedImg.loadingColor"
|
|
111
|
+
:loading-type="getSelectedImg.loadingType"
|
|
112
|
+
:loading-size="getSelectedImg.loadingSize"
|
|
113
|
+
:show-error="getSelectedImg.showError"
|
|
114
|
+
:webp="getSelectedImg.webp"
|
|
115
|
+
custom-class="pi-mg-left-32"
|
|
116
|
+
/>
|
|
117
|
+
<!-- 默认使用复选框 -->
|
|
118
|
+
<pi-checkbox
|
|
119
|
+
v-if="!getSelectedImg.src"
|
|
120
|
+
readonly
|
|
121
|
+
:value="item.isSelected"
|
|
122
|
+
:name="getSelectedCheckbox.name"
|
|
123
|
+
:shape="getSelectedCheckbox.shape"
|
|
124
|
+
:border-radius="getSelectedCheckbox.borderRadius"
|
|
125
|
+
:border="getSelectedCheckbox.border"
|
|
126
|
+
:disabled="getSelectedCheckbox.disabled"
|
|
127
|
+
:size="getSelectedCheckbox.size"
|
|
128
|
+
:icon-size="getSelectedCheckbox.iconSize"
|
|
129
|
+
:active-color="getSelectedCheckbox.activeColor"
|
|
130
|
+
:active-mode="getSelectedCheckbox.activeMode"
|
|
131
|
+
custom-class="pi-mg-left-32"
|
|
132
|
+
/>
|
|
133
|
+
</view>
|
|
134
|
+
</scroll-view>
|
|
135
|
+
<slot name="footer" />
|
|
136
|
+
</view>
|
|
137
|
+
</pi-popup-select>
|
|
138
|
+
</template>
|
|
139
|
+
|
|
140
|
+
<script>
|
|
141
|
+
import ValueSync from '../../mixin/value-sync'
|
|
142
|
+
import { getConfig } from '../../config'
|
|
143
|
+
|
|
144
|
+
const TAG = 'PiSelect'
|
|
145
|
+
const { select } = getConfig()
|
|
146
|
+
|
|
147
|
+
const PI_DEFAULT_FN_FLAG = 'PI_DEFAULT_FN_FLAG'
|
|
148
|
+
|
|
149
|
+
export default {
|
|
150
|
+
name: 'PiSelect',
|
|
151
|
+
// 混入v-model
|
|
152
|
+
mixins: [ValueSync],
|
|
153
|
+
props: {
|
|
154
|
+
// 初始值
|
|
155
|
+
value: {
|
|
156
|
+
required: false
|
|
157
|
+
},
|
|
158
|
+
// 自定义样式
|
|
159
|
+
customStyle: {
|
|
160
|
+
type: Object,
|
|
161
|
+
// {}
|
|
162
|
+
default() {
|
|
163
|
+
return select.customStyle
|
|
164
|
+
}
|
|
165
|
+
},
|
|
166
|
+
// 自定义样式类
|
|
167
|
+
customClass: {
|
|
168
|
+
type: String,
|
|
169
|
+
// ''
|
|
170
|
+
default() {
|
|
171
|
+
return select.customClass
|
|
172
|
+
}
|
|
173
|
+
},
|
|
174
|
+
// 选项列表
|
|
175
|
+
items: {
|
|
176
|
+
type: Array,
|
|
177
|
+
// []
|
|
178
|
+
default() {
|
|
179
|
+
return select.items
|
|
180
|
+
}
|
|
181
|
+
},
|
|
182
|
+
// 列表选项的唯一标识
|
|
183
|
+
keyField: {
|
|
184
|
+
type: String,
|
|
185
|
+
// 'id'
|
|
186
|
+
default: select.keyField
|
|
187
|
+
},
|
|
188
|
+
// 选项显示字段
|
|
189
|
+
displayField: {
|
|
190
|
+
type: String,
|
|
191
|
+
// 'text'
|
|
192
|
+
default: select.displayField
|
|
193
|
+
},
|
|
194
|
+
// 描述显示字段,默认为desc
|
|
195
|
+
descField: {
|
|
196
|
+
type: String,
|
|
197
|
+
// 'desc'
|
|
198
|
+
default: select.descField
|
|
199
|
+
},
|
|
200
|
+
// 默认值,单选是传Number, String, Object,多选时传Array
|
|
201
|
+
defaultValue: {
|
|
202
|
+
type: [Number, String, Object, Array],
|
|
203
|
+
// null
|
|
204
|
+
default: select.defaultValue
|
|
205
|
+
},
|
|
206
|
+
// 是否只绑定keyField的默认值,默认false
|
|
207
|
+
keyDefaultValue: {
|
|
208
|
+
type: Boolean,
|
|
209
|
+
default: select.keyDefaultValue
|
|
210
|
+
},
|
|
211
|
+
// 是否多选
|
|
212
|
+
isMulti: {
|
|
213
|
+
type: Boolean,
|
|
214
|
+
// false
|
|
215
|
+
default: select.isMulti
|
|
216
|
+
},
|
|
217
|
+
// 是否显示全选(多选isMulti开启的情况下)
|
|
218
|
+
showSelectAll: {
|
|
219
|
+
type: Boolean,
|
|
220
|
+
// false
|
|
221
|
+
default: select.showSelectAll
|
|
222
|
+
},
|
|
223
|
+
// 单选模式下,是否可取消选中
|
|
224
|
+
singleCancel: {
|
|
225
|
+
type: Boolean,
|
|
226
|
+
// true
|
|
227
|
+
default: select.singleCancel
|
|
228
|
+
},
|
|
229
|
+
// 单选模式下,是否直接选中,不需要点击确认按钮
|
|
230
|
+
singleConfirm: {
|
|
231
|
+
type: Boolean,
|
|
232
|
+
// false
|
|
233
|
+
default: select.singleConfirm
|
|
234
|
+
},
|
|
235
|
+
// 行高 值为数字,则单位默认rpx
|
|
236
|
+
itemHeight: {
|
|
237
|
+
type: [String, Number],
|
|
238
|
+
// 110
|
|
239
|
+
default: select.itemHeight
|
|
240
|
+
},
|
|
241
|
+
// 是否显示item下边框
|
|
242
|
+
showItemBottomBorder: {
|
|
243
|
+
type: Boolean,
|
|
244
|
+
// true
|
|
245
|
+
default: select.showItemBottomBorder
|
|
246
|
+
},
|
|
247
|
+
// 行样式
|
|
248
|
+
itemStyle: {
|
|
249
|
+
type: Object,
|
|
250
|
+
// {}
|
|
251
|
+
default() {
|
|
252
|
+
return select.itemStyle
|
|
253
|
+
}
|
|
254
|
+
},
|
|
255
|
+
// 选中图标的配置
|
|
256
|
+
selectedImg: {
|
|
257
|
+
type: Object,
|
|
258
|
+
default() {
|
|
259
|
+
// 参照img
|
|
260
|
+
return select.selectedImg
|
|
261
|
+
}
|
|
262
|
+
},
|
|
263
|
+
// 选中checkbox配置
|
|
264
|
+
selectedCheckbox: {
|
|
265
|
+
type: Object,
|
|
266
|
+
default() {
|
|
267
|
+
// 参照checkbox
|
|
268
|
+
return select.selectedCheckbox
|
|
269
|
+
}
|
|
270
|
+
},
|
|
271
|
+
// 弹窗选择参数设置
|
|
272
|
+
popupSelect: {
|
|
273
|
+
type: Object,
|
|
274
|
+
default() {
|
|
275
|
+
// 参照popupSelect
|
|
276
|
+
return select.popupSelect
|
|
277
|
+
}
|
|
278
|
+
},
|
|
279
|
+
// 确认按钮配置
|
|
280
|
+
confirmBtn: {
|
|
281
|
+
type: Object,
|
|
282
|
+
default() {
|
|
283
|
+
return select.confirmBtn
|
|
284
|
+
}
|
|
285
|
+
},
|
|
286
|
+
// 取消按钮配置
|
|
287
|
+
cancelBtn: {
|
|
288
|
+
type: Object,
|
|
289
|
+
default() {
|
|
290
|
+
return select.cancelBtn
|
|
291
|
+
}
|
|
292
|
+
},
|
|
293
|
+
// 弹窗参数设置
|
|
294
|
+
popup: {
|
|
295
|
+
type: Object,
|
|
296
|
+
default() {
|
|
297
|
+
// 参照popup
|
|
298
|
+
return select.popup
|
|
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: ''
|
|
322
|
+
}
|
|
323
|
+
},
|
|
324
|
+
data() {
|
|
325
|
+
return {
|
|
326
|
+
// 当前选中的值
|
|
327
|
+
selected: {},
|
|
328
|
+
keyword: '',
|
|
329
|
+
remoteItems: [],
|
|
330
|
+
remoteLoading: false,
|
|
331
|
+
pageNo: 1,
|
|
332
|
+
isEnd: false
|
|
333
|
+
}
|
|
334
|
+
},
|
|
335
|
+
computed: {
|
|
336
|
+
getSelectedImg() {
|
|
337
|
+
return this.$pi.lang.mergeDeep(select.selectedImg, this.selectedImg)
|
|
338
|
+
},
|
|
339
|
+
getSelectedCheckbox() {
|
|
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
|
+
)
|
|
350
|
+
},
|
|
351
|
+
getPopupSelect() {
|
|
352
|
+
const popupSelect = this.$pi.lang.mergeDeep(
|
|
353
|
+
select.popupSelect,
|
|
354
|
+
this.popupSelect
|
|
355
|
+
)
|
|
356
|
+
if (!this.singleCancel && this.singleConfirm) {
|
|
357
|
+
popupSelect.toolbarPosition = 'none'
|
|
358
|
+
}
|
|
359
|
+
return popupSelect
|
|
360
|
+
},
|
|
361
|
+
getConfirmBtn() {
|
|
362
|
+
const selectConfirmBtn = this.$pi.lang.mergeDeep(
|
|
363
|
+
select.confirmBtn,
|
|
364
|
+
this.popupSelect.confirmBtn
|
|
365
|
+
)
|
|
366
|
+
return this.$pi.lang.mergeDeep(selectConfirmBtn, this.confirmBtn)
|
|
367
|
+
},
|
|
368
|
+
getCancelBtn() {
|
|
369
|
+
const selectCancelBtn = this.$pi.lang.mergeDeep(
|
|
370
|
+
select.cancelBtn,
|
|
371
|
+
this.popupSelect.cancelBtn
|
|
372
|
+
)
|
|
373
|
+
return this.$pi.lang.mergeDeep(selectCancelBtn, this.cancelBtn)
|
|
374
|
+
},
|
|
375
|
+
getPopup() {
|
|
376
|
+
const selectPopup = this.$pi.lang.mergeDeep(
|
|
377
|
+
select.popup,
|
|
378
|
+
this.popupSelect.popup
|
|
379
|
+
)
|
|
380
|
+
return this.$pi.lang.mergeDeep(selectPopup, this.popup)
|
|
381
|
+
},
|
|
382
|
+
getItemStyle() {
|
|
383
|
+
return {
|
|
384
|
+
height: this.$pi.common.addUnit(this.itemHeight)
|
|
385
|
+
}
|
|
386
|
+
},
|
|
387
|
+
getItems() {
|
|
388
|
+
const targetItems = this.remoteSearchConfig.enable
|
|
389
|
+
? this.remoteItems
|
|
390
|
+
: this.items
|
|
391
|
+
return targetItems.map(item => {
|
|
392
|
+
let isSelected = false
|
|
393
|
+
if (this.isMulti) {
|
|
394
|
+
isSelected =
|
|
395
|
+
this.$pi.lang.isArray(this.selected) &&
|
|
396
|
+
this.selected.findIndex(
|
|
397
|
+
s => s[this.keyField] === item[this.keyField]
|
|
398
|
+
) !== -1
|
|
399
|
+
} else {
|
|
400
|
+
isSelected = this.selected[this.keyField] === item[this.keyField]
|
|
401
|
+
}
|
|
402
|
+
item.isSelected = isSelected
|
|
403
|
+
return item
|
|
404
|
+
})
|
|
405
|
+
},
|
|
406
|
+
getFirstSelectedId() {
|
|
407
|
+
const firstSelected = this.selected[0] || this.selected
|
|
408
|
+
const firstSelectedId = firstSelected[this.keyField]
|
|
409
|
+
return firstSelectedId ? `id-${firstSelected[this.keyField]}` : ''
|
|
410
|
+
},
|
|
411
|
+
isSelectAll() {
|
|
412
|
+
return this.getItems.every(item => item.isSelected)
|
|
413
|
+
}
|
|
414
|
+
},
|
|
415
|
+
watch: {
|
|
416
|
+
value(val) {
|
|
417
|
+
val && this.init()
|
|
418
|
+
}
|
|
419
|
+
},
|
|
420
|
+
methods: {
|
|
421
|
+
valid() {
|
|
422
|
+
if (!this.$pi.lang.isEmpty(this.defaultValue)) {
|
|
423
|
+
if (this.isMulti && !this.$pi.lang.isArray(this.defaultValue)) {
|
|
424
|
+
console.error(TAG, '多选模式下defaultValue必须为数组类型')
|
|
425
|
+
return false
|
|
426
|
+
}
|
|
427
|
+
if (this.isMulti && this.$pi.lang.isArray(this.defaultValue)) {
|
|
428
|
+
const isArrayObject = this.defaultValue.every(item => {
|
|
429
|
+
return this.$pi.lang.isObject(item)
|
|
430
|
+
})
|
|
431
|
+
if (this.keyDefaultValue && isArrayObject) {
|
|
432
|
+
console.error(
|
|
433
|
+
TAG,
|
|
434
|
+
'keyDefaultValue模式下defaultValue不能为对象数组类型'
|
|
435
|
+
)
|
|
436
|
+
return false
|
|
437
|
+
}
|
|
438
|
+
if (!this.keyDefaultValue && !isArrayObject) {
|
|
439
|
+
console.error(
|
|
440
|
+
TAG,
|
|
441
|
+
'非keyDefaultValue模式下defaultValue必须为对象数组类型'
|
|
442
|
+
)
|
|
443
|
+
return false
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
if (!this.isMulti) {
|
|
447
|
+
if (
|
|
448
|
+
this.keyDefaultValue &&
|
|
449
|
+
this.$pi.lang.isObject(this.defaultValue)
|
|
450
|
+
) {
|
|
451
|
+
console.error(
|
|
452
|
+
TAG,
|
|
453
|
+
'keyDefaultValue模式下defaultValue不能为对象类型'
|
|
454
|
+
)
|
|
455
|
+
return false
|
|
456
|
+
}
|
|
457
|
+
if (
|
|
458
|
+
!this.keyDefaultValue &&
|
|
459
|
+
(!this.$pi.lang.isObject(this.defaultValue) ||
|
|
460
|
+
this.$pi.lang.isArray(this.defaultValue))
|
|
461
|
+
) {
|
|
462
|
+
console.error(
|
|
463
|
+
TAG,
|
|
464
|
+
'非keyDefaultValue模式下defaultValue必须为对象类型'
|
|
465
|
+
)
|
|
466
|
+
return false
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
return true
|
|
471
|
+
},
|
|
472
|
+
init() {
|
|
473
|
+
if (!this.valid()) {
|
|
474
|
+
return console.error(TAG, '默认值校验失败,跳过初始化')
|
|
475
|
+
}
|
|
476
|
+
console.log(TAG, '初始化')
|
|
477
|
+
let selected = this.isMulti ? [] : {}
|
|
478
|
+
if (!this.$pi.lang.isEmpty(this.defaultValue)) {
|
|
479
|
+
// 如果有默认值,进行初始化
|
|
480
|
+
if (!this.keyDefaultValue) {
|
|
481
|
+
selected = this.$pi.lang.cloneDeep(this.defaultValue)
|
|
482
|
+
} else {
|
|
483
|
+
// 非对象类型构造成对象类型处理
|
|
484
|
+
if (this.isMulti && this.$pi.lang.isArray(this.defaultValue)) {
|
|
485
|
+
selected = this.defaultValue.map(item => ({
|
|
486
|
+
[this.keyField]: item
|
|
487
|
+
}))
|
|
488
|
+
}
|
|
489
|
+
if (!this.isMulti && !this.$pi.lang.isObject(this.defaultValue)) {
|
|
490
|
+
selected = {
|
|
491
|
+
[this.keyField]: this.defaultValue
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
this.selected = selected
|
|
497
|
+
},
|
|
498
|
+
handlePopupClose() {
|
|
499
|
+
this.val = false
|
|
500
|
+
// 关闭弹窗
|
|
501
|
+
this.$emit('close')
|
|
502
|
+
this.handleEmitChange()
|
|
503
|
+
},
|
|
504
|
+
handleSelectItem(item) {
|
|
505
|
+
if (item.disabled) return
|
|
506
|
+
if (!this.isMulti) {
|
|
507
|
+
// 单选
|
|
508
|
+
if (!this.singleCancel) {
|
|
509
|
+
this.selected = item
|
|
510
|
+
if (this.singleConfirm) {
|
|
511
|
+
setTimeout(() => {
|
|
512
|
+
this.handleConfirm()
|
|
513
|
+
}, 300)
|
|
514
|
+
}
|
|
515
|
+
return
|
|
516
|
+
}
|
|
517
|
+
// 如果单选允许取消,需要判断是否点击了同一个选项
|
|
518
|
+
const isSame =
|
|
519
|
+
!this.$pi.lang.isEmpty(this.selected) &&
|
|
520
|
+
this.selected[this.keyField] === item[this.keyField]
|
|
521
|
+
// 如果当前已勾选,比较是否同一个,如果同一个就取消勾选
|
|
522
|
+
this.selected = isSame ? {} : item
|
|
523
|
+
return
|
|
524
|
+
}
|
|
525
|
+
// 多选
|
|
526
|
+
const hasSelected =
|
|
527
|
+
this.selected.findIndex(
|
|
528
|
+
s => s[this.keyField] === item[this.keyField]
|
|
529
|
+
) !== -1
|
|
530
|
+
if (hasSelected) {
|
|
531
|
+
this.selected = this.selected.filter(
|
|
532
|
+
s => s[this.keyField] !== item[this.keyField]
|
|
533
|
+
)
|
|
534
|
+
} else {
|
|
535
|
+
this.selected.push(item)
|
|
536
|
+
}
|
|
537
|
+
},
|
|
538
|
+
/**
|
|
539
|
+
* @vuese
|
|
540
|
+
* 全选或全清选择值
|
|
541
|
+
* @arg selected=true 是否勾选
|
|
542
|
+
* @arg nodes=[] 需要改变的节点,不填默认全部
|
|
543
|
+
*/
|
|
544
|
+
toggleSelect(selected = true, nodes = []) {
|
|
545
|
+
if (!this.isMulti) return
|
|
546
|
+
if (!selected) {
|
|
547
|
+
// 全清
|
|
548
|
+
this.selected = []
|
|
549
|
+
return
|
|
550
|
+
}
|
|
551
|
+
const toggleSelect = this.items.filter(item => {
|
|
552
|
+
let toggleNode = true
|
|
553
|
+
if (nodes.length) {
|
|
554
|
+
toggleNode =
|
|
555
|
+
nodes.findIndex(
|
|
556
|
+
node => node[this.keyField] === item[this.keyField]
|
|
557
|
+
) !== -1
|
|
558
|
+
}
|
|
559
|
+
return toggleNode && !item.disabled
|
|
560
|
+
})
|
|
561
|
+
if (!toggleSelect.length) return
|
|
562
|
+
this.selected = toggleSelect
|
|
563
|
+
},
|
|
564
|
+
/**
|
|
565
|
+
* @vuese
|
|
566
|
+
* 取消选择
|
|
567
|
+
*/
|
|
568
|
+
handleCancel() {
|
|
569
|
+
this.$emit('cancel')
|
|
570
|
+
this.getPopupSelect.onCancelClose && this.handlePopupClose()
|
|
571
|
+
},
|
|
572
|
+
/**
|
|
573
|
+
* @vuese
|
|
574
|
+
* 确认选择
|
|
575
|
+
*/
|
|
576
|
+
handleConfirm() {
|
|
577
|
+
let selected = this.selected
|
|
578
|
+
if (!this.$pi.lang.isEmpty(selected) && this.keyDefaultValue) {
|
|
579
|
+
// 非对象类型返回值,返回值处理成非对象类型
|
|
580
|
+
if (this.$pi.lang.isArray(selected)) {
|
|
581
|
+
selected = selected.map(item => item[this.keyField])
|
|
582
|
+
} else if (this.$pi.lang.isObject(selected)) {
|
|
583
|
+
selected = selected[this.keyField]
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
this.$emit('confirm', selected, this.selected)
|
|
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)
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
</script>
|
|
665
|
+
|
|
666
|
+
<style lang="scss" scoped>
|
|
667
|
+
.pi-select {
|
|
668
|
+
.select-item.disabled {
|
|
669
|
+
opacity: $pi-disabled-opacity;
|
|
670
|
+
}
|
|
671
|
+
.pi-button-wrap {
|
|
672
|
+
flex: 1;
|
|
673
|
+
&:nth-child(2) {
|
|
674
|
+
margin-left: 24rpx;
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
</style>
|