必应搜索网站,建网站公司销售,设计类专业选科要求,企业营销策划案例分析1.需求#xff1a;3.0的桩可以值扫码通过蓝牙名字直接绑定#xff0c;2.0的桩二维码无蓝牙名称则需通过蓝牙列表来绑定 2.碰到问题 1.0 蓝牙列表需要去重#xff08;蓝牙列表通过deviceId去重再放进展示列表#xff09; 2.0页面会卡顿#xff08;调用my.stopBluetoothDevi…1.需求3.0的桩可以值扫码通过蓝牙名字直接绑定2.0的桩二维码无蓝牙名称则需通过蓝牙列表来绑定 2.碰到问题 1.0 蓝牙列表需要去重蓝牙列表通过deviceId去重再放进展示列表 2.0页面会卡顿调用my.stopBluetoothDevicesDiscovery() 3.特别注意点 4.代码
templateview styleheight:100vh;padding-top: 40rpx;view classtitleHead请选择蓝牙设备绑定/viewview classtable-body touchmovemoveview classtable-item v-for(item,index) in bluetoothList :keyindex clickselectBluetooth(item){{item.name}}/view/viewview classbottom-titleview设备名称规则:ZDBT桩编码后9位/viewview例:ZDBT000000V01/view/view/view
/templatescriptexport default {onShow() {this.initBluetooth()},onLoad() {},onUnload() {my.offBluetoothDeviceFound();my.closeBluetoothAdapter({success: function(res) {console.log(res);},fail: function(err) {console.log(err);}});},onHide() {my.offBluetoothDeviceFound();my.closeBluetoothAdapter({success: function(res) {console.log(res);},fail: function(err) {console.log(err);}});},onPullDownRefresh() {uni.showToast({title: 正在刷新...})this.connectBluetooth()},components: {// timePicker},data() {return {tipShow: false,show: false,msg: ,pendingShow: false,successShow: false,timer: null,count: 3,bluetoothList: [],idList:[],//存放设备deviceId数组 去重}},methods: {goService() {this.tipShow true;},// clickFla(){// my.stopPullDownRefresh()// my.offBluetoothDeviceFound();// },move() {my.stopPullDownRefresh()my.offBluetoothDeviceFound();my.stopBluetoothDevicesDiscovery();},/*选中蓝牙*/selectBluetooth(item) {my.stopPullDownRefresh()my.offBluetoothDeviceFound();my.stopBluetoothDevicesDiscovery({success: (res) {my.closeBluetoothAdapter();uni.reLaunch({url: /pages/bluetoothList/index?name item.name})},fail: (error) {console.log(error);},});},/*蓝牙初始化*/initBluetooth() {console.log(蓝牙初始化)let that this;my.openBluetoothAdapter({success: res {console.log(蓝牙初始化)console.log(res)console.log(蓝牙初始化)if (!res.isSupportBLE) {uni.showToast({title: 抱歉您的手机蓝牙暂不可用})return;}that.connectBluetooth()},fail: error {uni.showToast({title: JSON.stringify(error.errorMessage)})},});},/*搜索连接蓝牙*/connectBluetooth() {console.log(开始搜索蓝牙)let that this;let list []//启用下拉刷新my.startPullDownRefresh({success: function(res) {console.log(res);},fail: function(err) {console.log(err);}});my.startBluetoothDevicesDiscovery({success() {my.onBluetoothDeviceFound(res {var deviceArray res.devices;for (let item of deviceArray) {if (item.name ! undefined item.name ! null) {if (that.idList.indexOf(item[deviceId]) -1) {//数组去重that.idList.push(item[deviceId])that.bluetoothList.push(item)}}}//10秒后停止搜索释放系统资源let timer setTimeout(() {my.stopBluetoothDevicesDiscovery()my.stopPullDownRefresh()clearTimeout(timer)}, 10000);})}})}},}
/scriptstyle langscss scoped.titleHead {width: 100%;height: 66rpx;font-size: 48rpx;font-family: PingFangSC-Semibold, PingFang SC;font-weight: 600;color: #2D3748;line-height: 66rpx;margin: 0 50rpx 0 50rpx;}.table-body {display: flex;flex-direction: column;align-items: center;margin-top: 30rpx;height: calc(100vh - 350rpx);overflow: scroll;.table-item {width: 650rpx;height: 90rpx;line-height: 90rpx;background: #FFFFFF;box-shadow: 0rpx 0rpx 30rpx 14rpx rgba(236, 235, 236, 0.25);border-radius: 45rpx;padding-left: 50rpx;margin-bottom: 20rpx;}.table-active {width: 650rpx;height: 90rpx;background: #1677FF;color: #FFFFFF;box-shadow: 0rpx 0rpx 30rpx 14rpx rgba(236, 235, 236, 0.25);border-radius: 45rpx;padding-left: 50rpx;margin-bottom: 20rpx;}}.bottom-title {position: fixed;bottom: 100rpx;left: 50%;transform: translateX(-50%);font-size: 24rpx;font-family: PingFangSC-Regular, PingFang SC;font-weight: 400;color: #1677FF;line-height: 34rpx;view {text-align: center;}}
/style
5.效果