uview-plus 3.4.84 → 3.4.85

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/changelog.md CHANGED
@@ -1,7 +1,11 @@
1
+ ## 3.4.85(2025-08-11)
2
+ feat: 完善图片裁剪功能支持props及JS两种方式
3
+
4
+ fix: 修复H5下裁剪后图片黑屏
5
+
1
6
  ## 3.4.84(2025-08-11)
2
7
  feat: 新增cropper图片裁剪组件
3
8
 
4
-
5
9
  ## 3.4.83(2025-08-11)
6
10
  feat: 新增barcode无三方依赖条码组
7
11
 
@@ -1,12 +1,12 @@
1
- <template name="u-cropper">
2
- <view>
3
- <image :src="imgSrc.imgSrc" @click="select" :style="[ imgStyle ]" class="my-avatar"></image>
4
- <canvas canvas-id="avatar-canvas" id="avatar-canvas" class="my-canvas"
1
+ <template>
2
+ <view class="u-cropper">
3
+ <!-- <image :src="imgSrc.imgSrc" @click="select" :style="[ imgStyle ]" class="my-avatar"></image> -->
4
+ <canvas :canvas-id="'avatar-canvas-' + instanceId" :id="'avatar-canvas-' + instanceId" class="my-canvas"
5
5
  :style="{top: styleTop, height: cvsStyleHeight}" disable-scroll="false"></canvas>
6
- <canvas canvas-id="oper-canvas" id="oper-canvas" class="oper-canvas"
6
+ <canvas :canvas-id="'oper-canvas-' + instanceId" :id="'oper-canvas-' + instanceId" class="oper-canvas"
7
7
  :style="{top: styleTop, height: cvsStyleHeight}"
8
8
  disable-scroll="false" @touchstart="start" @touchmove="move" @touchend="end"></canvas>
9
- <canvas canvas-id="prv-canvas" id="prv-canvas" class="prv-canvas"disable-scroll="false"
9
+ <canvas :canvas-id="'prv-canvas-' + instanceId" :id="'prv-canvas-' + instanceId" class="prv-canvas"disable-scroll="false"
10
10
  @touchstart="hideImg":style="{ height: cvsStyleHeight, top: prvTop }"></canvas>
11
11
  <view class="oper-wrapper" :style="{display: styleDisplay}">
12
12
  <view class="oper">
@@ -24,6 +24,11 @@
24
24
  </view>
25
25
  </view>
26
26
  </view>
27
+ <view @click="chooseImage(0, {})" v-if="styleDisplay == 'none'">
28
+ <slot>
29
+
30
+ </slot>
31
+ </view>
27
32
  </view>
28
33
  </template>
29
34
 
@@ -33,6 +38,8 @@
33
38
  name: "u-cropper",
34
39
  data() {
35
40
  return {
41
+ // 添加实例ID用于区分不同实例
42
+ instanceId: Date.now() + '-' + Math.random().toString(36).substr(2, 9),
36
43
  cvsStyleHeight: '0px',
37
44
  styleDisplay: 'none',
38
45
  styleTop: '-10000px',
@@ -45,6 +52,17 @@
45
52
  },
46
53
  btnWidth: '19%',
47
54
  btnDsp: 'flex',
55
+ // 裁剪区域宽度,用于设置选择区域的宽度
56
+ arWidth: '',
57
+ // 裁剪区域高度,用于设置选择区域的高度
58
+ arHeight: '',
59
+ // 导出图片宽度,用于设置最终导出图片的宽度
60
+ expWidth: '',
61
+ // 导出图片高度,用于设置最终导出图片的高度
62
+ expHeight: '',
63
+ // 是否允许调整裁剪框大小
64
+ letChangeSize: false,
65
+
48
66
  };
49
67
  },
50
68
  watch: {
@@ -54,16 +72,6 @@
54
72
  },
55
73
  emits: ['avtinit', 'confirm'],
