messageInfo.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <template>
  2. <view class="center">
  3. <view class="title clamp">{{ item.title }}</view>
  4. <view class="tip flex">
  5. <view class="tip-left">作者:{{ item.author }}</view>
  6. <view class="tip-right">{{ item.add_time }}</view>
  7. </view>
  8. <view class="conetnt" v-for="(ls, index) in item.content" :key="index">
  9. <view v-if="ls.type == 'rich-text'" v-html="ls.value" class="main"></view>
  10. <video v-if="ls.type == 'video' && ls.value" :src="ls.value" style="width:100%;height: 300px"
  11. frameborder="0"></video>
  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. loadData() {
  32. details({}, this.id).then(({
  33. data
  34. }) => {
  35. console.log(data);
  36. data.content = data.content.replace(/<img/g, '<img class="rich-img"').replace(/<p>\s*<img/g,
  37. '<p class="pHeight"><img');
  38. data.content = this.getVideo(data.content);
  39. this.item = data;
  40. });
  41. },
  42. // 富文本视频解析
  43. getVideo(data) {
  44. let videoList = [];
  45. let videoReg = /<video.*?(?:>|\/>)/gi; //匹配到字符串中的 video 标签
  46. let srcReg = /src=[\'\"]?([^\'\"]*)[\'\"]?/i; //匹配到字符串中的 video 标签 的路径
  47. let arr = data.match(videoReg) || []; // arr 为包含所有video标签的数组
  48. let articleList = data.split('</video>'); // 把字符串 从视频标签分成数组
  49. arr.forEach((item, index) => {
  50. var src = item.match(srcReg);
  51. videoList.push(src[1]); //所要显示的字符串中 所有的video 标签 的路径
  52. });
  53. let needArticleList = [];
  54. articleList.forEach((item, index) => {
  55. if (item != '' && item != undefined) {
  56. // 常见的标签渲染
  57. needArticleList.push({
  58. type: 'rich-text',
  59. value: item + '</video>'
  60. });
  61. }
  62. let articleListLength = articleList.length; // 插入到原有video 标签位置
  63. if (index < articleListLength && videoList[index] != undefined) {
  64. needArticleList.push({
  65. type: 'video',
  66. value: videoList[index]
  67. });
  68. }
  69. });
  70. return needArticleList;
  71. }
  72. }
  73. };
  74. </script>
  75. <style lang="less">
  76. page {
  77. background-color: #FFF;
  78. min-height: 100%;
  79. }
  80. .center {
  81. width: 100%;
  82. height: 100%;
  83. }
  84. .title {
  85. padding: 30rpx 30rpx 0 24rpx;
  86. font-size: 32rpx;
  87. font-family: PingFang SC;
  88. font-weight: bold;
  89. color: #333333;
  90. }
  91. .tip {
  92. padding: 38rpx 32rpx 28rpx 24rpx;
  93. font-size: 24rpx;
  94. font-family: PingFang SC;
  95. font-weight: 500;
  96. color: #666666;
  97. border-bottom: 1px solid #e9e9e9;
  98. }
  99. .conetnt{
  100. padding: 30rpx;
  101. }
  102. /deep/ .main {
  103. .rich-img {
  104. width: 100% !important;
  105. height: auto;
  106. }
  107. }
  108. </style>