更新记录

1.0(2024-02-27)

uniapp 连接ble蓝牙打印机支持高功率 通过json数组 形式操作,只支持打包安卓(目前还不支持ios)。


平台兼容性

Vue2 Vue3
App 快应用 微信小程序 支付宝小程序 百度小程序 字节小程序 QQ小程序
HBuilderX 3.6.2 app-vue × × × × × ×
钉钉小程序 快手小程序 飞书小程序 京东小程序
× × × ×
H5-Safari Android Browser 微信浏览器(Android) QQ浏览器(Android) Chrome IE Edge Firefox PC-Safari
× × × × × × × × ×

本插件示例图参考个人旗下第一个免费插件例子,区别功能在于能支持高功率蓝牙打印机高传输等特点,目前只支持安卓设备

有何问题留下评论 及时修复

支持一,二维码 安卓高端品牌需要开启gps定位

第一步 找到下载的bleBlueTooth文件夹的依赖js文件:

import {getLocationManager,searchDevices,print,cancelDiscovery} from './searchDevices';
import {commands} from './command';

第二步 先打开蓝牙:

onMounted(() => { getLocationManager(()=>{}); });

第三步 离开页面关闭蓝牙(根据场景来):

onUnmounted(()=>{ cancelDiscovery(); });

第四步 搜索附近蓝牙设备:

searchDevices('',state.deviceData);

第五步 选中对应的蓝牙打印机进行发送json数组:

const state = reactive({
  current: 'tspl',
  deviceData: [
    {deviceId:0,name:'deviceId'},
    {deviceId:1,name:'deviceId'}
  ],
  data: [
    { id: "12345", width: 100, height: 100, title1: 'title_1', title2: 'title_2', title3: 'title_3' },
    { id: "123456", width: 100, height: 100, title1: 'title_4', title2: 'title_5', title3: 'title_6' },
    { id: "123456789", width: 100, height: 100, title1: 'title_7', title2: 'title_8', title3: 'title_9' }
  ], deviceId: '' });
const onPrintClick = () => {
  const stringData = [];
  state.data.forEach(item => {
    stringData.push(commands(state.current, item));
  })
  print(state.deviceId,stringData, () => {
    uni.showToast({
      title: '打印成功',
      duration: 2000,
    });
  })
}
const onBtnClick = (deviceId) => {
  state.deviceId = deviceId;
  searchDevices(deviceId);
}

第六步 commands方法 具体实现 点击commands.js查看;指令文档请到免费打印插件下载查看:

隐私、权限声明

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

蓝牙,gps

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

插件不采集任何数据

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

暂无用户评论。

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