bindWx.vue
2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<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>