shareDialog.vue 3.12 KB
<!-- 分享弹窗 -->
<template>
  <GLDialog title="分享" mode="mid" okText="关闭" :visible.sync="isShareVisible" :before-close="handleShareClose" :hasFooter="false">
    <div class="share-dialog flex">
      <div class="flex box poster">
        <div>
          <p class="share-txt">海报</p>
          <!-- <p>小程序码不带参数</p> -->
          <img style="width: 170px; height: 271px;" :src="shareForm.posterUrl" />
          <el-button style="display: block;margin-top: 16px;" :size="size" type="primary" @click="handleSaveImg(shareForm.posterUrl)">保存图片</el-button>
        </div>
      </div>
      <div style="margin-left: 10px;">
       <div class="flex box code">
         <div>
           <p class="share-txt">小程序码</p>
           <!-- <p>小程序码不带参数</p> -->
           <img style="width: 120px; height: 120px" :src="shareForm.qrCodeUrl" />
           <el-button style="display: block;margin-top: 16px;" :size="size" type="primary" @click="handleSaveImg(shareForm.qrCodeUrl, '小程序码')">保存图片</el-button>
         </div>
       </div>
       <div class="box page-route">
         <div>
           <p class="share-txt">短链</p>
           <div>
             <p class="link">{{ shareForm.linkUrl }}</p>
             <el-button style="display: block;margin-top: 16px;" :size="size" type="primary" @click="handleSaveTxt(shareForm.linkUrl)">复制链接</el-button>
             <!-- <p>链接是直播间原始页面路径,如需加入参数,详见使用方法</p> -->
           </div>
         </div>
       </div>
     </div>
    </div>
  </GLDialog>
</template>

<script>
export default {
  name: 'share',
  data() {
    return {}
  },

  props: {
    isShareVisible: {
      type: Boolean,
      default: false
    },
    shareForm: {
      type: Object,
      default: () => { }
    }
  },

  mounted() { },

  methods: {
    handleSaveImg(url, downloadTxt = '海报') {
      var alink = document.createElement('a')
      alink.href = url
      alink.setAttribute('target', '_blank')
      alink.download = downloadTxt
      alink.click()
      alink.remove()
    },
    handleSaveTxt(txt) {
      this.$message({
        message: '复制成功',
        type: 'success',
        customClass: 'message-Z-zinde'
      })
      const input = document.createElement('input')
      document.body.appendChild(input)
      input.setAttribute('value', txt)
      input.select()
      document.execCommand('Copy')
      document.body.removeChild(input)
    },
    handleShareClose() {
      this.$emit('handleShareClose')
    }
  }
}
</script>
<style scoped>
.share-dialog .box {
  background: #F8F8F8;
  border-radius: 2px;
  padding: 20px;
}
.share-dialog .poster {
  width: 295px;
  height: 425px;
}
.share-dialog .code {
  width: 295px;
  height: 194px;
}
.share-dialog .page-route {
  margin-top: 10px;
  width: 295px;
  height: 179px;
}
.share-dialog .page-route .link {
  width: 295px;
  font-family: PingFangSC-Medium;
  font-size: 14px;
  color: #5092FF;
  font-weight: 500;
}
.share-dialog .share-txt {
  font-family: PingFangSC-Medium;
  font-size: 14px;
  color: #333;
  font-weight: 500;
  margin-bottom: 8px;
}
</style>