artDetail.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <template>
  2. <view class="center">
  3. <!-- <view class="title clamp">{{ item.title }}</view>
  4. <view class="time">{{ item.add_time }}</view> -->
  5. <view class="main" v-for="(ls, index) in item.content" :key="index">
  6. <view v-if="ls.type == 'rich-text'" v-html="ls.value" class="main"></view>
  7. <video v-if="ls.type == 'video' && ls.value" :src="ls.value" style="width:100%;height: 300px"
  8. frameborder="0"></video>
  9. </view>
  10. <view class="uu" v-if="item.url" @click="navto(item.url)">
  11. 点击跳转查看更多
  12. </view>
  13. </view>
  14. </template>
  15. <script>
  16. import {
  17. details
  18. } from '@/api/user.js';
  19. export default {
  20. data() {
  21. return {
  22. id: '',
  23. item: ''
  24. };
  25. },
  26. onLoad(option) {
  27. this.id = option.id;
  28. this.loadData();
  29. },
  30. methods: {
  31. navto(uu) {
  32. if(uu.indexOf('http') == -1) {
  33. uni.navigateTo({
  34. url:uu,
  35. fail() {
  36. uni.switchTab({
  37. url:uu
  38. })
  39. }
  40. })
  41. }else {
  42. window.location.href = uu
  43. }
  44. },
  45. loadData() {
  46. details({}, this.id).then(({
  47. data
  48. }) => {
  49. console.log(data);
  50. data.content = data.content.replace(/<img/g, '<img class="rich-img"').replace(/<p>\s*<img/g,
  51. '<p class="pHeight"><img').replace(/<div/g, '<div style="max-width: 50% !important;"');
  52. data.content = this.getVideo(data.content);
  53. this.item = data;
  54. });
  55. },
  56. // 富文本视频解析
  57. getVideo(data) {
  58. let videoList = [];
  59. let videoReg = /<video.*?(?:>|\/>)/gi; //匹配到字符串中的 video 标签
  60. let srcReg = /src=[\'\"]?([^\'\"]*)[\'\"]?/i; //匹配到字符串中的 video 标签 的路径
  61. let arr = data.match(videoReg) || []; // arr 为包含所有video标签的数组
  62. let articleList = data.split('</video>'); // 把字符串 从视频标签分成数组
  63. arr.forEach((item, index) => {
  64. var src = item.match(srcReg);
  65. videoList.push(src[1]); //所要显示的字符串中 所有的video 标签 的路径
  66. });
  67. let needArticleList = [];
  68. articleList.forEach((item, index) => {
  69. if (item != '' && item != undefined) {
  70. // 常见的标签渲染
  71. needArticleList.push({
  72. type: 'rich-text',
  73. value: item + '</video>'
  74. });
  75. }
  76. let articleListLength = articleList.length; // 插入到原有video 标签位置
  77. if (index < articleListLength && videoList[index] != undefined) {
  78. needArticleList.push({
  79. type: 'video',
  80. value: videoList[index]
  81. });
  82. }
  83. });
  84. return needArticleList;
  85. }
  86. }
  87. };
  88. </script>
  89. <style lang="scss">
  90. page {
  91. background-color: #fff;
  92. min-height: 100%;
  93. height: auto;
  94. }
  95. .center {
  96. min-height: 100%;
  97. height: auto;
  98. background: #ffffff;
  99. padding: 10rpx 24rpx 0;
  100. }
  101. .title {
  102. font-size: 32rpx;
  103. font-family: PingFang SC;
  104. font-weight: bold;
  105. color: #333333;
  106. }
  107. .time {
  108. font-size: 24rpx;
  109. font-family: PingFangSC;
  110. font-weight: 500;
  111. color: #999999;
  112. margin-top: 40rpx;
  113. }
  114. .main {
  115. // margin-top: 60rpx;
  116. }
  117. /deep/ .main {
  118. text-align: justify;
  119. .rich-img {
  120. width: 100% !important;
  121. height: auto;
  122. }
  123. * {
  124. max-width: 100% !important;
  125. }
  126. li {
  127. list-style: none;
  128. padding: 0;
  129. margin: 0;
  130. }
  131. ul {
  132. padding: 0;
  133. margin: 0;
  134. }
  135. }
  136. .uu {
  137. padding-bottom: 40rpx;
  138. }
  139. </style>