当前位置:网站首页>小程序使用二维码插件
小程序使用二维码插件
2022-06-30 07:57:00 【Dark_programmer】
以钉钉小程序为例。
1. 安装插件
npm install qr-image
2. 在组件内引入
const qrImage= require(‘qr-image’)
3. 转成base64格式的url
_arrayBufferToBase64(raw) {
var base64 = "";
var encodings =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
var bytes = new Uint8Array(raw);
var byteLength = bytes.byteLength;
var byteRemainder = byteLength % 3;
var mainLength = byteLength - byteRemainder;
var a, b, c, d;
var chunk;
for (var i = 0; i < mainLength; i = i + 3) {
chunk = (bytes[i] << 16) | (bytes[i + 1] << 8) | bytes[i + 2];
a = (chunk & 16515072) >> 18;
b = (chunk & 258048) >> 12;
c = (chunk & 4032) >> 6;
d = chunk & 63;
base64 += encodings[a] + encodings[b] + encodings[c] + encodings[d];
}
if (byteRemainder == 1) {
chunk = bytes[mainLength];
a = (chunk & 252) >> 2;
b = (chunk & 3) << 4;
base64 += encodings[a] + encodings[b] + "==";
} else if (byteRemainder == 2) {
chunk = (bytes[mainLength] << 8) | bytes[mainLength + 1];
a = (chunk & 16128) >> 8;
b = (chunk & 1008) >> 4;
c = (chunk & 15) << 2;
base64 += encodings[a] + encodings[b] + encodings[c] + "=";
}
return "data:image/jpeg;base64," + base64;
}
4. 将数据通过上述方法转换
const content = '我是需要转换成二维码的内容,扫码就会看到我哦~';
const code = qrImage.imageSync( content , {
type: "png" });// 使用安装的插件
const qr_code = _arrayBufferToBase64(code); // 通过第三步将code转换为base64格式的二维码
5. 展示
<image mode="widthFix" src="{
{ qr_code }}" />
如此即可展示,二维码如下:
扫码结果:
边栏推荐
- Deep learning -- Realization of convolution by sliding window
- Deep learning -- feature point detection and target detection
- Xiashuo think tank: 125 planet updates reported today (packed with 101 meta universe collections)
- November 9, 2020 [wgs/gwas] - whole genome analysis (association analysis) process (Part 2)
- Final review -php learning notes 2-php language foundation
- Deep learning -- sequence model and mathematical symbols
- December 19, 2021 [reading notes] - bioinformatics and functional genomics (Chapter 5 advanced database search)
- Investment and financing analysis report of Supply Chain & logistics industry in 2021
- Hit the industry directly | the flying propeller launched the industry's first model selection tool
- Analysis of cross clock transmission in tinyriscv
猜你喜欢
Combinatorial mathematics Chapter 1 Notes
Construction of energy conservation supervision system for campus buildings of ankery University
2021.11.20 [reading notes] | differential variable splicing events and DTU analysis
【花雕体验】13 搭建ESP32C3之PlatformIO IDE开发环境
Spring Festival inventory of Internet giants in 2022
深度学习——GRU单元
Wangbohua: development situation and challenges of photovoltaic industry
【花雕体验】12 搭建ESP32C3之Arduino开发环境
Tencent and Fudan University "2021-2022 yuan universe report" with 102 yuan universe collections
6月底了,可以开始做准备了,不然这么赚钱的行业就没你的份了
随机推荐
JS code case
深度学习——词汇表征
HelloWorld
vulfocus入门靶机
【花雕体验】12 搭建ESP32C3之Arduino开发环境
深度学习——残差网络ResNets
Examen final - notes d'apprentissage PHP 5 - Tableau PHP
More, faster, better and cheaper. Here comes the fastdeploy beta of the low threshold AI deployment tool!
Xiashuo think tank: 42 reports on planet update today (including 23 planning cases)
【花雕体验】13 搭建ESP32C3之PlatformIO IDE开发环境
为什么大学毕业了还不知道干什么?
Simple application of generating function
December 13, 2021 [reading notes] | understanding of chain specific database building
Recurrence relation (difference equation) -- Hanoi problem
November 19, 2021 [reading notes] a summary of common problems of sneakemake (Part 2)
深度学习——GRU单元
Why don't you know what to do after graduation from university?
String and underlying character types of go data type
Lexicographic order -- full arrangement in bell sound
Deep learning -- Realization of convolution by sliding window