pc端的富文本数据展示:需要做哪些处理

请认真阅读富文本的注释(富文本区域):

<template>
  <div class="JournalismDetail_BOX">
    <!-- 新闻资讯 -->
    <div class="Journalism_heard">
      <img src="../../assets/news_banner@2x.png" />
    </div>
    <div class="JournalismDetail_box">
      <div class="left_box">
        <!-- 头部导航位置 -->
        <div class="Navigation_position">
          <div class="Navigation_content">
            <!-- <span> 当前位置:</span> -->
            <a-breadcrumb class="breadcrumb_box">
              <span> 当前位置:</span>
              <a-breadcrumb-item
                ><a class="breadcrumb_item" href="/newsInformation"
                  >新闻资讯</a
                ></a-breadcrumb-item
              >
              <a-breadcrumb-item>新闻详情</a-breadcrumb-item>
            </a-breadcrumb>
          </div>
          <div class="Navigation_return" @click="backOff">返回上一级</div>
        </div>
        <!-- 标题位置 -->
        <div class="text_box">
          <div class="text">{{ journalismDetail.title || '暂无数据' }}</div>
          <div class="Information_situation">
            <div class="Information_content">
              <span>信息来源:</span
              ><span>{{ journalismDetail.category || '暂无数据' }}</span>
            </div>
            <div class="Information_content">
              <span>发布时间:</span
              ><span>{{
                formatDate(journalismDetail.pubDate, 'D') || '暂无数据'
              }}</span>
            </div>
            <!-- <div class="Information_content">
              <span>浏览量:</span
              ><span>{{ journalismDetail.click || "暂无数据" }}</span>
            </div> -->
          </div>
          <!-- 富文本html开始 -->
          <div
            class="article_start ql-editor content-detail"
            v-html="journalismDetail.content"
          ></div>
            <!-- 富文本html结束 -->
          <div class="enclosure_box" v-if="NewsAnnex()">
            <div class="enclosure_name">相关附件</div>
            <div
              class="enclosure_content"
              v-for="(item, index) in journalismDetail.attachment"
              :key="index"
            >
              <div class="enclosure_index">{{ index + 1 }}.</div>
              <div class="enclosure_file">
                <a :href="$ServerBaseUrl + `/api/file/download/${item.uuid}`">
                  {{ item.name }}</a
                >
              </div>
            </div>
          </div>

          <!-- 上下页区域 -->
          <div class="Page_UpAndDown">
            <!-- 上下页 -->
            <div class="Page_Up">
              <span @click="topPage()">上一页:</span>
              <span @click="goNewsDetail(newsType[topPageInit - 1].uuid)">{{
                newsType[topPageInit - 1].title !== ''
                  ? newsType[topPageInit - 1].title
                  : '暂无数据'
              }}</span>
            </div>
            <div class="Page_Down" v-if="newsType.length >= 2">
              <span @click="bottomPage()">下一页:</span>

              <span @click="NewsBottomPage(pageNumData[topPageInit].uuid)">{{
                newsType[topPageInit].title !== ''
                  ? newsType[topPageInit].title
                  : '暂无数据'
              }}</span>
              <!-- <span
                v-else
                @click="NewsBottomPage(pageNumData[topPageInit].uuid)"
              >
                暂无数据
              </span> -->
            </div>
          </div>
        </div>
      </div>
      <div class="right_box">
        <div class="recommended_reading">
          <div class="recommended_reading_content">推荐阅读</div>
          <!-- :class="{ Read_the_title_blur: selectSidebars == item.id }" -->
          <div
            class="Read_the_title"
            v-for="(item, index) in newsType"
            :key="index"
            @click="selectSidebar(index, item.uuid)"
          >
            <span class="Dot"></span>
            {{ item.title || '暂无数据' }}
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
// import { Pagination } from 'antd';
export default {
  data() {
    return {
      JournalismState: true, // 有无新闻内容
      sidebarContentColor: false, // 侧边栏选中项文字颜色
      selectSidebars: null, // 默认选中项
      page: 1,
      navigation: '', // 路由传递的参数
      uuid: '', // 路由传递过来的当前数据id
      newsType: [
        {
          title: '暂无数据',
        },
        {
          title: '暂无数据',
        },
      ], // 推荐的侧边栏数据
      selectContentText: null, // 广告标题选中的颜色
      journalismDetail: {
        title: '',
        category: '',
        pubDate: '',
        click: '',
        content: '',
      }, // 初始化数据
      topPageInit: 1, // 当前位置
      pageNumData: [
        // {
        //   title: "",
        // },
        // {
        //   title: "",
        // },
      ], // 上下页数的数据
      bottomPageInit: 1, // 下一页
      topPageTitle: '', // 上一页显示的标题
      botmPageNoTitle: false, // 下一页显示的标题
      pageActuelleUp: '', // 上一页展示的数据
      pageActuelleBot: '', // 下一页展示的数据
      isNewsAnnex: false, // 控制附件是否显示
    }
  },
  mounted() {
    this.navigation = this.$route.query.navigation
    this.uuid = this.$route.query.uuid
    this.getInitData()
  },
  methods: {
    //格式化日期
    formatDate(date, flag) {
      return '-'
      if (date) {
        if (flag == 'm') {
          return date.substring(0, date.length - 3)
        } else if (flag == 'D') {
          return date.substring(0, date.length - 8)
        }
      }
    },
       // 初始化的时候对富文本进行处理  富文本js开始 this.$ServerBaseUrl是配置好的域名ip地址
    getInitData() {
      this.$get(`/api/article/quanzhou/public/${this.uuid}/click`).then(
        (res) => {
          // console.log(res.data, "获取富文本");
            // 对富文本字段进行处理 RegExp方法处理字符串,参数1要检索的字段,参数2替换成的值
          const regex2 = new RegExp('src="/api', 'gi')
          res.data.content = res.data.content.replace(
            regex2,
            `src="${this.$ServerBaseUrl}/api`
          )
          this.journalismDetail = res.data
          this.$get(
            `/api/article/quanzhou/public/page?statusIn=1&size=8&type=XWZX&categoryId=${res.data.categoryId}`
          ).then((data) => {
            let newData = data.data.content
            this.pageNumData = data.data.content
            // console.log(data.data.content, newData[0], newData[1], 999);
            // newData.splice(0, 1);
            newData.shift() // 删除第一个
            this.newsType = newData
            // console.log(data.data.content, newData, 6666);
            // this.NewsAnnex(); // 查看福建是否存在
            // 处理富文本图片显示不出来的问题
            // const regex = new RegExp("<img", "gi");
            // const regex2 = new RegExp('src="/api', "gi");
            // richtext = richtext.replace(
            //   regex2,
            //   `src="${this.$ServerBaseUrl}/api`
            // );
            // richtext = richtext.replace(regex, `<img style="max-width: 100%;"`);
          })
        }
      )
    },
    // 选择的侧边栏
    selectSidebar(i, uuid) {
      // console.log(i);
      this.selectSidebars = ++i
      // console.log(this.selectSidebars);
      this.uuid = uuid
      this.getInitData()
    },
    // 文章列表选中
    articleList(i) {
      this.selectContentText = ++i
      // console.log(this.selectContentText);
    },
    // 当前页数
    onChange(current) {
      this.current = current
      // console.log(this.current);
    },
    // 附件展示和隐藏 length 报错是这里影响的
    NewsAnnex() {
      let attachmentLength =
        this.journalismDetail.attachment == [] ? false : true
      if (attachmentLength) {
        this.isNewsAnnex = true
        return true
      } else {
        this.isNewsAnnex = false
        return false
      }
    },
    // 后退一步
    backOff() {
      this.$router.go(-1)
    },
    // 上一页
    topPage() {
      // console.log(this.newsType, "数组情况");
      // console.log(this.topPageInit, "看页数");
      if (this.topPageInit <= 0) {
        this.topPageInit = 0
        this.getInitData()
      } else {
        // console.log(this.topPageInit, "看页数");
        // this.topPageTitle = this.newsType[this.topPageInit - 1].title;
        this.topPageInit -= 1
        // console.log(this.topPageInit, "看页数");
        // debugger;
      }
      // this.topPageInit -= 1;
      // console.log(this.topPageInit,"看页数");
    },
    // 下一页
    bottomPage() {
      let botmNew = this.pageNumData.length
      if (this.topPageInit >= botmNew - 1) {
        this.topPageInit = 1
        this.getInitData()
      } else {
        this.botmPageTitle = this.pageNumData[this.topPageInit + 1].title
        // console.log(this.botmPageTitle);
        // debugger
        // if(this.pageNumData[this.topPageInit + 1].title){
        //     this.botmPageNoTitle=true
        // }
        this.topPageInit += 1
        // console.log(this.topPageInit);
      }
    },

    // 上一页新的详情页
    goNewsDetail(uuid) {
      this.$get(`/api/article/quanzhou/public/${uuid}/click`).then((res) => {
        // console.log(res, "-----");
        this.uuid = uuid
        this.getInitData()
        // this.journalismDetail = res.data;
      })
    },
    // 下一页新的详情页
    NewsBottomPage(uuid) {
      this.$get(`/api/article/quanzhou/public/${uuid}/click`).then((res) => {
        // console.log(res, "-----");
        this.uuid = uuid
        this.getInitData()
        // this.journalismDetail = res.data;
      })
    },
  },
}
</script>

