From 16213c0f85aa3ac8317797bf4a05fd12940e16d3 Mon Sep 17 00:00:00 2001 From: zhangwei <1504152376@qq.com> Date: 星期三, 05 三月 2025 17:29:42 +0800 Subject: [PATCH] - --- src/uni_modules/uview-plus/components/u-qrcode/qrcode.js | 83 ++++++++++++++++++++++++++++------------- 1 files changed, 56 insertions(+), 27 deletions(-) diff --git a/src/uni_modules/uview-plus/components/u-qrcode/qrcode.js b/src/uni_modules/uview-plus/components/u-qrcode/qrcode.js index ae5f945..7ec89fc 100644 --- a/src/uni_modules/uview-plus/components/u-qrcode/qrcode.js +++ b/src/uni_modules/uview-plus/components/u-qrcode/qrcode.js @@ -1031,6 +1031,7 @@ image: '', imageSize: 30, canvasId: opt.canvasId, + nvueContext: opt.nvueContext, context: opt.context, usingComponents: opt.usingComponents, showLoading: opt.showLoading, @@ -1090,7 +1091,12 @@ mask: true }); } - var ctx = uni.createCanvasContext(options.canvasId, options.context); + var ctx = ''; + if (options.nvueContext) { + ctx = options.nvueContext; + } else { + ctx = uni.createCanvasContext(options.canvasId, options.context); + } var count = qrCodeAlg.getModuleCount(); var ratioSize = options.size; var ratioImgSize = options.imageSize; @@ -1141,34 +1147,52 @@ ctx.draw(true, () => { // 淇濆瓨鍒颁复鏃跺尯鍩� setTimeout(() => { - uni.canvasToTempFilePath({ - width: options.width, - height: options.height, - destWidth: options.width, - destHeight: options.height, - canvasId: options.canvasId, - quality: Number(1), - success: function (res) { - if (options.cbResult) { - // 鐢变簬瀹樻柟杩樻病鏈夌粺涓�姝ゆ帴鍙g殑杈撳嚭瀛楁锛屾墍浠ュ厛鍒ゅ畾涓� 鏀粯瀹濅负 res.apFilePath - if (!empty(res.tempFilePath)) { - options.cbResult(res.tempFilePath) - } else if (!empty(res.apFilePath)) { - options.cbResult(res.apFilePath) - } else { + if (options.nvueContext) { + ctx.toTempFilePath( + 0, + 0, + options.width, + options.height, + options.width, + options.height, + "", + 1, + function(res) { + if (options.cbResult) { options.cbResult(res.tempFilePath) } } - }, - fail: function (res) { - if (options.cbResult) { - options.cbResult(res) - } - }, - complete: function () { - uni.hideLoading(); - }, - }, options.context); + ); + } else { + uni.canvasToTempFilePath({ + width: options.width, + height: options.height, + destWidth: options.width, + destHeight: options.height, + canvasId: options.canvasId, + quality: Number(1), + success: function (res) { + if (options.cbResult) { + // 鐢变簬瀹樻柟杩樻病鏈夌粺涓�姝ゆ帴鍙g殑杈撳嚭瀛楁锛屾墍浠ュ厛鍒ゅ畾涓� 鏀粯瀹濅负 res.apFilePath + if (!empty(res.tempFilePath)) { + options.cbResult(res.tempFilePath) + } else if (!empty(res.apFilePath)) { + options.cbResult(res.apFilePath) + } else { + options.cbResult(res.tempFilePath) + } + } + }, + fail: function (res) { + if (options.cbResult) { + options.cbResult(res) + } + }, + complete: function () { + uni.hideLoading(); + }, + }, options.context); + } }, options.text.length + 100); }); }, options.usingComponents ? 0 : 150); @@ -1193,7 +1217,12 @@ } }; QRCode.prototype.clear = function (fn) { - var ctx = uni.createCanvasContext(this.options.canvasId, this.options.context) + var ctx = ''; + if (options.nvueContext) { + ctx = options.nvueContext; + } else { + uni.createCanvasContext(this.options.canvasId, this.options.context) + } ctx.clearRect(0, 0, this.options.size, this.options.size) ctx.draw(false, () => { if (fn) { -- Gitblit v1.9.1