qrcode.vue
7.2 KB
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
<template>
<view class="qrcode">
<demo-block title="qrcode">
<!-- <image v-if="picture2" :src="picture2" mode="widthFix"></image> -->
<l-painter css="width: 100%; background: #fff" @fail="fail" @done="done" pathType="url" ref="poster" performance isCanvasToTempFilePath @success="path = $event">
<l-painter-view css="margin-top: 30rpx; box-sizing: border-box; background: #ffffff; border-radius: 16rpx; width: 606rpx; box-shadow: 0 20rpx 58rpx rgba(0,0,0,.15)">
<l-painter-image :src="downFile(qrCodeDetail.logo)" css="object-fit: cover; object-position: 50% 50%; width: 606rpx; height: 794rpx;" />
<!-- <l-painter-image src="https://img.zcool.cn/community/01b31d5e876a98a801216518480e2f.jpg@1280w_1l_2o_100sh.jpg" css="object-fit: cover; object-position: 50% 50%; width: 606rpx; height: 794rpx;" /> -->
<l-painter-view css="margin-top: 30rpx; display: flex; align-items: center;justify-content: space-between; padding: 0rpx 38rpx 42rpx; box-sizing: border-box;">
<l-painter-view css="margin-top: 40rpx; padding-left: 20rpx; display: inline-block">
<l-painter-text :text="UserInfo.nickname" css="display: block; padding-bottom: 10rpx; color: #000; font-size: 32rpx; fontWeight: bold" />
<l-painter-text text="邀请你加入宠物医院APP" css="color: rgba(0,0,0,.7); font-size: 24rpx" />
</l-painter-view>
<!-- 图片二维码 -->
<!-- <l-painter-image src="https://img.zcool.cn/community/01b31d5e876a98a801216518480e2f.jpg@1280w_1l_2o_100sh.jpg" css="width: 128rpx; height: 128rpx;" /> -->
<!-- <l-painter-image :src="downFile(qrCodeDetail.logo)" css="width: 128rpx; height: 128rpx;" /> -->
<!-- 二维码 -->
<l-painter-qrcode css="width: 128rpx; height: 128rpx;" :text="qrCodeDetail.qrcode"></l-painter-qrcode>
</l-painter-view>
</l-painter-view>
</l-painter>
<!-- <button type="default" @click="save">save</button> -->
</demo-block>
<view class="flexA ControlsBox">
<view class="flexCCol item" v-for="(_, index) in ControlsList" :key="index" @click="clickControlsItemHandler(_)">
<image :src="_.imgUrl" mode="aspectFill" />
<view>{{ _.title }}</view>
</view>
</view>
<view class="flexC" style="margin-top: 72rpx" @click="callbackHandler">
<image src="/static/images/closeqrcode.png" mode="aspectFill" style="width: 80rpx; height: 80rpx" />
</view>
</view>
</template>
<script>
import { getInvite, getPaper_basedata, updateChange_invite_paper } from '../../api'
import { baseURL } from '../../utils/http'
import { permision } from '../../utils/permission'
export default {
data: () => ({
picture: '',
path: '',
picture2: '',
show: false,
ControlsList: [
{ title: '微信', imgUrl: '/static/images/wechat.png', type: 'wechat' },
{ title: '朋友圈', imgUrl: '/static/images/puq.png', type: 'puq' },
{ title: '保存图片', imgUrl: '/static/images/download.png', type: 'download' }
],
qrCodeDetail: {},
UserInfo: {}
}),
onLoad() {
setTimeout(() => {
console.log(this.path)
}, 1000)
this.UserInfo = uni.getStorageSync('UserInfo')
this.getQrcodeHandler()
},
methods: {
downFile(fileName) {
if (fileName == '' || fileName == undefined) return ''
if (fileName.indexOf(baseURL) > -1 || fileName.indexOf('http://') > -1 || fileName.indexOf('https://') > -1) return fileName
return baseURL + fileName
},
async getQrcodeHandler() {
const { result } = await getInvite()
// const { result: Paper } = await getPaper_basedata()
const Paper = {}
this.qrCodeDetail = { ...result, ...Paper }
},
callbackHandler() {
uni.navigateBack({ delta: 1 })
},
// WXSceneTimeline 朋友圈
// WXSceneSession 聊天
shareQrcodeHandler(scene, imageUrl) {
uni.share({
provider: 'weixin',
scene: scene,
type: 2,
imageUrl: imageUrl,
success: function (res) {
console.log('success:' + JSON.stringify(res), '分享成功')
uni.$u.toast('分享成功')
setTimeout(() => uni.navigateBack(), 1200)
},
fail: function (err) {
console.log('fail:' + JSON.stringify(err), '分享失败')
}
})
},
clickControlsItemHandler(_) {
// console.log(_)
let that = this
this.$refs.poster.canvasToTempFilePathSync({
fileType: 'jpg',
quality: 1,
success: res => {
// console.log(res.tempFilePath.split('blob:'), '成功')
// this.picture2 = res.tempFilePath.split('blob:')[1]
// console.log(this.picture2, '11')
uni.uploadFile({
url: baseURL + '/sys/common/upload', //仅为示例,非真实的接口地址
filePath: res.tempFilePath,
name: 'file',
formData: {
user: 'test',
token: uni.getStorageSync('token')
},
success: async uploadFileRes => {
console.log(JSON.parse(uploadFileRes.data), '图片路径')
const uploadUrl = JSON.parse(uploadFileRes.data).message
await updateChange_invite_paper({ image: uploadUrl })
if (['puq', 'wechat'].includes(_.type)) return that.shareQrcodeHandler({ puq: 'WXSceneTimeline', wechat: 'WXSceneSession' }[_.type], that.downFile(uploadUrl))
}
})
},
fail(e) {
console.log('???????????', e)
}
})
if (_.type === 'download') return this.save()
},
close() {
this.show = false
},
fail(v) {
console.log(v)
},
done(v) {
console.log('绘制完成:')
},
async save() {
// #ifdef APP-PLUS
if (uni.getStorageSync('deviceType') === 'android') {
const result = await permision.premissionCheck('EXTERNAL_STORAGE')
if (result != 1) {
console.log('拒绝')
return
}
}
// #endif
this.$refs.poster.canvasToTempFilePathSync({
fileType: 'jpg',
quality: 1,
success: res => {
console.log(res.tempFilePath.split('blob:'), '成功')
// this.picture2 = res.tempFilePath.split('blob:')[1]
this.picture2 = res.tempFilePath
console.log(this.picture2, '11')
this.saveImage()
},
fail(e) {
console.log('???????????', e)
}
})
},
// 保存图征
saveImage() {
// #ifndef H5
uni.saveImageToPhotosAlbum({
filePath: this.picture2,
success(res) {
uni.showToast({
title: '已保存到相册',
icon: 'success',
duration: 2000
})
}
})
// #endif
}
}
}
</script>
<style>
page {
background: #f7f8fa !important;
}
</style>
<style lang="scss" scoped>
.qrcode {
box-sizing: border-box;
padding: 68rpx 72rpx 0;
.ControlsBox {
margin-top: 46rpx;
justify-content: space-around;
.item {
image {
width: 110rpx;
height: 110rpx;
border-radius: 50%;
margin-bottom: 12rpx;
}
color: #333333;
font-size: 24rpx;
}
}
}
</style>