<template>
<!-- 自定义导航栏 -->
<view class="bluetooth">
<view class="navBarBox">
<!-- 状态栏占位 -->
<view class="statusBar" :style="{ paddingTop: statusBarHeight + 'px' }"></view>
<!-- 真正的导航栏内容 -->
<view class="navBar">
<view class="titlefont" style="margin-left: 10px;">通信设备</view>
</view>
</view>
<!-- 发送数据 -->
<view class="send">
<view class="uni-textarea">
<view @tap="send_data" class="fasong">发送</view>
<view class="">
蓝牙返回的数据为:
</view>
</view>
</view>
<!-- 没有匹配的蓝牙设备 -->
<view class="no_match_bluetooth_list" v-if="no_match_list.length!=0">
<view class="h1">附近蓝牙设备</view>
<scroll-view scroll-y="100%">
<flex v-for="(item,index) in no_match_list" :key="index" >
<view class="uni-list" @tap="print(item.SN)">
<view class="uni-list-cell" hover-class="uni-list-cell-hover">
<view class="uni-list-cell-navigate uni-navigate-right uni-media-list ">
<view class="uni-media-list-body">
<image src="@/static/img/lanya.png" class="lanyaimg" mode="scaleToFill"></image>
<view class="lanySn"> {
{item.name}} </view>
</view>
</view>
</view>
</view>
</flex>
</scroll-view>
</view>
<view>
<popuphelp :helpshowModal="helpshowPay" @helpclose="oncloseahelp"></popuphelp>
</view>
<view class="btn">
<view class="btn_1" @tap="open_bluetooth()">帮 助</view>
<view class="btn_3" @tap="search_bluetooth()">刷 新</view>
</view>
</view>
</template>
<script>
import popuphelp from "@/pages/main/popuphelp.vue"
import blueTool from '../../common/dataFormatUtil.js';
import uTool from '../../common/buletoothUtil.js'
var main, Context, BluetoothManager, BluetoothAdapter, BManager, BAdapter,BluetoothDevice,IntentFilter,bluetoothSocket,device,_self;
export default {
components:{
popuphelp
},
data() {
return {
bArray:[],//用于搜索蓝牙去重用的
no_match_list:[],//没有配对的蓝牙列表
send_data_onoff:false,
send_data_list:'',//要发送的数据
statusBarHeight: 0,// 状态栏高度
helpshowPay: false,
show: false,
timer: null,
BDeviceList:[],
fa: '',
shou: '',
serviceId: '', //蓝牙服务 uuid
connectionid: '', //设备的 id
characteristicid: '', //特征
sheb: "",
mList:[],//搜索到的设备列表
mDeviceId:0,//连接的设备
targetNumber:'',//要连接的指定设备
};
},
onLoad() {
//获取手机状态栏高度
this.statusBarHeight = uni.getSystemInfoSync()['statusBarHeight'];
//获取android应用Activity对象
main = plus.android.runtimeMainActivity();
Context = plus.android.importClass("android.content.Context");
BManager = main.getSystemService(Context.BLUETOOTH_SERVICE);
//蓝牙适配器
BluetoothAdapter = plus.android.importClass("android.bl
Uni-app实现蓝牙搜索、连接、传送数据实例
于 2022-02-22 09:23:43 首次发布