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,492 +1,492 @@
1
- <template>
2
- <button
3
- class="pi-button fix-webkit-appearance"
4
- :style="[getCustomStyle, customStyle]"
5
- :class="[customClass, { round: round }]"
6
- :size="size"
7
- :type="type"
8
- :plain="plain"
9
- :disabled="disabled"
10
- :form-type="formType"
11
- :open-type="openType"
12
- :app-parameter="appParameter"
13
- :hover-stop-propagation="hoverStopPropagation"
14
- :send-message-title="sendMessageTitle"
15
- :send-message-path="sendMessagePath"
16
- :lang="lang"
17
- :session-from="sessionFrom"
18
- :send-message-img="sendMessageImg"
19
- :show-message-card="showMessageCard"
20
- :hover-class="getHoverClass"
21
- :hover-start-time="hoverStartTime"
22
- :hover-stay-time="hoverStayTime"
23
- :loading="loading"
24
- @tap.stop="handleButtonTap"
25
- @getphonenumber="handleGetPhoneNumber($event)"
26
- @getuserinfo="handleGetUserInfo($event)"
27
- @error="handleError($event)"
28
- @opensetting="handleOpenSetting($event)"
29
- @launchapp="handleLaunchApp($event)"
30
- >
31
- <!-- 按钮内容 -->
32
- <slot />
33
- <view v-if="ripple" class="pi-abso-full pi-of-hidden" :class="[{ round }]">
34
- <view class="wave-ripple" :class="[{ active: waveInfo.active }]" :style="[waveStyle]" />
35
- </view>
36
- </button>
37
- </template>
38
-
39
- <script>
40
- /**
41
- * 属性和官方uniapp button属性保持一致,扩展了一部分常用属性
42
- * 因为小程序不兼容v-bind="$attrs"写法,所以只能把官网属性重定义一遍
43
- */
44
- import { getConfig } from '../../config'
45
-
46
- import { debounce } from '@sadais/piui-tool/tools/common'
47
- const TAG = 'PiButton'
48
- const { button } = getConfig()
49
-
50
- export default {
51
- name: 'PiButton',
52
- props: {
53
- // 按钮尺寸
54
- size: {
55
- // `'default'` `'large'` `'medium'` `'small'` `'tiny'` `'mini'`
56
- type: String,
57
- // 'default'
58
- default: button.size,
59
- validator: function(value) {
60
- return ['default', 'large', 'medium', 'small', 'tiny', 'mini'].includes(value)
61
- }
62
- },
63
- // 按钮的预置样式
64
- type: {
65
- // `'default'` `'primary'` `'warn'` `'secondary'` `'line'` `text`
66
- type: String,
67
- // 'default'
68
- default: button.type,
69
- validator: function(value) {
70
- return ['default', 'primary', 'warn', 'secondary', 'line', 'text'].includes(value)
71
- }
72
- },
73
- // 按钮是否镂空
74
- plain: {
75
- type: Boolean,
76
- // false
77
- default: button.plain
78
- },
79
- // 是否禁止状态
80
- disabled: {
81
- type: Boolean,
82
- // false
83
- default: button.disabled
84
- },
85
- // 是否加载中
86
- loading: {
87
- type: Boolean,
88
- // false
89
- default: button.loading
90
- },
91
- // 取值为submit(提交表单),reset(重置表单)
92
- formType: {
93
- type: String,
94
- // ''
95
- default: button.formType
96
- },
97
- // 开放能力,具体请看uniapp稳定关于button组件部分说明
98
- openType: {
99
- type: String,
100
- // ''
101
- default: button.openType
102
- },
103
- // 指定按钮按下去的样式类。当 hover-class="none" 时,没有点击态效果
104
- hoverClass: {
105
- type: String,
106
- // 'button-hover'
107
- default: button.hoverClass
108
- },
109
- // 按住后多久出现点击态,单位毫秒
110
- hoverStartTime: {
111
- type: Number,
112
- // 20
113
- default: button.hoverStartTime
114
- },
115
- // 手指松开后点击态保留时间,单位毫秒
116
- hoverStayTime: {
117
- type: Number,
118
- // 70
119
- default: button.hoverStayTime
120
- },
121
- // 打开 APP 时,向 APP 传递的参数,open-type=launchApp时有效
122
- appParameter: {
123
- type: String,
124
- // ''
125
- default: button.appParameter
126
- },
127
- // 指定是否阻止本节点的祖先节点出现点击态,微信小程序有效
128
- hoverStopPropagation: {
129
- type: Boolean,
130
- // false
131
- default: button.hoverStopPropagation
132
- },
133
- // 指定返回用户信息的语言,zh_CN 简体中文,zh_TW 繁体中文,en 英文。只微信小程序有效
134
- lang: {
135
- type: String,
136
- // 'en'
137
- default: button.lang
138
- },
139
- // 会话来源,open-type="contact"时有效。只微信小程序有效
140
- sessionFrom: {
141
- type: String,
142
- // ''
143
- default: button.sessionFrom
144
- },
145
- // 会话内消息卡片标题,open-type="contact"时有效
146
- // 默认当前标题,只微信小程序有效
147
- sendMessageTitle: {
148
- type: String,
149
- // ''
150
- default: button.sendMessageTitle
151
- },
152
- // 会话内消息卡片点击跳转小程序路径,open-type="contact"时有效
153
- // 默认当前分享路径,只微信小程序有效
154
- sendMessagePath: {
155
- type: String,
156
- // ''
157
- default: button.sendMessagePath
158
- },
159
- // 会话内消息卡片图片,open-type="contact"时有效
160
- // 默认当前页面截图,只微信小程序有效
161
- sendMessageImg: {
162
- type: String,
163
- // ''
164
- default: button.sendMessageImg
165
- },
166
- // 是否显示会话内消息卡片,设置此参数为 true,用户进入客服会话会在右下角显示"可能要发送的小程序"提示,
167
- // 用户点击后可以快速发送小程序消息,open-type="contact"时有效
168
- showMessageCard: {
169
- type: Boolean,
170
- // false
171
- default: button.showMessageCard
172
- },
173
- // 自定义样式,对象形式
174
- customStyle: {
175
- type: Object,
176
- // {}
177
- default() {
178
- return button.customStyle
179
- }
180
- },
181
- // 自定义样式类,字符串形式
182
- customClass: {
183
- type: String,
184
- // {}
185
- default() {
186
- return button.customClass
187
- }
188
- },
189
- // 按钮宽度,不设置默认自动撑开,如果需要占满一行,填写’100%‘
190
- width: {
191
- type: [String, Number],
192
- // ''
193
- default: button.width
194
- },
195
- // 自定义颜色按钮(type为default,可自定义设置)
196
- color: {
197
- type: String,
198
- // ''
199
- default: button.color
200
- },
201
- // 自定义背景色按钮(type为default,可自定义设置)
202
- bgColor: {
203
- type: String,
204
- // ''
205
- default: button.bgColor
206
- },
207
- // 按钮是否椭圆
208
- round: {
209
- type: Boolean,
210
- // false
211
- default: button.round
212
- },
213
- // 是否开启水波纹效果(默认值:true)
214
- ripple: {
215
- type: Boolean,
216
- // true
217
- default: button.ripple
218
- },
219
- // 水波纹的背景颜色(默认值:'')
220
- rippleBgColor: {
221
- type: String,
222
- // ''
223
- default: button.rippleBgColor
224
- }
225
- },
226
- data() {
227
- return {
228
- waveInfo: {
229
- active: false, // 激活水波纹
230
- top: '', // 水波纹的起点Y坐标到按钮上边界的距离
231
- left: '', // 水波纹起点X坐标到按钮左边界的距离
232
- fields: { targetWidth: 0 } // 波纹按钮节点信息
233
- }
234
- }
235
- },
236
- computed: {
237
- getCustomStyle() {
238
- const style = {}
239
-
240
- if (this.color) style.color = this.color
241
- if (this.bgColor) style.backgroundColor = this.bgColor
242
- if (this.width) style.width = this.$pi.common.addUnit(this.width)
243
-
244
- if (style.width === '100%') {
245
- style.display = 'block'
246
- }
247
-
248
- return style
249
- },
250
- getHoverClass() {
251
- if (this.loading || this.disabled || this.ripple) return 'none'
252
- return this.hoverClass
253
- },
254
- waveStyle() {
255
- return {
256
- 'top': this.waveInfo.top + 'px',
257
- 'left': this.waveInfo.left + 'px',
258
- 'width': this.waveInfo.fields.targetWidth + 'px',
259
- 'height': this.waveInfo.fields.targetWidth + 'px',
260
- 'background-color': this.rippleBgColor || 'rgba(0, 0, 0, 0.05)'
261
- }
262
- }
263
- },
264
- methods: {
265
- handleButtonTap: debounce(function(e) {
266
- if (this.loading || this.disabled) return
267
- this.$emit('click', e)
268
- // 点击事件
269
- console.log(TAG, '触发按钮click事件')
270
- if (!this.ripple) return
271
- // 是否开启水波纹效果
272
- this.waveInfo.active = false
273
- this.$nextTick(function() {
274
- this.queryWaveInfo(e)
275
- })
276
- }, button.debounceTimeout),
277
- // 查询按钮的节点信息
278
- queryWaveInfo(e) {
279
- this.getElRectQuery().then(res => {
280
- // 查询返回的是一个数组节点
281
- let data = res[0]
282
- // 查询不到节点信息,不操作
283
- if (!data.width || !data.width) return
284
- // 水波纹的最终形态是一个正方形(通过border-radius让其变为一个圆形),这里要保证正方形的边长等于按钮的最长边
285
- // 最终的方形(变换后的圆形)才能覆盖整个按钮
286
- data.targetWidth = data.height > data.width ? data.height : data.width
287
- if (!data.targetWidth) return
288
- this.waveInfo.fields = data
289
- let touchesX = '',
290
- touchesY = ''
291
- // #ifdef MP-BAIDU
292
- touchesX = e.changedTouches[0].clientX
293
- touchesY = e.changedTouches[0].clientY
294
- // #endif
295
- // #ifdef MP-ALIPAY
296
- touchesX = e.detail.clientX
297
- touchesY = e.detail.clientY
298
- // #endif
299
- // #ifndef MP-BAIDU || MP-ALIPAY
300
- touchesX = e.touches[0].clientX
301
- touchesY = e.touches[0].clientY
302
- // #endif
303
- // 获取触摸点相对于按钮上边和左边的x和y坐标,原理是通过屏幕的触摸点(touchesY),减去按钮的上边界data.top
304
- // 但是由于`transform-origin`默认是center,所以这里再减去半径才是水波纹view应该的位置
305
- // 总的来说,就是把水波纹的矩形(变换后的圆形)的中心点,移动到我们的触摸点位置
306
- this.waveInfo.top = touchesY - data.top - data.targetWidth / 2
307
- this.waveInfo.left = touchesX - data.left - data.targetWidth / 2
308
- this.$nextTick(() => {
309
- this.waveInfo.active = true
310
- })
311
- })
312
- },
313
- // 获取节点区域信息
314
- getElRectQuery() {
315
- return new Promise(resolve => {
316
- let queryInfo = ''
317
- queryInfo = uni.createSelectorQuery().in(this)
318
- // #ifdef MP-ALIPAY
319
- queryInfo = uni.createSelectorQuery()
320
- // #endif
321
- queryInfo.select('.pi-button').boundingClientRect()
322
- queryInfo.exec(data => {
323
- resolve(data)
324
- })
325
- })
326
- },
327
- handleGetPhoneNumber(e) {
328
- // 微信小程序中获取用户手机号回调,需设置open-type="getPhoneNumber"
329
- this.$emit('getphonenumber', e)
330
- },
331
- handleGetUserInfo(e) {
332
- // 微信小程序中用户点击该按钮时,会返回获取到的用户信息,从返回参数的detail中获取到的值同uni.getUserInfo,需设置open-type="getUserInfo"
333
- this.$emit('getuserinfo', e)
334
- },
335
- handleError(e) {
336
- // 微信小程序中当使用开放能力时,发生错误的回调
337
- this.$emit('error', e)
338
- },
339
- handleOpenSetting(e) {
340
- // 微信小程序中在打开授权设置页并关闭后回调,需设置open-type="openSetting"
341
- this.$emit('opensetting', e)
342
- },
343
- handleLaunchApp(e) {
344
- // 微信小程序中从小程序打开 App 成功的回调
345
- this.$emit('launchapp', e)
346
- }
347
- }
348
- }
349
- </script>
350
-
351
- <style lang="scss" scoped>
352
- .round {
353
- overflow: hidden;
354
- border-radius: 500000rpx !important;
355
- }
356
-
357
- .pi-button {
358
- position: relative;
359
- display: inline-block;
360
- padding: $pi-button-default-padding;
361
- border: none;
362
- border-radius: $pi-button-default-radius;
363
- // 默认样式
364
- &[type='default'] {
365
- color: #333333;
366
- background-color: #e5e5e5;
367
- }
368
-
369
- &::after {
370
- border: none;
371
- }
372
- &[disabled] {
373
- opacity: $pi-disabled-opacity;
374
- }
375
- &[loading]::before {
376
- margin-right: 12rpx;
377
- }
378
- // 椭圆
379
- &.round {
380
- &::after {
381
- @extend .round;
382
- }
383
- }
384
- // 默认
385
- &[size='default'] {
386
- height: $pi-button-default-height;
387
- padding: $pi-button-default-padding;
388
- font-size: $pi-button-default-font-size;
389
- line-height: $pi-button-default-height;
390
- &[plain]::after {
391
- border: 8rpx solid #e5e5e5;
392
- }
393
- }
394
- // 大
395
- &[size='large'] {
396
- height: $pi-button-large-height;
397
- padding: $pi-button-large-padding;
398
- font-size: $pi-button-large-font-size;
399
- line-height: $pi-button-large-height;
400
- border-radius: $pi-button-large-radius;
401
- }
402
- // 中
403
- &[size='medium'] {
404
- height: $pi-button-medium-height;
405
- padding: $pi-button-medium-padding;
406
- font-size: $pi-button-medium-font-size;
407
- line-height: $pi-button-medium-height;
408
- border-radius: $pi-button-medium-radius;
409
- }
410
- // 小
411
- &[size='small'] {
412
- height: $pi-button-small-height;
413
- padding: $pi-button-small-padding;
414
- font-size: $pi-button-small-font-size;
415
- line-height: $pi-button-small-height;
416
- border-radius: $pi-button-small-radius;
417
- }
418
- // 超小
419
- &[size='tiny'] {
420
- height: $pi-button-tiny-height;
421
- padding: $pi-button-tiny-padding;
422
- font-size: $pi-button-tiny-font-size;
423
- line-height: $pi-button-tiny-height;
424
- border-radius: $pi-button-tiny-radius;
425
- }
426
- // 迷你
427
- &[size='mini'] {
428
- height: $pi-button-mini-height;
429
- padding: $pi-button-mini-padding;
430
- font-size: $pi-button-mini-font-size;
431
- line-height: $pi-button-mini-height;
432
- border-radius: $pi-button-mini-radius;
433
- }
434
-
435
- // 主要样式
436
- &[type='primary'] {
437
- background-color: $pi-primary-color;
438
- }
439
- &.button-hover[type='primary'] {
440
- background-color: rgba($pi-primary-color, 0.8);
441
- }
442
-
443
- // 次要
444
- &[type='secondary'] {
445
- color: $pi-primary-color;
446
- background-color: rgba($pi-primary-color, 0.1);
447
- }
448
- &.button-hover[type='secondary'] {
449
- background-color: rgba($pi-primary-color, 0.08);
450
- }
451
-
452
- // 线框
453
- &[type='line'] {
454
- color: $pi-primary-color;
455
- background-color: #ffffff;
456
- &::after {
457
- border: 8rpx solid $pi-primary-color;
458
- }
459
- }
460
- &.button-hover[type='line'] {
461
- background-color: rgba($pi-primary-color, 0.08);
462
- }
463
-
464
- &[type='text'] {
465
- background-color: transparent;
466
- &::after {
467
- border: none;
468
- }
469
- }
470
- &.button-hover[type='line'] {
471
- background-color: rgba($pi-primary-color, 0.08);
472
- }
473
-
474
- .wave-ripple {
475
- position: absolute;
476
- z-index: 0;
477
- overflow: hidden;
478
- pointer-events: none;
479
- user-select: none;
480
- background-clip: padding-box;
481
- border-radius: 100%;
482
- opacity: 1;
483
- transform: scale(0);
484
- transform-origin: center;
485
- &.active {
486
- opacity: 0;
487
- transition: opacity 1s linear, transform 0.4s linear;
488
- transform: scale(2);
489
- }
490
- }
491
- }
492
- </style>
1
+ <template>
2
+ <button
3
+ class="pi-button fix-webkit-appearance"
4
+ :style="[getCustomStyle, customStyle]"
5
+ :class="[customClass, { round: round }]"
6
+ :size="size"
7
+ :type="type"
8
+ :plain="plain"
9
+ :disabled="disabled"
10
+ :form-type="formType"
11
+ :open-type="openType"
12
+ :app-parameter="appParameter"
13
+ :hover-stop-propagation="hoverStopPropagation"
14
+ :send-message-title="sendMessageTitle"
15
+ :send-message-path="sendMessagePath"
16
+ :lang="lang"
17
+ :session-from="sessionFrom"
18
+ :send-message-img="sendMessageImg"
19
+ :show-message-card="showMessageCard"
20
+ :hover-class="getHoverClass"
21
+ :hover-start-time="hoverStartTime"
22
+ :hover-stay-time="hoverStayTime"
23
+ :loading="loading"
24
+ @tap.stop="handleButtonTap"
25
+ @getphonenumber="handleGetPhoneNumber($event)"
26
+ @getuserinfo="handleGetUserInfo($event)"
27
+ @error="handleError($event)"
28
+ @opensetting="handleOpenSetting($event)"
29
+ @launchapp="handleLaunchApp($event)"
30
+ >
31
+ <!-- 按钮内容 -->
32
+ <slot />
33
+ <view v-if="ripple" class="pi-abso-full pi-of-hidden" :class="[{ round }]">
34
+ <view class="wave-ripple" :class="[{ active: waveInfo.active }]" :style="[waveStyle]" />
35
+ </view>
36
+ </button>
37
+ </template>
38
+
39
+ <script>
40
+ /**
41
+ * 属性和官方uniapp button属性保持一致,扩展了一部分常用属性
42
+ * 因为小程序不兼容v-bind="$attrs"写法,所以只能把官网属性重定义一遍
43
+ */
44
+ import { getConfig } from '../../config'
45
+
46
+ import { debounce } from '@sadais/piui-tool/tools/common'
47
+ const TAG = 'PiButton'
48
+ const { button } = getConfig()
49
+
50
+ export default {
51
+ name: 'PiButton',
52
+ props: {
53
+ // 按钮尺寸
54
+ size: {
55
+ // `'default'` `'large'` `'medium'` `'small'` `'tiny'` `'mini'`
56
+ type: String,
57
+ // 'default'
58
+ default: button.size,
59
+ validator: function(value) {
60
+ return ['default', 'large', 'medium', 'small', 'tiny', 'mini'].includes(value)
61
+ }
62
+ },
63
+ // 按钮的预置样式
64
+ type: {
65
+ // `'default'` `'primary'` `'warn'` `'secondary'` `'line'` `text`
66
+ type: String,
67
+ // 'default'
68
+ default: button.type,
69
+ validator: function(value) {
70
+ return ['default', 'primary', 'warn', 'secondary', 'line', 'text'].includes(value)
71
+ }
72
+ },
73
+ // 按钮是否镂空
74
+ plain: {
75
+ type: Boolean,
76
+ // false
77
+ default: button.plain
78
+ },
79
+ // 是否禁止状态
80
+ disabled: {
81
+ type: Boolean,
82
+ // false
83
+ default: button.disabled
84
+ },
85
+ // 是否加载中
86
+ loading: {
87
+ type: Boolean,
88
+ // false
89
+ default: button.loading
90
+ },
91
+ // 取值为submit(提交表单),reset(重置表单)
92
+ formType: {
93
+ type: String,
94
+ // ''
95
+ default: button.formType
96
+ },
97
+ // 开放能力,具体请看uniapp稳定关于button组件部分说明
98
+ openType: {
99
+ type: String,
100
+ // ''
101
+ default: button.openType
102
+ },
103
+ // 指定按钮按下去的样式类。当 hover-class="none" 时,没有点击态效果
104
+ hoverClass: {
105
+ type: String,
106
+ // 'button-hover'
107
+ default: button.hoverClass
108
+ },
109
+ // 按住后多久出现点击态,单位毫秒
110
+ hoverStartTime: {
111
+ type: Number,
112
+ // 20
113
+ default: button.hoverStartTime
114
+ },
115
+ // 手指松开后点击态保留时间,单位毫秒
116
+ hoverStayTime: {
117
+ type: Number,
118
+ // 70
119
+ default: button.hoverStayTime
120
+ },
121
+ // 打开 APP 时,向 APP 传递的参数,open-type=launchApp时有效
122
+ appParameter: {
123
+ type: String,
124
+ // ''
125
+ default: button.appParameter
126
+ },
127
+ // 指定是否阻止本节点的祖先节点出现点击态,微信小程序有效
128
+ hoverStopPropagation: {
129
+ type: Boolean,
130
+ // false
131
+ default: button.hoverStopPropagation
132
+ },
133
+ // 指定返回用户信息的语言,zh_CN 简体中文,zh_TW 繁体中文,en 英文。只微信小程序有效
134
+ lang: {
135
+ type: String,
136
+ // 'en'
137
+ default: button.lang
138
+ },
139
+ // 会话来源,open-type="contact"时有效。只微信小程序有效
140
+ sessionFrom: {
141
+ type: String,
142
+ // ''
143
+ default: button.sessionFrom
144
+ },
145
+ // 会话内消息卡片标题,open-type="contact"时有效
146
+ // 默认当前标题,只微信小程序有效
147
+ sendMessageTitle: {
148
+ type: String,
149
+ // ''
150
+ default: button.sendMessageTitle
151
+ },
152
+ // 会话内消息卡片点击跳转小程序路径,open-type="contact"时有效
153
+ // 默认当前分享路径,只微信小程序有效
154
+ sendMessagePath: {
155
+ type: String,
156
+ // ''
157
+ default: button.sendMessagePath
158
+ },
159
+ // 会话内消息卡片图片,open-type="contact"时有效
160
+ // 默认当前页面截图,只微信小程序有效
161
+ sendMessageImg: {
162
+ type: String,
163
+ // ''
164
+ default: button.sendMessageImg
165
+ },
166
+ // 是否显示会话内消息卡片,设置此参数为 true,用户进入客服会话会在右下角显示"可能要发送的小程序"提示,
167
+ // 用户点击后可以快速发送小程序消息,open-type="contact"时有效
168
+ showMessageCard: {
169
+ type: Boolean,
170
+ // false
171
+ default: button.showMessageCard
172
+ },
173
+ // 自定义样式,对象形式
174
+ customStyle: {
175
+ type: Object,
176
+ // {}
177
+ default() {
178
+ return button.customStyle
179
+ }
180
+ },
181
+ // 自定义样式类,字符串形式
182
+ customClass: {
183
+ type: String,
184
+ // {}
185
+ default() {
186
+ return button.customClass
187
+ }
188
+ },
189
+ // 按钮宽度,不设置默认自动撑开,如果需要占满一行,填写’100%‘
190
+ width: {
191
+ type: [String, Number],
192
+ // ''
193
+ default: button.width
194
+ },
195
+ // 自定义颜色按钮(type为default,可自定义设置)
196
+ color: {
197
+ type: String,
198
+ // ''
199
+ default: button.color
200
+ },
201
+ // 自定义背景色按钮(type为default,可自定义设置)
202
+ bgColor: {
203
+ type: String,
204
+ // ''
205
+ default: button.bgColor
206
+ },
207
+ // 按钮是否椭圆
208
+ round: {
209
+ type: Boolean,
210
+ // false
211
+ default: button.round
212
+ },
213
+ // 是否开启水波纹效果(默认值:true)
214
+ ripple: {
215
+ type: Boolean,
216
+ // true
217
+ default: button.ripple
218
+ },
219
+ // 水波纹的背景颜色(默认值:'')
220
+ rippleBgColor: {
221
+ type: String,
222
+ // ''
223
+ default: button.rippleBgColor
224
+ }
225
+ },
226
+ data() {
227
+ return {
228
+ waveInfo: {
229
+ active: false, // 激活水波纹
230
+ top: '', // 水波纹的起点Y坐标到按钮上边界的距离
231
+ left: '', // 水波纹起点X坐标到按钮左边界的距离
232
+ fields: { targetWidth: 0 } // 波纹按钮节点信息
233
+ }
234
+ }
235
+ },
236
+ computed: {
237
+ getCustomStyle() {
238
+ const style = {}
239
+
240
+ if (this.color) style.color = this.color
241
+ if (this.bgColor) style.backgroundColor = this.bgColor
242
+ if (this.width) style.width = this.$pi.common.addUnit(this.width)
243
+
244
+ if (style.width === '100%') {
245
+ style.display = 'block'
246
+ }
247
+
248
+ return style
249
+ },
250
+ getHoverClass() {
251
+ if (this.loading || this.disabled || this.ripple) return 'none'
252
+ return this.hoverClass
253
+ },
254
+ waveStyle() {
255
+ return {
256
+ 'top': this.waveInfo.top + 'px',
257
+ 'left': this.waveInfo.left + 'px',
258
+ 'width': this.waveInfo.fields.targetWidth + 'px',
259
+ 'height': this.waveInfo.fields.targetWidth + 'px',
260
+ 'background-color': this.rippleBgColor || 'rgba(0, 0, 0, 0.05)'
261
+ }
262
+ }
263
+ },
264
+ methods: {
265
+ handleButtonTap: debounce(function(e) {
266
+ if (this.loading || this.disabled) return
267
+ this.$emit('click', e)
268
+ // 点击事件
269
+ console.log(TAG, '触发按钮click事件')
270
+ if (!this.ripple) return
271
+ // 是否开启水波纹效果
272
+ this.waveInfo.active = false
273
+ this.$nextTick(function() {
274
+ this.queryWaveInfo(e)
275
+ })
276
+ }, button.debounceTimeout),
277
+ // 查询按钮的节点信息
278
+ queryWaveInfo(e) {
279
+ this.getElRectQuery().then(res => {
280
+ // 查询返回的是一个数组节点
281
+ let data = res[0]
282
+ // 查询不到节点信息,不操作
283
+ if (!data.width || !data.width) return
284
+ // 水波纹的最终形态是一个正方形(通过border-radius让其变为一个圆形),这里要保证正方形的边长等于按钮的最长边
285
+ // 最终的方形(变换后的圆形)才能覆盖整个按钮
286
+ data.targetWidth = data.height > data.width ? data.height : data.width
287
+ if (!data.targetWidth) return
288
+ this.waveInfo.fields = data
289
+ let touchesX = '',
290
+ touchesY = ''
291
+ // #ifdef MP-BAIDU
292
+ touchesX = e.changedTouches[0].clientX
293
+ touchesY = e.changedTouches[0].clientY
294
+ // #endif
295
+ // #ifdef MP-ALIPAY
296
+ touchesX = e.detail.clientX
297
+ touchesY = e.detail.clientY
298
+ // #endif
299
+ // #ifndef MP-BAIDU || MP-ALIPAY
300
+ touchesX = e.touches[0].clientX
301
+ touchesY = e.touches[0].clientY
302
+ // #endif
303
+ // 获取触摸点相对于按钮上边和左边的x和y坐标,原理是通过屏幕的触摸点(touchesY),减去按钮的上边界data.top
304
+ // 但是由于`transform-origin`默认是center,所以这里再减去半径才是水波纹view应该的位置
305
+ // 总的来说,就是把水波纹的矩形(变换后的圆形)的中心点,移动到我们的触摸点位置
306
+ this.waveInfo.top = touchesY - data.top - data.targetWidth / 2
307
+ this.waveInfo.left = touchesX - data.left - data.targetWidth / 2
308
+ this.$nextTick(() => {
309
+ this.waveInfo.active = true
310
+ })
311
+ })
312
+ },
313
+ // 获取节点区域信息
314
+ getElRectQuery() {
315
+ return new Promise(resolve => {
316
+ let queryInfo = ''
317
+ queryInfo = uni.createSelectorQuery().in(this)
318
+ // #ifdef MP-ALIPAY
319
+ queryInfo = uni.createSelectorQuery()
320
+ // #endif
321
+ queryInfo.select('.pi-button').boundingClientRect()
322
+ queryInfo.exec(data => {
323
+ resolve(data)
324
+ })
325
+ })
326
+ },
327
+ handleGetPhoneNumber(e) {
328
+ // 微信小程序中获取用户手机号回调,需设置open-type="getPhoneNumber"
329
+ this.$emit('getphonenumber', e)
330
+ },
331
+ handleGetUserInfo(e) {
332
+ // 微信小程序中用户点击该按钮时,会返回获取到的用户信息,从返回参数的detail中获取到的值同uni.getUserInfo,需设置open-type="getUserInfo"
333
+ this.$emit('getuserinfo', e)
334
+ },
335
+ handleError(e) {
336
+ // 微信小程序中当使用开放能力时,发生错误的回调
337
+ this.$emit('error', e)
338
+ },
339
+ handleOpenSetting(e) {
340
+ // 微信小程序中在打开授权设置页并关闭后回调,需设置open-type="openSetting"
341
+ this.$emit('opensetting', e)
342
+ },
343
+ handleLaunchApp(e) {
344
+ // 微信小程序中从小程序打开 App 成功的回调
345
+ this.$emit('launchapp', e)
346
+ }
347
+ }
348
+ }
349
+ </script>
350
+
351
+ <style lang="scss" scoped>
352
+ .round {
353
+ overflow: hidden;
354
+ border-radius: 500000rpx !important;
355
+ }
356
+
357
+ .pi-button {
358
+ position: relative;
359
+ display: inline-block;
360
+ padding: $pi-button-default-padding;
361
+ border: none;
362
+ border-radius: $pi-button-default-radius;
363
+ // 默认样式
364
+ &[type='default'] {
365
+ color: #333333;
366
+ background-color: #e5e5e5;
367
+ }
368
+
369
+ &::after {
370
+ border: none;
371
+ }
372
+ &[disabled] {
373
+ opacity: $pi-disabled-opacity;
374
+ }
375
+ &[loading]::before {
376
+ margin-right: 12rpx;
377
+ }
378
+ // 椭圆
379
+ &.round {
380
+ &::after {
381
+ @extend .round;
382
+ }
383
+ }
384
+ // 默认
385
+ &[size='default'] {
386
+ height: $pi-button-default-height;
387
+ padding: $pi-button-default-padding;
388
+ font-size: $pi-button-default-font-size;
389
+ line-height: $pi-button-default-height;
390
+ &[plain]::after {
391
+ border: 8rpx solid #e5e5e5;
392
+ }
393
+ }
394
+ // 大
395
+ &[size='large'] {
396
+ height: $pi-button-large-height;
397
+ padding: $pi-button-large-padding;
398
+ font-size: $pi-button-large-font-size;
399
+ line-height: $pi-button-large-height;
400
+ border-radius: $pi-button-large-radius;
401
+ }
402
+ // 中
403
+ &[size='medium'] {
404
+ height: $pi-button-medium-height;
405
+ padding: $pi-button-medium-padding;
406
+ font-size: $pi-button-medium-font-size;
407
+ line-height: $pi-button-medium-height;
408
+ border-radius: $pi-button-medium-radius;
409
+ }
410
+ // 小
411
+ &[size='small'] {
412
+ height: $pi-button-small-height;
413
+ padding: $pi-button-small-padding;
414
+ font-size: $pi-button-small-font-size;
415
+ line-height: $pi-button-small-height;
416
+ border-radius: $pi-button-small-radius;
417
+ }
418
+ // 超小
419
+ &[size='tiny'] {
420
+ height: $pi-button-tiny-height;
421
+ padding: $pi-button-tiny-padding;
422
+ font-size: $pi-button-tiny-font-size;
423
+ line-height: $pi-button-tiny-height;
424
+ border-radius: $pi-button-tiny-radius;
425
+ }
426
+ // 迷你
427
+ &[size='mini'] {
428
+ height: $pi-button-mini-height;
429
+ padding: $pi-button-mini-padding;
430
+ font-size: $pi-button-mini-font-size;
431
+ line-height: $pi-button-mini-height;
432
+ border-radius: $pi-button-mini-radius;
433
+ }
434
+
435
+ // 主要样式
436
+ &[type='primary'] {
437
+ background-color: $pi-primary-color;
438
+ }
439
+ &.button-hover[type='primary'] {
440
+ background-color: rgba($pi-primary-color, 0.8);
441
+ }
442
+
443
+ // 次要
444
+ &[type='secondary'] {
445
+ color: $pi-primary-color;
446
+ background-color: rgba($pi-primary-color, 0.1);
447
+ }
448
+ &.button-hover[type='secondary'] {
449
+ background-color: rgba($pi-primary-color, 0.08);
450
+ }
451
+
452
+ // 线框
453
+ &[type='line'] {
454
+ color: $pi-primary-color;
455
+ background-color: #ffffff;
456
+ &::after {
457
+ border: 8rpx solid $pi-primary-color;
458
+ }
459
+ }
460
+ &.button-hover[type='line'] {
461
+ background-color: rgba($pi-primary-color, 0.08);
462
+ }
463
+
464
+ &[type='text'] {
465
+ background-color: transparent;
466
+ &::after {
467
+ border: none;
468
+ }
469
+ }
470
+ &.button-hover[type='line'] {
471
+ background-color: rgba($pi-primary-color, 0.08);
472
+ }
473
+
474
+ .wave-ripple {
475
+ position: absolute;
476
+ z-index: 0;
477
+ overflow: hidden;
478
+ pointer-events: none;
479
+ user-select: none;
480
+ background-clip: padding-box;
481
+ border-radius: 100%;
482
+ opacity: 1;
483
+ transform: scale(0);
484
+ transform-origin: center;
485
+ &.active {
486
+ opacity: 0;
487
+ transition: opacity 1s linear, transform 0.4s linear;
488
+ transform: scale(2);
489
+ }
490
+ }
491
+ }
492
+ </style>