text.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <template>
  2. <view :class="classList">
  3. <template v-for="item in data">
  4. <text
  5. v-if="item.type === 'text'"
  6. :class="item.data.class"
  7. :style="item.data.style"
  8. class="text"
  9. >
  10. {{item.data.value}}
  11. </text>
  12. <text
  13. v-if="item.type === 'link'"
  14. :class="item.data.class"
  15. :style="item.data.style"
  16. class="link"
  17. @click="goLink(item.data.attributes.link)"
  18. >
  19. {{item.data.value}}
  20. </text>
  21. <image-item v-else-if="item.type === 'image'" :data="item"></image-item>
  22. <!-- #ifdef H5 -->
  23. <br v-else-if="item.type === 'br'" class="br"/>
  24. <!-- #endif -->
  25. <!-- #ifndef H5 -->
  26. <text v-else-if="item.type === 'br'" class="br">\n</text>
  27. <!-- #endif -->
  28. </template>
  29. </view>
  30. </template>
  31. <script>
  32. import ImageItem from './image.vue'
  33. export default {
  34. name: "render-text",
  35. props: {
  36. data: {
  37. type: Array,
  38. default () {
  39. return []
  40. }
  41. },
  42. className: String,
  43. reset: Boolean
  44. },
  45. computed: {
  46. classList () {
  47. return [
  48. 'row-text',
  49. this.className,
  50. this.reset ? 'reset': ''
  51. ]
  52. }
  53. },
  54. components: {
  55. ImageItem
  56. },
  57. methods: {
  58. show () {
  59. uni.showToast({
  60. title: 'test',
  61. icon: 'none'
  62. })
  63. },
  64. // 点击链接跳转
  65. goLink(link) {
  66. // 如果链接为空,则返回
  67. if (!link) return
  68. // #ifdef H5
  69. // 在新窗口中打开链接
  70. window.open(link, '_blank')
  71. // #endif
  72. // #ifdef MP
  73. // 微信小程序不支持打开外链,复制链接到剪贴板
  74. uni.setClipboardData({
  75. data: link,
  76. success: () => {
  77. uni.showToast({
  78. title: '链接已复制',
  79. icon: 'none'
  80. })
  81. }
  82. })
  83. // #endif
  84. // #ifdef APP
  85. // 在webview中打开链接
  86. uni.navigateTo({
  87. url: `/uni_modules/uni-cms-article/pages/webview/webview?url=${encodeURIComponent(link)}`
  88. })
  89. // #endif
  90. }
  91. }
  92. }
  93. </script>
  94. <style scoped lang="scss">
  95. .row-text, .br {
  96. margin-bottom: 40rpx;
  97. &.reset {
  98. margin-bottom: 0;
  99. }
  100. }
  101. .header-1,
  102. .header-2,
  103. .header-3,
  104. .header-4,
  105. .header-5,
  106. .header-6 {
  107. font-weight: bold;
  108. }
  109. .header-1 {
  110. font-size: 44rpx;
  111. }
  112. .header-2 {
  113. font-size: 40rpx;
  114. }
  115. .header-3 {
  116. font-size: 38rpx;
  117. }
  118. .header-4 {
  119. font-size: 32rpx;
  120. }
  121. .header-5 {
  122. font-size: 28rpx;
  123. }
  124. .header-6 {
  125. font-size: 24rpx;
  126. }
  127. .bold {
  128. font-weight: bold;
  129. }
  130. .italic {
  131. font-style: italic;
  132. }
  133. .strike {
  134. text-decoration: line-through;
  135. }
  136. .underline {
  137. text-decoration: underline;
  138. }
  139. .link {
  140. color: #0064f9;
  141. text-decoration: underline;
  142. }
  143. </style>