zhangwei
2024-08-14 9d8994790fe403935ed46ad478f83ae110bb7a01
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
<template>
    <!--本文件由FirstUI授权予四川政采招投标咨询有限公司(会员ID: 16 3,营业执照号:    915101   3133   2     00619  3K)专用,请尊重知识产权,勿私下传播,违者追究法律责任。-->
    <view class="fui-button__wrap"
        :class="[!getWidth || getWidth==='100%' || getWidth===true?'fui-button__flex-1':'',disabled && !disabledBackground ? 'fui-button__opacity' : '']"
        :style="{width: getWidth,height: getHeight,marginTop:margin[0] || 0,    marginRight:margin[1]||0,marginBottom:margin[2] || margin[0]||0,marginLeft:margin[3] || margin[1]||0,borderRadius: getRadius,background:getBackground}"
        @touchstart="handleStart" @touchend="handleClick" @touchcancel="handleEnd">
        <button class="fui-button" :class="[
                bold ? 'fui-text__bold' : '',
                time && (plain || type==='link') ? 'fui-button__opacity' : '',
                !background && !disabledBackground && !plain?('fui-button__'+type):'',
                !getWidth || getWidth==='100%' || getWidth===true?'fui-button__flex-1':'',
                time && !plain && type!=='link' ? 'fui-button__active' : '',
                pc && !disabled?(plain || type==='link'?'fui-button__opacity-pc':'fui-button__active-pc'):'',
 
            ]" :style="{
                width: getWidth,
                height: getHeight,
                lineHeight: getHeight,
                background: disabled ? (disabledBackground || getTypeColor) : (plain ? 'transparent' : getBackground),
                borderWidth:!borderColor || !isNvue?'0':borderWidth,
                borderColor: borderColor ? borderColor : disabled && disabledBackground ? disabledBackground : (background || 'transparent'),
                borderRadius: getRadius,
                fontSize: getSize,
                color: getColor
            }" :loading="loading" :form-type="formType" :open-type="openType" :app-parameter="appParameter"
            :hoverStopPropagation="hoverStopPropagation" :lang="lang" :sessionFrom="sessionFrom"
            :sendMessageTitle="sendMessageTitle" :sendMessagePath="sendMessagePath" :sendMessageImg="sendMessageImg"
            :showMessageCard="showMessageCard" :groupId="groupId" :guildId="guildId" :publicId="publicId"
            :dataImId="dataImId" :dataImType="dataImType" :dataGoodsId="dataGoodsId" :dataOrderId="dataOrderId"
            :dataBizLine="dataBizLine" :phoneNumberNoQuotaToast="phoneNumberNoQuotaToast" @getuserinfo="bindgetuserinfo"
            @getphonenumber="bindgetphonenumber" @contact="bindcontact" @error="binderror"
            @opensetting="bindopensetting" @chooseavatar="bindchooseavatar" @launchapp="bindlaunchapp"
            @agreeprivacyauthorization="agreeprivacyauthorization" @addgroupapp="addgroupapp"
            @chooseaddress="chooseaddress" @chooseinvoicetitle="chooseinvoicetitle" @subscribe="bindsubscribe"
            @login="bindlogin" @im="bindim" :disabled="disabled" :scope="scope" @tap.stop="handleTap">
            <text class="fui-button__text"
                :class="{'fui-btn__gray-color':!background && !disabledBackground && !plain && type==='gray' && color==='#fff','fui-text__bold':bold}"
                v-if="text" :style="{fontSize: getSize,lineHeight:getSize,color:getColor}">{{text}}</text>
            <slot></slot>
        </button>
        <!-- #ifndef APP-NVUE -->
        <view v-if="borderColor" class="fui-button__thin-border"
            :class="[time && (plain || type==='link') && !disabled ? 'fui-button__opacity' : '',disabled && !disabledBackground ? 'fui-button__opacity' : '']"
            :style="{borderWidth:borderWidth,borderColor:borderColor ? borderColor : disabled && disabledBackground ? disabledBackground : (background || 'transparent'),borderRadius: getBorderRadius}">
        </view>
        <!-- #endif -->
    </view>
</template>
 
