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
<template>
    <!--本文件由FirstUI授权予四川政采招投标咨询有限公司(会员ID:1 6 3,营业执照号:    9 151  01 3 1   332 0 06 19 3 K)专用,请尊重知识产权,勿私下传播,违者追究法律责任。-->
    <a v-if="isShowA" class="fui-link__text" :href="href"
        :class="{'fui-link__underline':underline,'fui-link__defcolor':!color,'fui-link__active':highlight}"
        :style="{color:getColor,fontSize:size+'rpx',fontWeight:fontWeight}" :download="download">
        <slot>{{text || href}}</slot>
    </a>
    <!-- #ifndef APP-NVUE -->
    <text v-else class="fui-link__text" :class="{'fui-link__underline':underline,'fui-link__defcolor':!color,'fui-link__active':highlight}"
        :style="{color:getColor,fontSize:size+'rpx',fontWeight:fontWeight}" @tap="openURL">
        <slot>{{text || href}}</slot>
    </text>
    <!-- #endif -->
    <!-- #ifdef APP-NVUE -->
    <text v-else class="fui-link__text" :class="{'fui-link__underline':underline,'fui-link__defcolor':!color,'fui-link__active':highlight}"
        :style="{color:getColor,fontSize:size+'rpx',fontWeight:fontWeight}" @tap="openURL">{{text || href}}</text>
    <!-- #endif -->
</template>
 
<script>
    export default {
        name: 'fui-link',
        // #ifdef MP-WEIXIN
        options: {
            virtualHost: true
        },
        // #endif
        props: {
            href: {
                type: String,
                default: ''
            },
            text: {
                type: String,
                default: ''
            },
            download: {
                type: String,
                default: ''
            },
            underline: {
                type: [Boolean, String],
                default: false
            },
            copyTips: {
                type: String,
                default: '链接已复制'
            },
            color: {
                type: String,
                default: ''
            },
            size: {
                type: [Number, String],
                default: 28
            },
            fontWeight: {
                type: [Number, String],
                default: 400
            },
            highlight: {
                type: Boolean,
                default: false
            }
        },
        computed: {
            isShowA() {
                let h5 = false
                // #ifdef H5
                h5 = true;
                // #endif
                if ((this.isMail() || this.isTel()) && h5) {
                    return true;
                }
                return false;
            },
            getColor() {
                let color = this.color;
                // #ifdef APP-NVUE
                if (!color || color === true) {
                    const app = uni && uni.$fui && uni.$fui.color;
                    color = (app && app.link) || '#465CFF';
                }
                // #endif
                return color;
            }
        },
        methods: {
            isMail() {
                return this.href.startsWith('mailto:');
            },
            isTel() {
                return this.href.startsWith('tel:');
            },
            openURL() {
                // #ifdef APP-PLUS
                if (this.isTel()) {
                    this.makePhoneCall(this.href.replace('tel:', ''));
                } else {
                    plus.runtime.openURL(this.href);
                }
                // #endif
                // #ifdef H5
                window.open(this.href)
                // #endif
                // #ifdef MP
                uni.setClipboardData({
                    data: this.href,
                    success: () => {
                        uni.showToast({
                            title: this.copyTips,
                            icon: 'none'
                        });
                    }
                });
 
                // #endif
            },
            makePhoneCall(phoneNumber) {
                uni.makePhoneCall({
                    phoneNumber
                })
            }
        }
    }
</script>
 
<style scoped>
    /* #ifdef H5 */
    .fui-link__text {
        cursor: pointer;
    }
 
    /* #endif */
    .fui-link__underline {
        text-decoration: underline;
    }
 
    /* #ifndef APP-NVUE */
    .fui-link__defcolor {
        color: var(--fui-color-link, #465CFF) !important;
    }
 
    /* #endif */
    .fui-link__active:active{
        opacity: .5;
    }
</style>