blob: 2dd2a7355fca885a808ad4be1e8fbfa02bd45e7a [file] [log] [blame]
guangchao.xu070005a2020-12-07 09:56:40 +08001<template>
2 <text class="u-link" @tap.stop="openLink" :style="{
3 color: color,
4 fontSize: fontSize + 'rpx',
5 borderBottom: underLine ? `1px solid ${lineColor ? lineColor : color}` : 'none',
6 paddingBottom: underLine ? '0rpx' : '0'
7 }">
8 <slot></slot>
9 </text>
10</template>
11
12<script>
13 /**
14 * link 超链接
15 * @description 该组件为超链接组件,在不同平台有不同表现形式:在APP平台会通过plus环境打开内置浏览器,在小程序中把链接复制到粘贴板,同时提示信息,在H5中通过window.open打开链接。
16 * @tutorial https://www.uviewui.com/components/link.html
17 * @property {String} color 文字颜色(默认#606266)
18 * @property {String Number} font-size 字体大小,单位rpx(默认28)
19 * @property {Boolean} under-line 是否显示下划线(默认false)
20 * @property {String} href 跳转的链接,要带上http(s)
21 * @property {String} line-color 下划线颜色,默认同color参数颜色
22 * @property {String} mp-tips 各个小程序平台把链接复制到粘贴板后的提示语(默认“链接已复制,请在浏览器打开”)
23 * @example <u-link href="http://www.uviewui.com">蜀道难,难于上青天</u-link>
24 */
25 export default {
26 name: "u-link",
27 props: {
28 // 文字颜色
29 color: {
30 type: String,
31 default: '#2979ff'
32 },
33 // 字体大小,单位rpx
34 fontSize: {
35 type: [String, Number],
36 default: 28
37 },
38 // 是否显示下划线
39 underLine: {
40 type: Boolean,
41 default: false
42 },
43 // 要跳转的链接
44 href: {
45 type: String,
46 default: ''
47 },
48 // 小程序中复制到粘贴板的提示语
49 mpTips: {
50 type: String,
51 default: '链接已复制,请在浏览器打开'
52 },
53 // 下划线颜色
54 lineColor: {
55 type: String,
56 default: ''
57 }
58 },
59 methods: {
60 openLink() {
61 // #ifdef APP-PLUS
62 plus.runtime.openURL(this.href)
63 // #endif
64 // #ifdef H5
65 window.open(this.href)
66 // #endif
67 // #ifdef MP
68 uni.setClipboardData({
69 data: this.href,
70 success: () => {
71 uni.hideToast();
72 this.$nextTick(() => {
73 this.$u.toast(this.mpTips);
74 })
75 }
76 });
77 // #endif
78 }
79 }
80 }
81</script>
82
83<style lang="scss" scoped>
84 @import "../../libs/css/style.components.scss";
85
86 .u-link {
87 line-height: 1;
88 }
89</style>