1
0
forked from dyf/APP

修复蓝牙连接锁未释放的问题

This commit is contained in:
liub
2026-04-30 11:23:28 +08:00
parent 677586e51c
commit 6d9df4c945
24 changed files with 1225 additions and 759 deletions

67
App.vue
View File

@ -74,9 +74,23 @@
}); });
}); });
//监听网络变化
uni.onNetworkStatusChange((res)=>{
let title='网络连接已断开';
if(res.isConnected){
title='网络连接已恢复';
}
uni.showToast({
title:title
});
});
} }
if (plus.os.name == 'Android') { if (system.osName == 'android') {
if (plus.runtime.isAgreePrivacy()) { if (plus.runtime.isAgreePrivacy()) {
initOS(); initOS();
} }
@ -121,6 +135,10 @@
console.log('App Hide'); console.log('App Hide');
// #ifdef APP|APP-PLUS // #ifdef APP|APP-PLUS
uni.offNetworkStatusChange(result=>{
console.log("取消监听网络变化");
});
uni.setKeepScreenOn({ uni.setKeepScreenOn({
keepScreenOn: false keepScreenOn: false
}).then(res => { }).then(res => {
@ -181,6 +199,7 @@
// } // }
/* #endif */ /* #endif */
/* #ifndef APP-NVUE|APP-PLUS-NVUE */
.custom-file-picker .file-picker__box-content { .custom-file-picker .file-picker__box-content {
background: rgba(26, 26, 26, 1); background: rgba(26, 26, 26, 1);
border: none !important; border: none !important;
@ -188,76 +207,76 @@
width: 180rpx; width: 180rpx;
height: 180rpx; height: 180rpx;
} }
.uni-file-picker.custom-file-picker { .uni-file-picker.custom-file-picker {
overflow: inherit !important; overflow: inherit !important;
} }
.custom-file-picker .icon-add { .custom-file-picker .icon-add {
height: 5rpx !important; height: 5rpx !important;
width: 70rpx !important; width: 70rpx !important;
} }
.uni-picker-view-mask { .uni-picker-view-mask {
background: rgba(42, 42, 42, 1); background: rgba(42, 42, 42, 1);
z-index: -1; z-index: -1;
} }
.uni-picker-view-content { .uni-picker-view-content {
position: inherit; position: inherit;
} }
.uni-picker-view-wrapper { .uni-picker-view-wrapper {
background: rgba(42, 42, 42, 1); background: rgba(42, 42, 42, 1);
} }
.green { .green {
color: #aed600 !important; color: #aed600 !important;
} }
.red { .red {
color: #FF0000 !important; color: #FF0000 !important;
} }
.maincontent { .maincontent {
width: 100%; width: 100%;
min-height: 100vh; min-height: 100vh;
height: auto; height: auto;
padding: 30rpx; padding: 30rpx;
box-sizing: border-box; box-sizing: border-box;
} }
.contentBg { .contentBg {
background-color: #121212; background-color: #121212;
color: #ffffffde; color: #ffffffde;
} }
.uni-app--maxwidth, .uni-app--maxwidth,
.uni-body { .uni-body {
background-color: #121212; background-color: #121212;
} }
.fleft { .fleft {
float: left; float: left;
} }
.fright { .fright {
float: right; float: right;
} }
.clear { .clear {
clear: both; clear: both;
} }
.displayNone { .displayNone {
display: none !important; display: none !important;
} }
.visibilityHidden { .visibilityHidden {
visibility: hidden !important; visibility: hidden !important;
} }
.center { .center {
display: flex; display: flex;
flex-direction: row; flex-direction: row;
@ -266,25 +285,27 @@
justify-content: center; justify-content: center;
align-items: center; align-items: center;
} }
.navbarRight .img { .navbarRight .img {
width: 35rpx; width: 35rpx;
height: 35rpx; height: 35rpx;
margin-right: 30rpx; margin-right: 30rpx;
} }
.uni-navbar--fixed { .uni-navbar--fixed {
top: 0rpx; top: 0rpx;
} }
::v-deep .uni-navbar--fixed { ::v-deep .uni-navbar--fixed {
top: 0px; top: 0px;
} }
::v-deep .uni-navbar__placeholder { ::v-deep .uni-navbar__placeholder {
display: none !important; display: none !important;
} }
/* #endif */
// @font-face { // @font-face {
// font-family: "PingFang SC"; // font-family: "PingFang SC";

View File

@ -469,13 +469,7 @@
"navigationBarTitleText": "" "navigationBarTitleText": ""
} }
}, },
{
"path": "pages/210/HBY210",
"style": {
"navigationStyle": "custom",
"navigationBarTitleText": "HBY210"
}
},
{ {
"path": "pages/common/sosSet/TxtMsgSetting", "path": "pages/common/sosSet/TxtMsgSetting",
"style": { "style": {

View File

@ -193,7 +193,7 @@
} }
}, },
created() { created() {
this.Status.navbar.height = uni.getSystemInfoSync().statusBarHeight + 20; this.Status.navbar.height = uni.getSystemInfoSync().statusBarHeight + 44;
}, },
onUnload() { onUnload() {
console.log("页面卸载,释放资源"); console.log("页面卸载,释放资源");

View File

@ -15,7 +15,7 @@
</block> </block>
</uni-nav-bar> </uni-nav-bar>
<view class="eq"> <view class="eq" :style="{marginTop:Status.navbar.height+'px'}">
<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>
@ -84,7 +84,7 @@
</view> </view>
</view> </view>
<view class="warnnig" v-show="formData.sta_ShakeBit!='' && formData.sta_ShakeBit!='0'" <view class="warnnig" v-show="formData.sta_ShakeBit==1 && formData.sta_ShakeBit==2"
@click="showAction('map')"> @click="showAction('map')">
<view>{{ShakeBit}}</view> <view>{{ShakeBit}}</view>
</view> </view>
@ -297,7 +297,10 @@
permissions: [] permissions: []
} }
}, },
created() {
this.Status.navbar.height = uni.getSystemInfoSync().statusBarHeight + 44;
console.log("this.Status.navbar.height=",this.Status.navbar.height);
},
onUnload() { onUnload() {
console.log("页面卸载,释放资源"); console.log("页面卸载,释放资源");
ble.removeAllCallback(pagePath); ble.removeAllCallback(pagePath);
@ -355,7 +358,7 @@
these.device.latitude = form.sta_latitude; these.device.latitude = form.sta_latitude;
these.formData.blename = f.name ? f.name : "Unname"; these.formData.blename = f.name ? f.name : "Unname";
these.formData.deviceName = device.deviceName; these.formData.deviceName = device.deviceName;
these.formData.bleStatu = false; these.formData.bleStatu = false;
these.formData.deviceId = f.deviceId; these.formData.deviceId = f.deviceId;
ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId).then(res => { ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId).then(res => {
@ -412,6 +415,7 @@
let dic = { let dic = {
"1": "设备SOS求救中", "1": "设备SOS求救中",
"2": "设备静止报警中", "2": "设备静止报警中",
"6":"设备遇水报警中"
}; };
let keys = Object.keys(dic); let keys = Object.keys(dic);
let f = keys.find(key => { let f = keys.find(key => {

View File

@ -21,7 +21,7 @@
</uni-nav-bar> </uni-nav-bar>
<view class="eq"> <view class="eq" :style="{marginTop:Status.navbar.height+'px'}">
<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>
@ -280,7 +280,8 @@
callback: this.gotoShare, callback: this.gotoShare,
apiType: 'listA' apiType: 'listA'
}], }],
title: 'HBY100' title: 'HBY100',
height:90
}, },
curr: 0, curr: 0,
@ -465,7 +466,9 @@
} }
} }
}, },
created() {
this.Status.navbar.height = uni.getSystemInfoSync().statusBarHeight + 44;
},
onUnload() { onUnload() {
console.log("页面卸载,释放资源"); console.log("页面卸载,释放资源");
ble.removeAllCallback(pagePath); ble.removeAllCallback(pagePath);

View File

@ -188,7 +188,7 @@
} }
}, },
created() { created() {
this.Status.navbar.height = uni.getSystemInfoSync().statusBarHeight + 20; this.Status.navbar.height = uni.getSystemInfoSync().statusBarHeight + 44;
}, },
onUnload() { onUnload() {
console.log("页面卸载,释放资源"); console.log("页面卸载,释放资源");

View File

@ -21,7 +21,7 @@
</uni-nav-bar> </uni-nav-bar>
<view class="eq"> <view class="eq" :style="{marginTop:Status.navbar.height+'px'}">
<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>
@ -298,8 +298,8 @@
callback: this.gotoShare callback: this.gotoShare
} }
], ],
title: 'HBY102' title: 'HBY102',
height:90
}, },
apiType: '' apiType: ''
}, },
@ -419,7 +419,9 @@
permissions: [] permissions: []
} }
}, },
created() {
this.Status.navbar.height = uni.getSystemInfoSync().statusBarHeight + 44;
},
onUnload() { onUnload() {
console.log("页面卸载,释放资源"); console.log("页面卸载,释放资源");
ble.removeAllCallback(pagePath); ble.removeAllCallback(pagePath);

View File

@ -88,33 +88,33 @@
<view class="warnnig" :class="ShakeBit?'':'displayNone'"> <view class="warnnig" :class="ShakeBit?'':'displayNone'">
<view>{{ShakeBit}}</view> <view>{{ShakeBit}}</view>
<view>{{AlarmTime}}</view> <view>{{AlarmTime}}</view>
<uni-icons type="closeempty" size="16" color="#FFFFFF" @click="CloseWarn()"></uni-icons> <uni-icons type="closeempty" size="16" color="#FFFFFF" @click.stop="CloseWarn()"></uni-icons>
</view> </view>
<view class="lampMode"> <view class="lampMode">
<view class="mode " :class="{active:formData.sta_SOSGrade=='2'}" v-on:click.stop="sosSetting(2)"> <view class="mode " :class="{active:formData.sta_SOSGrade==2}" v-on:click.stop="sosSetting(2)">
<view class="leftImg"> <view class="leftImg">
<image v-show="formData.sta_SOSGrade!='2'" class="img" src="/static/images/670/rb.png" <image v-show="formData.sta_SOSGrade!=2" class="img" src="/static/images/670/rb.png"
mode="aspectFit"></image> mode="aspectFit"></image>
<image v-show="formData.sta_SOSGrade=='2'" class="img" src="/static/images/670/rbActive.png" <image v-show="formData.sta_SOSGrade==2" class="img" src="/static/images/670/rbActive.png"
mode="aspectFit"></image> mode="aspectFit"></image>
</view> </view>
<view class="rightTxt"> <view class="rightTxt">
<text class="bigTxt">红蓝警示</text> <text class="bigTxt">红蓝警示</text>
<text class="smallTxt">{{formData.sta_SOSGrade=='2'?'开启':'关闭'}}</text> <text class="smallTxt">{{formData.sta_SOSGrade==2?'开启':'关闭'}}</text>
</view> </view>
</view> </view>
<view class="mode " :class="{active:formData.sta_SOSGrade=='1'}" v-on:click.stop="sosSetting(1)"> <view class="mode " :class="{active:formData.sta_SOSGrade==1}" v-on:click.stop="sosSetting(1)">
<view class="leftImg"> <view class="leftImg">
<image v-show="formData.sta_SOSGrade!='1'" class="img" src="/static/images/670/sg.png" <image v-show="formData.sta_SOSGrade!=1" class="img" src="/static/images/670/sg.png"
mode="aspectFit"></image> mode="aspectFit"></image>
<image v-show="formData.sta_SOSGrade=='1'" class="img" src="/static/images/670/sgActive.png" <image v-show="formData.sta_SOSGrade==1" class="img" src="/static/images/670/sgActive.png"
mode="aspectFit"></image> mode="aspectFit"></image>
</view> </view>
<view class="rightTxt"> <view class="rightTxt">
<text class="bigTxt">声光报警</text> <text class="bigTxt">声光报警</text>
<text class="smallTxt">{{formData.sta_SOSGrade=='1'?'开启':'关闭'}}</text> <text class="smallTxt">{{formData.sta_SOSGrade==1?'开启':'关闭'}}</text>
</view> </view>
</view> </view>
@ -170,28 +170,42 @@
<view class="item"> <view class="item">
<text class="lbl">单位</text> <text class="lbl">单位</text>
<input class="value" v-model.trim="formData.company" placeholder="请输入单位" maxlength="8" <input class="value" v-model.trim="formData.company" placeholder="请输入单位" maxlength="6"
placeholder-class="usrplace" /> placeholder-class="usrplace" />
</view> </view>
<view class="item"> <view class="item">
<text class="lbl">姓名</text> <text class="lbl">姓名</text>
<input class="value" v-model.trim="formData.usrname" placeholder="请输入职位" maxlength="8" <input class="value" v-model.trim="formData.usrname" placeholder="请输入职位" maxlength="6"
placeholder-class="usrplace" /> placeholder-class="usrplace" />
</view> </view>
<view class="item"> <view class="item">
<text class="lbl">部门</text> <text class="lbl">部门</text>
<input class="value" v-model.trim="formData.job" placeholder="请输入姓名" maxlength="8" <input class="value" v-model.trim="formData.job" placeholder="请输入姓名" maxlength="6"
placeholder-class="usrplace" /> placeholder-class="usrplace" />
</view> </view>
<view class="item"> <view class="item">
<text class="lbl">ID</text> <text class="lbl">ID</text>
<input class="value" v-model.trim="formData.usrid" placeholder="ID" maxlength="16" <input class="value" v-model.trim="formData.usrid" placeholder="ID" maxlength="6"
placeholder-class="usrplace" /> placeholder-class="usrplace" />
</view> </view>
</view> </view>
<view class="usrinfo">
<view>
<text class="usrtitle fleft">发送信息</text>
<view class="btnSend fright" v-on:click.stop="sendMsg(null)">发送</view>
<view class="clear"></view>
</view>
<view>
<view class="item">
<input maxlength="16" class="value" style="text-indent: 20rpx;" v-model="formData.sendMsg"
placeholder="请输入文字" placeholder-class="usrplace" />
</view>
</view>
</view>
<BottomSlideMenuPlus :config="Status.BottomMenu" @btnClick="btnClick" @itemClick="itemClick" <BottomSlideMenuPlus :config="Status.BottomMenu" @btnClick="btnClick" @itemClick="itemClick"
@close="closeActionSheet"></BottomSlideMenuPlus> @close="closeActionSheet"></BottomSlideMenuPlus>
@ -229,6 +243,7 @@
import BleTool from '@/utils/BleHelper.js' import BleTool from '@/utils/BleHelper.js'
import BleReceive from '@/utils/BleReceive'; import BleReceive from '@/utils/BleReceive';
import SendBatchData from '@/utils/SendBatchData.js'; import SendBatchData from '@/utils/SendBatchData.js';
import MqttClient from '@/utils/mqtt.js';
var batchTool = null; var batchTool = null;
var eventChannel = null; var eventChannel = null;
@ -237,7 +252,7 @@
var recei = null; var recei = null;
var mq = null; var mq = null;
var pagePath = "/pages/210/HBY210"; var pagePath = "/pages/210/HBY210";
var sosTime = null;
export default { export default {
components: { components: {
TextToHexV1 TextToHexV1
@ -353,10 +368,11 @@
address: "", //地址 address: "", //地址
company: "湖北消防总队", //单位 company: "", //单位
usrname: "胡红军", //姓名 usrname: "", //姓名
job: "中队长", //职位 job: "", //职位
usrid: "", //id usrid: "", //id
sendMsg: '',
deviceId: "", deviceId: "",
@ -371,7 +387,8 @@
sta_RadarType: "", sta_RadarType: "",
sta_ShakeBit: 0, //报警状态 sta_ShakeBit: 0, //报警状态
sta_InfraRed: 0, sta_InfraRed: 0,
textLines: ['湖北星汉文化', '有限', '公司', '12345678'] textLines: ['湖北星汉文化', '有限', '公司', '12345678'],
sta_BreakNews:''
}, },
device: { device: {
id: "", id: "",
@ -457,22 +474,22 @@
return '开机充电中' return '开机充电中'
} }
}, },
RadarType(){ RadarType() {
let f=this.Status.BottomMenu.menuItems.find(v=>{ let f = this.Status.BottomMenu.menuItems.find(v => {
return v.value==this.formData.sta_RadarType; return v.value == this.formData.sta_RadarType;
}); });
if(f){ if (f) {
return f.text; return f.text;
} }
return '关闭'; return '关闭';
} }
}, },
created() { created() {
this.Status.navbar.height = uni.getSystemInfoSync().statusBarHeight + 20; this.Status.navbar.height = uni.getSystemInfoSync().statusBarHeight + 44;
}, },
onUnload() { onUnload() {
console.log("页面卸载,释放资源"); console.log("页面卸载,释放资源");
@ -502,7 +519,7 @@
}, },
onLoad() { onLoad() {
this.initWatch();
these = this; these = this;
recei = BleReceive.getBleReceive(); recei = BleReceive.getBleReceive();
ble = BleTool.getBleTool(); ble = BleTool.getBleTool();
@ -547,16 +564,19 @@
}); });
if (!f) { if (!f) {
these.showBleUnConnect(); these.showBleUnConnect();
// these.getDetail(); these.getDetail();
console.log("初始 sta_SOSGrade 值:", these.formData.sta_SOSGrade);
return; return;
} }
let form = f.formData; let form = f.formData;
if (form) { if (form) {
let keys = Object.keys(form); let keys = Object.keys(form);
for (var i = keys.length; i >= 0; i--) { for (let i = 0; i < keys.length; i++) {
let key = keys[i]; let key = keys[i];
if (key && form[key] != undefined) {
these.formData[key] = form[key];
}
these.formData[key] = form[key];
} }
} }
if (these.formData['imei'] && !these.device.deviceImei) { if (these.formData['imei'] && !these.device.deviceImei) {
@ -564,7 +584,7 @@
} else if (these.device.deviceImei) { } else if (these.device.deviceImei) {
these.formData['imei'] = these.device.deviceImei; these.formData['imei'] = these.device.deviceImei;
} }
// these.getDetail(); these.getDetail();
these.formData.bleStatu = 'connecting'; these.formData.bleStatu = 'connecting';
ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId).then(res => { ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId).then(res => {
@ -573,11 +593,42 @@
these.formData.bleStatu = 'err'; these.formData.bleStatu = 'err';
MsgError("连接错误:" + ex.msg, "确定", these); MsgError("连接错误:" + ex.msg, "确定", these);
}); });
console.log("初始 sta_SOSGrade 值:", these.formData.sta_SOSGrade);
}); });
}, },
methods: { methods: {
initWatch(){
this.$watch('formData.sta_BreakNews',(newVal,oldVal)=>{
if(newVal && newVal=='I get it'){
MsgSuccess("用户已确认收到紧急通知", "确定", these);
setTimeout(() => {
these.formData.sta_BreakNews = "";
}, 10);
}
});
this.$watch("formData.sta_PowerPercent", (newVal, oldVal) => {
console.log("电量发生变化");
if (newVal <= 20 && (this.formData.sta_system === 2 || this.formData.sta_system === 0)) {
//电量在20%及以及下,且是未充电状态提醒
showPop({
message: "设备电量低于20%,请充电",
borderColor: "#e034344d",
buttonBgColor: "#E03434",
buttonText: '确定',
buttonTextColor: '#FFFFFFde',
showCancel: false,
showHeader: false,
visibleClose: true,
textColor: '#E03434',
iconUrl: '/static/images/common/path.png'
}, this);
}
});
},
showAction(type) { showAction(type) {
if (type == 'BottomMenu') { if (type == 'BottomMenu') {
this.Status.BottomMenu.show = true; this.Status.BottomMenu.show = true;
@ -591,7 +642,7 @@
} else { } else {
this.Status.PictureMenu.show = true; this.Status.PictureMenu.show = true;
this.Status.BottomMenu.show = false; this.Status.BottomMenu.show = false;
this.Status.PictureMenu.activeIndex=0; this.Status.PictureMenu.activeIndex = 0;
} }
}, },
@ -1153,13 +1204,13 @@
}, },
btnClick() { btnClick() {
let f = this.getDevice(); let f = this.getDevice();
if (!f) { // if (!f) {
this.showBleUnConnect(); // this.showBleUnConnect();
return; // return;
} // }
this.Status.BottomMenu.show = false; this.Status.BottomMenu.show = false;
let d = this.Status.BottomMenu.menuItems[this.Status.BottomMenu.activeIndex]; let d = this.Status.BottomMenu.menuItems[this.Status.BottomMenu.activeIndex];
let bleSend = () => { let bleSend = () => {
let json = { let json = {
@ -1167,20 +1218,25 @@
}; };
json = JSON.stringify(json); json = JSON.stringify(json);
if (ble) { if (ble && f) {
ble.sendString(f.deviceId, json).then(res => { ble.sendString(f.deviceId, json).then(res => {
console.log("ble send success") console.log("ble send success")
this.formData.sta_RadarType = d.value; this.formData.sta_RadarType = d.value;
}).catch(ex => { }).catch(ex => {
this.mqSend(json); this.mqSend(json).then(res => {
console.log("ble send success")
this.formData.sta_RadarType = d.value;
});
});
} else {
this.mqSend(json).then(res => {
console.log("ble send success")
this.formData.sta_RadarType = d.value;
}); });
} }
} }
bleSend(); bleSend();
}, },
itemClick(item, index) { itemClick(item, index) {
this.Status.BottomMenu.activeIndex = index; this.Status.BottomMenu.activeIndex = index;
@ -1210,201 +1266,20 @@
if (!batchTool) { if (!batchTool) {
batchTool = new SendBatchData(these, f, ble); batchTool = new SendBatchData(these, f, ble);
} }
batchTool.SendUsr(4); batchTool.SendUsr(4);
return; return;
// let toByteValue = (value) => {
// if (typeof value === 'number') {
// return value;
// }
// if (typeof value === 'string') {
// if (value.startsWith('0x') || value.startsWith('0X')) {
// return parseInt(value, 16);
// }
// return parseInt(`0x${value}`, 16);
// }
// return 0;
// }
// let err = false;
// this.formData.textLines.find((txt) => {
// if (txt.length === 0) {
// console.log("txt=", txt);
// err = true;
// return true;
// }
// return false;
// })
// if (err) {
// MsgError('单位、部门、姓名、ID必须填写', '', these);
// return;
// }
// showLoading(these, {
// text: "请稍候..."
// });
// //握手
// let holdHand = () => {
// return new Promise((resolve, reject) => {
// updateLoading(these, {
// text: '设备准备中...'
// })
// let hexs = 'word transmit start';
// ble.sendString(f.deviceId, hexs, f.writeServiceId, f.wirteCharactId, 10).then(res => {
// setTimeout(() => {
// resolve(res)
// }, 2200);
// }).catch(ex => {
// reject(ex)
// });
// });
// }
// //画图
// let drawText = () => {
// return new Promise((resolve, reject) => {
// this.$refs.textToHex.drawAndGetPixels().then(allPixels => {
// if (!allPixels) {
// reject("文本初始化失败");
// return;
// }
// resolve(allPixels);
// }).catch(compEx => {
// reject(compEx);
// });
// });
// }
// //发送3个分包的数据
// let task = (allPixels) => {
// try {
// let combinedData = [];
// for (let i = 0; i < this.formData.textLines.length; i++) {
// let linePixels = (allPixels[i] || []).flat(Infinity).map(item =>
// typeof item === 'string' ? toByteValue(item) : item
// );
// for (var j = linePixels.length; j < 256; j++) {
// linePixels.push(0x00);
// }
// combinedData.push([0xFA, 0x06, i + 1, 1].concat(linePixels.slice(0, 128)));
// combinedData.push([0xFA, 0x06, i + 1, 2].concat(linePixels.slice(128, 256)));
// }
// combinedData.push([0x74, 0x72, 0x61, 0x6E, 0x73, 0x6D, 0x69, 0x74, 0x20, 0x63, 0x6F, 0x6D,
// 0x70, 0x6C, 0x65, 0x74, 0x65
// ]);
// let curr = 1;
// let len = combinedData.length;
// console.log(combinedData);
// showLoading(these, {
// text: '正在发送' + (curr - 1) + '/' + len
// });
// //分包发送
// let sendPacket = () => {
// if (combinedData.length === curr - 1) {
// these.setBleFormData();
// MsgSuccess("发送成功", '', these);
// let json = {
// deviceId: these.device.id,
// name: these.formData.textLines[1],
// position: these.formData.textLines[0],
// unitName: these.formData.textLines[2],
// code: ""
// };
// usrApi.sendUsr(json);
// hideLoading(these);
// return;
// }
// let array = combinedData[curr - 1];
// ble.sendHexs(f.deviceId, array, f.writeServiceId, f.wirteCharactId, 10).then(
// res => {
// updateLoading(these, {
// text: '正在发送' + curr + '/' + len
// });
// curr++;
// setTimeout(sendPacket, 300);
// }).catch(err => {
// if (err.code == '10007') {
// setTimeout(sendPacket, 300);
// } else {
// console.log("err:", err);
// hideLoading(these);
// MsgError("发送失败: " + (err.msg || err.message), '', these)
// }
// });
// }
// setTimeout(sendPacket, 0);
// // 5. 发送成功处理
// } catch (ex) {
// hideLoading(these);
// MsgError("发送失败: " + (ex.msg || ex.message), '', these);
// }
// }
// setTimeout(() => {
// Promise.allSettled([holdHand(), drawText()]).then(results => {
// console.log("results=", results)
// if (results[0].status == 'rejected') {
// updateLoading(these, {
// text: results[0].reason
// });
// setTimeout(() => {
// hideLoading(these)
// }, 500);
// return;
// }
// if (results[1].status == 'rejected') {
// updateLoading(these, {
// text: results[1].reason
// })
// setTimeout(() => {
// hideLoading(these)
// }, 500);
// return;
// }
// task(results[1].value);
// })
// }, 0);
}, },
toggleSetting(val, type) { toggleSetting(val, type) {
let f = this.getDevice(); let f = this.getDevice();
if (!f) { // if (!f) {
this.showBleUnConnect(); // this.showBleUnConnect();
return; // return;
} // }
let sta_type = "sta_" + type; let sta_type = "sta_" + type;
let newVal = null; let newVal = null;
if (val == this.formData[sta_type]) { if (val == this.formData[sta_type]) {
@ -1419,13 +1294,17 @@
let json = {}; let json = {};
json['ins_' + type] = newVal json['ins_' + type] = newVal
json = JSON.stringify(json); json = JSON.stringify(json);
if (ble) { if (ble && f) {
ble.sendString(f.deviceId, json).then(res => { ble.sendString(f.deviceId, json).then(res => {
console.log("send success") console.log("send success")
this.formData[sta_type] = newVal; this.formData[sta_type] = newVal;
}).catch(ex => { }).catch(ex => {
this.mqSend(json); this.mqSend(json);
}); });
} else {
this.mqSend(json).then(res => {
this.formData[sta_type] = newVal;
});
} }
} }
@ -1437,12 +1316,12 @@
CloseWarn() { CloseWarn() {
let f = this.getDevice(); let f = this.getDevice();
// #ifdef APP // // #ifdef APP
if (!f) { // if (!f) {
this.showBleUnConnect(); // this.showBleUnConnect();
return; // return;
} // }
// #endif // // #endif
// #ifdef WEB // #ifdef WEB
f = { f = {
@ -1454,8 +1333,8 @@
let json = { let json = {
ins_ShakeBit: 0 ins_ShakeBit: 0
}; };
json = JSON.stringify(json);
if (ble) { if (ble && f) {
ble.sendString(f.deviceId, json).then(res => { ble.sendString(f.deviceId, json).then(res => {
this.formData.sta_ShakeBit = 0; this.formData.sta_ShakeBit = 0;
this.formData.sta_InfraRed = 0; this.formData.sta_InfraRed = 0;
@ -1464,49 +1343,52 @@
this.formData.sta_ShakeBit = 0; this.formData.sta_ShakeBit = 0;
this.formData.sta_InfraRed = 0; this.formData.sta_InfraRed = 0;
}); });
} else {
this.mqSend(json);
this.formData.sta_ShakeBit = 0;
this.formData.sta_InfraRed = 0;
} }
} }
MsgError('确定解除报警?', '', these, bleSend); MsgError('确定解除报警?', '', these, bleSend);
}, },
sosSetting(val) { sosSetting(val) {
let f = this.getDevice(); console.log("old=", this.formData.sta_SOSGrade);
let f = these.getDevice();
if (!f) {
this.showBleUnConnect();
return;
}
let newVal = null; let newVal = null;
if (val == this.formData.sta_SOSGrade) { if (val == these.formData.sta_SOSGrade) {
newVal = 0; newVal = 0;
} else { } else {
newVal = val; newVal = val;
} }
console.log("old1=", this.formData.sta_SOSGrade);
let msg = ""; let msg = "";
if (newVal == 0 && this.formData.sta_SOSGrade == 1) { if (newVal == 0 && these.formData.sta_SOSGrade == 1) {
msg = "确定解除声光报警?"; msg = "确定解除声光报警?";
} else if (newVal == 1) { } else if (newVal == 1) {
msg = "确定开启声光报警?"; msg = "确定开启声光报警?";
} }
let bleSend = () => { let bleSend = () => {
console.log("old2=", this.formData.sta_SOSGrade);
let json = { let json = {
ins_SOSGrade: newVal ins_SOSGrade: newVal
}; };
json = JSON.stringify(json); console.log("json="+JSON.stringify(json));
if (ble) { these.formData.sta_SOSGrade = newVal;
ble.sendString(f.deviceId, json).then(res => {
this.formData.sta_SOSGrade = newVal; console.log("new=", this.formData.sta_SOSGrade);
}).catch(ex => { these.setBleFormData();
this.mqSend(json); console.log("these.formData.sta_SOSGrade=" + these.formData.sta_SOSGrade);
this.formData.sta_SOSGrade = newVal;
if (ble && f) {
ble.sendString(f.deviceId, json).catch(ex => {
these.mqSend(json);
}); });
} else {
these.mqSend(json);
} }
} };
if (msg) { if (msg) {
MsgError(msg, '', these, () => { MsgError(msg, '', these, () => {
@ -1515,7 +1397,25 @@
} else { } else {
bleSend(); bleSend();
} }
},
getDetail() {
var that = this;
usrApi.getDetail(this.device.id).then(res => {
console.log("获取人员信息=", res);
if (res && res.code == 200) {
res = res.data;
let personnelInfo = res.personnelInfo;
if (personnelInfo) {
that.formData.company = personnelInfo.unitName;
that.formData.usrname = personnelInfo.name;
that.formData.job = personnelInfo.position;
that.formData.usrid = personnelInfo.code
return;
}
}
});
}, },
getDevice: function() { getDevice: function() {
let f = ble.data.LinkedList.find((v) => { let f = ble.data.LinkedList.find((v) => {
@ -1556,22 +1456,178 @@
}, },
mqSend(json) { sendMsg() {
if (mq) { debugger;
mq.publish("B/" + this.device.deviceImei, json).then(res => { if (!this.permissions.includes('4') && this.Status.apiType !== 'listA') {
let keys = Object.keys(JSON.parse(json)); MsgError('无操作权限', '确定', these);
for (let i = 0; i < keys.length; i++) {
let key = keys[i]; return;
let state = key.replace('ins_', 'sta_'); }
this.formData[state] = json[key];
}
}).catch(ex => { this.formData.sendMsg.padStart(16, ' ');
this.formData.textLines = [this.formData.sendMsg.slice(0, 8), this.formData.sendMsg.slice(8, 16)];
showLoading(this, {
text: "发送中"
});
//握手
let holdHand = (hexs, time) => {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve(true)
}, time);
});
}
//画图
let drawText = () => {
return new Promise((resolve, reject) => {
this.$refs.textToHex.drawAndGetPixels().then(allPixels => {
if (!allPixels) {
reject("文本初始化失败");
return;
}
console.log("画图成功");
resolve(allPixels);
}).catch(compEx => {
reject(compEx);
});
}); });
}
//发送3个分包的数据
let task = (allPixels) => {
try {
let combinedData = [];
for (let i = 0; i < 2; i++) {
let linePixels = (allPixels[i] || []).flat(Infinity).map(item =>
item.replace('0x', '')
);
for (var j = linePixels.length; j < 256; j++) {
linePixels.push("00");
}
combinedData.push(['0' + (i + 1), '01'].concat(linePixels.slice(0, 128)));
combinedData.push(['0' + (i + 1), '02'].concat(linePixels.slice(128, 256)));
}
let curr = 1;
let len = combinedData.length;
console.log("包数量", len)
//分包发送
let sendPacket = () => {
if (combinedData.length === curr - 1) {
Common.saveDeviceLog({
deviceId: this.device.id,
name: '发送紧急通知',
sendMsg: this.formData.sendMsg.trim()
}).catch(ex => {
});
holdHand('transmit complete', 200).then(res => {
MsgSuccess("消息发送成功", "确定", these);
});
hideLoading(these);
return;
}
let array = combinedData[curr - 1];
let json = {
ins_msg: array.join("")
}
this.mqSend(json).then(
res => {
curr++;
console.log("发送成功", curr);
setTimeout(sendPacket, 500);
}).catch(err => {
if (err.code == '10007') {
setTimeout(sendPacket, 500);
} else {
console.log("err:", err);
MsgError('发送失败' + (err.msg || err.code), '确定', these);
}
});
}
setTimeout(sendPacket, 0);
// 5. 发送成功处理
} catch (ex) {
uni.showModal({
title: '提示',
content: '发送失败' + (ex.msg || ex.code)
})
}
} }
setTimeout(() => {
Promise.allSettled([holdHand('word transmit start', 2200), drawText()]).then(
results => {
console.log("PromiseAll=", results);
if (results[0].status == 'rejected') {
setTimeout(() => {
hideLoading(these)
}, 500);
return;
}
if (results[1].status == 'rejected') {
console.log("任务1失败了", results[1].reason);
return;
}
console.log("开始发送数据包");
task(results[1].value);
})
}, 0);
},
mqSend(json) {
return new Promise((resolve, reject) => {
if (mq) {
mq.publish("B/" + this.device.deviceImei, typeof(json)=='string'?json:JSON.stringify(json)).then(res => {
json=typeof(json)=='string'?JSON.parse(json):json
let keys = Object.keys(json);
for (let i = 0; i < keys.length; i++) {
let key = keys[i];
let state = key.replace('ins_', 'sta_');
this.formData[state] = json[key];
}
resolve(res);
}).catch(ex => {
reject(ex);
});
} else {
reject("mq未初始化");
}
});
}, },
showBleUnConnect() { showBleUnConnect() {
MsgError("蓝牙未连接过该设备,请使用蓝牙重新添加该设备", '去连接', this, () => { MsgError("蓝牙未连接过该设备,请使用蓝牙重新添加该设备", '去连接', this, () => {
@ -1628,6 +1684,7 @@
this.receivData(data); this.receivData(data);
}, },
receivData(data) { //处理蓝牙/MQ的数据 receivData(data) { //处理蓝牙/MQ的数据
console.log("data=", data);
let keys = Object.keys(data); let keys = Object.keys(data);
keys.forEach(key => { keys.forEach(key => {
this.formData[key] = data[key]; this.formData[key] = data[key];
@ -1978,8 +2035,8 @@
} }
.mode .leftImg .img { .mode .leftImg .img {
width: 70rpx; width: 55rpx;
height: 70rpx; height: 55rpx;
} }
.mode .rightTxt { .mode .rightTxt {

View File

@ -20,7 +20,7 @@
</view> </view>
</uni-nav-bar> </uni-nav-bar>
<view class="eq"> <view class="eq" :style="{marginTop:Status.navbar.height+'px'}">
<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>
@ -323,7 +323,8 @@
callback: this.gotoShare, callback: this.gotoShare,
apiType: 'listA' apiType: 'listA'
}], }],
title: 'BJQ4877' title: 'BJQ4877',
height:90
}, },
ShowEditChannel: false, ShowEditChannel: false,
@ -447,7 +448,9 @@
}, },
} }
}, },
created() {
this.Status.navbar.height = uni.getSystemInfoSync().statusBarHeight + 44;
},
onUnload() { onUnload() {
console.log("页面卸载,释放资源"); console.log("页面卸载,释放资源");
ble.removeAllCallback(pagePath); ble.removeAllCallback(pagePath);

View File

@ -39,7 +39,7 @@
</view> </view>
</view> </view>
@ -112,7 +112,7 @@
</view> </view>
</view> </view>
</view> </view>
<view class="warnnig" :class="formData.sta_ShakeBit!=0 ?'':'displayNone'"> <view class="warnnig" :class="formData.sta_ShakeBit!=0 ?'':'displayNone'">
<view>{{formData.sta_ShakeBit==3?'设备疑似受到外力碰撞':'设备声光报警中'}}</view> <view>{{formData.sta_ShakeBit==3?'设备疑似受到外力碰撞':'设备声光报警中'}}</view>
<view @click.stop="SOSToggle()"> <view @click.stop="SOSToggle()">
<uni-icons type="closeempty" color="#FFFFFFde" size="16"></uni-icons> <uni-icons type="closeempty" color="#FFFFFFde" size="16"></uni-icons>
@ -223,7 +223,7 @@
<text class="lbl">职位</text> <text class="lbl">职位</text>
<input class="value" v-model="formData.job" placeholder="请输入职位" placeholder-class="usrplace" /> <input class="value" v-model="formData.job" placeholder="请输入职位" placeholder-class="usrplace" />
</view> </view>
</view> </view>
</view> </view>
@ -243,7 +243,7 @@
</view> </view>
</view> </view>
<ProParams :id="device.id"></ProParams> <ProParams :id="device.id"></ProParams>
<MsgBox ref="msgPop" /> <MsgBox ref="msgPop" />
<global-loading ref="loading" /> <global-loading ref="loading" />
@ -278,17 +278,17 @@
import MqttClient from '@/utils/mqtt.js'; import MqttClient from '@/utils/mqtt.js';
import lnglatConvert from '@/utils/wgs84_to_gcj02.js'; import lnglatConvert from '@/utils/wgs84_to_gcj02.js';
import SendBatchData from '@/utils/SendBatchData.js'; import SendBatchData from '@/utils/SendBatchData.js';
var batchTool=null; var batchTool = null;
var eventChannel = null; var eventChannel = null;
var these = null; var these = null;
var ble = null; var ble = null;
var recei = null; var recei = null;
var mq = null; var mq = null;
var pagePath = "pages/6075J/BJQ6075J"; var pagePath = "pages/6075J/BJQ6075J";
var brightnessTimer = null; var brightnessTimer = null;
var reGeoTime=null; var reGeoTime = null;
export default { export default {
components: { components: {
TextToHexV1 TextToHexV1
@ -460,7 +460,7 @@
} }
}, },
created() { created() {
this.Status.navbar.height = uni.getSystemInfoSync().statusBarHeight + 20; this.Status.navbar.height = uni.getSystemInfoSync().statusBarHeight + 44;
}, },
onUnload() { onUnload() {
console.log("页面卸载,释放资源"); console.log("页面卸载,释放资源");
@ -487,10 +487,10 @@
ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId).then(res => { ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId).then(res => {
console.log("连接成功") console.log("连接成功")
these.formData.bleStatu = true; these.formData.bleStatu = true;
}).catch(ex => { }).catch(ex => {
these.formData.bleStatu = 'err'; these.formData.bleStatu = 'err';
MsgError("连接错误:" + ex.msg, "确定", these); MsgError("连接错误:" + ex.msg, "确定", these);
});; });;
} }
}, },
onHide: function() { onHide: function() {
@ -558,10 +558,12 @@
these.formData.bleStatu = 'connecting'; these.formData.bleStatu = 'connecting';
ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId).then(res => { ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId).then(res => {
these.formData.bleStatu = true; these.formData.bleStatu = true;
}).catch(ex => { }).catch(ex => {
these.formData.bleStatu = 'err'; these.formData.bleStatu = 'err';
MsgError("连接错误:" + ex.msg, "确定", these); MsgError("连接错误:" + ex.msg, "确定", these);
});; });
these.getDetail();
}); });
@ -648,14 +650,14 @@
let f = this.getDevice(); let f = this.getDevice();
if(!f){ if (!f) {
this.showBleUnConnect(); this.showBleUnConnect();
return; return;
} }
if(!batchTool){ if (!batchTool) {
batchTool=new SendBatchData(these,f,ble); batchTool = new SendBatchData(these, f, ble);
} }
batchTool.SendVideo(504); batchTool.SendVideo(504);
}, },
sendImg() { sendImg() {
@ -666,20 +668,20 @@
} }
let f = this.getDevice(); let f = this.getDevice();
if(!f){ if (!f) {
this.showBleUnConnect(); this.showBleUnConnect();
return; return;
} }
if(!batchTool){ if (!batchTool) {
batchTool=new SendBatchData(these,f,ble); batchTool = new SendBatchData(these, f, ble);
} }
batchTool.SendImg(); batchTool.SendImg();
return ; return;
}, },
sliderChanging(e) { sliderChanging(e) {
this.formData.sta_brightness = e.detail.value; this.formData.sta_brightness = e.detail.value;
@ -853,11 +855,11 @@
]; ];
let item3 = Object.assign({}, json); let item3 = Object.assign({}, json);
item3.textAlign='center'; item3.textAlign = 'center';
item3.name = 'media'; item3.name = 'media';
item3.title = '选择媒体'; item3.title = '选择媒体';
item3.menuItems = [{ item3.menuItems = [{
text: '照片', text: '照片',
value: 'img', value: 'img',
key: 'media' key: 'media'
}, },
@ -967,7 +969,7 @@
let sendLaser = () => { let sendLaser = () => {
this.sendData(json, null, 'string').then(res => { this.sendData(json, null, 'string').then(res => {
this.formData.sta_laser = val; this.formData.sta_laser = val;
this.formData.sta_LightGrade=6; this.formData.sta_LightGrade = 6;
this.setBleFormData(); this.setBleFormData();
}).catch(ex => { }).catch(ex => {
console.error("出现错误", ex) console.error("出现错误", ex)
@ -1004,8 +1006,8 @@
this.sendData(json, null, 'string').then((res) => { this.sendData(json, null, 'string').then((res) => {
let key = li.key.replace(/ins_/g, 'sta_'); let key = li.key.replace(/ins_/g, 'sta_');
this.formData[key] = li.value; this.formData[key] = li.value;
if(li.value!=6){ if (li.value != 6) {
this.formData.sta_laser=0; this.formData.sta_laser = 0;
} }
this.setBleFormData(); this.setBleFormData();
this.formData.sta_brightness = 100; this.formData.sta_brightness = 100;
@ -1028,9 +1030,9 @@
} }
if(!batchTool){ if (!batchTool) {
batchTool=new SendBatchData(these,f,ble); batchTool = new SendBatchData(these, f, ble);
} }
batchTool.SendUsr(3); batchTool.SendUsr(3);
}, },
sendMsg() { sendMsg() {
@ -1106,7 +1108,13 @@
if (combinedData.length === curr - 1) { if (combinedData.length === curr - 1) {
Common.saveDeviceLog({
deviceId: this.device.id,
name: '发送紧急通知',
sendMsg: this.formData.sendMsg.trim()
}).catch(ex => {
});
holdHand('transmit complete', 200).then(res => { holdHand('transmit complete', 200).then(res => {
MsgSuccess("消息发送成功", "确定", these); MsgSuccess("消息发送成功", "确定", these);
@ -1124,12 +1132,14 @@
this.sendData(json, '4g', 'string').then( this.sendData(json, '4g', 'string').then(
res => { res => {
curr++; curr++;
console.log("发送成功", curr) console.log("发送成功", curr);
setTimeout(sendPacket, 500); setTimeout(sendPacket, 1000);
}).catch(err => { }).catch(err => {
if (err.code == '10007') { if (err.code == '10007') {
setTimeout(sendPacket, 500); setTimeout(sendPacket, 1000);
} else { } else {
console.log("err:", err); console.log("err:", err);
MsgError('发送失败' + (err.msg || err.code), '确定', these); MsgError('发送失败' + (err.msg || err.code), '确定', these);
@ -1291,7 +1301,7 @@
borderColor: "#e034344d", borderColor: "#e034344d",
buttonBgColor: "#E03434", buttonBgColor: "#E03434",
buttonText: '去连接', buttonText: '去连接',
buttonTextColor: '#FFFFFFde', buttonTextColor: '#FFFFFFde',
showCancel: true, showCancel: true,
okCallback: function() { okCallback: function() {
console.log("1111"); console.log("1111");
@ -1361,37 +1371,37 @@
} }
this.setBleFormData(); this.setBleFormData();
}, },
reGeo() { reGeo() {
console.log("经纬度发生变化,执行逆地理") console.log("经纬度发生变化,执行逆地理")
let task = () => { let task = () => {
if (this.formData.sta_longitude && this.formData.sta_latitude) { if (this.formData.sta_longitude && this.formData.sta_latitude) {
let promise = lnglatConvert.wgs84_to_gcj02(this.formData.sta_longitude, this.formData let promise = lnglatConvert.wgs84_to_gcj02(this.formData.sta_longitude, this.formData
.sta_latitude); .sta_latitude);
promise.then(lnglat => { promise.then(lnglat => {
this.device.longitude = lnglat[0]; this.device.longitude = lnglat[0];
this.device.latitude = lnglat[1]; this.device.latitude = lnglat[1];
this.formData.sta_longitude=lnglat[0]; this.formData.sta_longitude = lnglat[0];
this.formData.sta_latitude=lnglat[1]; this.formData.sta_latitude = lnglat[1];
Common.regeo(lnglat[0], lnglat[1]).then(res => { Common.regeo(lnglat[0], lnglat[1]).then(res => {
this.formData.address = res.regeocode.formatted_address this.formData.address = res.regeocode.formatted_address
this.setBleFormData(); this.setBleFormData();
}).catch(ex => { }).catch(ex => {
console.error("逆地理失败了") console.error("逆地理失败了")
}); });
}).catch(err => { }).catch(err => {
console.error("坐标转换失败了"); console.error("坐标转换失败了");
}); });
} else { } else {
console.error("经纬度缺失"); console.error("经纬度缺失");
} }
} }
clearTimeout(reGeoTime); clearTimeout(reGeoTime);
reGeoTime = setTimeout(task, 500); reGeoTime = setTimeout(task, 500);
}, },
setBleFormData() { setBleFormData() {
if (!ble) { if (!ble) {
@ -1416,8 +1426,8 @@
} }
if (res.deviceId == these.formData.deviceId) { if (res.deviceId == these.formData.deviceId) {
this.formData.bleStatu = true; this.formData.bleStatu = true;
batchTool=new SendBatchData(this,res,ble); batchTool = new SendBatchData(this, res, ble);
setTimeout(() => { setTimeout(() => {
hideLoading(these, 1000); hideLoading(these, 1000);
}); });
@ -1433,7 +1443,7 @@
// return; // return;
// } // }
if (res.deviceId == these.formData.deviceId) { if (res.deviceId == these.formData.deviceId) {
batchTool=null; batchTool = null;
if (res.device) { if (res.device) {
these.formData.bleStatu = 'connecting'; these.formData.bleStatu = 'connecting';
} else { } else {
@ -1481,7 +1491,7 @@
updateLoading(these, { updateLoading(these, {
text: ex.msg text: ex.msg
}); });
these.formData.bleStatu = 'err'; these.formData.bleStatu = 'err';
}).finally(() => { }).finally(() => {
setTimeout(() => { setTimeout(() => {
hideLoading(these); hideLoading(these);
@ -1509,7 +1519,7 @@
these.formData.bleStatu = true; these.formData.bleStatu = true;
}).catch(ex => { }).catch(ex => {
these.formData.bleStatu = 'err'; these.formData.bleStatu = 'err';
MsgError("连接错误:" + ex.msg, "确定", these); MsgError("连接错误:" + ex.msg, "确定", these);
}); });
return; return;
} }
@ -1517,7 +1527,8 @@
}, },
gotoMap() { gotoMap() {
let promise =Promise.resolve([this.formData.sta_longitude, this.formData.sta_latitude]); //lnglatConvert.wgs84_to_gcj02(this.formData.sta_longitude, this.formData.sta_latitude); let promise = Promise.resolve([this.formData.sta_longitude, this.formData
.sta_latitude]); //lnglatConvert.wgs84_to_gcj02(this.formData.sta_longitude, this.formData.sta_latitude);
promise.then(lnglat => { promise.then(lnglat => {
this.detailData.longitude = lnglat[0]; this.detailData.longitude = lnglat[0];
@ -1536,7 +1547,7 @@
}); });
}, },
prevPage() { prevPage() {
uni.navigateBack({ uni.navigateBack({
@ -1941,7 +1952,7 @@
text-align: left; text-align: left;
} }
.slider-container { .slider-container {
padding: 0px; padding: 0px;

View File

@ -21,7 +21,7 @@
</uni-nav-bar> </uni-nav-bar>
<view class="eq"> <view class="eq" :style="{marginTop:Status.navbar.height+'px'}">
<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>
@ -208,7 +208,8 @@
callback: this.gotoShare, callback: this.gotoShare,
apiType: 'listA' apiType: 'listA'
}], }],
title: 'BJQ6155' title: 'BJQ6155',
height:90
}, },
lightMode: { lightMode: {
@ -338,6 +339,9 @@
} }
} }
}, },
created() {
this.Status.navbar.height = uni.getSystemInfoSync().statusBarHeight + 44;
},
onUnload() { onUnload() {
ble.removeAllCallback(pagePath); ble.removeAllCallback(pagePath);
}, },
@ -1660,7 +1664,9 @@
unitName: these.formData.textLines[2], unitName: these.formData.textLines[2],
code: "" code: ""
}; };
usrApi.sendUsr(json); usrApi.sendUsr(json).catch(ex=>{
console.error("ex=",ex);
});
hideLoading(these); hideLoading(these);
return; return;
@ -1743,15 +1749,12 @@
getDetail() { getDetail() {
var these = this; var these = 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) {
these.formData.textLines[2] = personnelInfo.unitName; these.formData.textLines=[personnelInfo.position, personnelInfo.name,personnelInfo.unitName];
these.formData.textLines[1] = personnelInfo.name;
these.formData.textLines[0] = personnelInfo.position;
} }
} }
}); });

View File

@ -22,7 +22,7 @@
</uni-nav-bar> </uni-nav-bar>
<view class="eq"> <view class="eq" :style="{marginTop:Status.navbar.height+'px'}">
<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>
@ -211,7 +211,8 @@
callback: this.gotoShare, callback: this.gotoShare,
apiType: 'listA' apiType: 'listA'
}], }],
title: 'BJQ6155' title: 'BJQ6155',
height:90
}, },
Pop: { Pop: {
@ -308,6 +309,9 @@
} }
}, },
created() {
this.Status.navbar.height = uni.getSystemInfoSync().statusBarHeight + 44;
},
onUnload() { onUnload() {
ble.removeAllCallback(pagePath); ble.removeAllCallback(pagePath);
}, },

View File

@ -56,19 +56,19 @@
{{ deviceInfo.onlineStatus === 0 ? '离线' : deviceInfo.onlineStatus === 2 ? '故障' : '在线' }} {{ deviceInfo.onlineStatus === 0 ? '离线' : deviceInfo.onlineStatus === 2 ? '故障' : '在线' }}
</text> </text>
</view> </view>
<view class="info-row" > <view class="info-row">
<text class="info-label">蓝牙名称</text> <text class="info-label">蓝牙名称</text>
<text class="info-value status-running" > <text class="info-value status-running">
{{deviceInfo.bluetoothName}} {{deviceInfo.bluetoothName}}
</text> </text>
</view> </view>
<view class="info-row" @click="bleStatuToggle"> <view class="info-row" @click="bleStatuToggle">
<text class="info-label">蓝牙状态</text> <text class="info-label">蓝牙状态</text>
<text class="info-value status-running" :class="getbleStatu.cls"> <text class="info-value status-running" :class="getbleStatu.cls">
{{getbleStatu.txt}} {{getbleStatu.txt}}
</text> </text>
</view> </view>
<view class="info-row" @click="bleStatuToggle"> <view class="info-row" @click="bleStatuToggle">
<text class="info-label">充电状态</text> <text class="info-label">充电状态</text>
<text class="info-value status-running"> <text class="info-value status-running">
{{deviceInfo.chargeState != 0?'充电中':'未充电'}} {{deviceInfo.chargeState != 0?'充电中':'未充电'}}
@ -356,6 +356,7 @@
var rec = null; var rec = null;
var pagePath = "/pages/6170/deviceControl/index"; var pagePath = "/pages/6170/deviceControl/index";
import api from '@/api/670/HBY670.js';
export default { export default {
components: { components: {
@ -443,28 +444,31 @@
return this.modeType === 'main' ? '灯光模式' : '激光模式'; return this.modeType === 'main' ? '灯光模式' : '激光模式';
}, },
getbleStatu() { getbleStatu() {
let txt="未连接" let txt = "未连接"
let cls=""; let cls = "";
if (this.formData.bleStatu === true) { if (this.formData.bleStatu === true) {
txt= '已连接'; txt = '已连接';
cls="green"; cls = "green";
} }
if (this.formData.bleStatu === 'connecting') { if (this.formData.bleStatu === 'connecting') {
txt= '连接中'; txt = '连接中';
} }
if (this.formData.bleStatu === 'dicconnect') { if (this.formData.bleStatu === 'dicconnect') {
txt= '正在断开'; txt = '正在断开';
} }
if (this.formData.bleStatu === 'err') { if (this.formData.bleStatu === 'err') {
txt= '连接异常'; txt = '连接异常';
cls="red" cls = "red"
}
return {
txt: txt,
cls: cls
} }
return {txt:txt,cls:cls}
} }
}, },
methods: { methods: {
initWatch(){ initWatch() {
this.$watch("deviceInfo.batteryPercentage",(newVal,oldVal)=>{ this.$watch("deviceInfo.batteryPercentage", (newVal, oldVal) => {
if (this.deviceInfo.batteryPercentage < 20 && if (this.deviceInfo.batteryPercentage < 20 &&
this.deviceInfo.chargeState == 0) { this.deviceInfo.chargeState == 0) {
this.popupType = 'bettery'; this.popupType = 'bettery';
@ -483,8 +487,8 @@
this.sliderValue = deviceState[2]; this.sliderValue = deviceState[2];
this.deviceInfo.batteryRemainingTime = deviceState[3]; this.deviceInfo.batteryRemainingTime = deviceState[3];
break; break;
case 6: case 6:
if(deviceState[1]==50){ if (deviceState[1] == 50) {
this.popupType = 'person'; this.popupType = 'person';
this.showPopupFlag = true; this.showPopupFlag = true;
this.popupMessage = '信息发送成功'; this.popupMessage = '信息发送成功';
@ -496,15 +500,15 @@
this.currentMainMode = this.getMainLightModeLabel(deviceState[1]); this.currentMainMode = this.getMainLightModeLabel(deviceState[1]);
this.isLaserOn = deviceState[2] === 1; //第3位表示当时激光灯档位 this.isLaserOn = deviceState[2] === 1; //第3位表示当时激光灯档位
this.currentlaserMode = this.isLaserOn ? "开启" : "关闭"; this.currentlaserMode = this.isLaserOn ? "开启" : "关闭";
this.deviceInfo.alarmStatus= deviceState[6];//报警状态 this.deviceInfo.alarmStatus = deviceState[6]; //报警状态
this.itemInfo.alarmStatus= deviceState[6]; this.itemInfo.alarmStatus = deviceState[6];
if (this.deviceInfo) { if (this.deviceInfo) {
this.deviceInfo.batteryPercentage = deviceState[3]; //第4位电量百分比 this.deviceInfo.batteryPercentage = deviceState[3]; //第4位电量百分比
this.deviceInfo.chargeState = deviceState[4]; //第5位为充电状态0没有充电1正在充电2为已充满 this.deviceInfo.chargeState = deviceState[4]; //第5位为充电状态0没有充电1正在充电2为已充满
this.deviceInfo.batteryRemainingTime = deviceState[5]; //第6位200代表电池剩余续航时间200分钟 this.deviceInfo.batteryRemainingTime = deviceState[5]; //第6位200代表电池剩余续航时间200分钟
} }
setTimeout(() => { setTimeout(() => {
if (this.apiType === 'listA') { if (this.apiType === 'listA') {
this.fetchDeviceDetail(data.data.id) this.fetchDeviceDetail(data.data.id)
} else { } else {
@ -539,7 +543,7 @@
if (this.formData.bleStatu === false || this.formData.bleStatu === 'err') { if (this.formData.bleStatu === false || this.formData.bleStatu === 'err') {
these.formData.bleStatu = 'connecting'; these.formData.bleStatu = 'connecting';
ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId).then(res => { ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId).then(res => {
these.formData.bleStatu = true; // these.formData.bleStatu = true;
}).catch(ex => { }).catch(ex => {
these.formData.bleStatu = 'err'; these.formData.bleStatu = 'err';
MsgError("连接错误:" + ex.msg, "确定", these); MsgError("连接错误:" + ex.msg, "确定", these);
@ -597,9 +601,11 @@
uni.navigateTo({ uni.navigateTo({
url: "/pages/common/addBLE/addEquip", url: "/pages/common/addBLE/addEquip",
events: { events: {
BindOver: function(data) { BindOver(data) {
console.log(data) console.log("蓝牙配对成功:", data);
these.formData.deviceId = data.bleId;
these.formData.bleStatu = true; these.formData.bleStatu = true;
console.log("蓝牙配对成功:", these.formData);
} }
}, },
success: function(res) { success: function(res) {
@ -627,9 +633,7 @@
}, },
bleStateBreak() { bleStateBreak() {
if (this.Status.pageHide) {
return;
}
//蓝牙适配器不可用 //蓝牙适配器不可用
this.formData.bleStatu = false; this.formData.bleStatu = false;
uni.showToast({ uni.showToast({
@ -640,9 +644,7 @@
}, },
bleStateRecovry() { bleStateRecovry() {
console.log("蓝牙可用"); console.log("蓝牙可用");
if (this.Status.pageHide) {
return;
}
console.log("蓝牙可用"); console.log("蓝牙可用");
//蓝牙适配器再次可用,尝试恢复连接 //蓝牙适配器再次可用,尝试恢复连接
showLoading(this, { showLoading(this, {
@ -650,7 +652,7 @@
}); });
this.formData.bleStatu = 'connecting'; this.formData.bleStatu = 'connecting';
ble.LinkBlue(these.formData.deviceId).then(() => { ble.LinkBlue(these.formData.deviceId).then(() => {
these.formData.bleStatu = true; // these.formData.bleStatu = true;
updateLoading(these, { updateLoading(these, {
text: '连接成功' text: '连接成功'
}); });
@ -688,18 +690,9 @@
}, },
deviceRecovry(res) { deviceRecovry(res) {
if (this.Status.pageHide) { console.log('蓝牙连接成功');
return; if (res.deviceId == this.formData.deviceId) {
} this.formData.bleStatu = true;
if (res.deviceId == these.formData.deviceId) {
this.formData.bleStatu = true;
setTimeout(() => {
hideLoading(these, 1000);
});
uni.showToast({
icon: 'success',
title: '蓝牙连接成功'
});
} }
}, },
@ -1127,7 +1120,7 @@
return; return;
} }
this.lightModeB = true; this.lightModeB = true;
this.selectedImage=null; this.selectedImage = null;
}, },
// 上传开机画面 // 上传开机画面
checkImgUpload() { checkImgUpload() {
@ -1609,6 +1602,18 @@
if (combinedData.length === curr - 1) { if (combinedData.length === curr - 1) {
holdHand('transmit complete', 200).then(res => { holdHand('transmit complete', 200).then(res => {
let json = {
deviceId: this.itemInfo.id,
name: these.personnelInfo.name,
position: these.personnelInfo.position,
unitName: these.personnelInfo.unitName,
code: these.personnelInfo.code
};
api.sendUsr(json);
MsgSuccess("人员信息发送成功", "确定", these); MsgSuccess("人员信息发送成功", "确定", these);
hideLoading(these); hideLoading(these);
this.setBleFormData(); this.setBleFormData();
@ -1791,7 +1796,7 @@
// title: registerRes.msg, // title: registerRes.msg,
// icon: 'none' // icon: 'none'
// }) // })
return return
} }
@ -1891,6 +1896,14 @@
}) })
return return
} }
Common.saveDeviceLog({
deviceId: this.itemInfo.id,
name: '发送紧急通知',
sendMsg: this.messageToSend
}).catch(ex => {
});
// 4. 获取设备状态 // 4. 获取设备状态
let deviceImei = this.itemInfo.deviceImei let deviceImei = this.itemInfo.deviceImei
//let typeName = this.itemInfo.typeName //let typeName = this.itemInfo.typeName
@ -2064,15 +2077,14 @@
payload) : payload; payload) : payload;
let keys = Object.keys(parsedMessage); let keys = Object.keys(parsedMessage);
if("sta_BreakNews" in parsedMessage){ if ("sta_BreakNews" in parsedMessage) {
console.error("收到确认消息") console.error("收到确认消息")
if(parsedMessage.sta_BreakNews=='I get it'){ if (parsedMessage.sta_BreakNews == 'I get it') {
MsgSuccess("用户已确认收到紧急通知","",this); MsgSuccess("用户已确认收到紧急通知", "", this);
} }
} } else if (keys.length && "state" in parsedMessage) {
else if (keys.length && "state" in parsedMessage) {
const deviceState = parsedMessage.state; // 直接取 state 数组 const deviceState = parsedMessage.state; // 直接取 state 数组
// 切换主灯光模式,亮度值设备同步 // 切换主灯光模式,亮度值设备同步
if (!deviceState || !deviceState instanceof Array) { if (!deviceState || !deviceState instanceof Array) {
@ -2080,8 +2092,8 @@
} }
this.onReceive(deviceState, parsedMessage); this.onReceive(deviceState, parsedMessage);
}else{ } else {
console.error("丢弃的消息",payload) console.error("丢弃的消息", payload)
} }
} catch (error) { } catch (error) {
console.log('解析MQTT消息失败:', error, '原始消息:', payload); console.log('解析MQTT消息失败:', error, '原始消息:', payload);
@ -2118,7 +2130,7 @@
these.formData.bleStatu = 'connecting'; these.formData.bleStatu = 'connecting';
ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId).then( ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId).then(
res => { res => {
these.formData.bleStatu = true; // these.formData.bleStatu = true;
}).catch(ex => { }).catch(ex => {
these.formData.bleStatu = 'err'; these.formData.bleStatu = 'err';
MsgError("连接错误:" + ex.msg, "确定", these); MsgError("连接错误:" + ex.msg, "确定", these);
@ -2140,8 +2152,8 @@
if (f) { if (f) {
this.formData.bleStatu = 'connecting'; this.formData.bleStatu = 'connecting';
ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId).then(res => { ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId).then(res => {
console.log("连接成功") console.log("连接成功", f)
this.formData.bleStatu = true; // these.formData.bleStatu = true;
}).catch(ex => { }).catch(ex => {
MsgError("连接错误:" + ex.msg, "确定", these); MsgError("连接错误:" + ex.msg, "确定", these);
}); });

View File

@ -21,7 +21,7 @@
</uni-nav-bar> </uni-nav-bar>
<view class="eq"> <view class="eq" :style="{marginTop:Status.navbar.height+'px'}">
<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>
@ -296,7 +296,9 @@ import request, { baseURL } from '@/utils/request.js';
}, },
} }
}, },
created() {
this.Status.navbar.height = uni.getSystemInfoSync().statusBarHeight + 44;
},
onUnload() { onUnload() {
console.log("页面卸载,释放资源"); console.log("页面卸载,释放资源");
ble.removeAllCallback(pagePath); ble.removeAllCallback(pagePath);
@ -667,20 +669,7 @@ import request, { baseURL } from '@/utils/request.js';
return; return;
} }
} }
let phone = uni.getStorageSync('phone');
if (phone === '17671332251') {
console.log("default=",that.device);
that.formData.company = '湖北消防总队';
that.formData.name = '胡红军';
that.formData.job = '中队长';
let arr=that.device.bluetoothName.split('-');
if(arr.length>1){
that.formData.id =arr[arr.length-1];
}else{
that.formData.id =that.device.bluetoothName;
}
}
}); });
}, },

View File

@ -18,7 +18,7 @@
<view class="eq"> <view class="eq":style="{marginTop:Status.navbar.height+'px'}">
<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>
@ -457,7 +457,7 @@
} }
}, },
created() { created() {
this.Status.navbar.height = uni.getSystemInfoSync().statusBarHeight + 20; this.Status.navbar.height = uni.getSystemInfoSync().statusBarHeight + 44;
}, },
onUnload() { onUnload() {
console.log("页面卸载,释放资源"); console.log("页面卸载,释放资源");

View File

@ -20,7 +20,7 @@
</view> </view>
</uni-nav-bar> </uni-nav-bar>
<view class="eq"> <view class="eq" :style="{marginTop:Status.navbar.height+'px'}">
<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>
@ -187,7 +187,8 @@
callback: this.gotoShare, callback: this.gotoShare,
apiType: 'listA' apiType: 'listA'
}], }],
title: 'BJQ6155' title: 'BJQ6155',
height:90
}, },
pageHide: false, pageHide: false,
@ -285,6 +286,9 @@
} }
}, },
created() {
this.Status.navbar.height = uni.getSystemInfoSync().statusBarHeight + 44;
},
onUnload() { onUnload() {
ble.removeAllCallback(pagePath); ble.removeAllCallback(pagePath);
}, },
@ -1346,10 +1350,7 @@ debugger;
res = res.data; res = res.data;
let personnelInfo = res.personnelInfo; let personnelInfo = res.personnelInfo;
if (personnelInfo) { if (personnelInfo) {
these.formData.inputLines[2] = personnelInfo.unitName; these.formData.inputLines=[personnelInfo.position,personnelInfo.name,personnelInfo.unitName];
these.formData.inputLines[1] = personnelInfo.name;
these.formData.inputLines[0] = personnelInfo.position;
} }
} }
}); });

