diff --git a/pages/common/callPolice/index.vue b/pages/common/callPolice/index.vue
index 7a11efb..920a09a 100644
--- a/pages/common/callPolice/index.vue
+++ b/pages/common/callPolice/index.vue
@@ -72,8 +72,10 @@
import MescrollUni from '@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-uni.vue';
+ import MqTool from '@/utils/MqHelper.js';
var timeout = null;
var these = null;
+ var mq=null;
export default {
components: {
CustomPopup,
@@ -94,13 +96,28 @@
alarmApiMapping: [{
type: ['HBY100-J'],
sendApi: deviceForceAlarmActivation,
- statusTypeName: 'FunctionAccessBatchStatusRule_BJQ100J'
+ statusTypeName: 'FunctionAccessBatchStatusRule_BJQ100J',
+ sendType: 'FYSSend'
},
{
type: ['BJQ6170'],
sendApi: deviceSendAlarmMessage,
- statusTypeName: 'FunctionAccessBatchStatusRule_BJQ200J'
+ statusTypeName: 'FunctionAccessBatchStatusRule_BJQ200J',
+ sendType: 'FYSSend'
},
+
+ {
+ type: ['BJQ6075J'],
+ sendApi: deviceSendAlarmMessage,
+ statusTypeName: '',
+ sendType: 'CommonSend'
+ },
+ {
+ type: ['HBY670'],
+ sendApi: deviceSendAlarmMessage,
+ statusTypeName: '',
+ sendType: 'XSSend'
+ }
]
},
loading: false,
@@ -132,19 +149,20 @@
currentApiConfig() {
const currentTypeName = this.sendInfo.typeName || '';
// 匹配到则用对应配置,匹配不到用默认配置
- let f= this.dic.alarmApiMapping.find(v=>{
- return v.type.indexOf(currentTypeName)>-1;
+ let f = this.dic.alarmApiMapping.find(v => {
+ return v.type.indexOf(currentTypeName) > -1;
});
- if(f){
+ if (f) {
return f;
- }else{
+ } else {
return {
sendApi: deviceDefaultAlarm,
- statusTypeName: 'FunctionAccessBatchStatusRule_Default'
+ statusTypeName: 'FunctionAccessBatchStatusRule_Default',
+ sendType:'FYSSend'
};
}
-
-
+
+
}
},
methods: {
@@ -189,12 +207,12 @@
selectAll() {
console.log('123');
// 仅对在线设备进行全选/取消
- const allSelected = this.deviceList.every(item => item.checked);
+ const allSelected = this.deviceList.every(item => item.checked);
this.deviceList.forEach(item => {
// 离线设备不修改checked状态
-
- item.checked = !allSelected;
-
+
+ item.checked = !allSelected;
+
});
this.$forceUpdate();
},
@@ -205,7 +223,7 @@
console.log(deviceType, 'deviceTypedeviceType');
this.loading = true;
let data = {
- pageNum: 1,
+ pageNum: this.mescroll?this.mescroll.num:1,
pageSize: 50,
deviceType: deviceType
}
@@ -217,11 +235,16 @@
checked: false
}));
this.total = res.total;
- this.deviceList = newDevices;
-
+
+ if(data.pageNum===1){
+ this.deviceList = newDevices;
+ }else{
+ this.deviceList =this.deviceList.concat(newDevices);
+ }
+
+
let hasNext = true;
- if (res.rows.length < this.size || this.deviceList.length >= this
- .total) {
+ if (res.rows.length < data.pageSize || this.deviceList.length >= this.total) {
hasNext = false;
} else {
hasNext = true;
@@ -271,7 +294,7 @@
this.pendingAlarmAction = 0
},
//动态调用对应接口
- async sendAlarmCommand() {
+ sendAlarmCommand() {
const selectedDevices = this.deviceList.filter(item => item.checked);
const deviceIds = selectedDevices.map(item => item.id);
const deviceImeiList = selectedDevices.map(item => item.deviceImei);
@@ -291,34 +314,78 @@
// 获取当前typeName对应的接口和参数配置
const {
sendApi,
- statusTypeName
+ statusTypeName,
+ sendType
} = this.currentApiConfig;
- // 准备请求数据
- // const batchId = generateShortId();
- const requestData = {
- deviceIds: deviceIds,
- typeName: this.sendInfo.typeName,
- deviceImeiList: deviceImeiList,
- // batchId: batchId,
- voiceStrobeAlarm: this.pendingAlarmAction == 1 ? '1' : '0'
- };
- // 动态调用匹配的接口
- const registerRes = await sendApi(requestData);
- if (registerRes.code == 200) {
+
+ //FYS的方法
+ let FYSSend = async () => {
+ const requestData = {
+ deviceIds: deviceIds,
+ typeName: this.sendInfo.typeName,
+ deviceImeiList: deviceImeiList,
+ // batchId: batchId,
+ voiceStrobeAlarm: this.pendingAlarmAction == 1 ? '1' : '0'
+ };
+ // 动态调用匹配的接口
+ const registerRes = await sendApi(requestData);
+ if (registerRes.code == 200) {
+ uni.showToast({
+ title: isAlarming ? '强制报警开启成功' : '报警已解除',
+ icon: 'success'
+ });
+ this.showPopupFlag = false
+ uni.$emit('deviceStatusUpdate', {});
+ setTimeout(() => {
+ uni.navigateBack()
+ }, 500)
+ } else {
+ uni.showToast({
+ title: registerRes.msg || '状态查询失败',
+ icon: 'none'
+ });
+ }
+ }
+ //XS的方法
+ let XSSend = () => {
+ let json=JSON.stringify({ins_SOSGrade:[1]});
+ for (let i = 0; i < deviceImeiList.length; i++) {
+ let imei = deviceImeiList[i];
+
+ mq.sendData("B/"+imei,json,false);
+ }
+
uni.showToast({
title: isAlarming ? '强制报警开启成功' : '报警已解除',
icon: 'success'
});
this.showPopupFlag = false
- uni.$emit('deviceStatusUpdate', {});
- setTimeout(() => {
- uni.navigateBack()
- }, 500)
- } else {
+ }
+ //统一通信协议方法
+ let CommonSend = () => {
+ let json=JSON.stringify({ins_ShakeBit:1});
+ for (let i = 0; i < deviceImeiList.length; i++) {
+ let imei = deviceImeiList[i];
+ mq.sendData("B/"+imei,json,false);
+ }
+
uni.showToast({
- title: registerRes.msg || '状态查询失败',
- icon: 'none'
+ title: isAlarming ? '强制报警开启成功' : '报警已解除',
+ icon: 'success'
});
+ this.showPopupFlag = false
+ }
+
+ switch (sendType) {
+ case "FYSSend":
+ FYSSend();
+ break;
+ case "XSSend":
+ XSSend();
+ break;
+ case "CommonSend":
+ CommonSend();
+ break;
}
} catch (error) {
@@ -336,8 +403,18 @@
this.sendAlarmCommand(this.popupType);
},
},
+ onUnload() {
+ if(mq){
+ mq.disconnect();
+ }
+ },
onLoad(options) {
these = this;
+ mq=MqTool.getMqTool();
+ if(mq){
+ mq.init();
+
+ }
const eventChannel = this.getOpenerEventChannel();
// 监听 'deviceSend' 事件,获取传过来的数据
eventChannel.on('devicePolice', (data) => {
diff --git a/pages/common/send/index.vue b/pages/common/send/index.vue
index bd4d85c..68efc2d 100644
--- a/pages/common/send/index.vue
+++ b/pages/common/send/index.vue
@@ -28,21 +28,27 @@
-
+
-
+
- 编辑信息
-
-
-
-
+ 编辑信息
+
+
+
+
+
+
+
+
+
@@ -60,13 +66,30 @@
getdeviceSTatus
} from '@/utils/function.js';
import MescrollUni from '@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-uni.vue';
+ import MqTool from '@/utils/MqHelper.js';
+ import gbk from '@/utils/gbk.js';
+ import TextToHexV1 from '@/components/TextToHex/TextToHexV1.vue';
+ import {
+ showLoading,
+ hideLoading,
+ updateLoading
+ } from '@/utils/loading.js';
+ import {
+ MsgSuccess,
+ MsgError,
+ MsgClose,
+ MsgWarning,
+ showPop
+ } from '@/utils/MsgPops.js';
- var timer=null;
- var these=null;
+ var mq = null;
+ var timer = null;
+ var these = null;
export default {
components: {
CustomPopup,
- MescrollUni
+ MescrollUni,
+ TextToHexV1
},
data() {
return {
@@ -95,16 +118,17 @@
textNoMore: '没有更多数据了'
},
mescrollHeight: 0,
+ textLines:[]
}
},
methods: {
getSystemInfoSyncH() {
-
+
let sysInfo = uni.getSystemInfoSync();
-
+
// 底部 footer 高度约 220rpx + 120rpx = 340rpx,转换为 px(1rpx = sysInfo.pixelRatio / 750 * 屏幕宽度?不,直接用 rpx 转 px 公式)
let footerHeight = 500 * (sysInfo.screenWidth / 750); // rpx 转 px
-
+
// console.log("footerHeight=", footerHeight);
this.mescrollHeight = sysInfo.screenHeight - footerHeight;
// console.log("mescrollHeight=", this.mescrollHeight);
@@ -114,21 +138,21 @@
},
// 下拉刷新
downCallback() {
-
+
console.log("触发下拉刷新");
if (this.mescroll) {
this.mescroll.resetUpScroll(false);
this.mescroll.scrollTo(0, 0);
}
this.getData(this.sendInfo.id);
-
-
+
+
},
// 上拉加载
upCallback() {
console.log("触发上拉加载");
-
-
+
+
this.getData(this.sendInfo.id);
},
// onPullDownRefresh() {
@@ -142,11 +166,11 @@
// 获取设备列表
getData(deviceType) {
clearTimeout(timer);
- timer=setTimeout(()=>{
- console.log("开始加载第"+(this.mescroll? this.mescroll.num:1)+'页数据')
+ timer = setTimeout(() => {
+ console.log("开始加载第" + (this.mescroll ? this.mescroll.num : 1) + '页数据')
this.loading = true;
let data = {
- pageNum:this.mescroll? this.mescroll.num:1,
+ pageNum: this.mescroll ? this.mescroll.num : 1,
pageSize: 50,
deviceType: deviceType
}
@@ -158,34 +182,38 @@
checked: false
}));
this.total = res.total;
- this.deviceList = newDevices
-
+ if (data.pageNum === 1) {
+ this.deviceList = newDevices;
+ } else {
+ this.deviceList = this.deviceList.concat(newDevices);
+ }
+
+
this.total = res.total;
// 判断是否加载完成
let hasNext = true;
- if (res.rows.length < this.size || this.deviceList.length >= this
- .total) {
+ if (res.rows.length < data.pageSize || this.deviceList.length >= this.total) {
hasNext = false;
} else {
hasNext = true;
}
this.mescroll.endSuccess(res.rows.length, hasNext);
- }else {
- this.mescroll.endSuccess(0, false);
- }
+ } else {
+ this.mescroll.endSuccess(0, false);
+ }
}).finally(() => {
this.loading = false;
- }).catch(ex=>{
-
- this.mescroll.endSuccess(0, false);
-
+ }).catch(ex => {
+
+ this.mescroll.endSuccess(0, false);
+
});
-
- },200);
-
+
+ }, 200);
+
},
// 发送文本消息
- sendTextMessage() {
+ sendTextMessage() {
// 防重复提交
if (this.isSending) return;
const selectedDevices = this.deviceList.filter(item => item.checked)
@@ -207,15 +235,15 @@
}
this.isSending = true;
//FYS的方法
- let FYSSend =async () => {
-
-
+ let FYSSend = async () => {
+
+
try {
- uni.showLoading({
- title: '发送中...',
+ showLoading(these,{
+ text: '发送中...',
mask: true
});
-
+
// 2. 准备请求数据
const batchId = generateShortId();
const data = {
@@ -251,51 +279,219 @@
// 5. 显示成功弹窗
this.showPopupFlag = true
}
- } catch (error) {
- uni.showToast({
- title: error.message,
- icon: 'none'
- });
+ } catch (error) {
+ MsgError(error.message,null,these);
} finally {
- uni.hideLoading();
+ hideLoading(these);
this.isSending = false;
}
}
//XS的方法
- let XSSend=() => {
-
-
+ let XSSend = () => {
+
+
try {
+
+
+ let text = this.messageToSend.padEnd(16,'').substring(0,16);
+ let arr = gbk.encode(text)
+ let gbkData = gbk.arr2hex(arr);
+ let len=gbkData.length;
+ let list = [];
+ console.log("gbkData=",gbkData);
+ let rec = function(payload, receive) {
+ debugger;
+
+ console.log("收到消息,imei=" + mei + ",消息内容,", payload);
+ let json =JSON.parse(payload.payload);
+ let mei=payload.receive.topic.replace('A/','');
-
-
- this.showPopupFlag=true;
+ let childData=null;
+ let childIndex=null;
+ if (json.sta_BreakNews === 1) {
+ childIndex=1;
+ childData=gbkData.slice(0,len/2);
+ }
+ else if (json.sta_BreakNews === 2) {
+ childIndex=2;
+ childData=gbkData.slice(len/2,len);
+ }
+ else if (json.sta_BreakNews === 'cover!') {
+ mq.unSubscribes({topic:"A/" + mei});
+ return;
+ }
+ if(childData){
+ console.log("childData=",childData)
+ let buffer={ins_BreakNews:[childIndex]};
+ for (var i = 0; i < childData.length; i += 2) {
+ let value = parseInt(childData[i] + "" + childData[i + 1], 16);
+
+ buffer.ins_BreakNews.push(value);
+ }
+
+ let msg=JSON.stringify(buffer);
+ mq.sendData("B/" + mei, msg, false);
+ }
+
+ };
+ let msg = JSON.stringify({
+ ins_BreakNews: [0]
+ });
+ for (let i = 0; i < deviceImeiList.length; i++) {
+
+ list.push({
+ imie: deviceImeiList[i],
+ topic: 'A/' + deviceImeiList[i],
+ callback: rec
+ });
+
+ mq.sendData("B/" + deviceImeiList[i], msg, false);
+
+ }
+
+
+
+ mq.subscribes(list);
+
+ this.showPopupFlag = true;
} catch (error) {
-
+
} finally {
-
+
this.isSending = false;
}
}
//FS的方法
let FSSend = () => {
-
- try {
-
+ this.messageToSend.padEnd(16, ' ').slice(0,16);
-
- this.showPopupFlag = true
-
- } catch (error) {
-
- } finally {
-
- this.isSending = false;
+ this.textLines = [this.messageToSend.slice(0, 8), this.messageToSend.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,imei) => {
+ 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) {
+
+
+ holdHand('transmit complete', 200).then(res => {
+
+
+ });
+
+ return;
+ }
+
+ let array = combinedData[curr - 1];
+
+ let json =JSON.stringify( {
+ ins_msg: array.join("")
+ });
+ mq.sendData("B/" + imei, json, false).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, 40);
+ // 5. 发送成功处理
+
+
+ } catch (ex) {
+ uni.showModal({
+ title: '提示',
+ content: '发送失败' + (ex.msg || ex.code)
+ })
+ }
+
+
+ }
+
+ setTimeout(()=>{
+ drawText().then(pixels=>{
+ for (let i = 0; i < deviceImeiList.length; i++) {
+ let imei = deviceImeiList[i];
+ task(pixels,imei);
+ }
+
+ setTimeout(()=>{
+ hideLoading(these);
+ MsgSuccess("发送成功",null,these);
+ },800);
+ })
+ }, 10);
+
+
}
-
-
+
+
let device = selectedDevices[0];
let sendDic = [{
urls: ['/pages/6170/deviceControl/index', '/pages/210/HBY210', '/pages/6075/BJQ6075',
@@ -314,43 +510,50 @@
];
-
- let f = sendDic.find(v => {
- return v.urls.indexOf(device.detailPageUrl)>-1;
- });
- if (f) {
- f.send();
- } else {
- FYSSend();
+ let f = sendDic.find(v => {
+ return v.urls.indexOf(device.detailPageUrl) > -1;
+ });
+
+ if (f) {
+ f.send();
+ } else {
+ FYSSend();
+ }
+
+ },
+ onPopupConfirm() {
+ this.showPopupFlag = false
+ uni.navigateBack()
+ console.log('用户点击了确定')
+ // 处理确认逻辑
+ },
+ },
+ onLoad(options) {
+ these = this;
+ mq = MqTool.getMqTool();
+ if(mq){
+ mq.init();
}
+ const eventChannel = this.getOpenerEventChannel();
+ // 监听 'deviceSend' 事件,获取传过来的数据
+ eventChannel.on('deviceSend', (data) => {
+ console.log('Received detail data:', data);
+ this.sendInfo = data.data
+ this.downCallback();
+ });
+ // 如果需要向调用页面返回数据,可以触发 'ack' 事件
+ eventChannel.emit('ack', {});
+
+ this.getSystemInfoSyncH();
},
- onPopupConfirm() {
- this.showPopupFlag = false
- uni.navigateBack()
- console.log('用户点击了确定')
- // 处理确认逻辑
- },
- },
- onLoad(options) {
- these=this;
- const eventChannel = this.getOpenerEventChannel();
- // 监听 'deviceSend' 事件,获取传过来的数据
- eventChannel.on('deviceSend', (data) => {
- console.log('Received detail data:', data);
-
- this.sendInfo = data.data
- this.downCallback();
- });
- // 如果需要向调用页面返回数据,可以触发 'ack' 事件
- eventChannel.emit('ack', {});
-
- this.getSystemInfoSyncH();
- },
- onUnload() {
- clearTimeout(timer);
- }
+ onUnload() {
+ clearTimeout(timer);
+ if (mq) {
+ mq.disconnect();
+ }
+ }
}
@@ -566,4 +769,11 @@
.device-card[data-offline="true"] {
opacity: 0.6;
}
+
+ .TextToHex {
+ position: fixed;
+ top: -99999rpx;
+ left: -99999rpx;
+ visibility: hidden;
+ }
\ No newline at end of file