uview-plus 3.5.5 → 3.5.15

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.
@@ -0,0 +1,622 @@
1
+ <template>
2
+ <view class="up-poster">
3
+ <!-- canvas用于绘制海报 -->
4
+ <canvas
5
+ v-if="showCanvas"
6
+ class="up-poster__hidden-canvas"
7
+ :canvas-id="canvasId"
8
+ :id="canvasId"
9
+ :style="{ width: canvasWidth + 'px', height: canvasHeight + 'px' }">
10
+ </canvas>
11
+ <!-- 隐藏的二维码组件,用于生成二维码图片 -->
12
+ <up-qrcode
13
+ ref="qrCode"
14
+ :val="qrCodeValue"
15
+ :size="qrCodeSize"
16
+ :margin="0"
17
+ :loadMake="false"
18
+ background="#ffffff"
19
+ foreground="#000000"
20
+ :class="['up-poster__hidden-qrcode', qrCodeShow ? '' : 'up-poster__hidden-qrcode--hidden']"
21
+ />
22
+ </view>
23
+ </template>
24
+
25
+ <script>
26
+ /**
27
+ * Poster 海报组件
28
+ * @description 用于生成海报的组件,支持文本、图片、二维码等元素
29
+ * @tutorial https://ijry.github.io/uview-plus/components/poster.html
30
+ *
31
+ * @property {Object} json 海报配置JSON数据
32
+ * @property {Object} json.css 海报容器样式
33
+ * @property {Array} json.views 海报元素列表
34
+ * @property {String} json.views.type 元素类型(text/image/qrcode/view)
35
+ * @property {String} json.views.text 文本内容(仅text类型)
36
+ * @property {String} json.views.src 图片地址(仅image/qrcode类型)
37
+ * @property {Object} json.views.css 元素样式
38
+ *
39
+ * @example <up-poster :json="posterJson"></up-poster>
40
+ */
41
+ export default {
42
+ name: 'up-poster',
43
+ props: {
44
+ json: {
45
+ type: Object,
46
+ default: () => ({})
47
+ }
48
+ },
49
+ data() {
50
+ return {
51
+ canvasId: 'u-poster-canvas-' + Date.now(),
52
+ showCanvas: false,
53
+ canvasWidth: 0,
54
+ canvasHeight: 0,
55
+ // 二维码相关数据
56
+ qrCodeValue: '',
57
+ qrCodeSize: 200,
58
+ qrCodeShow: false,
59
+ // 存储多个二维码的数据
60
+ qrCodeMap: new Map()
61
+ }
62
+ },
63
+ computed: {
64
+ // 根据传入的css生成文本样式
65
+ getTextStyle() {
66
+ return (css) => {
67
+ const style = {};
68
+ if (css.color) style.color = css.color;
69
+ if (css.fontSize) style.fontSize = css.fontSize;
70
+ if (css.fontWeight) style.fontWeight = css.fontWeight;
71
+ if (css.lineHeight) style.lineHeight = css.lineHeight;
72
+ if (css.textAlign) style.textAlign = css.textAlign;
73
+ return style;
74
+ }
75
+ }
76
+ },
77
+ methods: {
78
+ /**
79
+ * 导出海报图片
80
+ * @description 根据json配置生成海报并导出为临时图片路径
81
+ * @returns {Promise<Object>} 返回包含图片信息的对象
82
+ * @author jry ijry@qq.com
83
+ */
84
+ async exportImage() {
85
+ return new Promise(async(resolve, reject) => {
86
+ try {
87
+ // 获取海报尺寸信息
88
+ const posterSize = this.json.css;
89
+ // 将rpx转换为px
90
+ const width = this.convertRpxToPx(posterSize.width || '750rpx');
91
+ const height = this.convertRpxToPx(posterSize.height || '1114rpx');
92
+
93
+ // 设置canvas尺寸
94
+ this.canvasWidth = width;
95
+ this.canvasHeight = height;
96
+ this.showCanvas = true;
97
+
98
+ // 等待DOM更新
99
+ await this.$nextTick();
100
+
101
+ // 创建canvas上下文
102
+ const ctx = uni.createCanvasContext(this.canvasId, this);
103
+
104
+ // 绘制背景
105
+ if (posterSize.background) {
106
+ // 支持渐变背景色
107
+ if (posterSize.background.includes('linear-gradient') || posterSize.background.includes('radial-gradient')) {
108
+ this.drawGradientBackground(ctx, posterSize, 0, 0, width, height);
109
+ } else {
110
+ ctx.setFillStyle(posterSize.background);
111
+ ctx.fillRect(0, 0, width, height);
112
+ }
113
+ }
114
+
115
+ // 绘制所有元素
116
+ for (const item of this.json.views) {
117
+ await this.drawItem(ctx, item, width, height);
118
+ }
119
+
120
+ // 绘制到canvas
121
+ ctx.draw(false, () => {
122
+ // 等待绘制完成
123
+ setTimeout(() => {
124
+ // 导出图片
125
+ uni.canvasToTempFilePath({
126
+ canvasId: this.canvasId,
127
+ success: (res) => {
128
+ // 隐藏canvas
129
+ this.showCanvas = false;
130
+ // 返回图片路径
131
+ resolve({
132
+ width: width,
133
+ height: height,
134
+ path: res.tempFilePath,
135
+ // H5下添加blob格式
136
+ blob: this.dataURLToBlob(res.tempFilePath)
137
+ });
138
+ },
139
+ fail: (err) => {
140
+ // 隐藏canvas
141
+ this.showCanvas = false;
142
+ reject(new Error('导出图片失败: ' + JSON.stringify(err)));
143
+ }
144
+ }, this);
145
+ }, 300);
146
+ });
147
+
148
+ // 超时处理
149
+ setTimeout(() => {
150
+ this.showCanvas = false;
151
+ reject(new Error('导出图片超时'));
152
+ }, 10000);
153
+ } catch (error) {
154
+ this.showCanvas = false;
155
+ reject(error);
156
+ }
157
+ });
158
+ },
159
+
160
+ /**
161
+ * 绘制单个元素
162
+ * @description 根据元素类型绘制文本、图片、矩形或二维码到canvas
163
+ * @param {Object} ctx canvas上下文
164
+ * @param {Object} item 元素配置信息
165
+ * @param {Number} canvasWidth canvas宽度
166
+ * @param {Number} canvasHeight canvas高度
167
+ * @returns {Promise} 绘制完成的Promise
168
+ * @author jry ijry@qq.com
169
+ */
170
+ async drawItem(ctx, item, canvasWidth, canvasHeight) {
171
+ const css = item.css || {};
172
+ const left = this.convertRpxToPx(css.left || '0rpx');
173
+ const top = this.convertRpxToPx(css.top || '0rpx');
174
+ const width = this.convertRpxToPx(css.width || '0rpx');
175
+ const height = this.convertRpxToPx(css.height || '0rpx');
176
+
177
+ switch (item.type) {
178
+ case 'view':
179
+ // 绘制矩形背景
180
+ if (css.background) {
181
+ // 支持渐变背景色
182
+ if (css.background.includes('linear-gradient') || css.background.includes('radial-gradient')) {
183
+ this.drawGradientBackground(ctx, css, left, top, width, height);
184
+ } else {
185
+ ctx.setFillStyle(css.background);
186
+ // 处理圆角
187
+ if (css.radius) {
188
+ const radius = this.convertRpxToPx(css.radius);
189
+ this.drawRoundRect(ctx, left, top, width, height, radius, css.background);
190
+ } else {
191
+ ctx.fillRect(left, top, width, height);
192
+ }
193
+ }
194
+ }
195
+ break;
196
+
197
+ case 'text':
198
+ // 设置文本样式
199
+ if (css.color) ctx.setFillStyle(css.color);
200
+ if (css.fontSize) {
201
+ const fontSize = this.convertRpxToPx(css.fontSize);
202
+ ctx.setFontSize(fontSize);
203
+ }
204
+ if (css.fontWeight) {
205
+ ctx.setLineWidth(css.fontWeight === 'bold' ? 2 : 1);
206
+ }
207
+
208
+ // 处理文本换行
209
+ if (css.lineClamp) {
210
+ this.drawTextWithLineClamp(ctx, item.text, left, top, width, css);
211
+ } else {
212
+ // 修复:文本垂直居中对齐问题
213
+ const textBaseLine = css.fontSize ? this.convertRpxToPx(css.fontSize) / 2 : 10;
214
+ ctx.fillText(item.text, left, top + textBaseLine);
215
+ }
216
+ break;
217
+
218
+ case 'image':
219
+ // 绘制图片
220
+ return new Promise((resolve) => {
221
+ uni.getImageInfo({
222
+ src: item.src,
223
+ success: (res) => {
224
+ // 处理圆角
225
+ if (css.radius) {
226
+ const radius = this.convertRpxToPx(css.radius);
227
+ this.clipRoundRect(ctx, left, top, width, height, radius);
228
+ }
229
+ ctx.drawImage(item.src, left, top, width, height);
230
+ // 恢复剪切区域
231
+ ctx.restore();
232
+ resolve();
233
+ },
234
+ fail: () => {
235
+ // 图片加载失败时绘制占位符
236
+ ctx.setFillStyle('#f5f5f5');
237
+ ctx.fillRect(left, top, width, height);
238
+ resolve();
239
+ }
240
+ });
241
+ });
242
+
243
+ case 'qrcode':
244
+ // 绘制二维码
245
+ if (item.text) {
246
+ // 使用u-qrcode生成二维码图片
247
+ const qrCodeImageUrl = await this.generateQRCode(item.text, width, height);
248
+ return new Promise((resolve) => {
249
+ uni.getImageInfo({
250
+ src: qrCodeImageUrl,
251
+ success: (res) => {
252
+ ctx.drawImage(res.path, left, top, width, height);
253
+ resolve();
254
+ },
255
+ fail: () => {
256
+ // 二维码加载失败时绘制占位符
257
+ ctx.setFillStyle('#f5f5f5');
258
+ ctx.fillRect(left, top, width, height);
259
+ ctx.setFillStyle('#999');
260
+ ctx.setFontSize(12);
261
+ ctx.setTextAlign('center');
262
+ ctx.fillText('QR', left + width/2, top + height/2);
263
+ ctx.setTextAlign('left');
264
+ resolve();
265
+ }
266
+ });
267
+ });
268
+ } else {
269
+ // 绘制二维码占位符
270
+ ctx.setFillStyle('#f5f5f5');
271
+ ctx.fillRect(left, top, width, height);
272
+ ctx.setFillStyle('#999');
273
+ ctx.setFontSize(12);
274
+ ctx.setTextAlign('center');
275
+ ctx.fillText('QR', left + width/2, top + height/2);
276
+ ctx.setTextAlign('left');
277
+ }
278
+ break;
279
+ }
280
+ },
281
+
282
+ /**
283
+ * 绘制圆角矩形
284
+ * @description 绘制指定位置和尺寸的圆角矩形
285
+ * @param {Object} ctx canvas上下文
286
+ * @param {Number} x x坐标
287
+ * @param {Number} y y坐标
288
+ * @param {Number} width 宽度
289
+ * @param {Number} height 高度
290
+ * @param {Number} radius 圆角半径
291
+ * @param {String} fillColor 填充颜色
292
+ * @author jry ijry@qq.com
293
+ */
294
+ drawRoundRect(ctx, x, y, width, height, radius, fillColor) {
295
+ ctx.save();
296
+ ctx.beginPath();
297
+ ctx.moveTo(x + radius, y);
298
+ ctx.lineTo(x + width - radius, y);
299
+ ctx.quadraticCurveTo(x + width, y, x + width, y + radius);
300
+ ctx.lineTo(x + width, y + height - radius);
301
+ ctx.quadraticCurveTo(x + width, y + height, x + width - radius, y + height);
302
+ ctx.lineTo(x + radius, y + height);
303
+ ctx.quadraticCurveTo(x, y + height, x, y + height - radius);
304
+ ctx.lineTo(x, y + radius);
305
+ ctx.quadraticCurveTo(x, y, x + radius, y);
306
+ ctx.closePath();
307
+ if (fillColor) {
308
+ ctx.setFillStyle(fillColor);
309
+ ctx.fill();
310
+ }
311
+ ctx.restore();
312
+ },
313
+
314
+ /**
315
+ * 裁剪圆角矩形区域
316
+ * @description 在canvas上创建圆角矩形裁剪区域
317
+ * @param {Object} ctx canvas上下文
318
+ * @param {Number} x x坐标
319
+ * @param {Number} y y坐标
320
+ * @param {Number} width 宽度
321
+ * @param {Number} height 高度
322
+ * @param {Number} radius 圆角半径
323
+ * @author jry ijry@qq.com
324
+ */
325
+ clipRoundRect(ctx, x, y, width, height, radius) {
326
+ ctx.save();
327
+ ctx.beginPath();
328
+ ctx.arc(x + radius, y + radius, radius, Math.PI, Math.PI * 1.5);
329
+ ctx.lineTo(x + width - radius, y);
330
+ ctx.arc(x + width - radius, y + radius, radius, Math.PI * 1.5, Math.PI * 2);
331
+ ctx.lineTo(x + width, y + height - radius);
332
+ ctx.arc(x + width - radius, y + height - radius, radius, 0, Math.PI * 0.5);
333
+ ctx.lineTo(x + radius, y + height);
334
+ ctx.arc(x + radius, y + height - radius, radius, Math.PI * 0.5, Math.PI);
335
+ ctx.closePath();
336
+ ctx.clip();
337
+ },
338
+
339
+ /**
340
+ * 绘制带行数限制的文本
341
+ * @description 绘制可控制最大行数的文本,超出部分显示省略号
342
+ * @param {Object} ctx canvas上下文
343
+ * @param {String} text 文本内容
344
+ * @param {Number} x x坐标
345
+ * @param {Number} y y坐标
346
+ * @param {Number} maxWidth 最大宽度
347
+ * @param {Object} css 样式配置
348
+ * @author jry ijry@qq.com
349
+ */
350
+ drawTextWithLineClamp(ctx, text, x, y, maxWidth, css) {
351
+ const lineClamp = parseInt(css.lineClamp) || 1;
352
+ const lineHeight = css.lineHeight ? this.convertRpxToPx(css.lineHeight) : 20;
353
+ const lines = [];
354
+ let currentLine = '';
355
+
356
+ for (let i = 0; i < text.length; i++) {
357
+ const char = text[i];
358
+ const testLine = currentLine + char;
359
+ const metrics = ctx.measureText(testLine);
360
+
361
+ if (metrics.width > maxWidth && currentLine !== '') {
362
+ lines.push(currentLine);
363
+ currentLine = char;
364
+
365
+ // 如果已达最大行数,添加省略号并结束
366
+ if (lines.length === lineClamp) {
367
+ if (metrics.width > maxWidth) {
368
+ // 添加省略号
369
+ let fitLine = currentLine.substring(0, currentLine.length - 1);
370
+ while (ctx.measureText(fitLine + '...').width > maxWidth && fitLine.length > 0) {
371
+ fitLine = fitLine.substring(0, fitLine.length - 1);
372
+ }
373
+ lines[lines.length - 1] = fitLine + '...';
374
+ }
375
+ break;
376
+ }
377
+ } else {
378
+ currentLine = testLine;
379
+ }
380
+
381
+ // 处理最后一行
382
+ if (i === text.length - 1 && lines.length < lineClamp) {
383
+ lines.push(currentLine);
384
+ }
385
+ }
386
+
387
+ // 绘制每一行
388
+ for (let i = 0; i < lines.length; i++) {
389
+ // 修复:正确计算文本垂直位置
390
+ const textBaseLine = css.fontSize ? this.convertRpxToPx(css.fontSize) / 2 : 10;
391
+ ctx.fillText(lines[i], x, y + (i * lineHeight) + textBaseLine);
392
+ }
393
+ },
394
+
395
+ /**
396
+ * 生成二维码图片
397
+ * @description 根据文本内容生成二维码图片URL
398
+ * @param {String} text 二维码内容
399
+ * @param {Number} width 二维码宽度
400
+ * @param {Number} height 二维码高度
401
+ * @returns {Promise<String>} 二维码图片URL
402
+ * @author jry ijry@qq.com
403
+ */
404
+ generateQRCode(text, width, height) {
405
+ return new Promise((resolve) => {
406
+ // 为每个二维码生成唯一标识
407
+ const qrCodeKey = `${text}_${width}_${height}`;
408
+
409
+ // 检查是否已经生成过该二维码
410
+ if (this.qrCodeMap.has(qrCodeKey)) {
411
+ resolve(this.qrCodeMap.get(qrCodeKey));
412
+ return;
413
+ }
414
+
415
+ // 使用 u-qrcode 组件生成二维码
416
+ try {
417
+ // 设置二维码参数
418
+ this.qrCodeValue = text;
419
+ this.qrCodeSize = Math.max(width, height);
420
+ this.qrCodeShow = true;
421
+
422
+ // 等待DOM更新
423
+ this.$nextTick(() => {
424
+ // 获取二维码组件实例并导出图片
425
+ if (this.$refs.qrCode) {
426
+ // 延迟一点时间确保二维码渲染完成
427
+ setTimeout(() => {
428
+ // 调用 u-qrcode 的 toTempFilePath 方法导出图片
429
+ this.$refs.qrCode.toTempFilePath({
430
+ success: (res) => {
431
+ // 缓存二维码图片路径
432
+ this.qrCodeMap.set(qrCodeKey, res.tempFilePath);
433
+ this.qrCodeShow = false;
434
+ resolve(res.tempFilePath);
435
+ },
436
+ fail: (err) => {
437
+ console.error('二维码生成失败:', err);
438
+ this.qrCodeShow = false;
439
+ }
440
+ });
441
+ }, 300);
442
+ } else {
443
+ // 如果没有 u-qrcode 组件,返回占位符
444
+ this.qrCodeShow = false;
445
+ }
446
+ });
447
+ } catch (error) {
448
+ console.error('生成二维码出错:', error);
449
+ this.qrCodeShow = false;
450
+ }
451
+ });
452
+ },
453
+
454
+ /**
455
+ * 将rpx单位转换为px
456
+ * @description 根据屏幕密度将rpx单位转换为px单位
457
+ * @param {String|Number} rpxValue rpx值
458
+ * @returns {Number} 转换后的px值
459
+ * @author jry ijry@qq.com
460
+ */
461
+ convertRpxToPx(rpxValue) {
462
+ if (typeof rpxValue === 'number') return rpxValue;
463
+
464
+ // 使用uni-app自带的uni.rpx2px方法
465
+ if (typeof rpxValue === 'string' && rpxValue.endsWith('rpx')) {
466
+ const value = parseFloat(rpxValue);
467
+ return uni.rpx2px(value);
468
+ }
469
+
470
+ return parseFloat(rpxValue) || 0;
471
+ },
472
+
473
+ /**
474
+ * 绘制渐变背景
475
+ * @description 绘制线性渐变或径向渐变背景
476
+ * @param {Object} ctx canvas上下文
477
+ * @param {Object} css 样式配置
478
+ * @param {Number} left 左边距
479
+ * @param {Number} top 上边距
480
+ * @param {Number} width 宽度
481
+ * @param {Number} height 高度
482
+ * @author jry ijry@qq.com
483
+ */
484
+ drawGradientBackground(ctx, css, left, top, width, height) {
485
+ const background = css.background;
486
+ let gradient = null;
487
+
488
+ // 处理线性渐变
489
+ if (background.includes('linear-gradient')) {
490
+ // 解析线性渐变角度和颜色
491
+ const angleMatch = background.match(/linear-gradient\((\d+)deg/);
492
+ const angle = angleMatch ? parseInt(angleMatch[1]) : 135;
493
+
494
+ // 根据角度计算渐变起点和终点
495
+ let startX = left, startY = top, endX = left + width, endY = top + height;
496
+
497
+ // 简化的角度处理(支持常见角度)
498
+ if (angle === 0) {
499
+ startX = left;
500
+ startY = top + height;
501
+ endX = left;
502
+ endY = top;
503
+ } else if (angle === 90) {
504
+ startX = left;
505
+ startY = top;
506
+ endX = left + width;
507
+ endY = top;
508
+ } else if (angle === 180) {
509
+ startX = left;
510
+ startY = top;
511
+ endX = left;
512
+ endY = top + height;
513
+ } else if (angle === 270) {
514
+ startX = left + width;
515
+ startY = top;
516
+ endX = left;
517
+ endY = top;
518
+ }
519
+
520
+ gradient = ctx.createLinearGradient(startX, startY, endX, endY);
521
+
522
+ // 解析颜色值
523
+ const colorMatches = background.match(/#[0-9a-fA-F]+|rgba?\([^)]+\)/g);
524
+ if (colorMatches && colorMatches.length >= 2) {
525
+ // 添加渐变色点
526
+ colorMatches.forEach((color, index) => {
527
+ const stop = index / (colorMatches.length - 1);
528
+ gradient.addColorStop(stop, color);
529
+ });
530
+ }
531
+ }
532
+ // 处理径向渐变
533
+ else if (background.includes('radial-gradient')) {
534
+ // 径向渐变从中心开始
535
+ const centerX = left + width / 2;
536
+ const centerY = top + height / 2;
537
+ const radius = Math.min(width, height) / 2;
538
+
539
+ gradient = ctx.createRadialGradient(centerX, centerY, 0, centerX, centerY, radius);
540
+
541
+ // 解析颜色值
542
+ const colorMatches = background.match(/#[0-9a-fA-F]+|rgba?\([^)]+\)/g);
543
+ if (colorMatches && colorMatches.length >= 2) {
544
+ // 添加渐变色点
545
+ colorMatches.forEach((color, index) => {
546
+ const stop = index / (colorMatches.length - 1);
547
+ gradient.addColorStop(stop, color);
548
+ });
549
+ }
550
+ }
551
+
552
+ if (gradient) {
553
+ ctx.setFillStyle(gradient);
554
+ // 处理圆角
555
+ if (css.radius) {
556
+ const radius = this.convertRpxToPx(css.radius);
557
+ this.drawRoundRect(ctx, left, top, width, height, radius, gradient);
558
+ } else {
559
+ ctx.fillRect(left, top, width, height);
560
+ }
561
+ }
562
+ },
563
+
564
+ /**
565
+ * 将dataURL转换为Blob
566
+ * @description H5环境下将base64格式的dataURL转换为Blob对象
567
+ * @param {String} dataURL base64格式的图片数据
568
+ * @returns {Blob} Blob对象
569
+ * @author jry ijry@qq.com
570
+ */
571
+ dataURLToBlob(dataURL) {
572
+ // 检查是否为H5环境且是base64数据
573
+ // #ifdef H5
574
+ if (dataURL && dataURL.startsWith('data:image')) {
575
+ const parts = dataURL.split(';base64,');
576
+ const contentType = parts[0].split(':')[1];
577
+ const raw = window.atob(parts[1]);
578
+ const rawLength = raw.length;
579
+ const uInt8Array = new Uint8Array(rawLength);
580
+
581
+ for (let i = 0; i < rawLength; ++i) {
582
+ uInt8Array[i] = raw.charCodeAt(i);
583
+ }
584
+
585
+ return new Blob([uInt8Array], { type: contentType });
586
+ }
587
+ // #endif
588
+
589
+ return null;
590
+ },
591
+ }
592
+ }
593
+ </script>
594
+
595
+ <style lang="scss" scoped>
596
+ .up-poster {
597
+ position: relative;
598
+
599
+ &__canvas {
600
+ position: relative;
601
+ overflow: hidden;
602
+ }
603
+
604
+ &__hidden-canvas {
605
+ position: fixed;
606
+ top: -10000px;
607
+ left: -10000px;
608
+ z-index: -1;
609
+ }
610
+
611
+ &__hidden-qrcode {
612
+ position: fixed;
613
+ top: -10000px;
614
+ left: -10000px;
615
+ z-index: -1;
616
+
617
+ &--hidden {
618
+ display: none;
619
+ }
620
+ }
621
+ }
622
+ </style>
@@ -260,7 +260,7 @@ export default {
260
260
  url: this.result
261
261
  }, e)
262
262
  },
263
- async longpress() {
263
+ async toTempFilePath({success, fail}) {
264
264
  if (this.context) {
265
265
  this.ctx.toTempFilePath(
266
266
  0,
@@ -272,14 +272,15 @@ export default {
272
272
  "",
273
273
  1,
274
274
  res => {
275
- this.$emit('longpressCallback', res.tempFilePath)
275
+ success(res)
276
276
  }
277
277
  );
278
278
  }
279
279
  else {
280
-
281
280
  // #ifdef MP-TOUTIAO || H5
282
- this.$emit('longpressCallback', this.ctx.canvas.toDataURL("image/png", 1));
281
+ success({
282
+ tempFilePath: this.ctx.canvas.toDataURL("image/png", 1)
283
+ })
283
284
  // #endif
284
285
 
285
286
  // #ifdef APP-PLUS
@@ -287,10 +288,9 @@ export default {
287
288
  {
288
289
  canvasId: this.cid,
289
290
  success :res => {
290
- this.$emit('longpressCallback', res.tempFilePath)
291
+ success(res)
291
292
  },
292
- fail: err =>{
293
- }
293
+ fail: fail
294
294
  },
295
295
  this)
296
296
  // #endif
@@ -301,16 +301,22 @@ export default {
301
301
  {
302
302
  canvas,
303
303
  success :res => {
304
- this.$emit('longpressCallback', res.tempFilePath)
304
+ success(res)
305
305
  },
306
- fail: err =>{
307
- }
306
+ fail: fail
308
307
  },
309
308
  this)
310
309
  // #endif
311
-
312
310
  }
313
-
311
+ },
312
+ async longpress() {
313
+ this.toTempFilePath({
314
+ success: res => {
315
+ this.$emit('longpressCallback', res.tempFilePath)
316
+ },
317
+ fail: err => {
318
+ }
319
+ })
314
320
  },
315
321
 
316
322
  /**