670增加去连接蓝牙,其它体验问题小调整
This commit is contained in:
@ -2,7 +2,7 @@
|
|||||||
"name" : "星汉物联",
|
"name" : "星汉物联",
|
||||||
"appid" : "__UNI__A21EF43",
|
"appid" : "__UNI__A21EF43",
|
||||||
"description" : "设备管控",
|
"description" : "设备管控",
|
||||||
"versionName" : "1.0.28",
|
"versionName" : "1.0.29",
|
||||||
"versionCode" : "100",
|
"versionCode" : "100",
|
||||||
"transformPx" : false,
|
"transformPx" : false,
|
||||||
/* 5+App特有相关 */
|
/* 5+App特有相关 */
|
||||||
@ -66,7 +66,8 @@
|
|||||||
"NSLocationAlwaysUsageDescription" : "App需要您的同意,才能始终访问位置",
|
"NSLocationAlwaysUsageDescription" : "App需要您的同意,才能始终访问位置",
|
||||||
"NSLocationAlwaysAndWhenInUseUsageDescription" : "App需要您的同意,才能始终访问位置"
|
"NSLocationAlwaysAndWhenInUseUsageDescription" : "App需要您的同意,才能始终访问位置"
|
||||||
},
|
},
|
||||||
"dSYMs" : false
|
"dSYMs" : false,
|
||||||
|
"idfa" : false
|
||||||
},
|
},
|
||||||
/* SDK配置 */
|
/* SDK配置 */
|
||||||
"sdkConfigs" : {
|
"sdkConfigs" : {
|
||||||
@ -79,15 +80,16 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"maps" : {
|
"maps" : {
|
||||||
|
"customStyle" : true,
|
||||||
"amap" : {
|
"amap" : {
|
||||||
"name" : "amapHG8nIFW5",
|
"name" : "amapHG8nIFW5",
|
||||||
"appkey_ios" : "065c43f02c7b627a74ad7dd23b16bb4f",
|
"appkey_ios" : "065c43f02c7b627a74ad7dd23b16bb4f",
|
||||||
"appkey_android" : "d7d852dbda2b95f6f796fb9a711a9fee"
|
"appkey_android" : "d7d852dbda2b95f6f796fb9a711a9fee"
|
||||||
},
|
}
|
||||||
"customStyle" : true
|
|
||||||
},
|
},
|
||||||
"oauth" : {},
|
"oauth" : {},
|
||||||
"push" : {}
|
"push" : {},
|
||||||
|
"speech" : {}
|
||||||
},
|
},
|
||||||
"splashscreen" : {
|
"splashscreen" : {
|
||||||
"useOriginalMsgbox" : true,
|
"useOriginalMsgbox" : true,
|
||||||
@ -156,5 +158,6 @@
|
|||||||
"enable" : false
|
"enable" : false
|
||||||
},
|
},
|
||||||
"vueVersion" : "2",
|
"vueVersion" : "2",
|
||||||
"locale" : "auto"
|
"locale" : "zh-Hans",
|
||||||
|
"fallbackLocale" : "zh-Hans"
|
||||||
}
|
}
|
||||||
|
|||||||
@ -124,7 +124,7 @@
|
|||||||
:borderColor="Status.Pop.borderColor" :textColor="Status.Pop.textColor"
|
:borderColor="Status.Pop.borderColor" :textColor="Status.Pop.textColor"
|
||||||
:buttonBgColor="Status.Pop.buttonBgColor" :buttonTextColor="Status.Pop.buttonTextColor"
|
:buttonBgColor="Status.Pop.buttonBgColor" :buttonTextColor="Status.Pop.buttonTextColor"
|
||||||
:iconUrl="Status.Pop.iconUrl" :message="Status.Pop.message" :buttonText="Status.Pop.buttonText"
|
:iconUrl="Status.Pop.iconUrl" :message="Status.Pop.message" :buttonText="Status.Pop.buttonText"
|
||||||
@buttonClick="HidePop" :visiblePrompt="Status.Pop.visiblePrompt" :promptTitle="Status.Pop.promptTitle"
|
@buttonClick="HidePop" @closePop="closePop" :visiblePrompt="Status.Pop.visiblePrompt" :promptTitle="Status.Pop.promptTitle"
|
||||||
v-model="Status.Pop.modelValue" />
|
v-model="Status.Pop.modelValue" />
|
||||||
|
|
||||||
<!-- 下方菜单 -->
|
<!-- 下方菜单 -->
|
||||||
@ -538,7 +538,7 @@
|
|||||||
buttonBgColor: "#E03434",
|
buttonBgColor: "#E03434",
|
||||||
buttonText: '去连接',
|
buttonText: '去连接',
|
||||||
okCallback: function() {
|
okCallback: function() {
|
||||||
console.log("1111");
|
// console.log("1111");
|
||||||
uni.navigateTo({
|
uni.navigateTo({
|
||||||
url: "/pages/common/addBLE/addEquip",
|
url: "/pages/common/addBLE/addEquip",
|
||||||
events: {
|
events: {
|
||||||
@ -974,8 +974,15 @@
|
|||||||
})
|
})
|
||||||
|
|
||||||
},
|
},
|
||||||
|
closePop: function() {
|
||||||
|
this.Status.Pop.showPop = false;
|
||||||
|
|
||||||
|
if (this.Status.Pop.cancelCallback) {
|
||||||
|
this.Status.Pop.cancelCallback();
|
||||||
|
}
|
||||||
|
},
|
||||||
HidePop: function() {
|
HidePop: function() {
|
||||||
console.log("1111");
|
// console.log("1111");
|
||||||
if (this.Status.Pop.clickEvt == 'SendUsr') {
|
if (this.Status.Pop.clickEvt == 'SendUsr') {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -146,7 +146,7 @@
|
|||||||
:buttonBgColor="Status.Pop.buttonBgColor" :buttonTextColor="Status.Pop.buttonTextColor"
|
:buttonBgColor="Status.Pop.buttonBgColor" :buttonTextColor="Status.Pop.buttonTextColor"
|
||||||
:iconUrl="Status.Pop.iconUrl" :message="Status.Pop.message" :buttonText="Status.Pop.buttonText"
|
:iconUrl="Status.Pop.iconUrl" :message="Status.Pop.message" :buttonText="Status.Pop.buttonText"
|
||||||
@buttonClick="HidePop" :visiblePrompt="Status.Pop.visiblePrompt" :promptTitle="Status.Pop.promptTitle"
|
@buttonClick="HidePop" :visiblePrompt="Status.Pop.visiblePrompt" :promptTitle="Status.Pop.promptTitle"
|
||||||
v-model="Status.Pop.modelValue" />
|
v-model="Status.Pop.modelValue" @closePop="closePop" />
|
||||||
|
|
||||||
<!-- 下方菜单 -->
|
<!-- 下方菜单 -->
|
||||||
<BottomSlideMenuPlus :config="Status.BottomMenu" @close="closeMenu" @itemClick="handleItemClick"
|
<BottomSlideMenuPlus :config="Status.BottomMenu" @close="closeMenu" @itemClick="handleItemClick"
|
||||||
@ -173,7 +173,10 @@
|
|||||||
hideLoading,
|
hideLoading,
|
||||||
updateLoading
|
updateLoading
|
||||||
} from '@/utils/loading.js'
|
} from '@/utils/loading.js'
|
||||||
import {request,baseURL} from '../../utils/request';
|
import {
|
||||||
|
request,
|
||||||
|
baseURL
|
||||||
|
} from '../../utils/request';
|
||||||
|
|
||||||
import usrApi from '@/api/670/HBY670.js'
|
import usrApi from '@/api/670/HBY670.js'
|
||||||
const pagePath = "pages/650/HBY650";
|
const pagePath = "pages/650/HBY650";
|
||||||
@ -201,7 +204,7 @@
|
|||||||
promptTitle: '设备名称',
|
promptTitle: '设备名称',
|
||||||
modelValue: '',
|
modelValue: '',
|
||||||
visibleClose: false,
|
visibleClose: false,
|
||||||
okCallback:null
|
okCallback: null
|
||||||
},
|
},
|
||||||
BottomMenu: {
|
BottomMenu: {
|
||||||
show: false,
|
show: false,
|
||||||
@ -302,7 +305,7 @@
|
|||||||
|
|
||||||
console.log("收到父页面的参数:" + JSON.stringify(data));
|
console.log("收到父页面的参数:" + JSON.stringify(data));
|
||||||
var device = data.data;
|
var device = data.data;
|
||||||
these.device=device;
|
these.device = device;
|
||||||
let f = ble.data.LinkedList.find((v) => {
|
let f = ble.data.LinkedList.find((v) => {
|
||||||
if (v.macAddress == device.deviceMac) {
|
if (v.macAddress == device.deviceMac) {
|
||||||
console.log("找到设备了", v);
|
console.log("找到设备了", v);
|
||||||
@ -462,9 +465,9 @@
|
|||||||
getDetail() {
|
getDetail() {
|
||||||
var that = this;
|
var that = this;
|
||||||
usrApi.getDetail(this.device.id).then(res => {
|
usrApi.getDetail(this.device.id).then(res => {
|
||||||
|
|
||||||
if (res && res.code == 200) {
|
if (res && res.code == 200) {
|
||||||
res = res.data;
|
res = res.data;
|
||||||
let personnelInfo = res.personnelInfo;
|
let personnelInfo = res.personnelInfo;
|
||||||
if (personnelInfo) {
|
if (personnelInfo) {
|
||||||
that.formData.company = personnelInfo.unitName;
|
that.formData.company = personnelInfo.unitName;
|
||||||
@ -475,7 +478,7 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
setBleFormData() {
|
setBleFormData() {
|
||||||
ble.data.LinkedList.find((v) => {
|
ble.data.LinkedList.find((v) => {
|
||||||
if (v.deviceId == these.formData.deviceId) {
|
if (v.deviceId == these.formData.deviceId) {
|
||||||
@ -579,34 +582,36 @@
|
|||||||
|
|
||||||
|
|
||||||
},
|
},
|
||||||
showBleUnConnect(){
|
showBleUnConnect() {
|
||||||
|
|
||||||
this.showPop({
|
this.showPop({
|
||||||
message: "蓝牙未连接过该设备,请使用蓝牙重新添加该设备",
|
message: "蓝牙未连接过该设备,请使用蓝牙重新添加该设备",
|
||||||
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
|
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
|
||||||
borderColor: "#e034344d",
|
borderColor: "#e034344d",
|
||||||
buttonBgColor: "#E03434",
|
buttonBgColor: "#E03434",
|
||||||
buttonText:'去连接',
|
buttonText: '去连接',
|
||||||
okCallback:function(){
|
okCallback: function() {
|
||||||
console.log("1111");
|
console.log("1111");
|
||||||
uni.navigateTo({
|
uni.navigateTo({
|
||||||
url:"/pages/common/addBLE/addEquip",
|
url: "/pages/common/addBLE/addEquip",
|
||||||
events: {
|
events: {
|
||||||
BindOver: function(data) {
|
BindOver: function(data) {
|
||||||
console.log(data)
|
console.log(data)
|
||||||
}
|
|
||||||
},
|
|
||||||
success: function(res) {
|
|
||||||
// 通过eventChannel向被打开页面传送数据
|
|
||||||
res.eventChannel.emit('detailData', { data: these.device })
|
|
||||||
},
|
|
||||||
fail(ex){
|
|
||||||
console.log("跳转失败",ex);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
});
|
},
|
||||||
},
|
success: function(res) {
|
||||||
|
// 通过eventChannel向被打开页面传送数据
|
||||||
|
res.eventChannel.emit('detailData', {
|
||||||
|
data: these.device
|
||||||
|
})
|
||||||
|
},
|
||||||
|
fail(ex) {
|
||||||
|
console.log("跳转失败", ex);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
LampToggle: function() {
|
LampToggle: function() {
|
||||||
|
|
||||||
this.formData.cMode = !this.formData.cMode;
|
this.formData.cMode = !this.formData.cMode;
|
||||||
@ -1141,6 +1146,13 @@
|
|||||||
this.Status.BottomMenu.activeIndex = index;
|
this.Status.BottomMenu.activeIndex = index;
|
||||||
|
|
||||||
},
|
},
|
||||||
|
closePop: function() {
|
||||||
|
this.Status.Pop.showPop = false;
|
||||||
|
|
||||||
|
if (this.Status.Pop.cancelCallback) {
|
||||||
|
this.Status.Pop.cancelCallback();
|
||||||
|
}
|
||||||
|
},
|
||||||
HidePop: function() {
|
HidePop: function() {
|
||||||
if (this.Status.Pop.clickEvt == 'SendUsr') {
|
if (this.Status.Pop.clickEvt == 'SendUsr') {
|
||||||
|
|
||||||
@ -1148,7 +1160,7 @@
|
|||||||
console.log("1111");
|
console.log("1111");
|
||||||
|
|
||||||
this.Status.Pop.showPop = false;
|
this.Status.Pop.showPop = false;
|
||||||
if(this.Status.Pop.okCallback){
|
if (this.Status.Pop.okCallback) {
|
||||||
this.Status.Pop.okCallback();
|
this.Status.Pop.okCallback();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -1232,10 +1244,10 @@
|
|||||||
visibleClose: true
|
visibleClose: true
|
||||||
});
|
});
|
||||||
these.setBleFormData();
|
these.setBleFormData();
|
||||||
|
|
||||||
|
|
||||||
let json = {
|
let json = {
|
||||||
deviceId: these.device.id,
|
deviceId: these.device.id,
|
||||||
name: these.formData.company,
|
name: these.formData.company,
|
||||||
position: these.formData.name,
|
position: these.formData.name,
|
||||||
unitName: these.formData.job,
|
unitName: these.formData.job,
|
||||||
|
|||||||
@ -247,7 +247,8 @@
|
|||||||
:buttonBgColor="Status.Pop.buttonBgColor" :buttonTextColor="Status.Pop.buttonTextColor"
|
:buttonBgColor="Status.Pop.buttonBgColor" :buttonTextColor="Status.Pop.buttonTextColor"
|
||||||
:iconUrl="Status.Pop.iconUrl" :message="Status.Pop.message" :buttonText="Status.Pop.buttonText"
|
:iconUrl="Status.Pop.iconUrl" :message="Status.Pop.message" :buttonText="Status.Pop.buttonText"
|
||||||
@buttonClick="HidePop" @closePop="closePop" @cancelPop="closePop" :visiblePrompt="Status.Pop.visiblePrompt"
|
@buttonClick="HidePop" @closePop="closePop" @cancelPop="closePop" :visiblePrompt="Status.Pop.visiblePrompt"
|
||||||
:promptTitle="Status.Pop.promptTitle" v-model="Status.Pop.modelValue" />
|
:promptTitle="Status.Pop.promptTitle" v-model="Status.Pop.modelValue" :showCancel="Status.Pop.showCancel"
|
||||||
|
:buttonCancelText="Status.Pop.buttonCancelText" />
|
||||||
|
|
||||||
<!-- 下方菜单 -->
|
<!-- 下方菜单 -->
|
||||||
<BottomSlideMenuPlus :config="Status.BottomMenu" @close="closeMenu" @itemClick="handleItemClick"
|
<BottomSlideMenuPlus :config="Status.BottomMenu" @close="closeMenu" @itemClick="handleItemClick"
|
||||||
@ -311,15 +312,19 @@
|
|||||||
},
|
},
|
||||||
Pop: {
|
Pop: {
|
||||||
showPop: false, //是否显示弹窗
|
showPop: false, //是否显示弹窗
|
||||||
|
|
||||||
popType: 'custom',
|
popType: 'custom',
|
||||||
bgColor: '#383934bd',
|
bgColor: '#383934bd',
|
||||||
borderColor: '#BBE600',
|
borderColor: '#BBE600',
|
||||||
textColor: '#ffffffde',
|
textColor: '#ffffffde',
|
||||||
buttonBgColor: '#BBE600',
|
buttonBgColor: '#BBE600',
|
||||||
buttonTextColor: '#232323DE',
|
buttonTextColor: '#232323DE',
|
||||||
|
|
||||||
iconUrl: '',
|
iconUrl: '',
|
||||||
message: '您确定要这样做吗?',
|
message: '您确定要这样做吗?',
|
||||||
buttonText: '确定',
|
buttonText: '确定',
|
||||||
|
showCancel: false,
|
||||||
|
buttonCancelText: '取消',
|
||||||
clickEvt: '',
|
clickEvt: '',
|
||||||
visiblePrompt: false,
|
visiblePrompt: false,
|
||||||
promptTitle: '设备名称',
|
promptTitle: '设备名称',
|
||||||
@ -485,6 +490,7 @@
|
|||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
if (!f) {
|
if (!f) {
|
||||||
|
these.showBleUnConnect();
|
||||||
these.getDetail();
|
these.getDetail();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -516,6 +522,40 @@
|
|||||||
|
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
showBleUnConnect() {
|
||||||
|
|
||||||
|
this.showPop({
|
||||||
|
message: "蓝牙未连接过该设备,请使用蓝牙重新添加该设备",
|
||||||
|
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
|
||||||
|
borderColor: "#e034344d",
|
||||||
|
buttonBgColor: "#E03434",
|
||||||
|
buttonText: '去连接',
|
||||||
|
showCancel: true,
|
||||||
|
cancelCallback: () => {
|
||||||
|
this.closePop();
|
||||||
|
},
|
||||||
|
okCallback: function() {
|
||||||
|
console.log("1111");
|
||||||
|
uni.navigateTo({
|
||||||
|
url: "/pages/common/addBLE/addEquip",
|
||||||
|
events: {
|
||||||
|
BindOver: function(data) {
|
||||||
|
console.log(data)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
success: function(res) {
|
||||||
|
// 通过eventChannel向被打开页面传送数据
|
||||||
|
res.eventChannel.emit('detailData', {
|
||||||
|
data: these.device
|
||||||
|
})
|
||||||
|
},
|
||||||
|
fail(ex) {
|
||||||
|
console.log("跳转失败", ex);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
gotoMap() {
|
gotoMap() {
|
||||||
this.detailData.longitude = this.formData.Lon;
|
this.detailData.longitude = this.formData.Lon;
|
||||||
this.detailData.latitude = this.formData.Lat;
|
this.detailData.latitude = this.formData.Lat;
|
||||||
@ -545,12 +585,16 @@
|
|||||||
that.formData.address = res.address;
|
that.formData.address = res.address;
|
||||||
let personnelInfo = res.personnelInfo;
|
let personnelInfo = res.personnelInfo;
|
||||||
if (personnelInfo) {
|
if (personnelInfo) {
|
||||||
that.formData.company = personnelInfo.unitName;
|
that.formData.company = personnelInfo.name;
|
||||||
that.formData.usrname = personnelInfo.name;
|
that.formData.usrname = personnelInfo.unitName;
|
||||||
that.formData.job = personnelInfo.position;
|
that.formData.job = personnelInfo.position;
|
||||||
that.formData.usrid = personnelInfo.code
|
that.formData.usrid = personnelInfo.code
|
||||||
}
|
}
|
||||||
|
that.formData.imei=res.deviceImei;
|
||||||
|
these.device.deviceImei=res.deviceImei;
|
||||||
|
if(that.formData.imei){
|
||||||
|
that.initMQ();
|
||||||
|
}
|
||||||
let dic = {
|
let dic = {
|
||||||
"3": "hight",
|
"3": "hight",
|
||||||
"2": "center",
|
"2": "center",
|
||||||
@ -670,7 +714,7 @@
|
|||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
|
||||||
if (mqttClient) {
|
if (mqttClient) {
|
||||||
console.log("无需再次初始化")
|
// console.log("无需再次初始化")
|
||||||
resolve();
|
resolve();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -735,7 +779,10 @@
|
|||||||
qos: 1
|
qos: 1
|
||||||
});
|
});
|
||||||
if (flag) {
|
if (flag) {
|
||||||
resolve();
|
resolve({
|
||||||
|
code: 200,
|
||||||
|
msg: 'MQTT直连发送成功'
|
||||||
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
console.log("MQTT未连接,无法发布消息")
|
console.log("MQTT未连接,无法发布消息")
|
||||||
@ -994,6 +1041,7 @@
|
|||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
requestSend();
|
requestSend();
|
||||||
|
these.showBleUnConnect();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1062,7 +1110,7 @@
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
requestCloseSOS();
|
requestCloseSOS();
|
||||||
|
these.showBleUnConnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -1138,13 +1186,31 @@
|
|||||||
ins_SOSGrade: [dic.mqtt[type]]
|
ins_SOSGrade: [dic.mqtt[type]]
|
||||||
};
|
};
|
||||||
|
|
||||||
let requestSend = () => {
|
|
||||||
this.sendMQ(json).then((res) => {
|
|
||||||
console.log("4g发送成功");
|
|
||||||
json.deviceId = these.device.id;
|
|
||||||
json.deviceImei = these.device.deviceImei;
|
|
||||||
api.sendSos(json);
|
|
||||||
|
|
||||||
|
let message = {
|
||||||
|
instructValue: json.ins_SOSGrade[0]
|
||||||
|
};
|
||||||
|
|
||||||
|
message.deviceId = these.device.id;
|
||||||
|
message.deviceImei = these.device.deviceImei;
|
||||||
|
|
||||||
|
let requestSend = () => {
|
||||||
|
|
||||||
|
message.isBluetooth = false;
|
||||||
|
api.sendSos(message).then((res) => {
|
||||||
|
console.log("res=>", res);
|
||||||
|
if (res && res.code == 200) {
|
||||||
|
console.log("接口发送SOS指令成功");
|
||||||
|
return Promise.resolve({
|
||||||
|
code: 200,
|
||||||
|
msg: '操作成功'
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
return this.sendMQ(json);
|
||||||
|
}
|
||||||
|
|
||||||
|
}).then((res) => {
|
||||||
|
console.log("res=", res);
|
||||||
}).catch((ex) => {
|
}).catch((ex) => {
|
||||||
console.log("ex=", ex);
|
console.log("ex=", ex);
|
||||||
these.showPop({
|
these.showPop({
|
||||||
@ -1179,17 +1245,19 @@
|
|||||||
ble.sendData(f.deviceId, buffer, f.writeServiceId, f.wirteCharactId, 10).then(
|
ble.sendData(f.deviceId, buffer, f.writeServiceId, f.wirteCharactId, 10).then(
|
||||||
() => {
|
() => {
|
||||||
console.log("蓝牙发送成功了");
|
console.log("蓝牙发送成功了");
|
||||||
|
|
||||||
|
|
||||||
hideLoading(these);
|
hideLoading(these);
|
||||||
these.setBleFormData();
|
these.setBleFormData();
|
||||||
|
message.isBluetooth = true;
|
||||||
|
api.sendSos(message);
|
||||||
}).catch((ex) => {
|
}).catch((ex) => {
|
||||||
//使用4G发送
|
//使用4G发送
|
||||||
console.log("蓝牙发送失败,转4g发送", ex);
|
console.log("蓝牙发送失败,转4g发送", ex);
|
||||||
requestSend();
|
requestSend();
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
console.log("找不到蓝牙设备");
|
||||||
requestSend();
|
requestSend();
|
||||||
|
these.showBleUnConnect();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1367,6 +1435,7 @@
|
|||||||
} else {
|
} else {
|
||||||
console.log("找不到蓝牙设备,使用4G发送")
|
console.log("找不到蓝牙设备,使用4G发送")
|
||||||
requestSend();
|
requestSend();
|
||||||
|
these.showBleUnConnect();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1745,37 +1814,9 @@
|
|||||||
|
|
||||||
var sendVideo = (videoPath) => {
|
var sendVideo = (videoPath) => {
|
||||||
|
|
||||||
let f = these.getDevice();
|
|
||||||
if (!f) {
|
if (!f) {
|
||||||
these.showPop({
|
these.showBleUnConnect();
|
||||||
message: "蓝牙未连接,请连接后再试",
|
|
||||||
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
|
|
||||||
borderColor: "#e034344d",
|
|
||||||
buttonBgColor: "#E03434",
|
|
||||||
buttonText: '去连接',
|
|
||||||
okCallback: function() {
|
|
||||||
console.log("1111");
|
|
||||||
uni.navigateTo({
|
|
||||||
url: "/pages/common/addBLE/addEquip",
|
|
||||||
events: {
|
|
||||||
BindOver: function(data) {
|
|
||||||
console.log(data)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
success: function(res) {
|
|
||||||
// 通过eventChannel向被打开页面传送数据
|
|
||||||
res.eventChannel.emit('detailData', {
|
|
||||||
data: these.device
|
|
||||||
})
|
|
||||||
},
|
|
||||||
fail(ex) {
|
|
||||||
console.log("跳转失败", ex);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let uploadVideo = () => {
|
let uploadVideo = () => {
|
||||||
@ -2014,6 +2055,8 @@
|
|||||||
cancelCallback: null,
|
cancelCallback: null,
|
||||||
popType: 'custom',
|
popType: 'custom',
|
||||||
buttonText: '确定',
|
buttonText: '确定',
|
||||||
|
showCancel: false,
|
||||||
|
buttonCancelText: '取消',
|
||||||
clickEvt: ''
|
clickEvt: ''
|
||||||
};
|
};
|
||||||
if (!option) {
|
if (!option) {
|
||||||
@ -2102,6 +2145,7 @@
|
|||||||
if (!f) {
|
if (!f) {
|
||||||
//走4G通道
|
//走4G通道
|
||||||
requestSend();
|
requestSend();
|
||||||
|
these.showBleUnConnect();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
showLoading(this, {
|
showLoading(this, {
|
||||||
|
|||||||
@ -124,7 +124,7 @@
|
|||||||
:borderColor="Status.Pop.borderColor" :textColor="Status.Pop.textColor"
|
:borderColor="Status.Pop.borderColor" :textColor="Status.Pop.textColor"
|
||||||
:buttonBgColor="Status.Pop.buttonBgColor" :buttonTextColor="Status.Pop.buttonTextColor"
|
:buttonBgColor="Status.Pop.buttonBgColor" :buttonTextColor="Status.Pop.buttonTextColor"
|
||||||
:iconUrl="Status.Pop.iconUrl" :message="Status.Pop.message" :buttonText="Status.Pop.buttonText"
|
:iconUrl="Status.Pop.iconUrl" :message="Status.Pop.message" :buttonText="Status.Pop.buttonText"
|
||||||
@buttonClick="HidePop" :visiblePrompt="Status.Pop.visiblePrompt" :promptTitle="Status.Pop.promptTitle"
|
@buttonClick="HidePop" @closePop="closePop" :visiblePrompt="Status.Pop.visiblePrompt" :promptTitle="Status.Pop.promptTitle"
|
||||||
v-model="Status.Pop.modelValue" />
|
v-model="Status.Pop.modelValue" />
|
||||||
|
|
||||||
<!-- 下方菜单 -->
|
<!-- 下方菜单 -->
|
||||||
@ -972,6 +972,13 @@
|
|||||||
})
|
})
|
||||||
|
|
||||||
},
|
},
|
||||||
|
closePop: function() {
|
||||||
|
this.Status.Pop.showPop = false;
|
||||||
|
|
||||||
|
if (this.Status.Pop.cancelCallback) {
|
||||||
|
this.Status.Pop.cancelCallback();
|
||||||
|
}
|
||||||
|
},
|
||||||
HidePop: function() {
|
HidePop: function() {
|
||||||
console.log("1111");
|
console.log("1111");
|
||||||
if (this.Status.Pop.clickEvt == 'SendUsr') {
|
if (this.Status.Pop.clickEvt == 'SendUsr') {
|
||||||
|
|||||||
@ -102,6 +102,8 @@
|
|||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
Status: {
|
Status: {
|
||||||
|
intval: null,
|
||||||
|
time: null,
|
||||||
BottomMenu: {
|
BottomMenu: {
|
||||||
show: false,
|
show: false,
|
||||||
showHeader: false,
|
showHeader: false,
|
||||||
@ -152,7 +154,7 @@
|
|||||||
these = this;
|
these = this;
|
||||||
this.EquipMents = [];
|
this.EquipMents = [];
|
||||||
ble = bleTool.getBleTool();
|
ble = bleTool.getBleTool();
|
||||||
|
|
||||||
ble.addDeviceFound((arr) => {
|
ble.addDeviceFound((arr) => {
|
||||||
|
|
||||||
arr = arr.devices;
|
arr = arr.devices;
|
||||||
@ -173,11 +175,15 @@
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// console.log("equip=", these.EquipMents)
|
// console.log("equip=", these.EquipMents)
|
||||||
}, pagePath);
|
}, pagePath);
|
||||||
// console.log("addEquip")
|
// console.log("addEquip")
|
||||||
ble.addReceiveCallback((receivData, f, path, arr) => {
|
ble.addReceiveCallback((receivData, f, path, arr) => {
|
||||||
if (f.macAddress && these.device) {
|
if (f.macAddress && these.device) {
|
||||||
|
clearInterval(this.Status.intval);
|
||||||
|
this.Status.intval = null;
|
||||||
|
this.Status.time = null;
|
||||||
|
|
||||||
showLoading(these, {
|
showLoading(these, {
|
||||||
text: '正在验证设备'
|
text: '正在验证设备'
|
||||||
});
|
});
|
||||||
@ -202,10 +208,10 @@
|
|||||||
|
|
||||||
// this.EquipMents = [];
|
// this.EquipMents = [];
|
||||||
this.PairEquip = [];
|
this.PairEquip = [];
|
||||||
ble && ble.StartSearch().then(res=>{
|
ble && ble.StartSearch().then(res => {
|
||||||
console.log("开始搜索成功",res);
|
console.log("开始搜索成功", res);
|
||||||
}).catch((ex) => {
|
}).catch((ex) => {
|
||||||
console.log("开始搜索出现异常",ex);
|
console.log("开始搜索出现异常", ex);
|
||||||
if (ex.code == 10001) {
|
if (ex.code == 10001) {
|
||||||
these.showOpenSetting();
|
these.showOpenSetting();
|
||||||
}
|
}
|
||||||
@ -244,6 +250,8 @@
|
|||||||
ble.showBlueSetting(false);
|
ble.showBlueSetting(false);
|
||||||
},
|
},
|
||||||
DeviceVerdict(deviceId) { //判断是否是目标设备
|
DeviceVerdict(deviceId) { //判断是否是目标设备
|
||||||
|
console.log("deviceid=", deviceId);
|
||||||
|
console.log("these.device=", these.device)
|
||||||
if (these.device) { //从设备详情过来的,回设备详情去
|
if (these.device) { //从设备详情过来的,回设备详情去
|
||||||
let f = ble.data.LinkedList.find(v => {
|
let f = ble.data.LinkedList.find(v => {
|
||||||
if (v.deviceId == deviceId) {
|
if (v.deviceId == deviceId) {
|
||||||
@ -252,15 +260,32 @@
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
let removeLink=()=>{
|
||||||
|
ble.subScribe(deviceId,false);//取消订阅消息
|
||||||
|
ble.DropDevice(deviceId);//从缓存中删除该设备
|
||||||
|
ble.disconnectDevice(deviceId);//断开与该设备的连接
|
||||||
|
|
||||||
|
let index=this.PairEquip.findIndex(function(v) {
|
||||||
|
return v.deviceId == deviceId;
|
||||||
|
});
|
||||||
|
if(index>-1){
|
||||||
|
this.PairEquip.splice(index,1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log("f=", f);
|
||||||
if (f.macAddress) {
|
if (f.macAddress) {
|
||||||
|
|
||||||
|
|
||||||
if (f.macAddress != these.device.deviceMac) {
|
if (f.macAddress != these.device.deviceMac) {
|
||||||
ble.disconnectDevice(deviceId);
|
removeLink();
|
||||||
updateLoading(these, {
|
updateLoading(these, {
|
||||||
text: "设备Mac地址错误,请重选设备连接"
|
text: "设备Mac地址错误,请重选设备连接"
|
||||||
})
|
});
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
hideLoading(these);
|
||||||
|
}, 1000)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -270,9 +295,44 @@
|
|||||||
uni.navigateBack();
|
uni.navigateBack();
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
updateLoading(these, {
|
this.Status.time = 30;
|
||||||
text: "等待设备上报Mac地址"
|
|
||||||
})
|
|
||||||
|
|
||||||
|
this.Status.intval = null;
|
||||||
|
|
||||||
|
this.Status.intval = setInterval(() => {
|
||||||
|
this.Status.time = this.Status.time-1;
|
||||||
|
if (this.Status.time < 0) {
|
||||||
|
|
||||||
|
clearInterval(this.Status.intval)
|
||||||
|
this.Status.intval = null;
|
||||||
|
this.Status.time = null;
|
||||||
|
f = ble.data.LinkedList.find(v => {
|
||||||
|
if (v.deviceId == deviceId) {
|
||||||
|
v.device = these.device;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
if(!f.macAddress){
|
||||||
|
removeLink();
|
||||||
|
updateLoading(these, {
|
||||||
|
text: "出现错误,未收到设备Mac地址"
|
||||||
|
});
|
||||||
|
|
||||||
|
setTimeout(()=>{
|
||||||
|
hideLoading(these)
|
||||||
|
},1000);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
updateLoading(these, {
|
||||||
|
|
||||||
|
text: "等待设备上报Mac地址," + these.Status.time + 's'
|
||||||
|
});
|
||||||
|
|
||||||
|
}, 1000);
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -83,7 +83,7 @@ export default {
|
|||||||
id: marker.deviceImei, // 适配deviceId字段
|
id: marker.deviceImei, // 适配deviceId字段
|
||||||
latitude: lat,
|
latitude: lat,
|
||||||
longitude: lng,
|
longitude: lng,
|
||||||
iconPath: marker.devicePic || '/static/images/common/device.png',
|
iconPath: marker.devicePic || '/static/images/common/mapLocation.png',
|
||||||
width: 40,
|
width: 40,
|
||||||
height: 40,
|
height: 40,
|
||||||
anchor: {x: 0.5, y: 0.5}, // 锚点在中心
|
anchor: {x: 0.5, y: 0.5}, // 锚点在中心
|
||||||
|
|||||||
BIN
static/images/common/mapLocation.png
Normal file
BIN
static/images/common/mapLocation.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.7 KiB |
@ -1,7 +1,7 @@
|
|||||||
import receivTool from "@/utils/BleReceive.js"
|
import receivTool from "@/utils/BleReceive.js"
|
||||||
var recei = null;
|
var recei = null;
|
||||||
const serviceDic = [ //合作供应商的蓝牙主服务
|
const serviceDic = [ //合作供应商的蓝牙主服务
|
||||||
{
|
{
|
||||||
"serviceId": "0000FFE0-0000-1000-8000-00805F9B34FB",
|
"serviceId": "0000FFE0-0000-1000-8000-00805F9B34FB",
|
||||||
"writeId": "0000FFE1-0000-1000-8000-00805F9B34FB",
|
"writeId": "0000FFE1-0000-1000-8000-00805F9B34FB",
|
||||||
"notifyId": "0000FFE2-0000-1000-8000-00805F9B34FB"
|
"notifyId": "0000FFE2-0000-1000-8000-00805F9B34FB"
|
||||||
@ -11,7 +11,7 @@ const serviceDic = [ //合作供应商的蓝牙主服务
|
|||||||
"writeId": "0000AE03-0000-1000-8000-00805F9B34FB",
|
"writeId": "0000AE03-0000-1000-8000-00805F9B34FB",
|
||||||
"notifyId": "0000AE02-0000-1000-8000-00805F9B34FB"
|
"notifyId": "0000AE02-0000-1000-8000-00805F9B34FB"
|
||||||
}
|
}
|
||||||
|
|
||||||
];
|
];
|
||||||
|
|
||||||
class BleHelper {
|
class BleHelper {
|
||||||
@ -33,17 +33,19 @@ class BleHelper {
|
|||||||
}
|
}
|
||||||
if (linkedDevices && linkedDevices.length && linkedDevices.length > 0) {
|
if (linkedDevices && linkedDevices.length && linkedDevices.length > 0) {
|
||||||
console.log("111111", linkedDevices);
|
console.log("111111", linkedDevices);
|
||||||
linkedDevices.filter((v) => {
|
linkedDevices=linkedDevices.filter((v) => {
|
||||||
v.Linked = false;
|
v.Linked = false;
|
||||||
v.notifyState = false;
|
v.notifyState = false;
|
||||||
|
|
||||||
|
return v.device && v.device.id;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this.OpenBlue().then(()=>{
|
this.OpenBlue().then(() => {
|
||||||
this.linkAllDevices();
|
this.linkAllDevices();
|
||||||
});
|
});
|
||||||
|
|
||||||
}, 10);
|
}, 10);
|
||||||
this.data = {
|
this.data = {
|
||||||
isOpenBlue: false, //蓝牙模块是否开启
|
isOpenBlue: false, //蓝牙模块是否开启
|
||||||
@ -120,7 +122,7 @@ class BleHelper {
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//从缓存中删除某个设备,bleId蓝牙id,deviceId数据库中的设备id
|
||||||
DropDevice(bleId, deviceId) {
|
DropDevice(bleId, deviceId) {
|
||||||
let flag = false;
|
let flag = false;
|
||||||
for (var i = 0; i < this.data.LinkedList.length; i++) {
|
for (var i = 0; i < this.data.LinkedList.length; i++) {
|
||||||
@ -146,6 +148,7 @@ class BleHelper {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//更新缓存
|
||||||
updateCache() {
|
updateCache() {
|
||||||
// console.log("this.StorageKey=", this.StorageKey)
|
// console.log("this.StorageKey=", this.StorageKey)
|
||||||
uni.setStorageSync(this.StorageKey, this.data.LinkedList);
|
uni.setStorageSync(this.StorageKey, this.data.LinkedList);
|
||||||
@ -155,17 +158,23 @@ class BleHelper {
|
|||||||
// console.log("模块启动时,自动连接已连接过的设备", this.data.LinkedList);
|
// console.log("模块启动时,自动连接已连接过的设备", this.data.LinkedList);
|
||||||
|
|
||||||
if (this.data.LinkedList && this.data.LinkedList.length > 0) {
|
if (this.data.LinkedList && this.data.LinkedList.length > 0) {
|
||||||
|
let flag=false;
|
||||||
for (var i = 0; i < this.data.LinkedList.length; i++) {
|
for (var i = 0; i < this.data.LinkedList.length; i++) {
|
||||||
let device = this.data.LinkedList[i];
|
let device = this.data.LinkedList[i];
|
||||||
// console.log("自动连接绑定过的设备:" + device.deviceId);
|
// console.log("自动连接绑定过的设备:" + device.deviceId);
|
||||||
if (device.macAddress && device.device && device.device.id) {
|
if (device.macAddress && device.device && device.device.id) {
|
||||||
this.LinkBlue(device.deviceId, device.writeServiceId, device.wirteCharactId, device
|
this.LinkBlue(device.deviceId, device.writeServiceId, device.wirteCharactId, device
|
||||||
.notifyCharactId);
|
.notifyCharactId);
|
||||||
|
flag=true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
if(!flag){
|
||||||
|
this.updateCache();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// console.log("无设备连接");
|
console.log("蓝牙未连接过任何设备");
|
||||||
|
this.updateCache();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -387,7 +396,7 @@ class BleHelper {
|
|||||||
}
|
}
|
||||||
uni.getBluetoothAdapterState({
|
uni.getBluetoothAdapterState({
|
||||||
success: (info) => {
|
success: (info) => {
|
||||||
console.log("蓝牙状态获取成功,",info)
|
console.log("蓝牙状态获取成功,", info)
|
||||||
this.data.available = info.available;
|
this.data.available = info.available;
|
||||||
this.data.discovering = info.discovering;
|
this.data.discovering = info.discovering;
|
||||||
resolve(info);
|
resolve(info);
|
||||||
@ -461,8 +470,8 @@ class BleHelper {
|
|||||||
|
|
||||||
if (!res.connected) {
|
if (!res.connected) {
|
||||||
|
|
||||||
console.log("蓝牙连接已断开", res);
|
console.error("蓝牙适配器已不可用", res);
|
||||||
let f=this.data.LinkedList.find((v) => {
|
let f = this.data.LinkedList.find((v) => {
|
||||||
if (v.deviceId == res.deviceId) {
|
if (v.deviceId == res.deviceId) {
|
||||||
v.Linked = false;
|
v.Linked = false;
|
||||||
v.notifyState = false;
|
v.notifyState = false;
|
||||||
@ -471,15 +480,19 @@ class BleHelper {
|
|||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
this.updateCache();
|
this.updateCache();
|
||||||
console.log("尝试5次恢复连接");
|
if (f.device && f.device.id) {
|
||||||
this.LinkBlue(res.deviceId,f.writeServiceId,f.wirteCharactId,f.notifyCharactId,5)
|
console.log("尝试5次恢复连接,", f.deviceId);
|
||||||
|
this.LinkBlue(res.deviceId, f.writeServiceId, f
|
||||||
|
.wirteCharactId, f.notifyCharactId, 5)
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
console.log("蓝牙连接已恢复,", res);
|
console.log("蓝牙适配器已恢复,", res);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
uni.onBluetoothDeviceFound((devices) => {
|
uni.onBluetoothDeviceFound((devices) => {
|
||||||
console.log("发现新设备:" + JSON.stringify(devices));
|
// console.log("发现新设备:" + JSON.stringify(devices));
|
||||||
this.data.searchList = this.data.searchList.concat(
|
this.data.searchList = this.data.searchList.concat(
|
||||||
devices);
|
devices);
|
||||||
if (this.cfg.onDeviceFound) {
|
if (this.cfg.onDeviceFound) {
|
||||||
@ -539,20 +552,20 @@ class BleHelper {
|
|||||||
});
|
});
|
||||||
this.updateCache();
|
this.updateCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (str.indexOf('imei:') == 0) {
|
if (str.indexOf('imei:') == 0) {
|
||||||
let imei = str.split(':')[1];
|
let imei = str.split(':')[1];
|
||||||
|
|
||||||
|
|
||||||
this.data.LinkedList.find((v) => {
|
this.data.LinkedList.find((v) => {
|
||||||
if (v.deviceId == receive
|
if (v.deviceId == receive
|
||||||
.deviceId) {
|
.deviceId) {
|
||||||
v.imei=imei;
|
v.imei = imei;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.updateCache();
|
this.updateCache();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bytes[0] == 0xFC) { //6155以0xFC开头代表mac地址
|
if (bytes[0] == 0xFC) { //6155以0xFC开头代表mac地址
|
||||||
console.log("收到mac地址:", bytes)
|
console.log("收到mac地址:", bytes)
|
||||||
@ -572,7 +585,7 @@ class BleHelper {
|
|||||||
}
|
}
|
||||||
console.log("str=", str);
|
console.log("str=", str);
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
console.log("将数据转文本失败", ex);
|
console.error("将数据转文本失败", ex);
|
||||||
}
|
}
|
||||||
let recData = {
|
let recData = {
|
||||||
deviceId: receive.deviceId,
|
deviceId: receive.deviceId,
|
||||||
@ -589,31 +602,32 @@ class BleHelper {
|
|||||||
if (this.cfg.receivDataCallback.length > 0) {
|
if (this.cfg.receivDataCallback.length > 0) {
|
||||||
|
|
||||||
let path = this.getCurrentPagePath();
|
let path = this.getCurrentPagePath();
|
||||||
console.log("有人订阅消息")
|
// console.log("有人订阅消息")
|
||||||
this.cfg.receivDataCallback.forEach((
|
this.cfg.receivDataCallback.forEach((
|
||||||
rec) => {
|
rec) => {
|
||||||
console.log("有人订阅消息111", )
|
// console.log("有人订阅消息111", )
|
||||||
if (rec.callback) {
|
if (rec.callback) {
|
||||||
try {
|
try {
|
||||||
rec.callback(recData, f,
|
rec.callback(recData, f,
|
||||||
path, this.cfg
|
path, this.cfg
|
||||||
.receivDataCallback
|
.receivDataCallback
|
||||||
);
|
);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log("订阅消息出现异常",
|
console.error(
|
||||||
|
"订阅消息出现异常",
|
||||||
err);
|
err);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
console.log("无人订阅消息");
|
// console.log("无人订阅消息");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
console.log("无人订阅receivDataCallback,不处理数据");
|
// console.log("无人订阅receivDataCallback,不处理数据");
|
||||||
}
|
}
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
console.log("ex=", ex);
|
console.error("处理订阅消息失败,ex=", ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
@ -638,7 +652,7 @@ class BleHelper {
|
|||||||
console.log("res=", res)
|
console.log("res=", res)
|
||||||
return init();
|
return init();
|
||||||
}).then(resolve).catch((ex) => {
|
}).then(resolve).catch((ex) => {
|
||||||
console.log("22222");
|
console.error("异常:", ex);
|
||||||
reject(ex);
|
reject(ex);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -690,7 +704,7 @@ class BleHelper {
|
|||||||
let RunSearch = (serviceId) => {
|
let RunSearch = (serviceId) => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
uni.startBluetoothDevicesDiscovery({
|
uni.startBluetoothDevicesDiscovery({
|
||||||
services:serviceId? [serviceId]:[],
|
services: serviceId ? [serviceId] : [],
|
||||||
allowDuplicatesKey: true,
|
allowDuplicatesKey: true,
|
||||||
success: (res) => {
|
success: (res) => {
|
||||||
//console.log('开始搜索蓝牙设备成功');
|
//console.log('开始搜索蓝牙设备成功');
|
||||||
@ -713,9 +727,9 @@ class BleHelper {
|
|||||||
// for (let i = 0; i < serviceIds.length; i++) {
|
// for (let i = 0; i < serviceIds.length; i++) {
|
||||||
|
|
||||||
// promises.push(RunSearch(serviceIds[i]));
|
// promises.push(RunSearch(serviceIds[i]));
|
||||||
|
|
||||||
// }
|
// }
|
||||||
promises.push(RunSearch());
|
promises.push(RunSearch());
|
||||||
Promise.all(promises).then(resolve).catch(reject);
|
Promise.all(promises).then(resolve).catch(reject);
|
||||||
|
|
||||||
});
|
});
|
||||||
@ -778,14 +792,29 @@ class BleHelper {
|
|||||||
|
|
||||||
//订阅消息
|
//订阅消息
|
||||||
subScribe(deviceId, state) {
|
subScribe(deviceId, state) {
|
||||||
console.log("开始订阅消息");
|
console.log("开始订阅消息", state);
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
|
|
||||||
let c = this.data.LinkedList.find((v) => {
|
let c = this.data.LinkedList.find((v) => {
|
||||||
return v.deviceId == deviceId;
|
return v.deviceId == deviceId;
|
||||||
});
|
});
|
||||||
|
if (!deviceId) {
|
||||||
|
console.error('deviceId无效')
|
||||||
|
reject({
|
||||||
|
code: 404,
|
||||||
|
msg: 'deviceId无效'
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!c) {
|
||||||
|
console.error("已找不到该设备");
|
||||||
|
reject({
|
||||||
|
code: 404,
|
||||||
|
msg: '已找不到该设备'
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (state) {
|
if (state) {
|
||||||
if (c.notifyState) {
|
if (c.notifyState) {
|
||||||
resolve();
|
resolve();
|
||||||
@ -794,8 +823,8 @@ class BleHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let startSubScribe = (id, serviceId, characteristicId) => {
|
let startSubScribe = (id, serviceId, characteristicId) => {
|
||||||
console.log("serviceId=", serviceId);
|
// console.log("serviceId=", serviceId);
|
||||||
console.log("characteristicId=", characteristicId);
|
// console.log("characteristicId=", characteristicId);
|
||||||
let p1 = new Promise((succ, err) => {
|
let p1 = new Promise((succ, err) => {
|
||||||
|
|
||||||
uni.notifyBLECharacteristicValueChange({
|
uni.notifyBLECharacteristicValueChange({
|
||||||
@ -836,6 +865,7 @@ class BleHelper {
|
|||||||
});
|
});
|
||||||
return new Promise((succ, err) => {
|
return new Promise((succ, err) => {
|
||||||
Promise.race([p1, p2]).then(succ).catch(ex => {
|
Promise.race([p1, p2]).then(succ).catch(ex => {
|
||||||
|
// console.error("异常了:",ex);
|
||||||
if (ex.code == -1) {
|
if (ex.code == -1) {
|
||||||
succ();
|
succ();
|
||||||
return;
|
return;
|
||||||
@ -845,8 +875,16 @@ class BleHelper {
|
|||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let serv = serviceDic.find(v => {
|
||||||
|
return v.serviceId == c.writeServiceId;
|
||||||
|
});
|
||||||
let promies = new Array();
|
let promies = new Array();
|
||||||
if (c.Characteristics && c.Characteristics.length) {
|
if (c.notifyServiceid && c.notifyCharactId) {
|
||||||
|
promies.push(startSubScribe(c.deviceId, c.notifyServiceid, c.notifyCharactId));
|
||||||
|
} else if (serv) {
|
||||||
|
promies.push(startSubScribe(c.deviceId, serv.serviceId, serv.notifyId));
|
||||||
|
} else if (c.Characteristics && c.Characteristics.length) {
|
||||||
for (var i = 0; i < c.Characteristics.length; i++) {
|
for (var i = 0; i < c.Characteristics.length; i++) {
|
||||||
let item = c.Characteristics[i];
|
let item = c.Characteristics[i];
|
||||||
let serviceId = item.serviceId;
|
let serviceId = item.serviceId;
|
||||||
@ -854,36 +892,42 @@ class BleHelper {
|
|||||||
|
|
||||||
if (item.properties.notify) {
|
if (item.properties.notify) {
|
||||||
promies.push(startSubScribe(deviceId, serviceId, characteristicId));
|
promies.push(startSubScribe(deviceId, serviceId, characteristicId));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}else{
|
} else {
|
||||||
promies.push(startSubScribe(c.deviceId, c.notifyServiceid, c.notifyCharactId));
|
console.log("c=", c);
|
||||||
|
console.log("serv=", serv);
|
||||||
|
reject({
|
||||||
|
code: 403,
|
||||||
|
msg: "出现错误,找不到任何通知特征"
|
||||||
|
});
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (promies.length > 0) {
|
if (promies.length > 0) {
|
||||||
|
|
||||||
|
|
||||||
Promise.allSettled(promies).then((results) => {
|
Promise.allSettled(promies).then((results) => {
|
||||||
|
|
||||||
results.forEach((result, index) => {
|
results.forEach((result, index) => {
|
||||||
if (result.status === "fulfilled") {
|
if (result.status === "fulfilled") {
|
||||||
// console.log(`操作${index + 1}成功:`, result.value);
|
// console.log(`操作${index + 1}成功:`, result.value);
|
||||||
} else {
|
} else {
|
||||||
// console.log(`操作${index + 1}失败:`, result.reason
|
// console.log(`操作${index + 1}失败:`, result.reason
|
||||||
// .message);
|
// .message);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// console.log("订阅消息成功");
|
// console.log("订阅消息成功");
|
||||||
resolve();
|
resolve();
|
||||||
}).catch((ex) => {
|
}).catch((ex) => {
|
||||||
console.log("ex=",ex);
|
console.error("异常,ex=", ex);
|
||||||
reject(ex);
|
reject(ex);
|
||||||
}).finally(() => {
|
}).finally(() => {
|
||||||
// console.log("finally")
|
// console.log("finally")
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
console.log("没有特征需要订阅");
|
console.log("没有特征需要订阅");
|
||||||
resolve();
|
resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -933,7 +977,7 @@ class BleHelper {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (se) {
|
if (se) {
|
||||||
console.log("合作供应商的",s)
|
console.log("合作供应商的", s)
|
||||||
this.data.LinkedList.find((v) => {
|
this.data.LinkedList.find((v) => {
|
||||||
if (v.deviceId == id) {
|
if (v.deviceId == id) {
|
||||||
v.writeServiceId = s.serviceId;
|
v.writeServiceId = s.serviceId;
|
||||||
@ -983,11 +1027,11 @@ class BleHelper {
|
|||||||
.then((res) => {
|
.then((res) => {
|
||||||
console.log('设备连接成功,初始化完成', this.data
|
console.log('设备连接成功,初始化完成', this.data
|
||||||
.LinkedList);
|
.LinkedList);
|
||||||
|
|
||||||
resolve();
|
resolve();
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
console.log("errrr", error);
|
console.error("errrr=", error);
|
||||||
reject(error);
|
reject(error);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -1200,7 +1244,7 @@ class BleHelper {
|
|||||||
deviceId: deviceId,
|
deviceId: deviceId,
|
||||||
mtu: 512,
|
mtu: 512,
|
||||||
success: (mtu) => {
|
success: (mtu) => {
|
||||||
|
|
||||||
resolve(true);
|
resolve(true);
|
||||||
},
|
},
|
||||||
fail: () => {
|
fail: () => {
|
||||||
@ -1288,7 +1332,7 @@ class BleHelper {
|
|||||||
resolve();
|
resolve();
|
||||||
}, 500);
|
}, 500);
|
||||||
}).catch((ex) => {
|
}).catch((ex) => {
|
||||||
console.log("出现异常", ex);
|
console.error("出现异常", ex);
|
||||||
reject(ex);
|
reject(ex);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -1429,7 +1473,7 @@ class BleHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Promise.race([timeOut(ms), promise]).then(resolve).catch((ex) => {
|
Promise.race([timeOut(ms), promise]).then(resolve).catch((ex) => {
|
||||||
// console.log("ex=", ex);
|
// console.error("ex=", ex);
|
||||||
if (ex.code == -1) {
|
if (ex.code == -1) {
|
||||||
resolve(ex);
|
resolve(ex);
|
||||||
} else {
|
} else {
|
||||||
@ -1469,7 +1513,7 @@ class BleHelper {
|
|||||||
//console.log("发送成功")
|
//console.log("发送成功")
|
||||||
resolve();
|
resolve();
|
||||||
}).catch((ex) => {
|
}).catch((ex) => {
|
||||||
//console.log("出现异常", ex);
|
console.error("出现异常", ex);
|
||||||
reject(this.getError(ex));
|
reject(this.getError(ex));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -22,6 +22,9 @@ class BleReceive {
|
|||||||
setBleFormData(data,f) {
|
setBleFormData(data,f) {
|
||||||
if(data){
|
if(data){
|
||||||
let linkedList=uni.getStorageSync(this.StorageKey);
|
let linkedList=uni.getStorageSync(this.StorageKey);
|
||||||
|
if(!linkedList){
|
||||||
|
return;
|
||||||
|
}
|
||||||
linkedList.find((v)=>{
|
linkedList.find((v)=>{
|
||||||
if(f.deviceId==v.deviceId){
|
if(f.deviceId==v.deviceId){
|
||||||
let keys=Object.keys(data);
|
let keys=Object.keys(data);
|
||||||
|
|||||||
Reference in New Issue
Block a user