当前位置: 首页 > news >正文

泉州专业网站制作公司网站建设投标书 技术架构

泉州专业网站制作公司,网站建设投标书 技术架构,广东网站开发公司,wordpress编辑远程图片模拟的是蓝牙设备签到/签出&#xff1a; 获取指定蓝牙设备蓝牙初始搜索次数限制&#xff0c;超过限制就停止搜索蓝牙连接失败次数限制&#xff0c;超过限制标识蓝牙连接失败&#xff08;离开蓝牙范围或其他原因&#xff09;自动重连指定蓝牙 const device ref<any>(nu…

模拟的是蓝牙设备签到/签出:

  1. 获取指定蓝牙设备
  2. 蓝牙初始搜索次数限制,超过限制就停止搜索
  3. 蓝牙连接失败次数限制,超过限制标识蓝牙连接失败(离开蓝牙范围或其他原因)
  4. 自动重连指定蓝牙
const device = ref<any>(null); // 设备信息
const crpBlueList = ref<any[]>([]); // 扫描到的蓝牙信息列表
const linkStatus = ref(false); // 连接状态
const searchTimes = ref(0); // 搜索次数
const searchLimit = 5; // 搜索次数限制
const linkTimes = ref(0); // 扫描次数
const failTimes = ref(0); // 失败次数
const failLimit = 5; // 失败次数限制
const blueName = 'zo-crp'; // 指定蓝牙设备的名称前缀
let isSignIn = false; // 是否签到
// 签到
const signIn = () => {searchTimes.value = 0;uni.showLoading({title: '蓝牙搜索中...',mask: true});openBluetoothAdapter(() => {startBluetoothDeviceDiscovery();});
};
// 签出
const logout = () => {closeBlueTooth(device.value, () => {isSignIn = false;device.value = null;linkStatus.value = false;searchTimes.value = 0;linkTimes.value = 0;failTimes.value = 0;crpBlueList.value = [];uni.showToast({title: '已签出'});});
};
// 初始化蓝牙
const openBluetoothAdapter = (callback: Function) => {uni.openBluetoothAdapter({//打开蓝牙适配器接口success: (res) => {//已打开callback();},fail: (err) => {uni.hideLoading();uni.showModal({title: '',content: '该操作需要蓝牙支持!请打开蓝牙',showCancel: false,success: (res) => {if (res.confirm) {// #ifdef APPlet main = plus.android.runtimeMainActivity();let Intent = plus.android.importClass('android.content.Intent');let mIntent = new Intent('android.settings.BLUETOOTH_SETTINGS');main.startActivity(mIntent);// #endif} else {navigateBack();}},complete: () => {}});}});
};
// 搜索蓝牙
const startBluetoothDeviceDiscovery = () => {if (searchTimes.value > searchLimit - 1) {uni.showModal({content:'没有找到指定的蓝牙设备,请确认所在位置周边有指定蓝牙设备,且手机已开启位置信息并授权',confirmText: '重试',success: (res) => {if (res.confirm) {signIn();} else {stopBluetoothDevicesDiscovery(() => {uni.closeBluetoothAdapter({complete: () => {navigateBack();}});});}}});return;}searchTimes.value += 1;uni.startBluetoothDevicesDiscovery({success: (res) => {// 发现外围设备onBluetoothDeviceFound();},fail: (err) => {console.log(err, '开始搜索蓝牙设备备错误信息');}});
};
// 发现设备
const onBluetoothDeviceFound = () => {let t: any = setTimeout(() => {clearTimeout(t);t = null;stopBluetoothDevicesDiscovery(() => {// 停止搜索蓝牙uni.getBluetoothDevices({success: (res) => {const blueList = res.devices.filter((item: any) => item.name.toLowerCase().startsWith(blueName)).sort((a: any, b: any) => b.RSSI - a.RSSI);crpBlueList.value = blueList;if (!blueList.length) {startBluetoothDeviceDiscovery();return;}const Device: any = blueList[0];isSignIn = true;// 获取电量const serviceData = Array.prototype.map.call(new Uint8Array(Device.serviceData[Object.keys(Device.serviceData)[0]]), (bit) =>bit.toString(16)).join('');const Electric = parseInt(serviceData.slice(-2), 16);// 获取uuidconst UUID = Array.prototype.map.call(new Uint8Array(Device.advertisData), (bit) => ('00' + bit.toString(16)).slice(-2)).join('').substring(8, 40).toUpperCase();device.value = {name: Device.name,deviceId: Device.deviceId,electric: Electric,RSSI: Device.RSSI,UUID: UUID};linkStatus.value = true;createBLEConnection(Device);}});});}, 2000);
};
// 连接设备
const createBLEConnection = (item: any) => {uni.showLoading({title: '连接中,请稍等',mask: true});linkTimes.value += 1;uni.createBLEConnection({deviceId: item.deviceId,success(res) {linkStatus.value = true;failTimes.value = 0;uni.showToast({title: '蓝牙已连接',mask: true});onBLEConnectionStateChange(item);},fail(res) {linkStatus.value = false;plus.device.vibrate(500);if (failTimes.value < failLimit) {failTimes.value += 1;uni.showToast({title: item.name + '蓝牙连接失败',icon: 'none'});reLink(item);} else {closeBlueTooth(item, () => {uni.showToast({title: item.name + '蓝牙连接失败,取消连接',icon: 'none'});});}}});
};
// 监听蓝牙状态
const onBLEConnectionStateChange = (item: any) => {uni.onBLEConnectionStateChange((res) => {m_Debounce(() => {if (!res.connected && isSignIn) {reLink(item);}}, 500);});
};
// 蓝牙重连
const reLink = (item: any) => {closeBlueTooth(item, () => {let t: any = setTimeout(() => {clearTimeout(t);t = null;openBluetoothAdapter(() => {createBLEConnection(item);});}, 1000);});
};// 关闭连接+关闭蓝牙模块
const closeBlueTooth = (item: any, callback: Function) => {// 关闭连接uni.closeBLEConnection({deviceId: item.deviceId,complete: () => {// 关闭蓝牙模块uni.closeBluetoothAdapter({complete: () => {callback();}});}});
};// 停止搜索
const stopBluetoothDevicesDiscovery = (callback: Function) => {uni.stopBluetoothDevicesDiscovery({complete: (e) => {callback();},fail: (e) => {console.log('停止搜索蓝牙设备失败,错误码:' + e.errCode);}});
};
// 后退
const navigateBack = () => {uni.navigateBack({delta: 1,fail: () => {uni.reLaunch({url: '/pages/home/home'});}});
};
http://www.yayakq.cn/news/66285/

相关文章:

  • 做网站必须要有数据库重庆企业网站开发方案
  • 企业网站建设成本费用如何建设社交网站
  • 佛山外贸网站建设公司简单免费制作手机网站
  • 做标志的好网站论文网站建设目标
  • 昆明做网站网站网站怎么搭建
  • 网站前端是做啥的重庆教育集团建设公司网站
  • 廊坊做网站费用安徽创誉建设工程有限公司网站
  • c h5网站开发云编辑wordpress
  • 影楼网站源码php网站开发培训深圳
  • 网站年报公示怎么做google搜索下载
  • 网站参考页面设计建筑网站招聘
  • 禅城区建设局网站中华室内设计协会
  • 做视频的免费素材网站如何做漂亮的网站首页
  • 汕头企业网站建设wordpress上传大文件
  • 重庆在线网站推广中国域名查询网
  • 网站做优化有效吗中国设计网官网图标
  • 全媒体门户网站建设wordpress小工具不能完全显示
  • 亦庄网站建设公司wordpress网站鼠标
  • 南宁建设集团招聘信息网站网站建设公众号开
  • 佛山快速建站哪家服务专业网络排名优化软件
  • 企业网站建设的可行性分析炫酷做网站背景图
  • 深圳模板建站企业北京常规网络营销电话
  • 专业网站制作电话协会网站建设计划书
  • 旅游网站建设方案简介网站建设之后
  • 公司网站策划方案网站的模块
  • 白沙网站建设的基本情况小程序的网址
  • 移动微网站开发重庆网站的网络推广
  • 株洲网站制作建设wordpress mysql 设置
  • 海安企业网站建设汕头小程序定制
  • 电子商务网站的构建青浦做网站公司