hongkai-uni-ui 2.10.21 → 2.10.22

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.
@@ -1,470 +1,475 @@
1
- <template>
2
- <!-- #ifndef APP-NVUE -->
3
- <button
4
- :hover-start-time="Number(hoverStartTime)"
5
- :hover-stay-time="Number(hoverStayTime)"
6
- :form-type="formType"
7
- :open-type="openType"
8
- :app-parameter="appParameter"
9
- :hover-stop-propagation="hoverStopPropagation"
10
- :send-message-title="sendMessageTitle"
11
- :send-message-path="sendMessagePath"
12
- :lang="lang"
13
- :data-name="dataName"
14
- :disabled="disabled"
15
- :session-from="sessionFrom"
16
- :send-message-img="sendMessageImg"
17
- :show-message-card="showMessageCard"
18
- @getphonenumber="getphonenumber"
19
- @getrealtimephonenumber="getrealtimephonenumber"
20
- @chooseavatar="chooseavatar"
21
- @getuserinfo="getuserinfo"
22
- @error="error"
23
- @opensetting="opensetting"
24
- @launchapp="launchapp"
25
- @agreeprivacyauthorization="agreeprivacyauthorization"
26
- :hover-class="!disabled && !loading ? 'hk-button--active' : ''"
27
- class="hk-button hk-reset-button"
28
- :style="[baseColor, $hk.addStyle(customStyle)]"
29
- @tap="clickHandler"
30
- :class="bemClass"
31
- >
32
- <template v-if="loading">
33
- <hk-loading-icon :mode="loadingMode" :size="loadingSize * 1.15" :color="loadingColor"></hk-loading-icon>
34
- <text class="hk-button__loading-text" :style="[{ fontSize: textSize + 'px' }]">{{ loadingText || text }}</text>
35
- </template>
36
- <template v-else>
37
- <hk-icon-u v-if="icon" :name="icon" :color="iconColorCom" :size="textSize * 1.35" :customStyle="{ marginRight: '2px' }"></hk-icon-u>
38
- <slot>
39
- <text class="hk-button__text" :style="[{ fontSize: textSize + 'px' }]">{{ text }}</text>
40
- </slot>
41
- </template>
42
- </button>
43
- <!-- #endif -->
44
-
45
- <!-- #ifdef APP-NVUE -->
46
- <view
47
- :hover-start-time="Number(hoverStartTime)"
48
- :hover-stay-time="Number(hoverStayTime)"
49
- class="hk-button"
50
- :hover-class="!disabled && !loading && !color && (plain || type === 'info') ? 'hk-button--active--plain' : !disabled && !loading && !plain ? 'hk-button--active' : ''"
51
- @tap="clickHandler"
52
- :class="bemClass"
53
- :style="[baseColor, $hk.addStyle(customStyle)]"
54
- >
55
- <template v-if="loading">
56
- <hk-loading-icon :mode="loadingMode" :size="loadingSize * 1.15" :color="loadingColor"></hk-loading-icon>
57
- <text class="hk-button__loading-text" :style="[nvueTextStyle]" :class="[plain && `hk-button__text--plain--${type}`]">{{ loadingText || text }}</text>
58
- </template>
59
- <template v-else>
60
- <hk-icon-u v-if="icon" :name="icon" :color="iconColorCom" :size="textSize * 1.35"></hk-icon-u>
61
- <text
62
- class="hk-button__text"
63
- :style="[
64
- {
65
- marginLeft: icon ? '2px' : 0,
66
- },
67
- nvueTextStyle,
68
- ]"
69
- :class="[plain && `hk-button__text--plain--${type}`]"
70
- >
71
- {{ text }}
72
- </text>
73
- </template>
74
- </view>
75
- <!-- #endif -->
76
- </template>
77
-
78
- <script>
79
- import button from '../../mixins/button.js';
80
- import openType from '../../mixins/openType.js';
81
- import props from './props.js';
82
- /**
83
- * button 按钮
84
- * @description Button 按钮
85
- *
86
- * @property {Boolean} hairline 是否显示按钮的细边框 (默认 true )
87
- * @property {String} type 按钮的预置样式,info,primary,error,warning,success (默认 'info' )
88
- * @property {String} size 按钮尺寸,large,normal,mini (默认 normal)
89
- * @property {String} shape 按钮形状,circle(两边为半圆),square(带圆角) (默认 'square'
90
- * @property {Boolean} plain 按钮是否镂空,背景色透明 (默认 false
91
- * @property {Boolean} disabled 是否禁用 (默认 false
92
- * @property {Boolean} loading 按钮名称前是否带 loading 图标(App-nvue 平台,在 ios 上为雪花,Android上为圆圈) (默认 false)
93
- * @property {String | Number} loadingText 加载中提示文字
94
- * @property {String} loadingMode 加载状态图标类型 (默认 'spinner'
95
- * @property {String | Number} loadingSize 加载图标大小 (默认 15 )
96
- * @property {String} openType 开放能力,具体请看uniapp稳定关于button组件部分说明
97
- * @property {String} formType 用于 <form> 组件,点击分别会触发 <form> 组件的 submit/reset 事件
98
- * @property {String} appParameter 打开 APP 时,向 APP 传递的参数,open-type=launchApp时有效 (注:只微信小程序、QQ小程序有效)
99
- * @property {Boolean} hoverStopPropagation 指定是否阻止本节点的祖先节点出现点击态,微信小程序有效(默认 true
100
- * @property {String} lang 指定返回用户信息的语言,zh_CN 简体中文,zh_TW 繁体中文,en 英文(默认 en
101
- * @property {String} sessionFrom 会话来源,openType="contact"时有效
102
- * @property {String} sendMessageTitle 会话内消息卡片标题,openType="contact"时有效
103
- * @property {String} sendMessagePath 会话内消息卡片点击跳转小程序路径,openType="contact"时有效
104
- * @property {String} sendMessageImg 会话内消息卡片图片,openType="contact"时有效
105
- * @property {Boolean} showMessageCard 是否显示会话内消息卡片,设置此参数为 true,用户进入客服会话会在右下角显示"可能要发送的小程序"提示,用户点击后可以快速发送小程序消息,openType="contact"时有效(默认false)
106
- * @property {String} dataName 额外传参参数,用于小程序的data-xxx属性,通过target.dataset.name获取
107
- * @property {String | Number} throttleTime 节流,一定时间内只能触发一次 (默认 0 )
108
- * @property {String | Number} hoverStartTime 按住后多久出现点击态,单位毫秒 (默认 0 )
109
- * @property {String | Number} hoverStayTime 手指松开后点击态保留时间,单位毫秒 (默认 200 )
110
- * @property {String | Number} text 按钮文字,之所以通过props传入,是因为slot传入的话(注:nvue中无法控制文字的样式)
111
- * @property {String} icon 按钮图标
112
- * @property {String} iconColor 按钮图标颜色
113
- * @property {String} color 按钮颜色,支持传入linear-gradient渐变色
114
- * @property {Object} customStyle 定义需要用到的外部样式
115
- *
116
- * @event {Function} click 非禁止并且非加载中,才能点击
117
- * @event {Function} getphonenumber open-type="getPhoneNumber"时有效
118
- * @event {Function} getuserinfo 用户点击该按钮时,会返回获取到的用户信息,从返回参数的detail中获取到的值同uni.getUserInfo
119
- * @event {Function} error 当使用开放能力时,发生错误的回调
120
- * @event {Function} opensetting 在打开授权设置页并关闭后回调
121
- * @event {Function} agreePrivacyAuthorization 同意隐私协议回调
122
- * @event {Function} launchapp 打开 APP 成功的回调
123
- * @example <hk-button>月落</hk-button>
124
- */
125
- export default {
126
- name: 'hk-button',
127
- // #ifdef MP
128
- mixins: [uni.$hk.mpMixin, uni.$hk.mixin, button, openType, props],
129
- // #endif
130
- // #ifndef MP
131
- mixins: [uni.$hk.mpMixin, uni.$hk.mixin, props],
132
- // #endif
133
- data() {
134
- return {};
135
- },
136
- computed: {
137
- // 生成bem风格的类名
138
- bemClass() {
139
- // this.bem为一个computed变量,在mixin中
140
- if (!this.color) {
141
- return this.bem('button', ['type', 'shape', 'size'], ['disabled', 'plain', 'hairline']);
142
- } else {
143
- // 由于nvue的原因,在有color参数时,不需要传入type,否则会生成type相关的类型,影响最终的样式
144
- return this.bem('button', ['shape', 'size'], ['disabled', 'plain', 'hairline']);
145
- }
146
- },
147
- loadingColor() {
148
- if (this.plain) {
149
- // 如果有设置color值,则用color值,否则使用type主题颜色
150
- return this.color ? this.color : uni.$hk.config.color[`hk-${this.type}`];
151
- }
152
- if (this.type === 'info') {
153
- return '#c9c9c9';
154
- }
155
- return 'rgb(200, 200, 200)';
156
- },
157
- iconColorCom() {
158
- // 如果是镂空状态,设置了color就用color值,否则使用主题颜色,
159
- // hk-icon-u的color能接受一个主题颜色的值
160
- if (this.iconColor) return this.iconColor;
161
- if (this.plain) {
162
- return this.color ? this.color : this.type;
163
- } else {
164
- return this.type === 'info' ? '#000000' : '#ffffff';
165
- }
166
- },
167
- baseColor() {
168
- let style = {};
169
- if (this.color) {
170
- // 针对自定义了color颜色的情况,镂空状态下,就是用自定义的颜色
171
- style.color = this.plain ? this.color : 'white';
172
- if (!this.plain) {
173
- // 非镂空,背景色使用自定义的颜色
174
- style['background-color'] = this.color;
175
- }
176
- if (this.color.indexOf('gradient') !== -1) {
177
- // 如果自定义的颜色为渐变色,不显示边框,以及通过backgroundImage设置渐变色
178
- // weex文档说明可以写borderWidth的形式,为什么这里需要分开写?
179
- // 因为weex是阿里巴巴为了部门业绩考核而做的你懂的东西,所以需要这么写才有效
180
- style.borderTopWidth = 0;
181
- style.borderRightWidth = 0;
182
- style.borderBottomWidth = 0;
183
- style.borderLeftWidth = 0;
184
- if (!this.plain) {
185
- style.backgroundImage = this.color;
186
- }
187
- } else {
188
- // 非渐变色,则设置边框相关的属性
189
- style.borderColor = this.color;
190
- style.borderWidth = '1px';
191
- style.borderStyle = 'solid';
192
- }
193
- }
194
- return style;
195
- },
196
- // nvue版本按钮的字体不会继承父组件的颜色,需要对每一个text组件进行单独的设置
197
- nvueTextStyle() {
198
- let style = {};
199
- // 针对自定义了color颜色的情况,镂空状态下,就是用自定义的颜色
200
- if (this.type === 'info') {
201
- style.color = '#323233';
202
- }
203
- if (this.color) {
204
- style.color = this.plain ? this.color : 'white';
205
- }
206
- style.fontSize = this.textSize + 'px';
207
- return style;
208
- },
209
- // 字体大小
210
- textSize() {
211
- let fontSize = 14,
212
- { size } = this;
213
- if (size === 'large') fontSize = 16;
214
- if (size === 'normal') fontSize = 14;
215
- if (size === 'small') fontSize = 12;
216
- if (size === 'mini') fontSize = 10;
217
- return fontSize;
218
- },
219
- },
220
- methods: {
221
- clickHandler() {
222
- // 非禁止并且非加载中,才能点击
223
- if (!this.disabled && !this.loading) {
224
- // 进行节流控制,每this.throttle毫秒内,只在开始处执行
225
- uni.$hk.throttle(() => {
226
- this.$emit('click');
227
- }, this.throttleTime);
228
- }
229
- },
230
- // 下面为对接uniapp官方按钮开放能力事件回调的对接
231
- /**
232
- * 快速获取手机号
233
- * 手机号快速验证组件,平台会对号码进行验证,但不保证是实时验证。
234
- * @param {Object} res
235
- */
236
- getphonenumber(res) {
237
- this.$emit('getphonenumber', res);
238
- },
239
- /**
240
- * 实时验证手机号
241
- * 手机号实时验证组件,在每次请求时,平台均会对用户选择的手机号进行实时验证;
242
- * @param {Object} res
243
- */
244
- getrealtimephonenumber(res) {
245
- this.$emit('getrealtimephonenumber', res);
246
- },
247
- /**
248
- * 获取用户选择的头像
249
- */
250
- chooseavatar() {
251
- this.$emit('chooseavatar', res);
252
- },
253
- getuserinfo(res) {
254
- this.$emit('getuserinfo', res);
255
- },
256
- error(res) {
257
- this.$emit('error', res);
258
- },
259
- opensetting(res) {
260
- this.$emit('opensetting', res);
261
- },
262
- launchapp(res) {
263
- this.$emit('launchapp', res);
264
- },
265
- agreeprivacyauthorization(res) {
266
- this.$emit('agreeprivacyauthorization', res);
267
- },
268
- },
269
- };
270
- </script>
271
-
272
- <style lang="scss" scoped>
273
- @import '../../styles/components.scss';
274
-
275
- /* #ifndef APP-NVUE */
276
- @import './vue.scss';
277
- /* #endif */
278
-
279
- /* #ifdef APP-NVUE */
280
- @import './nvue.scss';
281
- /* #endif */
282
-
283
- $hk-button-hk-button-height: 40px !default;
284
- $hk-button-text-font-size: 15px !default;
285
- $hk-button-loading-text-font-size: 15px !default;
286
- $hk-button-loading-text-margin-left: 4px !default;
287
- $hk-button-large-width: 100% !default;
288
- $hk-button-large-height: 50px !default;
289
- $hk-button-normal-padding: 0 12px !default;
290
- $hk-button-large-padding: 0 15px !default;
291
- $hk-button-normal-font-size: 14px !default;
292
- $hk-button-small-min-width: 60px !default;
293
- $hk-button-small-height: 30px !default;
294
- $hk-button-small-padding: 0px 8px !default;
295
- $hk-button-mini-padding: 0px 8px !default;
296
- $hk-button-small-font-size: 12px !default;
297
- $hk-button-mini-height: 22px !default;
298
- $hk-button-mini-font-size: 10px !default;
299
- $hk-button-mini-min-width: 50px !default;
300
- $hk-button-disabled-opacity: 0.8 !default;
301
- $hk-button-info-color: #323233 !default;
302
- $hk-button-info-background-color: #fff !default;
303
- $hk-button-info-border-color: #ebedf0 !default;
304
- $hk-button-info-border-width: 1px !default;
305
- $hk-button-info-border-style: solid !default;
306
- $hk-button-success-color: #fff !default;
307
- $hk-button-success-background-color: $hk-success !default;
308
- $hk-button-success-border-color: $hk-button-success-background-color !default;
309
- $hk-button-success-border-width: 1px !default;
310
- $hk-button-success-border-style: solid !default;
311
- $hk-button-primary-color: #fff !default;
312
- $hk-button-primary-background-color: $hk-primary !default;
313
- $hk-button-primary-border-color: $hk-button-primary-background-color !default;
314
- $hk-button-primary-border-width: 1px !default;
315
- $hk-button-primary-border-style: solid !default;
316
- $hk-button-error-color: #fff !default;
317
- $hk-button-error-background-color: $hk-error !default;
318
- $hk-button-error-border-color: $hk-button-error-background-color !default;
319
- $hk-button-error-border-width: 1px !default;
320
- $hk-button-error-border-style: solid !default;
321
- $hk-button-warning-color: #fff !default;
322
- $hk-button-warning-background-color: $hk-warning !default;
323
- $hk-button-warning-border-color: $hk-button-warning-background-color !default;
324
- $hk-button-warning-border-width: 1px !default;
325
- $hk-button-warning-border-style: solid !default;
326
- $hk-button-block-width: 100% !default;
327
- $hk-button-circle-border-top-right-radius: 100px !default;
328
- $hk-button-circle-border-top-left-radius: 100px !default;
329
- $hk-button-circle-border-bottom-left-radius: 100px !default;
330
- $hk-button-circle-border-bottom-right-radius: 100px !default;
331
- $hk-button-square-border-top-right-radius: 3px !default;
332
- $hk-button-square-border-top-left-radius: 3px !default;
333
- $hk-button-square-border-bottom-left-radius: 3px !default;
334
- $hk-button-square-border-bottom-right-radius: 3px !default;
335
- $hk-button-icon-min-width: 1em !default;
336
- $hk-button-plain-background-color: #fff !default;
337
- $hk-button-hairline-border-width: 0.5px !default;
338
-
339
- .hk-button {
340
- height: $hk-button-hk-button-height;
341
- position: relative;
342
- align-items: center;
343
- justify-content: center;
344
- @include flex;
345
- /* #ifndef APP-NVUE */
346
- box-sizing: border-box;
347
- /* #endif */
348
- flex-direction: row;
349
-
350
- &__text {
351
- font-size: $hk-button-text-font-size;
352
- }
353
-
354
- &__loading-text {
355
- font-size: $hk-button-loading-text-font-size;
356
- margin-left: $hk-button-loading-text-margin-left;
357
- }
358
-
359
- &--large {
360
- /* #ifndef APP-NVUE */
361
- width: $hk-button-large-width;
362
- /* #endif */
363
- height: $hk-button-large-height;
364
- padding: $hk-button-large-padding;
365
- }
366
-
367
- &--normal {
368
- padding: $hk-button-normal-padding;
369
- font-size: $hk-button-normal-font-size;
370
- }
371
-
372
- &--small {
373
- /* #ifndef APP-NVUE */
374
- min-width: $hk-button-small-min-width;
375
- /* #endif */
376
- height: $hk-button-small-height;
377
- padding: $hk-button-small-padding;
378
- font-size: $hk-button-small-font-size;
379
- }
380
-
381
- &--mini {
382
- height: $hk-button-mini-height;
383
- font-size: $hk-button-mini-font-size;
384
- /* #ifndef APP-NVUE */
385
- min-width: $hk-button-mini-min-width;
386
- /* #endif */
387
- padding: $hk-button-mini-padding;
388
- }
389
-
390
- &--disabled {
391
- opacity: $hk-button-disabled-opacity;
392
- border-color: transparent !important;
393
- }
394
-
395
- &--info {
396
- color: $hk-button-info-color;
397
- background-color: $hk-button-info-background-color;
398
- border-color: $hk-button-info-border-color;
399
- border-width: $hk-button-info-border-width;
400
- border-style: $hk-button-info-border-style;
401
- }
402
-
403
- &--success {
404
- color: $hk-button-success-color;
405
- background-color: $hk-button-success-background-color;
406
- border-color: $hk-button-success-border-color;
407
- border-width: $hk-button-success-border-width;
408
- border-style: $hk-button-success-border-style;
409
- }
410
-
411
- &--primary {
412
- color: $hk-button-primary-color;
413
- background-color: $hk-button-primary-background-color;
414
- border-color: $hk-button-primary-border-color;
415
- border-width: $hk-button-primary-border-width;
416
- border-style: $hk-button-primary-border-style;
417
- }
418
-
419
- &--error {
420
- color: $hk-button-error-color;
421
- background-color: $hk-button-error-background-color;
422
- border-color: $hk-button-error-border-color;
423
- border-width: $hk-button-error-border-width;
424
- border-style: $hk-button-error-border-style;
425
- }
426
-
427
- &--warning {
428
- color: $hk-button-warning-color;
429
- background-color: $hk-button-warning-background-color;
430
- border-color: $hk-button-warning-border-color;
431
- border-width: $hk-button-warning-border-width;
432
- border-style: $hk-button-warning-border-style;
433
- }
434
-
435
- &--block {
436
- @include flex;
437
- width: $hk-button-block-width;
438
- }
439
-
440
- &--circle {
441
- border-top-right-radius: $hk-button-circle-border-top-right-radius;
442
- border-top-left-radius: $hk-button-circle-border-top-left-radius;
443
- border-bottom-left-radius: $hk-button-circle-border-bottom-left-radius;
444
- border-bottom-right-radius: $hk-button-circle-border-bottom-right-radius;
445
- }
446
-
447
- &--square {
448
- border-bottom-left-radius: $hk-button-square-border-top-right-radius;
449
- border-bottom-right-radius: $hk-button-square-border-top-left-radius;
450
- border-top-left-radius: $hk-button-square-border-bottom-left-radius;
451
- border-top-right-radius: $hk-button-square-border-bottom-right-radius;
452
- }
453
-
454
- &__icon {
455
- /* #ifndef APP-NVUE */
456
- min-width: $hk-button-icon-min-width;
457
- line-height: inherit !important;
458
- vertical-align: top;
459
- /* #endif */
460
- }
461
-
462
- &--plain {
463
- background-color: $hk-button-plain-background-color;
464
- }
465
-
466
- &--hairline {
467
- border-width: $hk-button-hairline-border-width !important;
468
- }
469
- }
470
- </style>
1
+ <template>
2
+ <!-- #ifndef APP-NVUE -->
3
+ <button
4
+ :hover-start-time="Number(hoverStartTime)"
5
+ :hover-stay-time="Number(hoverStayTime)"
6
+ :form-type="formType"
7
+ :open-type="openType"
8
+ :app-parameter="appParameter"
9
+ :hover-stop-propagation="hoverStopPropagation"
10
+ :send-message-title="sendMessageTitle"
11
+ :send-message-path="sendMessagePath"
12
+ :lang="lang"
13
+ :data-name="dataName"
14
+ :disabled="disabled"
15
+ :session-from="sessionFrom"
16
+ :send-message-img="sendMessageImg"
17
+ :show-message-card="showMessageCard"
18
+ @getphonenumber="getphonenumber"
19
+ @getrealtimephonenumber="getrealtimephonenumber"
20
+ @chooseavatar="chooseavatar"
21
+ @getuserinfo="getuserinfo"
22
+ @error="error"
23
+ @opensetting="opensetting"
24
+ @launchapp="launchapp"
25
+ @agreeprivacyauthorization="agreeprivacyauthorization"
26
+ :hover-class="!disabled && !loading ? 'hk-button--active' : ''"
27
+ class="hk-button hk-reset-button"
28
+ :style="[baseColor, $hk.addStyle(customStyle)]"
29
+ @tap="clickHandler"
30
+ :class="bemClass"
31
+ >
32
+ <template v-if="loading">
33
+ <hk-loading-icon :mode="loadingMode" :size="loadingSize * 1.15" :color="loadingColor"></hk-loading-icon>
34
+ <text class="hk-button__loading-text" :style="[{ fontSize: textSize + 'px' }]">{{ loadingText || text }}</text>
35
+ </template>
36
+ <template v-else>
37
+ <hk-icon-u v-if="icon" :name="icon" :color="iconColorCom" :size="textSize * 1.35" :customStyle="{ marginRight: '2px' }"></hk-icon-u>
38
+ <slot>
39
+ <text class="hk-button__text" :style="[{ fontSize: textSize + 'px' }]">{{ text }}</text>
40
+ </slot>
41
+ </template>
42
+ </button>
43
+ <!-- #endif -->
44
+
45
+ <!-- #ifdef APP-NVUE -->
46
+ <view
47
+ :hover-start-time="Number(hoverStartTime)"
48
+ :hover-stay-time="Number(hoverStayTime)"
49
+ class="hk-button"
50
+ :hover-class="
51
+ !disabled && !loading && !color && (plain || type === 'info') ? 'hk-button--active--plain' : !disabled && !loading && !plain ? 'hk-button--active' : ''
52
+ "
53
+ @tap="clickHandler"
54
+ :class="bemClass"
55
+ :style="[baseColor, $hk.addStyle(customStyle)]"
56
+ >
57
+ <template v-if="loading">
58
+ <hk-loading-icon :mode="loadingMode" :size="loadingSize * 1.15" :color="loadingColor"></hk-loading-icon>
59
+ <text class="hk-button__loading-text" :style="[nvueTextStyle]" :class="[plain && `hk-button__text--plain--${type}`]">{{ loadingText || text }}</text>
60
+ </template>
61
+ <template v-else>
62
+ <hk-icon-u v-if="icon" :name="icon" :color="iconColorCom" :size="textSize * 1.35"></hk-icon-u>
63
+ <text
64
+ class="hk-button__text"
65
+ :style="[
66
+ {
67
+ marginLeft: icon ? '2px' : 0
68
+ },
69
+ nvueTextStyle
70
+ ]"
71
+ :class="[plain && `hk-button__text--plain--${type}`]"
72
+ >
73
+ {{ text }}
74
+ </text>
75
+ </template>
76
+ </view>
77
+ <!-- #endif -->
78
+ </template>
79
+
80
+ <script>
81
+ import button from '../../mixins/button.js';
82
+ import openType from '../../mixins/openType.js';
83
+ import props from './props.js';
84
+ /**
85
+ * button 按钮
86
+ * @description Button 按钮
87
+ *
88
+ * @property {Boolean} hairline 是否显示按钮的细边框 (默认 true )
89
+ * @property {String} type 按钮的预置样式,info,primary,error,warning,success (默认 'info' )
90
+ * @property {String} size 按钮尺寸,large,normal,mini (默认 normal
91
+ * @property {String} shape 按钮形状,circle(两边为半圆),square(带圆角) (默认 'square'
92
+ * @property {Boolean} plain 按钮是否镂空,背景色透明 (默认 false)
93
+ * @property {Boolean} disabled 是否禁用 (默认 false)
94
+ * @property {Boolean} loading 按钮名称前是否带 loading 图标(App-nvue 平台,在 ios 上为雪花,Android上为圆圈) (默认 false
95
+ * @property {String | Number} loadingText 加载中提示文字
96
+ * @property {String} loadingMode 加载状态图标类型 (默认 'spinner' )
97
+ * @property {String | Number} loadingSize 加载图标大小 (默认 15
98
+ * @property {String} openType 开放能力,具体请看uniapp稳定关于button组件部分说明
99
+ * @property {String} formType 用于 <form> 组件,点击分别会触发 <form> 组件的 submit/reset 事件
100
+ * @property {String} appParameter 打开 APP 时,向 APP 传递的参数,open-type=launchApp时有效 (注:只微信小程序、QQ小程序有效)
101
+ * @property {Boolean} hoverStopPropagation 指定是否阻止本节点的祖先节点出现点击态,微信小程序有效(默认 true )
102
+ * @property {String} lang 指定返回用户信息的语言,zh_CN 简体中文,zh_TW 繁体中文,en 英文(默认 en )
103
+ * @property {String} sessionFrom 会话来源,openType="contact"时有效
104
+ * @property {String} sendMessageTitle 会话内消息卡片标题,openType="contact"时有效
105
+ * @property {String} sendMessagePath 会话内消息卡片点击跳转小程序路径,openType="contact"时有效
106
+ * @property {String} sendMessageImg 会话内消息卡片图片,openType="contact"时有效
107
+ * @property {Boolean} showMessageCard 是否显示会话内消息卡片,设置此参数为 true,用户进入客服会话会在右下角显示"可能要发送的小程序"提示,用户点击后可以快速发送小程序消息,openType="contact"时有效(默认false)
108
+ * @property {String} dataName 额外传参参数,用于小程序的data-xxx属性,通过target.dataset.name获取
109
+ * @property {String | Number} throttleTime 节流,一定时间内只能触发一次 (默认 0 )
110
+ * @property {String | Number} hoverStartTime 按住后多久出现点击态,单位毫秒 (默认 0 )
111
+ * @property {String | Number} hoverStayTime 手指松开后点击态保留时间,单位毫秒 (默认 200 )
112
+ * @property {String | Number} text 按钮文字,之所以通过props传入,是因为slot传入的话(注:nvue中无法控制文字的样式)
113
+ * @property {String} icon 按钮图标
114
+ * @property {String} iconColor 按钮图标颜色
115
+ * @property {String} color 按钮颜色,支持传入linear-gradient渐变色
116
+ * @property {Object} customStyle 定义需要用到的外部样式
117
+ *
118
+ * @event {Function} click 非禁止并且非加载中,才能点击
119
+ * @event {Function} getphonenumber open-type="getPhoneNumber"时有效
120
+ * @event {Function} getuserinfo 用户点击该按钮时,会返回获取到的用户信息,从返回参数的detail中获取到的值同uni.getUserInfo
121
+ * @event {Function} error 当使用开放能力时,发生错误的回调
122
+ * @event {Function} opensetting 在打开授权设置页并关闭后回调
123
+ * @event {Function} agreePrivacyAuthorization 同意隐私协议回调
124
+ * @event {Function} launchapp 打开 APP 成功的回调
125
+ * @example <hk-button>月落</hk-button>
126
+ */
127
+ export default {
128
+ name: 'hk-button',
129
+ // #ifdef MP
130
+ mixins: [uni.$hk.mpMixin, uni.$hk.mixin, button, openType, props],
131
+ // #endif
132
+ // #ifndef MP
133
+ mixins: [uni.$hk.mpMixin, uni.$hk.mixin, props],
134
+ // #endif
135
+ data() {
136
+ return {
137
+ throttleTimer: null
138
+ };
139
+ },
140
+ computed: {
141
+ // 生成bem风格的类名
142
+ bemClass() {
143
+ // this.bem为一个computed变量,在mixin中
144
+ if (!this.color) {
145
+ return this.bem('button', ['type', 'shape', 'size'], ['disabled', 'plain', 'hairline']);
146
+ } else {
147
+ // 由于nvue的原因,在有color参数时,不需要传入type,否则会生成type相关的类型,影响最终的样式
148
+ return this.bem('button', ['shape', 'size'], ['disabled', 'plain', 'hairline']);
149
+ }
150
+ },
151
+ loadingColor() {
152
+ if (this.plain) {
153
+ // 如果有设置color值,则用color值,否则使用type主题颜色
154
+ return this.color ? this.color : uni.$hk.config.color[`hk-${this.type}`];
155
+ }
156
+ if (this.type === 'info') {
157
+ return '#c9c9c9';
158
+ }
159
+ return 'rgb(200, 200, 200)';
160
+ },
161
+ iconColorCom() {
162
+ // 如果是镂空状态,设置了color就用color值,否则使用主题颜色,
163
+ // hk-icon-u的color能接受一个主题颜色的值
164
+ if (this.iconColor) return this.iconColor;
165
+ if (this.plain) {
166
+ return this.color ? this.color : this.type;
167
+ } else {
168
+ return this.type === 'info' ? '#000000' : '#ffffff';
169
+ }
170
+ },
171
+ baseColor() {
172
+ let style = {};
173
+ if (this.color) {
174
+ // 针对自定义了color颜色的情况,镂空状态下,就是用自定义的颜色
175
+ style.color = this.plain ? this.color : 'white';
176
+ if (!this.plain) {
177
+ // 非镂空,背景色使用自定义的颜色
178
+ style['background-color'] = this.color;
179
+ }
180
+ if (this.color.indexOf('gradient') !== -1) {
181
+ // 如果自定义的颜色为渐变色,不显示边框,以及通过backgroundImage设置渐变色
182
+ // weex文档说明可以写borderWidth的形式,为什么这里需要分开写?
183
+ // 因为weex是阿里巴巴为了部门业绩考核而做的你懂的东西,所以需要这么写才有效
184
+ style.borderTopWidth = 0;
185
+ style.borderRightWidth = 0;
186
+ style.borderBottomWidth = 0;
187
+ style.borderLeftWidth = 0;
188
+ if (!this.plain) {
189
+ style.backgroundImage = this.color;
190
+ }
191
+ } else {
192
+ // 非渐变色,则设置边框相关的属性
193
+ style.borderColor = this.color;
194
+ style.borderWidth = '1px';
195
+ style.borderStyle = 'solid';
196
+ }
197
+ }
198
+ return style;
199
+ },
200
+ // nvue版本按钮的字体不会继承父组件的颜色,需要对每一个text组件进行单独的设置
201
+ nvueTextStyle() {
202
+ let style = {};
203
+ // 针对自定义了color颜色的情况,镂空状态下,就是用自定义的颜色
204
+ if (this.type === 'info') {
205
+ style.color = '#323233';
206
+ }
207
+ if (this.color) {
208
+ style.color = this.plain ? this.color : 'white';
209
+ }
210
+ style.fontSize = this.textSize + 'px';
211
+ return style;
212
+ },
213
+ // 字体大小
214
+ textSize() {
215
+ let fontSize = 14,
216
+ { size } = this;
217
+ if (size === 'large') fontSize = 16;
218
+ if (size === 'normal') fontSize = 14;
219
+ if (size === 'small') fontSize = 12;
220
+ if (size === 'mini') fontSize = 10;
221
+ return fontSize;
222
+ }
223
+ },
224
+ methods: {
225
+ clickHandler() {
226
+ // 非禁止并且非加载中,才能点击
227
+ if (!this.disabled && !this.loading) {
228
+ // 进行节流控制,每this.throttle毫秒内,只在开始处执行
229
+ this.throttleTimer && clearTimeout(this.throttleTimer);
230
+ this.throttleTimer = setTimeout(() => {
231
+ this.$emit('click');
232
+ }, this.throttleTime || 1000);
233
+ }
234
+ },
235
+ // 下面为对接uniapp官方按钮开放能力事件回调的对接
236
+ /**
237
+ * 快速获取手机号
238
+ * 手机号快速验证组件,平台会对号码进行验证,但不保证是实时验证。
239
+ * @param {Object} res
240
+ */
241
+ getphonenumber(res) {
242
+ this.$emit('getphonenumber', res);
243
+ },
244
+ /**
245
+ * 实时验证手机号
246
+ * 手机号实时验证组件,在每次请求时,平台均会对用户选择的手机号进行实时验证;
247
+ * @param {Object} res
248
+ */
249
+ getrealtimephonenumber(res) {
250
+ this.$emit('getrealtimephonenumber', res);
251
+ },
252
+ /**
253
+ * 获取用户选择的头像
254
+ */
255
+ chooseavatar() {
256
+ this.$emit('chooseavatar', res);
257
+ },
258
+ getuserinfo(res) {
259
+ this.$emit('getuserinfo', res);
260
+ },
261
+ error(res) {
262
+ this.$emit('error', res);
263
+ },
264
+ opensetting(res) {
265
+ this.$emit('opensetting', res);
266
+ },
267
+ launchapp(res) {
268
+ this.$emit('launchapp', res);
269
+ },
270
+ agreeprivacyauthorization(res) {
271
+ this.$emit('agreeprivacyauthorization', res);
272
+ }
273
+ }
274
+ };
275
+ </script>
276
+
277
+ <style lang="scss" scoped>
278
+ @import '../../styles/components.scss';
279
+
280
+ /* #ifndef APP-NVUE */
281
+ @import './vue.scss';
282
+ /* #endif */
283
+
284
+ /* #ifdef APP-NVUE */
285
+ @import './nvue.scss';
286
+ /* #endif */
287
+
288
+ $hk-button-hk-button-height: 40px !default;
289
+ $hk-button-text-font-size: 15px !default;
290
+ $hk-button-loading-text-font-size: 15px !default;
291
+ $hk-button-loading-text-margin-left: 4px !default;
292
+ $hk-button-large-width: 100% !default;
293
+ $hk-button-large-height: 50px !default;
294
+ $hk-button-normal-padding: 0 12px !default;
295
+ $hk-button-large-padding: 0 15px !default;
296
+ $hk-button-normal-font-size: 14px !default;
297
+ $hk-button-small-min-width: 60px !default;
298
+ $hk-button-small-height: 30px !default;
299
+ $hk-button-small-padding: 0px 8px !default;
300
+ $hk-button-mini-padding: 0px 8px !default;
301
+ $hk-button-small-font-size: 12px !default;
302
+ $hk-button-mini-height: 22px !default;
303
+ $hk-button-mini-font-size: 10px !default;
304
+ $hk-button-mini-min-width: 50px !default;
305
+ $hk-button-disabled-opacity: 0.8 !default;
306
+ $hk-button-info-color: #323233 !default;
307
+ $hk-button-info-background-color: #fff !default;
308
+ $hk-button-info-border-color: #ebedf0 !default;
309
+ $hk-button-info-border-width: 1px !default;
310
+ $hk-button-info-border-style: solid !default;
311
+ $hk-button-success-color: #fff !default;
312
+ $hk-button-success-background-color: $hk-success !default;
313
+ $hk-button-success-border-color: $hk-button-success-background-color !default;
314
+ $hk-button-success-border-width: 1px !default;
315
+ $hk-button-success-border-style: solid !default;
316
+ $hk-button-primary-color: #fff !default;
317
+ $hk-button-primary-background-color: $hk-primary !default;
318
+ $hk-button-primary-border-color: $hk-button-primary-background-color !default;
319
+ $hk-button-primary-border-width: 1px !default;
320
+ $hk-button-primary-border-style: solid !default;
321
+ $hk-button-error-color: #fff !default;
322
+ $hk-button-error-background-color: $hk-error !default;
323
+ $hk-button-error-border-color: $hk-button-error-background-color !default;
324
+ $hk-button-error-border-width: 1px !default;
325
+ $hk-button-error-border-style: solid !default;
326
+ $hk-button-warning-color: #fff !default;
327
+ $hk-button-warning-background-color: $hk-warning !default;
328
+ $hk-button-warning-border-color: $hk-button-warning-background-color !default;
329
+ $hk-button-warning-border-width: 1px !default;
330
+ $hk-button-warning-border-style: solid !default;
331
+ $hk-button-block-width: 100% !default;
332
+ $hk-button-circle-border-top-right-radius: 100px !default;
333
+ $hk-button-circle-border-top-left-radius: 100px !default;
334
+ $hk-button-circle-border-bottom-left-radius: 100px !default;
335
+ $hk-button-circle-border-bottom-right-radius: 100px !default;
336
+ $hk-button-square-border-top-right-radius: 3px !default;
337
+ $hk-button-square-border-top-left-radius: 3px !default;
338
+ $hk-button-square-border-bottom-left-radius: 3px !default;
339
+ $hk-button-square-border-bottom-right-radius: 3px !default;
340
+ $hk-button-icon-min-width: 1em !default;
341
+ $hk-button-plain-background-color: #fff !default;
342
+ $hk-button-hairline-border-width: 0.5px !default;
343
+
344
+ .hk-button {
345
+ height: $hk-button-hk-button-height;
346
+ position: relative;
347
+ align-items: center;
348
+ justify-content: center;
349
+ @include flex;
350
+ /* #ifndef APP-NVUE */
351
+ box-sizing: border-box;
352
+ /* #endif */
353
+ flex-direction: row;
354
+
355
+ &__text {
356
+ font-size: $hk-button-text-font-size;
357
+ }
358
+
359
+ &__loading-text {
360
+ font-size: $hk-button-loading-text-font-size;
361
+ margin-left: $hk-button-loading-text-margin-left;
362
+ }
363
+
364
+ &--large {
365
+ /* #ifndef APP-NVUE */
366
+ width: $hk-button-large-width;
367
+ /* #endif */
368
+ height: $hk-button-large-height;
369
+ padding: $hk-button-large-padding;
370
+ }
371
+
372
+ &--normal {
373
+ padding: $hk-button-normal-padding;
374
+ font-size: $hk-button-normal-font-size;
375
+ }
376
+
377
+ &--small {
378
+ /* #ifndef APP-NVUE */
379
+ min-width: $hk-button-small-min-width;
380
+ /* #endif */
381
+ height: $hk-button-small-height;
382
+ padding: $hk-button-small-padding;
383
+ font-size: $hk-button-small-font-size;
384
+ }
385
+
386
+ &--mini {
387
+ height: $hk-button-mini-height;
388
+ font-size: $hk-button-mini-font-size;
389
+ /* #ifndef APP-NVUE */
390
+ min-width: $hk-button-mini-min-width;
391
+ /* #endif */
392
+ padding: $hk-button-mini-padding;
393
+ }
394
+
395
+ &--disabled {
396
+ opacity: $hk-button-disabled-opacity;
397
+ border-color: transparent !important;
398
+ }
399
+
400
+ &--info {
401
+ color: $hk-button-info-color;
402
+ background-color: $hk-button-info-background-color;
403
+ border-color: $hk-button-info-border-color;
404
+ border-width: $hk-button-info-border-width;
405
+ border-style: $hk-button-info-border-style;
406
+ }
407
+
408
+ &--success {
409
+ color: $hk-button-success-color;
410
+ background-color: $hk-button-success-background-color;
411
+ border-color: $hk-button-success-border-color;
412
+ border-width: $hk-button-success-border-width;
413
+ border-style: $hk-button-success-border-style;
414
+ }
415
+
416
+ &--primary {
417
+ color: $hk-button-primary-color;
418
+ background-color: $hk-button-primary-background-color;
419
+ border-color: $hk-button-primary-border-color;
420
+ border-width: $hk-button-primary-border-width;
421
+ border-style: $hk-button-primary-border-style;
422
+ }
423
+
424
+ &--error {
425
+ color: $hk-button-error-color;
426
+ background-color: $hk-button-error-background-color;
427
+ border-color: $hk-button-error-border-color;
428
+ border-width: $hk-button-error-border-width;
429
+ border-style: $hk-button-error-border-style;
430
+ }
431
+
432
+ &--warning {
433
+ color: $hk-button-warning-color;
434
+ background-color: $hk-button-warning-background-color;
435
+ border-color: $hk-button-warning-border-color;
436
+ border-width: $hk-button-warning-border-width;
437
+ border-style: $hk-button-warning-border-style;
438
+ }
439
+
440
+ &--block {
441
+ @include flex;
442
+ width: $hk-button-block-width;
443
+ }
444
+
445
+ &--circle {
446
+ border-top-right-radius: $hk-button-circle-border-top-right-radius;
447
+ border-top-left-radius: $hk-button-circle-border-top-left-radius;
448
+ border-bottom-left-radius: $hk-button-circle-border-bottom-left-radius;
449
+ border-bottom-right-radius: $hk-button-circle-border-bottom-right-radius;
450
+ }
451
+
452
+ &--square {
453
+ border-bottom-left-radius: $hk-button-square-border-top-right-radius;
454
+ border-bottom-right-radius: $hk-button-square-border-top-left-radius;
455
+ border-top-left-radius: $hk-button-square-border-bottom-left-radius;
456
+ border-top-right-radius: $hk-button-square-border-bottom-right-radius;
457
+ }
458
+
459
+ &__icon {
460
+ /* #ifndef APP-NVUE */
461
+ min-width: $hk-button-icon-min-width;
462
+ line-height: inherit !important;
463
+ vertical-align: top;
464
+ /* #endif */
465
+ }
466
+
467
+ &--plain {
468
+ background-color: $hk-button-plain-background-color;
469
+ }
470
+
471
+ &--hairline {
472
+ border-width: $hk-button-hairline-border-width !important;
473
+ }
474
+ }
475
+ </style>