123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- <template>
- <view class="center">
- <!-- <view class="title clamp">{{ item.title }}</view>
- <view class="time">{{ item.add_time }}</view> -->
- <view class="main" v-for="(ls, index) in item.content" :key="index">
- <view v-if="ls.type == 'rich-text'" v-html="ls.value" class="main"></view>
- <video v-if="ls.type == 'video' && ls.value" :src="ls.value" style="width:100%;height: 300px" frameborder="0"></video>
- </view>
- </view>
- </template>
- <script>
- import { details } from '@/api/user.js';
- export default {
- data() {
- return {
- id: '',
- item: ''
- };
- },
- onLoad(option) {
- this.id = option.id;
- this.loadData();
- },
-
- methods: {
- loadData() {
- details({}, this.id).then(({ data }) => {
- console.log(data);
- data.content = data.content.replace(/<img/g, '<img class="rich-img"').replace(/<p>\s*<img/g, '<p class="pHeight"><img').replace(/<div/g, '<div style="max-width: 50% !important;"');
- data.content = this.getVideo(data.content);
- this.item = data;
- uni.setNavigationBarTitle({
- title: data.title
- })
- });
- },
- // 富文本视频解析
- getVideo(data) {
- let videoList = [];
- let videoReg = /<video.*?(?:>|\/>)/gi; //匹配到字符串中的 video 标签
- let srcReg = /src=[\'\"]?([^\'\"]*)[\'\"]?/i; //匹配到字符串中的 video 标签 的路径
- let arr = data.match(videoReg) || []; // arr 为包含所有video标签的数组
- let articleList = data.split('</video>'); // 把字符串 从视频标签分成数组
- arr.forEach((item, index) => {
- var src = item.match(srcReg);
- videoList.push(src[1]); //所要显示的字符串中 所有的video 标签 的路径
- });
- let needArticleList = [];
- articleList.forEach((item, index) => {
- if (item != '' && item != undefined) {
- // 常见的标签渲染
- needArticleList.push({
- type: 'rich-text',
- value: item + '</video>'
- });
- }
- let articleListLength = articleList.length; // 插入到原有video 标签位置
- if (index < articleListLength && videoList[index] != undefined) {
- needArticleList.push({
- type: 'video',
- value: videoList[index]
- });
- }
- });
- return needArticleList;
- }
- }
- };
- </script>
- <style lang="scss">
- page {
- background-color: #fff;
- min-height: 100%;
- height: auto;
- }
- .center {
- min-height: 100%;
- height: auto;
- background: #ffffff;
- padding: 10rpx 24rpx 0;
- }
- .title {
- font-size: 32rpx;
- font-family: PingFang SC;
- font-weight: bold;
- color: #333333;
- }
- .time {
- font-size: 24rpx;
- font-family: PingFangSC;
- font-weight: 500;
- color: #999999;
- margin-top: 40rpx;
- }
- .main {
- // margin-top: 60rpx;
- }
- /deep/ .main {
- .rich-img {
- width: 100% !important;
- height: auto;
- }
- * {
- max-width: 100% !important;
- }
- }
- </style>
|