修改App图标、名称、蓝牙加入断线重连
This commit is contained in:
@ -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,11 +86,11 @@
|
||||
onLoad(option) {
|
||||
these = this;
|
||||
ble = bleTool.getBleTool();
|
||||
ble.addReceiveCallback((receive,f,path) => {
|
||||
ble.addReceiveCallback((receive, f, path) => {
|
||||
console.log("收到设备消息,", receive);
|
||||
if (these.device.deviceId == receive.deviceId) {
|
||||
// console.log("11111");
|
||||
|
||||
|
||||
if (receive.bytes[0] == 0xFC || receive.str.indexOf('mac address:') == 0) {
|
||||
if (f && f.macAddress) {
|
||||
these.device.macAddress = f.macAddress;
|
||||
@ -97,79 +99,91 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
},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 +221,21 @@
|
||||
if (res.code == 200) {
|
||||
these.Statu.bound = true;
|
||||
these.Statu.boundRemark = "设备绑定成功!";
|
||||
|
||||
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.setBleData();
|
||||
}
|
||||
});
|
||||
|
||||
ble.removeReceiveCallback(pagePath);
|
||||
|
||||
uni.$emit("refreshDeviceList");
|
||||
|
||||
Reference in New Issue
Block a user