Compare commits
15 Commits
e042436c5b
...
90cee62df1
| Author | SHA1 | Date | |
|---|---|---|---|
| 90cee62df1 | |||
| b114f6690d | |||
| 0ce4f4bef0 | |||
| fe87727e2d | |||
| 8689781e17 | |||
| e3a2624509 | |||
| 4c3999251e | |||
| f629a08385 | |||
| 4f3a8bb3ec | |||
| 7c2e68bca2 | |||
| c556b802e4 | |||
| d9e45becff | |||
| fd3a046ab3 | |||
| 195b9df67c | |||
| 3ac113de3f |
36
App.vue
@ -17,28 +17,35 @@
|
|||||||
// if(currTime>=time){
|
// if(currTime>=time){
|
||||||
// uni.removeStorageSync(val);
|
// uni.removeStorageSync(val);
|
||||||
// uni.removeStorageSync("token");
|
// uni.removeStorageSync("token");
|
||||||
// uni.removeStorageSync("clientID");
|
// uni.removeStorageSync("clientID");
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
// else if(val=="token" || val=="clientID"){
|
// else if(val=="token" || val=="clientID" || val=='phone'){
|
||||||
// console.log("忽略登陆信息");
|
// console.log("忽略登陆信息");
|
||||||
// }else{
|
// }else{
|
||||||
// uni.removeStorageSync(val);
|
// uni.removeStorageSync(val);
|
||||||
// }
|
// }
|
||||||
// });
|
// });
|
||||||
|
// uni.clearStorageSync();
|
||||||
//以上代码仅在开发时使用,否则会出现不可预知的问题。
|
//以上代码仅在开发时使用,否则会出现不可预知的问题。
|
||||||
|
|
||||||
uni.getSystemInfo({success:function(res){
|
|
||||||
if(res.uniPlatform=='app'){
|
|
||||||
bleTool.getBleTool();
|
|
||||||
upgrade.checkAndUpdateWgt();
|
|
||||||
|
|
||||||
}
|
|
||||||
}});
|
|
||||||
},
|
},
|
||||||
onShow: function() {
|
onShow: function() {
|
||||||
console.log('App Show');
|
console.log('App Show');
|
||||||
|
//将检查更新换到onshow,因为苹果用户喜欢一直挂着
|
||||||
|
uni.getSystemInfo({success:function(res){
|
||||||
|
if(res.uniPlatform=='app'){
|
||||||
|
let appid=plus.runtime.appid;
|
||||||
|
if(appid!=='HBuilder'){
|
||||||
|
console.log("appid=",appid);
|
||||||
|
bleTool.getBleTool();
|
||||||
|
upgrade.checkAndUpdateWgt();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}});
|
||||||
},
|
},
|
||||||
onHide: function() {
|
onHide: function() {
|
||||||
console.log('App Hide');
|
console.log('App Hide');
|
||||||
@ -91,6 +98,15 @@
|
|||||||
background: rgba(42, 42, 42, 1);
|
background: rgba(42, 42, 42, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.green{
|
||||||
|
color: #BBE600 !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.red{
|
||||||
|
color:#E03434 !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@font-face {
|
@font-face {
|
||||||
font-family: "PingFang SC";
|
font-family: "PingFang SC";
|
||||||
src: url("~@/static/fonts/PingFangSC.ttf") format("opentype");
|
src: url("~@/static/fonts/PingFangSC.ttf") format("opentype");
|
||||||
|
|||||||
@ -17,6 +17,7 @@
|
|||||||
:style="{color:textColor || getTypeStyle('textColor')}"
|
:style="{color:textColor || getTypeStyle('textColor')}"
|
||||||
@click="closeClick"
|
@click="closeClick"
|
||||||
>x</view>
|
>x</view>
|
||||||
|
|
||||||
<view v-if="!visiblePrompt">
|
<view v-if="!visiblePrompt">
|
||||||
<image
|
<image
|
||||||
v-if="iconUrl"
|
v-if="iconUrl"
|
||||||
@ -25,7 +26,10 @@
|
|||||||
class="popup-icon"
|
class="popup-icon"
|
||||||
:style="{ tintColor: textColor || getTypeStyle('textColor') }"
|
:style="{ tintColor: textColor || getTypeStyle('textColor') }"
|
||||||
></image>
|
></image>
|
||||||
<view class="popup-message">{{ message }}</view>
|
<view class="popup-message" :class="showSlot?'displayNone':''">{{ message }}</view>
|
||||||
|
<view class="popup-message" :class="showSlot?'':'displayNone'">
|
||||||
|
<slot></slot>
|
||||||
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
|
|
||||||
@ -40,16 +44,18 @@
|
|||||||
/>
|
/>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<view class="popBtnContent">
|
<view class="popBtnContent" v-show="showCancel || buttonText">
|
||||||
|
|
||||||
<view
|
<view
|
||||||
class="popup-button-cancel"
|
class="popup-button-cancel"
|
||||||
|
|
||||||
:style="{display:showCancel?'block':'none'}"
|
:style="{display:showCancel?'block':'none'}"
|
||||||
@click="handleCancelClick"
|
@click="handleCancelClick"
|
||||||
>{{ buttonCancelText?buttonCancelText:'取消' }}</view>
|
>{{ buttonCancelText?buttonCancelText:'取消' }}</view>
|
||||||
|
|
||||||
<view
|
<view
|
||||||
class="popup-button"
|
class="popup-button"
|
||||||
|
:class="buttonText?'':'displayNone'"
|
||||||
:style="{
|
:style="{
|
||||||
backgroundColor: buttonBgColor || getTypeStyle('buttonBgColor'),
|
backgroundColor: buttonBgColor || getTypeStyle('buttonBgColor'),
|
||||||
color: buttonTextColor || getTypeStyle('buttonTextColor')
|
color: buttonTextColor || getTypeStyle('buttonTextColor')
|
||||||
@ -125,6 +131,10 @@ export default {
|
|||||||
headerTxt:{
|
headerTxt:{
|
||||||
type:String,
|
type:String,
|
||||||
default:""
|
default:""
|
||||||
|
},
|
||||||
|
showSlot:{
|
||||||
|
type:Boolean,
|
||||||
|
default:false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
@ -202,6 +212,9 @@ export default {
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
.displayNone{
|
||||||
|
display: none !important
|
||||||
|
}
|
||||||
.message-popup {
|
.message-popup {
|
||||||
position: fixed;
|
position: fixed;
|
||||||
top: 0;
|
top: 0;
|
||||||
|
|||||||
231
components/TextToHex/textToDotMatrix.vue
Normal file
@ -0,0 +1,231 @@
|
|||||||
|
<template>
|
||||||
|
<view>
|
||||||
|
<canvas type="2d" canvas-id="reusableCanvas" :width="currentCanvasWidth" :height="currentCanvasHeight"
|
||||||
|
class="offscreen-canvas"></canvas>
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
name: "textToDotMatrix",
|
||||||
|
props: {
|
||||||
|
txts: {
|
||||||
|
type: Array,
|
||||||
|
default: () => [],
|
||||||
|
validator: (value) => value.every(item => typeof item === 'string')
|
||||||
|
},
|
||||||
|
fontSize: {
|
||||||
|
type: Number,
|
||||||
|
default: 16,
|
||||||
|
validator: (value) => value > 0 && value <= 100
|
||||||
|
},
|
||||||
|
bgColor: {
|
||||||
|
type: String,
|
||||||
|
default: "#ffffff"
|
||||||
|
},
|
||||||
|
color: {
|
||||||
|
type: String,
|
||||||
|
default: "#000000"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
// 当前Canvas的宽高(动态调整)
|
||||||
|
currentCanvasWidth: 0,
|
||||||
|
currentCanvasHeight: 0,
|
||||||
|
// Canvas上下文(复用)
|
||||||
|
ctx: null
|
||||||
|
};
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
validTxts() {
|
||||||
|
return this.txts.filter(line => line.trim() !== '');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
mounted() {
|
||||||
|
// 初始化Canvas上下文(只创建一次)
|
||||||
|
this.ctx = uni.createCanvasContext('reusableCanvas', this);
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
/**
|
||||||
|
* 估算单行文本所需的Canvas宽度
|
||||||
|
*/
|
||||||
|
calcLineWidth(textLine) {
|
||||||
|
return textLine.length * 16;
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 清除Canvas内容
|
||||||
|
*/
|
||||||
|
clearCanvas() {
|
||||||
|
this.ctx.setFillStyle(this.bgColor);
|
||||||
|
this.ctx.fillRect(0, 0, this.currentCanvasWidth, this.currentCanvasHeight);
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 复用单个Canvas处理所有文本行
|
||||||
|
*/
|
||||||
|
async drawAndGetPixels() {
|
||||||
|
let binaryToHex = (binaryArray) => {
|
||||||
|
if (!Array.isArray(binaryArray) || binaryArray.length !== 8) {
|
||||||
|
throw new Error("输入必须是包含8个元素的二进制数组");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查每个元素是否为0或1
|
||||||
|
if (!binaryArray.every(bit => bit === 0 || bit === 1)) {
|
||||||
|
throw new Error("数组元素必须只能是0或1");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 将二进制数组转换为十进制数
|
||||||
|
let decimalValue = 0;
|
||||||
|
for (let i = 0; i < 8; i++) {
|
||||||
|
// 计算每个位的权重并累加
|
||||||
|
decimalValue += binaryArray[i] * Math.pow(2, 7 - i);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 将十进制转换为十六进制字符串,并添加0x前缀
|
||||||
|
const hexString = "0x" + decimalValue.toString(16).padStart(2, '0').toUpperCase();
|
||||||
|
|
||||||
|
return hexString;
|
||||||
|
}
|
||||||
|
|
||||||
|
let convertCharToMatrix = (imageData, item) => {
|
||||||
|
// console.log("imgOldData=", imageData)
|
||||||
|
let matrix = [];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
let arr = [];
|
||||||
|
for (let y = 0; y < 16; y++) {
|
||||||
|
for (let x = 0; x < 16; x++) {
|
||||||
|
// 计算像素在imageData中的索引 (RGBA格式)
|
||||||
|
let index = (y * 16 + x) * 4;
|
||||||
|
let red = imageData[index];
|
||||||
|
|
||||||
|
// 黑色像素(R值较低)视为1,白色视为0
|
||||||
|
let isBlack = red < 128 ? 1 : 0;
|
||||||
|
arr.push(isBlack);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let firstHalf = arr.slice(0, arr.length / 2); // [1, 2, ..., 128]
|
||||||
|
let secondHalf = arr.slice(arr.length / 2); // [129, 130, ..., 256]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
for (let i = 0; i < 16; i++) {
|
||||||
|
let tmp = [];
|
||||||
|
for (let index = i; index < firstHalf.length; index += 16) {
|
||||||
|
tmp.push(firstHalf[index]);
|
||||||
|
}
|
||||||
|
tmp = tmp.reverse();
|
||||||
|
|
||||||
|
matrix.push(binaryToHex(tmp));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let i = 0; i < 16; i++) {
|
||||||
|
let tmp = [];
|
||||||
|
for (let index = i; index < secondHalf.length; index += 16) {
|
||||||
|
tmp.push(secondHalf[index]);
|
||||||
|
}
|
||||||
|
tmp = tmp.reverse();
|
||||||
|
|
||||||
|
matrix.push(binaryToHex(tmp));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
console.log("matrix=", matrix);
|
||||||
|
return matrix;
|
||||||
|
}
|
||||||
|
|
||||||
|
let drawTxt = async (textLine) => {
|
||||||
|
let result = {};
|
||||||
|
let ctx = this.ctx;
|
||||||
|
|
||||||
|
// 1. 动态调整Canvas尺寸
|
||||||
|
this.currentCanvasWidth = this.calcLineWidth(textLine);
|
||||||
|
this.currentCanvasHeight = 16;
|
||||||
|
|
||||||
|
// 2. 清空Canvas(绘制背景)
|
||||||
|
this.clearCanvas();
|
||||||
|
|
||||||
|
// 3. 设置文字样式
|
||||||
|
ctx.setFillStyle(this.color);
|
||||||
|
ctx.setTextBaseline('middle');
|
||||||
|
// ctx.setTextAlign('center')
|
||||||
|
ctx.setFontSize(this.fontSize);
|
||||||
|
ctx.font = `${this.fontSize}px "PingFangBold", "PingFang SC", Arial, sans-serif`;
|
||||||
|
|
||||||
|
// 4. 绘制当前行文本
|
||||||
|
let currentX = 0;
|
||||||
|
let currentY = this.fontSize / 2;
|
||||||
|
for (let j = 0; j < textLine.length; j++) {
|
||||||
|
let char = textLine[j];
|
||||||
|
ctx.fillText(char, currentX, currentY);
|
||||||
|
// 按实际字符宽度计算间距
|
||||||
|
let charWidth = ctx.measureText(char).width;
|
||||||
|
currentX += charWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 5. 异步绘制并获取像素数据(串行处理避免冲突)
|
||||||
|
await new Promise((resolve, reject) => {
|
||||||
|
ctx.draw(false, () => {
|
||||||
|
uni.canvasGetImageData({
|
||||||
|
canvasId: 'reusableCanvas',
|
||||||
|
x: 0,
|
||||||
|
y: 0,
|
||||||
|
width: this.currentCanvasWidth,
|
||||||
|
height: this.currentCanvasHeight,
|
||||||
|
success: res => {
|
||||||
|
|
||||||
|
result = {
|
||||||
|
line: textLine,
|
||||||
|
pixelData: res.data,
|
||||||
|
width: this.currentCanvasWidth,
|
||||||
|
height: this.currentCanvasHeight
|
||||||
|
};
|
||||||
|
resolve();
|
||||||
|
},
|
||||||
|
fail: err => {
|
||||||
|
// console.error(`处理第${i+1}行失败:`, err);
|
||||||
|
reject(err)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
let arr = [];
|
||||||
|
// 循环处理每行文本
|
||||||
|
for (let i = 0; i < this.validTxts.length; i++) {
|
||||||
|
|
||||||
|
let linePixls = [];
|
||||||
|
let item = this.validTxts[i];
|
||||||
|
console.log("item=", item);
|
||||||
|
for (var j = 0; j < item.length; j++) {
|
||||||
|
let result = await drawTxt(item[j]);
|
||||||
|
linePixls.push(convertCharToMatrix(result.pixelData, item));
|
||||||
|
}
|
||||||
|
console.log("hexs=", linePixls.join(","));
|
||||||
|
arr.push(linePixls);
|
||||||
|
}
|
||||||
|
|
||||||
|
return arr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.offscreen-canvas {
|
||||||
|
position: fixed;
|
||||||
|
left: -9999px;
|
||||||
|
top: -9999px;
|
||||||
|
visibility: hidden;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@ -5,18 +5,18 @@ const config = {
|
|||||||
BASE_URL: 'http://192.168.110.56:8000',
|
BASE_URL: 'http://192.168.110.56:8000',
|
||||||
API_PREFIX: '',
|
API_PREFIX: '',
|
||||||
// MQTT 配置
|
// MQTT 配置
|
||||||
MQTT_HOST: '47.120.79.150',
|
MQTT_HOST: 'www.cnxhyc.com',
|
||||||
MQTT_PORT: 8083,
|
MQTT_PORT: 8083,
|
||||||
MQTT_USERNAME: 'admin',
|
MQTT_USERNAME: 'admin',
|
||||||
MQTT_PASSWORD: '#YtvpSfCNG'
|
MQTT_PASSWORD: '#YtvpSfCNG'
|
||||||
},
|
},
|
||||||
// 生产环境
|
// 生产环境
|
||||||
production: {
|
production: {
|
||||||
BASE_URL: 'https://fuyuanshen.com/backend',
|
BASE_URL: 'https://www.cnxhyc.com/jq',
|
||||||
API_PREFIX: '',
|
API_PREFIX: '',
|
||||||
// MQTT 配置
|
// MQTT 配置
|
||||||
MQTT_HOST: 'www.cnxhyc.com',
|
MQTT_HOST: 'www.cnxhyc.com',
|
||||||
MQTT_PORT: 8083,
|
MQTT_PORT: 9084,
|
||||||
MQTT_USERNAME: 'admin',
|
MQTT_USERNAME: 'admin',
|
||||||
MQTT_PASSWORD: '#YtvpSfCNG'
|
MQTT_PASSWORD: '#YtvpSfCNG'
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
"name" : "星汉物联",
|
"name" : "星汉物联",
|
||||||
"appid" : "__UNI__A21EF43",
|
"appid" : "__UNI__A21EF43",
|
||||||
"description" : "设备管控",
|
"description" : "设备管控",
|
||||||
"versionName" : "1.0.0",
|
"versionName" : "1.0.3",
|
||||||
"versionCode" : "100",
|
"versionCode" : "100",
|
||||||
"transformPx" : false,
|
"transformPx" : false,
|
||||||
/* 5+App特有相关 */
|
/* 5+App特有相关 */
|
||||||
@ -60,11 +60,13 @@
|
|||||||
"ios" : {
|
"ios" : {
|
||||||
"dSYMs" : false,
|
"dSYMs" : false,
|
||||||
"privacyDescription" : {
|
"privacyDescription" : {
|
||||||
"NSLocationWhenInUseUsageDescription" : "App需要您的同意,才能在使用期间访问位置",
|
"NSLocationWhenInUseUsageDescription" : "App需要您的同意,访问位置,用于判定装备位置是否异常",
|
||||||
"NSLocationAlwaysUsageDescription" : "App需要您的同意,才能始终访问位置",
|
"NSLocationAlwaysUsageDescription" : "App需要您的同意,访问位置,用于判定装备位置是否异常",
|
||||||
"NSLocationAlwaysAndWhenInUseUsageDescription" : "App需要您的同意,才能始终访问位置",
|
"NSLocationAlwaysAndWhenInUseUsageDescription" : "App需要您的同意,访问位置,用于判定装备位置是否异常",
|
||||||
"NSBluetoothPeripheralUsageDescription" : "需要蓝牙访问权限,用于设备通信",
|
"NSBluetoothPeripheralUsageDescription" : "App需要您的同意访问蓝牙访问权限,用于设备通信与反向控制",
|
||||||
"NSBluetoothAlwaysUsageDescription" : "需要蓝牙访问权限,用于设备通信"
|
"NSBluetoothAlwaysUsageDescription" : "App需要您的同意访问蓝牙访问权限,用于设备通信与反向控制",
|
||||||
|
"NSPhotoLibraryUsageDescription" : "App需要您的同意访问相册,用于上传头像,设备开机画面",
|
||||||
|
"NSPhotoLibraryAddUsageDescription" : "App需要您的同意访问相册,用于上传头像,设备开机画面"
|
||||||
},
|
},
|
||||||
"idfa" : false
|
"idfa" : false
|
||||||
},
|
},
|
||||||
@ -84,7 +86,8 @@
|
|||||||
"appkey_ios" : "065c43f02c7b627a74ad7dd23b16bb4f",
|
"appkey_ios" : "065c43f02c7b627a74ad7dd23b16bb4f",
|
||||||
"appkey_android" : "d7d852dbda2b95f6f796fb9a711a9fee"
|
"appkey_android" : "d7d852dbda2b95f6f796fb9a711a9fee"
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
"push" : {}
|
||||||
},
|
},
|
||||||
"icons" : {
|
"icons" : {
|
||||||
"android" : {
|
"android" : {
|
||||||
|
|||||||
14
pages.json
@ -250,6 +250,20 @@
|
|||||||
"style": {
|
"style": {
|
||||||
"navigationBarTitleText": "BJQ7305"
|
"navigationBarTitleText": "BJQ7305"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path" : "pages/6331/BJQ6331",
|
||||||
|
"style" :
|
||||||
|
{
|
||||||
|
"navigationBarTitleText" : "BJQ6331"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path" : "pages/6331/AudioManager",
|
||||||
|
"style" :
|
||||||
|
{
|
||||||
|
"navigationBarTitleText" : "语音管理"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,9 +1,9 @@
|
|||||||
<template>
|
<template>
|
||||||
<view>
|
<view>
|
||||||
<canvas id="splashCanvas" canvas-id="splashCanvas" style="width: 160px; height: 80px; z-index: 9999;position: fixed; visibility: hidden;"></canvas>
|
<canvas id="splashCanvas" canvas-id="splashCanvas" :style="{'width':width+'px','height':height+'px'}" style=" z-index: 9999;position: fixed; visibility: hidden;"></canvas>
|
||||||
|
|
||||||
|
|
||||||
<qf-image-cropper :src="src" :showAngle="false" :width="1600" :height="800" fileType="jpg"
|
<qf-image-cropper :src="src" :showAngle="false" :width="cropWidth" :height="cropHeight" fileType="jpg"
|
||||||
@crop="handleCrop" :gpu="true">
|
@crop="handleCrop" :gpu="true">
|
||||||
</qf-image-cropper>
|
</qf-image-cropper>
|
||||||
</view>
|
</view>
|
||||||
@ -18,17 +18,30 @@
|
|||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
src: "",
|
src: "",
|
||||||
Statu: false
|
Statu: false,
|
||||||
|
width:160,
|
||||||
|
height:80,
|
||||||
|
times:10
|
||||||
|
}
|
||||||
|
},
|
||||||
|
computed:{
|
||||||
|
cropWidth(){
|
||||||
|
return this.width*this.times;
|
||||||
|
}
|
||||||
|
,
|
||||||
|
cropHeight(){
|
||||||
|
return this.height*this.times;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onLoad: function(option) {
|
onLoad: function(option) {
|
||||||
const eventChannel = this.getOpenerEventChannel();
|
const eventChannel = this.getOpenerEventChannel();
|
||||||
var these = this;
|
var these = this;
|
||||||
eventChannel.on('checkImg', (data)=> {
|
eventChannel.on('checkImg', (rec)=> {
|
||||||
console.log("我收到你的消息了,消息内容是:" + JSON.stringify(data));
|
console.log("我收到你的消息了,消息内容是:" + JSON.stringify(rec));
|
||||||
this.src = data.data;
|
this.src = rec.data;
|
||||||
console.log("我收到你的消息了,消息内容是:",data);
|
this.width=rec.width?rec.width:160;
|
||||||
|
this.height=rec.height?rec.height:80;
|
||||||
|
this.times=rec.times?rec.times:10;
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
@ -43,7 +56,7 @@
|
|||||||
const ctx = uni.createCanvasContext('splashCanvas', this);
|
const ctx = uni.createCanvasContext('splashCanvas', this);
|
||||||
ctx.drawImage(
|
ctx.drawImage(
|
||||||
e.tempFilePath,
|
e.tempFilePath,
|
||||||
0,0,160,80
|
0,0,these.width,these.height
|
||||||
);
|
);
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
ctx.draw(false, ()=>{
|
ctx.draw(false, ()=>{
|
||||||
@ -52,8 +65,8 @@
|
|||||||
canvasId: 'splashCanvas',
|
canvasId: 'splashCanvas',
|
||||||
x: 0,
|
x: 0,
|
||||||
y: 0,
|
y: 0,
|
||||||
width: 160,
|
width: these.width,
|
||||||
height: 80,
|
height: these.height,
|
||||||
success: (res) => {
|
success: (res) => {
|
||||||
// 处理像素数据并发送
|
// 处理像素数据并发送
|
||||||
|
|
||||||
@ -81,8 +94,7 @@
|
|||||||
|
|
||||||
<style>
|
<style>
|
||||||
.canvas {
|
.canvas {
|
||||||
width: 1600px;
|
|
||||||
height: 800px;
|
|
||||||
border: 1px solid #ccc;
|
border: 1px solid #ccc;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
@ -1,7 +1,7 @@
|
|||||||
<template>
|
<template>
|
||||||
<view class="content contentBg">
|
<view class="content contentBg">
|
||||||
<view class="eq">
|
<view class="eq">
|
||||||
<view class="leftImg">
|
<view class="leftImg" @click.stop="previewImg(formData.img)">
|
||||||
<image class="img" :src="formData.img" mode="aspectFit"></image>
|
<image class="img" :src="formData.img" mode="aspectFit"></image>
|
||||||
</view>
|
</view>
|
||||||
<view class="rightTxt">
|
<view class="rightTxt">
|
||||||
@ -34,6 +34,10 @@
|
|||||||
<text class="lbl">充电状态</text>
|
<text class="lbl">充电状态</text>
|
||||||
<text class="value">{{formData.statu}}</text>
|
<text class="value">{{formData.statu}}</text>
|
||||||
</view>
|
</view>
|
||||||
|
<view class="item">
|
||||||
|
<text class="lbl">蓝牙状态</text>
|
||||||
|
<text class="value" :class="formData.bleStatu?'green':'red'">{{formData.bleStatu?'已连接':'未连接'}}</text>
|
||||||
|
</view>
|
||||||
</view>
|
</view>
|
||||||
<view class="lamp">
|
<view class="lamp">
|
||||||
<view class="title">
|
<view class="title">
|
||||||
@ -124,8 +128,8 @@
|
|||||||
:borderColor="Status.Pop.borderColor" :textColor="Status.Pop.textColor"
|
:borderColor="Status.Pop.borderColor" :textColor="Status.Pop.textColor"
|
||||||
:buttonBgColor="Status.Pop.buttonBgColor" :buttonTextColor="Status.Pop.buttonTextColor"
|
:buttonBgColor="Status.Pop.buttonBgColor" :buttonTextColor="Status.Pop.buttonTextColor"
|
||||||
: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" @closePop="closePop" :visiblePrompt="Status.Pop.visiblePrompt" :promptTitle="Status.Pop.promptTitle"
|
@buttonClick="HidePop" @closePop="closePop" :visiblePrompt="Status.Pop.visiblePrompt"
|
||||||
v-model="Status.Pop.modelValue" />
|
:promptTitle="Status.Pop.promptTitle" v-model="Status.Pop.modelValue" />
|
||||||
|
|
||||||
<!-- 下方菜单 -->
|
<!-- 下方菜单 -->
|
||||||
<BottomSlideMenuPlus :config="Status.BottomMenu" @close="closeMenu" @itemClick="handleItemClick"
|
<BottomSlideMenuPlus :config="Status.BottomMenu" @close="closeMenu" @itemClick="handleItemClick"
|
||||||
@ -152,7 +156,7 @@
|
|||||||
updateLoading
|
updateLoading
|
||||||
} from '@/utils/loading.js'
|
} from '@/utils/loading.js'
|
||||||
import BleReceive from '@/utils/BleReceive';
|
import BleReceive from '@/utils/BleReceive';
|
||||||
|
var pagePath = "pages/6155/HBY6155";
|
||||||
|
|
||||||
var ble = null;
|
var ble = null;
|
||||||
var these = null;
|
var these = null;
|
||||||
@ -166,6 +170,7 @@
|
|||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
Status: {
|
Status: {
|
||||||
|
pageHide: false,
|
||||||
Pop: {
|
Pop: {
|
||||||
showPop: false, //是否显示弹窗
|
showPop: false, //是否显示弹窗
|
||||||
popType: 'custom',
|
popType: 'custom',
|
||||||
@ -182,7 +187,7 @@
|
|||||||
promptTitle: '设备名称',
|
promptTitle: '设备名称',
|
||||||
modelValue: '',
|
modelValue: '',
|
||||||
visibleClose: false,
|
visibleClose: false,
|
||||||
okCallback:null
|
okCallback: null
|
||||||
},
|
},
|
||||||
BottomMenu: {
|
BottomMenu: {
|
||||||
show: false,
|
show: false,
|
||||||
@ -232,7 +237,8 @@
|
|||||||
id: '',
|
id: '',
|
||||||
deviceId: '',
|
deviceId: '',
|
||||||
textLines: ['', '', ''],
|
textLines: ['', '', ''],
|
||||||
mode: ''
|
mode: '',
|
||||||
|
bleStatu: ''
|
||||||
},
|
},
|
||||||
inteval: 200,
|
inteval: 200,
|
||||||
device: {
|
device: {
|
||||||
@ -258,7 +264,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
onUnload() {
|
onUnload() {
|
||||||
ble.removeReceiveCallback(this);
|
ble.removeAllCallback(pagePath);
|
||||||
},
|
},
|
||||||
onLoad: function() {
|
onLoad: function() {
|
||||||
these = this;
|
these = this;
|
||||||
@ -310,7 +316,12 @@
|
|||||||
// link();
|
// link();
|
||||||
// }
|
// }
|
||||||
console.log("6155");
|
console.log("6155");
|
||||||
ble.addReceiveCallback(these.bleValueNotify);
|
ble.addReceiveCallback(these.bleValueNotify, pagePath);
|
||||||
|
ble.addStateBreakCallback(these.bleStateBreak, pagePath);
|
||||||
|
ble.addStateRecoveryCallback(these.bleStateRecovry, pagePath);
|
||||||
|
ble.addDisposeCallback(these.deviceDispose, pagePath);
|
||||||
|
ble.addRecoveryCallback(these.deviceRecovry, pagePath);
|
||||||
|
|
||||||
let eventChannel = this.getOpenerEventChannel();
|
let eventChannel = this.getOpenerEventChannel();
|
||||||
|
|
||||||
eventChannel.on('detailData', function(data) {
|
eventChannel.on('detailData', function(data) {
|
||||||
@ -346,7 +357,9 @@
|
|||||||
these.formData.img = device.devicePic;
|
these.formData.img = device.devicePic;
|
||||||
these.formData.id = device.id;
|
these.formData.id = device.id;
|
||||||
these.formData.deviceId = f.deviceId;
|
these.formData.deviceId = f.deviceId;
|
||||||
ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId);
|
ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId).then(res => {
|
||||||
|
these.formData.bleStatu = true;
|
||||||
|
});
|
||||||
these.setBleFormData();
|
these.setBleFormData();
|
||||||
these.getDetail();
|
these.getDetail();
|
||||||
|
|
||||||
@ -355,7 +368,10 @@
|
|||||||
|
|
||||||
},
|
},
|
||||||
onHide: function() {
|
onHide: function() {
|
||||||
|
this.Status.pageHide = true;
|
||||||
|
},
|
||||||
|
onShow() {
|
||||||
|
this.Status.pageHide = false;
|
||||||
},
|
},
|
||||||
onBackPress(e) {
|
onBackPress(e) {
|
||||||
|
|
||||||
@ -410,6 +426,85 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
deviceRecovry(res) {
|
||||||
|
if (this.Status.pageHide) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (res.deviceId == these.formData.deviceId) {
|
||||||
|
this.formData.bleStatu = true;
|
||||||
|
setTimeout(() => {
|
||||||
|
hideLoading(these, 1000);
|
||||||
|
});
|
||||||
|
uni.showToast({
|
||||||
|
icon: 'success',
|
||||||
|
title: '蓝牙连接成功'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
},
|
||||||
|
deviceDispose(res) {
|
||||||
|
if (this.Status.pageHide) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (res.deviceId == these.formData.deviceId) {
|
||||||
|
this.formData.bleStatu = false;
|
||||||
|
setTimeout(() => {
|
||||||
|
hideLoading(these, 1000);
|
||||||
|
});
|
||||||
|
uni.showToast({
|
||||||
|
icon: 'fail',
|
||||||
|
title: '蓝牙连接已断开'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
},
|
||||||
|
bleStateBreak() {
|
||||||
|
if (this.Status.pageHide) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//蓝牙适配器不可用
|
||||||
|
this.formData.bleStatu = false;
|
||||||
|
uni.showToast({
|
||||||
|
icon: 'fail',
|
||||||
|
title: '蓝牙已不可用'
|
||||||
|
})
|
||||||
|
hideLoading(this);
|
||||||
|
},
|
||||||
|
bleStateRecovry() {
|
||||||
|
console.log("蓝牙可用");
|
||||||
|
if (this.Status.pageHide) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
console.log("蓝牙可用");
|
||||||
|
//蓝牙适配器再次可用,尝试恢复连接
|
||||||
|
showLoading(this, {
|
||||||
|
text: "蓝牙恢复可用,正在连接设备"
|
||||||
|
});
|
||||||
|
ble.LinkBlue(these.formData.deviceId).then(() => {
|
||||||
|
these.formData.bleStatu = true;
|
||||||
|
updateLoading(these, {
|
||||||
|
text: '连接成功'
|
||||||
|
});
|
||||||
|
}).catch(ex => {
|
||||||
|
updateLoading(these, {
|
||||||
|
text: ex.msg
|
||||||
|
})
|
||||||
|
}).finally(() => {
|
||||||
|
setTimeout(() => {
|
||||||
|
hideLoading(these);
|
||||||
|
}, 1000);
|
||||||
|
|
||||||
|
});
|
||||||
|
},
|
||||||
|
previewImg(img) {
|
||||||
|
if (!img) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
uni.previewImage({
|
||||||
|
urls: [img]
|
||||||
|
})
|
||||||
|
},
|
||||||
getDevice: function() {
|
getDevice: function() {
|
||||||
// console.log("LinkedList=", ble.data.LinkedList);
|
// console.log("LinkedList=", ble.data.LinkedList);
|
||||||
// console.log("formData=", these.formData);
|
// console.log("formData=", these.formData);
|
||||||
@ -420,89 +515,28 @@
|
|||||||
return f;
|
return f;
|
||||||
},
|
},
|
||||||
bleValueNotify: function(receive, device, path) {
|
bleValueNotify: function(receive, device, path) {
|
||||||
|
if (this.Status.pageHide) {
|
||||||
let str = recei.ReceiveData(receive, device, path);
|
return;
|
||||||
|
|
||||||
console.log("处理接收到的数据:" + str);
|
|
||||||
return;
|
|
||||||
let data = recei.ReceiveData(receive, device, path);
|
|
||||||
let bytes = receive.bytes;
|
|
||||||
|
|
||||||
if (bytes[0] == 0xFB && bytes[1] == 0x64 && bytes.length >= 8) {
|
|
||||||
try {
|
|
||||||
|
|
||||||
let staticLevelByte = bytes[2];
|
|
||||||
let getName = function(type) {
|
|
||||||
let name = "";
|
|
||||||
switch (type) {
|
|
||||||
case 0x02:
|
|
||||||
name = '弱光';
|
|
||||||
break;
|
|
||||||
case 0x04:
|
|
||||||
name = '工作光';
|
|
||||||
break;
|
|
||||||
case 0x01:
|
|
||||||
name = '强光';
|
|
||||||
break;
|
|
||||||
case 0x03:
|
|
||||||
name = '爆闪';
|
|
||||||
break;
|
|
||||||
case 0x00:
|
|
||||||
name = '关闭';
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
let staticLevelText = getName(staticLevelByte);
|
|
||||||
|
|
||||||
// 解析照明档位
|
|
||||||
let lightingLevelByte = bytes[3];
|
|
||||||
let lightingLevelText = getName(lightingLevelByte);
|
|
||||||
|
|
||||||
|
|
||||||
// 解析剩余电量
|
|
||||||
let batteryLevelByte = bytes[4];
|
|
||||||
// 电量百分比范围检查
|
|
||||||
let batteryLevel = Math.max(0, Math.min(100, batteryLevelByte));
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//充电状态
|
|
||||||
let warn = bytes[5];
|
|
||||||
if (warn == 0x00) {
|
|
||||||
warn = '未充电';
|
|
||||||
} else if (warn == 0x01) {
|
|
||||||
warn = '充电中';
|
|
||||||
}
|
|
||||||
|
|
||||||
// 解析剩余照明时间(第三和第四字节,小端序)
|
|
||||||
let lightingTime = "";
|
|
||||||
let HH = Math.max(0, Math.min(100, bytes[6]));
|
|
||||||
let mm = Math.max(0, Math.min(100, bytes[7]));
|
|
||||||
lightingTime = HH + "小时" + mm + "分钟";
|
|
||||||
|
|
||||||
this.formData.mode = staticLevelText;
|
|
||||||
this.formData.fuMode = lightingLevelText;
|
|
||||||
this.formData.battary = batteryLevel;
|
|
||||||
this.formData.statu = warn;
|
|
||||||
this.formData.xuhang = lightingTime;
|
|
||||||
|
|
||||||
if (batteryLevel <= 20) {
|
|
||||||
this.showPop({
|
|
||||||
message: "设备电量低",
|
|
||||||
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
|
|
||||||
borderColor: "#e034344d",
|
|
||||||
buttonBgColor: "#E03434",
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
this.setBleFormData();
|
|
||||||
} catch (error) {
|
|
||||||
console.log('数据解析错误:', error);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
let json = recei.ReceiveData(receive, device, path);
|
||||||
|
if (!json) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let keys = Object.keys(json);
|
||||||
|
keys.forEach((key) => {
|
||||||
|
if (key in these.formData) {
|
||||||
|
these.formData[key] = json[key];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (this.formData.battary <= 20) {
|
||||||
|
this.showPop({
|
||||||
|
message: "设备电量低",
|
||||||
|
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
|
||||||
|
borderColor: "#e034344d",
|
||||||
|
buttonBgColor: "#E03434",
|
||||||
|
});
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
proParam: function() {
|
proParam: function() {
|
||||||
@ -544,6 +578,7 @@
|
|||||||
events: {
|
events: {
|
||||||
BindOver: function(data) {
|
BindOver: function(data) {
|
||||||
console.log(data)
|
console.log(data)
|
||||||
|
these.formData.bleStatu = true;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
success: function(res) {
|
success: function(res) {
|
||||||
@ -975,12 +1010,12 @@
|
|||||||
|
|
||||||
},
|
},
|
||||||
closePop: function() {
|
closePop: function() {
|
||||||
this.Status.Pop.showPop = false;
|
this.Status.Pop.showPop = false;
|
||||||
|
|
||||||
if (this.Status.Pop.cancelCallback) {
|
if (this.Status.Pop.cancelCallback) {
|
||||||
this.Status.Pop.cancelCallback();
|
this.Status.Pop.cancelCallback();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
HidePop: function() {
|
HidePop: function() {
|
||||||
// console.log("1111");
|
// console.log("1111");
|
||||||
if (this.Status.Pop.clickEvt == 'SendUsr') {
|
if (this.Status.Pop.clickEvt == 'SendUsr') {
|
||||||
|
|||||||
22
pages/6331/AudioManager.vue
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
<template>
|
||||||
|
<view>
|
||||||
|
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
|
||||||
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
|
||||||
|
</style>
|
||||||
1505
pages/6331/BJQ6331.vue
Normal file
@ -1,7 +1,7 @@
|
|||||||
<template>
|
<template>
|
||||||
<view class="content contentBg">
|
<view class="content contentBg">
|
||||||
<view class="eq">
|
<view class="eq">
|
||||||
<view class="leftImg">
|
<view class="leftImg" @click.stop="previewImg(formData.img)">
|
||||||
<image class="img" :src="formData.img" mode="aspectFit"></image>
|
<image class="img" :src="formData.img" mode="aspectFit"></image>
|
||||||
</view>
|
</view>
|
||||||
<view class="rightTxt">
|
<view class="rightTxt">
|
||||||
@ -30,6 +30,10 @@
|
|||||||
<text class="lbl">设备名称</text>
|
<text class="lbl">设备名称</text>
|
||||||
<text class="value">{{formData.deviceName}}</text>
|
<text class="value">{{formData.deviceName}}</text>
|
||||||
</view>
|
</view>
|
||||||
|
<view class="item">
|
||||||
|
<text class="lbl">蓝牙状态</text>
|
||||||
|
<text class="value" :class="formData.bleStatu?'green':'red'">{{formData.bleStatu?'已连接':'未连接'}}</text>
|
||||||
|
</view>
|
||||||
<view class="item">
|
<view class="item">
|
||||||
<text class="lbl">预警级别</text>
|
<text class="lbl">预警级别</text>
|
||||||
<text class="value">{{formData.warnLevel}}</text>
|
<text class="value">{{formData.warnLevel}}</text>
|
||||||
@ -180,6 +184,7 @@
|
|||||||
|
|
||||||
import usrApi from '@/api/670/HBY670.js'
|
import usrApi from '@/api/670/HBY670.js'
|
||||||
const pagePath = "pages/650/HBY650";
|
const pagePath = "pages/650/HBY650";
|
||||||
|
|
||||||
var ble = null;
|
var ble = null;
|
||||||
var these = null;
|
var these = null;
|
||||||
var recei = null;
|
var recei = null;
|
||||||
@ -263,7 +268,8 @@
|
|||||||
name: '',
|
name: '',
|
||||||
job: '',
|
job: '',
|
||||||
id: '',
|
id: '',
|
||||||
iswarn: false
|
iswarn: false,
|
||||||
|
bleStatu: false
|
||||||
},
|
},
|
||||||
rgb565Data: [],
|
rgb565Data: [],
|
||||||
videoHexArray: [],
|
videoHexArray: [],
|
||||||
@ -291,24 +297,31 @@
|
|||||||
|
|
||||||
onUnload() {
|
onUnload() {
|
||||||
console.log("页面卸载,释放资源");
|
console.log("页面卸载,释放资源");
|
||||||
ble.removeReceiveCallback(pagePath);
|
ble.removeAllCallback(pagePath);
|
||||||
},
|
},
|
||||||
onLoad: function() {
|
onLoad: function() {
|
||||||
these = this;
|
these = this;
|
||||||
recei = BleReceive.getBleReceive();
|
recei = BleReceive.getBleReceive();
|
||||||
ble = BleTool.getBleTool();
|
ble = BleTool.getBleTool();
|
||||||
console.log("650")
|
|
||||||
ble.addReceiveCallback(these.bleValueNotify);
|
|
||||||
|
ble.addReceiveCallback(these.bleValueNotify, pagePath);
|
||||||
|
ble.addStateBreakCallback(these.bleStateBreak, pagePath);
|
||||||
|
ble.addStateRecoveryCallback(these.bleStateRecovry, pagePath);
|
||||||
|
ble.addDisposeCallback(these.deviceDispose, pagePath);
|
||||||
|
ble.addRecoveryCallback(these.deviceRecovry, pagePath);
|
||||||
|
|
||||||
|
|
||||||
let eventChannel = this.getOpenerEventChannel();
|
let eventChannel = this.getOpenerEventChannel();
|
||||||
|
|
||||||
eventChannel.on('detailData', function(data) {
|
eventChannel.on('detailData', function(data) {
|
||||||
|
|
||||||
console.log("收到父页面的参数:" + JSON.stringify(data));
|
// console.log("收到父页面的参数:" + JSON.stringify(data));
|
||||||
var device = data.data;
|
var device = data.data;
|
||||||
these.device = device;
|
these.device = device;
|
||||||
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;
|
||||||
}
|
}
|
||||||
@ -332,9 +345,11 @@
|
|||||||
these.formData.blename = f.name ? f.name : "Unname";
|
these.formData.blename = f.name ? f.name : "Unname";
|
||||||
these.formData.deviceName = device.deviceName;
|
these.formData.deviceName = device.deviceName;
|
||||||
these.formData.img = device.devicePic;
|
these.formData.img = device.devicePic;
|
||||||
these.formData.id = device.id;
|
|
||||||
these.formData.deviceId = f.deviceId;
|
these.formData.deviceId = f.deviceId;
|
||||||
ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId);
|
ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId).then(res=>{
|
||||||
|
these.formData.bleStatu=true;
|
||||||
|
});
|
||||||
these.setBleFormData();
|
these.setBleFormData();
|
||||||
these.getDetail();
|
these.getDetail();
|
||||||
|
|
||||||
@ -343,10 +358,10 @@
|
|||||||
|
|
||||||
},
|
},
|
||||||
onHide: function() {
|
onHide: function() {
|
||||||
|
this.Status.pageHide = true;
|
||||||
},
|
},
|
||||||
onBackPress(e) {
|
onShow() {
|
||||||
ble.removeReceiveCallback(pagePath);
|
this.Status.pageHide = false;
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
RSSIRemark: function() {
|
RSSIRemark: function() {
|
||||||
@ -367,6 +382,85 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
deviceRecovry(res) {
|
||||||
|
if (this.Status.pageHide) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (res.deviceId == these.formData.deviceId) {
|
||||||
|
this.formData.bleStatu = true;
|
||||||
|
setTimeout(() => {
|
||||||
|
hideLoading(these, 1000);
|
||||||
|
});
|
||||||
|
uni.showToast({
|
||||||
|
icon: 'success',
|
||||||
|
title: '蓝牙连接成功'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
},
|
||||||
|
deviceDispose(res) {
|
||||||
|
if (this.Status.pageHide) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (res.deviceId == these.formData.deviceId) {
|
||||||
|
this.formData.bleStatu = false;
|
||||||
|
setTimeout(() => {
|
||||||
|
hideLoading(these, 1000);
|
||||||
|
});
|
||||||
|
uni.showToast({
|
||||||
|
icon: 'fail',
|
||||||
|
title: '蓝牙连接已断开'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
},
|
||||||
|
bleStateBreak() {
|
||||||
|
if (this.Status.pageHide) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//蓝牙适配器不可用
|
||||||
|
this.formData.bleStatu = false;
|
||||||
|
uni.showToast({
|
||||||
|
icon: 'fail',
|
||||||
|
title: '蓝牙已不可用'
|
||||||
|
})
|
||||||
|
hideLoading(this);
|
||||||
|
},
|
||||||
|
bleStateRecovry() {
|
||||||
|
console.log("蓝牙可用");
|
||||||
|
if (this.Status.pageHide) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
console.log("蓝牙可用");
|
||||||
|
//蓝牙适配器再次可用,尝试恢复连接
|
||||||
|
showLoading(this, {
|
||||||
|
text: "蓝牙恢复可用,正在连接设备"
|
||||||
|
});
|
||||||
|
ble.LinkBlue(these.formData.deviceId).then(() => {
|
||||||
|
these.formData.bleStatu = true;
|
||||||
|
updateLoading(these, {
|
||||||
|
text: '连接成功'
|
||||||
|
});
|
||||||
|
}).catch(ex => {
|
||||||
|
updateLoading(these, {
|
||||||
|
text: ex.msg
|
||||||
|
})
|
||||||
|
}).finally(() => {
|
||||||
|
setTimeout(() => {
|
||||||
|
hideLoading(these);
|
||||||
|
}, 1000);
|
||||||
|
|
||||||
|
});
|
||||||
|
},
|
||||||
|
previewImg(img) {
|
||||||
|
if (!img) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
uni.previewImage({
|
||||||
|
urls: [img]
|
||||||
|
})
|
||||||
|
},
|
||||||
getWarnStyle(index) {
|
getWarnStyle(index) {
|
||||||
let className = "";
|
let className = "";
|
||||||
switch (this.formData.warnLevel) {
|
switch (this.formData.warnLevel) {
|
||||||
@ -465,7 +559,7 @@
|
|||||||
getDetail() {
|
getDetail() {
|
||||||
var that = this;
|
var that = this;
|
||||||
usrApi.getDetail(this.device.id).then(res => {
|
usrApi.getDetail(this.device.id).then(res => {
|
||||||
|
console.log("res=",res);
|
||||||
if (res && res.code == 200) {
|
if (res && res.code == 200) {
|
||||||
res = res.data;
|
res = res.data;
|
||||||
let personnelInfo = res.personnelInfo;
|
let personnelInfo = res.personnelInfo;
|
||||||
@ -590,8 +684,9 @@
|
|||||||
borderColor: "#e034344d",
|
borderColor: "#e034344d",
|
||||||
buttonBgColor: "#E03434",
|
buttonBgColor: "#E03434",
|
||||||
buttonText: '去连接',
|
buttonText: '去连接',
|
||||||
|
buttonTextColor: '#FFFFFFde',
|
||||||
okCallback: function() {
|
okCallback: function() {
|
||||||
console.log("1111");
|
|
||||||
uni.navigateTo({
|
uni.navigateTo({
|
||||||
url: "/pages/common/addBLE/addEquip",
|
url: "/pages/common/addBLE/addEquip",
|
||||||
events: {
|
events: {
|
||||||
@ -620,7 +715,7 @@
|
|||||||
proParam: function() {
|
proParam: function() {
|
||||||
|
|
||||||
uni.navigateTo({
|
uni.navigateTo({
|
||||||
url: '/pages/common/productDes/index?id=' + this.formData.id,
|
url: '/pages/common/productDes/index?id=' + this.device.id,
|
||||||
success(ev) {
|
success(ev) {
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -628,7 +723,7 @@
|
|||||||
},
|
},
|
||||||
handRemark: function() {
|
handRemark: function() {
|
||||||
uni.navigateTo({
|
uni.navigateTo({
|
||||||
url: '/pages/common/operatingInstruct/index?id=' + this.formData.id,
|
url: '/pages/common/operatingInstruct/index?id=' + this.device.id,
|
||||||
success(ev) {
|
success(ev) {
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -636,7 +731,7 @@
|
|||||||
},
|
},
|
||||||
handVideo: function() {
|
handVideo: function() {
|
||||||
uni.navigateTo({
|
uni.navigateTo({
|
||||||
url: '/pages/common/operationVideo/index?id=' + this.formData.id,
|
url: '/pages/common/operationVideo/index?id=' + this.device.id,
|
||||||
success(ev) {
|
success(ev) {
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -984,7 +1079,7 @@
|
|||||||
|
|
||||||
uni.uploadFile({
|
uni.uploadFile({
|
||||||
// url: 'http://114.55.111.217/video/upload',
|
// url: 'http://114.55.111.217/video/upload',
|
||||||
url: baseURL+"app/video/upload",
|
url: baseURL + "app/video/upload",
|
||||||
filePath: videoPath,
|
filePath: videoPath,
|
||||||
name: 'file',
|
name: 'file',
|
||||||
header: {
|
header: {
|
||||||
@ -1148,7 +1243,7 @@
|
|||||||
},
|
},
|
||||||
closePop: function() {
|
closePop: function() {
|
||||||
this.Status.Pop.showPop = false;
|
this.Status.Pop.showPop = false;
|
||||||
|
|
||||||
if (this.Status.Pop.cancelCallback) {
|
if (this.Status.Pop.cancelCallback) {
|
||||||
this.Status.Pop.cancelCallback();
|
this.Status.Pop.cancelCallback();
|
||||||
}
|
}
|
||||||
@ -1157,7 +1252,7 @@
|
|||||||
if (this.Status.Pop.clickEvt == 'SendUsr') {
|
if (this.Status.Pop.clickEvt == 'SendUsr') {
|
||||||
|
|
||||||
}
|
}
|
||||||
console.log("1111");
|
|
||||||
|
|
||||||
this.Status.Pop.showPop = false;
|
this.Status.Pop.showPop = false;
|
||||||
if (this.Status.Pop.okCallback) {
|
if (this.Status.Pop.okCallback) {
|
||||||
@ -1248,9 +1343,9 @@
|
|||||||
|
|
||||||
let json = {
|
let json = {
|
||||||
deviceId: these.device.id,
|
deviceId: these.device.id,
|
||||||
name: these.formData.company,
|
name: these.formData.name,
|
||||||
position: these.formData.name,
|
position: these.formData.job,
|
||||||
unitName: these.formData.job,
|
unitName: these.formData.company,
|
||||||
code: these.formData.id
|
code: these.formData.id
|
||||||
};
|
};
|
||||||
usrApi.sendUsr(json)
|
usrApi.sendUsr(json)
|
||||||
@ -1262,7 +1357,9 @@
|
|||||||
let arr = gbk.encode(text)
|
let arr = gbk.encode(text)
|
||||||
let gbkData = gbk.arr2hex(arr);
|
let gbkData = gbk.arr2hex(arr);
|
||||||
|
|
||||||
|
let s = (text.length * 2).toString(16);
|
||||||
|
let len = String(s).padStart(4, '0')
|
||||||
|
len = len.match(/.{1,2}/g);
|
||||||
// 构建数据包
|
// 构建数据包
|
||||||
const bufferSize = 5 + gbkData.length / 2; // 头部4字节 + 数据部分
|
const bufferSize = 5 + gbkData.length / 2; // 头部4字节 + 数据部分
|
||||||
const buffer = new ArrayBuffer(bufferSize);
|
const buffer = new ArrayBuffer(bufferSize);
|
||||||
@ -1272,7 +1369,8 @@
|
|||||||
dataView.setUint8(0, 0x55); // 帧头
|
dataView.setUint8(0, 0x55); // 帧头
|
||||||
dataView.setUint8(1, 0x03); // 帧类型:文字
|
dataView.setUint8(1, 0x03); // 帧类型:文字
|
||||||
dataView.setUint8(2, currentPacket.toString(16)); // 包序号
|
dataView.setUint8(2, currentPacket.toString(16)); // 包序号
|
||||||
dataView.setUint16(3, (text.length * 2).toString(16)); // 数据长度
|
dataView.setUint8(3, parseInt('0x' + len[0], 16)); // 数据长度
|
||||||
|
dataView.setUint8(4, parseInt('0x' + len[1], 16)); // 数据长度
|
||||||
|
|
||||||
// 填充数据
|
// 填充数据
|
||||||
let index = 0;
|
let index = 0;
|
||||||
|
|||||||
@ -4,7 +4,7 @@
|
|||||||
:rightIcons="Status.navbar.icons" @icon-click="handleRightClick"></custom-navbar>
|
:rightIcons="Status.navbar.icons" @icon-click="handleRightClick"></custom-navbar>
|
||||||
|
|
||||||
<view class="eq" :style="{marginTop:Status.navbar.height+'px'}">
|
<view class="eq" :style="{marginTop:Status.navbar.height+'px'}">
|
||||||
<view class="leftImg">
|
<view class="leftImg" @click.stop="previewImg(device['devicePic'])">
|
||||||
<image class="img" :src="device['devicePic']" mode="aspectFit"></image>
|
<image class="img" :src="device['devicePic']" mode="aspectFit"></image>
|
||||||
</view>
|
</view>
|
||||||
<view class="rightTxt">
|
<view class="rightTxt">
|
||||||
@ -33,10 +33,15 @@
|
|||||||
<text class="lbl">设备名称</text>
|
<text class="lbl">设备名称</text>
|
||||||
<text class="value valueFont">{{device.deviceName}}</text>
|
<text class="value valueFont">{{device.deviceName}}</text>
|
||||||
</view>
|
</view>
|
||||||
|
<view class="item">
|
||||||
|
<text class="lbl">蓝牙状态</text>
|
||||||
|
<text class="value" :class="formData.bleStatu?'green':'red'">{{formData.bleStatu?'已连接':'未连接'}}</text>
|
||||||
|
</view>
|
||||||
<view class="item">
|
<view class="item">
|
||||||
<text class="lbl">设备状态</text>
|
<text class="lbl">设备状态</text>
|
||||||
<text class="value valueFont">{{formData.sta_system}}</text>
|
<text class="value valueFont">{{formData.sta_system}}</text>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<view class="item">
|
<view class="item">
|
||||||
<text class="lbl">定位信息</text>
|
<text class="lbl">定位信息</text>
|
||||||
<view class="multiValue" @click.stop="gotoMap()">
|
<view class="multiValue" @click.stop="gotoMap()">
|
||||||
@ -282,7 +287,7 @@
|
|||||||
request,
|
request,
|
||||||
baseURL
|
baseURL
|
||||||
} from '../../utils/request';
|
} from '../../utils/request';
|
||||||
|
import lnglatConvert from '@/utils/wgs84_to_gcj02.js'
|
||||||
|
|
||||||
const pagePath = "pages/670/HBY670";
|
const pagePath = "pages/670/HBY670";
|
||||||
var ble = null;
|
var ble = null;
|
||||||
@ -293,6 +298,7 @@
|
|||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
Status: {
|
Status: {
|
||||||
|
pageHide: false,
|
||||||
apiType: "listA",
|
apiType: "listA",
|
||||||
navbar: {
|
navbar: {
|
||||||
icons: [{
|
icons: [{
|
||||||
@ -369,6 +375,7 @@
|
|||||||
showClose: false
|
showClose: false
|
||||||
},
|
},
|
||||||
usrToggle: true,
|
usrToggle: true,
|
||||||
|
bleLinkCnt: 0
|
||||||
},
|
},
|
||||||
formData: {
|
formData: {
|
||||||
battary: "", //电量
|
battary: "", //电量
|
||||||
@ -380,9 +387,9 @@
|
|||||||
modeCurr: "", //档位
|
modeCurr: "", //档位
|
||||||
SOS: "", //sos
|
SOS: "", //sos
|
||||||
lightCurr: "qiang", //照明模式
|
lightCurr: "qiang", //照明模式
|
||||||
company: "", //单位
|
company: "湖北消防总队", //单位
|
||||||
usrname: "", //姓名
|
usrname: "胡红军", //姓名
|
||||||
job: "", //职位
|
job: "中队长", //职位
|
||||||
usrid: "", //id
|
usrid: "", //id
|
||||||
msgTxt: "", //消息1
|
msgTxt: "", //消息1
|
||||||
qzwarn: false, //是否强制报警
|
qzwarn: false, //是否强制报警
|
||||||
@ -390,7 +397,8 @@
|
|||||||
staticWarn: false, //静止报警
|
staticWarn: false, //静止报警
|
||||||
fourGStrenth: 0, //4G信号强度
|
fourGStrenth: 0, //4G信号强度
|
||||||
deviceId: "",
|
deviceId: "",
|
||||||
sta_system: "" //设备状态,0关机,1仅充电,2开机未充电,3,开机且充电
|
sta_system: "", //设备状态,0关机,1仅充电,2开机未充电,3,开机且充电
|
||||||
|
bleStatu: false
|
||||||
},
|
},
|
||||||
device: {
|
device: {
|
||||||
id: "",
|
id: "",
|
||||||
@ -445,7 +453,7 @@
|
|||||||
onUnload() {
|
onUnload() {
|
||||||
console.log("页面卸载,释放资源");
|
console.log("页面卸载,释放资源");
|
||||||
let statusTopic = `A/${this.formData.imei?this.formData.imei:this.device.deviceImei}`;
|
let statusTopic = `A/${this.formData.imei?this.formData.imei:this.device.deviceImei}`;
|
||||||
ble.removeReceiveCallback(pagePath);
|
ble.removeAllCallback(pagePath);
|
||||||
if (mqttClient) {
|
if (mqttClient) {
|
||||||
mqttClient.unsubscribe(statusTopic);
|
mqttClient.unsubscribe(statusTopic);
|
||||||
mqttClient.disconnect();
|
mqttClient.disconnect();
|
||||||
@ -459,8 +467,14 @@
|
|||||||
these = this;
|
these = this;
|
||||||
recei = BleReceive.getBleReceive();
|
recei = BleReceive.getBleReceive();
|
||||||
ble = BleTool.getBleTool();
|
ble = BleTool.getBleTool();
|
||||||
console.log("670")
|
|
||||||
ble.addReceiveCallback(these.bleValueNotify);
|
|
||||||
|
ble.addReceiveCallback(these.bleValueNotify, pagePath);
|
||||||
|
ble.addStateBreakCallback(these.bleStateBreak, pagePath);
|
||||||
|
ble.addStateRecoveryCallback(these.bleStateRecovry, pagePath);
|
||||||
|
ble.addDisposeCallback(these.deviceDispose, pagePath);
|
||||||
|
ble.addRecoveryCallback(these.deviceRecovry, pagePath);
|
||||||
|
|
||||||
let eventChannel = this.getOpenerEventChannel();
|
let eventChannel = this.getOpenerEventChannel();
|
||||||
|
|
||||||
eventChannel.on('detailData', function(data) {
|
eventChannel.on('detailData', function(data) {
|
||||||
@ -469,6 +483,7 @@
|
|||||||
var device = data.data;
|
var device = data.data;
|
||||||
these.Status.apiType = data.apiType;
|
these.Status.apiType = data.apiType;
|
||||||
these.device = device;
|
these.device = device;
|
||||||
|
these.formData.usrid = device.deviceImei;
|
||||||
if (data.apiType !== 'listA') {
|
if (data.apiType !== 'listA') {
|
||||||
Common.getdeviceShareId(data.data.id).then(res => {
|
Common.getdeviceShareId(data.data.id).then(res => {
|
||||||
if (res.code == 200) {
|
if (res.code == 200) {
|
||||||
@ -508,12 +523,17 @@
|
|||||||
these.formData['imei'] = these.device.deviceImei;
|
these.formData['imei'] = these.device.deviceImei;
|
||||||
}
|
}
|
||||||
these.getDetail();
|
these.getDetail();
|
||||||
ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId);
|
ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId).then(res => {
|
||||||
|
these.formData.bleStatu = true;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
},
|
},
|
||||||
|
onShow() {
|
||||||
|
this.Status.pageHide=false;
|
||||||
|
},
|
||||||
onHide: function() {
|
onHide: function() {
|
||||||
|
this.Status.pageHide=true;
|
||||||
},
|
},
|
||||||
onBackPress(e) {
|
onBackPress(e) {
|
||||||
ble.removeReceiveCallback(pagePath);
|
ble.removeReceiveCallback(pagePath);
|
||||||
@ -522,17 +542,99 @@
|
|||||||
|
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
showBleUnConnect() {
|
deviceRecovry(res) {
|
||||||
|
if (this.Status.pageHide) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (res.deviceId == these.formData.deviceId) {
|
||||||
|
this.formData.bleStatu = true;
|
||||||
|
setTimeout(() => {
|
||||||
|
hideLoading(these, 1000);
|
||||||
|
});
|
||||||
|
uni.showToast({
|
||||||
|
icon: 'success',
|
||||||
|
title: '蓝牙连接成功'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
},
|
||||||
|
deviceDispose(res) {
|
||||||
|
if (this.Status.pageHide) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (res.deviceId == these.formData.deviceId) {
|
||||||
|
this.formData.bleStatu = false;
|
||||||
|
setTimeout(() => {
|
||||||
|
hideLoading(these, 1000);
|
||||||
|
});
|
||||||
|
uni.showToast({
|
||||||
|
icon: 'fail',
|
||||||
|
title: '蓝牙连接已断开'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
},
|
||||||
|
bleStateBreak() {
|
||||||
|
if (this.Status.pageHide) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//蓝牙适配器不可用
|
||||||
|
this.formData.bleStatu = false;
|
||||||
|
uni.showToast({
|
||||||
|
icon: 'fail',
|
||||||
|
title: '蓝牙已不可用'
|
||||||
|
})
|
||||||
|
hideLoading(this);
|
||||||
|
},
|
||||||
|
bleStateRecovry() {
|
||||||
|
console.log("蓝牙可用");
|
||||||
|
if (this.Status.pageHide) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
console.log("蓝牙可用");
|
||||||
|
//蓝牙适配器再次可用,尝试恢复连接
|
||||||
|
showLoading(this, {
|
||||||
|
text: "蓝牙恢复可用,正在连接设备"
|
||||||
|
});
|
||||||
|
ble.LinkBlue(these.formData.deviceId).then(() => {
|
||||||
|
these.formData.bleStatu = true;
|
||||||
|
updateLoading(these, {
|
||||||
|
text: '连接成功'
|
||||||
|
});
|
||||||
|
}).catch(ex => {
|
||||||
|
updateLoading(these, {
|
||||||
|
text: ex.msg
|
||||||
|
})
|
||||||
|
}).finally(() => {
|
||||||
|
setTimeout(() => {
|
||||||
|
hideLoading(these);
|
||||||
|
}, 1000);
|
||||||
|
|
||||||
|
});
|
||||||
|
},
|
||||||
|
previewImg(img) {
|
||||||
|
if (!img) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
uni.previewImage({
|
||||||
|
urls: [img]
|
||||||
|
})
|
||||||
|
},
|
||||||
|
showBleUnConnect() {
|
||||||
|
this.Status.bleLinkCnt++;
|
||||||
|
if (this.Status.bleLinkCnt > 3) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
this.showPop({
|
this.showPop({
|
||||||
message: "蓝牙未连接过该设备,请使用蓝牙重新添加该设备",
|
message: "蓝牙未连接过该设备,请使用蓝牙重新添加该设备,取消"+(4-this.Status.bleLinkCnt)+"次后不再提醒",
|
||||||
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
|
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
|
||||||
borderColor: "#e034344d",
|
borderColor: "#e034344d",
|
||||||
buttonBgColor: "#E03434",
|
buttonBgColor: "#E03434",
|
||||||
buttonText: '去连接',
|
buttonText: '去连接',
|
||||||
showCancel: true,
|
showCancel: true,
|
||||||
cancelCallback: () => {
|
cancelCallback: () => {
|
||||||
this.closePop();
|
// this.closePop();
|
||||||
},
|
},
|
||||||
okCallback: function() {
|
okCallback: function() {
|
||||||
console.log("1111");
|
console.log("1111");
|
||||||
@ -557,8 +659,9 @@
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
gotoMap() {
|
gotoMap() {
|
||||||
this.detailData.longitude = this.formData.Lon;
|
let lnglat = lnglatConvert.wgs84_to_gcj02(this.formData.Lon, this.formData.Lat);
|
||||||
this.detailData.latitude = this.formData.Lat;
|
this.detailData.longitude = lnglat[0];
|
||||||
|
this.detailData.latitude = lnglat[1];
|
||||||
uni.navigateTo({
|
uni.navigateTo({
|
||||||
url: '/pages/common/map/index',
|
url: '/pages/common/map/index',
|
||||||
events: {
|
events: {
|
||||||
@ -585,14 +688,14 @@
|
|||||||
that.formData.address = res.address;
|
that.formData.address = res.address;
|
||||||
let personnelInfo = res.personnelInfo;
|
let personnelInfo = res.personnelInfo;
|
||||||
if (personnelInfo) {
|
if (personnelInfo) {
|
||||||
that.formData.company = personnelInfo.name;
|
that.formData.company = personnelInfo.unitName;
|
||||||
that.formData.usrname = personnelInfo.unitName;
|
that.formData.usrname = personnelInfo.name;
|
||||||
that.formData.job = personnelInfo.position;
|
that.formData.job = personnelInfo.position;
|
||||||
that.formData.usrid = personnelInfo.code
|
that.formData.usrid = personnelInfo.code
|
||||||
}
|
}
|
||||||
that.formData.imei=res.deviceImei;
|
that.formData.imei = res.deviceImei;
|
||||||
these.device.deviceImei=res.deviceImei;
|
these.device.deviceImei = res.deviceImei;
|
||||||
if(that.formData.imei){
|
if (that.formData.imei) {
|
||||||
that.initMQ();
|
that.initMQ();
|
||||||
}
|
}
|
||||||
let dic = {
|
let dic = {
|
||||||
@ -1160,6 +1263,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (this.formData.SOS == type) {
|
if (this.formData.SOS == type) {
|
||||||
|
console.log("111111");
|
||||||
type = "close";
|
type = "close";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1194,23 +1298,31 @@
|
|||||||
message.deviceId = these.device.id;
|
message.deviceId = these.device.id;
|
||||||
message.deviceImei = these.device.deviceImei;
|
message.deviceImei = these.device.deviceImei;
|
||||||
|
|
||||||
let requestSend = () => {
|
let requestSend = (callback) => {
|
||||||
|
debugger;
|
||||||
message.isBluetooth = false;
|
message.isBluetooth = false;
|
||||||
api.sendSos(message).then((res) => {
|
api.sendSos(message).then((res) => {
|
||||||
console.log("res=>", res);
|
console.log("res=>", res);
|
||||||
if (res && res.code == 200) {
|
if (res && res.code == 200) {
|
||||||
console.log("接口发送SOS指令成功");
|
console.log("接口发送SOS指令成功");
|
||||||
|
if (callback) {
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
|
||||||
return Promise.resolve({
|
return Promise.resolve({
|
||||||
code: 200,
|
code: 200,
|
||||||
msg: '操作成功'
|
msg: '操作成功'
|
||||||
});
|
});
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
return this.sendMQ(json);
|
return this.sendMQ(json);
|
||||||
}
|
}
|
||||||
|
|
||||||
}).then((res) => {
|
}).then((res) => {
|
||||||
console.log("res=", res);
|
console.log("res=", res);
|
||||||
|
if (callback) {
|
||||||
|
callback();
|
||||||
|
}
|
||||||
}).catch((ex) => {
|
}).catch((ex) => {
|
||||||
console.log("ex=", ex);
|
console.log("ex=", ex);
|
||||||
these.showPop({
|
these.showPop({
|
||||||
@ -1228,7 +1340,7 @@
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let bleSendCmd = () => {
|
let bleSendCmd = (callback) => {
|
||||||
let f = this.getDevice();
|
let f = this.getDevice();
|
||||||
let buffer = null;
|
let buffer = null;
|
||||||
if (f) {
|
if (f) {
|
||||||
@ -1241,75 +1353,87 @@
|
|||||||
dataView.setUint8(3, 0x00); // 数据长度
|
dataView.setUint8(3, 0x00); // 数据长度
|
||||||
dataView.setUint8(4, 0x01); // 数据长度
|
dataView.setUint8(4, 0x01); // 数据长度
|
||||||
dataView.setUint8(5, dic.ble[type]); // 数据
|
dataView.setUint8(5, dic.ble[type]); // 数据
|
||||||
|
console.log("type=", type);
|
||||||
ble.sendData(f.deviceId, buffer, f.writeServiceId, f.wirteCharactId, 10).then(
|
ble.sendData(f.deviceId, buffer, f.writeServiceId, f.wirteCharactId, 10).then(
|
||||||
() => {
|
() => {
|
||||||
console.log("蓝牙发送成功了");
|
console.log("蓝牙发送成功了");
|
||||||
hideLoading(these);
|
hideLoading(these);
|
||||||
these.setBleFormData();
|
these.setBleFormData();
|
||||||
message.isBluetooth = true;
|
message.isBluetooth = true;
|
||||||
api.sendSos(message);
|
// api.sendSos(message);
|
||||||
|
if (callback) {
|
||||||
|
callback();
|
||||||
|
}
|
||||||
}).catch((ex) => {
|
}).catch((ex) => {
|
||||||
//使用4G发送
|
//使用4G发送
|
||||||
console.log("蓝牙发送失败,转4g发送", ex);
|
console.log("蓝牙发送失败,转4g发送", ex);
|
||||||
requestSend();
|
requestSend(callback);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
console.log("找不到蓝牙设备");
|
console.log("找不到蓝牙设备");
|
||||||
requestSend();
|
requestSend(callback);
|
||||||
these.showBleUnConnect();
|
these.showBleUnConnect();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let OpenSOS = () => {
|
let OpenSOS = () => {
|
||||||
these.formData.qzwarn = true; //标记为强制报警了
|
let execSos = () => {
|
||||||
|
these.formData.qzwarn = true; //标记为强制报警了
|
||||||
|
|
||||||
|
these.Status.staticWarn.time = 180;
|
||||||
|
this.formData.SOS = type;
|
||||||
|
|
||||||
|
let loopFunc = () => {
|
||||||
|
if (these.Status.staticWarn.inteval === null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (these.Status.staticWarn.time === 0) {
|
||||||
|
|
||||||
|
|
||||||
|
clearInterval(these.Status.staticWarn.inteval);
|
||||||
|
these.Status.staticWarn.inteval = null;
|
||||||
|
these.formData.qzwarn = false;
|
||||||
|
|
||||||
|
if(this.Status.Pop.okCallback){
|
||||||
|
these.CloseWarn(false);
|
||||||
|
these.formData.SOS = 'close';
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
these.Status.staticWarn.time = these.Status.staticWarn
|
||||||
|
.time - 1;
|
||||||
|
|
||||||
|
if (these.Status.Pop.clickEvt == 'time' && this.Status.Pop.showPop) {
|
||||||
|
console.log("111111");
|
||||||
|
this.showQzWarn(this.Status.Pop.okCallback);
|
||||||
|
}
|
||||||
|
|
||||||
these.Status.staticWarn.time = 180;
|
|
||||||
this.formData.SOS = type;
|
|
||||||
|
|
||||||
let loopFunc = () => {
|
|
||||||
if (these.Status.staticWarn.inteval === null) {
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
if (these.Status.staticWarn.time === 0) {
|
these.Status.staticWarn.inteval = setInterval(() => {
|
||||||
|
loopFunc();
|
||||||
|
}, 1000);
|
||||||
clearInterval(these.Status.staticWarn.inteval);
|
|
||||||
these.Status.staticWarn.inteval = null;
|
|
||||||
these.formData.qzwarn = false;
|
|
||||||
these.formData.SOS = 'close';
|
|
||||||
these.CloseWarn(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
these.Status.staticWarn.time = these.Status.staticWarn
|
|
||||||
.time - 1;
|
|
||||||
|
|
||||||
if (these.Status.Pop.clickEvt == 'time' && this.Status.Pop.showPop) {
|
|
||||||
console.log("111111");
|
|
||||||
this.showQzWarn(this.Status.Pop.okCallback);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
these.Status.staticWarn.inteval = setInterval(() => {
|
|
||||||
loopFunc();
|
|
||||||
}, 1000);
|
|
||||||
|
|
||||||
bleSendCmd();
|
|
||||||
|
bleSendCmd(execSos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (type == 'rb') { //红蓝报警
|
if (type == 'rb') { //红蓝报警
|
||||||
console.log("11111");
|
console.log("11111");
|
||||||
let sendRb = () => {
|
let sendRb = () => {
|
||||||
|
|
||||||
this.formData.SOS = type;
|
this.formData.SOS = type;
|
||||||
bleSendCmd();
|
bleSendCmd();
|
||||||
these.formData.qzwarn = false;
|
these.formData.qzwarn = false;
|
||||||
this.Status.staticWarn.time = 0;
|
this.Status.staticWarn.time = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (these.formData.qzwarn && these.Status.staticWarn.inteval) {
|
if (these.formData.qzwarn && these.Status.staticWarn.inteval && these.Status.staticWarn.time) {
|
||||||
console.log("222222");
|
console.log("222222");
|
||||||
|
this.Status.Pop.okCallback=null;
|
||||||
these.showQzWarn(sendRb);
|
these.showQzWarn(sendRb);
|
||||||
} else {
|
} else {
|
||||||
sendRb();
|
sendRb();
|
||||||
@ -2094,12 +2218,14 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
let requestSend = () => {
|
let requestSend = () => {
|
||||||
|
|
||||||
|
|
||||||
let json = {
|
let json = {
|
||||||
deviceId: this.device.id,
|
deviceId: this.device.id,
|
||||||
deviceImei: this.device.deviceImei ? this.device.deviceImei : this.formData.imei,
|
deviceImei: this.device.deviceImei ? this.device.deviceImei : this.formData.imei,
|
||||||
name: this.formData.company,
|
unitName: this.formData.company,
|
||||||
position: this.formData.usrname,
|
name: this.formData.usrname,
|
||||||
unitName: this.formData.job,
|
position: this.formData.job,
|
||||||
code: this.formData.usrid
|
code: this.formData.usrid
|
||||||
};
|
};
|
||||||
api.sendUsr(json).then((res) => {
|
api.sendUsr(json).then((res) => {
|
||||||
@ -2196,33 +2322,41 @@
|
|||||||
hideLoading(these);
|
hideLoading(these);
|
||||||
|
|
||||||
|
|
||||||
let json = {
|
// let json = {
|
||||||
deviceId: these.device.id,
|
// deviceId: these.device.id,
|
||||||
name: these.formData.company,
|
// name: these.formData.company,
|
||||||
position: these.formData.usrname,
|
// position: these.formData.usrname,
|
||||||
unitName: these.formData.job,
|
// unitName: these.formData.job,
|
||||||
code: these.formData.usrid
|
// code: these.formData.usrid
|
||||||
};
|
// };
|
||||||
api.sendUsr(json)
|
// api.sendUsr(json)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取当前行文字
|
// 获取当前行文字
|
||||||
const text = textLines[currentPacket - 1] || '';
|
const text = textLines[currentPacket - 1] || '';
|
||||||
let arr = gbk.encode(text)
|
let arr = gbk.encode(text)
|
||||||
|
console.log("arr=",arr);
|
||||||
let gbkData = gbk.arr2hex(arr);
|
let gbkData = gbk.arr2hex(arr);
|
||||||
|
console.log("gbkData=",gbkData);
|
||||||
|
|
||||||
// 构建数据包
|
// 构建数据包
|
||||||
const bufferSize = 5 + gbkData.length / 2; // 头部4字节 + 数据部分
|
const bufferSize = 5 + gbkData.length / 2; // 头部4字节 + 数据部分
|
||||||
const buffer = new ArrayBuffer(bufferSize);
|
const buffer = new ArrayBuffer(bufferSize);
|
||||||
const dataView = new DataView(buffer);
|
const dataView = new DataView(buffer);
|
||||||
|
|
||||||
|
let s = (text.length * 2).toString(16);
|
||||||
|
let len = String(s).padStart(4, '0')
|
||||||
|
len = len.match(/.{1,2}/g);
|
||||||
|
|
||||||
// 填充头部
|
// 填充头部
|
||||||
dataView.setUint8(0, 0x55); // 帧头
|
dataView.setUint8(0, 0x55); // 帧头
|
||||||
dataView.setUint8(1, 0x03); // 帧类型:文字
|
dataView.setUint8(1, 0x03); // 帧类型:文字
|
||||||
dataView.setUint8(2, currentPacket.toString(16)); // 包序号
|
dataView.setUint8(2, currentPacket.toString(16)); // 包序号
|
||||||
dataView.setUint16(3, (text.length * 2).toString(16)); // 数据长度
|
dataView.setUint8(3, parseInt('0x' + len[0], 16)); // 数据长度
|
||||||
|
dataView.setUint8(4, parseInt('0x' + len[1], 16)); // 数据长度
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// 填充数据
|
// 填充数据
|
||||||
let index = 0;
|
let index = 0;
|
||||||
@ -2244,10 +2378,10 @@
|
|||||||
|
|
||||||
// 发送下一个包
|
// 发送下一个包
|
||||||
currentPacket++;
|
currentPacket++;
|
||||||
setTimeout(sendNextPacket, 0);
|
setTimeout(sendNextPacket, 200);
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
if (err.code == '10007') {
|
if (err.code == '10007') {
|
||||||
setTimeout(sendNextPacket, 0);
|
setTimeout(sendNextPacket, 200);
|
||||||
} else {
|
} else {
|
||||||
requestSend();
|
requestSend();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
<template>
|
<template>
|
||||||
<view class="content contentBg">
|
<view class="content contentBg">
|
||||||
<view class="eq">
|
<view class="eq">
|
||||||
<view class="leftImg">
|
<view class="leftImg" @click.stop="previewImg(formData.img)">
|
||||||
<image class="img" :src="formData.img" mode="aspectFit"></image>
|
<image class="img" :src="formData.img" mode="aspectFit"></image>
|
||||||
</view>
|
</view>
|
||||||
<view class="rightTxt">
|
<view class="rightTxt">
|
||||||
@ -34,6 +34,10 @@
|
|||||||
<text class="lbl">充电状态</text>
|
<text class="lbl">充电状态</text>
|
||||||
<text class="value">{{formData.statu}}</text>
|
<text class="value">{{formData.statu}}</text>
|
||||||
</view>
|
</view>
|
||||||
|
<view class="item">
|
||||||
|
<text class="lbl">蓝牙状态</text>
|
||||||
|
<text class="value" :class="formData.bleStatu?'green':'red'">{{formData.bleStatu?'已连接':'未连接'}}</text>
|
||||||
|
</view>
|
||||||
</view>
|
</view>
|
||||||
<view class="lamp">
|
<view class="lamp">
|
||||||
<view class="title">
|
<view class="title">
|
||||||
@ -67,7 +71,7 @@
|
|||||||
<text class="smallTxt">泛光模式</text>
|
<text class="smallTxt">泛光模式</text>
|
||||||
</view>
|
</view>
|
||||||
</view> -->
|
</view> -->
|
||||||
<view class="mode fleft" v-on:click.stop="UploadOpenImg()">
|
<view class="mode marginLeft fleft" v-on:click.stop="UploadOpenImg()">
|
||||||
<view class="leftImg">
|
<view class="leftImg">
|
||||||
<image class="img" src="/static/images/6155/DeviceDetail/open.png" mode="aspectFit"></image>
|
<image class="img" src="/static/images/6155/DeviceDetail/open.png" mode="aspectFit"></image>
|
||||||
</view>
|
</view>
|
||||||
@ -83,7 +87,7 @@
|
|||||||
<text class="usrtitle fleft">人员信息登记</text>
|
<text class="usrtitle fleft">人员信息登记</text>
|
||||||
<view class="btnSend fright" v-on:click.stop="sendUsr">发送</view>
|
<view class="btnSend fright" v-on:click.stop="sendUsr">发送</view>
|
||||||
<view class="clear"></view>
|
<view class="clear"></view>
|
||||||
<TextToHexV1 class="TextToHex" ref="textToHex" :txts="formData.textLines" :bgColor="'#FFFFFF'"
|
<textToDotMatrix class="TextToHex" ref="textToHex" :txts="formData.textLines" :bgColor="'#FFFFFF'"
|
||||||
:color="'#000000'" :fontSize="14" />
|
:color="'#000000'" :fontSize="14" />
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
@ -124,8 +128,8 @@
|
|||||||
:borderColor="Status.Pop.borderColor" :textColor="Status.Pop.textColor"
|
:borderColor="Status.Pop.borderColor" :textColor="Status.Pop.textColor"
|
||||||
:buttonBgColor="Status.Pop.buttonBgColor" :buttonTextColor="Status.Pop.buttonTextColor"
|
:buttonBgColor="Status.Pop.buttonBgColor" :buttonTextColor="Status.Pop.buttonTextColor"
|
||||||
: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" @closePop="closePop" :visiblePrompt="Status.Pop.visiblePrompt" :promptTitle="Status.Pop.promptTitle"
|
@buttonClick="HidePop" @closePop="closePop" :visiblePrompt="Status.Pop.visiblePrompt"
|
||||||
v-model="Status.Pop.modelValue" />
|
:promptTitle="Status.Pop.promptTitle" v-model="Status.Pop.modelValue" />
|
||||||
|
|
||||||
<!-- 下方菜单 -->
|
<!-- 下方菜单 -->
|
||||||
<BottomSlideMenuPlus :config="Status.BottomMenu" @close="closeMenu" @itemClick="handleItemClick"
|
<BottomSlideMenuPlus :config="Status.BottomMenu" @close="closeMenu" @itemClick="handleItemClick"
|
||||||
@ -143,7 +147,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import TextToHexV1 from '@/components/TextToHex/TextToHexV1.vue';
|
import textToDotMatrix from '@/components/TextToHex/textToDotMatrix.vue';
|
||||||
import bleTool from '@/utils/BleHelper.js';
|
import bleTool from '@/utils/BleHelper.js';
|
||||||
import usrApi from '@/api/670/HBY670.js'
|
import usrApi from '@/api/670/HBY670.js'
|
||||||
import {
|
import {
|
||||||
@ -158,14 +162,15 @@
|
|||||||
var these = null;
|
var these = null;
|
||||||
var BrighInteval = null;
|
var BrighInteval = null;
|
||||||
var recei = null;
|
var recei = null;
|
||||||
|
var pagePath = "pages/7305/BJQ7305";
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
TextToHexV1
|
textToDotMatrix
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
Status: {
|
Status: {
|
||||||
|
pageHide: false,
|
||||||
Pop: {
|
Pop: {
|
||||||
showPop: false, //是否显示弹窗
|
showPop: false, //是否显示弹窗
|
||||||
popType: 'custom',
|
popType: 'custom',
|
||||||
@ -182,7 +187,7 @@
|
|||||||
promptTitle: '设备名称',
|
promptTitle: '设备名称',
|
||||||
modelValue: '',
|
modelValue: '',
|
||||||
visibleClose: false,
|
visibleClose: false,
|
||||||
okCallback:null
|
okCallback: null
|
||||||
},
|
},
|
||||||
BottomMenu: {
|
BottomMenu: {
|
||||||
show: false,
|
show: false,
|
||||||
@ -232,7 +237,8 @@
|
|||||||
id: '',
|
id: '',
|
||||||
deviceId: '',
|
deviceId: '',
|
||||||
textLines: ['', '', ''],
|
textLines: ['', '', ''],
|
||||||
mode: ''
|
mode: '',
|
||||||
|
bleStatu: ''
|
||||||
},
|
},
|
||||||
inteval: 200,
|
inteval: 200,
|
||||||
device: {
|
device: {
|
||||||
@ -258,59 +264,18 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
onUnload() {
|
onUnload() {
|
||||||
ble.removeReceiveCallback(this);
|
ble.removeAllCallback(pagePath);
|
||||||
},
|
},
|
||||||
onLoad: function() {
|
onLoad: function() {
|
||||||
these = this;
|
these = this;
|
||||||
recei = BleReceive.getBleReceive();
|
recei = BleReceive.getBleReceive();
|
||||||
ble = bleTool.getBleTool();
|
ble = bleTool.getBleTool();
|
||||||
// let bleName = 'FB_Site_UART'; //JQZM-EF4651 FB_Site_UART
|
|
||||||
|
|
||||||
|
ble.addReceiveCallback(these.bleValueNotify, pagePath);
|
||||||
// let f = ble.data.LinkedList.find((v) => {
|
ble.addStateBreakCallback(these.bleStateBreak, pagePath);
|
||||||
// if (v.name == bleName) {
|
ble.addStateRecoveryCallback(these.bleStateRecovry,pagePath);
|
||||||
// console.log("找到设备了", v);
|
ble.addDisposeCallback(these.deviceDispose,pagePath);
|
||||||
// these.formData.deviceId = v.deviceId;
|
ble.addRecoveryCallback(these.deviceRecovry,pagePath);
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
// return false;
|
|
||||||
// });
|
|
||||||
|
|
||||||
// let link = () => {
|
|
||||||
// if (bleName == 'FB_Site_UART') {
|
|
||||||
// ble.LinkBlue(f.deviceId, '0000AE30-0000-1000-8000-00805F9B34FB',
|
|
||||||
// '0000AE03-0000-1000-8000-00805F9B34FB', '0000AE02-0000-1000-8000-00805F9B34FB');
|
|
||||||
// } else {
|
|
||||||
// ble.LinkBlue(f.deviceId, '0000FFE0-0000-1000-8000-00805F9B34FB',
|
|
||||||
// '0000FFE1-0000-1000-8000-00805F9B34FB', '0000FFE2-0000-1000-8000-00805F9B34FB');
|
|
||||||
// }
|
|
||||||
|
|
||||||
// }
|
|
||||||
// if (!f) {
|
|
||||||
|
|
||||||
|
|
||||||
// ble.addDeviceFound((res) => {
|
|
||||||
// // console.log("发现新设备", res);
|
|
||||||
// f = res.devices.find((v) => {
|
|
||||||
// return v.name == bleName;
|
|
||||||
// });
|
|
||||||
// if (f) {
|
|
||||||
|
|
||||||
// console.log("找到目标设备了", f);
|
|
||||||
// these.formData.deviceId = f.deviceId;
|
|
||||||
|
|
||||||
// link();
|
|
||||||
|
|
||||||
// ble.StopSearch();
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
|
|
||||||
// ble.StartSearch();
|
|
||||||
// } else {
|
|
||||||
// link();
|
|
||||||
// }
|
|
||||||
console.log("6155");
|
|
||||||
ble.addReceiveCallback(these.bleValueNotify);
|
|
||||||
let eventChannel = this.getOpenerEventChannel();
|
let eventChannel = this.getOpenerEventChannel();
|
||||||
|
|
||||||
eventChannel.on('detailData', function(data) {
|
eventChannel.on('detailData', function(data) {
|
||||||
@ -346,7 +311,10 @@
|
|||||||
these.formData.img = device.devicePic;
|
these.formData.img = device.devicePic;
|
||||||
these.formData.id = device.id;
|
these.formData.id = device.id;
|
||||||
these.formData.deviceId = f.deviceId;
|
these.formData.deviceId = f.deviceId;
|
||||||
ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId);
|
ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId).then(res=>{
|
||||||
|
console.log("连接成功")
|
||||||
|
these.formData.bleStatu=true;
|
||||||
|
});
|
||||||
these.setBleFormData();
|
these.setBleFormData();
|
||||||
these.getDetail();
|
these.getDetail();
|
||||||
|
|
||||||
@ -355,12 +323,11 @@
|
|||||||
|
|
||||||
},
|
},
|
||||||
onHide: function() {
|
onHide: function() {
|
||||||
|
this.Status.pageHide = true;
|
||||||
|
console.log("页面隐藏");
|
||||||
},
|
},
|
||||||
onBackPress(e) {
|
onShow: function() {
|
||||||
|
this.Status.pageHide = false;
|
||||||
ble.removeReceiveCallback();
|
|
||||||
|
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
RSSIRemark: function() {
|
RSSIRemark: function() {
|
||||||
@ -410,6 +377,85 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
deviceRecovry(res){
|
||||||
|
if(this.Status.pageHide){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(res.deviceId==these.formData.deviceId){
|
||||||
|
this.formData.bleStatu=true;
|
||||||
|
setTimeout(()=>{
|
||||||
|
hideLoading(these,1000);
|
||||||
|
});
|
||||||
|
uni.showToast({
|
||||||
|
icon:'success',
|
||||||
|
title:'蓝牙连接成功'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
},
|
||||||
|
deviceDispose(res){
|
||||||
|
if(this.Status.pageHide){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(res.deviceId==these.formData.deviceId){
|
||||||
|
this.formData.bleStatu=false;
|
||||||
|
setTimeout(()=>{
|
||||||
|
hideLoading(these,1000);
|
||||||
|
});
|
||||||
|
uni.showToast({
|
||||||
|
icon:'fail',
|
||||||
|
title:'蓝牙连接已断开'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
},
|
||||||
|
bleStateBreak() {
|
||||||
|
if(this.Status.pageHide){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//蓝牙适配器不可用
|
||||||
|
this.formData.bleStatu = false;
|
||||||
|
uni.showToast({
|
||||||
|
icon: 'fail',
|
||||||
|
title: '蓝牙已不可用'
|
||||||
|
})
|
||||||
|
hideLoading(this);
|
||||||
|
},
|
||||||
|
bleStateRecovry() {
|
||||||
|
console.log("蓝牙可用");
|
||||||
|
if(this.Status.pageHide){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
console.log("蓝牙可用");
|
||||||
|
//蓝牙适配器再次可用,尝试恢复连接
|
||||||
|
showLoading(this, {
|
||||||
|
text: "蓝牙恢复可用,正在连接设备"
|
||||||
|
});
|
||||||
|
ble.LinkBlue(these.formData.deviceId).then(() => {
|
||||||
|
these.formData.bleStatu = true;
|
||||||
|
updateLoading(these,{
|
||||||
|
text:'连接成功'
|
||||||
|
});
|
||||||
|
}).catch(ex => {
|
||||||
|
updateLoading(these, {
|
||||||
|
text: ex.msg
|
||||||
|
})
|
||||||
|
}).finally(() => {
|
||||||
|
setTimeout(() => {
|
||||||
|
hideLoading(these);
|
||||||
|
}, 1000);
|
||||||
|
|
||||||
|
});
|
||||||
|
},
|
||||||
|
previewImg(img) {
|
||||||
|
if (!img) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
uni.previewImage({
|
||||||
|
urls: [img]
|
||||||
|
})
|
||||||
|
},
|
||||||
getDevice: function() {
|
getDevice: function() {
|
||||||
// console.log("LinkedList=", ble.data.LinkedList);
|
// console.log("LinkedList=", ble.data.LinkedList);
|
||||||
// console.log("formData=", these.formData);
|
// console.log("formData=", these.formData);
|
||||||
@ -420,87 +466,27 @@
|
|||||||
return f;
|
return f;
|
||||||
},
|
},
|
||||||
bleValueNotify: function(receive, device, path) {
|
bleValueNotify: function(receive, device, path) {
|
||||||
|
if (this.Status.pageHide) {
|
||||||
let str = recei.ReceiveData(receive, device, path);
|
return;
|
||||||
|
}
|
||||||
console.log("处理接收到的数据:" + str);
|
let json = recei.ReceiveData(receive, device, path);
|
||||||
return;
|
if (!json) {
|
||||||
let data = recei.ReceiveData(receive, device, path);
|
return;
|
||||||
let bytes = receive.bytes;
|
}
|
||||||
|
let keys = Object.keys(json);
|
||||||
if (bytes[0] == 0xFB && bytes[1] == 0x64 && bytes.length >= 8) {
|
keys.forEach((key) => {
|
||||||
try {
|
if (key in these.formData) {
|
||||||
|
these.formData[key] = json[key];
|
||||||
let staticLevelByte = bytes[2];
|
|
||||||
let getName = function(type) {
|
|
||||||
let name = "";
|
|
||||||
switch (type) {
|
|
||||||
case 0x02:
|
|
||||||
name = '弱光';
|
|
||||||
break;
|
|
||||||
case 0x04:
|
|
||||||
name = '工作光';
|
|
||||||
break;
|
|
||||||
case 0x01:
|
|
||||||
name = '强光';
|
|
||||||
break;
|
|
||||||
case 0x03:
|
|
||||||
name = '爆闪';
|
|
||||||
break;
|
|
||||||
case 0x00:
|
|
||||||
name = '关闭';
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
let staticLevelText = getName(staticLevelByte);
|
|
||||||
|
|
||||||
// 解析照明档位
|
|
||||||
let lightingLevelByte = bytes[3];
|
|
||||||
let lightingLevelText = getName(lightingLevelByte);
|
|
||||||
|
|
||||||
|
|
||||||
// 解析剩余电量
|
|
||||||
let batteryLevelByte = bytes[4];
|
|
||||||
// 电量百分比范围检查
|
|
||||||
let batteryLevel = Math.max(0, Math.min(100, batteryLevelByte));
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//充电状态
|
|
||||||
let warn = bytes[5];
|
|
||||||
if (warn == 0x00) {
|
|
||||||
warn = '未充电';
|
|
||||||
} else if (warn == 0x01) {
|
|
||||||
warn = '充电中';
|
|
||||||
}
|
|
||||||
|
|
||||||
// 解析剩余照明时间(第三和第四字节,小端序)
|
|
||||||
let lightingTime = "";
|
|
||||||
let HH = Math.max(0, Math.min(100, bytes[6]));
|
|
||||||
let mm = Math.max(0, Math.min(100, bytes[7]));
|
|
||||||
lightingTime = HH + "小时" + mm + "分钟";
|
|
||||||
|
|
||||||
this.formData.mode = staticLevelText;
|
|
||||||
this.formData.fuMode = lightingLevelText;
|
|
||||||
this.formData.battary = batteryLevel;
|
|
||||||
this.formData.statu = warn;
|
|
||||||
this.formData.xuhang = lightingTime;
|
|
||||||
|
|
||||||
if (batteryLevel <= 20) {
|
|
||||||
this.showPop({
|
|
||||||
message: "设备电量低",
|
|
||||||
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
|
|
||||||
borderColor: "#e034344d",
|
|
||||||
buttonBgColor: "#E03434",
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
this.setBleFormData();
|
|
||||||
} catch (error) {
|
|
||||||
console.log('数据解析错误:', error);
|
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if ('battary' in json && this.formData.battary <= 20) {
|
||||||
|
this.showPop({
|
||||||
|
message: "设备电量低",
|
||||||
|
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
|
||||||
|
borderColor: "#e034344d",
|
||||||
|
buttonBgColor: "#E03434",
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
@ -544,6 +530,7 @@
|
|||||||
events: {
|
events: {
|
||||||
BindOver: function(data) {
|
BindOver: function(data) {
|
||||||
console.log(data)
|
console.log(data)
|
||||||
|
these.formData.bleStatu=true;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
success: function(res) {
|
success: function(res) {
|
||||||
@ -567,72 +554,18 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 处理像素数据并发送
|
|
||||||
var processAndSendImageData = function(pixels) {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
// 创建RGB565格式的像素数据
|
|
||||||
const arr = ble.convertToRGB565(pixels, 'bgr');
|
|
||||||
|
|
||||||
var list = [];
|
|
||||||
let index = 0; // 用于追踪arr的当前位置
|
|
||||||
let packetSize = 2048;
|
|
||||||
let cSize = 248;
|
|
||||||
// 外层循环:7个主要元素(i从1到7)
|
|
||||||
for (let i = 1; i < 8; i++) {
|
|
||||||
let secondLevel = [];
|
|
||||||
let secondCnt = 0;
|
|
||||||
// 中层循环:每个主要元素包含9个子数组(j从1到9)
|
|
||||||
for (let j = 1; j < 10; j++) {
|
|
||||||
// 确定当前子数组的长度:前8个是254,第9个是64
|
|
||||||
|
|
||||||
let thirdLevel = [];
|
|
||||||
|
|
||||||
// 从arr中提取相应数量的元素
|
|
||||||
for (let k = 0; k < cSize && index < arr.length; k++) {
|
|
||||||
|
|
||||||
if (secondCnt == packetSize) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
thirdLevel.push(arr[index]);
|
|
||||||
secondCnt++;
|
|
||||||
index++;
|
|
||||||
}
|
|
||||||
|
|
||||||
secondLevel.push(thirdLevel);
|
|
||||||
}
|
|
||||||
list.push(secondLevel);
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log("list=", list);
|
|
||||||
|
|
||||||
let length = 0;
|
|
||||||
for (let i = 0; i < list.length; i++) {
|
|
||||||
const item = list[i];
|
|
||||||
let clength = 0;
|
|
||||||
for (let j = 0; j < item.length; j++) {
|
|
||||||
const element = item[j];
|
|
||||||
console.log("第" + i + "包,第" + j + "小包,长度:" + element.length)
|
|
||||||
length += element.length;
|
|
||||||
clength += element.length;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// 分包发送
|
|
||||||
sendImagePackets(list).then(resolve).catch(reject);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// 分包发送图片数据
|
// 分包发送图片数据
|
||||||
var sendImagePackets = function(imageData) {
|
var sendImagePackets = function(packetData) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
|
||||||
// 总数据包数
|
// 总数据包数
|
||||||
const totalPackets = 7;
|
const totalPackets = 3;
|
||||||
let currentPacket = 1;
|
let currentPacket = 1;
|
||||||
let childPacket = 1;
|
|
||||||
let totalChildPacket = 9;
|
|
||||||
|
|
||||||
|
|
||||||
// 发送单个数据包
|
// 发送单个数据包
|
||||||
@ -650,65 +583,30 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
resolve();
|
resolve();
|
||||||
}, 20000)
|
}, 0)
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var packetData = imageData[currentPacket - 1][childPacket - 1];
|
|
||||||
// if (packetData.length == 0) {
|
|
||||||
// hideLoading(these);
|
|
||||||
// these.Status.BottomMenu.show = false;
|
|
||||||
|
|
||||||
// these.showPop({
|
|
||||||
// message: "上传成功",
|
|
||||||
// iconUrl: "/static/images/6155/DeviceDetail/uploadSuccess.png"
|
|
||||||
// });
|
|
||||||
|
|
||||||
// resolve();
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
let start = 0;
|
let start = 0;
|
||||||
let bufferSize = packetData.length * 2;
|
let bufferSize = 343; //总共1029字节3包,正好每包343字节
|
||||||
|
//FA 09 04 00 1024字节 FF
|
||||||
if (currentPacket == 7) {
|
|
||||||
if (childPacket > 2 && childPacket < 9) {
|
|
||||||
bufferSize = 496;
|
|
||||||
} else if (childPacket == 9) {
|
|
||||||
bufferSize = 128;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (childPacket == 1) {
|
|
||||||
bufferSize = bufferSize + 8
|
|
||||||
start = 8;
|
|
||||||
}
|
|
||||||
if (childPacket == 9) { //|| (currentPacket==7 && childPacket==3
|
|
||||||
bufferSize = bufferSize + 1
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//FA 09 10 04 FC 09 [00] [01] + 4096字节+FF 数据格式
|
|
||||||
var buffer = new ArrayBuffer(bufferSize);
|
var buffer = new ArrayBuffer(bufferSize);
|
||||||
var dataView = new DataView(buffer);
|
var dataView = new DataView(buffer);
|
||||||
if (childPacket == 1) {
|
if (currentPacket == 1) {
|
||||||
dataView.setUint8(0, 0xFA); // 帧头
|
dataView.setUint8(0, 0xFA); // 帧头
|
||||||
dataView.setUint8(1, 0x09); // 帧头
|
dataView.setUint8(1, 0x09); // 帧头
|
||||||
dataView.setUint8(2, 0x10); // 帧头
|
dataView.setUint8(2, 0x04); // 帧头
|
||||||
dataView.setUint8(3, 0x04); // 帧头
|
dataView.setUint8(3, 0x00); // 帧头
|
||||||
dataView.setUint8(4, 0xFC); // 帧头
|
|
||||||
dataView.setUint8(5, 0x09); // 帧头
|
|
||||||
|
|
||||||
dataView.setUint8(6, 0x00); // 图序号,图片固定0,视频的话要写序号
|
|
||||||
dataView.setUint8(7, currentPacket); //子包序号
|
|
||||||
}
|
|
||||||
|
|
||||||
for (let i = 0; i < packetData.length; i++) {
|
for (let i = 0; i < packetData.length; i++) {
|
||||||
dataView.setUint16(start + i * 2, packetData[i], false); //本包数据,大端字节序
|
dataView.setUint8(4 + i, parseInt(packetData[i], 16));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
console.log("packetData.length=", packetData.length);
|
if (currentPacket == totalPackets) {
|
||||||
console.log("bufferSize=", bufferSize)
|
|
||||||
if (childPacket == 9) { // || (currentPacket==7 && childPacket==3
|
|
||||||
dataView.setUint8(bufferSize - 1, 0xFF);
|
dataView.setUint8(bufferSize - 1, 0xFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -717,20 +615,12 @@
|
|||||||
30)
|
30)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
|
|
||||||
let curr = childPacket + (currentPacket - 1) *
|
|
||||||
totalChildPacket;
|
|
||||||
console.log("第" + currentPacket + "大包,第" + childPacket +
|
|
||||||
"小包发送完成,总计:" + curr);
|
|
||||||
updateLoading(these, {
|
updateLoading(these, {
|
||||||
text: "正在发送" + curr + "/63"
|
text: "正在发送" + currentPacket + "/" + totalPackets
|
||||||
|
|
||||||
})
|
})
|
||||||
if (childPacket == 9) {
|
currentPacket++;
|
||||||
currentPacket++;
|
|
||||||
childPacket = 1;
|
|
||||||
} else {
|
|
||||||
childPacket++;
|
|
||||||
}
|
|
||||||
|
|
||||||
setTimeout(sendNextPacket, 100);
|
setTimeout(sendNextPacket, 100);
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
@ -756,6 +646,7 @@
|
|||||||
// 开始发送数据
|
// 开始发送数据
|
||||||
sendNextPacket();
|
sendNextPacket();
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -769,16 +660,115 @@
|
|||||||
url: "/pages/6155/ImgCrop",
|
url: "/pages/6155/ImgCrop",
|
||||||
events: {
|
events: {
|
||||||
ImgCutOver: function(data) {
|
ImgCutOver: function(data) {
|
||||||
|
//将8位的二进制数组转换成16进制数据
|
||||||
|
let binaryToHex = (binaryArray) => {
|
||||||
|
if (!Array.isArray(binaryArray) || binaryArray
|
||||||
|
.length !== 8) {
|
||||||
|
throw new Error("输入必须是包含8个元素的二进制数组");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查每个元素是否为0或1
|
||||||
|
if (!binaryArray.every(bit => bit === 0 || bit ===
|
||||||
|
1)) {
|
||||||
|
throw new Error("数组元素必须只能是0或1");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 将二进制数组转换为十进制数
|
||||||
|
let decimalValue = 0;
|
||||||
|
for (let i = 0; i < 8; i++) {
|
||||||
|
// 计算每个位的权重并累加
|
||||||
|
decimalValue += binaryArray[i] * Math.pow(2,
|
||||||
|
7 - i);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 将十进制转换为十六进制字符串,并添加0x前缀
|
||||||
|
const hexString = "0x" + decimalValue.toString(16)
|
||||||
|
.padStart(2, '0').toUpperCase();
|
||||||
|
|
||||||
|
return hexString;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
let imageData = data.piexls;
|
||||||
|
let arr = [];
|
||||||
|
|
||||||
|
for (let currIndex = 0; currIndex < imageData
|
||||||
|
.length; currIndex += 4) {
|
||||||
|
let R = imageData[currIndex];
|
||||||
|
let G = imageData[currIndex + 1];
|
||||||
|
let B = imageData[currIndex + 2];
|
||||||
|
let A = imageData[currIndex + 3];
|
||||||
|
let grayVal = Math.floor(R * 0.299 + G * 0.587 + B *
|
||||||
|
0.114);
|
||||||
|
arr.push(grayVal < 128 ? 1 : 0);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
let f = arr.filter(v => {
|
||||||
|
return v === 1;
|
||||||
|
});
|
||||||
|
//如果有超过1/3的亮点,将进行反色处理
|
||||||
|
if (f.length > arr.length / 3) {
|
||||||
|
for (var r = 0; r < arr.length; r++) {
|
||||||
|
if (arr[r] === 0) {
|
||||||
|
arr[r] = 1;
|
||||||
|
} else {
|
||||||
|
arr[r] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// console.log("arr=", JSON.stringify(arr));
|
||||||
|
|
||||||
|
let matrix = [];
|
||||||
|
let size = 512;
|
||||||
|
let len = arr.length / size;
|
||||||
|
for (let j = 0; j < len; j++) {
|
||||||
|
let start = j * size;
|
||||||
|
let end = start + size;
|
||||||
|
|
||||||
|
let firstHalf = arr.slice(start, end);
|
||||||
|
|
||||||
|
let arr64 = [];
|
||||||
|
for (let row = 0; row < 8; row++) {
|
||||||
|
|
||||||
|
for (let col = 0; col < 64; col++) {
|
||||||
|
let ind = col + row * 64;
|
||||||
|
if (col === 63) {
|
||||||
|
|
||||||
|
}
|
||||||
|
let val = firstHalf[ind];
|
||||||
|
if (arr64.length < col + 1) {
|
||||||
|
arr64.push([])
|
||||||
|
}
|
||||||
|
|
||||||
|
arr64[col].push(val);
|
||||||
|
|
||||||
|
if (arr64[col].length === 8) {
|
||||||
|
|
||||||
|
arr64[col] = arr64[col].reverse();
|
||||||
|
matrix.push(binaryToHex(arr64[col]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log("matrix=", JSON.stringify(matrix));
|
||||||
|
|
||||||
|
|
||||||
showLoading(these, {
|
showLoading(these, {
|
||||||
text: "正在发送0/52"
|
text: "正在发送0/3"
|
||||||
});
|
});
|
||||||
|
|
||||||
these.Status.BottomMenu.show = false;
|
these.Status.BottomMenu.show = false;
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
processAndSendImageData(data.piexls).catch((
|
sendImagePackets(matrix).catch((
|
||||||
ex) => {
|
ex) => {
|
||||||
console.log("出现异常", ex);
|
console.log("出现异常", ex);
|
||||||
|
hideLoading(these);
|
||||||
|
|
||||||
});
|
});
|
||||||
}, 0)
|
}, 0)
|
||||||
|
|
||||||
@ -786,7 +776,10 @@
|
|||||||
},
|
},
|
||||||
success(ev) {
|
success(ev) {
|
||||||
ev.eventChannel.emit('checkImg', {
|
ev.eventChannel.emit('checkImg', {
|
||||||
data: res.tempFiles[0].path
|
data: res.tempFiles[0].path,
|
||||||
|
width: 64,
|
||||||
|
height: 32,
|
||||||
|
times: 10
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
fail(ex) {
|
fail(ex) {
|
||||||
@ -927,7 +920,7 @@
|
|||||||
text: "请稍候..."
|
text: "请稍候..."
|
||||||
});
|
});
|
||||||
|
|
||||||
ble.sendData(f.deviceId, buffer, f.writeServiceId, f.wirteCharactId, 30).then(() => {
|
ble.sendData(f.deviceId, buffer, f.writeServiceId, f.wirteCharactId, 100).then(() => {
|
||||||
this.formData.mode = mode;
|
this.formData.mode = mode;
|
||||||
this.setBleFormData();
|
this.setBleFormData();
|
||||||
}).catch((ex) => {
|
}).catch((ex) => {
|
||||||
@ -973,12 +966,12 @@
|
|||||||
|
|
||||||
},
|
},
|
||||||
closePop: function() {
|
closePop: function() {
|
||||||
this.Status.Pop.showPop = false;
|
this.Status.Pop.showPop = false;
|
||||||
|
|
||||||
if (this.Status.Pop.cancelCallback) {
|
if (this.Status.Pop.cancelCallback) {
|
||||||
this.Status.Pop.cancelCallback();
|
this.Status.Pop.cancelCallback();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
HidePop: function() {
|
HidePop: function() {
|
||||||
console.log("1111");
|
console.log("1111");
|
||||||
if (this.Status.Pop.clickEvt == 'SendUsr') {
|
if (this.Status.Pop.clickEvt == 'SendUsr') {
|
||||||
@ -1091,7 +1084,7 @@
|
|||||||
let inteval = parseInt(this.inteval ? this.inteval : 50);
|
let inteval = parseInt(this.inteval ? this.inteval : 50);
|
||||||
console.log("inteval=", inteval)
|
console.log("inteval=", inteval)
|
||||||
ble.sendData(f.deviceId, buffer, f.writeServiceId, f
|
ble.sendData(f.deviceId, buffer, f.writeServiceId, f
|
||||||
.wirteCharactId, 30).then(() => {
|
.wirteCharactId, 100).then(() => {
|
||||||
|
|
||||||
curr++;
|
curr++;
|
||||||
setTimeout(sendNext, inteval);
|
setTimeout(sendNext, inteval);
|
||||||
@ -1135,21 +1128,6 @@
|
|||||||
return level1.flat(Infinity);
|
return level1.flat(Infinity);
|
||||||
});
|
});
|
||||||
console.log("result=", result);
|
console.log("result=", result);
|
||||||
|
|
||||||
// var str1="FA 06 01 00 FF FF F7 9F EF 6F EC F7 EA 09 CF FF AF FB EF EB EF EB EC 6B EF EB EC 6B EF EB EF FB EE 63 FF FF FF FF F7 9F EF 6F EC F7 EA 09 CF FF AF FB EF EB EF EB EC 6B EF EB EC 6B EF EB EF FB EE 63 FF FF FF FF F7 FF 81 03 ED BB DD B7 CB CF F3 C7 CD 39 BE FF FE FF C0 03 FE FB FD FB F3 F7 8F 87 FF FF FF FF FE FF FE FF FE FF C0 03 FF FB FD FB FD FB FD FB FD FB FB FB FB FF F7 F7 EF F7 9F 8F FF FF 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 FF"
|
|
||||||
// var str2="FA 07 01 00 FF FF EE DD EE DF EF 5B AB DF AA 03 AE FF AE FF EE 03 EE FF EE FF EE 03 EE FF EE FF EE E3 FF FF FF FF EE DD EE DF EF 5B AB DF AA 03 AE FF AE FF EE 03 EE FF EE FF EE 03 EE FF EE FF EE E3 FF FF FF FF EF 77 EF 73 EF 7F 80 01 EF 7F EF 7F EF 03 E7 3B 8E BB EE D7 EE EF ED E7 ED 9B 8B 7D FF FF FF FF FF FF F7 EF F7 F7 EF F7 DF FB FF FF FF FF FE FF 80 01 FE 7F FD BF FB DF F7 E7 9F F9 FF FF 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 FF"
|
|
||||||
// var str3="FA 08 01 00 FF FF EF DF EC 01 EF FF AB FF AA 03 AA FB AE FB EE 03 EF DF EF DF EE DB ED DF ED DD EF 1F FF FF FF FF EF BF EF 87 81 77 EE F7 EC 03 81 7F EF 7F EF 7F EF 03 81 7F EF 7F EF 7D EF 7D EF 03 FF FF FF FF F9 F1 CF BF DF FF DF FF C1 FF DD 81 DD F7 DD F7 C1 F7 DF 77 FF 77 BF 77 BF 77 FF F7 FF FF FF FF FD FF FD FF FB FF FB FF F0 07 E7 F7 EF F7 D8 07 BF F7 FF F7 F8 07 FF F7 FF F7 FF C7 FF FF FF FF FF FF FF FF FF FF FE FF FE 7F FE 7F FE FF FD BF FD FF FB DF F7 EF EF F7 DF FB BF FD FF FF 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 FF"
|
|
||||||
|
|
||||||
// let arr1=('0x'+(str1.split(' ').join(",0x"))).split(',');
|
|
||||||
// let arr2=('0x'+(str2.split(' ').join(",0x"))).split(',');
|
|
||||||
// let arr3=('0x'+(str3.split(' ').join(",0x"))).split(',');
|
|
||||||
|
|
||||||
// result=[arr1,arr2,arr3];
|
|
||||||
|
|
||||||
|
|
||||||
// console.log("result=",result);
|
|
||||||
|
|
||||||
|
|
||||||
let h3dic = [0x06, 0x07, 0x08];
|
let h3dic = [0x06, 0x07, 0x08];
|
||||||
let pros = [];
|
let pros = [];
|
||||||
let flag = true;
|
let flag = true;
|
||||||
@ -1259,7 +1237,14 @@
|
|||||||
if (f) {
|
if (f) {
|
||||||
// 发送数据
|
// 发送数据
|
||||||
|
|
||||||
ble.sendData(f.deviceId, buffer, f.writeServiceId, f.wirteCharactId, 30);
|
ble.sendData(f.deviceId, buffer, f.writeServiceId, f.wirteCharactId, 100).catch(ex=>{
|
||||||
|
these.showPop({
|
||||||
|
message: "发送失败," + ex.msg,
|
||||||
|
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
|
||||||
|
borderColor: "#e034344d",
|
||||||
|
buttonBgColor: "#E03434",
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1301,7 +1286,14 @@
|
|||||||
if (f) {
|
if (f) {
|
||||||
// 发送数据
|
// 发送数据
|
||||||
|
|
||||||
ble.sendData(f.deviceId, buffer, f.writeServiceId, f.wirteCharactId, 30);
|
ble.sendData(f.deviceId, buffer, f.writeServiceId, f.wirteCharactId, 100).catch(ex=>{
|
||||||
|
these.showPop({
|
||||||
|
message: "发送失败," + ex.msg,
|
||||||
|
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
|
||||||
|
borderColor: "#e034344d",
|
||||||
|
buttonBgColor: "#E03434",
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -1489,6 +1481,7 @@
|
|||||||
letter-spacing: 0.07px;
|
letter-spacing: 0.07px;
|
||||||
text-align: left;
|
text-align: left;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
.lamp {
|
.lamp {
|
||||||
margin-top: 24rpx;
|
margin-top: 24rpx;
|
||||||
|
|||||||
@ -46,14 +46,14 @@
|
|||||||
var these = null;
|
var these = null;
|
||||||
var eventChannel = null;
|
var eventChannel = null;
|
||||||
var ble = null;
|
var ble = null;
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
Statu: {
|
Statu: {
|
||||||
bound: null,
|
bound: null,
|
||||||
timeInteval:null,
|
timeInteval: null,
|
||||||
isSearch:false
|
isSearch: false
|
||||||
},
|
},
|
||||||
device: {
|
device: {
|
||||||
"deviceId": "",
|
"deviceId": "",
|
||||||
@ -64,12 +64,12 @@
|
|||||||
"advertisServiceUUIDs": [
|
"advertisServiceUUIDs": [
|
||||||
|
|
||||||
],
|
],
|
||||||
"linkStatu": false,
|
"linkStatu": true,
|
||||||
"macAddress": "",
|
"macAddress": "",
|
||||||
"communicationMode":"",
|
"communicationMode": "",
|
||||||
"imei":""
|
"imei": ""
|
||||||
},
|
},
|
||||||
serverDevice:null
|
serverDevice: null
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
@ -83,51 +83,84 @@
|
|||||||
return "red";
|
return "red";
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
deviceStatu:function(){
|
deviceStatu: function() {
|
||||||
if(!this.device.name){
|
if (!this.device.name) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
if(!this.device.macAddress){
|
if (!this.device.linkStatu) {
|
||||||
|
return "蓝牙未连接";
|
||||||
|
}
|
||||||
|
if (!this.device.macAddress) {
|
||||||
return '等待设备上报Mac地址';
|
return '等待设备上报Mac地址';
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!this.device.deviceName ){
|
if (!this.device.deviceName) {
|
||||||
if(this.Statu.isSearch){
|
if (this.Statu.isSearch) {
|
||||||
return "无效设备";
|
return "无效设备";
|
||||||
}else{
|
} else {
|
||||||
if(this.Statu.timeInteval===null){
|
if (this.Statu.timeInteval === null) {
|
||||||
return "等待查询设备"
|
return "等待查询设备"
|
||||||
}else{
|
} else {
|
||||||
return "正在查询设备";
|
return "正在查询设备";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}else{
|
} else {
|
||||||
return "找到有效设备"
|
return "找到有效设备"
|
||||||
}
|
}
|
||||||
|
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
onUnload() {
|
onUnload() {
|
||||||
console.log("返回时断开蓝牙连接,取消订阅");
|
console.log("返回取消订阅");
|
||||||
|
|
||||||
ble.removeReceiveCallback(pagePath);
|
ble.removeAllCallback(pagePath);
|
||||||
},
|
},
|
||||||
onLoad(option) {
|
onLoad(option) {
|
||||||
these = this;
|
these = this;
|
||||||
ble = bleTool.getBleTool();
|
ble = bleTool.getBleTool();
|
||||||
console.log("LinkBle")
|
|
||||||
|
ble.addStateBreakCallback(res => {
|
||||||
|
these.device.linkStatu = false;
|
||||||
|
hideLoading(these);
|
||||||
|
uni.showToast({
|
||||||
|
icon:'fail',
|
||||||
|
title:'蓝牙已不可用'
|
||||||
|
})
|
||||||
|
},pagePath);
|
||||||
|
|
||||||
|
ble.addStateRecoveryCallback(res => {
|
||||||
|
if (these.device.deviceId) {
|
||||||
|
showLoading(these, {
|
||||||
|
text: '蓝牙已恢复正在连接设备'
|
||||||
|
});
|
||||||
|
|
||||||
|
these.reLinkdevice();
|
||||||
|
}
|
||||||
|
},pagePath);
|
||||||
|
ble.addDisposeCallback(res => {
|
||||||
|
console.log("处理蓝牙断开连接");
|
||||||
|
these.device.linkStatu = false;
|
||||||
|
if (these.device.deviceId == res.deviceId) {
|
||||||
|
|
||||||
|
showLoading(these, {
|
||||||
|
text: '蓝牙已断开,正在重连'
|
||||||
|
});
|
||||||
|
these.reLinkdevice();
|
||||||
|
}
|
||||||
|
},pagePath);
|
||||||
|
|
||||||
ble.addReceiveCallback((receive, f, path) => {
|
ble.addReceiveCallback((receive, f, path) => {
|
||||||
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);
|
||||||
these.device.imei=f.imei;
|
these.device.imei = f.imei;
|
||||||
if (receive.bytes[0] == 0xFC || receive.str.indexOf('mac address:') == 0) {
|
if (receive.bytes[0] == 0xFC || receive.str.indexOf('mac address:') == 0) {
|
||||||
if (f && f.macAddress) {
|
if (f && f.macAddress) {
|
||||||
these.device.macAddress = f.macAddress;
|
these.device.macAddress = f.macAddress;
|
||||||
console.log("222222");
|
console.log("222222");
|
||||||
these.Statu.isSearch=false;
|
these.Statu.isSearch = false;
|
||||||
these.initDevice();
|
these.initDevice();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -157,19 +190,41 @@
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
let inteval = setInterval(this.initDevice, 5000);
|
let inteval = setInterval(this.initDevice, 10000);
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
reLinkdevice() {
|
||||||
|
ble.LinkBlue(these.device.deviceId).then(res => {
|
||||||
|
updateLoading(these, {
|
||||||
|
text: '连接成功'
|
||||||
|
});
|
||||||
|
these.device.linkStatu = true;
|
||||||
|
setTimeout(() => {
|
||||||
|
hideLoading(these);
|
||||||
|
}, 2000);
|
||||||
|
}).catch(ex => {
|
||||||
|
updateLoading(these, {
|
||||||
|
text: ex.msg
|
||||||
|
});
|
||||||
|
setTimeout(() => {
|
||||||
|
hideLoading(these);
|
||||||
|
}, 2000);
|
||||||
|
});
|
||||||
|
},
|
||||||
initDevice: function() {
|
initDevice: function() {
|
||||||
if(!these.device.macAddress){
|
if (!these.device.macAddress) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
//无效的设备回调
|
||||||
|
let deviceInvalid = () => {
|
||||||
|
|
||||||
|
these.$set(these.device, "deviceName", "");
|
||||||
|
|
||||||
|
}
|
||||||
clearTimeout(this.Statu.timeInteval);
|
clearTimeout(this.Statu.timeInteval);
|
||||||
|
|
||||||
this.Statu.timeInteval = setTimeout(() => {
|
this.Statu.timeInteval = setTimeout(() => {
|
||||||
this.Statu.isSearch=true;
|
this.Statu.isSearch = true;
|
||||||
showLoading(these, {
|
showLoading(these, {
|
||||||
text: '正在获取设备信息'
|
text: '正在获取设备信息'
|
||||||
});
|
});
|
||||||
@ -181,45 +236,34 @@
|
|||||||
deviceMac: these.device.macAddress
|
deviceMac: these.device.macAddress
|
||||||
}
|
}
|
||||||
}).then(res => {
|
}).then(res => {
|
||||||
|
|
||||||
// console.log("获取设备信息", res);
|
console.log("获取设备信息", res);
|
||||||
if (res && res.code == 200) {
|
if (res && res.code == 200) {
|
||||||
|
console.log("res=", res);
|
||||||
let data = res.data;
|
let data = res.data;
|
||||||
this.serverDevice=data;
|
this.serverDevice = data;
|
||||||
if (data) {
|
if (data) {
|
||||||
let keys = Object.keys(data);
|
let keys = Object.keys(data);
|
||||||
ble.data.LinkedList.find((v) => {
|
ble.data.LinkedList.find((v) => {
|
||||||
if (v.deviceId == these.device.deviceId) {
|
if (v.deviceId == these.device.deviceId) {
|
||||||
for (var i = 0; i < keys.length; i++) {
|
for (var i = 0; i < keys.length; i++) {
|
||||||
let key = keys[i];
|
let key = keys[i];
|
||||||
// if(!v.device){
|
|
||||||
// v.device={};
|
|
||||||
// }
|
|
||||||
// v.device[key] = data[key];
|
|
||||||
// console.log("key="+key);
|
|
||||||
// console.log("value="+data[key]);
|
|
||||||
|
|
||||||
|
|
||||||
these.$set(these.device, key, data[key]);
|
these.$set(these.device, key, data[key]);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ble.setBleData();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
// console.log("device=", these.device);
|
deviceInvalid();
|
||||||
// console.log("LinkedList=", ble.data.LinkedList);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
deviceInvalid();
|
||||||
}
|
}
|
||||||
|
|
||||||
}).catch((ex) => {
|
}).catch((ex) => {
|
||||||
console.error("获取设备出现异常:", ex);
|
console.error("获取设备出现异常:", ex);
|
||||||
}).finally(() => {
|
}).finally(() => {
|
||||||
this.Statu.timeInteval=null;
|
this.Statu.timeInteval = null;
|
||||||
this.Statu.isSearch=false;
|
this.Statu.isSearch = false;
|
||||||
hideLoading(these);
|
hideLoading(these);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -242,7 +286,7 @@
|
|||||||
these.Statu.boundRemark = "设备上报Mac地址异常";
|
these.Statu.boundRemark = "设备上报Mac地址异常";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(!this.device.deviceName){
|
if (!this.device.deviceName) {
|
||||||
these.Statu.bound = false;
|
these.Statu.bound = false;
|
||||||
these.Statu.boundRemark = "设备未入库";
|
these.Statu.boundRemark = "设备未入库";
|
||||||
return;
|
return;
|
||||||
@ -267,25 +311,26 @@
|
|||||||
if (res.code == 200) {
|
if (res.code == 200) {
|
||||||
these.Statu.bound = true;
|
these.Statu.bound = true;
|
||||||
these.Statu.boundRemark = "设备绑定成功!";
|
these.Statu.boundRemark = "设备绑定成功!";
|
||||||
let data=these.serverDevice;
|
let data = these.serverDevice;
|
||||||
let keys = Object.keys(data);
|
let keys = Object.keys(data);
|
||||||
ble.data.LinkedList.find((v) => {
|
ble.data.LinkedList.find((v) => {
|
||||||
if (v.deviceId == these.device.deviceId) {
|
if (v.deviceId == these.device.deviceId) {
|
||||||
for (var i = 0; i < keys.length; i++) {
|
for (var i = 0; i < keys.length; i++) {
|
||||||
let key = keys[i];
|
let key = keys[i];
|
||||||
if(!v.device){
|
if (!v.device) {
|
||||||
v.device={};
|
v.device = {};
|
||||||
}
|
}
|
||||||
v.device[key] = data[key];
|
v.device[key] = data[key];
|
||||||
}
|
}
|
||||||
|
|
||||||
ble.updateCache();
|
ble.updateCache();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
ble.removeReceiveCallback(pagePath);
|
ble.removeReceiveCallback(pagePath);
|
||||||
clearTimeout(this.Statu.timeInteval);
|
clearTimeout(this.Statu.timeInteval);
|
||||||
this.Statu.timeInteval=null;
|
this.device.macAddress = null;
|
||||||
|
this.Statu.timeInteval = null;
|
||||||
uni.$emit("refreshDeviceList");
|
uni.$emit("refreshDeviceList");
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
uni.switchTab({
|
uni.switchTab({
|
||||||
@ -299,7 +344,7 @@
|
|||||||
}).catch((ex) => {
|
}).catch((ex) => {
|
||||||
these.Statu.bound = false;
|
these.Statu.bound = false;
|
||||||
these.Statu.boundRemark = '出现了未知的异常,操作失败';
|
these.Statu.boundRemark = '出现了未知的异常,操作失败';
|
||||||
console.log("ex=",ex);
|
console.log("ex=", ex);
|
||||||
}).finally(() => {
|
}).finally(() => {
|
||||||
hideLoading(this);
|
hideLoading(this);
|
||||||
});
|
});
|
||||||
|
|||||||
@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
<view class="imgContent center">
|
<view class="imgContent center">
|
||||||
<view class="img center">
|
<view class="img center">
|
||||||
<image src="/static/images/common/bluetooth.png" class="titleIco" mode="aspectFit">
|
<image src="/static/images/BLEAdd/bluetooth.png" class="titleIco" mode="aspectFit">
|
||||||
</image>
|
</image>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
@ -32,7 +32,9 @@
|
|||||||
</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" v-text="item.deviceId"></view>
|
<view class="id">
|
||||||
|
<text>信号:{{110+item.RSSI>100?100:110+item.RSSI}}%</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">
|
||||||
@ -44,19 +46,33 @@
|
|||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<view class="lblTitle">搜索设备</view>
|
<view class="lblTitle">
|
||||||
|
<text>搜索设备</text>
|
||||||
|
<view @click="refreshBleList()">刷新</view>
|
||||||
|
</view>
|
||||||
<view class="list searchList">
|
<view class="list searchList">
|
||||||
<view class="item" v-on:click="Link(item,index)" v-for="item, index in EquipMents"
|
<view class="item" v-on:click="Link(item,index)" v-for="item, index in EquipMents"
|
||||||
v-show="!item['linkStatu']">
|
v-show="!item['linkStatu']">
|
||||||
|
<view class="before" v-if="item.isTarget"></view>
|
||||||
<view class="leftImg ">
|
<view class="leftImg ">
|
||||||
<image src="/static/images/common/bluetooth.png" class="titleIco" mode="heightFix">
|
<image src="/static/images/BLEAdd/bluetooth.png" class="titleIco" mode="heightFix">
|
||||||
</image>
|
</image>
|
||||||
</view>
|
</view>
|
||||||
<view class="centertxt ">
|
<view class="centertxt ">
|
||||||
<view class="name" v-text="item.name?item.name:'Unnamed'"></view>
|
<view class="name">
|
||||||
<view class="id" v-text="item.deviceId"></view>
|
<text>{{item.name?item.name:'Unnamed'}}</text>
|
||||||
|
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<view class="id">
|
||||||
|
<text>信号:{{110+item.RSSI>100?100:110+item.RSSI}}%</text>
|
||||||
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<view class="rightIco center">
|
<view class="rightIco center">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<image :src="isItemLink(item,index)" class="img" mode="aspectFit">
|
<image :src="isItemLink(item,index)" class="img" mode="aspectFit">
|
||||||
</image>
|
</image>
|
||||||
</view>
|
</view>
|
||||||
@ -102,6 +118,7 @@
|
|||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
Status: {
|
Status: {
|
||||||
|
isPageHidden: false,
|
||||||
intval: null,
|
intval: null,
|
||||||
time: null,
|
time: null,
|
||||||
BottomMenu: {
|
BottomMenu: {
|
||||||
@ -142,87 +159,248 @@
|
|||||||
|
|
||||||
},
|
},
|
||||||
onHide: function() {
|
onHide: function() {
|
||||||
|
this.Status.isPageHidden = true;
|
||||||
ble.StopSearch();
|
ble.StopSearch();
|
||||||
},
|
},
|
||||||
|
|
||||||
onUnload() {
|
onUnload() {
|
||||||
ble.StopSearch();
|
ble.StopSearch();
|
||||||
ble.removeDeviceFound(pagePath);
|
ble.removeAllCallback(pagePath);
|
||||||
ble.removeReceiveCallback(pagePath);
|
|
||||||
},
|
},
|
||||||
onLoad() {
|
onLoad(option) {
|
||||||
|
let search = option.search;
|
||||||
these = this;
|
these = this;
|
||||||
this.EquipMents = [];
|
|
||||||
ble = bleTool.getBleTool();
|
|
||||||
|
|
||||||
ble.addDeviceFound((arr) => {
|
|
||||||
|
|
||||||
arr = arr.devices;
|
|
||||||
for (var i = 0; i < arr.length; i++) {
|
|
||||||
|
|
||||||
arr[i].linkStatu = false;
|
|
||||||
if (!arr[i].name) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
let f = these.EquipMents.find(function(v) {
|
|
||||||
return v.deviceId == arr[i].deviceId;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!f) {
|
|
||||||
|
|
||||||
these.EquipMents.push(arr[i]);
|
|
||||||
} else {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// console.log("equip=", these.EquipMents)
|
|
||||||
}, pagePath);
|
|
||||||
// console.log("addEquip")
|
|
||||||
ble.addReceiveCallback((receivData, f, path, arr) => {
|
|
||||||
if (f.macAddress && these.device) {
|
|
||||||
clearInterval(this.Status.intval);
|
|
||||||
this.Status.intval = null;
|
|
||||||
this.Status.time = null;
|
|
||||||
|
|
||||||
showLoading(these, {
|
|
||||||
text: '正在验证设备'
|
|
||||||
});
|
|
||||||
|
|
||||||
setTimeout(() => {
|
|
||||||
these.DeviceVerdict(f.deviceId);
|
|
||||||
}, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}, pagePath);
|
|
||||||
eventChannel = this.getOpenerEventChannel();
|
eventChannel = this.getOpenerEventChannel();
|
||||||
|
// this.EquipMents = [{
|
||||||
|
// "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
|
||||||
|
// }
|
||||||
|
// ];
|
||||||
|
|
||||||
|
|
||||||
|
let StartSubsrib = () => {
|
||||||
|
these.EquipMents = [];
|
||||||
|
ble = bleTool.getBleTool();
|
||||||
|
//蓝牙不可用的回调
|
||||||
|
ble.addStateBreakCallback(res=>{
|
||||||
|
if (these.Status.isPageHidden) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
console.log("处理蓝牙不可用");
|
||||||
|
hideLoading(these);
|
||||||
|
these.PairEquip=[];
|
||||||
|
these.EquipMents=[];
|
||||||
|
uni.showToast({
|
||||||
|
icon:'fail',
|
||||||
|
title:'蓝牙已不可用'
|
||||||
|
});
|
||||||
|
these.showOpenSetting();
|
||||||
|
|
||||||
|
},pagePath);
|
||||||
|
//蓝牙再次可用的回调
|
||||||
|
ble.addStateRecoveryCallback(res=>{
|
||||||
|
if (these.Status.isPageHidden) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
uni.showToast({
|
||||||
|
icon:'success',
|
||||||
|
title:'蓝牙恢复可用'
|
||||||
|
});
|
||||||
|
these.Status.BottomMenu.show = false;
|
||||||
|
these.EquipMents=[];
|
||||||
|
these.refreshBleList();
|
||||||
|
},pagePath);
|
||||||
|
|
||||||
|
//蓝牙断开连接的回调
|
||||||
|
ble.addDisposeCallback(res => {
|
||||||
|
if (these.Status.isPageHidden) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
console.log("处理蓝牙断开连接");
|
||||||
|
hideLoading(these);
|
||||||
|
|
||||||
|
these.PairEquip.find(function(v, ind) {
|
||||||
|
these.PairEquip.splice(ind, 1);
|
||||||
|
return v.deviceId == res.deviceId;
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
}, pagePath);
|
||||||
|
//蓝牙连接已恢复的回调
|
||||||
|
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.addDeviceFound((arr) => {
|
||||||
|
if (these.Status.isPageHidden) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
arr = arr.devices;
|
||||||
|
|
||||||
|
for (var i = 0; i < arr.length; i++) {
|
||||||
|
|
||||||
|
arr[i].linkStatu = false;
|
||||||
|
if (!arr[i].name) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
let f = these.EquipMents.find((v, index) => {
|
||||||
|
if (v.deviceId == arr[i].deviceId) {
|
||||||
|
|
||||||
|
these.$set(these.EquipMents[index], 'RSSI', arr[i].RSSI);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!f) {
|
||||||
|
console.log("发现新设备,", arr[i]);
|
||||||
|
|
||||||
|
if (these.device && these.device.bluetoothName) {
|
||||||
|
if (these.device.bluetoothName === arr[i].name || arr[i].name.indexOf(these
|
||||||
|
.device.bluetoothName) > -1 || these.device.bluetoothName.indexOf(arr[
|
||||||
|
i].name) > -1) {
|
||||||
|
arr[i].isTarget = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
arr[i].name = arr[i].name.replace('JQZM-', '');
|
||||||
|
these.EquipMents.push(arr[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.log("EquipMents=", these.EquipMents)
|
||||||
|
}, pagePath);
|
||||||
|
//收到设备的消息回调
|
||||||
|
ble.addReceiveCallback((receivData, f, path, arr) => {
|
||||||
|
if (these.Status.isPageHidden) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (f.macAddress && these.device) {
|
||||||
|
clearInterval(this.Status.intval);
|
||||||
|
this.Status.intval = null;
|
||||||
|
this.Status.time = null;
|
||||||
|
|
||||||
|
showLoading(these, {
|
||||||
|
text: '正在验证设备'
|
||||||
|
});
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
these.DeviceVerdict(f.deviceId);
|
||||||
|
}, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}, pagePath);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (search) {
|
||||||
|
StartSubsrib();
|
||||||
|
}
|
||||||
|
|
||||||
eventChannel.on('detailData', function(rec) {
|
eventChannel.on('detailData', function(rec) {
|
||||||
console.log("接收到父页面的参数:", rec);
|
console.log("接收到父页面的参数:", rec);
|
||||||
these.device = rec.data;
|
these.device = rec.data;
|
||||||
|
StartSubsrib();
|
||||||
|
these.refreshBleList();
|
||||||
});
|
});
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
onShow: function() {
|
onShow: function() {
|
||||||
|
this.Status.isPageHidden = false;
|
||||||
|
this.refreshBleList();
|
||||||
// this.EquipMents = [];
|
|
||||||
this.PairEquip = [];
|
|
||||||
ble && ble.StartSearch().then(res => {
|
|
||||||
console.log("开始搜索成功", res);
|
|
||||||
}).catch((ex) => {
|
|
||||||
console.log("开始搜索出现异常", ex);
|
|
||||||
if (ex.code == 10001) {
|
|
||||||
these.showOpenSetting();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
refreshBleList() {
|
||||||
|
if (!ble) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let promis = [];
|
||||||
|
for (let index = 0; index < this.PairEquip.length; index++) {
|
||||||
|
let item = this.PairEquip[index];
|
||||||
|
promis.push(ble.disconnectDevice(item.deviceId));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Promise.allSettled(promis).finally(() => {
|
||||||
|
ble.StopSearch().then(res => {
|
||||||
|
// console.log("停止搜索成功");
|
||||||
|
these.EquipMents = [];
|
||||||
|
these.PairEquip = [];
|
||||||
|
ble.StartSearch().then(result => {
|
||||||
|
// console.log("开始搜索成功");
|
||||||
|
}).catch(err => {
|
||||||
|
console.error("开始搜索失败,err=", err);
|
||||||
|
if (err.code === 10001) {
|
||||||
|
these.showOpenSetting();
|
||||||
|
} else {
|
||||||
|
uni.showModal({
|
||||||
|
title: '提示',
|
||||||
|
content: '出现异常:' + err.msg
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}).catch(ex => {
|
||||||
|
console.error("ex=", ex);
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
},
|
||||||
isItemLink: function(item, index) {
|
isItemLink: function(item, index) {
|
||||||
let src = '/static/images/BLEAdd/noLink.png';
|
let src = '/static/images/BLEAdd/noLink.png';
|
||||||
|
|
||||||
@ -260,19 +438,20 @@
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
let removeLink=()=>{
|
let removeLink = () => {
|
||||||
ble.subScribe(deviceId,false);//取消订阅消息
|
ble.subScribe(deviceId, false); //取消订阅消息
|
||||||
ble.DropDevice(deviceId);//从缓存中删除该设备
|
ble.DropDevice(deviceId, null); //从缓存中删除该设备并断开连接
|
||||||
ble.disconnectDevice(deviceId);//断开与该设备的连接
|
these.device.deviceMac = "";
|
||||||
|
let index = these.PairEquip.findIndex(function(v) {
|
||||||
let index=this.PairEquip.findIndex(function(v) {
|
|
||||||
return v.deviceId == deviceId;
|
return v.deviceId == deviceId;
|
||||||
});
|
});
|
||||||
if(index>-1){
|
if (index > -1) {
|
||||||
this.PairEquip.splice(index,1);
|
this.PairEquip.splice(index, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("f=", f);
|
console.log("f=", f);
|
||||||
if (f.macAddress) {
|
if (f.macAddress) {
|
||||||
|
|
||||||
@ -282,29 +461,34 @@
|
|||||||
updateLoading(these, {
|
updateLoading(these, {
|
||||||
text: "设备Mac地址错误,请重选设备连接"
|
text: "设备Mac地址错误,请重选设备连接"
|
||||||
});
|
});
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
hideLoading(these);
|
hideLoading(these);
|
||||||
}, 1000)
|
}, 1000)
|
||||||
return;
|
return;
|
||||||
}
|
} else {
|
||||||
|
|
||||||
|
}
|
||||||
hideLoading(these);
|
hideLoading(these);
|
||||||
|
|
||||||
ble.updateCache();
|
ble.updateCache();
|
||||||
uni.navigateBack();
|
uni.navigateBack();
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
|
||||||
this.Status.time = 30;
|
this.Status.time = 30;
|
||||||
|
showLoading(these, {
|
||||||
|
|
||||||
|
text: "等待设备上报Mac地址," + these.Status.time + 's'
|
||||||
|
});
|
||||||
|
console.log("11111111", this.Status.time);
|
||||||
|
clearInterval(this.Status.intval);
|
||||||
this.Status.intval = null;
|
this.Status.intval = null;
|
||||||
|
|
||||||
this.Status.intval = setInterval(() => {
|
|
||||||
this.Status.time = this.Status.time-1;
|
|
||||||
if (this.Status.time < 0) {
|
|
||||||
|
|
||||||
|
this.Status.intval = setInterval(() => {
|
||||||
|
this.Status.time = this.Status.time - 1;
|
||||||
|
if (this.Status.time < 0) {
|
||||||
|
console.log("停止倒计时", this.Status.time);
|
||||||
clearInterval(this.Status.intval)
|
clearInterval(this.Status.intval)
|
||||||
this.Status.intval = null;
|
this.Status.intval = null;
|
||||||
this.Status.time = null;
|
this.Status.time = null;
|
||||||
@ -315,23 +499,22 @@
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
if(!f.macAddress){
|
if (!f.macAddress) {
|
||||||
removeLink();
|
removeLink();
|
||||||
updateLoading(these, {
|
updateLoading(these, {
|
||||||
text: "出现错误,未收到设备Mac地址"
|
text: "出现错误,未收到设备Mac地址"
|
||||||
});
|
});
|
||||||
|
|
||||||
setTimeout(()=>{
|
setTimeout(() => {
|
||||||
hideLoading(these)
|
hideLoading(these)
|
||||||
},1000);
|
}, 1500);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
updateLoading(these, {
|
|
||||||
|
|
||||||
|
updateLoading(these, {
|
||||||
text: "等待设备上报Mac地址," + these.Status.time + 's'
|
text: "等待设备上报Mac地址," + these.Status.time + 's'
|
||||||
});
|
});
|
||||||
|
|
||||||
}, 1000);
|
}, 1000);
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
@ -387,7 +570,7 @@
|
|||||||
}
|
}
|
||||||
ble.LinkBlue(item.deviceId).then((res) => {
|
ble.LinkBlue(item.deviceId).then((res) => {
|
||||||
console.log("连接成功");
|
console.log("连接成功");
|
||||||
|
ble.StopSearch();
|
||||||
resolve(res);
|
resolve(res);
|
||||||
}).catch((ex) => {
|
}).catch((ex) => {
|
||||||
if (index == total) {
|
if (index == total) {
|
||||||
@ -408,6 +591,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
execLink().then((res) => {
|
execLink().then((res) => {
|
||||||
|
console.log("res=", res);
|
||||||
linkCallback(res);
|
linkCallback(res);
|
||||||
}).catch(ex => {
|
}).catch(ex => {
|
||||||
console.log("ex=", ex)
|
console.log("ex=", ex)
|
||||||
@ -433,7 +617,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.content {
|
.content {
|
||||||
background-color: #1d1d1d;
|
background-color: #121212;
|
||||||
color: #ffffffde;
|
color: #ffffffde;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
@ -508,13 +692,18 @@
|
|||||||
.animate .titleIco {
|
.animate .titleIco {
|
||||||
width: 36rpx;
|
width: 36rpx;
|
||||||
height: 36rpx;
|
height: 36rpx;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.circle {
|
.circle {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
border-radius: 50%;
|
border-radius: 50%;
|
||||||
background-color: #bbe60033;
|
background-color: #bbe60033;
|
||||||
animation: expand 3s infinite ease-out;
|
animation: expand 4s infinite ease-out;
|
||||||
|
display: inline-block;
|
||||||
|
transform: translate(-50%, -50%);
|
||||||
|
border: 1rpx solid #bbe6003d;
|
||||||
|
animation: expand 5s infinite ease-in-out;
|
||||||
}
|
}
|
||||||
|
|
||||||
.circle:nth-child(2) {
|
.circle:nth-child(2) {
|
||||||
@ -530,14 +719,19 @@
|
|||||||
width: 0;
|
width: 0;
|
||||||
height: 0;
|
height: 0;
|
||||||
opacity: 0.8;
|
opacity: 0.8;
|
||||||
transform: translate(-50%, -50%);
|
}
|
||||||
|
|
||||||
|
80% {
|
||||||
|
width: 18.75rem;
|
||||||
|
height: 18.75rem;
|
||||||
|
opacity: 0.2;
|
||||||
}
|
}
|
||||||
|
|
||||||
100% {
|
100% {
|
||||||
width: 18.75rem;
|
|
||||||
height: 18.75rem;
|
width: 0.5rem;
|
||||||
opacity: 0;
|
height: 0.5rem;
|
||||||
transform: translate(-50%, -50%);
|
opacity: 0.5;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -545,10 +739,10 @@
|
|||||||
padding: 30rpx;
|
padding: 30rpx;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: calc(100% - 400rpx);
|
height: calc(100% - 300rpx);
|
||||||
overflow-y: scroll;
|
overflow-y: scroll;
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 400rpx;
|
top: 300rpx;
|
||||||
left: 0rpx;
|
left: 0rpx;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -564,6 +758,13 @@
|
|||||||
width: 100%;
|
width: 100%;
|
||||||
height: 28rpx;
|
height: 28rpx;
|
||||||
line-height: 28rpx;
|
line-height: 28rpx;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
flex-wrap: nowrap;
|
||||||
|
align-content: center;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
margin-bottom: 20rpx;
|
||||||
}
|
}
|
||||||
|
|
||||||
.list {
|
.list {
|
||||||
@ -578,9 +779,10 @@
|
|||||||
|
|
||||||
.list .item {
|
.list .item {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 120rpx;
|
min-height: 120rpx;
|
||||||
|
height: auto;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
padding: 30rpx;
|
padding: 20rpx;
|
||||||
border-radius: 8px;
|
border-radius: 8px;
|
||||||
background: #1a1a1a;
|
background: #1a1a1a;
|
||||||
display: flex;
|
display: flex;
|
||||||
@ -588,7 +790,9 @@
|
|||||||
flex-wrap: nowrap;
|
flex-wrap: nowrap;
|
||||||
justify-content: flex-start;
|
justify-content: flex-start;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
margin-top: 10rpx;
|
margin-top: 20rpx;
|
||||||
|
position: relative;
|
||||||
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
.list .item .leftImg {
|
.list .item .leftImg {
|
||||||
@ -597,7 +801,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.list .item .centertxt {
|
.list .item .centertxt {
|
||||||
width: calc(100% - 150rpx);
|
width: calc(100% - 100rpx);
|
||||||
height: 100%;
|
height: 100%;
|
||||||
padding-left: 10rpx;
|
padding-left: 10rpx;
|
||||||
display: flex;
|
display: flex;
|
||||||
@ -609,15 +813,49 @@
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.list .item .before {
|
||||||
|
position: absolute;
|
||||||
|
bottom: 0px;
|
||||||
|
right: 0px;
|
||||||
|
content: "";
|
||||||
|
width: 0;
|
||||||
|
height: 0;
|
||||||
|
border-right: 30rpx solid #bbe600d4;
|
||||||
|
border-top: 30rpx solid transparent;
|
||||||
|
animation-delay: 1s;
|
||||||
|
animation: fade 1.5s infinite ease-in-out;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes fade {
|
||||||
|
0% {
|
||||||
|
opacity: 0.3;
|
||||||
|
}
|
||||||
|
|
||||||
|
50% {
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
100% {
|
||||||
|
opacity: 0.3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.list .item .rightIco {
|
.list .item .rightIco {
|
||||||
width: 50rpx;
|
width: 40rpx;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
flex-wrap: nowrap;
|
||||||
|
align-content: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
.list .item .leftImg .titleIco {
|
.list .item .leftImg .titleIco {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
|
filter: invert(100%);
|
||||||
}
|
}
|
||||||
|
|
||||||
.list .item .name {
|
.list .item .name {
|
||||||
@ -632,7 +870,7 @@
|
|||||||
.list .item .id {
|
.list .item .id {
|
||||||
color: #ffffff99;
|
color: #ffffff99;
|
||||||
font-family: "PingFang SC";
|
font-family: "PingFang SC";
|
||||||
font-size: 24rpx;
|
font-size: 26rpx;
|
||||||
font-weight: 400;
|
font-weight: 400;
|
||||||
line-height: 36rpx;
|
line-height: 36rpx;
|
||||||
text-align: left;
|
text-align: left;
|
||||||
@ -640,8 +878,8 @@
|
|||||||
|
|
||||||
|
|
||||||
.list .item .rightIco .img {
|
.list .item .rightIco .img {
|
||||||
width: 45rpx;
|
width: 40rpx;
|
||||||
height: 45rpx;
|
height: 40rpx;
|
||||||
}
|
}
|
||||||
|
|
||||||
.openBlue {
|
.openBlue {
|
||||||
|
|||||||
@ -416,7 +416,7 @@
|
|||||||
break;
|
break;
|
||||||
case 'bluetooth':
|
case 'bluetooth':
|
||||||
uni.navigateTo({
|
uni.navigateTo({
|
||||||
url: "/pages/common/addBLE/addEquip"
|
url: "/pages/common/addBLE/addEquip?search=all"
|
||||||
})
|
})
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -456,8 +456,9 @@
|
|||||||
if (this.$refs.swipeAction) {
|
if (this.$refs.swipeAction) {
|
||||||
this.$refs.swipeAction.closeAll();
|
this.$refs.swipeAction.closeAll();
|
||||||
}
|
}
|
||||||
|
console.log("111111",this.deviceId);
|
||||||
ble && ble.DropDevice(this.deviceId.id);
|
console.log("ble==null,",ble)
|
||||||
|
ble && ble.DropDevice(null,this.deviceId.id);
|
||||||
} else {
|
} else {
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
title: res.msg,
|
title: res.msg,
|
||||||
@ -540,6 +541,10 @@
|
|||||||
// 列表跳转
|
// 列表跳转
|
||||||
handleFile(item) {
|
handleFile(item) {
|
||||||
let url = item.detailPageUrl;
|
let url = item.detailPageUrl;
|
||||||
|
|
||||||
|
// url="/pages/6331/BJQ6331";
|
||||||
|
|
||||||
|
|
||||||
uni.navigateTo({
|
uni.navigateTo({
|
||||||
url: url,
|
url: url,
|
||||||
success: (res) => {
|
success: (res) => {
|
||||||
|
|||||||
@ -72,9 +72,9 @@
|
|||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
showView: false,
|
showView: false,
|
||||||
phone: '13800138002', //手机号码
|
phone: '', //手机号码
|
||||||
code: "123456", //验证码
|
code: "", //验证码
|
||||||
password: "123456",
|
password: "",
|
||||||
agreed: false,
|
agreed: false,
|
||||||
isCounting: false,
|
isCounting: false,
|
||||||
countdown: 0,
|
countdown: 0,
|
||||||
@ -84,6 +84,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
onLoad() {
|
onLoad() {
|
||||||
|
this.phone= uni.getStorageSync('phone');
|
||||||
if (uni.getStorageSync("token") && uni.getStorageSync("clientID")) { //免登陆
|
if (uni.getStorageSync("token") && uni.getStorageSync("clientID")) { //免登陆
|
||||||
let time = uni.getStorageSync("tokenTime");
|
let time = uni.getStorageSync("tokenTime");
|
||||||
if (!time) {
|
if (!time) {
|
||||||
@ -101,9 +102,11 @@
|
|||||||
uni.removeStorageSync("token")
|
uni.removeStorageSync("token")
|
||||||
uni.removeStorageSync("clientID")
|
uni.removeStorageSync("clientID")
|
||||||
uni.removeStorageSync("tokenTime")
|
uni.removeStorageSync("tokenTime")
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
// 验证码密码切换
|
// 验证码密码切换
|
||||||
@ -237,6 +240,7 @@
|
|||||||
uni.setStorageSync('token', res.data.access_token) // 缓存token
|
uni.setStorageSync('token', res.data.access_token) // 缓存token
|
||||||
uni.setStorageSync('clientID', res.data.client_id) // 缓存token
|
uni.setStorageSync('clientID', res.data.client_id) // 缓存token
|
||||||
uni.setStorageSync('tokenTime', new Date().getTime() + 86400000); //过期时间
|
uni.setStorageSync('tokenTime', new Date().getTime() + 86400000); //过期时间
|
||||||
|
uni.setStorageSync('phone',this.phone);
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
title: '登录成功',
|
title: '登录成功',
|
||||||
icon: 'success'
|
icon: 'success'
|
||||||
|
|||||||
@ -65,7 +65,7 @@
|
|||||||
deviceMac: '',
|
deviceMac: '',
|
||||||
communicationMode: '0', //0是4g,1是蓝牙
|
communicationMode: '0', //0是4g,1是蓝牙
|
||||||
})
|
})
|
||||||
console.log(this.deviceId, 'deerer ere');
|
console.log(this.deviceId, res);
|
||||||
if (res.code == 200) {
|
if (res.code == 200) {
|
||||||
|
|
||||||
this.isConnectNo = false
|
this.isConnectNo = false
|
||||||
|
|||||||
@ -7,7 +7,7 @@
|
|||||||
</view>
|
</view>
|
||||||
<view class="user-right">
|
<view class="user-right">
|
||||||
<view class="user-title">武汉星汉</view>
|
<view class="user-title">武汉星汉</view>
|
||||||
<view class="ID">ID:123456</view>
|
<view class="ID">ID:{{phone?phone:'123456'}}</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
<view class="content">
|
<view class="content">
|
||||||
@ -22,6 +22,11 @@
|
|||||||
<text class="title">隐私协议</text>
|
<text class="title">隐私协议</text>
|
||||||
<uni-icons type="right" size="25" color="rgba(255, 255, 255, 0.4)" class="uniIcon"></uni-icons>
|
<uni-icons type="right" size="25" color="rgba(255, 255, 255, 0.4)" class="uniIcon"></uni-icons>
|
||||||
</view>
|
</view>
|
||||||
|
<view class="menu-item" @click="gotoAppStore()" v-if="appVersion?true:false">
|
||||||
|
<image src="/static/images/common/ver.png" class="icon"></image>
|
||||||
|
<text class="title">版本更新 ({{appVersion}})</text>
|
||||||
|
<uni-icons type="right" size="25" color="rgba(255, 255, 255, 0.4)" class="uniIcon"></uni-icons>
|
||||||
|
</view>
|
||||||
<view class="menu-item" @click="aboutUs">
|
<view class="menu-item" @click="aboutUs">
|
||||||
<image src="/static/images/common/wm.png" class="icon"></image>
|
<image src="/static/images/common/wm.png" class="icon"></image>
|
||||||
<text class="title">关于我们</text>
|
<text class="title">关于我们</text>
|
||||||
@ -65,10 +70,48 @@
|
|||||||
export default {
|
export default {
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
showAgreement: false // 控制弹窗显示
|
showAgreement: false, // 控制弹窗显示
|
||||||
|
appVersion:'',
|
||||||
|
phone:''
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
onLoad() {
|
||||||
|
var these=this;
|
||||||
|
uni.getSystemInfo({
|
||||||
|
success(res) {
|
||||||
|
if(res.uniPlatform=='app'){
|
||||||
|
plus.runtime.getProperty(plus.runtime.appid, (widgetInfo) => {
|
||||||
|
const currentVersion = widgetInfo.version;
|
||||||
|
these.appVersion=currentVersion;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
this.phone= uni.getStorageSync('phone')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
//版本更新
|
||||||
|
gotoAppStore(){
|
||||||
|
let os=uni.getSystemInfoSync().platform;
|
||||||
|
let url=''
|
||||||
|
if(os==='ios'){
|
||||||
|
url='https://apps.apple.com/cn/app/星汉物联/id6752555460'
|
||||||
|
}
|
||||||
|
|
||||||
|
else if(os==='android'){
|
||||||
|
url='https://www.pgyer.com/xhwl';
|
||||||
|
}
|
||||||
|
|
||||||
|
plus.runtime.openURL(url, (res) => {
|
||||||
|
uni.showToast({
|
||||||
|
title: '打开失败',
|
||||||
|
icon: 'none'
|
||||||
|
});
|
||||||
|
});
|
||||||
|
},
|
||||||
// 取消
|
// 取消
|
||||||
handleDisagree() {
|
handleDisagree() {
|
||||||
this.showAgreement = false,
|
this.showAgreement = false,
|
||||||
@ -77,7 +120,7 @@
|
|||||||
// 确定
|
// 确定
|
||||||
handleAgree() {
|
handleAgree() {
|
||||||
// 退出登录
|
// 退出登录
|
||||||
Logout().then((res) => {
|
Logout().finally((res) => {
|
||||||
this.showAgreement = false
|
this.showAgreement = false
|
||||||
uni.showTabBar()
|
uni.showTabBar()
|
||||||
// 1. 清除本地存储的 token
|
// 1. 清除本地存储的 token
|
||||||
|
|||||||
BIN
static/images/6331/jieN.png
Normal file
|
After Width: | Height: | Size: 1.5 KiB |
BIN
static/images/6331/jieNActive.png
Normal file
|
After Width: | Height: | Size: 2.0 KiB |
BIN
static/images/6331/play.png
Normal file
|
After Width: | Height: | Size: 1.0 KiB |
BIN
static/images/6331/shuXie.png
Normal file
|
After Width: | Height: | Size: 2.0 KiB |
BIN
static/images/6331/shuxieActive.png
Normal file
|
After Width: | Height: | Size: 2.8 KiB |
BIN
static/images/6331/upload.png
Normal file
|
After Width: | Height: | Size: 1.3 KiB |
BIN
static/images/6331/volume.png
Normal file
|
After Width: | Height: | Size: 2.0 KiB |
BIN
static/images/6331/work.png
Normal file
|
After Width: | Height: | Size: 1.5 KiB |
BIN
static/images/6331/workActive.png
Normal file
|
After Width: | Height: | Size: 2.2 KiB |
|
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.5 KiB |
|
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 2.0 KiB |
|
Before Width: | Height: | Size: 2.0 KiB After Width: | Height: | Size: 2.0 KiB |
|
Before Width: | Height: | Size: 3.1 KiB After Width: | Height: | Size: 2.6 KiB |
|
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.8 KiB |
|
Before Width: | Height: | Size: 2.6 KiB After Width: | Height: | Size: 2.3 KiB |
BIN
static/images/BLEAdd/bluetooth.png
Normal file
|
After Width: | Height: | Size: 3.3 KiB |
BIN
static/images/common/ver.png
Normal file
|
After Width: | Height: | Size: 1.0 KiB |
@ -17,30 +17,30 @@ const serviceDic = [ //合作供应商的蓝牙主服务
|
|||||||
class BleHelper {
|
class BleHelper {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.StorageKey = "linkedDevices";
|
this.StorageKey = "linkedDevices";
|
||||||
|
|
||||||
recei = receivTool.getBleReceive();
|
recei = receivTool.getBleReceive();
|
||||||
|
|
||||||
this.init();
|
this.init();
|
||||||
}
|
}
|
||||||
init() {
|
init() {
|
||||||
let key = this.StorageKey;
|
|
||||||
var store = uni.getStorageInfoSync();
|
var store = uni.getStorageInfoSync();
|
||||||
var f = store.keys.find(function(v) {
|
var f = store.keys.includes(this.StorageKey);
|
||||||
return v == key;
|
|
||||||
});
|
|
||||||
var linkedDevices = [];
|
var linkedDevices = [];
|
||||||
if (f) {
|
if (f) {
|
||||||
linkedDevices = uni.getStorageSync(key);
|
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) => {
|
||||||
v.Linked = false;
|
v.Linked = false;
|
||||||
v.notifyState = false;
|
v.notifyState = false;
|
||||||
|
return true;
|
||||||
return v.device && v.device.id;
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this.OpenBlue().then(() => {
|
this.OpenBlue().then(() => {
|
||||||
this.linkAllDevices();
|
this.linkAllDevices();
|
||||||
@ -53,11 +53,16 @@ class BleHelper {
|
|||||||
discovering: false, //蓝牙是否正在搜索
|
discovering: false, //蓝牙是否正在搜索
|
||||||
searchList: [], //已搜索到的设备列表,
|
searchList: [], //已搜索到的设备列表,
|
||||||
isSubscribe: false, //是否开启了订阅
|
isSubscribe: false, //是否开启了订阅
|
||||||
LinkedList: linkedDevices, //已连接的设备列表
|
LinkedList: linkedDevices //已连接的设备列表
|
||||||
|
|
||||||
}
|
}
|
||||||
this.cfg = {
|
this.cfg = {
|
||||||
onDeviceFound: [], //发现新设备的事件
|
onDeviceFound: [], //发现新设备的事件
|
||||||
receivDataCallback: [] //接收到数据的事件
|
receivDataCallback: [], //接收到数据的事件
|
||||||
|
bleDisposeCallback: [], //蓝牙断开连接的事件
|
||||||
|
recoveryCallback: [], //蓝牙连接恢复的事件
|
||||||
|
stateRecoveryCallback: [], //蓝牙适配器恢复可用事件
|
||||||
|
stateBreakCallback: [] //蓝牙适配器不可用事件
|
||||||
}
|
}
|
||||||
// this.addReceiveCallback((a, b, c) => {
|
// this.addReceiveCallback((a, b, c) => {
|
||||||
// recei.ReceiveData(a, b, c);
|
// recei.ReceiveData(a, b, c);
|
||||||
@ -124,19 +129,24 @@ class BleHelper {
|
|||||||
}
|
}
|
||||||
//从缓存中删除某个设备,bleId蓝牙id,deviceId数据库中的设备id
|
//从缓存中删除某个设备,bleId蓝牙id,deviceId数据库中的设备id
|
||||||
DropDevice(bleId, deviceId) {
|
DropDevice(bleId, deviceId) {
|
||||||
|
|
||||||
let flag = false;
|
let flag = false;
|
||||||
for (var i = 0; i < this.data.LinkedList.length; i++) {
|
for (var i = 0; i < this.data.LinkedList.length; i++) {
|
||||||
let item = this.data.LinkedList[i];
|
let item = this.data.LinkedList[i];
|
||||||
if (bleId) {
|
if (deviceId && item.device) {
|
||||||
if (item.deviceId == bleId) {
|
if (item.device.id == deviceId) {
|
||||||
|
console.log("找到要删除的设备", item);
|
||||||
this.data.LinkedList.splice(i, 1);
|
this.data.LinkedList.splice(i, 1);
|
||||||
|
this.disconnectDevice(item.deviceId);
|
||||||
flag = true;
|
flag = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (item.device && item.device.id) {
|
if (bleId && item.deviceId == bleId) {
|
||||||
|
console.log("找到要删除的设备1,", item)
|
||||||
this.data.LinkedList.splice(i, 1);
|
this.data.LinkedList.splice(i, 1);
|
||||||
|
this.disconnectDevice(item.deviceId);
|
||||||
flag = true;
|
flag = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -150,34 +160,35 @@ class BleHelper {
|
|||||||
|
|
||||||
//更新缓存
|
//更新缓存
|
||||||
updateCache() {
|
updateCache() {
|
||||||
// console.log("this.StorageKey=", this.StorageKey)
|
|
||||||
uni.setStorageSync(this.StorageKey, this.data.LinkedList);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
uni.setStorageSync(this.StorageKey, this.data.LinkedList);
|
||||||
|
|
||||||
|
}
|
||||||
|
//连接所有已连接过的设备
|
||||||
linkAllDevices() {
|
linkAllDevices() {
|
||||||
// console.log("模块启动时,自动连接已连接过的设备", this.data.LinkedList);
|
// console.log("模块启动时,自动连接已连接过的设备", this.data.LinkedList);
|
||||||
|
|
||||||
if (this.data.LinkedList && this.data.LinkedList.length > 0) {
|
if (this.data.LinkedList && this.data.LinkedList.length > 0) {
|
||||||
let flag=false;
|
let flag = false;
|
||||||
for (var i = 0; i < this.data.LinkedList.length; i++) {
|
for (var i = 0; i < this.data.LinkedList.length; i++) {
|
||||||
let device = this.data.LinkedList[i];
|
let device = this.data.LinkedList[i];
|
||||||
// console.log("自动连接绑定过的设备:" + device.deviceId);
|
// console.log("自动连接绑定过的设备:" + device.deviceId);
|
||||||
if (device.macAddress && device.device && device.device.id) {
|
if (device.macAddress && device.device && device.device.id) {
|
||||||
this.LinkBlue(device.deviceId, device.writeServiceId, device.wirteCharactId, device
|
this.LinkBlue(device.deviceId, device.writeServiceId, device.wirteCharactId, device
|
||||||
.notifyCharactId);
|
.notifyCharactId);
|
||||||
flag=true;
|
flag = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
if(!flag){
|
if (!flag) {
|
||||||
this.updateCache();
|
this.updateCache();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
console.log("蓝牙未连接过任何设备");
|
// console.log("蓝牙未连接过任何设备");
|
||||||
this.updateCache();
|
this.updateCache();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//获取当前页面栈
|
||||||
getCurrentPagePath() {
|
getCurrentPagePath() {
|
||||||
|
|
||||||
const pages = getCurrentPages();
|
const pages = getCurrentPages();
|
||||||
@ -190,93 +201,128 @@ class BleHelper {
|
|||||||
// console.log("currentPage=", currentPage.route);
|
// console.log("currentPage=", currentPage.route);
|
||||||
return currentPage.route;
|
return currentPage.route;
|
||||||
}
|
}
|
||||||
|
//添加事件回调
|
||||||
//设置发现新设备的回调
|
addCallback(callback, currKey, type) {
|
||||||
addDeviceFound(callback, currKey) {
|
if (!type) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
let key = currKey ? currKey : this.getCurrentPagePath();
|
let key = currKey ? currKey : this.getCurrentPagePath();
|
||||||
if (!key) {
|
if (!key) {
|
||||||
key = new Date().getTime();
|
key = new Date().getTime();
|
||||||
}
|
}
|
||||||
if (key) {
|
if (key) {
|
||||||
// console.log("key=" + key);
|
// console.log("key=" + key);
|
||||||
let f = this.cfg.onDeviceFound.findIndex((v) => {
|
let f = this.cfg[type].findIndex((v) => {
|
||||||
return v.key == key;
|
return v.key == key;
|
||||||
});
|
});
|
||||||
if (f > -1) {
|
if (f > -1) {
|
||||||
this.cfg.onDeviceFound[f].callback = callback;
|
this.cfg[type][f].callback = callback;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.cfg.onDeviceFound.push({
|
this.cfg[type].push({
|
||||||
key: key,
|
key: key,
|
||||||
callback: callback
|
callback: callback
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//移除事件回调
|
||||||
|
removeCallback(currKey, type) {
|
||||||
|
if (!type) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let key = currKey ? currKey : this.getCurrentPagePath();
|
||||||
|
|
||||||
|
if (key) {
|
||||||
|
// console.log("key=" + key);
|
||||||
|
let f = this.cfg[type].findIndex((v) => {
|
||||||
|
return v.key == key;
|
||||||
|
});
|
||||||
|
if (f > -1) {
|
||||||
|
this.cfg[type].splice(f, 1);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (this.cfg[type].length > 0) {
|
||||||
|
this.cfg[type].splice(this.cfg[type].length - 1, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//设置蓝牙恢复连接的回调
|
||||||
|
addRecoveryCallback(callback, currKey) {
|
||||||
|
this.addCallback(callback, currKey, 'recoveryCallback');
|
||||||
|
}
|
||||||
|
|
||||||
|
//移除蓝牙恢复连接的回调
|
||||||
|
removeRecoveryCallback(currKey) {
|
||||||
|
this.removeCallback(currKey, 'recoveryCallback');
|
||||||
|
}
|
||||||
|
|
||||||
|
//设置蓝牙断开连接的回调
|
||||||
|
addDisposeCallback(callback, currKey) {
|
||||||
|
this.addCallback(callback, currKey, 'bleDisposeCallback');
|
||||||
|
}
|
||||||
|
|
||||||
|
//移除蓝牙断开连接的回调
|
||||||
|
removeDisposeCallback(currKey) {
|
||||||
|
this.removeCallback(currKey, 'bleDisposeCallback');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//设置发现新设备的回调
|
||||||
|
addDeviceFound(callback, currKey) {
|
||||||
|
this.addCallback(callback, currKey, 'onDeviceFound');
|
||||||
|
}
|
||||||
|
|
||||||
//移除发现新设备的回调
|
//移除发现新设备的回调
|
||||||
removeDeviceFound(currKey) {
|
removeDeviceFound(currKey) {
|
||||||
let key = currKey ? currKey : this.getCurrentPagePath();
|
this.removeCallback(currKey, 'onDeviceFound');
|
||||||
|
|
||||||
if (key) {
|
|
||||||
// console.log("key=" + key);
|
|
||||||
let f = this.cfg.onDeviceFound.findIndex((v) => {
|
|
||||||
return v.key == key;
|
|
||||||
});
|
|
||||||
if (f > -1) {
|
|
||||||
this.cfg.onDeviceFound.splice(f, 1);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (this.cfg.onDeviceFound.length > 0) {
|
|
||||||
this.cfg.onDeviceFound.splice(this.cfg.onDeviceFound.length - 1, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//添加接收到数据的回调
|
//添加接收到数据的回调
|
||||||
addReceiveCallback(callback, currKey) {
|
addReceiveCallback(callback, currKey) {
|
||||||
let key = currKey ? currKey : this.getCurrentPagePath();
|
this.addCallback(callback, currKey, 'receivDataCallback');
|
||||||
if (!key) {
|
|
||||||
key = new Date().getTime();
|
|
||||||
}
|
|
||||||
if (key) {
|
|
||||||
// console.log("订阅消息回调,key=" + key);
|
|
||||||
let f = this.cfg.receivDataCallback.findIndex((v) => {
|
|
||||||
return v.key == key;
|
|
||||||
});
|
|
||||||
if (f > -1) {
|
|
||||||
this.cfg.receivDataCallback.callback = callback;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.cfg.receivDataCallback.push({
|
|
||||||
key: key,
|
|
||||||
callback: callback
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//移除接收到数据的回调
|
||||||
|
|
||||||
//设置接收到数据的回调
|
|
||||||
removeReceiveCallback(currKey) {
|
removeReceiveCallback(currKey) {
|
||||||
let key = currKey ? currKey : this.getCurrentPagePath();
|
this.removeCallback(currKey, 'receivDataCallback');
|
||||||
if (key) {
|
|
||||||
// console.log("移除消息回调:" + key);
|
|
||||||
let f = this.cfg.receivDataCallback.findIndex((v) => {
|
|
||||||
return v.key == key;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (f > -1) {
|
|
||||||
this.cfg.receivDataCallback.splice(f, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
if (this.cfg.receivDataCallback.length > 0) {
|
|
||||||
this.cfg.receivDataCallback.splice(this.cfg.receivDataCallback.length - 1, 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//添加蓝牙不可用的回调
|
||||||
|
addStateBreakCallback(callback, currKey) {
|
||||||
|
this.addCallback(callback, currKey, 'stateBreakCallback');
|
||||||
|
}
|
||||||
|
|
||||||
|
//移除蓝牙不可用的回调
|
||||||
|
removeStateBreakCallback(currKey) {
|
||||||
|
this.removeCallback(currKey, 'stateBreakCallback');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//设置蓝牙适配器恢复可用的回调
|
||||||
|
addStateRecoveryCallback(callback, currKey) {
|
||||||
|
this.addCallback(callback, currKey, 'stateRecoveryCallback');
|
||||||
|
}
|
||||||
|
|
||||||
|
//移除蓝牙适配器恢复的回调
|
||||||
|
removeStateRecoveryCallback(currKey) {
|
||||||
|
this.removeCallback(currKey, 'stateRecoveryCallback');
|
||||||
|
}
|
||||||
|
|
||||||
|
//清除所有事件回调
|
||||||
|
removeAllCallback(currKey) {
|
||||||
|
this.removeDeviceFound(currKey)
|
||||||
|
this.removeDisposeCallback(currKey);
|
||||||
|
this.removeReceiveCallback(currKey);
|
||||||
|
this.removeRecoveryCallback(currKey);
|
||||||
|
this.removeStateRecoveryCallback(currKey);
|
||||||
|
this.removeStateBreakCallback(currKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
getError(ex) {
|
getError(ex) {
|
||||||
@ -379,7 +425,7 @@ class BleHelper {
|
|||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
if (this.data.available) {
|
if (this.data.available) {
|
||||||
console.log("蓝牙模块是可用状态");
|
// console.log("蓝牙模块是可用状态");
|
||||||
resolve({
|
resolve({
|
||||||
available: this.data.available,
|
available: this.data.available,
|
||||||
discovering: this.data.discovering
|
discovering: this.data.discovering
|
||||||
@ -387,7 +433,7 @@ class BleHelper {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!this.data.isOpenBlue) {
|
if (!this.data.isOpenBlue) {
|
||||||
console.log("蓝牙模块未打开");
|
console.error("蓝牙模块未打开");
|
||||||
resolve({
|
resolve({
|
||||||
available: false,
|
available: false,
|
||||||
discovering: false
|
discovering: false
|
||||||
@ -396,13 +442,13 @@ class BleHelper {
|
|||||||
}
|
}
|
||||||
uni.getBluetoothAdapterState({
|
uni.getBluetoothAdapterState({
|
||||||
success: (info) => {
|
success: (info) => {
|
||||||
console.log("蓝牙状态获取成功,", info)
|
// console.log("蓝牙状态获取成功,", info)
|
||||||
this.data.available = info.available;
|
this.data.available = info.available;
|
||||||
this.data.discovering = info.discovering;
|
this.data.discovering = info.discovering;
|
||||||
resolve(info);
|
resolve(info);
|
||||||
},
|
},
|
||||||
fail: (ex1) => {
|
fail: (ex1) => {
|
||||||
console.log("蓝牙状态获取失败", ex1);
|
console.error("蓝牙状态获取失败", ex1);
|
||||||
let res1 = {
|
let res1 = {
|
||||||
available: false,
|
available: false,
|
||||||
discovering: false
|
discovering: false
|
||||||
@ -418,7 +464,7 @@ class BleHelper {
|
|||||||
var init = () => {
|
var init = () => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
if (this.data.isOpenBlue) {
|
if (this.data.isOpenBlue) {
|
||||||
console.log("蓝牙状态已可用,提前返回");
|
// console.log("蓝牙状态已可用,提前返回");
|
||||||
resolve(false);
|
resolve(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -433,9 +479,12 @@ class BleHelper {
|
|||||||
if (this.data.isSubscribe) { //整个App生命周期,只订阅一次
|
if (this.data.isSubscribe) { //整个App生命周期,只订阅一次
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// console.log("开始订阅各类变化消息");
|
console.log("开始订阅各类变化消息");
|
||||||
this.data.isSubscribe = true;
|
this.data.isSubscribe = true;
|
||||||
|
|
||||||
|
// 保存每个设备的连接状态
|
||||||
|
let bleDeviceStates = {};
|
||||||
|
|
||||||
|
|
||||||
var bytesToHexString = (bytes) => {
|
var bytesToHexString = (bytes) => {
|
||||||
return bytes.map(byte => byte.toString(16).padStart(2,
|
return bytes.map(byte => byte.toString(16).padStart(2,
|
||||||
@ -449,56 +498,153 @@ class BleHelper {
|
|||||||
this.data.discovering = state.discovering;
|
this.data.discovering = state.discovering;
|
||||||
if (this.data.available && this.data
|
if (this.data.available && this.data
|
||||||
.isOpenBlue) { //蓝牙状态再次可用,重连所有设备
|
.isOpenBlue) { //蓝牙状态再次可用,重连所有设备
|
||||||
this.linkAllDevices();
|
|
||||||
|
if (this.cfg.stateRecoveryCallback.length > 0) {
|
||||||
|
this.cfg.stateRecoveryCallback.forEach(
|
||||||
|
c => {
|
||||||
|
try {
|
||||||
|
c.callback();
|
||||||
|
} catch (error) {
|
||||||
|
console.error(
|
||||||
|
"蓝牙适配器已恢复,但回调函数发生错误",
|
||||||
|
error);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (!state.available) { //蓝牙状态不可用了,将所有设备标记为断开连接
|
if (!state.available) { //蓝牙状态不可用了,将所有设备标记为断开连接
|
||||||
|
|
||||||
this.data.LinkedList.filter((v) => {
|
this.data.LinkedList.filter((v) => {
|
||||||
v.Linked = false;
|
v.Linked = false;
|
||||||
v.notifyState = false;
|
v.notifyState = false;
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
let keys = Object.keys(bleDeviceStates)
|
||||||
|
keys.filter(v => {
|
||||||
|
bleDeviceStates[v] = false;
|
||||||
|
});
|
||||||
|
|
||||||
|
this.cfg.stateBreakCallback.forEach(f => {
|
||||||
|
try {
|
||||||
|
f.callback();
|
||||||
|
} catch (error) {
|
||||||
|
console.error("蓝牙状态不可用了,执行回调异常",
|
||||||
|
error)
|
||||||
|
}
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
this.updateCache();
|
this.updateCache();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
uni.onBLEConnectionStateChange((res) => {
|
uni.onBLEConnectionStateChange((res) => {
|
||||||
|
console.log("蓝牙连接状态变化了", res);
|
||||||
|
// 检查状态是否真的发生了变化
|
||||||
|
if (bleDeviceStates[res.deviceId] === res.connected) {
|
||||||
|
console.error('专业给Uniapp填坑,连接状态');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!res.connected) {
|
// 更新状态记录
|
||||||
|
bleDeviceStates[res.deviceId] = res.connected;
|
||||||
|
|
||||||
console.error("蓝牙适配器已不可用", res);
|
setTimeout(() => {
|
||||||
let f = this.data.LinkedList.find((v) => {
|
if (!res.connected) {
|
||||||
if (v.deviceId == res.deviceId) {
|
console.error("蓝牙已断开", res);
|
||||||
v.Linked = false;
|
let f = this.data.LinkedList.find((
|
||||||
v.notifyState = false;
|
v) => {
|
||||||
return true;
|
if (v.deviceId == res
|
||||||
|
.deviceId) {
|
||||||
|
v.Linked = false;
|
||||||
|
v.notifyState = false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
this.updateCache();
|
||||||
|
if (f && f.device && f.device.id) {
|
||||||
|
console.log("尝试5次恢复连接,", f
|
||||||
|
.deviceId);
|
||||||
|
this.LinkBlue(res.deviceId, f
|
||||||
|
.writeServiceId, f
|
||||||
|
.wirteCharactId, f
|
||||||
|
.notifyCharactId, 5);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.cfg.bleDisposeCallback.length >
|
||||||
|
0) {
|
||||||
|
this.cfg.bleDisposeCallback.forEach(
|
||||||
|
(c) => {
|
||||||
|
try {
|
||||||
|
c.callback(res);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(
|
||||||
|
"执行蓝牙断开连接的回调出现异常,",
|
||||||
|
error)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
console.log("蓝牙连接已恢复,", res);
|
||||||
|
if (this.cfg.recoveryCallback.length >
|
||||||
|
0) {
|
||||||
|
this.cfg.recoveryCallback.forEach((
|
||||||
|
c) => {
|
||||||
|
try {
|
||||||
|
c.callback(res);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(
|
||||||
|
"执行蓝牙恢复连接的回调出现异常,",
|
||||||
|
error)
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
});
|
|
||||||
this.updateCache();
|
|
||||||
if (f.device && f.device.id) {
|
|
||||||
console.log("尝试5次恢复连接,", f.deviceId);
|
|
||||||
this.LinkBlue(res.deviceId, f.writeServiceId, f
|
|
||||||
.wirteCharactId, f.notifyCharactId, 5)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
}, 0);
|
||||||
console.log("蓝牙适配器已恢复,", res);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
uni.onBluetoothDeviceFound((devices) => {
|
uni.onBluetoothDeviceFound((res) => {
|
||||||
// console.log("发现新设备:" + JSON.stringify(devices));
|
// console.log("发现新设备:" + JSON.stringify(devices));
|
||||||
|
let arr = [];
|
||||||
|
for (var i = 0; i < res.devices.length; i++) {
|
||||||
|
let item = res.devices[i];
|
||||||
|
let f = serviceDic.find(v => {
|
||||||
|
return item.advertisServiceUUIDs
|
||||||
|
.includes(v.serviceId);
|
||||||
|
});
|
||||||
|
if (f) {
|
||||||
|
|
||||||
|
console.log("发现新设备:", item);
|
||||||
|
arr.push(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
if (arr.length === 0) {
|
||||||
|
// console.error("发现了设备,但不是想要的设备", res);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
res.devices = arr;
|
||||||
this.data.searchList = this.data.searchList.concat(
|
this.data.searchList = this.data.searchList.concat(
|
||||||
devices);
|
res);
|
||||||
if (this.cfg.onDeviceFound) {
|
if (this.cfg.onDeviceFound) {
|
||||||
if (this.cfg.onDeviceFound.length > 0) {
|
if (this.cfg.onDeviceFound.length > 0) {
|
||||||
this.cfg.onDeviceFound.forEach((found) => {
|
this.cfg.onDeviceFound.forEach((found) => {
|
||||||
found.callback(devices);
|
try {
|
||||||
|
found.callback(res);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("处理发现设备的回调出现异常,",
|
||||||
|
error);
|
||||||
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -635,7 +781,7 @@ class BleHelper {
|
|||||||
|
|
||||||
},
|
},
|
||||||
fail: (ex2) => {
|
fail: (ex2) => {
|
||||||
console.log("蓝牙模块启动失败", ex2);
|
console.error("蓝牙模块启动失败", ex2);
|
||||||
reject(this.getError(ex2));
|
reject(this.getError(ex2));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -649,7 +795,7 @@ class BleHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.CheckBlue().then((res) => {
|
this.CheckBlue().then((res) => {
|
||||||
console.log("res=", res)
|
// console.log("res=", res)
|
||||||
return init();
|
return init();
|
||||||
}).then(resolve).catch((ex) => {
|
}).then(resolve).catch((ex) => {
|
||||||
console.error("异常:", ex);
|
console.error("异常:", ex);
|
||||||
@ -673,12 +819,13 @@ class BleHelper {
|
|||||||
|
|
||||||
uni.closeBluetoothAdapter({
|
uni.closeBluetoothAdapter({
|
||||||
success: () => {
|
success: () => {
|
||||||
console.log("蓝牙模块已关闭");
|
// console.log("蓝牙模块已关闭");
|
||||||
this.data.isOpenBlue = false;
|
|
||||||
},
|
},
|
||||||
fail: (ex) => {
|
fail: (ex) => {
|
||||||
|
console.error('无法关闭蓝牙模块:', ex);
|
||||||
ex = this.getError(ex);
|
ex = this.getError(ex);
|
||||||
////console.log(msg);
|
|
||||||
},
|
},
|
||||||
complete: () => {
|
complete: () => {
|
||||||
resolve();
|
resolve();
|
||||||
@ -712,7 +859,7 @@ class BleHelper {
|
|||||||
|
|
||||||
},
|
},
|
||||||
fail: (err) => {
|
fail: (err) => {
|
||||||
console.log(`搜索蓝牙设备失败:`, err);
|
console.error(`搜索蓝牙设备失败:`, err);
|
||||||
|
|
||||||
reject(this.getError(err));
|
reject(this.getError(err));
|
||||||
}
|
}
|
||||||
@ -751,19 +898,41 @@ class BleHelper {
|
|||||||
|
|
||||||
//停止搜索
|
//停止搜索
|
||||||
StopSearch() {
|
StopSearch() {
|
||||||
return new Promise((resolve, reject) => {
|
let p1 = new Promise((resolve, reject) => {
|
||||||
uni.stopBluetoothDevicesDiscovery({
|
uni.stopBluetoothDevicesDiscovery({
|
||||||
success: (res) => {
|
success: (res) => {
|
||||||
//console.log("停止搜索蓝牙设备成功");
|
// console.log("停止搜索蓝牙设备成功");
|
||||||
resolve();
|
resolve();
|
||||||
},
|
},
|
||||||
fail: (ex) => {
|
fail: (ex) => {
|
||||||
//console.log("无法停止蓝牙搜索");
|
console.error("无法停止蓝牙搜索");
|
||||||
|
|
||||||
reject(this.getError(ex));
|
reject(this.getError(ex));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
})
|
});
|
||||||
|
|
||||||
|
let p2 = new Promise((succ, err) => {
|
||||||
|
setTimeout(() => {
|
||||||
|
err({
|
||||||
|
code: -1
|
||||||
|
});
|
||||||
|
}, 100);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
Promise.race([p1, p2]).then(resolve).catch(ex => {
|
||||||
|
if (ex.code == -1) {
|
||||||
|
console.error('专业给Uniapp填坑,停止搜索');
|
||||||
|
resolve();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
reject(ex);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
//获取已连接的设备
|
//获取已连接的设备
|
||||||
@ -792,7 +961,7 @@ class BleHelper {
|
|||||||
|
|
||||||
//订阅消息
|
//订阅消息
|
||||||
subScribe(deviceId, state) {
|
subScribe(deviceId, state) {
|
||||||
console.log("开始订阅消息", state);
|
// console.log("开始订阅消息", state);
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
|
|
||||||
@ -834,9 +1003,9 @@ class BleHelper {
|
|||||||
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) => {
|
||||||
@ -867,6 +1036,7 @@ class BleHelper {
|
|||||||
Promise.race([p1, p2]).then(succ).catch(ex => {
|
Promise.race([p1, p2]).then(succ).catch(ex => {
|
||||||
// console.error("异常了:",ex);
|
// console.error("异常了:",ex);
|
||||||
if (ex.code == -1) {
|
if (ex.code == -1) {
|
||||||
|
console.error('专业给Uniapp填坑,订阅成功');
|
||||||
succ();
|
succ();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -896,8 +1066,8 @@ class BleHelper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
console.log("c=", c);
|
// console.log("c=", c);
|
||||||
console.log("serv=", serv);
|
// console.log("serv=", serv);
|
||||||
reject({
|
reject({
|
||||||
code: 403,
|
code: 403,
|
||||||
msg: "出现错误,找不到任何通知特征"
|
msg: "出现错误,找不到任何通知特征"
|
||||||
@ -927,7 +1097,7 @@ class BleHelper {
|
|||||||
// console.log("finally")
|
// console.log("finally")
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
console.log("没有特征需要订阅");
|
console.error("没有特征需要订阅");
|
||||||
resolve();
|
resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -952,7 +1122,7 @@ class BleHelper {
|
|||||||
deviceId: id,
|
deviceId: id,
|
||||||
success: (res) => {
|
success: (res) => {
|
||||||
if (res.services && res.services.length > 0) {
|
if (res.services && res.services.length > 0) {
|
||||||
console.log("获取到服务:" + JSON.stringify(res));
|
// console.log("获取到服务:" + JSON.stringify(res));
|
||||||
|
|
||||||
this.data.LinkedList.find((v) => {
|
this.data.LinkedList.find((v) => {
|
||||||
if (v.deviceId == id) {
|
if (v.deviceId == id) {
|
||||||
@ -977,7 +1147,7 @@ class BleHelper {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (se) {
|
if (se) {
|
||||||
console.log("合作供应商的", s)
|
// console.log("合作供应商的", s)
|
||||||
this.data.LinkedList.find((v) => {
|
this.data.LinkedList.find((v) => {
|
||||||
if (v.deviceId == id) {
|
if (v.deviceId == id) {
|
||||||
v.writeServiceId = s.serviceId;
|
v.writeServiceId = s.serviceId;
|
||||||
@ -996,7 +1166,7 @@ class BleHelper {
|
|||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
console.log("预设的蓝牙服务和特征中找不到");
|
console.error("预设的蓝牙服务和特征中找不到");
|
||||||
for (var i = 0; i < res.services.length; i++) {
|
for (var i = 0; i < res.services.length; i++) {
|
||||||
let service = res.services[i];
|
let service = res.services[i];
|
||||||
promises.push(this.getFeatrus(id, service.uuid,
|
promises.push(this.getFeatrus(id, service.uuid,
|
||||||
@ -1006,7 +1176,7 @@ class BleHelper {
|
|||||||
|
|
||||||
|
|
||||||
if (promises.length == 0) {
|
if (promises.length == 0) {
|
||||||
console.log("未找到主服务");
|
console.error("未找到主服务");
|
||||||
reject({
|
reject({
|
||||||
msg: "未找到主服务",
|
msg: "未找到主服务",
|
||||||
code: -1
|
code: -1
|
||||||
@ -1025,8 +1195,8 @@ class BleHelper {
|
|||||||
|
|
||||||
})
|
})
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
console.log('设备连接成功,初始化完成', this.data
|
// console.log('设备连接成功,初始化完成', this.data
|
||||||
.LinkedList);
|
// .LinkedList);
|
||||||
|
|
||||||
resolve();
|
resolve();
|
||||||
})
|
})
|
||||||
@ -1074,7 +1244,7 @@ class BleHelper {
|
|||||||
serviceId: serviceId,
|
serviceId: serviceId,
|
||||||
success: (res) => {
|
success: (res) => {
|
||||||
|
|
||||||
console.log("获取到特征:" + JSON.stringify(res));
|
// console.log("获取到特征:" + JSON.stringify(res));
|
||||||
// res.characteristics.forEach((v) => {
|
// res.characteristics.forEach((v) => {
|
||||||
// v.serviceId = serviceId;
|
// v.serviceId = serviceId;
|
||||||
// });
|
// });
|
||||||
@ -1213,12 +1383,12 @@ class BleHelper {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("正在连接" + deviceId);
|
// console.log("正在连接" + deviceId);
|
||||||
uni.createBLEConnection({
|
uni.createBLEConnection({
|
||||||
deviceId: deviceId,
|
deviceId: deviceId,
|
||||||
timeout: 30000,
|
timeout: 30000,
|
||||||
success: (info) => {
|
success: (info) => {
|
||||||
console.log("新连接成功", this.data.LinkedList);
|
// console.log("新连接成功", this.data.LinkedList);
|
||||||
this.getLinkBlue().then((arr) => {
|
this.getLinkBlue().then((arr) => {
|
||||||
let cr = arr.devices.find(c => {
|
let cr = arr.devices.find(c => {
|
||||||
if (c.deviceId == deviceId) {
|
if (c.deviceId == deviceId) {
|
||||||
@ -1235,8 +1405,8 @@ class BleHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.updateCache();
|
this.updateCache();
|
||||||
console.log("LinkedList=", this.data
|
// console.log("LinkedList=", this.data
|
||||||
.LinkedList);
|
// .LinkedList);
|
||||||
|
|
||||||
// 处理 MTU 设置
|
// 处理 MTU 设置
|
||||||
if (plus.os.name === 'Android') {
|
if (plus.os.name === 'Android') {
|
||||||
@ -1248,7 +1418,8 @@ class BleHelper {
|
|||||||
resolve(true);
|
resolve(true);
|
||||||
},
|
},
|
||||||
fail: () => {
|
fail: () => {
|
||||||
console.log("mtu设置失败");
|
console.error(
|
||||||
|
"mtu设置失败");
|
||||||
resolve(
|
resolve(
|
||||||
true
|
true
|
||||||
); // MTU设置失败不影响连接成功
|
); // MTU设置失败不影响连接成功
|
||||||
@ -1263,7 +1434,8 @@ class BleHelper {
|
|||||||
},
|
},
|
||||||
fail: (ex) => {
|
fail: (ex) => {
|
||||||
ex = this.getError(ex);
|
ex = this.getError(ex);
|
||||||
console.log("蓝牙" + deviceId + "连接失败" + JSON.stringify(ex));
|
console.error("蓝牙" + deviceId + "连接失败" + JSON.stringify(
|
||||||
|
ex));
|
||||||
|
|
||||||
// 连接超时后自动重试
|
// 连接超时后自动重试
|
||||||
if (ex.code === 10012 && retryCount < maxRetries) {
|
if (ex.code === 10012 && retryCount < maxRetries) {
|
||||||
@ -1346,12 +1518,12 @@ class BleHelper {
|
|||||||
uni.closeBLEConnection({
|
uni.closeBLEConnection({
|
||||||
deviceId: id,
|
deviceId: id,
|
||||||
success: (res) => {
|
success: (res) => {
|
||||||
////console.log("蓝牙连接已断开:" + id);
|
console.log("用户主动断开了蓝牙:" + id);
|
||||||
this.subScribe(id, false);
|
this.subScribe(id, false);
|
||||||
resolve();
|
resolve();
|
||||||
},
|
},
|
||||||
fail: (ex) => {
|
fail: (ex) => {
|
||||||
|
console.error("无法断开蓝牙连接", ex);
|
||||||
reject(this.getError(ex));
|
reject(this.getError(ex));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -1398,7 +1570,46 @@ class BleHelper {
|
|||||||
////console.log("无已连接设备");
|
////console.log("无已连接设备");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//向蓝牙设备发送一个字符串的ASCII码
|
||||||
|
sendString(deviceid, str, writeServiceId, wirteCharactId, ms) {
|
||||||
|
if (str && str.length) {
|
||||||
|
let buffer = new ArrayBuffer(str.length);
|
||||||
|
let dataView = new DataView(buffer);
|
||||||
|
|
||||||
|
// 2. 将字符串转换为 ASCII 码并写入 DataView
|
||||||
|
for (let i = 0; i < str.length; i++) {
|
||||||
|
dataView.setUint8(i, str.charCodeAt(i));
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.sendData(deviceid, buffer, writeServiceId, wirteCharactId, ms);
|
||||||
|
} else {
|
||||||
|
return Promise.resolve({
|
||||||
|
code: 200,
|
||||||
|
msg: "没有数据要发送"
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//向蓝牙设备发送一个16进制的数组数据
|
||||||
|
sendHexs(deviceid, array, writeServiceId, wirteCharactId, ms) {
|
||||||
|
if (array && array.length) {
|
||||||
|
let bufferSize = array.length;
|
||||||
|
let buffer = new ArrayBuffer(bufferSize);
|
||||||
|
let dataView = new DataView(buffer);
|
||||||
|
for (let i = 0; i < array.length; i++) {
|
||||||
|
dataView.setUint8(i, array);
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.sendData(deviceid, buffer, writeServiceId, wirteCharactId, ms);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
return Promise.resolve({
|
||||||
|
code: 200,
|
||||||
|
msg: "没有数据要发送"
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
//向蓝牙设备发送数据,如果没连接将自动连接后再发
|
//向蓝牙设备发送数据,如果没连接将自动连接后再发
|
||||||
sendData(deviceid, buffer, writeServiceId, wirteCharactId, ms) {
|
sendData(deviceid, buffer, writeServiceId, wirteCharactId, ms) {
|
||||||
|
|
||||||
@ -1453,7 +1664,7 @@ class BleHelper {
|
|||||||
},
|
},
|
||||||
fail: (ex) => {
|
fail: (ex) => {
|
||||||
ex = this.getError(ex);
|
ex = this.getError(ex);
|
||||||
console.log("发送数据失败", ex);
|
console.error("发送数据失败", ex);
|
||||||
|
|
||||||
err(ex);
|
err(ex);
|
||||||
}
|
}
|
||||||
@ -1475,6 +1686,7 @@ class BleHelper {
|
|||||||
Promise.race([timeOut(ms), promise]).then(resolve).catch((ex) => {
|
Promise.race([timeOut(ms), promise]).then(resolve).catch((ex) => {
|
||||||
// console.error("ex=", ex);
|
// console.error("ex=", ex);
|
||||||
if (ex.code == -1) {
|
if (ex.code == -1) {
|
||||||
|
console.error('专业给Uniapp填坑,发送成功');
|
||||||
resolve(ex);
|
resolve(ex);
|
||||||
} else {
|
} else {
|
||||||
reject(ex);
|
reject(ex);
|
||||||
|
|||||||
@ -12,26 +12,25 @@ function checkAndUpdateWgt(updateUrl) {
|
|||||||
}
|
}
|
||||||
// 显示加载提示
|
// 显示加载提示
|
||||||
|
|
||||||
let urls = ['http://114.55.111.217/app/CheckUpdate', 'https://t3v3e2xsjv.by.takin.cc/app/CheckUpdate'];
|
let urls = ['https://dmsapp.skf.com.cn/HummerService/app/CheckUpdate'];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// 1. 获取当前应用版本信息
|
// 1. 获取当前应用版本信息
|
||||||
plus.runtime.getProperty(plus.runtime.appid, (widgetInfo) => {
|
plus.runtime.getProperty(plus.runtime.appid, (widgetInfo) => {
|
||||||
const currentVersion = widgetInfo.version;
|
const currentVersion = widgetInfo.version;
|
||||||
console.log("当前版本:" + currentVersion);
|
console.log("当前版本:" + currentVersion);
|
||||||
|
|
||||||
|
|
||||||
let callbck = (res) => {
|
let callbck = (res) => {
|
||||||
|
let flag = false;
|
||||||
uni.hideLoading();
|
uni.hideLoading();
|
||||||
// console.log("检查更新成功=", res)
|
console.log("检查更新成功=", res)
|
||||||
if (res.statusCode === 200) {
|
if (res.statusCode === 200) {
|
||||||
|
|
||||||
const updateInfo = res.data.data;
|
const updateInfo = res.data.data;
|
||||||
if (!updateInfo.hasUpdate) {
|
if (!updateInfo.hasUpdate) {
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
|
flag = true;
|
||||||
// 3. 显示更新提示
|
// 3. 显示更新提示
|
||||||
uni.showModal({
|
uni.showModal({
|
||||||
title: '检测到更新',
|
title: '检测到更新',
|
||||||
@ -45,16 +44,14 @@ function checkAndUpdateWgt(updateUrl) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
uni.showToast({
|
console.log('当前已是最新版本');
|
||||||
title: '当前已是最新版本',
|
|
||||||
icon: 'none',
|
|
||||||
duration: 2000
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return flag;
|
||||||
};
|
};
|
||||||
|
|
||||||
let Update = (url) => {
|
let Update = (url) => {
|
||||||
console.log("url=",url);
|
console.log("url=", url);
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
uni.request({
|
uni.request({
|
||||||
url: url,
|
url: url,
|
||||||
@ -62,42 +59,57 @@ function checkAndUpdateWgt(updateUrl) {
|
|||||||
data: {
|
data: {
|
||||||
currentVersion: currentVersion,
|
currentVersion: currentVersion,
|
||||||
platform: uni.getSystemInfoSync().platform,
|
platform: uni.getSystemInfoSync().platform,
|
||||||
appId:"xhyc"
|
appId: "xhyc"
|
||||||
},
|
},
|
||||||
success: (res) => {
|
success: (res) => {
|
||||||
// console.log("res=>",res)
|
// console.log("res=>",res)//坑,404居然进success
|
||||||
res.type='1';
|
if (res.statusCode === 200) {
|
||||||
resolve(res);
|
res.type = '1';
|
||||||
|
resolve(res);
|
||||||
|
} else {
|
||||||
|
reject(res);
|
||||||
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
fail: (err) => {
|
fail: (err) => {
|
||||||
console.log("err=",err);
|
console.log("err=", err);
|
||||||
reject(err);
|
reject(err);
|
||||||
},
|
},
|
||||||
complete:()=>{
|
complete: () => {
|
||||||
console.log("complete");
|
console.log("complete");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let Callback1 = (res) => {
|
let Callback1 = (res) => {
|
||||||
console.log("检查版本更新:", res);
|
console.log("检查版本更新:", res);
|
||||||
let os = plus.os.name.toLowerCase();
|
let os = plus.os.name.toLowerCase();
|
||||||
|
|
||||||
|
let flag = false;
|
||||||
if (res.code != 200) {
|
if (res.code != 200) {
|
||||||
return;
|
return flag;
|
||||||
}
|
}
|
||||||
let f = res.data.find(v => {
|
let f = res.data.find(v => {
|
||||||
|
|
||||||
if (v.dictLabel.toLowerCase() == os) {
|
if (v.dictLabel.toLowerCase() == os) {
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
console.log("f=", f)
|
||||||
if (f) {
|
if (f) {
|
||||||
if (f.dictValue == currentVersion) {
|
if (f.dictValue == currentVersion) {
|
||||||
|
flag = false;
|
||||||
|
return flag;
|
||||||
|
}
|
||||||
|
if(!f.dictValue || !f.remark){
|
||||||
|
flag=false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
flag = true;
|
||||||
uni.showModal({
|
uni.showModal({
|
||||||
title: '检测到更新',
|
title: '检测到更新',
|
||||||
content: '当前版本“' + currentVersion + '”,发现新版本“' + f.dictValue + '”,是否立即更新?',
|
content: '当前版本“' + currentVersion + '”,发现新版本“' + f.dictValue + '”,是否立即更新?',
|
||||||
@ -109,17 +121,20 @@ function checkAndUpdateWgt(updateUrl) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
flag = false;
|
||||||
}
|
}
|
||||||
|
return flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
let Update1 = () => {
|
let Update1 = () => {
|
||||||
return request({
|
return request({
|
||||||
url: '/app/auth/version',
|
url: '/app/auth/version',
|
||||||
method: 'get'
|
method: 'get'
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
let promises = [];
|
let promises = [];
|
||||||
for (var i = 0; i < urls.length; i++) {
|
for (var i = 0; i < urls.length; i++) {
|
||||||
promises.push(Update(urls[i]));
|
promises.push(Update(urls[i]));
|
||||||
@ -128,25 +143,25 @@ function checkAndUpdateWgt(updateUrl) {
|
|||||||
|
|
||||||
Promise.allSettled(promises).then(results => {
|
Promise.allSettled(promises).then(results => {
|
||||||
let length = results.length;
|
let length = results.length;
|
||||||
let flag=false;
|
let flag = false;
|
||||||
for (var i = 0; i < length; i++) {
|
for (var i = 0; i < length; i++) {
|
||||||
console.log('results['+i+']=',results[i]);
|
console.log('results[' + i + ']=', results[i]);
|
||||||
if (results[i].status == 'fulfilled' && results[i].value.type==='1' && !flag ) {
|
if (results[i].status == 'fulfilled' && results[i].value.type === '1' && !flag) {
|
||||||
flag=true;
|
if (results[i].value.statusCode === 200) {
|
||||||
callbck(results[i].value)
|
flag = callbck(results[i].value)
|
||||||
|
}
|
||||||
// break;
|
// break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(results[i].status == 'fulfilled' && results[i].value.type!=='1' && !flag){
|
if (results[i].status == 'fulfilled' && results[i].value.type !== '1' && !flag) {
|
||||||
flag=true;
|
|
||||||
Callback1(results[i].value);
|
flag = Callback1(results[i].value);
|
||||||
// break;
|
// break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(!flag){
|
if (!flag) {
|
||||||
console.log("检查更新失败了");
|
console.log("检查更新失败了");
|
||||||
}else{
|
} else {
|
||||||
console.log("检查更新成功");
|
console.log("检查更新成功");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
122
utils/wgs84_to_gcj02.js
Normal file
@ -0,0 +1,122 @@
|
|||||||
|
|
||||||
|
//地标 转 国测 常量
|
||||||
|
var x_PI = (3.14159265358979324 * 3000.0) / 180.0;
|
||||||
|
var PI = 3.1415926535897932384626;
|
||||||
|
var a = 6378245.0; //卫星椭球坐标投影到平面地图坐标系的投影因子。
|
||||||
|
var ee = 0.00669342162296594323; //椭球的偏心率。
|
||||||
|
|
||||||
|
|
||||||
|
//判断是否在国内,在中国国内的经纬度才需要做偏移
|
||||||
|
function out_of_china(lng, lat) {
|
||||||
|
return (
|
||||||
|
lng < 72.004 ||
|
||||||
|
lng > 137.8347 ||
|
||||||
|
(lat < 0.8293 || lat > 55.8271 || false)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
//转化经度
|
||||||
|
function transformlng(lng, lat) {
|
||||||
|
var ret =
|
||||||
|
300.0 +
|
||||||
|
lng +
|
||||||
|
2.0 * lat +
|
||||||
|
0.1 * lng * lng +
|
||||||
|
0.1 * lng * lat +
|
||||||
|
0.1 * Math.sqrt(Math.abs(lng));
|
||||||
|
ret +=
|
||||||
|
((20.0 * Math.sin(6.0 * lng * PI) +
|
||||||
|
20.0 * Math.sin(2.0 * lng * PI)) *
|
||||||
|
2.0) /
|
||||||
|
3.0;
|
||||||
|
ret +=
|
||||||
|
((20.0 * Math.sin(lng * PI) +
|
||||||
|
40.0 * Math.sin((lng / 3.0) * PI)) *
|
||||||
|
2.0) /
|
||||||
|
3.0;
|
||||||
|
ret +=
|
||||||
|
((150.0 * Math.sin((lng / 12.0) * PI) +
|
||||||
|
300.0 * Math.sin((lng / 30.0) * PI)) *
|
||||||
|
2.0) /
|
||||||
|
3.0;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
//转化纬度
|
||||||
|
function transformlat(lng, lat) {
|
||||||
|
var ret =
|
||||||
|
-100.0 +
|
||||||
|
2.0 * lng +
|
||||||
|
3.0 * lat +
|
||||||
|
0.2 * lat * lat +
|
||||||
|
0.1 * lng * lat +
|
||||||
|
0.2 * Math.sqrt(Math.abs(lng));
|
||||||
|
ret +=
|
||||||
|
((20.0 * Math.sin(6.0 * lng * PI) +
|
||||||
|
20.0 * Math.sin(2.0 * lng * PI)) *
|
||||||
|
2.0) /
|
||||||
|
3.0;
|
||||||
|
ret +=
|
||||||
|
((20.0 * Math.sin(lat * PI) +
|
||||||
|
40.0 * Math.sin((lat / 3.0) * PI)) *
|
||||||
|
2.0) /
|
||||||
|
3.0;
|
||||||
|
ret +=
|
||||||
|
((160.0 * Math.sin((lat / 12.0) * PI) +
|
||||||
|
320 * Math.sin((lat * PI) / 30.0)) *
|
||||||
|
2.0) /
|
||||||
|
3.0;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
//wgs84 to gcj02 地球坐标系 转 火星坐标系
|
||||||
|
function wgs84_to_gcj02(lng, lat) {
|
||||||
|
if (out_of_china(lng, lat)) {
|
||||||
|
return [lng, lat];
|
||||||
|
} else {
|
||||||
|
var dlat = transformlat(lng - 105.0, lat - 35.0);
|
||||||
|
var dlng = transformlng(lng - 105.0, lat - 35.0);
|
||||||
|
var radlat = (lat / 180.0) * PI;
|
||||||
|
var magic = Math.sin(radlat);
|
||||||
|
magic = 1 - ee * magic * magic;
|
||||||
|
var sqrtmagic = Math.sqrt(magic);
|
||||||
|
dlat =
|
||||||
|
(dlat * 180.0) /
|
||||||
|
(((a * (1 - ee)) / (magic * sqrtmagic)) * PI);
|
||||||
|
dlng =
|
||||||
|
(dlng * 180.0) / ((a / sqrtmagic) * Math.cos(radlat) * PI);
|
||||||
|
var mglat = lat + dlat;
|
||||||
|
var mglng = lng + dlng;
|
||||||
|
|
||||||
|
return [mglng, mglat];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//gcj02 to wgs84 火星坐标系 转 地球坐标系
|
||||||
|
function gcj02_to_wgs84(lng, lat) {
|
||||||
|
if (out_of_china(lng, lat)) {
|
||||||
|
return [lng, lat]
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
var dlat = transformlat(lng - 105.0, lat - 35.0);
|
||||||
|
var dlng = transformlng(lng - 105.0, lat - 35.0);
|
||||||
|
var radlat = lat / 180.0 * PI;
|
||||||
|
var magic = Math.sin(radlat);
|
||||||
|
magic = 1 - ee * magic * magic;
|
||||||
|
var sqrtmagic = Math.sqrt(magic);
|
||||||
|
dlat = (dlat * 180.0) / ((a * (1 - ee)) / (magic * sqrtmagic) * PI);
|
||||||
|
dlng = (dlng * 180.0) / (a / sqrtmagic * Math.cos(radlat) * PI);
|
||||||
|
var mglat = lat + dlat;
|
||||||
|
var mglng = lng + dlng;
|
||||||
|
return [lng * 2 - mglng, lat * 2 - mglat]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default {
|
||||||
|
gcj02_to_wgs84,
|
||||||
|
wgs84_to_gcj02
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||