View File

@ -35,7 +35,8 @@
</view> </view>
<view class="centertxt "> <view class="centertxt ">
<view class="name" v-text="item.name"></view> <view class="name" v-text="item.name"></view>
</view> </view>
<view class="rightIco center"> <view class="rightIco center">
<image src="/static/images/BLEAdd/linked.png" class="img" mode="aspectFit"> <image src="/static/images/BLEAdd/linked.png" class="img" mode="aspectFit">
@ -48,11 +49,12 @@
</view> </view>
<view class="lblTitle"> <view class="lblTitle">
<text>发现设备:{{deviceCnt}}</text> <text>发现设备:{{EquipMents.length}} 筛选设备:{{deviceCnt}}</text>
<view @click="refreshBleList()">刷新</view> <view @click="refreshBleList()">刷新</view>
</view> </view>
<view class=""> <view class="">
<input class="uni-input" v-model="search" placeholder="名称筛选" /> <input class="uni-input" v-model="search" placeholder="名称筛选" />
</view> </view>
<view class="list searchList"> <view class="list searchList">
<view class="item" v-on:click="Link(item,index)" v-for="item, index in EquipMents" <view class="item" v-on:click="Link(item,index)" v-for="item, index in EquipMents"
@ -66,11 +68,13 @@
<view class="name"> <view class="name">
<text>{{item.name?item.name:'Unnamed'}}</text> <text>{{item.name?item.name:'Unnamed'}}</text>
</view> </view>
<view class="id"> <view class="id">
<text>信号:{{item.RSSI}}dBm</text> <text>信号:{{item.RSSI}}dBm</text>
</view> </view>
<view class="id" v-if="item.advertisData">
<text>广播数据:{{item.advertisData}}</text>
</view>
</view> </view>
<view class="rightIco center"> <view class="rightIco center">
@ -272,7 +276,7 @@
} }
console.log("处理蓝牙不可用"); console.log("处理蓝牙不可用");
hideLoading(these); hideLoading(these);
these.PairEquip = []; these.PairEquip = [];
these.EquipMents = []; these.EquipMents = [];
uni.showToast({ uni.showToast({
@ -289,11 +293,11 @@
these.Status.BottomMenu.show = false; these.Status.BottomMenu.show = false;
these.PairEquip = []; these.PairEquip = [];
these.EquipMents = []; these.EquipMents = [];
if (these.Status.isPageHidden) { if (these.Status.isPageHidden) {
return; return;
} }
uni.showToast({ uni.showToast({
icon: 'fail', icon: 'fail',
title: '蓝牙恢复可用' title: '蓝牙恢复可用'
@ -321,7 +325,6 @@
//搜索到新设备的回调 (Always active) //搜索到新设备的回调 (Always active)
ble.addDeviceFound((arr) => { ble.addDeviceFound((arr) => {
// console.log("--- 收到原始扫描数据 ---", JSON.stringify(arr));
if (these.Status.isPageHidden) { if (these.Status.isPageHidden) {
return; return;
} }
@ -330,7 +333,6 @@
} }
arr = arr.devices; arr = arr.devices;
// console.log(`本次扫描批次发现 ${arr.length} 个设备`);
for (var i = 0; i < arr.length; i++) { for (var i = 0; i < arr.length; i++) {
let device = arr[i]; let device = arr[i];
@ -338,9 +340,7 @@
let f = these.EquipMents.find((v, index) => { let f = these.EquipMents.find((v, index) => {
if (v.deviceId == device.deviceId) { if (v.deviceId == device.deviceId) {
// console.log(
// `更新设备信号: ${device.name || device.deviceId}, RSSI: ${device.RSSI}`
// );
these.$set(these.EquipMents[index], 'RSSI', device.RSSI); these.$set(these.EquipMents[index], 'RSSI', device.RSSI);
return true; return true;
} }
@ -348,11 +348,10 @@
}); });
if (!f) { if (!f) {
// console.log("+++ 发现新设备,准备添加到列表:", JSON.stringify(device));
if (these.device && these.device.bluetoothName && device.name) { if (these.device && these.device.bluetoothName && device.name) {
const bn = these.device.bluetoothName; const bn = these.device.bluetoothName;
if (these.device.bluetoothName === device.name || if (bn === device.name ||
(device.name.indexOf(bn) > -1) || (device.name.indexOf(bn) > -1) ||
(bn.indexOf(device.name) > -1)) { (bn.indexOf(device.name) > -1)) {
device.isTarget = true; device.isTarget = true;
@ -364,8 +363,11 @@
these.EquipMents.push(device); these.EquipMents.push(device);
} }
these.EquipMents.sort((a, b) => b.RSSI - a.RSSI); //信号好的排前面,一般信号好的是目标设备
} }
these.EquipMents.sort((a, b) => b.RSSI - a.RSSI); //信号好的排前面,一般信号好的是目标设备
}, pagePath); }, pagePath);
//蓝牙连接已恢复的回调 //蓝牙连接已恢复的回调
@ -625,7 +627,7 @@
return; return;
} }
hideLoading(these); hideLoading(these);
these.device.bleId=deviceId;
eventChannel.emit('BindOver', these.device); eventChannel.emit('BindOver', these.device);
ble.updateCache(); ble.updateCache();

View File

@ -46,9 +46,14 @@
</view> </view>
<view class="tab"> <view class="tab">
<view class="center tabItem" @click="Status.tabIndex=0" :class="{'active':Status.tabIndex==0}">未入库(<text class="mathIcon">{{UnJoin.length}}</text>)</view> <view class="center tabItem" @click="Status.tabIndex=0" :class="{'active':Status.tabIndex==0}">未入库(<text
<view class="center tabItem" @click="Status.tabIndex=1" :class="{'active':Status.tabIndex==1}">已入库(<text class="mathIcon">{{joined.length}}</text>)</view> class="mathIcon">{{UnJoin.length}}</text>)</view>
<view class="center tabItem" @click="Status.tabIndex=2" :class="{'active':Status.tabIndex==2}">全部(<text class="mathIcon">{{SearchEquips.length}}</text>)</view> <view class="center tabItem" @click="Status.tabIndex=1" :class="{'active':Status.tabIndex==1}">已入库(<text
class="mathIcon">{{joined.length}}</text>)</view>
<view class="center tabItem" @click="Status.tabIndex=2" :class="{'active':Status.tabIndex==2}">已筛选(<text
class="mathIcon">{{SearchEquips.length}}</text>)</view>
<view class="center tabItem" @click="Status.tabIndex=3" :class="{'active':Status.tabIndex==3}">全部(<text
class="mathIcon">{{EquipMents.length}}</text>)</view>
</view> </view>
</view> </view>
<view class="mainContent"> <view class="mainContent">
@ -56,8 +61,7 @@
<view class="list searchList"> <view class="list searchList">
<view class="item" v-on:click="Link(item,index)" v-for="item, index in list" <view class="item" v-on:click="Link(item,index)" v-for="item, index in list"
v-show="!item['linkStatu']" v-show="!item['linkStatu']">
:class="{'displayNone':item.name.toLowerCase().indexOf(search.toLowerCase())===-1}">
<view class="leftImg "> <view class="leftImg ">
<image src="/static/images/common/bluetooth.png" class="titleIco" mode="heightFix"> <image src="/static/images/common/bluetooth.png" class="titleIco" mode="heightFix">
</image> </image>
@ -68,6 +72,7 @@
<text class="fright" :class="item.link?'green':'red'">{{item.link?'已连接':'未连接'}}</text> <text class="fright" :class="item.link?'green':'red'">{{item.link?'已连接':'未连接'}}</text>
<view class="clear"></view> <view class="clear"></view>
</view> </view>
<view class="name lbl" v-if="item.advertisData">广播数据:{{item.advertisData}}</view>
<view class="name lbl">Mac: <view class="name lbl">Mac:
<text class="green" v-if="item.macAddress">{{item.macAddress}}</text> <text class="green" v-if="item.macAddress">{{item.macAddress}}</text>
<view class="red" v-if="!item.macAddress && item.link"> <view class="red" v-if="!item.macAddress && item.link">
@ -141,6 +146,8 @@
var time = null; var time = null;
var time1 = null; var time1 = null;
var mq = null; var mq = null;
var isValidTime = null;
export default { export default {
data() { data() {
return { return {
@ -158,7 +165,7 @@
showBack: true, showBack: true,
height: 90 height: 90
}, },
tabIndex:0 tabIndex: 0
}, },
search: '', search: '',
groupid: '', groupid: '',
@ -169,20 +176,103 @@
devices: [], devices: [],
devicesCnt: 0, devicesCnt: 0,
privateNetUrl: '', privateNetUrl: '',
scanKey: '' scanKey: '',
typeKeys: [{
"type_name": "BJQ6170",
"ble": "BJQ6170"
},
{
"type_name": "HBY210",
"ble": "HBY210"
},
{
"type_name": "HBY670",
"ble": "HBY670"
},
{
"type_name": "BJQ6150",
"ble": "BJQ6150"
},
{
"type_name": "HBY650",
"ble": "HBY650"
},
{
"type_name": "BJQ7305",
"ble": "BJQ7305"
},
{
"type_name": "BJQ4877",
"ble": "BJQ4877"
},
{
"type_name": "HBY100",
"ble": "HBY100"
},
{
"type_name": "BJQ6070",
"ble": "BJQ6075"
},
{
"type_name": "HBY102",
"ble": "HBY102"
},
{
"type_name": "HBY018A",
"ble": "HBY018A"
},
{
"type_name": "BJQ6107",
"ble": "BJQ6107"
},
{
"type_name": "HBY100-J",
"ble": "HBY100J"
},
{
"type_name": "XH6155",
"ble": "BJQ6155"
},
{
"type_name": "BJQ6075J",
"ble": "BJQ6075"
},
{
"type_name": "HBY008A",
"ble": "HBY008A"
},
{
"type_name": "HBY100-Y",
"ble": "HBY100Y"
},
{
"type_name": "HBY102-J",
"ble": "HBY102J"
}
]
} }
}, },
computed: { computed: {
list(){ cType(){
if(this.Status.tabIndex==0){ let f=this.typeKeys.find(v=>{
return v.type_name==this.type.typeName;
});
return f;
},
list() {
if (this.Status.tabIndex == 0) {
return this.UnJoin; return this.UnJoin;
} }
if(this.Status.tabIndex==1){ if (this.Status.tabIndex == 1) {
return this.joined; return this.joined;
} }
if (this.Status.tabIndex == 2) {
return this.SearchEquips; return this.SearchEquips;
}
return this.EquipMents;
}, },
SearchEquips: function() { SearchEquips: function() {
let f = this.EquipMents.filter(v => { let f = this.EquipMents.filter(v => {
@ -190,19 +280,19 @@
}); });
return f; return f;
}, },
joined(){ joined() {
let f=this.EquipMents.filter(v => { let f = this.EquipMents.filter(v => {
return v.name.toLowerCase().indexOf(this.search.toLowerCase()) > -1 && v.isUpload; return v.name.toLowerCase().indexOf(this.search.toLowerCase()) > -1 && v.isUpload;
}); });
return f; return f;
}, },
UnJoin(){ UnJoin() {
let f=this.EquipMents.filter(v => { let f = this.EquipMents.filter(v => {
return v.name.toLowerCase().indexOf(this.search.toLowerCase()) > -1 && !v.isUpload; return v.name.toLowerCase().indexOf(this.search.toLowerCase()) > -1 && !v.isUpload;
}); });
return f; return f;
}, },
}, },
onHide: function() { onHide: function() {
ble.StopSearch(); ble.StopSearch();
@ -226,13 +316,13 @@
}, },
onLoad() { onLoad() {
these = this; these = this;
mq = MQTT.getMqTool(); mq = MQTT.getMqTool();
mq.init(); mq.init();
this.groupid = common.DateFormat(new Date(), 'yyyy-MM-dd HH:mm:ss'); this.groupid = common.DateFormat(new Date(), 'yyyy-MM-dd HH:mm:ss');
ble = bleTool.getBleTool(); ble = bleTool.getBleTool();
// serv = serTool.serverInit(); // serv = serTool.serverInit();
@ -431,9 +521,10 @@
// these.EquipMents=[]; // these.EquipMents=[];
ble.addDeviceFound((arr) => { ble.addDeviceFound((arr) => {
// console.log("发现新设备,",arr);
arr = arr.devices; arr = arr.devices;
let promis = []; let promis = [];
let newDevice = false;
for (var i = 0; i < arr.length; i++) { for (var i = 0; i < arr.length; i++) {
arr[i].linkStatu = false; arr[i].linkStatu = false;
@ -444,7 +535,11 @@
arr[i].name = arr[i].name.replace(/\r\n/g, '').replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,''); arr[i].name = arr[i].name.replace(/\r\n/g, '').replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,'');
if(these.cType){
if(arr[i].name.indexOf(these.cType.ble)===-1){
continue;
}
}
let f = these.EquipMents.find(function(v, index) { let f = these.EquipMents.find(function(v, index) {
if (v.deviceId == arr[i].deviceId) { if (v.deviceId == arr[i].deviceId) {
@ -455,18 +550,25 @@
}); });
if (!f) { if (!f) {
newDevice = true;
arr[i].remark = '正在校验...'; arr[i].remark = '正在校验...';
arr[i].isValid = false;
if (arr[i].advertisData) {
arr[i].macAddress = arr[i].advertisData;
}
these.EquipMents.unshift(arr[i]); these.EquipMents.unshift(arr[i]);
these.getDevice(arr[i]);
// console.log("EquipMents=", these.EquipMents);
} }
} }
these.sendEquipToMq(); these.sendEquipToMq();
// console.log("equip=", these.EquipMents)
if (newDevice) {
clearTimeout(isValidTime);
isValidTime = setTimeout(these.getDevice, 2000); //延迟执行验证
}
}, pagePath); }, pagePath);
// console.log("addEquip") // console.log("addEquip")
ble.addReceiveCallback((receivData, f, path, arr) => { ble.addReceiveCallback((receivData, f, path, arr) => {
@ -511,17 +613,17 @@
ble.addStateBreakCallback(() => { ble.addStateBreakCallback(() => {
MsgError('蓝牙不可用','确定',these); MsgError('蓝牙不可用', '确定', these);
these.EquipMents.filter((v, i) => { these.EquipMents.filter((v, i) => {
these.$set(these.EquipMents[i], 'link', false); these.$set(these.EquipMents[i], 'link', false);
}); });
}, pagePath); }, pagePath);
ble.addStateRecoveryCallback(() => { ble.addStateRecoveryCallback(() => {
these.ReSearch(); these.ReSearch();
MsgSuccess('蓝牙恢复可用','确定',these,()=>{ MsgSuccess('蓝牙恢复可用', '确定', these, () => {
MsgClear(these); MsgClear(these);
}); });
}, },
@ -555,7 +657,15 @@
eventChannel.on('addType', function(rec) { eventChannel.on('addType', function(rec) {
console.log("接收到父页面的参数:", rec); console.log("接收到父页面的参数:", rec);
these.type = rec.data; these.type = rec.data;
let ct=these.typeKeys.find(v=>{
if(v.type_name==these.type.typeName){
these.search=v.ble;
return true;
}
return false;
});
let callback = () => { let callback = () => {
these.getTypeDeviceCnt().then(res => { these.getTypeDeviceCnt().then(res => {
console.error("设备数量:", res); console.error("设备数量:", res);
@ -581,32 +691,32 @@
}); });
// #ifdef APP|APP-PLUS // #ifdef APP|APP-PLUS
setTimeout(()=>{ setTimeout(() => {
MsgInfo("如需要在PC上查看此数据,请复制链接后通过微信发送到PC,在PC端打开然后点右上角扫码授权","复制链接",these,true,()=>{ MsgInfo("如需要在PC上查看此数据,请复制链接后通过微信发送到PC,在PC端打开然后点右上角扫码授权", "复制链接", these, true, () => {
console.log("开始访问剪切板"); console.log("开始访问剪切板");
uni.setClipboardData({ uni.setClipboardData({
data:'https://static-mp-5b7c35fc-f6fe-4100-a2e1-3669e4d4bfc9.next.bspapp.com/AppTools/views/index.html', data: 'https://static-mp-5b7c35fc-f6fe-4100-a2e1-3669e4d4bfc9.next.bspapp.com/AppTools/views/index.html',
success(){ success() {
uni.showToast({ uni.showToast({
title:'已复制链接' title: '已复制链接'
}); });
plus.runtime.openURL('weixin://', (err) => { plus.runtime.openURL('weixin://', (err) => {
MsgError("打开微信失败,请手动打开微信,发送至'文件传输助手'"); MsgError("打开微信失败,请手动打开微信,发送至'文件传输助手'");
}); });
}, },
fail(ex) { fail(ex) {
console.error("ex=",ex); console.error("ex=", ex);
} }
}); });
}); });
},500); }, 500);
// #endif // #endif
}, },
onShow: function() { onShow: function() {
@ -699,120 +809,199 @@
}); });
}, },
getDevice(item) { getDevice() {
//从后台通过类型和名称查询设备
return new Promise((resolve, reject) => { let task = (item) => {
let f = null;
let fIndex = -1;
these.EquipMents.find(function(v, index) { return new Promise((resolve, reject) => {
if (v.deviceId == item.deviceId) { let f = null;
f = v; let fIndex = -1;
fIndex = index; these.EquipMents.find(function(v, index) {
return true; if (v.deviceId == item.deviceId) {
f = v;
fIndex = index;
return true;
}
return false;
});
if (fIndex == -1) {
reject("检验出现异常");
console.error("fIndex异常")
return;
} }
return false;
});
if (this.devicesCnt > 0) { if (this.devicesCnt > 0) {
if (this.devices && this.devices.length > 0) { console.log("从缓存验证")
let eqp = this.devices.find(v => { if (this.devices && this.devices.length > 0) {
let flag = v.bluetooth_name.replace(/\r\n/g, '').replace( console.log("正在从缓存验证1111")
/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '') == item.name; let eqp = this.devices.find(v => {
let flag = false;
if (!item.advertisData) {
flag = v.bluetooth_name.replace(/\r\n/g, '').replace(
/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '') == item.name;
} else {
flag = v.deviceMac == item.advertisData;
}
return flag;
return flag; });
if (eqp) {
console.log("缓存验证成功");
these.$set(these.EquipMents[fIndex], "isUpload",
true);
these.$set(these.EquipMents[fIndex], "remark",
"校验完成,设备已入库");
these.$set(these.EquipMents[fIndex], "macAddress",
eqp.device_mac);
these.$set(these.EquipMents[fIndex], "device_name", eqp.device_name);
these.$set(these.EquipMents[fIndex], 'isValid', true);
}); console.log("从缓存中找到了设备", eqp);
if (eqp) { resolve(eqp);
return;
}
// else{
// console.error("缓存验证失败");
// }
}
// console.error("缓存中找不到此设备22222222", this.devices);
// these.$set(these.EquipMents[fIndex], "remark", "校验完成,设备未入库");
// these.$set(these.EquipMents[fIndex], 'isValid', true);
// reject(null);
// these.sendEquipToMq();
// return;
}
let succCallback = (data) => {
if (data) {
these.$set(these.EquipMents[fIndex], "isUpload", these.$set(these.EquipMents[fIndex], "isUpload",
true); true);
these.$set(these.EquipMents[fIndex], "remark", these.$set(these.EquipMents[fIndex], "remark",
"校验完成,设备已入库"); "校验完成,设备已入库");
these.$set(these.EquipMents[fIndex], "macAddress", these.$set(these.EquipMents[fIndex], "macAddress",
eqp.device_mac); data.device_mac);
these.$set(these.EquipMents[fIndex], "device_name", eqp.device_name); these.$set(these.EquipMents[fIndex], "imei", data
console.log("从缓存中找到了设备", eqp); .device_imei);
resolve(eqp); these.$set(these.EquipMents[fIndex], "device_name", data.device_name);
return;
}
}
// console.error("缓存中找不到此设备22222222", this.devices);
these.$set(these.EquipMents[fIndex], "remark",
"校验完成,设备未入库");
reject(null);
these.sendEquipToMq();
return;
}
let succCallback = (data) => {
if (data) {
these.$set(these.EquipMents[fIndex], "isUpload",
true);
these.$set(these.EquipMents[fIndex], "remark",
"校验完成,设备已入库");
these.$set(these.EquipMents[fIndex], "macAddress",
data.device_mac);
these.$set(these.EquipMents[fIndex], "imei", data
.device_imei);
these.$set(these.EquipMents[fIndex], "device_name", data.device_name);
} else {
console.error("设备未入库111111", data)
these.$set(these.EquipMents[fIndex], "remark",
"校验完成,设备未入库");
}
these.sendEquipToMq();
}
let errCallback = () => {
these.$set(these.EquipMents[fIndex], "remark",
"校验出现异常");
these.sendEquipToMq();
}
let p2 = new Promise((resolve, reject) => {
let json = {
"tenant_id": this.type.tenantId,
"deviceType": this.type.deviceTypeId,
"deviceName": item.name
};
request({
url: '/app/xinghan/device/GetDeviceByName',
data: json,
method: 'POST'
}).then(res => {
if (res && res.code == 200) {
resolve(res.data);
return;
} else {
console.error("设备未入库111111", data)
these.$set(these.EquipMents[fIndex], "remark",
"校验完成,设备未入库");
} }
reject(res); these.sendEquipToMq();
}).catch(ex => { }
reject(ex);
let errCallback = (ex) => {
if (ex === null) {
these.$set(these.EquipMents[fIndex], "remark", "校验完成,设备未入库");
} else {
these.$set(these.EquipMents[fIndex], "remark", "校验出现异常");
}
these.sendEquipToMq();
}
let p2 = new Promise((succ, err) => {
if (item.advertisData) {
console.error("通过广播数据匹配mac地址");
request({
url: '/app/device/getDeviceInfoByDeviceMac',
method: 'GET',
data: {
deviceMac: item.advertisData
}
}).then(res => {
console.log("通过广播数据验证成功:", res)
if (res && res.code == 200) {
if (res.data) {
let data = {
device_mac: res.data.deviceMac,
device_imei: res.data.deviceImei,
device_name: res.data.deviceName,
id: res.data.id,
bluetooth_name: res.data.bluetoothName
};
succ(data);
} else {
err(null);
}
return;
}
err(res);
}).catch(ex => {
err(ex);
});
} else {
//从后台通过类型和名称查询设备
console.error("通过类型和名称查询设备");
let json = {
"tenant_id": this.type.tenantId,
"deviceType": this.type.deviceTypeId,
"deviceName": item.name
};
request({
url: '/app/xinghan/device/GetDeviceByName',
data: json,
method: 'POST'
}).then(res => {
console.log("通过名称校验结果", res);
if (res && res.code == 200) {
if (res.data) {
succ(res.data);
} else {
err(null);
}
return;
}
err(res);
}).catch(ex => {
err(ex);
});
}
}); });
})
Promise.any([p2]).then(res => {
succCallback(res);
}).catch(ex => {
errCallback(ex);
}).finally(() => {
p2.then(res => {
succCallback(res);
resolve(res);
}).catch(ex => {
errCallback(ex);
reject(ex);
}).finally(() => {
these.$set(these.EquipMents[fIndex], 'isValid', true);
});
}); });
}); }
for (let i = 0; i < this.EquipMents.length; i++) {
let element = this.EquipMents[i];
if (!element.isValid) {
task(element).catch(ex => {
if (ex === null && element.advertisData) {
console.log("广播自动入库");
this.uploadItem(element);
}
});
}
}
}, },
scan() { scan() {
@ -835,9 +1024,9 @@
let json = getUrlParams(res.result); let json = getUrlParams(res.result);
if (!json.key) { if (!json.key) {
MsgError('无效的二维码','',these); MsgError('无效的二维码', '', these);
return; return;
} }
this.scanKey = json.key; this.scanKey = json.key;
@ -909,27 +1098,29 @@
}, },
ReSearch() { ReSearch() {
if (!ble) { if (!ble) {
MsgError('蓝牙模块未初始化','',this); MsgError('蓝牙模块未初始化', '', this);
return; return;
} }
showLoading(this,{text:'请稍候...'}); showLoading(this, {
text: '请稍候...'
});
ble.disconnectDevice().finally(dis => { ble.disconnectDevice().finally(dis => {
ble.StopSearch().finally(res => { ble.StopSearch().finally(res => {
this.EquipMents = []; this.EquipMents = [];
this.PairEquip = []; this.PairEquip = [];
setTimeout(()=>{ setTimeout(() => {
ble.StartSearch().then(result => { ble.StartSearch().then(result => {
}).catch(err => { }).catch(err => {
console.error("err=", err); console.error("err=", err);
MsgError("出现错误:" + err.msg, '', these); MsgError("出现错误:" + err.msg, '', these);
}).finally(()=>{ }).finally(() => {
hideLoading(these); hideLoading(these);
}); });
},600) }, 600)
}).catch(ex => { }).catch(ex => {
console.error("ex=", ex); console.error("ex=", ex);
MsgError("出现错误:" + ex.msg, '', these); MsgError("出现错误:" + ex.msg, '', these);
@ -959,8 +1150,9 @@
method: 'post', method: 'post',
data: json data: json
}).then(res => { }).then(res => {
console.log("res=", res);
if (res && res.code == 200) { if (res && res.code == 200) {
console.log("res=", res);
this.EquipMents.find((v, index) => { this.EquipMents.find((v, index) => {
if (v.deviceId == item.deviceId) { if (v.deviceId == item.deviceId) {
this.$set(this.EquipMents[index], "isUpload", true); this.$set(this.EquipMents[index], "isUpload", true);
@ -978,22 +1170,27 @@
return false; return false;
}); });
} else { } else {
console.error("出现错误,", item); console.error("入库错误,", item);
console.error("出现错误,", this.devices); console.error("入库结果,", res);
this.EquipMents.find((v, index) => { this.EquipMents.find((v, index) => {
if (v.deviceId == item.deviceId) { if (v.deviceId == item.deviceId) {
this.$set(this.EquipMents[index], "isUpload", false);
this.$set(this.EquipMents[index], "remark", res.msg); this.$set(this.EquipMents[index], "remark", res.msg);
if (res.msg.indexOf('已存在') > -1) {
this.$set(this.EquipMents[index], "isUpload", true);
} else {
this.$set(this.EquipMents[index], "isUpload", false);
this.devices.find((d, i) => {
if (d.device_mac == item.macAddress) {
this.$set(this.EquipMents[index],
"device_name", d
.device_name);
return true;
}
});
}
this.devices.find((d, i) => {
if (d.device_mac == item.macAddress) {
this.$set(this.EquipMents[index], "device_name", d
.device_name);
return true;
}
});
return true; return true;
} }
@ -1010,10 +1207,14 @@
}, },
Link: function(item) { Link: function(item) {
if (item.advertisData) {
this.uploadItem(item);
return;
}
let exec = () => { let exec = () => {
showLoading(this, { showLoading(this, {
text: "正在连接:第1次" text: "正在连接..."
}); });
let index = 1; let index = 1;
@ -1053,7 +1254,7 @@
return false; return false;
}); });
resolve(res); resolve(res);
}).catch((ex) => { }).catch((ex) => {
if (index == total) { if (index == total) {
@ -1079,8 +1280,8 @@
these.sendEquipToMq(); these.sendEquipToMq();
}).catch(ex => { }).catch(ex => {
console.log("ex=", ex) console.log("ex=", ex)
MsgError("连接失败"+ex.code + ex.msg,'',these); MsgError("连接失败" + ex.code + ex.msg, '', these);
hideLoading(these); hideLoading(these);
}); });
} }
@ -1097,22 +1298,25 @@
</script> </script>
<style> <style>
.tabItem.active{ .tabItem.active {
border-bottom:2rpx solid #BBE600; border-bottom: 2rpx solid #BBE600;
color:#BBE600;
}
.mathIcon{
color: #BBE600; color: #BBE600;
} }
.tab{
display: flex; .mathIcon {
flex-direction: row; color: #BBE600;
flex-wrap: nowrap;
align-content: center;
justify-content: space-evenly;
height: 60rpx;
font-size: 28rpx;
} }
.tab {
display: flex;
flex-direction: row;
flex-wrap: nowrap;
align-content: center;
justify-content: space-evenly;
height: 60rpx;
font-size: 28rpx;
}
.noLink { .noLink {
text-align: center; text-align: center;
width: 100%; width: 100%;
@ -1479,7 +1683,7 @@
.topStatric { .topStatric {
width: 100%; width: 100%;
box-sizing: border-box; box-sizing: border-box;
padding:0rpx 30rpx; padding: 0rpx 30rpx;
position: fixed; position: fixed;
top: 0rpx; top: 0rpx;
z-index: 99; z-index: 99;
@ -1523,6 +1727,7 @@
overflow-y: scroll; overflow-y: scroll;
margin-top: 150rpx; margin-top: 150rpx;
} }
/* #endif */ /* #endif */

View File

@ -40,17 +40,25 @@
</view> </view>
<view class="device-name"> <view class="device-name">
<view>设备:{{item.deviceName}}</view> <view>设备:{{item.deviceName}}</view>
<view class="ID"> <view class="ID">
<view class="ID" ID:{{item.deviceImei?item.deviceImei:item.deviceMac}}
v-if="item.communicationMode==0 || item.communicationMode==2"> </view>
ID:{{item.deviceImei}}
<view class="ID">
<view class="center p10">
<view
:class="{'onlines':item.onlineStatus==1,'offlines':item.onlineStatus==0}">
{{item.onlineStatus==1?'在线':'离线'}}
</view>
<view class="splitLine"></view>
<view>电量{{item.battery || '0'}}%</view>
</view> </view>
<view class="ID" v-else>ID:{{item.deviceMac}}</view>
<!-- 在线状态 --> <!-- <view @click.stop="Disc()">识别</view> -->
<view class="onlines" v-if="item.onlineStatus==1">在线</view>
<!-- 离线状态 -->
<view class="offlines" v-if="item.onlineStatus==0">离线</view>
<view>电量{{item.battery || '0'}}%</view>
</view> </view>
</view> </view>
</view> </view>
@ -154,6 +162,10 @@
import bleTool from '@/utils/BleHelper.js'; import bleTool from '@/utils/BleHelper.js';
import MescrollUni from '@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-uni.vue' import MescrollUni from '@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-uni.vue'
import BleReceive from '@/utils/BleReceive'; import BleReceive from '@/utils/BleReceive';
import {
MsgError
} from '@/utils/MsgPops';
import MqttClient from '@/utils/mqtt.js';
var pagePath = 'pages/common/index'; var pagePath = 'pages/common/index';
var ble = null; var ble = null;
@ -707,6 +719,62 @@
} }
this.$set(this.deviceList[index], 'showOption', 'none'); this.$set(this.deviceList[index], 'showOption', 'none');
}, },
Disc(item, index) { //发送识别指令
let json = {
ins_disc: 1
};
let bleSend = () => {
let f = ble.data.LinkedList.find((v) => {
return v.macAddress == item.deviceMac;
});
if (f) {
ble.sendString(f.deviceId, json, f.writeServiceId, f.wirteCharactId, 30).then(res => {
index++;
setTimeout(sendNextPacket, 300);
}).catch(err => {
if (item.communicationMode == 1) {
MsgError(err.msg, '', this);
return;
}
mqSend();
});
}
}
let mqSend = () => {
let Send = () => {
let flag = mq.publish("B/" + item.deviceImei, JSON.stringify(json));
if (!flag) {
MsgError("识别设备失败,请检查手机网络连接", '', this);
}
}
if (!mq) {
mq = new MqttClient();
mq.connect(() => {
console.log("MQTT连接成功")
Send();
});
return ;
}
Send();
}
if (item.communicationMode == 1 || item.communicationMode == 2) {
bleSend.catch(ex => {
mqSend();
});
return;
}
if (item.communicationMode == 0) {
mqSend();
return;
}
},
// 列表跳转 // 列表跳转
handleFile(item, index) { handleFile(item, index) {
if (item.showOption == 'right') { if (item.showOption == 'right') {
@ -966,7 +1034,8 @@
box-sizing: border-box; box-sizing: border-box;
position: relative; position: relative;
} }
.device-card.active{
.device-card.active {
background-color: #2a2a2a !important; background-color: #2a2a2a !important;
} }
@ -1316,4 +1385,17 @@
width: 16px; width: 16px;
height: 16px; height: 16px;
} }
.splitLine {
background: linear-gradient(90.00deg, rgba(0, 0, 0, 0), rgba(255, 255, 255, 1) 44.525%, rgba(255, 254.75, 254.75, 0) 92%);
opacity: 0.2;
width: 25rpx;
height: 4rpx;
margin: 0rpx 10rpx;
transform: rotate(90.00deg);
}
.p10 {
padding-left: 20rpx;
}
</style> </style>

View File

@ -250,7 +250,7 @@
/* nvue 全屏必须这样写 */ /* nvue 全屏必须这样写 */
.container { .container {
flex: 1; flex: 1;
box-sizing: border-box;
} }
.map { .map {

View File

@ -768,7 +768,7 @@ class BleHelper {
} catch (convertException) { } catch (convertException) {
if (str && (str.trim().startsWith('{') || str.trim().startsWith('['))) { if (str && (str.trim().startsWith('{') || str.trim().startsWith('['))) {
console.error("JSON解析失败可能是格式错误的数据", convertException); console.error("JSON解析失败可能是格式错误的数据", convertException);
} }
console.error("错误的数据", str); console.error("错误的数据", str);
} }
@ -916,12 +916,12 @@ class BleHelper {
return; return;
} }
} }
// 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((
v) => { v) => {
if (v.deviceId == res if (v.deviceId == res
@ -940,15 +940,18 @@ class BleHelper {
if (!fdis) { if (!fdis) {
if (this.data.connectingDevices[res.deviceId]) { if (this.data.connectingDevices[res.deviceId]) {
console.log(`设备 ${res.deviceId} 已经在连接中,跳过自动重试`); console.log(`设备 ${res.deviceId} 已经在连接中,跳过自动重试`);
return; } else {
res.device = f.device;
console.log("蓝牙状态可用,尝试1次恢复连接,", f.deviceId);
this.LinkBlue(res.deviceId, f
.writeServiceId, f
.wirteCharactId, f
.notifyCharactId, 1).catch(ex => {
console.error(ex.msg);
});
} }
res.device = f.device;
console.log("蓝牙状态可用,尝试5次恢复连接,", f.deviceId);
this.LinkBlue(res.deviceId, f
.writeServiceId, f
.wirteCharactId, f
.notifyCharactId, 5);
} }
} }
@ -1010,6 +1013,19 @@ class BleHelper {
}); });
if (f) { if (f) {
if (item.advertisData) {
let bytes = new Uint8Array(item.advertisData);
let hex = Array.from(bytes).map(b => b.toString(16).toUpperCase().padStart(2, '0'))
.join(':');
let reg = /^([0-9a-f]{2}[:-]){5}[0-9a-f]{2}$/i;
if (reg.test(hex)) {
item.advertisData = hex;
} else {
item.advertisData = '';
}
}
item.name = item.name?.replace(/\r\n/g, '').replace(
/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
// console.log("发现目标设备:", item); // console.log("发现目标设备:", item);
arr.push(item); arr.push(item);
} }
@ -1577,17 +1593,42 @@ class BleHelper {
//连接某个设备 //连接某个设备
LinkBlue(deviceId, targetServiceId, writeCharId, notifyCharId, maxRetries) { LinkBlue(deviceId, targetServiceId, writeCharId, notifyCharId, maxRetries) {
//连接成功的回调
let LinkedCallback=() => {
if (this.cfg.recoveryCallback.length > 0) {
this.cfg.recoveryCallback.forEach((
c) => {
try {
c.callback({
deviceId: deviceId,
connected: true
});
} catch (error) {
console.error(
"执行蓝牙恢复连接的回调出现异常,",
error)
}
});
}
}
if (this.data.platform == 'web') { if (this.data.platform == 'web') {
LinkedCallback();
return Promise.resolve(true); return Promise.resolve(true);
} }
if (this.data.connectingDevices[deviceId]) { if (this.data.connectingDevices[deviceId]) {
console.error("连接任务进行中,本次连接被阻断") console.error("连接任务进行中,本次连接被阻断")
return Promise.resolve(false); return Promise.reject({
code: -1,
msg: '正在连接中,请稍候...'
});
} }
this.data.connectingDevices[deviceId] = true; this.data.connectingDevices[deviceId] = true;
if (maxRetries === undefined) { if (!maxRetries) {
maxRetries = 0; // 最大重试次数 maxRetries = 0; // 最大重试次数
} }
if (!writeCharId) { if (!writeCharId) {
@ -1608,33 +1649,37 @@ class BleHelper {
return false; return false;
}); });
////console.log("findex=" + fIndex); ////console.log("findex=" + fIndex);
var these = this; var these = this;
//连接设备 //连接设备
var linkDevice = () => { var linkDevice = () => {
// 添加重试次数限制 // 添加重试次数限制
let retryCount = 0; let retryCount = 0;
const connect = () => { const connect = () => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
if (fIndex > -1 && f?.Linked) { if (fIndex > -1 && f?.Linked) {
// console.log("当前已连接,跳过其他步骤"); console.log("当前已连接,释放连接锁");
delete this.data.connectingDevices[deviceId];
resolve(false); resolve(false);
LinkedCallback();
return; return;
} }
if (!this.data.available) { if (!this.data.available) {
console.error("蓝牙不可用,释放连接锁");
reject(this.getError({ reject(this.getError({
code: 10001 code: 10001
})); }));
delete this.data.connectingDevices[deviceId];
return; return;
} }
console.log("正在连接" + deviceId); console.log("正在连接" + deviceId);
uni.createBLEConnection({ uni.createBLEConnection({
deviceId: deviceId, deviceId: deviceId,
@ -1643,8 +1688,8 @@ class BleHelper {
//释放连接锁 //释放连接锁
delete this.data.connectingDevices[deviceId]; delete this.data.connectingDevices[deviceId];
console.log("新连接成功", this.data.LinkedList); console.error("新连接成功释放连接锁", deviceId);
LinkedCallback();
// 处理 MTU 设置 // 处理 MTU 设置
if (plus.os.name === 'Android') { if (plus.os.name === 'Android') {
this.setMtu(deviceId).catch(ex => { this.setMtu(deviceId).catch(ex => {
@ -1666,7 +1711,7 @@ 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 = this.data.LinkedList[fIndex].linkId =
linkId; linkId;
} else { } else {
this.data.LinkedList.push(cr); this.data.LinkedList.push(cr);
} }
@ -1683,22 +1728,7 @@ class BleHelper {
// console.log("LinkedList=", this.data // console.log("LinkedList=", this.data
// .LinkedList); // .LinkedList);
//执行连接成功的回调
if (this.cfg.recoveryCallback.length > 0) {
this.cfg.recoveryCallback.forEach((
c) => {
try {
c.callback({
deviceId: deviceId,
connected: true
});
} catch (error) {
console.error(
"执行蓝牙恢复连接的回调出现异常,",
error)
}
});
}
resolve(true); resolve(true);
@ -1722,6 +1752,7 @@ class BleHelper {
}, 1000); // 延迟1秒后重试 }, 1000); // 延迟1秒后重试
} else { } else {
//释放连接锁 //释放连接锁
console.error("连接失败,释放连接锁", deviceId)
delete this.data.connectingDevices[deviceId]; delete this.data.connectingDevices[deviceId];
reject(ex); reject(ex);
} }

View File

@ -14,7 +14,7 @@ import {
class BleReceive { class BleReceive {
constructor(_ref) { constructor(_ref) {
if(_ref){ if(_ref && !this.ref){
this.ref = _ref; this.ref = _ref;
} }
this.StorageKey = "linkedDevices"; this.StorageKey = "linkedDevices";

View File

@ -282,7 +282,7 @@ export default {
value: "46", value: "46",
label: "手动报警", label: "手动报警",
checked: false, checked: false,
type: ['210', '102', '6170','018A'] type: ['210', '102', '6170', '018A']
}, },
{ {
value: "47", value: "47",
@ -314,7 +314,7 @@ export default {
value: "51", value: "51",
label: "警示灯", label: "警示灯",
checked: false, checked: false,
type: ['100', '100J','018A'] type: ['100', '100J', '018A']
}, },
{ {
@ -600,7 +600,7 @@ export default {
}); });
}, },
MapNavi(lon, lat, name, mapType) {//打开地图路线规划页面 MapNavi(lon, lat, name, mapType) { //打开地图路线规划页面
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
if (!lon || !lat) { if (!lon || !lat) {
reject("经纬度不能为空"); reject("经纬度不能为空");
@ -609,19 +609,45 @@ export default {
let url = ""; let url = "";
if (!mapType || mapType == 'amap') { if (!mapType || mapType == 'amap') {
let amapScheme = uni.getSystemInfoSync().platform === 'ios' ? 'iosamap://' : 'androidamap://'; let amapScheme = uni.getSystemInfoSync().platform === 'ios' ? 'iosamap://' : 'androidamap://';
url = `${amapScheme}route/plan?sourceApplication=myapp&dlat=${lat}&dlon=${lon}&dname=${name}&dev=0&t=0`; url =
`${amapScheme}route/plan?sourceApplication=myapp&dlat=${lat}&dlon=${lon}&dname=${name}&dev=0&t=0`;
} else { } else {
url =`baidumap://map/direction?destination=latlng:${lat},${lon}|name:${name}&coord_type=gcj02&src=myapp` url =
`baidumap://map/direction?destination=latlng:${lat},${lon}|name:${name}&coord_type=gcj02&src=myapp`
} }
plus.runtime.openURL(url, (ex) => { plus.runtime.openURL(url, (ex) => {
console.error("ex=",ex); console.error("ex=", ex);
reject("无法打开地图软件"+url); reject("无法打开地图软件" + url);
}); });
}); });
},
saveDeviceLog(json) { //保存设备日志
return new Promise((resolve, reject) => {
let url = '/app/xinghan/device/saveDeviceLog';
request({
url: url,
method: 'POST',
data:json
}).then(res => {
if (res && res.code == 200) {
resolve(res);
return;
}
reject(res);
}).catch(ex => {
reject(ex);
});
});
} }
} }

View File

@ -15,6 +15,7 @@ import {
showPop showPop
} from '@/utils/MsgPops.js'; } from '@/utils/MsgPops.js';
import Common from '@/utils/Common.js'; import Common from '@/utils/Common.js';
import api from '@/api/670/HBY670.js'
class SendBatchData { class SendBatchData {
@ -48,6 +49,7 @@ class SendBatchData {
console.log("开始发送分片数据"); console.log("开始发送分片数据");
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
if (f) { if (f) {
ble.data.voiceUploading=true;
// 总数据包数 // 总数据包数
var totalPackets = 1536; //36; var totalPackets = 1536; //36;
@ -62,6 +64,7 @@ class SendBatchData {
const sendNextVideoPacket = () => { const sendNextVideoPacket = () => {
// console.log("准备发送一段数据"); // console.log("准备发送一段数据");
if (currentPacket > totalPackets) { if (currentPacket > totalPackets) {
ble.data.voiceUploading=false;
if (!ReSendNo) { if (!ReSendNo) {
setTimeout(() => { setTimeout(() => {
@ -149,7 +152,7 @@ class SendBatchData {
currentPacket); currentPacket);
setTimeout(sendNextVideoPacket, 800); setTimeout(sendNextVideoPacket, 800);
} else { } else {
ble.data.voiceUploading=false;
hideLoading(these); hideLoading(these);
showPop({ showPop({
@ -191,7 +194,7 @@ class SendBatchData {
ble.sendString(f.deviceId, "video transmit start", f ble.sendString(f.deviceId, "video transmit start", f
.writeServiceId, f.wirteCharactId).then(res => { .writeServiceId, f.wirteCharactId).then(res => {
ble.data.voiceUploading=true;
setTimeout(() => { setTimeout(() => {
console.log("握手成功了"); console.log("握手成功了");
resolve(true); resolve(true);
@ -652,6 +655,14 @@ class SendBatchData {
if (combinedData.length === curr - 1) { if (combinedData.length === curr - 1) {
setTimeout(() => { setTimeout(() => {
holdHand('transmit complete', 200).then(res => { holdHand('transmit complete', 200).then(res => {
let json = {
deviceId: these.device.id,
name: these.formData.usrname,
position: these.formData.job,
unitName: these.formData.company,
code: these.formData.usrid
};
api.sendUsr(json);
MsgSuccess("人员信息发送成功", "确定", these); MsgSuccess("人员信息发送成功", "确定", these);
hideLoading(these); hideLoading(these);
these.setBleFormData(); these.setBleFormData();
@ -738,6 +749,11 @@ class SendBatchData {
}); });
} }
SendMsg(){
}
} }
export default SendBatchData; export default SendBatchData;