groupCode.vue
2.66 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
<script>
export default {
props: {
// 实际群活码
groupCodeId: {
type: String,
default: '',
},
query: {
type: Object,
default: {
imgUrl: '',
},
},
groupCode: {
type: Object,
default: {},
},
},
data() {
return {
// groupCode: null,
clipboard: null,
}
},
watch: {
query: {
handler(val) {},
immediate: true,
},
},
computed: {
// codeUrl() {
// return this.groupCode ? this.groupCode.codeUrl : ''
// },
},
mounted() {
this.clipboard = new this.ClipboardJS('#copyUrl')
},
created() {
// this.getGroupDetail()
},
destroyed() {
this.clipboard.destroy()
},
methods: {
// 获取群活码信息
// getGroupDetail() {
// if (!this.groupCodeId) return
// this.groupCode = this.data
// },
transInfo() {
this.$emit('getGroupCode', this.groupCode)
},
// 下载
handleDownload(url, name) {
let image = new Image()
image.setAttribute('crossOrigin', 'anonymous')
image.src = url
image.onload = () => {
let canvas = document.createElement('canvas')
canvas.width = image.width
canvas.height = image.height
let ctx = canvas.getContext('2d')
ctx.drawImage(image, 0, 0, image.width, image.height)
canvas.toBlob((blob) => {
let url = URL.createObjectURL(blob)
let Link = document.createElement('a')
Link.download = name
Link.href = url
Link.click()
Link.remove()
// 用完释放URL对象
URL.revokeObjectURL(url)
})
}
},
},
}
</script>
<template>
<div class="page">
<div class="code-wrapper">
<div class="code-success">
<el-button type="success" icon="el-icon-check" circle></el-button>
</div>
<div class="code-text">拉新活码创建成功,支持复制二维码链接或直接下载</div>
<el-image
:src="query.imageUrl"
class="code-image"
style="width: 160px; height: 200px"
></el-image>
<div class="code-actions">
<el-button id="copyUrl" :data-clipboard-text="query.linkPath">复制链接</el-button>
<el-button type="primary" @click="handleDownload(query.imageUrl, query.qrName)"
>下载二维码</el-button
>
</div>
</div>
</div>
</template>
<style scoped lang="scss">
.code-wrapper {
text-align: center;
.code-success,
.code-text,
.code-image,
.code-actions {
padding: 20px 0;
}
}
</style>