56
74
  props:{
57
- // 裁剪区域宽度,用于设置选择区域的宽度
58
- areaWidth: '',
59
- // 裁剪区域高度,用于设置选择区域的高度
60
- areaHeight: '',
61
- // 导出图片宽度,用于设置最终导出图片的宽度
62
- exportWidth: '',
63
- // 导出图片高度,用于设置最终导出图片的高度
64
- exportHeight: '',
65
- // 是否允许调整裁剪框大小
66
- canChangeSize: false,
67
75
  minScale: '',
68
76
  maxScale: '',
69
77
  canScale: true,
@@ -76,17 +84,25 @@
76
84
  inner: false,
77
85
  quality: '',
78
86
  index: '',
87
+ canChangeSize: false,
88
+ areaWidth: '300rpx',
89
+ // 裁剪区域高度,用于设置选择区域的高度
90
+ areaHeight: '300rpx',
91
+ // 导出图片宽度,用于设置最终导出图片的宽度
92
+ exportWidth: '260rpx',
93
+ // 导出图片高度,用于设置最终导出图片的高度
94
+ exportHeight: '260rpx',
79
95
  },
80
96
  created() {
81
- this.ctxCanvas = uni.createCanvasContext('avatar-canvas', this);
82
- this.ctxCanvasOper = uni.createCanvasContext('oper-canvas', this);
83
- this.ctxCanvasPrv = uni.createCanvasContext('prv-canvas', this);
97
+ this.ctxCanvas = uni.createCanvasContext('avatar-canvas-' + this.instanceId, this);
98
+ this.ctxCanvasOper = uni.createCanvasContext('oper-canvas-' + this.instanceId, this);
99
+ this.ctxCanvasPrv = uni.createCanvasContext('prv-canvas-' + this.instanceId, this);
84
100
  this.qlty = parseInt(this.quality) || 0.9;
85
- this.imgSrc.imgSrc = this.avatarSrc;
101
+ this.imgSrc.imgSrc = this.imageSrc;
86
102
  this.letRotate = (this.canRotate === false || this.inner === true) ? 0 : 1;
87
103
  this.letScale = this.canScale === false ? 0 : 1;
88
104
  // 是否允许调整裁剪框大小,false表示不允许,其他值表示允许
89
- this.letChangeSize = this.canChangeSize === false ? 0 : 1;
105
+ this.letChangeSize = this.canChangeSize;
90
106
  this.isin = this.inner === true ? 1 : 0;
91
107
  this.indx = this.index || undefined;
92
108
  this.mnScale = this.minScale || 0.3;
@@ -162,8 +178,8 @@
162
178
  this.imgStyle = obj;
163
179
  }
164
180
 
165
- this.exportWidth && (this.exportWidth = this.exportWidth.indexOf('rpx') >= 0 ? parseInt(this.exportWidth)*this.pxRatio : parseInt(this.exportWidth));
166
- this.exportHeight && (this.exportHeight = this.exportHeight.indexOf('rpx') >= 0 ? parseInt(this.exportHeight)*this.pxRatio : parseInt(this.exportHeight));
181
+ this.expWidth && (this.expWidth = this.expWidth.indexOf('rpx') >= 0 ? parseInt(this.expWidth)*this.pxRatio : parseInt(this.expWidth));
182
+ this.expHeight && (this.expHeight = this.expHeight.indexOf('rpx') >= 0 ? parseInt(this.expHeight)*this.pxRatio : parseInt(this.expHeight));
167
183
 
