更新记录

1.0.0(2025-09-20) 下载此版本

初始版本


平台兼容性

uni-app(3.6.5)

Vue2 Vue3 Chrome Safari app-vue app-nvue Android iOS 鸿蒙
× × 5.0 × ×
微信小程序 支付宝小程序 抖音小程序 百度小程序 快手小程序 京东小程序 鸿蒙元服务 QQ小程序 飞书小程序 快应用-华为 快应用-联盟
- - - - - - - - - - -

ez-bluetooth 简化Uniapp蓝牙连接

简介

这个项目是在工作中,使用前人写的蓝牙连接过于繁琐。所以,才有了该项目。本项目中简化蓝牙操作。 直接使用uniapp中的蓝牙接口,并无使用安卓底层原生接口。

欢迎使用,有什么问题可以提我看到会回复。

功能描述

  1. 该项目目前有基本的蓝牙连接、搜索、写入、监听回调、关闭蓝牙等功能。我还增加了蓝牙连接失败重连功能。
  2. 内部含有小票打印命令集 (这部分目前只支持佳博。毕竟,我调试只使用的佳博。没有别的打印机(T_T))
  3. 项目使用TypeScript进行了类型标注。

    使用方式

    1、导入ez_bluetooth

    在Uniapp插件市场导入本项目到uni_modules

    2、导入模块

    <script lang="ts">
    /**
    * Bluetooth 蓝牙
    * BluetoothStore 蓝牙缓存(里面有注释)
    * LocalStore 操作本地缓存的工具
    */
    import { Bluetooth, BluetoothStore, LocalStore } from '@/uni_modules/ez-bluetooth';
    /**
    * 目前只使用佳博的打印机去测试
    * TextPrint 普通打印
    * QrCodePrint 二维码打印
    * BarcodePrint 条形码打印
    */
    import { TextPrint, QrCodePrint, BarcodePrint } from '@/uni_modules/ez-bluetooth/printer/receipt';
    /**
    * 这是类型标注使用的常量
    */
    import { LabelType, ReceiptType } from '@/uni_modules/ez-bluetooth/type';
    </script>

    3、API

    名称 方法 描述
    Bluetooth init 初始化
    search 搜索蓝牙
    connection 连接蓝牙
    write 写数据
    closeConnection 关闭蓝牙连接
    close 关闭蓝牙

    4、连接蓝牙

    请看示例代码

5、使用小票打印

/**
 * 普通打印
 */
const text = new TextPrint();
text.setCharacterSize(17);
text.setText('你好,欢迎来到使用EZ-Bluetooth');
text.setPrint();
text.setPrintAndFeedRow(1);
/**
 * 二维码打印
 */
const qr = new QrCodePrint('http://www.baidu.com/', LevelType.L, 5);
/**
 * 条形码打印
 */
const bar = new BarcodePrint();
bar.setBarcodeHeight(5); //条码高度
bar.setBarcodeWidth(2); //设置条码宽度
bar.setCode128('{A12345678');
text.setPrintAndFeedRow(1);
/**
 * 如果想普通文本+二维码+条形码打印在同一页
 * 参考下面部分代码
 */
const text = new TextPrint();
text.push(qr.getData());
text.setPrintAndFeedRow(1);
const bar = new BarcodePrint();
text.push(bar.getData());
Bluetooth.write(new Uint8Array(text.getData()).buffer);

6、打印机缓存

名称 key
蓝牙列表 DEVICE_LIST
蓝牙状态 BLUE_STATE
蓝牙连接状态 BLUE_CONNECT_STATE
保存连接过的设备信息 SAVE_DEVICE_LIST
设备通知回调内容 DEVICE_NOTIFY

隐私、权限声明

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

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

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

许可协议

MIT协议

暂无用户评论。