更新记录

0.0.0(2022-06-01)

1、初版提交


平台兼容性

Android Android CPU类型 iOS
适用版本区间:4.4 - 11.0 armeabi-v7a:未测试,arm64-v8a:未测试,x86:未测试 ×

原生插件通用使用流程:

  1. 购买插件,选择该插件绑定的项目。
  2. 在HBuilderX里找到项目,在manifest的app原生插件配置中勾选模块,如需要填写参数则参考插件作者的文档添加。
  3. 根据插件作者的提供的文档开发代码,在代码中引用插件,调用插件功能。
  4. 打包自定义基座,选择插件,得到自定义基座,然后运行时选择自定义基座,进行log输出测试。
  5. 开发完毕后正式云打包

付费原生插件目前不支持离线打包。
Android 离线打包原生插件另见文档 https://nativesupport.dcloud.net.cn/NativePlugin/offline_package/android
iOS 离线打包原生插件另见文档 https://nativesupport.dcloud.net.cn/NativePlugin/offline_package/ios

注意事项:使用HBuilderX2.7.14以下版本,如果同一插件且同一appid下购买并绑定了多个包名,提交云打包界面提示包名绑定不一致时,需要在HBuilderX项目中manifest.json->“App原生插件配置”->”云端插件“列表中删除该插件重新选择


目前仅支持安卓平台使用该插件

插件说明

本插件提供安卓手机使用蓝牙或USB连接打印机进行打印的相关功能。

Android 热敏小票综合打印插件测试Demo(支持蓝牙与USB) APK 下载链接 密码:8vbp

功能测试安装包下载至手机安装。需要调用USB接口时,请先使用OTG转接头与USB数据线连接手机充电口和热敏小票打印机后开始测试,需要在确保USB已连接后先点击初始化连接打印机,之后即可进行测试打印。插件内提供的接口都在测试Demo中有所展示。插件觉得好用的话不妨点个赞赏买个插件请作者喝杯奶茶吧~~

如果需要其他连接方式的打印接口,可参考下列连接:
Android 蓝牙热敏小票打印机功能插件bluetoothManager
Android USB接口热敏小票打印机插件usbPrinter

初始化

const syntheticalPrinterModule = uni.requireNativePlugin("singplugin-syntheticalPrinter");

返回码说明

{
    "code": "ok",//或error,表示执行结果成功或失败
    "result": "蓝牙已打开",//执行结果返回内容
}

初始化打印插件模块(调用其他接口前需要先初始化插件)

syntheticalPrinterModule.initPrinterModule(e => {//初始化打印模块,初始化之后才能开始使用其他接口
    uni.showToast({
        title: JSON.stringify(e),
        icon: 'none'
    })
})

检测蓝牙是否已开启

syntheticalPrinterModule.isBluetoothOpened(e => {
    uni.showToast({
        title: JSON.stringify(e),
        icon: 'none'
    })
})

开启蓝牙

syntheticalPrinterModule.turnOnBluetooth(e => {
    uni.showToast({
        title: JSON.stringify(e),
        icon: 'none'
    })
})

关闭蓝牙

syntheticalPrinterModule.turnOffBluetooth(e => {
    uni.showToast({
        title: JSON.stringify(e),
        icon: 'none'
    })
})

开始搜索附近蓝牙设备

syntheticalPrinterModule.startSearchNearbyDevice(e => {//不会在该方法内返回蓝牙设备列表,请绑定全局事件OnBluetoothDeviceFound获取或手动调用stopSearchNearbyDevice或getSearchedNearbyDeviceList获取搜索到的设备列表
    uni.showToast({
        title: JSON.stringify(e),
        icon: 'none'
    })
})

停止搜索附近蓝牙设备,并获得已搜索到的设备

syntheticalPrinterModule.stopSearchNearbyDevice(e => {//手动停止搜索附近蓝牙设备,并返回已搜索到的设备
    if (e.code == "ok") {
        _self.searchedDeviceList = e.result;//result为蓝牙信息列表
        uni.showToast({
            title: "结束搜索",
            icon: 'none'
        })
    } else {
        uni.showToast({
            title: JSON.stringify(e),
            icon: 'none'
        })
    }
})

获取已搜索到的设备列表(此方法不会停止搜索)

syntheticalPrinterModule.getSearchedNearbyDeviceList(e => {
    if (e.code == "ok") {
        _self.searchedDeviceList = e.result;//result为蓝牙信息列表
        uni.showToast({
            title: "获取搜索到的设备列表完成",
            icon: 'none'
        })
    } else {
        uni.showToast({
            title: JSON.stringify(e),
            icon: 'none'
        })
    }
})

获取当前设备已配对的蓝牙设备列表

syntheticalPrinterModule.getPairedDeviceList(e => {
    if (e.code == "ok") {
        _self.pairedDeviceList = e.result;//result为蓝牙信息列表
            uni.showToast({
                title: "获取已配对设备列表完成",
                icon: 'none'
            })
        } else {
            uni.showToast({
                title: JSON.stringify(e),
                icon: 'none'
        })
    }
})

蓝牙设备列表内容

[
    {
        name: "device1",//设备名称
        address: "11:11:11:11:11"//设备地址
    },
    {
        name: "device2",//设备名称
        address: "22:22:22:22:22"//设备地址
    },
    {
        name: "device3",//设备名称
        address: "33:33:33:33:33"//设备地址
    }
]

打开手机已配对蓝牙列表界面