<script>
    export default {
        name: 'fui-button',
        emits: ['click', 'getuserinfo', 'contact', 'getphonenumber', 'error', 'opensetting', 'chooseavatar', 'launchapp',
            'agreeprivacyauthorization', 'addgroupapp', 'chooseaddress', 'chooseinvoicetitle', 'subscribe', 'login',
            'im'
        ],
        // #ifdef MP-WEIXIN
        behaviors: ['wx://form-field-button'],
        // #endif
        // #ifdef MP-BAIDU
        behaviors: ['swan://form-field'],
        // #endif
        // #ifdef MP-QQ
        behaviors: ['qq://form-field'],
        // #endif
        // #ifdef H5
        behaviors: ['uni://form-field'],
        // #endif
        props: {
            //样式类型:primary,success, warning,danger,link,purple,gray
            type: {
                type: String,
                default: 'primary'
            },
            //按钮背景色,当传入值时type失效
            background: {
                type: String,
                default: ''
            },
            //按钮显示文本
            text: {
                type: String,
                default: ''
            },
            //按钮字体颜色
            color: {
                type: String,
                default: ''
            },
            //按钮禁用背景色
            disabledBackground: {
                type: String,
                default: ''
            },
            //按钮禁用字体颜色
            disabledColor: {
                type: String,
                default: ''
            },
            // #ifdef APP-NVUE
            borderWidth: {
                type: String,
                default: '0.5px'
            },
            // #endif
            // #ifndef APP-NVUE
            borderWidth: {
                type: String,
                default: '1px'
            },
            // #endif
            borderColor: {
                type: String,
                default: ''
            },
            //V1.9.8+ 按钮大小,优先级高于width和height,medium、small、mini
            btnSize: {
                type: String,
                default: ''
            },
            //宽度
            width: {
                type: String,
                default: '100%'
            },
            //高度
            height: {
                type: String,
                default: ''
            },
            //字体大小,单位rpx
            size: {
                type: [Number, String],
                default: 0
            },
            bold: {
                type: Boolean,
                default: false
            },
            //['20rpx','30rpx','20rpx','30rpx']->[上,右,下,左]
            margin: {
                type: Array,
                default () {
                    return ['0', '0']
                }
            },
            //圆角
            radius: {
                type: String,
                default: ''
            },
            plain: {
                type: Boolean,
                default: false
            },
            disabled: {
                type: Boolean,
                default: false
            },
            loading: {
                type: Boolean,
                default: false
            },
            formType: {
                type: String,
                default: ''
            },
            openType: {
                type: String,
                default: ''
            },
            //支付宝小程序
            //当 open-type 为 getAuthorize 时,可以设置 scope 为:phoneNumber、userInfo
            scope: {
                type: String,
                default: ''
            },
            appParameter: {
                type: String,
                default: ''
            },
            //v2.3.0+
            hoverStopPropagation: {
                type: Boolean,
                default: false
            },
            lang: {
                type: String,
                default: 'en'
            },
            sessionFrom: {
                type: String,
                default: ''
            },
            sendMessageTitle: {
                type: String,
                default: ''
            },
            sendMessagePath: {
                type: String,
                default: ''
            },
            sendMessageImg: {
                type: String,
                default: ''
            },
            showMessageCard: {
                type: Boolean,
                default: false
            },
            phoneNumberNoQuotaToast: {
                type: Boolean,
                default: true
            },
            groupId: {
                type: String,
                default: ''
            },
            guildId: {
                type: String,
                default: ''
            },
            publicId: {
                type: String,
                default: ''
            },
            dataImId: {
                type: String,
                default: ''
            },
            dataImType: {
                type: String,
                default: ''
            },
            dataGoodsId: {
                type: String,
                default: ''
            },
            dataOrderId: {
                type: String,
                default: ''
            },
            dataBizLine: {
                type: String,
                default: ''
            },
            index: {
                type: [Number, String],
                default: 0
            }
        },
        computed: {
            getTypeColor() {
                // #ifndef APP-NVUE
                return '';
                // #endif
                const app = uni && uni.$fui && uni.$fui.color
                let colors = {
                    primary: (app && app.primary) || '#465CFF',
                    success: (app && app.success) || '#09BE4F',
                    warning: (app && app.warning) || '#FFB703',
                    danger: (app && app.danger) || '#FF2B2B',
                    link: 'transparent',
                    purple: (app && app.purple) || '#6831FF',
                    gray: '#F8F8F8'
                }
                return colors[this.type] || 'transparent'
            },
            getBackground() {
                let color = this.getTypeColor
                if (this.disabled || this.plain) {
                    color = 'transparent';
                }
                if (!this.disabled && !this.plain && this.background) {
                    color = this.background
                }
                return color
            },
            getColor() {
                let color = '#fff'
                if (this.color) {
                    color = this.disabled && this.disabledBackground ? this.disabledColor : this.color
                } else {
                    if (this.disabled && this.disabledBackground) {
                        color = this.disabledColor || '#FFFFFF'
                    } else {
                        const app = uni && uni.$fui && uni.$fui.color;
                        const primary = (app && app.primary) || '#465CFF';
                        color = this.type === 'gray' ? primary : '#FFFFFF'
                    }
                }
                return color;
            },
            getSize() {
                let size = this.size || (uni && uni.$fui && uni.$fui.fuiButton && uni.$fui.fuiButton.size) || 32
                if (this.btnSize === 'small') {
                    size = size > 28 ? 28 : size;
                } else if (this.btnSize === 'mini') {
                    size = size > 28 ? 24 : size;
                }
                return `${size}rpx`
            },
            getWidth() {
                //medium 400*84 / small 200*84/ mini 120 * 64
                let width = this.width;
                if (this.btnSize && this.btnSize !== true) {
                    width = {
                        'medium': '400rpx',
                        'small': '200rpx',
                        'mini': '120rpx'
                    } [this.btnSize] || width
                }
                return width
            },
            getHeight() {
                let height = this.height || (uni && uni.$fui && uni.$fui.fuiButton && uni.$fui.fuiButton.height) || '96rpx'
                if (this.btnSize && this.btnSize !== true) {
                    height = {
                        'medium': '84rpx',
                        'small': '72rpx',
                        'mini': '64rpx'
                    } [this.btnSize] || height
                }
                return height
            },
            // #ifndef APP-NVUE
            getBorderRadius() {
                let radius = (uni && uni.$fui && uni.$fui.fuiButton && uni.$fui.fuiButton.radius) || '16rpx'
                radius = this.radius || radius || '0'
                if (~radius.indexOf('rpx')) {
                    radius = (Number(radius.replace('rpx', '')) * 2) + 'rpx'
                } else if (~radius.indexOf('px')) {
                    radius = (Number(radius.replace('px', '')) * 2) + 'px'
                } else if (~radius.indexOf('%')) {
                    radius = (Number(radius.replace('%', '')) * 2) + '%'
                }
                return radius
            },
            // #endif
            getRadius() {
                const radius = (uni && uni.$fui && uni.$fui.fuiButton && uni.$fui.fuiButton.radius) || '16rpx'
                return this.radius || radius
            }
        },
        data() {
            let isNvue = false
            // #ifdef APP-NVUE
            isNvue = true
            // #endif
            return {
                isNvue: isNvue,
                time: 0,
                trigger: false,
                pc: false
            };
        },
        created() {
            // #ifdef H5
            this.pc = this.isPC()
            // #endif
        },
        methods: {
            handleStart(e) {
                // #ifndef APP-NVUE
                if (this.disabled) return;
                this.trigger = false;
                if (new Date().getTime() - this.time <= 150) return;
                this.trigger = true;
                this.time = new Date().getTime();
                // #endif
            },
            handleClick() {
                if (this.disabled || !this.trigger) return;
                this.time = 0;
            },
            // #ifdef H5
            isPC() {
                if (typeof navigator !== 'object') return false;
                var userAgentInfo = navigator.userAgent;
                var Agents = ["Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod"];
                var flag = true;
                for (var v = 0; v < Agents.length - 1; v++) {
                    if (userAgentInfo.indexOf(Agents[v]) > 0) {
                        flag = false;
                        break;
                    }
                }
                return flag;
            },
            // #endif
            handleTap() {
                if (this.disabled) return;
                this.$emit('click', {
                    index: Number(this.index)
                });
            },
            handleEnd(e) {
                // #ifndef APP-NVUE
                if (this.disabled) return;
                setTimeout(() => {
                    this.time = 0;
                }, 150);
                // #endif
            },
            bindgetuserinfo({
                detail = {}
            } = {}) {
                this.$emit('getuserinfo', detail);
            },
            bindcontact({
                detail = {}
            } = {}) {
                this.$emit('contact', detail);
            },
            bindgetphonenumber({
                detail = {}
            } = {}) {
                this.$emit('getphonenumber', detail);
            },
            binderror({
                detail = {}
            } = {}) {
                this.$emit('error', detail);
            },
            bindopensetting({
                detail = {}
            } = {}) {
                this.$emit('opensetting', detail);
            },
            bindchooseavatar({
                detail = {}
            } = {}) {
                this.$emit('chooseavatar', detail);
            },
            bindlaunchapp({
                detail = {}
            } = {}) {
                this.$emit('launchapp', detail);
            },
            //v2.3.0+
            agreeprivacyauthorization(e) {
                this.$emit('agreeprivacyauthorization', e);
            },
            addgroupapp(e) {
                this.$emit('addgroupapp', e);
            },
            chooseaddress(e) {
                this.$emit('chooseaddress', e);
            },
            chooseinvoicetitle(e) {
                this.$emit('chooseinvoicetitle', e);
            },
            bindsubscribe(e) {
                this.$emit('subscribe', e);
            },
            bindlogin(e) {
                this.$emit('login', e);
            },
            bindim(e) {
                this.$emit('im', e);
            }
        }
    };
