蓝牙小优化,App隐藏时断开设备连接
This commit is contained in:
29
App.vue
29
App.vue
@ -1,6 +1,7 @@
|
|||||||
<script>
|
<script>
|
||||||
import bleTool from '@/utils/BleHelper.js'
|
import bleTool from '@/utils/BleHelper.js';
|
||||||
import upgrade from '@/utils/update.js'
|
import upgrade from '@/utils/update.js';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
|
||||||
onLaunch: function() {
|
onLaunch: function() {
|
||||||
@ -30,10 +31,8 @@
|
|||||||
//以上代码仅在开发时使用,否则会出现不可预知的问题。
|
//以上代码仅在开发时使用,否则会出现不可预知的问题。
|
||||||
|
|
||||||
// #ifdef APP|APP-PLUS
|
// #ifdef APP|APP-PLUS
|
||||||
if (plus.runtime.isAgreePrivacy()) {
|
let initOS = () => {
|
||||||
|
let ble = bleTool.getBleTool();
|
||||||
|
|
||||||
bleTool.getBleTool();
|
|
||||||
|
|
||||||
uni.getPushClientId({
|
uni.getPushClientId({
|
||||||
success(res) {
|
success(res) {
|
||||||
@ -62,8 +61,13 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
if (plus.os.name == 'Android') {
|
||||||
|
if(plus.runtime.isAgreePrivacy()){
|
||||||
|
initOS();
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
initOS();
|
||||||
}
|
}
|
||||||
|
|
||||||
// #endif
|
// #endif
|
||||||
@ -81,9 +85,18 @@
|
|||||||
upgrade.checkAndUpdateWgt();
|
upgrade.checkAndUpdateWgt();
|
||||||
}
|
}
|
||||||
// #endif
|
// #endif
|
||||||
|
|
||||||
|
|
||||||
},
|
},
|
||||||
onHide: function() {
|
onHide: function() {
|
||||||
console.log('App Hide');
|
console.log('App Hide');
|
||||||
|
// #ifdef APP|APP-PLUS
|
||||||
|
let ble = bleTool.getBleTool();
|
||||||
|
if (ble) {
|
||||||
|
console.log("断开所有蓝牙设备");
|
||||||
|
ble.disconnectDevice();
|
||||||
|
}
|
||||||
|
// #endif
|
||||||
},
|
},
|
||||||
onError(ex) {
|
onError(ex) {
|
||||||
console.error("出现了未知的异常", ex);
|
console.error("出现了未知的异常", ex);
|
||||||
|
|||||||
@ -23,7 +23,7 @@
|
|||||||
paddingRight: config.dividerMargin
|
paddingRight: config.dividerMargin
|
||||||
}" @click="handleItemClick(item, index)">
|
}" @click="handleItemClick(item, index)">
|
||||||
|
|
||||||
<view class="p100" :style="{backgroundColor:(config.activeIndex==index || item[config.valueMember]==config.value) ?config.itemBgColor:'',
|
<view class="p100" :data-acIdx="config.activeIndex" :data-ac="config.activeIndex==index" :style="{backgroundColor:(config.activeIndex==index || (item[config.valueMember]==config.value && config.value) ) ?config.itemBgColor:'',
|
||||||
justifyContent:config.textAlign
|
justifyContent:config.textAlign
|
||||||
}">
|
}">
|
||||||
<view class="imgContent" v-if="item.icon" :style="{
|
<view class="imgContent" v-if="item.icon" :style="{
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
"name" : "星汉物联",
|
"name" : "星汉物联",
|
||||||
"appid" : "__UNI__A21EF43",
|
"appid" : "__UNI__A21EF43",
|
||||||
"description" : "设备管控",
|
"description" : "设备管控",
|
||||||
"versionName" : "1.0.19",
|
"versionName" : "1.0.22",
|
||||||
"versionCode" : 101,
|
"versionCode" : 101,
|
||||||
"transformPx" : false,
|
"transformPx" : false,
|
||||||
/* 5+App特有相关 */
|
/* 5+App特有相关 */
|
||||||
|
|||||||
@ -355,6 +355,15 @@
|
|||||||
},
|
},
|
||||||
onShow() {
|
onShow() {
|
||||||
this.Status.pageHide = false;
|
this.Status.pageHide = false;
|
||||||
|
|
||||||
|
let f = this.getDevice();
|
||||||
|
if (f) {
|
||||||
|
these.formData.bleStatu = 'connecting';
|
||||||
|
ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId).then(res => {
|
||||||
|
console.log("连接成功")
|
||||||
|
these.formData.bleStatu = true;
|
||||||
|
});
|
||||||
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
|
|
||||||
@ -363,9 +372,9 @@
|
|||||||
methods: {
|
methods: {
|
||||||
|
|
||||||
LighSetting(item, index) {
|
LighSetting(item, index) {
|
||||||
let val=item.key;
|
let val = item.key;
|
||||||
if (item.key === this.formData.sta_LedType) {
|
if (item.key === this.formData.sta_LedType) {
|
||||||
val='led_off';
|
val = 'led_off';
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -501,13 +510,13 @@
|
|||||||
|
|
||||||
},
|
},
|
||||||
deviceDispose(res) {
|
deviceDispose(res) {
|
||||||
if (this.Status.pageHide) {
|
// if (this.Status.pageHide) {
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
if (res.deviceId == these.formData.deviceId) {
|
if (res.deviceId == these.formData.deviceId) {
|
||||||
if(res.device){
|
if (res.device) {
|
||||||
these.formData.bleStatu = 'connecting';
|
these.formData.bleStatu = 'connecting';
|
||||||
}else{
|
} else {
|
||||||
this.formData.bleStatu = false;
|
this.formData.bleStatu = false;
|
||||||
}
|
}
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
|
|||||||
@ -519,7 +519,7 @@
|
|||||||
ble = BleTool.getBleTool();
|
ble = BleTool.getBleTool();
|
||||||
|
|
||||||
this.$watch("formData.sta_battery", (newVal, oldVal) => {
|
this.$watch("formData.sta_battery", (newVal, oldVal) => {
|
||||||
if (newVal <= 20 && this.formData.sta_system==2) {
|
if (newVal <= 20 && this.formData.sta_system == 2) {
|
||||||
this.showMsg("设备电量低");
|
this.showMsg("设备电量低");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -595,6 +595,15 @@
|
|||||||
},
|
},
|
||||||
onShow() {
|
onShow() {
|
||||||
this.Status.pageHide = false;
|
this.Status.pageHide = false;
|
||||||
|
|
||||||
|
let f = this.getDevice();
|
||||||
|
if (f) {
|
||||||
|
these.formData.bleStatu = 'connecting';
|
||||||
|
ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId).then(res => {
|
||||||
|
console.log("连接成功")
|
||||||
|
these.formData.bleStatu = true;
|
||||||
|
});
|
||||||
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
getbleStatu() {
|
getbleStatu() {
|
||||||
@ -1197,9 +1206,9 @@
|
|||||||
|
|
||||||
},
|
},
|
||||||
deviceDispose(res) {
|
deviceDispose(res) {
|
||||||
if (this.Status.pageHide) {
|
// if (this.Status.pageHide) {
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
if (res.deviceId == these.formData.deviceId) {
|
if (res.deviceId == these.formData.deviceId) {
|
||||||
if (res.device) {
|
if (res.device) {
|
||||||
these.formData.bleStatu = 'connecting';
|
these.formData.bleStatu = 'connecting';
|
||||||
|
|||||||
@ -509,6 +509,16 @@
|
|||||||
},
|
},
|
||||||
onShow() {
|
onShow() {
|
||||||
this.Status.pageHide = false;
|
this.Status.pageHide = false;
|
||||||
|
|
||||||
|
let f = this.getDevice();
|
||||||
|
if (f) {
|
||||||
|
these.formData.bleStatu = 'connecting';
|
||||||
|
ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId).then(res => {
|
||||||
|
console.log("连接成功")
|
||||||
|
these.formData.bleStatu = true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
this.getLinkedCnt();
|
this.getLinkedCnt();
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
@ -975,13 +985,13 @@
|
|||||||
|
|
||||||
},
|
},
|
||||||
deviceDispose(res) {
|
deviceDispose(res) {
|
||||||
if (this.Status.pageHide) {
|
// if (this.Status.pageHide) {
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
if (res.deviceId == these.formData.deviceId) {
|
if (res.deviceId == these.formData.deviceId) {
|
||||||
if(res.device){
|
if (res.device) {
|
||||||
these.formData.bleStatu = 'connecting';
|
these.formData.bleStatu = 'connecting';
|
||||||
}else{
|
} else {
|
||||||
this.formData.bleStatu = false;
|
this.formData.bleStatu = false;
|
||||||
}
|
}
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
|
|||||||
@ -574,6 +574,15 @@
|
|||||||
},
|
},
|
||||||
onShow() {
|
onShow() {
|
||||||
this.Status.pageHide = false;
|
this.Status.pageHide = false;
|
||||||
|
|
||||||
|
let f=this.getDevice();
|
||||||
|
if(f){
|
||||||
|
these.formData.bleStatu = 'connecting';
|
||||||
|
ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId).then(res => {
|
||||||
|
console.log("连接成功")
|
||||||
|
these.formData.bleStatu = true;
|
||||||
|
});
|
||||||
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
getbleStatu() {
|
getbleStatu() {
|
||||||
@ -1083,9 +1092,9 @@
|
|||||||
|
|
||||||
},
|
},
|
||||||
deviceDispose(res) {
|
deviceDispose(res) {
|
||||||
if (this.Status.pageHide) {
|
// if (this.Status.pageHide) {
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
if (res.deviceId == these.formData.deviceId) {
|
if (res.deviceId == these.formData.deviceId) {
|
||||||
if(res.device){
|
if(res.device){
|
||||||
these.formData.bleStatu = 'connecting';
|
these.formData.bleStatu = 'connecting';
|
||||||
|
|||||||
@ -599,9 +599,9 @@ import request, { baseURL } from '@/utils/request.js';
|
|||||||
|
|
||||||
},
|
},
|
||||||
deviceDispose(res) {
|
deviceDispose(res) {
|
||||||
if (this.Status.pageHide) {
|
//if (this.Status.pageHide) {
|
||||||
return;
|
// return;
|
||||||
}
|
//}
|
||||||
if (res.deviceId == these.formData.deviceId) {
|
if (res.deviceId == these.formData.deviceId) {
|
||||||
if(res.device){
|
if(res.device){
|
||||||
these.formData.bleStatu = 'connecting';
|
these.formData.bleStatu = 'connecting';
|
||||||
|
|||||||
@ -679,7 +679,7 @@
|
|||||||
}
|
}
|
||||||
let that = this;
|
let that = this;
|
||||||
uni.navigateTo({
|
uni.navigateTo({
|
||||||
url: "/pages/ImgCrop/ImgCrop",
|
url: "/pages/common/ImgCrop/ImgCrop",
|
||||||
events: {
|
events: {
|
||||||
ImgCutOverPath: function(data) {
|
ImgCutOverPath: function(data) {
|
||||||
that.selectedImage = data.picPath;
|
that.selectedImage = data.picPath;
|
||||||
|
|||||||
@ -486,6 +486,15 @@
|
|||||||
},
|
},
|
||||||
onShow() {
|
onShow() {
|
||||||
this.Status.pageHide = false;
|
this.Status.pageHide = false;
|
||||||
|
|
||||||
|
let f=this.getDevice();
|
||||||
|
if(f){
|
||||||
|
these.formData.bleStatu = 'connecting';
|
||||||
|
ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId).then(res => {
|
||||||
|
console.log("连接成功")
|
||||||
|
these.formData.bleStatu = true;
|
||||||
|
});
|
||||||
|
}
|
||||||
},
|
},
|
||||||
onHide: function() {
|
onHide: function() {
|
||||||
this.Status.pageHide = true;
|
this.Status.pageHide = true;
|
||||||
@ -1145,7 +1154,7 @@
|
|||||||
sourceType: ['album'],
|
sourceType: ['album'],
|
||||||
success: function(res) {
|
success: function(res) {
|
||||||
uni.navigateTo({
|
uni.navigateTo({
|
||||||
url: "/pages/ImgCrop/ImgCrop",
|
url: "/pages/common/ImgCrop/ImgCrop",
|
||||||
events: {
|
events: {
|
||||||
ImgCutOver: function(data) {
|
ImgCutOver: function(data) {
|
||||||
|
|
||||||
@ -2012,9 +2021,9 @@
|
|||||||
|
|
||||||
},
|
},
|
||||||
deviceDispose(res) {
|
deviceDispose(res) {
|
||||||
if (this.Status.pageHide) {
|
// if (this.Status.pageHide) {
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
if (res.deviceId == these.formData.deviceId) {
|
if (res.deviceId == these.formData.deviceId) {
|
||||||
if (res.device) {
|
if (res.device) {
|
||||||
these.formData.bleStatu = 'connecting';
|
these.formData.bleStatu = 'connecting';
|
||||||
|
|||||||
@ -433,6 +433,14 @@
|
|||||||
},
|
},
|
||||||
onShow() {
|
onShow() {
|
||||||
this.Status.pageHide = false;
|
this.Status.pageHide = false;
|
||||||
|
let f = this.getDevice();
|
||||||
|
if (f) {
|
||||||
|
these.formData.bleStatu = 'connecting';
|
||||||
|
ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId).then(res => {
|
||||||
|
console.log("连接成功")
|
||||||
|
these.formData.bleStatu = true;
|
||||||
|
});
|
||||||
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
|
|
||||||
@ -689,9 +697,9 @@
|
|||||||
|
|
||||||
},
|
},
|
||||||
deviceDispose(res) {
|
deviceDispose(res) {
|
||||||
if (this.Status.pageHide) {
|
//if (this.Status.pageHide) {
|
||||||
return;
|
// return;
|
||||||
}
|
//}
|
||||||
if (res.deviceId == these.formData.deviceId) {
|
if (res.deviceId == these.formData.deviceId) {
|
||||||
this.formData.bleStatu = false;
|
this.formData.bleStatu = false;
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
|
|||||||
@ -426,6 +426,15 @@
|
|||||||
},
|
},
|
||||||
onShow() {
|
onShow() {
|
||||||
this.Status.pageHide = false;
|
this.Status.pageHide = false;
|
||||||
|
|
||||||
|
let f=this.getDevice();
|
||||||
|
if(f){
|
||||||
|
these.formData.bleStatu = 'connecting';
|
||||||
|
ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId).then(res => {
|
||||||
|
console.log("连接成功")
|
||||||
|
these.formData.bleStatu = true;
|
||||||
|
});
|
||||||
|
}
|
||||||
},
|
},
|
||||||
onBackPress(e) {
|
onBackPress(e) {
|
||||||
|
|
||||||
@ -581,9 +590,9 @@
|
|||||||
|
|
||||||
},
|
},
|
||||||
deviceDispose(res) {
|
deviceDispose(res) {
|
||||||
if (this.Status.pageHide) {
|
// if (this.Status.pageHide) {
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
if (res.deviceId == these.formData.deviceId) {
|
if (res.deviceId == these.formData.deviceId) {
|
||||||
if(res.device){
|
if(res.device){
|
||||||
these.formData.bleStatu = 'connecting';
|
these.formData.bleStatu = 'connecting';
|
||||||
@ -909,7 +918,7 @@
|
|||||||
sourceType: ['album'],
|
sourceType: ['album'],
|
||||||
success: function(res) {
|
success: function(res) {
|
||||||
uni.navigateTo({
|
uni.navigateTo({
|
||||||
url: "/pages/ImgCrop/ImgCrop",
|
url: "/pages/common/ImgCrop/ImgCrop",
|
||||||
events: {
|
events: {
|
||||||
ImgCutOver: function(data) {
|
ImgCutOver: function(data) {
|
||||||
|
|
||||||
|
|||||||
@ -396,6 +396,15 @@
|
|||||||
},
|
},
|
||||||
onShow() {
|
onShow() {
|
||||||
this.Status.pageHide = false;
|
this.Status.pageHide = false;
|
||||||
|
|
||||||
|
let f=this.getDevice();
|
||||||
|
if(f){
|
||||||
|
these.formData.bleStatu = 'connecting';
|
||||||
|
ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId).then(res => {
|
||||||
|
console.log("连接成功")
|
||||||
|
these.formData.bleStatu = true;
|
||||||
|
});
|
||||||
|
}
|
||||||
},
|
},
|
||||||
onBackPress(e) {
|
onBackPress(e) {
|
||||||
|
|
||||||
@ -562,9 +571,9 @@
|
|||||||
|
|
||||||
},
|
},
|
||||||
deviceDispose(res) {
|
deviceDispose(res) {
|
||||||
if (this.Status.pageHide) {
|
// if (this.Status.pageHide) {
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
if (res.deviceId == these.formData.deviceId) {
|
if (res.deviceId == these.formData.deviceId) {
|
||||||
if(res.device){
|
if(res.device){
|
||||||
these.formData.bleStatu = 'connecting';
|
these.formData.bleStatu = 'connecting';
|
||||||
@ -926,7 +935,7 @@
|
|||||||
sourceType: ['album'],
|
sourceType: ['album'],
|
||||||
success: function(res) {
|
success: function(res) {
|
||||||
uni.navigateTo({
|
uni.navigateTo({
|
||||||
url: "/pages/ImgCrop/ImgCrop",
|
url: "/pages/common/ImgCrop/ImgCrop",
|
||||||
events: {
|
events: {
|
||||||
ImgCutOver: function(data) {
|
ImgCutOver: function(data) {
|
||||||
|
|
||||||
|
|||||||
@ -331,7 +331,7 @@
|
|||||||
var ble = null;
|
var ble = null;
|
||||||
var rec = null;
|
var rec = null;
|
||||||
|
|
||||||
var pagePath = "pages/6170/BJQ6170";
|
var pagePath = "/pages/6170/deviceControl/index";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
@ -498,9 +498,12 @@
|
|||||||
if (receive.deviceId !== this.formData.deviceId) {
|
if (receive.deviceId !== this.formData.deviceId) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let data = recei.ReceiveData(receive, device, pagePath, recArr);
|
let data = rec.ReceiveData(receive, device, pagePath, recArr);
|
||||||
console.log("蓝牙收到消息", data)
|
console.log("蓝牙收到消息", data)
|
||||||
this.receivData(data);
|
this.receivData(data);
|
||||||
|
},
|
||||||
|
receivData(data) {
|
||||||
|
|
||||||
},
|
},
|
||||||
bleStateBreak() {
|
bleStateBreak() {
|
||||||
if (this.Status.pageHide) {
|
if (this.Status.pageHide) {
|
||||||
@ -542,9 +545,9 @@
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
deviceDispose(res) {
|
deviceDispose(res) {
|
||||||
if (this.Status.pageHide) {
|
// if (this.Status.pageHide) {
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
if (res.deviceId == these.formData.deviceId) {
|
if (res.deviceId == these.formData.deviceId) {
|
||||||
if (res.device) {
|
if (res.device) {
|
||||||
these.formData.bleStatu = 'connecting';
|
these.formData.bleStatu = 'connecting';
|
||||||
@ -856,20 +859,26 @@
|
|||||||
})
|
})
|
||||||
uni.hideLoading();
|
uni.hideLoading();
|
||||||
}
|
}
|
||||||
|
}).catch(ex => {
|
||||||
|
console.error("ex=", ex);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ble && this.itemInfo.deviceMac) {
|
if (ble && this.itemInfo.deviceMac) {
|
||||||
|
console.log("111111")
|
||||||
let f = this.getDevice();
|
let f = this.getDevice();
|
||||||
if (f) {
|
if (f) {
|
||||||
|
console.log("222222");
|
||||||
let json = {
|
let json = {
|
||||||
instruct: [1, 0, 0, 0, 0]
|
instruct: [1, 0, 0, 0, 0]
|
||||||
};
|
};
|
||||||
json.instruct[1] = parseInt(selectedItem.instructValue);
|
json.instruct[1] = parseInt(selectedItem.instructValue);
|
||||||
|
|
||||||
ble.sendString(f.deviceId, json).then(res => {
|
ble.sendString(f.deviceId, json).then(res => {
|
||||||
|
console.log("ble send success")
|
||||||
|
this.lightModeA = false;
|
||||||
}).catch(ex => {
|
}).catch(ex => {
|
||||||
|
console.error("ble send fail,mqsending....")
|
||||||
mqSend();
|
mqSend();
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@ -979,7 +988,7 @@
|
|||||||
}
|
}
|
||||||
let that = this;
|
let that = this;
|
||||||
uni.navigateTo({
|
uni.navigateTo({
|
||||||
url: "/pages/ImgCrop/ImgCrop",
|
url: "/pages/common/ImgCrop/ImgCrop",
|
||||||
events: {
|
events: {
|
||||||
ImgCutOver: function(data) {
|
ImgCutOver: function(data) {
|
||||||
that.selectedImage = data.picPath;
|
that.selectedImage = data.picPath;
|
||||||
@ -990,6 +999,9 @@
|
|||||||
ev.eventChannel.emit('checkImg', {
|
ev.eventChannel.emit('checkImg', {
|
||||||
data: res.tempFiles[0].path,
|
data: res.tempFiles[0].path,
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
fail(ex) {
|
||||||
|
console.error("跳转失败", ex);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -1797,7 +1809,7 @@
|
|||||||
onLoad(options) {
|
onLoad(options) {
|
||||||
these = this;
|
these = this;
|
||||||
|
|
||||||
|
rec = BleReceive.getBleReceive();
|
||||||
const eventChannel = this.getOpenerEventChannel();
|
const eventChannel = this.getOpenerEventChannel();
|
||||||
// 监听 'detailData' 事件,获取传过来的数据
|
// 监听 'detailData' 事件,获取传过来的数据
|
||||||
uni.showLoading({
|
uni.showLoading({
|
||||||
@ -1815,7 +1827,7 @@
|
|||||||
// 根据 apiType 设置右图标的显示状态
|
// 根据 apiType 设置右图标的显示状态
|
||||||
this.isRightIconVisible = this.apiType === 'listA';
|
this.isRightIconVisible = this.apiType === 'listA';
|
||||||
|
|
||||||
this.initBle();
|
|
||||||
// 初始化并连接MQTT
|
// 初始化并连接MQTT
|
||||||
this.mqttClient = new MqttClient();
|
this.mqttClient = new MqttClient();
|
||||||
this.mqttClient.connect(() => {
|
this.mqttClient.connect(() => {
|
||||||
@ -1896,6 +1908,9 @@
|
|||||||
rec = BleReceive.getBleReceive();
|
rec = BleReceive.getBleReceive();
|
||||||
ble = BleTool.getBleTool();
|
ble = BleTool.getBleTool();
|
||||||
|
|
||||||
|
this.initBle();
|
||||||
|
|
||||||
|
console.log("ble=", ble);
|
||||||
let f = ble.data.LinkedList.find((v) => {
|
let f = ble.data.LinkedList.find((v) => {
|
||||||
if (v.macAddress == this.itemInfo.deviceMac) {
|
if (v.macAddress == this.itemInfo.deviceMac) {
|
||||||
console.log("找到设备了", v);
|
console.log("找到设备了", v);
|
||||||
@ -1922,6 +1937,16 @@
|
|||||||
})
|
})
|
||||||
|
|
||||||
},
|
},
|
||||||
|
onShow() {
|
||||||
|
let f = this.getDevice();
|
||||||
|
if (f) {
|
||||||
|
these.formData.bleStatu = 'connecting';
|
||||||
|
ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId).then(res => {
|
||||||
|
console.log("连接成功")
|
||||||
|
these.formData.bleStatu = true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
onUnload() {
|
onUnload() {
|
||||||
// 页面卸载时断开MQTT连接
|
// 页面卸载时断开MQTT连接
|
||||||
if (this.mqttClient) {
|
if (this.mqttClient) {
|
||||||
|
|||||||
@ -414,6 +414,14 @@ import request, { baseURL } from '@/utils/request.js';
|
|||||||
},
|
},
|
||||||
onShow() {
|
onShow() {
|
||||||
this.Status.pageHide = false;
|
this.Status.pageHide = false;
|
||||||
|
let f = this.getDevice();
|
||||||
|
if (f) {
|
||||||
|
these.formData.bleStatu = 'connecting';
|
||||||
|
ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId).then(res => {
|
||||||
|
console.log("连接成功")
|
||||||
|
these.formData.bleStatu = true;
|
||||||
|
});
|
||||||
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
|
|
||||||
@ -613,9 +621,9 @@ import request, { baseURL } from '@/utils/request.js';
|
|||||||
|
|
||||||
},
|
},
|
||||||
deviceDispose(res) {
|
deviceDispose(res) {
|
||||||
if (this.Status.pageHide) {
|
//if (this.Status.pageHide) {
|
||||||
return;
|
// return;
|
||||||
}
|
//}
|
||||||
if (res.deviceId == these.formData.deviceId) {
|
if (res.deviceId == these.formData.deviceId) {
|
||||||
if(res.device){
|
if(res.device){
|
||||||
these.formData.bleStatu = 'connecting';
|
these.formData.bleStatu = 'connecting';
|
||||||
|
|||||||
@ -418,6 +418,15 @@ import request, { baseURL } from '@/utils/request.js';
|
|||||||
},
|
},
|
||||||
onShow() {
|
onShow() {
|
||||||
this.Status.pageHide = false;
|
this.Status.pageHide = false;
|
||||||
|
|
||||||
|
let f=this.getDevice();
|
||||||
|
if(f){
|
||||||
|
these.formData.bleStatu = 'connecting';
|
||||||
|
ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId).then(res => {
|
||||||
|
console.log("连接成功")
|
||||||
|
these.formData.bleStatu = true;
|
||||||
|
});
|
||||||
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
getbleStatu(){
|
getbleStatu(){
|
||||||
@ -510,9 +519,9 @@ import request, { baseURL } from '@/utils/request.js';
|
|||||||
|
|
||||||
},
|
},
|
||||||
deviceDispose(res) {
|
deviceDispose(res) {
|
||||||
if (this.Status.pageHide) {
|
// if (this.Status.pageHide) {
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
if (res.deviceId == these.formData.deviceId) {
|
if (res.deviceId == these.formData.deviceId) {
|
||||||
if(res.device){
|
if(res.device){
|
||||||
these.formData.bleStatu = 'connecting';
|
these.formData.bleStatu = 'connecting';
|
||||||
@ -1051,7 +1060,7 @@ import request, { baseURL } from '@/utils/request.js';
|
|||||||
var gotoCutImg = (imgPath) => {
|
var gotoCutImg = (imgPath) => {
|
||||||
|
|
||||||
uni.navigateTo({
|
uni.navigateTo({
|
||||||
url: "/pages/ImgCrop/ImgCrop",
|
url: "/pages/common/ImgCrop/ImgCrop",
|
||||||
events: {
|
events: {
|
||||||
ImgCutOver: function(data) {
|
ImgCutOver: function(data) {
|
||||||
// console.log("我收到裁剪后的图片了,感谢老铁," + data)
|
// console.log("我收到裁剪后的图片了,感谢老铁," + data)
|
||||||
|
|||||||
@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
<view class="eq" :style="{marginTop:Status.navbar.height+'px'}">
|
<view class="eq" >
|
||||||
<view class="leftImg" @click.stop="previewImg(device.devicePic?device.devicePic:formData.img)">
|
<view class="leftImg" @click.stop="previewImg(device.devicePic?device.devicePic:formData.img)">
|
||||||
<image class="img" :src="device.devicePic?device.devicePic:formData.img" mode="aspectFit"></image>
|
<image class="img" :src="device.devicePic?device.devicePic:formData.img" mode="aspectFit"></image>
|
||||||
</view>
|
</view>
|
||||||
@ -561,6 +561,15 @@
|
|||||||
},
|
},
|
||||||
onShow() {
|
onShow() {
|
||||||
this.Status.pageHide = false;
|
this.Status.pageHide = false;
|
||||||
|
|
||||||
|
let f=this.getDevice();
|
||||||
|
if(f){
|
||||||
|
these.formData.bleStatu = 'connecting';
|
||||||
|
ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId).then(res => {
|
||||||
|
console.log("连接成功")
|
||||||
|
these.formData.bleStatu = true;
|
||||||
|
});
|
||||||
|
}
|
||||||
},
|
},
|
||||||
onHide: function() {
|
onHide: function() {
|
||||||
this.Status.pageHide = true;
|
this.Status.pageHide = true;
|
||||||
@ -634,9 +643,9 @@
|
|||||||
|
|
||||||
},
|
},
|
||||||
deviceDispose(res) {
|
deviceDispose(res) {
|
||||||
if (this.Status.pageHide) {
|
// if (this.Status.pageHide) {
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
if (res.deviceId == these.formData.deviceId) {
|
if (res.deviceId == these.formData.deviceId) {
|
||||||
if(res.device){
|
if(res.device){
|
||||||
these.formData.bleStatu = 'connecting';
|
these.formData.bleStatu = 'connecting';
|
||||||
@ -1871,7 +1880,7 @@
|
|||||||
var gotoCutImg = (imgPath) => {
|
var gotoCutImg = (imgPath) => {
|
||||||
|
|
||||||
uni.navigateTo({
|
uni.navigateTo({
|
||||||
url: "/pages/ImgCrop/ImgCrop",
|
url: "/pages/common/ImgCrop/ImgCrop",
|
||||||
events: {
|
events: {
|
||||||
ImgCutOver: function(data) {
|
ImgCutOver: function(data) {
|
||||||
// console.log("我收到裁剪后的图片了,感谢老铁," + data)
|
// console.log("我收到裁剪后的图片了,感谢老铁," + data)
|
||||||
|
|||||||
@ -243,7 +243,7 @@
|
|||||||
],
|
],
|
||||||
activeIndex: -1,
|
activeIndex: -1,
|
||||||
bgColor: '#2a2a2a',
|
bgColor: '#2a2a2a',
|
||||||
itemBgColor: '#00000000',
|
itemBgColor: '#3a3a3a',
|
||||||
textColor: '#ffffffde',
|
textColor: '#ffffffde',
|
||||||
textAlign: 'flex-start',
|
textAlign: 'flex-start',
|
||||||
title: '主灯模式',
|
title: '主灯模式',
|
||||||
@ -376,6 +376,15 @@
|
|||||||
},
|
},
|
||||||
onShow: function() {
|
onShow: function() {
|
||||||
this.Status.pageHide = false;
|
this.Status.pageHide = false;
|
||||||
|
|
||||||
|
let f=this.getDevice();
|
||||||
|
if(f){
|
||||||
|
these.formData.bleStatu = 'connecting';
|
||||||
|
ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId).then(res => {
|
||||||
|
console.log("连接成功")
|
||||||
|
these.formData.bleStatu = true;
|
||||||
|
});
|
||||||
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
getbleStatu() {
|
getbleStatu() {
|
||||||
@ -399,22 +408,20 @@
|
|||||||
return txt;
|
return txt;
|
||||||
}
|
}
|
||||||
switch (this.formData.mode) {
|
switch (this.formData.mode) {
|
||||||
case 0:
|
case 1:
|
||||||
|
|
||||||
|
|
||||||
txt = "强光模式";
|
txt = "强光模式";
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 2:
|
||||||
txt = "弱光模式";
|
txt = "弱光模式";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 2:
|
case 3:
|
||||||
txt = "爆闪模式";
|
txt = "爆闪模式";
|
||||||
break;
|
break;
|
||||||
case 3:
|
|
||||||
txt = "关闭";
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
txt = "关闭";
|
txt = "关闭";
|
||||||
break;
|
break;
|
||||||
@ -481,9 +488,9 @@
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
deviceRecovry(res) {
|
deviceRecovry(res) {
|
||||||
if (this.Status.pageHide) {
|
// if (this.Status.pageHide) {
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
if (res.deviceId == these.formData.deviceId) {
|
if (res.deviceId == these.formData.deviceId) {
|
||||||
this.formData.bleStatu = true;
|
this.formData.bleStatu = true;
|
||||||
// 重新连接后状态以设备上报为准
|
// 重新连接后状态以设备上报为准
|
||||||
@ -498,9 +505,9 @@
|
|||||||
|
|
||||||
},
|
},
|
||||||
deviceDispose(res) {
|
deviceDispose(res) {
|
||||||
if (this.Status.pageHide) {
|
// if (this.Status.pageHide) {
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
if (res.deviceId == these.formData.deviceId) {
|
if (res.deviceId == these.formData.deviceId) {
|
||||||
if (res.device) {
|
if (res.device) {
|
||||||
these.formData.bleStatu = 'connecting';
|
these.formData.bleStatu = 'connecting';
|
||||||
@ -587,7 +594,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
let json = recei.ReceiveData(receive, device, path, recArr);
|
let json = recei.ReceiveData(receive, device, path, recArr);
|
||||||
console.log("收到消息:", receive.hexs);
|
console.log("收到消息:", receive);
|
||||||
if (!json) {
|
if (!json) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -597,6 +604,8 @@
|
|||||||
these.formData[key] = json[key];
|
these.formData[key] = json[key];
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
these.formData.mode=parseInt(receive.hexs[2],16);
|
||||||
|
console.error("mode="+these.formData.mode);
|
||||||
if ('statu' in json) {
|
if ('statu' in json) {
|
||||||
const chargingVal = json.statu;
|
const chargingVal = json.statu;
|
||||||
const isCharging = chargingVal === 1 || chargingVal === '1' || chargingVal === true ||
|
const isCharging = chargingVal === 1 || chargingVal === '1' || chargingVal === true ||
|
||||||
@ -783,7 +792,7 @@
|
|||||||
sourceType: ['album'],
|
sourceType: ['album'],
|
||||||
success: function(res) {
|
success: function(res) {
|
||||||
uni.navigateTo({
|
uni.navigateTo({
|
||||||
url: "/pages/ImgCrop/ImgCrop",
|
url: "/pages/common/ImgCrop/ImgCrop",
|
||||||
events: {
|
events: {
|
||||||
ImgCutOver: function(data) {
|
ImgCutOver: function(data) {
|
||||||
//将8位的二进制数组转换成16进制数据
|
//将8位的二进制数组转换成16进制数据
|
||||||
@ -1023,21 +1032,16 @@
|
|||||||
case 0:
|
case 0:
|
||||||
|
|
||||||
|
|
||||||
if (type == 'main') {
|
|
||||||
|
|
||||||
dataValue = 0x01;
|
dataValue = 0x01;
|
||||||
} else if (type == 'fu') {
|
|
||||||
|
|
||||||
dataValue = 0x04;
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
dataValue = 0x02;
|
dataValue = 0x02;
|
||||||
break;
|
break;
|
||||||
// case 2:
|
|
||||||
// dataValue = 0x02;
|
|
||||||
// break;
|
|
||||||
case 2:
|
case 2:
|
||||||
dataValue = 0x03;
|
dataValue = 0x03;
|
||||||
break;
|
break;
|
||||||
@ -1071,7 +1075,7 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
ble.sendData(f.deviceId, buffer, f.writeServiceId, f.wirteCharactId, 100).then(() => {
|
ble.sendData(f.deviceId, buffer, f.writeServiceId, f.wirteCharactId, 100).then(() => {
|
||||||
this.formData.mode = mode;
|
this.formData.mode = mode+1;
|
||||||
this.setBleFormData();
|
this.setBleFormData();
|
||||||
}).catch((ex) => {
|
}).catch((ex) => {
|
||||||
these.showPop({
|
these.showPop({
|
||||||
@ -1088,7 +1092,7 @@
|
|||||||
|
|
||||||
},
|
},
|
||||||
handleItemClick(item, index) {
|
handleItemClick(item, index) {
|
||||||
|
debugger;
|
||||||
|
|
||||||
this.Status.BottomMenu.activeIndex = index;
|
this.Status.BottomMenu.activeIndex = index;
|
||||||
|
|
||||||
|
|||||||
@ -104,6 +104,7 @@
|
|||||||
</view>
|
</view>
|
||||||
</BottomSlideMenuPlus>
|
</BottomSlideMenuPlus>
|
||||||
|
|
||||||
|
<MsgBox ref="msgPop" />
|
||||||
<global-loading ref="loading" />
|
<global-loading ref="loading" />
|
||||||
</view>
|
</view>
|
||||||
</template>
|
</template>
|
||||||
@ -115,7 +116,15 @@
|
|||||||
showLoading,
|
showLoading,
|
||||||
hideLoading,
|
hideLoading,
|
||||||
updateLoading
|
updateLoading
|
||||||
} from '@/utils/loading.js'
|
} from '@/utils/loading.js';
|
||||||
|
import {
|
||||||
|
MsgSuccess,
|
||||||
|
MsgError,
|
||||||
|
MsgClose,
|
||||||
|
MsgWarning,
|
||||||
|
showPop,
|
||||||
|
MsgClear
|
||||||
|
} from '@/utils/MsgPops.js';
|
||||||
const pagePath = "pages/common/addBLE/addEquip";
|
const pagePath = "pages/common/addBLE/addEquip";
|
||||||
var ble = null;
|
var ble = null;
|
||||||
var these = null;
|
var these = null;
|
||||||
@ -490,24 +499,17 @@
|
|||||||
console.log('定位权限已授予');
|
console.log('定位权限已授予');
|
||||||
resolve(true);
|
resolve(true);
|
||||||
} else {
|
} else {
|
||||||
console.warn('定位权限被拒绝');
|
// console.warn('定位权限被拒绝');
|
||||||
uni.showModal({
|
|
||||||
title: '权限提醒',
|
MsgClear(these);
|
||||||
content: '为了正常扫描蓝牙设备,需要您开启定位权限',
|
showPop({headerTxt:'权限提醒',message:'扫描蓝牙设备,需要您开启定位权限',buttonText:'去开启',okCallback:uni.openSetting},these,true);
|
||||||
showCancel: false,
|
|
||||||
success: () => {
|
|
||||||
uni.openSetting(); // 引导用户去设置页
|
|
||||||
}
|
|
||||||
});
|
|
||||||
resolve(false);
|
resolve(false);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
(error) => {
|
(error) => {
|
||||||
console.error('请求定位权限失败:', error);
|
|
||||||
uni.showToast({
|
MsgError('请求定位权限失败:'+error.code,'确定',these);
|
||||||
title: '权限请求异常',
|
|
||||||
icon: 'none'
|
|
||||||
});
|
|
||||||
resolve(false);
|
resolve(false);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -537,7 +539,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
showLoading(these, {
|
showLoading(these, {
|
||||||
text: '正在刷新'
|
text: '正在扫描蓝牙设备'
|
||||||
})
|
})
|
||||||
let time = null;
|
let time = null;
|
||||||
let startSearch = () => {
|
let startSearch = () => {
|
||||||
@ -558,10 +560,9 @@
|
|||||||
if (err.code === 10001) {
|
if (err.code === 10001) {
|
||||||
these.showOpenSetting();
|
these.showOpenSetting();
|
||||||
} else {
|
} else {
|
||||||
uni.showModal({
|
|
||||||
title: '提示',
|
MsgClear(these);
|
||||||
content: '出现错误:' + err.msg
|
MsgError('出现错误:' + err.msg,'确定',these);
|
||||||
});
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}).finally(() => {
|
}).finally(() => {
|
||||||
@ -571,7 +572,9 @@
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ble.StopSearch().finally(startSearch);
|
ble.StopSearch().catch(err=>{
|
||||||
|
console.error("err=",err);
|
||||||
|
}).finally(startSearch);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -806,9 +809,9 @@
|
|||||||
linkCallback(res);
|
linkCallback(res);
|
||||||
}).catch(ex => {
|
}).catch(ex => {
|
||||||
console.error("ex=", ex)
|
console.error("ex=", ex)
|
||||||
uni.showModal({
|
MsgClear(these);
|
||||||
content: "连接失败:" + ex.msg
|
|
||||||
});
|
MsgError("连接失败:" + ex.msg,'确定',these);
|
||||||
hideLoading(these);
|
hideLoading(these);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -234,11 +234,11 @@ class BleHelper {
|
|||||||
}
|
}
|
||||||
if (key) {
|
if (key) {
|
||||||
// console.log("key=" + key);
|
// console.log("key=" + key);
|
||||||
let f =-1;
|
let f = -1;
|
||||||
|
|
||||||
this.cfg[type].find((v,index) => {
|
this.cfg[type].find((v, index) => {
|
||||||
if(v.key == key){
|
if (v.key == key) {
|
||||||
f=index;
|
f = index;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (f > -1) {
|
if (f > -1) {
|
||||||
@ -262,10 +262,10 @@ class BleHelper {
|
|||||||
|
|
||||||
if (key) {
|
if (key) {
|
||||||
// console.log("key=" + key);
|
// console.log("key=" + key);
|
||||||
let f =-1;
|
let f = -1;
|
||||||
this.cfg[type].find((v,index) => {
|
this.cfg[type].find((v, index) => {
|
||||||
if(v.key == key){
|
if (v.key == key) {
|
||||||
f=index;
|
f = index;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (f > -1) {
|
if (f > -1) {
|
||||||
@ -281,23 +281,23 @@ class BleHelper {
|
|||||||
|
|
||||||
|
|
||||||
//获取某个事件的所有订阅者,但不包含某些订阅者
|
//获取某个事件的所有订阅者,但不包含某些订阅者
|
||||||
getCfgAllKeys(type,retains){
|
getCfgAllKeys(type, retains) {
|
||||||
if(!retains){
|
if (!retains) {
|
||||||
retains=[];
|
retains = [];
|
||||||
}
|
}
|
||||||
if(!Array.isArray(retains)){
|
if (!Array.isArray(retains)) {
|
||||||
retains=[retains];
|
retains = [retains];
|
||||||
}
|
}
|
||||||
let keys=null;
|
let keys = null;
|
||||||
for (let index = 0; index < this.cfg[type]; index++) {
|
for (let index = 0; index < this.cfg[type]; index++) {
|
||||||
let ele = this.cfg[type];
|
let ele = this.cfg[type];
|
||||||
let f=retains.find(v=>{
|
let f = retains.find(v => {
|
||||||
return v.toLowerCase()==ele.key.toLowerCase();
|
return v.toLowerCase() == ele.key.toLowerCase();
|
||||||
});
|
});
|
||||||
if(!f){
|
if (!f) {
|
||||||
if(!keys){
|
if (!keys) {
|
||||||
keys=[ele.key];
|
keys = [ele.key];
|
||||||
}else{
|
} else {
|
||||||
keys.push(ele.key);
|
keys.push(ele.key);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -317,8 +317,8 @@ class BleHelper {
|
|||||||
}
|
}
|
||||||
//移除所有蓝牙恢复连接的回调,但不包括currkey
|
//移除所有蓝牙恢复连接的回调,但不包括currkey
|
||||||
removeAllRecoveryCallback(currKey) {
|
removeAllRecoveryCallback(currKey) {
|
||||||
let keys=this.getCfgAllKeys('recoveryCallback',currKey);
|
let keys = this.getCfgAllKeys('recoveryCallback', currKey);
|
||||||
if(keys){
|
if (keys) {
|
||||||
for (let i = 0; i < keys.length; i++) {
|
for (let i = 0; i < keys.length; i++) {
|
||||||
let key = keys[i];
|
let key = keys[i];
|
||||||
this.removeRecoveryCallback(key);
|
this.removeRecoveryCallback(key);
|
||||||
@ -337,8 +337,8 @@ class BleHelper {
|
|||||||
this.removeCallback(currKey, 'bleDisposeCallback');
|
this.removeCallback(currKey, 'bleDisposeCallback');
|
||||||
}
|
}
|
||||||
removeAllDisposeCallback(currKey) {
|
removeAllDisposeCallback(currKey) {
|
||||||
let keys=this.getCfgAllKeys('bleDisposeCallback',currKey);
|
let keys = this.getCfgAllKeys('bleDisposeCallback', currKey);
|
||||||
if(keys){
|
if (keys) {
|
||||||
for (let i = 0; i < keys.length; i++) {
|
for (let i = 0; i < keys.length; i++) {
|
||||||
let key = keys[i];
|
let key = keys[i];
|
||||||
this.removeDisposeCallback(key);
|
this.removeDisposeCallback(key);
|
||||||
@ -358,8 +358,8 @@ class BleHelper {
|
|||||||
this.removeCallback(currKey, 'onDeviceFound');
|
this.removeCallback(currKey, 'onDeviceFound');
|
||||||
}
|
}
|
||||||
removeAllDeviceFound(currKey) {
|
removeAllDeviceFound(currKey) {
|
||||||
let keys=this.getCfgAllKeys('onDeviceFound',currKey);
|
let keys = this.getCfgAllKeys('onDeviceFound', currKey);
|
||||||
if(keys){
|
if (keys) {
|
||||||
for (let i = 0; i < keys.length; i++) {
|
for (let i = 0; i < keys.length; i++) {
|
||||||
let key = keys[i];
|
let key = keys[i];
|
||||||
this.removeDeviceFound(key);
|
this.removeDeviceFound(key);
|
||||||
@ -378,8 +378,8 @@ class BleHelper {
|
|||||||
this.removeCallback(currKey, 'receivDataCallback');
|
this.removeCallback(currKey, 'receivDataCallback');
|
||||||
}
|
}
|
||||||
removeAllReceiveCallback(currKey) {
|
removeAllReceiveCallback(currKey) {
|
||||||
let keys=this.getCfgAllKeys('receivDataCallback',currKey);
|
let keys = this.getCfgAllKeys('receivDataCallback', currKey);
|
||||||
if(keys){
|
if (keys) {
|
||||||
for (let i = 0; i < keys.length; i++) {
|
for (let i = 0; i < keys.length; i++) {
|
||||||
let key = keys[i];
|
let key = keys[i];
|
||||||
this.removeReceiveCallback(key);
|
this.removeReceiveCallback(key);
|
||||||
@ -398,8 +398,8 @@ class BleHelper {
|
|||||||
this.removeCallback(currKey, 'stateBreakCallback');
|
this.removeCallback(currKey, 'stateBreakCallback');
|
||||||
}
|
}
|
||||||
removeAllStateBreakCallback(currKey) {
|
removeAllStateBreakCallback(currKey) {
|
||||||
let keys=this.getCfgAllKeys('stateBreakCallback',currKey);
|
let keys = this.getCfgAllKeys('stateBreakCallback', currKey);
|
||||||
if(keys){
|
if (keys) {
|
||||||
for (let i = 0; i < keys.length; i++) {
|
for (let i = 0; i < keys.length; i++) {
|
||||||
let key = keys[i];
|
let key = keys[i];
|
||||||
this.removeStateBreakCallback(key);
|
this.removeStateBreakCallback(key);
|
||||||
@ -418,8 +418,8 @@ class BleHelper {
|
|||||||
this.removeCallback(currKey, 'stateRecoveryCallback');
|
this.removeCallback(currKey, 'stateRecoveryCallback');
|
||||||
}
|
}
|
||||||
removeAllStateRecoveryCallback(currKey) {
|
removeAllStateRecoveryCallback(currKey) {
|
||||||
let keys=this.getCfgAllKeys('stateRecoveryCallback',currKey);
|
let keys = this.getCfgAllKeys('stateRecoveryCallback', currKey);
|
||||||
if(keys){
|
if (keys) {
|
||||||
for (let i = 0; i < keys.length; i++) {
|
for (let i = 0; i < keys.length; i++) {
|
||||||
let key = keys[i];
|
let key = keys[i];
|
||||||
this.removeStateRecoveryCallback(key);
|
this.removeStateRecoveryCallback(key);
|
||||||
@ -448,10 +448,11 @@ class BleHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getError(ex) {
|
getError(ex) {
|
||||||
let code = ex.code;
|
|
||||||
ex.msg = code
|
ex.msg =ex.code+':'+ ex.errMsg;
|
||||||
|
|
||||||
let f = this.dic.errRemarks.find((v) => {
|
let f = this.dic.errRemarks.find((v) => {
|
||||||
return v.key == code;
|
return v.key == ex.code;
|
||||||
});
|
});
|
||||||
if (f) {
|
if (f) {
|
||||||
ex.msg = f.remark;
|
ex.msg = f.remark;
|
||||||
@ -733,13 +734,13 @@ class BleHelper {
|
|||||||
let trimmedStr = str.trim();
|
let trimmedStr = str.trim();
|
||||||
if (trimmedStr && (trimmedStr.startsWith('{') || trimmedStr.startsWith('['))) {
|
if (trimmedStr && (trimmedStr.startsWith('{') || trimmedStr.startsWith('['))) {
|
||||||
let receivJson = JSON.parse(str);
|
let receivJson = JSON.parse(str);
|
||||||
let key = "sta_address"; //HBY100以此方式上传mac地址
|
|
||||||
if (key in receivJson) {
|
if ("sta_address" in receivJson || "sta_imei" in receivJson) {
|
||||||
this.data.LinkedList.find((v) => {
|
this.data.LinkedList.find((v) => {
|
||||||
if (v.deviceId == receive
|
if (v.deviceId == receive
|
||||||
.deviceId) {
|
.deviceId) {
|
||||||
let macStr = receivJson[
|
let macStr = receivJson["sta_address"];
|
||||||
key];
|
if (macStr) {
|
||||||
if (macStr.includes(':')) {
|
if (macStr.includes(':')) {
|
||||||
v.macAddress = macStr;
|
v.macAddress = macStr;
|
||||||
} else {
|
} else {
|
||||||
@ -748,12 +749,20 @@ class BleHelper {
|
|||||||
'$1:').slice(0,
|
'$1:').slice(0,
|
||||||
-1)
|
-1)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let sta_imei=receivJson["sta_imei"];
|
||||||
|
if(sta_imei){
|
||||||
|
v.imei=sta_imei;
|
||||||
|
}
|
||||||
|
|
||||||
isUpdate = true;
|
isUpdate = true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
} catch (convertException) {
|
} catch (convertException) {
|
||||||
if (str && (str.trim().startsWith('{') || str.trim().startsWith('['))) {
|
if (str && (str.trim().startsWith('{') || str.trim().startsWith('['))) {
|
||||||
@ -779,7 +788,7 @@ class BleHelper {
|
|||||||
str: str,
|
str: str,
|
||||||
hexs: hexs
|
hexs: hexs
|
||||||
};
|
};
|
||||||
// console.log("监听到特征值:",recData);
|
// console.log("监听到特征值:", recData);
|
||||||
if (this.cfg.receivDataCallback) {
|
if (this.cfg.receivDataCallback) {
|
||||||
|
|
||||||
if (this.cfg.receivDataCallback.length > 0) {
|
if (this.cfg.receivDataCallback.length > 0) {
|
||||||
@ -886,7 +895,7 @@ class BleHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
BleConnChange() {
|
BleConnChange() {
|
||||||
let stateTimeout=null;
|
let stateTimeout = null;
|
||||||
uni.onBLEConnectionStateChange((res) => {
|
uni.onBLEConnectionStateChange((res) => {
|
||||||
|
|
||||||
|
|
||||||
@ -903,7 +912,7 @@ class BleHelper {
|
|||||||
// console.log("蓝牙连接状态变化了", res);
|
// console.log("蓝牙连接状态变化了", res);
|
||||||
|
|
||||||
clearTimeout(stateTimeout);
|
clearTimeout(stateTimeout);
|
||||||
stateTimeout=setTimeout(() => {
|
stateTimeout = setTimeout(() => {
|
||||||
if (!res.connected) {
|
if (!res.connected) {
|
||||||
// console.error("蓝牙已断开", res);
|
// console.error("蓝牙已断开", res);
|
||||||
let f = this.data.LinkedList.find((
|
let f = this.data.LinkedList.find((
|
||||||
@ -1071,7 +1080,7 @@ class BleHelper {
|
|||||||
let RunSearch = () => {
|
let RunSearch = () => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
uni.startBluetoothDevicesDiscovery({
|
uni.startBluetoothDevicesDiscovery({
|
||||||
services:[],
|
services: [],
|
||||||
allowDuplicatesKey: true,
|
allowDuplicatesKey: true,
|
||||||
success: (res) => {
|
success: (res) => {
|
||||||
console.log('开始搜索蓝牙设备成功');
|
console.log('开始搜索蓝牙设备成功');
|
||||||
@ -1370,8 +1379,7 @@ class BleHelper {
|
|||||||
// notifyCharId));
|
// notifyCharId));
|
||||||
|
|
||||||
|
|
||||||
} else
|
} else {
|
||||||
{
|
|
||||||
console.error("预设的蓝牙服务和特征中找不到");
|
console.error("预设的蓝牙服务和特征中找不到");
|
||||||
for (var i = 0; i < res.services.length; i++) {
|
for (var i = 0; i < res.services.length; i++) {
|
||||||
let service = res.services[i];
|
let service = res.services[i];
|
||||||
@ -1616,11 +1624,11 @@ class BleHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.getLinkBlue().then((arr) => {
|
this.getLinkBlue().then((arr) => {
|
||||||
let linkId=new Date().getTime();//本次连接的id
|
let linkId = new Date().getTime(); //本次连接的id
|
||||||
let cr = arr.devices.find(c => {
|
let cr = arr.devices.find(c => {
|
||||||
if (c.deviceId == deviceId) {
|
if (c.deviceId == deviceId) {
|
||||||
c.Linked = true;
|
c.Linked = true;
|
||||||
c.linkId=linkId
|
c.linkId = linkId
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@ -1628,7 +1636,8 @@ class BleHelper {
|
|||||||
|
|
||||||
if (fIndex > -1) {
|
if (fIndex > -1) {
|
||||||
this.data.LinkedList[fIndex].Linked = true;
|
this.data.LinkedList[fIndex].Linked = true;
|
||||||
this.data.LinkedList[fIndex].linkId=linkId;
|
this.data.LinkedList[fIndex].linkId =
|
||||||
|
linkId;
|
||||||
} else {
|
} else {
|
||||||
this.data.LinkedList.push(cr);
|
this.data.LinkedList.push(cr);
|
||||||
}
|
}
|
||||||
@ -2048,5 +2057,5 @@ export default {
|
|||||||
|
|
||||||
return instance;
|
return instance;
|
||||||
},
|
},
|
||||||
constService:serviceDic
|
constService: serviceDic
|
||||||
}
|
}
|
||||||
@ -11,7 +11,8 @@ class BleReceive {
|
|||||||
'/pages/670/HBY670': this.Receive_670.bind(this),
|
'/pages/670/HBY670': this.Receive_670.bind(this),
|
||||||
'/pages/4877/BJQ4877': this.Receive_4877.bind(this),
|
'/pages/4877/BJQ4877': this.Receive_4877.bind(this),
|
||||||
'/pages/100/HBY100': this.Receive_100.bind(this),
|
'/pages/100/HBY100': this.Receive_100.bind(this),
|
||||||
'/pages/102/HBY102': this.Receive_102.bind(this)
|
'/pages/102/HBY102': this.Receive_102.bind(this),
|
||||||
|
'/pages/6170/deviceControl/index':this.Receive_6170.bind(this)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -671,6 +672,43 @@ class BleReceive {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Receive_6170(receive, f, path, recArr) {
|
||||||
|
let receiveData = {};
|
||||||
|
|
||||||
|
try {
|
||||||
|
console.log("订阅消息者:", path);
|
||||||
|
console.log("设备收到消息:", f);
|
||||||
|
console.log("消息内容:", receive);
|
||||||
|
receiveData = JSON.parse(receive.str);
|
||||||
|
|
||||||
|
let recCnt = recArr.find(v => {
|
||||||
|
return v.key.replace(/\//g, "").toLowerCase() == f.device.detailPageUrl
|
||||||
|
.replace(/\//g, "").toLowerCase();
|
||||||
|
});
|
||||||
|
if (!recCnt) {
|
||||||
|
if (receiveData.sta_PowerPercent <= 20) {
|
||||||
|
uni.showModal({
|
||||||
|
title: "提示",
|
||||||
|
content: "设备'" + f.device.deviceName + "'电量低",
|
||||||
|
showCancel: false
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
receiveData = {};
|
||||||
|
console.error("文本解析失败", error)
|
||||||
|
}
|
||||||
|
return receiveData;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
Receive_102(receive, f, path, recArr) {
|
Receive_102(receive, f, path, recArr) {
|
||||||
let receiveData = {};
|
let receiveData = {};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user