1
0
forked from dyf/APP

Compare commits

...

8 Commits

30 changed files with 1366 additions and 16488 deletions

View File

@ -30,7 +30,7 @@
uni.getSystemInfo({success:function(res){
if(res.uniPlatform=='app'){
upgrade.checkAndUpdateWgt("http://114.55.111.217/app/CheckUpdate");
upgrade.checkAndUpdateWgt();
bleTool.getBleTool();
}
}});

View File

@ -83,10 +83,18 @@ function sendPic(data){
});
}
//设备详情
function getDetail(id){
return request({
url: '/api/xinghan/device/'+id,
method: 'get',
})
}
export default{
sendUsr:sendUsr,
warnMsg:warnMsg,
sendPic:sendPic
sendPic:sendPic,
getDetail:getDetail
}

View File

@ -226,78 +226,7 @@
"navigationBarTitleText": "呼叫"
}
},
{
"path": "pages/BlueTooth/ModeSetting/index",
"style": {
"navigationBarTitleText": "设备类型"
}
},
{
"path": "pages/BlueTooth/ModeSetting/VideoSend",
"style": {
"navigationBarTitleText": "发送视频"
}
},
{
"path": "pages/BlueTooth/ModeSetting/VideoSend_1",
"style": {
"navigationBarTitleText": "发送视频"
}
},
{
"path": "pages/BlueTooth/ModeSetting/VideoSend_670",
"style": {
"navigationBarTitleText": "发送视频"
}
},
{
"path": "pages/BlueTooth/ModeSetting/HBY650",
"style": {
"navigationBarTitleText": "HBY650"
}
},
{
"path": "pages/BlueTooth/ModeSetting/HBY650_1",
"style": {
"navigationBarTitleText": "HBY650"
}
},
{
"path": "pages/BlueTooth/ModeSetting/ModeSetting",
"style": {
"navigationBarTitleText": "7307-0.96TFT"
}
},
{
"path": "pages/BlueTooth/ModeSetting/update",
"style": {
"navigationBarTitleText": "版本更新"
}
},
{
"path": "pages/BlueTooth/ModeSetting/HBY6155",
"style": {
"navigationBarTitleText": "HBY6155"
}
},
{
"path": "pages/BlueTooth/ModeSetting/HBY6155V1",
"style": {
"navigationBarTitleText": "HBY6155_V1"
}
},
{
"path": "pages/BlueTooth/ModeSetting/HBY670V1",
"style": {
"navigationBarTitleText": "HBY670"
}
},
{
"path": "pages/670/HBY670",
"style": {
@ -318,19 +247,12 @@
}
},
{
"path": "pages/BlueTooth/ModeSetting/4877",
"path": "pages/7305/BJQ7305",
"style": {
"navigationBarTitleText": ""
}
},
{
"path" : "pages/7305/BJQ7305",
"style" :
{
"navigationBarTitleText" : "BJQ7305"
"navigationBarTitleText": "BJQ7305"
}
}
],
"tabBar": {

View File

@ -181,7 +181,8 @@
visiblePrompt: false,
promptTitle: '设备名称',
modelValue: '',
visibleClose: false
visibleClose: false,
okCallback:null
},
BottomMenu: {
show: false,
@ -328,7 +329,7 @@
});
if (!f) {
these.getDetail();
these.showBleUnConnect();
return;
}
@ -347,7 +348,7 @@
these.formData.deviceId = f.deviceId;
ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId);
these.setBleFormData();
these.getDetail();
});
@ -875,7 +876,7 @@
setMode(mode, type) {
let dataValue = 0;
switch (mode) {
case 0:
@ -1203,7 +1204,22 @@
setTimeout(task, 0);
},
getDetail() {
var that = this;
usrApi.getDetail(this.device.id).then(res => {
if (res && res.code == 200) {
res = res.data;
let personnelInfo = res.personnelInfo;
if (personnelInfo) {
these.formData.textLines[2] = personnelInfo.unitName;
these.formData.textLines[1] = personnelInfo.name;
these.formData.textLines[0] = personnelInfo.position;
}
}
});
},
ack: function() {

View File

@ -200,7 +200,8 @@
visiblePrompt: false,
promptTitle: '设备名称',
modelValue: '',
visibleClose: false
visibleClose: false,
okCallback:null
},
BottomMenu: {
show: false,
@ -255,10 +256,10 @@
cMode: false,
modeCurr: 'low',
company: '黄石消防支队',
name: '菜英俊',
job: '小队长',
id: 'HSXF01061',
company: '',
name: '',
job: '',
id: '',
iswarn: false
},
rgb565Data: [],
@ -314,6 +315,7 @@
these.showBleUnConnect();
these.getDetail();
return;
}
let form = f.formData;
@ -331,7 +333,7 @@
these.formData.deviceId = f.deviceId;
ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId);
these.setBleFormData();
these.getDetail();
});
@ -392,7 +394,7 @@
return className;
},
bleValueNotify: function(receive, device, path) { //订阅消息
console.log("收到设备的数据", data)
console.log("收到设备的数据", receive)
let data = recei.ReceiveData(receive, device, pagePath);
if (data) {
@ -457,6 +459,23 @@
return f;
},
getDetail() {
var that = this;
usrApi.getDetail(this.device.id).then(res => {
if (res && res.code == 200) {
res = res.data;
let personnelInfo = res.personnelInfo;
if (personnelInfo) {
that.formData.company = personnelInfo.unitName;
that.formData.name = personnelInfo.name;
that.formData.job = personnelInfo.position;
that.formData.id = personnelInfo.code
}
}
});
},
setBleFormData() {
ble.data.LinkedList.find((v) => {
if (v.deviceId == these.formData.deviceId) {
@ -491,7 +510,7 @@
dataValue = 0x65;
break;
case "close": //关闭
dataValue = 0x68;
dataValue = 0x64;
break;
case true: //开灯
dataValue = 0x6E;
@ -959,8 +978,8 @@
}
uni.uploadFile({
// url: 'http://114.55.111.217/video/upload',
url: baseURL+"app/video/upload",
url: 'http://114.55.111.217/video/upload',
// url: baseURL+"app/video/upload",
filePath: videoPath,
name: 'file',
header: {
@ -1126,9 +1145,12 @@
if (this.Status.Pop.clickEvt == 'SendUsr') {
}
console.log("1111");
this.Status.Pop.showPop = false;
if(this.Status.Pop.okCallback){
this.Status.Pop.okCallback();
}
},
showPop: function(option) {

View File

@ -27,19 +27,37 @@
<view class="eqinfo">
<view class="item">
<text class="lbl">设备IMEI</text>
<text class="value">{{device.deviceImei}}</text>
<text class="value valueFont">{{device.deviceImei}}</text>
</view>
<view class="item">
<text class="lbl">设备名称</text>
<text class="value">{{device.deviceName}}</text>
<text class="value valueFont">{{device.deviceName}}</text>
</view>
<view class="item">
<text class="lbl">设备状态</text>
<text class="value valueFont">{{formData.sta_system}}</text>
</view>
<view class="item">
<text class="lbl">定位信息</text>
<view>
<view>{{formData.lon}}&nbsp;&nbsp;{{formData.lat}}</view>
<text class="value">{{formData.address}}</text>
<view class="multiValue">
<view class="valueItem valueFont">
{{formData.Lon}}
</view>
<view class="valueItem valueFont">
{{formData.Lat}}
</view>
<view class="valueItem">
<view style="width:80%;float: right;text-align: right;" class="valueFont">{{formData.address}}
</view>
<view class="clear"></view>
</view>
</view>
</view>
</view>
@ -78,6 +96,10 @@
@click="GearSetting('hight','staticBattery')">
<view class="p100 center">高档</view>
</view>
<view class="item " :class="formData.modeCurr=='close'?'active':''"
@click="GearSetting('close','staticBattery')">
<view class="p100 center">关闭</view>
</view>
</view>
<view class="optTitle">
@ -201,15 +223,15 @@
<view class="proinfo lamp">
<text class="title">产品信息</text>
<view class="itemcontent">
<view class="item" @click="proParam()">
<view class="item" @click="proDetail('productDes')">
<image class="img" src="/static/images/6155/DeviceDetail/param.png" mode="aspectFit"></image>
<text class="txt">产品参数</text>
</view>
<view class="item" @click="handRemark()">
<view class="item" @click="proDetail('operatingInstruct')">
<image class="img" src="/static/images/6155/DeviceDetail/remark.png" mode="aspectFit"></image>
<text class="txt">操作说明</text>
</view>
<view class="item" @click="handVideo()">
<view class="item" @click="proDetail('operationVideo')">
<image class="img" src="/static/images/6155/DeviceDetail/video.png" mode="aspectFit"></image>
<text class="txt">操作视频</text>
</view>
@ -246,6 +268,7 @@
import BleReceive from '@/utils/BleReceive';
import api from '@/api/670/HBY670.js';
import MqttClient from '@/utils/mqtt.js';
import Common from '@/utils/Common.js'
import {
showLoading,
hideLoading,
@ -299,7 +322,7 @@
promptTitle: '设备名称',
modelValue: '',
visibleClose: false,
okCallback: null
},
BottomMenu: {
show: false,
@ -358,7 +381,8 @@
warnLevel: "", //报警级别
staticWarn: false, //静止报警
fourGStrenth: 0, //4G信号强度
deviceId: ""
deviceId: "",
sta_system: "" //设备状态0关机1仅充电2开机未充电,3开机且充电
},
device: {
id: "",
@ -381,7 +405,8 @@
},
rgb565Data: [],
videoHexArray: [],
picPath: ""
picPath: "",
permissions:[]//权限列表
}
},
created() {
@ -413,6 +438,15 @@
var device = data.data;
these.Status.apiType = data.apiType;
these.device = device;
if(data.apiType!=='listA'){
Common.getdeviceShareId(data.data.id).then(res=>{
if(res.code==200){
if(res.data.permission){
these.permissions=res.data.permission.split(',');
}
}
});
}
if (these.device.deviceImei) {
these.initMQ();
}
@ -425,6 +459,7 @@
return false;
});
if (!f) {
these.getDetail();
return;
}
let form = f.formData;
@ -440,6 +475,7 @@
} else if (these.device.deviceImei) {
these.formData['imei'] = these.device.deviceImei;
}
these.getDetail();
ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId);
});
@ -454,6 +490,75 @@
},
methods: {
getDetail() {
var that = this;
api.getDetail(this.device.id).then(res => {
if (res && res.code == 200) {
res = res.data;
let json = res;
console.log("res=", res);
that.formData.Lon = res.longitude;
that.formData.Lat = res.latitude;
that.formData.address = res.address;
let personnelInfo = res.personnelInfo;
if (personnelInfo) {
that.formData.company = personnelInfo.unitName;
that.formData.usrname = personnelInfo.name;
that.formData.job = personnelInfo.position;
that.formData.usrid = personnelInfo.code
}
let dic = {
"3": "hight",
"2": "center",
"1": "low",
"0": "close",
};
let staticLevelText = dic[json.staDetectGrade];
that.formData.modeCurr = staticLevelText;
dic = {
"0": "none",
"1": "ruo",
"2": "center",
"3": "hight",
"4": "veryhight",
};
let warn = dic[json.staDetectResult];
that.formData.warnLevel = warn;
let lightingLevelText = json.staLightGrade === 1 ? 'hight' : json.staLightGrade === 2 ?
'low' :
'close';
that.formData.lightCurr = lightingLevelText;
that.formData.battary = json.staPowerPercent
let hours = Math.floor(json.staPowerTime / 60);
let remainingMinutes = json.staPowerTime % 60;
let xuhang = '0分';
// 处理不同情况的显示
if (hours === 0) {
xuhang = `${remainingMinutes}`;
} else if (remainingMinutes === 0) {
xuhang = `${hours}小时`;
} else {
xuhang = `${hours}小时${remainingMinutes}`;
}
that.formData.xuhang = xuhang;
let sosText = json.staSOSGrade === 2 ? 'rb' : json.staSOSGrade === 1 ? "sg" : "close";
that.formData.SOS = sosText;
}
});
},
getWarnStyle(index) {
let className = "";
@ -505,8 +610,11 @@
ack: function(data) {}
},
success: (res) => {
debugger;
let json={persissonType:'670'};
Object.assign(json,this.device);
res.eventChannel.emit('share', {
data: this.device,
data:json
});
}
})
@ -540,6 +648,7 @@
console.log("收到设备上报的数据", payload);
this.parseDataMQ(json);
}
//以下操作已改到后端
// else if (keys.indexOf('sta_PicTrans') > -1) { //发送开机画面
// console.log("收到开机画面答复", payload);
// // this.SendImgMQ(json);
@ -598,56 +707,80 @@
},
parseDataMQ(json) {
let receiveData = {};
let staticLevelText = "";
let dic = {
"3": "hight",
"2": "center",
"1": "low",
"0": "close",
};
staticLevelText = dic[json.sta_DetectGrade];
let dic = {};
if ("sta_DetectGrade" in json) {
dic = {
"3": "hight",
"2": "center",
"1": "low",
"0": "close",
let lightingLevelText = json.sta_LightGrade ===
1 ? 'hight' :
json.sta_LightGrade ===
2 ?
'low' :
'close';
let warn = "";
dic = {
"0": "none",
"1": "ruo",
"2": "center",
"3": "hight",
"4": "veryhight",
};
warn = dic[json.sta_DetectResult];
};
let staticLevelText = dic[json.sta_DetectGrade];
receiveData.modeCurr = staticLevelText;
}
if ("sta_LightGrade" in json) {
let sosText = null;
if (json.sta_SOSGrade !== undefined) {
let lightingLevelText = json.sta_LightGrade === 1 ? 'hight' : json.sta_LightGrade === 2 ? 'low' :
'close';
receiveData.lightCurr = lightingLevelText;
}
if ("sta_DetectResult" in json) {
sosText = json.sta_SOSGrade === 2 ? 'rb' :
json.sta_SOSGrade === 1 ? "sg" : "close"
dic = {
"0": "none",
"1": "ruo",
"2": "center",
"3": "hight",
"4": "veryhight",
};
let warn = dic[json.sta_DetectResult];
receiveData.warnLevel = warn;
}
if ("sta_SOSGrade" in json) {
let sosText = json.sta_SOSGrade === 2 ? 'rb' : json.sta_SOSGrade === 1 ? "sg" : "close";
receiveData.SOS = sosText;
}
let staticWarn = json.sta_ShakeBit === 1;
receiveData.modeCurr = staticLevelText;
receiveData.lightCurr = lightingLevelText;
receiveData.xuhang = json.sta_PowerTime + "分钟";
receiveData.battary = json.sta_PowerPercent;
if ("sta_ShakeBit" in json) {
let staticWarn = json.sta_ShakeBit === 1;
receiveData.staticWarn = staticWarn;
}
receiveData.warnLevel = warn;
receiveData.staticWarn = staticWarn;
receiveData.fourGStrenth = json.sta_4gSinal;
receiveData.imei = json.sta_imei;
receiveData.Lon = json.sta_longitude;
receiveData.Lat = json.sta_latitude;
if ("sta_PowerTime" in json) {
let hours = Math.floor(json.sta_PowerTime / 60);
let remainingMinutes = json.sta_PowerTime % 60;
let xuhang = '0分';
// 处理不同情况的显示
if (hours === 0) {
xuhang = `${remainingMinutes}`;
} else if (remainingMinutes === 0) {
xuhang = `${hours}小时`;
} else {
xuhang = `${hours}小时${remainingMinutes}`;
}
receiveData.xuhang = xuhang;
}
("sta_PowerPercent" in json) && (receiveData.battary = json.sta_PowerPercent);
("sta_4gSinal" in json) && (receiveData.fourGStrenth = json.sta_4gSinal);
("sta_imei" in json) && (receiveData.imei = json.sta_imei);
("sta_longitude" in json) && (receiveData.Lon = json.sta_longitude);
("sta_latitude" in json) && (receiveData.Lat = json.sta_latitude);
if ("sta_system" in json) {
dic = {
"0": "关机",
"1": "仅充电",
"2": "开机未充电",
"3": "开机且充电"
}
receiveData.sta_system = dic[json.sta_system];
}
this.refreshFormData(receiveData, 'auto');
return receiveData;
},
@ -686,14 +819,14 @@
for (var i = 0; i < keys.length; i++) {
let key = keys[i];
if (key in these.formData) {
these.formData[key] = data[key];
this.formData[key] = data[key];
}
}
if (this.formData.imei) {
this.initMQ();
}
if (this.formData.staticWarn) { //有静止报警
these.showPop({
this.showPop({
message: "设备静止报警中",
iconUrl: "/static/images/6155/DeviceDetail/warnning.png",
borderColor: "#e034344d",
@ -701,8 +834,6 @@
buttonText: "确定",
clickEvt: "staticWarn"
});
}
this.setBleFormData();
@ -732,6 +863,18 @@
},
lightSetting: function(type) {
if(!this.permissions.includes('1') && this.Status.apiType!=='listA'){
this.showPop({
message: '无操作权限',
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
borderColor: "#e034344d",
buttonBgColor: "#E03434",
okCallback: null,
buttonText: "确定"
})
return;
}
if (this.formData.lightCurr == type) {
return;
}
@ -897,11 +1040,30 @@
borderColor: "#e034344d",
buttonBgColor: "#E03434",
buttonText: "解除报警",
okCallback: callback,
okCallback: () => {
if (callback) {
callback();
}
this.Status.Pop.okCallback = null;
},
clickEvt: 'time'
});
},
sosSetting: function(type) {
if(!this.permissions.includes('42') && this.Status.apiType!=='listA'){
this.showPop({
message: '无操作权限',
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
borderColor: "#e034344d",
buttonBgColor: "#E03434",
okCallback: null,
buttonText: "确定"
})
return;
}
if (this.formData.SOS == type) {
type = "close";
}
@ -985,7 +1147,7 @@
let OpenSOS = () => {
these.formData.qzwarn = true; //标记为强制报警了
these.Status.staticWarn.time = 50;
these.Status.staticWarn.time = 180;
this.formData.SOS = type;
let loopFunc = () => {
@ -1009,21 +1171,34 @@
console.log("111111");
this.showQzWarn(this.Status.Pop.okCallback);
}
}
these.Status.staticWarn.inteval = setInterval(() => {
loopFunc();
}, 1000)
}, 1000);
bleSendCmd();
}
if (type == 'rb') { //红蓝报警
this.formData.SOS = type;
bleSendCmd();
return;
}
if (type == 'sg') //强制报警
console.log("11111");
let sendRb = () => {
this.formData.SOS = type;
bleSendCmd();
these.formData.qzwarn=false;
this.Status.staticWarn.time=0;
return;
}
if (these.formData.qzwarn) {
console.log("222222");
these.showQzWarn(sendRb);
} else {
sendRb();
}
} else if (type == 'sg') //强制报警
{
this.showPop({
@ -1035,8 +1210,7 @@
buttonText: "开启"
});
return;
}
if (type == 'close') {
} else if (type == 'close') {
if (this.formData.SOS = 'sg') { //解除声光报警
this.CloseWarn(true);
@ -1053,8 +1227,20 @@
setTimeout(task, 0);
},
GearSetting: function(type) { //档位设置
if(!this.permissions.includes('41') && this.Status.apiType!=='listA'){
this.showPop({
message: '无操作权限',
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
borderColor: "#e034344d",
buttonBgColor: "#E03434",
okCallback: null,
buttonText: "确定"
})
return;
}
if (this.formData.modeCurr == type) {
type = "close";
return;
}
showLoading(this, {
text: "请稍候..."
@ -1066,7 +1252,7 @@
hight: 0x65,
center: 0x66,
low: 0x67,
close: 0x68
close: 0x64
},
mqtt: {
hight: 3,
@ -1137,32 +1323,27 @@
setTimeout(task, 0);
},
proParam: function() {
proDetail:function(type){
if(!this.permissions.includes('41') && this.Status.apiType!=='listA'){
this.showPop({
message: '无操作权限',
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
borderColor: "#e034344d",
buttonBgColor: "#E03434",
okCallback: null,
buttonText: "确定"
})
return;
}
uni.navigateTo({
url: '/pages/common/productDes/index?id=' + this.device.id,
url: '/pages/common/'+type+'/index?id=' + this.device.id,
success(ev) {
}
});
},
handRemark: function() {
uni.navigateTo({
url: '/pages/common/operatingInstruct/index?id=' + this.device.id,
success(ev) {
}
});
},
handVideo: function() {
uni.navigateTo({
url: '/pages/common/operationVideo/index?id=' + this.device.id,
success(ev) {
}
});
},
checkImgUpload: function(type, index) {
console.log("123213213213");
let f = these.getDevice();
@ -1576,8 +1757,8 @@
}
console.log("baseURL=", baseURL);
uni.uploadFile({
// url: 'http://114.55.111.217/video/upload',
url: baseURL + "/app/video/upload",
url: 'http://114.55.111.217/video/upload',
// url: baseURL + "/app/video/upload",
filePath: videoPath,
name: 'file',
header: {
@ -1617,7 +1798,7 @@
} else {
console.log("服务器未返回正确的数据");
console.log("服务器未返回正确的数据", arr);
these.showPop({
@ -1700,6 +1881,18 @@
},
ShowUpload: function() {
if(!this.permissions.includes('3') && this.Status.apiType!=='listA'){
this.showPop({
message: '无操作权限',
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
borderColor: "#e034344d",
buttonBgColor: "#E03434",
okCallback: null,
buttonText: "确定"
})
return;
}
//上传开机画面
this.Status.BottomMenu.menuItems = [];
this.Status.BottomMenu.title = "上传开机画面";
@ -1794,6 +1987,19 @@
this.Status.Pop.showPop = true;
},
sendUsr: function(ReSendNo) {
if(!this.permissions.includes('4') && this.Status.apiType!=='listA'){
this.showPop({
message: '无操作权限',
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
borderColor: "#e034344d",
buttonBgColor: "#E03434",
okCallback: null,
buttonText: "确定"
})
return;
}
let requestSend = () => {
let json = {
@ -1988,6 +2194,19 @@
},
sendUrgent(type) {
if(!this.permissions.includes('5') && this.Status.apiType!=='listA'){
this.showPop({
message: '无操作权限',
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
borderColor: "#e034344d",
buttonBgColor: "#E03434",
okCallback: null,
buttonText: "确定"
})
return;
}
if (!this.formData.msgTxt) {
return;
@ -1996,7 +2215,7 @@
text: "请稍候..."
});
this.setBleFormData();
let data = {
"sendMsg": this.formData.msgTxt,
@ -2187,7 +2406,8 @@
.eqinfo .item {
width: 100%;
height: 60rpx;
min-height: 60rpx;
height: auto;
line-height: 60rpx;
padding: 0rpx 28rpx;
box-sizing: border-box;
@ -2204,21 +2424,49 @@
font-family: PingFang SC;
font-size: 28rpx;
font-weight: 400;
width: 140rpx;
letter-spacing: 0.07px;
text-align: left;
}
.eqinfo .value {
color: rgba(255, 255, 255, 0.6);
font-family: PingFang SC;
font-size: 28rpx;
font-family: 'PingFang SC';
font-size: 28rpx !important;
font-weight: 400;
letter-spacing: 0.07px;
text-align: left;
}
.eqinfo .valueFont {
font-family: 'PingFang SC';
font-size: 28rpx !important;
font-weight: 400;
color: rgba(255, 255, 255, 0.6);
}
.eqinfo .multiValue {
display: flex;
flex-direction: column;
flex-wrap: wrap;
align-content: flex-end;
align-items: flex-end;
justify-content: flex-start;
width: calc(100% - 140rpx)
}
.eqinfo .valueItem {
height: auto;
line-height: 40rpx;
color: rgba(255, 255, 255, 0.6);
font-family: PingFang SC;
font-size: 14px;
font-weight: 400;
letter-spacing: 0.07px;
}
.lamp {
margin-top: 24rpx;
}

View File

@ -158,7 +158,7 @@
var these = null;
var BrighInteval = null;
var recei = null;
export default {
components: {
TextToHexV1
@ -181,7 +181,8 @@
visiblePrompt: false,
promptTitle: '设备名称',
modelValue: '',
visibleClose: false
visibleClose: false,
okCallback:null
},
BottomMenu: {
show: false,
@ -317,7 +318,7 @@
let device = data.data;
these.device = device;
let f = ble.data.LinkedList.find((v) => {
if (v.macAddress == device.deviceMac) {
console.log("找到设备了", v);
@ -328,7 +329,7 @@
});
if (!f) {
these.getDetail();
these.showBleUnConnect();
return;
}
@ -347,7 +348,7 @@
these.formData.deviceId = f.deviceId;
ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId);
these.setBleFormData();
these.getDetail();
});
@ -385,15 +386,15 @@
}
switch (this.formData.mode) {
case 0:
txt = "强光模式";
break;
case 1:
txt = "弱光模式";
break;
case 2:
txt = "爆闪模式";
break;
@ -403,7 +404,7 @@
default:
txt = "关闭";
break;
}
return txt;
}
@ -419,9 +420,9 @@
return f;
},
bleValueNotify: function(receive, device, path) {
let str = recei.ReceiveData(receive, device, path);
console.log("处理接收到的数据:" + str);
return;
let data = recei.ReceiveData(receive, device, path);
@ -529,29 +530,31 @@
}
});
},
showBleUnConnect(){
showBleUnConnect() {
this.showPop({
message: "蓝牙未连接过该设备,请使用蓝牙重新添加该设备",
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
borderColor: "#e034344d",
buttonBgColor: "#E03434",
buttonText:'去连接',
okCallback:function(){
buttonText: '去连接',
okCallback: function() {
console.log("1111");
uni.navigateTo({
url:"/pages/common/addBLE/addEquip",
events: {
BindOver: function(data) {
console.log(data)
}
},
success: function(res) {
// 通过eventChannel向被打开页面传送数据
res.eventChannel.emit('detailData', { data: these.device })
},
fail(ex){
console.log("跳转失败",ex);
}
url: "/pages/common/addBLE/addEquip",
events: {
BindOver: function(data) {
console.log(data)
}
},
success: function(res) {
// 通过eventChannel向被打开页面传送数据
res.eventChannel.emit('detailData', {
data: these.device
})
},
fail(ex) {
console.log("跳转失败", ex);
}
})
}
});
@ -642,8 +645,8 @@
these.showPop({
message: "上传成功",
iconUrl: "/static/images/6155/DeviceDetail/uploadSuccess.png",
borderColor : '#BBE600',
buttonBgColor : '#BBE600'
borderColor: '#BBE600',
buttonBgColor: '#BBE600'
});
resolve();
@ -889,9 +892,9 @@
case 1:
dataValue = 0x02;
break;
// case 2:
// dataValue = 0x02;
// break;
// case 2:
// dataValue = 0x02;
// break;
case 2:
dataValue = 0x03;
break;
@ -974,7 +977,7 @@
if (this.Status.Pop.clickEvt == 'SendUsr') {
}
if(this.Status.Pop.okCallback){
if (this.Status.Pop.okCallback) {
this.Status.Pop.okCallback();
}
this.Status.Pop.showPop = false;
@ -992,11 +995,11 @@
okCallback: null,
cancelCallback: null,
popType: 'custom',
buttonText:'确定',
buttonText: '确定',
clickEvt: ''
};
if (!option) {
}
let keys = Object.keys(option);
for (var i = 0; i < keys.length; i++) {
@ -1011,7 +1014,7 @@
}
this.Status.Pop[key] = defaultCfg[key];
}
this.Status.Pop.showPop = true;
},
sendUsr() {
@ -1171,18 +1174,18 @@
console.log("发送成功");
this.showPop({
message: "发送成功",
iconUrl: "/static/images/6155/DeviceDetail/uploadSuccess.png",
borderColor : '#BBE600',
buttonBgColor : '#BBE600'
iconUrl: "/static/images/6155/DeviceDetail/uploadSuccess.png",
borderColor: '#BBE600',
buttonBgColor: '#BBE600'
});
let json = {
deviceId: these.device.id,
name: these.formData.textLines[1],
position: these.formData.textLines[0],
deviceId: these.device.id,
name: these.formData.textLines[1],
position: these.formData.textLines[0],
unitName: these.formData.textLines[2],
code: ""
};
@ -1199,7 +1202,22 @@
setTimeout(task, 0);
},
getDetail() {
var that = this;
usrApi.getDetail(this.device.id).then(res => {
if (res && res.code == 200) {
res = res.data;
let personnelInfo = res.personnelInfo;
if (personnelInfo) {
these.formData.textLines[2] = personnelInfo.unitName;
these.formData.textLines[1] = personnelInfo.name;
these.formData.textLines[0] = personnelInfo.position;
}
}
});
},
ack: function() {

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,525 +0,0 @@
<template>
<view class="content">
<view>
重发包序号:{{reSendNumber}}
</view>
<view>
<text>发送间隔</text>
<input type="text" v-model="inteval" />
</view>
<view>
<button @click="checkVideo">选择视频</button>
<button @click="uploadVideo">发送</button>
</view>
<view class="sending-progress" v-if="isSending">
<view class="progress-bar">
<view class="progress-fill" :style="{ width: progress + '%' }"></view>
</view>
<text>正在发送: {{ progress }}% ({{ currentPacket }}/{{ totalPackets }})</text>
</view>
</view>
</template>
<script>
import Common from '@/utils/Common';
export default {
data() {
return {
videoPath: '',
inteval: 0,
progress: 0,
currentPacket: 0,
totalPackets: 100,
connectedDeviceId: '',
serviceId: '0xFFE1',
writeCharacteristicId: '0xFFE1',
notifyCharacteristicId: '0xFFE2',
isSending: "",
textProgress: "",
imgs: [],
videoWidth: 320,
videoHeight: 160,
videoDuration: 2,
reSendNumber:null,
hexArray: []
}
},
onLoad() {
const eventChannel = this.getOpenerEventChannel();
eventChannel.on('receiveDevice', (data) => {
this.connectedDeviceId = data.connectedDeviceId;
this.serviceId = data.serviceId;
this.writeCharacteristicId = data.writeCharacteristicId;
this.notifyCharacteristicId = data.notifyCharacteristicId;
});
eventChannel.on('ReSendVideo', (data) => {
//重新发送某一包
this.reSendNumber = data.videoNo;
setTimeout(() => {
this.shotVideoClick(this.hexArray, 'rgb565', data.videoNo);
}, 0);
});
},
methods: {
checkVideo: function() {
uni.chooseVideo({
sourceType: ['album', 'camera'],
compressed: false,
maxDuration: 2,
camera: 'back',
success: (res) => {
this.videoPath = res.tempFilePath;
this.imgs = [];
this.hexArray = [];
this.videoWidth = res.width;
this.videoHeight = res.height;
this.videoDuration = res.duration;
console.log("视频宽:" + res.width + ",视频高:" + res.height + ",视频时长:" + res.duration);
}
})
},
uploadVideo: function() {
if (this.hexArray.length > 0) {
console.log("开始处理,无需上传");
this.shotVideoClick(this.hexArray, 'rgb565');
return;
}
if (!this.videoPath) {
uni.showToast({
title: "请选择视频",
icon: 'fail'
})
return;
}
console.log("正在上传视频");
uni.showLoading({
title: "上传中"
});
let p2 = new Promise((resolve, reject) => {
let start = new Date();
console.log("Common.baseURL=" + Common.baseURL);
uni.uploadFile({
// url: Common.baseURL + 'video/upload',
url:'http://192.168.110.56:8000/app/video/upload',
filePath: this.videoPath,
name: 'file',
header: {
"Method": "POST",
"Content-Type": "multipart/form-data"
},
timeout: 600000,
fail: (ex) => {
//console.log("上传视频失败" + JSON.stringify(ex));
uni.showToast({
title: "视频文件上传失败了,请检查网络连接",
icon: 'fail'
})
uni.hideLoading();
reject(ex);
},
success: (res) => {
let end = new Date();
var diff = (end.getTime() - start.getTime()) / 1000;
let s = diff % 60;
let m = (diff - s) / 60;
console.log("上传完成,耗时:" + m + "分" + s + "秒");
uni.hideLoading();
resolve(res);
}
});
});
let p1 = this.HoldYouHand();
Promise.all([p2, p1]).then((arr) => {
if (arr[1] === true) {
let res = arr[0];
res = JSON.parse(res.data);
if (res.data) {
this.hexArray = res.data;
uni.showLoading({
title: "正在发送"
});
setTimeout(() => {
this.shotVideoClick(res.data, 'rgb565');
}, 0)
} else {
console.log("res")
uni.showModal({
content: "服务器未返回RGB565数据",
title: '错误'
})
}
} else {
uni.showModal({
content: "与设备握手失败了",
title: "错误"
})
}
});
},
bleSendComplete() {
var str = "transmit complete"; //握手的协议字符串
let buffer = new ArrayBuffer(str.length);
let dataView = new DataView(buffer);
for (let i = 0; i < str.length; i++) {
dataView.setUint8(i, str.charCodeAt(i));
}
setTimeout(() => {
this.sendData(buffer).then(() => {
console.log("完成指令发送成功");
}).catch(err => {
console.log("完成指令发送失败");
});
}, 3000)
},
shotVideoClick: function(array, type, ReSendNo) {
//console.log("处理视频完成", array);
//console.log("type=" + type)
//console.log("array=", array);
this.imgs = array;
var sendImagePackets = (imageData) => {
return new Promise((resolve, reject) => {
this.isSending = true;
this.progress = 0;
this.currentPacket = 0;
// 总数据包数
const totalPackets = 1536;
this.totalPackets = totalPackets;
let currentPacket = 1;
if (ReSendNo) {
console.log("11111");
this.progress = ReSendNo - 1;
this.currentPacket = ReSendNo - 1;
console.log("22222");
this.totalPackets = ReSendNo;
console.log("11111=",ReSendNo);
}
// 发送单个数据包
const sendNextPacket = () => {
console.log("currentPacket="+currentPacket+",imageData.length="+imageData.length);
if (currentPacket > totalPackets) {
this.isSending = false;
if (!ReSendNo) {
this.bleSendComplete();
} else {
// this.reSendNumber="";
}
resolve();
return;
}
// 计算当前包的数据
let packetSize = 250;
if (type == 'rgb565') {
packetSize = 500;
}
// 创建数据包
const startIndex = (currentPacket - 1) * packetSize;
const endIndex = Math.min(startIndex + packetSize, imageData.length);
if (startIndex > endIndex) {
resolve();
return;
}
console.log("111111");
const packetData = imageData.slice(startIndex, endIndex);
// 构建数据包
console.log("packetData.length"+packetData.length);
const bufferSize = 506; // 头部5字节 + 数据部分
const buffer = new ArrayBuffer(bufferSize);
const dataView = new DataView(buffer);
let sortNo = currentPacket.toString(16).padStart(4, '0');
// 填充头部
dataView.setUint8(0, 0x55); // 帧头
dataView.setUint8(1, 0x04); // 帧类型:开机画面
dataView.setUint8(2, '0x' + sortNo.substring(0, 2)); // 包序号
dataView.setUint8(3, '0x' + sortNo.substring(2, 4)); // 包序号
dataView.setUint8(4, 0x01);
dataView.setUint8(5, 0xF4);
if (type == 'rgb565') {
for (let i = 0; i < packetData.length; i++) {
dataView.setUint8(6 + i, '0x' + packetData[i]);
}
} else {
for (let i = 0; i < packetData.length; i++) {
dataView.setUint16(6 + i * 2, packetData[i], false);
}
}
let inteval = parseInt(this.inteval ? this.inteval : 0);
this.sendData(buffer).then(() => {
if(ReSendNo){
this.isSending = false;
resolve();
return;
}
// 更新进度
this.currentPacket = currentPacket;
this.progress = Math.round((currentPacket / totalPackets) *
100);
console.log(`发送数据包完成 ${currentPacket}/${totalPackets}`);
// 发送下一个包(添加延迟避免蓝牙缓冲区溢出)
currentPacket++;
setTimeout(sendNextPacket, inteval);
}).catch(err => {
// console.log(err.errMsg + ",发送失败了,正在补偿:" + currentPacket);
setTimeout(sendNextPacket, inteval);
// uni.showToast({
// title:"发送失败"+JSON.stringify(err)
// })
});
};
sendNextPacket();
});
}
if (type == 'rgb565') {
let start = new Date();
console.log("开始发送");
sendImagePackets(array).then(() => {
console.log("发送完成");
let end = new Date();
var diff = (end.getTime() - start.getTime()) / 1000;
let s = diff % 60;
let m = (diff - s) / 60;
console.log("发送完成,耗时:" + m + "分" + s + "秒");
uni.showModal({
content:"发送完成,耗时:" + m + "分" + s + "秒",
title:"提示"
});
}).catch((ex1) => {
//console.log("出现了异常", ex1)
}).finally(() => {
uni.hideLoading();
});
return;
}
},
HoldYouHand() {
var promise = new Promise((resolve, reject) => {
try {
let start = new Date();
var str = "video transmit start"; //握手的协议字符串
console.log("开始握手:" + str)
// 1. 创建 ArrayBuffer 和 DataView
const buffer = new ArrayBuffer(str.length);
const dataView = new DataView(buffer);
// 2. 将字符串转换为 ASCII 码并写入 DataView
for (let i = 0; i < str.length; i++) {
dataView.setUint8(i, str.charCodeAt(i));
}
//console.log("111111");
this.sendData(buffer).then(() => {
// 开始发送第一个包
setTimeout(() => {
let end = new Date();
var diff = (end.getTime() - start.getTime()) / 1000;
let s = diff % 60;
let m = (diff - s) / 60;
console.log("握手成功并完成2200ms等待,耗时" + m + "分" + s + "秒");
resolve(true);
}, 2200);
}).catch(err => {
//console.log("握手没有成功");
reject(err);
});
} catch (ex) {
reject(ex);
}
});
return promise;
},
sendData(buffer) {
////console.log("deviceId=" + this.connectedDeviceId);
////console.log("serviceId=" + this.serviceId);
return new Promise(async (resolve, reject) => {
// //console.log("开始发送数据buffer");
var promise = new Promise((succ, err) => {
uni.writeBLECharacteristicValue({
deviceId: this.connectedDeviceId,
serviceId: this.serviceId,
characteristicId: this.writeCharacteristicId,
value: buffer,
writeType: plus.os.name == 'iOS' ? 'write' : 'writeNoResponse',
success: () => {
// //console.log("发送数据成功");
succ();
},
fail: (ex) => {
//console.log("发送数据失败", ex);
err(ex);
},
complete: function() {
// //console.log("123456");
}
});
});
if (plus.os.name == 'iOS') {
function timeout(ms) {
return new Promise((_, err) => {
setTimeout(() => {
err({
code: -1,
errMsg: '超时了'
})
}, ms);
});
}
let inteval = parseInt(this.inteval ? this.inteval : 0);
Promise.race([promise, timeout(inteval)]).then(resolve).catch((ex) => {
//console.log("ex=", ex);
if (ex.code == -1) {
resolve();
} else {
reject();
}
}).finally(() => {
//console.log("完成了")
});
} else {
promise.then(resolve).catch(reject);
}
});
}
}
}
</script>
<style>
.sending-progress {
margin-top: 30rpx;
width: 100%;
}
.progress-bar {
height: 12rpx;
background-color: #e0e0e0;
border-radius: 6rpx;
overflow: hidden;
}
.progress-fill {
height: 100%;
background-color: #409eff;
transition: width 0.3s;
}
input {
border: 2rpx solid #000000;
}
button {
height: 100rpx;
line-height: 100rpx;
font-size: 28rpx;
float: left;
}
.content {
width: 100vw;
height: 300px;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.splash-frame {
height: 320rpx;
width: 640rpx;
border: 2rpx solid #409eff;
border-radius: 8rpx;
overflow: hidden;
position: relative;
background-color: #f0f0f0;
}
.splash-frame image {
width: 100%;
height: 100%;
}
</style>

View File

@ -1,517 +0,0 @@
<template>
<view class="content">
<canvas canvas-id="flashCanvas"
style="width: 160px; height: 80px; z-index: 9999;position: fixed; top:-9999px;left:-9999px;"></canvas>
<f-video ref="compARef" :src="videoPath" :direction="-90" :autoplay="true" @shotVideoClick="shotVideoClick"
:videoWidth="videoWidth" :videoHeight="videoHeight"></f-video>
<view>
<text>并发包数量</text>
<input type="text" v-model="packgeCnt" />
</view>
<view>
<text>发送间隔</text>
<input type="text" v-model="inteval" />
</view>
<view>
<button @click="checkVideo">选择视频</button>
<!-- <button @click="CutImg">发送</button> -->
<button @click="uploadVideo">发送</button>
</view>
<view class="sending-progress" v-if="isSending">
<view class="progress-bar">
<view class="progress-fill" :style="{ width: progress + '%' }"></view>
</view>
<text>正在发送: {{ progress }}% ({{ currentPacket }}/{{ totalPackets }})</text>
</view>
</view>
</template>
<script>
export default {
data() {
return {
videoPath: '',
packgeCnt: 20,
inteval: 0,
progress: 0,
currentPacket: 0,
totalPackets: 100,
connectedDeviceId: '',
serviceId: '0xFFE1',
writeCharacteristicId: '0xFFE1',
notifyCharacteristicId: '0xFFE2',
isSending: "",
textProgress: "",
imgs: [],
videoWidth: 320,
videoHeight: 160,
videoDuration: 2,
hexArray: []
}
},
onLoad() {
const eventChannel = this.getOpenerEventChannel();
eventChannel.on('receiveDevice', (data) => {
this.connectedDeviceId = data.connectedDeviceId;
this.serviceId = data.serviceId;
this.writeCharacteristicId = data.writeCharacteristicId;
this.notifyCharacteristicId = data.notifyCharacteristicId;
})
},
methods: {
checkVideo: function() {
uni.chooseVideo({
sourceType: ['album', 'camera'],
compressed: false,
maxDuration: 2,
camera: 'back',
success: (res) => {
this.videoPath = res.tempFilePath;
this.imgs = [];
this.hexArray = [];
this.$refs.compARef.base64 = [];
this.videoWidth = res.width;
this.videoHeight = res.height;
this.videoDuration = res.duration;
console.log("视频宽:" + res.width + ",视频高:" + res.height + ",视频时长:" + res.duration);
}
})
},
uploadVideo: function() {
if (this.hexArray.length > 0) {
console.log("开始处理,无需上传");
this.shotVideoClick(this.hexArray, 'rgb565');
return;
}
if(!this.videoPath){
uni.showToast({
title: "请选择视频",
icon: 'fail'
})
return;
}
console.log("正在上传视频");
uni.showLoading({
title: "上传中"
});
let p2=new Promise((resolve,reject)=>{
console.log("Common.baseURL="+Common.baseURL);
let start = new Date();
uni.uploadFile({
url: Common.baseURL+'video/upload',
// url: 'http://192.168.110.169:5000/video/upload',
filePath: this.videoPath,
name: 'file',
header: {
"Method": "POST",
"Content-Type": "multipart/form-data"
},
timeout: 600000,
fail: (ex) => {
//console.log("上传视频失败" + JSON.stringify(ex));
uni.showToast({
title: "视频文件上传失败了,请检查网络连接",
icon: 'fail'
})
uni.hideLoading();
reject(ex);
},
success: (res) => {
let end = new Date();
var diff = (end.getTime() - start.getTime()) / 1000;
let s = diff % 60;
let m = (diff - s) / 60;
console.log("上传完成,耗时:" + m + "分" + s + "秒");
uni.hideLoading();
resolve(res);
}
});
});
let p1=this.HoldYouHand();
Promise.all([p2,p1]).then((arr)=>{
if(arr[1]===true){
let res=arr[0];
res = JSON.parse(res.data);
if (res.data) {
this.hexArray = res.data;
uni.showLoading({
title: "正在发送"
});
setTimeout(() => {
this.shotVideoClick(res.data, 'rgb565');
}, 0)
} else {
console.log("res")
uni.showModal({
content: "服务器未返回RGB565数据",
title: '错误'
})
}
}else{
uni.showModal({
content:"与设备握手失败了",
title:"错误"
})
}
});
},
pause(e) {
////console.log('pause--------------------------', e);
},
shotVideoClick: function(array, type) {
//console.log("处理视频完成", array);
//console.log("type=" + type)
//console.log("array=", array);
this.imgs = array;
var sendImagePackets = (imageData) => {
return new Promise((resolve, reject) => {
this.isSending = true;
this.progress = 0;
this.currentPacket = 0;
// 总数据包数
const totalPackets = 1536;
this.totalPackets = totalPackets;
let currentPacket = 1;
let promises = [];
// 发送单个数据包
const sendNextPacket = () => {
////console.log("currentPacket="+currentPacket+",imageData.length="+imageData.length);
if (currentPacket > totalPackets) {
this.isSending = false;
resolve();
return;
}
// 计算当前包的数据
let packetSize = 250;
if (type == 'rgb565') {
packetSize = 500;
}
// 创建数据包
const startIndex = (currentPacket - 1) * packetSize;
const endIndex = Math.min(startIndex + packetSize, imageData.length);
if (startIndex > endIndex) {
resolve();
return;
}
////console.log("111111");
const packetData = imageData.slice(startIndex, endIndex);
// 构建数据包
////console.log("packetData.length"+packetData.length);
const bufferSize = 506; // 头部5字节 + 数据部分
const buffer = new ArrayBuffer(bufferSize);
const dataView = new DataView(buffer);
let sortNo = currentPacket.toString(16).padStart(4, '0');
// 填充头部
dataView.setUint8(0, 0x55); // 帧头
dataView.setUint8(1, 0x04); // 帧类型:开机画面
dataView.setUint8(2, '0x' + sortNo.substring(0, 2)); // 包序号
dataView.setUint8(3, '0x' + sortNo.substring(2, 4)); // 包序号
dataView.setUint8(4, 0x01);
dataView.setUint8(5, 0xF4);
if (type == 'rgb565') {
for (let i = 0; i < packetData.length; i++) {
dataView.setUint8(6 + i, '0x' + packetData[i]);
}
} else {
for (let i = 0; i < packetData.length; i++) {
dataView.setUint16(6 + i * 2, packetData[i], false);
}
}
let inteval = parseInt(this.inteval ? this.inteval : 0);
let promise = this.sendData(buffer);
promises.push(promise);
let packgeCnt = parseInt(this.packgeCnt || 20);
if (currentPacket % packgeCnt == 0 || (currentPacket >= totalPackets &&
promises.length > 0)) {
Promise.all(promises).then(() => {
if (currentPacket >= totalPackets) {
this.isSending = false;
resolve();
return;
}
this.currentPacket = currentPacket;
this.progress = Math.round((currentPacket / totalPackets) *
100);
currentPacket++;
setTimeout(sendNextPacket, inteval);
})
} else {
currentPacket++;
sendNextPacket();
}
// .then(() => {
// // 更新进度
// this.currentPacket = currentPacket;
// this.progress = Math.round((currentPacket / totalPackets) *
// 100);
// currentPacket++;
// setTimeout(sendNextPacket, inteval);
// }).catch(err => {
// console.log(err.errMsg+",发送失败了,正在补偿:" + currentPacket);
// setTimeout(sendNextPacket, inteval);
// });
};
//
sendNextPacket();
});
}
if (type == 'rgb565') {
let start = new Date();
console.log("开始发送");
sendImagePackets(array).then(() => {
let end = new Date();
var diff = (end.getTime() - start.getTime()) / 1000;
let s = diff % 60;
let m = (diff - s) / 60;
console.log("发送完成,耗时:" + m + "分" + s + "秒");
uni.showToast({
title: "发送完成,耗时:" + m + "分" + s + "秒",
icon: 'success',
})
}).catch((ex1) => {
//console.log("出现了异常", ex1)
}).finally(() => {
uni.hideLoading();
});
return;
}
},
HoldYouHand() {
var promise=new Promise((resolve,reject)=>{
try{
let start=new Date();
var str = "video transmit start"; //握手的协议字符串
console.log("开始握手:"+str)
// 1. 创建 ArrayBuffer 和 DataView
const buffer = new ArrayBuffer(str.length);
const dataView = new DataView(buffer);
// 2. 将字符串转换为 ASCII 码并写入 DataView
for (let i = 0; i < str.length; i++) {
dataView.setUint8(i, str.charCodeAt(i));
}
//console.log("111111");
this.sendData(buffer).then(() => {
// 开始发送第一个包
setTimeout(()=>{
let end = new Date();
var diff = (end.getTime() - start.getTime()) / 1000;
let s = diff % 60;
let m = (diff - s) / 60;
console.log("握手成功并完成2200ms等待,耗时"+m+"分"+s+"秒");
resolve(true);
}, 2200);
}).catch(err => {
//console.log("握手没有成功");
reject(err);
});
}catch(ex){
reject(ex);
}
});
return promise;
},
sendData(buffer) {
let sendBuffer = () => {
return new Promise((resolve, reject) => {
var promise = new Promise((succ, err) => {
uni.writeBLECharacteristicValue({
deviceId: this.connectedDeviceId,
serviceId: this.serviceId,
characteristicId: this.writeCharacteristicId,
value: buffer,
writeType: plus.os.name == 'iOS' ? 'write' : 'writeNoResponse',
success: () => {
// console.log("发送数据成功");
succ();
},
fail: (ex) => {
if (ex.code == '10007') {
// console.log("失败重试");
setTimeout(() => {
sendBuffer().then(succ).catch(err);
}, this.inteval || 0)
// succ()
} else
{
// console.log("发送数据失败",ex);
err(ex);
}
},
complete: function() {
//console.log("123456");
}
});
});
if (plus.os.name == 'iOS') {
function timeout(ms) {
return new Promise((_, err) => {
setTimeout(() => {
err({
code: -1,
errMsg: '超时了'
})
}, ms);
});
}
Promise.race([promise, timeout(this.inteval ? this.inteval : 0)]).then(() => {
// console.log("成功了");
resolve();
})
.catch((ex) => {
if (ex.code == -1) {
// console.log("超时了")
resolve();
} else {
reject(ex);
// console.log("异常了", ex);
//sendBuffer().then(resolve).catch(reject);
}
});
} else {
promise.then(() => {
//console.log("then........")
resolve();
}).catch(() => {
//console.log("catch.........")
reject()
});
}
});
}
return sendBuffer();
},
CutImg: function() {
if (this.imgs.length == 30) {
this.shotVideoClick(this.imgs, 'img');
return;
}
//console.log("开始处理视频")
uni.showLoading({
title: '开始处理'
});
this.$refs.compARef.shotVideoClick(0);
}
}
}
</script>
<style>
.sending-progress {
margin-top: 30rpx;
width: 100%;
}
.progress-bar {
height: 12rpx;
background-color: #e0e0e0;
border-radius: 6rpx;
overflow: hidden;
}
.progress-fill {
height: 100%;
background-color: #409eff;
transition: width 0.3s;
}
input {
border: 2rpx solid #000000;
}
button {
height: 100rpx;
line-height: 100rpx;
font-size: 28rpx;
float: left;
}
.content {
width: 100vw;
height: 300px;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
</style>

View File

@ -1,540 +0,0 @@
<template>
<view class="content">
<view>
<view>
选择的视频:{{videoPath}}</view>
</view>
<view>
重发包序号:{{reSendNumber}}
</view>
<view>
<text>发送间隔</text>
<input type="text" v-model="inteval" />
</view>
<view>
<button @click="checkVideo">选择视频</button>
<button @click="uploadVideo">发送</button>
</view>
<view class="sending-progress" v-if="isSending">
<view class="progress-bar">
<view class="progress-fill" :style="{ width: progress + '%' }"></view>
</view>
<text>正在发送: {{ progress }}% ({{ currentPacket }}/{{ totalPackets }})</text>
</view>
</view>
</template>
<script>
import Common from '../../../utils/Common';
var mqttClient=null;
export default {
data() {
return {
videoPath: '',
inteval: 0,
progress: 0,
currentPacket: 0,
totalPackets: 100,
connectedDeviceId: '',
serviceId: '0xFFE1',
writeCharacteristicId: '0xFFE1',
notifyCharacteristicId: '0xFFE2',
isSending: "",
textProgress: "",
netMode:"ble",
IMEI:"",
imgs: [],
videoWidth: 320,
videoHeight: 160,
videoDuration: 2,
hexArray: [],
reSendNumber:""
}
},
onLoad() {
const eventChannel = this.getOpenerEventChannel();
eventChannel.on('receiveDevice', (data) => {
this.connectedDeviceId = data.connectedDeviceId;
this.serviceId = data.serviceId;
this.writeCharacteristicId = data.writeCharacteristicId;
this.notifyCharacteristicId = data.notifyCharacteristicId;
this.netMode=data.netMode;
mqttClient=data.mqttClient;
this.IMEI=data.IMEI;
});
eventChannel.on('ReSendVideo',(data)=>{
//重新发送某一包
this.reSendNumber=data.videoNo;
setTimeout(()=>{
this.shotVideoClick(this.hexArray,'rgb565',data.videoNo);
},0);
});
},
methods: {
checkVideo: function() {
uni.chooseVideo({
sourceType: ['album', 'camera'],
compressed: false,
maxDuration: 2,
camera: 'back',
success: (res) => {
this.videoPath = res.tempFilePath;
this.imgs = [];
this.hexArray = [];
this.videoWidth = res.width;
this.videoHeight = res.height;
this.videoDuration = res.duration;
console.log("视频宽:" + res.width + ",视频高:" + res.height + ",视频时长:" + res.duration);
}
})
},
uploadVideo: function() {
if (this.hexArray.length > 0) {
console.log("开始处理,无需上传");
this.shotVideoClick(this.hexArray, 'rgb565');
return;
}
if(!this.videoPath){
uni.showToast({
title: "请选择视频",
icon: 'fail'
})
return;
}
console.log("正在上传视频");
uni.showLoading({
title: "上传中"
});
let p2=new Promise((resolve,reject)=>{
let start = new Date();
console.log("Common.baseURL="+Common.baseURL);
uni.uploadFile({
url:Common.baseURL+'video/upload',
filePath: this.videoPath,
name: 'file',
header: {
"Method": "POST",
"Content-Type": "multipart/form-data"
},
timeout: 600000,
fail: (ex) => {
//console.log("上传视频失败" + JSON.stringify(ex));
uni.showToast({
title: "视频文件上传失败了,请检查网络连接",
icon: 'fail'
})
uni.hideLoading();
reject(ex);
},
success: (res) => {
let end = new Date();
var diff = (end.getTime() - start.getTime()) / 1000;
let s = diff % 60;
let m = (diff - s) / 60;
console.log("上传完成,耗时:" + m + "分" + s + "秒");
uni.hideLoading();
resolve(res);
}
});
});
let p1=this.HoldYouHand();
Promise.all([p2,p1]).then((arr)=>{
if(arr[1]===true){
let res=arr[0];
res = JSON.parse(res.data);
if (res.data) {
this.hexArray = res.data;
uni.showLoading({
title: "正在发送"
});
setTimeout(() => {
this.shotVideoClick(res.data, 'rgb565');
}, 0)
} else {
console.log("res")
uni.showModal({
content: "服务器未返回RGB565数据",
title: '错误'
})
}
}else{
uni.showModal({
content:"与设备握手失败了",
title:"错误"
})
}
});
},
shotVideoClick: function(array, type,ReSendNo) {
//console.log("处理视频完成", array);
//console.log("type=" + type)
//console.log("array=", array);
this.imgs = array;
var sendImagePackets = (imageData) => {
return new Promise((resolve, reject) => {
this.isSending = true;
this.progress = 0;
this.currentPacket = 0;
// 总数据包数
var totalPackets = 1536;
this.totalPackets = totalPackets;
let currentPacket = 1;
if(ReSendNo){
this.progress = ReSendNo-1;
this.currentPacket = ReSendNo-1;
currentPacket=ReSendNo;
totalPackets=ReSendNo;
this.totalPackets=ReSendNo;
}
// 发送单个数据包
const sendNextPacket = () => {
////console.log("currentPacket="+currentPacket+",imageData.length="+imageData.length);
if (currentPacket > totalPackets) {
this.isSending = false;
if(!ReSendNo){
this.bleSendComplete();
}else{
// this.reSendNumber="";
}
resolve();
return;
}
// 计算当前包的数据
let packetSize = 250;
if (type == 'rgb565') {
packetSize = 500;
}
// 创建数据包
const startIndex = (currentPacket - 1) * packetSize;
const endIndex = Math.min(startIndex + packetSize, imageData.length);
if (startIndex > endIndex) {
resolve();
return;
}
////console.log("111111");
const packetData = imageData.slice(startIndex, endIndex);
// 构建数据包
////console.log("packetData.length"+packetData.length);
const bufferSize = 506; // 头部5字节 + 数据部分
const buffer = new ArrayBuffer(bufferSize);
const dataView = new DataView(buffer);
let sortNo = currentPacket.toString(16).padStart(4, '0');
// 填充头部
dataView.setUint8(0, 0x55); // 帧头
dataView.setUint8(1, 0x04); // 帧类型:开机画面
dataView.setUint8(2, '0x' + sortNo.substring(0, 2)); // 包序号
dataView.setUint8(3, '0x' + sortNo.substring(2, 4)); // 包序号
dataView.setUint8(4, 0x01);
dataView.setUint8(5, 0xF4);
if (type == 'rgb565') {
for (let i = 0; i < packetData.length; i++) {
dataView.setUint8(6 + i, '0x' + packetData[i]);
}
} else {
for (let i = 0; i < packetData.length; i++) {
dataView.setUint16(6 + i * 2, packetData[i], false);
}
}
let inteval = parseInt(this.inteval ? this.inteval : 0);
this.sendData(buffer).then(() => {
if(ReSendNo){
this.isSending = false;
resolve();
return;
}
// 更新进度
this.currentPacket = currentPacket;
this.progress = Math.round((currentPacket / totalPackets) *
100);
console.log(`发送数据包完成 ${currentPacket}/${totalPackets}`);
// 发送下一个包(添加延迟避免蓝牙缓冲区溢出)
currentPacket++;
setTimeout(sendNextPacket, inteval);
}).catch(err => {
console.log(err.errMsg + ",发送失败了,正在补偿:" + currentPacket);
setTimeout(sendNextPacket, inteval);
// uni.showToast({
// title:"发送失败"+JSON.stringify(err)
// })
});
};
sendNextPacket();
});
}
if (type == 'rgb565') {
let start = new Date();
console.log("开始发送");
sendImagePackets(array).then(() => {
console.log("发送完成");
let end = new Date();
var diff = (end.getTime() - start.getTime()) / 1000;
let s = diff % 60;
let m = (diff-s) / 60;
console.log("发送完成,耗时:" + m + "分" + s + "秒");
uni.showModal({
content: "发送完成,耗时:" + m + "分" + s + "秒",
title: 'success'
});
}).catch((ex1) => {
console.log("出现了异常", ex1)
}).finally(() => {
uni.hideLoading();
});
return;
}
},
HoldYouHand() {
var promise=new Promise((resolve,reject)=>{
try{
let start=new Date();
var str = "video transmit start"; //握手的协议字符串
console.log("开始握手:"+str)
// 1. 创建 ArrayBuffer 和 DataView
const buffer = new ArrayBuffer(str.length);
const dataView = new DataView(buffer);
// 2. 将字符串转换为 ASCII 码并写入 DataView
for (let i = 0; i < str.length; i++) {
dataView.setUint8(i, str.charCodeAt(i));
}
//console.log("111111");
this.sendData(buffer).then(() => {
// 开始发送第一个包
setTimeout(()=>{
let end = new Date();
var diff = (end.getTime() - start.getTime()) / 1000;
let s = diff % 60;
let m = (diff - s) / 60;
console.log("握手成功并完成2200ms等待,耗时"+m+"分"+s+"秒");
resolve(true);
}, 2200);
}).catch(err => {
//console.log("握手没有成功");
reject(err);
});
}catch(ex){
reject(ex);
}
});
return promise;
},
bleSendComplete() {
var str = "transmit complete"; //握手的协议字符串
let buffer = new ArrayBuffer(str.length);
let dataView = new DataView(buffer);
for (let i = 0; i < str.length; i++) {
dataView.setUint8(i, str.charCodeAt(i));
}
setTimeout(()=>{
this.sendData(buffer).then(() => {
console.log("完成指令发送成功");
}).catch(err => {
console.log("完成指令发送失败");
});
},3000)
},
sendData(buffer) {
if(this.netMode=='ble'){
return this.sendBle(buffer);
}
return this.sendMQ(buffer);
},
sendBle(buffer){
return new Promise(async (resolve, reject) => {
// //console.log("开始发送数据buffer");
var promise = new Promise((succ, err) => {
uni.writeBLECharacteristicValue({
deviceId: this.connectedDeviceId,
serviceId: this.serviceId,
characteristicId: this.writeCharacteristicId,
value: buffer,
writeType: plus.os.name == 'iOS' ? 'write' : 'writeNoResponse',
success: () => {
// //console.log("发送数据成功");
succ();
},
fail: (ex) => {
//console.log("发送数据失败", ex);
err(ex);
},
complete: function() {
// //console.log("123456");
}
});
});
if (plus.os.name == 'iOS') {
function timeout(ms) {
return new Promise((_, err) => {
setTimeout(() => {
err({
code: -1,
errMsg: '超时了'
})
}, ms);
});
}
let inteval = parseInt(this.inteval ? this.inteval : 0);
Promise.race([promise, timeout(inteval)]).then(resolve).catch((ex) => {
//console.log("ex=", ex);
if (ex.code == -1) {
resolve();
} else {
reject();
}
}).finally(() => {
//console.log("完成了")
});
} else {
promise.then(resolve).catch(reject);
}
});
},
sendMQ(message) {
const topic = `B/${this.IMEI}`;
return new Promise((resolve, reject) => {
if(!mqttClient){
reject("MQTT未连接");
return;
}
try {
let flag=mqttClient.publish(topic, message, {
qos: 1
});
if(flag){
resolve();
return;
}
reject("MQTT未连接无法发布消息");
} catch (error) {
reject(error);
}
});
}
}
}
</script>
<style>
.sending-progress {
margin-top: 30rpx;
width: 100%;
}
.progress-bar {
height: 12rpx;
background-color: #e0e0e0;
border-radius: 6rpx;
overflow: hidden;
}
.progress-fill {
height: 100%;
background-color: #409eff;
transition: width 0.3s;
}
input {
border: 2rpx solid #000000;
}
button {
height: 100rpx;
line-height: 100rpx;
font-size: 28rpx;
float: left;
}
.content {
width: 100vw;
height: 300px;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
</style>

View File

@ -1,118 +0,0 @@
<template>
<view class="container">
<view class="grid">
<view class="cell" @click="goToDetail(item.name)" v-for="item,index in options">{{item.url}}</view>
</view>
</view>
</template>
<script>
export default {
data() {
return {
options: [{
name: '/pages/BlueTooth/ModeSetting/ModeSetting',
url: '7307'
},
{
name: '/pages/BlueTooth/ModeSetting/HBY650',
url: 'HBY650'
},
// {
// name: '/pages/BlueTooth/ModeSetting/HBY650_1',
// url: 'HBY650_V1'
// },
{
name: '/pages/BlueTooth/ModeSetting/HBY6155',
url: '6155'
},
{
name: '/pages/BlueTooth/ModeSetting/HBY6155V1',
url: '6155_V1'
},
{
name: "/pages/BlueTooth/ModeSetting/HBY670V1",
url: 'HBY670'
},
{
name: "/pages/BlueTooth/ModeSetting/4877",
url: '4877'
},
{
name: '/pages/MapTest/MapTest',
url: '地图测试'
},
{
name: '',
url: '更多'
}
]
}
},
onShow: () => {
},
methods: {
goToDetail: function(url) {
console.log("url=" + url)
let qd = () => {
uni.showToast({
title: '敬请期待',
duration: 2000,
icon: "none"
});
};
if (url) {
uni.navigateTo({
url: url,
success: () => {
},
fail: () => {
qd();
}
});
} else {
qd();
}
}
}
}
</script>
<style>
.container {
padding: 15px;
background-color: #f5f5f5;
min-height: 100vh;
}
.grid {
display: flex;
align-content: space-around;
align-items: stretch;
justify-items: center;
flex-direction: row;
flex-wrap: wrap;
justify-content: flex-start;
}
.cell {
padding: 0rpx 20rpx;
border: 2rpx solid rgba(0, 0, 0, 0.3);
border-radius: 15rpx;
font-size: 28rpx;
height: 70rpx;
line-height: 70rpx;
margin-left: 30rpx;
margin-top: 20rpx;
}
</style>

View File

@ -1,273 +0,0 @@
<template>
<view class="update-container">
<!-- 进度条 -->
<view v-if="showProgress" class="progress-container">
<view class="progress-title">正在更新 {{ progress }}%</view>
<view class="progress-bar">
<view class="progress" :style="{ width: progress + '%' }"></view>
</view>
</view>
<!-- 更新提示弹窗 -->
<view v-if="showUpdateDialog" class="dialog-mask">
<view class="dialog">
<view class="dialog-title">发现新版本 v{{ newVersion }}</view>
<view class="dialog-content">{{ updateInfo.desc || '有新的功能和优化,建议立即更新' }}</view>
<view class="dialog-buttons">
<button v-if="!updateInfo.force" class="cancel-btn" @click="showUpdateDialog = false">稍后更新</button>
<button class="confirm-btn" @click="startUpdate">立即更新</button>
</view>
</view>
</view>
</view>
</template>
<script>
export default {
data() {
return {
// 当前版本
currentVersion: '',
// 最新版本
newVersion: '',
// 更新信息
updateInfo: {},
// 是否显示更新弹窗
showUpdateDialog: false,
// 是否显示进度条
showProgress: false,
// 更新进度
progress: 0
};
},
onLoad() {
// 初始化时检查版本
this.checkVersion();
},
methods: {
/**
* 检查当前版本
*/
async checkVersion() {
try {
// 获取当前应用版本
const versionInfo = plus.runtime.version;
this.currentVersion = versionInfo;
console.log('当前版本:', this.currentVersion);
// 调用后端接口检查最新版本
// 这里替换为你的后端接口地址
const res = await this.$http.get('/api/checkVersion', {
platform: uni.getSystemInfoSync().platform,
version: this.currentVersion
});
if (res.code === 0 && res.data.hasUpdate) {
this.newVersion = res.data.version;
this.updateInfo = res.data;
// 显示更新提示
this.showUpdateDialog = true;
} else {
console.log('当前已是最新版本');
}
} catch (error) {
console.error('版本检查失败:', error);
}
},
/**
* 开始更新
*/
startUpdate() {
if (!this.updateInfo.downloadUrl) {
uni.showToast({
title: '更新地址不存在',
icon: 'none'
});
return;
}
this.showUpdateDialog = false;
this.showProgress = true;
this.downloadWgt(this.updateInfo.downloadUrl);
},
/**
* 下载wgt包
*/
downloadWgt(url) {
const downloadTask = uni.downloadFile({
url: url,
success: (downloadResult) => {
if (downloadResult.statusCode === 200) {
// 下载成功安装wgt包
this.installWgt(downloadResult.tempFilePath);
} else {
this.showProgress = false;
uni.showToast({
title: '下载失败',
icon: 'none'
});
}
},
fail: (err) => {
this.showProgress = false;
console.error('下载失败:', err);
uni.showToast({
title: '下载失败,请稍后重试',
icon: 'none'
});
}
});
// 监听下载进度
downloadTask.onProgressUpdate((res) => {
this.progress = res.progress;
});
},
/**
* 安装wgt包
*/
installWgt(path) {
plus.runtime.install(
path,
{
force: false // 是否强制安装
},
() => {
console.log('安装成功');
this.showProgress = false;
// 安装成功后提示重启
uni.showModal({
title: '更新完成',
content: '应用已更新,是否立即重启?',
showCancel: !this.updateInfo.force,
success: (res) => {
if (res.confirm) {
// 重启应用
plus.runtime.restart();
}
}
});
},
(err) => {
console.error('安装失败:', err);
this.showProgress = false;
uni.showToast({
title: '更新失败: ' + err.message,
icon: 'none',
duration: 3000
});
}
);
}
}
};
</script>
<style scoped>
.update-container {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
pointer-events: none;
z-index: 9999;
}
/* 进度条样式 */
.progress-container {
position: fixed;
top: 0;
left: 0;
width: 100%;
background-color: #fff;
padding: 10rpx 20rpx;
pointer-events: auto;
}
.progress-title {
font-size: 28rpx;
color: #333;
margin-bottom: 10rpx;
text-align: center;
}
.progress-bar {
height: 8rpx;
background-color: #eee;
border-radius: 4rpx;
overflow: hidden;
}
.progress {
height: 100%;
background-color: #007aff;
transition: width 0.3s ease;
}
/* 弹窗样式 */
.dialog-mask {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
display: flex;
justify-content: center;
align-items: center;
pointer-events: auto;
}
.dialog {
width: 600rpx;
background-color: #fff;
border-radius: 16rpx;
overflow: hidden;
}
.dialog-title {
font-size: 36rpx;
font-weight: bold;
color: #333;
padding: 30rpx;
text-align: center;
border-bottom: 1px solid #eee;
}
.dialog-content {
font-size: 32rpx;
color: #666;
padding: 40rpx 30rpx;
line-height: 1.6;
}
.dialog-buttons {
display: flex;
border-top: 1px solid #eee;
}
.cancel-btn, .confirm-btn {
flex: 1;
height: 100rpx;
line-height: 100rpx;
font-size: 32rpx;
border: none;
background-color: transparent;
}
.cancel-btn {
color: #666;
border-right: 1px solid #eee;
}
.confirm-btn {
color: #007aff;
}
</style>

View File

@ -8,12 +8,18 @@
<view class="deviceName">
蓝牙名:{{device.name}}
</view>
<view class="deviceName">
状态:{{deviceStatu}}
</view>
<view class="deviceName">
设备名:{{device.deviceName}}
</view>
<view class="deviceId">
设备Mac:{{device.macAddress}}
</view>
<view class="deviceId">
设备IMEI:{{device.imei}}
</view>
<view class="bound" v-bind:class="boundStatu">
{{Statu.boundRemark}}
</view>
@ -40,12 +46,14 @@
var these = null;
var eventChannel = null;
var ble = null;
var timeInteval = null;
export default {
data() {
return {
Statu: {
bound: null
bound: null,
timeInteval:null,
isSearch:false
},
device: {
"deviceId": "",
@ -57,7 +65,9 @@
],
"linkStatu": false,
"macAddress": ""
"macAddress": "",
"communicationMode":"",
"imei":""
},
serverDevice:null
}
@ -72,15 +82,36 @@
} else {
return "red";
}
},
deviceStatu:function(){
if(!this.device.name){
return "";
}
if(!this.device.macAddress){
return '等待设备上报Mac地址';
}
if(!this.device.deviceName ){
if(this.Statu.isSearch){
return "无效设备";
}else{
if(this.Statu.timeInteval===null){
return "等待查询设备"
}else{
return "正在查询设备";
}
}
}else{
return "找到有效设备"
}
return "";
}
},
onBackPress() {
console.log("返回时断开蓝牙连接,取消订阅");
ble.disconnectDevice(these.device.deviceId);
ble.removeReceiveCallback(pagePath);
},
onUnload() {
console.log("返回时断开蓝牙连接,取消订阅");
ble.disconnectDevice(these.device.deviceId);
ble.removeReceiveCallback(pagePath);
},
onLoad(option) {
@ -91,11 +122,12 @@
console.log("收到设备消息,", receive);
if (these.device.deviceId == receive.deviceId) {
console.log("11111:",receive);
these.device.imei=f.imei;
if (receive.bytes[0] == 0xFC || receive.str.indexOf('mac address:') == 0) {
if (f && f.macAddress) {
these.device.macAddress = f.macAddress;
console.log("222222");
these.Statu.isSearch=false;
these.initDevice();
}
}
@ -112,9 +144,9 @@
keys.forEach((v, index) => {
these.device[v] = f[v];
})
console.log("LinkedList=", ble.data.LinkedList)
console.log("f=", f);
console.log("获取到设备", these.device);
// console.log("LinkedList=", ble.data.LinkedList)
// console.log("f=", f);
// console.log("获取到设备", these.device);
if (f.macAddress) {
these.device.macAddress = f.macAddress;
@ -125,14 +157,18 @@
}
})
// let inteval = setInterval(this.initDevice, 5000);
let inteval = setInterval(this.initDevice, 5000);
},
methods: {
initDevice: function() {
clearTimeout(timeInteval);
if(!these.device.macAddress){
return;
}
clearTimeout(this.Statu.timeInteval);
timeInteval = setTimeout(() => {
this.Statu.timeInteval = setTimeout(() => {
this.Statu.isSearch=true;
showLoading(these, {
text: '正在获取设备信息'
});
@ -144,6 +180,7 @@
deviceMac: these.device.macAddress
}
}).then(res => {
console.log("获取设备信息", res);
if (res && res.code == 200) {
let data = res.data;
@ -180,6 +217,8 @@
}).catch((ex) => {
console.log("获取设备出现异常:", ex);
}).finally(() => {
this.Statu.timeInteval=null;
this.Statu.isSearch=false;
hideLoading(these);
});
@ -202,11 +241,16 @@
these.Statu.boundRemark = "设备上报Mac地址异常";
return;
}
if(!this.device.deviceName){
these.Statu.bound = false;
these.Statu.boundRemark = "设备未入库";
return;
}
these.Statu.bound = null;
these.Statu.boundRemark = "";
showLoading(these, {
text: "连接中..."
text: "绑定中..."
})
let promise = request({
url: '/app/device/bind',
@ -214,7 +258,7 @@
data: {
deviceImei: '',
deviceMac: these.device.macAddress,
communicationMode: '1', //0是4g,1是蓝牙
communicationMode: 1, //0是4g,1是蓝牙,2蓝牙&4G
}
});
promise.then((res) => {

View File

@ -10,7 +10,7 @@
<view class="imgContent center">
<view class="img center">
<image src="/static/images/bluetooth.png" class="titleIco" mode="aspectFit">
<image src="/static/images/common/bluetooth.png" class="titleIco" mode="aspectFit">
</image>
</view>
@ -27,7 +27,7 @@
<view class="item " v-for="item, index in PairEquip" v-show="PairEquip.length>0">
<view class="leftImg ">
<image src="/static/images/BLEAdd/device.png" class="titleIco" mode="aspectFit">
<image src="/static/images/common/bluetooth.png" class="titleIco" mode="heightFix">
</image>
</view>
<view class="centertxt ">
@ -49,7 +49,7 @@
<view class="item" v-on:click="Link(item,index)" v-for="item, index in EquipMents"
v-show="!item['linkStatu']">
<view class="leftImg ">
<image src="/static/images/BLEAdd/device.png" class="titleIco" mode="aspectFit">
<image src="/static/images/common/bluetooth.png" class="titleIco" mode="heightFix">
</image>
</view>
<view class="centertxt ">
@ -81,8 +81,8 @@
</view>
</view>
</BottomSlideMenuPlus>
<global-loading ref="loading" />
<global-loading ref="loading" />
</view>
</template>
@ -94,10 +94,10 @@
hideLoading,
updateLoading
} from '@/utils/loading.js'
const pagePath="pages/common/addBLE/addEquip";
const pagePath = "pages/common/addBLE/addEquip";
var ble = null;
var these = null;
var eventChannel=null;
var eventChannel = null;
export default {
data() {
return {
@ -130,9 +130,9 @@
},
PairEquip: [], //已配对设备
EquipMents: [], //搜索出来的设备
device:null,
item:{
deviceId:''
device: null,
item: {
deviceId: ''
}
}
},
@ -141,28 +141,24 @@
},
onHide: function() {
ble.StopSearch();
},
onBackPress: (e) => {
onUnload() {
ble.StopSearch();
ble.removeDeviceFound(pagePath);
ble.removeReceiveCallback(pagePath);
},
onUnload(){
ble.StopSearch();
ble.removeDeviceFound(pagePath);
ble.removeReceiveCallback(pagePath);
},
onLoad() {
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){
if (!arr[i].name) {
continue;
}
let f = these.EquipMents.find(function(v) {
@ -170,51 +166,56 @@
});
if (!f) {
these.EquipMents.push(arr[i]);
} else {
}
}
// console.log("equip=", these.EquipMents)
}, pagePath);
// console.log("addEquip")
// ble.addReceiveCallback((receivData,f,path,arr) => {
// console.log("收到数据了:", receivData);//数据格式:{bytes:[109,97],str:"",hexs:"FA 01"}
// if (this.item.deviceId == receivData.deviceId) {
// console.log("11111:",receivData);
// }
// });
ble.addReceiveCallback((receivData, f, path, arr) => {
if (f.macAddress && these.device) {
showLoading(these, {
text: '正在验证设备'
});
setTimeout(() => {
these.DeviceVerdict(f.deviceId);
}, 0);
}
}, pagePath);
eventChannel = this.getOpenerEventChannel();
eventChannel.on('detailData', function(rec) {
console.log("接收到父页面的参数:",rec);
these.device=rec.data;
});
console.log("接收到父页面的参数:", rec);
these.device = rec.data;
});
},
onShow: function() {
this.EquipMents=[];
this.PairEquip=[];
ble.StartSearch().catch((ex) => {
// this.EquipMents = [];
this.PairEquip = [];
ble && ble.StartSearch().catch((ex) => {
if (ex.code == 10001) {
these.showOpenSetting();
}
});
},
methods: {
isItemLink: function(item, index) {
let src = '/static/images/BLEAdd/noLink.png';
if (this.PairEquip && this.PairEquip.length) {
if (this.PairEquip.length > 0) {
let f = this.PairEquip.find(function(v) {
@ -229,7 +230,7 @@
}
return src;
},
showOpenSetting: function() {
this.Status.BottomMenu.show = true;
@ -238,57 +239,121 @@
this.Status.BottomMenu.show = false;
ble.showBlueSetting(false);
},
Link: function(item, index) {
this.item.deviceId=item.deviceId;
showLoading(this,{
text: "正在连接"
});
setTimeout(() => {
let serviceid=null;
if(item.advertisServiceUUIDs.length>0){
serviceid=item.advertisServiceUUIDs[0];
}
ble.LinkBlue(item.deviceId,serviceid).then((res) => {
let c = these.PairEquip.find(function(v) {
return v.deviceId == item.deviceId;
});
if (!c) {
these.PairEquip.push(item);
DeviceVerdict(deviceId) { //判断是否是目标设备
if (these.device) { //从设备详情过来的,回设备详情去
let f = ble.data.LinkedList.find(v => {
if (v.deviceId == deviceId) {
v.device = these.device;
return true;
}
console.log("连接成功");
if(these.device){//从设备详情过来的,回设备详情去
ble.data.LinkedList.find(v=>{
if(v.deviceId==item.deviceId){
v.device=these.device;
return true;
}
return false;
});
ble.updateCache();
uni.navigateBack();
return false;
});
if (f.macAddress) {
if (f.macAddress != these.device.deviceMac) {
ble.disconnectDevice(deviceId);
updateLoading(these, {
text: "设备Mac地址错误,请重选设备连接"
})
return;
}
hideLoading(these);
ble.updateCache();
uni.navigateBack();
return true;
} else {
updateLoading(these, {
text: "等待设备上报Mac地址"
})
return undefined;
}
}
return false;
},
Link: function(item) {
this.item.deviceId = item.deviceId;
showLoading(this, {
text: "正在连接:第1次"
});
let index = 1;
let total = 5;
let linkCallback = (res) => {
let c = these.PairEquip.find(function(v) {
return v.deviceId == item.deviceId;
});
if (!c) {
these.PairEquip.push(item);
}
console.log("连接成功", these.device);
if (!these.device) {
console.log("跳转到绑定")
hideLoading(these);
uni.navigateTo({
url:"/pages/common/addBLE/LinkBle",
events:{
url: "/pages/common/addBLE/LinkBle",
events: {
},
success(res) {
res.eventChannel.emit('LinkItem', item);
res.eventChannel.emit('LinkItem', item);
}
});
return;
}
console.log("验证设备")
these.DeviceVerdict(item.deviceId);
}
let execLink = () => {
return new Promise((resolve, reject) => {
if (index > total) {
reject({
msg: "连接超时"
});
return;
}
ble.LinkBlue(item.deviceId).then((res) => {
console.log("连接成功");
resolve(res);
}).catch((ex) => {
if (index == total) {
console.log("连接了N次都没连上");
reject(ex);
return;
}
index++;
updateLoading(this, {
text: ex.msg + ",正在重试第" + index + "次"
})
execLink().then(resolve).catch(reject);
})
}).catch((ex) => {
console.log("ex=",ex)
uni.showModal({
content:"连接失败:"+ex.msg
});
}).finally(()=>{
hideLoading(this);
});
}, 0);
}
execLink().then((res) => {
linkCallback(res);
}).catch(ex => {
console.log("ex=", ex)
uni.showModal({
content: "连接失败:" + ex.msg
});
hideLoading(these);
});
}
@ -463,8 +528,8 @@
}
.list .item .leftImg {
width: 100rpx;
height: 70rpx;
width: 60rpx;
height: 60rpx;
}
.list .item .centertxt {
@ -496,7 +561,7 @@
font-family: "PingFang SC";
font-size: 26rpx;
font-weight: 400;
line-height: 50rpx;
line-height: 36rpx;
text-align: left;
}
@ -505,14 +570,14 @@
font-family: "PingFang SC";
font-size: 24rpx;
font-weight: 400;
line-height: 30rpx;
line-height: 36rpx;
text-align: left;
}
.list .item .rightIco .img {
width: 50rpx;
height: 50rpx;
width: 45rpx;
height: 45rpx;
}
.openBlue {

View File

@ -140,7 +140,8 @@
// 跳转到详情页面
handleFile(item) {
uni.navigateTo({
url: "/pages/6170/deviceControl/index",
// url: "/pages/6170/deviceControl/index",
url:'/pages/670/HBY670',
success: (res) => {
// 页面跳转成功后的回调函数
res.eventChannel.emit('detailData', {

View File

@ -227,7 +227,7 @@
break;
case 'share':
uni.navigateTo({
url: "/pages/6170/allShare/index"
url: "/pages/common/allShare/index"
})
break;
}

View File

@ -1,98 +1,98 @@
<template>
<view class="share">
<!-- 内容区域 -->
<view class="content">
<!-- 分享设备 -->
<view class="section" @click="shareDevice">
<text class="section-title">分享设备</text>
</view>
<!-- 分享管理 -->
<view class="section" @click="shareManagement">
<text class="section-title">分享管理</text>
</view>
</view>
</view>
</template>
<script>
export default {
data() {
return {
itemInfo:""
}
},
methods: {
// 分享设备
shareDevice(){
uni.navigateTo({
url: '/pages/common/shareDevices/index',
events: {
ack: function(data) {}
},
success: (res) => {
res.eventChannel.emit('shareDevice', {
data: this.itemInfo,
});
}
});
},
// 分享管理
shareManagement(){
uni.navigateTo({
url: '/pages/common/shareManagement/index',
events: {
ack: function(data) {}
},
success: (res) => {
res.eventChannel.emit('shareManagement', {
data: this.itemInfo,
});
}
});
}
},
onLoad() {
const eventChannel = this.getOpenerEventChannel();
// 监听 'shareDevice' 事件,获取传过来的数据
eventChannel.on('share', (data) => {
console.log(data,'datat');
this.itemInfo = data.data;
})
}
}
</script>
<style scoped>
.share {
padding: 30rpx;
background: #121212;
min-height: 100vh;
}
.status-bar {
/* 根据实际情况设置状态栏高度 */
width: 100%;
height: 20px;
background-color: #f3f3f3;
}
.title {
font-size: 20px;
margin-top: 10px;
}
.content {
width: 100%;
margin-top: 20px;
}
.section {
margin-bottom: 20px;
padding:50rpx;
border-radius: 16rpx;
background: rgba(26, 26, 26, 1);
text-align: center;
color: rgba(255, 255, 255, 0.87);
width: 100%;
}
<template>
<view class="share">
<!-- 内容区域 -->
<view class="content">
<!-- 分享设备 -->
<view class="section" @click="shareDevice">
<text class="section-title">分享设备</text>
</view>
<!-- 分享管理 -->
<view class="section" @click="shareManagement">
<text class="section-title">分享管理</text>
</view>
</view>
</view>
</template>
<script>
export default {
data() {
return {
itemInfo:""
}
},
methods: {
// 分享设备
shareDevice(){
uni.navigateTo({
url: '/pages/common/shareDevices/index',
events: {
ack: function(data) {}
},
success: (res) => {
res.eventChannel.emit('shareDevice', {
data: this.itemInfo,
});
}
});
},
// 分享管理
shareManagement(){
uni.navigateTo({
url: '/pages/common/shareManagement/index',
events: {
ack: function(data) {}
},
success: (res) => {
res.eventChannel.emit('shareManagement', {
data: this.itemInfo,
});
}
});
}
},
onLoad() {
const eventChannel = this.getOpenerEventChannel();
// 监听 'shareDevice' 事件,获取传过来的数据
eventChannel.on('share', (data) => {
console.log(data,'datat');
this.itemInfo = data.data;
})
}
}
</script>
<style scoped>
.share {
padding: 30rpx;
background: #121212;
min-height: 100vh;
}
.status-bar {
/* 根据实际情况设置状态栏高度 */
width: 100%;
height: 20px;
background-color: #f3f3f3;
}
.title {
font-size: 20px;
margin-top: 10px;
}
.content {
width: 100%;
margin-top: 20px;
}
.section {
margin-bottom: 20px;
padding:50rpx;
border-radius: 16rpx;
background: rgba(26, 26, 26, 1);
text-align: center;
color: rgba(255, 255, 255, 0.87);
width: 100%;
}
</style>

View File

@ -69,6 +69,7 @@
deviceShareCode,
deviceShareAdd
} from '@/api/6170/share.js'
import Common from '@/utils/Common.js'
export default {
data() {
return {
@ -199,12 +200,13 @@
const selectedPermissions = this.permissions.filter(permission => permission.checked).map(
permission =>
permission.value);
const res = await deviceShareAdd({
phonenumber: this.phone,
smsCode: this.code,
deviceId: this.itemInfo.id,
permission: selectedPermissions.join(',')
})
// const res = await deviceShareAdd({
// phonenumber: this.phone,
// smsCode: this.code,
// deviceId: this.itemInfo.id,
// permission: selectedPermissions.join(',')
// })
let res={code:200};
if (res.code == 200) {
this.shareShow = true
uni.hideLoading()
@ -237,6 +239,7 @@
eventChannel.on('shareDevice', (data) => {
console.log(data, 'data1t111');
this.itemInfo = data.data;
this.permissions=Common.getPermissions(this.itemInfo.persissonType);
})
}
};

View File

@ -1,5 +1,18 @@
import receivTool from "@/utils/BleReceive.js"
var recei = null;
const serviceDic = [ //合作供应商的蓝牙主服务
{
"serviceId": "0000AE30-0000-1000-8000-00805F9B34FB",
"writeId": "0000AE03-0000-1000-8000-00805F9B34FB",
"notifyId": "0000AE02-0000-1000-8000-00805F9B34FB"
},
{
"serviceId": "0000FFE0-0000-1000-8000-00805F9B34FB",
"writeId": "0000FFE1-0000-1000-8000-00805F9B34FB",
"notifyId": "0000FFE2-0000-1000-8000-00805F9B34FB"
}
];
class BleHelper {
constructor() {
this.StorageKey = "linkedDevices";
@ -130,12 +143,12 @@ class BleHelper {
}
updateCache() {
console.log("this.StorageKey=", this.StorageKey)
// console.log("this.StorageKey=", this.StorageKey)
uni.setStorageSync(this.StorageKey, this.data.LinkedList);
}
linkAllDevices() {
console.log("模块启动时,自动连接已连接过的设备", this.data.LinkedList);
// console.log("模块启动时,自动连接已连接过的设备", this.data.LinkedList);
if (this.data.LinkedList && this.data.LinkedList.length > 0) {
for (var i = 0; i < this.data.LinkedList.length; i++) {
@ -414,15 +427,18 @@ class BleHelper {
}
uni.onBluetoothAdapterStateChange((state) => {
console.log('蓝牙状态发生变化:' + JSON.stringify(state));
this.data.available = state.available;
this.data.discovering = state.discovering;
if (this.data.available && this.data
.isOpenBlue) { //蓝牙状态再次可用,重连所有设备
this.linkAllDevices();
// console.log('蓝牙状态发生变化:' + JSON.stringify(state));
if (this.data.available !== state.available) {
this.data.available = state.available;
this.data.discovering = state.discovering;
if (this.data.available && this.data
.isOpenBlue) { //蓝牙状态再次可用,重连所有设备
this.linkAllDevices();
}
}
if (!state.available) { //蓝牙状态不可用了,将所有设备标记为断开连接
this.data.LinkedList.filter((v) => {
v.Linked = false;
@ -439,7 +455,7 @@ class BleHelper {
if (!res.connected) {
console.log("蓝牙连接已断开", res);
this.data.LinkedList.find((v) => {
let f=this.data.LinkedList.find((v) => {
if (v.deviceId == res.deviceId) {
v.Linked = false;
v.notifyState = false;
@ -448,13 +464,15 @@ class BleHelper {
return false;
});
this.updateCache();
console.log("尝试5次恢复连接");
this.LinkBlue(res.deviceId,f.writeServiceId,f.wirteCharactId,f.notifyCharactId,5)
} else {
// console.log("蓝牙连接已恢复,", res);
console.log("蓝牙连接已恢复,", res);
}
});
uni.onBluetoothDeviceFound((devices) => {
// ////console.log("发现新设备:" + JSON.stringify(devices));
// console.log("发现新设备:" + JSON.stringify(devices));
this.data.searchList = this.data.searchList.concat(
devices);
if (this.cfg.onDeviceFound) {
@ -514,6 +532,20 @@ class BleHelper {
});
this.updateCache();
}
if (str.indexOf('imei:') == 0) {
let imei = str.split(':')[1];
this.data.LinkedList.find((v) => {
if (v.deviceId == receive
.deviceId) {
v.imei=imei;
}
});
this.updateCache();
}
if (bytes[0] == 0xFC) { //6155以0xFC开头代表mac地址
console.log("收到mac地址:", bytes)
@ -553,16 +585,18 @@ class BleHelper {
console.log("有人订阅消息")
this.cfg.receivDataCallback.forEach((
rec) => {
console.log("有人订阅消息111",)
console.log("有人订阅消息111", )
if (rec.callback) {
try{
rec.callback(recData, f,
path, this.cfg
.receivDataCallback);
}catch(err){
console.log("订阅消息出现异常",err);
try {
rec.callback(recData, f,
path, this.cfg
.receivDataCallback
);
} catch (err) {
console.log("订阅消息出现异常",
err);
}
}
})
} else {
@ -640,22 +674,42 @@ class BleHelper {
var these = this;
//开始搜索
var Search = () => {
console.log("Search........");
return new Promise((resolve, reject) => {
uni.startBluetoothDevicesDiscovery({
services: [],
allowDuplicatesKey: false,
success: (res) => {
//console.log('开始搜索蓝牙设备成功');
resolve(res);
//只搜索合作供应商的服务id
let serviceIds = serviceDic.map(v => {
return v.serviceId
});
},
fail: (err) => {
console.log(`搜索蓝牙设备失败:`, err);
//搜索一个服务id的设备循环调用
let RunSearch = (serviceId) => {
return new Promise((resolve, reject) => {
uni.startBluetoothDevicesDiscovery({
services:serviceId? [serviceId]:[],
allowDuplicatesKey: true,
success: (res) => {
//console.log('开始搜索蓝牙设备成功');
resolve(res);
reject(this.getError(err));
}
},
fail: (err) => {
console.log(`搜索蓝牙设备失败:`, err);
reject(this.getError(err));
}
});
});
}
return new Promise((resolve, reject) => {
let promises = [];
// for (let i = 0; i < serviceIds.length; i++) {
// promises.push(RunSearch(serviceIds[i]));
// }
promises.push(RunSearch());
Promise.all(promises).then(resolve).catch(reject);
});
@ -664,13 +718,15 @@ class BleHelper {
return this.OpenBlue().then((res) => {
console.log("蓝牙适配器状态", res)
// console.log("蓝牙适配器状态", res)
return Search();
});
}
//停止搜索
StopSearch() {
return new Promise((resolve, reject) => {
@ -714,21 +770,24 @@ class BleHelper {
//订阅消息
subScribe(deviceId, state) {
console.log("开始订阅消息");
return new Promise((resolve, reject) => {
setTimeout(() => {
let c = this.data.LinkedList.find((v) => {
return v.deviceId == deviceId;
});
if (state) {
if (c.notifyState) {
resolve();
return;
}
}
// console.log("c=", c);
let startSubScribe = (id, serviceId, characteristicId) => {
// console.log("serviceId=", serviceId);
// console.log("characteristicId=", characteristicId);
console.log("serviceId=", serviceId);
console.log("characteristicId=", characteristicId);
let p1 = new Promise((succ, err) => {
uni.notifyBLECharacteristicValueChange({
@ -787,33 +846,36 @@ class BleHelper {
if (item.properties.notify) {
promies.push(startSubScribe(deviceId, serviceId, characteristicId));
}
}
}else{
promies.push(startSubScribe(c.deviceId, c.notifyServiceid, c.notifyCharactId));
}
if (promies.length > 0) {
// console.log("234324324324");
Promise.allSettled(promies).then((results) => {
// console.log("11111");
results.forEach((result, index) => {
if (result.status === "fulfilled") {
// console.log(`操作${index + 1}成功:`, result.value);
// console.log(`操作${index + 1}成功:`, result.value);
} else {
// console.log(`操作${index + 1}失败:`, result.reason
// .message);
// console.log(`操作${index + 1}失败:`, result.reason
// .message);
}
});
// console.log("订阅消息成功");
resolve();
}).catch((ex) => {
// console.log("222222");
console.log("ex=",ex);
reject(ex);
}).finally(() => {
// console.log("finally")
});
} else {
// console.log("33333");
console.log("没有特征需要订阅");
resolve();
}
@ -845,16 +907,44 @@ class BleHelper {
v.services = res.services;
}
});
this.updateCache();
//this.updateCache();
var promises = [];
let s = null;
let se = res.services.find((v) => {
return v.uuid.indexOf(targetServiceId) > -1;
s = serviceDic.find(k => {
return k.serviceId == v.uuid;
})
if (s) {
return true;
}
return false;
// return v.uuid.indexOf(targetServiceId) > -1;
});
if (se) {
promises.push(this.getFeatrus(id, se.uuid, writeCharId,
notifyCharId));
console.log("合作供应商的",s)
this.data.LinkedList.find((v) => {
if (v.deviceId == id) {
v.writeServiceId = s.serviceId;
v.wirteCharactId = s.writeId;
v.notifyServiceid = s.serviceId;
v.notifyCharactId = s.notifyId;
}
});
this.updateCache();
//合作供应商的设备,直接订阅消息,不走发现特征了
promises.push(this.subScribe(id, true));
// promises.push(this.getFeatrus(id, se.uuid, writeCharId,
// notifyCharId));
} else {
console.log("预设的蓝牙服务和特征中找不到");
for (var i = 0; i < res.services.length; i++) {
let service = res.services[i];
promises.push(this.getFeatrus(id, service.uuid,
@ -873,13 +963,19 @@ class BleHelper {
Promise.all(promises)
.then(results => {
if (!s) {
//非指定供应商的设备,走订阅消息
return this.subScribe(id, true);
} else {
//指定供应商的设备已经订阅过了
return Promise.resolve();
}
return this.subScribe(id, true);
})
.then((res) => {
console.log('设备连接成功,初始化完成', res);
console.log("LinkedList=", this.data
console.log('设备连接成功,初始化完成', this.data
.LinkedList);
resolve();
})
.catch(error => {
@ -925,28 +1021,47 @@ class BleHelper {
deviceId: id,
serviceId: serviceId,
success: (res) => {
console.log("获取到特征:" + JSON.stringify(res));
res.characteristics.forEach((v) => {
v.serviceId = serviceId;
});
// res.characteristics.forEach((v) => {
// v.serviceId = serviceId;
// });
//写特征
let writeChar = res.characteristics.find(char => {
return char.uuid.indexOf(writeCharId) > -1
let fe = serviceDic.find(v => {
return v.serviceId == serviceId && v.writeId == char
.uuid;
})
// return char.uuid.indexOf(writeCharId) > -1
if (fe) {
return true;
}
return false;
});
if (!writeChar) {
writeChar = res.characteristics.find(char => {
return char.properties.write;
});
}
// if (!writeChar) {
// writeChar = res.characteristics.find(char => {
// return char.properties.write;
// });
// }
//通知特征
let notiChar = res.characteristics.find(char => {
return char.uuid.indexOf(notifyCharId) > -1;
let fe = serviceDic.find(v => {
return v.serviceId == serviceId && v.notifyId ==
char.uuid;
})
// return char.uuid.indexOf(writeCharId) > -1
if (fe) {
return true;
}
return false;
// return char.uuid.indexOf(notifyCharId) > -1;
});
if (!notiChar) {
notiChar = res.characteristics.find(char => {
return char.properties.notify;
});
}
// if (!notiChar) {
// notiChar = res.characteristics.find(char => {
// return char.properties.notify;
// });
// }
this.data.LinkedList.find(function(v) {
if (v.deviceId == id) {
if (!v.Characteristics) {
@ -998,9 +1113,11 @@ class BleHelper {
}
//连接某个设备
LinkBlue(deviceId, targetServiceId, writeCharId, notifyCharId) {
LinkBlue(deviceId, targetServiceId, writeCharId, notifyCharId, maxRetries) {
if (maxRetries === undefined) {
maxRetries = 0; // 最大重试次数
}
if (!writeCharId) {
writeCharId = "xxxx"; // "FFE1";
}
@ -1027,7 +1144,7 @@ class BleHelper {
var linkDevice = () => {
// 添加重试次数限制
let retryCount = 0;
const maxRetries = 5; // 最大重试次数
const connect = () => {
return new Promise((resolve, reject) => {
@ -1075,8 +1192,7 @@ class BleHelper {
deviceId: deviceId,
mtu: 512,
success: (mtu) => {
console.log("mtu设置成功",
mtu);
resolve(true);
},
fail: () => {
@ -1095,7 +1211,7 @@ class BleHelper {
},
fail: (ex) => {
ex = this.getError(ex);
console.log("蓝牙连接失败" + JSON.stringify(ex));
console.log("蓝牙" + deviceId + "连接失败" + JSON.stringify(ex));
// 连接超时后自动重试
if (ex.code === 10012 && retryCount < maxRetries) {

View File

@ -96,7 +96,7 @@ class BleReceive {
staticLevelText = '低档';
modeCurr = "low";
break;
case 0x68:
case 0x64:
staticLevelText = '关闭';
modeCurr = "close";
break;
@ -274,7 +274,7 @@ class BleReceive {
case 0x67:
staticLevelText = 'low';
break
case 0x68:
case 0x64:
staticLevelText = 'close';
break
}

View File

@ -1,218 +1,284 @@
var cfg={
Version:'Uat',//Dev:开发环境Uat:Uat环境Relese正式环境
DevApi:'http://192.168.110.54:8000/',//开发环境
UatApi:'http://114.55.111.217/',//UAT环境
ReleseApi:'http://relese:3169/api/'//Relese环境
}
import request from "@/utils/request.js";
export default {
baseURL : cfg.Version=='Dev'?cfg.DevApi:(cfg.Version=='Uat'?cfg.UatApi:cfg.ReleseApi),
guid:function generateUUID() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
const r = Math.random() * 16 | 0;
const v = c === 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
});
},
alert: function(title, content, callback) {
if(!title){
title='提示'
}
if(!content){
content=title;
}
uni.showModal({
title: title,
content: content,
success: function(res) {
if (res.confirm) {
console.log('用户点击确定');
} else if (res.cancel) {
console.log('用户点击取消');
}
if (callback) {
callback(res);
}
guid: function generateUUID() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
const r = Math.random() * 16 | 0;
const v = c === 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
});
},
alert: function(title, content, callback) {
if (!title) {
title = '提示'
}
if (!content) {
content = title;
}
uni.showModal({
title: title,
content: content,
success: function(res) {
if (res.confirm) {
console.log('用户点击确定');
} else if (res.cancel) {
console.log('用户点击取消');
}
});
},
showLoading:function(title,mask){
uni.showLoading({
title:title,
mask:mask,
})
},
hideLoading:function(){
uni.hideLoading();
},
showToast:function(title,mask,duration,callback){
if(!duration){
duration=1500;
}
if(mask==undefined){
mask=false;
}
uni.showToast({
title:title,
mask:mask,
duration:duration,
callback:callback,
icon: 'none'
})
},
GetData:function(url,data,method,contentType,succ,err,complete){
var these=this;
if(!url){
console.error("url为空");
return;
}
if(url.toLowerCase().indexOf('http://')==-1 || url.toLowerCase().indexOf('https://')==-1){
if(url.indexOf('/')==0){
url=url.substr(1,url.length-1);
if (callback) {
callback(res);
}
let ServerPath=these.DevApi;
if(these.Version==='Dev'){
ServerPath=these.DevApi;
}
else if(these.Version==='Uat'){
ServerPath=these.UatApi;
}
else if(these.Version==='Relese'){
ServerPath=these.ReleseApi;
}else{
these.DevApi
}
url=ServerPath+url;
}
var these=this;
if(!method){
method='POST';
});
},
showLoading: function(title, mask) {
uni.showLoading({
title: title,
mask: mask,
})
},
hideLoading: function() {
uni.hideLoading();
},
showToast: function(title, mask, duration, callback) {
if (!duration) {
duration = 1500;
}
if (mask == undefined) {
mask = false;
}
uni.showToast({
title: title,
mask: mask,
duration: duration,
callback: callback,
icon: 'none'
})
},
GetData: function(url, data, method, contentType, succ, err, complete) {
var these = this;
if (!url) {
console.error("url为空");
return;
}
if (url.toLowerCase().indexOf('http://') == -1 || url.toLowerCase().indexOf('https://') == -1) {
if (url.indexOf('/') == 0) {
url = url.substr(1, url.length - 1);
}
method=method.toUpperCase();
if(!contentType){
contentType='application/json;charset=UTF-8';
let ServerPath = these.DevApi;
if (these.Version === 'Dev') {
ServerPath = these.DevApi;
} else if (these.Version === 'Uat') {
ServerPath = these.UatApi;
} else if (these.Version === 'Relese') {
ServerPath = these.ReleseApi;
} else {
these.DevApi
}
these.checkLAN(
function(){
these.showLoading('请稍候..',true);
setTimeout(function(){
url = ServerPath + url;
}
var these = this;
if (!method) {
method = 'POST';
}
method = method.toUpperCase();
if (!contentType) {
contentType = 'application/json;charset=UTF-8';
}
these.checkLAN(
function() {
these.showLoading('请稍候..', true);
setTimeout(function() {
uni.request({
url:url,
data:data,
header:{
"Content-Type":contentType
url: url,
data: data,
header: {
"Content-Type": contentType
},
method:method,
timeout:60000,
dataType:'json',
success:function(json){
if(succ){
method: method,
timeout: 60000,
dataType: 'json',
success: function(json) {
if (succ) {
succ(json);
}
},
fail:function(ex){
if(err){
fail: function(ex) {
if (err) {
err(ex);
}
},
complete:function(){
if(complete){
complete: function() {
if (complete) {
complete();
}
}
});
},0);
}, 0);
}
,function(){
,
function() {
these.showToast('无网络连接');
});
},
checkLAN:function(succ,error){
uni.getNetworkType({
success: (res) => {
const networkType = res.networkType;
// 判断网络是否连接
if (networkType === 'none') {
},
checkLAN: function(succ, error) {
uni.getNetworkType({
success: (res) => {
const networkType = res.networkType;
// 判断网络是否连接
if (networkType === 'none') {
console.error('无网络连接')
if(error){
error();
}
}else{
if(succ){
if (error) {
error();
}
} else {
if (succ) {
succ();
}
}
},
fail: (err) => {
console.error('获取网络状态失败:', err);
if(error){
},
fail: (err) => {
console.error('获取网络状态失败:', err);
if (error) {
error();
}
}
});
},
DateFormat: function(date, format) {
if(!date){
date=new Date();
}
if(!format){
format='yyyy-MM-dd HH:mm:ss';
}
// 处理参数默认值
if (typeof date === 'string' || typeof date === 'number') {
date = new Date(date);
}
date = date instanceof Date ? date : new Date();
format = format || 'yyyy-MM-dd';
// 检查日期是否有效
if (isNaN(date.getTime())) {
return 'Invalid Date';
}
// 定义格式化映射
const formatMap = {
'yyyy': date.getFullYear(),
'MM': String(date.getMonth() + 1).padStart(2, '0'),
'dd': String(date.getDate()).padStart(2, '0'),
'HH': String(date.getHours()).padStart(2, '0'),
'mm': String(date.getMinutes()).padStart(2, '0'),
'ss': String(date.getSeconds()).padStart(2, '0'),
'SSS': String(date.getMilliseconds()).padStart(3, '0'),
'M': date.getMonth() + 1,
'd': date.getDate(),
'H': date.getHours(),
'm': date.getMinutes(),
's': date.getSeconds(),
'S': date.getMilliseconds()
};
// 替换格式字符串中的占位符
return format.replace(/(yyyy|MM|dd|HH|mm|ss|SSS|M|d|H|m|s|S)/g, (match) => {
return formatMap[match];
});
}
});
},
DateFormat: function(date, format) {
if (!date) {
date = new Date();
}
if (!format) {
format = 'yyyy-MM-dd HH:mm:ss';
}
// 处理参数默认值
if (typeof date === 'string' || typeof date === 'number') {
date = new Date(date);
}
date = date instanceof Date ? date : new Date();
format = format || 'yyyy-MM-dd';
// 检查日期是否有效
if (isNaN(date.getTime())) {
return 'Invalid Date';
}
// 定义格式化映射
const formatMap = {
'yyyy': date.getFullYear(),
'MM': String(date.getMonth() + 1).padStart(2, '0'),
'dd': String(date.getDate()).padStart(2, '0'),
'HH': String(date.getHours()).padStart(2, '0'),
'mm': String(date.getMinutes()).padStart(2, '0'),
'ss': String(date.getSeconds()).padStart(2, '0'),
'SSS': String(date.getMilliseconds()).padStart(3, '0'),
'M': date.getMonth() + 1,
'd': date.getDate(),
'H': date.getHours(),
'm': date.getMinutes(),
's': date.getSeconds(),
'S': date.getMilliseconds()
};
// 替换格式字符串中的占位符
return format.replace(/(yyyy|MM|dd|HH|mm|ss|SSS|M|d|H|m|s|S)/g, (match) => {
return formatMap[match];
});
},
getdeviceShareId(id) {//获取设备分享信息
return request({
url: `/app/deviceShare/${id}`,
method: 'get',
})
},
getPermissions(type) {
if (!type) {
type='6170';
}
let array = [{
value: "1",
label: "灯光模式",
checked: false,
type: ['210', '6170', '670']
},
{
value: "2",
label: "激光模式",
checked: false,
type: ['210', '6170']
},
{
value: "3",
label: "开机画面",
checked: false,
type: ['210', '6170', '670']
},
{
value: "4",
label: "人员信息登记",
checked: false,
type: ['210', '6170', '670']
},
{
value: "5",
label: "发送信息",
checked: false,
type: ['210', '6170', '670']
},
{
value: "6",
label: "产品信息",
checked: false,
type: ['210', '6170', '670']
}, {
value: "41",
label: "静电探测",
checked: false,
type: ['670']
}, {
value: "42",
label: "SOS",
checked: false,
type: ['210', '6170', '670']
}
]
let arr=[];
for (let i = 0; i < array.length; i++) {
let item = array[i];
if(!item){
continue;
}
if(!item.type){
continue;
}
let typeContais=item.type.find(v=>{
return v.includes(type);
});
if(typeContais){
let json={};
Object.assign(json,item);
arr.push(json);
}
}
return arr;
}
}

View File

@ -22,7 +22,7 @@ const request = (options) => {
header: options.header || {},
timeout: 30000,
success: (res) => {
console.log("res=",res);
// console.log("res=",res);
resolve(res.data);
},
fail: (err) => {

View File

@ -1,43 +1,106 @@
import request,{baseURL} from '@/utils/request.js'
import request, {
baseURL
} from '@/utils/request.js'
/**
* 检查并执行wgt热更新
* @param {String} updateUrl - 检查更新的接口地址
*/
function checkAndUpdateWgt(updateUrl) {
if(!plus){
if (!plus) {
return;
}
// 显示加载提示
let urls = ['http://114.55.111.217/app/CheckUpdate', 'https://t3v3e2xsjv.by.takin.cc/app/CheckUpdate'];
// 1. 获取当前应用版本信息
plus.runtime.getProperty(plus.runtime.appid, (widgetInfo) => {
const currentVersion = widgetInfo.version;
console.log("当前版本:" + currentVersion);
request({
url:'/app/auth/version',
method: 'get'
}).then(res=>{
console.log("检查版本更新:",res);
let os=plus.os.name.toLowerCase();
if(res.code!=200){
let callbck = (res) => {
uni.hideLoading();
// console.log("检查更新成功=", res)
if (res.statusCode === 200) {
const updateInfo = res.data.data;
if (!updateInfo.hasUpdate) {
return;
}
// 3. 显示更新提示
uni.showModal({
title: '检测到更新',
content: updateInfo.description || '有新版本可用,是否立即更新?',
confirmText: '立即更新',
cancelText: '稍后更新',
success: (modalRes) => {
if (modalRes.confirm) {
downloadAndInstallWgt(updateInfo.downloadUrl);
}
}
});
} else {
uni.showToast({
title: '当前已是最新版本',
icon: 'none',
duration: 2000
});
}
};
let Update = (url) => {
console.log("url=",url);
return new Promise((resolve, reject) => {
uni.request({
url: url,
method: 'GET',
data: {
currentVersion: currentVersion,
platform: uni.getSystemInfoSync().platform,
appId:"xhyc"
},
success: (res) => {
// console.log("res=>",res)
res.type='1';
resolve(res);
},
fail: (err) => {
console.log("err=",err);
reject(err);
},
complete:()=>{
console.log("complete");
}
});
});
}
let Callback1 = (res) => {
console.log("检查版本更新:", res);
let os = plus.os.name.toLowerCase();
if (res.code != 200) {
return;
}
let f=res.data.find(v=>{
if(v.dictLabel.toLowerCase()==os){
let f = res.data.find(v => {
if (v.dictLabel.toLowerCase() == os) {
return true;
}
return false;
});
if(f){
if(f.dictValue==currentVersion){
if (f) {
if (f.dictValue == currentVersion) {
return;
}
uni.showModal({
title: '检测到更新',
content: '当前版本“'+currentVersion+'”,发现新版本“'+f.dictValue+'”,是否立即更新?',
content: '当前版本“' + currentVersion + '”,发现新版本“' + f.dictValue + '”,是否立即更新?',
confirmText: '立即更新',
cancelText: '稍后更新',
success: (modalRes) => {
@ -47,58 +110,47 @@ function checkAndUpdateWgt(updateUrl) {
}
});
}
}).catch(ex=>{
console.log("检查更新失败:",ex);
});
// 2. 调用后端接口检查是否有更新
// uni.request({
// url: updateUrl,
// method: 'GET',
// data: {
// currentVersion: currentVersion,
// platform: uni.getSystemInfoSync().platform
// },
// success: (res) => {
// uni.hideLoading();
// console.log("res=", res)
// if (res.statusCode === 200) {
}
let Update1 = () => {
return request({
url: '/app/auth/version',
method: 'get'
});
}
let promises = [];
for (var i = 0; i < urls.length; i++) {
promises.push(Update(urls[i]));
}
promises.push(Update1());
Promise.allSettled(promises).then(results => {
let length = results.length;
let flag=false;
for (var i = 0; i < length; i++) {
console.log('results['+i+']=',results[i]);
if (results[i].status == 'fulfilled' && results[i].value.type==='1' && !flag ) {
flag=true;
callbck(results[i].value)
// break;
}
if(results[i].status == 'fulfilled' && results[i].value.type!=='1' && !flag){
flag=true;
Callback1(results[i].value);
// break;
}
}
if(!flag){
console.log("检查更新失败了");
}else{
console.log("检查更新成功");
}
});
// const updateInfo = res.data.data;
// if (!updateInfo.hasUpdate) {
// return;
// }
// // 3. 显示更新提示
// uni.showModal({
// title: '检测到更新',
// content: updateInfo.description || '有新版本可用,是否立即更新?',
// confirmText: '立即更新',
// cancelText: '稍后更新',
// success: (modalRes) => {
// if (modalRes.confirm) {
// downloadAndInstallWgt(updateInfo.downloadUrl);
// }
// }
// });
// } else {
// uni.showToast({
// title: '当前已是最新版本',
// icon: 'none',
// duration: 2000
// });
// }
// },
// fail: (err) => {
// uni.hideLoading();
// uni.showToast({
// title: '检查更新失败',
// icon: 'none',
// duration: 2000
// });
// console.error('检查更新失败:', err);
// }
// });
});
}
@ -108,8 +160,8 @@ function checkAndUpdateWgt(updateUrl) {
*/
function downloadAndInstallWgt(wgtUrl) {
// 显示下载进度
var wating=plus.nativeUI.showWaiting({
title:"下载中0%"
var wating = plus.nativeUI.showWaiting({
title: "下载中0%"
});
// uni.showLoading({
// title: '更新下载中...',
@ -182,7 +234,7 @@ function downloadAndInstallWgt(wgtUrl) {
// 监听下载进度
downloadTask.onProgressUpdate((progress) => {
console.log('下载进度: ' + progress.progress + '%');
wating.setTitle("下载中"+ progress.progress + '%');
wating.setTitle("下载中" + progress.progress + '%');
// 可以在这里更新自定义进度条
});
}