江西小程序管理端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

83 lines
2.5 KiB

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