168
184
  if(this.styleDisplay === 'flex') {
169
185
  this.drawInit(true);
@@ -190,9 +206,9 @@
190
206
  this.path = path;
191
207
  if( !this.hasSel ) {
192
208
  let style = this.selStyle || {};
193
- if( this.areaWidth && this.areaHeight ) {
194
- let areaWidth = this.areaWidth.indexOf('rpx') >= 0 ? parseInt(this.areaWidth) * this.pxRatio: parseInt(this.areaWidth),
195
- areaHeight = this.areaHeight.indexOf('rpx') >= 0 ? parseInt(this.areaHeight) * this.pxRatio: parseInt(this.areaHeight);
209
+ if( this.arWidth && this.arHeight ) {
210
+ let areaWidth = this.arWidth.indexOf('rpx') >= 0 ? parseInt(this.arWidth) * this.pxRatio: parseInt(this.arWidth),
211
+ areaHeight = this.arHeight.indexOf('rpx') >= 0 ? parseInt(this.arHeight) * this.pxRatio: parseInt(this.arHeight);
196
212
  style.width = areaWidth + 'px';
197
213
  style.height = areaHeight + 'px';
198
214
  style.top = (this.windowHeight - areaHeight - tabHeight)/2 + 'px';
@@ -240,12 +256,12 @@
240
256
  y = parseInt(style.top),
241
257
  width = parseInt(style.width),
242
258
  height = parseInt(style.height),
243
- expWidth = this.exportWidth || width,
244
- expHeight = this.exportHeight || height;
259
+ expWidth = this.expWidth || width,
260
+ expHeight = this.expHeight || height;
245
261
 
246
262
  // #ifdef H5
247
- x *= this.pixelRatio;
248
- y *= this.pixelRatio;
263
+ // x *= this.pixelRatio;
264
+ // y *= this.pixelRatio;
249
265
  expWidth = width;
250
266
  expHeight = height;
251
267
  // #endif
@@ -262,18 +278,17 @@
262
278
  height: height,
263
279
  destWidth: expWidth,
264
280
  destHeight: expHeight,
265
- canvasId: 'avatar-canvas',
281
+ canvasId: 'avatar-canvas-' + this.instanceId,
266
282
  fileType: 'png',
267
283
  quality: this.qlty,
268
284
  success: (r)=>{
269
285
  r = r.tempFilePath;
270
286
  // #ifdef H5
271
- alert()
272
287
  this.btop(r).then((r)=> {
273
- if(this.exportWidth && this.exportHeight) {
288
+ if(this.expWidth && this.expHeight) {
274
289
  let ctxCanvas = this.ctxCanvas;
275
- expWidth = this.exportWidth,
276
- expHeight = this.exportHeight;
290
+ expWidth = this.expWidth,
291
+ expHeight = this.expHeight;
277
292
 
278
293
  ctxCanvas.drawImage(r, 0, 0, expWidth, expHeight);
279
294
  ctxCanvas.draw(false,()=>{
@@ -284,7 +299,7 @@
284
299
  height: expHeight,
285
300
  destWidth: expWidth,
286
301
  destHeight: expHeight,
287
- canvasId: 'avatar-canvas',
302
+ canvasId: 'avatar-canvas-' + this.instanceId,
288
303
  fileType: 'png',
289
304
  quality: this.qlty,
290
305
  success: (r)=>{
@@ -335,12 +350,12 @@
335
350
  prvY = this.prvY,
336
351
  prvWidth = this.prvWidth,
337
352
  prvHeight = this.prvHeight,
338
- expWidth = this.exportWidth || prvWidth,
339
- expHeight = this.exportHeight || prvHeight;
353
+ expWidth = this.expWidth || prvWidth,
354
+ expHeight = this.expHeight || prvHeight;
340
355
 
341
356
  // #ifdef H5
342
- prvX *= this.pixelRatio;
343
- prvY *= this.pixelRatio;
357
+ // prvX *= this.pixelRatio;
358
+ // prvY *= this.pixelRatio;
344
359
  expWidth = prvWidth;
345
360
  expHeight = prvHeight;
346
361
  // #endif
@@ -358,17 +373,17 @@
358
373
  height: prvHeight,
359
374
  destWidth: expWidth,
360
375
  destHeight: expHeight,
361
- canvasId: 'prv-canvas',
376
+ canvasId: 'prv-canvas-' + this.instanceId,
362
377
  fileType: 'png',
363
378
  quality: this.qlty,
364
379
  success: (r)=>{
365
380
  r = r.tempFilePath;
366
381
  // #ifdef H5
367
382
  this.btop(r).then((r)=> {
368
- if(this.exportWidth && this.exportHeight) {
383
+ if(this.expWidth && this.expHeight) {
369
384
  let ctxCanvas = this.ctxCanvas;
370
- expWidth = this.exportWidth,
371
- expHeight = this.exportHeight;
385
+ expWidth = this.expWidth,
386
+ expHeight = this.expHeight;
372
387
 
373
388
  ctxCanvas.drawImage(r, 0, 0, expWidth, expHeight);
374
389
  ctxCanvas.draw(false, ()=>{
@@ -379,7 +394,7 @@
379
394
  height: expHeight,
380
395
  destWidth: expWidth,
381
396
  destHeight: expHeight,
382
- canvasId: 'avatar-canvas',
397
+ canvasId: 'avatar-canvas-' + this.instanceId,
383
398
  fileType: 'png',
384
399
  quality: this.qlty,
385
400
  success: (r)=>{
@@ -592,30 +607,24 @@
592
607
  if(this.fPreviewing) return;
593
608
  this.fPreviewing = true;
594
609
  setTimeout(()=>{ this.fPreviewing = false; }, 1000);
595
-
596
610
  let style = this.selStyle,
597
611
  x = parseInt(style.left),
598
612
  y = parseInt(style.top),
599
613
  width = parseInt(style.width),
600
614
  height = parseInt(style.height);
601
615
 
602
- // #ifdef H5
603
- x *= this.pixelRatio;
604
- y *= this.pixelRatio;
605
- // #endif
606
-
607
616
  uni.showLoading({ mask: true });
608
- console.log('size', x, y, width, height)
617
+ // console.log('size', x, y, width, height)
609
618
  uni.canvasToTempFilePath({
610
619
  x: x,
611
620
  y: y,
612
621
  width: width,
613
622
  height: height,
614
- canvasId: 'avatar-canvas',
623
+ canvasId: 'avatar-canvas-' + this.instanceId,
615
624
  fileType: 'png',
616
625
  quality: this.qlty,
617
626
  success: (r)=>{
618
- console.log(r)
627
+ // console.log(r)
619
628
  this.prvImgTmp = r = r.tempFilePath;
620
629
 
621
630
  let ctxCanvasPrv = this.ctxCanvasPrv,
@@ -635,7 +644,7 @@
635
644
  prvWidth *= radio;
636
645
  prvHeight = useHeight;
637
646
  }
638
- // ctxCanvasPrv.setFillStyle('black');
647
+ ctxCanvasPrv.setFillStyle('black');
639
648
  ctxCanvasPrv.fillRect(0, 0, prvX, prvY);
640
649
  ctxCanvasPrv.fillRect(x, y, width, height);
641
650
  this.prvX = prvX = (prvX-prvWidth)/2;
@@ -643,7 +652,7 @@
643
652
  this.prvWidth = prvWidth;
644
653
  this.prvHeight = prvHeight;
645
654
  ctxCanvasPrv.drawImage(r, prvX, prvY, prvWidth, prvHeight);
646
- ctxCanvasPrv.draw(false, () => {alert()
655
+ ctxCanvasPrv.draw(false, () => {
647
656
  // #ifdef H5
648
657
  this.btop(this.prvImgTmp).then((r)=> {
649
658
  this.showOper = false;
@@ -671,26 +680,28 @@
671
680
  },
672
681
  chooseImage(index=undefined, params=undefined, data=undefined) {
673
682
  if(params) {
674
- let areaWidth = params.areaWidth,
675
- areaHeight = params.areaHeight,
676
- expWidth = params.expWidth,
677
- expHeight = params.expHeight,
683
+ console.log(params)
684
+ let areaWidth = params.areaWidth || this.areaWidth,
685
+ areaHeight = params.areaHeight || this.areaHeight,
686
+ expWidth = params.exportWidth || this.exportWidth,
687
+ expHeight = params.exportHeight || this.exportHeight,
678
688
  quality = params.quality,
679
689
  canRotate = params.canRotate,
680
690
  canScale = params.canScale,
681
- canChangeSize = params.canChangeSize || false,
691
+ canChangeSize = params.canChangeSize,
682
692
  minScale = params.minScale,
683
693
  maxScale = params.maxScale,
684
694
  stretch = params.stretch,
685
695
  inner = params.inner,
686
696
  lock = params.lock;
697
+ console.log('areaWidth', this.areaWidth)
687
698
 
688
- expWidth && (this.exportWidth = expWidth.indexOf('rpx') >= 0 ? parseInt(expWidth)*this.pxRatio : parseInt(expWidth));
689
- expHeight && (this.exportHeight = expHeight.indexOf('rpx') >= 0 ? parseInt(expHeight)*this.pxRatio : parseInt(expHeight));
699
+ expWidth && (this.expWidth = expWidth.indexOf('rpx') >= 0 ? parseInt(expWidth)*this.pxRatio : parseInt(expWidth));
700
+ expHeight && (this.expHeight = expHeight.indexOf('rpx') >= 0 ? parseInt(expHeight)*this.pxRatio : parseInt(expHeight));
690
701
  this.letRotate = canRotate === false ? 0 : 1;
691
702
  this.letScale = canScale === false ? 0 : 1;
692
703
  // 设置是否允许调整裁剪框大小
693
- this.letChangeSize = canChangeSize === false ? 0 : 1;
704
+ this.letChangeSize = canChangeSize || false;
694
705
  this.qlty = parseInt(quality) || 0.9;
695
706
  this.mnScale = minScale || 0.3;
696
707
  this.mxScale = maxScale || 4;
@@ -712,6 +723,7 @@
712
723
  this.selStyle.height = areaHeight + 'px';
713
724
  this.selStyle.top = (this.windowHeight - areaHeight - tabHeight)/2 + 'px';
714
725
  this.selStyle.left = (this.windowWidth - areaWidth)/2 + 'px';
726
+ // console.log(this.selStyle);
715
727
  this.hasSel = true;
716
728
  }
717
729
  }
@@ -936,7 +948,7 @@
936
948
  prvHeight *= this.pixelRatio;
937
949
  // #endif
938
950
  uni.canvasGetImageData({
939
- canvasId: 'prv-canvas',
951
+ canvasId: 'prv-canvas-' + this.instanceId,
940
952
  x: prvX,
941
953
  y: prvY,
942
954
  width: prvWidth,
@@ -1070,7 +1082,7 @@
1070
1082
  prvHeight *= this.pixelRatio;
1071
1083
  // #endif
1072
1084
  uni.canvasPutImageData({
1073
- canvasId: 'prv-canvas',
1085
+ canvasId: 'prv-canvas-' + this.instanceId,
1074
1086
  x: prvX,
1075
1087
  y: prvY,
1076
1088
  width: prvWidth,
@@ -1104,7 +1116,8 @@
1104
1116
  }
1105
1117
  </script>
1106
1118
 
1107
- <style>
1119
+ <style lang="scss" scoped>
1120
+ .u-cropper {
1108
1121
  .my-canvas{
1109
1122
  display: flex;
1110
1123
  position: fixed !important;
@@ -1196,4 +1209,5 @@
1196
1209
  .my-slider {
1197
1210
  flex-grow: 1;
1198
1211
  }
1212
+ }
1199
1213
  </style>
package/package.json CHANGED
@@ -2,8 +2,8 @@
2
2
  "id": "uview-plus",
3
3
  "name": "uview-plus",
4
4
  "displayName": "零云®uview-plus3.0重磅发布,全面的Vue3鸿蒙跨端移动组件库,组件丰富维护更新稳定。",
5
- "version": "3.4.84",
6
- "description": "零云®uview-plus已兼容vue3,100+全面的组件和便捷的工具会让您信手拈来,如鱼得水。",
5
+ "version": "3.4.85",
6
+ "description": "零云®uview-plus已兼容vue3,100+全面的组件和便捷的工具会让您信手拈来。近期新增拖动排序、条码、图片裁剪、下拉刷新、虚拟列表等。",
7
7
  "keywords": [
8
8
  "uview",
9
9
  "uview-plus",