添加报警功能

This commit is contained in:
liub
2025-08-28 14:05:06 +08:00
parent c2aa8bfa2f
commit 9846fe2315
18 changed files with 1212 additions and 444 deletions

41
App.vue
View File

@ -1,14 +1,46 @@
<script>
import bleTool from '@/utils/BleHelper.js'
import upgrade from '@/utils/update.js'
export default {
onLaunch: function() {
//以下代码仅在开发时使用,否则会出现不可预知的问题。
//清除登陆之外的所有信息;
// let store=uni.getStorageInfoSync();
// store.keys.forEach((val,index,array)=>{
// if(val=="tokenTime"){
// let time=uni.getStorageSync(val);
// if(!time){
// time=0;
// }
// let currTime=new Date().getTime();
// if(currTime>=time){
// uni.removeStorageSync(val);
// uni.removeStorageSync("token");
// uni.removeStorageSync("clientID");
// }
// }
// else if(val=="token" || val=="clientID"){
// console.log("忽略登陆信息");
// }else{
// uni.removeStorageSync(val);
// }
// });
//以上代码仅在开发时使用,否则会出现不可预知的问题。
uni.getSystemInfo({success:function(res){
if(res.uniPlatform=='app'){
upgrade.checkAndUpdateWgt("http://114.55.111.217/app/CheckUpdate");
bleTool.getBleTool();
}
}});
},
onShow: function() {
console.log('App Show')
console.log('App Show');
},
onHide: function() {
console.log('App Hide')
console.log('App Hide');
}
}
</script>
@ -54,4 +86,9 @@
.uni-picker-view-wrapper{
background: rgba(42, 42, 42, 1);
}
@font-face {
font-family: "PingFang SC";
src: url("~@/static/fonts/PingFangSC.ttf") format("opentype");
}
</style>

View File

