018A初步完成
This commit is contained in:
@ -651,7 +651,7 @@ class BleHelper {
|
||||
BleReceive() {
|
||||
uni.onBLECharacteristicValueChange((receive) => {
|
||||
//订阅消息
|
||||
// console.log("收到订阅消息", receive);
|
||||
// console.log("收到订阅消息", receive);
|
||||
let f = this.data.LinkedList.find((v) => {
|
||||
return v.deviceId == receive.deviceId;
|
||||
})
|
||||
@ -768,6 +768,7 @@ class BleHelper {
|
||||
} catch (convertException) {
|
||||
if (str && (str.trim().startsWith('{') || str.trim().startsWith('['))) {
|
||||
console.error("JSON解析失败(可能是格式错误的数据)", convertException);
|
||||
console.error("错误的数据", str);
|
||||
}
|
||||
}
|
||||
|
||||
@ -810,6 +811,7 @@ class BleHelper {
|
||||
console.error(
|
||||
"订阅消息出现异常",
|
||||
err);
|
||||
console.error("异常数据:", str);
|
||||
}
|
||||
|
||||
}
|
||||
@ -976,7 +978,10 @@ class BleHelper {
|
||||
if (this.cfg.recoveryCallback.length > 0) {
|
||||
this.cfg.recoveryCallback.forEach(c => {
|
||||
try {
|
||||
c.callback({ deviceId: res.deviceId, connected: true });
|
||||
c.callback({
|
||||
deviceId: res.deviceId,
|
||||
connected: true
|
||||
});
|
||||
} catch (err) {
|
||||
console.error("执行蓝牙恢复连接的回调异常", err);
|
||||
}
|
||||
@ -998,15 +1003,15 @@ class BleHelper {
|
||||
// console.log("发现新设备",item.name+" "+item.RSSI);
|
||||
// }
|
||||
|
||||
let f = serviceDic.find(v => {
|
||||
return item.advertisServiceUUIDs
|
||||
.includes(v.serviceId);
|
||||
});
|
||||
if (f) {
|
||||
let f = serviceDic.find(v => {
|
||||
return item.advertisServiceUUIDs
|
||||
.includes(v.serviceId);
|
||||
});
|
||||
if (f) {
|
||||
|
||||
// console.log("发现目标设备:", item);
|
||||
arr.push(item);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
if (arr.length === 0) {
|
||||
@ -1140,7 +1145,7 @@ class BleHelper {
|
||||
//停止搜索
|
||||
StopSearch() {
|
||||
if (this.data.platform == 'web' || !this.data.discovering) {
|
||||
console.error("web平台或当前没有搜索,直接返回",this.data.discovering);
|
||||
console.error("web平台或当前没有搜索,直接返回", this.data.discovering);
|
||||
return Promise.resolve();
|
||||
}
|
||||
let p1 = new Promise((resolve, reject) => {
|
||||
@ -1575,9 +1580,11 @@ class BleHelper {
|
||||
return Promise.resolve(true);
|
||||
}
|
||||
if (this.data.connectingDevices[deviceId]) {
|
||||
console.error("连接任务进行中,本次连接被阻断")
|
||||
return Promise.resolve(false);
|
||||
}
|
||||
this.data.connectingDevices = true;
|
||||
|
||||
this.data.connectingDevices[deviceId] = true;
|
||||
|
||||
if (maxRetries === undefined) {
|
||||
maxRetries = 0; // 最大重试次数
|
||||
@ -1600,35 +1607,37 @@ class BleHelper {
|
||||
return false;
|
||||
});
|
||||
////console.log("findex=" + fIndex);
|
||||
|
||||
|
||||
var these = this;
|
||||
|
||||
|
||||
//连接设备
|
||||
var linkDevice = () => {
|
||||
// 添加重试次数限制
|
||||
|
||||
let retryCount = 0;
|
||||
|
||||
|
||||
const connect = () => {
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
if (fIndex > -1 && f?.Linked) {
|
||||
// console.log("当前已连接,跳过其他步骤");
|
||||
resolve(false);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (!this.data.available) {
|
||||
reject(this.getError({
|
||||
code: 10001
|
||||
}));
|
||||
return;
|
||||
}
|
||||
|
||||
// console.log("正在连接" + deviceId);
|
||||
|
||||
console.log("正在连接" + deviceId);
|
||||
uni.createBLEConnection({
|
||||
deviceId: deviceId,
|
||||
timeout: 20000,
|
||||
timeout: 10000,
|
||||
success: (info) => {
|
||||
//释放连接锁
|
||||
|
||||
@ -1728,7 +1737,7 @@ class BleHelper {
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
this.OpenBlue().then((res) => {
|
||||
////console.log("2222222");
|
||||
console.log("2222222");
|
||||
return linkDevice(deviceId);
|
||||
}).then((res) => {
|
||||
|
||||
@ -1772,6 +1781,7 @@ class BleHelper {
|
||||
}, 500);
|
||||
}).catch((ex) => {
|
||||
console.error("出现异常", ex);
|
||||
delete this.data.connectingDevices[deviceId];
|
||||
reject(ex);
|
||||
});
|
||||
});
|
||||
@ -1869,6 +1879,7 @@ class BleHelper {
|
||||
}
|
||||
//向蓝牙设备发送一个字符串的ASCII码
|
||||
sendString(deviceid, str, writeServiceId, wirteCharactId, ms, iosIsChuck, chunkSize) {
|
||||
debugger;
|
||||
if (str && typeof(str) == 'object') {
|
||||
str = JSON.stringify(str);
|
||||
}
|
||||
@ -1913,6 +1924,7 @@ class BleHelper {
|
||||
}
|
||||
//向蓝牙设备发送数据,如果没连接将自动连接后再发
|
||||
sendData(deviceid, buffer, writeServiceId, wirteCharactId, ms, iosIsChuck, chunkSize) {
|
||||
debugger;
|
||||
if (this.data.platform == 'web') {
|
||||
return Promise.resolve("h5平台默认成功");
|
||||
}
|
||||
@ -1995,7 +2007,9 @@ class BleHelper {
|
||||
},
|
||||
fail: (ex) => {
|
||||
ex = this.getError(ex);
|
||||
console.error("✗ 蓝牙指令发送失败 - deviceId:",device.deviceId, "错误:", ex);
|
||||
console.error(
|
||||
"✗ 蓝牙指令发送失败 - deviceId:",
|
||||
device.deviceId, "错误:", ex);
|
||||
|
||||
_err(ex);
|
||||
}
|
||||
@ -2057,7 +2071,7 @@ class BleHelper {
|
||||
);
|
||||
},
|
||||
20
|
||||
); // 20ms延迟,可根据需要调整
|
||||
); // 20ms延迟,可根据需要调整
|
||||
});
|
||||
}
|
||||
_resolve(result);
|
||||
@ -2078,7 +2092,7 @@ class BleHelper {
|
||||
);
|
||||
},
|
||||
20
|
||||
); // 20ms延迟,可根据需要调整
|
||||
); // 20ms延迟,可根据需要调整
|
||||
});
|
||||
}
|
||||
_resolve(ex);
|
||||
|
||||
@ -31,6 +31,7 @@ class BleReceive {
|
||||
'/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)
|
||||
};
|
||||
|
||||
}
|
||||
@ -743,9 +744,9 @@ class BleReceive {
|
||||
let receiveData = {};
|
||||
|
||||
try {
|
||||
console.log("订阅消息者:", path);
|
||||
console.log("设备收到消息:", f);
|
||||
console.log("消息内容:", receive);
|
||||
// console.log("订阅消息者:", path);
|
||||
// console.log("设备收到消息:", f);
|
||||
// console.log("消息内容:", receive);
|
||||
receiveData = JSON.parse(receive.str);
|
||||
|
||||
let recCnt = recArr.find(v => {
|
||||
@ -770,6 +771,7 @@ class BleReceive {
|
||||
} catch (error) {
|
||||
receiveData = {};
|
||||
console.error("文本解析失败", error)
|
||||
console.error("错误数据:",receive);
|
||||
}
|
||||
return receiveData;
|
||||
|
||||
@ -973,6 +975,35 @@ class BleReceive {
|
||||
return receiveData;
|
||||
|
||||
}
|
||||
Receive_018A(receive, f, path, recArr) {
|
||||
let receiveData = {};
|
||||
|
||||
try {
|
||||
|
||||
receiveData = JSON.parse(receive.str);
|
||||
|
||||
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);
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
receiveData = {};
|
||||
console.log("文本解析失败", error)
|
||||
}
|
||||
return receiveData;
|
||||
|
||||
}
|
||||
|
||||
Receive_210(receive, f, path, recArr) {
|
||||
let receiveData = {};
|
||||
|
||||
@ -1008,11 +1039,9 @@ class BleReceive {
|
||||
let receiveInstance = null;
|
||||
export default {
|
||||
getBleReceive: function(_ref) {
|
||||
console.log("_ref=",_ref);
|
||||
// console.log("_ref=",_ref);
|
||||
if (!receiveInstance) {
|
||||
receiveInstance = new BleReceive(_ref);
|
||||
}else{
|
||||
console.log("使用现有实例receiveInstance")
|
||||
}
|
||||
return receiveInstance;
|
||||
}
|
||||
|
||||
166
utils/Common.js
166
utils/Common.js
@ -218,31 +218,31 @@ export default {
|
||||
value: "1",
|
||||
label: "灯光模式",
|
||||
checked: false,
|
||||
type: ['6170', '670','102','6155','650','7305','6075']
|
||||
type: ['6170', '670', '102', '6155', '650', '7305', '6075']
|
||||
},
|
||||
{
|
||||
value: "2",
|
||||
label: "激光模式",
|
||||
checked: false,
|
||||
type: ['6170','6075']
|
||||
type: ['6170', '6075']
|
||||
},
|
||||
{
|
||||
value: "3",
|
||||
label: "开机画面",
|
||||
checked: false,
|
||||
type: ['210', '6170', '670','6155','650','7305','6075']
|
||||
type: ['210', '6170', '670', '6155', '650', '7305', '6075']
|
||||
},
|
||||
{
|
||||
value: "4",
|
||||
label: "人员信息登记",
|
||||
checked: false,
|
||||
type: ['210', '6170', '670','6155','650','7305','6075']
|
||||
type: ['210', '6170', '670', '6155', '650', '7305', '6075']
|
||||
},
|
||||
{
|
||||
value: "5",
|
||||
label: "发送信息",
|
||||
checked: false,
|
||||
type: ['210', '6170', '670','6075']
|
||||
type: ['210', '6170', '670', '6075']
|
||||
},
|
||||
{
|
||||
value: "6",
|
||||
@ -253,12 +253,12 @@ export default {
|
||||
value: "41",
|
||||
label: "静电探测",
|
||||
checked: false,
|
||||
type: ['670','650']
|
||||
type: ['670', '650']
|
||||
}, {
|
||||
value: "42",
|
||||
label: "SOS",
|
||||
checked: false,
|
||||
type: ['670','4877','6075']
|
||||
type: ['670', '4877', '6075']
|
||||
},
|
||||
{
|
||||
value: "43",
|
||||
@ -266,25 +266,25 @@ export default {
|
||||
checked: false,
|
||||
type: ['210']
|
||||
},
|
||||
{
|
||||
{
|
||||
value: "44",
|
||||
label: "报警声音",
|
||||
checked: false,
|
||||
type: ['210']
|
||||
},
|
||||
{
|
||||
{
|
||||
value: "45",
|
||||
label: "自动报警",
|
||||
checked: false,
|
||||
type: ['210']
|
||||
},
|
||||
{
|
||||
{
|
||||
value: "46",
|
||||
label: "手动报警",
|
||||
checked: false,
|
||||
type: ['210','102','6170']
|
||||
type: ['210', '102', '6170']
|
||||
},
|
||||
{
|
||||
{
|
||||
value: "47",
|
||||
label: "报警时长",
|
||||
checked: false,
|
||||
@ -302,28 +302,28 @@ export default {
|
||||
checked: false,
|
||||
type: ['102']
|
||||
},
|
||||
|
||||
|
||||
{
|
||||
value: "50",
|
||||
label: "报警模式",
|
||||
checked: false,
|
||||
type: ['100','100J']
|
||||
type: ['100', '100J']
|
||||
},
|
||||
|
||||
|
||||
{
|
||||
value: "51",
|
||||
label: "警示灯",
|
||||
checked: false,
|
||||
type: ['100','100J']
|
||||
type: ['100', '100J']
|
||||
},
|
||||
|
||||
|
||||
{
|
||||
value: "52",
|
||||
label: "语音管理",
|
||||
checked: false,
|
||||
type: ['100','100J']
|
||||
type: ['100', '100J']
|
||||
},
|
||||
|
||||
|
||||
{
|
||||
value: "53",
|
||||
label: "箭头模式",
|
||||
@ -340,7 +340,7 @@ export default {
|
||||
value: "55",
|
||||
label: "修改信道",
|
||||
checked: false,
|
||||
type: ['4877','102']
|
||||
type: ['4877', '102']
|
||||
},
|
||||
{
|
||||
value: "56",
|
||||
@ -400,10 +400,10 @@ export default {
|
||||
},
|
||||
//将相对路径的文件移动到_downloads文件夹中
|
||||
moveFileToDownloads(tempFilePath) {
|
||||
|
||||
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
if(!tempFilePath){
|
||||
if (!tempFilePath) {
|
||||
console.log("无文件需要移动");
|
||||
resolve(tempFilePath);
|
||||
return;
|
||||
@ -452,20 +452,21 @@ export default {
|
||||
});
|
||||
},
|
||||
|
||||
getOSAndUpload(){
|
||||
let os=uni.getSystemInfoSync().platform;
|
||||
let url=''
|
||||
if(os==='ios'){
|
||||
url='https://apps.apple.com/cn/app/星汉物联/id6752555460'
|
||||
getOSAndUpload() {
|
||||
let os = uni.getSystemInfoSync().platform;
|
||||
let url = ''
|
||||
if (os === 'ios') {
|
||||
url = 'https://apps.apple.com/cn/app/星汉物联/id6752555460'
|
||||
} else if (os === 'android') {
|
||||
url = 'https://www.pgyer.com/xhwl';
|
||||
}
|
||||
|
||||
else if(os==='android'){
|
||||
url='https://www.pgyer.com/xhwl';
|
||||
}
|
||||
return {os:os,url:url};
|
||||
return {
|
||||
os: os,
|
||||
url: url
|
||||
};
|
||||
},
|
||||
|
||||
|
||||
|
||||
|
||||
//将点阵数据转换成RGB565
|
||||
convertToRGB565(pixels, type) {
|
||||
if (!type) {
|
||||
@ -478,15 +479,106 @@ export default {
|
||||
let g = pixels[i + 1];
|
||||
let b = pixels[i + 2];
|
||||
let a = pixels[i + 3];
|
||||
|
||||
|
||||
if (type == 'bgr') {
|
||||
result[index++] = ((b & 0xF8) << 8) | ((g & 0xFC) << 3) | (r >> 3);
|
||||
} else {
|
||||
result[index++] = ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | (b >> 3);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
return result;
|
||||
},
|
||||
formatTime(value, unit = 'minute') {
|
||||
// 边界处理:空值、0或负数
|
||||
if (!value || value <= 0) return '0秒';
|
||||
|
||||
// 将所有单位统一转换为分钟和总秒数
|
||||
let minutes;
|
||||
let totalSeconds;
|
||||
|
||||
switch (unit) {
|
||||
case 'second': // 秒
|
||||
minutes = value / 60;
|
||||
totalSeconds = value;
|
||||
break;
|
||||
case 'minute': // 分钟(默认)
|
||||
minutes = value;
|
||||
totalSeconds = value * 60;
|
||||
break;
|
||||
case 'hour': // 小时
|
||||
minutes = value * 60;
|
||||
totalSeconds = value * 3600;
|
||||
break;
|
||||
case 'day': // 天
|
||||
minutes = value * 24 * 60;
|
||||
totalSeconds = value * 86400;
|
||||
break;
|
||||
default:
|
||||
minutes = value;
|
||||
totalSeconds = value * 60;
|
||||
}
|
||||
|
||||
// 定义时间单位(分钟)
|
||||
const units = [
|
||||
{ label: '年', minutes: 365 * 24 * 60 },
|
||||
{ label: '月', minutes: 30 * 24 * 60 }, // 按30天简化计算
|
||||
{ label: '天', minutes: 24 * 60 },
|
||||
{ label: '小时', minutes: 60 },
|
||||
{ label: '分', minutes: 1 }
|
||||
];
|
||||
|
||||
let remaining = minutes;
|
||||
const parts = [];
|
||||
|
||||
for (const unitObj of units) {
|
||||
const val = Math.floor(remaining / unitObj.minutes);
|
||||
if (val > 0) {
|
||||
parts.push(`${val}${unitObj.label}`);
|
||||
remaining %= unitObj.minutes;
|
||||
}
|
||||
}
|
||||
|
||||
// 处理剩余的秒数(remaining 现在是小于1分钟的分钟数)
|
||||
if (remaining > 0) {
|
||||
const seconds = Math.round(remaining * 60);
|
||||
if (seconds > 0) {
|
||||
parts.push(`${seconds}秒`);
|
||||
}
|
||||
}
|
||||
|
||||
// 如果没有任何部分,返回总秒数
|
||||
if (parts.length === 0) {
|
||||
return `${Math.floor(totalSeconds)}秒`;
|
||||
}
|
||||
|
||||
return parts.join('');
|
||||
},
|
||||
regeo(lon, lat) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let url =
|
||||
'https://restapi.amap.com/v3/geocode/regeo?key=ca3af8a20d628897020893892bda5ae4&location=' +
|
||||
lon + ',' + lat;
|
||||
|
||||
request({
|
||||
url: url,
|
||||
method: 'GET',
|
||||
isAuthen: false
|
||||
}).then(res => {
|
||||
if (res) {
|
||||
if (res.infocode == '10000' && res.info == 'OK') {
|
||||
resolve(res);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
reject(res);
|
||||
}).catch(ex => {
|
||||
reject(ex);
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,5 +1,5 @@
|
||||
import config from '../config/index.js';
|
||||
export const env = 'production'; //production development //开发of线上 改这里就行
|
||||
export const env = 'development'; //production development //开发of线上 改这里就行
|
||||
const BASE = config[env];
|
||||
const request = (options) => {
|
||||
// console.log("options" + JSON.stringify(options), BASE.BASE_URL)
|
||||
|
||||
Reference in New Issue
Block a user