zhangmeng
2024-04-19 e3ba120cb766a17e098e58d11c39ffc600a3070c
commit | author | age
e3ba12 1 <template>
Z 2     <text
3         class="u-link"
4         @tap.stop="openLink"
5         :style="[linkStyle, $u.addStyle(customStyle)]"
6     >{{text}}</text>
7 </template>
8
9 <script>
10     import props from './props.js';
11
12     /**
13      * link 超链接
14      * @description 该组件为超链接组件,在不同平台有不同表现形式:在APP平台会通过plus环境打开内置浏览器,在小程序中把链接复制到粘贴板,同时提示信息,在H5中通过window.open打开链接。
15      * @tutorial https://www.uviewui.com/components/link.html
16      * @property {String}            color        文字颜色 (默认 color['u-primary'] )
17      * @property {String | Number}    fontSize    字体大小,单位px (默认 15 )
18      * @property {Boolean}            underLine    是否显示下划线 (默认 false )
19      * @property {String}            href        跳转的链接,要带上http(s)
20      * @property {String}            mpTips        各个小程序平台把链接复制到粘贴板后的提示语(默认“链接已复制,请在浏览器打开”)
21      * @property {String}            lineColor    下划线颜色,默认同color参数颜色 
22      * @property {String}            text        超链接的问题,不使用slot形式传入,是因为nvue下无法修改颜色 
23      * @property {Object}            customStyle    定义需要用到的外部样式
24      * 
25      * @example <u-link href="http://www.uviewui.com">蜀道难,难于上青天</u-link>
26      */
27     export default {
28         name: "u-link",
29         mixins: [uni.$u.mpMixin, uni.$u.mixin,props],
30         computed: {
31             linkStyle() {
32                 const style = {
33                     color: this.color,
34                     fontSize: uni.$u.addUnit(this.fontSize),
35                     // line-height设置为比字体大小多2px
36                     lineHeight: uni.$u.addUnit(uni.$u.getPx(this.fontSize) + 2),
37                     textDecoration: this.underLine ? 'underline' : 'none'
38                 }
39                 // if (this.underLine) {
40                 //     style.borderBottomColor = this.lineColor || this.color
41                 //     style.borderBottomWidth = '1px'
42                 // }
43                 return style
44             }
45         },
46         methods: {
47             openLink() {
48                 // #ifdef APP-PLUS
49                 plus.runtime.openURL(this.href)
50                 // #endif
51                 // #ifdef H5
52                 window.open(this.href)
53                 // #endif
54                 // #ifdef MP
55                 uni.setClipboardData({
56                     data: this.href,
57                     success: () => {
58                         uni.hideToast();
59                         this.$nextTick(() => {
60                             uni.$u.toast(this.mpTips);
61                         })
62                     }
63                 });
64                 // #endif
65                 this.$emit('click')
66             }
67         }
68     }
69 </script>
70
71 <style lang="scss" scoped>
72     @import "../../libs/css/components.scss";
73     $u-link-line-height:1 !default;
74
75     .u-link {
76         /* #ifndef APP-NVUE */
77         line-height: $u-link-line-height;
78         /* #endif */
79         @include flex;
80         flex-wrap: wrap;
81         flex: 1;
82     }
83 </style>