bindWx.vue 2.18 KB
<template>
    <div>
        <el-dialog
          class="qrcode-dialog"
          :show-close="false"
          width="15%"
          top="26vh"
          :visible.sync="dialogVisible">
            <div class="qrcode-wrapper">
                <span>请用微信扫描如下二维码</span>
                <div id="qrcode" ref="qrcode">{{ msg }}</div>
            </div>
        </el-dialog>
    </div>
</template>

<script>
import QRCode from "qrcodejs2"
export default {
    data() {
        return {
            dialogVisible: false,
            msg: ''
        }
    },
    watch: {
      dialogVisible(newVal,oldVal){
          if(!newVal){
              this.$emit('ChildBindEnd',true)
          }
      }
    },
    methods: {
        dialogInit() {
            this.dialogVisible = true;
            this.msg = this.$t('echartsTitle.loading')
            this.getWechatUrl()
        },
        getWechatUrl() {
            let params = {
                userUnid: this.$cookie.get('unid')
            }
            this.$api.management.wechatUrl(window._vionConfig.messageUrl, params)
            .then(res => {
                let result = res.data.data;
                let wechatUrl = result.bindUrl;
                setTimeout(() => {
                    this.qrcode(wechatUrl)
                },0)
            })
            .catch(err => {
                this.msg = 'load failed!'
                this.catchErrorHandle(err)
            })
        },
        qrcode(url) {
            if(document.getElementById("qrcode")) {
                document.getElementById("qrcode").innerHTML = "";
            }
            let qrcode = new QRCode("qrcode", {
                width: 250,
                height: 250, // 高度
                correctLevel: QRCode.CorrectLevel.M // L|M|Q|H
                // render: 'canvas' // 设置渲染方式(有两种方式 table和canvas,默认是canvas)
                // background: '#f0f'
                // foreground: '#ff0'
            });
            qrcode.makeCode(url);
      },
    }
}
</script>

<style scoped>
    .qrcode-wrapper {
        /* width: 250px; 
        height: 250px;  */
        background-color: #fff;
        text-align: center;
    }
    
</style>