uview-plus组件库全面升级更新,订单结算判断支付方式是否可用代码调整,公众号关注二维码修改

This commit is contained in:
2025-10-21 10:44:31 +08:00
parent 5d98b7efc2
commit 5f3a307fec
395 changed files with 31264 additions and 2477 deletions

View File

@@ -1037,6 +1037,9 @@ let QRCode = {};
showLoading: opt.showLoading,
loadingText: opt.loadingText,
};
let canvas = null;
if (typeof opt === 'string') { // 只编码ASCII字符串
opt = {
text: opt
@@ -1083,8 +1086,29 @@ let QRCode = {};
}
return options.foreground;
}
let getCanvas = async (id) => {
return new Promise((resolve, reject)=>{
try {
const query = uni.createSelectorQuery().in(this.options.context);
query.select(`#${id}`)
.fields({ node: true, size: true })
.exec((res) => {
resolve(res[0].node)
})
}
catch (e) {
console.error("createCanvasContextFail",e)
}
})
}
// 创建canvas
let createCanvas = function (options) {
let createCanvas = async function (options) {
let isApp = false;
// #ifdef APP
isApp = true;
// #endif
if(options.showLoading){
uni.showLoading({
title: options.loadingText,
@@ -1094,9 +1118,27 @@ let QRCode = {};
var ctx = '';
if (options.nvueContext) {
ctx = options.nvueContext;
} else {
ctx = uni.createCanvasContext(options.canvasId, options.context);
}
else {
// 获取canvas node节点
canvas = await getCanvas(options.canvasId);
// #ifdef MP
// 不清楚是小程序的bug还是什么原因canvas的node节点宽高和设置的宽高不一致 重新设置下
canvas.width = options.size;
canvas.height = options.size;
// #endif
// #ifdef APP
ctx = uni.createCanvasContext(options.canvasId, options.context);
// #endif
// #ifndef APP
ctx = canvas.getContext('2d');
// #endif
}
// 设置组件中data里面的ctx
options.context.ctx = ctx;
options.context.canvas = canvas;
var count = qrCodeAlg.getModuleCount();
var ratioSize = options.size;
var ratioImgSize = options.imageSize;
@@ -1107,14 +1149,18 @@ let QRCode = {};
for (var row = 0; row < count; row++) {
for (var col = 0; col < count; col++) {
var w = (Math.ceil((col + 1) * tileW) - Math.floor(col * tileW));
var h = (Math.ceil((row + 1) * tileW) - Math.floor(row * tileW));
var h = (Math.ceil((row + 1) * tileH) - Math.floor(row * tileH));
var foreground = getForeGround({
row: row,
col: col,
count: count,
options: options
});
ctx.setFillStyle(qrCodeAlg.modules[row][col] ? foreground : options.background);
if (options.nvueContext) {
ctx.setFillStyle(qrCodeAlg.modules[row][col] ? foreground : options.background);
} else {
ctx.fillStyle = qrCodeAlg.modules[row][col] ? foreground : options.background;
}
ctx.fillRect(Math.round(col * tileW), Math.round(row * tileH), w, h);
}
}
@@ -1122,18 +1168,49 @@ let QRCode = {};
var x = Number(((ratioSize - ratioImgSize) / 2).toFixed(2));
var y = Number(((ratioSize - ratioImgSize) / 2).toFixed(2));
drawRoundedRect(ctx, x, y, ratioImgSize, ratioImgSize, 2, 6, true, true)
ctx.drawImage(options.image, x, y, ratioImgSize, ratioImgSize);
if (options.nvueContext) {
ctx.drawImage(options.image, x, y, ratioImgSize, ratioImgSize);
}
else {
// #ifdef H5 || APP
const img = new Image();
// #endif
// #ifndef H5 || APP
const img = canvas.createImage();
// #endif
img.onload = () => {
ctx.drawImage(img, x, y, ratioImgSize, ratioImgSize);
};
img.src = options.image;
}
// 画圆角矩形
function drawRoundedRect(ctxi, x, y, width, height, r, lineWidth, fill, stroke) {
ctxi.setLineWidth(lineWidth);
ctxi.setFillStyle(options.background);
ctxi.setStrokeStyle(options.background);
ctxi.beginPath(); // draw top and top right corner
if (options.nvueContext || isApp) {
ctxi.setLineWidth(lineWidth);
ctxi.setFillStyle(options.background);
ctxi.setStrokeStyle(options.background);
}
else {
ctxi.lineWidth = lineWidth;
ctxi.fillStyle = options.background;
ctxi.strokeStyle = options.background;
}
ctxi.beginPath(); // draw top and top right corner
ctxi.moveTo(x + r, y);
ctxi.arcTo(x + width, y, x + width, y + r, r); // draw right side and bottom right corner
ctxi.arcTo(x + width, y + height, x + width - r, y + height, r); // draw bottom and bottom left corner
ctxi.arcTo(x, y + height, x, y + height - r, r); // draw left and top left corner
ctxi.arcTo(x, y, x + r, y, r);
ctxi.lineTo(x + width, y); // move to top-right corner
ctxi.arc(x + width - r, y + r, r, -Math.PI / 2, 0); // draw right side and bottom right corner
ctxi.lineTo(x + width, y + height - r);
ctxi.arc(x + width - r, y + height - r, r, 0, Math.PI / 2); // draw bottom and bottom left corner
ctxi.lineTo(x + r, y + height);
ctxi.arc(x + r, y + height - r, r, Math.PI / 2, Math.PI);// draw left and top left corner
ctxi.lineTo(x, y + r);
ctxi.arc(x + r, y + r, r, Math.PI, Math.PI * 3 / 2);
ctxi.closePath();
if (fill) {
ctxi.fill();
@@ -1144,57 +1221,64 @@ let QRCode = {};
}
}
setTimeout(() => {
ctx.draw(true, () => {
// 保存到临时区域
setTimeout(() => {
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)
}
}
);
} 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) {
// 由于官方还没有统一此接口的输出字段,所以先判定下 支付宝为 res.apFilePath
if (!empty(res.tempFilePath)) {
options.cbResult(res.tempFilePath)
} else if (!empty(res.apFilePath)) {
options.cbResult(res.apFilePath)
} else {
// canvas2 绘制是自动的不需要手动绘制
if(options.nvueContext || isApp){
ctx.draw(true, () => {
// 保存到临时区域
setTimeout(() => {
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);
}
}, options.text.length + 100);
});
);
} 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) {
// 由于官方还没有统一此接口的输出字段,所以先判定下 支付宝为 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);
});
}
else{
options.cbResult("")
}
}, options.usingComponents ? 0 : 150);
}
createCanvas(this.options);
@@ -1232,4 +1316,4 @@ let QRCode = {};
};
})()
export default QRCode
export default QRCode