@ -1,4 +1,4 @@
import {request,baseURL} from '@/utils/request'
import request, { baseURL } from '@/utils/request'
function getdata(data,url,method){
return new Promise((resolve,reject)=>{
@ -14,6 +14,7 @@ function getdata(data,url,method){
method: method,
data:data
}).then((res)=>{
console.log("res=",res);
resolve(res);
}).catch(ex=>{
reject(ex);

55
api/670/History.js Normal file
View File

@ -0,0 +1,55 @@
import request, { baseURL } from '@/utils/request'
function getdata(data,url,method){
return new Promise((resolve,reject)=>{
if(!url){
reject('url为空');
return;
}
if(!method){
method='POST';
}
request({
url: url,
method: method,
data:data
}).then((res)=>{
console.log("res=",res);
resolve(res);
}).catch(ex=>{
console.log("ex=",ex);
reject(ex);
});
});
}
//获取开关机数据
function getSwithData(data){
let url="";
return getdata(data,url,"POST");
}
//报警信息
function getWarnData(data){
let url=""
return getdata(data,url,"POST");
}
//故障信息
function getFaulData(data){
let url=""
return getdata(data,url,"POST");
}
export default{
getSwithData:getSwithData,
getWarnData:getWarnData,
getFaulData:getFaulData
}

View File

@ -177,17 +177,19 @@ export default {
return styles[this.type][styleType]
},
handleButtonClick() {
console.log('[MessagePopup] Button clicked with value:', this.inputValue)
this.$emit('buttonClick', this.inputValue)
},
handleMaskClick() {
console.log('[MessagePopup] Mask clicked')
this.$emit('maskClick')
},
closeClick(){
this.$emit('closePop')
},
handleCancelClick(){
this.$emit('cancelPop');
},
handleInput(e) {

View File

@ -2,14 +2,14 @@ import App from './App'
//// 引入 uView UI
import uView from 'vk-uview-ui';
import bleTool from '@/store/BLETools.js';
// #ifndef VUE3
import Vue from 'vue'
import store from './store/store';
import './uni.promisify.adaptor'
Vue.config.productionTip = false
Vue.prototype.$bleTool = bleTool;
App.mpType = 'app'
const app = new Vue({
store,
@ -25,7 +25,7 @@ import {
} from 'vue'
export function createApp() {
const app = createSSRApp(App)
app.config.globalProperties.$bleTool = bleTool;
// 使用 uView UI
app.use(uView)
return {

View File

@ -2,7 +2,7 @@
"name" : "JingQuan",
"appid" : "__UNI__A21EF43",
"description" : "设备管控",
"versionName" : "1.0.0",
"versionName" : "1.0.9",
"versionCode" : "100",
"transformPx" : false,
/* 5+App */

View File

@ -265,7 +265,8 @@
{
"path": "pages/670/HBY670",
"style": {
"navigationBarTitleText": "HBY670"
"navigationBarTitleText": "HBY670",
"navigationStyle": "custom"
}
},
{
@ -273,6 +274,13 @@
"style": {
"navigationBarTitleText": "HBY650"
}
},
{
"path" : "pages/670/History",
"style" :
{
"navigationBarTitleText" : "历史记录"
}
}

View File

@ -1,6 +1,9 @@
<template>
<view class="content contentBg">
<view class="eq">
<custom-navbar :title="Status.navbar.title" :showBack="Status.navbar.showBack" color="#FFFFFF"
:rightIcons="Status.navbar.icons" @icon-click="handleRightClick"></custom-navbar>
<view class="eq" :style="{marginTop:Status.navbar.height+'px'}">
<view class="leftImg">
<image class="img" :src="device['devicePic']" mode="aspectFit"></image>
</view>
@ -41,8 +44,14 @@
</view>
<view class="warnnig" v-bind:class="formData.staticWarn?'':'displayNone'">
<view>设备自动报警中</view>
<view>{{Status.staticWarn.time}}s</view>
<view>警告环境存在漏电电源</view>
<view class="netContent">
<view v-bind:class="getWarnStyle(1)" class="net netone"></view>
<view v-bind:class="getWarnStyle(2)" class="net nettwo"></view>
<view v-bind:class="getWarnStyle(3)" class="net netsiri"></view>
<view v-bind:class="getWarnStyle(4)" class="net netfour"></view>
<view v-bind:class="getWarnStyle(5)" class="net netfive"></view>
</view>
</view>
<view class="optTitle">
@ -64,18 +73,22 @@
</view>
<view class="optTitle">
SOS
报警
</view>
<view class="sosContent">
<view class="item" @click="sosSetting('sg')" :class="formData.SOS=='sg'?'active':''">
<view class="imgContent center">
<image class="img" :src="formData.SOS=='sg'?'/static/images/670/sgActive.png':'/static/images/670/sg.png'" mode="aspectFit"></image>
<image class="img"
:src="formData.SOS=='sg'?'/static/images/670/sgActive.png':'/static/images/670/sg.png'"
mode="aspectFit"></image>
</view>
<view class="txt">声光报警</view>
</view>
<view class="item" @click="sosSetting('rb')" :class="formData.SOS=='rb'?'active':''">
<view class="imgContent center">
<image class="img" :src="formData.SOS=='rb'?'/static/images/670/rbActive.png':'/static/images/670/rb.png'" mode="aspectFit"></image>
<image class="img"
:src="formData.SOS=='rb'?'/static/images/670/rbActive.png':'/static/images/670/rb.png'"
mode="aspectFit"></image>
</view>
<view class="txt">红蓝闪烁</view>
</view>
@ -86,19 +99,25 @@
<view class="lightMode">
<view class="item" @click="lightSetting('qiang')" :class="formData.lightCurr=='qiang'?'active':''">
<view class="imgContent center">
<image class="img" :src="formData.lightCurr=='qiang'?'/static/images/670/qiangActive.png':'/static/images/670/qiang.png'" mode="aspectFit"></image>
<image class="img"
:src="formData.lightCurr=='qiang'?'/static/images/670/qiangActive.png':'/static/images/670/qiang.png'"
mode="aspectFit"></image>
</view>
<view class="txt">强光</view>
</view>
<view class="item" @click="lightSetting('ruo')" :class="formData.lightCurr=='ruo'?'active':''">
<view class="imgContent center">
<image class="img" :src="formData.lightCurr=='ruo'?'/static/images/670/ruoActive.png':'/static/images/670/ruo.png'" mode="aspectFit"></image>
<image class="img"
:src="formData.lightCurr=='ruo'?'/static/images/670/ruoActive.png':'/static/images/670/ruo.png'"
mode="aspectFit"></image>
</view>
<view class="txt">弱光</view>
</view>
<view class="item" @click="lightSetting('close')" :class="formData.lightCurr=='close'?'active':''">
<view class="imgContent center">
<image class="img" :src="formData.lightCurr=='close'?'/static/images/670/jieNActive.png':'/static/images/670/jieN.png'" mode="aspectFit"></image>
<image class="img"
:src="formData.lightCurr=='close'?'/static/images/670/jieNActive.png':'/static/images/670/jieN.png'"
mode="aspectFit"></image>
</view>
<view class="txt">关闭</view>
</view>
@ -149,7 +168,8 @@
<view>
<view class="item">
<input class="value" style="text-indent: 20rpx;" v-model="formData.msgTxt" placeholder="请输入文字" placeholder-class="usrplace" />
<input class="value" style="text-indent: 20rpx;" v-model="formData.msgTxt" placeholder="请输入文字"
placeholder-class="usrplace" />
</view>
</view>
@ -191,8 +211,8 @@
:borderColor="Status.Pop.borderColor" :textColor="Status.Pop.textColor"
:buttonBgColor="Status.Pop.buttonBgColor" :buttonTextColor="Status.Pop.buttonTextColor"
:iconUrl="Status.Pop.iconUrl" :message="Status.Pop.message" :buttonText="Status.Pop.buttonText"
@buttonClick="HidePop" :visiblePrompt="Status.Pop.visiblePrompt" :promptTitle="Status.Pop.promptTitle"
v-model="Status.Pop.modelValue" />
@buttonClick="HidePop" @closePop="closePop" @cancelPop="closePop" :visiblePrompt="Status.Pop.visiblePrompt"
:promptTitle="Status.Pop.promptTitle" v-model="Status.Pop.modelValue" />
<!-- 下方菜单 -->
<BottomSlideMenuPlus :config="Status.BottomMenu" @close="closeMenu" @itemClick="handleItemClick"
@ -230,6 +250,19 @@
data() {
return {
Status: {
apiType:"listA",
navbar: {
icons: [{
src: '/static/images/common/msg.png'
},
{
src: '/static/images/common/shape.png'
}
],
title: 'HBY670',
showBack: true,
height: 90
},
staticWarn: {
time: 0,
inteval: null
@ -302,7 +335,7 @@
company: "", //单位
usrname: "", //姓名
job: "", //职位
id: "", //id
usrid: "", //id
msgTxt: "", //消息1
qzwarn: false, //是否强制报警
warnLevel: "", //报警级别
@ -334,13 +367,22 @@
picPath: ""
}
},
created() {
this.Status.navbar.height = uni.getSystemInfoSync().statusBarHeight + 20;
},
onUnload() {
console.log("页面卸载,释放资源");
let statusTopic = `A/${this.formData.imei?this.formData.imei:this.device.deviceImei}`;
ble.removeReceiveCallback(pagePath);
if (mqttClient) {
mqttClient.unsubscribe(statusTopic);
mqttClient.disconnect();
mqttClient = null;
}
},
onLoad: function() {
console.log("670页面加载");
// console.log("670页面加载");
these = this;
recei = BleReceive.getBleReceive();
ble = BleTool.getBleTool();
@ -351,6 +393,7 @@
console.log("收到父页面的参数:" + JSON.stringify(data));
var device = data.data;
these.Status.apiType=data.apiType;
these.device = device;
if (these.device.deviceImei) {
these.initMQ();
@ -358,7 +401,7 @@
let f = ble.data.LinkedList.find((v) => {
if (v.macAddress == device.deviceMac) {
console.log("找到设备了", v);
these.formData.deviceId = v.deviceId;
return true;
}
return false;
@ -376,8 +419,7 @@
}
if (these.formData['imei'] && !these.device.deviceImei) {
these.initMQ();
}
else if(these.device.deviceImei){
} else if (these.device.deviceImei) {
these.formData['imei'] = these.device.deviceImei;
}
ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId);
@ -391,45 +433,91 @@
ble.removeReceiveCallback(pagePath);
},
computed: {
RSSIRemark: function() {
let remark = '极弱';
if (this.formData.RSSI <= 0 && this.formData.RSSI >= -30) {
remark = '强';
}
if (this.formData.RSSI < -30 && this.formData.RSSI >= -60) {
remark = '一般';
}
if (this.formData.RSSI < -60 && this.formData.RSSI >= -85) {
remark = '弱';
}
if (this.formData.RSSI < -85 && this.formData.RSSI >= -100) {
remark = '微弱';
}
}
},
methods: {
getWarnStyle(index) {
let className = "";
switch (this.formData.warnLevel) {
case "none":
break;
case "ruo":
if (index <= 1) {
className = "active";
}
break;
case "center":
if (index <= 3) {
className = "active";
}
break;
case "hight":
if (index <= 4) {
className = "active";
}
break;
case "veryhight":
if (index <= 5) {
className = "active";
}
break;
}
return className;
},
handleRightClick: function(s, e) {
if (s === 0) {
console.log("消息");
uni.navigateTo({
url: '/pages/670/History',
success: (res) => {
res.eventChannel.emit('detailData', {
data: these.device,
});
}
})
return;
} else if (s === 1) {
console.log("分享");
uni.navigateTo({
url: '/pages/6170/share/index',
events: {
ack: function(data) {}
},
success: (res) => {
res.eventChannel.emit('share', {
data: this.device,
});
}
})
}
},
initMQ() {
return new Promise((resolve, reject) => {
console.log("正在初始化MQtt")
if (mqttClient) {
console.log("无需再次初始化")
resolve();
return;
}
console.log("正在初始化MQtt")
mqttClient = new MqttClient();
mqttClient.connect(() => {
console.log("连接成功,开始订阅消息")
// 订阅来自设备的状态更新
const statusTopic = `A/${this.formData.imei?this.formData.imei:this.device.deviceImei}`;
const statusTopic =
`A/${this.formData.imei?this.formData.imei:this.device.deviceImei}`;
mqttClient.subscribe(statusTopic, (payload, receive) => {
try {
let json = JSON.parse(payload);
let keys = Object.keys(json);
// console.log("keys=", keys);
// console.log("keys=", keys);sta_DetectGrade
if (keys.indexOf('sta_DetectGrade') > -1) { //上报的报文
console.log("收到设备上报的数据", payload);
this.parseDataMQ(json);
@ -462,6 +550,7 @@
sendMQ(message) {
message = JSON.stringify(message);
console.log("imei=", this.formData.imei ? this.formData.imei : this.device.deviceImei);
const topic = `B/${this.formData.imei?this.formData.imei:this.device.deviceImei}`;
return new Promise((resolve, reject) => {
if (!mqttClient) {
@ -481,7 +570,8 @@
reject("MQTT未连接无法发布消息");
} catch (error) {
console.log("出现了异常", error);
mqttClient.unsubscribe(`A/${this.formData.imei?this.formData.imei:this.device.deviceImei}`);
mqttClient.unsubscribe(
`A/${this.formData.imei?this.formData.imei:this.device.deviceImei}`);
mqttClient.disconnect();
this.initMQ();
reject(error);
@ -489,6 +579,7 @@
});
},
parseDataMQ(json) {
let receiveData = {};
let staticLevelText = "";
let dic = {
"3": "hight",
@ -516,16 +607,22 @@
warn = dic[json.sta_DetectResult];
let sosText = json.sta_SOSGrade === 2 ? 'rb' :
let sosText =null;
if(json.sta_SOSGrade!==undefined){
sosText=json.sta_SOSGrade === 2 ? 'rb' :
json.sta_SOSGrade === 1 ? "sg" : "close"
receiveData.SOS = sosText;
}
let staticWarn = json.sta_ShakeBit === 1;
receiveData.modeCurr = staticLevelText;
receiveData.lightCurr = lightingLevelText;
receiveData.xuhang = json.sta_PowerTime + "分钟";
receiveData.battary = json.sta_PowerPercent + "%";
receiveData.SOS = sosText;
receiveData.warnLevel = warn;
receiveData.staticWarn = staticWarn;
receiveData.fourGStrenth = json.sta_4gSinal;
@ -533,7 +630,7 @@
receiveData.Lon = json.sta_longitude;
receiveData.Lat = json.sta_latitude;
this.refreshFormData(receiveData);
this.refreshFormData(receiveData,'auto');
return receiveData;
},
bleValueNotify: function(receive, device, path) { //订阅消息
@ -562,11 +659,11 @@
}
return;
}
this.refreshFormData(data);
this.refreshFormData(data,'auto');
}
},
refreshFormData(data){
refreshFormData(data,type) {
let keys = Object.keys(data);
for (var i = 0; i < keys.length; i++) {
let key = keys[i];
@ -579,22 +676,22 @@
}
if (these.formData.staticWarn) { //有静止报警
these.showPop({
message: "自动报警",
message: "环境存在漏电电源",
iconUrl: "/static/images/6155/DeviceDetail/warnning.png",
borderColor: "#e034344d",
buttonBgColor: "#E03434",
buttonText:"解除报警",
buttonText: "确定",
clickEvt: "staticWarn"
});
this.Status.staticWarn.time=180;
this.Status.staticWarn.inteval=setInterval(()=>{
if(this.Status.staticWarn.time===0){
clearInterval(this.Status.staticWarn.inteval);
this.formData.staticWarn=false;
return;
}
this.Status.staticWarn.time=this.Status.staticWarn.time-1;
},1000)
// this.Status.staticWarn.time=5;
// this.Status.staticWarn.inteval=setInterval(()=>{
// if(this.Status.staticWarn.time===0){
// clearInterval(this.Status.staticWarn.inteval);
// this.formData.staticWarn=false;
// return;
// }
// this.Status.staticWarn.time=this.Status.staticWarn.time-1;
// },1000)
}
@ -650,13 +747,14 @@
};
console.log("type=", type);
let json = {
ins_SOSGrade: [dic.mqtt[type]]
ins_LightGrade: [dic.mqtt[type]]
};
let requestSend = () => {
this.sendMQ(json).then((res) => {
console.log("4g发送成功");
}).catch((ex) => {
console.log("ex=",ex);
these.showPop({
message: "通信异常,请检查手机或设备网络",
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
@ -713,13 +811,13 @@
this.formData.SOS = type;
let dic = {
ble: {
sg: 0x68,
rb: 0x69,
rb: 0x68,
sg: 0x69,
close: 0x6A
},
mqtt: {
sg: 2,
rb: 1,
sg: 1,
rb: 2,
close: 0
}
@ -733,6 +831,7 @@
this.sendMQ(json).then((res) => {
console.log("4g发送成功");
}).catch((ex) => {
console.log("ex=",ex);
these.showPop({
message: "通信异常,请检查手机或设备网络",
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
@ -748,6 +847,7 @@
}
let SendCmd = () => {
let f = this.getDevice();
let buffer = null;
if (f) {
@ -761,8 +861,25 @@
dataView.setUint8(4, 0x01); // 数据长度
dataView.setUint8(5, dic.ble[type]); // 数据
ble.sendData(f.deviceId, buffer, f.writeServiceId, f.wirteCharactId, 10).then(() => {
ble.sendData(f.deviceId, buffer, f.writeServiceId, f.wirteCharactId, 10).then(
() => {
console.log("蓝牙发送成功了");
dic={
close: 0x71
}
if(type in dic){
dataView.setUint8(1, 0x06); // 帧类型
dataView.setUint8(5, 0x71); // 数据
}else{
dataView.setUint8(1, 0x06); // 帧类型
dataView.setUint8(5, 0x70); // 数据
}
ble.sendData(f.deviceId, buffer, f.writeServiceId, f.wirteCharactId, 10).then(()=>{
console.log("蓝牙发送报警成功",type);
})
hideLoading(these);
these.setBleFormData();
}).catch((ex) => {
@ -775,6 +892,9 @@
}
}
SendCmd();
}
setTimeout(task, 0);
},
GearSetting: function(type) { //档位设置
@ -809,6 +929,7 @@
this.sendMQ(json).then((res) => {
console.log("4g发送成功");
}).catch((ex) => {
console.log("ex=",ex)
these.showPop({
message: "通信异常,请检查手机或设备网络",
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
@ -848,6 +969,7 @@
requestSend();
});
} else {
console.log("找不到蓝牙设备使用4G发送")
requestSend();
}
}
@ -1057,6 +1179,8 @@
sendImgByRequest().then(resolve).catch(reject);
});
} else {
sendImgByRequest().then(resolve).catch(reject);
}
});
}
@ -1406,26 +1530,51 @@
},
HidePop: function() {
if (this.Status.Pop.clickEvt == 'staticWarn') {
this.Status.staticWarnTime=0;
// this.Status.staticWarnTime=0;
// clearInterval(this.Status.staticWarn.inteval);
// this.formData.staticWarn=false;
}
if(this.Status.Pop.okCallback){
console.log("执行点击按钮回调");
this.Status.Pop.okCallback();
}
this.Status.Pop.showPop = false;
},
showPop: function(option) {
closePop: function() {
this.Status.Pop.showPop = false;
if (!option) {
option = {
a: 1
if(this.Status.Pop.cancelCallback){
this.Status.Pop.cancelCallback();
}
},
showPop: function(option) {
hideLoading(this);
let defaultCfg = {
showCancel: false,
borderColor: '#BBE600',
buttonBgColor:'#BBE600',
okCallback:null,
cancelCallback:null,
popType: 'custom'
};
if (!option) {
}
let keys = Object.keys(option);
for (var i = 0; i < keys.length; i++) {
let key = keys[i];
these.Status.Pop[key] = option[key];
}
if (!option.borderColor) {
option.borderColor = '#BBE600';
option.buttonBgColor = '#BBE600';
keys = Object.keys(defaultCfg);
for (var i = 0; i < keys.length; i++) {
let key = keys[i];
if(key in option){
continue;
}
these.Status.Pop[key] = defaultCfg[key];
}
these.Status.Pop.showPop = true;
},
sendUsr: function(ReSendNo) {
@ -1435,9 +1584,9 @@
deviceId: this.device.id,
deviceImei: this.device.deviceImei ? this.device.deviceImei : this.formData.imei,
name: this.formData.company,
position: this.formData.name,
position: this.formData.usrname,
unitName: this.formData.job,
code: this.formData.id
code: this.formData.usrid
};
api.sendUsr(json).then((res) => {
these.showPop({
@ -1472,9 +1621,9 @@
var textLines = [
this.formData.company,
this.formData.name,
this.formData.usrname,
this.formData.job,
this.formData.id
this.formData.usrid
];
@ -1641,7 +1790,10 @@
]
}
console.log("data=", data);
api.warnMsg(data).then((res)=>{
api.warnMsg(data).catch((ex) => {
console.log("ex=", ex);
}).then((res) => {
console.log("res=", res)
if (res.code == 200) {
these.showPop({
showPop: true, //是否显示弹窗
@ -1945,6 +2097,7 @@
box-sizing: border-box;
padding: 24rpx 28rpx;
background: rgba(26, 26, 26, 1);
margin-bottom: 20rpx;
}
.usrtitle {
@ -2258,6 +2411,7 @@ padding:30rpx 0rpx 10rpx 30rpx;
justify-content: space-between;
align-items: center;
}
.sosContent .item {
width: calc(calc(100% - 80rpx) / 2);
height: 100%;
@ -2289,6 +2443,7 @@ padding:30rpx 0rpx 10rpx 30rpx;
border-radius: 4rpx;
margin-right: 30rpx;
}
.sosContent .imgContent .img {
width: 70%;
height: 70%;
@ -2342,19 +2497,62 @@ display: flex;
width: 80rpx;
height: 100rpx;
}
.lightMode .imgContent .img {
width: 100%;
height: 100%;
}
.picVideo .btnImg {
width: 100%;
height: 100rpx;
border-radius: 16rpx;
background: rgba(42, 42, 42, 1);
}
.picVideo .btnImg .img {
width: 40rpx;
height: 40rpx;
}
.netContent {
display: flex;
flex-direction: row;
flex-wrap: nowrap;
align-content: flex-end;
justify-content: space-around;
align-items: flex-end;
width: 50rpx;
}
.net {
width: 7rpx;
background: rgba(255, 255, 255, 0.3);
}
.net.netone {
height: 11rpx;
}
.net.nettwo {
height: 17rpx;
}
.net.netsiri {
height: 23rpx;
}
.net.netfour {
height: 29rpx;
}
.net.netfive {
height: 35rpx;
}
.net.active {
background: #FFFFFF !important;
}
</style>

446
pages/670/History.vue Normal file
View File

@ -0,0 +1,446 @@
<template>
<view class="content contentBg">
<view class="topTip">
<view class="item" @click="tabChange(0)" :class="Status.tabIndex===0?'active':''">开机</view>
<view class="item" @click="tabChange(1)" :class="Status.tabIndex===1?'active':''">报警</view>
<view class="item" @click="tabChange(2)" :class="Status.tabIndex===2?'active':''">故障</view>
</view>
<view class="tabs">
<view class="tab" :class="Status.tabIndex===0?'active':''">
<view class="li" v-for="item,index in SwithData">
<view>
<view class="label">开机时间</view>
<view class="value">{{item['open']}}</view>
</view>
<view class="marginTop10">
<view class="label">关机时间</view>
<view class="value">{{item['close']}}</view>
</view>
</view>
</view>
<view class="tab" :class="Status.tabIndex===1?'active':''">
<view class="li warn" v-for="item,index in WarnData">
<view class="row">
<view class="label">报警事项:</view>
<view class="value red">{{item['evtName']}}</view>
</view>
<view class="marginTop10 row">
<view class="label">报警地点:</view>
<view class="value">{{item['address']}}</view>
</view>
<view class="marginTop10 row">
<view class="label">报警时间:</view>
<view class="value">{{item['open']}}</view>
</view>
<view class="marginTop10 row">
<view class="label">解除时间:</view>
<view class="value">{{item['close']}}</view>
</view>
<view class="marginTop10 row">
<view class="label">报警时长:</view>
<view class="value">{{item['time']}}</view>
</view>
</view>
</view>
<view class="tab" :class="Status.tabIndex===2?'active':''">
<view class="li warn" v-for="item,index in FaultData">
<view class="row">
<view class="label">故障部位:</view>
<view class="value red">{{item['evtName']}}</view>
</view>
<view class="marginTop10 row">
<view class="label">故障时间:</view>
<view class="value">{{item['open']}}</view>
</view>
<view class="marginTop10 row">
<view class="label">处理时间:</view>
<view class="value">{{item['close']}}</view>
</view>
</view>
</view>
</view>
<global-loading ref="loading"></global-loading>
</view>
</template>
<script>
import Common from '@/utils/Common.js';
import api from '@/api/670/History.js'
import {
showLoading,
hideLoading,
updateLoading
} from '@/utils/loading.js'
export default {
data() {
return {
Status: {
tabIndex: 1
},
device: {},
SwithData: [], //开关机的数据
FaultData: [], //故障数据
WarnData: [], //报警数据
}
},
onLoad() {
var these = this;
let channel = this.getOpenerEventChannel();
channel.on('detailData', function(opt) {
console.log("我收到你的数据了,谢谢你。", opt.data);
these.device = opt.data;
these.tabChange(these.Status.tabIndex, true);
});
},
methods: {
loadWarnData() { //加载报警数据
var these = this;
let promise1 = new Promise((resolve, reject) => {
let arr = [];
let endDate = new Date();
arr.push({
evtName: '环境存在漏电电源',
address: '湖北省武汉市洪山区关山街道国际企业中心聚星楼',
open: Common.DateFormat(endDate),
time: '00:00:59'
});
for (var i = 1; i < 10; i++) {
arr.push({
evtName: '环境存在漏电电源',
address: '湖北省武汉市洪山区关山街道国际企业中心聚星楼',
open: Common.DateFormat(endDate.setHours(i * -24)),
time: '00:00:59'
});
}
for (var i = 0; i < arr.length; i++) {
let item = new Date(arr[i].open);
let close = Common.DateFormat(item.setHours(4));
arr[i].close = close;
}
resolve(arr);
});
let promise2 = new Promise((resolve, reject) => {
api.getWarnData(this.device).then((res) => {
resolve(res);
}).catch((ex) => {
console.log("获取数据异常", ex);
reject(ex);
});
});
Promise.allSettled([promise1, promise2]).then(results => {
if (results[1].status == 'fulfilled') {
these.WarnData = results[1].value;
} else {
these.WarnData = results[0].value;
}
});
},
loadSwithData() { //加载开关机数据
var these = this;
let promise1 = new Promise((resolve, reject) => {
let arr = [];
let endDate = new Date();
arr.push({
open: Common.DateFormat(endDate)
});
for (var i = 1; i < 10; i++) {
arr.push({
open: Common.DateFormat(endDate.setHours(i * -24))
});
}
for (var i = 0; i < arr.length; i++) {
let item = new Date(arr[i].open);
let close = Common.DateFormat(item.setHours(4));
arr[i].close = close;
}
resolve(arr);
});
let promise2 = new Promise((resolve, reject) => {
api.getSwithData(this.device).then((res) => {
resolve(res);
}).catch((ex) => {
console.log("获取数据异常", ex);
reject(ex);
});
});
Promise.allSettled([promise1, promise2]).then(results => {
if (results[1].status == 'fulfilled') {
these.SwithData = results[1].value;
} else {
these.SwithData = results[0].value;
}
});
},
loadFaultData() { //加载故障数据
var these = this;
let promise1 = new Promise((resolve, reject) => {
let arr = [];
let endDate = new Date();
let dic = ['报警灯', '蜂鸣器', '电池', '蓝牙模块', '定位器', '4G模块'];
arr.push({
evtName: '报警灯',
open: Common.DateFormat(endDate),
});
for (var i = 1; i < 10; i++) {
arr.push({
evtName: dic[i % 6],
open: Common.DateFormat(endDate.setHours(i * -24)),
});
}
for (var i = 0; i < arr.length; i++) {
let item = new Date(arr[i].open);
let close = Common.DateFormat(item.setHours(72), "yyyy-MM-dd");
arr[i].close = close;
}
resolve(arr);
});
let promise2 = new Promise((resolve, reject) => {
api.getFaulData(this.device).then((res) => {
resolve(res);
}).catch((ex) => {
console.log("获取数据异常", ex);
reject(ex);
});
});
Promise.allSettled([promise1, promise2]).then(results => {
if (results[1].status == 'fulfilled') {
these.FaultData = results[1].value;
} else {
these.FaultData = results[0].value;
}
});
},
tabChange(index, ispostback) {
if (this.Status.tabIndex === index && !ispostback) {
return;
}
this.Status.tabIndex = index;
showLoading(this);
let promise = new Promise((resolve, reject) => {
try {
if (index === 0) {
this.loadSwithData();
} else if (index === 1) {
this.loadWarnData();
} else if (index === 2) {
this.loadFaultData();
}
} catch (error) {
//TODO handle the exception
} finally {
hideLoading(this);
}
});
}
}
}
</script>
<style>
.tab .warn .value {
padding-left: 10rpx;
}
.tab .warn .value.red {
color: rgba(224, 52, 52, 1) !important;
}
.tab .warn .row {
display: flex;
flex-direction: row;
flex-wrap: nowrap;
align-content: center;
justify-content: flex-start;
align-items: flex-start;
}
.marginTop10 {
margin-top: 20rpx;
}
.tab .li .value {
color: rgba(255, 255, 255, 0.87);
width: calc(100% - 110rpx);
height: auto;
box-sizing: border-box;
}
.tab .li .label {
color: rgba(255, 255, 255, 0.6);
white-space: nowrap;
width: 110rpx;
}
.tab .li {
font-family: 'PingFang SC';
font-size: 24rpx;
font-weight: 400;
line-height: 35rpx;
letter-spacing: 0.14rpx;
width: 100%;
border-radius: 16rpx;
margin-top: 24rpx;
background: rgba(26, 26, 26, 1);
box-sizing: border-box;
padding: 20rpx 30rpx;
}
.tab.active {
display: block;
}
.tab {
width: 100%;
height: auto;
display: none;
}
.tabs {
width: 100%;
height: auto;
}
.topTip .item.active {
color: rgba(187, 230, 0, 1) !important;
font-size: 36rpx !important;
}
.topTip .item.active::before {
background: rgba(187, 230, 0, 1);
}
.topTip .item::before {
content: "";
width: 50%;
height: 4px;
border-radius: 31px;
position: absolute;
background: #00000000;
bottom: -10px;
left: 25%;
}
.topTip .item {
color: rgba(255, 255, 255, 0.87);
font-family: 'PingFang SC';
font-size: 28rpx;
font-weight: 400;
letter-spacing: 0.14rpx;
position: relative;
}
.topTip {
padding: 30rpx 0rpx;
display: flex;
flex-direction: row;
flex-wrap: nowrap;
align-content: center;
justify-content: space-between;
align-items: center;
position: sticky;
background-color: #121212;
height: 110rpx;
z-index: 9999;
margin-top: -30rpx;
}
/* #ifdef H5 */
/* 仅在 H5 平台生效的样式 */
.topTip {
top: 44px;
}
/* #endif */
/* #ifdef APP-PLUS */
/* 仅在 App 平台生效的样式 */
.topTip {
top: 0rpx;
}
/* #endif */
.content {
padding: 30rpx;
box-sizing: border-box;
width: 100%;
min-height: 100vh;
height: auto;
}
.contentBg {
background-color: #121212;
color: #ffffffde;
}
.fleft {
float: left;
}
.fright {
float: right;
}
.clear {
clear: both;
}
.displayNone {
display: none !important;
}
.p100 {
width: 100%;
height: 100%;
}
.center {
display: flex;
flex-direction: row;
flex-wrap: nowrap;
align-content: center;
justify-content: center;
align-items: center;
}
</style>

View File

@ -78,6 +78,7 @@
ble.removeReceiveCallback(pagePath);
},
onUnload() {
console.log("返回时断开蓝牙连接,取消订阅");
ble.removeReceiveCallback(pagePath);
},
onLoad(option) {
@ -86,12 +87,12 @@
ble.addReceiveCallback((receive,f,path) => {
console.log("收到设备消息,", receive);
if (these.device.deviceId == receive.deviceId) {
console.log("11111");
// console.log("11111");
if (receive.bytes[0] == 0xFC || receive.str.indexOf('mac address:') == 0) {
if (f && f.macAddress) {
these.device.macAddress = f.macAddress;
console.log("222222");
// console.log("222222");
these.initDevice();
}
}
@ -99,13 +100,23 @@
},pagePath);
eventChannel = this.getOpenerEventChannel();
eventChannel.on('LinkItem', function(data) {
console.log("data=",data);
let f = ble.data.LinkedList.find((v) => {
return v.deviceId = data.deviceId;
return v.deviceId == data.deviceId;
});
if (f) {
these.device = Object.assign({}, these.device, f);
console.log("获取到设备", f);
let keys=Object.keys(f);
keys.forEach((v,index)=>{
these.device[v]=f[v];
})
console.log("LinkedList=",ble.data.LinkedList)
console.log("f=", f);
console.log("获取到设备", these.device);
if (f.macAddress) {
these.device.macAddress = f.macAddress;
these.initDevice();
}
} else {
console.log("未获取到设备");
}
@ -117,6 +128,7 @@
showLoading(these, {
text: '正在获取设备信息'
});
console.log("these.device=",these.device);
request({
url: '/app/device/getDeviceInfoByDeviceMac',
method: 'GET',
@ -130,12 +142,12 @@
if (data) {
let keys = Object.keys(data);
ble.data.LinkedList.find((v) => {
if(v.deviceId = these.device.deviceId){
if(v.deviceId == these.device.deviceId){
for (var i = 0; i < keys.length; i++) {
let key = keys[i];
v[key] = data[key];
console.log("key="+key);
console.log("value="+data[key]);
// console.log("key="+key);
// console.log("value="+data[key]);
these.$set(these.device, key, data[key]);
@ -163,7 +175,7 @@
// 调用绑定设备接口
let f = ble.data.LinkedList.find((v) => {
return v.deviceId = these.device.deviceId;
return v.deviceId == these.device.deviceId;
});
if (!f) {
these.Statu.bound = false;
@ -195,7 +207,7 @@
if (res.code == 200) {
these.Statu.bound = true;
these.Statu.boundRemark = "设备绑定成功!";
ble.removeReceiveCallback(pagePath);
uni.$emit("refreshDeviceList");
setTimeout(() => {

View File

@ -136,7 +136,7 @@
},
onHide: function() {
ble.StopSearch();
ble.removeReceiveCallback(pagePath);
},
onBackPress: (e) => {
ble.StopSearch();
@ -145,8 +145,7 @@
},
onUnload(){
ble.StopSearch();
ble.removeDeviceFound(pagePath);
ble.removeReceiveCallback(pagePath);
},
onLoad() {
these = this;
@ -172,7 +171,12 @@
}
}
},pagePath);
// ble.addReceiveCallback((receivData) => {
// console.log("收到数据了:", receivData);//数据格式:{bytes:[109,97],str:"",hexs:"FA 01"}
// // let data=uni.getStorageSync(ble.StorageKey);
// console.log("LinkedList=",ble.data.LinkedList);
// },pagePath);
},
onShow: function() {
@ -187,12 +191,7 @@
});
ble.addReceiveCallback((receivData) => {
console.log("收到数据了:", receivData);//数据格式:{bytes:[109,97],str:"",hexs:"FA 01"}
console.log("LinkedList=",ble.data.LinkedList);
let data=uni.getStorageSync(ble.StorageKey);
console.log("data=",data);
},pagePath);
},
@ -241,7 +240,7 @@
these.PairEquip.push(item);
}
ble.removeReceiveCallback(pagePath);
console.log("连接成功");
uni.navigateTo({
url:"/pages/common/addBLE/LinkBle",
events:{

View File

@ -486,6 +486,10 @@
// 列表跳转
handleFile(item) {
let url = item.detailPageUrl;
// console.log("url=",url);
// if(!url){
//url="/pages/670/HBY670"
// }
uni.navigateTo({
url: url,
events: {
@ -498,6 +502,8 @@
deviceType: this.tabs[this.activeTab].id || '',
apiType: 'listA' //标识,根据这个参数,区分普通详情,分享跳转详情,查不一样的权限信息
});
},fail(ex) {
console.log("ex=",ex);
}
})
},

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

View File

@ -105,17 +105,17 @@ class BleHelper {
}
linkAllDevices() {
console.log("模块启动时,自动连接已连接过的设备", this.data.LinkedList);
// console.log("模块启动时,自动连接已连接过的设备", this.data.LinkedList);
if (this.data.LinkedList && this.data.LinkedList.length > 0) {
for (var i = 0; i < this.data.LinkedList.length; i++) {
let device = this.data.LinkedList[i];
console.log("自动连接:" + device.deviceId);
// console.log("自动连接:" + device.deviceId);
this.LinkBlue(device.deviceId, device.writeServiceId, device.wirteCharactId, device
.notifyCharactId);
}
} else {
console.log("无设备连接");
// console.log("无设备连接");
}
}
@ -128,7 +128,7 @@ class BleHelper {
}
const currentPage = pages[pages.length - 1];
console.log("currentPage=", currentPage.route);
// console.log("currentPage=", currentPage.route);
return currentPage.route;
}
@ -181,7 +181,7 @@ class BleHelper {
key = new Date().getTime();
}
if (key) {
console.log("订阅消息回调,key=" + key);
// console.log("订阅消息回调,key=" + key);
let f = this.cfg.receivDataCallback.findIndex((v) => {
return v.key == key;
});
@ -363,7 +363,7 @@ class BleHelper {
uni.openBluetoothAdapter({
success: (args) => {
console.log("蓝牙初始化成功:" + JSON.stringify(args));
// console.log("蓝牙初始化成功:" + JSON.stringify(args));
this.data.isOpenBlue = true;
this.data.available=true;
resolve(true);
@ -371,7 +371,7 @@ class BleHelper {
if (this.data.isSubscribe) { //整个App生命周期只订阅一次
return;
}
console.log("开始订阅各类变化消息");
// console.log("开始订阅各类变化消息");
this.data.isSubscribe = true;
@ -417,7 +417,7 @@ class BleHelper {
uni.setStorageSync(this.StorageKey, this.data
.LinkedList);
} else {
console.log("蓝牙连接已恢复,", res);
// console.log("蓝牙连接已恢复,", res);
}
});
@ -437,7 +437,7 @@ class BleHelper {
uni.onBLECharacteristicValueChange((receive) => {
//订阅消息
console.log("收到订阅消息",receive);
// console.log("收到订阅消息",receive);
let f=this.data.LinkedList.find((v) => {
return v.deviceId == receive.deviceId;
})
@ -500,7 +500,7 @@ class BleHelper {
str: str,
hexs: hexs
};
console.log("监听到特征值:" + JSON.stringify(recData));
// console.log("监听到特征值:" + JSON.stringify(recData));
if (this.cfg.receivDataCallback) {
if (this.cfg.receivDataCallback.length > 0) {
@ -678,7 +678,7 @@ class BleHelper {
state: state,
success: (res) => {
if (state) {
console.log("订阅消息成功", res);
// console.log("订阅消息成功", res);
} else {
console.log("取消订阅成功", res);
}

View File

@ -48,22 +48,23 @@ class BleReceive {
if(f && f.macAddress && f.id){
let data={};
if(f.detailPageUrl=='/pages/6155/deviceDetail'){
console.log("该设备是6155");
// console.log("该设备是6155");
data= this.Receive_6155(receive,f,path);
}
if(f.detailPageUrl=='/pages/650/HBY650'){
console.log("该设备是650");
// console.log("该设备是650");
data= this.Receive_650(receive,f,path);
}
if(f.detailPageUrl=='/pages/670/HBY670'){
console.log("该设备是670");
// console.log("该设备是670");
data= this.Receive_670(receive,f,path);
}
console.log("收到数据并处理完毕,",data);
// console.log("收到数据并处理完毕,",data);
return data;
}
console.log("已收到该消息,但无法处理",f);
// console.log("已收到该消息,但无法处理",receive);
return receive;
}
@ -253,11 +254,11 @@ class BleReceive {
Receive_670(receive,f,path){
var todo = (bytes) =>{
console.log("todo");
// console.log("todo",receive);
let receiveData = {};
if (bytes[0] == 0x55) {
try {
console.log("todo");
// console.log("todo");
// 跳过帧头(第一个字节),从第二个字节开始解析
let staticLevelByte = bytes[1];
let staticLevelText = '';
@ -275,7 +276,7 @@ class BleReceive {
staticLevelText = 'close';
break
}
console.log("todo");
// console.log("todo");
// 解析照明档位
let lightingLevelByte = bytes[2];
let lightingLevelText = lightingLevelByte === 0x6d ? 'hight': lightingLevelByte === 0x6e ? 'low': 'close';
@ -287,7 +288,7 @@ class BleReceive {
let batteryLevelByte = bytes[5];
let batteryLevel = Math.max(0, Math.min(100, batteryLevelByte));
console.log("todo");
// console.log("todo");
let warn = bytes[6];
if (warn == 0x00) {
warn = 'none';
@ -304,7 +305,7 @@ class BleReceive {
let staticWarn = bytes[7] == 0x01;//静止报警
let fourGStrenth = bytes[8]; //4g信号强度
let sosTxt = bytes[9] == 0x00 ? 'close' : bytes[9] == 0x01 ? 'sg' : 'rb';
console.log("todo");
// console.log("todo");
receiveData.modeCurr = staticLevelText;
receiveData.lightCurr = lightingLevelText;
receiveData.xuhang = lightingTime ;
@ -316,7 +317,7 @@ class BleReceive {
} catch(error) {
console.log('数据解析错误:', error);
}
console.log("todo");
// console.log("todo");
} else {
try {
let uint8Array = new Uint8Array(receive.value);
@ -340,6 +341,7 @@ class BleReceive {
console.log('收到纬度:', +this.receiveData.macAddress);
} else {
try {
// console.log("str=",str);
let json=JSON.parse(str);
if("staBlue_picture" in json){
//重发图片
@ -372,7 +374,7 @@ class BleReceive {
} catch (error) {
receiveData={};
console.log("文本解析失败")
// console.log("文本解析失败",error)
}
}
} catch(ex) {
@ -380,7 +382,7 @@ class BleReceive {
console.log('将数据转文本失败', ex);
}
}
console.log("todo",receiveData);
// console.log("todo",receiveData);
this.setBleFormData(receiveData,f);
return receiveData;
}

View File

@ -5,19 +5,17 @@ export const showLoading = (ev,options) => {
if(!ev){
return;
}
let defaultTxt="请稍候...";
if(!options){
options={a:1};
options={text:defaultTxt};
}
if(!options.text && options.title){
options.text=options.title;
}
if(!options.text){
options.text="请稍候...";
options.text=defaultTxt;
}
ev.$refs.loading.show(options);
}
// 隐藏loading

View File

@ -171,7 +171,7 @@ class MqttClient {
potentialJsons.forEach(jsonString => {
if (jsonString.trim() === '') return;
if (this.messageCallbacks.has(topic)) {
this.messageCallbacks.get(topic)(jsonString);
this.messageCallbacks.get(topic)(jsonString,message);
}
});
};
@ -285,8 +285,10 @@ class MqttClient {
mqttMessage.qos = 1;
this.client.send(mqttMessage);
console.log(`成功发布消息到主题 ${topic}: ${message}`);
return true;
} else {
console.error('MQTT未连接无法发布');
return false;
}
}

View File

@ -22,9 +22,11 @@ const request = (options) => {
header: options.header || {},
timeout: 30000,
success: (res) => {
console.log("res=",res);
resolve(res.data);
},
fail: (err) => {
console.log("ex=",err);
reject(err);
}
};