c_ShareBox.vue
15.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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
<template>
<div class="abroad_detail_share_box" :class="type == 'order' ? 'type_order' : ''" @click="handleMask">
<div class="content" @click.stop>
<img class="share_img" src="@/assets/service/share.png" alt="" />
<p class="share_text" v-if="posterLoaded">{{ posterBody }}</p>
<div class="line" v-if="posterLoaded"></div>
<div class="share_btn_box">
<button class="btn btn1" v-clipboard:copy="posterBody" v-clipboard:success="copyTextPoster" v-clipboard:error="onError">
复制文字生成海报
</button>
<button class="btn btn2" v-clipboard:copy="posterBody" v-clipboard:success="copyTextFriend" v-clipboard:error="onError">
复制文字分享至朋友
</button>
</div>
<div class="line2"></div>
</div>
<div id="posterBox" v-if="showPoster" @click="showPoster = false">
<div class="poster_content" @click.stop>
<img class="poster" :src="posterUrl" alt="" />
<button class="btn">长按图片保存海报</button>
</div>
</div>
<div id="posterCreateBox">
<img class="poster1" v-if="sizeType == 2" alt="" />
<img class="poster1_logo" v-if="sizeType == 2" src="@/assets/service/logo4.png" alt="" />
<div class="poster2" v-else>
<img class="logo" src="@/assets/service/logo3.png" alt="" />
<p class="title">{{ detailData.course_name }}</p>
<p class="des" v-if="periodArr.length > 0">{{ periodArr[0].productSceneName }}</p>
<img class="poster2img" alt="" />
<p class="price" v-if="periodArr.length > 0">
活动价¥{{ periodArr[0].groupPeriodActivityList.actualPrice }}起/人<del
>市场价¥{{ periodArr[0].groupPeriodActivityList.productPrice }}/人</del
>
</p>
</div>
<div class="bottom_box">
<p class="text">
<span>{{ nickName }} 邀请你参与本研学活动</span><span class="des">{{ posterLabel }}</span>
</p>
<div class="qrcodeBox">
<div id="qrcode" ref="imageWrapper" v-if="!codeImgUrl"></div>
<div class="imgBox">
<img :src="codeImgUrl" v-if="codeImgUrl" style="width:100%;height:100%" crossorigin="anonymous" />
</div>
</div>
</div>
</div>
</div>
</template>
<script>
import html2canvas from 'html2canvas'
import QRCode from 'qrcodejs2' // 引入qrcode
export default {
props: ['type', 'detailData'],
data() {
return {
posterBody: '',
posterLabel: '',
imageUrl: '',
sizeType: 1,
showPoster: false,
posterUrl: '',
nickName: '',
periodArr: [],
codeImgUrl: '',
posterLoaded: false,
}
},
mounted() {
let userInfo = localStorage.getItem('userInfo')
if (userInfo) {
this.nickName = JSON.parse(userInfo).nickName
}
this.getCoursePoster()
this.getPeriod()
this.creatQrCode()
},
methods: {
// 获取海报信息
getCoursePoster() {
this.$toast.loading({
message: '加载中...',
duration: 0,
forbidClick: true,
})
this.yxAxios.get(`${this.yanxueUrl}/api/Product/CoursePoster/ByCourseId?courseId=${this.detailData.id}`).then((res) => {
if (res.data.data) {
this.sizeType = res.data.data.sizeType
this.posterBody = res.data.data.posterBody
localStorage.setItem('posterBody', res.data.data.posterBody)
this.posterLabel = res.data.data.posterLabel
localStorage.setItem('posterLabel', res.data.data.posterLabel)
if (this.sizeType == 1 || !res.data.data.imageUrl) {
this.getImage(this.detailData.coverList ? this.detailData.coverList[0].cover_url : this.detailData.converUrl)
} else {
this.getImage(res.data.data.imageUrl) //获取到海报使用海报图片
}
} else {
this.getImage(this.detailData.coverList ? this.detailData.coverList[0].cover_url : this.detailData.converUrl) //未获取到海报使用课程第一张图片
}
this.$toast.clear()
this.posterLoaded = true
})
},
// 获取可使用行程套餐
getPeriod() {
let date = this.Moment().format('YYYY-MM-DD')
let weekOfday = this.Moment().format('E') // 计算今天是这周第几天
// 如果为限时团购,就传星期三的日期
if (this.$route.query.ProgramType == 1) {
let TGMSTabActive = localStorage.getItem('TGMSTabActive')
if (TGMSTabActive == 1) {
date = this.Moment()
.add(weekOfday == 7 ? 3 : 10 - weekOfday, 'days')
.format('YYYY-MM-DD')
} else {
date = this.Moment()
.add(weekOfday == 7 ? -4 : 3 - weekOfday, 'days')
.format('YYYY-MM-DD')
}
}
let param = {
productId: this.detailData.id,
state: '1',
pageIndex: 1,
pageSize: 999,
date: date,
}
if (this.$route.query.productSceneId) {
param.productSceneId = this.$route.query.productSceneId
}
if (this.$route.query.DateComboType) {
param.DateComboType = this.$route.query.DateComboType
}
if (this.$route.query.ProgramType) {
param.ProgramType = this.$route.query.ProgramType
}
if (this.$route.query.ZZCTCanBuy) {
param.ZZCTCanBuy = this.$route.query.ZZCTCanBuy
}
this.yxAxios.post(`${this.yanxueUrl}/api/Product/ProductScene/List`, param).then((res) => {
let data = res.data.data.data
let periodArr = []
for (let i in data) {
if (data[i].groupPeriodActivityList) {
// 如果是直通车产品,不显示常规拼团套餐
if (this.$route.query.ProgramType && data[i].dateBindTypeName == '常规拼团') {
} else {
periodArr.push(data[i])
}
}
}
this.periodArr = periodArr.sort(this.sortUpDate)
// this.periodArr = periodArr
console.log('套餐列表:', periodArr)
})
},
// 日期排序
sortUpDate(a, b) {
return a.groupPeriodActivityList.actualPrice - b.groupPeriodActivityList.actualPrice
},
handleMask() {
this.$emit('hiddenShare')
},
// 复制文字生成海报
copyTextPoster() {
this.$toast.fail('复制成功')
this.createPoster()
},
// 复制文字分享至朋友
copyTextFriend() {
this.$toast.fail('复制成功')
this.$emit('showShareDes')
},
onError() {
this.$toast.fail('复制失败')
},
// 生成海报
createPoster() {
this.$toast.loading({
message: '加载中...',
duration: 0,
forbidClick: true,
})
html2canvas(document.getElementById('posterCreateBox'), {
backgroundColor: null, //画出来的图片有白色的边框,不要可设置背景为透明色(null)
useCORS: true, //支持图片跨域
scale: 1, //设置放大的倍数
}).then((canvas) => {
this.$toast.clear()
//截图用img元素承装,显示在页面的上
// let img = new Image()
// img.src = canvas.toDataURL('image/jpeg') // toDataURL :图片格式转成 base64
// document.getElementById('posterBox').appendChild(img)
this.posterUrl = canvas.toDataURL('image/jpeg')
this.showPoster = true
})
},
//创建qrcode
creatQrCode() {
let link = `https://payment.myjxt.com/center/#/abroad_detail?courseId=${this.detailData.id}&publicName=SXYX}`
if (this.detailData.bindId || this.detailData.dateComboBindId || this.$route.query.bindId) {
link = link + '&bindId=' + (this.detailData.bindId || this.detailData.dateComboBindId || this.$route.query.bindId)
}
if (localStorage.getItem('talentData')) {
const talentData = JSON.parse(localStorage.getItem('talentData'))
link = link + '&inviteCode=' + talentData.inviteCode
}
if (this.$route.query.ProgramType) {
link = link + '&ProgramType=' + this.$route.query.ProgramType
}
if (this.$route.query.ZZCTCanBuy) {
link = link + '&ZZCTCanBuy=' + this.$route.query.ZZCTCanBuy
}
document.getElementById('qrcode').innerHTML = ''
this.qrcodePIc = new QRCode('qrcode', {
text: link,
width: 240,
height: 240,
colorDark: '#333333', // 二维码颜色
colorLight: '#ffffff', // 二维码背景色
correctLevel: QRCode.CorrectLevel.L, // 容错率,L/M/H
})
let canvas = document.getElementById('qrcode').innerHTML
// console.log(canvas)
this.canvanqrCode()
},
canvanqrCode() {
html2canvas(this.$refs.imageWrapper, {
width: 240,
height: 240,
}).then((canvas) => {
let dataURL = canvas.toDataURL('image/png')
this.codeImgUrl = dataURL
})
},
getBas64(url, outputFormat = 'image/png') {
return new Promise(function(resolve, reject) {
let canvas = document.createElement('CANVAS'),
ctx = canvas.getContext('2d'),
img = new Image()
img.crossOrigin = 'Anonymous' // 重点!设置image对象可跨域请求
img.onload = function() {
canvas.height = img.height
canvas.width = img.width
ctx.drawImage(img, 0, 0)
let dataURL = canvas.toDataURL(outputFormat)
canvas = null
resolve(dataURL)
}
// img.src = url; // 旧的方式
img.src = url + '?t=' + new Date().valueOf() // 防止oss的缓存问题
})
},
getImage(url) {
let that = this
var xhr = new XMLHttpRequest()
xhr.open('get', url, true)
// 设置请求头(这一步得设置不然oss图片还是跨域)
xhr.setRequestHeader('Cache-Control', 'no-cache')
xhr.responseType = 'blob'
xhr.onload = function() {
if (this.status == 200) {
if (that.sizeType == 2) {
document.getElementsByClassName('poster1')[0].src = URL.createObjectURL(this.response)
} else {
document.getElementsByClassName('poster2img')[0].src = URL.createObjectURL(this.response)
}
}
}
xhr.send()
},
},
}
</script>
<style lang="scss">
.abroad_detail_share_box {
width: 100%;
height: calc(100% - 176px);
position: fixed;
top: 0;
left: 0;
background: rgba(0, 0, 0, 0.5);
z-index: 99;
.content {
width: 100%;
height: 308px;
position: absolute;
bottom: 0;
box-sizing: border-box;
background: #fff;
border-top-left-radius: 20px;
border-top-right-radius: 20px;
}
.share_img {
display: none;
}
.share_text {
font-size: 28px;
line-height: 40px;
height: 80px;
color: #666;
margin: 32px 42px;
display: -webkit-box;
white-space: break-spaces;
-webkit-line-clamp: 2;
text-overflow: ellipsis;
overflow: hidden;
-webkit-box-orient: vertical;
}
.line {
width: 708px;
border-bottom: 2px dashed #d1d1d1;
margin: 0 auto;
}
.line2 {
width: 100%;
border-bottom: 2px dashed #d1d1d1;
position: absolute;
bottom: 0;
}
.share_btn_box {
display: flex;
justify-content: space-around;
margin-top: 46px;
.btn {
font-size: 28px;
width: 296px;
height: 72px;
line-height: 72px;
border-radius: 18px;
border: none;
}
.btn1 {
background: #ecf4ff;
color: #4092ff;
}
.btn2 {
background: #e3fff1;
color: #05b55b;
}
}
#posterBox {
width: 100%;
height: 100%;
position: fixed;
top: 0;
left: 0;
background: rgba(0, 0, 0, 0.5);
z-index: 99;
.poster_content {
width: 540px;
height: 960px;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
margin-top: -100px;
}
.poster {
width: 100%;
user-select: auto;
pointer-events: auto;
}
.btn {
width: 448px;
height: 84px;
background: #4092ff;
border-radius: 58px;
text-align: center;
font-size: 32px;
color: #fff;
line-height: 84px;
border: none;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
margin-top: 600px;
}
}
#posterCreateBox {
// width: 540px;
// height: 960px;
width: 1500px;
height: 2664px;
background: #fff;
position: absolute;
top: 0;
left: 100%;
.poster1 {
width: 100%;
height: 2140px;
}
.poster1_logo {
width: 500px;
position: absolute;
top: 50px;
left: 50px;
}
.poster2 {
.logo {
width: 344px;
display: block;
margin: 0 auto;
margin-top: 100px;
}
.title {
font-size: 76px;
font-weight: bold;
color: #4092ff;
text-align: center;
margin-top: 60px;
display: -webkit-box;
white-space: break-spaces;
-webkit-line-clamp: 2;
text-overflow: ellipsis;
overflow: hidden;
-webkit-box-orient: vertical;
padding: 0 50px;
box-sizing: border-box;
}
.des {
font-size: 60px;
color: #999;
text-align: center;
margin-top: 24px;
}
.poster2img {
width: 1392px;
height: 1044px;
display: block;
margin: 0 auto;
margin-top: 60px;
}
.price {
text-align: center;
font-size: 64px;
color: #ff5f5f;
margin-top: 80px;
line-height: 88px;
del {
color: #999;
font-size: 56px;
margin-left: 8px;
}
}
}
.bottom_box {
width: 100%;
padding: 52px;
display: flex;
justify-content: space-between;
position: absolute;
bottom: 0;
box-sizing: border-box;
.text {
font-size: 64px;
color: #999999;
white-space: break-spaces;
span {
color: #0f3853;
}
.des {
display: block;
font-size: 56px;
color: #999;
margin-top: 20px;
}
}
}
}
.qrcodeBox {
.imgBox {
width: 380px;
height: 380px;
}
}
}
.abroad_detail_share_box.type_order {
height: 100%;
.content {
width: 616px;
height: 632px;
bottom: auto;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
border-radius: 20px;
border: none;
}
.share_img {
display: block;
width: 518px;
margin: 0 auto;
margin-top: -90px;
}
.share_text {
// padding: 0 50px;
text-align: center;
margin-top: 20px;
display: -webkit-box;
-webkit-line-clamp: 2;
text-overflow: ellipsis;
overflow: hidden;
-webkit-box-orient: vertical;
}
.line,
.line2 {
display: none;
}
.share_btn_box {
margin-top: 58px;
display: block;
.btn {
width: 504px;
height: 92px;
line-height: 88px;
box-sizing: border-box;
border: 2px solid #3385ff;
display: block;
margin: 0 auto;
border-radius: 46px;
}
.btn1 {
color: #3385ff;
background: #fff;
}
.btn2 {
color: #fff;
background: #3385ff;
margin-top: 24px;
}
}
}
</style>