Compare commits
16 Commits
ac59e28281
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| b76a41b624 | |||
| c286660a10 | |||
| 5163491ea3 | |||
| 0e66d375fc | |||
| 1fcaf8a9a4 | |||
| 75b9f27965 | |||
| bdea9dac4b | |||
| 444b3b35ac | |||
| 3e19646ed7 | |||
| 44607f9b0c | |||
| 23b72ef9ae | |||
| 84feb9f1e8 | |||
| 3a9de3078c | |||
| 9b6a5e095c | |||
| 7735abc2a1 | |||
| c626f3766e |
41
App.vue
41
App.vue
@ -1,7 +1,11 @@
|
|||||||
<script>
|
<script>
|
||||||
import bleTool from '@/utils/BleHelper.js';
|
import bleTool from '@/utils/BleHelper.js';
|
||||||
import upgrade from '@/utils/update.js';
|
import upgrade from '@/utils/update.js';
|
||||||
|
|
||||||
|
// 延迟断开蓝牙:选择文件/录音等会触发 onHide,8 秒内返回则不断开
|
||||||
|
const BLE_DISCONNECT_DELAY = 8000;
|
||||||
|
let _bleDisconnectTimer = null;
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
|
||||||
onLaunch: function() {
|
onLaunch: function() {
|
||||||
@ -27,7 +31,7 @@
|
|||||||
// uni.removeStorageSync(val);
|
// uni.removeStorageSync(val);
|
||||||
// }
|
// }
|
||||||
// });
|
// });
|
||||||
uni.clearStorageSync();
|
// uni.clearStorageSync();
|
||||||
//以上代码仅在开发时使用,否则会出现不可预知的问题。
|
//以上代码仅在开发时使用,否则会出现不可预知的问题。
|
||||||
|
|
||||||
// #ifdef APP|APP-PLUS
|
// #ifdef APP|APP-PLUS
|
||||||
@ -63,10 +67,10 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (plus.os.name == 'Android') {
|
if (plus.os.name == 'Android') {
|
||||||
if(plus.runtime.isAgreePrivacy()){
|
if (plus.runtime.isAgreePrivacy()) {
|
||||||
initOS();
|
initOS();
|
||||||
}
|
}
|
||||||
}else{
|
} else {
|
||||||
initOS();
|
initOS();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,7 +78,11 @@
|
|||||||
},
|
},
|
||||||
onShow: function() {
|
onShow: function() {
|
||||||
console.log('App Show');
|
console.log('App Show');
|
||||||
|
// 取消延迟断开:用户可能只是选文件/录音后返回,不断开蓝牙
|
||||||
|
if (_bleDisconnectTimer) {
|
||||||
|
clearTimeout(_bleDisconnectTimer);
|
||||||
|
_bleDisconnectTimer = null;
|
||||||
|
}
|
||||||
//将检查更新换到onshow,因为苹果用户喜欢一直挂着
|
//将检查更新换到onshow,因为苹果用户喜欢一直挂着
|
||||||
// #ifdef APP|APP-PLUS
|
// #ifdef APP|APP-PLUS
|
||||||
|
|
||||||
@ -91,11 +99,26 @@
|
|||||||
onHide: function() {
|
onHide: function() {
|
||||||
console.log('App Hide');
|
console.log('App Hide');
|
||||||
// #ifdef APP|APP-PLUS
|
// #ifdef APP|APP-PLUS
|
||||||
|
// 上传中不主动断开:语音上传进行中则不断开蓝牙
|
||||||
let ble = bleTool.getBleTool();
|
let ble = bleTool.getBleTool();
|
||||||
if (ble) {
|
if (ble && ble.isVoiceUploading && ble.isVoiceUploading()) {
|
||||||
console.log("断开所有蓝牙设备");
|
console.log('App Hide: 语音上传中,不启动断开定时器');
|
||||||
ble.disconnectDevice();
|
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
|
// #endif
|
||||||
},
|
},
|
||||||
onError(ex) {
|
onError(ex) {
|
||||||
|
|||||||
@ -320,44 +320,56 @@ class HBY100JProtocol {
|
|||||||
const ft = (fileType & 0xFF) || 1;
|
const ft = (fileType & 0xFF) || 1;
|
||||||
const DELAY_AFTER_START = 80; // 开始包后、等设备响应后再发的缓冲(ms)
|
const DELAY_AFTER_START = 80; // 开始包后、等设备响应后再发的缓冲(ms)
|
||||||
const DELAY_PACKET = 80; // 数据包间延时(ms),参考6155
|
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);
|
if (onProgress) onProgress(1);
|
||||||
const bleToolPromise = import('@/utils/BleHelper.js').then(m => m.default.getBleTool());
|
const bleToolPromise = import('@/utils/BleHelper.js').then(m => m.default.getBleTool());
|
||||||
const send = (dataBytes) => {
|
let bleRef = null;
|
||||||
|
const send = (dataBytes, label = '') => {
|
||||||
const buf = new ArrayBuffer(dataBytes.length + 3);
|
const buf = new ArrayBuffer(dataBytes.length + 3);
|
||||||
const v = new Uint8Array(buf);
|
const v = new Uint8Array(buf);
|
||||||
v[0] = 0xFA;
|
v[0] = 0xFA;
|
||||||
v[1] = 0x05;
|
v[1] = 0x05;
|
||||||
for (let i = 0; i < dataBytes.length; i++) v[2 + i] = dataBytes[i];
|
for (let i = 0; i < dataBytes.length; i++) v[2 + i] = dataBytes[i];
|
||||||
v[v.length - 1] = 0xFF;
|
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));
|
return bleToolPromise.then(ble => ble.sendData(this.bleDeviceId, buf, this.SERVICE_UUID, this.WRITE_UUID));
|
||||||
};
|
};
|
||||||
const delay = (ms) => new Promise(r => setTimeout(r, ms));
|
const delay = (ms) => new Promise(r => setTimeout(r, ms));
|
||||||
// 开始包: FA 05 [fileType] [phase=0] [size 4B LE] FF
|
// 开始包: 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 startData = [ft, 0, total & 0xFF, (total >> 8) & 0xFF, (total >> 16) & 0xFF, (total >> 24) & 0xFF];
|
||||||
const waitPromise = this.waitForFileResponse(1000);
|
const waitPromise = this.waitForFileResponse(1000);
|
||||||
return send(startData)
|
return bleToolPromise.then(ble => {
|
||||||
.then(() => { if (onProgress) onProgress(3); return waitPromise; })
|
bleRef = ble;
|
||||||
.then(() => { if (onProgress) onProgress(5); return delay(DELAY_AFTER_START); })
|
ble.setVoiceUploading(true);
|
||||||
.then(() => {
|
return send(startData, ' 开始包')
|
||||||
let seq = 0;
|
.then(() => { if (onProgress) onProgress(3); return waitPromise; })
|
||||||
const sendNext = (offset) => {
|
.then(() => { if (onProgress) onProgress(5); return delay(DELAY_AFTER_START); })
|
||||||
if (offset >= total) {
|
.then(() => {
|
||||||
return delay(DELAY_PACKET).then(() => send([ft, 2]));
|
let seq = 0;
|
||||||
}
|
const sendNext = (offset) => {
|
||||||
const chunk = bytes.slice(offset, Math.min(offset + chunkSize, total));
|
if (offset >= total) {
|
||||||
const chunkData = [ft, 1, seq & 0xFF, (seq >> 8) & 0xFF, ...chunk];
|
return delay(DELAY_PACKET).then(() => send([ft, 2], ' 结束包'));
|
||||||
return send(chunkData).then(() => {
|
}
|
||||||
seq++;
|
const chunk = bytes.slice(offset, Math.min(offset + chunkSize, total));
|
||||||
if (onProgress) onProgress(Math.min(100, Math.floor((offset + chunk.length) / total * 100)));
|
const chunkData = [ft, 1, seq & 0xFF, (seq >> 8) & 0xFF, ...chunk];
|
||||||
return delay(DELAY_PACKET).then(() => sendNext(offset + chunk.length));
|
return send(chunkData, ` #${seq} 数据包`).then(() => {
|
||||||
});
|
seq++;
|
||||||
};
|
if (onProgress) onProgress(Math.min(100, Math.floor((offset + chunk.length) / total * 100)));
|
||||||
return sendNext(0);
|
return delay(DELAY_PACKET).then(() => sendNext(offset + chunk.length));
|
||||||
})
|
});
|
||||||
.then(() => {
|
};
|
||||||
if (onProgress) onProgress(100);
|
return sendNext(0);
|
||||||
return { code: 200, msg: '语音文件已通过蓝牙上传' };
|
})
|
||||||
});
|
.then(() => {
|
||||||
|
if (onProgress) onProgress(100);
|
||||||
|
return { code: 200, msg: '语音文件已通过蓝牙上传' };
|
||||||
|
});
|
||||||
|
}).finally(() => {
|
||||||
|
if (bleRef) bleRef.setVoiceUploading(false);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
"name" : "星汉物联",
|
"name" : "星汉物联",
|
||||||
"appid" : "__UNI__A21EF43",
|
"appid" : "__UNI__A21EF43",
|
||||||
"description" : "设备管控",
|
"description" : "设备管控",
|
||||||
"versionName" : "1.0.22",
|
"versionName" : "1.0.24",
|
||||||
"versionCode" : 101,
|
"versionCode" : 101,
|
||||||
"transformPx" : false,
|
"transformPx" : false,
|
||||||
/* 5+App特有相关 */
|
/* 5+App特有相关 */
|
||||||
@ -56,7 +56,8 @@
|
|||||||
"<uses-permission android:name=\"android.permission.ACCESS_COARSE_LOCATION\"/>",
|
"<uses-permission android:name=\"android.permission.ACCESS_COARSE_LOCATION\"/>",
|
||||||
"<uses-permission android:name=\"android.permission.READ_EXTERNAL_STORAGE\"/>",
|
"<uses-permission android:name=\"android.permission.READ_EXTERNAL_STORAGE\"/>",
|
||||||
"<uses-permission android:name=\"android.permission.a\"/>",
|
"<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,
|
"minSdkVersion" : 21,
|
||||||
"abiFilters" : [ "armeabi-v7a", "arm64-v8a", "x86" ],
|
"abiFilters" : [ "armeabi-v7a", "arm64-v8a", "x86" ],
|
||||||
|
|||||||
@ -194,7 +194,7 @@
|
|||||||
<view class="slider-container">
|
<view class="slider-container">
|
||||||
<slider min="10" max="100" step="10" :disabled="false" :value="formData.sta_LightDimmer"
|
<slider min="10" max="100" step="10" :disabled="false" :value="formData.sta_LightDimmer"
|
||||||
activeColor="#bbe600" backgroundColor="#686767" block-size="20" block-color="#ffffffde"
|
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>
|
||||||
<view class="line"></view>
|
<view class="line"></view>
|
||||||
@ -206,7 +206,7 @@
|
|||||||
<view class="slider-container">
|
<view class="slider-container">
|
||||||
<slider min="0.5" max="10" step="0.5" :disabled="false" :value="formData.sta_LightFreq"
|
<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"
|
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>
|
||||||
<view class="line"></view>
|
<view class="line"></view>
|
||||||
@ -218,7 +218,7 @@
|
|||||||
<view class="slider-container">
|
<view class="slider-container">
|
||||||
<slider min="1" max="8" step="1" :disabled="false" :value="formData.sta_VoiceVolume"
|
<slider min="1" max="8" step="1" :disabled="false" :value="formData.sta_VoiceVolume"
|
||||||
activeColor="#bbe600" backgroundColor="#686767" block-size="20" block-color="#ffffffde"
|
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>
|
</view>
|
||||||
|
|
||||||
|
|
||||||
@ -850,9 +850,11 @@
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
onFreqChanging(e){
|
||||||
|
this.formData.sta_LightFreq = e.detail.value;
|
||||||
|
},
|
||||||
//频率
|
//频率
|
||||||
onFreqChanging(e) {
|
onFreqChanged(e) {
|
||||||
let f = this.getDevice();
|
let f = this.getDevice();
|
||||||
// #ifdef APP-PLUS
|
// #ifdef APP-PLUS
|
||||||
if (!f) {
|
if (!f) {
|
||||||
@ -897,8 +899,11 @@
|
|||||||
|
|
||||||
}, 100);
|
}, 100);
|
||||||
},
|
},
|
||||||
|
onVolumeChanging(e){
|
||||||
|
this.formData.sta_VoiceVolume = e.detail.value;
|
||||||
|
},
|
||||||
//音量
|
//音量
|
||||||
onVolumeChanging(e) {
|
onVolumeChanged(e) {
|
||||||
let f = this.getDevice();
|
let f = this.getDevice();
|
||||||
// #ifdef APP-PLUS
|
// #ifdef APP-PLUS
|
||||||
if (!f) {
|
if (!f) {
|
||||||
@ -938,8 +943,11 @@
|
|||||||
|
|
||||||
}, 100);
|
}, 100);
|
||||||
},
|
},
|
||||||
|
onBrightnessChanging(e){
|
||||||
|
this.formData.sta_LightDimmer = e.detail.value;
|
||||||
|
},
|
||||||
// 亮度调节
|
// 亮度调节
|
||||||
onBrightnessChanging(e) {
|
onBrightnessChanged(e) {
|
||||||
let f = this.getDevice();
|
let f = this.getDevice();
|
||||||
// #ifdef APP-PLUS
|
// #ifdef APP-PLUS
|
||||||
if (!f) {
|
if (!f) {
|
||||||
|
|||||||
@ -50,7 +50,8 @@
|
|||||||
</view>
|
</view>
|
||||||
<view class="item" @click.top="bleStatuToggle">
|
<view class="item" @click.top="bleStatuToggle">
|
||||||
<text class="lbl">蓝牙状态</text>
|
<text class="lbl">蓝牙状态</text>
|
||||||
<text class="value" :class="formData.bleStatu?'green':'red'">{{device.getbleStatu}}</text>
|
<text class="value"
|
||||||
|
:class="(!formData.bleStatu || formData.bleStatu==='err')?'red':'green'">{{getbleStatu}}</text>
|
||||||
</view>
|
</view>
|
||||||
<view class="item">
|
<view class="item">
|
||||||
<text class="lbl">设备状态</text>
|
<text class="lbl">设备状态</text>
|
||||||
@ -469,6 +470,17 @@
|
|||||||
onLoad: function() {
|
onLoad: function() {
|
||||||
const eventChannel = this.getOpenerEventChannel();
|
const eventChannel = this.getOpenerEventChannel();
|
||||||
var these = this;
|
var these = this;
|
||||||
|
|
||||||
|
this.$watch("deviceInfo.batteryPercentage", (newVal, oldVal) => {
|
||||||
|
if (newVal <= 20) {
|
||||||
|
uni.showToast({
|
||||||
|
title: '设备电量低',
|
||||||
|
icon: 'none',
|
||||||
|
duration: 2000
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
eventChannel.on('detailData', function(data) {
|
eventChannel.on('detailData', function(data) {
|
||||||
var device = data.data;
|
var device = data.data;
|
||||||
these.device = device;
|
these.device = device;
|
||||||
@ -607,9 +619,11 @@
|
|||||||
console.log(this.activePermissions, 'this.activePermissions');
|
console.log(this.activePermissions, 'this.activePermissions');
|
||||||
these.fetchDeviceDetail(data.data.deviceId)
|
these.fetchDeviceDetail(data.data.deviceId)
|
||||||
}
|
}
|
||||||
// 尝试连接蓝牙:需先扫描获取 BLE deviceId,不能直接用 MAC
|
// 尝试连接蓝牙:需先扫描获取 BLE deviceId,不能直接用 MAC;延迟 500ms 确保蓝牙适配器就绪
|
||||||
if (data.data.deviceMac) {
|
if (data.data.deviceMac) {
|
||||||
these.tryConnect100JBle(data.data.deviceMac);
|
setTimeout(() => {
|
||||||
|
these.tryConnect100JBle(data.data.deviceMac);
|
||||||
|
}, 500);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.createThrottledFunctions();
|
this.createThrottledFunctions();
|
||||||
@ -641,10 +655,53 @@
|
|||||||
this.Status.pageHide = false;
|
this.Status.pageHide = false;
|
||||||
},
|
},
|
||||||
computed: {
|
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: {
|
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() {
|
createThrottledFunctions() {
|
||||||
// 创建节流函数
|
// 创建节流函数
|
||||||
this.throttledBrightnessChange = this.throttle(this.handleBrightnessChange, 500);
|
this.throttledBrightnessChange = this.throttle(this.handleBrightnessChange, 500);
|
||||||
@ -991,42 +1048,73 @@
|
|||||||
|
|
||||||
deviceRecovry(res) {},
|
deviceRecovry(res) {},
|
||||||
deviceDispose(res) {},
|
deviceDispose(res) {},
|
||||||
// 100J 蓝牙连接:先查缓存/尝试直连,失败则扫描(createBLEConnection 需要扫描返回的 deviceId)
|
// 100J 蓝牙连接:先查缓存/尝试直连,失败则扫描
|
||||||
|
// 注意:Android 的 createBLEConnection 需要系统返回的 deviceId,服务端 MAC(11:22:33:44:55:02) 与 deviceId(02:55:44:33:22:11) 字节序相反
|
||||||
tryConnect100JBle(deviceMac) {
|
tryConnect100JBle(deviceMac) {
|
||||||
const that = this;
|
const that = this;
|
||||||
const macNorm = (m) => (m || '').replace(/:/g, '').toUpperCase();
|
const macNorm = (m) => (m || '').replace(/:/g, '').toUpperCase();
|
||||||
const targetMacNorm = macNorm(deviceMac);
|
const targetMacNorm = macNorm(deviceMac);
|
||||||
const last6 = targetMacNorm.slice(-6);
|
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 匹配
|
// 1. 查缓存:之前连过且 mac 匹配
|
||||||
const cached = bleTool.data.LinkedList.find(v => {
|
const cached = bleTool.data.LinkedList.find(v => {
|
||||||
const m = macNorm(v.macAddress);
|
const m = macNorm(v.macAddress);
|
||||||
return m === targetMacNorm || m.slice(-6) === last6;
|
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) {
|
if (cached && cached.deviceId) {
|
||||||
console.log('[100J] 使用缓存设备连接', cached.deviceId);
|
console.log('[100J] 使用缓存设备连接', cached.deviceId);
|
||||||
bleTool.LinkBlue(cached.deviceId).then(() => {
|
that.formData.bleStatu = 'connecting';
|
||||||
|
bleTool.LinkBlue(cached.deviceId, SVC, WRITE, NOTIFY, 2).then(() => {
|
||||||
console.log('100J 蓝牙连接成功(缓存)');
|
console.log('100J 蓝牙连接成功(缓存)');
|
||||||
that.bleStateRecovry({ deviceId: cached.deviceId });
|
that.formData.bleStatu = true;
|
||||||
|
that.bleStateRecovry({
|
||||||
|
deviceId: cached.deviceId
|
||||||
|
});
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
console.log('100J 蓝牙连接失败(缓存),尝试扫描', err);
|
console.log('100J 蓝牙连接失败(缓存),尝试扫描', err);
|
||||||
|
that.formData.bleStatu = 'err';
|
||||||
that.connect100JByScan(deviceMac, last6);
|
that.connect100JByScan(deviceMac, last6);
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. 无缓存:先尝试直连(Android 上 deviceId 可能为 MAC)
|
// 2. 无缓存:先尝试直连。Android 上 deviceId 多为 MAC 反序(11:22:33:44:55:02->02:55:44:33:22:11)
|
||||||
console.log('[100J] 尝试直连', deviceMac);
|
that.formData.bleStatu = 'connecting';
|
||||||
bleTool.LinkBlue(deviceMac).then(() => {
|
const tryDirect = (id) => bleTool.LinkBlue(id, SVC, WRITE, NOTIFY, 2).then(() => {
|
||||||
console.log('100J 蓝牙连接成功(直连)');
|
console.log('100J 蓝牙连接成功(直连)', id);
|
||||||
that.bleStateRecovry({ deviceId: deviceMac });
|
that.formData.bleStatu = true;
|
||||||
}).catch(err => {
|
that.bleStateRecovry({
|
||||||
console.log('100J 蓝牙直连失败,开始扫描', err);
|
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);
|
that.connect100JByScan(deviceMac, last6);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
connect100JByScan(deviceMac, last6) {
|
connect100JByScan(deviceMac, last6) {
|
||||||
const that = this;
|
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;
|
let resolved = false;
|
||||||
const timeout = 15000;
|
const timeout = 15000;
|
||||||
const timer = setTimeout(() => {
|
const timer = setTimeout(() => {
|
||||||
@ -1050,11 +1138,16 @@
|
|||||||
bleTool.StopSearch();
|
bleTool.StopSearch();
|
||||||
bleTool.removeDeviceFound('HBY100J_SCAN');
|
bleTool.removeDeviceFound('HBY100J_SCAN');
|
||||||
console.log('[100J] 扫描到目标设备', match.name, match.deviceId);
|
console.log('[100J] 扫描到目标设备', match.name, match.deviceId);
|
||||||
bleTool.LinkBlue(match.deviceId).then(() => {
|
that.formData.bleStatu = 'connecting';
|
||||||
|
bleTool.LinkBlue(match.deviceId, SVC, WRITE, NOTIFY, 2).then(() => {
|
||||||
console.log('100J 蓝牙连接成功(扫描)');
|
console.log('100J 蓝牙连接成功(扫描)');
|
||||||
that.bleStateRecovry({ deviceId: match.deviceId });
|
that.formData.bleStatu = true;
|
||||||
|
that.bleStateRecovry({
|
||||||
|
deviceId: match.deviceId
|
||||||
|
});
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
console.log('100J 蓝牙连接失败,将使用4G', err);
|
console.log('100J 蓝牙连接失败,将使用4G', err);
|
||||||
|
that.formData.bleStatu = 'err';
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}, 'HBY100J_SCAN');
|
}, 'HBY100J_SCAN');
|
||||||
@ -1071,6 +1164,7 @@
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
bleStateBreak() {
|
bleStateBreak() {
|
||||||
|
this.formData.bleStatu = false;
|
||||||
updateBleStatus(false, '', this.deviceInfo.deviceId);
|
updateBleStatus(false, '', this.deviceInfo.deviceId);
|
||||||
},
|
},
|
||||||
bleStateRecovry(res) {
|
bleStateRecovry(res) {
|
||||||
@ -1095,7 +1189,8 @@
|
|||||||
previewImg(img) {},
|
previewImg(img) {},
|
||||||
bleValueNotify: function(receive, device, path, recArr) { //订阅消息
|
bleValueNotify: function(receive, device, path, recArr) { //订阅消息
|
||||||
// 仅处理当前设备的数据(device 为 LinkedList 中匹配 receive.deviceId 的项)
|
// 仅处理当前设备的数据(device 为 LinkedList 中匹配 receive.deviceId 的项)
|
||||||
if (device && device.device && this.deviceInfo.deviceId && device.device.id != this.deviceInfo.deviceId) return;
|
if (device && device.device && this.deviceInfo.deviceId && device.device.id != this.deviceInfo
|
||||||
|
.deviceId) return;
|
||||||
// 解析蓝牙上报数据 (协议: FC=MAC主动上报, FB=指令响应)
|
// 解析蓝牙上报数据 (协议: FC=MAC主动上报, FB=指令响应)
|
||||||
if (!receive.bytes || receive.bytes.length < 3) return;
|
if (!receive.bytes || receive.bytes.length < 3) return;
|
||||||
const parsedData = parseBleData(receive.bytes);
|
const parsedData = parseBleData(receive.bytes);
|
||||||
@ -1124,9 +1219,62 @@
|
|||||||
this.$set(this.deviceInfo, 'batteryRemainingTime', parsedData.batteryRemainingTime);
|
this.$set(this.deviceInfo, 'batteryRemainingTime', parsedData.batteryRemainingTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.deviceInfo.batteryPercentage <= 20) {
|
|
||||||
this.showMsg("设备电量低");
|
|
||||||
|
// 设备物理按键切换:蓝牙响应同步到 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() {},
|
showBleUnConnect() {},
|
||||||
|
|
||||||
|
|||||||
@ -60,12 +60,12 @@
|
|||||||
</view>
|
</view>
|
||||||
<view class="item" @click.top="bleStatuToggle">
|
<view class="item" @click.top="bleStatuToggle">
|
||||||
<text class="lbl">蓝牙状态</text>
|
<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>
|
||||||
<!-- <view class="item">
|
|
||||||
<text class="lbl">设备状态</text>
|
|
||||||
<text class="value">{{formData.sta_charge?dic.sta_charge[formData.sta_charge]:"" }}</text>
|
|
||||||
</view> -->
|
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<view class="warnnig" v-for="item,index in warnDevices">
|
<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"
|
:iconUrl="Status.Pop.iconUrl" :message="Status.Pop.message" :buttonText="Status.Pop.buttonText"
|
||||||
@buttonClick="HidePop" :visiblePrompt="Status.Pop.visiblePrompt" :promptTitle="Status.Pop.promptTitle"
|
@buttonClick="HidePop" :visiblePrompt="Status.Pop.visiblePrompt" :promptTitle="Status.Pop.promptTitle"
|
||||||
v-model="Status.Pop.modelValue" @closePop="closePop" :buttonCancelText="Status.Pop.buttonCancelText"
|
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,
|
curr: 0,
|
||||||
total: 0,
|
total: 0,
|
||||||
pageHide: false,
|
pageHide: false,
|
||||||
|
ShowEditChannel: false,
|
||||||
Pop: {
|
Pop: {
|
||||||
showPop: false, //是否显示弹窗
|
showPop: false, //是否显示弹窗
|
||||||
popType: 'custom',
|
popType: 'custom',
|
||||||
@ -325,8 +333,8 @@
|
|||||||
warnTime: '',
|
warnTime: '',
|
||||||
sta_sosadd: "",
|
sta_sosadd: "",
|
||||||
sta_sosName: '',
|
sta_sosName: '',
|
||||||
sta_IntrusTime: ''
|
sta_IntrusTime: '',
|
||||||
|
ins_Channel:23
|
||||||
},
|
},
|
||||||
dic: {
|
dic: {
|
||||||
sta_LightType: [
|
sta_LightType: [
|
||||||
@ -519,7 +527,7 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
this.getLinkedCnt();
|
// this.getLinkedCnt();
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
Distance: function() {
|
Distance: function() {
|
||||||
@ -561,6 +569,73 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
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() { //获取在线设备的数量
|
getLinkedCnt() { //获取在线设备的数量
|
||||||
|
|
||||||
let f = this.getDevice();
|
let f = this.getDevice();
|
||||||
@ -2266,4 +2341,30 @@
|
|||||||
/deep/ .uni-navbar--fixed {
|
/deep/ .uni-navbar--fixed {
|
||||||
top: 0px;
|
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>
|
</style>
|
||||||
@ -10,8 +10,8 @@
|
|||||||
</uni-nav-bar>
|
</uni-nav-bar>
|
||||||
<view class="contentBg">
|
<view class="contentBg">
|
||||||
<view class="row">
|
<view class="row">
|
||||||
<view class="typeItem fleft" :class="{'active':Status.tabType=='link'}" @click.stop="tabChange('link')">
|
<!-- <view class="typeItem fleft" :class="{'active':Status.tabType=='link'}" @click.stop="tabChange('link')">
|
||||||
连接记录</view>
|
连接记录</view> -->
|
||||||
<view class="typeItem fleft" :class="{'active':Status.tabType=='warn'}" @click.stop="tabChange('warn')">
|
<view class="typeItem fleft" :class="{'active':Status.tabType=='warn'}" @click.stop="tabChange('warn')">
|
||||||
报警记录</view>
|
报警记录</view>
|
||||||
<view class="filterIco fright" @click.stop="showFilter()">
|
<view class="filterIco fright" @click.stop="showFilter()">
|
||||||
@ -90,7 +90,7 @@
|
|||||||
<view class="mothItem center" :class="{active:Status.filterDayType=='monthThree'}"
|
<view class="mothItem center" :class="{active:Status.filterDayType=='monthThree'}"
|
||||||
@click.stop="mothItemChange('monthThree')">近三个月</view>
|
@click.stop="mothItemChange('monthThree')">近三个月</view>
|
||||||
<view class="mothItem center" :class="{active:Status.filterDayType=='monthOne'}"
|
<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'}"
|
<view class="mothItem center" :class="{active:Status.filterDayType=='customer'}"
|
||||||
@click.stop="mothItemChange('customer')">自定义</view>
|
@click.stop="mothItemChange('customer')">自定义</view>
|
||||||
|
|
||||||
@ -204,7 +204,7 @@
|
|||||||
filterMode: true, //是否筛选日期
|
filterMode: true, //是否筛选日期
|
||||||
filterDayMode: 'end', //当前筛选的是开始还是结束
|
filterDayMode: 'end', //当前筛选的是开始还是结束
|
||||||
filterDayType: 'customer', //当前筛选的日期是哪种类型
|
filterDayType: 'customer', //当前筛选的日期是哪种类型
|
||||||
tabType: 'link',
|
tabType: 'warn',
|
||||||
|
|
||||||
datePickValue: [999, 999, 999] //日期选择控件绑定的值
|
datePickValue: [999, 999, 999] //日期选择控件绑定的值
|
||||||
|
|
||||||
@ -251,10 +251,10 @@
|
|||||||
|
|
||||||
let eventChannel = this.getOpenerEventChannel();
|
let eventChannel = this.getOpenerEventChannel();
|
||||||
|
|
||||||
eventChannel.on('detailData', function(data) {
|
eventChannel.on('detailData', (data)=> {
|
||||||
var device = data.data;
|
var device = data.data;
|
||||||
these.device = device;
|
this.device = device;
|
||||||
these.tabChange('link');
|
this.tabChange('warn');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
@ -304,7 +304,7 @@
|
|||||||
let today = new Date();
|
let today = new Date();
|
||||||
let end = Common.DateFormat(today, 'yyyy-MM-dd');
|
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.start = start;
|
||||||
this.filter.end = end;
|
this.filter.end = end;
|
||||||
|
|
||||||
@ -595,7 +595,9 @@
|
|||||||
if (!these.Status.filterMode) {
|
if (!these.Status.filterMode) {
|
||||||
if (these.filter.MM) {
|
if (these.filter.MM) {
|
||||||
start = new Date(these.filter.MM + '-01');
|
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 => {
|
data = data.filter(v => {
|
||||||
|
|
||||||
let t = v.linkEqs[0].linkTime
|
let t = v.linkEqs[0].linkTime
|
||||||
@ -613,7 +615,7 @@
|
|||||||
console.log("these.filter.end=",these.filter.end);
|
console.log("these.filter.end=",these.filter.end);
|
||||||
start = new Date(these.filter.start);
|
start = new Date(these.filter.start);
|
||||||
end = new Date(these.filter.end);
|
end = new Date(these.filter.end);
|
||||||
end.setMonth(1);
|
end.setDate(end.getDate()+1);
|
||||||
console.log("start=",start);
|
console.log("start=",start);
|
||||||
console.log("end=",end);
|
console.log("end=",end);
|
||||||
if(start && end){
|
if(start && end){
|
||||||
@ -643,7 +645,8 @@
|
|||||||
return t >= start;
|
return t >= start;
|
||||||
});
|
});
|
||||||
} else if (these.filter.end) {
|
} 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 => {
|
data = data.filter(v => {
|
||||||
|
|
||||||
@ -680,7 +683,7 @@
|
|||||||
if (systemInfo.uniPlatform == 'web') {
|
if (systemInfo.uniPlatform == 'web') {
|
||||||
|
|
||||||
for (let i = 0; i < 20; i++) {
|
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 numItems = Math.floor(Math.random() * 5) + 1; // 1-5条
|
||||||
|
|
||||||
const item = {
|
const item = {
|
||||||
@ -740,7 +743,8 @@
|
|||||||
console.log("hese.filter.end=" + these.filter.end);
|
console.log("hese.filter.end=" + these.filter.end);
|
||||||
let start = new Date(these.filter.start);
|
let start = new Date(these.filter.start);
|
||||||
let end = new Date(these.filter.end);
|
let end = new Date(these.filter.end);
|
||||||
end.setMonth(1);
|
|
||||||
|
end.setDate(end.getDate()+ 1);
|
||||||
data = data.filter(v => {
|
data = data.filter(v => {
|
||||||
|
|
||||||
let t = v.warnTime
|
let t = v.warnTime
|
||||||
@ -748,7 +752,7 @@
|
|||||||
t = new Date(v.warnTime);
|
t = new Date(v.warnTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
return t >= start && t <= end;
|
return t >= start && t < end;
|
||||||
});
|
});
|
||||||
} else if (these.filter.start) {
|
} else if (these.filter.start) {
|
||||||
let start = new Date(these.filter.start);
|
let start = new Date(these.filter.start);
|
||||||
@ -762,7 +766,8 @@
|
|||||||
return t >= start;
|
return t >= start;
|
||||||
});
|
});
|
||||||
} else if (these.filter.end) {
|
} 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 => {
|
data = data.filter(v => {
|
||||||
let t = v.warnTime
|
let t = v.warnTime
|
||||||
if (!(t instanceof Date)) {
|
if (!(t instanceof Date)) {
|
||||||
@ -774,7 +779,9 @@
|
|||||||
} else {
|
} else {
|
||||||
if (these.filter.MM) {
|
if (these.filter.MM) {
|
||||||
let start = new Date(these.filter.MM + '-01');
|
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) => {
|
data = data.filter((v) => {
|
||||||
let t = v.warnTime
|
let t = v.warnTime
|
||||||
if (!(t instanceof Date)){
|
if (!(t instanceof Date)){
|
||||||
|
|||||||
@ -74,7 +74,7 @@
|
|||||||
|
|
||||||
<view class="slider-container">
|
<view class="slider-container">
|
||||||
<slider min="1" max="100" step="1" :disabled="false" :value="formData.liangDu" activeColor="#bbe600"
|
<slider min="1" max="100" step="1" :disabled="false" :value="formData.liangDu" activeColor="#bbe600"
|
||||||
backgroundColor="#00000000" block-size="20" block-color="#ffffffde" @change="sliderChange"
|
backgroundColor="#00000000" block-size="20" block-color="#ffffffde" @change="sliderChange" @changing="sliderChanging"
|
||||||
class="custom-slider" />
|
class="custom-slider" />
|
||||||
|
|
||||||
</view>
|
</view>
|
||||||
@ -385,7 +385,7 @@
|
|||||||
}
|
}
|
||||||
let f = ble.data.LinkedList.find((v) => {
|
let f = ble.data.LinkedList.find((v) => {
|
||||||
if (v.macAddress == device.deviceMac) {
|
if (v.macAddress == device.deviceMac) {
|
||||||
console.log("找到设备了", v);
|
// console.log("找到设备了", v);
|
||||||
these.formData.deviceId = v.deviceId;
|
these.formData.deviceId = v.deviceId;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -824,7 +824,7 @@
|
|||||||
let packetData = these.rgb565Data.slice(startIndex,
|
let packetData = these.rgb565Data.slice(startIndex,
|
||||||
endIndex);
|
endIndex);
|
||||||
// 构建数据包
|
// 构建数据包
|
||||||
let bufferSize = os == 'Android' ? 505 :133; // 5 + packetData.length * 2; // 头部5字节 + 数据部分
|
let bufferSize = os ==packetSize.length*2+5; // 5 + packetData.length * 2; // 头部5字节 + 数据部分
|
||||||
let buffer = new ArrayBuffer(bufferSize);
|
let buffer = new ArrayBuffer(bufferSize);
|
||||||
let dataView = new DataView(buffer);
|
let dataView = new DataView(buffer);
|
||||||
|
|
||||||
@ -1784,6 +1784,9 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
},
|
},
|
||||||
|
sliderChanging(evt){
|
||||||
|
this.formData.liangDu = evt.detail.value;
|
||||||
|
},
|
||||||
sliderChange: function(evt) {
|
sliderChange: function(evt) {
|
||||||
|
|
||||||
if (!this.permissions.includes('1') && this.Status.apiType !== 'listA') {
|
if (!this.permissions.includes('1') && this.Status.apiType !== 'listA') {
|
||||||
@ -1834,10 +1837,10 @@
|
|||||||
|
|
||||||
dataView.setUint8(0, 0x55); // 帧头
|
dataView.setUint8(0, 0x55); // 帧头
|
||||||
dataView.setUint8(1, 0x07); // 帧类型:亮度调节
|
dataView.setUint8(1, 0x07); // 帧类型:亮度调节
|
||||||
dataView.setUint8(2, 0x01); // 包序号
|
dataView.setUint8(2, 0x01);
|
||||||
dataView.setUint8(3, 0x00); // 包序号
|
dataView.setUint8(3, 0x00);
|
||||||
dataView.setUint8(4, 0x01); // 数据长度
|
dataView.setUint8(4, 0x01); //
|
||||||
dataView.setUint8(5, liangDu); // 数据长度
|
dataView.setUint8(5, liangDu); // 数据
|
||||||
|
|
||||||
let f = this.getDevice();
|
let f = this.getDevice();
|
||||||
if (f) {
|
if (f) {
|
||||||
|
|||||||
@ -74,7 +74,7 @@
|
|||||||
<view class="slider-container">
|
<view class="slider-container">
|
||||||
<slider min="1" max="100" step="1" :disabled="false" :value="formData.liangDu" activeColor="#bbe600"
|
<slider min="1" max="100" step="1" :disabled="false" :value="formData.liangDu" activeColor="#bbe600"
|
||||||
backgroundColor="#00000000" block-size="20" block-color="#ffffffde" @change="sliderChange"
|
backgroundColor="#00000000" block-size="20" block-color="#ffffffde" @change="sliderChange"
|
||||||
@changing="sliderChange" class="custom-slider" />
|
@changing="sliderChanging" class="custom-slider" />
|
||||||
|
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
@ -1394,6 +1394,10 @@ debugger;
|
|||||||
});
|
});
|
||||||
|
|
||||||
},
|
},
|
||||||
|
sliderChanging(evt){
|
||||||
|
this.formData.liangDu = evt.detail.value;
|
||||||
|
},
|
||||||
|
|
||||||
sliderChange: function(evt) {
|
sliderChange: function(evt) {
|
||||||
this.formData.liangDu = evt.detail.value;
|
this.formData.liangDu = evt.detail.value;
|
||||||
clearTimeout(BrighInteval)
|
clearTimeout(BrighInteval)
|
||||||
|
|||||||
@ -53,7 +53,9 @@
|
|||||||
Statu: {
|
Statu: {
|
||||||
bound: null,
|
bound: null,
|
||||||
timeInteval: null,
|
timeInteval: null,
|
||||||
isSearch: false
|
isSearch: false,
|
||||||
|
pageHide:false,
|
||||||
|
isBind:false
|
||||||
},
|
},
|
||||||
device: {
|
device: {
|
||||||
"deviceId": "",
|
"deviceId": "",
|
||||||
@ -115,17 +117,32 @@
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
onShow() {
|
||||||
|
this.Statu.pageHide=false;
|
||||||
|
},
|
||||||
|
onHide() {
|
||||||
|
this.Statu.pageHide=true;
|
||||||
|
},
|
||||||
onUnload() {
|
onUnload() {
|
||||||
console.log("返回取消订阅");
|
console.log("返回取消订阅");
|
||||||
clearInterval(inteval);
|
clearInterval(inteval);
|
||||||
ble.removeAllCallback(pagePath);
|
ble.removeAllCallback(pagePath);
|
||||||
|
|
||||||
|
if(!this.Statu.isBind && these.device.deviceId){
|
||||||
|
ble.disconnectDevice(these.device.deviceId).catch(ex=>{
|
||||||
|
console.error("无法断开蓝牙连接");
|
||||||
|
});
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
onLoad(option) {
|
onLoad(option) {
|
||||||
these = this;
|
these = this;
|
||||||
ble = bleTool.getBleTool();
|
ble = bleTool.getBleTool();
|
||||||
|
|
||||||
ble.addStateBreakCallback(res => {
|
ble.addStateBreakCallback(res => {
|
||||||
|
if(this.Statu.pageHide){
|
||||||
|
return;
|
||||||
|
}
|
||||||
these.device.linkStatu = false;
|
these.device.linkStatu = false;
|
||||||
hideLoading(these);
|
hideLoading(these);
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
@ -135,6 +152,9 @@
|
|||||||
},pagePath);
|
},pagePath);
|
||||||
|
|
||||||
ble.addStateRecoveryCallback(res => {
|
ble.addStateRecoveryCallback(res => {
|
||||||
|
if(this.Statu.pageHide){
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (these.device.deviceId) {
|
if (these.device.deviceId) {
|
||||||
showLoading(these, {
|
showLoading(these, {
|
||||||
text: '蓝牙已恢复正在连接设备'
|
text: '蓝牙已恢复正在连接设备'
|
||||||
@ -144,6 +164,9 @@
|
|||||||
}
|
}
|
||||||
},pagePath);
|
},pagePath);
|
||||||
ble.addDisposeCallback(res => {
|
ble.addDisposeCallback(res => {
|
||||||
|
if(this.Statu.pageHide){
|
||||||
|
return;
|
||||||
|
}
|
||||||
console.log("处理蓝牙断开连接");
|
console.log("处理蓝牙断开连接");
|
||||||
these.device.linkStatu = false;
|
these.device.linkStatu = false;
|
||||||
if (these.device.deviceId == res.deviceId) {
|
if (these.device.deviceId == res.deviceId) {
|
||||||
@ -156,6 +179,9 @@
|
|||||||
},pagePath);
|
},pagePath);
|
||||||
|
|
||||||
ble.addReceiveCallback((receive, f, path) => {
|
ble.addReceiveCallback((receive, f, path) => {
|
||||||
|
if(this.Statu.pageHide){
|
||||||
|
return;
|
||||||
|
}
|
||||||
console.log("收到设备消息,", receive);
|
console.log("收到设备消息,", receive);
|
||||||
if (these.device.deviceId == receive.deviceId) {
|
if (these.device.deviceId == receive.deviceId) {
|
||||||
console.log("11111:", receive);
|
console.log("11111:", receive);
|
||||||
@ -372,6 +398,7 @@
|
|||||||
clearTimeout(this.Statu.timeInteval);
|
clearTimeout(this.Statu.timeInteval);
|
||||||
this.device.macAddress = null;
|
this.device.macAddress = null;
|
||||||
this.Statu.timeInteval = null;
|
this.Statu.timeInteval = null;
|
||||||
|
this.Statu.isBind=true;
|
||||||
uni.$emit("refreshDeviceList");
|
uni.$emit("refreshDeviceList");
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
uni.switchTab({
|
uni.switchTab({
|
||||||
|
|||||||
@ -23,9 +23,10 @@
|
|||||||
<view class="p100">
|
<view class="p100">
|
||||||
|
|
||||||
<view class="lblTitle">配对设备</view>
|
<view class="lblTitle">配对设备</view>
|
||||||
|
|
||||||
<view class="list" style="margin-bottom: 30rpx;">
|
<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 ">
|
<view class="leftImg ">
|
||||||
<image src="/static/images/common/bluetooth.png" class="titleIco filterNone"
|
<image src="/static/images/common/bluetooth.png" class="titleIco filterNone"
|
||||||
mode="heightFix">
|
mode="heightFix">
|
||||||
@ -33,9 +34,7 @@
|
|||||||
</view>
|
</view>
|
||||||
<view class="centertxt ">
|
<view class="centertxt ">
|
||||||
<view class="name" v-text="item.name"></view>
|
<view class="name" v-text="item.name"></view>
|
||||||
<view class="id">
|
|
||||||
<text>信号:{{item.RSSI}}dBm</text>
|
|
||||||
</view>
|
|
||||||
</view>
|
</view>
|
||||||
<view class="rightIco center">
|
<view class="rightIco center">
|
||||||
<image src="/static/images/BLEAdd/linked.png" class="img" mode="aspectFit">
|
<image src="/static/images/BLEAdd/linked.png" class="img" mode="aspectFit">
|
||||||
@ -134,6 +133,7 @@
|
|||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
Status: {
|
Status: {
|
||||||
|
navigateTO: false,
|
||||||
isPageHidden: false,
|
isPageHidden: false,
|
||||||
intval: null,
|
intval: null,
|
||||||
time: null,
|
time: null,
|
||||||
@ -165,11 +165,14 @@
|
|||||||
},
|
},
|
||||||
search: '', //筛选
|
search: '', //筛选
|
||||||
PairEquip: [], //已配对设备
|
PairEquip: [], //已配对设备
|
||||||
|
tmpLink:[],//本次已配对
|
||||||
EquipMents: [], //搜索出来的设备
|
EquipMents: [], //搜索出来的设备
|
||||||
device: null,
|
device: null,
|
||||||
item: {
|
item: {
|
||||||
deviceId: ''
|
deviceId: ''
|
||||||
}
|
},
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
@ -189,9 +192,20 @@
|
|||||||
if (ble) {
|
if (ble) {
|
||||||
ble.StopSearch();
|
ble.StopSearch();
|
||||||
ble.removeAllCallback(pagePath);
|
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) {
|
onLoad(option) {
|
||||||
|
debugger;
|
||||||
eventChannel = this.getOpenerEventChannel();
|
eventChannel = this.getOpenerEventChannel();
|
||||||
|
|
||||||
eventChannel.on('detailData', function(rec) {
|
eventChannel.on('detailData', function(rec) {
|
||||||
@ -211,8 +225,8 @@
|
|||||||
|
|
||||||
const systemInfo = uni.getSystemInfoSync();
|
const systemInfo = uni.getSystemInfoSync();
|
||||||
|
|
||||||
ble = bleTool.getBleTool(); // Ensure ble is initialized
|
// Ensure ble is initialized
|
||||||
|
|
||||||
if (systemInfo.uniPlatform == 'web') {
|
if (systemInfo.uniPlatform == 'web') {
|
||||||
|
|
||||||
|
|
||||||
@ -236,86 +250,19 @@
|
|||||||
"name": "EF4651",
|
"name": "EF4651",
|
||||||
"linkStatu": false,
|
"linkStatu": false,
|
||||||
"isTarget": true
|
"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
|
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
console.error("1111111111")
|
||||||
these.PairEquip = [this.EquipMents[0]];
|
this.PairEquip=[this.EquipMents[0]];
|
||||||
this.$forceUpdate();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
ble = bleTool.getBleTool();
|
||||||
|
this.refreshLinked();
|
||||||
|
|
||||||
let StartSubsrib = () => {
|
let StartSubsrib = () => {
|
||||||
|
|
||||||
these.EquipMents = [];
|
these.EquipMents = [];
|
||||||
if (!ble) {
|
if (!ble) {
|
||||||
ble = bleTool.getBleTool();
|
ble = bleTool.getBleTool();
|
||||||
@ -327,6 +274,7 @@
|
|||||||
}
|
}
|
||||||
console.log("处理蓝牙不可用");
|
console.log("处理蓝牙不可用");
|
||||||
hideLoading(these);
|
hideLoading(these);
|
||||||
|
console.error("1111111111")
|
||||||
these.PairEquip = [];
|
these.PairEquip = [];
|
||||||
these.EquipMents = [];
|
these.EquipMents = [];
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
@ -336,13 +284,14 @@
|
|||||||
these.showOpenSetting();
|
these.showOpenSetting();
|
||||||
|
|
||||||
}, pagePath);
|
}, pagePath);
|
||||||
|
|
||||||
//蓝牙恢复可用的回调
|
//蓝牙恢复可用的回调
|
||||||
ble.addStateRecoveryCallback(res=>{
|
ble.addStateRecoveryCallback(res => {
|
||||||
if (these.Status.isPageHidden) {
|
if (these.Status.isPageHidden) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
these.Status.BottomMenu.show = false;
|
these.Status.BottomMenu.show = false;
|
||||||
|
console.error("1111111111")
|
||||||
these.PairEquip = [];
|
these.PairEquip = [];
|
||||||
these.EquipMents = [];
|
these.EquipMents = [];
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
@ -350,7 +299,7 @@
|
|||||||
title: '蓝牙恢复可用'
|
title: '蓝牙恢复可用'
|
||||||
});
|
});
|
||||||
these.refreshBleList();
|
these.refreshBleList();
|
||||||
}),pagePath;
|
}), pagePath;
|
||||||
|
|
||||||
//蓝牙断开连接的回调
|
//蓝牙断开连接的回调
|
||||||
ble.addDisposeCallback(res => {
|
ble.addDisposeCallback(res => {
|
||||||
@ -360,10 +309,7 @@
|
|||||||
// console.log("处理蓝牙断开连接");
|
// console.log("处理蓝牙断开连接");
|
||||||
|
|
||||||
|
|
||||||
these.PairEquip.find(function(v, ind) {
|
these.refreshLinked();
|
||||||
these.PairEquip.splice(ind, 1);
|
|
||||||
return v.deviceId == res.deviceId;
|
|
||||||
});
|
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
hideLoading(these);
|
hideLoading(these);
|
||||||
@ -422,39 +368,31 @@
|
|||||||
these.EquipMents.sort((a, b) => b.RSSI - a.RSSI); //信号好的排前面,一般信号好的是目标设备
|
these.EquipMents.sort((a, b) => b.RSSI - a.RSSI); //信号好的排前面,一般信号好的是目标设备
|
||||||
}
|
}
|
||||||
}, pagePath);
|
}, 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 = () => {
|
let startValidDevice = () => {
|
||||||
if (these.device) {
|
if (these.device) {
|
||||||
console.log("进入配对模式,启用连接恢复和验证逻辑。");
|
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) => {
|
ble.addReceiveCallback((receivData, f, path, arr) => {
|
||||||
@ -476,7 +414,7 @@
|
|||||||
showLoading(these, {
|
showLoading(these, {
|
||||||
text: '正在验证设备'
|
text: '正在验证设备'
|
||||||
});
|
});
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
these.DeviceVerdict(f.deviceId);
|
these.DeviceVerdict(f.deviceId);
|
||||||
}, 0);
|
}, 0);
|
||||||
@ -488,15 +426,33 @@
|
|||||||
|
|
||||||
StartSubsrib();
|
StartSubsrib();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
onShow: function() {
|
onShow: function() {
|
||||||
|
debugger;
|
||||||
this.Status.isPageHidden = false;
|
this.Status.isPageHidden = false;
|
||||||
|
this.Status.navigateTO = false;
|
||||||
this.refreshBleList();
|
this.refreshBleList();
|
||||||
|
this.refreshLinked();
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
refreshLinked(){
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if(ble){
|
||||||
|
let arr=[];
|
||||||
|
arr=ble.data.LinkedList.filter(v=>{
|
||||||
|
return v.Linked;
|
||||||
|
});
|
||||||
|
this.PairEquip=arr;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
},
|
||||||
checkAndRequestLocationPermission() {
|
checkAndRequestLocationPermission() {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
|
|
||||||
@ -515,16 +471,21 @@
|
|||||||
resolve(true);
|
resolve(true);
|
||||||
} else {
|
} else {
|
||||||
// console.warn('定位权限被拒绝');
|
// console.warn('定位权限被拒绝');
|
||||||
|
|
||||||
MsgClear(these);
|
MsgClear(these);
|
||||||
showPop({headerTxt:'权限提醒',message:'扫描蓝牙设备,需要您开启定位权限',buttonText:'去开启',okCallback:uni.openSetting},these,true);
|
showPop({
|
||||||
|
headerTxt: '权限提醒',
|
||||||
|
message: '扫描蓝牙设备,需要您开启定位权限',
|
||||||
|
buttonText: '去开启',
|
||||||
|
okCallback: uni.openSetting
|
||||||
|
}, these, true);
|
||||||
|
|
||||||
resolve(false);
|
resolve(false);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
(error) => {
|
(error) => {
|
||||||
|
|
||||||
MsgError('请求定位权限失败:'+error.code,'确定',these);
|
MsgError('请求定位权限失败:' + error.code, '确定', these);
|
||||||
resolve(false);
|
resolve(false);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -565,19 +526,19 @@
|
|||||||
|
|
||||||
time = setTimeout(() => {
|
time = setTimeout(() => {
|
||||||
these.EquipMents = [];
|
these.EquipMents = [];
|
||||||
these.PairEquip = [];
|
|
||||||
|
|
||||||
ble.StartSearch().then(result => {
|
ble.StartSearch().then(result => {
|
||||||
console.log("开始搜索成功", result);
|
// console.log("开始搜索成功", result);
|
||||||
|
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
console.error("开始搜索失败:", err);
|
console.error("开始搜索失败:", err);
|
||||||
if (err.code === 10001) {
|
if (err.code === 10001) {
|
||||||
these.showOpenSetting();
|
these.showOpenSetting();
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
MsgClear(these);
|
MsgClear(these);
|
||||||
MsgError('出现错误:' + err.msg,'确定',these);
|
MsgError('出现错误:' + err.msg, '确定', these);
|
||||||
|
|
||||||
}
|
}
|
||||||
}).finally(() => {
|
}).finally(() => {
|
||||||
@ -587,8 +548,8 @@
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ble.StopSearch().catch(err=>{
|
ble.StopSearch().catch(err => {
|
||||||
console.error("err=",err);
|
console.error("err=", err);
|
||||||
}).finally(startSearch);
|
}).finally(startSearch);
|
||||||
|
|
||||||
|
|
||||||
@ -716,13 +677,14 @@
|
|||||||
|
|
||||||
text: "等待设备上报Mac地址," + these.Status.time + 's'
|
text: "等待设备上报Mac地址," + these.Status.time + 's'
|
||||||
});
|
});
|
||||||
console.log("11111111", this.Status.time);
|
|
||||||
clearInterval(this.Status.intval);
|
clearInterval(this.Status.intval);
|
||||||
this.Status.intval = null;
|
this.Status.intval = null;
|
||||||
|
|
||||||
this.Status.intval = setInterval(() => {
|
this.Status.intval = setInterval(() => {
|
||||||
this.Status.time = this.Status.time - 1;
|
this.Status.time = this.Status.time - 1;
|
||||||
if (this.Status.time < 0) {
|
if (this.Status.time < 0) {
|
||||||
|
hideLoading(these);
|
||||||
console.log("停止倒计时", this.Status.time);
|
console.log("停止倒计时", this.Status.time);
|
||||||
clearInterval(this.Status.intval)
|
clearInterval(this.Status.intval)
|
||||||
this.Status.intval = null;
|
this.Status.intval = null;
|
||||||
@ -742,9 +704,12 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
updateLoading(these, {
|
updateLoading(these, {
|
||||||
|
|
||||||
text: "等待设备上报Mac地址," + these.Status.time + 's'
|
text: "等待设备上报Mac地址," + these.Status.time + 's'
|
||||||
});
|
});
|
||||||
|
|
||||||
}, 1000);
|
}, 1000);
|
||||||
|
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -760,14 +725,7 @@
|
|||||||
let index = 1;
|
let index = 1;
|
||||||
let total = 5;
|
let total = 5;
|
||||||
|
|
||||||
let linkCallback = (res) => {
|
let linkCallback = (res) => {
|
||||||
let c = these.PairEquip.find(function(v) {
|
|
||||||
return v.deviceId == item.deviceId;
|
|
||||||
});
|
|
||||||
if (!c) {
|
|
||||||
|
|
||||||
these.PairEquip.push(item);
|
|
||||||
}
|
|
||||||
console.log("连接成功", these.device);
|
console.log("连接成功", these.device);
|
||||||
if (!these.device) {
|
if (!these.device) {
|
||||||
console.log("跳转到绑定")
|
console.log("跳转到绑定")
|
||||||
@ -778,19 +736,18 @@
|
|||||||
|
|
||||||
},
|
},
|
||||||
success(res) {
|
success(res) {
|
||||||
|
these.Status.navigateTO = true;
|
||||||
res.eventChannel.emit('LinkItem', item);
|
res.eventChannel.emit('LinkItem', item);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// console.log("验证设备")
|
|
||||||
// these.DeviceVerdict(item.deviceId);
|
|
||||||
}
|
}
|
||||||
let execLink = () => {
|
let execLink = () => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
|
||||||
|
|
||||||
if (index > total) {
|
if (index > total) {
|
||||||
reject({
|
reject({
|
||||||
msg: "连接超时"
|
msg: "连接超时"
|
||||||
@ -798,6 +755,7 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ble.LinkBlue(item.deviceId).then((res) => {
|
ble.LinkBlue(item.deviceId).then((res) => {
|
||||||
|
this.tmpLink=[item];
|
||||||
console.log("连接成功");
|
console.log("连接成功");
|
||||||
ble.StopSearch();
|
ble.StopSearch();
|
||||||
resolve(res);
|
resolve(res);
|
||||||
@ -825,14 +783,30 @@
|
|||||||
}).catch(ex => {
|
}).catch(ex => {
|
||||||
console.error("ex=", ex)
|
console.error("ex=", ex)
|
||||||
MsgClear(these);
|
MsgClear(these);
|
||||||
|
|
||||||
MsgError("连接失败:" + ex.msg,'确定',these);
|
MsgError("连接失败:" + ex.msg, '确定', these);
|
||||||
hideLoading(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
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -972,7 +946,7 @@
|
|||||||
position: absolute;
|
position: absolute;
|
||||||
top: 240rpx;
|
top: 240rpx;
|
||||||
left: 0rpx;
|
left: 0rpx;
|
||||||
/* border: 1px solid #BBE600; */
|
z-index: 101;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1016,7 +990,7 @@
|
|||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
padding: 20rpx;
|
padding: 20rpx;
|
||||||
border-radius: 8px;
|
border-radius: 8px;
|
||||||
background: #1a1a1a;
|
background: #1a1a1a9e;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
flex-wrap: nowrap;
|
flex-wrap: nowrap;
|
||||||
|
|||||||
@ -304,14 +304,14 @@
|
|||||||
|
|
||||||
},
|
},
|
||||||
bleBreak(res) {
|
bleBreak(res) {
|
||||||
console.error("蓝牙断开连接", res);
|
// console.error("蓝牙断开连接", res);
|
||||||
if (res.deviceId) {
|
if (res.deviceId) {
|
||||||
this.updateBleStatu(res.deviceId);
|
this.updateBleStatu(res.deviceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
bleRecovery(res) {
|
bleRecovery(res) {
|
||||||
console.log("蓝牙连接成功", res);
|
// console.log("蓝牙连接成功", res);
|
||||||
if (res.deviceId) {
|
if (res.deviceId) {
|
||||||
this.updateBleStatu(res.deviceId);
|
this.updateBleStatu(res.deviceId);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,180 +1,180 @@
|
|||||||
// eslint-disable
|
// eslint-disable
|
||||||
export const isObject = (obj) => {
|
export const isObject = (obj) => {
|
||||||
return obj
|
return obj
|
||||||
? Object.prototype.toString.call(obj) === "[object Object]"
|
? Object.prototype.toString.call(obj) === "[object Object]"
|
||||||
: false;
|
: false;
|
||||||
};
|
};
|
||||||
export const isArray = (arr) => {
|
export const isArray = (arr) => {
|
||||||
return arr ? Array.isArray(arr) : false;
|
return arr ? Array.isArray(arr) : false;
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
* handle async await
|
* handle async await
|
||||||
* @param {*} promise promise
|
* @param {*} promise promise
|
||||||
*/
|
*/
|
||||||
export const awaitWrap = (promise) =>
|
export const awaitWrap = (promise) =>
|
||||||
promise.then((res) => [null, res]).catch((err) => [err, {}]);
|
promise.then((res) => [null, res]).catch((err) => [err, {}]);
|
||||||
/**
|
/**
|
||||||
* 深拷贝
|
* 深拷贝
|
||||||
* @param {*} source
|
* @param {*} source
|
||||||
*/
|
*/
|
||||||
export const deepClone = (source) => {
|
export const deepClone = (source) => {
|
||||||
if (!isObject(source) && !isArray(source)) return source;
|
if (!isObject(source) && !isArray(source)) return source;
|
||||||
const targetObj = isArray(source) ? [] : {}; // 判断复制的目标是数组还是对象
|
const targetObj = isArray(source) ? [] : {}; // 判断复制的目标是数组还是对象
|
||||||
for (let keys in source) {
|
for (let keys in source) {
|
||||||
// 遍历目标
|
// 遍历目标
|
||||||
if (source.hasOwnProperty(keys)) {
|
if (source.hasOwnProperty(keys)) {
|
||||||
if (source[keys] && typeof source[keys] === "object") {
|
if (source[keys] && typeof source[keys] === "object") {
|
||||||
// 如果值是对象,就递归一下
|
// 如果值是对象,就递归一下
|
||||||
targetObj[keys] = isArray(source[keys]) ? [] : {};
|
targetObj[keys] = isArray(source[keys]) ? [] : {};
|
||||||
targetObj[keys] = deepClone(source[keys]);
|
targetObj[keys] = deepClone(source[keys]);
|
||||||
} else {
|
} else {
|
||||||
// 如果不是,就直接赋值
|
// 如果不是,就直接赋值
|
||||||
targetObj[keys] = source[keys];
|
targetObj[keys] = source[keys];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return targetObj;
|
return targetObj;
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
* @description JS对象深度合并
|
* @description JS对象深度合并
|
||||||
* @param {object} target 需要拷贝的对象
|
* @param {object} target 需要拷贝的对象
|
||||||
* @param {object} source 拷贝的来源对象
|
* @param {object} source 拷贝的来源对象
|
||||||
* @returns {object|boolean} 深度合并后的对象或者false(入参有不是对象)
|
* @returns {object|boolean} 深度合并后的对象或者false(入参有不是对象)
|
||||||
*/
|
*/
|
||||||
export const deepMerge = (target = {}, source = {}) => {
|
export const deepMerge = (target = {}, source = {}) => {
|
||||||
target = deepClone(target);
|
target = deepClone(target);
|
||||||
if (typeof target !== "object" || typeof source !== "object") return false;
|
if (typeof target !== "object" || typeof source !== "object") return false;
|
||||||
for (const prop in source) {
|
for (const prop in source) {
|
||||||
if (!source.hasOwnProperty(prop)) continue;
|
if (!source.hasOwnProperty(prop)) continue;
|
||||||
if (prop in target) {
|
if (prop in target) {
|
||||||
if (typeof target[prop] !== "object") {
|
if (typeof target[prop] !== "object") {
|
||||||
target[prop] = source[prop];
|
target[prop] = source[prop];
|
||||||
} else if (typeof source[prop] !== "object") {
|
} else if (typeof source[prop] !== "object") {
|
||||||
target[prop] = source[prop];
|
target[prop] = source[prop];
|
||||||
} else if (target[prop].concat && source[prop].concat) {
|
} else if (target[prop].concat && source[prop].concat) {
|
||||||
target[prop] = target[prop].concat(source[prop]);
|
target[prop] = target[prop].concat(source[prop]);
|
||||||
} else {
|
} else {
|
||||||
target[prop] = deepMerge(target[prop], source[prop]);
|
target[prop] = deepMerge(target[prop], source[prop]);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
target[prop] = source[prop];
|
target[prop] = source[prop];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return target;
|
return target;
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
* 将File对象转为 Blob Url
|
* 将File对象转为 Blob Url
|
||||||
* @param {File} File对象
|
* @param {File} File对象
|
||||||
* @returns Blob Url
|
* @returns Blob Url
|
||||||
*/
|
*/
|
||||||
export const fileToBlob = (file) => {
|
export const fileToBlob = (file) => {
|
||||||
if (!file) return;
|
if (!file) return;
|
||||||
const fileType = file.type;
|
const fileType = file.type;
|
||||||
const blob = new Blob([file], { type: fileType || 'application/*' });
|
const blob = new Blob([file], { type: fileType || 'application/*' });
|
||||||
const blobUrl = window.URL.createObjectURL(blob);
|
const blobUrl = window.URL.createObjectURL(blob);
|
||||||
return blobUrl;
|
return blobUrl;
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
* 将File对象转为 base64
|
* 将File对象转为 base64
|
||||||
* @param {File} File对象
|
* @param {File} File对象
|
||||||
* @returns base64
|
* @returns base64
|
||||||
*/
|
*/
|
||||||
export const fileToBase64 = (file) => {
|
export const fileToBase64 = (file) => {
|
||||||
if (!file) return;
|
if (!file) return;
|
||||||
return new Promise((r, j) => {
|
return new Promise((r, j) => {
|
||||||
const reader = new FileReader();
|
const reader = new FileReader();
|
||||||
reader.onloadend = () => {
|
reader.onloadend = () => {
|
||||||
const base64String = reader.result;
|
const base64String = reader.result;
|
||||||
r(base64String);
|
r(base64String);
|
||||||
};
|
};
|
||||||
reader.onerror = () => {
|
reader.onerror = () => {
|
||||||
j({ mode: 'fileToBase64', data: { errMsg: 'File to base64 fail.' } });
|
j({ mode: 'fileToBase64', data: { errMsg: 'File to base64 fail.' } });
|
||||||
};
|
};
|
||||||
reader.readAsDataURL(file);
|
reader.readAsDataURL(file);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
* base64转临时路径(改自https://github.com/zhetengbiji/image-tools/blob/master/index.js)
|
* base64转临时路径(改自https://github.com/zhetengbiji/image-tools/blob/master/index.js)
|
||||||
* @param base64
|
* @param base64
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
function dataUrlToBase64(str) {
|
function dataUrlToBase64(str) {
|
||||||
var array = str.split(',');
|
var array = str.split(',');
|
||||||
return array[array.length - 1];
|
return array[array.length - 1];
|
||||||
};
|
};
|
||||||
function biggerThan(v1, v2) {
|
function biggerThan(v1, v2) {
|
||||||
var v1Array = v1.split('.');
|
var v1Array = v1.split('.');
|
||||||
var v2Array = v2.split('.');
|
var v2Array = v2.split('.');
|
||||||
var update = false;
|
var update = false;
|
||||||
for (var index = 0; index < v2Array.length; index++) {
|
for (var index = 0; index < v2Array.length; index++) {
|
||||||
var diff = v1Array[index] - v2Array[index];
|
var diff = v1Array[index] - v2Array[index];
|
||||||
if (diff !== 0) {
|
if (diff !== 0) {
|
||||||
update = diff > 0;
|
update = diff > 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return update;
|
return update;
|
||||||
};
|
};
|
||||||
var index = 0;
|
var index = 0;
|
||||||
function getNewFileId() {
|
function getNewFileId() {
|
||||||
return Date.now() + String(index++);
|
return Date.now() + String(index++);
|
||||||
};
|
};
|
||||||
export const base64ToPath = (base64, name = '') => {
|
export const base64ToPath = (base64, name = '') => {
|
||||||
return new Promise((r, j) => {
|
return new Promise((r, j) => {
|
||||||
if (typeof plus !== 'object') {
|
if (typeof plus !== 'object') {
|
||||||
return j(new Error('not support'));
|
return j(new Error('not support'));
|
||||||
}
|
}
|
||||||
var fileName = '';
|
var fileName = '';
|
||||||
if (name) {
|
if (name) {
|
||||||
const names = name.split('.');
|
const names = name.split('.');
|
||||||
const extName = names.splice(-1);
|
const extName = names.splice(-1);
|
||||||
fileName = `${names.join('.')}-${getNewFileId()}.${extName}`;
|
fileName = `${names.join('.')}-${getNewFileId()}.${extName}`;
|
||||||
} else {
|
} else {
|
||||||
const names = base64.split(',')[0].match(/data\:\S+\/(\S+);/);
|
const names = base64.split(',')[0].match(/data\:\S+\/(\S+);/);
|
||||||
if (!names) {
|
if (!names) {
|
||||||
j(new Error('base64 error'));
|
j(new Error('base64 error'));
|
||||||
}
|
}
|
||||||
const extName = names[1];
|
const extName = names[1];
|
||||||
fileName = `${getNewFileId()}.${extName}`;
|
fileName = `${getNewFileId()}.${extName}`;
|
||||||
}
|
}
|
||||||
var basePath = '_doc';
|
var basePath = '_doc';
|
||||||
var dirPath = 'uniapp_temp';
|
var dirPath = 'uniapp_temp';
|
||||||
var filePath = `${basePath}/${dirPath}/${fileName}`;
|
var filePath = `${basePath}/${dirPath}/${fileName}`;
|
||||||
if (!biggerThan(plus.os.name === 'Android' ? '1.9.9.80627' : '1.9.9.80472', plus.runtime.innerVersion)) {
|
if (!biggerThan(plus.os.name === 'Android' ? '1.9.9.80627' : '1.9.9.80472', plus.runtime.innerVersion)) {
|
||||||
plus.io.resolveLocalFileSystemURL(basePath, function (entry) {
|
plus.io.resolveLocalFileSystemURL(basePath, function (entry) {
|
||||||
entry.getDirectory(dirPath, {
|
entry.getDirectory(dirPath, {
|
||||||
create: true,
|
create: true,
|
||||||
exclusive: false,
|
exclusive: false,
|
||||||
}, function (entry) {
|
}, function (entry) {
|
||||||
entry.getFile(fileName, {
|
entry.getFile(fileName, {
|
||||||
create: true,
|
create: true,
|
||||||
exclusive: false,
|
exclusive: false,
|
||||||
}, function (entry) {
|
}, function (entry) {
|
||||||
entry.createWriter(function (writer) {
|
entry.createWriter(function (writer) {
|
||||||
writer.onwrite = function () {
|
writer.onwrite = function () {
|
||||||
r(filePath);
|
r(filePath);
|
||||||
}
|
}
|
||||||
writer.onerror = j;
|
writer.onerror = j;
|
||||||
writer.seek(0);
|
writer.seek(0);
|
||||||
writer.writeAsBinary(dataUrlToBase64(base64));
|
writer.writeAsBinary(dataUrlToBase64(base64));
|
||||||
}, j)
|
}, j)
|
||||||
}, j)
|
}, j)
|
||||||
}, j)
|
}, j)
|
||||||
}, j)
|
}, j)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var bitmap = new plus.nativeObj.Bitmap(fileName);
|
var bitmap = new plus.nativeObj.Bitmap(fileName);
|
||||||
bitmap.loadBase64Data(base64, function () {
|
bitmap.loadBase64Data(base64, function () {
|
||||||
bitmap.save(filePath, {}, function () {
|
bitmap.save(filePath, {}, function () {
|
||||||
bitmap.clear();
|
bitmap.clear();
|
||||||
r(filePath);
|
r(filePath);
|
||||||
}, function (error) {
|
}, function (error) {
|
||||||
bitmap.clear();
|
bitmap.clear();
|
||||||
j(error);
|
j(error);
|
||||||
});
|
});
|
||||||
}, function (error) {
|
}, function (error) {
|
||||||
bitmap.clear();
|
bitmap.clear();
|
||||||
j(error);
|
j(error);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@ -36,7 +36,7 @@ class BleHelper {
|
|||||||
linkedDevices = uni.getStorageSync(this.StorageKey);
|
linkedDevices = uni.getStorageSync(this.StorageKey);
|
||||||
}
|
}
|
||||||
if (linkedDevices && linkedDevices.length && linkedDevices.length > 0) {
|
if (linkedDevices && linkedDevices.length && linkedDevices.length > 0) {
|
||||||
console.log("111111", linkedDevices);
|
// console.log("111111", linkedDevices);
|
||||||
linkedDevices = linkedDevices.filter((v) => {
|
linkedDevices = linkedDevices.filter((v) => {
|
||||||
if (v) {
|
if (v) {
|
||||||
v.Linked = false;
|
v.Linked = false;
|
||||||
@ -61,7 +61,8 @@ class BleHelper {
|
|||||||
LinkedList: linkedDevices, //已连接的设备列表
|
LinkedList: linkedDevices, //已连接的设备列表
|
||||||
platform: systemInfo.uniPlatform,
|
platform: systemInfo.uniPlatform,
|
||||||
Disconnect: [], //主动断开的设备
|
Disconnect: [], //主动断开的设备
|
||||||
connectingDevices: {} //正在连接的设备
|
connectingDevices: {}, //正在连接的设备
|
||||||
|
voiceUploading: false //语音上传中(上传中不主动断开蓝牙)
|
||||||
}
|
}
|
||||||
this.cfg = {
|
this.cfg = {
|
||||||
onDeviceFound: [], //发现新设备的事件
|
onDeviceFound: [], //发现新设备的事件
|
||||||
@ -561,7 +562,7 @@ class BleHelper {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!this.data.isOpenBlue) {
|
if (!this.data.isOpenBlue) {
|
||||||
console.error("蓝牙模块未打开");
|
console.log("蓝牙模块未打开,即将初始化");
|
||||||
resolve({
|
resolve({
|
||||||
available: false,
|
available: false,
|
||||||
discovering: false
|
discovering: false
|
||||||
@ -613,13 +614,13 @@ class BleHelper {
|
|||||||
if (this.data.isSubscribe) { //整个App生命周期,只订阅一次
|
if (this.data.isSubscribe) { //整个App生命周期,只订阅一次
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
console.error("开始订阅各类变化消息");
|
// console.error("开始订阅各类变化消息");
|
||||||
this.data.isSubscribe = true;
|
this.data.isSubscribe = true;
|
||||||
this.BleStateChange(); //蓝牙适配器变化
|
this.BleStateChange(); //蓝牙适配器变化
|
||||||
this.BleConnChange(); //蓝牙连接变化
|
this.BleConnChange(); //蓝牙连接变化
|
||||||
this.BleDeviceFound(); //发现新设备
|
this.BleDeviceFound(); //发现新设备
|
||||||
this.BleReceive(); //收到消息
|
this.BleReceive(); //收到消息
|
||||||
console.error("订阅各类变化消息完成");
|
// console.error("订阅各类变化消息完成");
|
||||||
},
|
},
|
||||||
fail: (ex2) => {
|
fail: (ex2) => {
|
||||||
console.error("蓝牙模块启动失败", ex2);
|
console.error("蓝牙模块启动失败", ex2);
|
||||||
@ -962,7 +963,7 @@ class BleHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
console.log("蓝牙连接已恢复", res);
|
// console.log("蓝牙连接已恢复", res);
|
||||||
// 系统级连接恢复:更新 LinkedList 并通知业务层,避免 sendData 误判未连接而重复 createBLEConnection
|
// 系统级连接恢复:更新 LinkedList 并通知业务层,避免 sendData 误判未连接而重复 createBLEConnection
|
||||||
let f = this.data.LinkedList.find(v => v.deviceId == res.deviceId);
|
let f = this.data.LinkedList.find(v => v.deviceId == res.deviceId);
|
||||||
if (f) {
|
if (f) {
|
||||||
@ -994,15 +995,15 @@ class BleHelper {
|
|||||||
// console.log("发现新设备",item.name+" "+item.RSSI);
|
// console.log("发现新设备",item.name+" "+item.RSSI);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
let f = serviceDic.find(v => {
|
let f = serviceDic.find(v => {
|
||||||
return item.advertisServiceUUIDs
|
return item.advertisServiceUUIDs
|
||||||
.includes(v.serviceId);
|
.includes(v.serviceId);
|
||||||
});
|
});
|
||||||
if (f) {
|
if (f) {
|
||||||
|
|
||||||
// console.log("发现目标设备:", item);
|
// console.log("发现目标设备:", item);
|
||||||
arr.push(item);
|
arr.push(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
if (arr.length === 0) {
|
if (arr.length === 0) {
|
||||||
@ -1098,7 +1099,7 @@ class BleHelper {
|
|||||||
services: [],
|
services: [],
|
||||||
allowDuplicatesKey: true,
|
allowDuplicatesKey: true,
|
||||||
success: (res) => {
|
success: (res) => {
|
||||||
console.log('开始搜索蓝牙设备成功');
|
// console.log('开始搜索蓝牙设备成功');
|
||||||
resolve(res);
|
resolve(res);
|
||||||
|
|
||||||
},
|
},
|
||||||
@ -1237,11 +1238,11 @@ class BleHelper {
|
|||||||
characteristicId: characteristicId,
|
characteristicId: characteristicId,
|
||||||
state: state,
|
state: state,
|
||||||
success: (res) => {
|
success: (res) => {
|
||||||
if (state) {
|
// if (state) {
|
||||||
console.log("订阅消息成功", res);
|
// console.log("订阅消息成功", res);
|
||||||
} else {
|
// } else {
|
||||||
console.log("取消订阅成功", res);
|
// console.log("取消订阅成功", res);
|
||||||
}
|
// }
|
||||||
|
|
||||||
this.data.LinkedList.find((v) => {
|
this.data.LinkedList.find((v) => {
|
||||||
if (v.deviceId == deviceId) {
|
if (v.deviceId == deviceId) {
|
||||||
@ -1311,13 +1312,13 @@ class BleHelper {
|
|||||||
|
|
||||||
results.forEach((result, index) => {
|
results.forEach((result, index) => {
|
||||||
if (result.status === "fulfilled") {
|
if (result.status === "fulfilled") {
|
||||||
console.log(`订阅消息操作${index + 1}成功:`, result.value);
|
// console.log(`订阅消息操作${index + 1}成功:`, result.value);
|
||||||
} else {
|
} else {
|
||||||
console.error(`订阅消息操作${index + 1}失败:`, result
|
console.error(`订阅消息操作${index + 1}失败:`, result
|
||||||
.reason);
|
.reason);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
console.log("订阅消息完成,deviceId:", deviceId);
|
// console.log("订阅消息完成,deviceId:", deviceId);
|
||||||
resolve();
|
resolve();
|
||||||
}).catch((ex) => {
|
}).catch((ex) => {
|
||||||
console.error("异常,ex=", ex);
|
console.error("异常,ex=", ex);
|
||||||
@ -1624,7 +1625,7 @@ class BleHelper {
|
|||||||
// console.log("正在连接" + deviceId);
|
// console.log("正在连接" + deviceId);
|
||||||
uni.createBLEConnection({
|
uni.createBLEConnection({
|
||||||
deviceId: deviceId,
|
deviceId: deviceId,
|
||||||
timeout: 15000,
|
timeout: 20000,
|
||||||
success: (info) => {
|
success: (info) => {
|
||||||
//释放连接锁
|
//释放连接锁
|
||||||
|
|
||||||
@ -1808,6 +1809,13 @@ class BleHelper {
|
|||||||
});
|
});
|
||||||
return prom;
|
return prom;
|
||||||
}
|
}
|
||||||
|
// 语音上传中不主动断开:设置/查询上传状态(App onHide 时检查)
|
||||||
|
setVoiceUploading(flag) {
|
||||||
|
this.data.voiceUploading = !!flag;
|
||||||
|
}
|
||||||
|
isVoiceUploading() {
|
||||||
|
return !!this.data.voiceUploading;
|
||||||
|
}
|
||||||
//断开连接
|
//断开连接
|
||||||
disconnectDevice(deviceId) {
|
disconnectDevice(deviceId) {
|
||||||
if (this.data.platform == 'web') {
|
if (this.data.platform == 'web') {
|
||||||
|
|||||||
@ -14,8 +14,7 @@ class BleReceive {
|
|||||||
'/pages/100/HBY100': this.Receive_100.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/6170/deviceControl/index':this.Receive_6170.bind(this),
|
||||||
'/pages/100J/HBY100-J': this.Receive_100J.bind(this),
|
'/pages/100J/HBY100-J': this.Receive_100J.bind(this)
|
||||||
'/pages/102/HBY102': this.Receive_102.bind(this)
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
980
utils/Common.js
980
utils/Common.js
@ -1,491 +1,491 @@
|
|||||||
import request from "@/utils/request.js";
|
import request from "@/utils/request.js";
|
||||||
export default {
|
export default {
|
||||||
audioStorageKey: "audioStorageKey",
|
audioStorageKey: "audioStorageKey",
|
||||||
pcmStorageKey: "pcmStorageKey",
|
pcmStorageKey: "pcmStorageKey",
|
||||||
guid: function generateUUID() {
|
guid: function generateUUID() {
|
||||||
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
|
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
|
||||||
let r = Math.random() * 16 | 0;
|
let r = Math.random() * 16 | 0;
|
||||||
let v = c === 'x' ? r : (r & 0x3 | 0x8);
|
let v = c === 'x' ? r : (r & 0x3 | 0x8);
|
||||||
return v.toString(16);
|
return v.toString(16);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
alert: function(title, content, callback) {
|
alert: function(title, content, callback) {
|
||||||
if (!title) {
|
if (!title) {
|
||||||
title = '提示'
|
title = '提示'
|
||||||
}
|
}
|
||||||
if (!content) {
|
if (!content) {
|
||||||
content = title;
|
content = title;
|
||||||
}
|
}
|
||||||
|
|
||||||
uni.showModal({
|
uni.showModal({
|
||||||
title: title,
|
title: title,
|
||||||
content: content,
|
content: content,
|
||||||
success: function(res) {
|
success: function(res) {
|
||||||
if (res.confirm) {
|
if (res.confirm) {
|
||||||
console.log('用户点击确定');
|
console.log('用户点击确定');
|
||||||
} else if (res.cancel) {
|
} else if (res.cancel) {
|
||||||
console.log('用户点击取消');
|
console.log('用户点击取消');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (callback) {
|
if (callback) {
|
||||||
callback(res);
|
callback(res);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
showLoading: function(title, mask) {
|
showLoading: function(title, mask) {
|
||||||
uni.showLoading({
|
uni.showLoading({
|
||||||
title: title,
|
title: title,
|
||||||
mask: mask,
|
mask: mask,
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
hideLoading: function() {
|
hideLoading: function() {
|
||||||
uni.hideLoading();
|
uni.hideLoading();
|
||||||
},
|
},
|
||||||
showToast: function(title, mask, duration, callback) {
|
showToast: function(title, mask, duration, callback) {
|
||||||
if (!duration) {
|
if (!duration) {
|
||||||
duration = 1500;
|
duration = 1500;
|
||||||
}
|
}
|
||||||
if (mask == undefined) {
|
if (mask == undefined) {
|
||||||
mask = false;
|
mask = false;
|
||||||
}
|
}
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
title: title,
|
title: title,
|
||||||
mask: mask,
|
mask: mask,
|
||||||
duration: duration,
|
duration: duration,
|
||||||
callback: callback,
|
callback: callback,
|
||||||
icon: 'none'
|
icon: 'none'
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
GetData: function(url, data, method, contentType, succ, err, complete) {
|
GetData: function(url, data, method, contentType, succ, err, complete) {
|
||||||
var these = this;
|
var these = this;
|
||||||
if (!url) {
|
if (!url) {
|
||||||
console.error("url为空");
|
console.error("url为空");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (url.toLowerCase().indexOf('http://') == -1 || url.toLowerCase().indexOf('https://') == -1) {
|
if (url.toLowerCase().indexOf('http://') == -1 || url.toLowerCase().indexOf('https://') == -1) {
|
||||||
if (url.indexOf('/') == 0) {
|
if (url.indexOf('/') == 0) {
|
||||||
url = url.substr(1, url.length - 1);
|
url = url.substr(1, url.length - 1);
|
||||||
}
|
}
|
||||||
let ServerPath = these.DevApi;
|
let ServerPath = these.DevApi;
|
||||||
if (these.Version === 'Dev') {
|
if (these.Version === 'Dev') {
|
||||||
ServerPath = these.DevApi;
|
ServerPath = these.DevApi;
|
||||||
} else if (these.Version === 'Uat') {
|
} else if (these.Version === 'Uat') {
|
||||||
ServerPath = these.UatApi;
|
ServerPath = these.UatApi;
|
||||||
} else if (these.Version === 'Relese') {
|
} else if (these.Version === 'Relese') {
|
||||||
ServerPath = these.ReleseApi;
|
ServerPath = these.ReleseApi;
|
||||||
} else {
|
} else {
|
||||||
these.DevApi
|
these.DevApi
|
||||||
}
|
}
|
||||||
url = ServerPath + url;
|
url = ServerPath + url;
|
||||||
}
|
}
|
||||||
|
|
||||||
var these = this;
|
var these = this;
|
||||||
if (!method) {
|
if (!method) {
|
||||||
method = 'POST';
|
method = 'POST';
|
||||||
}
|
}
|
||||||
method = method.toUpperCase();
|
method = method.toUpperCase();
|
||||||
|
|
||||||
if (!contentType) {
|
if (!contentType) {
|
||||||
contentType = 'application/json;charset=UTF-8';
|
contentType = 'application/json;charset=UTF-8';
|
||||||
}
|
}
|
||||||
|
|
||||||
these.checkLAN(
|
these.checkLAN(
|
||||||
|
|
||||||
function() {
|
function() {
|
||||||
these.showLoading('请稍候..', true);
|
these.showLoading('请稍候..', true);
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
uni.request({
|
uni.request({
|
||||||
url: url,
|
url: url,
|
||||||
data: data,
|
data: data,
|
||||||
header: {
|
header: {
|
||||||
"Content-Type": contentType
|
"Content-Type": contentType
|
||||||
},
|
},
|
||||||
method: method,
|
method: method,
|
||||||
timeout: 60000,
|
timeout: 60000,
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
success: function(json) {
|
success: function(json) {
|
||||||
|
|
||||||
if (succ) {
|
if (succ) {
|
||||||
succ(json);
|
succ(json);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
fail: function(ex) {
|
fail: function(ex) {
|
||||||
|
|
||||||
if (err) {
|
if (err) {
|
||||||
err(ex);
|
err(ex);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
complete: function() {
|
complete: function() {
|
||||||
|
|
||||||
if (complete) {
|
if (complete) {
|
||||||
complete();
|
complete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}, 0);
|
}, 0);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
,
|
,
|
||||||
function() {
|
function() {
|
||||||
these.showToast('无网络连接');
|
these.showToast('无网络连接');
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
checkLAN: function(succ, error) {
|
checkLAN: function(succ, error) {
|
||||||
uni.getNetworkType({
|
uni.getNetworkType({
|
||||||
success: (res) => {
|
success: (res) => {
|
||||||
let networkType = res.networkType;
|
let networkType = res.networkType;
|
||||||
|
|
||||||
|
|
||||||
// 判断网络是否连接
|
// 判断网络是否连接
|
||||||
if (networkType === 'none') {
|
if (networkType === 'none') {
|
||||||
console.error('无网络连接')
|
console.error('无网络连接')
|
||||||
if (error) {
|
if (error) {
|
||||||
error();
|
error();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (succ) {
|
if (succ) {
|
||||||
succ();
|
succ();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
fail: (err) => {
|
fail: (err) => {
|
||||||
console.error('获取网络状态失败:', err);
|
console.error('获取网络状态失败:', err);
|
||||||
if (error) {
|
if (error) {
|
||||||
error();
|
error();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
},
|
},
|
||||||
DateFormat: function(date, format) {
|
DateFormat: function(date, format) {
|
||||||
if (!date) {
|
if (!date) {
|
||||||
date = new Date();
|
date = new Date();
|
||||||
}
|
}
|
||||||
if (!format) {
|
if (!format) {
|
||||||
format = 'yyyy-MM-dd HH:mm:ss';
|
format = 'yyyy-MM-dd HH:mm:ss';
|
||||||
}
|
}
|
||||||
// 处理参数默认值
|
// 处理参数默认值
|
||||||
if (typeof date === 'string' || typeof date === 'number') {
|
if (typeof date === 'string' || typeof date === 'number') {
|
||||||
date = new Date(date);
|
date = new Date(date);
|
||||||
}
|
}
|
||||||
date = date instanceof Date ? date : new Date();
|
date = date instanceof Date ? date : new Date();
|
||||||
format = format || 'yyyy-MM-dd';
|
format = format || 'yyyy-MM-dd';
|
||||||
|
|
||||||
// 检查日期是否有效
|
// 检查日期是否有效
|
||||||
if (isNaN(date.getTime())) {
|
if (isNaN(date.getTime())) {
|
||||||
return 'Invalid Date';
|
return 'Invalid Date';
|
||||||
}
|
}
|
||||||
|
|
||||||
// 定义格式化映射
|
// 定义格式化映射
|
||||||
let formatMap = {
|
let formatMap = {
|
||||||
'yyyy': date.getFullYear(),
|
'yyyy': date.getFullYear(),
|
||||||
'MM': String(date.getMonth() + 1).padStart(2, '0'),
|
'MM': String(date.getMonth() + 1).padStart(2, '0'),
|
||||||
'dd': String(date.getDate()).padStart(2, '0'),
|
'dd': String(date.getDate()).padStart(2, '0'),
|
||||||
'HH': String(date.getHours()).padStart(2, '0'),
|
'HH': String(date.getHours()).padStart(2, '0'),
|
||||||
'mm': String(date.getMinutes()).padStart(2, '0'),
|
'mm': String(date.getMinutes()).padStart(2, '0'),
|
||||||
'ss': String(date.getSeconds()).padStart(2, '0'),
|
'ss': String(date.getSeconds()).padStart(2, '0'),
|
||||||
'SSS': String(date.getMilliseconds()).padStart(3, '0'),
|
'SSS': String(date.getMilliseconds()).padStart(3, '0'),
|
||||||
'M': date.getMonth() + 1,
|
'M': date.getMonth() + 1,
|
||||||
'd': date.getDate(),
|
'd': date.getDate(),
|
||||||
'H': date.getHours(),
|
'H': date.getHours(),
|
||||||
'm': date.getMinutes(),
|
'm': date.getMinutes(),
|
||||||
's': date.getSeconds(),
|
's': date.getSeconds(),
|
||||||
'S': date.getMilliseconds()
|
'S': date.getMilliseconds()
|
||||||
};
|
};
|
||||||
|
|
||||||
// 替换格式字符串中的占位符
|
// 替换格式字符串中的占位符
|
||||||
return format.replace(/(yyyy|MM|dd|HH|mm|ss|SSS|M|d|H|m|s|S)/g, (match) => {
|
return format.replace(/(yyyy|MM|dd|HH|mm|ss|SSS|M|d|H|m|s|S)/g, (match) => {
|
||||||
return formatMap[match];
|
return formatMap[match];
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
getdeviceShareId(id) { //获取设备分享信息
|
getdeviceShareId(id) { //获取设备分享信息
|
||||||
return request({
|
return request({
|
||||||
url: `/app/deviceShare/${id}`,
|
url: `/app/deviceShare/${id}`,
|
||||||
method: 'get',
|
method: 'get',
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
getPermissions(type) {
|
getPermissions(type) {
|
||||||
if (!type) {
|
if (!type) {
|
||||||
type = '6170';
|
type = '6170';
|
||||||
}
|
}
|
||||||
let array = [{
|
let array = [{
|
||||||
value: "1",
|
value: "1",
|
||||||
label: "灯光模式",
|
label: "灯光模式",
|
||||||
checked: false,
|
checked: false,
|
||||||
type: ['6170', '670','102','6155','650','7305','6075']
|
type: ['6170', '670','102','6155','650','7305','6075']
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: "2",
|
value: "2",
|
||||||
label: "激光模式",
|
label: "激光模式",
|
||||||
checked: false,
|
checked: false,
|
||||||
type: ['6170','6075']
|
type: ['6170','6075']
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: "3",
|
value: "3",
|
||||||
label: "开机画面",
|
label: "开机画面",
|
||||||
checked: false,
|
checked: false,
|
||||||
type: ['210', '6170', '670','6155','650','7305','6075']
|
type: ['210', '6170', '670','6155','650','7305','6075']
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: "4",
|
value: "4",
|
||||||
label: "人员信息登记",
|
label: "人员信息登记",
|
||||||
checked: false,
|
checked: false,
|
||||||
type: ['210', '6170', '670','6155','650','7305','6075']
|
type: ['210', '6170', '670','6155','650','7305','6075']
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: "5",
|
value: "5",
|
||||||
label: "发送信息",
|
label: "发送信息",
|
||||||
checked: false,
|
checked: false,
|
||||||
type: ['210', '6170', '670','6075']
|
type: ['210', '6170', '670','6075']
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: "6",
|
value: "6",
|
||||||
label: "产品信息",
|
label: "产品信息",
|
||||||
checked: false,
|
checked: false,
|
||||||
type: ['210', '6170', '670']
|
type: ['210', '6170', '670']
|
||||||
}, {
|
}, {
|
||||||
value: "41",
|
value: "41",
|
||||||
label: "静电探测",
|
label: "静电探测",
|
||||||
checked: false,
|
checked: false,
|
||||||
type: ['670','650']
|
type: ['670','650']
|
||||||
}, {
|
}, {
|
||||||
value: "42",
|
value: "42",
|
||||||
label: "SOS",
|
label: "SOS",
|
||||||
checked: false,
|
checked: false,
|
||||||
type: ['670','4877','6075']
|
type: ['670','4877','6075']
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: "43",
|
value: "43",
|
||||||
label: "联机设备",
|
label: "联机设备",
|
||||||
checked: false,
|
checked: false,
|
||||||
type: ['210']
|
type: ['210']
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: "44",
|
value: "44",
|
||||||
label: "报警声音",
|
label: "报警声音",
|
||||||
checked: false,
|
checked: false,
|
||||||
type: ['210']
|
type: ['210']
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: "45",
|
value: "45",
|
||||||
label: "自动报警",
|
label: "自动报警",
|
||||||
checked: false,
|
checked: false,
|
||||||
type: ['210']
|
type: ['210']
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: "46",
|
value: "46",
|
||||||
label: "手动报警",
|
label: "手动报警",
|
||||||
checked: false,
|
checked: false,
|
||||||
type: ['210','102']
|
type: ['210','102']
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: "47",
|
value: "47",
|
||||||
label: "报警时长",
|
label: "报警时长",
|
||||||
checked: false,
|
checked: false,
|
||||||
type: ['210']
|
type: ['210']
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: "48",
|
value: "48",
|
||||||
label: "物体感应",
|
label: "物体感应",
|
||||||
checked: false,
|
checked: false,
|
||||||
type: ['102']
|
type: ['102']
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: "49",
|
value: "49",
|
||||||
label: "联机模式",
|
label: "联机模式",
|
||||||
checked: false,
|
checked: false,
|
||||||
type: ['102']
|
type: ['102']
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
value: "50",
|
value: "50",
|
||||||
label: "报警模式",
|
label: "报警模式",
|
||||||
checked: false,
|
checked: false,
|
||||||
type: ['100','100J']
|
type: ['100','100J']
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
value: "51",
|
value: "51",
|
||||||
label: "警示灯",
|
label: "警示灯",
|
||||||
checked: false,
|
checked: false,
|
||||||
type: ['100','100J']
|
type: ['100','100J']
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
value: "52",
|
value: "52",
|
||||||
label: "语音管理",
|
label: "语音管理",
|
||||||
checked: false,
|
checked: false,
|
||||||
type: ['100','100J']
|
type: ['100','100J']
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
value: "53",
|
value: "53",
|
||||||
label: "箭头模式",
|
label: "箭头模式",
|
||||||
checked: false,
|
checked: false,
|
||||||
type: ['4877']
|
type: ['4877']
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: "54",
|
value: "54",
|
||||||
label: "配组设置",
|
label: "配组设置",
|
||||||
checked: false,
|
checked: false,
|
||||||
type: ['4877']
|
type: ['4877']
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: "55",
|
value: "55",
|
||||||
label: "修改信道",
|
label: "修改信道",
|
||||||
checked: false,
|
checked: false,
|
||||||
type: ['4877']
|
type: ['4877','102']
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: "56",
|
value: "56",
|
||||||
label: "灯光类型设置",
|
label: "灯光类型设置",
|
||||||
checked: false,
|
checked: false,
|
||||||
type: ['100J']
|
type: ['100J']
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
let arr = [];
|
let arr = [];
|
||||||
for (let i = 0; i < array.length; i++) {
|
for (let i = 0; i < array.length; i++) {
|
||||||
let item = array[i];
|
let item = array[i];
|
||||||
if (!item) {
|
if (!item) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!item.type) {
|
if (!item.type) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let typeContais = item.type.find(v => {
|
let typeContais = item.type.find(v => {
|
||||||
return v.includes(type);
|
return v.includes(type);
|
||||||
});
|
});
|
||||||
if (typeContais) {
|
if (typeContais) {
|
||||||
let json = {};
|
let json = {};
|
||||||
Object.assign(json, item);
|
Object.assign(json, item);
|
||||||
arr.push(json);
|
arr.push(json);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return arr;
|
return arr;
|
||||||
},
|
},
|
||||||
//10进制转换为16进制字符串
|
//10进制转换为16进制字符串
|
||||||
decimalToHexLittleEndian(num, byteCount, revers) {
|
decimalToHexLittleEndian(num, byteCount, revers) {
|
||||||
// 处理负数(如果需要支持负数,可先转为补码)
|
// 处理负数(如果需要支持负数,可先转为补码)
|
||||||
if (num < 0) {
|
if (num < 0) {
|
||||||
num = 0xFFFFFFFF + num + 1;
|
num = 0xFFFFFFFF + num + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 转为16进制,去除前缀0x,转为大写
|
// 转为16进制,去除前缀0x,转为大写
|
||||||
let hex = num.toString(16).toUpperCase();
|
let hex = num.toString(16).toUpperCase();
|
||||||
|
|
||||||
// 计算需要补充的0的数量,确保每个字节占2位
|
// 计算需要补充的0的数量,确保每个字节占2位
|
||||||
let padLength = (byteCount || Math.ceil(hex.length / 2) * 2) - hex.length;
|
let padLength = (byteCount || Math.ceil(hex.length / 2) * 2) - hex.length;
|
||||||
if (padLength > 0) {
|
if (padLength > 0) {
|
||||||
hex = '0'.repeat(padLength) + hex;
|
hex = '0'.repeat(padLength) + hex;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 分割为字节数组(每2位一个字节)
|
// 分割为字节数组(每2位一个字节)
|
||||||
let bytes = [];
|
let bytes = [];
|
||||||
for (let i = 0; i < hex.length; i += 2) {
|
for (let i = 0; i < hex.length; i += 2) {
|
||||||
bytes.push(hex.substr(i, 2));
|
bytes.push(hex.substr(i, 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 是否反转字节顺序(低位在前)并拼接
|
// 是否反转字节顺序(低位在前)并拼接
|
||||||
if (revers) {
|
if (revers) {
|
||||||
return bytes.reverse().join('');
|
return bytes.reverse().join('');
|
||||||
}
|
}
|
||||||
return bytes.join('');
|
return bytes.join('');
|
||||||
},
|
},
|
||||||
//将相对路径的文件移动到_downloads文件夹中
|
//将相对路径的文件移动到_downloads文件夹中
|
||||||
moveFileToDownloads(tempFilePath) {
|
moveFileToDownloads(tempFilePath) {
|
||||||
|
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
if(!tempFilePath){
|
if(!tempFilePath){
|
||||||
console.log("无文件需要移动");
|
console.log("无文件需要移动");
|
||||||
resolve(tempFilePath);
|
resolve(tempFilePath);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//本来就在此目录时直接返回
|
//本来就在此目录时直接返回
|
||||||
if (tempFilePath.indexOf("_downloads") === 0) {
|
if (tempFilePath.indexOf("_downloads") === 0) {
|
||||||
console.log("文件已存在,无需移动");
|
console.log("文件已存在,无需移动");
|
||||||
resolve(tempFilePath);
|
resolve(tempFilePath);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//不是app直接返回
|
//不是app直接返回
|
||||||
if (!uni.getSystemInfoSync().uniPlatform.includes('app')) {
|
if (!uni.getSystemInfoSync().uniPlatform.includes('app')) {
|
||||||
resolve('仅支持 App 端操作');
|
resolve('仅支持 App 端操作');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// console.log("tempFilePath=", tempFilePath);
|
// console.log("tempFilePath=", tempFilePath);
|
||||||
var srcPath = plus.io.convertLocalFileSystemURL(tempFilePath);
|
var srcPath = plus.io.convertLocalFileSystemURL(tempFilePath);
|
||||||
// console.log("srcPath=", srcPath);
|
// console.log("srcPath=", srcPath);
|
||||||
plus.io.resolveLocalFileSystemURL(srcPath,
|
plus.io.resolveLocalFileSystemURL(srcPath,
|
||||||
(fileEntry) => {
|
(fileEntry) => {
|
||||||
|
|
||||||
plus.io.requestFileSystem(plus.io.PUBLIC_DOWNLOADS, (fs) => {
|
plus.io.requestFileSystem(plus.io.PUBLIC_DOWNLOADS, (fs) => {
|
||||||
// console.log("fs=",fs.name);
|
// console.log("fs=",fs.name);
|
||||||
// console.log("fs=",fs.root.fullPath);
|
// console.log("fs=",fs.root.fullPath);
|
||||||
|
|
||||||
fileEntry.moveTo(fs.root, fileEntry.name, (entry) => {
|
fileEntry.moveTo(fs.root, fileEntry.name, (entry) => {
|
||||||
console.log("entry=", entry);
|
console.log("entry=", entry);
|
||||||
let relativePath = `_downloads/${entry.name}`;
|
let relativePath = `_downloads/${entry.name}`;
|
||||||
resolve(relativePath);
|
resolve(relativePath);
|
||||||
|
|
||||||
}, (ex) => {
|
}, (ex) => {
|
||||||
reject(ex)
|
reject(ex)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
}, (e) => {
|
}, (e) => {
|
||||||
console.error("请求download目录失败 " + e);
|
console.error("请求download目录失败 " + e);
|
||||||
reject(e);
|
reject(e);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
(error) => {
|
(error) => {
|
||||||
console.log('文件不存在/路径错误:', error.message); // 核心问题!
|
console.log('文件不存在/路径错误:', error.message); // 核心问题!
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
getOSAndUpload(){
|
getOSAndUpload(){
|
||||||
let os=uni.getSystemInfoSync().platform;
|
let os=uni.getSystemInfoSync().platform;
|
||||||
let url=''
|
let url=''
|
||||||
if(os==='ios'){
|
if(os==='ios'){
|
||||||
url='https://apps.apple.com/cn/app/星汉物联/id6752555460'
|
url='https://apps.apple.com/cn/app/星汉物联/id6752555460'
|
||||||
}
|
}
|
||||||
|
|
||||||
else if(os==='android'){
|
else if(os==='android'){
|
||||||
url='https://www.pgyer.com/xhwl';
|
url='https://www.pgyer.com/xhwl';
|
||||||
}
|
}
|
||||||
return {os:os,url:url};
|
return {os:os,url:url};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
//将点阵数据转换成RGB565
|
//将点阵数据转换成RGB565
|
||||||
convertToRGB565(pixels, type) {
|
convertToRGB565(pixels, type) {
|
||||||
if (!type) {
|
if (!type) {
|
||||||
type = 'rgb';
|
type = 'rgb';
|
||||||
}
|
}
|
||||||
const result = new Uint16Array(pixels.length / 4);
|
const result = new Uint16Array(pixels.length / 4);
|
||||||
let index = 0;
|
let index = 0;
|
||||||
for (let i = 0; i < pixels.length; i += 4) {
|
for (let i = 0; i < pixels.length; i += 4) {
|
||||||
let r = pixels[i];
|
let r = pixels[i];
|
||||||
let g = pixels[i + 1];
|
let g = pixels[i + 1];
|
||||||
let b = pixels[i + 2];
|
let b = pixels[i + 2];
|
||||||
let a = pixels[i + 3];
|
let a = pixels[i + 3];
|
||||||
|
|
||||||
if (type == 'bgr') {
|
if (type == 'bgr') {
|
||||||
result[index++] = ((b & 0xF8) << 8) | ((g & 0xFC) << 3) | (r >> 3);
|
result[index++] = ((b & 0xF8) << 8) | ((g & 0xFC) << 3) | (r >> 3);
|
||||||
} else {
|
} else {
|
||||||
result[index++] = ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | (b >> 3);
|
result[index++] = ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | (b >> 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user