index.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <template>
  2. <view class="content">
  3. <template v-for="op in content">
  4. <render-text
  5. v-if="op.type === 'paragraph'"
  6. :data="op.data"
  7. :className="op.class"
  8. :style="op.style"
  9. ></render-text>
  10. <render-image
  11. v-else-if="op.type === 'image' && op.data.length > 0"
  12. :data="op.data[0]"
  13. :className="op.class"
  14. :style="op.style"
  15. ></render-image>
  16. <render-list
  17. v-else-if="op.type === 'list'"
  18. :data="op.data"
  19. :style="op.style"
  20. ></render-list>
  21. <view
  22. v-else-if="op.type === 'divider'"
  23. class="divider"
  24. ></view>
  25. <render-video
  26. v-else-if="op.type === 'mediaVideo'"
  27. :data="op.data"
  28. ></render-video>
  29. <render-unlock-content
  30. v-else-if="op.type === 'unlockContent'"
  31. :adp-id="adConfig.adpId"
  32. :watch-ad-unique-type="adConfig.watchAdUniqueType"
  33. ></render-unlock-content>
  34. </template>
  35. </view>
  36. </template>
  37. <script>
  38. import {parseImageUrl} from "@/uni_modules/uni-cms-article/common/parse-image-url"
  39. import text from './text.vue'
  40. import image from './image.vue'
  41. import video from './video.vue'
  42. import list from './list.vue'
  43. import unlockContent from './unlock-content.vue'
  44. export default {
  45. name: "render-article-detail",
  46. props: {
  47. content: {
  48. type: Array,
  49. default () {
  50. return []
  51. }
  52. },
  53. contentImages: {
  54. type: Array,
  55. default () {
  56. return []
  57. }
  58. },
  59. adConfig: {
  60. type: Object,
  61. default: {}
  62. }
  63. },
  64. data() {
  65. return {
  66. articleImages: []
  67. }
  68. },
  69. components: {
  70. renderUnlockContent: unlockContent,
  71. renderText: text,
  72. renderImage: image,
  73. renderList: list,
  74. renderVideo: video
  75. },
  76. mounted() {
  77. this.initImage()
  78. },
  79. // #ifdef VUE2
  80. beforeDestroy() {
  81. uni.$off('imagePreview')
  82. },
  83. // #endif
  84. // #ifdef VUE3
  85. beforeUnmount () {
  86. uni.$off('imagePreview')
  87. },
  88. // #endif
  89. methods: {
  90. // 初始化图片
  91. async initImage() {
  92. // 获取所有图片
  93. const parseImages = await parseImageUrl(this.contentImages)
  94. if (parseImages != null) {
  95. this.articleImages = parseImages.map(image => image.src)
  96. }
  97. // 监听图片预览
  98. uni.$on('imagePreview', this.imagePreview)
  99. },
  100. // 点击图片预览
  101. imagePreview(src) {
  102. if (src) {
  103. uni.previewImage({
  104. current: src.split('?')[0], // 当前显示图片的http链接
  105. urls: this.articleImages // 需要预览的图片http链接列表
  106. })
  107. }
  108. },
  109. }
  110. }
  111. </script>
  112. <style scoped lang="scss">
  113. .content {
  114. line-height: 1.75;
  115. font-size: 32rpx;
  116. margin-top: 40rpx;
  117. padding: 0 30rpx 80rpx;
  118. word-break: break-word;
  119. color: #333;
  120. }
  121. .divider {
  122. height: 1px;
  123. background: #d8d8d8;
  124. width: 100%;
  125. margin: 40rpx 0;
  126. }
  127. </style>