</script>
 
<style scoped>
    .fui-button__wrap {
        position: relative;
        /* #ifndef APP-NVUE */
        background: transparent !important;
        flex-direction: row;
        /* #endif */
    }
 
    .fui-button {
        border-width: 0;
        /* #ifndef APP-NVUE */
        display: flex;
        align-items: center;
        justify-content: center;
        box-sizing: border-box;
        /* #endif */
        border-style: solid;
        position: relative;
        padding-left: 0;
        padding-right: 0;
        /* #ifndef APP-NVUE */
        overflow: hidden;
        transform: translateZ(0);
        -webkit-touch-callout: none;
        -webkit-user-select: none;
        user-select: none;
        /* #endif */
    }
 
    /* #ifndef APP-NVUE */
    .fui-button__thin-border {
        position: absolute;
        width: 200%;
        height: 200%;
        transform-origin: 0 0;
        transform: scale(0.5, 0.5) translateZ(0);
        box-sizing: border-box;
        left: 0;
        top: 0;
        border-radius: 32rpx;
        border-style: solid;
        pointer-events: none;
    }
 
    /* #endif */
 
    .fui-button__flex-1 {
        flex: 1;
        /* #ifndef APP-NVUE */
        width: 100%;
        /* #endif */
    }
 
    .fui-button::after {
        border: 0;
    }
 
    /* #ifdef H5 */
    .fui-button__active-pc {
        position: relative;
    }
 
    .fui-button__opacity-pc:active {
        opacity: 0.5;
    }
 
    .fui-button__active-pc:active::after {
        content: ' ';
        background-color: var(--fui-bg-color-hover, rgba(0, 0, 0, 0.2));
        position: absolute;
        width: 100%;
        height: 100%;
        left: 0;
        right: 0;
        top: 0;
        transform: none;
        z-index: 2;
        border-radius: 0;
    }
 
    /* #endif */
 
    /* #ifndef APP-NVUE */
    .fui-button__active {
        overflow: hidden !important;
    }
 
    .fui-button__active::after {
        content: ' ';
        background-color: var(--fui-bg-color-hover, rgba(0, 0, 0, 0.2));
        position: absolute;
        width: 100%;
        height: 100%;
        left: 0;
        right: 0;
        top: 0;
        transform: none;
        z-index: 2;
        border-radius: 0;
    }
 
    /* #endif */
    .fui-button__text {
        text-align: center;
        flex-direction: row;
        align-items: center;
        justify-content: center !important;
        padding-left: 0 !important;
    }
 
    .fui-button__opacity {
        opacity: 0.5;
    }
 
    .fui-text__bold {
        font-weight: bold;
    }
 
    .fui-button__link {
        border-color: transparent !important;
        background-color: transparent !important;
    }
 
    /* #ifndef APP-NVUE */
    .fui-button__primary {
        border-color: var(--fui-color-primary, #465CFF) !important;
        background: var(--fui-color-primary, #465CFF) !important;
    }
 
 
    .fui-button__success {
        border-color: var(--fui-color-success, #09BE4F) !important;
        background: var(--fui-color-success, #09BE4F) !important;
    }
 
    .fui-button__warning {
        border-color: var(--fui-color-warning, #FFB703) !important;
        background: var(--fui-color-warning, #FFB703) !important;
    }
 
    .fui-button__danger {
        border-color: var(--fui-color-danger, #FF2B2B) !important;
        background: var(--fui-color-danger, #FF2B2B) !important;
    }
 
    .fui-button__purple {
        border-color: var(--fui-color-purple, #6831FF) !important;
        background: var(--fui-color-purple, #6831FF) !important;
    }
 
    .fui-button__gray {
        border-color: var(--fui-bg-color-content, #F8F8F8) !important;
        background: var(--fui-bg-color-content, #F8F8F8) !important;
        color: var(--fui-color-primary, #465CFF) !important;
    }
 
    .fui-btn__gray-color {
        color: var(--fui-color-primary, #465CFF) !important;
    }
 
    /* #endif */
</style>