更新记录
1.0(2024-02-27) 下载此版本
uniapp 连接ble蓝牙打印机支持高功率 通过json数组 形式操作,只支持打包安卓(目前还不支持ios)。
平台兼容性
uni-app
Vue2 | Vue3 | Chrome | Safari | app-vue | app-nvue | Android | iOS | 鸿蒙 |
---|---|---|---|---|---|---|---|---|
√ | √ | - | - | √ | - | - | - | - |
微信小程序 | 支付宝小程序 | 抖音小程序 | 百度小程序 | 快手小程序 | 京东小程序 | 鸿蒙元服务 | QQ小程序 | 飞书小程序 | 快应用-华为 | 快应用-联盟 |
---|---|---|---|---|---|---|---|---|---|---|
× | × | × | × | × | × | - | × | × | × | × |
本插件示例图参考个人旗下第一个免费插件例子,区别功能在于能支持高功率蓝牙打印机高传输等特点,目前只支持安卓设备
有何问题留下评论 及时修复
支持一,二维码 安卓高端品牌需要开启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);
}