Compare commits
28 Commits
7512b7211c
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| b76a41b624 | |||
| c286660a10 | |||
| 5163491ea3 | |||
| 0e66d375fc | |||
| 1fcaf8a9a4 | |||
| 75b9f27965 | |||
| bdea9dac4b | |||
| 444b3b35ac | |||
| 3e19646ed7 | |||
| 44607f9b0c | |||
| 23b72ef9ae | |||
| 84feb9f1e8 | |||
| 3a9de3078c | |||
| ac59e28281 | |||
| f943bb9b09 | |||
| a2680fc14d | |||
| ebe126d826 | |||
| f86e6a4fb7 | |||
| bb0610ff1a | |||
| 61f00e1cbf | |||
| a9848bd299 | |||
| 729f782c42 | |||
| 2c9197833b | |||
| 141267b25f | |||
| ede41f68fd | |||
| 9b6a5e095c | |||
| 7735abc2a1 | |||
| c626f3766e |
58
App.vue
58
App.vue
@ -1,6 +1,11 @@
|
||||
<script>
|
||||
import bleTool from '@/utils/BleHelper.js'
|
||||
import upgrade from '@/utils/update.js'
|
||||
import bleTool from '@/utils/BleHelper.js';
|
||||
import upgrade from '@/utils/update.js';
|
||||
|
||||
// 延迟断开蓝牙:选择文件/录音等会触发 onHide,8 秒内返回则不断开
|
||||
const BLE_DISCONNECT_DELAY = 8000;
|
||||
let _bleDisconnectTimer = null;
|
||||
|
||||
export default {
|
||||
|
||||
onLaunch: function() {
|
||||
@ -30,11 +35,9 @@
|
||||
//以上代码仅在开发时使用,否则会出现不可预知的问题。
|
||||
|
||||
// #ifdef APP|APP-PLUS
|
||||
if (plus.runtime.isAgreePrivacy()) {
|
||||
let initOS = () => {
|
||||
let ble = bleTool.getBleTool();
|
||||
|
||||
|
||||
bleTool.getBleTool();
|
||||
|
||||
uni.getPushClientId({
|
||||
success(res) {
|
||||
console.log("推送信息:", res);
|
||||
@ -62,28 +65,61 @@
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
if (plus.os.name == 'Android') {
|
||||
if (plus.runtime.isAgreePrivacy()) {
|
||||
initOS();
|
||||
}
|
||||
} else {
|
||||
initOS();
|
||||
}
|
||||
|
||||
// #endif
|
||||
},
|
||||
onShow: function() {
|
||||
console.log('App Show');
|
||||
|
||||
// 取消延迟断开:用户可能只是选文件/录音后返回,不断开蓝牙
|
||||
if (_bleDisconnectTimer) {
|
||||
clearTimeout(_bleDisconnectTimer);
|
||||
_bleDisconnectTimer = null;
|
||||
}
|
||||
//将检查更新换到onshow,因为苹果用户喜欢一直挂着
|
||||
// #ifdef APP|APP-PLUS
|
||||
|
||||
let appid = plus.runtime.appid;
|
||||
console.log("appid=", appid);
|
||||
|
||||
if (appid !== 'HBuilder') {
|
||||
|
||||
if (appid !== 'HBuilder') {
|
||||
upgrade.checkAndUpdateWgt();
|
||||
}
|
||||
// #endif
|
||||
|
||||
|
||||
},
|
||||
onHide: function() {
|
||||
console.log('App Hide');
|
||||
// #ifdef APP|APP-PLUS
|
||||
// 上传中不主动断开:语音上传进行中则不断开蓝牙
|
||||
let ble = bleTool.getBleTool();
|
||||
if (ble && ble.isVoiceUploading && ble.isVoiceUploading()) {
|
||||
console.log('App Hide: 语音上传中,不启动断开定时器');
|
||||
return;
|
||||
}
|
||||
// 延迟断开:选文件/录音会短暂 onHide,8 秒内返回则不断开
|
||||
if (_bleDisconnectTimer) clearTimeout(_bleDisconnectTimer);
|
||||
_bleDisconnectTimer = setTimeout(() => {
|
||||
_bleDisconnectTimer = null;
|
||||
let ble2 = bleTool.getBleTool();
|
||||
if (ble2) {
|
||||
console.log("App隐藏了,断开所有蓝牙设备,停止搜索");
|
||||
ble2.StopSearch().catch(ex => {});
|
||||
ble2.disconnectDevice().catch(ex => {});
|
||||
console.log("断开所有蓝牙设备");
|
||||
|
||||
|
||||
}
|
||||
}, BLE_DISCONNECT_DELAY);
|
||||
// #endif
|
||||
},
|
||||
onError(ex) {
|
||||
console.error("出现了未知的异常", ex);
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
import request from '@/utils/request'
|
||||
import Common from '@/utils/Common.js'
|
||||
|
||||
// ================== 蓝牙协议封装类 ==================
|
||||
class HBY100JProtocol {
|
||||
@ -13,6 +14,24 @@ class HBY100JProtocol {
|
||||
this.NOTIFY_UUID = '0000AE02-0000-1000-8000-00805F9B34FB'; // 0xAE02
|
||||
|
||||
this.onNotifyCallback = null;
|
||||
this._fileResponseResolve = null; // 文件上传时等待设备 FB 05 响应
|
||||
}
|
||||
|
||||
// 等待设备 FB 05 响应,超时后仍 resolve(设备可能不响应每包)
|
||||
waitForFileResponse(timeoutMs = 2000) {
|
||||
return new Promise((resolve) => {
|
||||
const timer = setTimeout(() => {
|
||||
if (this._fileResponseResolve) {
|
||||
this._fileResponseResolve = null;
|
||||
resolve(null);
|
||||
}
|
||||
}, timeoutMs);
|
||||
this._fileResponseResolve = (result) => {
|
||||
clearTimeout(timer);
|
||||
this._fileResponseResolve = null;
|
||||
resolve(result);
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
setBleConnectionStatus(status, bleDeviceId = '') {
|
||||
@ -27,28 +46,56 @@ class HBY100JProtocol {
|
||||
}
|
||||
|
||||
parseBleData(buffer) {
|
||||
const view = new Uint8Array(buffer);
|
||||
const view = buffer instanceof Uint8Array ? buffer : new Uint8Array(buffer);
|
||||
if (view.length < 3) return null;
|
||||
|
||||
const header = view[0];
|
||||
const tail = view[view.length - 1];
|
||||
|
||||
// 5.1 连接蓝牙设备主动上报 MAC 地址: FC + 6字节MAC + FF
|
||||
if (header === 0xFC && tail === 0xFF && view.length >= 8) {
|
||||
const macBytes = view.slice(1, 7);
|
||||
const macAddress = Array.from(macBytes).map(b => b.toString(16).padStart(2, '0').toUpperCase()).join(':');
|
||||
const result = { type: 'mac', macAddress };
|
||||
console.log('[100J-蓝牙] 设备上报MAC:', macAddress, '原始:', Array.from(view).map(b => b.toString(16).padStart(2, '0').toUpperCase()).join(' '));
|
||||
if (this.onNotifyCallback) this.onNotifyCallback(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
if (header !== 0xFB || tail !== 0xFF) return null; // 校验头尾
|
||||
|
||||
const funcCode = view[1];
|
||||
const data = view.slice(2, view.length - 1);
|
||||
const hexStr = Array.from(view).map(b => b.toString(16).padStart(2, '0').toUpperCase()).join(' ');
|
||||
|
||||
let result = { funcCode, rawData: data };
|
||||
|
||||
switch (funcCode) {
|
||||
case 0x01: result.resetType = data[0]; break;
|
||||
case 0x02: break;
|
||||
case 0x03: break;
|
||||
case 0x03:
|
||||
// 5.4 获取设备位置:经度8B+纬度8B 均为 float64,设备主动上报(1分钟)与主动查询响应格式相同
|
||||
if (data.length >= 16) {
|
||||
const lonBuf = new ArrayBuffer(8);
|
||||
const latBuf = new ArrayBuffer(8);
|
||||
new Uint8Array(lonBuf).set(data.slice(0, 8));
|
||||
new Uint8Array(latBuf).set(data.slice(8, 16));
|
||||
result.longitude = new DataView(lonBuf).getFloat64(0, true);
|
||||
result.latitude = new DataView(latBuf).getFloat64(0, true);
|
||||
}
|
||||
break;
|
||||
case 0x05:
|
||||
// 05: 文件更新响应 FB 05 [fileType] [status] FF,status: 1=成功 2=失败
|
||||
if (data.length >= 1) result.fileType = data[0];
|
||||
if (data.length >= 2) result.fileStatus = data[1]; // 1=Success, 2=Failure
|
||||
if (this._fileResponseResolve) this._fileResponseResolve(result);
|
||||
break;
|
||||
case 0x04:
|
||||
// 04: 获取电源状态 (根据协议图解析)
|
||||
// 假设电量百分比在第16字节,具体需要根据你提供的协议图来定
|
||||
// 这里我按照协议图的结构,如果电量百分比在第16字节:
|
||||
if (data.length >= 17) {
|
||||
result.batteryPercentage = data[16];
|
||||
// 5.5 获取设备电源状态: 电池容量8B + 电压8B + 百分比1B + 车载电源1B + 续航时间2B(分钟)
|
||||
if (data.length >= 20) {
|
||||
result.batteryPercentage = data[16];
|
||||
result.vehiclePower = data[17];
|
||||
result.batteryRemainingTime = data[18] | (data[19] << 8); // 小端序,单位分钟
|
||||
}
|
||||
break;
|
||||
case 0x06:
|
||||
@ -94,6 +141,10 @@ class HBY100JProtocol {
|
||||
break;
|
||||
}
|
||||
|
||||
const funcNames = { 0x01: '复位', 0x02: '基础信息', 0x03: '位置', 0x04: '电源状态', 0x05: '文件更新', 0x06: '语音播报', 0x09: '音量', 0x0A: '爆闪模式', 0x0B: '爆闪频率', 0x0C: '强制报警', 0x0D: 'LED亮度', 0x0E: '工作方式' };
|
||||
const name = funcNames[funcCode] || ('0x' + funcCode.toString(16));
|
||||
console.log('[100J-蓝牙] 设备响应 FB:', name, '解析:', JSON.stringify(result), '原始:', hexStr);
|
||||
|
||||
if (this.onNotifyCallback) {
|
||||
this.onNotifyCallback(result);
|
||||
}
|
||||
@ -114,6 +165,8 @@ class HBY100JProtocol {
|
||||
view[2 + i] = dataBytes[i];
|
||||
}
|
||||
view[view.length - 1] = 0xFF; // 结尾
|
||||
const sendHex = Array.from(view).map(b => b.toString(16).padStart(2, '0').toUpperCase()).join(' ');
|
||||
console.log('[100J-蓝牙] 下发指令 FA:', '0x' + funcCode.toString(16).toUpperCase(), sendHex);
|
||||
|
||||
// 使用项目中统一的 BleHelper 发送数据
|
||||
import('@/utils/BleHelper.js').then(module => {
|
||||
@ -127,6 +180,9 @@ class HBY100JProtocol {
|
||||
|
||||
// 纯蓝牙指令发送方法
|
||||
deviceReset(type = 0) { return this.sendBleData(0x01, [type]); }
|
||||
getBasicInfo() { return this.sendBleData(0x02, []); }
|
||||
getLocation() { return this.sendBleData(0x03, []); }
|
||||
getPowerStatus() { return this.sendBleData(0x04, []); }
|
||||
setVoiceBroadcast(enable) { return this.sendBleData(0x06, [enable]); }
|
||||
setVolume(volume) { return this.sendBleData(0x09, [volume]); }
|
||||
setStrobeMode(enable, mode) { return this.sendBleData(0x0A, [enable, mode]); }
|
||||
@ -134,6 +190,187 @@ class HBY100JProtocol {
|
||||
setForceAlarm(enable, mode) { return this.sendBleData(0x0C, [enable, mode]); }
|
||||
setLightBrightness(red, blue = 0, yellow = 0) { return this.sendBleData(0x0D, [red, blue, yellow]); }
|
||||
getCurrentWorkMode() { return this.sendBleData(0x0E, []); }
|
||||
|
||||
// 0x05 文件上传:分片传输,协议 FA 05 [fileType] [phase] [data...] FF
|
||||
// fileType: 1=语音 2=图片 3=动图 4=OTA
|
||||
// phase: 0=开始 1=数据 2=结束
|
||||
// 每包最大字节 蓝牙:CHUNK_SIZE=500
|
||||
// 支持 fileUrl(需网络下载) 或 localPath(无网络时本地文件)
|
||||
uploadVoiceFileBle(fileUrlOrLocalPath, fileType = 1, onProgress) {
|
||||
const CHUNK_SIZE = 500; // 每包有效数据,参考 6155 deviceDetail.vue
|
||||
return new Promise((resolve, reject) => {
|
||||
if (!this.isBleConnected || !this.bleDeviceId) {
|
||||
return reject(new Error('蓝牙未连接'));
|
||||
}
|
||||
if (!fileUrlOrLocalPath) {
|
||||
return reject(new Error('缺少文件地址或本地路径'));
|
||||
}
|
||||
const isLocalPath = !/^https?:\/\//i.test(fileUrlOrLocalPath);
|
||||
if (onProgress) onProgress(1);
|
||||
const readFromPath = (path) => {
|
||||
const doSend = (bytes) => {
|
||||
this._sendVoiceChunks(bytes, fileType, CHUNK_SIZE, onProgress)
|
||||
.then(resolve).catch(reject);
|
||||
};
|
||||
// App 端 getFileSystemManager 未实现,直接用 plus.io.requestFileSystem+getFile
|
||||
readFromPathPlus(path, doSend, reject);
|
||||
};
|
||||
const readFileEntry = (entry, doSend, reject) => {
|
||||
entry.file((file) => {
|
||||
const reader = new plus.io.FileReader();
|
||||
reader.onloadend = (e) => {
|
||||
try {
|
||||
const buf = e.target.result;
|
||||
const bytes = new Uint8Array(buf);
|
||||
doSend(bytes);
|
||||
} catch (err) {
|
||||
console.error('[100J-蓝牙] 读取ArrayBuffer异常:', err);
|
||||
reject(err);
|
||||
}
|
||||
};
|
||||
reader.onerror = () => reject(new Error('读取文件失败'));
|
||||
reader.readAsArrayBuffer(file);
|
||||
}, (err) => reject(err));
|
||||
};
|
||||
const readFromPathPlus = (path, doSend, reject) => {
|
||||
if (typeof plus === 'undefined' || !plus.io) {
|
||||
console.error('[100J-蓝牙] 当前环境不支持文件读取(plus.io)');
|
||||
reject(new Error('当前环境不支持文件读取'));
|
||||
return;
|
||||
}
|
||||
// _downloads/ 用 requestFileSystem+getFile(避免 resolveLocalFileSystemURL 卡住)
|
||||
if (path && path.startsWith('_downloads/')) {
|
||||
const fileName = path.replace(/^_downloads\//, '');
|
||||
plus.io.requestFileSystem(plus.io.PUBLIC_DOWNLOADS, (fs) => {
|
||||
fs.root.getFile(fileName, {}, (entry) => readFileEntry(entry, doSend, reject), (err) => reject(err));
|
||||
}, (err) => reject(err));
|
||||
return;
|
||||
}
|
||||
// _doc/ 用 requestFileSystem(PRIVATE_DOC),逐级 getDirectory 再 getFile(嵌套路径兼容)
|
||||
if (path && path.startsWith('_doc/')) {
|
||||
const relPath = path.replace(/^_doc\//, '');
|
||||
const parts = relPath.split('/');
|
||||
const fileName = parts.pop();
|
||||
const dirs = parts;
|
||||
plus.io.requestFileSystem(plus.io.PRIVATE_DOC, (fs) => {
|
||||
let cur = fs.root;
|
||||
const next = (i) => {
|
||||
if (i >= dirs.length) {
|
||||
cur.getFile(fileName, { create: false }, (entry) => readFileEntry(entry, doSend, reject), (err) => reject(err));
|
||||
return;
|
||||
}
|
||||
cur.getDirectory(dirs[i], { create: false }, (dir) => { cur = dir; next(i + 1); }, (err) => reject(err));
|
||||
};
|
||||
next(0);
|
||||
}, (err) => reject(err));
|
||||
return;
|
||||
}
|
||||
// 其他路径兜底
|
||||
let resolvePath = path;
|
||||
if (path && path.startsWith('/') && !path.startsWith('file://')) resolvePath = 'file://' + path;
|
||||
plus.io.resolveLocalFileSystemURL(resolvePath, (entry) => readFileEntry(entry, doSend, reject), (err) => reject(err));
|
||||
};
|
||||
if (isLocalPath) {
|
||||
// 本地路径:无网络时直接读取
|
||||
readFromPath(fileUrlOrLocalPath);
|
||||
} else {
|
||||
// 网络 URL:优先用 uni.request 直接拉取 ArrayBuffer(类似 100 设备,无文件 IO),失败再走 downloadFile
|
||||
let fetchUrl = fileUrlOrLocalPath;
|
||||
if (fetchUrl.startsWith('http://')) fetchUrl = 'https://' + fetchUrl.slice(7);
|
||||
if (onProgress) onProgress(2);
|
||||
uni.request({
|
||||
url: fetchUrl,
|
||||
method: 'GET',
|
||||
responseType: 'arraybuffer',
|
||||
timeout: 60000,
|
||||
success: (res) => {
|
||||
if (res.statusCode === 200 && res.data) {
|
||||
const bytes = res.data instanceof ArrayBuffer ? new Uint8Array(res.data) : new Uint8Array(res.data || []);
|
||||
if (bytes.length > 0) {
|
||||
const doSend = (b) => {
|
||||
this._sendVoiceChunks(b, fileType, CHUNK_SIZE, onProgress).then(resolve).catch(reject);
|
||||
};
|
||||
doSend(bytes);
|
||||
return;
|
||||
}
|
||||
}
|
||||
fallbackDownload();
|
||||
},
|
||||
fail: () => fallbackDownload()
|
||||
});
|
||||
const fallbackDownload = () => {
|
||||
uni.downloadFile({
|
||||
url: fetchUrl,
|
||||
success: (res) => {
|
||||
if (res.statusCode !== 200 || !res.tempFilePath) {
|
||||
reject(new Error('下载失败: ' + (res.statusCode || '无路径')));
|
||||
return;
|
||||
}
|
||||
Common.moveFileToDownloads(res.tempFilePath).then((p) => readFromPath(p)).catch(() => readFromPath(res.tempFilePath));
|
||||
},
|
||||
fail: (err) => reject(err)
|
||||
});
|
||||
};
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
_sendVoiceChunks(bytes, fileType, chunkSize, onProgress) {
|
||||
const total = bytes.length;
|
||||
const ft = (fileType & 0xFF) || 1;
|
||||
const DELAY_AFTER_START = 80; // 开始包后、等设备响应后再发的缓冲(ms)
|
||||
const DELAY_PACKET = 80; // 数据包间延时(ms),参考6155
|
||||
const toHex = (arr) => Array.from(arr).map(b => b.toString(16).padStart(2, '0').toUpperCase()).join(' ');
|
||||
console.log('[100J-蓝牙] 语音下发总大小:', total, '字节, fileType=', ft);
|
||||
if (onProgress) onProgress(1);
|
||||
const bleToolPromise = import('@/utils/BleHelper.js').then(m => m.default.getBleTool());
|
||||
let bleRef = null;
|
||||
const send = (dataBytes, label = '') => {
|
||||
const buf = new ArrayBuffer(dataBytes.length + 3);
|
||||
const v = new Uint8Array(buf);
|
||||
v[0] = 0xFA;
|
||||
v[1] = 0x05;
|
||||
for (let i = 0; i < dataBytes.length; i++) v[2 + i] = dataBytes[i];
|
||||
v[v.length - 1] = 0xFF;
|
||||
const hex = toHex(v);
|
||||
const preview = v.length <= 32 ? hex : hex.slice(0, 96) + '...';
|
||||
console.log(`[100J-蓝牙] 下发${label} 共${v.length}字节:`, preview);
|
||||
return bleToolPromise.then(ble => ble.sendData(this.bleDeviceId, buf, this.SERVICE_UUID, this.WRITE_UUID));
|
||||
};
|
||||
const delay = (ms) => new Promise(r => setTimeout(r, ms));
|
||||
// 开始包: FA 05 [fileType] [phase=0] [size 4B LE] FF
|
||||
const startData = [ft, 0, total & 0xFF, (total >> 8) & 0xFF, (total >> 16) & 0xFF, (total >> 24) & 0xFF];
|
||||
const waitPromise = this.waitForFileResponse(1000);
|
||||
return bleToolPromise.then(ble => {
|
||||
bleRef = ble;
|
||||
ble.setVoiceUploading(true);
|
||||
return send(startData, ' 开始包')
|
||||
.then(() => { if (onProgress) onProgress(3); return waitPromise; })
|
||||
.then(() => { if (onProgress) onProgress(5); return delay(DELAY_AFTER_START); })
|
||||
.then(() => {
|
||||
let seq = 0;
|
||||
const sendNext = (offset) => {
|
||||
if (offset >= total) {
|
||||
return delay(DELAY_PACKET).then(() => send([ft, 2], ' 结束包'));
|
||||
}
|
||||
const chunk = bytes.slice(offset, Math.min(offset + chunkSize, total));
|
||||
const chunkData = [ft, 1, seq & 0xFF, (seq >> 8) & 0xFF, ...chunk];
|
||||
return send(chunkData, ` #${seq} 数据包`).then(() => {
|
||||
seq++;
|
||||
if (onProgress) onProgress(Math.min(100, Math.floor((offset + chunk.length) / total * 100)));
|
||||
return delay(DELAY_PACKET).then(() => sendNext(offset + chunk.length));
|
||||
});
|
||||
};
|
||||
return sendNext(0);
|
||||
})
|
||||
.then(() => {
|
||||
if (onProgress) onProgress(100);
|
||||
return { code: 200, msg: '语音文件已通过蓝牙上传' };
|
||||
});
|
||||
}).finally(() => {
|
||||
if (bleRef) bleRef.setVoiceUploading(false);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// ================== 全局单例与状态管理 ==================
|
||||
@ -143,6 +380,12 @@ const protocolInstance = new HBY100JProtocol();
|
||||
export function updateBleStatus(isConnected, bleDeviceId, deviceId) {
|
||||
protocolInstance.setBleConnectionStatus(isConnected, bleDeviceId);
|
||||
protocolInstance.deviceId = deviceId;
|
||||
console.log('[100J] 蓝牙状态:', isConnected ? '已连接(后续指令走蓝牙)' : '已断开(后续指令走4G)', { bleDeviceId: bleDeviceId || '-', deviceId });
|
||||
}
|
||||
|
||||
// 暴露给页面:获取当前蓝牙连接状态(用于跨页面传递,确保语音管理等子页走蓝牙优先)
|
||||
export function getBleStatus() {
|
||||
return { isConnected: protocolInstance.isBleConnected, bleDeviceId: protocolInstance.bleDeviceId, deviceId: protocolInstance.deviceId };
|
||||
}
|
||||
|
||||
// 暴露给页面:解析蓝牙接收到的数据
|
||||
@ -150,6 +393,76 @@ export function parseBleData(buffer) {
|
||||
return protocolInstance.parseBleData(buffer);
|
||||
}
|
||||
|
||||
// 暴露给页面:蓝牙连接后主动拉取电源状态(电量、续航)
|
||||
export function fetchBlePowerStatus() {
|
||||
if (!protocolInstance.isBleConnected) return Promise.reject(new Error('蓝牙未连接'));
|
||||
console.log('[100J-蓝牙] 拉取电源状态 已通过蓝牙发送 FA 04 FF');
|
||||
return protocolInstance.getPowerStatus();
|
||||
}
|
||||
|
||||
// 暴露给页面:蓝牙连接后主动拉取定位(优先蓝牙,设备也会每1分钟主动上报)
|
||||
export function fetchBleLocation() {
|
||||
if (!protocolInstance.isBleConnected) return Promise.reject(new Error('蓝牙未连接'));
|
||||
console.log('[100J-蓝牙] 拉取定位 已通过蓝牙发送 FA 03 FF');
|
||||
return protocolInstance.getLocation();
|
||||
}
|
||||
|
||||
// 等待蓝牙连接(扫描中时轮询,设备页可能在后台完成连接,100J 扫描约 15s)
|
||||
function waitForBleConnection(maxWaitMs = 12000, intervalMs = 500) {
|
||||
if (protocolInstance.isBleConnected && protocolInstance.bleDeviceId) return Promise.resolve(true);
|
||||
return new Promise((resolve) => {
|
||||
const start = Date.now();
|
||||
const tick = () => {
|
||||
if (protocolInstance.isBleConnected && protocolInstance.bleDeviceId) {
|
||||
console.log('[100J] 等待蓝牙连接成功');
|
||||
resolve(true);
|
||||
return;
|
||||
}
|
||||
if (Date.now() - start >= maxWaitMs) {
|
||||
console.log('[100J] 等待蓝牙连接超时,将走4G');
|
||||
resolve(false);
|
||||
return;
|
||||
}
|
||||
setTimeout(tick, intervalMs);
|
||||
};
|
||||
console.log('[100J] 蓝牙未连接,等待扫描/连接中...', maxWaitMs, 'ms');
|
||||
tick();
|
||||
});
|
||||
}
|
||||
|
||||
// 暴露给页面:尝试重连蓝牙(优先策略:断线后发指令前先尝试重连)
|
||||
export function tryReconnectBle(timeoutMs = 2500) {
|
||||
if (protocolInstance.isBleConnected) return Promise.resolve(true);
|
||||
if (!protocolInstance.bleDeviceId) return Promise.resolve(false);
|
||||
return new Promise((resolve) => {
|
||||
import('@/utils/BleHelper.js').then(module => {
|
||||
const bleTool = module.default.getBleTool();
|
||||
const deviceId = protocolInstance.bleDeviceId;
|
||||
const f = bleTool.data.LinkedList.find(v => v.deviceId === deviceId);
|
||||
if (!f) {
|
||||
resolve(false);
|
||||
return;
|
||||
}
|
||||
const svc = f.writeServiceId || '0000AE30-0000-1000-8000-00805F9B34FB';
|
||||
const write = f.wirteCharactId || '0000AE03-0000-1000-8000-00805F9B34FB';
|
||||
const notify = f.notifyCharactId || '0000AE02-0000-1000-8000-00805F9B34FB';
|
||||
const timer = setTimeout(() => {
|
||||
resolve(protocolInstance.isBleConnected);
|
||||
}, timeoutMs);
|
||||
console.log('[100J] 蓝牙优先:尝试重连', deviceId);
|
||||
bleTool.LinkBlue(deviceId, svc, write, notify, 1).then(() => {
|
||||
clearTimeout(timer);
|
||||
protocolInstance.setBleConnectionStatus(true, deviceId);
|
||||
console.log('[100J] 蓝牙重连成功');
|
||||
resolve(true);
|
||||
}).catch(() => {
|
||||
clearTimeout(timer);
|
||||
resolve(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// ================== API 接口 (拦截层) ==================
|
||||
|
||||
// 获取语音管理列表
|
||||
@ -177,13 +490,26 @@ export function deviceDeleteAudioFile(params) {
|
||||
})
|
||||
}
|
||||
|
||||
// 更新语音,使用语音
|
||||
// 更新语音/使用语音:蓝牙优先,4G 兜底(不影响原有 4G 音频下发)
|
||||
// 有 fileUrl 或 localPath 且蓝牙可用时走蓝牙;否则或蓝牙失败时走 4G(与原先逻辑一致)
|
||||
export function deviceUpdateVoice(data) {
|
||||
return request({
|
||||
const httpExec = () => request({
|
||||
url: `/app/hby100j/device/updateVoice`,
|
||||
method: 'post',
|
||||
data:data
|
||||
})
|
||||
data: { id: data.id }
|
||||
});
|
||||
const localPath = data.localPath;
|
||||
const fileUrl = data.fileUrl;
|
||||
const hasLocalPath = localPath && typeof localPath === 'string' && localPath.length > 0;
|
||||
const hasFileUrl = fileUrl && typeof fileUrl === 'string' && fileUrl.length > 0;
|
||||
const fileSource = hasLocalPath ? localPath : (hasFileUrl ? fileUrl : null);
|
||||
if (!fileSource) {
|
||||
console.log('[100J] 语音上传:无 fileUrl/localPath,走 4G');
|
||||
return httpExec(); // 无文件源:直接 4G(原有逻辑)
|
||||
}
|
||||
console.log('[100J] 语音上传:有文件源,蓝牙优先', { isBleConnected: protocolInstance.isBleConnected, bleDeviceId: protocolInstance.bleDeviceId || '-' });
|
||||
const bleExec = () => protocolInstance.uploadVoiceFileBle(fileSource, 1, data.onProgress);
|
||||
return execWithBleFirst(bleExec, httpExec, '语音文件上传', data.onWaiting);
|
||||
}
|
||||
// 100J信息
|
||||
export function deviceDetail(id) {
|
||||
@ -193,86 +519,75 @@ export function deviceDetail(id) {
|
||||
})
|
||||
}
|
||||
|
||||
// 蓝牙优先、4G 兜底:未连接时先等待扫描/连接,再尝试重连;蓝牙失败时回退 4G
|
||||
function execWithBleFirst(bleExec, httpExec, logName, onWaiting) {
|
||||
const doBle = () => bleExec().then(res => ({ ...(res || {}), _channel: 'ble' }));
|
||||
const do4G = () => httpExec().then(res => { res._channel = '4g'; return res; });
|
||||
if (protocolInstance.isBleConnected && protocolInstance.bleDeviceId) {
|
||||
return doBle().catch(() => { console.log('[100J] 蓝牙失败,回退4G'); return do4G(); });
|
||||
}
|
||||
// 无 bleDeviceId 时:可能扫描中,先等待连接(设备页在后台可能完成连接)
|
||||
if (!protocolInstance.bleDeviceId) {
|
||||
if (typeof onWaiting === 'function') onWaiting();
|
||||
return waitForBleConnection(12000).then(connected => {
|
||||
return connected ? doBle().catch(() => { console.log('[100J] 蓝牙失败,回退4G'); return do4G(); }) : do4G();
|
||||
});
|
||||
}
|
||||
return tryReconnectBle(2500).then(reconnected => {
|
||||
return reconnected ? doBle().catch(() => { console.log('[100J] 蓝牙失败,回退4G'); return do4G(); }) : do4G();
|
||||
});
|
||||
}
|
||||
|
||||
// 爆闪模式
|
||||
export function deviceStrobeMode(data) {
|
||||
if (protocolInstance.isBleConnected) {
|
||||
return protocolInstance.setStrobeMode(data.enable, data.mode).then(res => {
|
||||
return { code: 200, msg: '操作成功(蓝牙)' };
|
||||
});
|
||||
}
|
||||
return request({
|
||||
url: `/app/hby100j/device/strobeMode`,
|
||||
method: 'post',
|
||||
data:data
|
||||
})
|
||||
return execWithBleFirst(
|
||||
() => protocolInstance.setStrobeMode(data.enable, data.mode).then(() => ({ code: 200, msg: '操作成功(蓝牙)' })),
|
||||
() => request({ url: `/app/hby100j/device/strobeMode`, method: 'post', data }),
|
||||
'爆闪模式'
|
||||
);
|
||||
}
|
||||
|
||||
// 强制报警
|
||||
export function deviceForceAlarmActivation(data) {
|
||||
if (protocolInstance.isBleConnected) {
|
||||
return protocolInstance.setForceAlarm(data.voiceStrobeAlarm, data.mode).then(res => {
|
||||
return { code: 200, msg: '操作成功(蓝牙)' };
|
||||
});
|
||||
}
|
||||
return request({
|
||||
url: `/app/hby100j/device/forceAlarmActivation`,
|
||||
method: 'post',
|
||||
data:data
|
||||
})
|
||||
return execWithBleFirst(
|
||||
() => protocolInstance.setForceAlarm(data.voiceStrobeAlarm, data.mode).then(() => ({ code: 200, msg: '操作成功(蓝牙)' })),
|
||||
() => request({ url: `/app/hby100j/device/forceAlarmActivation`, method: 'post', data }),
|
||||
'强制报警'
|
||||
);
|
||||
}
|
||||
|
||||
// 爆闪频率
|
||||
export function deviceStrobeFrequency(data) {
|
||||
if (protocolInstance.isBleConnected) {
|
||||
return protocolInstance.setStrobeFrequency(data.frequency).then(res => {
|
||||
return { code: 200, msg: '操作成功(蓝牙)' };
|
||||
});
|
||||
}
|
||||
return request({
|
||||
url: `/app/hby100j/device/strobeFrequency`,
|
||||
method: 'post',
|
||||
data:data
|
||||
})
|
||||
return execWithBleFirst(
|
||||
() => protocolInstance.setStrobeFrequency(data.frequency).then(() => ({ code: 200, msg: '操作成功(蓝牙)' })),
|
||||
() => request({ url: `/app/hby100j/device/strobeFrequency`, method: 'post', data }),
|
||||
'爆闪频率'
|
||||
);
|
||||
}
|
||||
|
||||
// 灯光调节亮度
|
||||
export function deviceLightAdjustment(data) {
|
||||
if (protocolInstance.isBleConnected) {
|
||||
return protocolInstance.setLightBrightness(data.brightness, data.brightness, data.brightness).then(res => {
|
||||
return { code: 200, msg: '操作成功(蓝牙)' };
|
||||
});
|
||||
}
|
||||
return request({
|
||||
url: `/app/hby100j/device/lightAdjustment`,
|
||||
method: 'post',
|
||||
data:data
|
||||
})
|
||||
return execWithBleFirst(
|
||||
() => protocolInstance.setLightBrightness(data.brightness, data.brightness, data.brightness).then(() => ({ code: 200, msg: '操作成功(蓝牙)' })),
|
||||
() => request({ url: `/app/hby100j/device/lightAdjustment`, method: 'post', data }),
|
||||
'灯光亮度'
|
||||
);
|
||||
}
|
||||
|
||||
// 调节音量
|
||||
export function deviceUpdateVolume(data) {
|
||||
if (protocolInstance.isBleConnected) {
|
||||
return protocolInstance.setVolume(data.volume).then(res => {
|
||||
return { code: 200, msg: '操作成功(蓝牙)' };
|
||||
});
|
||||
}
|
||||
return request({
|
||||
url: `/app/hby100j/device/updateVolume`,
|
||||
method: 'post',
|
||||
data:data
|
||||
})
|
||||
return execWithBleFirst(
|
||||
() => protocolInstance.setVolume(data.volume).then(() => ({ code: 200, msg: '操作成功(蓝牙)' })),
|
||||
() => request({ url: `/app/hby100j/device/updateVolume`, method: 'post', data }),
|
||||
'调节音量'
|
||||
);
|
||||
}
|
||||
|
||||
// 语音播放
|
||||
export function deviceVoiceBroadcast(data) {
|
||||
if (protocolInstance.isBleConnected) {
|
||||
return protocolInstance.setVoiceBroadcast(data.voiceBroadcast).then(res => {
|
||||
return { code: 200, msg: '操作成功(蓝牙)' };
|
||||
});
|
||||
}
|
||||
return request({
|
||||
url: `/app/hby100j/device/voiceBroadcast`,
|
||||
method: 'post',
|
||||
data:data
|
||||
})
|
||||
return execWithBleFirst(
|
||||
() => protocolInstance.setVoiceBroadcast(data.voiceBroadcast).then(() => ({ code: 200, msg: '操作成功(蓝牙)' })),
|
||||
() => request({ url: `/app/hby100j/device/voiceBroadcast`, method: 'post', data }),
|
||||
'语音播报'
|
||||
);
|
||||
}
|
||||
@ -23,7 +23,7 @@
|
||||
paddingRight: config.dividerMargin
|
||||
}" @click="handleItemClick(item, index)">
|
||||
|
||||
<view class="p100" :style="{backgroundColor:(config.activeIndex==index || item[config.valueMember]==config.value) ?config.itemBgColor:'',
|
||||
<view class="p100" :data-acIdx="config.activeIndex" :data-ac="config.activeIndex==index" :style="{backgroundColor:(config.activeIndex==index || (item[config.valueMember]==config.value && config.value) ) ?config.itemBgColor:'',
|
||||
justifyContent:config.textAlign
|
||||
}">
|
||||
<view class="imgContent" v-if="item.icon" :style="{
|
||||
|
||||
@ -14,7 +14,7 @@
|
||||
default: () => [],
|
||||
validator: (value) => value.every(item => typeof item === 'string')
|
||||
},
|
||||
|
||||
|
||||
fontSize: {
|
||||
type: Number,
|
||||
default: 16,
|
||||
@ -27,6 +27,10 @@
|
||||
color: {
|
||||
type: String,
|
||||
default: "#000000"
|
||||
},
|
||||
maxLength: {
|
||||
type: Number,
|
||||
default: 5
|
||||
}
|
||||
},
|
||||
data() {
|
||||
@ -145,13 +149,21 @@
|
||||
return hexString;
|
||||
}
|
||||
|
||||
let convertCharToMatrix = (imageData, item) => {
|
||||
let convertCharToMatrix = (imageData) => {
|
||||
const charWidth = 13;
|
||||
const charHeight = 13;
|
||||
const pixels = [];
|
||||
for (let i = 0; i < imageData.length; i += 4) {
|
||||
// const R = imageData[i];
|
||||
// pixels.push(R < 128 ? 1 : 0);
|
||||
|
||||
|
||||
const R = imageData[i];
|
||||
pixels.push(R < 128 ? 1 : 0);
|
||||
const G = imageData[i + 1];
|
||||
const B = imageData[i + 2];
|
||||
const gray = 0.299 * R + 0.587 * G + 0.114 * B; // 灰度转换
|
||||
pixels.push(gray < 128 ? 1 : 0);
|
||||
|
||||
}
|
||||
|
||||
const lowBytes = new Array(charWidth).fill(0);
|
||||
@ -173,11 +185,12 @@
|
||||
}
|
||||
|
||||
let drawTxt = async (textLine) => {
|
||||
debugger;
|
||||
let result = {};
|
||||
let ctx = this.ctx;
|
||||
|
||||
// 1. 动态调整Canvas尺寸
|
||||
this.currentCanvasWidth = 13;
|
||||
this.currentCanvasWidth = 13 * this.maxLength;
|
||||
this.currentCanvasHeight = 13;
|
||||
|
||||
// 2. 清空Canvas(绘制背景)
|
||||
@ -191,16 +204,15 @@
|
||||
ctx.font = `${this.fontSize}px "PingFangBold", "PingFang SC", Arial, sans-serif`;
|
||||
|
||||
// 4. 绘制当前行文本
|
||||
let currentX = 0;
|
||||
let currentY = this.fontSize / 2 + 1;
|
||||
for (let j = 0; j < textLine.length; j++) {
|
||||
let char = textLine[j];
|
||||
ctx.fillText(char, currentX, currentY);
|
||||
// 按实际字符宽度计算间距
|
||||
let charWidth = ctx.measureText(char).width;
|
||||
currentX += charWidth;
|
||||
}
|
||||
debugger;
|
||||
|
||||
|
||||
let currentX =(this.maxLength - textLine.length) * this.fontSize / 2;
|
||||
|
||||
|
||||
let currentY = this.fontSize / 2 + 1;
|
||||
ctx.fillText(textLine, currentX, currentY);
|
||||
|
||||
// 5. 异步绘制并获取像素数据(串行处理避免冲突)
|
||||
await new Promise((resolve, reject) => {
|
||||
ctx.draw(false, () => {
|
||||
@ -212,11 +224,14 @@
|
||||
width: this.currentCanvasWidth,
|
||||
height: this.currentCanvasHeight,
|
||||
success: res => {
|
||||
debugger;
|
||||
result = {
|
||||
line: textLine,
|
||||
pixelData: res.data,
|
||||
width: this.currentCanvasWidth,
|
||||
height: this.currentCanvasHeight
|
||||
width: this
|
||||
.currentCanvasWidth,
|
||||
height: this
|
||||
.currentCanvasHeight
|
||||
};
|
||||
resolve();
|
||||
},
|
||||
@ -234,15 +249,34 @@
|
||||
let arr = [];
|
||||
// 循环处理每行文本
|
||||
for (let i = 0; i < this.validTxts.length; i++) {
|
||||
|
||||
debugger;
|
||||
let linePixls = [];
|
||||
let item = this.validTxts[i];
|
||||
// console.log("item=", item);
|
||||
for (var j = 0; j < item.length; j++) {
|
||||
let result = await drawTxt(item[j]);
|
||||
linePixls.push(convertCharToMatrix(result.pixelData, item));
|
||||
let res = await drawTxt(item);
|
||||
let rawData= res.pixelData;
|
||||
|
||||
|
||||
let result = [[], [], [], [], []];
|
||||
|
||||
|
||||
|
||||
for (let char = 0; char < 5; char++) {
|
||||
for (let row = 0; row < 13; row++) {
|
||||
let start = row * (5 * 52) + char * 52 + 1;
|
||||
let end = start + 51;
|
||||
|
||||
for (let i = 0; i < 52; i++) {
|
||||
result[char].push(rawData[start + i]);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
// console.log("hexs=", linePixls.join(","));
|
||||
debugger;
|
||||
for (var j = 0; j < result.length; j++) {
|
||||
|
||||
linePixls.push(convertCharToMatrix(result[j]));
|
||||
}
|
||||
|
||||
arr.push(linePixls);
|
||||
}
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
"name" : "星汉物联",
|
||||
"appid" : "__UNI__A21EF43",
|
||||
"description" : "设备管控",
|
||||
"versionName" : "1.0.19",
|
||||
"versionName" : "1.0.24",
|
||||
"versionCode" : 101,
|
||||
"transformPx" : false,
|
||||
/* 5+App特有相关 */
|
||||
@ -56,7 +56,8 @@
|
||||
"<uses-permission android:name=\"android.permission.ACCESS_COARSE_LOCATION\"/>",
|
||||
"<uses-permission android:name=\"android.permission.READ_EXTERNAL_STORAGE\"/>",
|
||||
"<uses-permission android:name=\"android.permission.a\"/>",
|
||||
"<uses-permission android:name=\"android.permission.BLUETOOTH_CONNECT\"/>"
|
||||
"<uses-permission android:name=\"android.permission.BLUETOOTH_CONNECT\"/>",
|
||||
"<uses-permission android:name=\"android.permission.BLUETOOTH_SCAN\"/>"
|
||||
],
|
||||
"minSdkVersion" : 21,
|
||||
"abiFilters" : [ "armeabi-v7a", "arm64-v8a", "x86" ],
|
||||
|
||||
@ -95,7 +95,7 @@
|
||||
|
||||
|
||||
|
||||
<view style="padding-bottom: 20rpx;">
|
||||
<view style="padding-bottom: 20rpx;">
|
||||
|
||||
|
||||
<view class="proinfo lamp">
|
||||
@ -355,6 +355,15 @@
|
||||
},
|
||||
onShow() {
|
||||
this.Status.pageHide = false;
|
||||
|
||||
let f = this.getDevice();
|
||||
if (f) {
|
||||
these.formData.bleStatu = 'connecting';
|
||||
ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId).then(res => {
|
||||
console.log("连接成功")
|
||||
these.formData.bleStatu = true;
|
||||
});
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
|
||||
@ -363,14 +372,14 @@
|
||||
methods: {
|
||||
|
||||
LighSetting(item, index) {
|
||||
let val=item.key;
|
||||
let val = item.key;
|
||||
if (item.key === this.formData.sta_LedType) {
|
||||
val='led_off';
|
||||
|
||||
val = 'led_off';
|
||||
|
||||
}
|
||||
|
||||
|
||||
let f = this.getDevice();
|
||||
|
||||
|
||||
// #ifdef APP-PLUS
|
||||
if (!f) {
|
||||
this.showBleUnConnect();
|
||||
@ -382,7 +391,7 @@
|
||||
deviceId: '12345'
|
||||
}
|
||||
// #endif
|
||||
|
||||
|
||||
let json = {
|
||||
ins_LedType: val
|
||||
}
|
||||
@ -390,10 +399,10 @@
|
||||
ble.sendString(f.deviceId, json, f.writeServiceId, f.wirteCharactId, 30).then(res => {
|
||||
this.formData.sta_LedType = val;
|
||||
these.setBleFormData();
|
||||
|
||||
|
||||
}).catch(ex => {
|
||||
this.showMsg(ex.msg);
|
||||
|
||||
|
||||
});
|
||||
},
|
||||
|
||||
@ -501,13 +510,13 @@
|
||||
|
||||
},
|
||||
deviceDispose(res) {
|
||||
if (this.Status.pageHide) {
|
||||
return;
|
||||
}
|
||||
// if (this.Status.pageHide) {
|
||||
// return;
|
||||
// }
|
||||
if (res.deviceId == these.formData.deviceId) {
|
||||
if(res.device){
|
||||
if (res.device) {
|
||||
these.formData.bleStatu = 'connecting';
|
||||
}else{
|
||||
} else {
|
||||
this.formData.bleStatu = false;
|
||||
}
|
||||
setTimeout(() => {
|
||||
|
||||
@ -194,7 +194,7 @@
|
||||
<view class="slider-container">
|
||||
<slider min="10" max="100" step="10" :disabled="false" :value="formData.sta_LightDimmer"
|
||||
activeColor="#bbe600" backgroundColor="#686767" block-size="20" block-color="#ffffffde"
|
||||
@change="onBrightnessChanging" @changing="onBrightnessChanging" class="custom-slider" />
|
||||
@change="onBrightnessChanged" @changing="onBrightnessChanging" class="custom-slider" />
|
||||
|
||||
</view>
|
||||
<view class="line"></view>
|
||||
@ -206,7 +206,7 @@
|
||||
<view class="slider-container">
|
||||
<slider min="0.5" max="10" step="0.5" :disabled="false" :value="formData.sta_LightFreq"
|
||||
activeColor="#bbe600" backgroundColor="#686767" block-size="20" block-color="#ffffffde"
|
||||
@change="onFreqChanging" @changing="onFreqChanging" class="custom-slider" />
|
||||
@change="onFreqChanged" @changing="onFreqChanging" class="custom-slider" />
|
||||
|
||||
</view>
|
||||
<view class="line"></view>
|
||||
@ -218,7 +218,7 @@
|
||||
<view class="slider-container">
|
||||
<slider min="1" max="8" step="1" :disabled="false" :value="formData.sta_VoiceVolume"
|
||||
activeColor="#bbe600" backgroundColor="#686767" block-size="20" block-color="#ffffffde"
|
||||
@change="onVolumeChanging" @changing="onVolumeChanging" class="custom-slider" />
|
||||
@change="onVolumeChanged" @changing="onVolumeChanging" class="custom-slider" />
|
||||
</view>
|
||||
|
||||
|
||||
@ -519,7 +519,7 @@
|
||||
ble = BleTool.getBleTool();
|
||||
|
||||
this.$watch("formData.sta_battery", (newVal, oldVal) => {
|
||||
if (newVal <= 20 && this.formData.sta_system==2) {
|
||||
if (newVal <= 20 && this.formData.sta_system == 2) {
|
||||
this.showMsg("设备电量低");
|
||||
}
|
||||
});
|
||||
@ -595,6 +595,15 @@
|
||||
},
|
||||
onShow() {
|
||||
this.Status.pageHide = false;
|
||||
|
||||
let f = this.getDevice();
|
||||
if (f) {
|
||||
these.formData.bleStatu = 'connecting';
|
||||
ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId).then(res => {
|
||||
console.log("连接成功")
|
||||
these.formData.bleStatu = true;
|
||||
});
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
getbleStatu() {
|
||||
@ -841,9 +850,11 @@
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
onFreqChanging(e){
|
||||
this.formData.sta_LightFreq = e.detail.value;
|
||||
},
|
||||
//频率
|
||||
onFreqChanging(e) {
|
||||
onFreqChanged(e) {
|
||||
let f = this.getDevice();
|
||||
// #ifdef APP-PLUS
|
||||
if (!f) {
|
||||
@ -888,8 +899,11 @@
|
||||
|
||||
}, 100);
|
||||
},
|
||||
onVolumeChanging(e){
|
||||
this.formData.sta_VoiceVolume = e.detail.value;
|
||||
},
|
||||
//音量
|
||||
onVolumeChanging(e) {
|
||||
onVolumeChanged(e) {
|
||||
let f = this.getDevice();
|
||||
// #ifdef APP-PLUS
|
||||
if (!f) {
|
||||
@ -929,8 +943,11 @@
|
||||
|
||||
}, 100);
|
||||
},
|
||||
onBrightnessChanging(e){
|
||||
this.formData.sta_LightDimmer = e.detail.value;
|
||||
},
|
||||
// 亮度调节
|
||||
onBrightnessChanging(e) {
|
||||
onBrightnessChanged(e) {
|
||||
let f = this.getDevice();
|
||||
// #ifdef APP-PLUS
|
||||
if (!f) {
|
||||
@ -1197,9 +1214,9 @@
|
||||
|
||||
},
|
||||
deviceDispose(res) {
|
||||
if (this.Status.pageHide) {
|
||||
return;
|
||||
}
|
||||
// if (this.Status.pageHide) {
|
||||
// return;
|
||||
// }
|
||||
if (res.deviceId == these.formData.deviceId) {
|
||||
if (res.device) {
|
||||
these.formData.bleStatu = 'connecting';
|
||||
|
||||
@ -37,13 +37,26 @@
|
||||
<text class="value">{{ deviceInfo.deviceName }}</text>
|
||||
</view>
|
||||
<view class="item">
|
||||
<text class="lbl">IMEI</text>
|
||||
<text class="lbl">设备IMEI</text>
|
||||
<text class="value">{{ deviceInfo.deviceImei }}</text>
|
||||
</view>
|
||||
<view class="item">
|
||||
<text class="lbl">Mac地址</text>
|
||||
<text class="value">{{device.deviceMac}}</text>
|
||||
</view>
|
||||
<view class="item">
|
||||
<text class="lbl">蓝牙名称</text>
|
||||
<text class="value valueFont">{{device.bluetoothName}}</text>
|
||||
</view>
|
||||
<view class="item" @click.top="bleStatuToggle">
|
||||
<text class="lbl">蓝牙状态</text>
|
||||
<text class="value"
|
||||
:class="(!formData.bleStatu || formData.bleStatu==='err')?'red':'green'">{{getbleStatu}}</text>
|
||||
</view>
|
||||
<view class="item">
|
||||
<text class="lbl">设备状态</text>
|
||||
<text class="value">{{ deviceInfo.onlineStatus === 0 ? '离线' : deviceInfo.onlineStatus
|
||||
=== 2 ? '故障' : '在线' }}</text>
|
||||
<text class="value"
|
||||
:class="deviceInfo.onlineStatus===0?'red':'green'">{{ deviceInfo.onlineStatus === 0 ? '离线': '在线' }}</text>
|
||||
</view>
|
||||
<view class="info-row">
|
||||
<text class="info-label" style="display: flex; align-items: center;">定位信息</text>
|
||||
@ -231,7 +244,10 @@
|
||||
deviceUpdateVolume,
|
||||
deviceVoiceBroadcast,
|
||||
updateBleStatus,
|
||||
parseBleData
|
||||
getBleStatus,
|
||||
parseBleData,
|
||||
fetchBlePowerStatus,
|
||||
fetchBleLocation
|
||||
} from '@/api/100J/HBY100-J.js'
|
||||
import BleHelper from '@/utils/BleHelper.js';
|
||||
var bleTool = BleHelper.getBleTool();
|
||||
@ -440,7 +456,7 @@
|
||||
alarmStatus: null,
|
||||
detailPageUrl: "/pages/650/HBY650",
|
||||
showConfirm: false,
|
||||
deviceId:''
|
||||
deviceId: ''
|
||||
},
|
||||
permissions: [],
|
||||
audioData: {
|
||||
@ -454,6 +470,17 @@
|
||||
onLoad: function() {
|
||||
const eventChannel = this.getOpenerEventChannel();
|
||||
var these = this;
|
||||
|
||||
this.$watch("deviceInfo.batteryPercentage", (newVal, oldVal) => {
|
||||
if (newVal <= 20) {
|
||||
uni.showToast({
|
||||
title: '设备电量低',
|
||||
icon: 'none',
|
||||
duration: 2000
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
eventChannel.on('detailData', function(data) {
|
||||
var device = data.data;
|
||||
these.device = device;
|
||||
@ -589,30 +616,26 @@
|
||||
these.fetchDeviceDetail(data.data.id)
|
||||
} else {
|
||||
this.activePermissions = data.data.permission ? data.data.permission.split(',') : [];
|
||||
console.log(this.activePermissions,'this.activePermissions');
|
||||
console.log(this.activePermissions, 'this.activePermissions');
|
||||
these.fetchDeviceDetail(data.data.deviceId)
|
||||
}
|
||||
|
||||
// 尝试连接蓝牙:需先扫描获取 BLE deviceId,不能直接用 MAC;延迟 500ms 确保蓝牙适配器就绪
|
||||
if (data.data.deviceMac) {
|
||||
setTimeout(() => {
|
||||
these.tryConnect100JBle(data.data.deviceMac);
|
||||
}, 500);
|
||||
}
|
||||
});
|
||||
this.createThrottledFunctions();
|
||||
|
||||
|
||||
// 注册蓝牙相关事件
|
||||
bleTool.addReceiveCallback(this.bleValueNotify, "HBY100J");
|
||||
bleTool.addReceiveCallback(this.bleValueNotify.bind(this), "HBY100J");
|
||||
bleTool.addDisposeCallback(this.bleStateBreak, "HBY100J");
|
||||
bleTool.addRecoveryCallback(this.bleStateRecovry, "HBY100J");
|
||||
bleTool.addStateBreakCallback(this.bleStateBreak, "HBY100J");
|
||||
bleTool.addStateRecoveryCallback(this.bleStateRecovry, "HBY100J");
|
||||
|
||||
// 尝试连接蓝牙
|
||||
if (data.data.deviceMac) {
|
||||
// 假设 deviceMac 是蓝牙的 deviceId
|
||||
bleTool.LinkBlue(data.data.deviceMac).then(() => {
|
||||
console.log("100J 蓝牙连接成功");
|
||||
this.bleStateRecovry({deviceId: data.data.deviceMac});
|
||||
}).catch(err => {
|
||||
console.log("100J 蓝牙连接失败,将使用4G", err);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
},
|
||||
onHide: function() {
|
||||
@ -625,15 +648,60 @@
|
||||
bleTool.removeRecoveryCallback("HBY100J");
|
||||
bleTool.removeStateBreakCallback("HBY100J");
|
||||
bleTool.removeStateRecoveryCallback("HBY100J");
|
||||
bleTool.removeDeviceFound("HBY100J_SCAN");
|
||||
bleTool.StopSearch();
|
||||
},
|
||||
onShow() {
|
||||
this.Status.pageHide = false;
|
||||
},
|
||||
computed: {
|
||||
|
||||
getbleStatu() {
|
||||
if (this.formData.bleStatu === true) {
|
||||
return '已连接';
|
||||
}
|
||||
if (this.formData.bleStatu === 'connecting') {
|
||||
return '连接中';
|
||||
}
|
||||
if (this.formData.bleStatu === 'dicconnect') {
|
||||
return '正在断开';
|
||||
}
|
||||
if (this.formData.bleStatu === 'err') {
|
||||
return '连接异常';
|
||||
}
|
||||
return '未连接';
|
||||
}
|
||||
},
|
||||
|
||||
methods: {
|
||||
bleStatuToggle() {
|
||||
let f = bleTool.data.LinkedList.find((v) => {
|
||||
return v.macAddress == this.device.deviceMac;
|
||||
});
|
||||
|
||||
if (!f) {
|
||||
this.tryConnect100JBle(this.device.deviceMac);
|
||||
return;
|
||||
}
|
||||
if (this.formData.bleStatu === true) {
|
||||
this.formData.bleStatu = 'dicconnect';
|
||||
bleTool.disconnectDevice(f.deviceId).finally(r => {
|
||||
this.formData.bleStatu = false;
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.formData.bleStatu === false || this.formData.bleStatu === 'err') {
|
||||
this.formData.bleStatu = 'connecting';
|
||||
bleTool.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId).then(res => {
|
||||
these.formData.bleStatu = true;
|
||||
}).catch(ex => {
|
||||
these.formData.bleStatu = 'err';
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
},
|
||||
createThrottledFunctions() {
|
||||
// 创建节流函数
|
||||
this.throttledBrightnessChange = this.throttle(this.handleBrightnessChange, 500);
|
||||
@ -704,16 +772,17 @@
|
||||
}
|
||||
})
|
||||
},
|
||||
// 语音管理
|
||||
// 语音管理(传递蓝牙状态,确保子页走蓝牙优先)
|
||||
audioManager(item) {
|
||||
if (this.Status.apiType !== 'listA') {}
|
||||
const ble = getBleStatus();
|
||||
uni.navigateTo({
|
||||
url: '/pages/100J/audioManager/AudioList',
|
||||
events: {},
|
||||
success: (res) => {
|
||||
// 页面跳转成功后的回调函数
|
||||
res.eventChannel.emit('deviceData', {
|
||||
data: item
|
||||
data: item,
|
||||
ble
|
||||
});
|
||||
},
|
||||
});
|
||||
@ -979,29 +1048,233 @@
|
||||
|
||||
deviceRecovry(res) {},
|
||||
deviceDispose(res) {},
|
||||
// 100J 蓝牙连接:先查缓存/尝试直连,失败则扫描
|
||||
// 注意:Android 的 createBLEConnection 需要系统返回的 deviceId,服务端 MAC(11:22:33:44:55:02) 与 deviceId(02:55:44:33:22:11) 字节序相反
|
||||
tryConnect100JBle(deviceMac) {
|
||||
const that = this;
|
||||
const macNorm = (m) => (m || '').replace(/:/g, '').toUpperCase();
|
||||
const targetMacNorm = macNorm(deviceMac);
|
||||
const last6 = targetMacNorm.slice(-6);
|
||||
// Android BLE deviceId 多为 MAC 字节反序,如 11:22:33:44:55:02 -> 02:55:44:33:22:11
|
||||
const macToDeviceId = (mac) => {
|
||||
const parts = (mac || '').split(':').filter(Boolean);
|
||||
return parts.length === 6 ? parts.reverse().join(':') : mac;
|
||||
};
|
||||
|
||||
// 1. 查缓存:之前连过且 mac 匹配
|
||||
const cached = bleTool.data.LinkedList.find(v => {
|
||||
const m = macNorm(v.macAddress);
|
||||
return m === targetMacNorm || m.slice(-6) === last6;
|
||||
});
|
||||
const SVC = '0000AE30-0000-1000-8000-00805F9B34FB';
|
||||
const WRITE = '0000AE03-0000-1000-8000-00805F9B34FB';
|
||||
const NOTIFY = '0000AE02-0000-1000-8000-00805F9B34FB';
|
||||
if (cached && cached.deviceId) {
|
||||
console.log('[100J] 使用缓存设备连接', cached.deviceId);
|
||||
that.formData.bleStatu = 'connecting';
|
||||
bleTool.LinkBlue(cached.deviceId, SVC, WRITE, NOTIFY, 2).then(() => {
|
||||
console.log('100J 蓝牙连接成功(缓存)');
|
||||
that.formData.bleStatu = true;
|
||||
that.bleStateRecovry({
|
||||
deviceId: cached.deviceId
|
||||
});
|
||||
}).catch(err => {
|
||||
console.log('100J 蓝牙连接失败(缓存),尝试扫描', err);
|
||||
that.formData.bleStatu = 'err';
|
||||
that.connect100JByScan(deviceMac, last6);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// 2. 无缓存:先尝试直连。Android 上 deviceId 多为 MAC 反序(11:22:33:44:55:02->02:55:44:33:22:11)
|
||||
that.formData.bleStatu = 'connecting';
|
||||
const tryDirect = (id) => bleTool.LinkBlue(id, SVC, WRITE, NOTIFY, 2).then(() => {
|
||||
console.log('100J 蓝牙连接成功(直连)', id);
|
||||
that.formData.bleStatu = true;
|
||||
that.bleStateRecovry({
|
||||
deviceId: id
|
||||
});
|
||||
}).catch(ex => {
|
||||
that.formData.bleStatu = 'err';
|
||||
});
|
||||
const deviceIdReversed = macToDeviceId(deviceMac);
|
||||
console.log('[100J] 尝试直连', deviceIdReversed, '(MAC反序)');
|
||||
tryDirect(deviceIdReversed).catch(() => {
|
||||
if (deviceIdReversed !== deviceMac) {
|
||||
console.log('[100J] 反序直连失败,尝试原 MAC', deviceMac);
|
||||
return tryDirect(deviceMac);
|
||||
}
|
||||
return Promise.reject();
|
||||
}).catch(() => {
|
||||
console.log('[100J] 蓝牙直连失败,开始扫描');
|
||||
that.connect100JByScan(deviceMac, last6);
|
||||
});
|
||||
},
|
||||
connect100JByScan(deviceMac, last6) {
|
||||
const that = this;
|
||||
const SVC = '0000AE30-0000-1000-8000-00805F9B34FB';
|
||||
const WRITE = '0000AE03-0000-1000-8000-00805F9B34FB';
|
||||
const NOTIFY = '0000AE02-0000-1000-8000-00805F9B34FB';
|
||||
let resolved = false;
|
||||
const timeout = 15000;
|
||||
const timer = setTimeout(() => {
|
||||
if (resolved) return;
|
||||
resolved = true;
|
||||
bleTool.StopSearch();
|
||||
bleTool.removeDeviceFound('HBY100J_SCAN');
|
||||
console.log('100J 蓝牙扫描超时,将使用4G');
|
||||
}, timeout);
|
||||
|
||||
bleTool.addDeviceFound((res) => {
|
||||
if (resolved) return;
|
||||
const devices = res.devices || [];
|
||||
const match = devices.find(d => {
|
||||
const name = (d.name || '').replace(/\r\n/g, '').trim();
|
||||
return name === 'HBY100J' || name.startsWith('LED-') && name.slice(-6) === last6;
|
||||
});
|
||||
if (match) {
|
||||
resolved = true;
|
||||
clearTimeout(timer);
|
||||
bleTool.StopSearch();
|
||||
bleTool.removeDeviceFound('HBY100J_SCAN');
|
||||
console.log('[100J] 扫描到目标设备', match.name, match.deviceId);
|
||||
that.formData.bleStatu = 'connecting';
|
||||
bleTool.LinkBlue(match.deviceId, SVC, WRITE, NOTIFY, 2).then(() => {
|
||||
console.log('100J 蓝牙连接成功(扫描)');
|
||||
that.formData.bleStatu = true;
|
||||
that.bleStateRecovry({
|
||||
deviceId: match.deviceId
|
||||
});
|
||||
}).catch(err => {
|
||||
console.log('100J 蓝牙连接失败,将使用4G', err);
|
||||
that.formData.bleStatu = 'err';
|
||||
});
|
||||
}
|
||||
}, 'HBY100J_SCAN');
|
||||
|
||||
bleTool.StartSearch().then(() => {
|
||||
console.log('[100J] 开始扫描蓝牙,设备名 HBY100J 或 LED-' + last6);
|
||||
}).catch(err => {
|
||||
if (!resolved) {
|
||||
resolved = true;
|
||||
clearTimeout(timer);
|
||||
bleTool.removeDeviceFound('HBY100J_SCAN');
|
||||
console.log('100J 蓝牙扫描启动失败,将使用4G', err);
|
||||
}
|
||||
});
|
||||
},
|
||||
bleStateBreak() {
|
||||
this.formData.bleStatu = false;
|
||||
updateBleStatus(false, '', this.deviceInfo.deviceId);
|
||||
},
|
||||
bleStateRecovry(res) {
|
||||
let bleDeviceId = res ? res.deviceId : '';
|
||||
// 蓝牙适配器恢复可用(关闭蓝牙后重新开启):无 deviceId,需主动重连
|
||||
if (!res || !res.deviceId) {
|
||||
const mac = (this.device && this.device.deviceMac) || (this.deviceInfo && this.deviceInfo.deviceMac);
|
||||
if (mac) {
|
||||
console.log('[100J] 蓝牙适配器已恢复,尝试重连', mac);
|
||||
this.tryConnect100JBle(mac);
|
||||
}
|
||||
return;
|
||||
}
|
||||
let bleDeviceId = res.deviceId;
|
||||
updateBleStatus(true, bleDeviceId, this.deviceInfo.deviceId);
|
||||
// 蓝牙连接成功后主动拉取电源状态、定位(优先蓝牙,设备也会每1分钟主动上报)
|
||||
// 两指令间隔 150ms,避免 writeBLECharacteristicValue:fail property not support
|
||||
fetchBlePowerStatus()
|
||||
.then(() => new Promise(r => setTimeout(r, 150)))
|
||||
.then(() => fetchBleLocation())
|
||||
.catch(() => {});
|
||||
},
|
||||
previewImg(img) {},
|
||||
bleValueNotify: function(receive, device, path, recArr) { //订阅消息
|
||||
// 注意:这里 receive.deviceId 是蓝牙的 MAC 地址,而 this.formData.deviceId 是 4G 的 ID
|
||||
// 所以这里需要修改判断逻辑,或者不判断直接解析
|
||||
|
||||
// 尝试解析蓝牙上报的数据
|
||||
if (receive.bytes) {
|
||||
const parsedData = parseBleData(receive.bytes);
|
||||
if (parsedData && parsedData.batteryPercentage !== undefined) {
|
||||
this.deviceInfo.batteryPercentage = parsedData.batteryPercentage;
|
||||
}
|
||||
// 仅处理当前设备的数据(device 为 LinkedList 中匹配 receive.deviceId 的项)
|
||||
if (device && device.device && this.deviceInfo.deviceId && device.device.id != this.deviceInfo
|
||||
.deviceId) return;
|
||||
// 解析蓝牙上报数据 (协议: FC=MAC主动上报, FB=指令响应)
|
||||
if (!receive.bytes || receive.bytes.length < 3) return;
|
||||
const parsedData = parseBleData(receive.bytes);
|
||||
if (!parsedData) return;
|
||||
|
||||
// 5.1 连接后设备主动上报 MAC 地址 (FC + 6字节 + FF)
|
||||
if (parsedData.type === 'mac' && parsedData.macAddress) {
|
||||
this.formData.macAddress = parsedData.macAddress;
|
||||
this.device.deviceMac = parsedData.macAddress;
|
||||
this.$set(this.deviceInfo, 'deviceMac', parsedData.macAddress);
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.deviceInfo.batteryPercentage <= 20) {
|
||||
this.showMsg("设备电量低");
|
||||
// 5.4 设备位置 (0x03):主动查询响应或设备定时上报(1分钟),优先蓝牙
|
||||
// 使用 $set 确保 Vue2 能检测新增属性并触发视图更新
|
||||
if (parsedData.longitude !== undefined && parsedData.latitude !== undefined) {
|
||||
this.$set(this.deviceInfo, 'longitude', parsedData.longitude);
|
||||
this.$set(this.deviceInfo, 'latitude', parsedData.latitude);
|
||||
}
|
||||
|
||||
// 5.5 获取设备电源状态 (0x04)
|
||||
if (parsedData.batteryPercentage !== undefined) {
|
||||
this.$set(this.deviceInfo, 'batteryPercentage', parsedData.batteryPercentage);
|
||||
}
|
||||
if (parsedData.batteryRemainingTime !== undefined) {
|
||||
this.$set(this.deviceInfo, 'batteryRemainingTime', parsedData.batteryRemainingTime);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 设备物理按键切换:蓝牙响应同步到 APP 页面(与 4G MQTT 逻辑一致)
|
||||
const fc = parsedData.funcCode;
|
||||
// 0x0C 强制报警:设备按键切换报警状态
|
||||
if (fc === 0x0C && parsedData.alarmEnable !== undefined) {
|
||||
if (parsedData.alarmEnable === 1) {
|
||||
this.$set(this.deviceInfo, 'voiceStrobeAlarm', 1);
|
||||
this.formData.sta_VoiceType = (parsedData.alarmMode ?? 0) + '';
|
||||
} else {
|
||||
this.$set(this.deviceInfo, 'voiceStrobeAlarm', -1);
|
||||
this.formData.sta_VoiceType = (parsedData.alarmMode ?? 0) + '';
|
||||
}
|
||||
}
|
||||
// 0x0A 爆闪模式:警示灯开关/模式
|
||||
if (fc === 0x0A && parsedData.strobeEnable !== undefined) {
|
||||
if (parsedData.strobeEnable === 1) {
|
||||
this.formData.sta_LightType = (parsedData.strobeMode ?? 0) + '';
|
||||
} else {
|
||||
this.formData.sta_LightType = '-1';
|
||||
}
|
||||
}
|
||||
// 0x0E 工作方式:综合状态(设备按键切换后上报)
|
||||
if (fc === 0x0E) {
|
||||
if (parsedData.strobeEnable !== undefined) {
|
||||
if (parsedData.strobeEnable === 1) {
|
||||
this.formData.sta_LightType = (parsedData.strobeMode ?? 0) + '';
|
||||
} else {
|
||||
this.formData.sta_LightType = '-1';
|
||||
}
|
||||
}
|
||||
if (parsedData.alarmEnable !== undefined) {
|
||||
if (parsedData.alarmEnable === 1) {
|
||||
this.$set(this.deviceInfo, 'voiceStrobeAlarm', 1);
|
||||
this.formData.sta_VoiceType = (parsedData.alarmMode ?? 0) + '';
|
||||
} else {
|
||||
this.$set(this.deviceInfo, 'voiceStrobeAlarm', -1);
|
||||
this.formData.sta_VoiceType = (parsedData.alarmMode ?? 0) + '';
|
||||
}
|
||||
}
|
||||
if (parsedData.voiceBroadcast !== undefined) {
|
||||
if (parsedData.voiceBroadcast === 1) this.formData.sta_VoiceType = '7';
|
||||
else if (this.formData.sta_VoiceType === '7') this.formData.sta_VoiceType = '-1';
|
||||
}
|
||||
if (parsedData.volume !== undefined) this.formData.volume = parsedData.volume;
|
||||
if (parsedData.strobeFrequency !== undefined) this.formData.strobeFrequency = parsedData
|
||||
.strobeFrequency;
|
||||
if (parsedData.redBrightness !== undefined) this.formData.lightBrightness = parsedData
|
||||
.redBrightness;
|
||||
}
|
||||
// 0x09 音量、0x0D 亮度:单独响应时同步
|
||||
if (fc === 0x09 && parsedData.volume !== undefined) this.formData.volume = parsedData.volume;
|
||||
if (fc === 0x0B && parsedData.strobeFrequency !== undefined) this.formData.strobeFrequency = parsedData
|
||||
.strobeFrequency;
|
||||
if (fc === 0x0D && parsedData.redBrightness !== undefined) this.formData.lightBrightness = parsedData
|
||||
.redBrightness;
|
||||
},
|
||||
showBleUnConnect() {},
|
||||
|
||||
|
||||
@ -104,8 +104,10 @@
|
||||
deviceVoliceList,
|
||||
videRenameAudioFile,
|
||||
deviceDeleteAudioFile,
|
||||
deviceUpdateVoice
|
||||
deviceUpdateVoice,
|
||||
updateBleStatus
|
||||
} from '@/api/100J/HBY100-J.js'
|
||||
import { baseURL } from '@/utils/request.js'
|
||||
import {
|
||||
showLoading,
|
||||
hideLoading,
|
||||
@ -217,6 +219,10 @@
|
||||
console.log(rec, 'ressss');
|
||||
this.blue = rec.ble;
|
||||
this.device = rec.data;
|
||||
// 同步蓝牙状态,确保语音上传走蓝牙优先
|
||||
if (rec.ble && (rec.ble.isConnected || rec.ble.bleDeviceId)) {
|
||||
updateBleStatus(!!rec.ble.isConnected, rec.ble.bleDeviceId || '', rec.data?.deviceId || '');
|
||||
}
|
||||
this.getinitData(rec.data.deviceId, true)
|
||||
});
|
||||
|
||||
@ -231,25 +237,46 @@
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
//语音管理列表
|
||||
//语音管理列表(合并云端 + 本地无网络保存的语音)
|
||||
getinitData(val, isLoadMore = false) {
|
||||
let data = {
|
||||
deviceId: this.device.deviceId
|
||||
}
|
||||
deviceVoliceList(data).then((res) => {
|
||||
const deviceId = this.device.deviceId;
|
||||
if (!deviceId) return;
|
||||
const mergeLocal = (serverList) => {
|
||||
const key = `100J_local_audio_${deviceId}`;
|
||||
const cacheKey = `100J_local_path_cache_${deviceId}`;
|
||||
const localList = uni.getStorageSync(key) || [];
|
||||
const pathCache = uni.getStorageSync(cacheKey) || {};
|
||||
const localMapped = localList.map(item => ({
|
||||
...item,
|
||||
fileNameExt: item.name || '本地语音',
|
||||
createTime: item._createTime || item.createTime || Common.DateFormat(new Date(), "yyyy年MM月dd日"),
|
||||
fileUrl: item.fileUrl || item.localPath,
|
||||
useStatus: 0,
|
||||
_isLocal: true
|
||||
}));
|
||||
const enriched = (serverList || []).map(item => {
|
||||
const urlKey = item.fileUrl || item.url || item.filePath || item.audioUrl || item.ossUrl;
|
||||
const localPath = pathCache[urlKey] || pathCache[item.id];
|
||||
return localPath ? { ...item, localPath } : item;
|
||||
});
|
||||
return [...localMapped, ...enriched];
|
||||
};
|
||||
deviceVoliceList({ deviceId }).then((res) => {
|
||||
if (res.code == 200) {
|
||||
this.total = res.total;
|
||||
const list = res.data.map(item => ({
|
||||
const list = (res.data || []).map(item => ({
|
||||
...item,
|
||||
createTime: item.createTime || Common.DateFormat(new Date(), "yyyy年MM月dd日")
|
||||
}));
|
||||
this.dataListA = list;
|
||||
// 通知mescroll加载完成
|
||||
if (this.mescroll) {
|
||||
this.mescroll.endBySize(list.length, this.total);
|
||||
}
|
||||
this.dataListA = mergeLocal(list);
|
||||
if (this.mescroll) this.mescroll.endBySize(this.dataListA.length, this.total + (this.dataListA.length - list.length));
|
||||
}
|
||||
})
|
||||
}).catch(() => {
|
||||
// 无网络时仅显示本地保存的语音
|
||||
this.dataListA = mergeLocal([]);
|
||||
this.total = this.dataListA.length;
|
||||
if (this.mescroll) this.mescroll.endBySize(this.dataListA.length, this.total);
|
||||
});
|
||||
},
|
||||
createAudioPlayer(localPath) {
|
||||
if (innerAudioContext) {
|
||||
@ -401,22 +428,24 @@
|
||||
return;
|
||||
}
|
||||
let task = () => {
|
||||
let data = {
|
||||
fileId: item.fileId,
|
||||
deviceId: this.device.deviceId
|
||||
if (item._isLocal) {
|
||||
// 本地项:从本地存储移除
|
||||
const key = `100J_local_audio_${this.device.deviceId}`;
|
||||
let list = uni.getStorageSync(key) || [];
|
||||
list = list.filter(l => l.id !== item.id && l.Id !== item.Id);
|
||||
uni.setStorageSync(key, list);
|
||||
uni.showToast({ title: '已删除', icon: 'none', duration: 1000 });
|
||||
this.getinitData();
|
||||
this.$refs.swipeAction.closeAll();
|
||||
return;
|
||||
}
|
||||
deviceDeleteAudioFile(data).then((res) => {
|
||||
deviceDeleteAudioFile({ fileId: item.fileId, deviceId: this.device.deviceId }).then((res) => {
|
||||
if (res.code == 200) {
|
||||
uni.showToast({
|
||||
title: res.msg,
|
||||
icon: 'none',
|
||||
duration: 1000
|
||||
});
|
||||
this.getinitData()
|
||||
// 关闭所有滑动项
|
||||
uni.showToast({ title: res.msg, icon: 'none', duration: 1000 });
|
||||
this.getinitData();
|
||||
this.$refs.swipeAction.closeAll();
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
this.showPop({
|
||||
showPop: true, //是否显示弹窗
|
||||
@ -468,71 +497,82 @@
|
||||
}
|
||||
},
|
||||
Apply(item, index) {
|
||||
this.mqttClient = new MqttClient();
|
||||
let data = {
|
||||
id: item.id
|
||||
this.updateProgress = 0;
|
||||
this.isUpdating = true;
|
||||
// 本地项优先用 localPath;云端项用 fileUrl(兼容多种字段名),相对路径补全 baseURL
|
||||
let fileUrl = '';
|
||||
let localPath = (item.localPath && typeof item.localPath === 'string') ? item.localPath : '';
|
||||
if (!item._isLocal) {
|
||||
const raw = item.fileUrl || item.url || item.filePath || item.audioUrl || item.ossUrl || '';
|
||||
fileUrl = (typeof raw === 'string' && raw) ? (raw.startsWith('/') ? (baseURL + raw) : raw) : '';
|
||||
} else {
|
||||
// 本地项:localPath 优先,无则用 fileUrl(mergeLocal 中可能只有 fileUrl 存路径)
|
||||
if (!localPath && item.fileUrl) localPath = item.fileUrl;
|
||||
}
|
||||
deviceUpdateVoice(data).then((RES) => {
|
||||
console.log(RES,'RES');
|
||||
if (RES.code == 200) {
|
||||
const data = {
|
||||
id: item.id,
|
||||
fileUrl,
|
||||
localPath,
|
||||
onProgress: (p) => { this.updateProgress = p; },
|
||||
onWaiting: () => { uni.showToast({ title: '等待蓝牙连接中...', icon: 'none', duration: 2000 }); }
|
||||
};
|
||||
// 整体超时 60 秒(仅影响蓝牙上传,4G HTTP 很快返回)
|
||||
const overallTimer = setTimeout(() => {
|
||||
if (this.isUpdating) {
|
||||
uni.showToast({ title: '操作超时', icon: 'none', duration: 2000 });
|
||||
this.isUpdating = false;
|
||||
this.updateProgress = 0;
|
||||
this.isUpdating = true;
|
||||
}
|
||||
}, 60000);
|
||||
deviceUpdateVoice(data).then((RES) => {
|
||||
clearTimeout(overallTimer);
|
||||
if (RES.code == 200) {
|
||||
// 蓝牙上传:进度已由 onProgress 更新,直接完成
|
||||
if (RES._channel === 'ble') {
|
||||
uni.showToast({ title: '音频上传成功', icon: 'success', duration: 2000 });
|
||||
this.isUpdating = false;
|
||||
setTimeout(() => { uni.navigateBack(); }, 1500);
|
||||
return;
|
||||
}
|
||||
// 4G:订阅 MQTT 获取设备端进度,6 秒超时
|
||||
this.upgradeTimer = setTimeout(() => {
|
||||
if (this.isUpdating) {
|
||||
uni.showToast({ title: '音频进度同步超时', icon: 'none', duration: 2000 });
|
||||
this.isUpdating = false;
|
||||
this.updateProgress = 0;
|
||||
}
|
||||
}, 6000);
|
||||
this.mqttClient = this.mqttClient || new MqttClient();
|
||||
this.mqttClient.connect(() => {
|
||||
// 订阅来自设备的状态更新
|
||||
const statusTopic = `status/894078/HBY100/${this.device.deviceImei}`;
|
||||
this.mqttClient.subscribe(statusTopic, (payload) => {
|
||||
console.log(payload, 'payloadpayloadpayload');
|
||||
try {
|
||||
// 解析MQTT返回的payload
|
||||
const payloadObj = typeof payload === 'string' ? JSON.parse(
|
||||
payload) : payload;
|
||||
// 取出进度值(用可选链避免字段不存在报错)
|
||||
const payloadObj = typeof payload === 'string' ? JSON.parse(payload) : payload;
|
||||
const progress = payloadObj.data?.progress;
|
||||
if (progress !== undefined && !isNaN(progress) && progress >=
|
||||
0 && progress <= 100) {
|
||||
if (progress !== undefined && !isNaN(progress) && progress >= 0 && progress <= 100) {
|
||||
this.updateProgress = progress;
|
||||
console.log('当前升级进度:', progress + '%');
|
||||
// 进度到100%时,触发升级完成逻辑
|
||||
if (progress === 100) {
|
||||
clearTimeout(this.upgradeTimer);
|
||||
uni.showToast({
|
||||
title: '升级完成!',
|
||||
icon: 'success',
|
||||
duration: 2000
|
||||
});
|
||||
uni.showToast({ title: '音频上传成功', icon: 'success', duration: 2000 });
|
||||
this.isUpdating = false;
|
||||
setTimeout(() => {
|
||||
uni.navigateBack();
|
||||
}, 1500);
|
||||
setTimeout(() => { uni.navigateBack(); }, 1500);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
clearTimeout(this.upgradeTimer);
|
||||
clearTimeout(this.upgradeTimer);
|
||||
console.error('解析MQTT payload失败:', e);
|
||||
}
|
||||
})
|
||||
})
|
||||
} else {
|
||||
uni.showToast({
|
||||
title: RES.msg,
|
||||
icon: 'none',
|
||||
duration: 1000
|
||||
});
|
||||
});
|
||||
|
||||
} else {
|
||||
this.isUpdating = false;
|
||||
uni.showToast({ title: RES.msg || '操作失败', icon: 'none', duration: 1000 });
|
||||
}
|
||||
})
|
||||
this.upgradeTimer = setTimeout(() => {
|
||||
// 超时后执行:隐藏进度条+提示超时+重置进度
|
||||
uni.showToast({
|
||||
title: '升级进度同步超时',
|
||||
icon: 'none',
|
||||
duration: 2000
|
||||
});
|
||||
this.isUpdating = false; // 关闭进度条
|
||||
this.updateProgress = 0; // 重置进度值
|
||||
// 可选:如果需要取消MQTT订阅,加这行(根据需求选择)
|
||||
// this.mqttClient.unsubscribe(statusTopic);
|
||||
}, 6000); // 6000ms = 6秒,时间可直接修改
|
||||
}).catch((err) => {
|
||||
clearTimeout(overallTimer);
|
||||
this.isUpdating = false;
|
||||
uni.showToast({ title: err.message || '操作失败', icon: 'none', duration: 2000 });
|
||||
});
|
||||
},
|
||||
closePop: function() {
|
||||
this.Status.Pop.showPop = false;
|
||||
|
||||
@ -421,6 +421,44 @@
|
||||
hideLoading(these);
|
||||
}, 1200);
|
||||
},
|
||||
// 无网络时保存到本地,供蓝牙直接发送(不依赖 OSS)
|
||||
// 将临时文件复制到持久化目录 _doc/100J_audio/,避免被系统清理
|
||||
saveLocalForBle(filePath) {
|
||||
const deviceId = these.Status.ID;
|
||||
if (!deviceId) return;
|
||||
const doSave = (persistentPath) => {
|
||||
const item = {
|
||||
...these.cEdit,
|
||||
localPath: persistentPath,
|
||||
fileUrl: '',
|
||||
deviceId,
|
||||
id: 'local_' + these.cEdit.Id,
|
||||
_createTime: these.cEdit.createTime || Common.DateFormat(new Date(), "yyyy年MM月dd日"),
|
||||
_isLocal: true
|
||||
};
|
||||
const key = `100J_local_audio_${deviceId}`;
|
||||
let list = uni.getStorageSync(key) || [];
|
||||
list.unshift(item);
|
||||
uni.setStorageSync(key, list);
|
||||
these.AudioData.tempFilePath = "";
|
||||
these.Status.isRecord = false;
|
||||
uni.navigateBack();
|
||||
};
|
||||
if (typeof plus !== 'undefined' && plus.io) {
|
||||
const fileName = 'audio_' + (these.cEdit.Id || Date.now()) + '.mp3';
|
||||
plus.io.resolveLocalFileSystemURL(filePath, (entry) => {
|
||||
plus.io.resolveLocalFileSystemURL('_doc/', (docEntry) => {
|
||||
docEntry.getDirectory('100J_audio', { create: true }, (dirEntry) => {
|
||||
entry.copyTo(dirEntry, fileName, (newEntry) => {
|
||||
doSave(newEntry.fullPath);
|
||||
}, () => { doSave(filePath); });
|
||||
}, () => { doSave(filePath); });
|
||||
}, () => { doSave(filePath); });
|
||||
}, () => { doSave(filePath); });
|
||||
} else {
|
||||
doSave(filePath);
|
||||
}
|
||||
},
|
||||
// 保存录音并上传(已修复文件格式问题)
|
||||
uploadLuYin() {
|
||||
// 文件类型验证
|
||||
@ -486,6 +524,19 @@
|
||||
}
|
||||
const resData = JSON.parse(res.data);
|
||||
if (resData.code === 200) {
|
||||
// 缓存本地路径,Apply 时优先用本地文件走蓝牙,避免下载失败
|
||||
const deviceId = these.Status.ID;
|
||||
if (deviceId) {
|
||||
const cacheKey = `100J_local_path_cache_${deviceId}`;
|
||||
const d = resData.data;
|
||||
const fileUrl = (d && typeof d === 'object' && d.fileUrl) || (typeof d === 'string' ? d : '');
|
||||
if (filePath) {
|
||||
let cache = uni.getStorageSync(cacheKey) || {};
|
||||
if (fileUrl) cache[fileUrl] = filePath;
|
||||
if (d && typeof d === 'object' && d.id) cache[d.id] = filePath;
|
||||
uni.setStorageSync(cacheKey, cache);
|
||||
}
|
||||
}
|
||||
// 合并两个存储操作
|
||||
Promise.all([
|
||||
new Promise((resolve, reject) => {
|
||||
@ -541,8 +592,10 @@
|
||||
},
|
||||
fail: (err) => {
|
||||
console.error('上传文件失败:', err);
|
||||
// 无网络时保存到本地,供蓝牙直接发送
|
||||
these.saveLocalForBle(filePath);
|
||||
uni.showToast({
|
||||
title: '上传失败,请检查网络',
|
||||
title: '网络不可用,已保存到本地,可通过蓝牙发送',
|
||||
icon: 'none',
|
||||
duration: 3000
|
||||
});
|
||||
|
||||
@ -60,12 +60,12 @@
|
||||
</view>
|
||||
<view class="item" @click.top="bleStatuToggle">
|
||||
<text class="lbl">蓝牙状态</text>
|
||||
<text class="value" :class="formData.bleStatu?'green':'red'">{{getbleStatu}}</text>
|
||||
<text class="value" :class="(!formData.bleStatu || formData.bleStatu==='err')?'red':'green'">{{getbleStatu}}</text>
|
||||
</view>
|
||||
<view class="item">
|
||||
<text class="lbl">信道:{{formData.sta_Channel}}</text>
|
||||
<text class="value green" @click.stop="ShowChannelEdit()">修改</text>
|
||||
</view>
|
||||
<!-- <view class="item">
|
||||
<text class="lbl">设备状态</text>
|
||||
<text class="value">{{formData.sta_charge?dic.sta_charge[formData.sta_charge]:"" }}</text>
|
||||
</view> -->
|
||||
</view>
|
||||
|
||||
<view class="warnnig" v-for="item,index in warnDevices">
|
||||
@ -177,7 +177,14 @@
|
||||
:iconUrl="Status.Pop.iconUrl" :message="Status.Pop.message" :buttonText="Status.Pop.buttonText"
|
||||
@buttonClick="HidePop" :visiblePrompt="Status.Pop.visiblePrompt" :promptTitle="Status.Pop.promptTitle"
|
||||
v-model="Status.Pop.modelValue" @closePop="closePop" :buttonCancelText="Status.Pop.buttonCancelText"
|
||||
:showCancel="Status.Pop.showCancel" @cancelPop="closePop" />
|
||||
:showCancel="Status.Pop.showCancel" @cancelPop="closePop" :showSlot="Status.Pop.showSlot">
|
||||
<view v-if="Status.ShowEditChannel" class="popup-prompt">
|
||||
<text class="popup-prompt-title">修改信道</text>
|
||||
<input class="popup-prompt-input" type="number" placeholder="1-125的整数"
|
||||
placeholder-class="popup-prompt-input-placeHolder" v-model="formData.ins_Channel" />
|
||||
|
||||
</view>
|
||||
</MessagePopup>
|
||||
|
||||
<!-- 下方菜单 -->
|
||||
|
||||
@ -221,6 +228,7 @@
|
||||
curr: 0,
|
||||
total: 0,
|
||||
pageHide: false,
|
||||
ShowEditChannel: false,
|
||||
Pop: {
|
||||
showPop: false, //是否显示弹窗
|
||||
popType: 'custom',
|
||||
@ -325,8 +333,8 @@
|
||||
warnTime: '',
|
||||
sta_sosadd: "",
|
||||
sta_sosName: '',
|
||||
sta_IntrusTime: ''
|
||||
|
||||
sta_IntrusTime: '',
|
||||
ins_Channel:23
|
||||
},
|
||||
dic: {
|
||||
sta_LightType: [
|
||||
@ -509,7 +517,17 @@
|
||||
},
|
||||
onShow() {
|
||||
this.Status.pageHide = false;
|
||||
this.getLinkedCnt();
|
||||
|
||||
let f = this.getDevice();
|
||||
if (f) {
|
||||
these.formData.bleStatu = 'connecting';
|
||||
ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId).then(res => {
|
||||
console.log("连接成功")
|
||||
these.formData.bleStatu = true;
|
||||
});
|
||||
}
|
||||
|
||||
// this.getLinkedCnt();
|
||||
},
|
||||
computed: {
|
||||
Distance: function() {
|
||||
@ -551,6 +569,73 @@
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
onChannelChanging() {
|
||||
|
||||
let f = this.getDevice();
|
||||
// #ifdef APP-PLUS
|
||||
if (!f) {
|
||||
this.showBleUnConnect();
|
||||
return;
|
||||
}
|
||||
// #endif
|
||||
|
||||
let regex = /^([1-9]|[1-7][0-9]|80)$/;
|
||||
if (!regex.test(this.formData.ins_Channel)) {
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: '只能输入1-80整数'
|
||||
});
|
||||
return;
|
||||
}
|
||||
var buffer = {
|
||||
ins_Channel: this.formData.ins_Channel
|
||||
}
|
||||
ble.sendString(f.deviceId, buffer);
|
||||
},
|
||||
ShowChannelEdit() {
|
||||
|
||||
if (!this.permissions.includes('55') && this.Status.apiType !== 'listA') {
|
||||
|
||||
this.showPop({
|
||||
message: '无操作权限',
|
||||
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
|
||||
borderColor: "#e034344d",
|
||||
buttonBgColor: "#E03434",
|
||||
okCallback: null,
|
||||
buttonText: "确定"
|
||||
})
|
||||
return;
|
||||
}
|
||||
|
||||
this.Status.ShowEditChannel = true;
|
||||
this.showPop({
|
||||
showPop: true, //是否显示弹窗
|
||||
popType: 'custom',
|
||||
bgColor: '#383934bd',
|
||||
borderColor: '#BBE600',
|
||||
textColor: '#ffffffde',
|
||||
buttonBgColor: '#BBE600',
|
||||
buttonTextColor: '#232323DE',
|
||||
iconUrl: '',
|
||||
message: '',
|
||||
buttonText: '确定',
|
||||
clickEvt: '',
|
||||
visiblePrompt: false,
|
||||
promptTitle: '',
|
||||
modelValue: '',
|
||||
visibleClose: false,
|
||||
okCallback: () => {
|
||||
this.onChannelChanging();
|
||||
this.Status.ShowEditChannel = false;
|
||||
},
|
||||
showSlot: true,
|
||||
buttonCancelText: '取消',
|
||||
showCancel: true,
|
||||
cancelCallback: () => {
|
||||
this.Status.ShowEditChannel = false;
|
||||
}
|
||||
});
|
||||
},
|
||||
getLinkedCnt() { //获取在线设备的数量
|
||||
|
||||
let f = this.getDevice();
|
||||
@ -975,13 +1060,13 @@
|
||||
|
||||
},
|
||||
deviceDispose(res) {
|
||||
if (this.Status.pageHide) {
|
||||
return;
|
||||
}
|
||||
// if (this.Status.pageHide) {
|
||||
// return;
|
||||
// }
|
||||
if (res.deviceId == these.formData.deviceId) {
|
||||
if(res.device){
|
||||
if (res.device) {
|
||||
these.formData.bleStatu = 'connecting';
|
||||
}else{
|
||||
} else {
|
||||
this.formData.bleStatu = false;
|
||||
}
|
||||
setTimeout(() => {
|
||||
@ -2256,4 +2341,30 @@
|
||||
/deep/ .uni-navbar--fixed {
|
||||
top: 0px;
|
||||
}
|
||||
|
||||
.popup-prompt-input {
|
||||
|
||||
width: 100%;
|
||||
height: 60rpx;
|
||||
line-height: 60rpx;
|
||||
color: rgba(255, 255, 255, 0.87);
|
||||
box-sizing: border-box;
|
||||
border-bottom: 2rpx solid rgba(255, 255, 255, 0.4);
|
||||
font-size: 28rpx;
|
||||
font-weight: 400;
|
||||
letter-spacing: 0.14px;
|
||||
}
|
||||
|
||||
.popup-prompt-input-placeHolder {
|
||||
color: rgba(255, 255, 255, 0.4);
|
||||
|
||||
font-family: PingFang SC;
|
||||
font-size: 28rpx;
|
||||
font-weight: 400;
|
||||
|
||||
letter-spacing: 0.14px;
|
||||
text-align: center;
|
||||
|
||||
}
|
||||
|
||||
</style>
|
||||
@ -10,8 +10,8 @@
|
||||
</uni-nav-bar>
|
||||
<view class="contentBg">
|
||||
<view class="row">
|
||||
<view class="typeItem fleft" :class="{'active':Status.tabType=='link'}" @click.stop="tabChange('link')">
|
||||
连接记录</view>
|
||||
<!-- <view class="typeItem fleft" :class="{'active':Status.tabType=='link'}" @click.stop="tabChange('link')">
|
||||
连接记录</view> -->
|
||||
<view class="typeItem fleft" :class="{'active':Status.tabType=='warn'}" @click.stop="tabChange('warn')">
|
||||
报警记录</view>
|
||||
<view class="filterIco fright" @click.stop="showFilter()">
|
||||
@ -90,7 +90,7 @@
|
||||
<view class="mothItem center" :class="{active:Status.filterDayType=='monthThree'}"
|
||||
@click.stop="mothItemChange('monthThree')">近三个月</view>
|
||||
<view class="mothItem center" :class="{active:Status.filterDayType=='monthOne'}"
|
||||
@click.stop="mothItemChange('monthOne')" }>近一个月</view>
|
||||
@click.stop="mothItemChange('monthOne')" >近一个月</view>
|
||||
<view class="mothItem center" :class="{active:Status.filterDayType=='customer'}"
|
||||
@click.stop="mothItemChange('customer')">自定义</view>
|
||||
|
||||
@ -204,7 +204,7 @@
|
||||
filterMode: true, //是否筛选日期
|
||||
filterDayMode: 'end', //当前筛选的是开始还是结束
|
||||
filterDayType: 'customer', //当前筛选的日期是哪种类型
|
||||
tabType: 'link',
|
||||
tabType: 'warn',
|
||||
|
||||
datePickValue: [999, 999, 999] //日期选择控件绑定的值
|
||||
|
||||
@ -251,10 +251,10 @@
|
||||
|
||||
let eventChannel = this.getOpenerEventChannel();
|
||||
|
||||
eventChannel.on('detailData', function(data) {
|
||||
eventChannel.on('detailData', (data)=> {
|
||||
var device = data.data;
|
||||
these.device = device;
|
||||
these.tabChange('link');
|
||||
this.device = device;
|
||||
this.tabChange('warn');
|
||||
});
|
||||
|
||||
|
||||
@ -304,7 +304,7 @@
|
||||
let today = new Date();
|
||||
let end = Common.DateFormat(today, 'yyyy-MM-dd');
|
||||
|
||||
let start = Common.DateFormat(today.setMonth(diff), 'yyyy-MM-dd');
|
||||
let start = Common.DateFormat(today.setMonth(today.getMonth()+ diff), 'yyyy-MM-dd');
|
||||
this.filter.start = start;
|
||||
this.filter.end = end;
|
||||
|
||||
@ -595,7 +595,9 @@
|
||||
if (!these.Status.filterMode) {
|
||||
if (these.filter.MM) {
|
||||
start = new Date(these.filter.MM + '-01');
|
||||
end = start.setMonth(1);
|
||||
end = new Date(these.filter.MM + '-01')
|
||||
end.setMonth(end.getMonth()+1);
|
||||
end.setDate(end.getDate()+1);
|
||||
data = data.filter(v => {
|
||||
|
||||
let t = v.linkEqs[0].linkTime
|
||||
@ -613,7 +615,7 @@
|
||||
console.log("these.filter.end=",these.filter.end);
|
||||
start = new Date(these.filter.start);
|
||||
end = new Date(these.filter.end);
|
||||
end.setMonth(1);
|
||||
end.setDate(end.getDate()+1);
|
||||
console.log("start=",start);
|
||||
console.log("end=",end);
|
||||
if(start && end){
|
||||
@ -643,7 +645,8 @@
|
||||
return t >= start;
|
||||
});
|
||||
} else if (these.filter.end) {
|
||||
end = new Date(these.filter.end).setMonth(1);
|
||||
end = new Date(these.filter.end);
|
||||
end.setDate(end.getDate()+1);
|
||||
|
||||
data = data.filter(v => {
|
||||
|
||||
@ -680,7 +683,7 @@
|
||||
if (systemInfo.uniPlatform == 'web') {
|
||||
|
||||
for (let i = 0; i < 20; i++) {
|
||||
const timestamp = 1710072900000 + (i * 3600000); // 每小时递增
|
||||
const timestamp = new Date().getTime() - (i * 3600000); // 每小时递增
|
||||
const numItems = Math.floor(Math.random() * 5) + 1; // 1-5条
|
||||
|
||||
const item = {
|
||||
@ -740,7 +743,8 @@
|
||||
console.log("hese.filter.end=" + these.filter.end);
|
||||
let start = new Date(these.filter.start);
|
||||
let end = new Date(these.filter.end);
|
||||
end.setMonth(1);
|
||||
|
||||
end.setDate(end.getDate()+ 1);
|
||||
data = data.filter(v => {
|
||||
|
||||
let t = v.warnTime
|
||||
@ -748,7 +752,7 @@
|
||||
t = new Date(v.warnTime);
|
||||
}
|
||||
|
||||
return t >= start && t <= end;
|
||||
return t >= start && t < end;
|
||||
});
|
||||
} else if (these.filter.start) {
|
||||
let start = new Date(these.filter.start);
|
||||
@ -762,7 +766,8 @@
|
||||
return t >= start;
|
||||
});
|
||||
} else if (these.filter.end) {
|
||||
let end = new Date(these.filter.end).setMonth(1);
|
||||
let end = new Date(these.filter.end);
|
||||
end.setDate(end.getDate()+ 1);
|
||||
data = data.filter(v => {
|
||||
let t = v.warnTime
|
||||
if (!(t instanceof Date)) {
|
||||
@ -774,7 +779,9 @@
|
||||
} else {
|
||||
if (these.filter.MM) {
|
||||
let start = new Date(these.filter.MM + '-01');
|
||||
let end = start.setMonth(1);
|
||||
let end = new Date(these.filter.MM + '-01');
|
||||
end.setMonth(end.getMonth()+1);
|
||||
end.setDate(end.getDate()+1);
|
||||
data = data.filter((v) => {
|
||||
let t = v.warnTime
|
||||
if (!(t instanceof Date)){
|
||||
|
||||
@ -574,6 +574,15 @@
|
||||
},
|
||||
onShow() {
|
||||
this.Status.pageHide = false;
|
||||
|
||||
let f=this.getDevice();
|
||||
if(f){
|
||||
these.formData.bleStatu = 'connecting';
|
||||
ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId).then(res => {
|
||||
console.log("连接成功")
|
||||
these.formData.bleStatu = true;
|
||||
});
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
getbleStatu() {
|
||||
@ -1083,9 +1092,9 @@
|
||||
|
||||
},
|
||||
deviceDispose(res) {
|
||||
if (this.Status.pageHide) {
|
||||
return;
|
||||
}
|
||||
// if (this.Status.pageHide) {
|
||||
// return;
|
||||
// }
|
||||
if (res.deviceId == these.formData.deviceId) {
|
||||
if(res.device){
|
||||
these.formData.bleStatu = 'connecting';
|
||||
|
||||
@ -599,9 +599,9 @@ import request, { baseURL } from '@/utils/request.js';
|
||||
|
||||
},
|
||||
deviceDispose(res) {
|
||||
if (this.Status.pageHide) {
|
||||
return;
|
||||
}
|
||||
//if (this.Status.pageHide) {
|
||||
// return;
|
||||
//}
|
||||
if (res.deviceId == these.formData.deviceId) {
|
||||
if(res.device){
|
||||
these.formData.bleStatu = 'connecting';
|
||||
|
||||
@ -679,7 +679,7 @@
|
||||
}
|
||||
let that = this;
|
||||
uni.navigateTo({
|
||||
url: "/pages/ImgCrop/ImgCrop",
|
||||
url: "/pages/common/ImgCrop/ImgCrop",
|
||||
events: {
|
||||
ImgCutOverPath: function(data) {
|
||||
that.selectedImage = data.picPath;
|
||||
|
||||
@ -486,6 +486,15 @@
|
||||
},
|
||||
onShow() {
|
||||
this.Status.pageHide = false;
|
||||
|
||||
let f=this.getDevice();
|
||||
if(f){
|
||||
these.formData.bleStatu = 'connecting';
|
||||
ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId).then(res => {
|
||||
console.log("连接成功")
|
||||
these.formData.bleStatu = true;
|
||||
});
|
||||
}
|
||||
},
|
||||
onHide: function() {
|
||||
this.Status.pageHide = true;
|
||||
@ -1145,7 +1154,7 @@
|
||||
sourceType: ['album'],
|
||||
success: function(res) {
|
||||
uni.navigateTo({
|
||||
url: "/pages/ImgCrop/ImgCrop",
|
||||
url: "/pages/common/ImgCrop/ImgCrop",
|
||||
events: {
|
||||
ImgCutOver: function(data) {
|
||||
|
||||
@ -2012,9 +2021,9 @@
|
||||
|
||||
},
|
||||
deviceDispose(res) {
|
||||
if (this.Status.pageHide) {
|
||||
return;
|
||||
}
|
||||
// if (this.Status.pageHide) {
|
||||
// return;
|
||||
// }
|
||||
if (res.deviceId == these.formData.deviceId) {
|
||||
if (res.device) {
|
||||
these.formData.bleStatu = 'connecting';
|
||||
|
||||
@ -433,6 +433,14 @@
|
||||
},
|
||||
onShow() {
|
||||
this.Status.pageHide = false;
|
||||
let f = this.getDevice();
|
||||
if (f) {
|
||||
these.formData.bleStatu = 'connecting';
|
||||
ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId).then(res => {
|
||||
console.log("连接成功")
|
||||
these.formData.bleStatu = true;
|
||||
});
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
|
||||
@ -689,9 +697,9 @@
|
||||
|
||||
},
|
||||
deviceDispose(res) {
|
||||
if (this.Status.pageHide) {
|
||||
return;
|
||||
}
|
||||
//if (this.Status.pageHide) {
|
||||
// return;
|
||||
//}
|
||||
if (res.deviceId == these.formData.deviceId) {
|
||||
this.formData.bleStatu = false;
|
||||
setTimeout(() => {
|
||||
|
||||
@ -74,8 +74,8 @@
|
||||
|
||||
<view class="slider-container">
|
||||
<slider min="1" max="100" step="1" :disabled="false" :value="formData.liangDu" activeColor="#bbe600"
|
||||
backgroundColor="#00000000" block-size="20" block-color="#ffffffde" @change="sliderChange"
|
||||
@changing="sliderChange" class="custom-slider" />
|
||||
backgroundColor="#00000000" block-size="20" block-color="#ffffffde" @change="sliderChange" @changing="sliderChanging"
|
||||
class="custom-slider" />
|
||||
|
||||
</view>
|
||||
</view>
|
||||
@ -129,17 +129,17 @@
|
||||
|
||||
<view class="item">
|
||||
<text class="lbl">单位:</text>
|
||||
<input class="value" v-model.trim="formData.textLines[0]" placeholder="请输入单位"
|
||||
<input class="value" v-model.trim="formData.textLines[0]" placeholder="请输入单位" maxlength="8"
|
||||
placeholder-class="usrplace" />
|
||||
</view>
|
||||
<view class="item">
|
||||
<text class="lbl">部门:</text>
|
||||
<input class="value" v-model.trim="formData.textLines[1]" placeholder="请输入姓名"
|
||||
<input class="value" v-model.trim="formData.textLines[1]" placeholder="请输入姓名" maxlength="8"
|
||||
placeholder-class="usrplace" />
|
||||
</view>
|
||||
<view class="item">
|
||||
<text class="lbl">姓名:</text>
|
||||
<input class="value" v-model.trim="formData.textLines[2]" placeholder="请输入职位"
|
||||
<input class="value" v-model.trim="formData.textLines[2]" placeholder="请输入职位" maxlength="8"
|
||||
placeholder-class="usrplace" />
|
||||
</view>
|
||||
|
||||
@ -286,7 +286,7 @@
|
||||
light: null,
|
||||
bleStatu: ''
|
||||
},
|
||||
inteval: 80,
|
||||
inteval: 150,
|
||||
device: {
|
||||
id: "",
|
||||
deviceName: "",
|
||||
@ -385,7 +385,7 @@
|
||||
}
|
||||
let f = ble.data.LinkedList.find((v) => {
|
||||
if (v.macAddress == device.deviceMac) {
|
||||
console.log("找到设备了", v);
|
||||
// console.log("找到设备了", v);
|
||||
these.formData.deviceId = v.deviceId;
|
||||
return true;
|
||||
}
|
||||
@ -426,6 +426,15 @@
|
||||
},
|
||||
onShow() {
|
||||
this.Status.pageHide = false;
|
||||
|
||||
let f = this.getDevice();
|
||||
if (f) {
|
||||
these.formData.bleStatu = 'connecting';
|
||||
ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId).then(res => {
|
||||
console.log("连接成功")
|
||||
these.formData.bleStatu = true;
|
||||
});
|
||||
}
|
||||
},
|
||||
onBackPress(e) {
|
||||
|
||||
@ -581,13 +590,13 @@
|
||||
|
||||
},
|
||||
deviceDispose(res) {
|
||||
if (this.Status.pageHide) {
|
||||
return;
|
||||
}
|
||||
// if (this.Status.pageHide) {
|
||||
// return;
|
||||
// }
|
||||
if (res.deviceId == these.formData.deviceId) {
|
||||
if(res.device){
|
||||
if (res.device) {
|
||||
these.formData.bleStatu = 'connecting';
|
||||
}else{
|
||||
} else {
|
||||
this.formData.bleStatu = false;
|
||||
}
|
||||
setTimeout(() => {
|
||||
@ -759,14 +768,14 @@
|
||||
these.showBleUnConnect();
|
||||
return;
|
||||
}
|
||||
|
||||
let os = plus.os.name;
|
||||
// 分包发送图片数据
|
||||
var sendImagePackets = function(ReSendNo) {
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
// 总数据包数
|
||||
let totalPackets = 52;
|
||||
let totalPackets = os=='Android'?52:200;
|
||||
let currentPacket = 1;
|
||||
|
||||
if (ReSendNo) {
|
||||
@ -785,19 +794,20 @@
|
||||
message: "上传成功",
|
||||
iconUrl: "/static/images/common/success.png",
|
||||
});
|
||||
|
||||
setTimeout(()=>{
|
||||
ble.sendString(f.deviceId, "transmit complete", f.writeServiceId, f
|
||||
.wirteCharactId);
|
||||
},1000);
|
||||
|
||||
|
||||
setTimeout(() => {
|
||||
ble.sendString(f.deviceId, "transmit complete", f
|
||||
.writeServiceId, f
|
||||
.wirteCharactId);
|
||||
}, 1000);
|
||||
|
||||
these.rgb565Data = null;
|
||||
resolve();
|
||||
return;
|
||||
}
|
||||
|
||||
// 计算当前包的数据
|
||||
let packetSize = 250;
|
||||
let packetSize = os == 'Android' ? 250 : 64;
|
||||
// if (currentPacket <= 51) {
|
||||
// packetSize = 250; // 前51个包每个500字节
|
||||
// } else {
|
||||
@ -805,77 +815,59 @@
|
||||
// }
|
||||
|
||||
// 创建数据包
|
||||
const startIndex = (currentPacket - 1) * packetSize;
|
||||
const endIndex = Math.min(startIndex + packetSize, these.rgb565Data
|
||||
let startIndex = (currentPacket - 1) * packetSize;
|
||||
let endIndex = Math.min(startIndex + packetSize, these.rgb565Data
|
||||
.length);
|
||||
if (startIndex > endIndex) {
|
||||
return;
|
||||
}
|
||||
const packetData = these.rgb565Data.slice(startIndex,
|
||||
let packetData = these.rgb565Data.slice(startIndex,
|
||||
endIndex);
|
||||
// 构建数据包
|
||||
const bufferSize = 505; // 5 + packetData.length * 2; // 头部5字节 + 数据部分
|
||||
const buffer = new ArrayBuffer(bufferSize);
|
||||
const dataView = new DataView(buffer);
|
||||
let bufferSize = os ==packetSize.length*2+5; // 5 + packetData.length * 2; // 头部5字节 + 数据部分
|
||||
let buffer = new ArrayBuffer(bufferSize);
|
||||
let dataView = new DataView(buffer);
|
||||
|
||||
// 填充头部
|
||||
dataView.setUint8(0, 0x55); // 帧头
|
||||
dataView.setUint8(0, os == 'Android' ? 0x55 : 0x56); // 帧头
|
||||
dataView.setUint8(1, 0x02); // 帧类型:开机画面
|
||||
dataView.setUint8(2, '0x' + currentPacket.toString(16).padStart(2,
|
||||
'0')); // 包序号
|
||||
|
||||
|
||||
if (packetData.length == 250) {
|
||||
dataView.setUint8(3, 0x01);
|
||||
dataView.setUint8(4, 0xF4);
|
||||
} else {
|
||||
dataView.setUint8(3, 0x00);
|
||||
dataView.setUint8(4, 0x64);
|
||||
}
|
||||
|
||||
dataView.setUint8(2, currentPacket); // 包序号
|
||||
dataView.setUint16(3, packetData.length*2,false);
|
||||
|
||||
// 填充数据(每个RGB565值占2字节)
|
||||
for (let i = 0; i < packetData.length; i++) {
|
||||
dataView.setUint16(5 + i * 2, packetData[i], false); // 大端字节序
|
||||
}
|
||||
|
||||
if (currentPacket > 51) { //第52包补FF
|
||||
for (var i = 105; i < bufferSize; i++) {
|
||||
dataView.setUint8(i, 0xFF);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//发送数据包
|
||||
ble.sendData(f.deviceId, buffer, f.writeServiceId, f.wirteCharactId,
|
||||
10)
|
||||
.then(() => {
|
||||
10).then(() => {
|
||||
|
||||
|
||||
updateLoading(these, {
|
||||
text: "正在发送:" + currentPacket + "/" +
|
||||
totalPackets
|
||||
})
|
||||
currentPacket++;
|
||||
updateLoading(these, {
|
||||
text: "正在发送:" + currentPacket + "/" +
|
||||
totalPackets
|
||||
})
|
||||
currentPacket++;
|
||||
|
||||
setTimeout(sendNextPacket,os=='Android'? these.inteval:these.inteval/2);
|
||||
}).catch(err => {
|
||||
console.log("发送数据包失败了" + JSON.stringify(err));
|
||||
if (err.code == '10007') {
|
||||
setTimeout(sendNextPacket, these.inteval);
|
||||
}).catch(err => {
|
||||
console.log("发送数据包失败了" + JSON.stringify(err));
|
||||
if (err.code == '10007') {
|
||||
setTimeout(sendNextPacket, these.inteval);
|
||||
return;
|
||||
}
|
||||
these.Status.BottomMenu.show = false;
|
||||
these.showPop({
|
||||
message: err.msg,
|
||||
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
|
||||
borderColor: "#e034344d",
|
||||
buttonBgColor: "#E03434",
|
||||
});
|
||||
hideLoading(these);
|
||||
these.rgb565Data = null;
|
||||
reject(err);
|
||||
return;
|
||||
}
|
||||
these.Status.BottomMenu.show = false;
|
||||
these.showPop({
|
||||
message: err.msg,
|
||||
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
|
||||
borderColor: "#e034344d",
|
||||
buttonBgColor: "#E03434",
|
||||
});
|
||||
hideLoading(these);
|
||||
these.rgb565Data = null;
|
||||
reject(err);
|
||||
});
|
||||
}
|
||||
|
||||
if (ReSendNo) {
|
||||
@ -909,12 +901,12 @@
|
||||
sourceType: ['album'],
|
||||
success: function(res) {
|
||||
uni.navigateTo({
|
||||
url: "/pages/ImgCrop/ImgCrop",
|
||||
url: "/pages/common/ImgCrop/ImgCrop",
|
||||
events: {
|
||||
ImgCutOver: function(data) {
|
||||
|
||||
showLoading(these, {
|
||||
text: "正在发送0/52"
|
||||
text: "正在发送..."
|
||||
});
|
||||
console.log("data=", data);
|
||||
these.Status.BottomMenu.show = false;
|
||||
@ -955,6 +947,8 @@
|
||||
})
|
||||
return;
|
||||
}
|
||||
let os=plus.os.name;
|
||||
// os='Android';
|
||||
let f = these.getDevice();
|
||||
|
||||
if (!f) {
|
||||
@ -974,7 +968,7 @@
|
||||
return new Promise((resolve, reject) => {
|
||||
if (f) {
|
||||
// 总数据包数
|
||||
var totalPackets = 1536; //36;
|
||||
var totalPackets =os=='Android' ? 1536 : 6000; //36;
|
||||
|
||||
let currentPacket = 1;
|
||||
console.log("发送数据准备中,总共" + totalPackets);
|
||||
@ -987,27 +981,30 @@
|
||||
const sendNextVideoPacket = () => {
|
||||
// console.log("准备发送一段数据");
|
||||
if (currentPacket > totalPackets) {
|
||||
updateLoading(these,{text:'发送完毕,正在处理'})
|
||||
if (!ReSendNo) {
|
||||
setTimeout(() => {
|
||||
|
||||
ble.sendString(f.deviceId, "transmit complete", f
|
||||
.writeServiceId, f.wirteCharactId, 20)
|
||||
|
||||
ble.sendString(f.deviceId, "transmit complete", f.writeServiceId, f.wirteCharactId, 20)
|
||||
.then(
|
||||
() => {
|
||||
console.log("全部发送完毕")
|
||||
|
||||
hideLoading(these);
|
||||
these.showPop({
|
||||
showPop: true,
|
||||
message: "上传成功",
|
||||
iconUrl: "/static/images/common/success.png"
|
||||
});
|
||||
|
||||
}).catch((ex) => {
|
||||
console.log("出现异常", ex);
|
||||
});
|
||||
}, 500);
|
||||
}, os=='Android'?500:15000);
|
||||
|
||||
}
|
||||
these.Status.BottomMenu.show = false;
|
||||
hideLoading(these);
|
||||
these.showPop({
|
||||
showPop: true,
|
||||
message: "上传成功",
|
||||
iconUrl: "/static/images/common/success.png"
|
||||
});
|
||||
|
||||
these.videoHexArray = null;
|
||||
resolve();
|
||||
|
||||
@ -1015,7 +1012,7 @@
|
||||
}
|
||||
|
||||
// 计算当前包的数据
|
||||
let packetSize = 500;
|
||||
let packetSize =os=='Android'? 500:128;
|
||||
|
||||
|
||||
// 创建数据包
|
||||
@ -1031,33 +1028,28 @@
|
||||
|
||||
// 构建数据包
|
||||
////console.log("packetData.length"+packetData.length);
|
||||
const bufferSize = 504; // 头部5字节 + 数据部分
|
||||
const bufferSize =packetSize+4; // 头部5字节 + 数据部分
|
||||
const buffer = new ArrayBuffer(bufferSize);
|
||||
const dataView = new DataView(buffer);
|
||||
|
||||
let sortNo = currentPacket.toString(16).padStart(4, '0');
|
||||
|
||||
|
||||
// 填充头部
|
||||
dataView.setUint8(0, 0x55); // 帧头
|
||||
dataView.setUint8(0, os=='Android'?0x55:0x56); // 帧头
|
||||
dataView.setUint8(1, 0x04); // 帧类型:开机画面
|
||||
dataView.setUint8(2, '0x' + sortNo.substring(0, 2)); // 包序号
|
||||
dataView.setUint8(3, '0x' + sortNo.substring(2, 4)); // 包序号
|
||||
|
||||
// dataView.setUint8(4, 0x01);
|
||||
// dataView.setUint8(5, 0xF4);
|
||||
|
||||
dataView.setUint16(2, currentPacket,false); // 包序号
|
||||
|
||||
for (let i = 0; i < packetData.length; i++) {
|
||||
dataView.setUint8(4 + i, '0x' + packetData[i]);
|
||||
dataView.setUint8(4 + i, parseInt(packetData[i],16));
|
||||
}
|
||||
|
||||
let inteval = 40;
|
||||
let inteval = os=='Android'? 100:40;
|
||||
|
||||
ble.sendData(f.deviceId, buffer, f.writeServiceId, f
|
||||
.wirteCharactId, 10).then(() => {
|
||||
|
||||
|
||||
updateLoading(these, {
|
||||
text: "正在发送:" + currentPacket + "/" +
|
||||
totalPackets
|
||||
text: "正在发送:" +currentPacket+'/'+totalPackets
|
||||
})
|
||||
|
||||
currentPacket++;
|
||||
@ -1069,7 +1061,7 @@
|
||||
if (err.code == '10007') { //遇到这个错误自动重新发送
|
||||
console.log(err.errMsg + ",发送失败了,正在补偿:" +
|
||||
currentPacket);
|
||||
setTimeout(sendNextVideoPacket, inteval);
|
||||
setTimeout(sendNextVideoPacket, 500);
|
||||
} else {
|
||||
these.Status.BottomMenu.show = false;
|
||||
hideLoading(these);
|
||||
@ -1183,7 +1175,7 @@
|
||||
if (res.data) {
|
||||
these.videoHexArray = res.data;
|
||||
updateLoading(these, {
|
||||
text: "正在发送:0/1536"
|
||||
text: "正在发送..."
|
||||
});
|
||||
|
||||
these.Status.BottomMenu.show = false;
|
||||
@ -1227,7 +1219,7 @@
|
||||
}).catch((ex1) => {
|
||||
//console.log("出现了异常", ex1)
|
||||
}).finally(() => {
|
||||
hideLoading(these);
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
@ -1583,7 +1575,7 @@
|
||||
|
||||
let err = false;
|
||||
this.formData.textLines.find((txt) => {
|
||||
if (txt.length === 0 || txt.length > 7) {
|
||||
if (txt.length === 0 || txt.length > 8) {
|
||||
console.log("txt=", txt);
|
||||
err = true;
|
||||
return true;
|
||||
@ -1592,7 +1584,7 @@
|
||||
})
|
||||
if (err) {
|
||||
this.showPop({
|
||||
message: "单位、部门、姓名必须填写且最多7字",
|
||||
message: "单位、部门、姓名必须填写且最多8字",
|
||||
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
|
||||
borderColor: "#e034344d",
|
||||
buttonBgColor: "#E03434",
|
||||
@ -1647,11 +1639,12 @@
|
||||
linePixels.push(0x00);
|
||||
|
||||
}
|
||||
linePixels = [0xFA, 0x06, 0x03, i + 1].concat(linePixels);
|
||||
combinedData.push([0xFA, 0x06, i + 1, 1].concat(linePixels.slice(0, 128)));
|
||||
combinedData.push([0xFA, 0x06, i + 1, 2].concat(linePixels.slice(128, 256)));
|
||||
|
||||
|
||||
|
||||
linePixels.push(0xFF)
|
||||
|
||||
combinedData.push(linePixels);
|
||||
}
|
||||
combinedData.push([0x74, 0x72, 0x61, 0x6E, 0x73, 0x6D, 0x69, 0x74, 0x20, 0x63, 0x6F, 0x6D,
|
||||
0x70, 0x6C, 0x65, 0x74, 0x65
|
||||
@ -1703,11 +1696,11 @@
|
||||
text: '正在发送' + curr + '/' + len
|
||||
});
|
||||
curr++;
|
||||
setTimeout(sendPacket, 150);
|
||||
setTimeout(sendPacket, 300);
|
||||
}).catch(err => {
|
||||
if (err.code == '10007') {
|
||||
|
||||
setTimeout(sendPacket, 150);
|
||||
setTimeout(sendPacket, 300);
|
||||
} else {
|
||||
console.log("err:", err);
|
||||
hideLoading(these);
|
||||
@ -1741,6 +1734,7 @@
|
||||
|
||||
setTimeout(() => {
|
||||
Promise.allSettled([holdHand(), drawText()]).then(results => {
|
||||
console.log("results=", results)
|
||||
if (results[0].status == 'rejected') {
|
||||
updateLoading(these, {
|
||||
text: results[0].reason
|
||||
@ -1790,6 +1784,9 @@
|
||||
});
|
||||
|
||||
},
|
||||
sliderChanging(evt){
|
||||
this.formData.liangDu = evt.detail.value;
|
||||
},
|
||||
sliderChange: function(evt) {
|
||||
|
||||
if (!this.permissions.includes('1') && this.Status.apiType !== 'listA') {
|
||||
@ -1840,10 +1837,10 @@
|
||||
|
||||
dataView.setUint8(0, 0x55); // 帧头
|
||||
dataView.setUint8(1, 0x07); // 帧类型:亮度调节
|
||||
dataView.setUint8(2, 0x01); // 包序号
|
||||
dataView.setUint8(3, 0x00); // 包序号
|
||||
dataView.setUint8(4, 0x01); // 数据长度
|
||||
dataView.setUint8(5, liangDu); // 数据长度
|
||||
dataView.setUint8(2, 0x01);
|
||||
dataView.setUint8(3, 0x00);
|
||||
dataView.setUint8(4, 0x01); //
|
||||
dataView.setUint8(5, liangDu); // 数据
|
||||
|
||||
let f = this.getDevice();
|
||||
if (f) {
|
||||
|
||||
@ -396,6 +396,15 @@
|
||||
},
|
||||
onShow() {
|
||||
this.Status.pageHide = false;
|
||||
|
||||
let f=this.getDevice();
|
||||
if(f){
|
||||
these.formData.bleStatu = 'connecting';
|
||||
ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId).then(res => {
|
||||
console.log("连接成功")
|
||||
these.formData.bleStatu = true;
|
||||
});
|
||||
}
|
||||
},
|
||||
onBackPress(e) {
|
||||
|
||||
@ -562,9 +571,9 @@
|
||||
|
||||
},
|
||||
deviceDispose(res) {
|
||||
if (this.Status.pageHide) {
|
||||
return;
|
||||
}
|
||||
// if (this.Status.pageHide) {
|
||||
// return;
|
||||
// }
|
||||
if (res.deviceId == these.formData.deviceId) {
|
||||
if(res.device){
|
||||
these.formData.bleStatu = 'connecting';
|
||||
@ -926,7 +935,7 @@
|
||||
sourceType: ['album'],
|
||||
success: function(res) {
|
||||
uni.navigateTo({
|
||||
url: "/pages/ImgCrop/ImgCrop",
|
||||
url: "/pages/common/ImgCrop/ImgCrop",
|
||||
events: {
|
||||
ImgCutOver: function(data) {
|
||||
|
||||
|
||||
@ -52,9 +52,9 @@
|
||||
{{ deviceInfo.onlineStatus === 0 ? '离线' : deviceInfo.onlineStatus === 2 ? '故障' : '在线' }}
|
||||
</text>
|
||||
</view>
|
||||
<view class="info-row" v-if="itemInfo.deviceMac">
|
||||
<view class="info-row" v-if="itemInfo.deviceMac" @click="bleStatuToggle">
|
||||
<text class="info-label">蓝牙状态</text>
|
||||
<text class="info-value status-running">
|
||||
<text class="info-value status-running" >
|
||||
{{getbleStatu}}
|
||||
</text>
|
||||
</view>
|
||||
@ -331,7 +331,7 @@
|
||||
var ble = null;
|
||||
var rec = null;
|
||||
|
||||
var pagePath = "pages/6170/BJQ6170";
|
||||
var pagePath = "/pages/6170/deviceControl/index";
|
||||
|
||||
export default {
|
||||
components: {
|
||||
@ -404,7 +404,8 @@
|
||||
},
|
||||
Status: {
|
||||
pageHide: null
|
||||
}
|
||||
},
|
||||
inteval: 120
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
@ -432,20 +433,48 @@
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
bleStatuToggle() {
|
||||
let f = this.getDevice();
|
||||
if (!f) {
|
||||
this.showBleUnConnect();
|
||||
return;
|
||||
}
|
||||
if (this.formData.bleStatu === true) {
|
||||
this.formData.bleStatu = 'dicconnect';
|
||||
ble.disconnectDevice(f.deviceId).finally(r => {
|
||||
this.formData.bleStatu = false;
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.formData.bleStatu === false || this.formData.bleStatu === 'err') {
|
||||
these.formData.bleStatu = 'connecting';
|
||||
ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId).then(res => {
|
||||
these.formData.bleStatu = true;
|
||||
}).catch(ex => {
|
||||
these.formData.bleStatu = 'err';
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
},
|
||||
getDevice: function() {
|
||||
if (ble) {
|
||||
console.log("LinkedList=", ble.data.LinkedList);
|
||||
console.log("this.device=", this.itemInfo);
|
||||
let f = ble.data.LinkedList.find((v) => {
|
||||
if (v.macAddress == this.itemInfo.deviceMac) {
|
||||
if (!this.formData.deviceId) {
|
||||
this.formData.deviceId = v.deviceId
|
||||
};
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
console.log("LinkedList=", ble.data.LinkedList);
|
||||
console.log("this.device=", this.device);
|
||||
let f = ble.data.LinkedList.find((v) => {
|
||||
if (v.macAddress == this.itemInfo.deviceMac) {
|
||||
if (!this.formData.deviceId) {
|
||||
this.formData.deviceId = v.deviceId
|
||||
};
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
return f;
|
||||
return f;
|
||||
}
|
||||
return null;
|
||||
},
|
||||
initBle() {
|
||||
if (this.itemInfo.deviceMac) {
|
||||
@ -498,9 +527,12 @@
|
||||
if (receive.deviceId !== this.formData.deviceId) {
|
||||
return;
|
||||
}
|
||||
let data = recei.ReceiveData(receive, device, pagePath, recArr);
|
||||
let data = rec.ReceiveData(receive, device, pagePath, recArr);
|
||||
console.log("蓝牙收到消息", data)
|
||||
this.receivData(data);
|
||||
},
|
||||
receivData(data) {
|
||||
|
||||
},
|
||||
bleStateBreak() {
|
||||
if (this.Status.pageHide) {
|
||||
@ -542,9 +574,9 @@
|
||||
});
|
||||
},
|
||||
deviceDispose(res) {
|
||||
if (this.Status.pageHide) {
|
||||
return;
|
||||
}
|
||||
// if (this.Status.pageHide) {
|
||||
// return;
|
||||
// }
|
||||
if (res.deviceId == these.formData.deviceId) {
|
||||
if (res.device) {
|
||||
these.formData.bleStatu = 'connecting';
|
||||
@ -856,20 +888,26 @@
|
||||
})
|
||||
uni.hideLoading();
|
||||
}
|
||||
}).catch(ex => {
|
||||
console.error("ex=", ex);
|
||||
});
|
||||
}
|
||||
|
||||
if (ble && this.itemInfo.deviceMac) {
|
||||
console.log("111111")
|
||||
let f = this.getDevice();
|
||||
if (f) {
|
||||
console.log("222222");
|
||||
let json = {
|
||||
instruct: [1, 0, 0, 0, 0]
|
||||
};
|
||||
json.instruct[1] = parseInt(selectedItem.instructValue);
|
||||
|
||||
ble.sendString(f.deviceId, json).then(res => {
|
||||
|
||||
console.log("ble send success")
|
||||
this.lightModeA = false;
|
||||
}).catch(ex => {
|
||||
console.error("ble send fail,mqsending....")
|
||||
mqSend();
|
||||
});
|
||||
} else {
|
||||
@ -979,7 +1017,7 @@
|
||||
}
|
||||
let that = this;
|
||||
uni.navigateTo({
|
||||
url: "/pages/ImgCrop/ImgCrop",
|
||||
url: "/pages/common/ImgCrop/ImgCrop",
|
||||
events: {
|
||||
ImgCutOver: function(data) {
|
||||
that.selectedImage = data.picPath;
|
||||
@ -990,6 +1028,9 @@
|
||||
ev.eventChannel.emit('checkImg', {
|
||||
data: res.tempFiles[0].path,
|
||||
});
|
||||
},
|
||||
fail(ex) {
|
||||
console.error("跳转失败", ex);
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -1247,9 +1288,11 @@
|
||||
});
|
||||
}
|
||||
|
||||
setTimeout(function() {
|
||||
setTimeout(()=> {
|
||||
sendImagePackets().catch(() => {
|
||||
|
||||
}).finally(()=>{
|
||||
this.lightModeB=false;
|
||||
});
|
||||
}, 0)
|
||||
}
|
||||
@ -1797,7 +1840,7 @@
|
||||
onLoad(options) {
|
||||
these = this;
|
||||
|
||||
|
||||
rec = BleReceive.getBleReceive();
|
||||
const eventChannel = this.getOpenerEventChannel();
|
||||
// 监听 'detailData' 事件,获取传过来的数据
|
||||
uni.showLoading({
|
||||
@ -1815,7 +1858,7 @@
|
||||
// 根据 apiType 设置右图标的显示状态
|
||||
this.isRightIconVisible = this.apiType === 'listA';
|
||||
|
||||
this.initBle();
|
||||
|
||||
// 初始化并连接MQTT
|
||||
this.mqttClient = new MqttClient();
|
||||
this.mqttClient.connect(() => {
|
||||
@ -1896,6 +1939,9 @@
|
||||
rec = BleReceive.getBleReceive();
|
||||
ble = BleTool.getBleTool();
|
||||
|
||||
this.initBle();
|
||||
|
||||
console.log("ble=", ble);
|
||||
let f = ble.data.LinkedList.find((v) => {
|
||||
if (v.macAddress == this.itemInfo.deviceMac) {
|
||||
console.log("找到设备了", v);
|
||||
@ -1908,9 +1954,9 @@
|
||||
if (f) {
|
||||
these.formData.bleStatu = 'connecting';
|
||||
ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId).then(
|
||||
res => {
|
||||
these.formData.bleStatu = true;
|
||||
});
|
||||
res => {
|
||||
these.formData.bleStatu = true;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -1922,6 +1968,17 @@
|
||||
})
|
||||
|
||||
},
|
||||
onShow() {
|
||||
debugger;
|
||||
let f = this.getDevice();
|
||||
if (f) {
|
||||
this.formData.bleStatu = 'connecting';
|
||||
ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId).then(res => {
|
||||
console.log("连接成功")
|
||||
this.formData.bleStatu = true;
|
||||
});
|
||||
}
|
||||
},
|
||||
onUnload() {
|
||||
// 页面卸载时断开MQTT连接
|
||||
if (this.mqttClient) {
|
||||
|
||||
@ -414,6 +414,14 @@ import request, { baseURL } from '@/utils/request.js';
|
||||
},
|
||||
onShow() {
|
||||
this.Status.pageHide = false;
|
||||
let f = this.getDevice();
|
||||
if (f) {
|
||||
these.formData.bleStatu = 'connecting';
|
||||
ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId).then(res => {
|
||||
console.log("连接成功")
|
||||
these.formData.bleStatu = true;
|
||||
});
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
|
||||
@ -613,9 +621,9 @@ import request, { baseURL } from '@/utils/request.js';
|
||||
|
||||
},
|
||||
deviceDispose(res) {
|
||||
if (this.Status.pageHide) {
|
||||
return;
|
||||
}
|
||||
//if (this.Status.pageHide) {
|
||||
// return;
|
||||
//}
|
||||
if (res.deviceId == these.formData.deviceId) {
|
||||
if(res.device){
|
||||
these.formData.bleStatu = 'connecting';
|
||||
|
||||
@ -418,6 +418,15 @@ import request, { baseURL } from '@/utils/request.js';
|
||||
},
|
||||
onShow() {
|
||||
this.Status.pageHide = false;
|
||||
|
||||
let f=this.getDevice();
|
||||
if(f){
|
||||
these.formData.bleStatu = 'connecting';
|
||||
ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId).then(res => {
|
||||
console.log("连接成功")
|
||||
these.formData.bleStatu = true;
|
||||
});
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
getbleStatu(){
|
||||
@ -510,9 +519,9 @@ import request, { baseURL } from '@/utils/request.js';
|
||||
|
||||
},
|
||||
deviceDispose(res) {
|
||||
if (this.Status.pageHide) {
|
||||
return;
|
||||
}
|
||||
// if (this.Status.pageHide) {
|
||||
// return;
|
||||
// }
|
||||
if (res.deviceId == these.formData.deviceId) {
|
||||
if(res.device){
|
||||
these.formData.bleStatu = 'connecting';
|
||||
@ -1051,7 +1060,7 @@ import request, { baseURL } from '@/utils/request.js';
|
||||
var gotoCutImg = (imgPath) => {
|
||||
|
||||
uni.navigateTo({
|
||||
url: "/pages/ImgCrop/ImgCrop",
|
||||
url: "/pages/common/ImgCrop/ImgCrop",
|
||||
events: {
|
||||
ImgCutOver: function(data) {
|
||||
// console.log("我收到裁剪后的图片了,感谢老铁," + data)
|
||||
|
||||
@ -16,7 +16,7 @@
|
||||
|
||||
|
||||
|
||||
<view class="eq" :style="{marginTop:Status.navbar.height+'px'}">
|
||||
<view class="eq" >
|
||||
<view class="leftImg" @click.stop="previewImg(device.devicePic?device.devicePic:formData.img)">
|
||||
<image class="img" :src="device.devicePic?device.devicePic:formData.img" mode="aspectFit"></image>
|
||||
</view>
|
||||
@ -561,6 +561,15 @@
|
||||
},
|
||||
onShow() {
|
||||
this.Status.pageHide = false;
|
||||
|
||||
let f=this.getDevice();
|
||||
if(f){
|
||||
these.formData.bleStatu = 'connecting';
|
||||
ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId).then(res => {
|
||||
console.log("连接成功")
|
||||
these.formData.bleStatu = true;
|
||||
});
|
||||
}
|
||||
},
|
||||
onHide: function() {
|
||||
this.Status.pageHide = true;
|
||||
@ -634,9 +643,9 @@
|
||||
|
||||
},
|
||||
deviceDispose(res) {
|
||||
if (this.Status.pageHide) {
|
||||
return;
|
||||
}
|
||||
// if (this.Status.pageHide) {
|
||||
// return;
|
||||
// }
|
||||
if (res.deviceId == these.formData.deviceId) {
|
||||
if(res.device){
|
||||
these.formData.bleStatu = 'connecting';
|
||||
@ -1871,7 +1880,7 @@
|
||||
var gotoCutImg = (imgPath) => {
|
||||
|
||||
uni.navigateTo({
|
||||
url: "/pages/ImgCrop/ImgCrop",
|
||||
url: "/pages/common/ImgCrop/ImgCrop",
|
||||
events: {
|
||||
ImgCutOver: function(data) {
|
||||
// console.log("我收到裁剪后的图片了,感谢老铁," + data)
|
||||
|
||||
@ -74,7 +74,7 @@
|
||||
<view class="slider-container">
|
||||
<slider min="1" max="100" step="1" :disabled="false" :value="formData.liangDu" activeColor="#bbe600"
|
||||
backgroundColor="#00000000" block-size="20" block-color="#ffffffde" @change="sliderChange"
|
||||
@changing="sliderChange" class="custom-slider" />
|
||||
@changing="sliderChanging" class="custom-slider" />
|
||||
|
||||
</view>
|
||||
</view>
|
||||
@ -114,20 +114,20 @@
|
||||
<view class="btnSend fright" v-on:click.stop="sendUsr">发送</view>
|
||||
<view class="clear"></view>
|
||||
<textToDotMatrixFor7305 class="TextToHex" ref="textToHex" :txts="formData.textLines"
|
||||
:bgColor="'#FFFFFF'" :color="'#000000'" :fontSize="11" />
|
||||
:bgColor="'#FFFFFF'" :color="'#000000'" :fontSize="13" />
|
||||
</view>
|
||||
|
||||
<view class="item">
|
||||
<text class="lbl">单位:</text>
|
||||
<input class="value" v-model="formData.textLines[0]" placeholder="请输入单位" placeholder-class="usrplace" />
|
||||
<input class="value" v-model="formData.inputLines[0]" placeholder="请输入单位" placeholder-class="usrplace" />
|
||||
</view>
|
||||
<view class="item">
|
||||
<text class="lbl">部门:</text>
|
||||
<input class="value" v-model="formData.textLines[1]" placeholder="请输入姓名" placeholder-class="usrplace" />
|
||||
<input class="value" v-model="formData.inputLines[1]" placeholder="请输入姓名" placeholder-class="usrplace" />
|
||||
</view>
|
||||
<view class="item">
|
||||
<text class="lbl">姓名:</text>
|
||||
<input class="value" v-model="formData.textLines[2]" placeholder="请输入职位" placeholder-class="usrplace" />
|
||||
<input class="value" v-model="formData.inputLines[2]" placeholder="请输入职位" placeholder-class="usrplace" />
|
||||
</view>
|
||||
|
||||
</view>
|
||||
@ -243,7 +243,7 @@
|
||||
],
|
||||
activeIndex: -1,
|
||||
bgColor: '#2a2a2a',
|
||||
itemBgColor: '#00000000',
|
||||
itemBgColor: '#3a3a3a',
|
||||
textColor: '#ffffffde',
|
||||
textAlign: 'flex-start',
|
||||
title: '主灯模式',
|
||||
@ -272,9 +272,10 @@
|
||||
liangDu: '100',
|
||||
id: '',
|
||||
deviceId: '',
|
||||
textLines: ['', '', ''],
|
||||
textLines: [],
|
||||
mode: '',
|
||||
bleStatu: ''
|
||||
bleStatu: '',
|
||||
inputLines:[]
|
||||
},
|
||||
inteval: 500,
|
||||
device: {
|
||||
@ -376,6 +377,15 @@
|
||||
},
|
||||
onShow: function() {
|
||||
this.Status.pageHide = false;
|
||||
|
||||
let f=this.getDevice();
|
||||
if(f){
|
||||
these.formData.bleStatu = 'connecting';
|
||||
ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId).then(res => {
|
||||
console.log("连接成功")
|
||||
these.formData.bleStatu = true;
|
||||
});
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
getbleStatu() {
|
||||
@ -399,22 +409,20 @@
|
||||
return txt;
|
||||
}
|
||||
switch (this.formData.mode) {
|
||||
case 0:
|
||||
case 1:
|
||||
|
||||
|
||||
txt = "强光模式";
|
||||
|
||||
break;
|
||||
case 1:
|
||||
case 2:
|
||||
txt = "弱光模式";
|
||||
break;
|
||||
|
||||
case 2:
|
||||
case 3:
|
||||
txt = "爆闪模式";
|
||||
break;
|
||||
case 3:
|
||||
txt = "关闭";
|
||||
break;
|
||||
|
||||
default:
|
||||
txt = "关闭";
|
||||
break;
|
||||
@ -481,9 +489,9 @@
|
||||
})
|
||||
},
|
||||
deviceRecovry(res) {
|
||||
if (this.Status.pageHide) {
|
||||
return;
|
||||
}
|
||||
// if (this.Status.pageHide) {
|
||||
// return;
|
||||
// }
|
||||
if (res.deviceId == these.formData.deviceId) {
|
||||
this.formData.bleStatu = true;
|
||||
// 重新连接后状态以设备上报为准
|
||||
@ -498,9 +506,9 @@
|
||||
|
||||
},
|
||||
deviceDispose(res) {
|
||||
if (this.Status.pageHide) {
|
||||
return;
|
||||
}
|
||||
// if (this.Status.pageHide) {
|
||||
// return;
|
||||
// }
|
||||
if (res.deviceId == these.formData.deviceId) {
|
||||
if (res.device) {
|
||||
these.formData.bleStatu = 'connecting';
|
||||
@ -587,7 +595,7 @@
|
||||
}
|
||||
|
||||
let json = recei.ReceiveData(receive, device, path, recArr);
|
||||
console.log("收到消息:", receive.hexs);
|
||||
console.log("收到消息:", receive);
|
||||
if (!json) {
|
||||
return;
|
||||
}
|
||||
@ -597,6 +605,8 @@
|
||||
these.formData[key] = json[key];
|
||||
}
|
||||
});
|
||||
these.formData.mode=parseInt(receive.hexs[2],16);
|
||||
console.error("mode="+these.formData.mode);
|
||||
if ('statu' in json) {
|
||||
const chargingVal = json.statu;
|
||||
const isCharging = chargingVal === 1 || chargingVal === '1' || chargingVal === true ||
|
||||
@ -783,7 +793,7 @@
|
||||
sourceType: ['album'],
|
||||
success: function(res) {
|
||||
uni.navigateTo({
|
||||
url: "/pages/ImgCrop/ImgCrop",
|
||||
url: "/pages/common/ImgCrop/ImgCrop",
|
||||
events: {
|
||||
ImgCutOver: function(data) {
|
||||
//将8位的二进制数组转换成16进制数据
|
||||
@ -1023,21 +1033,16 @@
|
||||
case 0:
|
||||
|
||||
|
||||
if (type == 'main') {
|
||||
|
||||
|
||||
dataValue = 0x01;
|
||||
} else if (type == 'fu') {
|
||||
|
||||
dataValue = 0x04;
|
||||
}
|
||||
|
||||
|
||||
break;
|
||||
case 1:
|
||||
dataValue = 0x02;
|
||||
break;
|
||||
// case 2:
|
||||
// dataValue = 0x02;
|
||||
// break;
|
||||
|
||||
case 2:
|
||||
dataValue = 0x03;
|
||||
break;
|
||||
@ -1071,7 +1076,7 @@
|
||||
});
|
||||
|
||||
ble.sendData(f.deviceId, buffer, f.writeServiceId, f.wirteCharactId, 100).then(() => {
|
||||
this.formData.mode = mode;
|
||||
this.formData.mode = mode+1;
|
||||
this.setBleFormData();
|
||||
}).catch((ex) => {
|
||||
these.showPop({
|
||||
@ -1088,7 +1093,7 @@
|
||||
|
||||
},
|
||||
handleItemClick(item, index) {
|
||||
|
||||
debugger;
|
||||
|
||||
this.Status.BottomMenu.activeIndex = index;
|
||||
|
||||
@ -1191,8 +1196,9 @@
|
||||
these.showBleUnConnect()
|
||||
return;
|
||||
}
|
||||
debugger;
|
||||
let err = false;
|
||||
this.formData.textLines.find((txt) => {
|
||||
this.formData.inputLines.find((txt) => {
|
||||
if (txt.length === 0 || txt.length > 5) {
|
||||
console.log("txt=", txt);
|
||||
err = true;
|
||||
@ -1209,12 +1215,16 @@
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
this.formData.textLines=[this.formData.inputLines[0],this.formData.inputLines[1],this.formData.inputLines[2]];
|
||||
|
||||
showLoading(these, {
|
||||
text: "请稍候..."
|
||||
text: "发送中..."
|
||||
});
|
||||
this.setBleFormData();
|
||||
let task = async () => {
|
||||
var sendTxtPackge = (rgbdata, type, str) => {
|
||||
var sendTxtPackge = (rgbdata, type, str,index) => {
|
||||
|
||||
var promise = new Promise((resolve, reject) => {
|
||||
try {
|
||||
@ -1257,7 +1267,7 @@
|
||||
.toString(16).padStart(2, '0'));
|
||||
console.log(`发送数据块 ${chunkIndex + 1}/${numChunks}:`, hexArray
|
||||
.join(' '));
|
||||
|
||||
updateLoading(these,{text:'正在发送'+((index-1)*14+chunkIndex + 1)+'/42'})
|
||||
ble.sendData(f.deviceId, chunk, f.writeServiceId, f
|
||||
.wirteCharactId, 100).then(() => {
|
||||
chunkIndex++;
|
||||
@ -1314,7 +1324,7 @@
|
||||
|
||||
try {
|
||||
// console.log("1111");
|
||||
await sendTxtPackge(rgb, h3dic[i], str);
|
||||
await sendTxtPackge(rgb, h3dic[i], str,i+1);
|
||||
// console.log("222222");
|
||||
} catch (ex) {
|
||||
flag = false;
|
||||
@ -1367,9 +1377,9 @@
|
||||
res = res.data;
|
||||
let personnelInfo = res.personnelInfo;
|
||||
if (personnelInfo) {
|
||||
these.formData.textLines[2] = personnelInfo.unitName;
|
||||
these.formData.textLines[1] = personnelInfo.name;
|
||||
these.formData.textLines[0] = personnelInfo.position;
|
||||
these.formData.inputLines[2] = personnelInfo.unitName;
|
||||
these.formData.inputLines[1] = personnelInfo.name;
|
||||
these.formData.inputLines[0] = personnelInfo.position;
|
||||
|
||||
}
|
||||
}
|
||||
@ -1384,6 +1394,10 @@
|
||||
});
|
||||
|
||||
},
|
||||
sliderChanging(evt){
|
||||
this.formData.liangDu = evt.detail.value;
|
||||
},
|
||||
|
||||
sliderChange: function(evt) {
|
||||
this.formData.liangDu = evt.detail.value;
|
||||
clearTimeout(BrighInteval)
|
||||
|
||||
@ -53,7 +53,9 @@
|
||||
Statu: {
|
||||
bound: null,
|
||||
timeInteval: null,
|
||||
isSearch: false
|
||||
isSearch: false,
|
||||
pageHide:false,
|
||||
isBind:false
|
||||
},
|
||||
device: {
|
||||
"deviceId": "",
|
||||
@ -115,17 +117,32 @@
|
||||
return "";
|
||||
}
|
||||
},
|
||||
|
||||
onShow() {
|
||||
this.Statu.pageHide=false;
|
||||
},
|
||||
onHide() {
|
||||
this.Statu.pageHide=true;
|
||||
},
|
||||
onUnload() {
|
||||
console.log("返回取消订阅");
|
||||
clearInterval(inteval);
|
||||
ble.removeAllCallback(pagePath);
|
||||
|
||||
if(!this.Statu.isBind && these.device.deviceId){
|
||||
ble.disconnectDevice(these.device.deviceId).catch(ex=>{
|
||||
console.error("无法断开蓝牙连接");
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
onLoad(option) {
|
||||
these = this;
|
||||
ble = bleTool.getBleTool();
|
||||
|
||||
ble.addStateBreakCallback(res => {
|
||||
if(this.Statu.pageHide){
|
||||
return;
|
||||
}
|
||||
these.device.linkStatu = false;
|
||||
hideLoading(these);
|
||||
uni.showToast({
|
||||
@ -135,6 +152,9 @@
|
||||
},pagePath);
|
||||
|
||||
ble.addStateRecoveryCallback(res => {
|
||||
if(this.Statu.pageHide){
|
||||
return;
|
||||
}
|
||||
if (these.device.deviceId) {
|
||||
showLoading(these, {
|
||||
text: '蓝牙已恢复正在连接设备'
|
||||
@ -144,6 +164,9 @@
|
||||
}
|
||||
},pagePath);
|
||||
ble.addDisposeCallback(res => {
|
||||
if(this.Statu.pageHide){
|
||||
return;
|
||||
}
|
||||
console.log("处理蓝牙断开连接");
|
||||
these.device.linkStatu = false;
|
||||
if (these.device.deviceId == res.deviceId) {
|
||||
@ -156,6 +179,9 @@
|
||||
},pagePath);
|
||||
|
||||
ble.addReceiveCallback((receive, f, path) => {
|
||||
if(this.Statu.pageHide){
|
||||
return;
|
||||
}
|
||||
console.log("收到设备消息,", receive);
|
||||
if (these.device.deviceId == receive.deviceId) {
|
||||
console.log("11111:", receive);
|
||||
@ -372,6 +398,7 @@
|
||||
clearTimeout(this.Statu.timeInteval);
|
||||
this.device.macAddress = null;
|
||||
this.Statu.timeInteval = null;
|
||||
this.Statu.isBind=true;
|
||||
uni.$emit("refreshDeviceList");
|
||||
setTimeout(() => {
|
||||
uni.switchTab({
|
||||
|
||||
@ -23,9 +23,10 @@
|
||||
<view class="p100">
|
||||
|
||||
<view class="lblTitle">配对设备</view>
|
||||
|
||||
<view class="list" style="margin-bottom: 30rpx;">
|
||||
|
||||
<view class="item " v-for="item, index in PairEquip" v-show="PairEquip.length>0">
|
||||
<view class="item " @click.stop="disConnect(item,index)" v-for="item, index in PairEquip" v-show="PairEquip.length>0">
|
||||
<view class="leftImg ">
|
||||
<image src="/static/images/common/bluetooth.png" class="titleIco filterNone"
|
||||
mode="heightFix">
|
||||
@ -33,9 +34,7 @@
|
||||
</view>
|
||||
<view class="centertxt ">
|
||||
<view class="name" v-text="item.name"></view>
|
||||
<view class="id">
|
||||
<text>信号:{{item.RSSI}}dBm</text>
|
||||
</view>
|
||||
|
||||
</view>
|
||||
<view class="rightIco center">
|
||||
<image src="/static/images/BLEAdd/linked.png" class="img" mode="aspectFit">
|
||||
@ -104,6 +103,7 @@
|
||||
</view>
|
||||
</BottomSlideMenuPlus>
|
||||
|
||||
<MsgBox ref="msgPop" />
|
||||
<global-loading ref="loading" />
|
||||
</view>
|
||||
</template>
|
||||
@ -115,7 +115,15 @@
|
||||
showLoading,
|
||||
hideLoading,
|
||||
updateLoading
|
||||
} from '@/utils/loading.js'
|
||||
} from '@/utils/loading.js';
|
||||
import {
|
||||
MsgSuccess,
|
||||
MsgError,
|
||||
MsgClose,
|
||||
MsgWarning,
|
||||
showPop,
|
||||
MsgClear
|
||||
} from '@/utils/MsgPops.js';
|
||||
const pagePath = "pages/common/addBLE/addEquip";
|
||||
var ble = null;
|
||||
var these = null;
|
||||
@ -125,6 +133,7 @@
|
||||
data() {
|
||||
return {
|
||||
Status: {
|
||||
navigateTO: false,
|
||||
isPageHidden: false,
|
||||
intval: null,
|
||||
time: null,
|
||||
@ -156,11 +165,14 @@
|
||||
},
|
||||
search: '', //筛选
|
||||
PairEquip: [], //已配对设备
|
||||
tmpLink:[],//本次已配对
|
||||
EquipMents: [], //搜索出来的设备
|
||||
device: null,
|
||||
item: {
|
||||
deviceId: ''
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
@ -180,9 +192,20 @@
|
||||
if (ble) {
|
||||
ble.StopSearch();
|
||||
ble.removeAllCallback(pagePath);
|
||||
if (!this.device && !this.Status.navigateTO) {
|
||||
if (this.tmpLink && this.tmpLink.length && this.tmpLink.length > 0) {
|
||||
console.error("页面卸载时,断开所有连接")
|
||||
let f = this.tmpLink.forEach((v) => {
|
||||
ble.disconnectDevice(v.deviceId).catch(ex => {
|
||||
console.error("无法断开设备连接", ex);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
onLoad(option) {
|
||||
debugger;
|
||||
eventChannel = this.getOpenerEventChannel();
|
||||
|
||||
eventChannel.on('detailData', function(rec) {
|
||||
@ -202,8 +225,8 @@
|
||||
|
||||
const systemInfo = uni.getSystemInfoSync();
|
||||
|
||||
ble = bleTool.getBleTool(); // Ensure ble is initialized
|
||||
|
||||
// Ensure ble is initialized
|
||||
|
||||
if (systemInfo.uniPlatform == 'web') {
|
||||
|
||||
|
||||
@ -227,86 +250,19 @@
|
||||
"name": "EF4651",
|
||||
"linkStatu": false,
|
||||
"isTarget": true
|
||||
},
|
||||
{
|
||||
"RSSI": -69,
|
||||
"advertisData": "",
|
||||
"advertisServiceUUIDs": [
|
||||
"0000FFE0-0000-1000-8000-00805F9B34FB"
|
||||
],
|
||||
"deviceId": "4F0DAC91-4391-CB07-905E-72D7F03EFCD3",
|
||||
"name": "4877-BF743D",
|
||||
"linkStatu": false
|
||||
},
|
||||
{
|
||||
"RSSI": -55,
|
||||
"advertisData": "",
|
||||
"advertisServiceUUIDs": [
|
||||
"0000FFE0-0000-1000-8000-00805F9B34FB"
|
||||
],
|
||||
"deviceId": "EBDA4E6F-3A28-FF65-A845-AE8CC7B78375",
|
||||
"name": "HBY670-BF74EA",
|
||||
"linkStatu": false
|
||||
},
|
||||
{
|
||||
"RSSI": -61,
|
||||
"advertisData": "",
|
||||
"advertisServiceUUIDs": [
|
||||
"0000FFE0-0000-1000-8000-00805F9B34FB"
|
||||
],
|
||||
"deviceId": "469FB381-B47E-1E40-8073-EF50B5704AAB",
|
||||
"name": "EF4651",
|
||||
"linkStatu": false,
|
||||
"isTarget": true
|
||||
},
|
||||
{
|
||||
"RSSI": -69,
|
||||
"advertisData": "",
|
||||
"advertisServiceUUIDs": [
|
||||
"0000FFE0-0000-1000-8000-00805F9B34FB"
|
||||
],
|
||||
"deviceId": "4F0DAC91-4391-CB07-905E-72D7F03EFCD3",
|
||||
"name": "4877-BF743D",
|
||||
"linkStatu": false
|
||||
}, {
|
||||
"RSSI": -55,
|
||||
"advertisData": "",
|
||||
"advertisServiceUUIDs": [
|
||||
"0000FFE0-0000-1000-8000-00805F9B34FB"
|
||||
],
|
||||
"deviceId": "EBDA4E6F-3A28-FF65-A845-AE8CC7B78375",
|
||||
"name": "HBY670-BF74EA",
|
||||
"linkStatu": false
|
||||
},
|
||||
{
|
||||
"RSSI": -61,
|
||||
"advertisData": "",
|
||||
"advertisServiceUUIDs": [
|
||||
"0000FFE0-0000-1000-8000-00805F9B34FB"
|
||||
],
|
||||
"deviceId": "469FB381-B47E-1E40-8073-EF50B5704AAB",
|
||||
"name": "EF4651",
|
||||
"linkStatu": false,
|
||||
"isTarget": true
|
||||
},
|
||||
{
|
||||
"RSSI": -69,
|
||||
"advertisData": "",
|
||||
"advertisServiceUUIDs": [
|
||||
"0000FFE0-0000-1000-8000-00805F9B34FB"
|
||||
],
|
||||
"deviceId": "4F0DAC91-4391-CB07-905E-72D7F03EFCD3",
|
||||
"name": "4877-BF743D",
|
||||
"linkStatu": false
|
||||
}
|
||||
];
|
||||
|
||||
|
||||
these.PairEquip = [this.EquipMents[0]];
|
||||
this.$forceUpdate();
|
||||
console.error("1111111111")
|
||||
this.PairEquip=[this.EquipMents[0]];
|
||||
|
||||
return;
|
||||
}
|
||||
ble = bleTool.getBleTool();
|
||||
this.refreshLinked();
|
||||
|
||||
let StartSubsrib = () => {
|
||||
|
||||
these.EquipMents = [];
|
||||
if (!ble) {
|
||||
ble = bleTool.getBleTool();
|
||||
@ -318,6 +274,7 @@
|
||||
}
|
||||
console.log("处理蓝牙不可用");
|
||||
hideLoading(these);
|
||||
console.error("1111111111")
|
||||
these.PairEquip = [];
|
||||
these.EquipMents = [];
|
||||
uni.showToast({
|
||||
@ -328,6 +285,22 @@
|
||||
|
||||
}, pagePath);
|
||||
|
||||
//蓝牙恢复可用的回调
|
||||
ble.addStateRecoveryCallback(res => {
|
||||
if (these.Status.isPageHidden) {
|
||||
return;
|
||||
}
|
||||
these.Status.BottomMenu.show = false;
|
||||
console.error("1111111111")
|
||||
these.PairEquip = [];
|
||||
these.EquipMents = [];
|
||||
uni.showToast({
|
||||
icon: 'fail',
|
||||
title: '蓝牙恢复可用'
|
||||
});
|
||||
these.refreshBleList();
|
||||
}), pagePath;
|
||||
|
||||
//蓝牙断开连接的回调
|
||||
ble.addDisposeCallback(res => {
|
||||
if (these.Status.isPageHidden) {
|
||||
@ -336,10 +309,7 @@
|
||||
// console.log("处理蓝牙断开连接");
|
||||
|
||||
|
||||
these.PairEquip.find(function(v, ind) {
|
||||
these.PairEquip.splice(ind, 1);
|
||||
return v.deviceId == res.deviceId;
|
||||
});
|
||||
these.refreshLinked();
|
||||
|
||||
setTimeout(() => {
|
||||
hideLoading(these);
|
||||
@ -398,39 +368,31 @@
|
||||
these.EquipMents.sort((a, b) => b.RSSI - a.RSSI); //信号好的排前面,一般信号好的是目标设备
|
||||
}
|
||||
}, pagePath);
|
||||
|
||||
//蓝牙连接已恢复的回调
|
||||
ble.addRecoveryCallback(res => {
|
||||
if (these.Status.isPageHidden) {
|
||||
return;
|
||||
}
|
||||
these.refreshLinked();
|
||||
|
||||
// hideLoading(these);
|
||||
|
||||
if (!these.device) {
|
||||
hideLoading(these);
|
||||
}else{
|
||||
clearInterval(this.Status.intval);
|
||||
these.DeviceVerdict(res.deviceId);
|
||||
}
|
||||
|
||||
|
||||
}, pagePath);
|
||||
}
|
||||
|
||||
let startValidDevice = () => {
|
||||
if (these.device) {
|
||||
console.log("进入配对模式,启用连接恢复和验证逻辑。");
|
||||
//蓝牙连接已恢复的回调
|
||||
ble.addRecoveryCallback(res => {
|
||||
if (these.Status.isPageHidden) {
|
||||
return;
|
||||
}
|
||||
// hideLoading(these);
|
||||
these.EquipMents.find(function(v, ind) {
|
||||
if (v.deviceId == res.deviceId) {
|
||||
these.PairEquip.push(v);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
if (these.device) {
|
||||
clearInterval(this.Status.intval);
|
||||
showLoading(these, {
|
||||
text: '蓝牙连接已恢复,正在验证设备'
|
||||
});
|
||||
|
||||
setTimeout(() => {
|
||||
these.DeviceVerdict(res.deviceId);
|
||||
}, 0);
|
||||
} else {
|
||||
hideLoading(these);
|
||||
}
|
||||
|
||||
|
||||
}, pagePath);
|
||||
|
||||
|
||||
//收到设备的消息回调
|
||||
ble.addReceiveCallback((receivData, f, path, arr) => {
|
||||
@ -452,7 +414,7 @@
|
||||
showLoading(these, {
|
||||
text: '正在验证设备'
|
||||
});
|
||||
|
||||
|
||||
setTimeout(() => {
|
||||
these.DeviceVerdict(f.deviceId);
|
||||
}, 0);
|
||||
@ -464,15 +426,33 @@
|
||||
|
||||
StartSubsrib();
|
||||
|
||||
|
||||
|
||||
|
||||
},
|
||||
|
||||
onShow: function() {
|
||||
debugger;
|
||||
this.Status.isPageHidden = false;
|
||||
this.Status.navigateTO = false;
|
||||
this.refreshBleList();
|
||||
this.refreshLinked();
|
||||
},
|
||||
methods: {
|
||||
refreshLinked(){
|
||||
|
||||
|
||||
|
||||
if(ble){
|
||||
let arr=[];
|
||||
arr=ble.data.LinkedList.filter(v=>{
|
||||
return v.Linked;
|
||||
});
|
||||
this.PairEquip=arr;
|
||||
}
|
||||
|
||||
|
||||
},
|
||||
checkAndRequestLocationPermission() {
|
||||
return new Promise((resolve) => {
|
||||
|
||||
@ -490,24 +470,22 @@
|
||||
console.log('定位权限已授予');
|
||||
resolve(true);
|
||||
} else {
|
||||
console.warn('定位权限被拒绝');
|
||||
uni.showModal({
|
||||
title: '权限提醒',
|
||||
content: '为了正常扫描蓝牙设备,需要您开启定位权限',
|
||||
showCancel: false,
|
||||
success: () => {
|
||||
uni.openSetting(); // 引导用户去设置页
|
||||
}
|
||||
});
|
||||
// console.warn('定位权限被拒绝');
|
||||
|
||||
MsgClear(these);
|
||||
showPop({
|
||||
headerTxt: '权限提醒',
|
||||
message: '扫描蓝牙设备,需要您开启定位权限',
|
||||
buttonText: '去开启',
|
||||
okCallback: uni.openSetting
|
||||
}, these, true);
|
||||
|
||||
resolve(false);
|
||||
}
|
||||
},
|
||||
(error) => {
|
||||
console.error('请求定位权限失败:', error);
|
||||
uni.showToast({
|
||||
title: '权限请求异常',
|
||||
icon: 'none'
|
||||
});
|
||||
|
||||
MsgError('请求定位权限失败:' + error.code, '确定', these);
|
||||
resolve(false);
|
||||
}
|
||||
);
|
||||
@ -537,7 +515,7 @@
|
||||
}
|
||||
}
|
||||
showLoading(these, {
|
||||
text: '正在刷新'
|
||||
text: '正在扫描蓝牙设备'
|
||||
})
|
||||
let time = null;
|
||||
let startSearch = () => {
|
||||
@ -548,20 +526,19 @@
|
||||
|
||||
time = setTimeout(() => {
|
||||
these.EquipMents = [];
|
||||
these.PairEquip = [];
|
||||
|
||||
|
||||
ble.StartSearch().then(result => {
|
||||
console.log("开始搜索成功", result);
|
||||
// console.log("开始搜索成功", result);
|
||||
|
||||
}).catch(err => {
|
||||
console.error("开始搜索失败:", err);
|
||||
if (err.code === 10001) {
|
||||
these.showOpenSetting();
|
||||
} else {
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: '出现错误:' + err.msg
|
||||
});
|
||||
|
||||
MsgClear(these);
|
||||
MsgError('出现错误:' + err.msg, '确定', these);
|
||||
|
||||
}
|
||||
}).finally(() => {
|
||||
@ -571,7 +548,9 @@
|
||||
|
||||
}
|
||||
|
||||
ble.StopSearch().finally(startSearch);
|
||||
ble.StopSearch().catch(err => {
|
||||
console.error("err=", err);
|
||||
}).finally(startSearch);
|
||||
|
||||
|
||||
|
||||
@ -698,13 +677,14 @@
|
||||
|
||||
text: "等待设备上报Mac地址," + these.Status.time + 's'
|
||||
});
|
||||
console.log("11111111", this.Status.time);
|
||||
|
||||
clearInterval(this.Status.intval);
|
||||
this.Status.intval = null;
|
||||
|
||||
this.Status.intval = setInterval(() => {
|
||||
this.Status.time = this.Status.time - 1;
|
||||
if (this.Status.time < 0) {
|
||||
hideLoading(these);
|
||||
console.log("停止倒计时", this.Status.time);
|
||||
clearInterval(this.Status.intval)
|
||||
this.Status.intval = null;
|
||||
@ -724,9 +704,12 @@
|
||||
}
|
||||
|
||||
updateLoading(these, {
|
||||
|
||||
text: "等待设备上报Mac地址," + these.Status.time + 's'
|
||||
});
|
||||
|
||||
}, 1000);
|
||||
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
@ -742,14 +725,7 @@
|
||||
let index = 1;
|
||||
let total = 5;
|
||||
|
||||
let linkCallback = (res) => {
|
||||
let c = these.PairEquip.find(function(v) {
|
||||
return v.deviceId == item.deviceId;
|
||||
});
|
||||
if (!c) {
|
||||
|
||||
these.PairEquip.push(item);
|
||||
}
|
||||
let linkCallback = (res) => {
|
||||
console.log("连接成功", these.device);
|
||||
if (!these.device) {
|
||||
console.log("跳转到绑定")
|
||||
@ -760,19 +736,18 @@
|
||||
|
||||
},
|
||||
success(res) {
|
||||
|
||||
these.Status.navigateTO = true;
|
||||
res.eventChannel.emit('LinkItem', item);
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
// console.log("验证设备")
|
||||
// these.DeviceVerdict(item.deviceId);
|
||||
|
||||
}
|
||||
let execLink = () => {
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
|
||||
|
||||
if (index > total) {
|
||||
reject({
|
||||
msg: "连接超时"
|
||||
@ -780,6 +755,7 @@
|
||||
return;
|
||||
}
|
||||
ble.LinkBlue(item.deviceId).then((res) => {
|
||||
this.tmpLink=[item];
|
||||
console.log("连接成功");
|
||||
ble.StopSearch();
|
||||
resolve(res);
|
||||
@ -806,15 +782,31 @@
|
||||
linkCallback(res);
|
||||
}).catch(ex => {
|
||||
console.error("ex=", ex)
|
||||
uni.showModal({
|
||||
content: "连接失败:" + ex.msg
|
||||
});
|
||||
MsgClear(these);
|
||||
|
||||
MsgError("连接失败:" + ex.msg, '确定', these);
|
||||
hideLoading(these);
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
},
|
||||
disConnect:function(item,index){
|
||||
// #ifdef H5|WEB
|
||||
|
||||
this.PairEquip.splice(index,1);
|
||||
|
||||
// #endif
|
||||
// #ifdef APP|APP-PLUS
|
||||
if(ble){
|
||||
ble.disconnectDevice(item.deviceId).catch(ex=>{
|
||||
console.error("无法断开连接",ex);
|
||||
});
|
||||
}
|
||||
// #endif
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -954,7 +946,7 @@
|
||||
position: absolute;
|
||||
top: 240rpx;
|
||||
left: 0rpx;
|
||||
/* border: 1px solid #BBE600; */
|
||||
z-index: 101;
|
||||
}
|
||||
|
||||
|
||||
@ -998,7 +990,7 @@
|
||||
box-sizing: border-box;
|
||||
padding: 20rpx;
|
||||
border-radius: 8px;
|
||||
background: #1a1a1a;
|
||||
background: #1a1a1a9e;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
flex-wrap: nowrap;
|
||||
|
||||
@ -304,14 +304,14 @@
|
||||
|
||||
},
|
||||
bleBreak(res) {
|
||||
console.error("蓝牙断开连接", res);
|
||||
// console.error("蓝牙断开连接", res);
|
||||
if (res.deviceId) {
|
||||
this.updateBleStatu(res.deviceId);
|
||||
}
|
||||
|
||||
},
|
||||
bleRecovery(res) {
|
||||
console.log("蓝牙连接成功", res);
|
||||
// console.log("蓝牙连接成功", res);
|
||||
if (res.deviceId) {
|
||||
this.updateBleStatu(res.deviceId);
|
||||
}
|
||||
|
||||
@ -106,6 +106,18 @@
|
||||
}
|
||||
|
||||
}
|
||||
let appid='';
|
||||
// #ifdef APP|APP-PLUS
|
||||
appid = plus.runtime.appid;
|
||||
// #endif
|
||||
// #ifdef WEB
|
||||
appid='HBuilder';
|
||||
// #endif
|
||||
if (appid === 'HBuilder') {
|
||||
this.phone='17671332251';
|
||||
this.password='123456';
|
||||
this.isChecked=true;
|
||||
}
|
||||
|
||||
},
|
||||
methods: {
|
||||
|
||||
536
temp_hby100j_ebe126d.js
Normal file
536
temp_hby100j_ebe126d.js
Normal file
@ -0,0 +1,536 @@
|
||||
import request from '@/utils/request'
|
||||
import Common from '@/utils/Common.js'
|
||||
|
||||
// ================== 钃濈墮鍗忚灏佽绫?==================
|
||||
class HBY100JProtocol {
|
||||
constructor() {
|
||||
this.deviceId = ''; // 4G 鎺ュ彛鎵€闇€鐨?deviceId
|
||||
this.isBleConnected = false;
|
||||
this.bleDeviceId = ''; // 灏忕▼搴?APP涓繛鎺ヨ摑鐗欑殑 deviceId
|
||||
|
||||
// 钃濈墮鏈嶅姟涓庣壒寰佸€?UUID
|
||||
this.SERVICE_UUID = '0000AE30-0000-1000-8000-00805F9B34FB'; // 0xAE30
|
||||
this.WRITE_UUID = '0000AE03-0000-1000-8000-00805F9B34FB'; // 0xAE03
|
||||
this.NOTIFY_UUID = '0000AE02-0000-1000-8000-00805F9B34FB'; // 0xAE02
|
||||
|
||||
this.onNotifyCallback = null;
|
||||
this._fileResponseResolve = null; // 鏂囦欢涓婁紶鏃剁瓑寰呰澶?FB 05 鍝嶅簲
|
||||
}
|
||||
|
||||
// 绛夊緟璁惧 FB 05 鍝嶅簲锛岃秴鏃跺悗浠?resolve锛堣澶囧彲鑳戒笉鍝嶅簲姣忓寘锛? waitForFileResponse(timeoutMs = 2000) {
|
||||
return new Promise((resolve) => {
|
||||
const timer = setTimeout(() => {
|
||||
if (this._fileResponseResolve) {
|
||||
this._fileResponseResolve = null;
|
||||
resolve(null);
|
||||
}
|
||||
}, timeoutMs);
|
||||
this._fileResponseResolve = (result) => {
|
||||
clearTimeout(timer);
|
||||
this._fileResponseResolve = null;
|
||||
resolve(result);
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
setBleConnectionStatus(status, bleDeviceId = '') {
|
||||
this.isBleConnected = status;
|
||||
if (bleDeviceId) {
|
||||
this.bleDeviceId = bleDeviceId;
|
||||
}
|
||||
}
|
||||
|
||||
onNotify(callback) {
|
||||
this.onNotifyCallback = callback;
|
||||
}
|
||||
|
||||
parseBleData(buffer) {
|
||||
const view = buffer instanceof Uint8Array ? buffer : new Uint8Array(buffer);
|
||||
if (view.length < 3) return null;
|
||||
|
||||
const header = view[0];
|
||||
const tail = view[view.length - 1];
|
||||
|
||||
// 5.1 杩炴帴钃濈墮璁惧涓诲姩涓婃姤 MAC 鍦板潃: FC + 6瀛楄妭MAC + FF
|
||||
if (header === 0xFC && tail === 0xFF && view.length >= 8) {
|
||||
const macBytes = view.slice(1, 7);
|
||||
const macAddress = Array.from(macBytes).map(b => b.toString(16).padStart(2, '0').toUpperCase()).join(':');
|
||||
const result = { type: 'mac', macAddress };
|
||||
console.log('[100J-钃濈墮] 璁惧涓婃姤MAC:', macAddress, '鍘熷:', Array.from(view).map(b => b.toString(16).padStart(2, '0').toUpperCase()).join(' '));
|
||||
if (this.onNotifyCallback) this.onNotifyCallback(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
if (header !== 0xFB || tail !== 0xFF) return null; // 鏍¢獙澶村熬
|
||||
|
||||
const funcCode = view[1];
|
||||
const data = view.slice(2, view.length - 1);
|
||||
const hexStr = Array.from(view).map(b => b.toString(16).padStart(2, '0').toUpperCase()).join(' ');
|
||||
|
||||
let result = { funcCode, rawData: data };
|
||||
|
||||
switch (funcCode) {
|
||||
case 0x01: result.resetType = data[0]; break;
|
||||
case 0x02: break;
|
||||
case 0x03:
|
||||
// 5.4 鑾峰彇璁惧浣嶇疆锛氱粡搴?B+绾害8B 鍧囦负 float64锛岃澶囦富鍔ㄤ笂鎶?1鍒嗛挓)涓庝富鍔ㄦ煡璇㈠搷搴旀牸寮忕浉鍚? if (data.length >= 16) {
|
||||
const lonBuf = new ArrayBuffer(8);
|
||||
const latBuf = new ArrayBuffer(8);
|
||||
new Uint8Array(lonBuf).set(data.slice(0, 8));
|
||||
new Uint8Array(latBuf).set(data.slice(8, 16));
|
||||
result.longitude = new DataView(lonBuf).getFloat64(0, true);
|
||||
result.latitude = new DataView(latBuf).getFloat64(0, true);
|
||||
}
|
||||
break;
|
||||
case 0x05:
|
||||
// 05: 鏂囦欢鏇存柊鍝嶅簲 FB 05 [fileType] [status] FF锛宻tatus: 1=鎴愬姛 2=澶辫触
|
||||
if (data.length >= 1) result.fileType = data[0];
|
||||
if (data.length >= 2) result.fileStatus = data[1]; // 1=Success, 2=Failure
|
||||
if (this._fileResponseResolve) this._fileResponseResolve(result);
|
||||
break;
|
||||
case 0x04:
|
||||
// 5.5 鑾峰彇璁惧鐢垫簮鐘舵€? 鐢垫睜瀹归噺8B + 鐢靛帇8B + 鐧惧垎姣?B + 杞﹁浇鐢垫簮1B + 缁埅鏃堕棿2B(鍒嗛挓)
|
||||
if (data.length >= 20) {
|
||||
result.batteryPercentage = data[16];
|
||||
result.vehiclePower = data[17];
|
||||
result.batteryRemainingTime = data[18] | (data[19] << 8); // 灏忕搴忥紝鍗曚綅鍒嗛挓
|
||||
}
|
||||
break;
|
||||
case 0x06:
|
||||
// 06: 璇煶鎾姤鍝嶅簲
|
||||
result.voiceBroadcast = data[0];
|
||||
break;
|
||||
case 0x09:
|
||||
// 09: 淇敼闊抽噺鍝嶅簲
|
||||
result.volume = data[0];
|
||||
break;
|
||||
case 0x0A:
|
||||
// 0A: 鐖嗛棯妯″紡鍝嶅簲
|
||||
result.strobeEnable = data[0];
|
||||
result.strobeMode = data[1];
|
||||
break;
|
||||
case 0x0B:
|
||||
// 0B: 淇敼璀︾ず鐏垎闂鐜囧搷搴? result.strobeFrequency = data[0];
|
||||
break;
|
||||
case 0x0C:
|
||||
// 0C: 寮哄埗澹板厜鎶ヨ鍝嶅簲
|
||||
result.alarmEnable = data[0];
|
||||
result.alarmMode = data[1];
|
||||
break;
|
||||
case 0x0D:
|
||||
// 0D: 璀︾ず鐏?LED 浜害璋冭妭鍝嶅簲
|
||||
result.redBrightness = data[0];
|
||||
result.blueBrightness = data[1];
|
||||
result.yellowBrightness = data[2];
|
||||
break;
|
||||
case 0x0E:
|
||||
// 0E: 鑾峰彇褰撳墠宸ヤ綔鏂瑰紡鍝嶅簲
|
||||
result.voiceBroadcast = data[0];
|
||||
result.alarmEnable = data[1];
|
||||
result.alarmMode = data[2];
|
||||
result.strobeEnable = data[3];
|
||||
result.strobeMode = data[4];
|
||||
result.strobeFrequency = data[5];
|
||||
result.volume = data[6];
|
||||
result.redBrightness = data[7];
|
||||
result.blueBrightness = data[8];
|
||||
result.yellowBrightness = data[9];
|
||||
break;
|
||||
}
|
||||
|
||||
const funcNames = { 0x01: '澶嶄綅', 0x02: '鍩虹淇℃伅', 0x03: '浣嶇疆', 0x04: '鐢垫簮鐘舵€?, 0x05: '鏂囦欢鏇存柊', 0x06: '璇煶鎾姤', 0x09: '闊抽噺', 0x0A: '鐖嗛棯妯″紡', 0x0B: '鐖嗛棯棰戠巼', 0x0C: '寮哄埗鎶ヨ', 0x0D: 'LED浜害', 0x0E: '宸ヤ綔鏂瑰紡' };
|
||||
const name = funcNames[funcCode] || ('0x' + funcCode.toString(16));
|
||||
console.log('[100J-钃濈墮] 璁惧鍝嶅簲 FB:', name, '瑙f瀽:', JSON.stringify(result), '鍘熷:', hexStr);
|
||||
|
||||
if (this.onNotifyCallback) {
|
||||
this.onNotifyCallback(result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
sendBleData(funcCode, dataBytes = []) {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (!this.isBleConnected || !this.bleDeviceId) {
|
||||
return reject(new Error('钃濈墮鏈繛鎺?));
|
||||
}
|
||||
|
||||
const buffer = new ArrayBuffer(dataBytes.length + 3);
|
||||
const view = new Uint8Array(buffer);
|
||||
view[0] = 0xFA; // 鏁版嵁澶? view[1] = funcCode; // 鍔熻兘鐮? for (let i = 0; i < dataBytes.length; i++) {
|
||||
view[2 + i] = dataBytes[i];
|
||||
}
|
||||
view[view.length - 1] = 0xFF; // 缁撳熬
|
||||
const sendHex = Array.from(view).map(b => b.toString(16).padStart(2, '0').toUpperCase()).join(' ');
|
||||
console.log('[100J-钃濈墮] 涓嬪彂鎸囦护 FA:', '0x' + funcCode.toString(16).toUpperCase(), sendHex);
|
||||
|
||||
// 浣跨敤椤圭洰涓粺涓€鐨?BleHelper 鍙戦€佹暟鎹? import('@/utils/BleHelper.js').then(module => {
|
||||
const bleTool = module.default.getBleTool();
|
||||
bleTool.sendData(this.bleDeviceId, buffer, this.SERVICE_UUID, this.WRITE_UUID)
|
||||
.then(res => resolve(res))
|
||||
.catch(err => reject(err));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// 绾摑鐗欐寚浠ゅ彂閫佹柟娉? deviceReset(type = 0) { return this.sendBleData(0x01, [type]); }
|
||||
getBasicInfo() { return this.sendBleData(0x02, []); }
|
||||
getLocation() { return this.sendBleData(0x03, []); }
|
||||
getPowerStatus() { return this.sendBleData(0x04, []); }
|
||||
setVoiceBroadcast(enable) { return this.sendBleData(0x06, [enable]); }
|
||||
setVolume(volume) { return this.sendBleData(0x09, [volume]); }
|
||||
setStrobeMode(enable, mode) { return this.sendBleData(0x0A, [enable, mode]); }
|
||||
setStrobeFrequency(frequency) { return this.sendBleData(0x0B, [frequency]); }
|
||||
setForceAlarm(enable, mode) { return this.sendBleData(0x0C, [enable, mode]); }
|
||||
setLightBrightness(red, blue = 0, yellow = 0) { return this.sendBleData(0x0D, [red, blue, yellow]); }
|
||||
getCurrentWorkMode() { return this.sendBleData(0x0E, []); }
|
||||
|
||||
// 0x05 鏂囦欢涓婁紶锛氬垎鐗囦紶杈擄紝鍗忚 FA 05 [fileType] [phase] [data...] FF
|
||||
// fileType: 1=璇煶 2=鍥剧墖 3=鍔ㄥ浘 4=OTA
|
||||
// phase: 0=寮€濮?1=鏁版嵁 2=缁撴潫
|
||||
// 姣忓寘鏈€澶у瓧鑺?钃濈墮锛欳HUNK_SIZE=500
|
||||
// 鏀寔 fileUrl(闇€缃戠粶涓嬭浇) 鎴?localPath(鏃犵綉缁滄椂鏈湴鏂囦欢)
|
||||
uploadVoiceFileBle(fileUrlOrLocalPath, fileType = 1, onProgress) {
|
||||
const CHUNK_SIZE = 500; // 姣忓寘鏈夋晥鏁版嵁锛屽弬鑰?6155 deviceDetail.vue
|
||||
return new Promise((resolve, reject) => {
|
||||
if (!this.isBleConnected || !this.bleDeviceId) {
|
||||
return reject(new Error('钃濈墮鏈繛鎺?));
|
||||
}
|
||||
if (!fileUrlOrLocalPath) {
|
||||
return reject(new Error('缂哄皯鏂囦欢鍦板潃鎴栨湰鍦拌矾寰?));
|
||||
}
|
||||
const isLocalPath = !/^https?:\/\//i.test(fileUrlOrLocalPath);
|
||||
if (onProgress) onProgress(1);
|
||||
const readFromPath = (path) => {
|
||||
const doSend = (bytes) => {
|
||||
this._sendVoiceChunks(bytes, fileType, CHUNK_SIZE, onProgress)
|
||||
.then(resolve).catch(reject);
|
||||
};
|
||||
// App 绔?getFileSystemManager 鏈疄鐜帮紝鐩存帴鐢?plus.io.requestFileSystem+getFile
|
||||
readFromPathPlus(path, doSend, reject);
|
||||
};
|
||||
const readFileEntry = (entry, doSend, reject) => {
|
||||
entry.file((file) => {
|
||||
const reader = new plus.io.FileReader();
|
||||
reader.onloadend = (e) => {
|
||||
try {
|
||||
const buf = e.target.result;
|
||||
const bytes = new Uint8Array(buf);
|
||||
doSend(bytes);
|
||||
} catch (err) {
|
||||
console.error('[100J-钃濈墮] 璇诲彇ArrayBuffer寮傚父:', err);
|
||||
reject(err);
|
||||
}
|
||||
};
|
||||
reader.onerror = () => reject(new Error('璇诲彇鏂囦欢澶辫触'));
|
||||
reader.readAsArrayBuffer(file);
|
||||
}, (err) => reject(err));
|
||||
};
|
||||
const readFromPathPlus = (path, doSend, reject) => {
|
||||
if (typeof plus === 'undefined' || !plus.io) {
|
||||
console.error('[100J-钃濈墮] 褰撳墠鐜涓嶆敮鎸佹枃浠惰鍙?plus.io)');
|
||||
reject(new Error('褰撳墠鐜涓嶆敮鎸佹枃浠惰鍙?));
|
||||
return;
|
||||
}
|
||||
// _downloads/ 鐢?requestFileSystem+getFile锛堥伩鍏?resolveLocalFileSystemURL 鍗′綇锛? if (path && path.startsWith('_downloads/')) {
|
||||
const fileName = path.replace(/^_downloads\//, '');
|
||||
plus.io.requestFileSystem(plus.io.PUBLIC_DOWNLOADS, (fs) => {
|
||||
fs.root.getFile(fileName, {}, (entry) => readFileEntry(entry, doSend, reject), (err) => reject(err));
|
||||
}, (err) => reject(err));
|
||||
return;
|
||||
}
|
||||
// _doc/ 鐢?requestFileSystem(PRIVATE_DOC)锛岄€愮骇 getDirectory 鍐?getFile锛堝祵濂楄矾寰勫吋瀹癸級
|
||||
if (path && path.startsWith('_doc/')) {
|
||||
const relPath = path.replace(/^_doc\//, '');
|
||||
const parts = relPath.split('/');
|
||||
const fileName = parts.pop();
|
||||
const dirs = parts;
|
||||
plus.io.requestFileSystem(plus.io.PRIVATE_DOC, (fs) => {
|
||||
let cur = fs.root;
|
||||
const next = (i) => {
|
||||
if (i >= dirs.length) {
|
||||
cur.getFile(fileName, { create: false }, (entry) => readFileEntry(entry, doSend, reject), (err) => reject(err));
|
||||
return;
|
||||
}
|
||||
cur.getDirectory(dirs[i], { create: false }, (dir) => { cur = dir; next(i + 1); }, (err) => reject(err));
|
||||
};
|
||||
next(0);
|
||||
}, (err) => reject(err));
|
||||
return;
|
||||
}
|
||||
// 鍏朵粬璺緞鍏滃簳
|
||||
let resolvePath = path;
|
||||
if (path && path.startsWith('/') && !path.startsWith('file://')) resolvePath = 'file://' + path;
|
||||
plus.io.resolveLocalFileSystemURL(resolvePath, (entry) => readFileEntry(entry, doSend, reject), (err) => reject(err));
|
||||
};
|
||||
if (isLocalPath) {
|
||||
// 鏈湴璺緞锛氭棤缃戠粶鏃剁洿鎺ヨ鍙? readFromPath(fileUrlOrLocalPath);
|
||||
} else {
|
||||
// 缃戠粶 URL锛氫紭鍏堢敤 uni.request 鐩存帴鎷夊彇 ArrayBuffer锛堢被浼?100 璁惧锛屾棤鏂囦欢 IO锛夛紝澶辫触鍐嶈蛋 downloadFile
|
||||
let fetchUrl = fileUrlOrLocalPath;
|
||||
if (fetchUrl.startsWith('http://')) fetchUrl = 'https://' + fetchUrl.slice(7);
|
||||
uni.request({
|
||||
url: fetchUrl,
|
||||
method: 'GET',
|
||||
responseType: 'arraybuffer',
|
||||
timeout: 60000,
|
||||
success: (res) => {
|
||||
if (res.statusCode === 200 && res.data) {
|
||||
const bytes = res.data instanceof ArrayBuffer ? new Uint8Array(res.data) : new Uint8Array(res.data || []);
|
||||
if (bytes.length > 0) {
|
||||
const doSend = (b) => {
|
||||
this._sendVoiceChunks(b, fileType, CHUNK_SIZE, onProgress).then(resolve).catch(reject);
|
||||
};
|
||||
doSend(bytes);
|
||||
return;
|
||||
}
|
||||
}
|
||||
fallbackDownload();
|
||||
},
|
||||
fail: () => fallbackDownload()
|
||||
});
|
||||
const fallbackDownload = () => {
|
||||
uni.downloadFile({
|
||||
url: fetchUrl,
|
||||
success: (res) => {
|
||||
if (res.statusCode !== 200 || !res.tempFilePath) {
|
||||
reject(new Error('涓嬭浇澶辫触: ' + (res.statusCode || '鏃犺矾寰?)));
|
||||
return;
|
||||
}
|
||||
Common.moveFileToDownloads(res.tempFilePath).then((p) => readFromPath(p)).catch(() => readFromPath(res.tempFilePath));
|
||||
},
|
||||
fail: (err) => reject(err)
|
||||
});
|
||||
};
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
_sendVoiceChunks(bytes, fileType, chunkSize, onProgress) {
|
||||
const total = bytes.length;
|
||||
const ft = (fileType & 0xFF) || 1;
|
||||
const DELAY_AFTER_START = 200; // 寮€濮嬪寘鍚庛€佺瓑璁惧鍝嶅簲鍚庡啀鍙戠殑缂撳啿(ms)
|
||||
const DELAY_PACKET = 200; // 鏁版嵁鍖呴棿寤舵椂(ms)锛岃澶囨敹涓嶅叏鏃堕€傚綋鍔犲ぇ
|
||||
const toHex = (arr) => Array.from(arr).map(b => b.toString(16).padStart(2, '0').toUpperCase()).join(' ');
|
||||
console.log('[100J-钃濈墮] 璇煶鏂囦欢鎬诲ぇ灏?', total, '瀛楄妭, fileType=', ft);
|
||||
if (onProgress) onProgress(0);
|
||||
const bleToolPromise = import('@/utils/BleHelper.js').then(m => m.default.getBleTool());
|
||||
const send = (dataBytes, label = '') => {
|
||||
const buf = new ArrayBuffer(dataBytes.length + 3);
|
||||
const v = new Uint8Array(buf);
|
||||
v[0] = 0xFA;
|
||||
v[1] = 0x05;
|
||||
for (let i = 0; i < dataBytes.length; i++) v[2 + i] = dataBytes[i];
|
||||
v[v.length - 1] = 0xFF;
|
||||
const hex = toHex(v);
|
||||
const preview = v.length <= 32 ? hex : hex.slice(0, 96) + '...';
|
||||
console.log(`[100J-钃濈墮] 鍙戦€?{label} 鍏?{v.length}瀛楄妭:`, preview);
|
||||
return bleToolPromise.then(ble => ble.sendData(this.bleDeviceId, buf, this.SERVICE_UUID, this.WRITE_UUID));
|
||||
};
|
||||
const delay = (ms) => new Promise(r => setTimeout(r, ms));
|
||||
// 寮€濮嬪寘: FA 05 [fileType] [phase=0] [size 4B LE] FF
|
||||
const startData = [ft, 0, total & 0xFF, (total >> 8) & 0xFF, (total >> 16) & 0xFF, (total >> 24) & 0xFF];
|
||||
const waitPromise = this.waitForFileResponse(1000);
|
||||
return send(startData, ' 寮€濮嬪寘')
|
||||
.then(() => { if (onProgress) onProgress(1); return waitPromise; })
|
||||
.then(() => { if (onProgress) onProgress(2); return delay(DELAY_AFTER_START); })
|
||||
.then(() => {
|
||||
let seq = 0;
|
||||
const sendNext = (offset) => {
|
||||
if (offset >= total) {
|
||||
return delay(DELAY_PACKET).then(() => send([ft, 2], ' 缁撴潫鍖?));
|
||||
}
|
||||
const chunk = bytes.slice(offset, Math.min(offset + chunkSize, total));
|
||||
const chunkData = [ft, 1, seq & 0xFF, (seq >> 8) & 0xFF, ...chunk];
|
||||
return send(chunkData, ` #${seq} 鏁版嵁鍖卄).then(() => {
|
||||
seq++;
|
||||
const pct = Math.round((offset + chunk.length) / total * 100);
|
||||
if (onProgress) onProgress(Math.min(99, Math.max(3, pct)));
|
||||
return delay(DELAY_PACKET).then(() => sendNext(offset + chunk.length));
|
||||
});
|
||||
};
|
||||
return sendNext(0);
|
||||
})
|
||||
.then(() => delay(DELAY_PACKET))
|
||||
.then(() => {
|
||||
if (onProgress) onProgress(100);
|
||||
return { code: 200, msg: '璇煶鏂囦欢宸查€氳繃钃濈墮涓婁紶' };
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// ================== 鍏ㄥ眬鍗曚緥涓庣姸鎬佺鐞?==================
|
||||
const protocolInstance = new HBY100JProtocol();
|
||||
|
||||
// 鏆撮湶缁欓〉闈細鏇存柊钃濈墮杩炴帴鐘舵€?export function updateBleStatus(isConnected, bleDeviceId, deviceId) {
|
||||
protocolInstance.setBleConnectionStatus(isConnected, bleDeviceId);
|
||||
protocolInstance.deviceId = deviceId;
|
||||
console.log('[100J] 钃濈墮鐘舵€?', isConnected ? '宸茶繛鎺?鍚庣画鎸囦护璧拌摑鐗?' : '宸叉柇寮€(鍚庣画鎸囦护璧?G)', { bleDeviceId: bleDeviceId || '-', deviceId });
|
||||
}
|
||||
|
||||
// 鏆撮湶缁欓〉闈細瑙f瀽钃濈墮鎺ユ敹鍒扮殑鏁版嵁
|
||||
export function parseBleData(buffer) {
|
||||
return protocolInstance.parseBleData(buffer);
|
||||
}
|
||||
|
||||
// 鏆撮湶缁欓〉闈細钃濈墮杩炴帴鍚庝富鍔ㄦ媺鍙栫數婧愮姸鎬?鐢甸噺銆佺画鑸?
|
||||
export function fetchBlePowerStatus() {
|
||||
if (!protocolInstance.isBleConnected) return Promise.reject(new Error('钃濈墮鏈繛鎺?));
|
||||
console.log('[100J-钃濈墮] 鎷夊彇鐢垫簮鐘舵€?宸查€氳繃钃濈墮鍙戦€?FA 04 FF');
|
||||
return protocolInstance.getPowerStatus();
|
||||
}
|
||||
|
||||
// 鏆撮湶缁欓〉闈細钃濈墮杩炴帴鍚庝富鍔ㄦ媺鍙栧畾浣?浼樺厛钃濈墮锛岃澶囦篃浼氭瘡1鍒嗛挓涓诲姩涓婃姤)
|
||||
export function fetchBleLocation() {
|
||||
if (!protocolInstance.isBleConnected) return Promise.reject(new Error('钃濈墮鏈繛鎺?));
|
||||
console.log('[100J-钃濈墮] 鎷夊彇瀹氫綅 宸查€氳繃钃濈墮鍙戦€?FA 03 FF');
|
||||
return protocolInstance.getLocation();
|
||||
}
|
||||
|
||||
// 鏆撮湶缁欓〉闈細灏濊瘯閲嶈繛钃濈墮(浼樺厛绛栫暐锛氭柇绾垮悗鍙戞寚浠ゅ墠鍏堝皾璇曢噸杩?
|
||||
export function tryReconnectBle(timeoutMs = 2500) {
|
||||
if (protocolInstance.isBleConnected) return Promise.resolve(true);
|
||||
if (!protocolInstance.bleDeviceId) return Promise.resolve(false);
|
||||
return new Promise((resolve) => {
|
||||
import('@/utils/BleHelper.js').then(module => {
|
||||
const bleTool = module.default.getBleTool();
|
||||
const deviceId = protocolInstance.bleDeviceId;
|
||||
const f = bleTool.data.LinkedList.find(v => v.deviceId === deviceId);
|
||||
if (!f) {
|
||||
resolve(false);
|
||||
return;
|
||||
}
|
||||
const svc = f.writeServiceId || '0000AE30-0000-1000-8000-00805F9B34FB';
|
||||
const write = f.wirteCharactId || '0000AE03-0000-1000-8000-00805F9B34FB';
|
||||
const notify = f.notifyCharactId || '0000AE02-0000-1000-8000-00805F9B34FB';
|
||||
const timer = setTimeout(() => {
|
||||
resolve(protocolInstance.isBleConnected);
|
||||
}, timeoutMs);
|
||||
console.log('[100J] 钃濈墮浼樺厛锛氬皾璇曢噸杩?, deviceId);
|
||||
bleTool.LinkBlue(deviceId, svc, write, notify, 1).then(() => {
|
||||
clearTimeout(timer);
|
||||
protocolInstance.setBleConnectionStatus(true, deviceId);
|
||||
console.log('[100J] 钃濈墮閲嶈繛鎴愬姛');
|
||||
resolve(true);
|
||||
}).catch(() => {
|
||||
clearTimeout(timer);
|
||||
resolve(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// ================== API 鎺ュ彛 (鎷︽埅灞? ==================
|
||||
|
||||
// 鑾峰彇璇煶绠$悊鍒楄〃
|
||||
export function deviceVoliceList(params) {
|
||||
return request({
|
||||
url: `/app/video/queryAudioFileList`,
|
||||
method: 'get',
|
||||
data:params
|
||||
})
|
||||
}
|
||||
// 閲嶅懡鍚?export function videRenameAudioFile(data) {
|
||||
return request({
|
||||
url: `/app/video/renameAudioFile`,
|
||||
method: 'post',
|
||||
data:data
|
||||
})
|
||||
}
|
||||
// 鍒犻櫎璇煶鏂囦欢鍒楄〃
|
||||
export function deviceDeleteAudioFile(params) {
|
||||
return request({
|
||||
url: `/app/video/deleteAudioFile`,
|
||||
method: 'get',
|
||||
data:params
|
||||
})
|
||||
}
|
||||
|
||||
// 鏇存柊璇煶/浣跨敤璇煶锛氳摑鐗欎紭鍏堬紝4G 鍏滃簳锛堜笉褰卞搷鍘熸湁 4G 闊抽涓嬪彂锛?// 鏈?fileUrl 鎴?localPath 涓旇摑鐗欏彲鐢ㄦ椂璧拌摑鐗欙紱鍚﹀垯鎴栬摑鐗欏け璐ユ椂璧?4G锛堜笌鍘熷厛閫昏緫涓€鑷达級
|
||||
export function deviceUpdateVoice(data) {
|
||||
const httpExec = () => request({
|
||||
url: `/app/hby100j/device/updateVoice`,
|
||||
method: 'post',
|
||||
data: { id: data.id }
|
||||
});
|
||||
const localPath = data.localPath;
|
||||
const fileUrl = data.fileUrl;
|
||||
const hasLocalPath = localPath && typeof localPath === 'string' && localPath.length > 0;
|
||||
const hasFileUrl = fileUrl && typeof fileUrl === 'string' && fileUrl.length > 0;
|
||||
const fileSource = hasLocalPath ? localPath : (hasFileUrl ? fileUrl : null);
|
||||
if (!fileSource) {
|
||||
return httpExec(); // 鏃犳枃浠舵簮锛氱洿鎺?4G锛堝師鏈夐€昏緫锛? }
|
||||
const bleExec = () => protocolInstance.uploadVoiceFileBle(fileSource, 1, data.onProgress);
|
||||
return execWithBleFirst(bleExec, httpExec, '璇煶鏂囦欢涓婁紶');
|
||||
}
|
||||
// 100J淇℃伅
|
||||
export function deviceDetail(id) {
|
||||
return request({
|
||||
url: `/app/hby100j/device/${id}`,
|
||||
method: 'get',
|
||||
})
|
||||
}
|
||||
|
||||
// 钃濈墮浼樺厛銆?G 鍏滃簳锛氭湭杩炴帴鏃跺皾璇曢噸杩烇紱钃濈墮澶辫触鏃跺洖閫€ 4G锛堜繚鎸佸師鏈?4G 閫氳涓嶅彉锛?function execWithBleFirst(bleExec, httpExec, logName) {
|
||||
const doBle = () => bleExec().then(res => ({ ...(res || {}), _channel: 'ble' }));
|
||||
const do4G = () => httpExec().then(res => { res._channel = '4g'; return res; });
|
||||
if (protocolInstance.isBleConnected) {
|
||||
return doBle().catch(() => { console.log('[100J] 钃濈墮澶辫触锛屽洖閫€4G'); return do4G(); });
|
||||
}
|
||||
return tryReconnectBle(2500).then(reconnected => {
|
||||
return reconnected ? doBle().catch(() => { console.log('[100J] 钃濈墮澶辫触锛屽洖閫€4G'); return do4G(); }) : do4G();
|
||||
});
|
||||
}
|
||||
|
||||
// 鐖嗛棯妯″紡
|
||||
export function deviceStrobeMode(data) {
|
||||
return execWithBleFirst(
|
||||
() => protocolInstance.setStrobeMode(data.enable, data.mode).then(() => ({ code: 200, msg: '鎿嶄綔鎴愬姛(钃濈墮)' })),
|
||||
() => request({ url: `/app/hby100j/device/strobeMode`, method: 'post', data }),
|
||||
'鐖嗛棯妯″紡'
|
||||
);
|
||||
}
|
||||
|
||||
// 寮哄埗鎶ヨ
|
||||
export function deviceForceAlarmActivation(data) {
|
||||
return execWithBleFirst(
|
||||
() => protocolInstance.setForceAlarm(data.voiceStrobeAlarm, data.mode).then(() => ({ code: 200, msg: '鎿嶄綔鎴愬姛(钃濈墮)' })),
|
||||
() => request({ url: `/app/hby100j/device/forceAlarmActivation`, method: 'post', data }),
|
||||
'寮哄埗鎶ヨ'
|
||||
);
|
||||
}
|
||||
|
||||
// 鐖嗛棯棰戠巼
|
||||
export function deviceStrobeFrequency(data) {
|
||||
return execWithBleFirst(
|
||||
() => protocolInstance.setStrobeFrequency(data.frequency).then(() => ({ code: 200, msg: '鎿嶄綔鎴愬姛(钃濈墮)' })),
|
||||
() => request({ url: `/app/hby100j/device/strobeFrequency`, method: 'post', data }),
|
||||
'鐖嗛棯棰戠巼'
|
||||
);
|
||||
}
|
||||
|
||||
// 鐏厜璋冭妭浜害
|
||||
export function deviceLightAdjustment(data) {
|
||||
return execWithBleFirst(
|
||||
() => protocolInstance.setLightBrightness(data.brightness, data.brightness, data.brightness).then(() => ({ code: 200, msg: '鎿嶄綔鎴愬姛(钃濈墮)' })),
|
||||
() => request({ url: `/app/hby100j/device/lightAdjustment`, method: 'post', data }),
|
||||
'鐏厜浜害'
|
||||
);
|
||||
}
|
||||
|
||||
// 璋冭妭闊抽噺
|
||||
export function deviceUpdateVolume(data) {
|
||||
return execWithBleFirst(
|
||||
() => protocolInstance.setVolume(data.volume).then(() => ({ code: 200, msg: '鎿嶄綔鎴愬姛(钃濈墮)' })),
|
||||
() => request({ url: `/app/hby100j/device/updateVolume`, method: 'post', data }),
|
||||
'璋冭妭闊抽噺'
|
||||
);
|
||||
}
|
||||
|
||||
// 璇煶鎾斁
|
||||
export function deviceVoiceBroadcast(data) {
|
||||
return execWithBleFirst(
|
||||
() => protocolInstance.setVoiceBroadcast(data.voiceBroadcast).then(() => ({ code: 200, msg: '鎿嶄綔鎴愬姛(钃濈墮)' })),
|
||||
() => request({ url: `/app/hby100j/device/voiceBroadcast`, method: 'post', data }),
|
||||
'璇煶鎾姤'
|
||||
);
|
||||
}
|
||||
@ -1,180 +1,180 @@
|
||||
// eslint-disable
|
||||
export const isObject = (obj) => {
|
||||
return obj
|
||||
? Object.prototype.toString.call(obj) === "[object Object]"
|
||||
: false;
|
||||
};
|
||||
export const isArray = (arr) => {
|
||||
return arr ? Array.isArray(arr) : false;
|
||||
};
|
||||
/**
|
||||
* handle async await
|
||||
* @param {*} promise promise
|
||||
*/
|
||||
export const awaitWrap = (promise) =>
|
||||
promise.then((res) => [null, res]).catch((err) => [err, {}]);
|
||||
/**
|
||||
* 深拷贝
|
||||
* @param {*} source
|
||||
*/
|
||||
export const deepClone = (source) => {
|
||||
if (!isObject(source) && !isArray(source)) return source;
|
||||
const targetObj = isArray(source) ? [] : {}; // 判断复制的目标是数组还是对象
|
||||
for (let keys in source) {
|
||||
// 遍历目标
|
||||
if (source.hasOwnProperty(keys)) {
|
||||
if (source[keys] && typeof source[keys] === "object") {
|
||||
// 如果值是对象,就递归一下
|
||||
targetObj[keys] = isArray(source[keys]) ? [] : {};
|
||||
targetObj[keys] = deepClone(source[keys]);
|
||||
} else {
|
||||
// 如果不是,就直接赋值
|
||||
targetObj[keys] = source[keys];
|
||||
}
|
||||
}
|
||||
}
|
||||
return targetObj;
|
||||
};
|
||||
/**
|
||||
* @description JS对象深度合并
|
||||
* @param {object} target 需要拷贝的对象
|
||||
* @param {object} source 拷贝的来源对象
|
||||
* @returns {object|boolean} 深度合并后的对象或者false(入参有不是对象)
|
||||
*/
|
||||
export const deepMerge = (target = {}, source = {}) => {
|
||||
target = deepClone(target);
|
||||
if (typeof target !== "object" || typeof source !== "object") return false;
|
||||
for (const prop in source) {
|
||||
if (!source.hasOwnProperty(prop)) continue;
|
||||
if (prop in target) {
|
||||
if (typeof target[prop] !== "object") {
|
||||
target[prop] = source[prop];
|
||||
} else if (typeof source[prop] !== "object") {
|
||||
target[prop] = source[prop];
|
||||
} else if (target[prop].concat && source[prop].concat) {
|
||||
target[prop] = target[prop].concat(source[prop]);
|
||||
} else {
|
||||
target[prop] = deepMerge(target[prop], source[prop]);
|
||||
}
|
||||
} else {
|
||||
target[prop] = source[prop];
|
||||
}
|
||||
}
|
||||
return target;
|
||||
};
|
||||
/**
|
||||
* 将File对象转为 Blob Url
|
||||
* @param {File} File对象
|
||||
* @returns Blob Url
|
||||
*/
|
||||
export const fileToBlob = (file) => {
|
||||
if (!file) return;
|
||||
const fileType = file.type;
|
||||
const blob = new Blob([file], { type: fileType || 'application/*' });
|
||||
const blobUrl = window.URL.createObjectURL(blob);
|
||||
return blobUrl;
|
||||
};
|
||||
/**
|
||||
* 将File对象转为 base64
|
||||
* @param {File} File对象
|
||||
* @returns base64
|
||||
*/
|
||||
export const fileToBase64 = (file) => {
|
||||
if (!file) return;
|
||||
return new Promise((r, j) => {
|
||||
const reader = new FileReader();
|
||||
reader.onloadend = () => {
|
||||
const base64String = reader.result;
|
||||
r(base64String);
|
||||
};
|
||||
reader.onerror = () => {
|
||||
j({ mode: 'fileToBase64', data: { errMsg: 'File to base64 fail.' } });
|
||||
};
|
||||
reader.readAsDataURL(file);
|
||||
});
|
||||
};
|
||||
/**
|
||||
* base64转临时路径(改自https://github.com/zhetengbiji/image-tools/blob/master/index.js)
|
||||
* @param base64
|
||||
* @returns
|
||||
*/
|
||||
function dataUrlToBase64(str) {
|
||||
var array = str.split(',');
|
||||
return array[array.length - 1];
|
||||
};
|
||||
function biggerThan(v1, v2) {
|
||||
var v1Array = v1.split('.');
|
||||
var v2Array = v2.split('.');
|
||||
var update = false;
|
||||
for (var index = 0; index < v2Array.length; index++) {
|
||||
var diff = v1Array[index] - v2Array[index];
|
||||
if (diff !== 0) {
|
||||
update = diff > 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return update;
|
||||
};
|
||||
var index = 0;
|
||||
function getNewFileId() {
|
||||
return Date.now() + String(index++);
|
||||
};
|
||||
export const base64ToPath = (base64, name = '') => {
|
||||
return new Promise((r, j) => {
|
||||
if (typeof plus !== 'object') {
|
||||
return j(new Error('not support'));
|
||||
}
|
||||
var fileName = '';
|
||||
if (name) {
|
||||
const names = name.split('.');
|
||||
const extName = names.splice(-1);
|
||||
fileName = `${names.join('.')}-${getNewFileId()}.${extName}`;
|
||||
} else {
|
||||
const names = base64.split(',')[0].match(/data\:\S+\/(\S+);/);
|
||||
if (!names) {
|
||||
j(new Error('base64 error'));
|
||||
}
|
||||
const extName = names[1];
|
||||
fileName = `${getNewFileId()}.${extName}`;
|
||||
}
|
||||
var basePath = '_doc';
|
||||
var dirPath = 'uniapp_temp';
|
||||
var filePath = `${basePath}/${dirPath}/${fileName}`;
|
||||
if (!biggerThan(plus.os.name === 'Android' ? '1.9.9.80627' : '1.9.9.80472', plus.runtime.innerVersion)) {
|
||||
plus.io.resolveLocalFileSystemURL(basePath, function (entry) {
|
||||
entry.getDirectory(dirPath, {
|
||||
create: true,
|
||||
exclusive: false,
|
||||
}, function (entry) {
|
||||
entry.getFile(fileName, {
|
||||
create: true,
|
||||
exclusive: false,
|
||||
}, function (entry) {
|
||||
entry.createWriter(function (writer) {
|
||||
writer.onwrite = function () {
|
||||
r(filePath);
|
||||
}
|
||||
writer.onerror = j;
|
||||
writer.seek(0);
|
||||
writer.writeAsBinary(dataUrlToBase64(base64));
|
||||
}, j)
|
||||
}, j)
|
||||
}, j)
|
||||
}, j)
|
||||
return;
|
||||
}
|
||||
var bitmap = new plus.nativeObj.Bitmap(fileName);
|
||||
bitmap.loadBase64Data(base64, function () {
|
||||
bitmap.save(filePath, {}, function () {
|
||||
bitmap.clear();
|
||||
r(filePath);
|
||||
}, function (error) {
|
||||
bitmap.clear();
|
||||
j(error);
|
||||
});
|
||||
}, function (error) {
|
||||
bitmap.clear();
|
||||
j(error);
|
||||
});
|
||||
});
|
||||
};
|
||||
// eslint-disable
|
||||
export const isObject = (obj) => {
|
||||
return obj
|
||||
? Object.prototype.toString.call(obj) === "[object Object]"
|
||||
: false;
|
||||
};
|
||||
export const isArray = (arr) => {
|
||||
return arr ? Array.isArray(arr) : false;
|
||||
};
|
||||
/**
|
||||
* handle async await
|
||||
* @param {*} promise promise
|
||||
*/
|
||||
export const awaitWrap = (promise) =>
|
||||
promise.then((res) => [null, res]).catch((err) => [err, {}]);
|
||||
/**
|
||||
* 深拷贝
|
||||
* @param {*} source
|
||||
*/
|
||||
export const deepClone = (source) => {
|
||||
if (!isObject(source) && !isArray(source)) return source;
|
||||
const targetObj = isArray(source) ? [] : {}; // 判断复制的目标是数组还是对象
|
||||
for (let keys in source) {
|
||||
// 遍历目标
|
||||
if (source.hasOwnProperty(keys)) {
|
||||
if (source[keys] && typeof source[keys] === "object") {
|
||||
// 如果值是对象,就递归一下
|
||||
targetObj[keys] = isArray(source[keys]) ? [] : {};
|
||||
targetObj[keys] = deepClone(source[keys]);
|
||||
} else {
|
||||
// 如果不是,就直接赋值
|
||||
targetObj[keys] = source[keys];
|
||||
}
|
||||
}
|
||||
}
|
||||
return targetObj;
|
||||
};
|
||||
/**
|
||||
* @description JS对象深度合并
|
||||
* @param {object} target 需要拷贝的对象
|
||||
* @param {object} source 拷贝的来源对象
|
||||
* @returns {object|boolean} 深度合并后的对象或者false(入参有不是对象)
|
||||
*/
|
||||
export const deepMerge = (target = {}, source = {}) => {
|
||||
target = deepClone(target);
|
||||
if (typeof target !== "object" || typeof source !== "object") return false;
|
||||
for (const prop in source) {
|
||||
if (!source.hasOwnProperty(prop)) continue;
|
||||
if (prop in target) {
|
||||
if (typeof target[prop] !== "object") {
|
||||
target[prop] = source[prop];
|
||||
} else if (typeof source[prop] !== "object") {
|
||||
target[prop] = source[prop];
|
||||
} else if (target[prop].concat && source[prop].concat) {
|
||||
target[prop] = target[prop].concat(source[prop]);
|
||||
} else {
|
||||
target[prop] = deepMerge(target[prop], source[prop]);
|
||||
}
|
||||
} else {
|
||||
target[prop] = source[prop];
|
||||
}
|
||||
}
|
||||
return target;
|
||||
};
|
||||
/**
|
||||
* 将File对象转为 Blob Url
|
||||
* @param {File} File对象
|
||||
* @returns Blob Url
|
||||
*/
|
||||
export const fileToBlob = (file) => {
|
||||
if (!file) return;
|
||||
const fileType = file.type;
|
||||
const blob = new Blob([file], { type: fileType || 'application/*' });
|
||||
const blobUrl = window.URL.createObjectURL(blob);
|
||||
return blobUrl;
|
||||
};
|
||||
/**
|
||||
* 将File对象转为 base64
|
||||
* @param {File} File对象
|
||||
* @returns base64
|
||||
*/
|
||||
export const fileToBase64 = (file) => {
|
||||
if (!file) return;
|
||||
return new Promise((r, j) => {
|
||||
const reader = new FileReader();
|
||||
reader.onloadend = () => {
|
||||
const base64String = reader.result;
|
||||
r(base64String);
|
||||
};
|
||||
reader.onerror = () => {
|
||||
j({ mode: 'fileToBase64', data: { errMsg: 'File to base64 fail.' } });
|
||||
};
|
||||
reader.readAsDataURL(file);
|
||||
});
|
||||
};
|
||||
/**
|
||||
* base64转临时路径(改自https://github.com/zhetengbiji/image-tools/blob/master/index.js)
|
||||
* @param base64
|
||||
* @returns
|
||||
*/
|
||||
function dataUrlToBase64(str) {
|
||||
var array = str.split(',');
|
||||
return array[array.length - 1];
|
||||
};
|
||||
function biggerThan(v1, v2) {
|
||||
var v1Array = v1.split('.');
|
||||
var v2Array = v2.split('.');
|
||||
var update = false;
|
||||
for (var index = 0; index < v2Array.length; index++) {
|
||||
var diff = v1Array[index] - v2Array[index];
|
||||
if (diff !== 0) {
|
||||
update = diff > 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return update;
|
||||
};
|
||||
var index = 0;
|
||||
function getNewFileId() {
|
||||
return Date.now() + String(index++);
|
||||
};
|
||||
export const base64ToPath = (base64, name = '') => {
|
||||
return new Promise((r, j) => {
|
||||
if (typeof plus !== 'object') {
|
||||
return j(new Error('not support'));
|
||||
}
|
||||
var fileName = '';
|
||||
if (name) {
|
||||
const names = name.split('.');
|
||||
const extName = names.splice(-1);
|
||||
fileName = `${names.join('.')}-${getNewFileId()}.${extName}`;
|
||||
} else {
|
||||
const names = base64.split(',')[0].match(/data\:\S+\/(\S+);/);
|
||||
if (!names) {
|
||||
j(new Error('base64 error'));
|
||||
}
|
||||
const extName = names[1];
|
||||
fileName = `${getNewFileId()}.${extName}`;
|
||||
}
|
||||
var basePath = '_doc';
|
||||
var dirPath = 'uniapp_temp';
|
||||
var filePath = `${basePath}/${dirPath}/${fileName}`;
|
||||
if (!biggerThan(plus.os.name === 'Android' ? '1.9.9.80627' : '1.9.9.80472', plus.runtime.innerVersion)) {
|
||||
plus.io.resolveLocalFileSystemURL(basePath, function (entry) {
|
||||
entry.getDirectory(dirPath, {
|
||||
create: true,
|
||||
exclusive: false,
|
||||
}, function (entry) {
|
||||
entry.getFile(fileName, {
|
||||
create: true,
|
||||
exclusive: false,
|
||||
}, function (entry) {
|
||||
entry.createWriter(function (writer) {
|
||||
writer.onwrite = function () {
|
||||
r(filePath);
|
||||
}
|
||||
writer.onerror = j;
|
||||
writer.seek(0);
|
||||
writer.writeAsBinary(dataUrlToBase64(base64));
|
||||
}, j)
|
||||
}, j)
|
||||
}, j)
|
||||
}, j)
|
||||
return;
|
||||
}
|
||||
var bitmap = new plus.nativeObj.Bitmap(fileName);
|
||||
bitmap.loadBase64Data(base64, function () {
|
||||
bitmap.save(filePath, {}, function () {
|
||||
bitmap.clear();
|
||||
r(filePath);
|
||||
}, function (error) {
|
||||
bitmap.clear();
|
||||
j(error);
|
||||
});
|
||||
}, function (error) {
|
||||
bitmap.clear();
|
||||
j(error);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
@ -36,7 +36,7 @@ class BleHelper {
|
||||
linkedDevices = uni.getStorageSync(this.StorageKey);
|
||||
}
|
||||
if (linkedDevices && linkedDevices.length && linkedDevices.length > 0) {
|
||||
console.log("111111", linkedDevices);
|
||||
// console.log("111111", linkedDevices);
|
||||
linkedDevices = linkedDevices.filter((v) => {
|
||||
if (v) {
|
||||
v.Linked = false;
|
||||
@ -56,12 +56,13 @@ class BleHelper {
|
||||
isOpenBlue: false, //蓝牙模块是否开启
|
||||
available: false, //蓝牙状态是否可用
|
||||
discovering: false, //蓝牙是否正在搜索
|
||||
|
||||
|
||||
isSubscribe: false, //是否开启了订阅
|
||||
LinkedList: linkedDevices, //已连接的设备列表
|
||||
platform: systemInfo.uniPlatform,
|
||||
Disconnect: [], //主动断开的设备
|
||||
connectingDevices: {} //正在连接的设备
|
||||
connectingDevices: {}, //正在连接的设备
|
||||
voiceUploading: false //语音上传中(上传中不主动断开蓝牙)
|
||||
}
|
||||
this.cfg = {
|
||||
onDeviceFound: [], //发现新设备的事件
|
||||
@ -139,7 +140,7 @@ class BleHelper {
|
||||
{
|
||||
key: '10013',
|
||||
remark: '连接 deviceId 为空或者是格式不正确'
|
||||
},
|
||||
},
|
||||
{
|
||||
key: '10016',
|
||||
remark: '定位服务已关闭'
|
||||
@ -234,11 +235,11 @@ class BleHelper {
|
||||
}
|
||||
if (key) {
|
||||
// console.log("key=" + key);
|
||||
let f =-1;
|
||||
|
||||
this.cfg[type].find((v,index) => {
|
||||
if(v.key == key){
|
||||
f=index;
|
||||
let f = -1;
|
||||
|
||||
this.cfg[type].find((v, index) => {
|
||||
if (v.key == key) {
|
||||
f = index;
|
||||
}
|
||||
});
|
||||
if (f > -1) {
|
||||
@ -262,10 +263,10 @@ class BleHelper {
|
||||
|
||||
if (key) {
|
||||
// console.log("key=" + key);
|
||||
let f =-1;
|
||||
this.cfg[type].find((v,index) => {
|
||||
if(v.key == key){
|
||||
f=index;
|
||||
let f = -1;
|
||||
this.cfg[type].find((v, index) => {
|
||||
if (v.key == key) {
|
||||
f = index;
|
||||
}
|
||||
});
|
||||
if (f > -1) {
|
||||
@ -281,26 +282,26 @@ class BleHelper {
|
||||
|
||||
|
||||
//获取某个事件的所有订阅者,但不包含某些订阅者
|
||||
getCfgAllKeys(type,retains){
|
||||
if(!retains){
|
||||
retains=[];
|
||||
getCfgAllKeys(type, retains) {
|
||||
if (!retains) {
|
||||
retains = [];
|
||||
}
|
||||
if(!Array.isArray(retains)){
|
||||
retains=[retains];
|
||||
if (!Array.isArray(retains)) {
|
||||
retains = [retains];
|
||||
}
|
||||
let keys=null;
|
||||
let keys = null;
|
||||
for (let index = 0; index < this.cfg[type]; index++) {
|
||||
let ele = this.cfg[type];
|
||||
let f=retains.find(v=>{
|
||||
return v.toLowerCase()==ele.key.toLowerCase();
|
||||
let f = retains.find(v => {
|
||||
return v.toLowerCase() == ele.key.toLowerCase();
|
||||
});
|
||||
if(!f){
|
||||
if(!keys){
|
||||
keys=[ele.key];
|
||||
}else{
|
||||
keys.push(ele.key);
|
||||
if (!f) {
|
||||
if (!keys) {
|
||||
keys = [ele.key];
|
||||
} else {
|
||||
keys.push(ele.key);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
return keys;
|
||||
@ -316,15 +317,15 @@ class BleHelper {
|
||||
this.removeCallback(currKey, 'recoveryCallback');
|
||||
}
|
||||
//移除所有蓝牙恢复连接的回调,但不包括currkey
|
||||
removeAllRecoveryCallback(currKey) {
|
||||
let keys=this.getCfgAllKeys('recoveryCallback',currKey);
|
||||
if(keys){
|
||||
removeAllRecoveryCallback(currKey) {
|
||||
let keys = this.getCfgAllKeys('recoveryCallback', currKey);
|
||||
if (keys) {
|
||||
for (let i = 0; i < keys.length; i++) {
|
||||
let key = keys[i];
|
||||
this.removeRecoveryCallback(key);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
//设置蓝牙断开连接的回调
|
||||
@ -337,14 +338,14 @@ class BleHelper {
|
||||
this.removeCallback(currKey, 'bleDisposeCallback');
|
||||
}
|
||||
removeAllDisposeCallback(currKey) {
|
||||
let keys=this.getCfgAllKeys('bleDisposeCallback',currKey);
|
||||
if(keys){
|
||||
let keys = this.getCfgAllKeys('bleDisposeCallback', currKey);
|
||||
if (keys) {
|
||||
for (let i = 0; i < keys.length; i++) {
|
||||
let key = keys[i];
|
||||
this.removeDisposeCallback(key);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -358,14 +359,14 @@ class BleHelper {
|
||||
this.removeCallback(currKey, 'onDeviceFound');
|
||||
}
|
||||
removeAllDeviceFound(currKey) {
|
||||
let keys=this.getCfgAllKeys('onDeviceFound',currKey);
|
||||
if(keys){
|
||||
let keys = this.getCfgAllKeys('onDeviceFound', currKey);
|
||||
if (keys) {
|
||||
for (let i = 0; i < keys.length; i++) {
|
||||
let key = keys[i];
|
||||
this.removeDeviceFound(key);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
//添加接收到数据的回调
|
||||
@ -378,14 +379,14 @@ class BleHelper {
|
||||
this.removeCallback(currKey, 'receivDataCallback');
|
||||
}
|
||||
removeAllReceiveCallback(currKey) {
|
||||
let keys=this.getCfgAllKeys('receivDataCallback',currKey);
|
||||
if(keys){
|
||||
let keys = this.getCfgAllKeys('receivDataCallback', currKey);
|
||||
if (keys) {
|
||||
for (let i = 0; i < keys.length; i++) {
|
||||
let key = keys[i];
|
||||
this.removeReceiveCallback(key);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
//添加蓝牙不可用的回调
|
||||
@ -398,14 +399,14 @@ class BleHelper {
|
||||
this.removeCallback(currKey, 'stateBreakCallback');
|
||||
}
|
||||
removeAllStateBreakCallback(currKey) {
|
||||
let keys=this.getCfgAllKeys('stateBreakCallback',currKey);
|
||||
if(keys){
|
||||
let keys = this.getCfgAllKeys('stateBreakCallback', currKey);
|
||||
if (keys) {
|
||||
for (let i = 0; i < keys.length; i++) {
|
||||
let key = keys[i];
|
||||
this.removeStateBreakCallback(key);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
//设置蓝牙适配器恢复可用的回调
|
||||
@ -418,14 +419,14 @@ class BleHelper {
|
||||
this.removeCallback(currKey, 'stateRecoveryCallback');
|
||||
}
|
||||
removeAllStateRecoveryCallback(currKey) {
|
||||
let keys=this.getCfgAllKeys('stateRecoveryCallback',currKey);
|
||||
if(keys){
|
||||
let keys = this.getCfgAllKeys('stateRecoveryCallback', currKey);
|
||||
if (keys) {
|
||||
for (let i = 0; i < keys.length; i++) {
|
||||
let key = keys[i];
|
||||
this.removeStateRecoveryCallback(key);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
//清除所有事件回调
|
||||
@ -448,10 +449,11 @@ class BleHelper {
|
||||
}
|
||||
|
||||
getError(ex) {
|
||||
let code = ex.code;
|
||||
ex.msg = code
|
||||
|
||||
ex.msg = ex.code + ':' + ex.errMsg;
|
||||
|
||||
let f = this.dic.errRemarks.find((v) => {
|
||||
return v.key == code;
|
||||
return v.key == ex.code;
|
||||
});
|
||||
if (f) {
|
||||
ex.msg = f.remark;
|
||||
@ -560,7 +562,7 @@ class BleHelper {
|
||||
return;
|
||||
}
|
||||
if (!this.data.isOpenBlue) {
|
||||
console.error("蓝牙模块未打开");
|
||||
console.log("蓝牙模块未打开,即将初始化");
|
||||
resolve({
|
||||
available: false,
|
||||
discovering: false
|
||||
@ -612,13 +614,13 @@ class BleHelper {
|
||||
if (this.data.isSubscribe) { //整个App生命周期,只订阅一次
|
||||
return;
|
||||
}
|
||||
console.error("开始订阅各类变化消息");
|
||||
// console.error("开始订阅各类变化消息");
|
||||
this.data.isSubscribe = true;
|
||||
this.BleStateChange(); //蓝牙适配器变化
|
||||
this.BleConnChange(); //蓝牙连接变化
|
||||
this.BleDeviceFound(); //发现新设备
|
||||
this.BleReceive(); //收到消息
|
||||
console.error("订阅各类变化消息完成");
|
||||
// console.error("订阅各类变化消息完成");
|
||||
},
|
||||
fail: (ex2) => {
|
||||
console.error("蓝牙模块启动失败", ex2);
|
||||
@ -733,20 +735,26 @@ class BleHelper {
|
||||
let trimmedStr = str.trim();
|
||||
if (trimmedStr && (trimmedStr.startsWith('{') || trimmedStr.startsWith('['))) {
|
||||
let receivJson = JSON.parse(str);
|
||||
let key = "sta_address"; //HBY100以此方式上传mac地址
|
||||
if (key in receivJson) {
|
||||
|
||||
if ("sta_address" in receivJson || "sta_imei" in receivJson) {
|
||||
this.data.LinkedList.find((v) => {
|
||||
if (v.deviceId == receive
|
||||
.deviceId) {
|
||||
let macStr = receivJson[
|
||||
key];
|
||||
if (macStr.includes(':')) {
|
||||
v.macAddress = macStr;
|
||||
} else {
|
||||
v.macAddress = macStr
|
||||
.replace(/(.{2})/g,
|
||||
'$1:').slice(0,
|
||||
-1)
|
||||
let macStr = receivJson["sta_address"];
|
||||
if (macStr) {
|
||||
if (macStr.includes(':')) {
|
||||
v.macAddress = macStr;
|
||||
} else {
|
||||
v.macAddress = macStr
|
||||
.replace(/(.{2})/g,
|
||||
'$1:').slice(0,
|
||||
-1)
|
||||
}
|
||||
}
|
||||
|
||||
let sta_imei = receivJson["sta_imei"];
|
||||
if (sta_imei) {
|
||||
v.imei = sta_imei;
|
||||
}
|
||||
|
||||
isUpdate = true;
|
||||
@ -754,6 +762,8 @@ class BleHelper {
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
} catch (convertException) {
|
||||
if (str && (str.trim().startsWith('{') || str.trim().startsWith('['))) {
|
||||
@ -779,23 +789,23 @@ class BleHelper {
|
||||
str: str,
|
||||
hexs: hexs
|
||||
};
|
||||
// console.log("监听到特征值:",recData);
|
||||
// console.log("监听到特征值:", recData);
|
||||
if (this.cfg.receivDataCallback) {
|
||||
|
||||
if (this.cfg.receivDataCallback.length > 0) {
|
||||
|
||||
// console.log("有人订阅消息")
|
||||
// console.log("有人订阅消息")
|
||||
this.cfg.receivDataCallback.forEach((
|
||||
rec) => {
|
||||
// console.log("有人订阅消息111", )
|
||||
// console.log("有人订阅消息111", )
|
||||
if (rec.callback) {
|
||||
try {
|
||||
// console.log("正在处理订阅消息",rec);
|
||||
// console.log("正在处理订阅消息",rec);
|
||||
rec.callback(recData, f,
|
||||
rec.key, this.cfg
|
||||
.receivDataCallback
|
||||
);
|
||||
// console.log("处理订阅消息完毕");
|
||||
// console.log("处理订阅消息完毕");
|
||||
} catch (err) {
|
||||
console.error(
|
||||
"订阅消息出现异常",
|
||||
@ -886,10 +896,10 @@ class BleHelper {
|
||||
}
|
||||
|
||||
BleConnChange() {
|
||||
let stateTimeout=null;
|
||||
let stateTimeout = null;
|
||||
uni.onBLEConnectionStateChange((res) => {
|
||||
|
||||
|
||||
|
||||
|
||||
// 检查状态是否真的发生了变化
|
||||
let ble = this.data.LinkedList.find(dev => {
|
||||
return res.deviceId === dev.deviceId;
|
||||
@ -903,7 +913,7 @@ class BleHelper {
|
||||
// console.log("蓝牙连接状态变化了", res);
|
||||
|
||||
clearTimeout(stateTimeout);
|
||||
stateTimeout=setTimeout(() => {
|
||||
stateTimeout = setTimeout(() => {
|
||||
if (!res.connected) {
|
||||
// console.error("蓝牙已断开", res);
|
||||
let f = this.data.LinkedList.find((
|
||||
@ -953,7 +963,22 @@ class BleHelper {
|
||||
}
|
||||
|
||||
} else {
|
||||
console.log("蓝牙连接已恢复", res);
|
||||
// console.log("蓝牙连接已恢复", res);
|
||||
// 系统级连接恢复:更新 LinkedList 并通知业务层,避免 sendData 误判未连接而重复 createBLEConnection
|
||||
let f = this.data.LinkedList.find(v => v.deviceId == res.deviceId);
|
||||
if (f) {
|
||||
f.Linked = true;
|
||||
this.updateCache();
|
||||
}
|
||||
if (this.cfg.recoveryCallback.length > 0) {
|
||||
this.cfg.recoveryCallback.forEach(c => {
|
||||
try {
|
||||
c.callback({ deviceId: res.deviceId, connected: true });
|
||||
} catch (err) {
|
||||
console.error("执行蓝牙恢复连接的回调异常", err);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}, 50);
|
||||
@ -970,15 +995,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) {
|
||||
@ -986,7 +1011,7 @@ class BleHelper {
|
||||
return;
|
||||
}
|
||||
res.devices = arr;
|
||||
|
||||
|
||||
if (this.cfg.onDeviceFound) {
|
||||
if (this.cfg.onDeviceFound.length > 0) {
|
||||
this.cfg.onDeviceFound.forEach((found) => {
|
||||
@ -1011,7 +1036,7 @@ class BleHelper {
|
||||
this.data.available = false;
|
||||
this.data.discovering = false;
|
||||
this.data.isOpenBlue = false;
|
||||
|
||||
|
||||
|
||||
return Promise.resolve();
|
||||
}
|
||||
@ -1028,7 +1053,7 @@ class BleHelper {
|
||||
this.data.available = false;
|
||||
this.data.discovering = false;
|
||||
this.data.isOpenBlue = false;
|
||||
|
||||
|
||||
resolve();
|
||||
},
|
||||
fail: (ex) => {
|
||||
@ -1063,7 +1088,7 @@ class BleHelper {
|
||||
if (this.data.platform == 'web') {
|
||||
return Promise.resolve({});
|
||||
}
|
||||
|
||||
|
||||
var these = this;
|
||||
//开始搜索
|
||||
var Search = () => {
|
||||
@ -1071,10 +1096,10 @@ class BleHelper {
|
||||
let RunSearch = () => {
|
||||
return new Promise((resolve, reject) => {
|
||||
uni.startBluetoothDevicesDiscovery({
|
||||
services:[],
|
||||
services: [],
|
||||
allowDuplicatesKey: true,
|
||||
success: (res) => {
|
||||
console.log('开始搜索蓝牙设备成功');
|
||||
// console.log('开始搜索蓝牙设备成功');
|
||||
resolve(res);
|
||||
|
||||
},
|
||||
@ -1213,11 +1238,11 @@ class BleHelper {
|
||||
characteristicId: characteristicId,
|
||||
state: state,
|
||||
success: (res) => {
|
||||
if (state) {
|
||||
console.log("订阅消息成功", res);
|
||||
} else {
|
||||
console.log("取消订阅成功", res);
|
||||
}
|
||||
// if (state) {
|
||||
// console.log("订阅消息成功", res);
|
||||
// } else {
|
||||
// console.log("取消订阅成功", res);
|
||||
// }
|
||||
|
||||
this.data.LinkedList.find((v) => {
|
||||
if (v.deviceId == deviceId) {
|
||||
@ -1227,7 +1252,7 @@ class BleHelper {
|
||||
// console.log("success SubScribe");
|
||||
succ(
|
||||
res
|
||||
); //见了鬼了,有时候执行了succ但promise永远pending了
|
||||
); //见了鬼了,有时候执行了succ但promise永远pending了
|
||||
},
|
||||
fail: (ex) => {
|
||||
|
||||
@ -1287,13 +1312,13 @@ class BleHelper {
|
||||
|
||||
results.forEach((result, index) => {
|
||||
if (result.status === "fulfilled") {
|
||||
console.log(`订阅消息操作${index + 1}成功:`, result.value);
|
||||
// console.log(`订阅消息操作${index + 1}成功:`, result.value);
|
||||
} else {
|
||||
console.error(`订阅消息操作${index + 1}失败:`, result
|
||||
.reason);
|
||||
}
|
||||
});
|
||||
console.log("订阅消息完成,deviceId:", deviceId);
|
||||
// console.log("订阅消息完成,deviceId:", deviceId);
|
||||
resolve();
|
||||
}).catch((ex) => {
|
||||
console.error("异常,ex=", ex);
|
||||
@ -1370,8 +1395,7 @@ class BleHelper {
|
||||
// notifyCharId));
|
||||
|
||||
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
console.error("预设的蓝牙服务和特征中找不到");
|
||||
for (var i = 0; i < res.services.length; i++) {
|
||||
let service = res.services[i];
|
||||
@ -1601,26 +1625,26 @@ class BleHelper {
|
||||
// console.log("正在连接" + deviceId);
|
||||
uni.createBLEConnection({
|
||||
deviceId: deviceId,
|
||||
timeout: 15000,
|
||||
timeout: 20000,
|
||||
success: (info) => {
|
||||
//释放连接锁
|
||||
|
||||
|
||||
delete this.data.connectingDevices[deviceId];
|
||||
console.log("新连接成功", this.data.LinkedList);
|
||||
|
||||
|
||||
// 处理 MTU 设置
|
||||
if (plus.os.name === 'Android') {
|
||||
this.setMtu(deviceId).catch(ex => {
|
||||
console.error("mtu设置失败=", ex);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
this.getLinkBlue().then((arr) => {
|
||||
let linkId=new Date().getTime();//本次连接的id
|
||||
let linkId = new Date().getTime(); //本次连接的id
|
||||
let cr = arr.devices.find(c => {
|
||||
if (c.deviceId == deviceId) {
|
||||
c.Linked = true;
|
||||
c.linkId=linkId
|
||||
c.linkId = linkId
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -1628,7 +1652,8 @@ class BleHelper {
|
||||
|
||||
if (fIndex > -1) {
|
||||
this.data.LinkedList[fIndex].Linked = true;
|
||||
this.data.LinkedList[fIndex].linkId=linkId;
|
||||
this.data.LinkedList[fIndex].linkId =
|
||||
linkId;
|
||||
} else {
|
||||
this.data.LinkedList.push(cr);
|
||||
}
|
||||
@ -1662,7 +1687,7 @@ class BleHelper {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
resolve(true);
|
||||
|
||||
}).catch((ex) => {
|
||||
@ -1784,6 +1809,13 @@ class BleHelper {
|
||||
});
|
||||
return prom;
|
||||
}
|
||||
// 语音上传中不主动断开:设置/查询上传状态(App onHide 时检查)
|
||||
setVoiceUploading(flag) {
|
||||
this.data.voiceUploading = !!flag;
|
||||
}
|
||||
isVoiceUploading() {
|
||||
return !!this.data.voiceUploading;
|
||||
}
|
||||
//断开连接
|
||||
disconnectDevice(deviceId) {
|
||||
if (this.data.platform == 'web') {
|
||||
@ -1843,7 +1875,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);
|
||||
}
|
||||
@ -1867,7 +1899,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);
|
||||
@ -1876,7 +1908,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({
|
||||
@ -1887,33 +1919,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);
|
||||
@ -1943,9 +1975,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) {
|
||||
@ -1954,31 +1988,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) {
|
||||
@ -2030,7 +2161,7 @@ class BleHelper {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -2048,5 +2179,5 @@ export default {
|
||||
|
||||
return instance;
|
||||
},
|
||||
constService:serviceDic
|
||||
}
|
||||
constService: serviceDic
|
||||
}
|
||||
@ -1,4 +1,5 @@
|
||||
import Common from '@/utils/Common.js'
|
||||
import { parseBleData } from '@/api/100J/HBY100-J.js'
|
||||
|
||||
class BleReceive {
|
||||
constructor() {
|
||||
@ -11,7 +12,9 @@ class BleReceive {
|
||||
'/pages/670/HBY670': this.Receive_670.bind(this),
|
||||
'/pages/4877/BJQ4877': this.Receive_4877.bind(this),
|
||||
'/pages/100/HBY100': this.Receive_100.bind(this),
|
||||
'/pages/102/HBY102': this.Receive_102.bind(this)
|
||||
'/pages/102/HBY102': this.Receive_102.bind(this),
|
||||
'/pages/6170/deviceControl/index':this.Receive_6170.bind(this),
|
||||
'/pages/100J/HBY100-J': this.Receive_100J.bind(this)
|
||||
};
|
||||
}
|
||||
|
||||
@ -670,6 +673,58 @@ class BleReceive {
|
||||
|
||||
}
|
||||
|
||||
Receive_100J(receive, f, path, recArr) {
|
||||
let receiveData = {};
|
||||
try {
|
||||
if (!receive.bytes || receive.bytes.length < 3) return receiveData;
|
||||
const parsed = parseBleData(receive.bytes);
|
||||
if (!parsed) return receiveData;
|
||||
if (parsed.longitude !== undefined) receiveData.longitude = parsed.longitude;
|
||||
if (parsed.latitude !== undefined) receiveData.latitude = parsed.latitude;
|
||||
if (parsed.batteryPercentage !== undefined) receiveData.batteryPercentage = parsed.batteryPercentage;
|
||||
if (parsed.batteryRemainingTime !== undefined) receiveData.batteryRemainingTime = parsed.batteryRemainingTime;
|
||||
} catch (e) {
|
||||
console.log('[100J] BleReceive 解析失败', e);
|
||||
}
|
||||
return receiveData;
|
||||
}
|
||||
|
||||
Receive_6170(receive, f, path, recArr) {
|
||||
let receiveData = {};
|
||||
|
||||
try {
|
||||
console.log("订阅消息者:", path);
|
||||
console.log("设备收到消息:", f);
|
||||
console.log("消息内容:", receive);
|
||||
receiveData = JSON.parse(receive.str);
|
||||
|
||||
let recCnt = recArr.find(v => {
|
||||
return v.key.replace(/\//g, "").toLowerCase() == f.device.detailPageUrl
|
||||
.replace(/\//g, "").toLowerCase();
|
||||
});
|
||||
if (!recCnt) {
|
||||
if (receiveData.sta_PowerPercent <= 20) {
|
||||
uni.showModal({
|
||||
title: "提示",
|
||||
content: "设备'" + f.device.deviceName + "'电量低",
|
||||
showCancel: false
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
} catch (error) {
|
||||
receiveData = {};
|
||||
console.error("文本解析失败", error)
|
||||
}
|
||||
return receiveData;
|
||||
|
||||
}
|
||||
|
||||
Receive_102(receive, f, path, recArr) {
|
||||
let receiveData = {};
|
||||
|
||||
980
utils/Common.js
980
utils/Common.js
@ -1,491 +1,491 @@
|
||||
import request from "@/utils/request.js";
|
||||
export default {
|
||||
audioStorageKey: "audioStorageKey",
|
||||
pcmStorageKey: "pcmStorageKey",
|
||||
guid: function generateUUID() {
|
||||
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
|
||||
let r = Math.random() * 16 | 0;
|
||||
let v = c === 'x' ? r : (r & 0x3 | 0x8);
|
||||
return v.toString(16);
|
||||
});
|
||||
},
|
||||
alert: function(title, content, callback) {
|
||||
if (!title) {
|
||||
title = '提示'
|
||||
}
|
||||
if (!content) {
|
||||
content = title;
|
||||
}
|
||||
|
||||
uni.showModal({
|
||||
title: title,
|
||||
content: content,
|
||||
success: function(res) {
|
||||
if (res.confirm) {
|
||||
console.log('用户点击确定');
|
||||
} else if (res.cancel) {
|
||||
console.log('用户点击取消');
|
||||
}
|
||||
|
||||
if (callback) {
|
||||
callback(res);
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
showLoading: function(title, mask) {
|
||||
uni.showLoading({
|
||||
title: title,
|
||||
mask: mask,
|
||||
})
|
||||
},
|
||||
hideLoading: function() {
|
||||
uni.hideLoading();
|
||||
},
|
||||
showToast: function(title, mask, duration, callback) {
|
||||
if (!duration) {
|
||||
duration = 1500;
|
||||
}
|
||||
if (mask == undefined) {
|
||||
mask = false;
|
||||
}
|
||||
uni.showToast({
|
||||
title: title,
|
||||
mask: mask,
|
||||
duration: duration,
|
||||
callback: callback,
|
||||
icon: 'none'
|
||||
})
|
||||
},
|
||||
GetData: function(url, data, method, contentType, succ, err, complete) {
|
||||
var these = this;
|
||||
if (!url) {
|
||||
console.error("url为空");
|
||||
return;
|
||||
}
|
||||
|
||||
if (url.toLowerCase().indexOf('http://') == -1 || url.toLowerCase().indexOf('https://') == -1) {
|
||||
if (url.indexOf('/') == 0) {
|
||||
url = url.substr(1, url.length - 1);
|
||||
}
|
||||
let ServerPath = these.DevApi;
|
||||
if (these.Version === 'Dev') {
|
||||
ServerPath = these.DevApi;
|
||||
} else if (these.Version === 'Uat') {
|
||||
ServerPath = these.UatApi;
|
||||
} else if (these.Version === 'Relese') {
|
||||
ServerPath = these.ReleseApi;
|
||||
} else {
|
||||
these.DevApi
|
||||
}
|
||||
url = ServerPath + url;
|
||||
}
|
||||
|
||||
var these = this;
|
||||
if (!method) {
|
||||
method = 'POST';
|
||||
}
|
||||
method = method.toUpperCase();
|
||||
|
||||
if (!contentType) {
|
||||
contentType = 'application/json;charset=UTF-8';
|
||||
}
|
||||
|
||||
these.checkLAN(
|
||||
|
||||
function() {
|
||||
these.showLoading('请稍候..', true);
|
||||
setTimeout(function() {
|
||||
uni.request({
|
||||
url: url,
|
||||
data: data,
|
||||
header: {
|
||||
"Content-Type": contentType
|
||||
},
|
||||
method: method,
|
||||
timeout: 60000,
|
||||
dataType: 'json',
|
||||
success: function(json) {
|
||||
|
||||
if (succ) {
|
||||
succ(json);
|
||||
}
|
||||
},
|
||||
fail: function(ex) {
|
||||
|
||||
if (err) {
|
||||
err(ex);
|
||||
}
|
||||
},
|
||||
complete: function() {
|
||||
|
||||
if (complete) {
|
||||
complete();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}, 0);
|
||||
|
||||
}
|
||||
|
||||
,
|
||||
function() {
|
||||
these.showToast('无网络连接');
|
||||
});
|
||||
},
|
||||
checkLAN: function(succ, error) {
|
||||
uni.getNetworkType({
|
||||
success: (res) => {
|
||||
let networkType = res.networkType;
|
||||
|
||||
|
||||
// 判断网络是否连接
|
||||
if (networkType === 'none') {
|
||||
console.error('无网络连接')
|
||||
if (error) {
|
||||
error();
|
||||
}
|
||||
} else {
|
||||
if (succ) {
|
||||
succ();
|
||||
}
|
||||
|
||||
}
|
||||
},
|
||||
fail: (err) => {
|
||||
console.error('获取网络状态失败:', err);
|
||||
if (error) {
|
||||
error();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
},
|
||||
DateFormat: function(date, format) {
|
||||
if (!date) {
|
||||
date = new Date();
|
||||
}
|
||||
if (!format) {
|
||||
format = 'yyyy-MM-dd HH:mm:ss';
|
||||
}
|
||||
// 处理参数默认值
|
||||
if (typeof date === 'string' || typeof date === 'number') {
|
||||
date = new Date(date);
|
||||
}
|
||||
date = date instanceof Date ? date : new Date();
|
||||
format = format || 'yyyy-MM-dd';
|
||||
|
||||
// 检查日期是否有效
|
||||
if (isNaN(date.getTime())) {
|
||||
return 'Invalid Date';
|
||||
}
|
||||
|
||||
// 定义格式化映射
|
||||
let formatMap = {
|
||||
'yyyy': date.getFullYear(),
|
||||
'MM': String(date.getMonth() + 1).padStart(2, '0'),
|
||||
'dd': String(date.getDate()).padStart(2, '0'),
|
||||
'HH': String(date.getHours()).padStart(2, '0'),
|
||||
'mm': String(date.getMinutes()).padStart(2, '0'),
|
||||
'ss': String(date.getSeconds()).padStart(2, '0'),
|
||||
'SSS': String(date.getMilliseconds()).padStart(3, '0'),
|
||||
'M': date.getMonth() + 1,
|
||||
'd': date.getDate(),
|
||||
'H': date.getHours(),
|
||||
'm': date.getMinutes(),
|
||||
's': date.getSeconds(),
|
||||
'S': date.getMilliseconds()
|
||||
};
|
||||
|
||||
// 替换格式字符串中的占位符
|
||||
return format.replace(/(yyyy|MM|dd|HH|mm|ss|SSS|M|d|H|m|s|S)/g, (match) => {
|
||||
return formatMap[match];
|
||||
});
|
||||
},
|
||||
getdeviceShareId(id) { //获取设备分享信息
|
||||
return request({
|
||||
url: `/app/deviceShare/${id}`,
|
||||
method: 'get',
|
||||
})
|
||||
},
|
||||
getPermissions(type) {
|
||||
if (!type) {
|
||||
type = '6170';
|
||||
}
|
||||
let array = [{
|
||||
value: "1",
|
||||
label: "灯光模式",
|
||||
checked: false,
|
||||
type: ['6170', '670','102','6155','650','7305','6075']
|
||||
},
|
||||
{
|
||||
value: "2",
|
||||
label: "激光模式",
|
||||
checked: false,
|
||||
type: ['6170','6075']
|
||||
},
|
||||
{
|
||||
value: "3",
|
||||
label: "开机画面",
|
||||
checked: false,
|
||||
type: ['210', '6170', '670','6155','650','7305','6075']
|
||||
},
|
||||
{
|
||||
value: "4",
|
||||
label: "人员信息登记",
|
||||
checked: false,
|
||||
type: ['210', '6170', '670','6155','650','7305','6075']
|
||||
},
|
||||
{
|
||||
value: "5",
|
||||
label: "发送信息",
|
||||
checked: false,
|
||||
type: ['210', '6170', '670','6075']
|
||||
},
|
||||
{
|
||||
value: "6",
|
||||
label: "产品信息",
|
||||
checked: false,
|
||||
type: ['210', '6170', '670']
|
||||
}, {
|
||||
value: "41",
|
||||
label: "静电探测",
|
||||
checked: false,
|
||||
type: ['670','650']
|
||||
}, {
|
||||
value: "42",
|
||||
label: "SOS",
|
||||
checked: false,
|
||||
type: ['670','4877','6075']
|
||||
},
|
||||
{
|
||||
value: "43",
|
||||
label: "联机设备",
|
||||
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']
|
||||
},
|
||||
{
|
||||
value: "47",
|
||||
label: "报警时长",
|
||||
checked: false,
|
||||
type: ['210']
|
||||
},
|
||||
{
|
||||
value: "48",
|
||||
label: "物体感应",
|
||||
checked: false,
|
||||
type: ['102']
|
||||
},
|
||||
{
|
||||
value: "49",
|
||||
label: "联机模式",
|
||||
checked: false,
|
||||
type: ['102']
|
||||
},
|
||||
|
||||
{
|
||||
value: "50",
|
||||
label: "报警模式",
|
||||
checked: false,
|
||||
type: ['100','100J']
|
||||
},
|
||||
|
||||
{
|
||||
value: "51",
|
||||
label: "警示灯",
|
||||
checked: false,
|
||||
type: ['100','100J']
|
||||
},
|
||||
|
||||
{
|
||||
value: "52",
|
||||
label: "语音管理",
|
||||
checked: false,
|
||||
type: ['100','100J']
|
||||
},
|
||||
|
||||
{
|
||||
value: "53",
|
||||
label: "箭头模式",
|
||||
checked: false,
|
||||
type: ['4877']
|
||||
},
|
||||
{
|
||||
value: "54",
|
||||
label: "配组设置",
|
||||
checked: false,
|
||||
type: ['4877']
|
||||
},
|
||||
{
|
||||
value: "55",
|
||||
label: "修改信道",
|
||||
checked: false,
|
||||
type: ['4877']
|
||||
},
|
||||
{
|
||||
value: "56",
|
||||
label: "灯光类型设置",
|
||||
checked: false,
|
||||
type: ['100J']
|
||||
},
|
||||
]
|
||||
|
||||
let arr = [];
|
||||
for (let i = 0; i < array.length; i++) {
|
||||
let item = array[i];
|
||||
if (!item) {
|
||||
continue;
|
||||
}
|
||||
if (!item.type) {
|
||||
continue;
|
||||
}
|
||||
let typeContais = item.type.find(v => {
|
||||
return v.includes(type);
|
||||
});
|
||||
if (typeContais) {
|
||||
let json = {};
|
||||
Object.assign(json, item);
|
||||
arr.push(json);
|
||||
}
|
||||
}
|
||||
return arr;
|
||||
},
|
||||
//10进制转换为16进制字符串
|
||||
decimalToHexLittleEndian(num, byteCount, revers) {
|
||||
// 处理负数(如果需要支持负数,可先转为补码)
|
||||
if (num < 0) {
|
||||
num = 0xFFFFFFFF + num + 1;
|
||||
}
|
||||
|
||||
// 转为16进制,去除前缀0x,转为大写
|
||||
let hex = num.toString(16).toUpperCase();
|
||||
|
||||
// 计算需要补充的0的数量,确保每个字节占2位
|
||||
let padLength = (byteCount || Math.ceil(hex.length / 2) * 2) - hex.length;
|
||||
if (padLength > 0) {
|
||||
hex = '0'.repeat(padLength) + hex;
|
||||
}
|
||||
|
||||
// 分割为字节数组(每2位一个字节)
|
||||
let bytes = [];
|
||||
for (let i = 0; i < hex.length; i += 2) {
|
||||
bytes.push(hex.substr(i, 2));
|
||||
}
|
||||
|
||||
// 是否反转字节顺序(低位在前)并拼接
|
||||
if (revers) {
|
||||
return bytes.reverse().join('');
|
||||
}
|
||||
return bytes.join('');
|
||||
},
|
||||
//将相对路径的文件移动到_downloads文件夹中
|
||||
moveFileToDownloads(tempFilePath) {
|
||||
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
if(!tempFilePath){
|
||||
console.log("无文件需要移动");
|
||||
resolve(tempFilePath);
|
||||
return;
|
||||
}
|
||||
//本来就在此目录时直接返回
|
||||
if (tempFilePath.indexOf("_downloads") === 0) {
|
||||
console.log("文件已存在,无需移动");
|
||||
resolve(tempFilePath);
|
||||
return;
|
||||
}
|
||||
//不是app直接返回
|
||||
if (!uni.getSystemInfoSync().uniPlatform.includes('app')) {
|
||||
resolve('仅支持 App 端操作');
|
||||
return;
|
||||
}
|
||||
// console.log("tempFilePath=", tempFilePath);
|
||||
var srcPath = plus.io.convertLocalFileSystemURL(tempFilePath);
|
||||
// console.log("srcPath=", srcPath);
|
||||
plus.io.resolveLocalFileSystemURL(srcPath,
|
||||
(fileEntry) => {
|
||||
|
||||
plus.io.requestFileSystem(plus.io.PUBLIC_DOWNLOADS, (fs) => {
|
||||
// console.log("fs=",fs.name);
|
||||
// console.log("fs=",fs.root.fullPath);
|
||||
|
||||
fileEntry.moveTo(fs.root, fileEntry.name, (entry) => {
|
||||
console.log("entry=", entry);
|
||||
let relativePath = `_downloads/${entry.name}`;
|
||||
resolve(relativePath);
|
||||
|
||||
}, (ex) => {
|
||||
reject(ex)
|
||||
});
|
||||
|
||||
|
||||
}, (e) => {
|
||||
console.error("请求download目录失败 " + e);
|
||||
reject(e);
|
||||
});
|
||||
},
|
||||
(error) => {
|
||||
console.log('文件不存在/路径错误:', error.message); // 核心问题!
|
||||
}
|
||||
);
|
||||
});
|
||||
},
|
||||
|
||||
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';
|
||||
}
|
||||
return {os:os,url:url};
|
||||
},
|
||||
|
||||
|
||||
//将点阵数据转换成RGB565
|
||||
convertToRGB565(pixels, type) {
|
||||
if (!type) {
|
||||
type = 'rgb';
|
||||
}
|
||||
const result = new Uint16Array(pixels.length / 4);
|
||||
let index = 0;
|
||||
for (let i = 0; i < pixels.length; i += 4) {
|
||||
let r = pixels[i];
|
||||
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;
|
||||
}
|
||||
import request from "@/utils/request.js";
|
||||
export default {
|
||||
audioStorageKey: "audioStorageKey",
|
||||
pcmStorageKey: "pcmStorageKey",
|
||||
guid: function generateUUID() {
|
||||
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
|
||||
let r = Math.random() * 16 | 0;
|
||||
let v = c === 'x' ? r : (r & 0x3 | 0x8);
|
||||
return v.toString(16);
|
||||
});
|
||||
},
|
||||
alert: function(title, content, callback) {
|
||||
if (!title) {
|
||||
title = '提示'
|
||||
}
|
||||
if (!content) {
|
||||
content = title;
|
||||
}
|
||||
|
||||
uni.showModal({
|
||||
title: title,
|
||||
content: content,
|
||||
success: function(res) {
|
||||
if (res.confirm) {
|
||||
console.log('用户点击确定');
|
||||
} else if (res.cancel) {
|
||||
console.log('用户点击取消');
|
||||
}
|
||||
|
||||
if (callback) {
|
||||
callback(res);
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
showLoading: function(title, mask) {
|
||||
uni.showLoading({
|
||||
title: title,
|
||||
mask: mask,
|
||||
})
|
||||
},
|
||||
hideLoading: function() {
|
||||
uni.hideLoading();
|
||||
},
|
||||
showToast: function(title, mask, duration, callback) {
|
||||
if (!duration) {
|
||||
duration = 1500;
|
||||
}
|
||||
if (mask == undefined) {
|
||||
mask = false;
|
||||
}
|
||||
uni.showToast({
|
||||
title: title,
|
||||
mask: mask,
|
||||
duration: duration,
|
||||
callback: callback,
|
||||
icon: 'none'
|
||||
})
|
||||
},
|
||||
GetData: function(url, data, method, contentType, succ, err, complete) {
|
||||
var these = this;
|
||||
if (!url) {
|
||||
console.error("url为空");
|
||||
return;
|
||||
}
|
||||
|
||||
if (url.toLowerCase().indexOf('http://') == -1 || url.toLowerCase().indexOf('https://') == -1) {
|
||||
if (url.indexOf('/') == 0) {
|
||||
url = url.substr(1, url.length - 1);
|
||||
}
|
||||
let ServerPath = these.DevApi;
|
||||
if (these.Version === 'Dev') {
|
||||
ServerPath = these.DevApi;
|
||||
} else if (these.Version === 'Uat') {
|
||||
ServerPath = these.UatApi;
|
||||
} else if (these.Version === 'Relese') {
|
||||
ServerPath = these.ReleseApi;
|
||||
} else {
|
||||
these.DevApi
|
||||
}
|
||||
url = ServerPath + url;
|
||||
}
|
||||
|
||||
var these = this;
|
||||
if (!method) {
|
||||
method = 'POST';
|
||||
}
|
||||
method = method.toUpperCase();
|
||||
|
||||
if (!contentType) {
|
||||
contentType = 'application/json;charset=UTF-8';
|
||||
}
|
||||
|
||||
these.checkLAN(
|
||||
|
||||
function() {
|
||||
these.showLoading('请稍候..', true);
|
||||
setTimeout(function() {
|
||||
uni.request({
|
||||
url: url,
|
||||
data: data,
|
||||
header: {
|
||||
"Content-Type": contentType
|
||||
},
|
||||
method: method,
|
||||
timeout: 60000,
|
||||
dataType: 'json',
|
||||
success: function(json) {
|
||||
|
||||
if (succ) {
|
||||
succ(json);
|
||||
}
|
||||
},
|
||||
fail: function(ex) {
|
||||
|
||||
if (err) {
|
||||
err(ex);
|
||||
}
|
||||
},
|
||||
complete: function() {
|
||||
|
||||
if (complete) {
|
||||
complete();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}, 0);
|
||||
|
||||
}
|
||||
|
||||
,
|
||||
function() {
|
||||
these.showToast('无网络连接');
|
||||
});
|
||||
},
|
||||
checkLAN: function(succ, error) {
|
||||
uni.getNetworkType({
|
||||
success: (res) => {
|
||||
let networkType = res.networkType;
|
||||
|
||||
|
||||
// 判断网络是否连接
|
||||
if (networkType === 'none') {
|
||||
console.error('无网络连接')
|
||||
if (error) {
|
||||
error();
|
||||
}
|
||||
} else {
|
||||
if (succ) {
|
||||
succ();
|
||||
}
|
||||
|
||||
}
|
||||
},
|
||||
fail: (err) => {
|
||||
console.error('获取网络状态失败:', err);
|
||||
if (error) {
|
||||
error();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
},
|
||||
DateFormat: function(date, format) {
|
||||
if (!date) {
|
||||
date = new Date();
|
||||
}
|
||||
if (!format) {
|
||||
format = 'yyyy-MM-dd HH:mm:ss';
|
||||
}
|
||||
// 处理参数默认值
|
||||
if (typeof date === 'string' || typeof date === 'number') {
|
||||
date = new Date(date);
|
||||
}
|
||||
date = date instanceof Date ? date : new Date();
|
||||
format = format || 'yyyy-MM-dd';
|
||||
|
||||
// 检查日期是否有效
|
||||
if (isNaN(date.getTime())) {
|
||||
return 'Invalid Date';
|
||||
}
|
||||
|
||||
// 定义格式化映射
|
||||
let formatMap = {
|
||||
'yyyy': date.getFullYear(),
|
||||
'MM': String(date.getMonth() + 1).padStart(2, '0'),
|
||||
'dd': String(date.getDate()).padStart(2, '0'),
|
||||
'HH': String(date.getHours()).padStart(2, '0'),
|
||||
'mm': String(date.getMinutes()).padStart(2, '0'),
|
||||
'ss': String(date.getSeconds()).padStart(2, '0'),
|
||||
'SSS': String(date.getMilliseconds()).padStart(3, '0'),
|
||||
'M': date.getMonth() + 1,
|
||||
'd': date.getDate(),
|
||||
'H': date.getHours(),
|
||||
'm': date.getMinutes(),
|
||||
's': date.getSeconds(),
|
||||
'S': date.getMilliseconds()
|
||||
};
|
||||
|
||||
// 替换格式字符串中的占位符
|
||||
return format.replace(/(yyyy|MM|dd|HH|mm|ss|SSS|M|d|H|m|s|S)/g, (match) => {
|
||||
return formatMap[match];
|
||||
});
|
||||
},
|
||||
getdeviceShareId(id) { //获取设备分享信息
|
||||
return request({
|
||||
url: `/app/deviceShare/${id}`,
|
||||
method: 'get',
|
||||
})
|
||||
},
|
||||
getPermissions(type) {
|
||||
if (!type) {
|
||||
type = '6170';
|
||||
}
|
||||
let array = [{
|
||||
value: "1",
|
||||
label: "灯光模式",
|
||||
checked: false,
|
||||
type: ['6170', '670','102','6155','650','7305','6075']
|
||||
},
|
||||
{
|
||||
value: "2",
|
||||
label: "激光模式",
|
||||
checked: false,
|
||||
type: ['6170','6075']
|
||||
},
|
||||
{
|
||||
value: "3",
|
||||
label: "开机画面",
|
||||
checked: false,
|
||||
type: ['210', '6170', '670','6155','650','7305','6075']
|
||||
},
|
||||
{
|
||||
value: "4",
|
||||
label: "人员信息登记",
|
||||
checked: false,
|
||||
type: ['210', '6170', '670','6155','650','7305','6075']
|
||||
},
|
||||
{
|
||||
value: "5",
|
||||
label: "发送信息",
|
||||
checked: false,
|
||||
type: ['210', '6170', '670','6075']
|
||||
},
|
||||
{
|
||||
value: "6",
|
||||
label: "产品信息",
|
||||
checked: false,
|
||||
type: ['210', '6170', '670']
|
||||
}, {
|
||||
value: "41",
|
||||
label: "静电探测",
|
||||
checked: false,
|
||||
type: ['670','650']
|
||||
}, {
|
||||
value: "42",
|
||||
label: "SOS",
|
||||
checked: false,
|
||||
type: ['670','4877','6075']
|
||||
},
|
||||
{
|
||||
value: "43",
|
||||
label: "联机设备",
|
||||
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']
|
||||
},
|
||||
{
|
||||
value: "47",
|
||||
label: "报警时长",
|
||||
checked: false,
|
||||
type: ['210']
|
||||
},
|
||||
{
|
||||
value: "48",
|
||||
label: "物体感应",
|
||||
checked: false,
|
||||
type: ['102']
|
||||
},
|
||||
{
|
||||
value: "49",
|
||||
label: "联机模式",
|
||||
checked: false,
|
||||
type: ['102']
|
||||
},
|
||||
|
||||
{
|
||||
value: "50",
|
||||
label: "报警模式",
|
||||
checked: false,
|
||||
type: ['100','100J']
|
||||
},
|
||||
|
||||
{
|
||||
value: "51",
|
||||
label: "警示灯",
|
||||
checked: false,
|
||||
type: ['100','100J']
|
||||
},
|
||||
|
||||
{
|
||||
value: "52",
|
||||
label: "语音管理",
|
||||
checked: false,
|
||||
type: ['100','100J']
|
||||
},
|
||||
|
||||
{
|
||||
value: "53",
|
||||
label: "箭头模式",
|
||||
checked: false,
|
||||
type: ['4877']
|
||||
},
|
||||
{
|
||||
value: "54",
|
||||
label: "配组设置",
|
||||
checked: false,
|
||||
type: ['4877']
|
||||
},
|
||||
{
|
||||
value: "55",
|
||||
label: "修改信道",
|
||||
checked: false,
|
||||
type: ['4877','102']
|
||||
},
|
||||
{
|
||||
value: "56",
|
||||
label: "灯光类型设置",
|
||||
checked: false,
|
||||
type: ['100J']
|
||||
},
|
||||
]
|
||||
|
||||
let arr = [];
|
||||
for (let i = 0; i < array.length; i++) {
|
||||
let item = array[i];
|
||||
if (!item) {
|
||||
continue;
|
||||
}
|
||||
if (!item.type) {
|
||||
continue;
|
||||
}
|
||||
let typeContais = item.type.find(v => {
|
||||
return v.includes(type);
|
||||
});
|
||||
if (typeContais) {
|
||||
let json = {};
|
||||
Object.assign(json, item);
|
||||
arr.push(json);
|
||||
}
|
||||
}
|
||||
return arr;
|
||||
},
|
||||
//10进制转换为16进制字符串
|
||||
decimalToHexLittleEndian(num, byteCount, revers) {
|
||||
// 处理负数(如果需要支持负数,可先转为补码)
|
||||
if (num < 0) {
|
||||
num = 0xFFFFFFFF + num + 1;
|
||||
}
|
||||
|
||||
// 转为16进制,去除前缀0x,转为大写
|
||||
let hex = num.toString(16).toUpperCase();
|
||||
|
||||
// 计算需要补充的0的数量,确保每个字节占2位
|
||||
let padLength = (byteCount || Math.ceil(hex.length / 2) * 2) - hex.length;
|
||||
if (padLength > 0) {
|
||||
hex = '0'.repeat(padLength) + hex;
|
||||
}
|
||||
|
||||
// 分割为字节数组(每2位一个字节)
|
||||
let bytes = [];
|
||||
for (let i = 0; i < hex.length; i += 2) {
|
||||
bytes.push(hex.substr(i, 2));
|
||||
}
|
||||
|
||||
// 是否反转字节顺序(低位在前)并拼接
|
||||
if (revers) {
|
||||
return bytes.reverse().join('');
|
||||
}
|
||||
return bytes.join('');
|
||||
},
|
||||
//将相对路径的文件移动到_downloads文件夹中
|
||||
moveFileToDownloads(tempFilePath) {
|
||||
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
if(!tempFilePath){
|
||||
console.log("无文件需要移动");
|
||||
resolve(tempFilePath);
|
||||
return;
|
||||
}
|
||||
//本来就在此目录时直接返回
|
||||
if (tempFilePath.indexOf("_downloads") === 0) {
|
||||
console.log("文件已存在,无需移动");
|
||||
resolve(tempFilePath);
|
||||
return;
|
||||
}
|
||||
//不是app直接返回
|
||||
if (!uni.getSystemInfoSync().uniPlatform.includes('app')) {
|
||||
resolve('仅支持 App 端操作');
|
||||
return;
|
||||
}
|
||||
// console.log("tempFilePath=", tempFilePath);
|
||||
var srcPath = plus.io.convertLocalFileSystemURL(tempFilePath);
|
||||
// console.log("srcPath=", srcPath);
|
||||
plus.io.resolveLocalFileSystemURL(srcPath,
|
||||
(fileEntry) => {
|
||||
|
||||
plus.io.requestFileSystem(plus.io.PUBLIC_DOWNLOADS, (fs) => {
|
||||
// console.log("fs=",fs.name);
|
||||
// console.log("fs=",fs.root.fullPath);
|
||||
|
||||
fileEntry.moveTo(fs.root, fileEntry.name, (entry) => {
|
||||
console.log("entry=", entry);
|
||||
let relativePath = `_downloads/${entry.name}`;
|
||||
resolve(relativePath);
|
||||
|
||||
}, (ex) => {
|
||||
reject(ex)
|
||||
});
|
||||
|
||||
|
||||
}, (e) => {
|
||||
console.error("请求download目录失败 " + e);
|
||||
reject(e);
|
||||
});
|
||||
},
|
||||
(error) => {
|
||||
console.log('文件不存在/路径错误:', error.message); // 核心问题!
|
||||
}
|
||||
);
|
||||
});
|
||||
},
|
||||
|
||||
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';
|
||||
}
|
||||
return {os:os,url:url};
|
||||
},
|
||||
|
||||
|
||||
//将点阵数据转换成RGB565
|
||||
convertToRGB565(pixels, type) {
|
||||
if (!type) {
|
||||
type = 'rgb';
|
||||
}
|
||||
const result = new Uint16Array(pixels.length / 4);
|
||||
let index = 0;
|
||||
for (let i = 0; i < pixels.length; i += 4) {
|
||||
let r = pixels[i];
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user