修改7305人员信息取模组件,文本自动居中
This commit is contained in:
@ -448,9 +448,9 @@ class BleHelper {
|
||||
}
|
||||
|
||||
getError(ex) {
|
||||
|
||||
ex.msg =ex.code+':'+ ex.errMsg;
|
||||
|
||||
|
||||
ex.msg = ex.code + ':' + ex.errMsg;
|
||||
|
||||
let f = this.dic.errRemarks.find((v) => {
|
||||
return v.key == ex.code;
|
||||
});
|
||||
@ -750,10 +750,10 @@ class BleHelper {
|
||||
-1)
|
||||
}
|
||||
}
|
||||
|
||||
let sta_imei=receivJson["sta_imei"];
|
||||
if(sta_imei){
|
||||
v.imei=sta_imei;
|
||||
|
||||
let sta_imei = receivJson["sta_imei"];
|
||||
if (sta_imei) {
|
||||
v.imei = sta_imei;
|
||||
}
|
||||
|
||||
isUpdate = true;
|
||||
@ -1637,7 +1637,7 @@ class BleHelper {
|
||||
if (fIndex > -1) {
|
||||
this.data.LinkedList[fIndex].Linked = true;
|
||||
this.data.LinkedList[fIndex].linkId =
|
||||
linkId;
|
||||
linkId;
|
||||
} else {
|
||||
this.data.LinkedList.push(cr);
|
||||
}
|
||||
@ -1852,7 +1852,7 @@ class BleHelper {
|
||||
|
||||
}
|
||||
//向蓝牙设备发送一个字符串的ASCII码
|
||||
sendString(deviceid, str, writeServiceId, wirteCharactId, ms) {
|
||||
sendString(deviceid, str, writeServiceId, wirteCharactId, ms, iosIsChuck, chunkSize) {
|
||||
if (str && typeof(str) == 'object') {
|
||||
str = JSON.stringify(str);
|
||||
}
|
||||
@ -1876,7 +1876,7 @@ class BleHelper {
|
||||
}
|
||||
|
||||
//向蓝牙设备发送一个16进制的数组数据
|
||||
sendHexs(deviceid, array, writeServiceId, wirteCharactId, ms) {
|
||||
sendHexs(deviceid, array, writeServiceId, wirteCharactId, ms, iosIsChuck, chunkSize) {
|
||||
if (array && array.length) {
|
||||
let bufferSize = array.length;
|
||||
let buffer = new ArrayBuffer(bufferSize);
|
||||
@ -1885,7 +1885,7 @@ class BleHelper {
|
||||
dataView.setUint8(i, array[i]);
|
||||
}
|
||||
|
||||
return this.sendData(deviceid, buffer, writeServiceId, wirteCharactId, ms);
|
||||
return this.sendData(deviceid, buffer, writeServiceId, wirteCharactId, ms, iosIsChuck, chunkSize);
|
||||
|
||||
} else {
|
||||
return Promise.resolve({
|
||||
@ -1896,33 +1896,33 @@ class BleHelper {
|
||||
|
||||
}
|
||||
//向蓝牙设备发送数据,如果没连接将自动连接后再发
|
||||
sendData(deviceid, buffer, writeServiceId, wirteCharactId, ms) {
|
||||
sendData(deviceid, buffer, writeServiceId, wirteCharactId, ms, iosIsChuck, chunkSize) {
|
||||
if (this.data.platform == 'web') {
|
||||
return Promise.resolve("h5平台默认成功");
|
||||
}
|
||||
|
||||
// 打印发送的蓝牙指令
|
||||
let bufferHex = '';
|
||||
if (buffer) {
|
||||
let bytes = [];
|
||||
// 处理不同类型的buffer(ArrayBuffer、Uint8Array等)
|
||||
if (buffer instanceof ArrayBuffer) {
|
||||
let dataView = new DataView(buffer);
|
||||
for (let i = 0; i < buffer.byteLength; i++) {
|
||||
bytes.push(dataView.getUint8(i));
|
||||
}
|
||||
} else if (buffer.byteLength !== undefined) {
|
||||
// 如果是 Uint8Array 或其他类型
|
||||
for (let i = 0; i < buffer.byteLength; i++) {
|
||||
bytes.push(buffer[i] || 0);
|
||||
}
|
||||
} else if (Array.isArray(buffer)) {
|
||||
bytes = buffer;
|
||||
}
|
||||
if (bytes.length > 0) {
|
||||
bufferHex = bytes.map(b => '0x' + b.toString(16).padStart(2, '0').toUpperCase()).join(' ');
|
||||
}
|
||||
}
|
||||
// let bufferHex = '';
|
||||
// if (buffer) {
|
||||
// let bytes = [];
|
||||
// // 处理不同类型的buffer(ArrayBuffer、Uint8Array等)
|
||||
// if (buffer instanceof ArrayBuffer) {
|
||||
// let dataView = new DataView(buffer);
|
||||
// for (let i = 0; i < buffer.byteLength; i++) {
|
||||
// bytes.push(dataView.getUint8(i));
|
||||
// }
|
||||
// } else if (buffer.byteLength !== undefined) {
|
||||
// // 如果是 Uint8Array 或其他类型
|
||||
// for (let i = 0; i < buffer.byteLength; i++) {
|
||||
// bytes.push(buffer[i] || 0);
|
||||
// }
|
||||
// } else if (Array.isArray(buffer)) {
|
||||
// bytes = buffer;
|
||||
// }
|
||||
// if (bytes.length > 0) {
|
||||
// bufferHex = bytes.map(b => '0x' + b.toString(16).padStart(2, '0').toUpperCase()).join(' ');
|
||||
// }
|
||||
// }
|
||||
// console.log("准备发送蓝牙指令 - deviceId:", deviceid, "writeServiceId:", writeServiceId, "writeCharactId:", wirteCharactId);
|
||||
// console.log("发送数据(Hex):", bufferHex || "(空数据)");
|
||||
// console.log("发送数据(原始buffer长度):", buffer ? (buffer.byteLength || buffer.length || 0) : 0);
|
||||
@ -1952,9 +1952,11 @@ class BleHelper {
|
||||
|
||||
|
||||
|
||||
|
||||
let sendBuffer = () => {
|
||||
|
||||
return new Promise(async (resolve, reject) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
let os = plus.os.name;
|
||||
|
||||
var promise = new Promise((succ, err) => {
|
||||
if (!c) {
|
||||
@ -1963,31 +1965,128 @@ class BleHelper {
|
||||
})); //没有找到指定设备
|
||||
return;
|
||||
}
|
||||
// console.log("device=", device);
|
||||
uni.writeBLECharacteristicValue({
|
||||
deviceId: device.deviceId,
|
||||
serviceId: device.writeServiceId,
|
||||
characteristicId: device.wirteCharactId,
|
||||
value: buffer,
|
||||
writeType: 'write',
|
||||
success: () => {
|
||||
console.log("✓ 蓝牙指令发送成功 - deviceId:", device
|
||||
.deviceId);
|
||||
succ();
|
||||
},
|
||||
fail: (ex) => {
|
||||
ex = this.getError(ex);
|
||||
console.error("✗ 蓝牙指令发送失败 - deviceId:", device
|
||||
.deviceId, "错误:", ex);
|
||||
let sendPacket = (data) => {
|
||||
return new Promise((_succ, _err) => {
|
||||
uni.writeBLECharacteristicValue({
|
||||
deviceId: device.deviceId,
|
||||
serviceId: device.writeServiceId,
|
||||
characteristicId: device.wirteCharactId,
|
||||
value: data,
|
||||
writeType: 'write',
|
||||
success: () => {
|
||||
// console.log("✓ 蓝牙指令发送成功 - deviceId:",device.deviceId);
|
||||
_succ();
|
||||
},
|
||||
fail: (ex) => {
|
||||
ex = this.getError(ex);
|
||||
console.error("✗ 蓝牙指令发送失败 - deviceId:",device.deviceId, "错误:", ex);
|
||||
|
||||
err(ex);
|
||||
_err(ex);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
if (os === 'iOS' && iosIsChuck) {
|
||||
console.error("正在分包发送");
|
||||
let splitArrayBuffer = (buffer) => {
|
||||
if (!chunkSize) {
|
||||
chunkSize = 150;
|
||||
}
|
||||
const chunks = [];
|
||||
const uint8Array = new Uint8Array(buffer);
|
||||
|
||||
for (let i = 0; i < uint8Array.length; i += chunkSize) {
|
||||
const end = Math.min(i + chunkSize, uint8Array.length);
|
||||
const chunk = uint8Array.slice(i, end).buffer;
|
||||
chunks.push(chunk);
|
||||
}
|
||||
|
||||
return chunks;
|
||||
}
|
||||
});
|
||||
|
||||
let arrs = splitArrayBuffer(buffer);
|
||||
console.error("分包数量", arrs.length);
|
||||
// 如果数据块数量小于2,直接发送原始数据或第一个数据块
|
||||
if (arrs.length < 2) {
|
||||
return sendPacket(buffer).then(resolve).catch(reject);
|
||||
}
|
||||
|
||||
// 多块数据需要按顺序发送
|
||||
let index = 0;
|
||||
|
||||
const sendNext = () => {
|
||||
return new Promise((_resolve, _reject) => {
|
||||
console.log("正在发送分包" + index);
|
||||
|
||||
if (index >= arrs.length) {
|
||||
return _resolve();
|
||||
}
|
||||
|
||||
|
||||
|
||||
Promise.race([this.timeOut(ms), sendPacket(arrs[
|
||||
index])]).then((
|
||||
result) => {
|
||||
console.log(
|
||||
`✗ 第${index + 1}/${arrs.length}个数据包发送成功`
|
||||
);
|
||||
index++;
|
||||
if (index < arrs.length) {
|
||||
// iOS平台需要延迟发送,避免数据包发送过快
|
||||
return new Promise(resolve1 => {
|
||||
setTimeout(() => {
|
||||
resolve1(
|
||||
sendNext()
|
||||
);
|
||||
},
|
||||
20
|
||||
); // 20ms延迟,可根据需要调整
|
||||
});
|
||||
}
|
||||
_resolve(result);
|
||||
}).catch((ex) => {
|
||||
// console.error("ex=", ex);
|
||||
if (ex.code == -1) {
|
||||
console.log(
|
||||
`✗ 第${index + 1}/${arrs.length}个数据包发送成功`
|
||||
);
|
||||
index++;
|
||||
if (index < arrs.length) {
|
||||
// iOS平台需要延迟发送,避免数据包发送过快
|
||||
return new Promise(resolve1 => {
|
||||
setTimeout(() => {
|
||||
resolve1
|
||||
(
|
||||
sendNext()
|
||||
);
|
||||
},
|
||||
20
|
||||
); // 20ms延迟,可根据需要调整
|
||||
});
|
||||
}
|
||||
_resolve(ex);
|
||||
} else {
|
||||
console.error(
|
||||
`✗ 第${index + 1}/${arrs.length}个数据包发送失败:`,
|
||||
error);
|
||||
_reject(ex);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
};
|
||||
|
||||
return sendNext();
|
||||
} else {
|
||||
|
||||
return sendPacket(buffer).then(resolve).catch(reject);
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
if (plus.os.name == 'iOS') {
|
||||
|
||||
|
||||
|
||||
if (os == 'iOS') {
|
||||
Promise.race([this.timeOut(ms), promise]).then(resolve).catch((ex) => {
|
||||
// console.error("ex=", ex);
|
||||
if (ex.code == -1) {
|
||||
|
||||
Reference in New Issue
Block a user