<style lang="less" scoped>
.JournalismDetail_BOX {
  background-color: #f5f5f5;
  padding-bottom: 40px;
  .Journalism_heard {
    width: 100%;
    height: 400px;
    background-color: rgb(127, 169, 192);
    > img {
      width: 100%;
      height: 400px;
    }
  }
  .JournalismDetail_box {
    width: 1200px;
    // height: 2080px; // 设计图的尺寸
    // height: 1200px; // 自定义尺寸
    height: 100%;
    background-color: #fff;
    margin: 22px auto;
    display: flex;
    justify-content: flex-start;
    .left_box {
      width: 900px;
      height: 100%;
      background-color: #fff;
      // margin-right: 20px;
      padding: 20px;
      border-right: 20px solid #f5f5f5;
      .Navigation_position {
        display: flex;
        justify-content: space-between;
        height: 31px;
        border-bottom: 1px solid #d8d8d8;
        margin-bottom: 39px;
        .Navigation_content {
          flex: 1;
          height: 20px;
          .breadcrumb_box {
            > span {
              height: 20px;
              color: #666666;
              font-weight: 400;
              font-size: 14px;
            }
            .breadcrumb_item {
              color: #666666;
              &:hover {
                color: #00468e;
              }
            }
          }
        }
        .Navigation_return {
          height: 20px;
          cursor: pointer;
          color: #999999;
          &:hover {
            color: #333333;
          }
        }
      }
      .text_box {
        .text {
          font-family: PingFangSC-Regular, PingFang SC;
          font-size: 18px;
          font-weight: 400;
          color: #333333;
          text-align: center;
          margin-bottom: 10px;
        }
        .Information_situation {
          // width: 494px;
          width: 374px;
          display: flex;
          justify-content: space-between;
          margin: 0 auto;
          margin-bottom: 30px;
          .Information_content {
            > span {
              font-size: 14px;
              font-weight: 400;
              color: #666666;
            }
          }
        }
        .article_start {
          font-size: 14px;
          font-weight: 400;
          color: #333333;
        }
        .enclosure_box {
          margin-top: 40px;
          border-top: 1px solid #d8d8d8;
          .enclosure_name {
            margin: 16px 0px;
            font-size: 16px;
            color: #333;
            font-weight: 500;
          }
          .enclosure_content {
            display: flex;
            justify-content: flex-start;
            margin-bottom: 10px;
            .enclosure_index {
              margin-right: 20px;
            }
          }
        }

        #Journalism_text {
          width: 100%;
          height: 800px;
          line-height: 700px;
          resize: none;
          background-color: #fff;
          text-align: center;
          scroll-margin-inline-start: 1px solid #f2f2f2;
          -webkit-scrollbar: 1px;
          margin-bottom: 72px;
        }
        .Page_UpAndDown {
          margin: 60px auto;
          .Page_Up {
            cursor: pointer;
            > span {
              height: 28px;
              font-size: 14px;
              font-weight: 400;
              color: #333333;
              line-height: 28px;

              &:hover {
                color: #00468e;
              }
            }
          }
          .Page_Down {
            cursor: pointer;
            > span {
              height: 28px;
              font-size: 14px;
              font-weight: 400;
              color: #333333;
              line-height: 28px;
              &:hover {
                color: #00468e;
              }
            }
            // &:nth-child(2) {
            //   &:hover {
            //     color: #00468e;
            //   }
            // }
          }
        }
      }
    }
    .right_box {
      width: 280px;
      height: 100%;
      background-color: #fff;
      padding: 20px 20px;
      .recommended_reading {
        .recommended_reading_content {
          position: relative;
          font-size: 18px;
          font-weight: 400;
          color: #333333;
          // padding-left: 5px; // 效果图的距离
          padding-left: 10px;
          margin-bottom: 10px;
          &::before {
            width: 3px;
            height: 18px;
            //   height: 25px;
            background-color: #00468e;
            border-radius: 2px 0px 2px 0px;
            position: absolute;
            content: '';
            top: 0px;
            bottom: 0;
            left: 0;
            margin: auto;
            background: #026bac;
            box-shadow: 0px 1px 1px 0px rgba(2, 107, 172, 0.3);
            margin-top: auto;
            margin-right: auto;
            margin-bottom: auto;
            margin-left: auto;
            border-top-left-radius: 50px;
            border-top-right-radius: 0px;
            border-bottom-right-radius: 50px;
            border-bottom-left-radius: 0px;
            background-image: initial;
            background-position-x: initial;
            background-position-y: initial;
            background-size: initial;
            background-repeat-x: initial;
            background-repeat-y: initial;
            background-attachment: initial;
            background-origin: initial;
            background-clip: initial;
            background-color: #00468e;
          }
        }
        .Read_the_title {
          position: relative;
          padding-left: 10px;
          padding-bottom: 10px;
          cursor: default;
          font-size: 14px;
          font-weight: 400;
          color: #333333;
          cursor: pointer;
          &:hover {
            color: #00468e;
          }
          // &::before {
          //   width: 4px;
          //   height: 4px;
          //   background-color: #333;
          //   border-radius: 50%;
          //   position: absolute;
          //   content: "";
          //   top: 9px;
          //   left: 0;
          //   background-color: #00468e;
          //   background-image: initial;
          //   background-position-x: initial;
          //   background-position-y: initial;
          //   background-size: initial;
          //   background-repeat-x: initial;
          //   background-repeat-y: initial;
          //   background-attachment: initial;
          //   background-origin: initial;
          //   background-clip: initial;
          //   &:hover {
          //     background-color: #00468e;
          //   }
          // }
          .Dot {
            width: 4px;
            height: 4px;
            background-color: #333;
            border-radius: 50%;
            position: absolute;
            top: 9px;
            left: 0;
            &:hover {
              background-color: #00468e;
            }
          }
        }
        // 小圆点高亮蓝色
        .Read_the_title:hover > .Dot {
          background-color: #00468e;
        }
        //   动态添加颜色
        // .Read_the_title_blur {
        //   color: #00468e;
        //   &::before {
        //     background-color: #00468e;
        //   }
        // }
      }
    }
  }
}
</style>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值