preview.vue 8.07 KB
<template>
  <div class="img-bg">
    <div class="preview-content">
      <div class="preview-info" v-show="previewList.length">
        <img class="avatar" src="@/assets/guestCustom/default-customer.png" alt />
        <div class="preview-box" v-for="item in previewList" :key="item.id">
          <div class="preview-box-desc">
            <template v-if="item.attType == 1">
              <div class="preview-text text" v-html="item.attContent[0]"></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 && !previewList.map(k => k.attType).includes(3)" 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[0]" type="video/mp4" />
                </video>
                <i
                  class="el-icon-video-play"
                  @click="
                    videoShow = true
                    videoUrl = item.attContent[0]
                  "
                ></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: { eventBus: Object },
  data() {
    return {
      videoShow: false,
      previewList: [],
      previewListFilter: [],
      videoUrl: ''
    }
  },
  watch: {
    previewList(val) {
      console.log(val)
      if (val.length && val[0].attType == 1) {
        const attContent = val[0].attContent[0]
        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">`
        })
        val[0].attContent[0] = htm
      }
      //图片合并
      // const previewListFilter = val.map(item=>{
      //   return {
      //     attContent: [item.attContent],
      //     attType: item.attType
      //   }
      // })
      // this.previewListFilter =  previewListFilter.reduce((prev, cur) => {
      //   let index = prev.find(item=>item.attType == ATT_TYPE.IMAGE)
      //   if(index != -1 && prev.length) {
      //     return prev[index].attContent.concat(cur.attContent)
      //   }
      //   return prev.concat(cur)
      // },[])
      // console.log(this.previewListFilter)
    }
  },
  created() {
    this.eventBus.$on('update', val => {
      setTimeout(() => {
        this.previewList = val
      }, 100)
    })
  },
  mounted() {}
}
</script>

<style lang="scss" scoped>
.img-list {
  margin-right: 3px;
}
.img-bg {
  position: relative;
  width: 290px;
  height: 566px;
  background-image: url(../../../assets/guestCustom/friend-bg.png);
  background-size: 100%;
  .preview-content {
    position: absolute;
    width: 250px;
    height: 350px;
    overflow-y: auto;
    top: 125px;
    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: 180px;
      }
      .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>