preview.vue 7.51 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">
            <!-- <img class="applet-logo" src="@/assets/guestCustom/applet-logo.png" alt /> -->
            <div class="activity-name">{{item.attContent.marketingName}}</div>
            <img class="activity-logo" src="@/assets/guestCustom/activity-logo.png" alt />
            <div class="activity-footer">
              <img src="@/assets/guestCustom/applet-footer.png" alt />
            </div>
          </div>
          <!-- <div class="preview-text preview-link">
            {{ item.attContent.url }}
            <img src="@/assets/guestCustom/preview-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">
          <!-- <el-image style="width: 100px" :src="item.attContent" fit="contain"></el-image> -->
          <video style="width: 100px" :src="item.attContent"></video>
        </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>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'Preview',
  props: { eventBus: Object },
  data() {
    return {
      previewList: [],
      currentTime: ''
    }
  },
  watch: {
    previewList(val) {
      if (val.length && val[0].attType == 1) {
        const attContent = val[0].attContent
        const htm = attContent.replace(/\[[\u4E00-\u9FA5]{1,3}]/gi, function(res) {
          let word = res.replace(/\[|\]/gi, '')
          const list = [
            '微笑',
            '撇嘴',
            '色',
            '发呆',
            '得意',
            '流泪',
            '害羞',
            '闭嘴',
            '睡',
            '大哭',
            '尴尬',
            '发怒',
            '调皮',
            '呲牙',
            '惊讶',
            '难过',
            '酷',
            '冷汗',
            '抓狂',
            '吐',
            '偷笑',
            '可爱',
            '白眼',
            '傲慢',
            '饥饿',
            '困',
            '惊恐',
            '流汗',
            '憨笑',
            '大兵',
            '奋斗',
            '咒骂',
            '疑问',
            '嘘',
            '晕',
            '折磨',
            '衰',
            '骷髅',
            '敲打',
            '再见',
            '擦汗',
            '抠鼻',
            '鼓掌',
            '糗大了',
            '坏笑',
            '左哼哼',
            '右哼哼',
            '哈欠',
            '鄙视',
            '委屈',
            '快哭了',
            '阴险',
            '亲亲',
            '吓',
            '可怜',
            '菜刀',
            '西瓜',
            '啤酒',
            '篮球',
            '乒乓',
            '咖啡',
            '饭',
            '猪头',
            '玫瑰',
            '凋谢',
            '示爱',
            '爱心',
            '心碎',
            '蛋糕',
            '闪电',
            '炸弹',
            '刀',
            '足球',
            '瓢虫',
            '便便',
            '月亮',
            '太阳',
            '礼物',
            '拥抱',
            '强',
            '弱',
            '握手',
            '胜利',
            '抱拳',
            '勾引',
            '拳头',
            '差劲',
            '爱你',
            'NO',
            'OK',
            '爱情',
            '飞吻',
            '跳跳',
            '发抖',
            '怄火',
            '转圈',
            '磕头',
            '回头',
            '跳绳',
            '挥手',
            '激动',
            '街舞',
            '献吻',
            '左太极',
            '右太极'
          ]
          let index = list.indexOf(word)
          return `<img src="https://res.wx.qq.com/mpres/htmledition/images/icon/emotion/${index}.gif">`
        })
        val[0].attContent = htm
      }
    }
  },
  created() {
    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" scope>
.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-wrap: break-word;
      }
      .text {
        font-size: 16px;
        padding: 8px 11px;
      }
      .preview-link {
        display: inline-flex;
        word-break: break-all;
        font-size: 14px;
        padding: 8px 8px 8px 11px;
        img {
          width: 34px;
          height: 34px;
          margin-left: 10px;
        }
      }
      .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;
        }
      }
    }
  }
}
</style>