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,356 +1,356 @@
1
- <template>
2
- <view class="pi-dropdown pi-rela pi-w-100P" :class="[customClass]" :style="[customStyle]">
3
- <view>
4
- <pi-tabs
5
- :value="activeItem"
6
- :items="tabs"
7
- :show-slider-bar="false"
8
- show-item-split-line
9
- :stretch="stretch"
10
- :height="tabHeight"
11
- active-text-color="inherit"
12
- >
13
- <!-- 注意:slot内不能使用父组件data -->
14
- <dropdown-tab
15
- slot="item"
16
- slot-scope="{ item, index }"
17
- :item="item"
18
- class="pi-w-100P pi-h-100P"
19
- @click="handleClickTab(item, index)"
20
- />
21
- </pi-tabs>
22
- </view>
23
- <!-- 展示dropdownItem下的数据 -->
24
- <view
25
- class="pi-dropdown-content"
26
- :class="[contentClass]"
27
- :style="[contentStyle, contentCombinationStyle]"
28
- >
29
- <slot />
30
- </view>
31
-
32
- <!-- 遮罩层 -->
33
- <view
34
- v-if="!closed"
35
- class="pi-fixed pi-dropdown-mask"
36
- :class="[show ? getMask.animationShow : getMask.animationHide]"
37
- :style="[
38
- {
39
- 'z-index': getMask.zIndex,
40
- 'top': maskAlignTop ? containerRect.top + containerRect.height + 'px' : '-9999px',
41
- 'background': getMask.background,
42
- 'animation-duration': getDuration.css
43
- }
44
- ]"
45
- @touchmove.stop.prevent="() => {}"
46
- @tap.stop.prevent="closeMask"
47
- />
48
- </view>
49
- </template>
50
-
51
- <script>
52
- import ValueSync from '../../mixin/value-sync'
53
- import { parentInit } from '../../mixin/props-sync'
54
- import { getConfig } from '../../config'
55
- import { parseDuration } from '@sadais/piui-tool/tools/common'
56
- import DropdownTab from './components/dropdown-tab.vue'
57
-
58
- const TAG = 'PiDropdown'
59
- const { dropdown } = getConfig()
60
-
61
- export default {
62
- name: 'PiDropdown',
63
- components: {
64
- DropdownTab
65
- },
66
- mixins: [
67
- ValueSync,
68
- parentInit([
69
- 'itemHeight',
70
- 'keyField',
71
- 'displayField',
72
- 'disabledField',
73
- 'selectedImg',
74
- 'selectedCheckbox'
75
- ])
76
- ], // 注入value与val,进行双向绑定
77
- props: {
78
- // 初始值
79
- value: {
80
- required: false,
81
- default() {
82
- return []
83
- }
84
- },
85
- // 自定义样式,对象形式
86
- customStyle: {
87
- type: Object,
88
- default() {
89
- // {}
90
- return dropdown.customStyle
91
- }
92
- },
93
- // 自定义样式类,字符串形式
94
- customClass: {
95
- type: String,
96
- default() {
97
- // ''
98
- return dropdown.customClass
99
- }
100
- },
101
- // 自定义样式,对象形式
102
- contentStyle: {
103
- type: Object,
104
- default() {
105
- // {}
106
- return dropdown.contentStyle
107
- }
108
- },
109
- // 自定义样式类,字符串形式
110
- contentClass: {
111
- type: String,
112
- default() {
113
- // ''
114
- return dropdown.contentClass
115
- }
116
- },
117
- // 蒙层参数设置
118
- mask: {
119
- type: Object,
120
- default() {
121
- // 参照mask
122
- return dropdown.mask
123
- }
124
- },
125
- // 默认选中色
126
- activeColor: {
127
- type: String,
128
- default() {
129
- // ''
130
- return dropdown.activeColor
131
- }
132
- },
133
- // 标签是否均分布局,可选值 `true`
134
- stretch: {
135
- type: Boolean,
136
- // `false`
137
- default() {
138
- return dropdown.stretch
139
- }
140
- },
141
- // 标签的高度,单位rpx
142
- tabHeight: {
143
- type: [String, Number],
144
- // `80`
145
- default() {
146
- return dropdown.tabHeight
147
- }
148
- },
149
- // -------------以下属性为子组件pi-dropdown-item继承用--------------
150
- // 行高 值为数字,则单位默认rpx
151
- itemHeight: {
152
- type: [String, Number],
153
- // 110
154
- default: dropdown.itemHeight
155
- },
156
- // 选项id字段
157
- keyField: {
158
- type: String,
159
- // `id`
160
- default: dropdown.keyField
161
- },
162
- // 选项显示字段
163
- displayField: {
164
- type: String,
165
- // `text`
166
- default: dropdown.displayField
167
- },
168
- // 选项禁用字段,默认为disabled
169
- disabledField: {
170
- type: String,
171
- // `text`
172
- default: dropdown.disabledField
173
- },
174
- // 选中图标的配置
175
- selectedImg: {
176
- type: Object,
177
- default() {
178
- // 参照img
179
- return dropdown.selectedImg
180
- }
181
- },
182
- // 选中checkbox配置
183
- selectedCheckbox: {
184
- type: [Object, String],
185
- default() {
186
- // 参照checkbox
187
- return dropdown.selectedCheckbox
188
- }
189
- },
190
- // 是否需要蒙层顶部对齐组件,可选值 `false`
191
- maskAlignTop: {
192
- type: Boolean,
193
- // `true`
194
- default() {
195
- return dropdown.maskAlignTop
196
- }
197
- },
198
- disabled: {
199
- type: Boolean,
200
- default: dropdown.disabled
201
- }
202
- },
203
- data() {
204
- return {
205
- containerRect: { left: 0, right: 0, top: 0 }, // 容器的位置
206
-
207
- tabs: [], // 下拉菜单
208
- activeItem: {}, // 当前选中项
209
-
210
- show: false, // 是否显示节点
211
- showed: false, // 是否显示动画执行完毕
212
- closed: true, // 是否已关闭(用来防止val为false的情况,动画无法执行)
213
- submiting: false // 正在更新值(防止快速切换提交)
214
- }
215
- },
216
- computed: {
217
- contentCombinationStyle() {
218
- const { containerRect, closed } = this
219
- return {
220
- top: `${containerRect.height}px`,
221
- left: `-${containerRect.left}px`,
222
- width: `${this.$pi.system.systemInfo.windowWidth}px`,
223
- zIndex: !closed ? 101 : -1
224
- }
225
- },
226
- getMask() {
227
- return this.$pi.lang.mergeDeep(dropdown.mask, this.mask)
228
- },
229
- getDuration() {
230
- return parseDuration(this.getMask.duration, dropdown.mask.duration)
231
- }
232
- },
233
- watch: {
234
- // 界面根据值的变化而变化
235
- value: {
236
- immediate: false,
237
- handler(val) {
238
- this.init()
239
- }
240
- }
241
- },
242
- mounted() {
243
- this.init()
244
- },
245
- methods: {
246
- init() {
247
- console.log(TAG, 'init')
248
- let hasValueChange = false
249
- const val = this.$pi.lang.cloneDeep(this.val)
250
- this.tabs = this._children.map((item, index) => {
251
- if (this.val[index] === undefined) {
252
- this.val[index] = ''
253
- }
254
- // 同步父子组件的值
255
- if (this.val[index] !== item.val) {
256
- console.log(TAG, 'Dropdown和DropdownItem绑定值不一致,即将同步')
257
- item.emitChange(this.val[index])
258
- }
259
- const currentOption = item.options?.find(
260
- opt => !opt.clearable && opt[item.getKeyField] === this.val[index]
261
- )
262
- const newItem = {
263
- showIcon: item.showIcon,
264
- iconOption: item.getIconOption,
265
- id: item._uid,
266
- text: currentOption ? currentOption[item.getDisplayField] : item.title,
267
- disabled: item.disabled,
268
- opened: false,
269
- activeColor: this.activeColor
270
- }
271
- return newItem
272
- })
273
- if (hasValueChange) {
274
- this.val = val
275
- this.handleEmitChange()
276
- }
277
- },
278
- // 显示当前Tab
279
- async handleClickTab(item) {
280
- if (this.disabled || item.disabled) return
281
- if (this.submiting) return console.log(TAG, '你点得太快了')
282
- if (this.show && item.id === this.activeItem.id) {
283
- this.closeMask()
284
- return
285
- }
286
- // 更新打开的tab标志
287
- this.tabs = this.tabs.map(tab => {
288
- tab.opened = tab.id === item.id
289
- return tab
290
- })
291
- this.activeItem = item
292
- // 每次点击都重新更新父容器的位置
293
- this.containerRect = await this.$pi.common.queryRect(this, '.pi-dropdown', false)
294
- this.openMask()
295
- this._children.forEach(child => {
296
- child.show = child._uid === item.id
297
- })
298
- },
299
- openMask() {
300
- if (this.show) return
301
- console.log(TAG, '显示下拉菜单遮罩层')
302
- this.closed = false
303
- this.show = true
304
- this.showed = false
305
- this.getMask.hideTabBar && uni.hideTabBar()
306
- setTimeout(() => {
307
- this.showed = true
308
- }, this.getDuration.js)
309
- },
310
- // 仅关闭窗口,不作数据操作
311
- closeMask() {
312
- if (!this.show || !this.showed) return
313
- console.log(TAG, '隐藏下拉菜单遮罩层')
314
- this._children.forEach(child => {
315
- child.show = false
316
- })
317
- this.show = false
318
- this.showed = false
319
- this.tabs = this.tabs.map(tab => {
320
- tab.opened = false
321
- return tab
322
- })
323
- setTimeout(() => {
324
- this.closed = true
325
- this.submiting = false
326
- this.getMask.hideTabBar && uni.showTabBar()
327
- }, this.getDuration.js)
328
- },
329
- // 关闭弹窗并返回结果
330
- submit() {
331
- this.submiting = true
332
- this.closeMask()
333
- setTimeout(() => {
334
- // 延迟执行,防止父子组件的值同步不上
335
- const submitVal = this._children.map(item => item.val)
336
- this.val = submitVal // 把最终结果传给绑定的v-model值
337
- this.handleEmitChange()
338
- }, 20)
339
- }
340
- }
341
- }
342
- </script>
343
-
344
- <style lang="scss" scoped>
345
- .pi-dropdown {
346
- .pi-dropdown-content {
347
- position: absolute;
348
- background: #ffffff;
349
- }
350
- .pi-dropdown-mask {
351
- left: -9999px;
352
- right: -9999px;
353
- bottom: -9999px;
354
- }
355
- }
356
- </style>
1
+ <template>
2
+ <view class="pi-dropdown pi-rela pi-w-100P" :class="[customClass]" :style="[customStyle]">
3
+ <view>
4
+ <pi-tabs
5
+ :value="activeItem"
6
+ :items="tabs"
7
+ :show-slider-bar="false"
8
+ show-item-split-line
9
+ :stretch="stretch"
10
+ :height="tabHeight"
11
+ active-text-color="inherit"
12
+ >
13
+ <!-- 注意:slot内不能使用父组件data -->
14
+ <dropdown-tab
15
+ slot="item"
16
+ slot-scope="{ item, index }"
17
+ :item="item"
18
+ class="pi-w-100P pi-h-100P"
19
+ @click="handleClickTab(item, index)"
20
+ />
21
+ </pi-tabs>
22
+ </view>
23
+ <!-- 展示dropdownItem下的数据 -->
24
+ <view
25
+ class="pi-dropdown-content"
26
+ :class="[contentClass]"
27
+ :style="[contentStyle, contentCombinationStyle]"
28
+ >
29
+ <slot />
30
+ </view>
31
+
32
+ <!-- 遮罩层 -->
33
+ <view
34
+ v-if="!closed"
35
+ class="pi-fixed pi-dropdown-mask"
36
+ :class="[show ? getMask.animationShow : getMask.animationHide]"
37
+ :style="[
38
+ {
39
+ 'z-index': getMask.zIndex,
40
+ 'top': maskAlignTop ? containerRect.top + containerRect.height + 'px' : '-9999px',
41
+ 'background': getMask.background,
42
+ 'animation-duration': getDuration.css
43
+ }
44
+ ]"
45
+ @touchmove.stop.prevent="() => {}"
46
+ @tap.stop.prevent="closeMask"
47
+ />
48
+ </view>
49
+ </template>
50
+
51
+ <script>
52
+ import ValueSync from '../../mixin/value-sync'
53
+ import { parentInit } from '../../mixin/props-sync'
54
+ import { getConfig } from '../../config'
55
+ import { parseDuration } from '@sadais/piui-tool/tools/common'
56
+ import DropdownTab from './components/dropdown-tab.vue'
57
+
58
+ const TAG = 'PiDropdown'
59
+ const { dropdown } = getConfig()
60
+
61
+ export default {
62
+ name: 'PiDropdown',
63
+ components: {
64
+ DropdownTab
65
+ },
66
+ mixins: [
67
+ ValueSync,
68
+ parentInit([
69
+ 'itemHeight',
70
+ 'keyField',
71
+ 'displayField',
72
+ 'disabledField',
73
+ 'selectedImg',
74
+ 'selectedCheckbox'
75
+ ])
76
+ ], // 注入value与val,进行双向绑定
77
+ props: {
78
+ // 初始值
79
+ value: {
80
+ required: false,
81
+ default() {
82
+ return []
83
+ }
84
+ },
85
+ // 自定义样式,对象形式
86
+ customStyle: {
87
+ type: Object,
88
+ default() {
89
+ // {}
90
+ return dropdown.customStyle
91
+ }
92
+ },
93
+ // 自定义样式类,字符串形式
94
+ customClass: {
95
+ type: String,
96
+ default() {
97
+ // ''
98
+ return dropdown.customClass
99
+ }
100
+ },
101
+ // 自定义样式,对象形式
102
+ contentStyle: {
103
+ type: Object,
104
+ default() {
105
+ // {}
106
+ return dropdown.contentStyle
107
+ }
108
+ },
109
+ // 自定义样式类,字符串形式
110
+ contentClass: {
111
+ type: String,
112
+ default() {
113
+ // ''
114
+ return dropdown.contentClass
115
+ }
116
+ },
117
+ // 蒙层参数设置
118
+ mask: {
119
+ type: Object,
120
+ default() {
121
+ // 参照mask
122
+ return dropdown.mask
123
+ }
124
+ },
125
+ // 默认选中色
126
+ activeColor: {
127
+ type: String,
128
+ default() {
129
+ // ''
130
+ return dropdown.activeColor
131
+ }
132
+ },
133
+ // 标签是否均分布局,可选值 `true`
134
+ stretch: {
135
+ type: Boolean,
136
+ // `false`
137
+ default() {
138
+ return dropdown.stretch
139
+ }
140
+ },
141
+ // 标签的高度,单位rpx
142
+ tabHeight: {
143
+ type: [String, Number],
144
+ // `80`
145
+ default() {
146
+ return dropdown.tabHeight
147
+ }
148
+ },
149
+ // -------------以下属性为子组件pi-dropdown-item继承用--------------
150
+ // 行高 值为数字,则单位默认rpx
151
+ itemHeight: {
152
+ type: [String, Number],
153
+ // 110
154
+ default: dropdown.itemHeight
155
+ },
156
+ // 选项id字段
157
+ keyField: {
158
+ type: String,
159
+ // `id`
160
+ default: dropdown.keyField
161
+ },
162
+ // 选项显示字段
163
+ displayField: {
164
+ type: String,
165
+ // `text`
166
+ default: dropdown.displayField
167
+ },
168
+ // 选项禁用字段,默认为disabled
169
+ disabledField: {
170
+ type: String,
171
+ // `text`
172
+ default: dropdown.disabledField
173
+ },
174
+ // 选中图标的配置
175
+ selectedImg: {
176
+ type: Object,
177
+ default() {
178
+ // 参照img
179
+ return dropdown.selectedImg
180
+ }
181
+ },
182
+ // 选中checkbox配置
183
+ selectedCheckbox: {
184
+ type: [Object, String],
185
+ default() {
186
+ // 参照checkbox
187
+ return dropdown.selectedCheckbox
188
+ }
189
+ },
190
+ // 是否需要蒙层顶部对齐组件,可选值 `false`
191
+ maskAlignTop: {
192
+ type: Boolean,
193
+ // `true`
194
+ default() {
195
+ return dropdown.maskAlignTop
196
+ }
197
+ },
198
+ disabled: {
199
+ type: Boolean,
200
+ default: dropdown.disabled
201
+ }
202
+ },
203
+ data() {
204
+ return {
205
+ containerRect: { left: 0, right: 0, top: 0 }, // 容器的位置
206
+
207
+ tabs: [], // 下拉菜单
208
+ activeItem: {}, // 当前选中项
209
+
210
+ show: false, // 是否显示节点
211
+ showed: false, // 是否显示动画执行完毕
212
+ closed: true, // 是否已关闭(用来防止val为false的情况,动画无法执行)
213
+ submiting: false // 正在更新值(防止快速切换提交)
214
+ }
215
+ },
216
+ computed: {
217
+ contentCombinationStyle() {
218
+ const { containerRect, closed } = this
219
+ return {
220
+ top: `${containerRect.height}px`,
221
+ left: `-${containerRect.left}px`,
222
+ width: `${this.$pi.system.systemInfo.windowWidth}px`,
223
+ zIndex: !closed ? 101 : -1
224
+ }
225
+ },
226
+ getMask() {
227
+ return this.$pi.lang.mergeDeep(dropdown.mask, this.mask)
228
+ },
229
+ getDuration() {
230
+ return parseDuration(this.getMask.duration, dropdown.mask.duration)
231
+ }
232
+ },
233
+ watch: {
234
+ // 界面根据值的变化而变化
235
+ value: {
236
+ immediate: false,
237
+ handler(val) {
238
+ this.init()
239
+ }
240
+ }
241
+ },
242
+ mounted() {
243
+ this.init()
244
+ },
245
+ methods: {
246
+ init() {
247
+ console.log(TAG, 'init')
248
+ let hasValueChange = false
249
+ const val = this.$pi.lang.cloneDeep(this.val)
250
+ this.tabs = this._children.map((item, index) => {
251
+ if (this.val[index] === undefined) {
252
+ this.val[index] = ''
253
+ }
254
+ // 同步父子组件的值
255
+ if (this.val[index] !== item.val) {
256
+ console.log(TAG, 'Dropdown和DropdownItem绑定值不一致,即将同步')
257
+ item.emitChange(this.val[index])
258
+ }
259
+ const currentOption = item.options?.find(
260
+ opt => !opt.clearable && opt[item.getKeyField] === this.val[index]
261
+ )
262
+ const newItem = {
263
+ showIcon: item.showIcon,
264
+ iconOption: item.getIconOption,
265
+ id: item._uid,
266
+ text: currentOption ? currentOption[item.getDisplayField] : item.title,
267
+ disabled: item.disabled,
268
+ opened: false,
269
+ activeColor: this.activeColor
270
+ }
271
+ return newItem
272
+ })
273
+ if (hasValueChange) {
274
+ this.val = val
275
+ this.handleEmitChange()
276
+ }
277
+ },
278
+ // 显示当前Tab
279
+ async handleClickTab(item) {
280
+ if (this.disabled || item.disabled) return
281
+ if (this.submiting) return console.log(TAG, '你点得太快了')
282
+ if (this.show && item.id === this.activeItem.id) {
283
+ this.closeMask()
284
+ return
285
+ }
286
+ // 更新打开的tab标志
287
+ this.tabs = this.tabs.map(tab => {
288
+ tab.opened = tab.id === item.id
289
+ return tab
290
+ })
291
+ this.activeItem = item
292
+ // 每次点击都重新更新父容器的位置
293
+ this.containerRect = await this.$pi.common.queryRect(this, '.pi-dropdown', false)
294
+ this.openMask()
295
+ this._children.forEach(child => {
296
+ child.show = child._uid === item.id
297
+ })
298
+ },
299
+ openMask() {
300
+ if (this.show) return
301
+ console.log(TAG, '显示下拉菜单遮罩层')
302
+ this.closed = false
303
+ this.show = true
304
+ this.showed = false
305
+ this.getMask.hideTabBar && uni.hideTabBar()
306
+ setTimeout(() => {
307
+ this.showed = true
308
+ }, this.getDuration.js)
309
+ },
310
+ // 仅关闭窗口,不作数据操作
311
+ closeMask() {
312
+ if (!this.show || !this.showed) return
313
+ console.log(TAG, '隐藏下拉菜单遮罩层')
314
+ this._children.forEach(child => {
315
+ child.show = false
316
+ })
317
+ this.show = false
318
+ this.showed = false
319
+ this.tabs = this.tabs.map(tab => {
320
+ tab.opened = false
321
+ return tab
322
+ })
323
+ setTimeout(() => {
324
+ this.closed = true
325
+ this.submiting = false
326
+ this.getMask.hideTabBar && uni.showTabBar()
327
+ }, this.getDuration.js)
328
+ },
329
+ // 关闭弹窗并返回结果
330
+ submit() {
331
+ this.submiting = true
332
+ this.closeMask()
333
+ setTimeout(() => {
334
+ // 延迟执行,防止父子组件的值同步不上
335
+ const submitVal = this._children.map(item => item.val)
336
+ this.val = submitVal // 把最终结果传给绑定的v-model值
337
+ this.handleEmitChange()
338
+ }, 20)
339
+ }
340
+ }
341
+ }
342
+ </script>
343
+
344
+ <style lang="scss" scoped>
345
+ .pi-dropdown {
346
+ .pi-dropdown-content {
347
+ position: absolute;
348
+ background: #ffffff;
349
+ }
350
+ .pi-dropdown-mask {
351
+ left: -9999px;
352
+ right: -9999px;
353
+ bottom: -9999px;
354
+ }
355
+ }
356
+ </style>