groupCode.vue
2.18 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
<script>
import { getDetail, download } from '@/api/drainageCode/group'
export default {
props: {
// 实际群活码
groupCodeId: {
type: String,
default: '',
},
data: {
type: Object,
default: {
codeUrl: '',
},
},
},
data() {
return {
groupCode: null,
clipboard: null,
}
},
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
},
// 下载
handleDownload() {
if (!this.groupCode) return
const name = this.groupCode.activityName + '.png'
download(this.groupCode.id).then((res) => {
if (res != null) {
let blob = new Blob([res], { type: 'application/zip' })
let url = window.URL.createObjectURL(blob)
const link = document.createElement('a') // 创建a标签
link.href = url
link.download = name // 重命名文件
link.click()
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 size="medium"></el-button>
</div>
<div class="code-text">群活码创建成功,支持复制二维码链接或直接下载</div>
<el-image :src="codeUrl" class="code-image" style="width: 160px; height: 200px"></el-image>
<div class="code-actions">
<el-button id="copyUrl" type="text" size="medium" :data-clipboard-text="codeUrl"
>复制链接</el-button
>
<el-button type="text" size="medium" @click="handleDownload()">下载二维码</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>