<template>
  <div style="background-color: #f2f2f2; min-height: 100%; width: 100%">
    <div>
      <el-row :gutter="20">
        <el-col :span="5"><div class="grid-content ep-bg-purple" /></el-col>
        <el-col
          style="
            background-color: white;
            height: 100%;
            border: 2px solid #ececec;
            padding: 15px 10px;
            overflow-y: auto;
          "
          :span="14"
        >
          <div
            style="
              height: 100%;
              border: 2px solid #f0f0f0;
              margin-top: 10px;
              min-height: 1000px;
            "
          >
            <div
              style="background-color: #e1e1e1; height: 150px; width: 100%"
              class="grid-content ep-bg-purple"
            >
              <div
                style="
                  font-size: 25px;
                  font-weight: 600;
                  height: 80px;
                  line-height: 80px;
                  text-align: center;
                  border-bottom: 2px solid #63a2ef;
                "
              >
                <div style="font-size: 25px">
                  {{ title1 }}
                </div>
              </div>
              <div
                style="
                  font-size: 14px;
                  height: 25px;

                  text-align: center;

                  line-height: 25px;
                "
              >
                <div style="display: inline-block">作者：{{ createBy }}</div>
                <div style="display: inline-block; margin: 0 25px">
                  发布时间：{{ parseTime(publishTime, "{y}-{m}-{d} {h}:{m}") }}
                </div>
                <div style="display: inline-block">浏览量：{{ views }}</div>
                <!-- <div
                                    style="
                                      display: inline-block;
                                      margin: 0 15px;
                                    "
                                  >
                                    发布部门：
                                  </div> -->
              </div>
              <div style="padding: 30px 15px; background-color: white">
                <div v-html="responseData"></div>
                <div
                  v-for="image in getImagesFromData(responseData)"
                  :key="image"
                >
                  <el-image
                    :fit="contain"
                    :src="image.src"
                    :alt="image.alt"
                    :width="image.width"
                    :height="image.height"
                  />
                </div>
                <div
                  v-if="files == null ? false : true"
                  style="margin-top: 40px"
                >
                  附件：{{ files.url }}
                </div>
              </div>
            </div>
          </div>
        </el-col>
        <el-col :span="5"><div class="grid-content ep-bg-purple" /></el-col>
      </el-row>
    </div>
  </div>
</template>

<script>
import { getArticle } from "@/api/system/article";
export default {
  name: "YinetoaDetail",

  data() {
    return {
      title1: "",
      publishTime: "",
      createBy: "",
      views: "",
      content: "",
    };
  },
  created() {
    this.getArticle();
  },
  mounted() {},

  methods: {
    getImagesFromData(data) {
      // 在这里解析数据，提取图片信息并返回一个包含图片相关属性的数组
      // 例如，假设数据中的图片信息是以<img>标签的形式呈现的：
      const imagePattern =
        /<img\s*src="([^"]+)"\s*alt="([^"]+)"\s*width="(\d+)"\s*height="(\d+)"\s*\/?>/g;
      const images = [];
      let match;
      while ((match = imagePattern.exec(data)) !== null) {
        const src = match[1];
        const alt = match[2];
        const width = parseInt(match[3], 10);
        const height = parseInt(match[4], 10);
        images.push({ src, alt, width, height });
      }
      return images;
    },
    async getArticle() {
      //console.log("id", this.$route.query.id);
      const { data } = await getArticle(this.$route.query.id);
      //console.log("data1111", data);
      this.title1 = data.title;
      this.publishTime = data.publishTime;
      this.createBy = data.createBy;
      this.views = data.views;
      this.files = data.files;
      this.responseData = data.content;
    },
    // goToDetailPage(row) {
    //   this.centerDialogVisible = true;
    //   //console.log("row", row);
    //   this.title1 = row.title;
    //   this.publishTime = row.publishTime;
    //   this.createBy = row.createBy;
    //   this.views = row.views;
    //   this.responseData = row.content;
    // },
  },
};
</script>

<style lang="scss" scoped>
::v-deep img {
  max-width: 790px;
}
html,
body {
  width: 100%;
  height: 100%;
}
</style>
