uv-link.vue 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <template>
  2. <text
  3. class="uv-link"
  4. @tap.stop="openLink"
  5. :style="[linkStyle, $uv.addStyle(customStyle)]"
  6. >{{text}}</text>
  7. </template>
  8. <script>
  9. import mpMixin from '@/uni_modules/uv-ui-tools/libs/mixin/mpMixin.js'
  10. import mixin from '@/uni_modules/uv-ui-tools/libs/mixin/mixin.js'
  11. import props from './props.js';
  12. /**
  13. * link 超链接
  14. * @description 该组件为超链接组件,在不同平台有不同表现形式:在APP平台会通过plus环境打开内置浏览器,在小程序中把链接复制到粘贴板,同时提示信息,在H5中通过window.open打开链接。
  15. * @tutorial https://www.uvui.cn/components/link.html
  16. * @property {String} color 文字颜色 (默认 color['uv-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 <uv-link href="http://www.uvui.cn">蜀道难,难于上青天</uv-link>
  26. */
  27. export default {
  28. name: "uv-link",
  29. emits:['click'],
  30. mixins: [mpMixin, mixin, props],
  31. computed: {
  32. linkStyle() {
  33. const style = {
  34. color: this.color,
  35. fontSize: this.$uv.addUnit(this.fontSize),
  36. // line-height设置为比字体大小多2px
  37. lineHeight: this.$uv.addUnit(this.$uv.getPx(this.fontSize) + 2),
  38. textDecoration: this.underLine ? 'underline' : 'none'
  39. }
  40. return style
  41. }
  42. },
  43. methods: {
  44. openLink() {
  45. // #ifdef APP-PLUS
  46. plus.runtime.openURL(this.href)
  47. // #endif
  48. // #ifdef H5
  49. window.open(this.href)
  50. // #endif
  51. // #ifdef MP
  52. uni.setClipboardData({
  53. data: this.href,
  54. success: () => {
  55. uni.hideToast();
  56. this.$nextTick(() => {
  57. this.$uv.toast(this.mpTips);
  58. })
  59. }
  60. });
  61. // #endif
  62. this.$emit('click')
  63. }
  64. }
  65. }
  66. </script>
  67. <style lang="scss" scoped>
  68. @import '@/uni_modules/uv-ui-tools/libs/css/components.scss';
  69. @import '@/uni_modules/uv-ui-tools/libs/css/color.scss';
  70. $uv-link-line-height:1 !default;
  71. .uv-link {
  72. /* #ifndef APP-NVUE */
  73. line-height: $uv-link-line-height;
  74. /* #endif */
  75. @include flex;
  76. flex-wrap: wrap;
  77. flex: 1;
  78. color: $uv-primary;
  79. }
  80. </style>