1
0
forked from dyf/APP

完成008A功能开发

This commit is contained in:
liub
2026-05-19 17:38:56 +08:00
parent 6d9df4c945
commit 8f53a45280
63 changed files with 4162 additions and 766 deletions

View File

@ -73,15 +73,15 @@ class BleHelper {
},
{
key: '10001',
remark: '当前蓝牙适配器不可用'
remark: '当前蓝牙适配器不可用,请打开手机蓝牙'
},
{
key: '10002',
remark: '没有找到指定设备'
remark: '没有找到指定设备,设备不在信号范围或被他人连接'
},
{
key: '10003',
remark: '蓝牙设备连接失败'
remark: '蓝牙设备连接失败,请重试'
},
{
key: '10004',
@ -101,7 +101,7 @@ class BleHelper {
},
{
key: '10008',
remark: '其余所有系统上报的异常'
remark: '系统错误,请重试'
},
{
key: '10009',
@ -122,7 +122,7 @@ class BleHelper {
{
key: '10013',
remark: '连接 deviceId 为空或者是格式不正确'
},
},
{
key: '10016',
remark: '定位服务已关闭'
@ -1667,7 +1667,7 @@ class BleHelper {
console.log("当前已连接,释放连接锁");
delete this.data.connectingDevices[deviceId];
resolve(false);
LinkedCallback();
return;
}
@ -1689,7 +1689,7 @@ class BleHelper {
delete this.data.connectingDevices[deviceId];
console.error("新连接成功释放连接锁", deviceId);
LinkedCallback();
// 处理 MTU 设置
if (plus.os.name === 'Android') {
this.setMtu(deviceId).catch(ex => {
@ -1703,6 +1703,7 @@ class BleHelper {
if (c.deviceId == deviceId) {
c.Linked = true;
c.linkId = linkId
return true;
}
return false;
@ -1710,8 +1711,9 @@ class BleHelper {
if (fIndex > -1) {
this.data.LinkedList[fIndex].Linked = true;
this.data.LinkedList[fIndex].linkId =
linkId;
this.data.LinkedList[fIndex].linkId =linkId;
this.data.LinkedList[fIndex].name =cr.name;
this.data.LinkedList[fIndex].advertisData =cr.advertisData;
} else {
this.data.LinkedList.push(cr);
}
@ -1725,12 +1727,7 @@ class BleHelper {
return true;
}
})
// console.log("LinkedList=", this.data
// .LinkedList);
resolve(true);
}).catch((ex) => {
@ -1738,6 +1735,12 @@ class BleHelper {
});
},
fail: (ex) => {
if(ex.code===10010){
console.log("设备已连接,无需重复连接");
delete this.data.connectingDevices[deviceId];
resolve(true);
return;
}
ex = this.getError(ex);
console.error("蓝牙" + deviceId + "连接失败" + JSON.stringify(
ex));
@ -1772,7 +1775,7 @@ class BleHelper {
console.log("2222222");
return linkDevice(deviceId);
}).then((res) => {
LinkedCallback();
if (res) { //新连接(含 createBLEConnection 刚成功)
// console.log("11111111");
if (fIndex == -1) {
@ -1780,11 +1783,19 @@ class BleHelper {
return this.getService(deviceId, targetServiceId, writeCharId,
notifyCharId); //获取服务
} else {
// 设备已在 LinkedList例如缓存/重连):不能仅用缓存的 write/notify UUID 直接订阅。
// 重连后须先 getBLEDeviceServices否则部分机型 notifyBLECharacteristicValueChange 报 no service(10004)notify 收不到任何数据。
console.log("已缓存设备重新连接,重新发现服务并订阅", deviceId);
return this.getService(deviceId, targetServiceId, writeCharId,
notifyCharId);
if (f.wirteCharactId && f.notifyCharactId) {
if (!f.notifyState) {
// console.log("开始订阅特征");
this.subScribe(deviceId, true);
} else {
console.log("不订阅消息");
}
return Promise.resolve(true);
} else {
console.log("开始获取服务", targetServiceId)
return this.getService(deviceId, targetServiceId, writeCharId,
notifyCharId);
}
}
} else { //已连接过,直接订阅消息
// console.log("11111111");

View File

@ -11,12 +11,15 @@ import {
MsgClear,
MsgInfo
} from '@/utils/MsgPops.js';
import MqPlus from '@/utils/MqPlus.js';
var mqcommon = null;
const homePath = 'pages/common/index'
class BleReceive {
constructor(_ref) {
if(_ref && !this.ref){
this.ref = _ref;
}
if (_ref && !this.ref) {
this.ref = _ref;
}
this.StorageKey = "linkedDevices";
this.HandlerMap = {
'/pages/6155/deviceDetail': this.Receive_6155.bind(this),
@ -30,10 +33,10 @@ class BleReceive {
'/pages/6170/deviceControl/index': this.Receive_6170.bind(this),
'/pages/100J/HBY100-J': this.Receive_100J.bind(this),
'/pages/6075J/BJQ6075J': this.Receive_6075.bind(this),
'/pages/210/HBY210':this.Receive_210.bind(this),
'/pages/018A/HBY018A':this.Receive_018A.bind(this)
'/pages/210/HBY210': this.Receive_210.bind(this),
'/pages/018A/HBY018A': this.Receive_018A.bind(this)
};
mqcommon = MqPlus.getMqPlus();
}
@ -213,7 +216,7 @@ class BleReceive {
msg.push("设备'" + f.device.deviceName + "'环境存在漏电电源");
}
if (this.ref && msg.length>0) {
if (this.ref && msg.length > 0) {
if (msg.length > 0) {
msg = msg.join(',');
MsgError("'" + f.device.deviceName + "'环境存在漏电电源", '', this.ref, () => {
@ -222,8 +225,6 @@ class BleReceive {
}
}
}
}
return formData;
} catch (error) {
@ -289,6 +290,13 @@ class BleReceive {
let data = parseData(receive.bytes);
console.log("data=", data);
if (f && f.device && mqcommon && path == homePath) {
if (data.battary) {
mqcommon.sendCharge(f.device.id, 1, data.battary);
}
}
return data;
}
@ -373,7 +381,7 @@ class BleReceive {
msgs.push("静止报警中");
}
if (receiveData.battary <= 20) {
msg.push("设备'" + f.device.deviceName + "'电量低");
msgs.push("设备'" + f.device.deviceName + "'电量低");
}
if (msgs.length > 0) {
msgs = msgs.join(";");
@ -461,7 +469,9 @@ class BleReceive {
let data = todo(receive.bytes);
if (f && f.device && mqcommon && path == homePath) {
mqcommon.sendCharge(f.device.id, 1);
}
return data;
}
@ -503,11 +513,18 @@ class BleReceive {
//充电状态
let chargeType = 1;
let warn = bytes[5];
if (warn == 0x00) {
warn = '未充电';
chargeType = 1;
} else if (warn == 0x01) {
warn = '充电中';
chargeType = 0;
}
if (f && f.device && mqcommon && path == homePath) {
mqcommon.sendCharge(f.device.id, chargeType);
}
// 解析剩余照明时间(第三和第四字节,小端序)
@ -604,13 +621,17 @@ class BleReceive {
//充电状态
let chargeType = 1;
let warn = bytes[5];
if (warn == 0x00) {
warn = '未充电';
} else if (warn == 0x01) {
warn = '充电中';
chargeType = 0;
}
if (f && f.device && mqcommon && path == homePath) {
mqcommon.sendCharge(f.device.id, chargeType);
}
// 解析剩余照明时间(第三和第四字节,小端序)
let lightingTime = "";
let HH = Math.max(0, Math.min(100, bytes[6]));
@ -633,7 +654,7 @@ class BleReceive {
});
console.log("formData=",formData)
console.log("formData=", formData)
if (!recCnt) {
console.log("11111");
if (formData.battary <= 20 && bytes[5] == 0x00) {
@ -682,6 +703,10 @@ class BleReceive {
} catch (error) {
receiveData = {};
console.log("文本解析失败", error)
} finally {
if (f && f.device && mqcommon && receiveData.sta_PowerPercent && path == homePath) {
mqcommon.sendCharge(f.device.id, 1, receiveData.sta_PowerPercent);
}
}
return receiveData;
@ -699,6 +724,14 @@ class BleReceive {
return v.key.replace(/\//g, "").toLowerCase() == f.device.detailPageUrl
.replace(/\//g, "").toLowerCase();
});
let chargeType = 1;
if (receiveData.sta_system == '1' || receiveData.sta_system == '3') {
chargeType = 0;
}
if (f && f.device && mqcommon && path == homePath) {
mqcommon.sendCharge(f.device.id, chargeType);
}
if (!recCnt) {
if (receiveData.sta_battery <= 20 && (receiveData.sta_system != '1' || receiveData.sta_system !=
'3')) {
@ -748,14 +781,16 @@ class BleReceive {
// console.log("设备收到消息:", f);
// console.log("消息内容:", receive);
receiveData = JSON.parse(receive.str);
let deviceState = receiveData.state;
let recCnt = recArr.find(v => {
return v.key.replace(/\//g, "").toLowerCase() == f.device.detailPageUrl
.replace(/\//g, "").toLowerCase();
});
if (!recCnt) {
let deviceState = receiveData.state;
if (deviceState && deviceState instanceof Array) {
if (deviceState && deviceState instanceof Array) {
let recCnt = recArr.find(v => {
return v.key.replace(/\//g, "").toLowerCase() == f.device.detailPageUrl
.replace(/\//g, "").toLowerCase();
});
if (!recCnt) {
if (deviceState[0] == 12 && deviceState[3] <= 20 && deviceState[4] == 0) {
if (this.ref) {
MsgError("设备'" + f.device.deviceName + "'电量低", '', this.ref, () => {
@ -764,14 +799,34 @@ class BleReceive {
}
}
}
if (f && f.device && mqcommon && path == homePath) {
if (deviceState[0] == 12) {
let chargeType = 1;
if (deviceState[4] == 0) {
chargeType = 1;
} else {
chargeType = 0;
}
mqcommon.sendCharge(f.device.id, chargeType);
} else {
mqcommon.sendCharge(f.device.id, 1);
}
}
}
} catch (error) {
receiveData = {};
console.error("文本解析失败", error)
console.error("错误数据:",receive);
console.error("错误数据:", receive);
}
return receiveData;
@ -790,6 +845,19 @@ class BleReceive {
return v.key.replace(/\//g, "").toLowerCase() == f.device.detailPageUrl
.replace(/\//g, "").toLowerCase();
});
if (f && f.device && mqcommon && path == homePath) {
let chargeType = 1;
if (receiveData.sta_charge == 0) {
chargeType = 1;
} else {
chargeType = 0;
}
mqcommon.sendCharge(f.device.id, chargeType);
}
if (!recCnt) {
let msgs = [];
@ -800,9 +868,9 @@ class BleReceive {
if (receiveData.sta_Intrusion === 1) {
msgs.push("设备'" + f.device.deviceName + "'闯入报警中");
}
if (this.ref && msg.length>0) {
if (this.ref && msgs.length > 0) {
msgs = msgs.join(",");
MsgError(msgs, '', this.ref, () => {
MsgClear(this.ref);
@ -814,7 +882,6 @@ class BleReceive {
if (f.device && path === "pages/common/index") { //仅在首页订阅此操作
console.error("1111111111");
let linkKey = "102_" + f.device.id + "_linked";
let warnKey = "102_" + f.device.id + "_warning";
let time = new Date(); //Common.DateFormat(new Date(),'yyyy-MM-dd HH:mmss');
@ -954,17 +1021,29 @@ class BleReceive {
receiveData = JSON.parse(receive.str);
if (f && f.device && mqcommon && path == homePath) {
let chargeType = 1;
if (receiveData.sta_system != 3 || receiveData.sta_system != 1) {
chargeType = 1;
} else {
chargeType = 0;
}
mqcommon.sendCharge(f.device.id, chargeType);
}
let recCnt = recArr.find(v => {
return v.key.replace(/\//g, "").toLowerCase() == f.device.detailPageUrl
.replace(/\//g, "").toLowerCase();
});
if (!recCnt && this.ref) {
if (receiveData.sta_PowerPercent <= 20 && (receiveData.sta_system != 3 || receiveData.sta_system !=1)) {
MsgError("设备'" + f.device.deviceName + "'电量低", '', this.ref, () => {
MsgClear(this.ref);
});
if (receiveData.sta_PowerPercent <= 20 && (receiveData.sta_system != 3 || receiveData.sta_system !=
1)) {
MsgError("设备'" + f.device.deviceName + "'电量低", '', this.ref, () => {
MsgClear(this.ref);
});
}
}
@ -977,33 +1056,47 @@ class BleReceive {
}
Receive_018A(receive, f, path, recArr) {
let receiveData = {};
try {
receiveData = JSON.parse(receive.str);
if (f && f.device && mqcommon && path == homePath) {
let chargeType = 1;
if (receiveData.sta_system != 3 || receiveData.sta_system != 1) {
chargeType = 1;
} else {
chargeType = 0;
}
mqcommon.sendCharge(f.device.id, chargeType);
}
let recCnt = recArr.find(v => {
return v.key.replace(/\//g, "").toLowerCase() == f.device.detailPageUrl
.replace(/\//g, "").toLowerCase();
});
if (!recCnt && this.ref) {
if (receiveData.sta_PowerPercent <= 20 && (receiveData.sta_system != 3 || receiveData.sta_system !=1)) {
MsgError("设备'" + f.device.deviceName + "'电量低", '', this.ref, () => {
MsgClear(this.ref);
});
if (receiveData.sta_PowerPercent <= 20 && (receiveData.sta_system != 3 || receiveData.sta_system !=
1)) {
MsgError("设备'" + f.device.deviceName + "'电量低", '', this.ref, () => {
MsgClear(this.ref);
});
}
}
} catch (error) {
receiveData = {};
console.log("文本解析失败", error)
}
return receiveData;
}
Receive_210(receive, f, path, recArr) {
let receiveData = {};
@ -1011,17 +1104,27 @@ class BleReceive {
receiveData = JSON.parse(receive.str);
if (f && f.device && mqcommon && path == homePath) {
let chargeType = 1;
if (receiveData.sta_system != 3 || receiveData.sta_system != 1) {
chargeType = 1;
} else {
chargeType = 0;
}
mqcommon.sendCharge(f.device.id, chargeType);
}
let recCnt = recArr.find(v => {
return v.key.replace(/\//g, "").toLowerCase() == f.device.detailPageUrl
.replace(/\//g, "").toLowerCase();
});
if (!recCnt && this.ref) {
if (receiveData.sta_PowerPercent <= 20 && (receiveData.sta_system != 3 || receiveData.sta_system !=1)) {
MsgError("设备'" + f.device.deviceName + "'电量低", '', this.ref, () => {
MsgClear(this.ref);
});
if (receiveData.sta_PowerPercent <= 20 && (receiveData.sta_system != 3 || receiveData.sta_system !=
1)) {
MsgError("设备'" + f.device.deviceName + "'电量低", '', this.ref, () => {
MsgClear(this.ref);
});
}
}

View File

@ -218,7 +218,7 @@ export default {
value: "1",
label: "灯光模式",
checked: false,
type: ['6170', '670', '102', '6155', '650', '7305', '6075']
type: ['6170', '670', '102', '6155', '650', '7305', '6075','008A','018A']
},
{
value: "2",
@ -340,7 +340,7 @@ export default {
value: "55",
label: "修改信道",
checked: false,
type: ['4877', '102']
type: ['4877', '102','008A']
},
{
value: "56",

91
utils/MqPlus.js Normal file
View File

@ -0,0 +1,91 @@
import MqttClient from '@/utils/mqtt.js';
class MqPlus {
constructor() {
this.mq = null;
this.init();
}
init(callback) {
this.mq = new MqttClient();
this.mq.connect(() => {
console.log("连接成功");
if(callback){
callback();
}
});
}
//通用发送消息
sendData(topic, payload) {
let task=()=>{
if (payload === undefined || payload === null) {
console.error("消息内容为空")
return false;
}
if (typeof payload === 'object') {
payload = JSON.stringify(payload);
}
this.mq.publish(topic, payload);
}
if(!this.mq){
this.init(task)
}else{
task();
}
}
//发送手机号登陆与推送数据
sendUsrLogin() {
if(!this.mq){
return
}
let pushid=uni.getStorageSync("push_cid");
let phone=uni.getStorageSync("phone");
this.sendData("app/login",{phone:phone,pushid:pushid});
}
//发送充放电数据,chargeType1放电0充电
sendCharge(deviceid,chargeType,battary){
if(!this.mq){
return;
}
let json={
deviceid:deviceid,
sta_system:chargeType,
}
if(battary!==undefined){
json.battary=battary;
}
this.sendData("app/charge",json);
}
//发送报警
sendWarning(deviceid,warn){
if(!this.mq){
return;
}
let json={
deviceid:deviceid,
sta_ShakeBit:warn,
}
this.sendData("app/warn",json);
}
}
let mqplusInstance = null;
export default {
getMqPlus: function() {
if (!mqplusInstance) {
mqplusInstance = new MqPlus();
}
return mqplusInstance;
}
}

View File

@ -7,7 +7,7 @@ var MsgType = {
}
var time = null;
// 显示成功
export const MsgSuccess = (msg, btnTxt, ev,tapCallback) => {
export const MsgSuccess = (msg, btnTxt, ev,tapCallback,showCancel) => {
if (!ev) {
@ -17,13 +17,13 @@ export const MsgSuccess = (msg, btnTxt, ev,tapCallback) => {
return null;
}
let option = ev.$refs.msgPop.showMsg(msg, btnTxt, MsgType.succ,tapCallback);
let option = ev.$refs.msgPop.showMsg(msg, btnTxt, MsgType.succ,tapCallback,showCancel);
createClear(ev);
return option;
}
//显示失败
export const MsgError = (msg, btnTxt, ev,tapCallback) => {
export const MsgError = (msg, btnTxt, ev,tapCallback,showCancel) => {
if (!ev) {
@ -34,12 +34,12 @@ export const MsgError = (msg, btnTxt, ev,tapCallback) => {
return null;
}
let option = ev.$refs.msgPop.showMsg(msg, btnTxt, MsgType.error,tapCallback);
let option = ev.$refs.msgPop.showMsg(msg, btnTxt, MsgType.error,tapCallback,showCancel);
createClear(ev);
return option;
}
//显示警告
export const MsgWarning = (msg, btnTxt, ev, isClear,tapCallback) => {
export const MsgWarning = (msg, btnTxt, ev, isClear,tapCallback,showCancel) => {
if (!ev) {
return null;
@ -48,7 +48,7 @@ export const MsgWarning = (msg, btnTxt, ev, isClear,tapCallback) => {
return null;
}
let option = ev.$refs.msgPop.showMsg(msg, btnTxt, MsgType.warn,tapCallback);
let option = ev.$refs.msgPop.showMsg(msg, btnTxt, MsgType.warn,tapCallback,showCancel);
if (isClear === undefined || isClear) {
createClear(ev);
}
@ -58,7 +58,7 @@ export const MsgWarning = (msg, btnTxt, ev, isClear,tapCallback) => {
}
//显示警告
export const MsgInfo = (msg, btnTxt, ev, isClear,btnCallback) => {
export const MsgInfo = (msg, btnTxt, ev, isClear,btnCallback,showCancel) => {
if (!ev) {
return null;
@ -67,7 +67,7 @@ export const MsgInfo = (msg, btnTxt, ev, isClear,btnCallback) => {
return null;
}
let option = ev.$refs.msgPop.showMsg(msg, btnTxt, MsgType.info,btnCallback);
let option = ev.$refs.msgPop.showMsg(msg, btnTxt, MsgType.info,btnCallback,showCancel);
if (isClear === undefined || isClear) {
createClear(ev);
}
@ -78,7 +78,7 @@ export const MsgInfo = (msg, btnTxt, ev, isClear,btnCallback) => {
}
//显示捕获窗口,用于自定义弹窗内容
export const MsgPrompt = ( ev,refName, btnCallback,isClear) => {
export const MsgPrompt = ( ev,refName, btnCallback,isClear,showCancel) => {
if (!ev) {
return null;
@ -87,7 +87,7 @@ export const MsgPrompt = ( ev,refName, btnCallback,isClear) => {
return null;
}
let option = ev.$refs[refName].showMsg("", "", MsgType.prompt,btnCallback);
let option = ev.$refs[refName].showMsg("", "", MsgType.prompt,btnCallback,showCancel);
if (isClear === undefined || isClear) {
createClear(ev);
}

View File

@ -16,7 +16,7 @@ import {
} from '@/utils/MsgPops.js';
import Common from '@/utils/Common.js';
import api from '@/api/670/HBY670.js'
import gbk from '@/utils/gbk.js'
class SendBatchData {
@ -28,9 +28,13 @@ class SendBatchData {
this.ble = _ble;
}
//发送开机视频
//发送开机视频1536包
SendVideo(bufferSize) {
const systemInfo = uni.getSystemInfoSync();
const platform = systemInfo.platform;
const isIOS = platform === 'ios';
let these = this.these;
let f = this.f;
let ble = this.ble;
@ -49,7 +53,7 @@ class SendBatchData {
console.log("开始发送分片数据");
return new Promise((resolve, reject) => {
if (f) {
ble.data.voiceUploading=true;
ble.data.voiceUploading = true;
// 总数据包数
var totalPackets = 1536; //36;
@ -64,7 +68,7 @@ class SendBatchData {
const sendNextVideoPacket = () => {
// console.log("准备发送一段数据");
if (currentPacket > totalPackets) {
ble.data.voiceUploading=false;
ble.data.voiceUploading = false;
if (!ReSendNo) {
setTimeout(() => {
@ -76,7 +80,7 @@ class SendBatchData {
}).catch((ex) => {
console.log("出现异常", ex);
});
}, 500);
}, 2000);
}
@ -128,10 +132,10 @@ class SendBatchData {
for (let i = 0; i < packetData.length; i++) {
dataView.setUint8(beginIndex + i, packetData[i]);
dataView.setUint8(beginIndex + i, parseInt(packetData[i], 16));
}
let inteval = 80;
let inteval = isIOS ? 300 : 80;
ble.sendData(f.deviceId, buffer, f.writeServiceId, f
.wirteCharactId, 10).then(() => {
@ -152,7 +156,7 @@ class SendBatchData {
currentPacket);
setTimeout(sendNextVideoPacket, 800);
} else {
ble.data.voiceUploading=false;
ble.data.voiceUploading = false;
hideLoading(these);
showPop({
@ -194,7 +198,7 @@ class SendBatchData {
ble.sendString(f.deviceId, "video transmit start", f
.writeServiceId, f.wirteCharactId).then(res => {
ble.data.voiceUploading=true;
ble.data.voiceUploading = true;
setTimeout(() => {
console.log("握手成功了");
resolve(true);
@ -244,6 +248,8 @@ class SendBatchData {
}
});
});
Promise.all([p1, p2]).then((arr) => {
@ -327,9 +333,7 @@ class SendBatchData {
let duration = res.duration;
// 获取平台信息
const systemInfo = uni.getSystemInfoSync();
const platform = systemInfo.platform;
const isIOS = platform === 'ios';
console.log("平台:", platform, "uni.chooseVideo返回 - 宽度:", width, "高度:", height,
"时长:", duration);
@ -379,7 +383,7 @@ class SendBatchData {
}
//发送图片,
//发送图片,52包
SendImg() {
let these = this.these;
let f = this.f;
@ -558,7 +562,7 @@ class SendBatchData {
});
}
//发送人员信息
//发送人员信息(点阵)
SendUsr(totalRows) {
let these = this.these;
@ -594,14 +598,17 @@ class SendBatchData {
//握手
let holdHand = (hexs, time) => {
return new Promise((resolve, reject) => {
console.log("11111");
these.sendData(hexs, 'ble', "string").then(res => {
ble.sendString(f.deviceId, hexs, null, null, 15).then(res => {
console.log("22222")
setTimeout(() => {
resolve(res)
}, time);
}).catch(ex => {
console.log("33333", ex);
console.error("握手失败")
reject(ex)
});
@ -715,7 +722,7 @@ class SendBatchData {
setTimeout(() => {
Promise.allSettled([holdHand('word transmit start', 2200), drawText()]).then(results => {
if (results[0].status == 'rejected') {
MsgError("与蓝牙设备握手失败,请重试", '', these);
MsgError("与蓝牙设备握手失败,请重试," + results[0].reason, '', these);
setTimeout(() => {
hideLoading(these)
}, 500);
@ -749,11 +756,267 @@ class SendBatchData {
});
}
SendMsg(){
SendMsgByGBK(txts, _mq) {
debugger;
let these = this.these;
let f = this.f;
let ble = this.ble;
let mq = _mq;
if (!these.permissions.includes('5') && these.Status.apiType !== 'listA') {
showPop({
message: '无操作权限',
iconUrl: "/static/images/common/uploadErr.png",
borderColor: "#e034344d",
buttonBgColor: "#E03434",
buttonTextColor: "#FFFFFFde",
okCallback: null,
buttonText: "确定"
}, these)
return;
}
showLoading(these, {
text: "请稍候..."
});
let send = (txt) => {
return mq.publish("B/" + these.device.deviceImei, txt);
}
let curr = 0;
let sendNext = () => {
if (curr >= txts.length) {
hideLoading(these);
MsgSuccess("发送成功", '', these);
return;
}
let txt = txts[curr];
let arr = gbk.encode(txt)
console.log("正在发送:", txt);
let json = {
ins_msg: [curr + 1]
}
let gbkData = gbk.arr2hex(arr);
for (let i = 0; i < gbkData.length; i += 2) {
let value = parseInt(gbkData[i] + "" + gbkData[i + 1], 16);
json.ins_msg.push(value);
}
txt = JSON.stringify(json);
updateLoading(these, {
text: '正在发送' + (curr + 1) + '/' + txts.length
});
if (send(txt)) {
curr++;
setTimeout(sendNext, 200);
} else {
MsgError("发送失败了,请检查网络连接后重试", '', these);
}
}
setTimeout(sendNext, 2200);
}
HoldYouHand(cmd, timeout) {
let these = this.these;
let f = this.f;
let ble = this.ble;
return new Promise((resolve, reject) => {
ble.sendString(f.deviceId, cmd, f
.writeServiceId, f.wirteCharactId).then(res => {
if (timeout) {
setTimeout(() => {
console.log("握手成功了");
resolve(true);
}, timeout);
return;
}
resolve(true);
}).catch(ex => {
reject(ex);
console.error("发送文本‘" + cmd + "’失败");
console.error("ex=", ex);
});
});
}
sendUsrByGBK(textLines, ReSendNo) {
let these = this.these;
let f = this.f;
let ble = this.ble;
if (!these.permissions.includes('4') && these.Status.apiType !== 'listA') {
showPop({
message: '无操作权限',
iconUrl: "/static/images/common/uploadErr.png",
borderColor: "#e034344d",
buttonBgColor: "#E03434",
okCallback: null,
buttonText: "确定"
}, these)
return;
}
showLoading(these, {
text: "请稍候..."
});
var sendText = () => {
// 总数据包数
let totalPackets = textLines.length;
let currentPacket = 1;
// console.log("currentPacket=",currentPacket);
// console.log("ReSendNo=",ReSendNo);
if (ReSendNo) {
totalPackets = ReSendNo;
currentPacket = ReSendNo;
}
// console.log("currentPacket=",currentPacket);
// 发送单个数据包
const sendNextPacket = () => {
if (currentPacket > totalPackets) {
if (!ReSendNo) {
setTimeout(() => {
this.HoldYouHand("transmit complete");
}, 500);
}
showPop({
showPop: true, //是否显示弹窗
popType: 'custom',
bgColor: '#383934bd',
borderColor: '#BBE600',
textColor: '#ffffffde',
buttonBgColor: '#BBE600',
buttonTextColor: '#232323DE',
iconUrl: '/static/images/6155/DeviceDetail/sendSucc.png',
message: '人员信息发送成功',
buttonText: '确定',
clickEvt: 'SendUsr',
visiblePrompt: false,
promptTitle: '',
modelValue: '',
visibleClose: true
}, these);
these.setBleFormData();
let json = {
deviceId: these.device.id,
name: these.formData.name,
position: these.formData.job,
unitName: these.formData.company,
code: these.formData.id
};
api.sendUsr(json)
return;
}
// 获取当前行文字
const text = textLines[currentPacket - 1] || '';
let arr = gbk.encode(text)
let gbkData = gbk.arr2hex(arr);
console.log("正在发送:" + text);
console.log("正在发送:" + arr);
// 构建数据包
const bufferSize = 5 + gbkData.length / 2; // 头部4字节 + 数据部分
const buffer = new ArrayBuffer(bufferSize);
const dataView = new DataView(buffer);
// 填充头部
dataView.setUint8(0, 0x55); // 帧头
dataView.setUint8(1, 0x03); // 帧类型:文字
dataView.setUint8(2, currentPacket.toString(16)); // 包序号
dataView.setUint16(3, text.length, false); // 数据长度
// 填充数据
let index = 0;
for (var i = 0; i < gbkData.length; i += 2) {
let value = parseInt(gbkData[i] + "" + gbkData[i + 1], 16);
console.log("value=", value)
dataView.setUint8(5 + index, value);
index++;
}
// 发送数据包
ble.sendData(f.deviceId, buffer, f.writeServiceId, f.wirteCharactId, 10).then(() => {
// 更新进度
console.log(
`发送文字数据包 ${currentPacket}/${totalPackets}: ${text}`
);
// 发送下一个包
currentPacket++;
setTimeout(sendNextPacket, 80);
}).catch(err => {
showPop({
message: "文字发送失败," + err.msg,
iconUrl: "/static/images/common/uploadErr.png",
borderColor: "#e034344d",
buttonBgColor: "#E03434",
}, these);
}).finally(() => {
hideLoading(these);
});
};
// 开始发送第一个包
sendNextPacket();
}
if (ReSendNo) {
sendText(ReSendNo);
return;
}
setTimeout(() => {
this.HoldYouHand("word transmit start", 120).then(
() => {
setTimeout(sendText, 200);
}).catch((ex) => {
console.log("握手没有成功", ex);
hideLoading(these);
showPop({
message: ex.msg,
iconUrl: "/static/images/common/uploadErr.png",
borderColor: "#e034344d",
buttonBgColor: "#E03434",
}, these);
});
}, 0);
}
}
export default SendBatchData;

View File

@ -148,6 +148,7 @@ class MqttClient {
this.options.clientId
);
this.setCallbacks();
}
setCallbacks() {