sever.vue
5.1 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
<template>
<div class="severbody" id="captureId">
<nav-bar class="severnav">
<div slot="left" class="back" @click="goBack">
<img src="../../assets/img/back3.png" alt="">
</div>
<div slot="center" class="userinfotitle">
客服
</div>
<div slot="right" class="back"></div>
</nav-bar>
<div class="cont-center">
<div class="severbottom"></div>
<div class="sever" id="capture">
<img src="../../assets/img/Frame 106@2x.png" alt="" class="tou">
<div class="sever_title">客服</div>
<div class="sever_tip">添加客服微信,一对一解决您的问题</div>
<div class="erweima" id="erweima" ref="erweima">
<img :src="image" alt="" class="erweima"/>
<!-- <van-image
width="100%"
height="100%"
src="../../assets/img/cardbg.png"
/> -->
</div>
<div class="phone display-flex" @click="phone">
<img src="../../assets/img/phone2.png" alt="">
<div>{{severinfo.mobile}}</div>
</div>
</div>
<div class="savebtn" @click="clickGeneratePicture">
<!-- <img src="../../assets/img/load.png" alt="" class="save"> -->
<div class="savetext">长按图片保存到本地</div>
</div>
</div>
</div>
</template>
<script>
import html2canvas from 'html2canvas'
export default {
data () {
return {
dataURL: '',
severinfo: '',
image: ''
}
},
methods: {
goBack () {
this.$router.go(-1)
},
phone () {
window.location.href = 'tel:' + this.severinfo.mobile
},
async severfun () {
const that = this
const reslist = await that.api.sever()
if (reslist.code === 1) {
that.severinfo = reslist.data
that.image = 'data:image/png;base64,' + reslist.data.qrcode_base64
// console.log(that.image)
// that.creatcanvas(that.image)
} else {
that.$toast(reslist.msg)
}
},
// 绘制二维码图片
// creatcanvas(image){
// window.onload = function() {
// let contents=document.getElementById('erweima')
// let context=contents.getContext('2d')
// context.drawImage(image,0,0,50,50)
// }
// },
// 生成图片
clickGeneratePicture () {
html2canvas(document.querySelector('#capture')).then(canvas => {
const link = document.createElement('a') // 创建一个超链接对象实例
const event = new MouseEvent('click') // 创建一个鼠标事件的实例
link.download = 'Button.png' // 设置要下载的图片的名称
link.href = canvas.toDataURL() // 将图片的URL设置到超链接的href中
// console.log(link.href)
link.dispatchEvent(event) // 触发超链接的点击事件
})
}
},
mounted () {
this.severfun()
}
}
</script>
<style lang="scss" >
.severbody{
background: #257CFF;
height: 100vh;
overflow: hidden;
}
.severnav .userinfotitle{
color: #fff;
}
.back,.left{
width: 1.6rem;
}
.cont-center{
position: fixed;
top: 45%;
left: 50%;
transform: translate(-50%,-50%);
}
.severbottom{
width: 5.9rem;
height: 9rem;
border-radius: 0.08rem;
opacity: 1;
background: rgba(255,255,255,1);
text-align: center;
padding-bottom: 0.32rem;
position: absolute;
top:35%;
left: 50%;
transform: translate(-50%,-50%);
z-index: 1;
}
.savebtn{
width: 2.5rem;
position: fixed;
top: 5.5rem;
left: 50%;
transform: translate(-50%,0);
z-index: 3;
text-align: center;
}
.sever{
width: 5.9rem;
height: 10rem;
border-radius: 0.08rem;
opacity: 1;
text-align: center;
padding-bottom: 0.32rem;
position: absolute;
top: 35%;
left: 50%;
transform: translate(-50%,-50%);
z-index: 2;
/* border: 1px solid red; */
}
.tou{
width: 1.28rem;
height: 1.28rem;
border-radius: 50%;
margin-bottom: 0.32rem;
}
.sever_title{
color: rgba(34,39,43,1);
font-size: 0.4rem;
font-weight: 600;
margin-bottom: 0.16rem;
}
.sever_tip{
color: rgba(134.64,144.13,153,1);
font-size: 0.24rem;
font-weight: 400;
margin-bottom: 0.7rem;
}
.erweima{
width: 3.92rem;
height: 3.92rem;
margin:0 auto 0.65rem;
}
.phone{
width: 3.92rem;
height: 0.8rem;
border-radius: 0.4rem;
opacity: 1;
background: rgba(0,231.63,162.14,1);
padding: 0.18rem 0.64rem;
box-sizing: border-box;
color: rgba(255,255,255,1);
font-size: 0.32rem;
margin: 0 auto;
}
.phone img{
width: 0.4rem;
height: 0.4rem;
margin-right: 0.32rem;
}
.save{
width: 0.96rem;
height: 0.96rem;
/* margin: 0.14rem auto; */
}
.savetext{
color: rgba(255,255,255,1);
font-size: 0.24rem;
font-weight: 500;
padding-bottom: 0rem;
}
</style>