Blame view

src/components/inspection/inspectionPointQrCode.vue 2.29 KB
1d73dc48   wuxw   继续晚上巡检功能
1
  <template>
48ea9c43   wuxw   巡检开发完成
2
3
4
5
6
    <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>
1d73dc48   wuxw   继续晚上巡检功能
7
      </div>
48ea9c43   wuxw   巡检开发完成
8
9
10
11
  
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">{{ $t('common.close') }}</el-button>
      </span>
1d73dc48   wuxw   继续晚上巡检功能
12
13
14
15
16
    </el-dialog>
  </template>
  
  <script>
  import QRCode from 'qrcodejs2'
48ea9c43   wuxw   巡检开发完成
17
  import { getCommunityId } from '@/api/community/communityApi'
1d73dc48   wuxw   继续晚上巡检功能
18
19
20
21
22
  
  export default {
    name: 'InspectionPointQrCode',
    data() {
      return {
48ea9c43   wuxw   巡检开发完成
23
        dialogVisible: false,
1d73dc48   wuxw   继续晚上巡检功能
24
25
26
27
        inspectionPointQrCodeInfo: {
          url: '',
          inspectionName: ''
        },
48ea9c43   wuxw   巡检开发完成
28
29
        qrcode: null,
        communityId: ''
1d73dc48   wuxw   继续晚上巡检功能
30
31
      }
    },
48ea9c43   wuxw   巡检开发完成
32
33
34
    created() {
      this.communityId = getCommunityId()
    },
1d73dc48   wuxw   继续晚上巡检功能
35
    methods: {
48ea9c43   wuxw   巡检开发完成
36
37
38
39
40
41
42
      open(inspectionPoint) {
        this.dialogVisible = true
        this.inspectionPointQrCodeInfo = {
          url: this.generateQrUrl(inspectionPoint),
          inspectionName: inspectionPoint.inspectionName
        }
  
1d73dc48   wuxw   继续晚上巡检功能
43
44
45
46
        this.$nextTick(() => {
          this.generateQrCode()
        })
      },
48ea9c43   wuxw   巡检开发完成
47
48
49
50
  
      generateQrUrl(inspectionPoint) {
        // 这里根据实际业务生成二维码URL
        return `${window.location.origin}/inspection/task?inspectionId=${inspectionPoint.inspectionId}&communityId=${this.communityId}`
1d73dc48   wuxw   继续晚上巡检功能
51
      },
48ea9c43   wuxw   巡检开发完成
52
  
1d73dc48   wuxw   继续晚上巡检功能
53
      generateQrCode() {
48ea9c43   wuxw   巡检开发完成
54
55
56
57
        // 清除现有的二维码
        if (this.qrcode) {
          this.qrcode.clear()
          this.$refs.qrcode.innerHTML = ''
1d73dc48   wuxw   继续晚上巡检功能
58
        }
48ea9c43   wuxw   巡检开发完成
59
60
61
  
        // 生成新的二维码
        this.qrcode = new QRCode(this.$refs.qrcode, {
1d73dc48   wuxw   继续晚上巡检功能
62
63
64
          text: this.inspectionPointQrCodeInfo.url,
          width: 200,
          height: 200,
48ea9c43   wuxw   巡检开发完成
65
66
          colorDark: "#000000",
          colorLight: "#ffffff",
1d73dc48   wuxw   继续晚上巡检功能
67
68
69
70
71
          correctLevel: QRCode.CorrectLevel.L
        })
      }
    },
    beforeDestroy() {
48ea9c43   wuxw   巡检开发完成
72
73
      if (this.qrcode) {
        this.qrcode.clear()
1d73dc48   wuxw   继续晚上巡检功能
74
75
76
77
78
79
      }
    }
  }
  </script>
  
  <style scoped>
48ea9c43   wuxw   巡检开发完成
80
81
  .qr-code-container {
    padding: 20px;
1d73dc48   wuxw   继续晚上巡检功能
82
83
  }
  
48ea9c43   wuxw   巡检开发完成
84
85
  .text-center {
    text-align: center;
1d73dc48   wuxw   继续晚上巡检功能
86
87
  }
  
48ea9c43   wuxw   巡检开发完成
88
89
  .inspection-name {
    font-size: 18px;
1d73dc48   wuxw   继续晚上巡检功能
90
    font-weight: bold;
48ea9c43   wuxw   巡检开发完成
91
    margin: 15px 0;
1d73dc48   wuxw   继续晚上巡检功能
92
93
  }
  
48ea9c43   wuxw   巡检开发完成
94
  .tip-text {
1d73dc48   wuxw   继续晚上巡检功能
95
    font-size: 14px;
48ea9c43   wuxw   巡检开发完成
96
97
    color: #606266;
    margin-top: 10px;
1d73dc48   wuxw   继续晚上巡检功能
98
99
  }
  </style>