inspectionPointQrCode.vue
2.05 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
83
84
85
86
87
88
89
90
91
92
93
94
95
<template>
<el-dialog :title="$t('inspectionPointQrCode.title')" :visible.sync="dialogVisible" width="400px" center>
<div class="qr-code-container text-center">
<div id="qrcode" ref="qrcode" style="width: 200px; height: 200px; margin: 0 auto;"></div>
<p class="inspection-name">{{ inspectionPointQrCodeInfo.inspectionName }}</p>
<p class="tip-text">{{ $t('inspectionPointQrCode.tip') }}</p>
</div>
<span slot="footer" class="dialog-footer">
<el-button @click="dialogVisible = false">{{ $t('common.close') }}</el-button>
</span>
</el-dialog>
</template>
<script>
import QRCode from 'qrcodejs2'
import { getCommunityId } from '@/api/community/communityApi'
export default {
name: 'InspectionPointQrCode',
data() {
return {
dialogVisible: false,
inspectionPointQrCodeInfo: {
url: '',
inspectionName: ''
},
qrcode: null,
communityId: ''
}
},
created() {
this.communityId = getCommunityId()
},
methods: {
open(inspectionPoint) {
this.dialogVisible = true
this.inspectionPointQrCodeInfo = {
url: inspectionPoint.url,
inspectionName: inspectionPoint.inspectionName
}
this.$nextTick(() => {
this.generateQrCode()
})
},
generateQrCode() {
// 清除现有的二维码
if (this.qrcode) {
this.qrcode.clear()
this.$refs.qrcode.innerHTML = ''
}
// 生成新的二维码
this.qrcode = new QRCode(this.$refs.qrcode, {
text: this.inspectionPointQrCodeInfo.url,
width: 200,
height: 200,
colorDark: "#000000",
colorLight: "#ffffff",
correctLevel: QRCode.CorrectLevel.L
})
}
},
beforeDestroy() {
if (this.qrcode) {
this.qrcode.clear()
}
}
}
</script>
<style scoped>
.qr-code-container {
padding: 20px;
}
.text-center {
text-align: center;
}
.inspection-name {
font-size: 18px;
font-weight: bold;
margin: 15px 0;
}
.tip-text {
font-size: 14px;
color: #606266;
margin-top: 10px;
}
</style>