|
|
@@ -20,8 +20,9 @@
|
|
20
|
20
|
src="https://cdn.bjtdba.com/vod/image/2025-02-18/20250218234259970.png"
|
|
21
|
21
|
mode=""
|
|
22
|
22
|
></image>
|
|
|
23
|
+
|
|
23
|
24
|
<view class="activite-cardImg">
|
|
24
|
|
- <image :src="qrcode_src" mode="widthFix"></image>
|
|
|
25
|
+ <image :src="qrcode_src" mode="widthFix" ref="imagRef"></image>
|
|
25
|
26
|
</view>
|
|
26
|
27
|
<view class="activite-cardText">{{ code_id }}</view>
|
|
27
|
28
|
<view class="activite-cardBtn"> 扫码即得养老金 </view>
|
|
|
@@ -43,20 +44,29 @@
|
|
43
|
44
|
</view>
|
|
44
|
45
|
</view>
|
|
45
|
46
|
</view>
|
|
46
|
|
-
|
|
47
|
|
- <view class="downLoadButton" @click="clickGeneratePicture">
|
|
|
47
|
+ <!-- <image class="activite-card-logo" :src="imageUrl" mode=""></image> -->
|
|
|
48
|
+ <!-- <view class="downLoadButton" @click="clickGeneratePicture">
|
|
48
|
49
|
<image
|
|
49
|
50
|
class="downLoad-image"
|
|
50
|
51
|
src="../../static/saveImage.png"
|
|
51
|
52
|
mode=""
|
|
52
|
53
|
></image>
|
|
53
|
54
|
<view class="downLoad-text"> 保存图片 </view>
|
|
54
|
|
- </view>
|
|
|
55
|
+ </view> -->
|
|
|
56
|
+ <!-- <view class="downLoadButton" @click="clickGeneratePicture2">
|
|
|
57
|
+ <image
|
|
|
58
|
+ class="downLoad-image"
|
|
|
59
|
+ src="../../static/saveImage.png"
|
|
|
60
|
+ mode=""
|
|
|
61
|
+ ></image>
|
|
|
62
|
+ <view class="downLoad-text"> 保存图片 </view>
|
|
|
63
|
+ </view> -->
|
|
55
|
64
|
</view>
|
|
56
|
65
|
|
|
57
|
66
|
<!-- ************************* 海报画板 **********************-->
|
|
58
|
67
|
<view style="position: absolute; bottom: 10%; left: 0%" v-show="flag">
|
|
59
|
68
|
<l-painter
|
|
|
69
|
+ v-if="poster"
|
|
60
|
70
|
:board="poster"
|
|
61
|
71
|
css="width: 750rpx;heigth:200rpx"
|
|
62
|
72
|
isCanvasToTempFilePath
|
|
|
@@ -67,13 +77,26 @@
|
|
67
|
77
|
>
|
|
68
|
78
|
</l-painter>
|
|
69
|
79
|
</view>
|
|
|
80
|
+
|
|
70
|
81
|
<!-- ************************* 海报画板 **********************-->
|
|
|
82
|
+ <canvas
|
|
|
83
|
+ canvas-id="container"
|
|
|
84
|
+ id="container"
|
|
|
85
|
+ :style="{
|
|
|
86
|
+ width: canvasWidth + 'rpx',
|
|
|
87
|
+ height: canvasHeight + 'rpx',
|
|
|
88
|
+ opacity: 1,
|
|
|
89
|
+ }"
|
|
|
90
|
+ ></canvas>
|
|
71
|
91
|
</view>
|
|
72
|
92
|
</template>
|
|
73
|
93
|
|
|
74
|
94
|
<script>
|
|
75
|
95
|
import { queryByKey } from "@/commit/shop.js";
|
|
76
|
96
|
import lPainter from "@/uni_modules/lime-painter/components/l-painter/l-painter.vue";
|
|
|
97
|
+import html2canvas from "html2canvas";
|
|
|
98
|
+import { saveAs } from "file-saver";
|
|
|
99
|
+
|
|
77
|
100
|
export default {
|
|
78
|
101
|
components: {
|
|
79
|
102
|
lPainter,
|
|
|
@@ -84,12 +107,14 @@ export default {
|
|
84
|
107
|
qrcode_src: "",
|
|
85
|
108
|
code_id: "",
|
|
86
|
109
|
status: "",
|
|
87
|
|
- imageUrl: "",
|
|
88
|
110
|
picture: "",
|
|
89
|
111
|
isHide: true,
|
|
90
|
|
- poster: {},
|
|
|
112
|
+ poster: null,
|
|
91
|
113
|
image: "",
|
|
92
|
114
|
flag: false,
|
|
|
115
|
+ canvasWidth: 300, // 单位:rpx
|
|
|
116
|
+ canvasHeight: 300,
|
|
|
117
|
+ imageUrl: "",
|
|
93
|
118
|
};
|
|
94
|
119
|
},
|
|
95
|
120
|
onLoad(e) {
|
|
|
@@ -105,7 +130,7 @@ export default {
|
|
105
|
130
|
},
|
|
106
|
131
|
methods: {
|
|
107
|
132
|
queryByKey() {
|
|
108
|
|
- const _this = this
|
|
|
133
|
+ const _this = this;
|
|
109
|
134
|
queryByKey({
|
|
110
|
135
|
key: "merchant_xiaochengxu_shenhe",
|
|
111
|
136
|
}).then(
|
|
|
@@ -114,9 +139,9 @@ export default {
|
|
114
|
139
|
this.status = res.data.data.status;
|
|
115
|
140
|
uni.hideLoading();
|
|
116
|
141
|
|
|
117
|
|
- this.$nextTick(()=>{
|
|
118
|
|
- _this.drawPoster();
|
|
119
|
|
- })
|
|
|
142
|
+ this.$nextTick(() => {
|
|
|
143
|
+ _this.drawPoster();
|
|
|
144
|
+ });
|
|
120
|
145
|
}
|
|
121
|
146
|
},
|
|
122
|
147
|
(fail) => {
|
|
|
@@ -125,11 +150,59 @@ export default {
|
|
125
|
150
|
}
|
|
126
|
151
|
);
|
|
127
|
152
|
},
|
|
|
153
|
+ async drawImageToCanvas() {
|
|
|
154
|
+ // const ctx = uni.createCanvasContext("myCanvas", this);
|
|
|
155
|
+ // 清空画布
|
|
|
156
|
+ // ctx.clearRect(0, 0, this.canvasWidth, this.canvasHeight);
|
|
|
157
|
+ // const img = new Image();
|
|
|
158
|
+ // img.crossOrigin = 'anonymous'; // 设置跨域属性
|
|
|
159
|
+ // img.src = 'https://example.com/your-image.jpg'; // 替换为实际的图片地址
|
|
|
160
|
+ const _this = this;
|
|
|
161
|
+ try {
|
|
|
162
|
+ const resData = await uni.getImageInfo({
|
|
|
163
|
+ src: decodeURIComponent(this.qrcode_src),
|
|
|
164
|
+ });
|
|
|
165
|
+ const res = resData[1] || {};
|
|
|
166
|
+ // 居中绘制图片(带缩放)
|
|
|
167
|
+ const imgWidth = res.width;
|
|
|
168
|
+ const imgHeight = res.height;
|
|
|
169
|
+ const scale = Math.min(
|
|
|
170
|
+ this.canvasWidth / imgWidth,
|
|
|
171
|
+ this.canvasHeight / imgHeight
|
|
|
172
|
+ );
|
|
|
173
|
+ const drawWidth = imgWidth * scale;
|
|
|
174
|
+ const drawHeight = imgHeight * scale;
|
|
|
175
|
+ const offsetX = (this.canvasWidth - drawWidth) / 2;
|
|
|
176
|
+ const offsetY = (this.canvasHeight - drawHeight) / 2;
|
|
|
177
|
+ console.log(res, "resData");
|
|
|
178
|
+ uni.canvasToTempFilePath({
|
|
|
179
|
+ x: offsetX,
|
|
|
180
|
+ y: offsetY,
|
|
|
181
|
+ width: imgWidth,
|
|
|
182
|
+ height: imgHeight,
|
|
|
183
|
+ destWidth: drawWidth,
|
|
|
184
|
+ destHeight: drawHeight,
|
|
|
185
|
+ canvasId: "container",
|
|
|
186
|
+ success: function (res) {
|
|
|
187
|
+ // 在H5平台下,tempFilePath 为 base64
|
|
|
188
|
+ // const imageUrl = `data:image/png;base64,${res.tempFilePath}`;
|
|
|
189
|
+ const imageUrl = `${res.tempFilePath}`;
|
|
|
190
|
+ const contentPath = _this.$refs.imagRef.contentPath;
|
|
|
191
|
+ _this.fileDwonload(imageUrl, contentPath);
|
|
|
192
|
+ },
|
|
|
193
|
+ });
|
|
|
194
|
+
|
|
|
195
|
+ // ctx.drawImage(res.path, offsetX, offsetY, drawWidth, drawHeight);
|
|
|
196
|
+ // ctx.draw();
|
|
|
197
|
+ } catch (err) {
|
|
|
198
|
+ console.error("图片加载失败:", err);
|
|
|
199
|
+ }
|
|
|
200
|
+ },
|
|
128
|
201
|
|
|
129
|
202
|
// 绘制图片
|
|
130
|
203
|
drawPoster() {
|
|
131
|
204
|
//获取数据后,开始绘画
|
|
132
|
|
- const that =this
|
|
|
205
|
+ const that = this;
|
|
133
|
206
|
|
|
134
|
207
|
this.poster = {
|
|
135
|
208
|
width: "750rpx",
|
|
|
@@ -261,9 +334,9 @@ export default {
|
|
261
|
334
|
},
|
|
262
|
335
|
],
|
|
263
|
336
|
};
|
|
264
|
|
- let base = this.poster;
|
|
265
|
|
- const painter = that.$refs.posterRef || {};
|
|
266
|
|
- painter.render(base);
|
|
|
337
|
+ // let base = this.poster;
|
|
|
338
|
+ // const painter = that.$refs.posterRef || {};
|
|
|
339
|
+ // painter.render(base);
|
|
267
|
340
|
},
|
|
268
|
341
|
|
|
269
|
342
|
topgi() {
|
|
|
@@ -296,89 +369,116 @@ export default {
|
|
296
|
369
|
pathType: "url",
|
|
297
|
370
|
success: (res) => {
|
|
298
|
371
|
console.log(res.tempFilePath);
|
|
299
|
|
- this.picture = res.tempFilePath
|
|
|
372
|
+ this.picture = res.tempFilePath;
|
|
300
|
373
|
// 2.保存
|
|
301
|
|
- this.saveImage()
|
|
|
374
|
+ this.saveImage();
|
|
302
|
375
|
},
|
|
303
|
376
|
fail(e) {
|
|
304
|
377
|
console.log("???????????", e);
|
|
305
|
378
|
},
|
|
306
|
379
|
});
|
|
307
|
380
|
},
|
|
308
|
|
-
|
|
|
381
|
+ clickGeneratePicture2() {
|
|
|
382
|
+ this.drawImageToCanvas();
|
|
|
383
|
+ },
|
|
309
|
384
|
// 保存图片
|
|
310
|
385
|
saveImage() {
|
|
311
|
386
|
let that = this;
|
|
312
|
387
|
console.log("xxxxxxxxxxxx");
|
|
313
|
|
- console.log(that.picture);
|
|
314
|
|
- if (that.picture !== "") {
|
|
315
|
|
- uni.hideLoading();
|
|
316
|
|
- //#ifdef App-PLUS
|
|
317
|
|
- uni.getSetting({
|
|
318
|
|
- success(res) {
|
|
319
|
|
- if (res.authSetting["scope.writePhotosAlbum"]) {
|
|
320
|
|
- that.saveImageToAlbum();
|
|
321
|
|
- } else if (
|
|
322
|
|
- res.authSetting["scope.writePhotosAlbum"] === undefined
|
|
323
|
|
- ) {
|
|
324
|
|
- uni.authorize({
|
|
325
|
|
- scope: "scope.writePhotosAlbum",
|
|
326
|
|
- success() {
|
|
327
|
|
- uni.showModal({
|
|
328
|
|
- title: "保存成功",
|
|
329
|
|
- content: "图片已成功保存到相册,快去分享到您的圈子吧",
|
|
330
|
|
- showCancel: false,
|
|
331
|
|
- });
|
|
332
|
|
- },
|
|
333
|
|
- fail() {
|
|
334
|
|
- that.authConfirm();
|
|
335
|
|
- },
|
|
336
|
|
- });
|
|
337
|
|
- } else {
|
|
338
|
|
- that.authConfirm();
|
|
339
|
|
- }
|
|
340
|
|
- },
|
|
341
|
|
- });
|
|
342
|
|
- //#endif
|
|
343
|
|
- // #ifdef H5
|
|
344
|
|
- that.posterData()
|
|
345
|
|
- // #endif
|
|
346
|
|
-
|
|
347
|
|
- } else {
|
|
348
|
|
- uni.showModal({
|
|
349
|
|
- title: "提示",
|
|
350
|
|
- content: "生成海报失败,请重试",
|
|
351
|
|
- showCancel: false,
|
|
352
|
|
- });
|
|
353
|
|
- }
|
|
|
388
|
+ console.log(that.picture);
|
|
|
389
|
+ if (that.picture !== "") {
|
|
|
390
|
+ uni.hideLoading();
|
|
|
391
|
+ uni.getSetting({
|
|
|
392
|
+ success(res) {
|
|
|
393
|
+ if (res.authSetting["scope.writePhotosAlbum"]) {
|
|
|
394
|
+ that.saveImageToAlbum();
|
|
|
395
|
+ } else if (
|
|
|
396
|
+ res.authSetting["scope.writePhotosAlbum"] === undefined
|
|
|
397
|
+ ) {
|
|
|
398
|
+ uni.authorize({
|
|
|
399
|
+ scope: "scope.writePhotosAlbum",
|
|
|
400
|
+ success() {
|
|
|
401
|
+ uni.showModal({
|
|
|
402
|
+ title: "保存成功",
|
|
|
403
|
+ content: "图片已成功保存到相册,快去分享到您的圈子吧",
|
|
|
404
|
+ showCancel: false,
|
|
|
405
|
+ });
|
|
|
406
|
+ },
|
|
|
407
|
+ fail() {
|
|
|
408
|
+ that.authConfirm();
|
|
|
409
|
+ },
|
|
|
410
|
+ });
|
|
|
411
|
+ } else {
|
|
|
412
|
+ that.authConfirm();
|
|
|
413
|
+ }
|
|
|
414
|
+ },
|
|
|
415
|
+ });
|
|
|
416
|
+ } else {
|
|
|
417
|
+ uni.showModal({
|
|
|
418
|
+ title: "提示",
|
|
|
419
|
+ content: "生成海报失败,请重试",
|
|
|
420
|
+ showCancel: false,
|
|
|
421
|
+ });
|
|
|
422
|
+ }
|
|
354
|
423
|
},
|
|
355
|
|
- posterData() {
|
|
356
|
|
- let path = this.picture;
|
|
357
|
|
- let that = this;
|
|
358
|
|
- // #ifdef H5
|
|
359
|
|
- var eleLink = document.createElement("a");
|
|
360
|
|
- eleLink.download = "filename";
|
|
361
|
|
- eleLink.style.display = "none";
|
|
362
|
|
- eleLink.href = path;
|
|
363
|
|
- document.body.appendChild(eleLink);
|
|
364
|
|
- eleLink.click();
|
|
365
|
|
- // 然后移除
|
|
366
|
|
- document.body.removeChild(eleLink);
|
|
367
|
|
- // #endif
|
|
368
|
|
- // #ifndef H5
|
|
369
|
|
- uni.saveImageToPhotosAlbum({
|
|
370
|
|
- filePath: path,
|
|
371
|
|
- success(res) {
|
|
372
|
|
- uni.showToast({
|
|
373
|
|
- title: "图片已成功保存到相册,快去分享到您的圈子吧",
|
|
374
|
|
- icon: "success",
|
|
375
|
|
- duration: 2000,
|
|
376
|
|
- });
|
|
|
424
|
+
|
|
|
425
|
+ fileDwonload(base64Data, path) {
|
|
|
426
|
+ uni.showLoading({ title: "保存中...", mask: true });
|
|
|
427
|
+ const _this =this
|
|
|
428
|
+ // const blob = this.base64ToBlob(base64Data);
|
|
|
429
|
+ // const blobUrl = URL.createObjectURL(blob);
|
|
|
430
|
+ const finName = "海报.jpg";
|
|
|
431
|
+ uni.downloadFile({
|
|
|
432
|
+ url: path, //请求地址
|
|
|
433
|
+ success: (res) => {
|
|
|
434
|
+ //下载成功
|
|
|
435
|
+ console.log(res, "下载成功");
|
|
|
436
|
+ if (res.statusCode === 200) {
|
|
|
437
|
+ //保存文件
|
|
|
438
|
+ let filePath = res.tempFilePath;
|
|
|
439
|
+ // #ifdef H5
|
|
|
440
|
+ saveAs(filePath, finName);
|
|
|
441
|
+ uni.showModal({
|
|
|
442
|
+ title: "保存成功",
|
|
|
443
|
+ content: "图片已成功保存到相册,快去分享到您的圈子吧",
|
|
|
444
|
+ showCancel: false,
|
|
|
445
|
+ });
|
|
|
446
|
+ // #endif
|
|
|
447
|
+ // #ifdef MP-WEIXIN || APP-PLUS
|
|
|
448
|
+ uni.saveFile({
|
|
|
449
|
+ tempFilePath: filePath,
|
|
|
450
|
+ success: function (filRes) {
|
|
|
451
|
+ console.log(filRes, "=====>");
|
|
|
452
|
+ },
|
|
|
453
|
+ fail: function (err) {
|
|
|
454
|
+ console.log("保存失败");
|
|
|
455
|
+ },
|
|
|
456
|
+ });
|
|
|
457
|
+ // #endif
|
|
|
458
|
+ uni.hideLoading();
|
|
|
459
|
+ }
|
|
|
460
|
+ },
|
|
|
461
|
+ fail: (e) => {
|
|
|
462
|
+ console.log(e, "文件下载失败downloadFile");
|
|
|
463
|
+ uni.hideLoading();
|
|
|
464
|
+ _this.loadFiles(path, finName);
|
|
|
465
|
+
|
|
|
466
|
+ // uni.showToast({
|
|
|
467
|
+ // title: "文件下载保存失败",
|
|
|
468
|
+ // icon: "error",
|
|
|
469
|
+ // });
|
|
377
|
470
|
},
|
|
378
|
471
|
});
|
|
379
|
|
- // #endif
|
|
380
|
472
|
},
|
|
381
|
|
-
|
|
|
473
|
+ loadFiles(url, fileName) {
|
|
|
474
|
+ const a = document.createElement("a");
|
|
|
475
|
+ a.href = url;
|
|
|
476
|
+ a.download = fileName;
|
|
|
477
|
+ a.style.display = "none";
|
|
|
478
|
+ document.body.appendChild(a);
|
|
|
479
|
+ a.click();
|
|
|
480
|
+ document.body.removeChild(a);
|
|
|
481
|
+ },
|
|
382
|
482
|
// 未授权相册功能 重新弹窗
|
|
383
|
483
|
authConfirm() {
|
|
384
|
484
|
let that = this;
|
|
|
@@ -411,7 +511,20 @@ export default {
|
|
411
|
511
|
},
|
|
412
|
512
|
});
|
|
413
|
513
|
},
|
|
|
514
|
+ base64ToBlob(base64) {
|
|
|
515
|
+ const parts = base64.split(";base64,");
|
|
|
516
|
+ const mimeType = parts[0].split(":")[1];
|
|
|
517
|
+ const base64Data = parts[1];
|
|
|
518
|
+ var binaryData = atob(base64.split(";base64,")[1]);
|
|
|
519
|
+ // const binaryData = atob(base64Data);
|
|
|
520
|
+ const arrayBuffer = new ArrayBuffer(binaryData.length);
|
|
|
521
|
+ const uint8Array = new Uint8Array(arrayBuffer);
|
|
|
522
|
+ for (let i = 0; i < binaryData.length; i++) {
|
|
|
523
|
+ uint8Array[i] = binaryData.charCodeAt(i);
|
|
|
524
|
+ }
|
|
414
|
525
|
|
|
|
526
|
+ return new Blob([uint8Array], { type: mimeType });
|
|
|
527
|
+ },
|
|
415
|
528
|
// 保存到相册
|
|
416
|
529
|
saveImageToAlbum() {
|
|
417
|
530
|
uni.saveImageToPhotosAlbum({
|