Blame view

src/components/inspection/inspectionPointQrCode.vue 1.85 KB
1d73dc48   wuxw   继续晚上巡检功能
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
96
97
98
  <template>
    <el-dialog
      :title="$t('inspectionPointQrCode.title')"
      :visible.sync="visible"
      width="400px"
      @close="handleClose"
    >
      <div class="qr-container">
        <div ref="qrcode" class="qrcode"></div>
        <div class="point-name">{{ inspectionPointQrCodeInfo.inspectionName }}</div>
        <p class="tip">{{ $t('inspectionPointQrCode.tip') }}</p>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button @click="visible = false">{{ $t('common.close') }}</el-button>
      </div>
    </el-dialog>
  </template>
  
  <script>
  import QRCode from 'qrcodejs2'
  
  export default {
    name: 'InspectionPointQrCode',
    data() {
      return {
        visible: false,
        inspectionPointQrCodeInfo: {
          url: '',
          inspectionName: ''
        },
        qrCode: null
      }
    },
    methods: {
      open(qrInfo) {
        this.inspectionPointQrCodeInfo = { ...qrInfo }
        this.visible = true
        
        this.$nextTick(() => {
          this.generateQrCode()
        })
      },
      
      handleClose() {
        this.inspectionPointQrCodeInfo = {
          url: '',
          inspectionName: ''
        }
        if (this.qrCode) {
          this.qrCode.clear()
        }
      },
      
      generateQrCode() {
        if (this.qrCode) {
          this.qrCode.clear()
        }
        
        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-container {
    text-align: center;
  }
  
  .qrcode {
    display: inline-block;
    margin: 0 auto;
  }
  
  .point-name {
    margin-top: 15px;
    font-size: 16px;
    font-weight: bold;
  }
  
  .tip {
    margin-top: 10px;
    color: #999;
    font-size: 14px;
  }
  </style>