syntheticalPrinterModule.openPairBluetoothDevice(e => {
    if (e.code == "ok") {
        uni.showToast({
            title: "打开蓝牙配对界面",
            icon: 'none'
        })
    } else {
        uni.showToast({
            title: JSON.stringify(e),
            icon: 'none'
        })
    }
})

根据地址连接蓝牙设备

syntheticalPrinterModule.connectPairedDevice({//根据地址连接蓝牙设备
    deviceAddress: address//地址值为蓝牙设备列表内的address
}, e => {
    uni.showToast({
        title: e.result,
        icon: 'none'
    })
});

连接USB设备

syntheticalPrinterModule.connectUSBPrinter(e => {
    uni.showToast({
        title: JSON.stringify(e),
        icon: 'none'
    })
})

断开USB连接

syntheticalPrinterModule.disconnectUSBPrinter(e => {
    uni.showToast({
        title: JSON.stringify(e),
        icon: 'none'
    })
})

打印文字

syntheticalPrinterModule.printText({//打印字符串
    text: _self.textPrint,//需要打印的字符串
    encoding: _self.encodingList[_self.encodingIndex],//打印字符串使用的编码格式,不填默认GBK
    printCount: 1,//打印次数,不填默认1
}, e => {
    uni.showToast({
        title: e,
        icon: 'none'
    })
});

可选打印字符串使用的编码格式

encodingList: ["GBK", "UTF-8", "BIG5", "GB2312", "Shift-JIS", "EUC-KR"], //可选编码格式

打印图片

syntheticalPrinterModule.printImage({
    imagePath: _self.selectedImagePath,//传入图片在手机内的绝对本地路径,注意必须是绝对本地路径
    printCount: 1,//打印次数,默认为1
}, e => {
    uni.showToast({
        title: e,
        icon: 'none'
    })
});

如何获取图片的本地路径

handleSelectImage: function() {
    uni.chooseImage({
        count: 1, //  上传图片数量的控制为1
        sizeType: ["original"],//原图
        sourceType: ["album"],
        success(res) {
            let tempFilePath = res.tempFilePaths[0];
            _self.selectedImagePath = plus.io.convertLocalFileSystemURL(tempFilePath);//需要获取图片的绝对本地路径
        }
    })
}

打印条形码(该功能与部分打印机机型不兼容,请谨慎使用)

syntheticalPrinterModule.printBarcode({
    barcodeContent: _self.textBarcode,//条形码内容,数字组成的字符串
    barcodeWidth: _self.barcodeWidthIndex, //条码宽度(1-5):默认单位1
    barcodeHeight: _self.barcodeHeightIndex,//条码高度(1-8):默认单位1
    barcodeFontPosition: _self.barcodeTextPositionIndex, //字体打印位置(0-3),默认不打印文字
    printCount: 1,//打印次数,默认1
}, e => {
    uni.showToast({
        title: e,
        icon: 'none'
    })
});

字体打印位置对应序号

0 => 不打印条码文本,
1 => 条码上方打印,
2 => 条码下方打印,
3 => 条码上、下方打印

打印二维码(该功能与部分打印机机型不兼容,请谨慎使用)

syntheticalPrinterModule.printQrcode({
    qrcodeContent: _self.textQrcode,//二维码内容字符串
    qrcodeSize: _self.qrcodeSize, //二维码大小(1-15),默认1(某些机型上不能正确调整大小)
    errorCorrectionLevel: _self.qrcodeErrorCorrectionLevel, //二维码纠错等级(0-3),默认1
    printCount: 1, // 打印次数:默认1
}, e => {
    uni.showToast({
        title: e,
        icon: 'none'
    })
});

可绑定监听事件

const globalEvent = uni.requireNativePlugin('globalEvent');
bindPluginEvent() { //绑定插件内部事件监听
    globalEvent.addEventListener('BluetoothDiscovery', function(e) { //监听蓝牙开始扫描事件
        uni.showToast({
            title: "globalEvent" + JSON.stringify(e),
            icon: 'none'
        })
    });

    globalEvent.addEventListener('OnFinishBluetoothDiscovery', function(e) { //监听蓝牙结束扫描事件
        uni.showToast({
            title: "globalEvent" + JSON.stringify(e),
            icon: 'none'
        })
    });

    globalEvent.addEventListener('OnBluetoothConnected', function(e) { //监听蓝牙已连接事件
        uni.showToast({
            title: "globalEvent" + JSON.stringify(e),
            icon: 'none'
        })
    });

    globalEvent.addEventListener('OnBluetoothDisconnected', function(e) { //监听蓝牙连接断开事件
        uni.showToast({
            title: "globalEvent" + JSON.stringify(e),
            icon: 'none'
        })
    });

    globalEvent.addEventListener('OnBluetoothDeviceFound', function(e) { //监听搜索发现蓝牙设备事件,返回内容为设备名称与地址,如果需要实时获取搜索到的蓝牙设备信息可在此获取
        _self.searchedDeviceList.push(e);
    });

    globalEvent.addEventListener('OnUSBDisconnected', function(e) { //监听USB连接断开事件
        uni.showToast({
            title: "globalEvent" + JSON.stringify(e),
            icon: 'none'
        })
    });
}

隐私、权限声明

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

"<uses-permission android:name=\"android.permission.BLUETOOTH\"/>", "<uses-permission android:name=\"android.permission.BLUETOOTH_ADMIN\"/>", "<uses-permission android:name=\"android.permission.BLUETOOTH_PRIVILEGED\"/>", "<uses-permission android:name=\"android.permission.BLUETOOTH_CONNECT\"/>", "<uses-permission android:name=\"android.permission.WRITE_EXTERNAL_STORAGE\"/>"

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

插件不采集任何数据

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

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