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.
Files changed (160) hide show
  1. package/.prettierrc +7 -7
  2. package/CHANGELOG.md +545 -545
  3. package/LICENSE +20 -20
  4. package/README.md +166 -166
  5. package/components/pi-action-sheet/index.vue +247 -247
  6. package/components/pi-badge/index.vue +146 -146
  7. package/components/pi-bottom-bar/index.vue +139 -139
  8. package/components/pi-bubble/index.vue +174 -174
  9. package/components/pi-button/index.vue +492 -492
  10. package/components/pi-calendar-input/index.vue +230 -230
  11. package/components/pi-calendar-panel/components/calendar-days/index.vue +410 -410
  12. package/components/pi-calendar-panel/index.vue +473 -473
  13. package/components/pi-canvas/index.vue +407 -407
  14. package/components/pi-card/index.vue +127 -127
  15. package/components/pi-cascader/index.vue +601 -601
  16. package/components/pi-checkbox/index.vue +363 -363
  17. package/components/pi-checkbox-group/index.vue +222 -222
  18. package/components/pi-circle-progress/index.vue +311 -311
  19. package/components/pi-code-input/index.vue +270 -270
  20. package/components/pi-collapse/index.vue +124 -124
  21. package/components/pi-collapse-item/index.vue +352 -352
  22. package/components/pi-count-down/index.vue +245 -245
  23. package/components/pi-count-up/index.vue +209 -209
  24. package/components/pi-date-picker-input/index.vue +219 -219
  25. package/components/pi-divider/index.vue +112 -112
  26. package/components/pi-dropdown/components/dropdown-tab.vue +71 -71
  27. package/components/pi-dropdown/index.vue +356 -356
  28. package/components/pi-dropdown-item/index.vue +252 -252
  29. package/components/pi-form/index.vue +273 -273
  30. package/components/pi-form-item/index.vue +603 -590
  31. package/components/pi-gap/index.vue +72 -72
  32. package/components/pi-grid/index.vue +92 -92
  33. package/components/pi-grid-item/index.vue +220 -220
  34. package/components/pi-icon/index.vue +147 -147
  35. package/components/pi-img/index.vue +266 -266
  36. package/components/pi-img-cropper/canvas.js +106 -106
  37. package/components/pi-img-cropper/index.vue +357 -357
  38. package/components/pi-img-cropper/touch.js +163 -163
  39. package/components/pi-img-cropper/vector.js +34 -34
  40. package/components/pi-input/index.vue +409 -401
  41. package/components/pi-line/index.vue +78 -78
  42. package/components/pi-line-progress/index.vue +198 -198
  43. package/components/pi-list/index.vue +115 -115
  44. package/components/pi-list-item/index.vue +335 -335
  45. package/components/pi-loading/index.vue +188 -188
  46. package/components/pi-marquee/index.vue +310 -310
  47. package/components/pi-marquee-item/index.vue +47 -47
  48. package/components/pi-mask/index.vue +198 -198
  49. package/components/pi-modal/index.vue +303 -303
  50. package/components/pi-navbar/index.vue +421 -421
  51. package/components/pi-notify/index.vue +239 -239
  52. package/components/pi-number-keyboard/index.vue +189 -189
  53. package/components/pi-opentype-button/index.vue +501 -501
  54. package/components/pi-pagination/index.vue +290 -290
  55. package/components/pi-picker/index.vue +317 -317
  56. package/components/pi-popup/index.vue +356 -356
  57. package/components/pi-popup-select/index.vue +300 -300
  58. package/components/pi-radio/index.vue +403 -403
  59. package/components/pi-radio-group/index.vue +300 -300
  60. package/components/pi-rate/index.vue +212 -212
  61. package/components/pi-regions-select/index.vue +349 -349
  62. package/components/pi-regions-select-input/index.vue +230 -230
  63. package/components/pi-search/index.vue +386 -386
  64. package/components/pi-section/index.vue +218 -218
  65. package/components/pi-select/index.vue +678 -678
  66. package/components/pi-select-input/index.vue +273 -273
  67. package/components/pi-skeleton/index.vue +280 -280
  68. package/components/pi-status-bar/index.vue +56 -56
  69. package/components/pi-stepper/index.vue +408 -408
  70. package/components/pi-steps/index.vue +378 -378
  71. package/components/pi-subsection/index.vue +403 -403
  72. package/components/pi-swiper/index.vue +344 -344
  73. package/components/pi-switch/index.vue +231 -231
  74. package/components/pi-table/index.vue +351 -351
  75. package/components/pi-tabs/index.vue +435 -435
  76. package/components/pi-tag/index.vue +488 -488
  77. package/components/pi-upload-img/index.vue +980 -980
  78. package/components/pi-waterfall/index.vue +130 -130
  79. package/config/actionSheet.js +24 -24
  80. package/config/badge.js +9 -9
  81. package/config/bottomBar.js +11 -11
  82. package/config/bubble.js +6 -6
  83. package/config/button.js +29 -29
  84. package/config/calendar.js +19 -19
  85. package/config/calendarInput.js +19 -19
  86. package/config/calendarPanel.js +27 -27
  87. package/config/card.js +8 -8
  88. package/config/cascader.js +22 -22
  89. package/config/checkbox.js +15 -15
  90. package/config/checkboxGroup.js +15 -15
  91. package/config/circleProgress.js +20 -20
  92. package/config/codeInput.js +13 -13
  93. package/config/collapse.js +7 -7
  94. package/config/collapseItem.js +11 -11
  95. package/config/countDown.js +12 -12
  96. package/config/countUp.js +13 -13
  97. package/config/datePickerInput.js +18 -18
  98. package/config/divider.js +10 -10
  99. package/config/dropdown.js +25 -25
  100. package/config/dropdownItem.js +26 -26
  101. package/config/form.js +29 -29
  102. package/config/formItem.js +27 -27
  103. package/config/gap.js +8 -8
  104. package/config/grid.js +9 -9
  105. package/config/gridItem.js +12 -12
  106. package/config/icon.js +11 -11
  107. package/config/img.js +21 -21
  108. package/config/imgCropper.js +26 -26
  109. package/config/index.js +28 -28
  110. package/config/input.js +37 -36
  111. package/config/line.js +8 -8
  112. package/config/lineProgress.js +14 -14
  113. package/config/list.js +12 -12
  114. package/config/listItem.js +25 -25
  115. package/config/loading.js +10 -10
  116. package/config/marquee.js +10 -10
  117. package/config/mask.js +12 -12
  118. package/config/modal.js +36 -36
  119. package/config/navbar.js +32 -32
  120. package/config/notify.js +13 -13
  121. package/config/numberKeyboard.js +21 -21
  122. package/config/pagination.js +10 -10
  123. package/config/picker.js +19 -19
  124. package/config/popup.js +23 -23
  125. package/config/popupSelect.js +35 -35
  126. package/config/radio.js +16 -16
  127. package/config/radioGroup.js +17 -17
  128. package/config/rate.js +15 -15
  129. package/config/regionsData.js +58 -58
  130. package/config/regionsSelect.js +19 -19
  131. package/config/regionsSelectInput.js +29 -29
  132. package/config/search.js +27 -27
  133. package/config/section.js +23 -23
  134. package/config/select.js +41 -41
  135. package/config/selectInput.js +29 -29
  136. package/config/skeleton.js +13 -13
  137. package/config/statusBar.js +5 -5
  138. package/config/stepper.js +19 -19
  139. package/config/steps.js +19 -19
  140. package/config/subsection.js +14 -14
  141. package/config/swiper.js +22 -22
  142. package/config/switch.js +13 -13
  143. package/config/table.js +8 -8
  144. package/config/tabs.js +23 -23
  145. package/config/tag.js +21 -21
  146. package/config/uploadImg.js +81 -81
  147. package/config/waterfall.js +6 -6
  148. package/index.js +41 -41
  149. package/mixin/component-custom.js +24 -24
  150. package/mixin/emitter.js +45 -45
  151. package/mixin/props-sync.js +65 -65
  152. package/mixin/value-sync.js +32 -32
  153. package/mixin/wx-code.js +30 -30
  154. package/package.json +28 -28
  155. package/plugins/async-validator.js +1511 -1511
  156. package/scss/animation.scss +260 -260
  157. package/scss/icon/icon.scss +595 -595
  158. package/scss/index.scss +5 -5
  159. package/scss/mixin.scss +47 -47
  160. package/tools/index.js +19 -19
