preview.vue 7.86 KB
<template>
  <div class="img-bg">
    <div class="preview-content">
      <div class="preview-time">{{ currentTime }}</div>
      <div class="preview-info" v-for="item in previewList" :key="item.id">
        <img class="avatar" src="@/assets/guestCustom/default-customer.png" alt />
        <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-activity">
            <div class="activity-name">{{ item.attContent.marketingName }}</div>
            <img v-if="item.attContent.marketingType != 5 && item.attContent.marketingType != 6 && item.attContent.marketingType != 7" class="activity-logo" src="@/assets/guestCustom/activity-logo.png" alt />
            <img v-if="item.attContent.marketingType == 5" class="activity-logo" src="@/assets/guestCustom/activity-spike.png" alt />
            <img v-if="item.attContent.marketingType == 6" class="activity-logo" src="@/assets/guestCustom/activity-service.png" alt />
            <img v-if="item.attContent.marketingType == 7" class="link-logo" src="@/assets/guestCustom/link.png" alt />
            <div class="activity-footer" v-if="item.attContent.marketingType != 7">
              <img src="@/assets/guestCustom/applet-footer.png" alt />
            </div>
          </div>
        </template>
        <template v-else-if="item.attType == 4">
          <div class="preview-activity">
            <div class="activity-name">{{ item.attContent.title }}</div>
            <img class="link-logo" src="@/assets/guestCustom/link.png" alt />
          </div>
        </template>
        <template v-else-if="item.attType == 2">
          <el-image style="width: 100px" :src="item.attContent" fit="contain"></el-image>
        </template>
        <template v-else-if="item.attType == 3">
          <div class="video-panel" :key="itm">
            <video id="video" width="95">
              <source :src="item.attContent" type="video/mp4" />
            </video>
            <i class="el-icon-video-play"></i>
          </div>
        </template>
        <template v-else-if="item.attType == 5">
          <div class="preview-text text preview-applet">
            <div class="preview-applet-title">
              <img :src="item.attContent.picUrl" alt />
              <span>{{ item.attContent.title }}</span>
            </div>
            {{ item.attContent.page }}
          </div>
        </template>
        <template v-else-if="item.attType == 6">
          <div class="preview-pdf">
            <div class="pdf-title">{{ item.attContent.fileName }}</div>
            <div class="preview-link">
              <img src="@/assets/guestCustom/preview-link.png" alt="" />
            </div>
          </div>
        </template>
      </div>
    </div>
  </div>
</template>

<script>
import { utils } from 'glsx-common'
import emoji from '@/utils/emo'
export default {
  name: 'Preview',
  props: { eventBus: Object, previewVal: Array },
  data() {
    return {
      previewList: [],
      currentTime: ''
    }
  },
  watch: {
    previewList(val) {
      if (val.length) {
        val.forEach(item => {
          if (item.attType == 1) {
            const attContent = item.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 style="width: 16px;height: 16px;vertical-align: middle;" src="https://img01.glsx.com.cn/weapp/resource/saas/scrm/emoji/${index}.png">`
            })
            item.attContent = htm
          } else if (item.attType != 2 && item.attType != 3 && item.attType != 7) {
            // console.log(item.attContent, JSON.parse(item.attContent).fileName)
            item.attContent = JSON.parse(item.attContent)
          }
        })
      }
    },
    previewVal: {
      handler(val) {
        console.log(val)
        this.previewList = utils.deepClone(val).filter(item => item.attContent)
      },
      deep: true
    }
  },
  created() {
    if (this.eventBus) {
      this.eventBus.$on('update', val => {
        this.previewList = val
      })
    }
  },
  mounted() {
    const date = new Date()
    let hours = date.getHours()
    hours = hours < 10 ? `0${hours}` : hours
    let minutes = date.getMinutes()
    minutes = minutes < 10 ? `0${minutes}` : minutes
    this.currentTime = `${date.getFullYear()}年${date.getMonth() + 1}月${date.getDate()}日 ${hours}:${minutes}`
  }
}
</script>

<style lang="scss" scoped>
.img-bg {
  position: relative;
  width: 290px;
  height: 566px;
  background-image: url(../../../assets/guestCustom/iphone-bg.png);
  background-size: 100%;
  .preview-content {
    position: absolute;
    width: 250px;
    height: 350px;
    overflow-y: auto;
    top: 115px;
    left: 20px;
    // background-color: cornflowerblue;
    .preview-time {
      font-size: 10px;
      color: #999;
      text-align: center;
      margin-bottom: 15px;
    }
    .preview-info {
      display: flex;
      padding: 0 44px 20px 9px;
      .avatar {
        width: 26px;
        height: 26px;
        margin-right: 8px;
      }
      .preview-text {
        position: relative;
        max-width: 169px;
        color: #333;
        background-color: #fff;
        border-radius: 4px;
        word-break: break-all;
        display: flex;
        // img {
        //   width: 16px;
        //   height: 16px;
        //   vertical-align: middle;
        // }
      }
      .text {
        display: inline-block;
        font-size: 12px;
        padding: 8px 11px;
        line-height: 16px;
        white-space: pre-wrap;
      }
      .preview-link {
        display: flex;
        justify-content: flex-end;
        img {
          width: 30px;
          height: 30px;
        }
      }
      .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;
        }
      }
      .preview-pdf {
        width: 158px;
        height: 62px;
        background-color: #fff;
        padding: 5px 13px;
        box-sizing: border-box;
        .pdf-title {
          font-size: 12px;
          color: #333;
          line-height: 16px;
        }
      }
      .video-panel {
        position: relative;
        .el-icon-video-play {
          position: absolute;
          top: 50%;
          left: 50%;
          transform: translate(-50%, -50%);
          z-index: 10;
          font-size: 20px;
          color: #fff;
          // cursor: pointer;
        }
      }
    }
  }
}
.link-logo {
  width: 30px;
  height: 30px;
  margin-left: 131px;
  margin-bottom: 5px;
}
</style>