employeeDialog.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
115
116
117
118
119
120
<template>
<d2-dialog
title="员工注册码"
:is-visible="employeeVisible"
class="qRcodeDailog"
width="750px"
btn-ok-label="下载"
@closeDialog="handleClose"
@confirmDialog="handleAddConfirm"
>
<div class="employee-wrap" v-if="qrCodeURL">
<div class="title">员工注册码</div>
<div class="code">
<img :src="qrCodeURL" alt="" />
</div>
</div>
</d2-dialog>
</template>
<script>
// alipayQrcode
import { employeeRegister } from "@api/shopConfig"
export default {
name: "employeeDialog",
data() {
return {
// 基本数据
baseData: {
merchantList: []
},
loading: true,
qrCodeURL: ""
}
},
props: {
employeeVisible: {
type: Boolean,
default: false
},
info: {
type: Object,
default: null
}
},
watch: {},
created() {},
components: {},
mounted() {
this.getEmployeeRegister()
},
methods: {
getEmployeeRegister() {
employeeRegister({
merchantId: this.info.merchantId
}).then((res) => {
if (res) {
this.qrCodeURL = res.qrCode
this.loading = false
}
})
},
downloadIamge(imgsrc, name = new Date().getTime()) {
//下载图片地址和图片名
var image = new Image()
// 解决跨域 Canvas 污染问题
image.setAttribute("crossOrigin", "anonymous")
image.onload = function () {
var canvas = document.createElement("canvas")
canvas.width = image.width
canvas.height = image.height
var context = canvas.getContext("2d")
context.drawImage(image, 0, 0, image.width, image.height)
var url = canvas.toDataURL("image/png") //得到图片的base64编码数据
var a = document.createElement("a") // 生成一个a元素
var event = new MouseEvent("click") // 创建一个单击事件
a.download = name || "photo" // 设置图片名称
a.href = url // 将生成的URL设置为a.href属性
a.dispatchEvent(event) // 触发a的单击事件
}
image.src = imgsrc
},
handleAddConfirm() {
// this.downImg(this.qrCodeURL, "员工注册码.png")
this.downloadIamge(this.qrCodeURL, "员工注册码.png")
},
handleClose() {
this.$emit("dialogClose", true)
}
}
}
</script>
<style scoped lang="scss">
.employee-wrap {
display: flex;
align-items: center;
flex-direction: column;
justify-content: center;
.title {
font-weight: 500;
font-size: 14px;
color: #333333;
margin-bottom: 8px;
}
.code {
width: 120px;
height: 120px;
img {
width: 100%;
}
}
}
</style>