@@ -1,317 +1,317 @@
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
- >
20
- <slot name="header" />
21
- <picker-view
22
- v-if="val"
23
- class="pi-text-center pi-h-100P"
24
- :style="[customStyle]"
25
- :class="[customClass]"
26
- :indicator-style="indicatorStyle"
27
- :value="pickerValue"
28
- @pickstart="handlePickstart"
29
- @pickend="handlePickend"
30
- @change="handlePickerChange"
31
- >
32
- <picker-view-column v-for="(column, index) in columns" :key="index">
33
- <view v-for="item in column" :key="item[keyField]" :style="indicatorStyle">
34
- {{ item[displayField] }}
35
- </view>
36
- </picker-view-column>
37
- </picker-view>
38
- <slot name="footer" />
39
- </pi-popup-select>
40
- </template>
41
-
42
- <script>
43
- import ValueSync from '../../mixin/value-sync'
44
- import { getConfig } from '../../config'
45
-
46
- const TAG = 'PiPicker'
47
- const { picker } = getConfig()
48
-
49
- /**
50
- * 注意: default-value数组的长度,必须与列数相同,否则无效。
51
- * 单列模式 如设置default-value为[1]表示默认选中第2个(从0开始),[5]表示选中第6个。
52
- * 多列模式 如设置default-value为[1, 3]表示第一列默认选中第2个,第二列默认选中第4个。
53
- */
54
- export default {
55
- name: 'PiPicker',
56
- // 混入v-model
57
- mixins: [ValueSync],
58
- props: {
59
- // 初始值
60
- value: {
61
- required: false
62
- },
63
- // 自定义样式
64
- customStyle: {
65
- type: Object,
66
- // {}
67
- default() {
68
- return picker.customStyle
69
- }
70
- },
71
- // 自定义样式类
72
- customClass: {
73
- type: String,
74
- // ''
75
- default() {
76
- return picker.customClass
77
- }
78
- },
79
- // 选项列表
80
- items: {
81
- type: Array,
82
- // []
83
- default() {
84
- return picker.items
85
- }
86
- },
87
- // 选项id字段
88
- keyField: {
89
- type: String,
90
- // 'id'
91
- default: picker.keyField
92
- },
93
- // 选项显示字段
94
- displayField: {
95
- type: String,
96
- // 'text'
97
- default: picker.displayField
98
- },
99
- // 自定义多列联动模式的children属性名
100
- childField: {
101
- type: String,
102
- // 'children'
103
- default: picker.childField
104
- },
105
- // 默认值,单选是传Object,多选时传Array
106
- defaultValue: {
107
- type: Array,
108
- // null
109
- default: picker.defaultValue
110
- },
111
- // 选择器类型
112
- type: {
113
- // 'single', 'multi', 'multi-auto'
114
- type: String,
115
- // 'single'
116
- default: picker.type,
117
- validator: function(value) {
118
- return ['single', 'multi', 'multi-auto'].includes(value)
119
- }
120
- },
121
- // 行高 单位默认rpx
122
- itemHeight: {
123
- type: [String, Number],
124
- // 110
125
- default: picker.itemHeight
126
- },
127
- // 是否显示item下边框
128
- showItemBottomBorder: {
129
- type: Boolean,
130
- // true
131
- default: picker.showItemBottomBorder
132
- },
133
- // 行样式
134
- itemStyle: {
135
- type: Object,
136
- // {}
137
- default() {
138
- return picker.itemStyle
139
- }
140
- },
141
- // 弹窗选择参数设置
142
- popupSelect: {
143
- type: Object,
144
- default() {
145
- // 参照popup
146
- return picker.popupSelect
147
- }
148
- },
149
- // 确认按钮配置
150
- confirmBtn: {
151
- type: Object,
152
- default() {
153
- return picker.confirmBtn
154
- }
155
- },
156
- // 取消按钮配置
157
- cancelBtn: {
158
- type: Object,
159
- default() {
160
- return picker.cancelBtn
161
- }
162
- },
163
- // 弹窗参数设置
164
- popup: {
165
- type: Object,
166
- default() {
167
- // 参照popup
168
- return picker.popup
169
- }
170
- }
171
- },
172
- data() {
173
- return {
174
- pickerValue: [],
175
- scrolling: false // picker是否在滚动中,小程序在scrolling中点确定,选择的项目不正确
176
- }
177
- },
178
- computed: {
179
- getPopupSelect() {
180
- return this.$pi.lang.mergeDeep(picker.popupSelect, this.popupSelect)
181
- },
182
- getConfirmBtn() {
183
- const pickerConfirmBtn = this.$pi.lang.mergeDeep(
184
- picker.confirmBtn,
185
- this.popupSelect.confirmBtn
186
- )
187
- const mergeConfirmBtn = this.$pi.lang.mergeDeep(pickerConfirmBtn, this.confirmBtn)
188
- if (!mergeConfirmBtn.disabled) {
189
- mergeConfirmBtn.disabled = this.scrolling
190
- }
191
- return mergeConfirmBtn
192
- },
193
- getCancelBtn() {
194
- const pickerCancelBtn = this.$pi.lang.mergeDeep(picker.cancelBtn, this.popupSelect.cancelBtn)
195
- return this.$pi.lang.mergeDeep(pickerCancelBtn, this.cancelBtn)
196
- },
197
- getPopup() {
198
- const pickerPopup = this.$pi.lang.mergeDeep(picker.popup, this.popupSelect.popup)
199
- return this.$pi.lang.mergeDeep(pickerPopup, this.popup)
200
- },
201
- getItemStyle() {
202
- const itemHeight = this.$pi.common.addUnit(this.itemHeight)
203
- return {
204
- height: itemHeight,
205
- lineHeight: itemHeight
206
- }
207
- },
208
- indicatorStyle() {
209
- const itemHeight = uni.upx2px(this.itemHeight)
210
- return `height: ${itemHeight}px;line-height: ${itemHeight}px;`
211
- },
212
- columns() {
213
- if (this.type === 'single') return [this.items]
214
- if (this.type === 'multi') return this.items
215
- if (this.type === 'multi-auto') {
216
- let columns = this.items
217
- return this.pickerValue.map((value, index) => {
218
- const returnValue = [...columns]
219
- const column = columns[value]
220
- if (column[this.childField] && column[this.childField].length) {
221
- columns = column[this.childField]
222
- }
223
- return returnValue
224
- })
225
- }
226
-
227
- return this.items
228
- }
229
- },
230
- watch: {
231
- value: {
232
- deep: true,
233
- immediate: true,
234
- handler(value) {
235
- // 每次弹窗显示,进行数据初始化
236
- value && this.init()
237
- }
238
- }
239
- },
240
- methods: {
241
- init() {
242
- if (this.defaultValue) {
243
- this.pickerValue = this.defaultValue
244
- } else {
245
- if (this.type === 'single') this.pickerValue = [0]
246
- if (this.type === 'multi') return (this.pickerValue = [0, 0])
247
- if (this.type === 'multi-auto') {
248
- let count = 1
249
- let column = this.items
250
- // 只要有元素并且第一个元素有children属性,继续历遍
251
- while (column[0][this.childField]) {
252
- column = column[0] ? column[0][this.childField] : {}
253
- count++
254
- }
255
- this.pickerValue = new Array(count).fill(0)
256
- }
257
- }
258
- },
259
- handlePickstart() {
260
- this.scrolling = true
261
- },
262
- // 标识滑动结束
263
- handlePickend() {
264
- this.scrolling = false
265
- },
266
- handlePopupClose() {
267
- this.val = false
268
- // 弹窗关闭
269
- this.$emit('close')
270
- this.handleEmitChange()
271
- },
272
- handlePickerChange(e) {
273
- let pickerValue = e.detail.value
274
-
275
- if (this.type === 'multi-auto') {
276
- // 如果是多列联动,pickerValue的值需要重新生成
277
- // 第几列发生变化
278
- let columnIndex = this.pickerValue.findIndex((p, i) => pickerValue[i] !== p)
279
- pickerValue = pickerValue.slice(0, columnIndex + 1)
280
- let columnValue = pickerValue[columnIndex]
281
- let columns = this.columns[columnIndex]
282
- let column = columns[columnValue]
283
- while (column[this.childField]) {
284
- columns = column[this.childField]
285
- column = columns[0]
286
- columnIndex++
287
- pickerValue[columnIndex] = 0
288
- }
289
- }
290
- this.pickerValue = pickerValue
291
- },
292
- /**
293
- * @vuese
294
- * 取消选择
295
- */
296
- handleCancel() {
297
- this.$emit('cancel')
298
- this.onCancelClose && this.handlePopupClose()
299
- },
300
- /**
301
- * @vuese
302
- * 确认选择
303
- */
304
- handleConfirm() {
305
- if (this.scrolling) return
306
- this.$emit('confirm', this.pickerValue)
307
- this.onConfirmClose && this.handlePopupClose()
308
- }
309
- }
310
- }
311
- </script>
312
-
313
- <style lang="scss" scoped>
314
- .pi-picker {
315
- height: 50vh;
316
- }
317
- </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
+ >
20
+ <slot name="header" />
21
+ <picker-view
22
+ v-if="val"
23
+ class="pi-text-center pi-h-100P"
24
+ :style="[customStyle]"
25
+ :class="[customClass]"
26
+ :indicator-style="indicatorStyle"
27
+ :value="pickerValue"
28
+ @pickstart="handlePickstart"
29
+ @pickend="handlePickend"
30
+ @change="handlePickerChange"
31
+ >
32
+ <picker-view-column v-for="(column, index) in columns" :key="index">
33
+ <view v-for="item in column" :key="item[keyField]" :style="indicatorStyle">
34
+ {{ item[displayField] }}
35
+ </view>
36
+ </picker-view-column>
37
+ </picker-view>
38
+ <slot name="footer" />
39
+ </pi-popup-select>
40
+ </template>
41
+
42
+ <script>
43
+ import ValueSync from '../../mixin/value-sync'
44
+ import { getConfig } from '../../config'
45
+
46
+ const TAG = 'PiPicker'
47
+ const { picker } = getConfig()
48
+
49
+ /**
50
+ * 注意: default-value数组的长度,必须与列数相同,否则无效。
51
+ * 单列模式 如设置default-value为[1]表示默认选中第2个(从0开始),[5]表示选中第6个。
52
+ * 多列模式 如设置default-value为[1, 3]表示第一列默认选中第2个,第二列默认选中第4个。
53
+ */
54
+ export default {
55
+ name: 'PiPicker',
56
+ // 混入v-model
57
+ mixins: [ValueSync],
58
+ props: {
59
+ // 初始值
60
+ value: {
61
+ required: false
62
+ },
63
+ // 自定义样式
64
+ customStyle: {
65
+ type: Object,
66
+ // {}
67
+ default() {
68
+ return picker.customStyle
69
+ }
70
+ },
71
+ // 自定义样式类
72
+ customClass: {
73
+ type: String,
74
+ // ''
75
+ default() {
76
+ return picker.customClass
77
+ }
78
+ },
79
+ // 选项列表
80
+ items: {
81
+ type: Array,
82
+ // []
83
+ default() {
84
+ return picker.items
85
+ }
86
+ },
87
+ // 选项id字段
88
+ keyField: {
89
+ type: String,
90
+ // 'id'
91
+ default: picker.keyField
92
+ },
93
+ // 选项显示字段
94
+ displayField: {
95
+ type: String,
96
+ // 'text'
97
+ default: picker.displayField
98
+ },
99
+ // 自定义多列联动模式的children属性名
100
+ childField: {
101
+ type: String,
102
+ // 'children'
103
+ default: picker.childField
104
+ },
105
+ // 默认值,单选是传Object,多选时传Array
106
+ defaultValue: {
107
+ type: Array,
108
+ // null
109
+ default: picker.defaultValue
110
+ },
111
+ // 选择器类型
112
+ type: {
113
+ // 'single', 'multi', 'multi-auto'
114
+ type: String,
115
+ // 'single'
116
+ default: picker.type,
117
+ validator: function(value) {
118
+ return ['single', 'multi', 'multi-auto'].includes(value)
119
+ }
120
+ },
121
+ // 行高 单位默认rpx
122
+ itemHeight: {
123
+ type: [String, Number],
124
+ // 110
125
+ default: picker.itemHeight
126
+ },
127
+ // 是否显示item下边框
128
+ showItemBottomBorder: {
129
+ type: Boolean,
130
+ // true
131
+ default: picker.showItemBottomBorder
132
+ },
133
+ // 行样式
134
+ itemStyle: {
135
+ type: Object,
136
+ // {}
137
+ default() {
138
+ return picker.itemStyle
139
+ }
140
+ },
141
+ // 弹窗选择参数设置
142
+ popupSelect: {
143
+ type: Object,
144
+ default() {
145
+ // 参照popup
146
+ return picker.popupSelect
147
+ }
148
+ },
149
+ // 确认按钮配置
150
+ confirmBtn: {
151
+ type: Object,
152
+ default() {
153
+ return picker.confirmBtn
154
+ }
155
+ },
156
+ // 取消按钮配置
157
+ cancelBtn: {
158
+ type: Object,
159
+ default() {
160
+ return picker.cancelBtn
161
+ }
162
+ },
163
+ // 弹窗参数设置
164
+ popup: {
165
+ type: Object,
166
+ default() {
167
+ // 参照popup
168
+ return picker.popup
169
+ }
170
+ }
171
+ },
172
+ data() {
173
+ return {
174
+ pickerValue: [],
175
+ scrolling: false // picker是否在滚动中,小程序在scrolling中点确定,选择的项目不正确
176
+ }
177
+ },
178
+ computed: {
179
+ getPopupSelect() {
180
+ return this.$pi.lang.mergeDeep(picker.popupSelect, this.popupSelect)
181
+ },
182
+ getConfirmBtn() {
183
+ const pickerConfirmBtn = this.$pi.lang.mergeDeep(
184
+ picker.confirmBtn,
185
+ this.popupSelect.confirmBtn
186
+ )
187
+ const mergeConfirmBtn = this.$pi.lang.mergeDeep(pickerConfirmBtn, this.confirmBtn)
188
+ if (!mergeConfirmBtn.disabled) {
189
+ mergeConfirmBtn.disabled = this.scrolling
190
+ }
191
+ return mergeConfirmBtn
192
+ },
193
+ getCancelBtn() {
194
+ const pickerCancelBtn = this.$pi.lang.mergeDeep(picker.cancelBtn, this.popupSelect.cancelBtn)
195
+ return this.$pi.lang.mergeDeep(pickerCancelBtn, this.cancelBtn)
196
+ },
197
+ getPopup() {
198
+ const pickerPopup = this.$pi.lang.mergeDeep(picker.popup, this.popupSelect.popup)
199
+ return this.$pi.lang.mergeDeep(pickerPopup, this.popup)
200
+ },
201
+ getItemStyle() {
202
+ const itemHeight = this.$pi.common.addUnit(this.itemHeight)
203
+ return {
204
+ height: itemHeight,
205
+ lineHeight: itemHeight
206
+ }
207
+ },
208
+ indicatorStyle() {
209
+ const itemHeight = uni.upx2px(this.itemHeight)
210
+ return `height: ${itemHeight}px;line-height: ${itemHeight}px;`
211
+ },
212
+ columns() {
213
+ if (this.type === 'single') return [this.items]
214
+ if (this.type === 'multi') return this.items
215
+ if (this.type === 'multi-auto') {
216
+ let columns = this.items
217
+ return this.pickerValue.map((value, index) => {
218
+ const returnValue = [...columns]
219
+ const column = columns[value]
220
+ if (column[this.childField] && column[this.childField].length) {
221
+ columns = column[this.childField]
222
+ }
223
+ return returnValue
224
+ })
225
+ }
226
+
227
+ return this.items
228
+ }
229
+ },
230
+ watch: {
231
+ value: {
232
+ deep: true,
233
+ immediate: true,
234
+ handler(value) {
235
+ // 每次弹窗显示,进行数据初始化
236
+ value && this.init()
237
+ }
238
+ }
239
+ },
240
+ methods: {
241
+ init() {
242
+ if (this.defaultValue) {
243
+ this.pickerValue = this.defaultValue
244
+ } else {
245
+ if (this.type === 'single') this.pickerValue = [0]
246
+ if (this.type === 'multi') return (this.pickerValue = [0, 0])
247
+ if (this.type === 'multi-auto') {
248
+ let count = 1
249
+ let column = this.items
250
+ // 只要有元素并且第一个元素有children属性,继续历遍
251
+ while (column[0][this.childField]) {
252
+ column = column[0] ? column[0][this.childField] : {}
253
+ count++
254
+ }
255
+ this.pickerValue = new Array(count).fill(0)
256
+ }
257
+ }
258
+ },
259
+ handlePickstart() {
260
+ this.scrolling = true
261
+ },
262
+ // 标识滑动结束
263
+ handlePickend() {
264
+ this.scrolling = false
265
+ },
266
+ handlePopupClose() {
267
+ this.val = false
268
+ // 弹窗关闭
269
+ this.$emit('close')
270
+ this.handleEmitChange()
271
+ },
272
+ handlePickerChange(e) {
273
+ let pickerValue = e.detail.value
274
+
275
+ if (this.type === 'multi-auto') {
276
+ // 如果是多列联动,pickerValue的值需要重新生成
277
+ // 第几列发生变化
278
+ let columnIndex = this.pickerValue.findIndex((p, i) => pickerValue[i] !== p)
279
+ pickerValue = pickerValue.slice(0, columnIndex + 1)
280
+ let columnValue = pickerValue[columnIndex]
281
+ let columns = this.columns[columnIndex]
282
+ let column = columns[columnValue]
283
+ while (column[this.childField]) {
284
+ columns = column[this.childField]
285
+ column = columns[0]
286
+ columnIndex++
287
+ pickerValue[columnIndex] = 0
288
+ }
289
+ }
290
+ this.pickerValue = pickerValue
291
+ },
292
+ /**
293
+ * @vuese
294
+ * 取消选择
295
+ */
296
+ handleCancel() {
297
+ this.$emit('cancel')
298
+ this.onCancelClose && this.handlePopupClose()
299
+ },
300
+ /**
301
+ * @vuese
302
+ * 确认选择
303
+ */
304
+ handleConfirm() {
305
+ if (this.scrolling) return
306
+ this.$emit('confirm', this.pickerValue)
307
+ this.onConfirmClose && this.handlePopupClose()
308
+ }
309
+ }
310
+ }
311
+ </script>
312
+
313
+ <style lang="scss" scoped>
314
+ .pi-picker {
315
+ height: 50vh;
316
+ }
317
+ </style>