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.

87 lines
2.7 KiB

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