u-link.vue 2.4 KB

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