批量报警、批量发送消息,多个供应商的协议作区分
This commit is contained in:
@ -72,8 +72,10 @@
|
|||||||
|
|
||||||
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 MqTool from '@/utils/MqHelper.js';
|
||||||
var timeout = null;
|
var timeout = null;
|
||||||
var these = null;
|
var these = null;
|
||||||
|
var mq=null;
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
CustomPopup,
|
CustomPopup,
|
||||||
@ -94,13 +96,28 @@
|
|||||||
alarmApiMapping: [{
|
alarmApiMapping: [{
|
||||||
type: ['HBY100-J'],
|
type: ['HBY100-J'],
|
||||||
sendApi: deviceForceAlarmActivation,
|
sendApi: deviceForceAlarmActivation,
|
||||||
statusTypeName: 'FunctionAccessBatchStatusRule_BJQ100J'
|
statusTypeName: 'FunctionAccessBatchStatusRule_BJQ100J',
|
||||||
|
sendType: 'FYSSend'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: ['BJQ6170'],
|
type: ['BJQ6170'],
|
||||||
sendApi: deviceSendAlarmMessage,
|
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,
|
loading: false,
|
||||||
@ -132,19 +149,20 @@
|
|||||||
currentApiConfig() {
|
currentApiConfig() {
|
||||||
const currentTypeName = this.sendInfo.typeName || '';
|
const currentTypeName = this.sendInfo.typeName || '';
|
||||||
// 匹配到则用对应配置,匹配不到用默认配置
|
// 匹配到则用对应配置,匹配不到用默认配置
|
||||||
let f= this.dic.alarmApiMapping.find(v=>{
|
let f = this.dic.alarmApiMapping.find(v => {
|
||||||
return v.type.indexOf(currentTypeName)>-1;
|
return v.type.indexOf(currentTypeName) > -1;
|
||||||
});
|
});
|
||||||
if(f){
|
if (f) {
|
||||||
return f;
|
return f;
|
||||||
}else{
|
} else {
|
||||||
return {
|
return {
|
||||||
sendApi: deviceDefaultAlarm,
|
sendApi: deviceDefaultAlarm,
|
||||||
statusTypeName: 'FunctionAccessBatchStatusRule_Default'
|
statusTypeName: 'FunctionAccessBatchStatusRule_Default',
|
||||||
|
sendType:'FYSSend'
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
@ -189,12 +207,12 @@
|
|||||||
selectAll() {
|
selectAll() {
|
||||||
console.log('123');
|
console.log('123');
|
||||||
// 仅对在线设备进行全选/取消
|
// 仅对在线设备进行全选/取消
|
||||||
const allSelected = this.deviceList.every(item => item.checked);
|
const allSelected = this.deviceList.every(item => item.checked);
|
||||||
this.deviceList.forEach(item => {
|
this.deviceList.forEach(item => {
|
||||||
// 离线设备不修改checked状态
|
// 离线设备不修改checked状态
|
||||||
|
|
||||||
item.checked = !allSelected;
|
item.checked = !allSelected;
|
||||||
|
|
||||||
});
|
});
|
||||||
this.$forceUpdate();
|
this.$forceUpdate();
|
||||||
},
|
},
|
||||||
@ -205,7 +223,7 @@
|
|||||||
console.log(deviceType, 'deviceTypedeviceType');
|
console.log(deviceType, 'deviceTypedeviceType');
|
||||||
this.loading = true;
|
this.loading = true;
|
||||||
let data = {
|
let data = {
|
||||||
pageNum: 1,
|
pageNum: this.mescroll?this.mescroll.num:1,
|
||||||
pageSize: 50,
|
pageSize: 50,
|
||||||
deviceType: deviceType
|
deviceType: deviceType
|
||||||
}
|
}
|
||||||
@ -217,11 +235,16 @@
|
|||||||
checked: false
|
checked: false
|
||||||
}));
|
}));
|
||||||
this.total = res.total;
|
this.total = res.total;
|
||||||
this.deviceList = newDevices;
|
|
||||||
|
if(data.pageNum===1){
|
||||||
|
this.deviceList = newDevices;
|
||||||
|
}else{
|
||||||
|
this.deviceList =this.deviceList.concat(newDevices);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
let hasNext = true;
|
let hasNext = true;
|
||||||
if (res.rows.length < this.size || this.deviceList.length >= this
|
if (res.rows.length < data.pageSize || this.deviceList.length >= this.total) {
|
||||||
.total) {
|
|
||||||
hasNext = false;
|
hasNext = false;
|
||||||
} else {
|
} else {
|
||||||
hasNext = true;
|
hasNext = true;
|
||||||
@ -271,7 +294,7 @@
|
|||||||
this.pendingAlarmAction = 0
|
this.pendingAlarmAction = 0
|
||||||
},
|
},
|
||||||
//动态调用对应接口
|
//动态调用对应接口
|
||||||
async sendAlarmCommand() {
|
sendAlarmCommand() {
|
||||||
const selectedDevices = this.deviceList.filter(item => item.checked);
|
const selectedDevices = this.deviceList.filter(item => item.checked);
|
||||||
const deviceIds = selectedDevices.map(item => item.id);
|
const deviceIds = selectedDevices.map(item => item.id);
|
||||||
const deviceImeiList = selectedDevices.map(item => item.deviceImei);
|
const deviceImeiList = selectedDevices.map(item => item.deviceImei);
|
||||||
@ -291,34 +314,78 @@
|
|||||||
// 获取当前typeName对应的接口和参数配置
|
// 获取当前typeName对应的接口和参数配置
|
||||||
const {
|
const {
|
||||||
sendApi,
|
sendApi,
|
||||||
statusTypeName
|
statusTypeName,
|
||||||
|
sendType
|
||||||
} = this.currentApiConfig;
|
} = this.currentApiConfig;
|
||||||
// 准备请求数据
|
|
||||||
// const batchId = generateShortId();
|
//FYS的方法
|
||||||
const requestData = {
|
let FYSSend = async () => {
|
||||||
deviceIds: deviceIds,
|
const requestData = {
|
||||||
typeName: this.sendInfo.typeName,
|
deviceIds: deviceIds,
|
||||||
deviceImeiList: deviceImeiList,
|
typeName: this.sendInfo.typeName,
|
||||||
// batchId: batchId,
|
deviceImeiList: deviceImeiList,
|
||||||
voiceStrobeAlarm: this.pendingAlarmAction == 1 ? '1' : '0'
|
// batchId: batchId,
|
||||||
};
|
voiceStrobeAlarm: this.pendingAlarmAction == 1 ? '1' : '0'
|
||||||
// 动态调用匹配的接口
|
};
|
||||||
const registerRes = await sendApi(requestData);
|
// 动态调用匹配的接口
|
||||||
if (registerRes.code == 200) {
|
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({
|
uni.showToast({
|
||||||
title: isAlarming ? '强制报警开启成功' : '报警已解除',
|
title: isAlarming ? '强制报警开启成功' : '报警已解除',
|
||||||
icon: 'success'
|
icon: 'success'
|
||||||
});
|
});
|
||||||
this.showPopupFlag = false
|
this.showPopupFlag = false
|
||||||
uni.$emit('deviceStatusUpdate', {});
|
}
|
||||||
setTimeout(() => {
|
//统一通信协议方法
|
||||||
uni.navigateBack()
|
let CommonSend = () => {
|
||||||
}, 500)
|
let json=JSON.stringify({ins_ShakeBit:1});
|
||||||
} else {
|
for (let i = 0; i < deviceImeiList.length; i++) {
|
||||||
|
let imei = deviceImeiList[i];
|
||||||
|
mq.sendData("B/"+imei,json,false);
|
||||||
|
}
|
||||||
|
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
title: registerRes.msg || '状态查询失败',
|
title: isAlarming ? '强制报警开启成功' : '报警已解除',
|
||||||
icon: 'none'
|
icon: 'success'
|
||||||
});
|
});
|
||||||
|
this.showPopupFlag = false
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (sendType) {
|
||||||
|
case "FYSSend":
|
||||||
|
FYSSend();
|
||||||
|
break;
|
||||||
|
case "XSSend":
|
||||||
|
XSSend();
|
||||||
|
break;
|
||||||
|
case "CommonSend":
|
||||||
|
CommonSend();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@ -336,8 +403,18 @@
|
|||||||
this.sendAlarmCommand(this.popupType);
|
this.sendAlarmCommand(this.popupType);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
onUnload() {
|
||||||
|
if(mq){
|
||||||
|
mq.disconnect();
|
||||||
|
}
|
||||||
|
},
|
||||||
onLoad(options) {
|
onLoad(options) {
|
||||||
these = this;
|
these = this;
|
||||||
|
mq=MqTool.getMqTool();
|
||||||
|
if(mq){
|
||||||
|
mq.init();
|
||||||
|
|
||||||
|
}
|
||||||
const eventChannel = this.getOpenerEventChannel();
|
const eventChannel = this.getOpenerEventChannel();
|
||||||
// 监听 'deviceSend' 事件,获取传过来的数据
|
// 监听 'deviceSend' 事件,获取传过来的数据
|
||||||
eventChannel.on('devicePolice', (data) => {
|
eventChannel.on('devicePolice', (data) => {
|
||||||
|
|||||||
@ -28,21 +28,27 @@
|
|||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</mescroll-uni>
|
</mescroll-uni>
|
||||||
<!-- </scroll-view> -->
|
<!-- </scroll-view> -->
|
||||||
|
|
||||||
<view class="editInfmation">
|
<view class="editInfmation">
|
||||||
<view class="ql-editor">编辑信息</view>
|
<view class="ql-editor">编辑信息</view>
|
||||||
<view class="ql-input">
|
<view class="ql-input">
|
||||||
<textarea placeholder-style="color:rgba(255, 255, 255, 0.4)" placeholder="请输入内容" class="textarea"
|
<textarea placeholder-style="color:rgba(255, 255, 255, 0.4)" placeholder="请输入内容" class="textarea"
|
||||||
v-model="messageToSend" :maxlength="20" />
|
v-model="messageToSend" :maxlength="20" />
|
||||||
</view>
|
<TextToHexV1 class="TextToHex" ref="textToHex" :txts="textLines" :bgColor="'#FFFFFF'"
|
||||||
<button class="login-btn" @click.stop="sendTextMessage">发送</button>
|
:color="'#000000'" :fontSize="16" />
|
||||||
</view>
|
</view>
|
||||||
|
<button class="login-btn" @click.stop="sendTextMessage">发送</button>
|
||||||
|
</view>
|
||||||
<!-- 成功提示弹框 -->
|
<!-- 成功提示弹框 -->
|
||||||
<CustomPopup :show="showPopupFlag" :title="popupTitle" :message="popupMessage"
|
<CustomPopup :show="showPopupFlag" :title="popupTitle" :message="popupMessage"
|
||||||
icon="/static/images/common/sendSucc.png" :confirm-text="popupConfirmText" :show-cancel="false"
|
icon="/static/images/common/sendSucc.png" :confirm-text="popupConfirmText" :show-cancel="false"
|
||||||
@confirm="onPopupConfirm" />
|
@confirm="onPopupConfirm" />
|
||||||
|
|
||||||
|
<MsgBox ref="msgPop" />
|
||||||
|
<global-loading ref="loading" />
|
||||||
|
|
||||||
</view>
|
</view>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@ -60,13 +66,30 @@
|
|||||||
getdeviceSTatus
|
getdeviceSTatus
|
||||||
} from '@/utils/function.js';
|
} from '@/utils/function.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 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 mq = null;
|
||||||
var these=null;
|
var timer = null;
|
||||||
|
var these = null;
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
CustomPopup,
|
CustomPopup,
|
||||||
MescrollUni
|
MescrollUni,
|
||||||
|
TextToHexV1
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
@ -95,16 +118,17 @@
|
|||||||
textNoMore: '没有更多数据了'
|
textNoMore: '没有更多数据了'
|
||||||
},
|
},
|
||||||
mescrollHeight: 0,
|
mescrollHeight: 0,
|
||||||
|
textLines:[]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
getSystemInfoSyncH() {
|
getSystemInfoSyncH() {
|
||||||
|
|
||||||
let sysInfo = uni.getSystemInfoSync();
|
let sysInfo = uni.getSystemInfoSync();
|
||||||
|
|
||||||
// 底部 footer 高度约 220rpx + 120rpx = 340rpx,转换为 px(1rpx = sysInfo.pixelRatio / 750 * 屏幕宽度?不,直接用 rpx 转 px 公式)
|
// 底部 footer 高度约 220rpx + 120rpx = 340rpx,转换为 px(1rpx = sysInfo.pixelRatio / 750 * 屏幕宽度?不,直接用 rpx 转 px 公式)
|
||||||
let footerHeight = 500 * (sysInfo.screenWidth / 750); // rpx 转 px
|
let footerHeight = 500 * (sysInfo.screenWidth / 750); // rpx 转 px
|
||||||
|
|
||||||
// console.log("footerHeight=", footerHeight);
|
// console.log("footerHeight=", footerHeight);
|
||||||
this.mescrollHeight = sysInfo.screenHeight - footerHeight;
|
this.mescrollHeight = sysInfo.screenHeight - footerHeight;
|
||||||
// console.log("mescrollHeight=", this.mescrollHeight);
|
// console.log("mescrollHeight=", this.mescrollHeight);
|
||||||
@ -114,21 +138,21 @@
|
|||||||
},
|
},
|
||||||
// 下拉刷新
|
// 下拉刷新
|
||||||
downCallback() {
|
downCallback() {
|
||||||
|
|
||||||
console.log("触发下拉刷新");
|
console.log("触发下拉刷新");
|
||||||
if (this.mescroll) {
|
if (this.mescroll) {
|
||||||
this.mescroll.resetUpScroll(false);
|
this.mescroll.resetUpScroll(false);
|
||||||
this.mescroll.scrollTo(0, 0);
|
this.mescroll.scrollTo(0, 0);
|
||||||
}
|
}
|
||||||
this.getData(this.sendInfo.id);
|
this.getData(this.sendInfo.id);
|
||||||
|
|
||||||
|
|
||||||
},
|
},
|
||||||
// 上拉加载
|
// 上拉加载
|
||||||
upCallback() {
|
upCallback() {
|
||||||
console.log("触发上拉加载");
|
console.log("触发上拉加载");
|
||||||
|
|
||||||
|
|
||||||
this.getData(this.sendInfo.id);
|
this.getData(this.sendInfo.id);
|
||||||
},
|
},
|
||||||
// onPullDownRefresh() {
|
// onPullDownRefresh() {
|
||||||
@ -142,11 +166,11 @@
|
|||||||
// 获取设备列表
|
// 获取设备列表
|
||||||
getData(deviceType) {
|
getData(deviceType) {
|
||||||
clearTimeout(timer);
|
clearTimeout(timer);
|
||||||
timer=setTimeout(()=>{
|
timer = setTimeout(() => {
|
||||||
console.log("开始加载第"+(this.mescroll? this.mescroll.num:1)+'页数据')
|
console.log("开始加载第" + (this.mescroll ? this.mescroll.num : 1) + '页数据')
|
||||||
this.loading = true;
|
this.loading = true;
|
||||||
let data = {
|
let data = {
|
||||||
pageNum:this.mescroll? this.mescroll.num:1,
|
pageNum: this.mescroll ? this.mescroll.num : 1,
|
||||||
pageSize: 50,
|
pageSize: 50,
|
||||||
deviceType: deviceType
|
deviceType: deviceType
|
||||||
}
|
}
|
||||||
@ -158,34 +182,38 @@
|
|||||||
checked: false
|
checked: false
|
||||||
}));
|
}));
|
||||||
this.total = res.total;
|
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;
|
this.total = res.total;
|
||||||
// 判断是否加载完成
|
// 判断是否加载完成
|
||||||
let hasNext = true;
|
let hasNext = true;
|
||||||
if (res.rows.length < this.size || this.deviceList.length >= this
|
if (res.rows.length < data.pageSize || this.deviceList.length >= this.total) {
|
||||||
.total) {
|
|
||||||
hasNext = false;
|
hasNext = false;
|
||||||
} else {
|
} else {
|
||||||
hasNext = true;
|
hasNext = true;
|
||||||
}
|
}
|
||||||
this.mescroll.endSuccess(res.rows.length, hasNext);
|
this.mescroll.endSuccess(res.rows.length, hasNext);
|
||||||
}else {
|
} else {
|
||||||
this.mescroll.endSuccess(0, false);
|
this.mescroll.endSuccess(0, false);
|
||||||
}
|
}
|
||||||
}).finally(() => {
|
}).finally(() => {
|
||||||
this.loading = false;
|
this.loading = false;
|
||||||
}).catch(ex=>{
|
}).catch(ex => {
|
||||||
|
|
||||||
this.mescroll.endSuccess(0, false);
|
this.mescroll.endSuccess(0, false);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
},200);
|
}, 200);
|
||||||
|
|
||||||
},
|
},
|
||||||
// 发送文本消息
|
// 发送文本消息
|
||||||
sendTextMessage() {
|
sendTextMessage() {
|
||||||
// 防重复提交
|
// 防重复提交
|
||||||
if (this.isSending) return;
|
if (this.isSending) return;
|
||||||
const selectedDevices = this.deviceList.filter(item => item.checked)
|
const selectedDevices = this.deviceList.filter(item => item.checked)
|
||||||
@ -207,15 +235,15 @@
|
|||||||
}
|
}
|
||||||
this.isSending = true;
|
this.isSending = true;
|
||||||
//FYS的方法
|
//FYS的方法
|
||||||
let FYSSend =async () => {
|
let FYSSend = async () => {
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
uni.showLoading({
|
showLoading(these,{
|
||||||
title: '发送中...',
|
text: '发送中...',
|
||||||
mask: true
|
mask: true
|
||||||
});
|
});
|
||||||
|
|
||||||
// 2. 准备请求数据
|
// 2. 准备请求数据
|
||||||
const batchId = generateShortId();
|
const batchId = generateShortId();
|
||||||
const data = {
|
const data = {
|
||||||
@ -251,51 +279,219 @@
|
|||||||
// 5. 显示成功弹窗
|
// 5. 显示成功弹窗
|
||||||
this.showPopupFlag = true
|
this.showPopupFlag = true
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
uni.showToast({
|
MsgError(error.message,null,these);
|
||||||
title: error.message,
|
|
||||||
icon: 'none'
|
|
||||||
});
|
|
||||||
} finally {
|
} finally {
|
||||||
uni.hideLoading();
|
hideLoading(these);
|
||||||
this.isSending = false;
|
this.isSending = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//XS的方法
|
//XS的方法
|
||||||
let XSSend=() => {
|
let XSSend = () => {
|
||||||
|
|
||||||
|
|
||||||
try {
|
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/','');
|
||||||
|
|
||||||
|
let childData=null;
|
||||||
|
let childIndex=null;
|
||||||
this.showPopupFlag=true;
|
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) {
|
} catch (error) {
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
|
|
||||||
this.isSending = false;
|
this.isSending = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//FS的方法
|
//FS的方法
|
||||||
let FSSend = () => {
|
let FSSend = () => {
|
||||||
|
|
||||||
|
|
||||||
try {
|
this.messageToSend.padEnd(16, ' ').slice(0,16);
|
||||||
|
|
||||||
|
|
||||||
|
this.textLines = [this.messageToSend.slice(0, 8), this.messageToSend.slice(8, 16)];
|
||||||
this.showPopupFlag = true
|
|
||||||
|
|
||||||
} catch (error) {
|
|
||||||
|
showLoading(this, {
|
||||||
} finally {
|
text: "发送中"
|
||||||
|
});
|
||||||
this.isSending = false;
|
//握手
|
||||||
|
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 device = selectedDevices[0];
|
||||||
let sendDic = [{
|
let sendDic = [{
|
||||||
urls: ['/pages/6170/deviceControl/index', '/pages/210/HBY210', '/pages/6075/BJQ6075',
|
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) {
|
let f = sendDic.find(v => {
|
||||||
f.send();
|
return v.urls.indexOf(device.detailPageUrl) > -1;
|
||||||
} else {
|
});
|
||||||
FYSSend();
|
|
||||||
|
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() {
|
onUnload() {
|
||||||
this.showPopupFlag = false
|
clearTimeout(timer);
|
||||||
uni.navigateBack()
|
if (mq) {
|
||||||
console.log('用户点击了确定')
|
mq.disconnect();
|
||||||
// 处理确认逻辑
|
}
|
||||||
},
|
}
|
||||||
},
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@ -566,4 +769,11 @@
|
|||||||
.device-card[data-offline="true"] {
|
.device-card[data-offline="true"] {
|
||||||
opacity: 0.6;
|
opacity: 0.6;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.TextToHex {
|
||||||
|
position: fixed;
|
||||||
|
top: -99999rpx;
|
||||||
|
left: -99999rpx;
|
||||||
|
visibility: hidden;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
Reference in New Issue
Block a user