jhzh
2025-04-03 db12897dc68c68d40c557aa59ad78022e2b30ac2
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
<template>
  <div class="qrbox">
    <canvas :canvas-id="id" :style="{
      width:`100%`,
      height:`100%`,
    }"></canvas>
  </div>
</template>
<script>
import uQRCode from "@/js_sdk/Sansnn-uQRCode/uqrcode.js";
export default {
  props: {
    text: {
      default: "",
      type: String,
      required: false,
    },
  },
  data() {
    return {
      width: 100,
      height: 100,
      id: `qrcode${Math.random()}`,
    };
  },
  watch: {
    text() {
      this.getRec();
    },
  },
  methods: {
    // 获取尺寸
    getRec() {
      let query = uni.createSelectorQuery().in(this);
      query
        .select(".qrbox canvas")
        .boundingClientRect((e)=> {
          this.width = e.width
          this.height = e.height
          this.make()
        })
        .exec();
    },
    make() {
      uQRCode.make({
        canvasId: this.id,
        componentInstance: this,
        text: this.text,
        size: this.width,
        margin: 0,
        backgroundColor: '#ffffff',
        foregroundColor: '#000000',
        fileType: 'jpg',
        correctLevel: uQRCode.errorCorrectLevel.H,
        success: res => {
        }
      })
    }
  },
  mounted() {
    this.getRec();
  },
};
</script>