@byted/qrcode-generator
Advanced tools
Comparing version 1.0.3 to 1.0.4
@@ -27,2 +27,3 @@ var qrcode = require("qrcode"); | ||
if(!Util.domValidate(cus_id).status) { | ||
reject(qrcode); | ||
return; | ||
@@ -59,6 +60,10 @@ } else { | ||
qrcode.upload = (id, url) => { | ||
if(!qrcode.blobInstance[id]) { | ||
console.error(`[byted-qrcode-generator] upload Error. the blobInstance named '${id}' does not exist, please render QRCode first.`); | ||
} else { | ||
return new Promise((resolve, reject) => { | ||
return new Promise((resolve, reject) => { | ||
if(!qrcode.blobInstance[id]) { | ||
console.error(`[byted-qrcode-generator] upload Error. the blobInstance named '${id}' does not exist, please render QRCode first.`); | ||
reject(qrcode); | ||
} else if(!url) { | ||
console.error(`[byted-qrcode-generator] upload Error. please specify the upload URL.`); | ||
reject(qrcode); | ||
} else { | ||
let formData = new FormData(); | ||
@@ -72,18 +77,20 @@ formData.append("file", qrcode.blobInstance[id]); | ||
headers: {'Content-Type': 'multipart/form-data'} | ||
}).then((res) => { | ||
if (res.status == 200) { | ||
let result = res.data.status_code; | ||
if (result == 0) { | ||
resolve(qrcode); | ||
} else { | ||
console.error("[byted-qrcode-generator] qrcode upload failed.") | ||
reject(qrcode); | ||
} | ||
}) | ||
.then((res) => { | ||
if (res.status == 200) { | ||
let result = res.data.status_code; | ||
if (result == 0) { | ||
resolve(qrcode); | ||
} else { | ||
console.error("[byted-qrcode-generator] qrcode upload failed.") | ||
reject(qrcode); | ||
} | ||
}).catch((err) => { | ||
console.error("[byted-qrcode-generator] qrcode upload failed. " + err); | ||
reject(qrcode); | ||
}); | ||
}) | ||
} | ||
} | ||
}) | ||
.catch((err) => { | ||
console.error("[byted-qrcode-generator] qrcode upload failed. " + err); | ||
reject(qrcode); | ||
}); | ||
} | ||
}) | ||
} | ||
@@ -127,4 +134,18 @@ | ||
/** 销毁二维码实例并清空画布 | ||
* @param id Canvas画布id | ||
* @returns | ||
*/ | ||
qrcode.destroy = (id) => { | ||
qrcode.canvasInstance[id] = null; | ||
qrcode.blobInstance[id] = null; | ||
var canvas = document.getElementById(id); | ||
var ctx = canvas.getContext("2d"); | ||
ctx.setTransform(1, 0, 0, 1, 0, 0); | ||
ctx.clearRect(0, 0, canvas.width, canvas.height); | ||
} | ||
module.exports = qrcode; | ||
} | ||
@@ -55,3 +55,3 @@ module.exports = Utils = { | ||
/** | ||
* 将以base64的图片url数据转换为Blob | ||
* 将base64编码表示的图片URL转换为Blob | ||
* @param {string} urlData 用url方式表示的base64图片数据 | ||
@@ -61,5 +61,3 @@ * @returns | ||
convertBase64UrlToBlob(urlData) { | ||
//去掉url头,并转换为byte | ||
let bytes = window.atob(urlData.split(',')[1]); | ||
//处理异常,将ascii码小于0的转换为大于0 | ||
let bytes = window.atob(urlData.split(',')[1]); | ||
let ab = new ArrayBuffer(bytes.length); | ||
@@ -66,0 +64,0 @@ let ia = new Uint8Array(ab); |
{ | ||
"name": "@byted/qrcode-generator", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"description": "A tool for generating qrcode. Support to render canvas, display image, download image file and execute callback, upload image file and execute callback, add customized picture to the center of the qrcode and etc.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -61,5 +61,8 @@ # byted-qrcode-generator | ||
* destroy(id) | ||
>销毁二维码实例并清空画布 | ||
>@param id Canvas画布id | ||
>@returns |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9845
201
67