完成008A功能开发
This commit is contained in:
@ -2,7 +2,7 @@
|
||||
<view class="content">
|
||||
<view class="deviceDetail">
|
||||
<view class="imgContent">
|
||||
<image src="/static/images/BLEAdd/addBleDevice.png" class="titleIco" mode="aspectFit">
|
||||
<image src="/static/images/common/svg.png" class="titleIco" mode="aspectFit">
|
||||
</image>
|
||||
</view>
|
||||
<view class="deviceName">
|
||||
@ -46,7 +46,7 @@
|
||||
var these = null;
|
||||
var eventChannel = null;
|
||||
var ble = null;
|
||||
var inteval=null;
|
||||
var inteval = null;
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
@ -54,8 +54,8 @@
|
||||
bound: null,
|
||||
timeInteval: null,
|
||||
isSearch: false,
|
||||
pageHide:false,
|
||||
isBind:false
|
||||
pageHide: false,
|
||||
isBind: false
|
||||
},
|
||||
device: {
|
||||
"deviceId": "",
|
||||
@ -72,9 +72,9 @@
|
||||
"imei": ""
|
||||
},
|
||||
serverDevice: null,
|
||||
groupid:null,
|
||||
typeList:[],
|
||||
uploadStatu:null
|
||||
groupid: null,
|
||||
typeList: [],
|
||||
uploadStatu: null
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
@ -110,54 +110,54 @@
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
return "找到有效设备"
|
||||
|
||||
|
||||
|
||||
return "找到有效设备"
|
||||
|
||||
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
},
|
||||
onShow() {
|
||||
this.Statu.pageHide=false;
|
||||
this.Statu.pageHide = false;
|
||||
},
|
||||
onHide() {
|
||||
this.Statu.pageHide=true;
|
||||
this.Statu.pageHide = true;
|
||||
},
|
||||
onUnload() {
|
||||
console.log("返回取消订阅");
|
||||
clearInterval(inteval);
|
||||
ble.removeAllCallback(pagePath);
|
||||
clearTimeout(this.Statu.timeInteval);
|
||||
this.uploadStatu=null;
|
||||
if(!this.Statu.isBind && these.device.deviceId){
|
||||
ble.disconnectDevice(these.device.deviceId).catch(ex=>{
|
||||
this.uploadStatu = null;
|
||||
if (!this.Statu.isBind && these.device.deviceId) {
|
||||
ble.disconnectDevice(these.device.deviceId).catch(ex => {
|
||||
console.error("无法断开蓝牙连接");
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
onLoad(option) {
|
||||
these = this;
|
||||
this.groupid=new Date().getTime()+"";
|
||||
|
||||
this.groupid = new Date().getTime() + "";
|
||||
|
||||
ble = bleTool.getBleTool();
|
||||
|
||||
ble.addStateBreakCallback(res => {
|
||||
if(this.Statu.pageHide){
|
||||
if (this.Statu.pageHide) {
|
||||
return;
|
||||
}
|
||||
these.device.linkStatu = false;
|
||||
hideLoading(these);
|
||||
uni.showToast({
|
||||
icon:'fail',
|
||||
title:'蓝牙已不可用'
|
||||
icon: 'fail',
|
||||
title: '蓝牙已不可用'
|
||||
})
|
||||
},pagePath);
|
||||
|
||||
}, pagePath);
|
||||
|
||||
ble.addStateRecoveryCallback(res => {
|
||||
if(this.Statu.pageHide){
|
||||
if (this.Statu.pageHide) {
|
||||
return;
|
||||
}
|
||||
if (these.device.deviceId) {
|
||||
@ -167,9 +167,9 @@
|
||||
|
||||
these.reLinkdevice();
|
||||
}
|
||||
},pagePath);
|
||||
}, pagePath);
|
||||
ble.addDisposeCallback(res => {
|
||||
if(this.Statu.pageHide){
|
||||
if (this.Statu.pageHide) {
|
||||
return;
|
||||
}
|
||||
console.log("处理蓝牙断开连接");
|
||||
@ -181,59 +181,56 @@
|
||||
});
|
||||
these.reLinkdevice();
|
||||
}
|
||||
},pagePath);
|
||||
}, pagePath);
|
||||
|
||||
ble.addReceiveCallback((receive, f, path) => {
|
||||
if(this.Statu.pageHide){
|
||||
if (this.Statu.pageHide) {
|
||||
return;
|
||||
}
|
||||
console.log("收到设备消息,", receive);
|
||||
if (these.device.deviceId == receive.deviceId) {
|
||||
console.log("11111:", receive);
|
||||
these.device.imei = f.imei;
|
||||
let flag=false;
|
||||
if (receive.bytes && receive.bytes.length && receive.bytes[0] == 0xFC) {//6155 7305
|
||||
let flag = false;
|
||||
if (receive.bytes && receive.bytes.length && receive.bytes[0] == 0xFC) { //6155 7305
|
||||
if (f && f.macAddress) {
|
||||
flag=true;
|
||||
}
|
||||
}
|
||||
else if(receive.str.indexOf('mac address:') == 0){//650 670
|
||||
flag = true;
|
||||
}
|
||||
} else if (receive.str.indexOf('mac address:') == 0) { //650 670
|
||||
if (f && f.macAddress) {
|
||||
flag=true;
|
||||
}
|
||||
}
|
||||
else{
|
||||
try{
|
||||
console.log("str=",receive.str)
|
||||
let json=JSON.parse(receive.str);
|
||||
let key = "sta_address";
|
||||
if (key in json) {//100
|
||||
flag = true;
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
console.log("str=", receive.str)
|
||||
let json = JSON.parse(receive.str);
|
||||
let key = "sta_address";
|
||||
if (key in json) { //100
|
||||
if (f && f.macAddress) {
|
||||
flag=true;
|
||||
flag = true;
|
||||
}
|
||||
}
|
||||
}catch(err){
|
||||
console.log("出现异常,",err);
|
||||
} catch (err) {
|
||||
console.log("出现异常,", err);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(flag){
|
||||
|
||||
|
||||
if (flag) {
|
||||
these.device.macAddress = f.macAddress;
|
||||
console.log("222222");
|
||||
these.Statu.isSearch = false;
|
||||
these.initDevice();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}, pagePath);
|
||||
eventChannel = this.getOpenerEventChannel();
|
||||
|
||||
if(option.mac){
|
||||
this.device.macAddress=option.mac;
|
||||
|
||||
if (option.mac) {
|
||||
this.device.macAddress = option.mac;
|
||||
these.initDevice();
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
eventChannel.on('LinkItem', function(data) {
|
||||
console.log("data=", data);
|
||||
let f = ble.data.LinkedList.find((v) => {
|
||||
@ -244,126 +241,140 @@
|
||||
keys.forEach((v, index) => {
|
||||
these.device[v] = f[v];
|
||||
})
|
||||
these.device.name = data.name;
|
||||
// console.log("LinkedList=", ble.data.LinkedList)
|
||||
// console.log("f=", f);
|
||||
// console.log("获取到设备", these.device);
|
||||
console.log("获取到设备", these.device);
|
||||
if (f.macAddress) {
|
||||
these.device.macAddress = f.macAddress;
|
||||
|
||||
|
||||
these.initDevice();
|
||||
}
|
||||
} else {
|
||||
console.log("未获取到设备");
|
||||
}
|
||||
})
|
||||
|
||||
inteval = setInterval(this.initDevice, 10000);
|
||||
|
||||
inteval = setInterval(this.initDevice, 10000);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
},
|
||||
methods: {
|
||||
getDevList() {
|
||||
return new Promise((resolve,reject)=>{
|
||||
return new Promise((resolve, reject) => {
|
||||
let arr = [
|
||||
|
||||
];
|
||||
request({
|
||||
url: '/app/xinghan/device/typeAll',
|
||||
method: 'get'
|
||||
}).then(res => {
|
||||
if (res && res.code == 200) {
|
||||
console.log("获取到类型", res.data);
|
||||
arr = res.data;
|
||||
this.typeList = arr;
|
||||
resolve(arr);
|
||||
return;
|
||||
}
|
||||
reject();
|
||||
|
||||
}).catch(ex => {
|
||||
console.error("获取设备类型列表失败",ex);
|
||||
reject();
|
||||
})
|
||||
});
|
||||
|
||||
},
|
||||
uploadItem() {
|
||||
if(this.uploadStatu!==null){
|
||||
console.error("执行过上传,不再执行");
|
||||
return;
|
||||
}
|
||||
|
||||
this.uploadStatu="start";
|
||||
console.log("开始上传设备");
|
||||
|
||||
let type=this.device.name.toLowerCase();
|
||||
if(type.indexOf("bjq6155-")>-1){//6155特别处理
|
||||
type="xh6155"
|
||||
}
|
||||
if(type.indexOf("bjq6155-")>-1){//6155特别处理
|
||||
type="xh6155"
|
||||
}
|
||||
if(type.indexOf("bjq6075-")>-1){//6075j特别处理
|
||||
bype='bjq6075j';
|
||||
}
|
||||
type=type.replace(/-/g,'');
|
||||
let upload=()=>{
|
||||
let f=this.typeList.find((v,i)=>{
|
||||
if(type.indexOf(v.typeName.replace(/-/g,'').toLowerCase())>-1){
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
if(!f){
|
||||
this.uploadStatu="type is valid";
|
||||
console.error("找不到此类型名称",type);
|
||||
console.error("tpelist=",this.typeList);
|
||||
return;
|
||||
}
|
||||
let json = {
|
||||
"deviceType": f.id,
|
||||
"deviceName": this.device.name,
|
||||
"deviceMac": this.device.macAddress,
|
||||
"bluetoothName": this.device.name,
|
||||
"deviceImei":this.device.imei?this.device.imei:'',
|
||||
"remark": "com.chxhyc.cn auto upload"
|
||||
}
|
||||
|
||||
];
|
||||
request({
|
||||
url: '/app/xinghan/device/add',
|
||||
method: 'post',
|
||||
data: json
|
||||
url: '/app/xinghan/device/typeAll',
|
||||
method: 'get'
|
||||
}).then(res => {
|
||||
if (res && res.code == 200) {
|
||||
this.uploadStatu="success";
|
||||
console.log("上传成功",res);
|
||||
} else {
|
||||
this.uploadStatu="upload error";
|
||||
console.error("上传失败,",res);
|
||||
console.log("获取到类型", res.data);
|
||||
arr = res.data;
|
||||
this.typeList = arr;
|
||||
resolve(arr);
|
||||
return;
|
||||
}
|
||||
reject();
|
||||
|
||||
}).catch(ex => {
|
||||
this.uploadStatu="upload error";
|
||||
console.error("上传失败,",ex);
|
||||
});
|
||||
}
|
||||
|
||||
let exec = () => {
|
||||
|
||||
if(this.typeList.length==0){
|
||||
this.getDevList().then(results=>{
|
||||
upload();
|
||||
}).catch(ex=>{
|
||||
this.uploadStatu="get types error";
|
||||
console.error("获取类型失败,",ex);
|
||||
});
|
||||
}else{
|
||||
upload();
|
||||
console.error("获取设备类型列表失败", ex);
|
||||
reject();
|
||||
})
|
||||
});
|
||||
|
||||
},
|
||||
uploadItem() {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (this.uploadStatu !== null) {
|
||||
let err = "执行过上传,不再执行";
|
||||
console.error(err);
|
||||
reject(err);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
setTimeout(exec, 10)
|
||||
|
||||
this.uploadStatu = "start";
|
||||
console.log("开始上传设备");
|
||||
|
||||
let type = this.device.name.toLowerCase();
|
||||
|
||||
if (type.indexOf("bjq6155-") > -1) { //6155特别处理
|
||||
type = "xh6155"
|
||||
}
|
||||
if (type.indexOf("bjq6075-") > -1) { //6075j特别处理
|
||||
type = 'bjq6075j';
|
||||
}
|
||||
type = type.replace(/-/g, '');
|
||||
let upload = () => {
|
||||
let f = this.typeList.find((v, i) => {
|
||||
if (type.indexOf(v.typeName.replace(/-/g, '').toLowerCase()) > -1) {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
if (!f) {
|
||||
this.uploadStatu = "type is valid";
|
||||
console.error("找不到此类型名称", type);
|
||||
console.error("tpelist=", this.typeList);
|
||||
reject(this.uploadStatu);
|
||||
return;
|
||||
}
|
||||
let json = {
|
||||
"deviceType": f.id,
|
||||
"deviceName": this.device.name,
|
||||
"deviceMac": this.device.macAddress,
|
||||
"bluetoothName": this.device.name,
|
||||
"remark": "com.chxhyc.cn auto upload"
|
||||
}
|
||||
|
||||
if (this.device.imei) {
|
||||
json.deviceImei = this.device.imei;
|
||||
}
|
||||
request({
|
||||
url: '/app/xinghan/device/add',
|
||||
method: 'post',
|
||||
data: json
|
||||
}).then(res => {
|
||||
if (res && res.code == 200) {
|
||||
this.uploadStatu = "success";
|
||||
console.log("上传成功", res);
|
||||
resolve();
|
||||
} else {
|
||||
this.uploadStatu = "upload error";
|
||||
console.error("上传失败,", res);
|
||||
console.error("上传失败,", json);
|
||||
reject(this.uploadStatu);
|
||||
}
|
||||
}).catch(ex => {
|
||||
this.uploadStatu = "upload error";
|
||||
console.error("上传失败,", ex);
|
||||
reject(this.uploadStatu);
|
||||
});
|
||||
}
|
||||
|
||||
let exec = () => {
|
||||
|
||||
if (this.typeList.length == 0) {
|
||||
this.getDevList().then(results => {
|
||||
upload();
|
||||
}).catch(ex => {
|
||||
this.uploadStatu = "get types error";
|
||||
console.error("获取类型失败,", ex);
|
||||
reject(this.uploadStatu);
|
||||
});
|
||||
} else {
|
||||
upload();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
setTimeout(exec, 10)
|
||||
});
|
||||
|
||||
|
||||
},
|
||||
reLinkdevice() {
|
||||
ble.LinkBlue(these.device.deviceId).then(res => {
|
||||
@ -388,10 +399,10 @@
|
||||
return;
|
||||
}
|
||||
//无效的设备回调
|
||||
let deviceInvalid = () => {
|
||||
these.$set(these.device, "deviceName", "");
|
||||
|
||||
|
||||
let deviceInvalid = () => {
|
||||
these.$set(these.device, "deviceName", "");
|
||||
|
||||
|
||||
}
|
||||
clearTimeout(this.Statu.timeInteval);
|
||||
|
||||
@ -427,10 +438,16 @@
|
||||
clearInterval(inteval);
|
||||
} else {
|
||||
deviceInvalid();
|
||||
this.uploadItem();
|
||||
if (this.uploadStatu==null) {
|
||||
this.uploadItem().then(res => {
|
||||
this.initDevice();
|
||||
}).catch(err => {
|
||||
console.error("上传失败", err);
|
||||
});
|
||||
}
|
||||
}
|
||||
} else {
|
||||
this.serverDevice =null;
|
||||
this.serverDevice = null;
|
||||
deviceInvalid();
|
||||
}
|
||||
|
||||
@ -447,15 +464,67 @@
|
||||
},
|
||||
Bind() {
|
||||
// 调用绑定设备接口
|
||||
|
||||
// let f = ble.data.LinkedList.find((v) => {
|
||||
// return v.deviceId == these.device.deviceId;
|
||||
// });
|
||||
// if (!f) {
|
||||
// these.Statu.bound = false;
|
||||
// these.Statu.boundRemark = "蓝牙连接不成功";
|
||||
// return;
|
||||
// }
|
||||
|
||||
let task = () => {
|
||||
these.Statu.bound = null;
|
||||
these.Statu.boundRemark = "";
|
||||
showLoading(these, {
|
||||
|
||||
text: "绑定中..."
|
||||
})
|
||||
let promise = request({
|
||||
url: '/app/device/bind',
|
||||
method: 'POST',
|
||||
data: {
|
||||
deviceImei: '',
|
||||
deviceMac: these.device.macAddress,
|
||||
communicationMode: 1, //0是4g,1是蓝牙,2蓝牙&4G
|
||||
}
|
||||
});
|
||||
promise.then((res) => {
|
||||
console.log("1111" + JSON.stringify(res));
|
||||
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);
|
||||
clearTimeout(this.Statu.timeInteval);
|
||||
this.device.macAddress = null;
|
||||
this.Statu.timeInteval = null;
|
||||
this.Statu.isBind = true;
|
||||
uni.$emit("refreshDeviceList");
|
||||
setTimeout(() => {
|
||||
uni.switchTab({
|
||||
url: "/pages/common/index/index"
|
||||
});
|
||||
}, 500);
|
||||
} else {
|
||||
these.Statu.bound = false;
|
||||
these.Statu.boundRemark = res.msg;
|
||||
}
|
||||
}).catch((ex) => {
|
||||
these.Statu.bound = false;
|
||||
these.Statu.boundRemark = '出现了未知的异常,操作失败';
|
||||
console.log("ex=", ex);
|
||||
}).finally(() => {
|
||||
hideLoading(this);
|
||||
});
|
||||
}
|
||||
if (!this.device.macAddress) {
|
||||
these.Statu.bound = false;
|
||||
these.Statu.boundRemark = "获取设备Mac地址异常";
|
||||
@ -466,64 +535,9 @@
|
||||
these.Statu.boundRemark = "设备未入库";
|
||||
return;
|
||||
}
|
||||
these.Statu.bound = null;
|
||||
these.Statu.boundRemark = "";
|
||||
showLoading(these, {
|
||||
|
||||
text: "绑定中..."
|
||||
})
|
||||
let promise = request({
|
||||
url: '/app/device/bind',
|
||||
method: 'POST',
|
||||
data: {
|
||||
deviceImei: '',
|
||||
deviceMac: these.device.macAddress,
|
||||
communicationMode: 1, //0是4g,1是蓝牙,2蓝牙&4G
|
||||
}
|
||||
});
|
||||
promise.then((res) => {
|
||||
console.log("1111" + JSON.stringify(res));
|
||||
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];
|
||||
}
|
||||
task();
|
||||
|
||||
ble.updateCache();
|
||||
}
|
||||
});
|
||||
|
||||
ble.removeReceiveCallback(pagePath);
|
||||
clearTimeout(this.Statu.timeInteval);
|
||||
this.device.macAddress = null;
|
||||
this.Statu.timeInteval = null;
|
||||
this.Statu.isBind=true;
|
||||
uni.$emit("refreshDeviceList");
|
||||
setTimeout(() => {
|
||||
uni.switchTab({
|
||||
url: "/pages/common/index/index"
|
||||
});
|
||||
}, 500);
|
||||
} else {
|
||||
these.Statu.bound = false;
|
||||
these.Statu.boundRemark = res.msg;
|
||||
}
|
||||
}).catch((ex) => {
|
||||
these.Statu.bound = false;
|
||||
these.Statu.boundRemark = '出现了未知的异常,操作失败';
|
||||
console.log("ex=", ex);
|
||||
}).finally(() => {
|
||||
hideLoading(this);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user