1
0
forked from dyf/APP
This commit is contained in:
fengerli
2025-09-18 14:20:11 +08:00
34 changed files with 34422 additions and 6977 deletions

View File

@ -12,14 +12,14 @@
设备名:{{device.deviceName}}
</view>
<view class="deviceId">
ID:{{device.deviceId}}
设备Mac:{{device.macAddress}}
</view>
<view class="bound" v-bind:class="boundStatu">
{{Statu.boundRemark}}
</view>
</view>
<view class="btnLink" @click="Link()">
连接
绑定
</view>
<global-loading ref="loading" />
@ -34,12 +34,13 @@
hideLoading,
updateLoading
} from '@/utils/loading.js';
const pagePath="pages/common/addBLE/LinkBle";
const pagePath = "pages/common/addBLE/LinkBle";
var these = null;
var eventChannel = null;
var ble = null;
var timeInteval = null;
export default {
data() {
return {
@ -57,7 +58,8 @@
],
"linkStatu": false,
"macAddress": ""
}
},
serverDevice:null
}
},
computed: {
@ -84,92 +86,105 @@
onLoad(option) {
these = this;
ble = bleTool.getBleTool();
ble.addReceiveCallback((receive,f,path) => {
console.log("LinkBle")
ble.addReceiveCallback((receive, f, path) => {
console.log("收到设备消息,", receive);
if (these.device.deviceId == receive.deviceId) {
// console.log("11111");
console.log("11111:",receive);
if (receive.bytes[0] == 0xFC || receive.str.indexOf('mac address:') == 0) {
if (f && f.macAddress) {
these.device.macAddress = f.macAddress;
// console.log("222222");
console.log("222222");
these.initDevice();
}
}
}
},pagePath);
}, pagePath);
eventChannel = this.getOpenerEventChannel();
eventChannel.on('LinkItem', function(data) {
console.log("data=",data);
console.log("data=", data);
let f = ble.data.LinkedList.find((v) => {
return v.deviceId == data.deviceId;
});
if (f) {
let keys=Object.keys(f);
keys.forEach((v,index)=>{
these.device[v]=f[v];
let keys = Object.keys(f);
keys.forEach((v, index) => {
these.device[v] = f[v];
})
console.log("LinkedList=",ble.data.LinkedList)
console.log("f=", f);
console.log("LinkedList=", ble.data.LinkedList)
console.log("f=", f);
console.log("获取到设备", these.device);
if (f.macAddress) {
these.device.macAddress = f.macAddress;
these.initDevice();
}
these.device.macAddress = f.macAddress;
these.initDevice();
}
} else {
console.log("未获取到设备");
}
})
// let inteval = setInterval(this.initDevice, 5000);
},
methods: {
initDevice: function() {
showLoading(these, {
text: '正在获取设备信息'
});
console.log("these.device=",these.device);
request({
url: '/app/device/getDeviceInfoByDeviceMac',
method: 'GET',
data: {
deviceMac: these.device.macAddress
}
}).then(res => {
console.log("获取设备信息", res);
if (res && res.code == 200) {
let data = res.data;
if (data) {
let keys = Object.keys(data);
ble.data.LinkedList.find((v) => {
if(v.deviceId == these.device.deviceId){
for (var i = 0; i < keys.length; i++) {
let key = keys[i];
v[key] = data[key];
// console.log("key="+key);
// console.log("value="+data[key]);
these.$set(these.device, key, data[key]);
}
ble.setBleData();
}
});
console.log("device=",these.device);
console.log("LinkedList=",ble.data.LinkedList);
clearTimeout(timeInteval);
timeInteval = setTimeout(() => {
showLoading(these, {
text: '正在获取设备信息'
});
console.log("these.device=", these.device);
request({
url: '/app/device/getDeviceInfoByDeviceMac',
method: 'GET',
data: {
deviceMac: these.device.macAddress
}
}
}).then(res => {
console.log("获取设备信息", res);
if (res && res.code == 200) {
let data = res.data;
this.serverDevice=data;
if (data) {
let keys = Object.keys(data);
ble.data.LinkedList.find((v) => {
if (v.deviceId == these.device.deviceId) {
for (var i = 0; i < keys.length; i++) {
let key = keys[i];
// if(!v.device){
// v.device={};
// }
// v.device[key] = data[key];
// console.log("key="+key);
// console.log("value="+data[key]);
these.$set(these.device, key, data[key]);
}
// ble.setBleData();
}
});
console.log("device=", these.device);
console.log("LinkedList=", ble.data.LinkedList);
}
}
}).catch((ex) => {
console.log("获取设备出现异常:", ex);
}).finally(() => {
hideLoading(these);
});
}, 500);
}).catch((ex) => {
console.log("获取设备出现异常:", ex);
}).finally(() => {
hideLoading(these);
});
},
Link() {
// 调用绑定设备接口
@ -207,6 +222,22 @@
if (res.code == 200) {
these.Statu.bound = true;
these.Statu.boundRemark = "设备绑定成功!";
let data=these.serverDevice;
let keys = Object.keys(data);
ble.data.LinkedList.find((v) => {
if (v.deviceId == these.device.deviceId) {
for (var i = 0; i < keys.length; i++) {
let key = keys[i];
if(!v.device){
v.device={};
}
v.device[key] = data[key];
}
ble.updateCache();
}
});
ble.removeReceiveCallback(pagePath);
uni.$emit("refreshDeviceList");
@ -222,6 +253,7 @@
}).catch((ex) => {
these.Statu.bound = false;
these.Statu.boundRemark = '出现了未知的异常,操作失败';
console.log("ex=",ex);
}).finally(() => {
hideLoading(this);
});

View File

@ -97,6 +97,7 @@
const pagePath="pages/common/addBLE/addEquip";
var ble = null;
var these = null;
var eventChannel=null;
export default {
data() {
return {
@ -128,7 +129,11 @@
},
PairEquip: [], //已配对设备
EquipMents: [] //搜索出来的设备
EquipMents: [], //搜索出来的设备
device:null,
item:{
deviceId:''
}
}
},
computed: {
@ -145,7 +150,8 @@
},
onUnload(){
ble.StopSearch();
ble.removeDeviceFound(pagePath);
ble.removeReceiveCallback(pagePath);
},
onLoad() {
these = this;
@ -170,13 +176,23 @@
}
}
},pagePath);
// ble.addReceiveCallback((receivData) => {
}, pagePath);
// console.log("addEquip")
// ble.addReceiveCallback((receivData,f,path,arr) => {
// console.log("收到数据了:", receivData);//数据格式:{bytes:[109,97],str:"",hexs:"FA 01"}
// if (this.item.deviceId == receivData.deviceId) {
// console.log("11111:",receivData);
// // let data=uni.getStorageSync(ble.StorageKey);
// console.log("LinkedList=",ble.data.LinkedList);
// },pagePath);
// }
// });
eventChannel = this.getOpenerEventChannel();
eventChannel.on('detailData', function(rec) {
console.log("接收到父页面的参数:",rec);
these.device=rec.data;
});
},
onShow: function() {
@ -223,7 +239,7 @@
ble.showBlueSetting(false);
},
Link: function(item, index) {
this.item.deviceId=item.deviceId;
showLoading(this,{
text: "正在连接"
});
@ -241,6 +257,18 @@
these.PairEquip.push(item);
}
console.log("连接成功");
if(these.device){//从设备详情过来的,回设备详情去
ble.data.LinkedList.find(v=>{
if(v.deviceId==item.deviceId){
v.device=these.device;
return true;
}
return false;
});
ble.updateCache();
uni.navigateBack();
return;
}
uni.navigateTo({
url:"/pages/common/addBLE/LinkBle",
events:{

View File

@ -144,6 +144,8 @@
deviceUnbind, //删除设备
deviceReName
} from '@/api/common/index.js'
import BleHelper from '@/utils/BleHelper.js';
var ble=null;
export default {
onPullDownRefresh() {
// 执行下拉刷新时的操作,比如重新获取数据
@ -388,7 +390,9 @@
}, 500);
this.deleteShow = false
// 关闭所有滑动项
this.$refs.swipeAction.closeAll();
this.$refs.swipeAction.closeAll();
ble && ble.DropDevice(data.id);
} else {
uni.showToast({
title: res.msg,
@ -555,6 +559,7 @@
console.log('列表收到消息了么');
this.onIntall()
});
ble=BleHelper.getBleTool();
},
beforeDestroy() {
// 组件销毁前移除监听器