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
99
100
101
102
103
  | <template>     
 |      <view class='pages'>             
 |          <view class='father_view'>  
 |              <view class='son_view'>  
 |                <view class="title-bg">需要转换的文本:</view> 
 |                <textarea class="textarea-bg" v-model="text1" @blur="inputText"  placeholder="请在这里输入" />  
 |              </view> 
 |          </view> 
 |           
 |          <!-- 二维码 --> 
 |          <view class="qr-box"> 
 |              <canvas canvas-id="qrcode" v-show="qrShow" style="width: 300rpx;margin: 0 auto;"/> 
 |          </view>         
 |               
 |          <button @click='btn'>生成二维码</button>                 
 |      </view>         
 |  </template> 
 |    
 |  <script> 
 |      import uQRCode from '@/static/js/uqrcode.js' //引入uqrcode.js 
 |      export default { 
 |          data() { 
 |              return { 
 |                  qrShow: false,                 
 |                  text1:'' 
 |              } 
 |          }, 
 |                   
 |          methods: {     
 |              //*获取文本框内容*// 
 |              inputText:function (e) { 
 |                  this.text1 = e.detail.value     
 |              }, 
 |           
 |              //*按钮*// 
 |              btn: function () {                                         
 |                  if (this.text1 == '' ) { 
 |                      uni.showToast({  //显示对话框 
 |                          title: "请输入文本", 
 |                          icon: 'none', 
 |                          duration: 1000, 
 |                      }) 
 |                  } else { 
 |                      this.qrFun(this.text1) //调用二维码方法 
 |                  } 
 |              }, 
 |               
 |              //**生成二维码**// 
 |              qrFun: function(text) { 
 |                  this.qrShow = true 
 |                  uQRCode.make({ 
 |                      canvasId: 'qrcode', 
 |                      componentInstance: this, 
 |                      text: text, 
 |                      size: 150, 
 |                      margin: 0, 
 |                      backgroundColor: '#ffffff', 
 |                      foregroundColor: '#000000', 
 |                      fileType: 'jpg', 
 |                      errorCorrectLevel: uQRCode.errorCorrectLevel.H, 
 |                      success: res => {} 
 |                  }) 
 |              } 
 |          } 
 |      } 
 |  </script> 
 |    
 |  <style>     
 |      .pages { 
 |          width: 98%; 
 |          margin: auto; 
 |          overflow: hidden; 
 |      }     
 |       
 |      /* 多行文本 */ 
 |      textarea { 
 |          width: 98%; 
 |          height: 250rpx; 
 |          margin-left: 10rpx; 
 |          margin-right: 10rpx; 
 |          margin-top: 10rpx; 
 |      } 
 |       
 |      .textarea-bg { 
 |          width: 94%; 
 |          border-style: solid; 
 |          border-color: #ff007f; 
 |          font-size: 32rpx; 
 |      } 
 |       
 |      button { 
 |          width: 80%; 
 |          margin-top: 180rpx; 
 |          background-color: #ffaa00; 
 |      } 
 |       
 |      .qr-box { 
 |          width: 400rpx; 
 |          height: 460rpx; 
 |          margin: 0 auto; 
 |          margin-top: 20rpx; 
 |      } 
 |  </style> 
 |  
  |