更新记录

1.0.31(2020-11-30)

1.0.31 更新说明:

  • 更新explain依赖最低支持版本为1.0.83。

1.0.3(2020-11-21)

1.0.3

1.0.23(2020-11-17)

1.0.23 explain升级至1.0.73。

查看更多

平台兼容性

阿里云 腾讯云 支付宝小程序云
×

云函数类插件通用教程

使用云函数类插件的前提是:使用HBuilderX 2.9+


EXPLAIN-QRCODE

explain扩展模块,主要用于生成二维码。

QQ群:970799055

支持云函数URL化,集成响应可直接响应为图片,无需做转换,使用更加简单方便。相比uQRCode,explain-qrcode书写代码量更少,且有网就有二维码,100%生成成功,不会因为平台差异,设备差异导致生成失败,无需在前端做适配和兼容。

云函数URL化预览:https://75bb46ae-4018-4f21-94a2-c226eb480d30.bspapp.com/http/qrcode?text=explain-qrcode(空间有限,仅做预览,请不要直接在项目中使用。应上传至云函数,开启URL化后将该地址替换成你的地址。)

若从插件市场直接部署后报错,在本地重新上传部署一次即可。

模块依赖

需要安装依赖:

模块名称 最低版本 链接
explain 1.0.83 https://ext.dcloud.net.cn/plugin?id=3312

模块方法

make(options)

生成二维码。

参数 类型 必填 说明
text String 二维码内容
type String 类型,可选bufferbase64,默认buffer
imageType String 返回图片类型,默认png
errorCorrectLevel String 纠错等级,可选LMQH,默认M
margin Number 边距,默认1

使用示例

const explain = require("explain");
explain.qrcode = require("explain-qrcode");

let qrcodeImage = explain.qrcode.make({
    text: "explain-qrcode",
    type: "base64",
    imageType: "png",
    errorCorrectLevel: "M",
    margin: 2
});

qr()

qrcode模块依赖于qr-image,调用该方法得到qr-image对象,可以使用qr-image方法。

插件使用方式

参数说明

参数 类型 必填 说明
text String 二维码内容
ec_level String 纠错等级,可选LMQH,默认M
margin Number 边距,默认2

云函数URL化示例

html

<template>
    <view>
        <!-- 空间有限,仅做预览,请不要直接在项目中使用。应上传至云函数,开启URL化后将该地址替换成你的地址。 -->
        <image src="https://75bb46ae-4018-4f21-94a2-c226eb480d30.bspapp.com/http/qrcode?text=explain-qrcode&ec_level=M&margin=2" mode="widthFix" />
    </view>
</template>

云函数调用示例

html

<template>
    <view>
        <image :src="qrcodeSrc" mode="widthFix" />
    </view>
</template>

javascript

export default {
    data() {
        return {
            qrcodeText: 'explain-qrcode',
            qrcodeErrorCorrectLevel: 'M',
            qrcodeMargin: 2,
            qrcodeSrc: ''
        }
    },
    onLoad() {
        uniCloud.callFunction({
            name: 'explain-qrcode',
            data: {
                service: 'qrcode',
                action: 'make',
                params: {
                    text: this.qrcodeText,
                    ec_level: this.qrcodeErrorCorrectLevel,
                    margin: this.qrcodeMargin
                }
            }
        }).then(res => {
            this.qrcodeSrc = res.result // 得到图片base64
        })
    }
}

隐私、权限声明

1. 本插件需要申请的系统权限列表:

2. 本插件采集的数据、发送的服务器地址、以及数据用途说明:

3. 本插件是否包含广告,如包含需详细说明广告表达方式、展示频率:

许可协议

MIT协议

使用中有什么不明白的地方,就向插件作者提问吧~ 我要提问