preview.vue 8.43 KB
<template>
  <div class="img-bg">
    <div class="preview-content">
      <div class="preview-info" v-show="previewListFilter.length">
        <img class="avatar" src="@/assets/guestCustom/default-customer.png" alt />
        <div class="preview-box" v-for="item in previewListFilter" :key="item.id">
          <div class="preview-box-desc">
            <template v-if="item.attType == 1">
              <div class="preview-text text" v-html="item.attContent"></div>
            </template>
            <template v-else-if="item.attType == 7">
              <div class="preview-text preview-link">
                <img src="@/assets/guestCustom/preview-link.png" alt />
                <div>{{ item.attContent[0].marketingName }}</div>
              </div>
            </template>
            <template v-else-if="item.attType == 2" v-for="(imgItem, index) in item.attContent">
              <el-image style="width: 52px; height: 52px" class="img-list" :src="imgItem" fit="fit" :key="index" :preview-src-list="item.attContent"></el-image>
            </template>
            <template v-else-if="item.attType == 3">
              <!-- <el-image style="width: 100px" :src="item.attContent" fit="contain"></el-image> -->
              <div class="video-panel">
                <video id="video" width="100%" height="100%" preload loop muted>
                  <source :src="item.attContent" type="video/mp4" />
                </video>
                <i
                  class="el-icon-video-play"
                  @click="
                    videoShow = true
                    videoUrl = item.attContent
                  "
                ></i>
              </div>
            </template>
          </div>
        </div>

        <div class="preview-operation">赞 | 评论</div>
      </div>
    </div>
    <div class="video-dialog" v-if="videoShow">
      <div class="video-dialog-panel">
        <div class="video-close"><i class="el-icon-close" @click="videoShow = false"></i></div>
        <video height="100%" autoplay controls :src="this.videoUrl"></video>
      </div>
    </div>
  </div>
</template>

<script>
const ATT_TYPE = {
  TEXT: 1,
  IMAGE: 2,
  VEDIO: 3,
  URL: 4,
  MINIPROGRAM: 5,
  FILE: 6,
  ACTIVITY: 7
}
import emoji from '@/utils/emo'
export default {
  name: 'Preview',
  props: { previewView: Array },
  data() {
    return {
      videoShow: false,
      previewList: [],
      previewListFilter: [],
      videoUrl: ''
    }
  },
  watch: {
    previewView: {
      handler(val) {
        const previewVal = this.$common.utils.deepClone(val).filter(item => item)
        console.log(previewVal)
        this.previewListFilter = []
        for (let i in previewVal) {
          if (previewVal[i].attType == 1) {
            const attContent = previewVal[i].attContent
            const htm = attContent.replace(/\[[\u4E00-\u9FA56]{1,4}]/gi, function (res) {
              let word = res.replace(/\[|\]/gi, '')
              const list = emoji.flat(Infinity)
              let index = parseInt(list.indexOf(word)) + 1
              if (index < 10) {
                index = '00' + index
              } else if (index >= 10 && index < 100) {
                index = '0' + index
              }
              return `<img src="https://img01.glsx.com.cn/weapp/resource/saas/scrm/emoji/${index}.png">`
            })
            this.previewListFilter.push({
              attType: 1,
              attContent: htm
            })
          } else if (previewVal[i].attType == 2) {
            const pindex = this.previewListFilter.findIndex(item => item.attType == 2)
            if (pindex == -1) {
              this.previewListFilter.push({
                attType: 2,
                attContent: [previewVal[i].attContent]
              })
            } else {
              this.previewListFilter[pindex].attContent.push(previewVal[i].attContent)
            }
          } else {
            this.previewListFilter.push({
              attType: previewVal[i].attType,
              attContent: previewVal[i].attContent
            })
          }
        }
        this.$nextTick(() => {
          this.previewListFilter = this.previewListFilter.filter(item => item)
        })
      },
      deep: true
    }
  }
}
</script>

