storeBelieveInLight il y a 1 an
Parent
commit
beb6711f42
4 fichiers modifiés avec 204 ajouts et 90 suppressions
  1. 1 0
      package.json
  2. 4 4
      pages/cashier/index.vue
  3. 195 82
      shop/perating/activitecode.vue
  4. 4 4
      shop/perating/statement.vue

+ 1 - 0
package.json

@@ -5,6 +5,7 @@
5
     "base-64": "^1.0.0",
5
     "base-64": "^1.0.0",
6
     "crypto-js": "^4.1.1",
6
     "crypto-js": "^4.1.1",
7
     "easemob-websdk": "^4.6.0",
7
     "easemob-websdk": "^4.6.0",
8
+    "file-saver": "^2.0.5",
8
     "html2canvas": "^1.4.1",
9
     "html2canvas": "^1.4.1",
9
     "pinia": "^2.1.0",
10
     "pinia": "^2.1.0",
10
     "vconsole": "^3.15.1"
11
     "vconsole": "^3.15.1"

+ 4 - 4
pages/cashier/index.vue

@@ -118,20 +118,20 @@
118
 						消费分
118
 						消费分
119
 					</view>
119
 					</view>
120
 				</view> -->
120
 				</view> -->
121
-        <!-- <view class="yis">
121
+        <view class="yis">
122
           <view class="sgjd">
122
           <view class="sgjd">
123
             {{ dataList.sun == undefined ? 0 : dataList.sun }}
123
             {{ dataList.sun == undefined ? 0 : dataList.sun }}
124
           </view>
124
           </view>
125
           <view class="sf"> 锁定会员数 </view>
125
           <view class="sf"> 锁定会员数 </view>
126
-        </view> -->
127
-        <view class="yis">
126
+        </view>
127
+        <!-- <view class="yis">
128
           <view class="sgjd">
128
           <view class="sgjd">
129
             {{
129
             {{
130
               dataList.visitorNumber == undefined ? 0 : dataList.visitorNumber
130
               dataList.visitorNumber == undefined ? 0 : dataList.visitorNumber
131
             }}
131
             }}
132
           </view>
132
           </view>
133
           <view class="sf"> 访客数 </view>
133
           <view class="sf"> 访客数 </view>
134
-        </view>
134
+        </view> -->
135
         <view class="yis">
135
         <view class="yis">
136
           <view class="sgjd">
136
           <view class="sgjd">
137
             {{ dataList.number == undefined ? 0 : dataList.number }}
137
             {{ dataList.number == undefined ? 0 : dataList.number }}

+ 195 - 82
shop/perating/activitecode.vue

@@ -20,8 +20,9 @@
20
           src="https://cdn.bjtdba.com/vod/image/2025-02-18/20250218234259970.png"
20
           src="https://cdn.bjtdba.com/vod/image/2025-02-18/20250218234259970.png"
21
           mode=""
21
           mode=""
22
         ></image>
22
         ></image>
23
+
23
         <view class="activite-cardImg">
24
         <view class="activite-cardImg">
24
-          <image :src="qrcode_src" mode="widthFix"></image>
25
+          <image :src="qrcode_src" mode="widthFix" ref="imagRef"></image>
25
         </view>
26
         </view>
26
         <view class="activite-cardText">{{ code_id }}</view>
27
         <view class="activite-cardText">{{ code_id }}</view>
27
         <view class="activite-cardBtn"> 扫码即得养老金 </view>
28
         <view class="activite-cardBtn"> 扫码即得养老金 </view>
@@ -43,20 +44,29 @@
43
           </view>
44
           </view>
44
         </view>
45
         </view>
45
       </view>
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
         <image
49
         <image
49
           class="downLoad-image"
50
           class="downLoad-image"
50
           src="../../static/saveImage.png"
51
           src="../../static/saveImage.png"
51
           mode=""
52
           mode=""
52
         ></image>
53
         ></image>
53
         <view class="downLoad-text"> 保存图片 </view>
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
     </view>
64
     </view>
56
 
65
 
57
     <!-- ************************* 海报画板 **********************-->
66
     <!-- ************************* 海报画板 **********************-->
58
     <view style="position: absolute; bottom: 10%; left: 0%" v-show="flag">
67
     <view style="position: absolute; bottom: 10%; left: 0%" v-show="flag">
59
       <l-painter
68
       <l-painter
69
+        v-if="poster"
60
         :board="poster"
70
         :board="poster"
61
         css="width: 750rpx;heigth:200rpx"
71
         css="width: 750rpx;heigth:200rpx"
62
         isCanvasToTempFilePath
72
         isCanvasToTempFilePath
@@ -67,13 +77,26 @@
67
       >
77
       >
68
       </l-painter>
78
       </l-painter>
69
     </view>
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
   </view>
91
   </view>
72
 </template>
92
 </template>
73
 
93
 
74
 <script>
94
 <script>
75
 import { queryByKey } from "@/commit/shop.js";
95
 import { queryByKey } from "@/commit/shop.js";
