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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
| <template>
| <!-- 联系我们 -->
| <!-- -->
| <view class="contact-container">
| <view class="container" @click="saveCode">
| <!-- <image src="../../../static/uni.png" mode="aspectFit" class="code"></image> -->
| <canvas type="2d" id="myQrcode" class="code"></canvas>
| <view class="info">
| <view class="desc">
| <p>{{name||'-'}}的推广二维码</p>
| <p style="font-size: 600;color: #000;">点击保存二维码</p>
| </view>
| </view>
| </view>
| </view>
| </template>
|
| <script>
| import drawQrcode from '@/plugins/weapp.qrcode.esm.js'
|
| export default {
| data() {
| return {
| name: '',
| userId: '',
| canvas: undefined,
| }
| },
| onLoad(options) {
| if (!this.currentInfo.partnerDTO) {
| this.$message.showToast('请先完善合伙人信息')
| return
| }
| this.name = this.currentInfo.partnerDTO.name || '佚名'
| // this.userId = this.currentInfo.userId
| this.initcode()
| },
| methods: {
| initcode() {
| let that = this
| const query = uni.createSelectorQuery()
|
| query.select('#myQrcode')
| .fields({
| node: true,
| size: true
| })
| .exec((res) => {
| var canvas = res[0].node
| that.canvas = canvas
| // 调用方法drawQrcode生成二维码
| drawQrcode({
| callback:function(e){
| console.log('drawQrcode callback',e)
| },
| canvas: canvas,
| canvasId: 'myQrcode',
| width: 480,
| height: 480,
| padding: 30,
| background: '#ffffff',
| foreground: '#000000',
| text: JSON.stringify({
| 'name': that.name,
| 'userId': that.currentInfo.id,
| 'version': '1.0.0'
| }),
| // text: `https://www.hmyxianhua.com/wx-c-jump/sub_pages/customer/customer-info/customer-info?name=${that.name}&userId=${that.currentInfo.id}`
| // JSON.stringify({
| // 'name': that.name,
| // 'userId': this.currentIn fo.id
| // }),
| })
| // .catch(e) {
| // console.log('drawQrcode', e)
| // }
| })
| },
| saveCode() {
|
| // 获取临时路径(得到之后,想干嘛就干嘛了)
| uni.canvasToTempFilePath({
| canvasId: 'myQrcode',
| canvas: this.canvas,
| x: 0,
| y: 0,
| width: 480,
| height: 480,
| destWidth: 260,
| destHeight: 260,
| success(res) {
| console.log('二维码临时路径:', res.tempFilePath)
| uni.saveImageToPhotosAlbum({
| filePath: res.tempFilePath,
| success: function() {
| console.log('save success');
| uni.showToast({
| title: '保存成功'
| })
| },
| fail(res) {
| // console.error(res)
| uni.showToast({
| title: '保存失败。',
| icon: 'error'
| })
| }
| })
| },
| fail(res) {
| uni.showToast({
| title: '保存失败',
| icon: 'error'
| })
| }
| })
| }
| }
| }
| </script>
|
| <style lang="scss" scoped>
| .contact-container {
| position: relative;
|
| .container {
| position: absolute;
| top: 148rpx;
| // width: 694rpx;
| left: 30rpx;
| right: 30rpx;
| min-height: 712rpx;
| // background: #FFFFFF;
| border-radius: 20rpx;
|
| .code {
| margin-left: auto;
| margin-right: auto;
| margin-top: 24rpx;
| width: 482rpx;
| height: 482rpx;
| margin-bottom: 32rpx;
| display: block;
| }
|
| .info {
| text-align: center;
|
| .desc {
| font-weight: 400;
| font-size: 28rpx;
| color: #666666;
| line-height: 40rpx;
| font-style: normal;
| margin-bottom: 126rpx;
|
| p {
| line-height: 48rpx;
| }
| }
|
| .main {
| font-weight: 600;
| font-size: 48rpx;
| color: #000000;
| margin-top: 48rpx;
| margin-bottom: 32rpx;
|
| }
| }
| }
|
| .top-image {
| width: 418rpx;
| height: 228rpx;
| position: absolute;
| top: 16rpx;
| left: 50%;
| transform: translateX(-50%);
|
| }
| }
| </style>
|
|