uview-pro 0.2.0 → 0.2.2
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/changelog.md +501 -459
- package/components/common/props.ts +22 -22
- package/components/u-action-sheet/types.ts +35 -35
- package/components/u-action-sheet/u-action-sheet.vue +160 -160
- package/components/u-alert-tips/types.ts +39 -39
- package/components/u-alert-tips/u-alert-tips.vue +212 -212
- package/components/u-avatar/types.ts +34 -34
- package/components/u-avatar/u-avatar.vue +193 -193
- package/components/u-avatar-cropper/types.ts +23 -23
- package/components/u-avatar-cropper/u-avatar-cropper.vue +286 -286
- package/components/u-avatar-cropper/weCropper.d.ts +62 -62
- package/components/u-avatar-cropper/weCropper.js +1253 -1253
- package/components/u-avatar-cropper/weCropper.ts +1255 -1255
- package/components/u-back-top/types.ts +39 -39
- package/components/u-back-top/u-back-top.vue +125 -125
- package/components/u-badge/types.ts +36 -36
- package/components/u-badge/u-badge.vue +165 -165
- package/components/u-button/types.ts +66 -66
- package/components/u-button/u-button.vue +556 -556
- package/components/u-calendar/types.ts +73 -63
- package/components/u-calendar/u-calendar.vue +638 -592
- package/components/u-car-keyboard/types.ts +12 -12
- package/components/u-car-keyboard/u-car-keyboard.vue +234 -234
- package/components/u-card/types.ts +59 -59
- package/components/u-card/u-card.vue +194 -194
- package/components/u-cell-group/types.ts +17 -17
- package/components/u-cell-group/u-cell-group.vue +50 -50
- package/components/u-cell-item/types.ts +54 -54
- package/components/u-cell-item/u-cell-item.vue +202 -202
- package/components/u-checkbox/types.ts +31 -31
- package/components/u-checkbox/u-checkbox.vue +267 -267
- package/components/u-checkbox-group/types.ts +32 -32
- package/components/u-checkbox-group/u-checkbox-group.vue +79 -79
- package/components/u-circle-progress/types.ts +52 -52
- package/components/u-circle-progress/u-circle-progress.vue +187 -187
- package/components/u-city-select/types.ts +20 -20
- package/components/u-city-select/u-city-select.vue +236 -236
- package/components/u-col/types.ts +30 -30
- package/components/u-col/u-col.vue +123 -123
- package/components/u-collapse/types.ts +33 -33
- package/components/u-collapse/u-collapse.vue +69 -69
- package/components/u-collapse-item/types.ts +27 -27
- package/components/u-collapse-item/u-collapse-item.vue +213 -201
- package/components/u-column-notice/types.ts +48 -48
- package/components/u-column-notice/u-column-notice.vue +176 -176
- package/components/u-count-down/types.ts +42 -42
- package/components/u-count-down/u-count-down.vue +258 -258
- package/components/u-count-to/types.ts +32 -32
- package/components/u-count-to/u-count-to.vue +241 -241
- package/components/u-divider/types.ts +31 -31
- package/components/u-divider/u-divider.vue +121 -121
- package/components/u-dropdown/types.ts +32 -32
- package/components/u-dropdown/u-dropdown.vue +289 -289
- package/components/u-dropdown-item/types.ts +27 -27
- package/components/u-dropdown-item/u-dropdown-item.vue +123 -123
- package/components/u-empty/types.ts +36 -36
- package/components/u-empty/u-empty.vue +88 -88
- package/components/u-field/types.ts +69 -69
- package/components/u-field/u-field.vue +354 -354
- package/components/u-form/u-form.vue +132 -132
- package/components/u-form-item/u-form-item.vue +417 -417
- package/components/u-full-screen/types.ts +14 -14
- package/components/u-full-screen/u-full-screen.vue +82 -82
- package/components/u-gap/types.ts +18 -18
- package/components/u-gap/u-gap.vue +40 -40
- package/components/u-grid/types.ts +19 -19
- package/components/u-grid/u-grid.vue +93 -93
- package/components/u-grid-item/types.ts +16 -16
- package/components/u-grid-item/u-grid-item.vue +130 -130
- package/components/u-icon/types.ts +62 -62
- package/components/u-icon/u-icon.vue +281 -281
- package/components/u-image/types.ts +51 -51
- package/components/u-image/u-image.vue +222 -222
- package/components/u-index-anchor/types.ts +16 -16
- package/components/u-index-anchor/u-index-anchor.vue +86 -86
- package/components/u-index-list/types.ts +43 -43
- package/components/u-index-list/u-index-list.vue +355 -355
- package/components/u-input/types.ts +140 -140
- package/components/u-input/u-input.vue +264 -264
- package/components/u-keyboard/types.ts +40 -40
- package/components/u-keyboard/u-keyboard.vue +158 -158
- package/components/u-lazy-load/types.ts +37 -37
- package/components/u-lazy-load/u-lazy-load.vue +233 -233
- package/components/u-line/types.ts +44 -44
- package/components/u-line/u-line.vue +59 -59
- package/components/u-line-progress/types.ts +58 -58
- package/components/u-line-progress/u-line-progress.vue +109 -109
- package/components/u-link/types.ts +43 -43
- package/components/u-link/u-link.vue +75 -75
- package/components/u-loading/types.ts +35 -35
- package/components/u-loading/u-loading.vue +90 -90
- package/components/u-loading-popup/types.ts +26 -26
- package/components/u-loading-popup/u-loading-popup.vue +239 -239
- package/components/u-loadmore/types.ts +79 -79
- package/components/u-loadmore/u-loadmore.vue +140 -140
- package/components/u-mask/types.ts +43 -43
- package/components/u-mask/u-mask.vue +106 -106
- package/components/u-message-input/types.ts +74 -74
- package/components/u-message-input/u-message-input.vue +255 -255
- package/components/u-modal/types.ts +118 -118
- package/components/u-modal/u-modal.vue +204 -204
- package/components/u-navbar/types.ts +103 -103
- package/components/u-navbar/u-navbar.vue +226 -226
- package/components/u-no-network/image.ts +2 -2
- package/components/u-no-network/types.ts +28 -28
- package/components/u-no-network/u-no-network.vue +290 -290
- package/components/u-notice-bar/types.ts +111 -111
- package/components/u-notice-bar/u-notice-bar.vue +174 -174
- package/components/u-number-box/types.ts +42 -42
- package/components/u-number-box/u-number-box.vue +312 -312
- package/components/u-number-keyboard/types.ts +26 -26
- package/components/u-number-keyboard/u-number-keyboard.vue +166 -166
- package/components/u-picker/types.ts +123 -123
- package/components/u-picker/u-picker.vue +637 -637
- package/components/u-popup/types.ts +59 -59
- package/components/u-popup/u-popup.vue +359 -359
- package/components/u-radio/types.ts +25 -25
- package/components/u-radio/u-radio.vue +258 -258
- package/components/u-radio-group/types.ts +29 -29
- package/components/u-radio-group/u-radio-group.vue +98 -98
- package/components/u-rate/types.ts +40 -40
- package/components/u-rate/u-rate.vue +234 -234
- package/components/u-read-more/types.ts +35 -35
- package/components/u-read-more/u-read-more.vue +150 -150
- package/components/u-root-portal/u-root-portal.vue +54 -0
- package/components/u-row/types.ts +20 -20
- package/components/u-row/u-row.vue +87 -87
- package/components/u-row-notice/types.ts +39 -39
- package/components/u-row-notice/u-row-notice.vue +213 -213
- package/components/u-safe-bottom/u-safe-bottom.vue +46 -46
- package/components/u-search/types.ts +53 -53
- package/components/u-search/u-search.vue +256 -256
- package/components/u-section/types.ts +32 -32
- package/components/u-section/u-section.vue +125 -125
- package/components/u-select/types.ts +43 -43
- package/components/u-select/u-select.vue +361 -361
- package/components/u-skeleton/types.ts +20 -20
- package/components/u-skeleton/u-skeleton.vue +205 -205
- package/components/u-slider/types.ts +32 -32
- package/components/u-slider/u-slider.vue +238 -238
- package/components/u-status-bar/u-status-bar.vue +65 -65
- package/components/u-steps/types.ts +28 -28
- package/components/u-steps/u-steps.vue +160 -160
- package/components/u-sticky/types.ts +22 -22
- package/components/u-sticky/u-sticky.vue +159 -159
- package/components/u-subsection/types.ts +36 -36
- package/components/u-subsection/u-subsection.vue +328 -328
- package/components/u-swipe-action/types.ts +50 -50
- package/components/u-swipe-action/u-swipe-action.vue +253 -253
- package/components/u-swiper/types.ts +47 -47
- package/components/u-swiper/u-swiper.vue +266 -266
- package/components/u-switch/types.ts +28 -28
- package/components/u-switch/u-switch.vue +136 -136
- package/components/u-tabbar/types.ts +36 -36
- package/components/u-tabbar/u-tabbar.vue +280 -280
- package/components/u-table/types.ts +25 -25
- package/components/u-table/u-table.vue +55 -55
- package/components/u-tabs/types.ts +51 -51
- package/components/u-tabs/u-tabs.vue +284 -284
- package/components/u-tabs-swiper/types.ts +53 -53
- package/components/u-tabs-swiper/u-tabs-swiper.vue +379 -379
- package/components/u-tag/types.ts +37 -37
- package/components/u-tag/u-tag.vue +244 -244
- package/components/u-td/types.ts +12 -12
- package/components/u-td/u-td.vue +87 -87
- package/components/u-text/types.ts +69 -69
- package/components/u-text/u-text.vue +326 -326
- package/components/u-th/types.ts +12 -12
- package/components/u-th/u-th.vue +81 -81
- package/components/u-time-line/u-time-line.vue +39 -39
- package/components/u-time-line-item/types.ts +14 -14
- package/components/u-time-line-item/u-time-line-item.vue +78 -78
- package/components/u-toast/types.ts +36 -36
- package/components/u-toast/u-toast.vue +233 -233
- package/components/u-top-tips/types.ts +14 -14
- package/components/u-top-tips/u-top-tips.vue +113 -113
- package/components/u-tr/types.ts +8 -8
- package/components/u-tr/u-tr.vue +24 -24
- package/components/u-upload/types.ts +74 -74
- package/components/u-upload/u-upload.vue +545 -545
- package/components/u-verification-code/types.ts +22 -22
- package/components/u-verification-code/u-verification-code.vue +164 -164
- package/components/u-waterfall/types.ts +16 -16
- package/components/u-waterfall/u-waterfall.vue +175 -175
- package/iconfont.css +912 -912
- package/index.scss +25 -25
- package/index.ts +29 -29
- package/libs/config/config.ts +26 -26
- package/libs/config/zIndex.ts +37 -37
- package/libs/css/color.scss +155 -155
- package/libs/css/common.scss +178 -178
- package/libs/css/style.components.scss +16 -16
- package/libs/css/style.h5.scss +8 -8
- package/libs/css/style.mp.scss +72 -72
- package/libs/css/style.nvue.scss +15 -15
- package/libs/css/style.vue.scss +188 -188
- package/libs/function/$parent.ts +21 -21
- package/libs/function/addUnit.ts +13 -13
- package/libs/function/color.ts +37 -37
- package/libs/function/colorGradient.ts +125 -125
- package/libs/function/debounce.ts +28 -28
- package/libs/function/deepClone.ts +39 -39
- package/libs/function/deepMerge.ts +34 -34
- package/libs/function/getParent.ts +59 -59
- package/libs/function/getRect.ts +26 -26
- package/libs/function/guid.ts +42 -42
- package/libs/function/md5.ts +391 -391
- package/libs/function/parent.ts +21 -21
- package/libs/function/queryParams.ts +60 -60
- package/libs/function/random.ts +16 -16
- package/libs/function/randomArray.ts +11 -11
- package/libs/function/route.ts +118 -118
- package/libs/function/styleUtils.ts +83 -83
- package/libs/function/sys.ts +15 -15
- package/libs/function/test.ts +285 -285
- package/libs/function/throttle.ts +31 -31
- package/libs/function/timeFormat.ts +54 -54
- package/libs/function/timeFrom.ts +48 -48
- package/libs/function/toast.ts +14 -14
- package/libs/function/trim.ts +21 -21
- package/libs/function/type2icon.ts +36 -36
- package/libs/hooks/index.ts +3 -3
- package/libs/hooks/useEmitter.ts +77 -77
- package/libs/hooks/useParent.ts +31 -31
- package/libs/hooks/useRect.ts +33 -33
- package/libs/index.ts +291 -291
- package/libs/request/auto-http.ts +76 -76
- package/libs/request/index.ts +223 -223
- package/libs/store/index.ts +88 -88
- package/libs/util/area.ts +1 -3771
- package/libs/util/async-validator.d.ts +62 -62
- package/libs/util/async-validator.js +1 -1368
- package/libs/util/calendar.d.ts +57 -0
- package/libs/util/calendar.js +1 -0
- package/libs/util/city.ts +1 -432
- package/libs/util/emitter.ts +102 -102
- package/libs/util/mitt.ts +115 -115
- package/libs/util/parent.ts +20 -20
- package/libs/util/province.ts +1 -37
- package/package.json +1 -1
- package/readme.md +239 -237
- package/theme.scss +38 -38
- package/types/components.d.ts +97 -96
- package/types/global.d.ts +295 -255
- package/types/ignore-errors.d.ts +30 -30
- package/types/index.d.ts +19 -19
- package/types/uni-app.d.ts +63 -63
|
@@ -1,556 +1,556 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<button
|
|
3
|
-
id="u-wave-btn"
|
|
4
|
-
class="u-btn u-line-1 u-fix-ios-appearance"
|
|
5
|
-
:class="[
|
|
6
|
-
'u-size-' + size,
|
|
7
|
-
plain ? 'u-btn--' + type + '--plain' : '',
|
|
8
|
-
loading ? 'u-loading' : '',
|
|
9
|
-
shape === 'circle' ? 'u-round-circle' : '',
|
|
10
|
-
hairLine ? showHairLineBorder : 'u-btn--bold-border',
|
|
11
|
-
'u-btn--' + type,
|
|
12
|
-
disabled ? `u-btn--${type}--disabled` : ''
|
|
13
|
-
]"
|
|
14
|
-
:hover-start-time="Number(hoverStartTime)"
|
|
15
|
-
:hover-stay-time="Number(hoverStayTime)"
|
|
16
|
-
:disabled="disabled"
|
|
17
|
-
:form-type="formType"
|
|
18
|
-
:open-type="disabled || loading ? undefined : openType"
|
|
19
|
-
:app-parameter="appParameter"
|
|
20
|
-
:hover-stop-propagation="hoverStopPropagation"
|
|
21
|
-
:send-message-title="sendMessageTitle"
|
|
22
|
-
send-message-path="sendMessagePath"
|
|
23
|
-
:lang="lang"
|
|
24
|
-
:data-name="dataName"
|
|
25
|
-
:session-from="sessionFrom"
|
|
26
|
-
:send-message-img="sendMessageImg"
|
|
27
|
-
:show-message-card="showMessageCard"
|
|
28
|
-
@getAuthorize="getAuthorize"
|
|
29
|
-
@getuserinfo="getuserinfo"
|
|
30
|
-
@contact="contact"
|
|
31
|
-
@getphonenumber="getphonenumber"
|
|
32
|
-
@error="error"
|
|
33
|
-
@launchapp="launchapp"
|
|
34
|
-
@opensetting="opensetting"
|
|
35
|
-
@chooseavatar="chooseavatar"
|
|
36
|
-
@agreeprivacyauthorization="agreeprivacyauthorization"
|
|
37
|
-
:style="[
|
|
38
|
-
customStyle,
|
|
39
|
-
{
|
|
40
|
-
overflow: ripple ? 'hidden' : 'visible'
|
|
41
|
-
}
|
|
42
|
-
]"
|
|
43
|
-
@tap.stop="click($event)"
|
|
44
|
-
:hover-class="getHoverClass"
|
|
45
|
-
:loading="loading"
|
|
46
|
-
>
|
|
47
|
-
<slot></slot>
|
|
48
|
-
<view
|
|
49
|
-
v-if="ripple"
|
|
50
|
-
class="u-wave-ripple"
|
|
51
|
-
:class="[waveActive ? 'u-wave-active' : '']"
|
|
52
|
-
:style="{
|
|
53
|
-
top: rippleTop + 'px',
|
|
54
|
-
left: rippleLeft + 'px',
|
|
55
|
-
width: fields.targetWidth + 'px',
|
|
56
|
-
height: fields.targetWidth + 'px',
|
|
57
|
-
'background-color': rippleBgColor || 'rgba(0, 0, 0, 0.15)'
|
|
58
|
-
}"
|
|
59
|
-
></view>
|
|
60
|
-
</button>
|
|
61
|
-
</template>
|
|
62
|
-
|
|
63
|
-
<script setup lang="ts">
|
|
64
|
-
import { ref, computed, nextTick } from 'vue';
|
|
65
|
-
import { $u } from '../../';
|
|
66
|
-
import { ButtonProps } from './types';
|
|
67
|
-
|
|
68
|
-
defineOptions({
|
|
69
|
-
name: 'u-button'
|
|
70
|
-
});
|
|
71
|
-
/**
|
|
72
|
-
* button 按钮
|
|
73
|
-
* @description Button 按钮
|
|
74
|
-
* @tutorial https://uviewpro.cn/zh/components/button.html
|
|
75
|
-
* @property {String} size 按钮的大小
|
|
76
|
-
* @property {Boolean} ripple 是否开启点击水波纹效果
|
|
77
|
-
* @property {String} ripple-bg-color 水波纹的背景色,ripple为true时有效
|
|
78
|
-
* @property {String} type 按钮的样式类型
|
|
79
|
-
* @property {Boolean} plain 按钮是否镂空,背景色透明
|
|
80
|
-
* @property {Boolean} disabled 是否禁用
|
|
81
|
-
* @property {Boolean} hair-line 是否显示按钮的细边框(默认true)
|
|
82
|
-
* @property {String} shape 按钮外观形状,见文档说明
|
|
83
|
-
* @property {Boolean} loading 按钮名称前是否带 loading 图标(App-nvue 平台,在 ios 上为雪花,Android上为圆圈)
|
|
84
|
-
* @property {String} form-type 用于 <form> 组件,点击分别会触发 <form> 组件的 submit/reset 事件
|
|
85
|
-
* @property {String} open-type 开放能力
|
|
86
|
-
* @property {String} data-name 额外传参参数,用于小程序的data-xxx属性,通过target.dataset.name获取
|
|
87
|
-
* @property {String} hover-class 指定按钮按下去的样式类。当 hover-class="none" 时,没有点击态效果(App-nvue 平台暂不支持)
|
|
88
|
-
* @property {Number} hover-start-time 按住后多久出现点击态,单位毫秒
|
|
89
|
-
* @property {Number} hover-stay-time 手指松开后点击态保留时间,单位毫秒
|
|
90
|
-
* @property {Object} custom-style 对按钮的自定义样式,对象形式,见文档说明
|
|
91
|
-
* @property {String} app-parameter 打开 APP 时,向 APP 传递的参数,open-type=launchApp时有效
|
|
92
|
-
* @property {Boolean} hover-stop-propagation 指定是否阻止本节点的祖先节点出现点击态,微信小程序有效
|
|
93
|
-
* @property {String} lang 指定返回用户信息的语言,zh_CN 简体中文,zh_TW 繁体中文,en 英文。只微信小程序有效
|
|
94
|
-
* @property {String} session-from 会话来源,open-type="contact"时有效。只微信小程序有效
|
|
95
|
-
* @property {String} send-message-title 会话内消息卡片标题,open-type="contact"时有效
|
|
96
|
-
* @property {String} send-message-path 会话内消息卡片点击跳转小程序路径,open-type="contact"时有效
|
|
97
|
-
* @property {String} send-message-img 会话内消息卡片图片,open-type="contact"时有效
|
|
98
|
-
* @property {Boolean} show-message-card 是否显示会话内消息卡片,open-type="contact"时有效
|
|
99
|
-
* @property {Number|String} throttle-time 节流,一定时间内只能触发一次,单位毫秒
|
|
100
|
-
* @property {String} scope 支付宝小程序,当 open-type 为 getAuthorize 时有效。可选值:'phoneNumber' | 'userInfo'
|
|
101
|
-
* @event {Function} click 按钮点击
|
|
102
|
-
* @event {Function} getphonenumber open-type="getPhoneNumber"时有效
|
|
103
|
-
* @event {Function} getuserinfo 用户点击该按钮时,会返回获取到的用户信息,从返回参数的detail中获取到的值同uni.getUserInfo
|
|
104
|
-
* @event {Function} error 当使用开放能力时,发生错误的回调
|
|
105
|
-
* @event {Function} opensetting 在打开授权设置页并关闭后回调
|
|
106
|
-
* @event {Function} launchapp 打开 APP 成功的回调
|
|
107
|
-
* @event {Function} contact 客服消息回调
|
|
108
|
-
* @event {Function} chooseavatar 头像选择回调
|
|
109
|
-
* @event {Function} agreeprivacyauthorization 用户点击允许授权回调
|
|
110
|
-
* @example <u-button>月落</u-button>
|
|
111
|
-
*/
|
|
112
|
-
|
|
113
|
-
const emit = defineEmits(['click', 'getuserinfo', 'contact', 'getphonenumber', 'error', 'launchapp', 'opensetting', 'chooseavatar', 'agreeprivacyauthorization']);
|
|
114
|
-
|
|
115
|
-
const props = defineProps(ButtonProps);
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* 按钮水波纹相关状态
|
|
119
|
-
*/
|
|
120
|
-
const rippleTop = ref(0); // 水波纹的起点Y坐标到按钮上边界的距离
|
|
121
|
-
const rippleLeft = ref(0); // 水波纹起点X坐标到按钮左边界的距离
|
|
122
|
-
const fields = ref<Record<string, any>>({}); // 波纹按钮节点信息
|
|
123
|
-
const waveActive = ref(false); // 激活水波纹
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* 当没有传bgColor变量时,按钮按下去的颜色类名
|
|
127
|
-
* @returns {string}
|
|
128
|
-
*/
|
|
129
|
-
const getHoverClass = computed(() => {
|
|
130
|
-
// 如果开启水波纹效果,则不启用hover-class效果
|
|
131
|
-
if (props.loading || props.disabled || props.ripple || props.hoverClass) return '';
|
|
132
|
-
let hoverClass = '';
|
|
133
|
-
hoverClass = props.plain ? 'u-' + props.type + '-plain-hover' : 'u-' + props.type + '-hover';
|
|
134
|
-
return hoverClass;
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* 在'primary', 'success', 'error', 'warning'类型下,不显示边框,否则会造成四角有毛刺现象
|
|
139
|
-
* @returns {string}
|
|
140
|
-
*/
|
|
141
|
-
const showHairLineBorder = computed(() => {
|
|
142
|
-
if (['primary', 'success', 'error', 'warning'].indexOf(props.type) >= 0 && !props.plain) {
|
|
143
|
-
return '';
|
|
144
|
-
} else {
|
|
145
|
-
return 'u-hairline-border';
|
|
146
|
-
}
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
* 按钮点击
|
|
151
|
-
* @param e 事件对象
|
|
152
|
-
* @emits click
|
|
153
|
-
*/
|
|
154
|
-
function click(e: any) {
|
|
155
|
-
$u.throttle(() => {
|
|
156
|
-
// 如果按钮时disabled和loading状态,不触发水波纹效果
|
|
157
|
-
if (props.loading === true || props.disabled === true) return;
|
|
158
|
-
// 是否开启水波纹效果
|
|
159
|
-
if (props.ripple) {
|
|
160
|
-
// 每次点击时,移除上一次的类,再次添加,才能触发动画效果
|
|
161
|
-
waveActive.value = false;
|
|
162
|
-
nextTick(() => {
|
|
163
|
-
getWaveQuery(e);
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
emit('click', e);
|
|
167
|
-
}, Number(props.throttleTime));
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
/**
|
|
171
|
-
* 查询按钮的节点信息
|
|
172
|
-
* @param e 事件对象
|
|
173
|
-
*/
|
|
174
|
-
function getWaveQuery(e: any) {
|
|
175
|
-
getElQuery().then((res: any[]) => {
|
|
176
|
-
// 查询返回的是一个数组节点
|
|
177
|
-
let data = res[0];
|
|
178
|
-
// 查询不到节点信息,不操作
|
|
179
|
-
if (!data.width || !data.width) return;
|
|
180
|
-
// 水波纹的最终形态是一个正方形(通过border-radius让其变为一个圆形),这里要保证正方形的边长等于按钮的最长边
|
|
181
|
-
// 最终的方形(变换后的圆形)才能覆盖整个按钮
|
|
182
|
-
data.targetWidth = data.height > data.width ? data.height : data.width;
|
|
183
|
-
if (!data.targetWidth) return;
|
|
184
|
-
fields.value = data;
|
|
185
|
-
let touchesX = '',
|
|
186
|
-
touchesY = '';
|
|
187
|
-
// #ifdef MP-BAIDU
|
|
188
|
-
// @ts-ignore
|
|
189
|
-
touchesX = e.changedTouches[0].clientX;
|
|
190
|
-
touchesY = e.changedTouches[0].clientY;
|
|
191
|
-
// #endif
|
|
192
|
-
// #ifdef MP-ALIPAY
|
|
193
|
-
// @ts-ignore
|
|
194
|
-
touchesX = e.detail.clientX;
|
|
195
|
-
touchesY = e.detail.clientY;
|
|
196
|
-
// #endif
|
|
197
|
-
// #ifndef MP-BAIDU || MP-ALIPAY
|
|
198
|
-
// @ts-ignore
|
|
199
|
-
touchesX = e.touches[0].clientX;
|
|
200
|
-
touchesY = e.touches[0].clientY;
|
|
201
|
-
// #endif
|
|
202
|
-
// 获取触摸点相对于按钮上边和左边的x和y坐标,原理是通过屏幕的触摸点(touchesY),减去按钮的上边界data.top
|
|
203
|
-
// 但是由于`transform-origin`默认是center,所以这里再减去半径才是水波纹view应该的位置
|
|
204
|
-
// 总的来说,就是把水波纹的矩形(变换后的圆形)的中心点,移动到我们的触摸点位置
|
|
205
|
-
rippleTop.value = Number(touchesY) - data.top - data.targetWidth / 2;
|
|
206
|
-
rippleLeft.value = Number(touchesX) - data.left - data.targetWidth / 2;
|
|
207
|
-
nextTick(() => {
|
|
208
|
-
waveActive.value = true;
|
|
209
|
-
});
|
|
210
|
-
});
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
/**
|
|
214
|
-
* 获取节点信息
|
|
215
|
-
* @returns {Promise<any[]>}
|
|
216
|
-
*/
|
|
217
|
-
function getElQuery(): Promise<any[]> {
|
|
218
|
-
return new Promise(resolve => {
|
|
219
|
-
let queryInfo: any = '';
|
|
220
|
-
// 获取元素节点信息,请查看uniapp相关文档
|
|
221
|
-
// https://uniapp.dcloud.io/api/ui/nodes-info?id=nodesrefboundingclientrect
|
|
222
|
-
// @ts-ignore
|
|
223
|
-
queryInfo = uni.createSelectorQuery().in(null);
|
|
224
|
-
// #ifdef MP-ALIPAY
|
|
225
|
-
// @ts-ignore
|
|
226
|
-
queryInfo = uni.createSelectorQuery();
|
|
227
|
-
// #endif
|
|
228
|
-
queryInfo.select('.u-btn').boundingClientRect();
|
|
229
|
-
queryInfo.exec((data: any) => {
|
|
230
|
-
resolve(data);
|
|
231
|
-
});
|
|
232
|
-
});
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
// 下面为对接uniapp官方按钮开放能力事件回调的对接
|
|
236
|
-
/**
|
|
237
|
-
* open-type="getPhoneNumber"时有效
|
|
238
|
-
*/
|
|
239
|
-
function getphonenumber(event: any) {
|
|
240
|
-
emit('getphonenumber', event);
|
|
241
|
-
}
|
|
242
|
-
/**
|
|
243
|
-
* 用户点击该按钮时,会返回获取到的用户信息,从返回参数的detail中获取到的值同uni.getUserInfo
|
|
244
|
-
*/
|
|
245
|
-
function getuserinfo(event: any) {
|
|
246
|
-
emit('getuserinfo', event);
|
|
247
|
-
}
|
|
248
|
-
/**
|
|
249
|
-
* 当使用开放能力时,发生错误的回调
|
|
250
|
-
*/
|
|
251
|
-
function error(event: any) {
|
|
252
|
-
emit('error', event);
|
|
253
|
-
}
|
|
254
|
-
/**
|
|
255
|
-
* 在打开授权设置页并关闭后回调
|
|
256
|
-
*/
|
|
257
|
-
function opensetting(event: any) {
|
|
258
|
-
emit('opensetting', event);
|
|
259
|
-
}
|
|
260
|
-
/**
|
|
261
|
-
* 打开 APP 成功的回调
|
|
262
|
-
*/
|
|
263
|
-
function launchapp(event: any) {
|
|
264
|
-
emit('launchapp', event);
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
/**
|
|
268
|
-
* 支付宝小程序授权
|
|
269
|
-
* @param event
|
|
270
|
-
*/
|
|
271
|
-
function getAuthorize(event: any) {
|
|
272
|
-
if (props.scope === 'phoneNumber') {
|
|
273
|
-
getphonenumber(event);
|
|
274
|
-
} else if (props.scope === 'userInfo') {
|
|
275
|
-
getuserinfo(event);
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
/**
|
|
280
|
-
* 客服消息回调
|
|
281
|
-
* @param event
|
|
282
|
-
*/
|
|
283
|
-
function contact(event: any) {
|
|
284
|
-
emit('contact', event);
|
|
285
|
-
}
|
|
286
|
-
/**
|
|
287
|
-
* 头像选择回调
|
|
288
|
-
* @param event
|
|
289
|
-
*/
|
|
290
|
-
function chooseavatar(event: any) {
|
|
291
|
-
emit('chooseavatar', event);
|
|
292
|
-
}
|
|
293
|
-
/**
|
|
294
|
-
* 用户点击允许授权回调
|
|
295
|
-
* @param event
|
|
296
|
-
*/
|
|
297
|
-
function agreeprivacyauthorization(event: any) {
|
|
298
|
-
emit('agreeprivacyauthorization', event);
|
|
299
|
-
}
|
|
300
|
-
</script>
|
|
301
|
-
|
|
302
|
-
<style scoped lang="scss">
|
|
303
|
-
@import '../../libs/css/style.components.scss';
|
|
304
|
-
.u-btn::after {
|
|
305
|
-
border: none;
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
.u-btn {
|
|
309
|
-
position: relative;
|
|
310
|
-
border: 0;
|
|
311
|
-
//border-radius: 10rpx;
|
|
312
|
-
/* #ifndef APP-NVUE */
|
|
313
|
-
display: inline-flex;
|
|
314
|
-
/* #endif */
|
|
315
|
-
// 避免边框某些场景可能被“裁剪”,不能设置为hidden
|
|
316
|
-
overflow: visible;
|
|
317
|
-
line-height: 1;
|
|
318
|
-
@include vue-flex;
|
|
319
|
-
align-items: center;
|
|
320
|
-
justify-content: center;
|
|
321
|
-
cursor: pointer;
|
|
322
|
-
padding: 0 40rpx;
|
|
323
|
-
z-index: 1;
|
|
324
|
-
box-sizing: border-box;
|
|
325
|
-
transition: all 0.15s;
|
|
326
|
-
|
|
327
|
-
&--bold-border {
|
|
328
|
-
border: 1px solid #ffffff;
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
&--default {
|
|
332
|
-
color: $u-content-color;
|
|
333
|
-
border-color: #c0c4cc;
|
|
334
|
-
background-color: #ffffff;
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
&--primary {
|
|
338
|
-
color: #ffffff;
|
|
339
|
-
border-color: $u-type-primary;
|
|
340
|
-
background-color: $u-type-primary;
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
&--success {
|
|
344
|
-
color: #ffffff;
|
|
345
|
-
border-color: $u-type-success;
|
|
346
|
-
background-color: $u-type-success;
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
&--error {
|
|
350
|
-
color: #ffffff;
|
|
351
|
-
border-color: $u-type-error;
|
|
352
|
-
background-color: $u-type-error;
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
&--warning {
|
|
356
|
-
color: #ffffff;
|
|
357
|
-
border-color: $u-type-warning;
|
|
358
|
-
background-color: $u-type-warning;
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
&--default--disabled {
|
|
362
|
-
color: #ffffff;
|
|
363
|
-
border-color: #e4e7ed;
|
|
364
|
-
background-color: #ffffff;
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
&--primary--disabled {
|
|
368
|
-
color: #ffffff !important;
|
|
369
|
-
border-color: $u-type-primary-disabled !important;
|
|
370
|
-
background-color: $u-type-primary-disabled !important;
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
&--success--disabled {
|
|
374
|
-
color: #ffffff !important;
|
|
375
|
-
border-color: $u-type-success-disabled !important;
|
|
376
|
-
background-color: $u-type-success-disabled !important;
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
&--error--disabled {
|
|
380
|
-
color: #ffffff !important;
|
|
381
|
-
border-color: $u-type-error-disabled !important;
|
|
382
|
-
background-color: $u-type-error-disabled !important;
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
&--warning--disabled {
|
|
386
|
-
color: #ffffff !important;
|
|
387
|
-
border-color: $u-type-warning-disabled !important;
|
|
388
|
-
background-color: $u-type-warning-disabled !important;
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
&--primary--plain {
|
|
392
|
-
color: $u-type-primary !important;
|
|
393
|
-
border-color: $u-type-primary-disabled !important;
|
|
394
|
-
background-color: $u-type-primary-light !important;
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
&--success--plain {
|
|
398
|
-
color: $u-type-success !important;
|
|
399
|
-
border-color: $u-type-success-disabled !important;
|
|
400
|
-
background-color: $u-type-success-light !important;
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
&--error--plain {
|
|
404
|
-
color: $u-type-error !important;
|
|
405
|
-
border-color: $u-type-error-disabled !important;
|
|
406
|
-
background-color: $u-type-error-light !important;
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
&--warning--plain {
|
|
410
|
-
color: $u-type-warning !important;
|
|
411
|
-
border-color: $u-type-warning-disabled !important;
|
|
412
|
-
background-color: $u-type-warning-light !important;
|
|
413
|
-
}
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
.u-hairline-border:after {
|
|
417
|
-
content: ' ';
|
|
418
|
-
position: absolute;
|
|
419
|
-
pointer-events: none;
|
|
420
|
-
// 设置为border-box,意味着下面的scale缩小为0.5,实际上缩小的是伪元素的内容(border-box意味着内容不含border)
|
|
421
|
-
box-sizing: border-box;
|
|
422
|
-
// 中心点作为变形(scale())的原点
|
|
423
|
-
-webkit-transform-origin: 0 0;
|
|
424
|
-
transform-origin: 0 0;
|
|
425
|
-
left: 0;
|
|
426
|
-
top: 0;
|
|
427
|
-
width: 199.8%;
|
|
428
|
-
height: 199.7%;
|
|
429
|
-
-webkit-transform: scale(0.5, 0.5);
|
|
430
|
-
transform: scale(0.5, 0.5);
|
|
431
|
-
border: 1px solid currentColor;
|
|
432
|
-
z-index: 1;
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
.u-wave-ripple {
|
|
436
|
-
z-index: 0;
|
|
437
|
-
position: absolute;
|
|
438
|
-
border-radius: 100%;
|
|
439
|
-
background-clip: padding-box;
|
|
440
|
-
pointer-events: none;
|
|
441
|
-
user-select: none;
|
|
442
|
-
transform: scale(0);
|
|
443
|
-
opacity: 1;
|
|
444
|
-
transform-origin: center;
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
.u-wave-ripple.u-wave-active {
|
|
448
|
-
opacity: 0;
|
|
449
|
-
transform: scale(2);
|
|
450
|
-
transition:
|
|
451
|
-
opacity 1s linear,
|
|
452
|
-
transform 0.4s linear;
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
.u-round-circle {
|
|
456
|
-
border-radius: 100rpx;
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
.u-round-circle::after {
|
|
460
|
-
border-radius: 100rpx;
|
|
461
|
-
}
|
|
462
|
-
|
|
463
|
-
.u-loading::after {
|
|
464
|
-
background-color: hsla(0, 0%, 100%, 0.35);
|
|
465
|
-
}
|
|
466
|
-
|
|
467
|
-
.u-size-default {
|
|
468
|
-
font-size: 30rpx;
|
|
469
|
-
height: 80rpx;
|
|
470
|
-
line-height: 80rpx;
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
.u-size-medium {
|
|
474
|
-
/* #ifndef APP-NVUE */
|
|
475
|
-
display: inline-flex;
|
|
476
|
-
/* #endif */
|
|
477
|
-
width: auto;
|
|
478
|
-
font-size: 26rpx;
|
|
479
|
-
height: 70rpx;
|
|
480
|
-
line-height: 70rpx;
|
|
481
|
-
padding: 0 80rpx;
|
|
482
|
-
}
|
|
483
|
-
|
|
484
|
-
.u-size-mini {
|
|
485
|
-
/* #ifndef APP-NVUE */
|
|
486
|
-
display: inline-flex;
|
|
487
|
-
/* #endif */
|
|
488
|
-
width: auto;
|
|
489
|
-
font-size: 22rpx;
|
|
490
|
-
padding-top: 1px;
|
|
491
|
-
height: 50rpx;
|
|
492
|
-
line-height: 50rpx;
|
|
493
|
-
padding: 0 20rpx;
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
.u-primary-plain-hover {
|
|
497
|
-
color: #ffffff !important;
|
|
498
|
-
background: $u-type-primary-dark !important;
|
|
499
|
-
}
|
|
500
|
-
|
|
501
|
-
.u-default-plain-hover {
|
|
502
|
-
color: $u-type-primary-dark !important;
|
|
503
|
-
background: $u-type-primary-light !important;
|
|
504
|
-
}
|
|
505
|
-
|
|
506
|
-
.u-success-plain-hover {
|
|
507
|
-
color: #ffffff !important;
|
|
508
|
-
background: $u-type-success-dark !important;
|
|
509
|
-
}
|
|
510
|
-
|
|
511
|
-
.u-warning-plain-hover {
|
|
512
|
-
color: #ffffff !important;
|
|
513
|
-
background: $u-type-warning-dark !important;
|
|
514
|
-
}
|
|
515
|
-
|
|
516
|
-
.u-error-plain-hover {
|
|
517
|
-
color: #ffffff !important;
|
|
518
|
-
background: $u-type-error-dark !important;
|
|
519
|
-
}
|
|
520
|
-
|
|
521
|
-
.u-info-plain-hover {
|
|
522
|
-
color: #ffffff !important;
|
|
523
|
-
background: $u-type-info-dark !important;
|
|
524
|
-
}
|
|
525
|
-
|
|
526
|
-
.u-default-hover {
|
|
527
|
-
color: $u-type-primary-dark !important;
|
|
528
|
-
border-color: $u-type-primary-dark !important;
|
|
529
|
-
background-color: $u-type-primary-light !important;
|
|
530
|
-
}
|
|
531
|
-
|
|
532
|
-
.u-primary-hover {
|
|
533
|
-
background: $u-type-primary-dark !important;
|
|
534
|
-
color: #fff;
|
|
535
|
-
}
|
|
536
|
-
|
|
537
|
-
.u-success-hover {
|
|
538
|
-
background: $u-type-success-dark !important;
|
|
539
|
-
color: #fff;
|
|
540
|
-
}
|
|
541
|
-
|
|
542
|
-
.u-info-hover {
|
|
543
|
-
background: $u-type-info-dark !important;
|
|
544
|
-
color: #fff;
|
|
545
|
-
}
|
|
546
|
-
|
|
547
|
-
.u-warning-hover {
|
|
548
|
-
background: $u-type-warning-dark !important;
|
|
549
|
-
color: #fff;
|
|
550
|
-
}
|
|
551
|
-
|
|
552
|
-
.u-error-hover {
|
|
553
|
-
background: $u-type-error-dark !important;
|
|
554
|
-
color: #fff;
|
|
555
|
-
}
|
|
556
|
-
</style>
|
|
1
|
+
<template>
|
|
2
|
+
<button
|
|
3
|
+
id="u-wave-btn"
|
|
4
|
+
class="u-btn u-line-1 u-fix-ios-appearance"
|
|
5
|
+
:class="[
|
|
6
|
+
'u-size-' + size,
|
|
7
|
+
plain ? 'u-btn--' + type + '--plain' : '',
|
|
8
|
+
loading ? 'u-loading' : '',
|
|
9
|
+
shape === 'circle' ? 'u-round-circle' : '',
|
|
10
|
+
hairLine ? showHairLineBorder : 'u-btn--bold-border',
|
|
11
|
+
'u-btn--' + type,
|
|
12
|
+
disabled ? `u-btn--${type}--disabled` : ''
|
|
13
|
+
]"
|
|
14
|
+
:hover-start-time="Number(hoverStartTime)"
|
|
15
|
+
:hover-stay-time="Number(hoverStayTime)"
|
|
16
|
+
:disabled="disabled"
|
|
17
|
+
:form-type="formType"
|
|
18
|
+
:open-type="disabled || loading ? undefined : openType"
|
|
19
|
+
:app-parameter="appParameter"
|
|
20
|
+
:hover-stop-propagation="hoverStopPropagation"
|
|
21
|
+
:send-message-title="sendMessageTitle"
|
|
22
|
+
send-message-path="sendMessagePath"
|
|
23
|
+
:lang="lang"
|
|
24
|
+
:data-name="dataName"
|
|
25
|
+
:session-from="sessionFrom"
|
|
26
|
+
:send-message-img="sendMessageImg"
|
|
27
|
+
:show-message-card="showMessageCard"
|
|
28
|
+
@getAuthorize="getAuthorize"
|
|
29
|
+
@getuserinfo="getuserinfo"
|
|
30
|
+
@contact="contact"
|
|
31
|
+
@getphonenumber="getphonenumber"
|
|
32
|
+
@error="error"
|
|
33
|
+
@launchapp="launchapp"
|
|
34
|
+
@opensetting="opensetting"
|
|
35
|
+
@chooseavatar="chooseavatar"
|
|
36
|
+
@agreeprivacyauthorization="agreeprivacyauthorization"
|
|
37
|
+
:style="[
|
|
38
|
+
customStyle,
|
|
39
|
+
{
|
|
40
|
+
overflow: ripple ? 'hidden' : 'visible'
|
|
41
|
+
}
|
|
42
|
+
]"
|
|
43
|
+
@tap.stop="click($event)"
|
|
44
|
+
:hover-class="getHoverClass"
|
|
45
|
+
:loading="loading"
|
|
46
|
+
>
|
|
47
|
+
<slot></slot>
|
|
48
|
+
<view
|
|
49
|
+
v-if="ripple"
|
|
50
|
+
class="u-wave-ripple"
|
|
51
|
+
:class="[waveActive ? 'u-wave-active' : '']"
|
|
52
|
+
:style="{
|
|
53
|
+
top: rippleTop + 'px',
|
|
54
|
+
left: rippleLeft + 'px',
|
|
55
|
+
width: fields.targetWidth + 'px',
|
|
56
|
+
height: fields.targetWidth + 'px',
|
|
57
|
+
'background-color': rippleBgColor || 'rgba(0, 0, 0, 0.15)'
|
|
58
|
+
}"
|
|
59
|
+
></view>
|
|
60
|
+
</button>
|
|
61
|
+
</template>
|
|
62
|
+
|
|
63
|
+
<script setup lang="ts">
|
|
64
|
+
import { ref, computed, nextTick } from 'vue';
|
|
65
|
+
import { $u } from '../../';
|
|
66
|
+
import { ButtonProps } from './types';
|
|
67
|
+
|
|
68
|
+
defineOptions({
|
|
69
|
+
name: 'u-button'
|
|
70
|
+
});
|
|
71
|
+
/**
|
|
72
|
+
* button 按钮
|
|
73
|
+
* @description Button 按钮
|
|
74
|
+
* @tutorial https://uviewpro.cn/zh/components/button.html
|
|
75
|
+
* @property {String} size 按钮的大小
|
|
76
|
+
* @property {Boolean} ripple 是否开启点击水波纹效果
|
|
77
|
+
* @property {String} ripple-bg-color 水波纹的背景色,ripple为true时有效
|
|
78
|
+
* @property {String} type 按钮的样式类型
|
|
79
|
+
* @property {Boolean} plain 按钮是否镂空,背景色透明
|
|
80
|
+
* @property {Boolean} disabled 是否禁用
|
|
81
|
+
* @property {Boolean} hair-line 是否显示按钮的细边框(默认true)
|
|
82
|
+
* @property {String} shape 按钮外观形状,见文档说明
|
|
83
|
+
* @property {Boolean} loading 按钮名称前是否带 loading 图标(App-nvue 平台,在 ios 上为雪花,Android上为圆圈)
|
|
84
|
+
* @property {String} form-type 用于 <form> 组件,点击分别会触发 <form> 组件的 submit/reset 事件
|
|
85
|
+
* @property {String} open-type 开放能力
|
|
86
|
+
* @property {String} data-name 额外传参参数,用于小程序的data-xxx属性,通过target.dataset.name获取
|
|
87
|
+
* @property {String} hover-class 指定按钮按下去的样式类。当 hover-class="none" 时,没有点击态效果(App-nvue 平台暂不支持)
|
|
88
|
+
* @property {Number} hover-start-time 按住后多久出现点击态,单位毫秒
|
|
89
|
+
* @property {Number} hover-stay-time 手指松开后点击态保留时间,单位毫秒
|
|
90
|
+
* @property {Object} custom-style 对按钮的自定义样式,对象形式,见文档说明
|
|
91
|
+
* @property {String} app-parameter 打开 APP 时,向 APP 传递的参数,open-type=launchApp时有效
|
|
92
|
+
* @property {Boolean} hover-stop-propagation 指定是否阻止本节点的祖先节点出现点击态,微信小程序有效
|
|
93
|
+
* @property {String} lang 指定返回用户信息的语言,zh_CN 简体中文,zh_TW 繁体中文,en 英文。只微信小程序有效
|
|
94
|
+
* @property {String} session-from 会话来源,open-type="contact"时有效。只微信小程序有效
|
|
95
|
+
* @property {String} send-message-title 会话内消息卡片标题,open-type="contact"时有效
|
|
96
|
+
* @property {String} send-message-path 会话内消息卡片点击跳转小程序路径,open-type="contact"时有效
|
|
97
|
+
* @property {String} send-message-img 会话内消息卡片图片,open-type="contact"时有效
|
|
98
|
+
* @property {Boolean} show-message-card 是否显示会话内消息卡片,open-type="contact"时有效
|
|
99
|
+
* @property {Number|String} throttle-time 节流,一定时间内只能触发一次,单位毫秒
|
|
100
|
+
* @property {String} scope 支付宝小程序,当 open-type 为 getAuthorize 时有效。可选值:'phoneNumber' | 'userInfo'
|
|
101
|
+
* @event {Function} click 按钮点击
|
|
102
|
+
* @event {Function} getphonenumber open-type="getPhoneNumber"时有效
|
|
103
|
+
* @event {Function} getuserinfo 用户点击该按钮时,会返回获取到的用户信息,从返回参数的detail中获取到的值同uni.getUserInfo
|
|
104
|
+
* @event {Function} error 当使用开放能力时,发生错误的回调
|
|
105
|
+
* @event {Function} opensetting 在打开授权设置页并关闭后回调
|
|
106
|
+
* @event {Function} launchapp 打开 APP 成功的回调
|
|
107
|
+
* @event {Function} contact 客服消息回调
|
|
108
|
+
* @event {Function} chooseavatar 头像选择回调
|
|
109
|
+
* @event {Function} agreeprivacyauthorization 用户点击允许授权回调
|
|
110
|
+
* @example <u-button>月落</u-button>
|
|
111
|
+
*/
|
|
112
|
+
|
|
113
|
+
const emit = defineEmits(['click', 'getuserinfo', 'contact', 'getphonenumber', 'error', 'launchapp', 'opensetting', 'chooseavatar', 'agreeprivacyauthorization']);
|
|
114
|
+
|
|
115
|
+
const props = defineProps(ButtonProps);
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* 按钮水波纹相关状态
|
|
119
|
+
*/
|
|
120
|
+
const rippleTop = ref(0); // 水波纹的起点Y坐标到按钮上边界的距离
|
|
121
|
+
const rippleLeft = ref(0); // 水波纹起点X坐标到按钮左边界的距离
|
|
122
|
+
const fields = ref<Record<string, any>>({}); // 波纹按钮节点信息
|
|
123
|
+
const waveActive = ref(false); // 激活水波纹
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* 当没有传bgColor变量时,按钮按下去的颜色类名
|
|
127
|
+
* @returns {string}
|
|
128
|
+
*/
|
|
129
|
+
const getHoverClass = computed(() => {
|
|
130
|
+
// 如果开启水波纹效果,则不启用hover-class效果
|
|
131
|
+
if (props.loading || props.disabled || props.ripple || props.hoverClass) return '';
|
|
132
|
+
let hoverClass = '';
|
|
133
|
+
hoverClass = props.plain ? 'u-' + props.type + '-plain-hover' : 'u-' + props.type + '-hover';
|
|
134
|
+
return hoverClass;
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* 在'primary', 'success', 'error', 'warning'类型下,不显示边框,否则会造成四角有毛刺现象
|
|
139
|
+
* @returns {string}
|
|
140
|
+
*/
|
|
141
|
+
const showHairLineBorder = computed(() => {
|
|
142
|
+
if (['primary', 'success', 'error', 'warning'].indexOf(props.type) >= 0 && !props.plain) {
|
|
143
|
+
return '';
|
|
144
|
+
} else {
|
|
145
|
+
return 'u-hairline-border';
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* 按钮点击
|
|
151
|
+
* @param e 事件对象
|
|
152
|
+
* @emits click
|
|
153
|
+
*/
|
|
154
|
+
function click(e: any) {
|
|
155
|
+
$u.throttle(() => {
|
|
156
|
+
// 如果按钮时disabled和loading状态,不触发水波纹效果
|
|
157
|
+
if (props.loading === true || props.disabled === true) return;
|
|
158
|
+
// 是否开启水波纹效果
|
|
159
|
+
if (props.ripple) {
|
|
160
|
+
// 每次点击时,移除上一次的类,再次添加,才能触发动画效果
|
|
161
|
+
waveActive.value = false;
|
|
162
|
+
nextTick(() => {
|
|
163
|
+
getWaveQuery(e);
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
emit('click', e);
|
|
167
|
+
}, Number(props.throttleTime));
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* 查询按钮的节点信息
|
|
172
|
+
* @param e 事件对象
|
|
173
|
+
*/
|
|
174
|
+
function getWaveQuery(e: any) {
|
|
175
|
+
getElQuery().then((res: any[]) => {
|
|
176
|
+
// 查询返回的是一个数组节点
|
|
177
|
+
let data = res[0];
|
|
178
|
+
// 查询不到节点信息,不操作
|
|
179
|
+
if (!data.width || !data.width) return;
|
|
180
|
+
// 水波纹的最终形态是一个正方形(通过border-radius让其变为一个圆形),这里要保证正方形的边长等于按钮的最长边
|
|
181
|
+
// 最终的方形(变换后的圆形)才能覆盖整个按钮
|
|
182
|
+
data.targetWidth = data.height > data.width ? data.height : data.width;
|
|
183
|
+
if (!data.targetWidth) return;
|
|
184
|
+
fields.value = data;
|
|
185
|
+
let touchesX = '',
|
|
186
|
+
touchesY = '';
|
|
187
|
+
// #ifdef MP-BAIDU
|
|
188
|
+
// @ts-ignore
|
|
189
|
+
touchesX = e.changedTouches[0].clientX;
|
|
190
|
+
touchesY = e.changedTouches[0].clientY;
|
|
191
|
+
// #endif
|
|
192
|
+
// #ifdef MP-ALIPAY
|
|
193
|
+
// @ts-ignore
|
|
194
|
+
touchesX = e.detail.clientX;
|
|
195
|
+
touchesY = e.detail.clientY;
|
|
196
|
+
// #endif
|
|
197
|
+
// #ifndef MP-BAIDU || MP-ALIPAY
|
|
198
|
+
// @ts-ignore
|
|
199
|
+
touchesX = e.touches[0].clientX;
|
|
200
|
+
touchesY = e.touches[0].clientY;
|
|
201
|
+
// #endif
|
|
202
|
+
// 获取触摸点相对于按钮上边和左边的x和y坐标,原理是通过屏幕的触摸点(touchesY),减去按钮的上边界data.top
|
|
203
|
+
// 但是由于`transform-origin`默认是center,所以这里再减去半径才是水波纹view应该的位置
|
|
204
|
+
// 总的来说,就是把水波纹的矩形(变换后的圆形)的中心点,移动到我们的触摸点位置
|
|
205
|
+
rippleTop.value = Number(touchesY) - data.top - data.targetWidth / 2;
|
|
206
|
+
rippleLeft.value = Number(touchesX) - data.left - data.targetWidth / 2;
|
|
207
|
+
nextTick(() => {
|
|
208
|
+
waveActive.value = true;
|
|
209
|
+
});
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* 获取节点信息
|
|
215
|
+
* @returns {Promise<any[]>}
|
|
216
|
+
*/
|
|
217
|
+
function getElQuery(): Promise<any[]> {
|
|
218
|
+
return new Promise(resolve => {
|
|
219
|
+
let queryInfo: any = '';
|
|
220
|
+
// 获取元素节点信息,请查看uniapp相关文档
|
|
221
|
+
// https://uniapp.dcloud.io/api/ui/nodes-info?id=nodesrefboundingclientrect
|
|
222
|
+
// @ts-ignore
|
|
223
|
+
queryInfo = uni.createSelectorQuery().in(null);
|
|
224
|
+
// #ifdef MP-ALIPAY
|
|
225
|
+
// @ts-ignore
|
|
226
|
+
queryInfo = uni.createSelectorQuery();
|
|
227
|
+
// #endif
|
|
228
|
+
queryInfo.select('.u-btn').boundingClientRect();
|
|
229
|
+
queryInfo.exec((data: any) => {
|
|
230
|
+
resolve(data);
|
|
231
|
+
});
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// 下面为对接uniapp官方按钮开放能力事件回调的对接
|
|
236
|
+
/**
|
|
237
|
+
* open-type="getPhoneNumber"时有效
|
|
238
|
+
*/
|
|
239
|
+
function getphonenumber(event: any) {
|
|
240
|
+
emit('getphonenumber', event);
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* 用户点击该按钮时,会返回获取到的用户信息,从返回参数的detail中获取到的值同uni.getUserInfo
|
|
244
|
+
*/
|
|
245
|
+
function getuserinfo(event: any) {
|
|
246
|
+
emit('getuserinfo', event);
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* 当使用开放能力时,发生错误的回调
|
|
250
|
+
*/
|
|
251
|
+
function error(event: any) {
|
|
252
|
+
emit('error', event);
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* 在打开授权设置页并关闭后回调
|
|
256
|
+
*/
|
|
257
|
+
function opensetting(event: any) {
|
|
258
|
+
emit('opensetting', event);
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* 打开 APP 成功的回调
|
|
262
|
+
*/
|
|
263
|
+
function launchapp(event: any) {
|
|
264
|
+
emit('launchapp', event);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* 支付宝小程序授权
|
|
269
|
+
* @param event
|
|
270
|
+
*/
|
|
271
|
+
function getAuthorize(event: any) {
|
|
272
|
+
if (props.scope === 'phoneNumber') {
|
|
273
|
+
getphonenumber(event);
|
|
274
|
+
} else if (props.scope === 'userInfo') {
|
|
275
|
+
getuserinfo(event);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* 客服消息回调
|
|
281
|
+
* @param event
|
|
282
|
+
*/
|
|
283
|
+
function contact(event: any) {
|
|
284
|
+
emit('contact', event);
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* 头像选择回调
|
|
288
|
+
* @param event
|
|
289
|
+
*/
|
|
290
|
+
function chooseavatar(event: any) {
|
|
291
|
+
emit('chooseavatar', event);
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* 用户点击允许授权回调
|
|
295
|
+
* @param event
|
|
296
|
+
*/
|
|
297
|
+
function agreeprivacyauthorization(event: any) {
|
|
298
|
+
emit('agreeprivacyauthorization', event);
|
|
299
|
+
}
|
|
300
|
+
</script>
|
|
301
|
+
|
|
302
|
+
<style scoped lang="scss">
|
|
303
|
+
@import '../../libs/css/style.components.scss';
|
|
304
|
+
.u-btn::after {
|
|
305
|
+
border: none;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
.u-btn {
|
|
309
|
+
position: relative;
|
|
310
|
+
border: 0;
|
|
311
|
+
//border-radius: 10rpx;
|
|
312
|
+
/* #ifndef APP-NVUE */
|
|
313
|
+
display: inline-flex;
|
|
314
|
+
/* #endif */
|
|
315
|
+
// 避免边框某些场景可能被“裁剪”,不能设置为hidden
|
|
316
|
+
overflow: visible;
|
|
317
|
+
line-height: 1;
|
|
318
|
+
@include vue-flex;
|
|
319
|
+
align-items: center;
|
|
320
|
+
justify-content: center;
|
|
321
|
+
cursor: pointer;
|
|
322
|
+
padding: 0 40rpx;
|
|
323
|
+
z-index: 1;
|
|
324
|
+
box-sizing: border-box;
|
|
325
|
+
transition: all 0.15s;
|
|
326
|
+
|
|
327
|
+
&--bold-border {
|
|
328
|
+
border: 1px solid #ffffff;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
&--default {
|
|
332
|
+
color: $u-content-color;
|
|
333
|
+
border-color: #c0c4cc;
|
|
334
|
+
background-color: #ffffff;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
&--primary {
|
|
338
|
+
color: #ffffff;
|
|
339
|
+
border-color: $u-type-primary;
|
|
340
|
+
background-color: $u-type-primary;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
&--success {
|
|
344
|
+
color: #ffffff;
|
|
345
|
+
border-color: $u-type-success;
|
|
346
|
+
background-color: $u-type-success;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
&--error {
|
|
350
|
+
color: #ffffff;
|
|
351
|
+
border-color: $u-type-error;
|
|
352
|
+
background-color: $u-type-error;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
&--warning {
|
|
356
|
+
color: #ffffff;
|
|
357
|
+
border-color: $u-type-warning;
|
|
358
|
+
background-color: $u-type-warning;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
&--default--disabled {
|
|
362
|
+
color: #ffffff;
|
|
363
|
+
border-color: #e4e7ed;
|
|
364
|
+
background-color: #ffffff;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
&--primary--disabled {
|
|
368
|
+
color: #ffffff !important;
|
|
369
|
+
border-color: $u-type-primary-disabled !important;
|
|
370
|
+
background-color: $u-type-primary-disabled !important;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
&--success--disabled {
|
|
374
|
+
color: #ffffff !important;
|
|
375
|
+
border-color: $u-type-success-disabled !important;
|
|
376
|
+
background-color: $u-type-success-disabled !important;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
&--error--disabled {
|
|
380
|
+
color: #ffffff !important;
|
|
381
|
+
border-color: $u-type-error-disabled !important;
|
|
382
|
+
background-color: $u-type-error-disabled !important;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
&--warning--disabled {
|
|
386
|
+
color: #ffffff !important;
|
|
387
|
+
border-color: $u-type-warning-disabled !important;
|
|
388
|
+
background-color: $u-type-warning-disabled !important;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
&--primary--plain {
|
|
392
|
+
color: $u-type-primary !important;
|
|
393
|
+
border-color: $u-type-primary-disabled !important;
|
|
394
|
+
background-color: $u-type-primary-light !important;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
&--success--plain {
|
|
398
|
+
color: $u-type-success !important;
|
|
399
|
+
border-color: $u-type-success-disabled !important;
|
|
400
|
+
background-color: $u-type-success-light !important;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
&--error--plain {
|
|
404
|
+
color: $u-type-error !important;
|
|
405
|
+
border-color: $u-type-error-disabled !important;
|
|
406
|
+
background-color: $u-type-error-light !important;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
&--warning--plain {
|
|
410
|
+
color: $u-type-warning !important;
|
|
411
|
+
border-color: $u-type-warning-disabled !important;
|
|
412
|
+
background-color: $u-type-warning-light !important;
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
.u-hairline-border:after {
|
|
417
|
+
content: ' ';
|
|
418
|
+
position: absolute;
|
|
419
|
+
pointer-events: none;
|
|
420
|
+
// 设置为border-box,意味着下面的scale缩小为0.5,实际上缩小的是伪元素的内容(border-box意味着内容不含border)
|
|
421
|
+
box-sizing: border-box;
|
|
422
|
+
// 中心点作为变形(scale())的原点
|
|
423
|
+
-webkit-transform-origin: 0 0;
|
|
424
|
+
transform-origin: 0 0;
|
|
425
|
+
left: 0;
|
|
426
|
+
top: 0;
|
|
427
|
+
width: 199.8%;
|
|
428
|
+
height: 199.7%;
|
|
429
|
+
-webkit-transform: scale(0.5, 0.5);
|
|
430
|
+
transform: scale(0.5, 0.5);
|
|
431
|
+
border: 1px solid currentColor;
|
|
432
|
+
z-index: 1;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
.u-wave-ripple {
|
|
436
|
+
z-index: 0;
|
|
437
|
+
position: absolute;
|
|
438
|
+
border-radius: 100%;
|
|
439
|
+
background-clip: padding-box;
|
|
440
|
+
pointer-events: none;
|
|
441
|
+
user-select: none;
|
|
442
|
+
transform: scale(0);
|
|
443
|
+
opacity: 1;
|
|
444
|
+
transform-origin: center;
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
.u-wave-ripple.u-wave-active {
|
|
448
|
+
opacity: 0;
|
|
449
|
+
transform: scale(2);
|
|
450
|
+
transition:
|
|
451
|
+
opacity 1s linear,
|
|
452
|
+
transform 0.4s linear;
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
.u-round-circle {
|
|
456
|
+
border-radius: 100rpx;
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
.u-round-circle::after {
|
|
460
|
+
border-radius: 100rpx;
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
.u-loading::after {
|
|
464
|
+
background-color: hsla(0, 0%, 100%, 0.35);
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
.u-size-default {
|
|
468
|
+
font-size: 30rpx;
|
|
469
|
+
height: 80rpx;
|
|
470
|
+
line-height: 80rpx;
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
.u-size-medium {
|
|
474
|
+
/* #ifndef APP-NVUE */
|
|
475
|
+
display: inline-flex;
|
|
476
|
+
/* #endif */
|
|
477
|
+
width: auto;
|
|
478
|
+
font-size: 26rpx;
|
|
479
|
+
height: 70rpx;
|
|
480
|
+
line-height: 70rpx;
|
|
481
|
+
padding: 0 80rpx;
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
.u-size-mini {
|
|
485
|
+
/* #ifndef APP-NVUE */
|
|
486
|
+
display: inline-flex;
|
|
487
|
+
/* #endif */
|
|
488
|
+
width: auto;
|
|
489
|
+
font-size: 22rpx;
|
|
490
|
+
padding-top: 1px;
|
|
491
|
+
height: 50rpx;
|
|
492
|
+
line-height: 50rpx;
|
|
493
|
+
padding: 0 20rpx;
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
.u-primary-plain-hover {
|
|
497
|
+
color: #ffffff !important;
|
|
498
|
+
background: $u-type-primary-dark !important;
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
.u-default-plain-hover {
|
|
502
|
+
color: $u-type-primary-dark !important;
|
|
503
|
+
background: $u-type-primary-light !important;
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
.u-success-plain-hover {
|
|
507
|
+
color: #ffffff !important;
|
|
508
|
+
background: $u-type-success-dark !important;
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
.u-warning-plain-hover {
|
|
512
|
+
color: #ffffff !important;
|
|
513
|
+
background: $u-type-warning-dark !important;
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
.u-error-plain-hover {
|
|
517
|
+
color: #ffffff !important;
|
|
518
|
+
background: $u-type-error-dark !important;
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
.u-info-plain-hover {
|
|
522
|
+
color: #ffffff !important;
|
|
523
|
+
background: $u-type-info-dark !important;
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
.u-default-hover {
|
|
527
|
+
color: $u-type-primary-dark !important;
|
|
528
|
+
border-color: $u-type-primary-dark !important;
|
|
529
|
+
background-color: $u-type-primary-light !important;
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
.u-primary-hover {
|
|
533
|
+
background: $u-type-primary-dark !important;
|
|
534
|
+
color: #fff;
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
.u-success-hover {
|
|
538
|
+
background: $u-type-success-dark !important;
|
|
539
|
+
color: #fff;
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
.u-info-hover {
|
|
543
|
+
background: $u-type-info-dark !important;
|
|
544
|
+
color: #fff;
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
.u-warning-hover {
|
|
548
|
+
background: $u-type-warning-dark !important;
|
|
549
|
+
color: #fff;
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
.u-error-hover {
|
|
553
|
+
background: $u-type-error-dark !important;
|
|
554
|
+
color: #fff;
|
|
555
|
+
}
|
|
556
|
+
</style>
|