<style lang="scss" scoped>
.img-list {
  margin-right: 3px;
}
.img-bg {
  position: relative;
  width: 240px;
  height: 445px;
  padding: 20px 0;
  background-image: url(../../../assets/guestCustom/friend-bg.png);
  background-size: 100%;
  background-repeat: no-repeat;
  .preview-content {
    position: absolute;
    width: 224px;
    height: 350px;
    overflow-y: auto;
    top: 90px;
    left: 20px;
    // background-color: cornflowerblue;
    .preview-time {
      font-size: 10px;
      color: #999;
      text-align: center;
      margin-bottom: 15px;
    }
    .preview-info {
      padding: 0 0px 20px 9px;
      position: relative;
      .avatar {
        position: absolute;
        top: 0px;
        left: 5px;
        width: 26px;
        height: 26px;
        margin-right: 8px;
      }
      .preview-box {
        margin-left: 30px;
        width: 165px;
      }
      .preview-operation {
        float: right;
        margin-right: 30px;
        margin-top: 15px;
        text-align: center;
        width: 64px;
        height: 22px;
        line-height: 22px;
        background: #f7f7f7;
        font-size: 10px;
        font-weight: 400;
        color: #556993;
      }
      .video-panel {
        width: 100%;
        height: 102px;
        display: flex;
        align-items: center;
        justify-content: center;
        position: relative;
        video {
          position: absolute;
        }
        i {
          z-index: 10;
          font-size: 20px;
          color: #fff;
          cursor: pointer;
        }
      }
      .preview-text {
        font-size: 14px;
        position: relative;
        color: #333;
        background-color: #fff;
        border-radius: 4px;
        word-wrap: break-word;
        word-break: break-all;
        line-height: 20px;
        /deep/ img {
          width: 20px;
          height: 20px;
          vertical-align: middle;
        }
      }
      .text {
        width: 100%;
        font-size: 12px;
        padding: 0px;
        margin-bottom: 6px;
      }
      .preview-link {
        padding: 6px 0px;
        font-size: 12px;
        background: #f7f7f7;
        display: flex;
        align-items: center;
        img {
          margin: 0px 12px 0px 5px;
          width: 24px;
          height: 24px;
        }
        div {
          overflow: hidden;
          text-overflow: ellipsis;
          display: -webkit-box;
          -webkit-line-clamp: 2;
          line-clamp: 2;
          -webkit-box-orient: vertical;
        }
      }
      .preview-text::before {
        content: '';
        position: absolute;
        left: -10px;
        top: 20%;
        border-width: 5px;
        border-style: dashed solid dashed dashed;
        border-color: transparent #fff transparent transparent;
        // background-color: cornflowerblue;
      }
      .preview-applet {
        img {
          width: 20px;
          height: 20px;
          margin-right: 4px;
        }
        &-title {
          display: flex;
          align-self: center;
          color: #999;
          margin-bottom: 5px;
        }
      }
      .preview-activity {
        width: 160px;
        // height: 184px;
        background-color: #fff;
        border-radius: 4px;
        border: 1px solid #dce1e5;
        padding: 7px 7px 0;
        .activity-name {
          font-size: 12px;
          color: #333;
          margin: 7px 0 4px;
          width: 160px;
          text-overflow: ellipsis;
          overflow: hidden;
          white-space: nowrap;
        }
        .applet-logo {
          width: 95px;
          height: 24px;
        }
        .activity-footer {
          margin-top: 4px;
          border-top: 1px solid #edeff3;
        }
      }
    }
  }
}
.video-dialog {
  z-index: 2001;
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  overflow: auto;
  background: rgba($color: #000000, $alpha: 0.5);
  &-panel {
    background: #000000;
    position: absolute;
    top: 100px;
    left: 50%;
    transform: translateX(-50%);
    height: calc(100% - 200px);
    width: auto;
    box-sizing: border-box;
    padding: 10px 20px 20px;
    overflow: hidden;
    .video-close {
      display: flex;
      justify-content: flex-end;
      height: 40px;
      i {
        cursor: pointer;
        font-size: 25px;
        color: #5850ff;
      }
    }
  }
}
</style>