76
 import lPainter from "@/uni_modules/lime-painter/components/l-painter/l-painter.vue";
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
 export default {
100
 export default {
78
   components: {
101
   components: {
79
     lPainter,
102
     lPainter,
@@ -84,12 +107,14 @@ export default {
84
       qrcode_src: "",
107
       qrcode_src: "",
85
       code_id: "",
108
       code_id: "",
86
       status: "",
109
       status: "",
87
-      imageUrl: "",
88
       picture: "",
110
       picture: "",
89
       isHide: true,
111
       isHide: true,
90
-      poster: {},
112
+      poster: null,
91
       image: "",
113
       image: "",
92
       flag: false,
114
       flag: false,
115
+      canvasWidth: 300, // 单位:rpx
116
+      canvasHeight: 300,
117
+      imageUrl: "",
93
     };
118
     };
94
   },
119
   },
95
   onLoad(e) {
120
   onLoad(e) {
@@ -105,7 +130,7 @@ export default {
105
   },
130
   },
106
   methods: {
131
   methods: {
107
     queryByKey() {
132
     queryByKey() {
108
-		const _this = this
133
+      const _this = this;
109
       queryByKey({
134
       queryByKey({
110
         key: "merchant_xiaochengxu_shenhe",
135
         key: "merchant_xiaochengxu_shenhe",
111
       }).then(
136
       }).then(
@@ -114,9 +139,9 @@ export default {
114
             this.status = res.data.data.status;
139
             this.status = res.data.data.status;
115
             uni.hideLoading();
140
             uni.hideLoading();
116
 
141
 
117
-           this.$nextTick(()=>{
118
-			 _this.drawPoster();
119
-		   })
142
+            this.$nextTick(() => {
143
+              _this.drawPoster();
144
+            });
120
           }
145
           }
121
         },
146
         },
122
         (fail) => {
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
     drawPoster() {
203
     drawPoster() {
131
       //获取数据后,开始绘画
204
       //获取数据后,开始绘画
132
-	  const that =this
205
+      const that = this;
133
 
206
 
134
       this.poster = {
207
       this.poster = {
135
         width: "750rpx",
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
     topgi() {
342
     topgi() {
@@ -296,89 +369,116 @@ export default {
296
         pathType: "url",
369
         pathType: "url",
297
         success: (res) => {
370
         success: (res) => {
298
           console.log(res.tempFilePath);
371
           console.log(res.tempFilePath);
299
-          this.picture = res.tempFilePath
372
+          this.picture = res.tempFilePath;
300
           // 2.保存
373
           // 2.保存
301
-          this.saveImage()
374
+          this.saveImage();
302
         },
375
         },
303
         fail(e) {
376
         fail(e) {
304
           console.log("???????????", e);
377
           console.log("???????????", e);
305
         },
378
         },
306
       });
379
       });
307
     },
380
     },
308
-
381
+    clickGeneratePicture2() {
382
+      this.drawImageToCanvas();
383
+    },
309
     // 保存图片
384
     // 保存图片
310
     saveImage() {
385
     saveImage() {
311
       let that = this;
386
       let that = this;
312
       console.log("xxxxxxxxxxxx");
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
     authConfirm() {
483
     authConfirm() {
384
       let that = this;
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
     saveImageToAlbum() {
529
     saveImageToAlbum() {
417
       uni.saveImageToPhotosAlbum({
530
       uni.saveImageToPhotosAlbum({

+ 4 - 4
shop/perating/statement.vue

@@ -78,21 +78,21 @@
78
 					消费分
78
 					消费分
79
 				</view>
79
 				</view>
80
 			</view> -->
80
 			</view> -->
81
-      <!-- <view class="yis">
81
+      <view class="yis">
82
 				<view class="sgjd">
82
 				<view class="sgjd">
83
 					{{dataList.sun==undefined?0:dataList.sun}}
83
 					{{dataList.sun==undefined?0:dataList.sun}}
84
 				</view>
84
 				</view>
85
 				<view class="sf">
85
 				<view class="sf">
86
 					锁定会员数
86
 					锁定会员数
87
 				</view>
87
 				</view>
88
-			</view> -->
88
+			</view>
89
 
89
 
90
-      <view class="yis">
90
+      <!-- <view class="yis">
91
         <view class="sgjd">
91
         <view class="sgjd">
92
           {{ dataList.visitorNumber == undefined ? 0 : dataList.visitorNumber }}
92
           {{ dataList.visitorNumber == undefined ? 0 : dataList.visitorNumber }}
93
         </view>
93
         </view>
94
         <view class="sf"> 访客数 </view>
94
         <view class="sf"> 访客数 </view>
95
-      </view>
95
+      </view> -->
96
       <view class="yis">
96
       <view class="yis">
97
         <view class="sgjd">
97
         <view class="sgjd">
98
           {{ dataList.number == undefined ? 0 : dataList.number }}
98
           {{ dataList.number == undefined ? 0 : dataList.number }}