uview-plus 3.4.41 → 3.4.43

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,3 +1,9 @@
1
+ ## 3.4.43(2025-06-16)
2
+ feat: table2支持header插槽
3
+
4
+ ## 3.4.42(2025-06-12)
5
+ fix: 修复qrcode中默认id问题及canvas2时App无法绘制二维码 感谢@jiaruiyan
6
+
1
7
  ## 3.4.41(2025-06-11)
2
8
  feat: qrcode支持 新参数useRootHeightAndWidth 是否使用根节点的宽高 感谢@YJR
3
9
 
@@ -1104,6 +1104,11 @@ let QRCode = {};
1104
1104
  }
1105
1105
  // 创建canvas
1106
1106
  let createCanvas = async function (options) {
1107
+ let isApp = false;
1108
+ // #ifdef APP
1109
+ isApp = true;
1110
+ // #endif
1111
+
1107
1112
  if(options.showLoading){
1108
1113
  uni.showLoading({
1109
1114
  title: options.loadingText,
@@ -1122,7 +1127,13 @@ let QRCode = {};
1122
1127
  canvas.width = options.size;
1123
1128
  canvas.height = options.size;
1124
1129
  // #endif
1130
+ // #ifdef APP
1131
+ ctx = uni.createCanvasContext(options.canvasId, options.context);
1132
+ // #endif
1133
+ // #ifndef APP
1125
1134
  ctx = canvas.getContext('2d');
1135
+ // #endif
1136
+
1126
1137
  }
1127
1138
  // 设置组件中data里面的ctx
1128
1139
  options.context.ctx = ctx;
@@ -1161,12 +1172,14 @@ let QRCode = {};
1161
1172
  ctx.drawImage(options.image, x, y, ratioImgSize, ratioImgSize);
1162
1173
  }
1163
1174
  else {
1164
- // #ifdef H5
1175
+ // #ifdef H5 || APP
1165
1176
  const img = new Image();
1166
1177
  // #endif
1167
- // #ifndef H5
1178
+
1179
+ // #ifndef H5 || APP
1168
1180
  const img = canvas.createImage();
1169
1181
  // #endif
1182
+
1170
1183
  img.onload = () => {
1171
1184
  ctx.drawImage(img, x, y, ratioImgSize, ratioImgSize);
1172
1185
  };
@@ -1174,7 +1187,7 @@ let QRCode = {};
1174
1187
  }
1175
1188
  // 画圆角矩形
1176
1189
  function drawRoundedRect(ctxi, x, y, width, height, r, lineWidth, fill, stroke) {
1177
- if (options.nvueContext) {
1190
+ if (options.nvueContext || isApp) {
1178
1191
  ctxi.setLineWidth(lineWidth);
1179
1192
  ctxi.setFillStyle(options.background);
1180
1193
  ctxi.setStrokeStyle(options.background);
@@ -1209,7 +1222,7 @@ let QRCode = {};
1209
1222
  }
1210
1223
  setTimeout(() => {
1211
1224
  // canvas2 绘制是自动的不需要手动绘制
1212
- if(options.nvueContext){
1225
+ if(options.nvueContext || isApp){
1213
1226
  ctx.draw(true, () => {
1214
1227
  // 保存到临时区域
1215
1228
  setTimeout(() => {
@@ -1,32 +1,50 @@
1
1
  <template>
2
- <view class="u-qrcode"
2
+ <view class="u-qrcode"
3
3
  :id="rootId"
4
4
  :style="{
5
5
  width: useRootHeightAndWidth ? '100%' : 'auto',
6
6
  height: useRootHeightAndWidth ? '100%' : 'auto',
7
7
  }"
8
8
  @longpress="longpress">
9
- <view class="u-qrcode__content" @click="preview">
10
- <!-- #ifndef APP-NVUE -->
11
- <canvas
9
+ <view class="u-qrcode__content" @click="preview">
10
+
11
+ <!-- #ifndef APP-NVUE || APP-PLUS -->
12
+ <canvas
12
13
  class="u-qrcode__canvas"
13
- :id="cid"
14
+ :id="cid"
14
15
  :canvas-id="cid"
15
16
  type="2d"
16
17
  :style="{ width: sizeLocal + unit, height: sizeLocal + unit }" />
17
- <!-- #endif -->
18
- <!-- #ifdef APP-NVUE -->
19
- <gcanvas class="u-qrcode__canvas" ref="gcanvess"
20
- :style="{ width: sizeLocal + unit, height: sizeLocal + unit }">
21
- </gcanvas>
22
- <!-- #endif -->
23
- <view v-if="showLoading && loading" class="u-qrcode__loading"
24
- :style="{ width: sizeLocal + unit, height: sizeLocal + unit }">
25
- <up-loading-icon vertical :text="loadingText" textSize="14px"></up-loading-icon>
26
- </view>
27
- </view>
18
+ <!-- #endif -->
19
+
20
+ <!-- #ifdef APP-PLUS -->
21
+ <canvas
22
+ class="u-qrcode__canvas"
23
+ :id="cid"
24
+ :canvas-id="cid"
25
+ :style="{ width: sizeLocal + unit, height: sizeLocal + unit }" />
26
+ <!-- #endif -->
28
27
 
29
- </view>
28
+ <!-- #ifdef APP-PLUS -->
29
+ <canvas
30
+ class="u-qrcode__canvas"
31
+ :id="cid"
32
+ :canvas-id="cid"
33
+ :style="{ width: sizeLocal + unit, height: sizeLocal + unit }" />
34
+ <!-- #endif -->
35
+
36
+ <!-- #ifdef APP-NVUE -->
37
+ <gcanvas class="u-qrcode__canvas" ref="gcanvess"
38
+ :style="{ width: sizeLocal + unit, height: sizeLocal + unit }">
39
+ </gcanvas>
40
+ <!-- #endif -->
41
+ <view v-if="showLoading && loading" class="u-qrcode__loading"
42
+ :style="{ width: sizeLocal + unit, height: sizeLocal + unit }">
43
+ <up-loading-icon vertical :text="loadingText" textSize="14px"></up-loading-icon>
44
+ </view>
45
+ </view>
46
+
47
+ </view>
30
48
  </template>
31
49
 
32
50
  <script>
@@ -34,215 +52,215 @@ import QRCode from "./qrcode.js"
34
52
  // #ifdef APP-NVUE
35
53
  // https://github.com/dcloudio/NvueCanvasDemo/blob/master/README.md
36
54
  import {
37
- enable,
38
- WeexBridge
55
+ enable,
56
+ WeexBridge
39
57
  } from '../../libs/util/gcanvas/index.js';
40
58
  // #endif
41
59
  let qrcode
42
60
  export default {
43
- name: "u-qrcode",
44
- props: {
45
- cid: {
46
- type: String,
47
- default: 'u-qrcode-canvas' + Math.random().toString()
48
- },
49
- size: {
50
- type: Number,
51
- default: 200
52
- },
53
- unit: {
54
- type: String,
55
- default: 'px'
56
- },
57
- show: {
58
- type: Boolean,
59
- default: true
60
- },
61
- val: {
62
- type: String,
63
- default: ''
64
- },
65
- background: {
66
- type: String,
67
- default: '#ffffff'
68
- },
69
- foreground: {
70
- type: String,
71
- default: '#000000'
72
- },
73
- pdground: {
74
- type: String,
75
- default: '#000000'
76
- },
77
- icon: {
78
- type: String,
79
- default: ''
80
- },
81
- iconSize: {
82
- type: Number,
83
- default: 40
84
- },
85
- lv: {
86
- type: Number,
87
- default: 3
88
- },
89
- onval: {
90
- type: Boolean,
91
- default: true
92
- },
93
- loadMake: {
94
- type: Boolean,
95
- default: true
96
- },
97
- usingComponents: {
98
- type: Boolean,
99
- default: true
100
- },
101
- showLoading: {
102
- type: Boolean,
103
- default: true
104
- },
105
- loadingText: {
106
- type: String,
107
- default: '生成中'
108
- },
109
- allowPreview: {
110
- type: Boolean,
111
- default: false
112
- },
61
+ name: "u-qrcode",
62
+ props: {
63
+ cid: {
64
+ type: String,
65
+ default: () => `u-qrcode-canvas${Math.floor(Math.random() * 1000000)}`
66
+ },
67
+ size: {
68
+ type: Number,
69
+ default: 200
70
+ },
71
+ unit: {
72
+ type: String,
73
+ default: 'px'
74
+ },
75
+ show: {
76
+ type: Boolean,
77
+ default: true
78
+ },
79
+ val: {
80
+ type: String,
81
+ default: ''
82
+ },
83
+ background: {
84
+ type: String,
85
+ default: '#ffffff'
86
+ },
87
+ foreground: {
88
+ type: String,
89
+ default: '#000000'
90
+ },
91
+ pdground: {
92
+ type: String,
93
+ default: '#000000'
94
+ },
95
+ icon: {
96
+ type: String,
97
+ default: ''
98
+ },
99
+ iconSize: {
100
+ type: Number,
101
+ default: 40
102
+ },
103
+ lv: {
104
+ type: Number,
105
+ default: 3
106
+ },
107
+ onval: {
108
+ type: Boolean,
109
+ default: true
110
+ },
111
+ loadMake: {
112
+ type: Boolean,
113
+ default: true
114
+ },
115
+ usingComponents: {
116
+ type: Boolean,
117
+ default: true
118
+ },
119
+ showLoading: {
120
+ type: Boolean,
121
+ default: true
122
+ },
123
+ loadingText: {
124
+ type: String,
125
+ default: '生成中'
126
+ },
127
+ allowPreview: {
128
+ type: Boolean,
129
+ default: false
130
+ },
113
131
  // 是否使用根节点宽高
114
132
  useRootHeightAndWidth: {
115
133
  type: Boolean,
116
134
  default: () => false
117
135
  },
118
- },
119
- emits: ['result', 'longpressCallback'],
120
- data() {
121
- return {
122
- loading: false,
123
- result: '',
124
- popupShow: false,
125
- list: [
126
- {
127
- name: '保存二维码',
128
- }
129
- ],
136
+ },
137
+ emits: ['result', 'longpressCallback'],
138
+ data() {
139
+ return {
140
+ loading: false,
141
+ result: '',
142
+ popupShow: false,
143
+ list: [
144
+ {
145
+ name: '保存二维码',
146
+ }
147
+ ],
130
148
  rootId: `rootId${Number(Math.random() * 100).toFixed(0)}`,
131
- ganvas: null,
132
- context: '',
133
- canvasObj: {},
149
+ ganvas: null,
150
+ context: '',
151
+ canvasObj: {},
134
152
  sizeLocal: this.size,
135
153
  ctx: null, // ctx 在new Qrcode 时js文件内部设置
136
154
  canvas: null, // ctx 在new Qrcode 时js文件内部设置
137
- }
138
- },
155
+ }
156
+ },
139
157
  async mounted(){
140
158
  // 如果使用根节点的宽高 则 重新设置 size
141
159
  if(this.useRootHeightAndWidth){
142
160
  await this.setNewSize()
143
161
  }
144
162
 
145
- // #ifdef APP-NVUE
146
- /*获取元素引用*/
147
- this.ganvas = this.$refs["gcanvess"]
148
- /*通过元素引用获取canvas对象*/
149
- this.canvasObj = enable(this.ganvas, {
150
- bridge: WeexBridge
151
- })
152
- /*获取绘图所需的上下文,目前不支持3d*/
153
- this.context = this.canvasObj.getContext('2d')
154
- // #endif
163
+ // #ifdef APP-NVUE
164
+ /*获取元素引用*/
165
+ this.ganvas = this.$refs["gcanvess"]
166
+ /*通过元素引用获取canvas对象*/
167
+ this.canvasObj = enable(this.ganvas, {
168
+ bridge: WeexBridge
169
+ })
170
+ /*获取绘图所需的上下文,目前不支持3d*/
171
+ this.context = this.canvasObj.getContext('2d')
172
+ // #endif
155
173
 
156
- if (this.loadMake) {
157
- if (!this._empty(this.val)) {
158
- setTimeout(() => {
174
+ if (this.loadMake) {
175
+ if (!this._empty(this.val)) {
176
+ setTimeout(() => {
159
177
  setTimeout(()=>{
160
178
  this._makeCode()
161
179
  })
162
- }, 0);
163
- }
164
- }
165
- },
166
- methods: {
167
- _makeCode() {
168
- let that = this
169
- if (!this._empty(this.val)) {
170
- // #ifndef APP-NVUE
171
- this.loading = true
172
- // #endif
173
- qrcode = new QRCode({
174
- context: that, // 上下文环境
175
- canvasId: that.cid, // canvas-id
176
- nvueContext: that.context,
177
- usingComponents: that.usingComponents, // 是否是自定义组件
178
- showLoading: false, // 是否显示loading
179
- loadingText: that.loadingText, // loading文字
180
- text: that.val, // 生成内容
181
- size: that.sizeLocal, // 二维码大小
182
- background: that.background, // 背景色
183
- foreground: that.foreground, // 前景色
184
- pdground: that.pdground, // 定位角点颜色
185
- correctLevel: that.lv, // 容错级别
186
- image: that.icon, // 二维码图标
187
- imageSize: that.iconSize,// 二维码图标大小
188
- cbResult: function (res) { // 生成二维码的回调
189
- that._result(res)
190
- },
191
- });
192
- } else {
193
- uni.showToast({
194
- title: '二维码内容不能为空',
195
- icon: 'none',
196
- duration: 2000
197
- });
198
- }
199
- },
200
- _clearCode() {
201
- this._result('')
202
- qrcode.clear()
203
- },
204
- _saveCode() {
205
- let that = this;
206
- if (this.result != "") {
207
- uni.saveImageToPhotosAlbum({
208
- filePath: that.result,
209
- success: function () {
210
- uni.showToast({
211
- title: '二维码保存成功',
212
- icon: 'success',
213
- duration: 2000
214
- });
215
- }
216
- });
217
- }
218
- },
219
- preview(e) {
220
- // 预览图片
221
- // console.log(this.result)
222
- if (this.allowPreview) {
223
- uni.previewImage({
224
- urls: [this.result],
225
- longPressActions: {
226
- itemList: ['保存二维码图片'],
227
- success: function(data) {
228
- // console.log('选中了第' + (data.tapIndex + 1) + '个按钮,第' + (data.index + 1) + '张图片');
229
- switch (data.tapIndex) {
230
- case 0:
231
- that._saveCode();
232
- break;
233
- }
234
- },
235
- fail: function(err) {
236
- console.log(err.errMsg);
237
- }
238
- }
239
- });
240
- }
241
- this.$emit('preview', {
242
- url: this.result
243
- }, e)
244
- },
245
- async longpress() {
180
+ }, 0);
181
+ }
182
+ }
183
+ },
184
+ methods: {
185
+ _makeCode() {
186
+ let that = this
187
+ if (!this._empty(this.val)) {
188
+ // #ifndef APP-NVUE
189
+ this.loading = true
190
+ // #endif
191
+ qrcode = new QRCode({
192
+ context: that, // 上下文环境
193
+ canvasId: that.cid, // canvas-id
194
+ nvueContext: that.context,
195
+ usingComponents: that.usingComponents, // 是否是自定义组件
196
+ showLoading: false, // 是否显示loading
197
+ loadingText: that.loadingText, // loading文字
198
+ text: that.val, // 生成内容
199
+ size: that.sizeLocal, // 二维码大小
200
+ background: that.background, // 背景色
201
+ foreground: that.foreground, // 前景色
202
+ pdground: that.pdground, // 定位角点颜色
203
+ correctLevel: that.lv, // 容错级别
204
+ image: that.icon, // 二维码图标
205
+ imageSize: that.iconSize,// 二维码图标大小
206
+ cbResult: function (res) { // 生成二维码的回调
207
+ that._result(res)
208
+ },
209
+ });
210
+ } else {
211
+ uni.showToast({
212
+ title: '二维码内容不能为空',
213
+ icon: 'none',
214
+ duration: 2000
215
+ });
216
+ }
217
+ },
218
+ _clearCode() {
219
+ this._result('')
220
+ qrcode.clear()
221
+ },
222
+ _saveCode() {
223
+ let that = this;
224
+ if (this.result != "") {
225
+ uni.saveImageToPhotosAlbum({
226
+ filePath: that.result,
227
+ success: function () {
228
+ uni.showToast({
229
+ title: '二维码保存成功',
230
+ icon: 'success',
231
+ duration: 2000
232
+ });
233
+ }
234
+ });
235
+ }
236
+ },
237
+ preview(e) {
238
+ // 预览图片
239
+ // console.log(this.result)
240
+ if (this.allowPreview) {
241
+ uni.previewImage({
242
+ urls: [this.result],
243
+ longPressActions: {
244
+ itemList: ['保存二维码图片'],
245
+ success: function(data) {
246
+ // console.log('选中了第' + (data.tapIndex + 1) + '个按钮,第' + (data.index + 1) + '张图片');
247
+ switch (data.tapIndex) {
248
+ case 0:
249
+ that._saveCode();
250
+ break;
251
+ }
252
+ },
253
+ fail: function(err) {
254
+ console.log(err.errMsg);
255
+ }
256
+ }
257
+ });
258
+ }
259
+ this.$emit('preview', {
260
+ url: this.result
261
+ }, e)
262
+ },
263
+ async longpress() {
246
264
  if (this.context) {
247
265
  this.ctx.toTempFilePath(
248
266
  0,
@@ -259,17 +277,30 @@ export default {
259
277
  );
260
278
  }
261
279
  else {
262
- const canvas = await this.getNode(this.cId,true);
280
+
263
281
  // #ifdef MP-TOUTIAO || H5
264
282
  this.$emit('longpressCallback', this.ctx.canvas.toDataURL("image/png", 1));
265
283
  // #endif
266
284
 
267
- // #ifndef MP-TOUTIAO || H5
285
+ // #ifdef APP-PLUS
286
+ uni.canvasToTempFilePath(
287
+ {
288
+ canvasId: this.cid,
289
+ success :res => {
290
+ this.$emit('longpressCallback', res.tempFilePath)
291
+ },
292
+ fail: err =>{
293
+ }
294
+ },
295
+ this)
296
+ // #endif
297
+
298
+ // #ifndef MP-TOUTIAO || H5 || APP-PLUS
299
+ const canvas = await this.getNode(this.cId,true);
268
300
  uni.canvasToTempFilePath(
269
301
  {
270
302
  canvas,
271
303
  success :res => {
272
- console.log(res.tempFilePath)
273
304
  this.$emit('longpressCallback', res.tempFilePath)
274
305
  },
275
306
  fail: err =>{
@@ -280,7 +311,7 @@ export default {
280
311
 
281
312
  }
282
313
 
283
- },
314
+ },
284
315
 
285
316
  /**
286
317
  * 使用根节点宽高 设置新的size
@@ -326,74 +357,74 @@ export default {
326
357
  })
327
358
  },
328
359
 
329
- selectClick(index) {
330
- switch (index) {
331
- case 0:
332
- alert('保存二维码')
333
- this._saveCode();
334
- break;
335
- }
336
- },
337
- _result(res) {
338
- this.loading = false;
339
- this.result = res;
340
- this.$emit('result', res);
341
- },
342
- _empty(v) {
343
- let tp = typeof v,
344
- rt = false;
345
- if (tp == "number" && String(v) == "") {
346
- rt = true
347
- } else if (tp == "undefined") {
348
- rt = true
349
- } else if (tp == "object") {
350
- if (JSON.stringify(v) == "{}" || JSON.stringify(v) == "[]" || v == null) rt = true
351
- } else if (tp == "string") {
352
- if (v == "" || v == "undefined" || v == "null" || v == "{}" || v == "[]") rt = true
353
- } else if (tp == "function") {
354
- rt = false
355
- }
356
- return rt
357
- },
358
- },
359
- watch: {
360
- size: function (n, o) {
361
- if (n != o && !this._empty(n)) {
362
- this.cSize = n
363
- if (!this._empty(this.val)) {
364
- setTimeout(() => {
365
- this._makeCode()
366
- }, 100);
367
- }
368
- }
369
- },
370
- val: function (n, o) {
371
- if (this.onval) {
372
- if (n != o && !this._empty(n)) {
373
- setTimeout(() => {
374
- this._makeCode()
375
- }, 0);
376
- }
377
- }
378
- }
379
- },
380
- computed: {
381
- }
360
+ selectClick(index) {
361
+ switch (index) {
362
+ case 0:
363
+ alert('保存二维码')
364
+ this._saveCode();
365
+ break;
366
+ }
367
+ },
368
+ _result(res) {
369
+ this.loading = false;
370
+ this.result = res;
371
+ this.$emit('result', res);
372
+ },
373
+ _empty(v) {
374
+ let tp = typeof v,
375
+ rt = false;
376
+ if (tp == "number" && String(v) == "") {
377
+ rt = true
378
+ } else if (tp == "undefined") {
379
+ rt = true
380
+ } else if (tp == "object") {
381
+ if (JSON.stringify(v) == "{}" || JSON.stringify(v) == "[]" || v == null) rt = true
382
+ } else if (tp == "string") {
383
+ if (v == "" || v == "undefined" || v == "null" || v == "{}" || v == "[]") rt = true
384
+ } else if (tp == "function") {
385
+ rt = false
386
+ }
387
+ return rt
388
+ },
389
+ },
390
+ watch: {
391
+ size: function (n, o) {
392
+ if (n != o && !this._empty(n)) {
393
+ this.cSize = n
394
+ if (!this._empty(this.val)) {
395
+ setTimeout(() => {
396
+ this._makeCode()
397
+ }, 100);
398
+ }
399
+ }
400
+ },
401
+ val: function (n, o) {
402
+ if (this.onval) {
403
+ if (n != o && !this._empty(n)) {
404
+ setTimeout(() => {
405
+ this._makeCode()
406
+ }, 0);
407
+ }
408
+ }
409
+ }
410
+ },
411
+ computed: {
412
+ }
382
413
  }
383
414
  </script>
384
415
  <style lang="scss" scoped>
385
416
  .u-qrcode {
386
- &__loading {
387
- display: flex;
388
- justify-content: center;
389
- align-items: center;
390
- background-color: #f7f7f7;
391
- position: absolute;
392
- top: 0;
393
- bottom: 0;
394
- left: 0;
395
- right: 0;
396
- }
417
+ &__loading {
418
+ display: flex;
419
+ justify-content: center;
420
+ align-items: center;
421
+ background-color: #f7f7f7;
422
+ position: absolute;
423
+ top: 0;
424
+ bottom: 0;
425
+ left: 0;
426
+ right: 0;
427
+ }
397
428
 
398
429
  /* #ifdef MP-TOUTIAO */
399
430
  /**字节小程序在编译时会出现一个 [hidde]:{ display: none !important; } 这个样式
@@ -404,15 +435,15 @@ export default {
404
435
  }
405
436
  /* #endif */
406
437
 
407
- &__content {
408
- position: relative;
438
+ &__content {
439
+ position: relative;
409
440
 
410
- &__canvas {
411
- position: fixed;
412
- top: -99999rpx;
413
- left: -99999rpx;
414
- z-index: -99999;
415
- }
416
- }
441
+ &__canvas {
442
+ position: fixed;
443
+ top: -99999rpx;
444
+ left: -99999rpx;
445
+ z-index: -99999;
446
+ }
447
+ }
417
448
  }
418
449
  </style>
@@ -10,8 +10,10 @@
10
10
  headerCellClassName ? headerCellClassName(col) : '',
11
11
  col.fixed === 'left' ? 'u-table-fixed-left' : '',
12
12
  col.fixed === 'right' ? 'u-table-fixed-right' : ''
13
- ]" @click="handleHeaderClick(col)">
14
- {{ col.title }}
13
+ ]" @click="handleHeaderClick(col)">
14
+ <slot name="header" :column="col" :columnIndex="colIndex" :level="1">
15
+ {{ col.title }}
16
+ </slot>
15
17
  <view v-if="col.sortable">
16
18
  {{ getSortIcon(col.key) }}
17
19
  </view>
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "id": "uview-plus",
3
3
  "name": "uview-plus",
4
4
  "displayName": "零云®uview-plus3.0重磅发布,全面的Vue3鸿蒙移动组件库。",
5
- "version": "3.4.41",
5
+ "version": "3.4.43",
6
6
  "description": "零云®uview-plus已兼容vue3,全面的组件和便捷的工具会让您信手拈来,如鱼得水。",
7
7
  "keywords": [
8
8
  "uview",