Compare commits
8 Commits
ed49622f1a
...
97cbb25753
| Author | SHA1 | Date | |
|---|---|---|---|
| 97cbb25753 | |||
| f3c21c2e1b | |||
| f8f199ad32 | |||
| 50373f407d | |||
| 1cd9853f2f | |||
| 482a47bd4f | |||
| ff5e363ccc | |||
| cb44810c6b |
2
App.vue
2
App.vue
@ -30,7 +30,7 @@
|
|||||||
|
|
||||||
uni.getSystemInfo({success:function(res){
|
uni.getSystemInfo({success:function(res){
|
||||||
if(res.uniPlatform=='app'){
|
if(res.uniPlatform=='app'){
|
||||||
upgrade.checkAndUpdateWgt("http://114.55.111.217/app/CheckUpdate");
|
upgrade.checkAndUpdateWgt();
|
||||||
bleTool.getBleTool();
|
bleTool.getBleTool();
|
||||||
}
|
}
|
||||||
}});
|
}});
|
||||||
|
|||||||
@ -83,10 +83,18 @@ function sendPic(data){
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//设备详情
|
||||||
|
function getDetail(id){
|
||||||
|
return request({
|
||||||
|
url: '/api/xinghan/device/'+id,
|
||||||
|
method: 'get',
|
||||||
|
})
|
||||||
|
}
|
||||||
export default{
|
export default{
|
||||||
sendUsr:sendUsr,
|
sendUsr:sendUsr,
|
||||||
warnMsg:warnMsg,
|
warnMsg:warnMsg,
|
||||||
sendPic:sendPic
|
sendPic:sendPic,
|
||||||
|
getDetail:getDetail
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
84
pages.json
84
pages.json
@ -226,78 +226,7 @@
|
|||||||
"navigationBarTitleText": "呼叫"
|
"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",
|
"path": "pages/670/HBY670",
|
||||||
"style": {
|
"style": {
|
||||||
@ -318,19 +247,12 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"path": "pages/BlueTooth/ModeSetting/4877",
|
"path": "pages/7305/BJQ7305",
|
||||||
"style": {
|
"style": {
|
||||||
"navigationBarTitleText": ""
|
"navigationBarTitleText": "BJQ7305"
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"path" : "pages/7305/BJQ7305",
|
|
||||||
"style" :
|
|
||||||
{
|
|
||||||
"navigationBarTitleText" : "BJQ7305"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
],
|
],
|
||||||
"tabBar": {
|
"tabBar": {
|
||||||
|
|||||||
@ -181,7 +181,8 @@
|
|||||||
visiblePrompt: false,
|
visiblePrompt: false,
|
||||||
promptTitle: '设备名称',
|
promptTitle: '设备名称',
|
||||||
modelValue: '',
|
modelValue: '',
|
||||||
visibleClose: false
|
visibleClose: false,
|
||||||
|
okCallback:null
|
||||||
},
|
},
|
||||||
BottomMenu: {
|
BottomMenu: {
|
||||||
show: false,
|
show: false,
|
||||||
@ -328,7 +329,7 @@
|
|||||||
});
|
});
|
||||||
if (!f) {
|
if (!f) {
|
||||||
|
|
||||||
|
these.getDetail();
|
||||||
these.showBleUnConnect();
|
these.showBleUnConnect();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -347,7 +348,7 @@
|
|||||||
these.formData.deviceId = f.deviceId;
|
these.formData.deviceId = f.deviceId;
|
||||||
ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId);
|
ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId);
|
||||||
these.setBleFormData();
|
these.setBleFormData();
|
||||||
|
these.getDetail();
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
@ -875,7 +876,7 @@
|
|||||||
setMode(mode, type) {
|
setMode(mode, type) {
|
||||||
|
|
||||||
let dataValue = 0;
|
let dataValue = 0;
|
||||||
|
|
||||||
|
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case 0:
|
case 0:
|
||||||
@ -1203,7 +1204,22 @@
|
|||||||
|
|
||||||
setTimeout(task, 0);
|
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() {
|
ack: function() {
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -200,7 +200,8 @@
|
|||||||
visiblePrompt: false,
|
visiblePrompt: false,
|
||||||
promptTitle: '设备名称',
|
promptTitle: '设备名称',
|
||||||
modelValue: '',
|
modelValue: '',
|
||||||
visibleClose: false
|
visibleClose: false,
|
||||||
|
okCallback:null
|
||||||
},
|
},
|
||||||
BottomMenu: {
|
BottomMenu: {
|
||||||
show: false,
|
show: false,
|
||||||
@ -255,10 +256,10 @@
|
|||||||
cMode: false,
|
cMode: false,
|
||||||
modeCurr: 'low',
|
modeCurr: 'low',
|
||||||
|
|
||||||
company: '黄石消防支队',
|
company: '',
|
||||||
name: '菜英俊',
|
name: '',
|
||||||
job: '小队长',
|
job: '',
|
||||||
id: 'HSXF01061',
|
id: '',
|
||||||
iswarn: false
|
iswarn: false
|
||||||
},
|
},
|
||||||
rgb565Data: [],
|
rgb565Data: [],
|
||||||
@ -314,6 +315,7 @@
|
|||||||
|
|
||||||
|
|
||||||
these.showBleUnConnect();
|
these.showBleUnConnect();
|
||||||
|
these.getDetail();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let form = f.formData;
|
let form = f.formData;
|
||||||
@ -331,7 +333,7 @@
|
|||||||
these.formData.deviceId = f.deviceId;
|
these.formData.deviceId = f.deviceId;
|
||||||
ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId);
|
ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId);
|
||||||
these.setBleFormData();
|
these.setBleFormData();
|
||||||
|
these.getDetail();
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
@ -392,7 +394,7 @@
|
|||||||
return className;
|
return className;
|
||||||
},
|
},
|
||||||
bleValueNotify: function(receive, device, path) { //订阅消息
|
bleValueNotify: function(receive, device, path) { //订阅消息
|
||||||
console.log("收到设备的数据", data)
|
console.log("收到设备的数据", receive)
|
||||||
let data = recei.ReceiveData(receive, device, pagePath);
|
let data = recei.ReceiveData(receive, device, pagePath);
|
||||||
|
|
||||||
if (data) {
|
if (data) {
|
||||||
@ -457,6 +459,23 @@
|
|||||||
|
|
||||||
return f;
|
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() {
|
setBleFormData() {
|
||||||
ble.data.LinkedList.find((v) => {
|
ble.data.LinkedList.find((v) => {
|
||||||
if (v.deviceId == these.formData.deviceId) {
|
if (v.deviceId == these.formData.deviceId) {
|
||||||
@ -491,7 +510,7 @@
|
|||||||
dataValue = 0x65;
|
dataValue = 0x65;
|
||||||
break;
|
break;
|
||||||
case "close": //关闭
|
case "close": //关闭
|
||||||
dataValue = 0x68;
|
dataValue = 0x64;
|
||||||
break;
|
break;
|
||||||
case true: //开灯
|
case true: //开灯
|
||||||
dataValue = 0x6E;
|
dataValue = 0x6E;
|
||||||
@ -959,8 +978,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
uni.uploadFile({
|
uni.uploadFile({
|
||||||
// url: 'http://114.55.111.217/video/upload',
|
url: 'http://114.55.111.217/video/upload',
|
||||||
url: baseURL+"app/video/upload",
|
// url: baseURL+"app/video/upload",
|
||||||
filePath: videoPath,
|
filePath: videoPath,
|
||||||
name: 'file',
|
name: 'file',
|
||||||
header: {
|
header: {
|
||||||
@ -1126,9 +1145,12 @@
|
|||||||
if (this.Status.Pop.clickEvt == 'SendUsr') {
|
if (this.Status.Pop.clickEvt == 'SendUsr') {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
console.log("1111");
|
||||||
|
|
||||||
this.Status.Pop.showPop = false;
|
this.Status.Pop.showPop = false;
|
||||||
|
if(this.Status.Pop.okCallback){
|
||||||
|
this.Status.Pop.okCallback();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
showPop: function(option) {
|
showPop: function(option) {
|
||||||
|
|
||||||
|
|||||||
@ -27,19 +27,37 @@
|
|||||||
<view class="eqinfo">
|
<view class="eqinfo">
|
||||||
<view class="item">
|
<view class="item">
|
||||||
<text class="lbl">设备IMEI</text>
|
<text class="lbl">设备IMEI</text>
|
||||||
<text class="value">{{device.deviceImei}}</text>
|
<text class="value valueFont">{{device.deviceImei}}</text>
|
||||||
</view>
|
</view>
|
||||||
<view class="item">
|
<view class="item">
|
||||||
<text class="lbl">设备名称</text>
|
<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>
|
||||||
<view class="item">
|
<view class="item">
|
||||||
<text class="lbl">定位信息</text>
|
<text class="lbl">定位信息</text>
|
||||||
<view>
|
<view class="multiValue">
|
||||||
<view>{{formData.lon}} {{formData.lat}}</view>
|
<view class="valueItem valueFont">
|
||||||
<text class="value">{{formData.address}}</text>
|
{{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>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
@ -78,6 +96,10 @@
|
|||||||
@click="GearSetting('hight','staticBattery')">
|
@click="GearSetting('hight','staticBattery')">
|
||||||
<view class="p100 center">高档</view>
|
<view class="p100 center">高档</view>
|
||||||
</view>
|
</view>
|
||||||
|
<view class="item " :class="formData.modeCurr=='close'?'active':''"
|
||||||
|
@click="GearSetting('close','staticBattery')">
|
||||||
|
<view class="p100 center">关闭</view>
|
||||||
|
</view>
|
||||||
|
|
||||||
</view>
|
</view>
|
||||||
<view class="optTitle">
|
<view class="optTitle">
|
||||||
@ -201,15 +223,15 @@
|
|||||||
<view class="proinfo lamp">
|
<view class="proinfo lamp">
|
||||||
<text class="title">产品信息</text>
|
<text class="title">产品信息</text>
|
||||||
<view class="itemcontent">
|
<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>
|
<image class="img" src="/static/images/6155/DeviceDetail/param.png" mode="aspectFit"></image>
|
||||||
<text class="txt">产品参数</text>
|
<text class="txt">产品参数</text>
|
||||||
</view>
|
</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>
|
<image class="img" src="/static/images/6155/DeviceDetail/remark.png" mode="aspectFit"></image>
|
||||||
<text class="txt">操作说明</text>
|
<text class="txt">操作说明</text>
|
||||||
</view>
|
</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>
|
<image class="img" src="/static/images/6155/DeviceDetail/video.png" mode="aspectFit"></image>
|
||||||
<text class="txt">操作视频</text>
|
<text class="txt">操作视频</text>
|
||||||
</view>
|
</view>
|
||||||
@ -246,6 +268,7 @@
|
|||||||
import BleReceive from '@/utils/BleReceive';
|
import BleReceive from '@/utils/BleReceive';
|
||||||
import api from '@/api/670/HBY670.js';
|
import api from '@/api/670/HBY670.js';
|
||||||
import MqttClient from '@/utils/mqtt.js';
|
import MqttClient from '@/utils/mqtt.js';
|
||||||
|
import Common from '@/utils/Common.js'
|
||||||
import {
|
import {
|
||||||
showLoading,
|
showLoading,
|
||||||
hideLoading,
|
hideLoading,
|
||||||
@ -299,7 +322,7 @@
|
|||||||
promptTitle: '设备名称',
|
promptTitle: '设备名称',
|
||||||
modelValue: '',
|
modelValue: '',
|
||||||
visibleClose: false,
|
visibleClose: false,
|
||||||
|
okCallback: null
|
||||||
},
|
},
|
||||||
BottomMenu: {
|
BottomMenu: {
|
||||||
show: false,
|
show: false,
|
||||||
@ -358,7 +381,8 @@
|
|||||||
warnLevel: "", //报警级别
|
warnLevel: "", //报警级别
|
||||||
staticWarn: false, //静止报警
|
staticWarn: false, //静止报警
|
||||||
fourGStrenth: 0, //4G信号强度
|
fourGStrenth: 0, //4G信号强度
|
||||||
deviceId: ""
|
deviceId: "",
|
||||||
|
sta_system: "" //设备状态,0关机,1仅充电,2开机未充电,3,开机且充电
|
||||||
},
|
},
|
||||||
device: {
|
device: {
|
||||||
id: "",
|
id: "",
|
||||||
@ -381,7 +405,8 @@
|
|||||||
},
|
},
|
||||||
rgb565Data: [],
|
rgb565Data: [],
|
||||||
videoHexArray: [],
|
videoHexArray: [],
|
||||||
picPath: ""
|
picPath: "",
|
||||||
|
permissions:[]//权限列表
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
@ -413,6 +438,15 @@
|
|||||||
var device = data.data;
|
var device = data.data;
|
||||||
these.Status.apiType = data.apiType;
|
these.Status.apiType = data.apiType;
|
||||||
these.device = device;
|
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) {
|
if (these.device.deviceImei) {
|
||||||
these.initMQ();
|
these.initMQ();
|
||||||
}
|
}
|
||||||
@ -425,6 +459,7 @@
|
|||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
if (!f) {
|
if (!f) {
|
||||||
|
these.getDetail();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let form = f.formData;
|
let form = f.formData;
|
||||||
@ -440,6 +475,7 @@
|
|||||||
} else if (these.device.deviceImei) {
|
} else if (these.device.deviceImei) {
|
||||||
these.formData['imei'] = these.device.deviceImei;
|
these.formData['imei'] = these.device.deviceImei;
|
||||||
}
|
}
|
||||||
|
these.getDetail();
|
||||||
ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId);
|
ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -454,6 +490,75 @@
|
|||||||
|
|
||||||
},
|
},
|
||||||
methods: {
|
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) {
|
getWarnStyle(index) {
|
||||||
let className = "";
|
let className = "";
|
||||||
|
|
||||||
@ -505,8 +610,11 @@
|
|||||||
ack: function(data) {}
|
ack: function(data) {}
|
||||||
},
|
},
|
||||||
success: (res) => {
|
success: (res) => {
|
||||||
|
debugger;
|
||||||
|
let json={persissonType:'670'};
|
||||||
|
Object.assign(json,this.device);
|
||||||
res.eventChannel.emit('share', {
|
res.eventChannel.emit('share', {
|
||||||
data: this.device,
|
data:json
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -540,6 +648,7 @@
|
|||||||
console.log("收到设备上报的数据", payload);
|
console.log("收到设备上报的数据", payload);
|
||||||
this.parseDataMQ(json);
|
this.parseDataMQ(json);
|
||||||
}
|
}
|
||||||
|
//以下操作已改到后端
|
||||||
// else if (keys.indexOf('sta_PicTrans') > -1) { //发送开机画面
|
// else if (keys.indexOf('sta_PicTrans') > -1) { //发送开机画面
|
||||||
// console.log("收到开机画面答复", payload);
|
// console.log("收到开机画面答复", payload);
|
||||||
// // this.SendImgMQ(json);
|
// // this.SendImgMQ(json);
|
||||||
@ -598,56 +707,80 @@
|
|||||||
},
|
},
|
||||||
parseDataMQ(json) {
|
parseDataMQ(json) {
|
||||||
let receiveData = {};
|
let receiveData = {};
|
||||||
let staticLevelText = "";
|
|
||||||
let dic = {
|
|
||||||
"3": "hight",
|
|
||||||
"2": "center",
|
|
||||||
"1": "low",
|
|
||||||
"0": "close",
|
|
||||||
|
|
||||||
};
|
let dic = {};
|
||||||
staticLevelText = dic[json.sta_DetectGrade];
|
if ("sta_DetectGrade" in json) {
|
||||||
|
dic = {
|
||||||
|
"3": "hight",
|
||||||
|
"2": "center",
|
||||||
|
"1": "low",
|
||||||
|
"0": "close",
|
||||||
|
|
||||||
let lightingLevelText = json.sta_LightGrade ===
|
};
|
||||||
1 ? 'hight' :
|
let staticLevelText = dic[json.sta_DetectGrade];
|
||||||
json.sta_LightGrade ===
|
receiveData.modeCurr = staticLevelText;
|
||||||
2 ?
|
}
|
||||||
'low' :
|
|
||||||
'close';
|
|
||||||
let warn = "";
|
|
||||||
dic = {
|
|
||||||
"0": "none",
|
|
||||||
"1": "ruo",
|
|
||||||
"2": "center",
|
|
||||||
"3": "hight",
|
|
||||||
"4": "veryhight",
|
|
||||||
};
|
|
||||||
warn = dic[json.sta_DetectResult];
|
|
||||||
|
|
||||||
|
if ("sta_LightGrade" in json) {
|
||||||
|
|
||||||
let sosText = null;
|
let lightingLevelText = json.sta_LightGrade === 1 ? 'hight' : json.sta_LightGrade === 2 ? 'low' :
|
||||||
if (json.sta_SOSGrade !== undefined) {
|
'close';
|
||||||
|
receiveData.lightCurr = lightingLevelText;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ("sta_DetectResult" in json) {
|
||||||
|
|
||||||
sosText = json.sta_SOSGrade === 2 ? 'rb' :
|
dic = {
|
||||||
json.sta_SOSGrade === 1 ? "sg" : "close"
|
"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;
|
receiveData.SOS = sosText;
|
||||||
}
|
}
|
||||||
let staticWarn = json.sta_ShakeBit === 1;
|
|
||||||
|
|
||||||
receiveData.modeCurr = staticLevelText;
|
if ("sta_ShakeBit" in json) {
|
||||||
receiveData.lightCurr = lightingLevelText;
|
let staticWarn = json.sta_ShakeBit === 1;
|
||||||
receiveData.xuhang = json.sta_PowerTime + "分钟";
|
receiveData.staticWarn = staticWarn;
|
||||||
receiveData.battary = json.sta_PowerPercent;
|
}
|
||||||
|
|
||||||
receiveData.warnLevel = warn;
|
if ("sta_PowerTime" in json) {
|
||||||
receiveData.staticWarn = staticWarn;
|
let hours = Math.floor(json.sta_PowerTime / 60);
|
||||||
receiveData.fourGStrenth = json.sta_4gSinal;
|
let remainingMinutes = json.sta_PowerTime % 60;
|
||||||
receiveData.imei = json.sta_imei;
|
let xuhang = '0分';
|
||||||
receiveData.Lon = json.sta_longitude;
|
// 处理不同情况的显示
|
||||||
receiveData.Lat = json.sta_latitude;
|
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');
|
this.refreshFormData(receiveData, 'auto');
|
||||||
return receiveData;
|
return receiveData;
|
||||||
},
|
},
|
||||||
@ -686,14 +819,14 @@
|
|||||||
for (var i = 0; i < keys.length; i++) {
|
for (var i = 0; i < keys.length; i++) {
|
||||||
let key = keys[i];
|
let key = keys[i];
|
||||||
if (key in these.formData) {
|
if (key in these.formData) {
|
||||||
these.formData[key] = data[key];
|
this.formData[key] = data[key];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (this.formData.imei) {
|
if (this.formData.imei) {
|
||||||
this.initMQ();
|
this.initMQ();
|
||||||
}
|
}
|
||||||
if (this.formData.staticWarn) { //有静止报警
|
if (this.formData.staticWarn) { //有静止报警
|
||||||
these.showPop({
|
this.showPop({
|
||||||
message: "设备静止报警中",
|
message: "设备静止报警中",
|
||||||
iconUrl: "/static/images/6155/DeviceDetail/warnning.png",
|
iconUrl: "/static/images/6155/DeviceDetail/warnning.png",
|
||||||
borderColor: "#e034344d",
|
borderColor: "#e034344d",
|
||||||
@ -701,8 +834,6 @@
|
|||||||
buttonText: "确定",
|
buttonText: "确定",
|
||||||
clickEvt: "staticWarn"
|
clickEvt: "staticWarn"
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.setBleFormData();
|
this.setBleFormData();
|
||||||
@ -732,6 +863,18 @@
|
|||||||
|
|
||||||
},
|
},
|
||||||
lightSetting: function(type) {
|
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) {
|
if (this.formData.lightCurr == type) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -897,11 +1040,30 @@
|
|||||||
borderColor: "#e034344d",
|
borderColor: "#e034344d",
|
||||||
buttonBgColor: "#E03434",
|
buttonBgColor: "#E03434",
|
||||||
buttonText: "解除报警",
|
buttonText: "解除报警",
|
||||||
okCallback: callback,
|
okCallback: () => {
|
||||||
|
if (callback) {
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
this.Status.Pop.okCallback = null;
|
||||||
|
},
|
||||||
clickEvt: 'time'
|
clickEvt: 'time'
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
sosSetting: function(type) {
|
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) {
|
if (this.formData.SOS == type) {
|
||||||
type = "close";
|
type = "close";
|
||||||
}
|
}
|
||||||
@ -985,7 +1147,7 @@
|
|||||||
let OpenSOS = () => {
|
let OpenSOS = () => {
|
||||||
these.formData.qzwarn = true; //标记为强制报警了
|
these.formData.qzwarn = true; //标记为强制报警了
|
||||||
|
|
||||||
these.Status.staticWarn.time = 50;
|
these.Status.staticWarn.time = 180;
|
||||||
this.formData.SOS = type;
|
this.formData.SOS = type;
|
||||||
|
|
||||||
let loopFunc = () => {
|
let loopFunc = () => {
|
||||||
@ -1009,21 +1171,34 @@
|
|||||||
console.log("111111");
|
console.log("111111");
|
||||||
this.showQzWarn(this.Status.Pop.okCallback);
|
this.showQzWarn(this.Status.Pop.okCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
these.Status.staticWarn.inteval = setInterval(() => {
|
these.Status.staticWarn.inteval = setInterval(() => {
|
||||||
loopFunc();
|
loopFunc();
|
||||||
}, 1000)
|
}, 1000);
|
||||||
|
|
||||||
bleSendCmd();
|
bleSendCmd();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (type == 'rb') { //红蓝报警
|
if (type == 'rb') { //红蓝报警
|
||||||
this.formData.SOS = type;
|
console.log("11111");
|
||||||
bleSendCmd();
|
let sendRb = () => {
|
||||||
return;
|
this.formData.SOS = type;
|
||||||
}
|
bleSendCmd();
|
||||||
if (type == 'sg') //强制报警
|
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({
|
this.showPop({
|
||||||
@ -1035,8 +1210,7 @@
|
|||||||
buttonText: "开启"
|
buttonText: "开启"
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
} else if (type == 'close') {
|
||||||
if (type == 'close') {
|
|
||||||
|
|
||||||
if (this.formData.SOS = 'sg') { //解除声光报警
|
if (this.formData.SOS = 'sg') { //解除声光报警
|
||||||
this.CloseWarn(true);
|
this.CloseWarn(true);
|
||||||
@ -1053,8 +1227,20 @@
|
|||||||
setTimeout(task, 0);
|
setTimeout(task, 0);
|
||||||
},
|
},
|
||||||
GearSetting: function(type) { //档位设置
|
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) {
|
if (this.formData.modeCurr == type) {
|
||||||
type = "close";
|
return;
|
||||||
}
|
}
|
||||||
showLoading(this, {
|
showLoading(this, {
|
||||||
text: "请稍候..."
|
text: "请稍候..."
|
||||||
@ -1066,7 +1252,7 @@
|
|||||||
hight: 0x65,
|
hight: 0x65,
|
||||||
center: 0x66,
|
center: 0x66,
|
||||||
low: 0x67,
|
low: 0x67,
|
||||||
close: 0x68
|
close: 0x64
|
||||||
},
|
},
|
||||||
mqtt: {
|
mqtt: {
|
||||||
hight: 3,
|
hight: 3,
|
||||||
@ -1137,32 +1323,27 @@
|
|||||||
|
|
||||||
setTimeout(task, 0);
|
setTimeout(task, 0);
|
||||||
},
|
},
|
||||||
|
proDetail:function(type){
|
||||||
proParam: function() {
|
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({
|
uni.navigateTo({
|
||||||
url: '/pages/common/productDes/index?id=' + this.device.id,
|
url: '/pages/common/'+type+'/index?id=' + this.device.id,
|
||||||
success(ev) {
|
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) {
|
checkImgUpload: function(type, index) {
|
||||||
console.log("123213213213");
|
console.log("123213213213");
|
||||||
let f = these.getDevice();
|
let f = these.getDevice();
|
||||||
@ -1576,8 +1757,8 @@
|
|||||||
}
|
}
|
||||||
console.log("baseURL=", baseURL);
|
console.log("baseURL=", baseURL);
|
||||||
uni.uploadFile({
|
uni.uploadFile({
|
||||||
// url: 'http://114.55.111.217/video/upload',
|
url: 'http://114.55.111.217/video/upload',
|
||||||
url: baseURL + "/app/video/upload",
|
// url: baseURL + "/app/video/upload",
|
||||||
filePath: videoPath,
|
filePath: videoPath,
|
||||||
name: 'file',
|
name: 'file',
|
||||||
header: {
|
header: {
|
||||||
@ -1617,7 +1798,7 @@
|
|||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
console.log("服务器未返回正确的数据");
|
console.log("服务器未返回正确的数据", arr);
|
||||||
|
|
||||||
|
|
||||||
these.showPop({
|
these.showPop({
|
||||||
@ -1700,6 +1881,18 @@
|
|||||||
|
|
||||||
},
|
},
|
||||||
ShowUpload: function() {
|
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.menuItems = [];
|
||||||
this.Status.BottomMenu.title = "上传开机画面";
|
this.Status.BottomMenu.title = "上传开机画面";
|
||||||
@ -1794,6 +1987,19 @@
|
|||||||
this.Status.Pop.showPop = true;
|
this.Status.Pop.showPop = true;
|
||||||
},
|
},
|
||||||
sendUsr: function(ReSendNo) {
|
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 requestSend = () => {
|
||||||
let json = {
|
let json = {
|
||||||
@ -1988,6 +2194,19 @@
|
|||||||
|
|
||||||
},
|
},
|
||||||
sendUrgent(type) {
|
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) {
|
if (!this.formData.msgTxt) {
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@ -1996,7 +2215,7 @@
|
|||||||
text: "请稍候..."
|
text: "请稍候..."
|
||||||
});
|
});
|
||||||
this.setBleFormData();
|
this.setBleFormData();
|
||||||
|
|
||||||
|
|
||||||
let data = {
|
let data = {
|
||||||
"sendMsg": this.formData.msgTxt,
|
"sendMsg": this.formData.msgTxt,
|
||||||
@ -2187,7 +2406,8 @@
|
|||||||
|
|
||||||
.eqinfo .item {
|
.eqinfo .item {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 60rpx;
|
min-height: 60rpx;
|
||||||
|
height: auto;
|
||||||
line-height: 60rpx;
|
line-height: 60rpx;
|
||||||
padding: 0rpx 28rpx;
|
padding: 0rpx 28rpx;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
@ -2204,21 +2424,49 @@
|
|||||||
font-family: PingFang SC;
|
font-family: PingFang SC;
|
||||||
font-size: 28rpx;
|
font-size: 28rpx;
|
||||||
font-weight: 400;
|
font-weight: 400;
|
||||||
|
width: 140rpx;
|
||||||
letter-spacing: 0.07px;
|
letter-spacing: 0.07px;
|
||||||
text-align: left;
|
text-align: left;
|
||||||
}
|
}
|
||||||
|
|
||||||
.eqinfo .value {
|
.eqinfo .value {
|
||||||
color: rgba(255, 255, 255, 0.6);
|
color: rgba(255, 255, 255, 0.6);
|
||||||
font-family: PingFang SC;
|
font-family: 'PingFang SC';
|
||||||
font-size: 28rpx;
|
font-size: 28rpx !important;
|
||||||
font-weight: 400;
|
font-weight: 400;
|
||||||
|
|
||||||
letter-spacing: 0.07px;
|
letter-spacing: 0.07px;
|
||||||
text-align: left;
|
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 {
|
.lamp {
|
||||||
margin-top: 24rpx;
|
margin-top: 24rpx;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -158,7 +158,7 @@
|
|||||||
var these = null;
|
var these = null;
|
||||||
var BrighInteval = null;
|
var BrighInteval = null;
|
||||||
var recei = null;
|
var recei = null;
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
TextToHexV1
|
TextToHexV1
|
||||||
@ -181,7 +181,8 @@
|
|||||||
visiblePrompt: false,
|
visiblePrompt: false,
|
||||||
promptTitle: '设备名称',
|
promptTitle: '设备名称',
|
||||||
modelValue: '',
|
modelValue: '',
|
||||||
visibleClose: false
|
visibleClose: false,
|
||||||
|
okCallback:null
|
||||||
},
|
},
|
||||||
BottomMenu: {
|
BottomMenu: {
|
||||||
show: false,
|
show: false,
|
||||||
@ -317,7 +318,7 @@
|
|||||||
|
|
||||||
let device = data.data;
|
let device = data.data;
|
||||||
these.device = device;
|
these.device = device;
|
||||||
|
|
||||||
let f = ble.data.LinkedList.find((v) => {
|
let f = ble.data.LinkedList.find((v) => {
|
||||||
if (v.macAddress == device.deviceMac) {
|
if (v.macAddress == device.deviceMac) {
|
||||||
console.log("找到设备了", v);
|
console.log("找到设备了", v);
|
||||||
@ -328,7 +329,7 @@
|
|||||||
});
|
});
|
||||||
if (!f) {
|
if (!f) {
|
||||||
|
|
||||||
|
these.getDetail();
|
||||||
these.showBleUnConnect();
|
these.showBleUnConnect();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -347,7 +348,7 @@
|
|||||||
these.formData.deviceId = f.deviceId;
|
these.formData.deviceId = f.deviceId;
|
||||||
ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId);
|
ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId);
|
||||||
these.setBleFormData();
|
these.setBleFormData();
|
||||||
|
these.getDetail();
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
@ -385,15 +386,15 @@
|
|||||||
}
|
}
|
||||||
switch (this.formData.mode) {
|
switch (this.formData.mode) {
|
||||||
case 0:
|
case 0:
|
||||||
|
|
||||||
|
|
||||||
txt = "强光模式";
|
txt = "强光模式";
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
txt = "弱光模式";
|
txt = "弱光模式";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
txt = "爆闪模式";
|
txt = "爆闪模式";
|
||||||
break;
|
break;
|
||||||
@ -403,7 +404,7 @@
|
|||||||
default:
|
default:
|
||||||
txt = "关闭";
|
txt = "关闭";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
return txt;
|
return txt;
|
||||||
}
|
}
|
||||||
@ -419,9 +420,9 @@
|
|||||||
return f;
|
return f;
|
||||||
},
|
},
|
||||||
bleValueNotify: function(receive, device, path) {
|
bleValueNotify: function(receive, device, path) {
|
||||||
|
|
||||||
let str = recei.ReceiveData(receive, device, path);
|
let str = recei.ReceiveData(receive, device, path);
|
||||||
|
|
||||||
console.log("处理接收到的数据:" + str);
|
console.log("处理接收到的数据:" + str);
|
||||||
return;
|
return;
|
||||||
let data = recei.ReceiveData(receive, device, path);
|
let data = recei.ReceiveData(receive, device, path);
|
||||||
@ -529,29 +530,31 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
showBleUnConnect(){
|
showBleUnConnect() {
|
||||||
this.showPop({
|
this.showPop({
|
||||||
message: "蓝牙未连接过该设备,请使用蓝牙重新添加该设备",
|
message: "蓝牙未连接过该设备,请使用蓝牙重新添加该设备",
|
||||||
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
|
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
|
||||||
borderColor: "#e034344d",
|
borderColor: "#e034344d",
|
||||||
buttonBgColor: "#E03434",
|
buttonBgColor: "#E03434",
|
||||||
buttonText:'去连接',
|
buttonText: '去连接',
|
||||||
okCallback:function(){
|
okCallback: function() {
|
||||||
console.log("1111");
|
console.log("1111");
|
||||||
uni.navigateTo({
|
uni.navigateTo({
|
||||||
url:"/pages/common/addBLE/addEquip",
|
url: "/pages/common/addBLE/addEquip",
|
||||||
events: {
|
events: {
|
||||||
BindOver: function(data) {
|
BindOver: function(data) {
|
||||||
console.log(data)
|
console.log(data)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
success: function(res) {
|
success: function(res) {
|
||||||
// 通过eventChannel向被打开页面传送数据
|
// 通过eventChannel向被打开页面传送数据
|
||||||
res.eventChannel.emit('detailData', { data: these.device })
|
res.eventChannel.emit('detailData', {
|
||||||
},
|
data: these.device
|
||||||
fail(ex){
|
})
|
||||||
console.log("跳转失败",ex);
|
},
|
||||||
}
|
fail(ex) {
|
||||||
|
console.log("跳转失败", ex);
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -642,8 +645,8 @@
|
|||||||
these.showPop({
|
these.showPop({
|
||||||
message: "上传成功",
|
message: "上传成功",
|
||||||
iconUrl: "/static/images/6155/DeviceDetail/uploadSuccess.png",
|
iconUrl: "/static/images/6155/DeviceDetail/uploadSuccess.png",
|
||||||
borderColor : '#BBE600',
|
borderColor: '#BBE600',
|
||||||
buttonBgColor : '#BBE600'
|
buttonBgColor: '#BBE600'
|
||||||
});
|
});
|
||||||
|
|
||||||
resolve();
|
resolve();
|
||||||
@ -889,9 +892,9 @@
|
|||||||
case 1:
|
case 1:
|
||||||
dataValue = 0x02;
|
dataValue = 0x02;
|
||||||
break;
|
break;
|
||||||
// case 2:
|
// case 2:
|
||||||
// dataValue = 0x02;
|
// dataValue = 0x02;
|
||||||
// break;
|
// break;
|
||||||
case 2:
|
case 2:
|
||||||
dataValue = 0x03;
|
dataValue = 0x03;
|
||||||
break;
|
break;
|
||||||
@ -974,7 +977,7 @@
|
|||||||
if (this.Status.Pop.clickEvt == 'SendUsr') {
|
if (this.Status.Pop.clickEvt == 'SendUsr') {
|
||||||
|
|
||||||
}
|
}
|
||||||
if(this.Status.Pop.okCallback){
|
if (this.Status.Pop.okCallback) {
|
||||||
this.Status.Pop.okCallback();
|
this.Status.Pop.okCallback();
|
||||||
}
|
}
|
||||||
this.Status.Pop.showPop = false;
|
this.Status.Pop.showPop = false;
|
||||||
@ -992,11 +995,11 @@
|
|||||||
okCallback: null,
|
okCallback: null,
|
||||||
cancelCallback: null,
|
cancelCallback: null,
|
||||||
popType: 'custom',
|
popType: 'custom',
|
||||||
buttonText:'确定',
|
buttonText: '确定',
|
||||||
clickEvt: ''
|
clickEvt: ''
|
||||||
};
|
};
|
||||||
if (!option) {
|
if (!option) {
|
||||||
|
|
||||||
}
|
}
|
||||||
let keys = Object.keys(option);
|
let keys = Object.keys(option);
|
||||||
for (var i = 0; i < keys.length; i++) {
|
for (var i = 0; i < keys.length; i++) {
|
||||||
@ -1011,7 +1014,7 @@
|
|||||||
}
|
}
|
||||||
this.Status.Pop[key] = defaultCfg[key];
|
this.Status.Pop[key] = defaultCfg[key];
|
||||||
}
|
}
|
||||||
|
|
||||||
this.Status.Pop.showPop = true;
|
this.Status.Pop.showPop = true;
|
||||||
},
|
},
|
||||||
sendUsr() {
|
sendUsr() {
|
||||||
@ -1171,18 +1174,18 @@
|
|||||||
console.log("发送成功");
|
console.log("发送成功");
|
||||||
this.showPop({
|
this.showPop({
|
||||||
message: "发送成功",
|
message: "发送成功",
|
||||||
iconUrl: "/static/images/6155/DeviceDetail/uploadSuccess.png",
|
iconUrl: "/static/images/6155/DeviceDetail/uploadSuccess.png",
|
||||||
borderColor : '#BBE600',
|
borderColor: '#BBE600',
|
||||||
buttonBgColor : '#BBE600'
|
buttonBgColor: '#BBE600'
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
let json = {
|
let json = {
|
||||||
deviceId: these.device.id,
|
deviceId: these.device.id,
|
||||||
name: these.formData.textLines[1],
|
name: these.formData.textLines[1],
|
||||||
position: these.formData.textLines[0],
|
position: these.formData.textLines[0],
|
||||||
unitName: these.formData.textLines[2],
|
unitName: these.formData.textLines[2],
|
||||||
code: ""
|
code: ""
|
||||||
};
|
};
|
||||||
@ -1199,7 +1202,22 @@
|
|||||||
|
|
||||||
setTimeout(task, 0);
|
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() {
|
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
@ -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>
|
|
||||||
@ -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>
|
|
||||||
@ -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>
|
|
||||||
@ -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>
|
|
||||||
@ -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>
|
|
||||||
@ -8,12 +8,18 @@
|
|||||||
<view class="deviceName">
|
<view class="deviceName">
|
||||||
蓝牙名:{{device.name}}
|
蓝牙名:{{device.name}}
|
||||||
</view>
|
</view>
|
||||||
|
<view class="deviceName">
|
||||||
|
状态:{{deviceStatu}}
|
||||||
|
</view>
|
||||||
<view class="deviceName">
|
<view class="deviceName">
|
||||||
设备名:{{device.deviceName}}
|
设备名:{{device.deviceName}}
|
||||||
</view>
|
</view>
|
||||||
<view class="deviceId">
|
<view class="deviceId">
|
||||||
设备Mac:{{device.macAddress}}
|
设备Mac:{{device.macAddress}}
|
||||||
</view>
|
</view>
|
||||||
|
<view class="deviceId">
|
||||||
|
设备IMEI:{{device.imei}}
|
||||||
|
</view>
|
||||||
<view class="bound" v-bind:class="boundStatu">
|
<view class="bound" v-bind:class="boundStatu">
|
||||||
{{Statu.boundRemark}}
|
{{Statu.boundRemark}}
|
||||||
</view>
|
</view>
|
||||||
@ -40,12 +46,14 @@
|
|||||||
var these = null;
|
var these = null;
|
||||||
var eventChannel = null;
|
var eventChannel = null;
|
||||||
var ble = null;
|
var ble = null;
|
||||||
var timeInteval = null;
|
|
||||||
export default {
|
export default {
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
Statu: {
|
Statu: {
|
||||||
bound: null
|
bound: null,
|
||||||
|
timeInteval:null,
|
||||||
|
isSearch:false
|
||||||
},
|
},
|
||||||
device: {
|
device: {
|
||||||
"deviceId": "",
|
"deviceId": "",
|
||||||
@ -57,7 +65,9 @@
|
|||||||
|
|
||||||
],
|
],
|
||||||
"linkStatu": false,
|
"linkStatu": false,
|
||||||
"macAddress": ""
|
"macAddress": "",
|
||||||
|
"communicationMode":"",
|
||||||
|
"imei":""
|
||||||
},
|
},
|
||||||
serverDevice:null
|
serverDevice:null
|
||||||
}
|
}
|
||||||
@ -72,15 +82,36 @@
|
|||||||
} else {
|
} else {
|
||||||
return "red";
|
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() {
|
onUnload() {
|
||||||
console.log("返回时断开蓝牙连接,取消订阅");
|
console.log("返回时断开蓝牙连接,取消订阅");
|
||||||
|
ble.disconnectDevice(these.device.deviceId);
|
||||||
ble.removeReceiveCallback(pagePath);
|
ble.removeReceiveCallback(pagePath);
|
||||||
},
|
},
|
||||||
onLoad(option) {
|
onLoad(option) {
|
||||||
@ -91,11 +122,12 @@
|
|||||||
console.log("收到设备消息,", receive);
|
console.log("收到设备消息,", receive);
|
||||||
if (these.device.deviceId == receive.deviceId) {
|
if (these.device.deviceId == receive.deviceId) {
|
||||||
console.log("11111:",receive);
|
console.log("11111:",receive);
|
||||||
|
these.device.imei=f.imei;
|
||||||
if (receive.bytes[0] == 0xFC || receive.str.indexOf('mac address:') == 0) {
|
if (receive.bytes[0] == 0xFC || receive.str.indexOf('mac address:') == 0) {
|
||||||
if (f && f.macAddress) {
|
if (f && f.macAddress) {
|
||||||
these.device.macAddress = f.macAddress;
|
these.device.macAddress = f.macAddress;
|
||||||
console.log("222222");
|
console.log("222222");
|
||||||
|
these.Statu.isSearch=false;
|
||||||
these.initDevice();
|
these.initDevice();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -112,9 +144,9 @@
|
|||||||
keys.forEach((v, index) => {
|
keys.forEach((v, index) => {
|
||||||
these.device[v] = f[v];
|
these.device[v] = f[v];
|
||||||
})
|
})
|
||||||
console.log("LinkedList=", ble.data.LinkedList)
|
// console.log("LinkedList=", ble.data.LinkedList)
|
||||||
console.log("f=", f);
|
// console.log("f=", f);
|
||||||
console.log("获取到设备", these.device);
|
// console.log("获取到设备", these.device);
|
||||||
if (f.macAddress) {
|
if (f.macAddress) {
|
||||||
these.device.macAddress = f.macAddress;
|
these.device.macAddress = f.macAddress;
|
||||||
|
|
||||||
@ -125,14 +157,18 @@
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// let inteval = setInterval(this.initDevice, 5000);
|
let inteval = setInterval(this.initDevice, 5000);
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
|
||||||
initDevice: function() {
|
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, {
|
showLoading(these, {
|
||||||
text: '正在获取设备信息'
|
text: '正在获取设备信息'
|
||||||
});
|
});
|
||||||
@ -144,6 +180,7 @@
|
|||||||
deviceMac: these.device.macAddress
|
deviceMac: these.device.macAddress
|
||||||
}
|
}
|
||||||
}).then(res => {
|
}).then(res => {
|
||||||
|
|
||||||
console.log("获取设备信息", res);
|
console.log("获取设备信息", res);
|
||||||
if (res && res.code == 200) {
|
if (res && res.code == 200) {
|
||||||
let data = res.data;
|
let data = res.data;
|
||||||
@ -180,6 +217,8 @@
|
|||||||
}).catch((ex) => {
|
}).catch((ex) => {
|
||||||
console.log("获取设备出现异常:", ex);
|
console.log("获取设备出现异常:", ex);
|
||||||
}).finally(() => {
|
}).finally(() => {
|
||||||
|
this.Statu.timeInteval=null;
|
||||||
|
this.Statu.isSearch=false;
|
||||||
hideLoading(these);
|
hideLoading(these);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -202,11 +241,16 @@
|
|||||||
these.Statu.boundRemark = "设备上报Mac地址异常";
|
these.Statu.boundRemark = "设备上报Mac地址异常";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if(!this.device.deviceName){
|
||||||
|
these.Statu.bound = false;
|
||||||
|
these.Statu.boundRemark = "设备未入库";
|
||||||
|
return;
|
||||||
|
}
|
||||||
these.Statu.bound = null;
|
these.Statu.bound = null;
|
||||||
these.Statu.boundRemark = "";
|
these.Statu.boundRemark = "";
|
||||||
showLoading(these, {
|
showLoading(these, {
|
||||||
|
|
||||||
text: "连接中..."
|
text: "绑定中..."
|
||||||
})
|
})
|
||||||
let promise = request({
|
let promise = request({
|
||||||
url: '/app/device/bind',
|
url: '/app/device/bind',
|
||||||
@ -214,7 +258,7 @@
|
|||||||
data: {
|
data: {
|
||||||
deviceImei: '',
|
deviceImei: '',
|
||||||
deviceMac: these.device.macAddress,
|
deviceMac: these.device.macAddress,
|
||||||
communicationMode: '1', //0是4g,1是蓝牙
|
communicationMode: 1, //0是4g,1是蓝牙,2蓝牙&4G
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
promise.then((res) => {
|
promise.then((res) => {
|
||||||
|
|||||||
@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
<view class="imgContent center">
|
<view class="imgContent center">
|
||||||
<view class="img 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>
|
</image>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
@ -27,7 +27,7 @@
|
|||||||
|
|
||||||
<view class="item " v-for="item, index in PairEquip" v-show="PairEquip.length>0">
|
<view class="item " v-for="item, index in PairEquip" v-show="PairEquip.length>0">
|
||||||
<view class="leftImg ">
|
<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>
|
</image>
|
||||||
</view>
|
</view>
|
||||||
<view class="centertxt ">
|
<view class="centertxt ">
|
||||||
@ -49,7 +49,7 @@
|
|||||||
<view class="item" v-on:click="Link(item,index)" v-for="item, index in EquipMents"
|
<view class="item" v-on:click="Link(item,index)" v-for="item, index in EquipMents"
|
||||||
v-show="!item['linkStatu']">
|
v-show="!item['linkStatu']">
|
||||||
<view class="leftImg ">
|
<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>
|
</image>
|
||||||
</view>
|
</view>
|
||||||
<view class="centertxt ">
|
<view class="centertxt ">
|
||||||
@ -81,8 +81,8 @@
|
|||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</BottomSlideMenuPlus>
|
</BottomSlideMenuPlus>
|
||||||
|
|
||||||
<global-loading ref="loading" />
|
<global-loading ref="loading" />
|
||||||
</view>
|
</view>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@ -94,10 +94,10 @@
|
|||||||
hideLoading,
|
hideLoading,
|
||||||
updateLoading
|
updateLoading
|
||||||
} from '@/utils/loading.js'
|
} from '@/utils/loading.js'
|
||||||
const pagePath="pages/common/addBLE/addEquip";
|
const pagePath = "pages/common/addBLE/addEquip";
|
||||||
var ble = null;
|
var ble = null;
|
||||||
var these = null;
|
var these = null;
|
||||||
var eventChannel=null;
|
var eventChannel = null;
|
||||||
export default {
|
export default {
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
@ -130,9 +130,9 @@
|
|||||||
},
|
},
|
||||||
PairEquip: [], //已配对设备
|
PairEquip: [], //已配对设备
|
||||||
EquipMents: [], //搜索出来的设备
|
EquipMents: [], //搜索出来的设备
|
||||||
device:null,
|
device: null,
|
||||||
item:{
|
item: {
|
||||||
deviceId:''
|
deviceId: ''
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -141,28 +141,24 @@
|
|||||||
},
|
},
|
||||||
onHide: function() {
|
onHide: function() {
|
||||||
ble.StopSearch();
|
ble.StopSearch();
|
||||||
|
|
||||||
},
|
},
|
||||||
onBackPress: (e) => {
|
|
||||||
|
onUnload() {
|
||||||
ble.StopSearch();
|
ble.StopSearch();
|
||||||
ble.removeDeviceFound(pagePath);
|
ble.removeDeviceFound(pagePath);
|
||||||
ble.removeReceiveCallback(pagePath);
|
ble.removeReceiveCallback(pagePath);
|
||||||
},
|
},
|
||||||
onUnload(){
|
|
||||||
ble.StopSearch();
|
|
||||||
ble.removeDeviceFound(pagePath);
|
|
||||||
ble.removeReceiveCallback(pagePath);
|
|
||||||
},
|
|
||||||
onLoad() {
|
onLoad() {
|
||||||
these = this;
|
these = this;
|
||||||
|
this.EquipMents = [];
|
||||||
ble = bleTool.getBleTool();
|
ble = bleTool.getBleTool();
|
||||||
ble.addDeviceFound((arr) => {
|
ble.addDeviceFound((arr) => {
|
||||||
|
|
||||||
arr = arr.devices;
|
arr = arr.devices;
|
||||||
for (var i = 0; i < arr.length; i++) {
|
for (var i = 0; i < arr.length; i++) {
|
||||||
|
|
||||||
arr[i].linkStatu = false;
|
arr[i].linkStatu = false;
|
||||||
if(!arr[i].name){
|
if (!arr[i].name) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let f = these.EquipMents.find(function(v) {
|
let f = these.EquipMents.find(function(v) {
|
||||||
@ -170,51 +166,56 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (!f) {
|
if (!f) {
|
||||||
|
|
||||||
these.EquipMents.push(arr[i]);
|
these.EquipMents.push(arr[i]);
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// console.log("equip=", these.EquipMents)
|
||||||
}, pagePath);
|
}, pagePath);
|
||||||
// console.log("addEquip")
|
// console.log("addEquip")
|
||||||
// ble.addReceiveCallback((receivData,f,path,arr) => {
|
ble.addReceiveCallback((receivData, f, path, arr) => {
|
||||||
// console.log("收到数据了:", receivData);//数据格式:{bytes:[109,97],str:"",hexs:"FA 01"}
|
if (f.macAddress && these.device) {
|
||||||
// if (this.item.deviceId == receivData.deviceId) {
|
showLoading(these, {
|
||||||
// console.log("11111:",receivData);
|
text: '正在验证设备'
|
||||||
|
});
|
||||||
|
|
||||||
// }
|
setTimeout(() => {
|
||||||
|
these.DeviceVerdict(f.deviceId);
|
||||||
// });
|
}, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}, pagePath);
|
||||||
eventChannel = this.getOpenerEventChannel();
|
eventChannel = this.getOpenerEventChannel();
|
||||||
|
|
||||||
eventChannel.on('detailData', function(rec) {
|
eventChannel.on('detailData', function(rec) {
|
||||||
console.log("接收到父页面的参数:",rec);
|
console.log("接收到父页面的参数:", rec);
|
||||||
these.device=rec.data;
|
these.device = rec.data;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
onShow: function() {
|
onShow: function() {
|
||||||
|
|
||||||
|
|
||||||
this.EquipMents=[];
|
// this.EquipMents = [];
|
||||||
this.PairEquip=[];
|
this.PairEquip = [];
|
||||||
ble.StartSearch().catch((ex) => {
|
ble && ble.StartSearch().catch((ex) => {
|
||||||
if (ex.code == 10001) {
|
if (ex.code == 10001) {
|
||||||
these.showOpenSetting();
|
these.showOpenSetting();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
isItemLink: function(item, index) {
|
isItemLink: function(item, index) {
|
||||||
let src = '/static/images/BLEAdd/noLink.png';
|
let src = '/static/images/BLEAdd/noLink.png';
|
||||||
|
|
||||||
if (this.PairEquip && this.PairEquip.length) {
|
if (this.PairEquip && this.PairEquip.length) {
|
||||||
if (this.PairEquip.length > 0) {
|
if (this.PairEquip.length > 0) {
|
||||||
let f = this.PairEquip.find(function(v) {
|
let f = this.PairEquip.find(function(v) {
|
||||||
@ -229,7 +230,7 @@
|
|||||||
}
|
}
|
||||||
return src;
|
return src;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
showOpenSetting: function() {
|
showOpenSetting: function() {
|
||||||
this.Status.BottomMenu.show = true;
|
this.Status.BottomMenu.show = true;
|
||||||
@ -238,57 +239,121 @@
|
|||||||
this.Status.BottomMenu.show = false;
|
this.Status.BottomMenu.show = false;
|
||||||
ble.showBlueSetting(false);
|
ble.showBlueSetting(false);
|
||||||
},
|
},
|
||||||
Link: function(item, index) {
|
DeviceVerdict(deviceId) { //判断是否是目标设备
|
||||||
this.item.deviceId=item.deviceId;
|
if (these.device) { //从设备详情过来的,回设备详情去
|
||||||
showLoading(this,{
|
let f = ble.data.LinkedList.find(v => {
|
||||||
text: "正在连接"
|
if (v.deviceId == deviceId) {
|
||||||
});
|
v.device = these.device;
|
||||||
setTimeout(() => {
|
return true;
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
console.log("连接成功");
|
return false;
|
||||||
if(these.device){//从设备详情过来的,回设备详情去
|
});
|
||||||
ble.data.LinkedList.find(v=>{
|
if (f.macAddress) {
|
||||||
if(v.deviceId==item.deviceId){
|
|
||||||
v.device=these.device;
|
|
||||||
return true;
|
if (f.macAddress != these.device.deviceMac) {
|
||||||
}
|
ble.disconnectDevice(deviceId);
|
||||||
return false;
|
updateLoading(these, {
|
||||||
});
|
text: "设备Mac地址错误,请重选设备连接"
|
||||||
ble.updateCache();
|
})
|
||||||
uni.navigateBack();
|
|
||||||
return;
|
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({
|
uni.navigateTo({
|
||||||
url:"/pages/common/addBLE/LinkBle",
|
url: "/pages/common/addBLE/LinkBle",
|
||||||
events:{
|
events: {
|
||||||
|
|
||||||
},
|
},
|
||||||
success(res) {
|
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 {
|
.list .item .leftImg {
|
||||||
width: 100rpx;
|
width: 60rpx;
|
||||||
height: 70rpx;
|
height: 60rpx;
|
||||||
}
|
}
|
||||||
|
|
||||||
.list .item .centertxt {
|
.list .item .centertxt {
|
||||||
@ -496,7 +561,7 @@
|
|||||||
font-family: "PingFang SC";
|
font-family: "PingFang SC";
|
||||||
font-size: 26rpx;
|
font-size: 26rpx;
|
||||||
font-weight: 400;
|
font-weight: 400;
|
||||||
line-height: 50rpx;
|
line-height: 36rpx;
|
||||||
text-align: left;
|
text-align: left;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -505,14 +570,14 @@
|
|||||||
font-family: "PingFang SC";
|
font-family: "PingFang SC";
|
||||||
font-size: 24rpx;
|
font-size: 24rpx;
|
||||||
font-weight: 400;
|
font-weight: 400;
|
||||||
line-height: 30rpx;
|
line-height: 36rpx;
|
||||||
text-align: left;
|
text-align: left;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
.list .item .rightIco .img {
|
.list .item .rightIco .img {
|
||||||
width: 50rpx;
|
width: 45rpx;
|
||||||
height: 50rpx;
|
height: 45rpx;
|
||||||
}
|
}
|
||||||
|
|
||||||
.openBlue {
|
.openBlue {
|
||||||
|
|||||||
@ -140,7 +140,8 @@
|
|||||||
// 跳转到详情页面
|
// 跳转到详情页面
|
||||||
handleFile(item) {
|
handleFile(item) {
|
||||||
uni.navigateTo({
|
uni.navigateTo({
|
||||||
url: "/pages/6170/deviceControl/index",
|
// url: "/pages/6170/deviceControl/index",
|
||||||
|
url:'/pages/670/HBY670',
|
||||||
success: (res) => {
|
success: (res) => {
|
||||||
// 页面跳转成功后的回调函数
|
// 页面跳转成功后的回调函数
|
||||||
res.eventChannel.emit('detailData', {
|
res.eventChannel.emit('detailData', {
|
||||||
|
|||||||
@ -227,7 +227,7 @@
|
|||||||
break;
|
break;
|
||||||
case 'share':
|
case 'share':
|
||||||
uni.navigateTo({
|
uni.navigateTo({
|
||||||
url: "/pages/6170/allShare/index"
|
url: "/pages/common/allShare/index"
|
||||||
})
|
})
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,98 +1,98 @@
|
|||||||
<template>
|
<template>
|
||||||
<view class="share">
|
<view class="share">
|
||||||
<!-- 内容区域 -->
|
<!-- 内容区域 -->
|
||||||
<view class="content">
|
<view class="content">
|
||||||
<!-- 分享设备 -->
|
<!-- 分享设备 -->
|
||||||
<view class="section" @click="shareDevice">
|
<view class="section" @click="shareDevice">
|
||||||
<text class="section-title">分享设备</text>
|
<text class="section-title">分享设备</text>
|
||||||
</view>
|
</view>
|
||||||
<!-- 分享管理 -->
|
<!-- 分享管理 -->
|
||||||
<view class="section" @click="shareManagement">
|
<view class="section" @click="shareManagement">
|
||||||
<text class="section-title">分享管理</text>
|
<text class="section-title">分享管理</text>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
export default {
|
export default {
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
itemInfo:""
|
itemInfo:""
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
// 分享设备
|
// 分享设备
|
||||||
shareDevice(){
|
shareDevice(){
|
||||||
uni.navigateTo({
|
uni.navigateTo({
|
||||||
url: '/pages/common/shareDevices/index',
|
url: '/pages/common/shareDevices/index',
|
||||||
events: {
|
events: {
|
||||||
ack: function(data) {}
|
ack: function(data) {}
|
||||||
},
|
},
|
||||||
success: (res) => {
|
success: (res) => {
|
||||||
res.eventChannel.emit('shareDevice', {
|
res.eventChannel.emit('shareDevice', {
|
||||||
data: this.itemInfo,
|
data: this.itemInfo,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
// 分享管理
|
// 分享管理
|
||||||
shareManagement(){
|
shareManagement(){
|
||||||
uni.navigateTo({
|
uni.navigateTo({
|
||||||
url: '/pages/common/shareManagement/index',
|
url: '/pages/common/shareManagement/index',
|
||||||
events: {
|
events: {
|
||||||
ack: function(data) {}
|
ack: function(data) {}
|
||||||
},
|
},
|
||||||
success: (res) => {
|
success: (res) => {
|
||||||
res.eventChannel.emit('shareManagement', {
|
res.eventChannel.emit('shareManagement', {
|
||||||
data: this.itemInfo,
|
data: this.itemInfo,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onLoad() {
|
onLoad() {
|
||||||
const eventChannel = this.getOpenerEventChannel();
|
const eventChannel = this.getOpenerEventChannel();
|
||||||
// 监听 'shareDevice' 事件,获取传过来的数据
|
// 监听 'shareDevice' 事件,获取传过来的数据
|
||||||
eventChannel.on('share', (data) => {
|
eventChannel.on('share', (data) => {
|
||||||
console.log(data,'datat');
|
console.log(data,'datat');
|
||||||
this.itemInfo = data.data;
|
this.itemInfo = data.data;
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
.share {
|
.share {
|
||||||
padding: 30rpx;
|
padding: 30rpx;
|
||||||
background: #121212;
|
background: #121212;
|
||||||
min-height: 100vh;
|
min-height: 100vh;
|
||||||
}
|
}
|
||||||
|
|
||||||
.status-bar {
|
.status-bar {
|
||||||
/* 根据实际情况设置状态栏高度 */
|
/* 根据实际情况设置状态栏高度 */
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 20px;
|
height: 20px;
|
||||||
background-color: #f3f3f3;
|
background-color: #f3f3f3;
|
||||||
}
|
}
|
||||||
|
|
||||||
.title {
|
.title {
|
||||||
font-size: 20px;
|
font-size: 20px;
|
||||||
margin-top: 10px;
|
margin-top: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.content {
|
.content {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
margin-top: 20px;
|
margin-top: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.section {
|
.section {
|
||||||
margin-bottom: 20px;
|
margin-bottom: 20px;
|
||||||
padding:50rpx;
|
padding:50rpx;
|
||||||
border-radius: 16rpx;
|
border-radius: 16rpx;
|
||||||
background: rgba(26, 26, 26, 1);
|
background: rgba(26, 26, 26, 1);
|
||||||
text-align: center;
|
text-align: center;
|
||||||
color: rgba(255, 255, 255, 0.87);
|
color: rgba(255, 255, 255, 0.87);
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
@ -69,6 +69,7 @@
|
|||||||
deviceShareCode,
|
deviceShareCode,
|
||||||
deviceShareAdd
|
deviceShareAdd
|
||||||
} from '@/api/6170/share.js'
|
} from '@/api/6170/share.js'
|
||||||
|
import Common from '@/utils/Common.js'
|
||||||
export default {
|
export default {
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
@ -199,12 +200,13 @@
|
|||||||
const selectedPermissions = this.permissions.filter(permission => permission.checked).map(
|
const selectedPermissions = this.permissions.filter(permission => permission.checked).map(
|
||||||
permission =>
|
permission =>
|
||||||
permission.value);
|
permission.value);
|
||||||
const res = await deviceShareAdd({
|
// const res = await deviceShareAdd({
|
||||||
phonenumber: this.phone,
|
// phonenumber: this.phone,
|
||||||
smsCode: this.code,
|
// smsCode: this.code,
|
||||||
deviceId: this.itemInfo.id,
|
// deviceId: this.itemInfo.id,
|
||||||
permission: selectedPermissions.join(',')
|
// permission: selectedPermissions.join(',')
|
||||||
})
|
// })
|
||||||
|
let res={code:200};
|
||||||
if (res.code == 200) {
|
if (res.code == 200) {
|
||||||
this.shareShow = true
|
this.shareShow = true
|
||||||
uni.hideLoading()
|
uni.hideLoading()
|
||||||
@ -237,6 +239,7 @@
|
|||||||
eventChannel.on('shareDevice', (data) => {
|
eventChannel.on('shareDevice', (data) => {
|
||||||
console.log(data, 'data1t111');
|
console.log(data, 'data1t111');
|
||||||
this.itemInfo = data.data;
|
this.itemInfo = data.data;
|
||||||
|
this.permissions=Common.getPermissions(this.itemInfo.persissonType);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,5 +1,18 @@
|
|||||||
import receivTool from "@/utils/BleReceive.js"
|
import receivTool from "@/utils/BleReceive.js"
|
||||||
var recei = null;
|
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 {
|
class BleHelper {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.StorageKey = "linkedDevices";
|
this.StorageKey = "linkedDevices";
|
||||||
@ -130,12 +143,12 @@ class BleHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
updateCache() {
|
updateCache() {
|
||||||
console.log("this.StorageKey=", this.StorageKey)
|
// console.log("this.StorageKey=", this.StorageKey)
|
||||||
uni.setStorageSync(this.StorageKey, this.data.LinkedList);
|
uni.setStorageSync(this.StorageKey, this.data.LinkedList);
|
||||||
}
|
}
|
||||||
|
|
||||||
linkAllDevices() {
|
linkAllDevices() {
|
||||||
console.log("模块启动时,自动连接已连接过的设备", this.data.LinkedList);
|
// console.log("模块启动时,自动连接已连接过的设备", this.data.LinkedList);
|
||||||
|
|
||||||
if (this.data.LinkedList && this.data.LinkedList.length > 0) {
|
if (this.data.LinkedList && this.data.LinkedList.length > 0) {
|
||||||
for (var i = 0; i < this.data.LinkedList.length; i++) {
|
for (var i = 0; i < this.data.LinkedList.length; i++) {
|
||||||
@ -414,15 +427,18 @@ class BleHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
uni.onBluetoothAdapterStateChange((state) => {
|
uni.onBluetoothAdapterStateChange((state) => {
|
||||||
console.log('蓝牙状态发生变化:' + JSON.stringify(state));
|
// console.log('蓝牙状态发生变化:' + JSON.stringify(state));
|
||||||
this.data.available = state.available;
|
if (this.data.available !== state.available) {
|
||||||
this.data.discovering = state.discovering;
|
this.data.available = state.available;
|
||||||
if (this.data.available && this.data
|
this.data.discovering = state.discovering;
|
||||||
.isOpenBlue) { //蓝牙状态再次可用,重连所有设备
|
if (this.data.available && this.data
|
||||||
this.linkAllDevices();
|
.isOpenBlue) { //蓝牙状态再次可用,重连所有设备
|
||||||
|
this.linkAllDevices();
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (!state.available) { //蓝牙状态不可用了,将所有设备标记为断开连接
|
if (!state.available) { //蓝牙状态不可用了,将所有设备标记为断开连接
|
||||||
this.data.LinkedList.filter((v) => {
|
this.data.LinkedList.filter((v) => {
|
||||||
v.Linked = false;
|
v.Linked = false;
|
||||||
@ -439,7 +455,7 @@ class BleHelper {
|
|||||||
if (!res.connected) {
|
if (!res.connected) {
|
||||||
|
|
||||||
console.log("蓝牙连接已断开", res);
|
console.log("蓝牙连接已断开", res);
|
||||||
this.data.LinkedList.find((v) => {
|
let f=this.data.LinkedList.find((v) => {
|
||||||
if (v.deviceId == res.deviceId) {
|
if (v.deviceId == res.deviceId) {
|
||||||
v.Linked = false;
|
v.Linked = false;
|
||||||
v.notifyState = false;
|
v.notifyState = false;
|
||||||
@ -448,13 +464,15 @@ class BleHelper {
|
|||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
this.updateCache();
|
this.updateCache();
|
||||||
|
console.log("尝试5次恢复连接");
|
||||||
|
this.LinkBlue(res.deviceId,f.writeServiceId,f.wirteCharactId,f.notifyCharactId,5)
|
||||||
} else {
|
} else {
|
||||||
// console.log("蓝牙连接已恢复,", res);
|
console.log("蓝牙连接已恢复,", res);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
uni.onBluetoothDeviceFound((devices) => {
|
uni.onBluetoothDeviceFound((devices) => {
|
||||||
// ////console.log("发现新设备:" + JSON.stringify(devices));
|
// console.log("发现新设备:" + JSON.stringify(devices));
|
||||||
this.data.searchList = this.data.searchList.concat(
|
this.data.searchList = this.data.searchList.concat(
|
||||||
devices);
|
devices);
|
||||||
if (this.cfg.onDeviceFound) {
|
if (this.cfg.onDeviceFound) {
|
||||||
@ -514,6 +532,20 @@ class BleHelper {
|
|||||||
});
|
});
|
||||||
this.updateCache();
|
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地址
|
if (bytes[0] == 0xFC) { //6155以0xFC开头代表mac地址
|
||||||
console.log("收到mac地址:", bytes)
|
console.log("收到mac地址:", bytes)
|
||||||
@ -553,16 +585,18 @@ class BleHelper {
|
|||||||
console.log("有人订阅消息")
|
console.log("有人订阅消息")
|
||||||
this.cfg.receivDataCallback.forEach((
|
this.cfg.receivDataCallback.forEach((
|
||||||
rec) => {
|
rec) => {
|
||||||
console.log("有人订阅消息111",)
|
console.log("有人订阅消息111", )
|
||||||
if (rec.callback) {
|
if (rec.callback) {
|
||||||
try{
|
try {
|
||||||
rec.callback(recData, f,
|
rec.callback(recData, f,
|
||||||
path, this.cfg
|
path, this.cfg
|
||||||
.receivDataCallback);
|
.receivDataCallback
|
||||||
}catch(err){
|
);
|
||||||
console.log("订阅消息出现异常",err);
|
} catch (err) {
|
||||||
|
console.log("订阅消息出现异常",
|
||||||
|
err);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
@ -640,22 +674,42 @@ class BleHelper {
|
|||||||
var these = this;
|
var these = this;
|
||||||
//开始搜索
|
//开始搜索
|
||||||
var Search = () => {
|
var Search = () => {
|
||||||
console.log("Search........");
|
//只搜索合作供应商的服务id
|
||||||
return new Promise((resolve, reject) => {
|
let serviceIds = serviceDic.map(v => {
|
||||||
uni.startBluetoothDevicesDiscovery({
|
return v.serviceId
|
||||||
services: [],
|
});
|
||||||
allowDuplicatesKey: false,
|
|
||||||
success: (res) => {
|
|
||||||
//console.log('开始搜索蓝牙设备成功');
|
|
||||||
resolve(res);
|
|
||||||
|
|
||||||
},
|
//搜索一个服务id的设备,循环调用
|
||||||
fail: (err) => {
|
let RunSearch = (serviceId) => {
|
||||||
console.log(`搜索蓝牙设备失败:`, err);
|
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) => {
|
return this.OpenBlue().then((res) => {
|
||||||
console.log("蓝牙适配器状态", res)
|
// console.log("蓝牙适配器状态", res)
|
||||||
|
|
||||||
return Search();
|
return Search();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//停止搜索
|
//停止搜索
|
||||||
StopSearch() {
|
StopSearch() {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
@ -714,21 +770,24 @@ class BleHelper {
|
|||||||
|
|
||||||
//订阅消息
|
//订阅消息
|
||||||
subScribe(deviceId, state) {
|
subScribe(deviceId, state) {
|
||||||
|
console.log("开始订阅消息");
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
|
|
||||||
let c = this.data.LinkedList.find((v) => {
|
let c = this.data.LinkedList.find((v) => {
|
||||||
return v.deviceId == deviceId;
|
return v.deviceId == deviceId;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (state) {
|
if (state) {
|
||||||
if (c.notifyState) {
|
if (c.notifyState) {
|
||||||
resolve();
|
resolve();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// console.log("c=", c);
|
|
||||||
let startSubScribe = (id, serviceId, characteristicId) => {
|
let startSubScribe = (id, serviceId, characteristicId) => {
|
||||||
// console.log("serviceId=", serviceId);
|
console.log("serviceId=", serviceId);
|
||||||
// console.log("characteristicId=", characteristicId);
|
console.log("characteristicId=", characteristicId);
|
||||||
let p1 = new Promise((succ, err) => {
|
let p1 = new Promise((succ, err) => {
|
||||||
|
|
||||||
uni.notifyBLECharacteristicValueChange({
|
uni.notifyBLECharacteristicValueChange({
|
||||||
@ -787,33 +846,36 @@ class BleHelper {
|
|||||||
|
|
||||||
if (item.properties.notify) {
|
if (item.properties.notify) {
|
||||||
promies.push(startSubScribe(deviceId, serviceId, characteristicId));
|
promies.push(startSubScribe(deviceId, serviceId, characteristicId));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}else{
|
||||||
|
promies.push(startSubScribe(c.deviceId, c.notifyServiceid, c.notifyCharactId));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (promies.length > 0) {
|
if (promies.length > 0) {
|
||||||
|
|
||||||
// console.log("234324324324");
|
|
||||||
Promise.allSettled(promies).then((results) => {
|
Promise.allSettled(promies).then((results) => {
|
||||||
// console.log("11111");
|
|
||||||
results.forEach((result, index) => {
|
results.forEach((result, index) => {
|
||||||
if (result.status === "fulfilled") {
|
if (result.status === "fulfilled") {
|
||||||
// console.log(`操作${index + 1}成功:`, result.value);
|
// console.log(`操作${index + 1}成功:`, result.value);
|
||||||
} else {
|
} else {
|
||||||
// console.log(`操作${index + 1}失败:`, result.reason
|
// console.log(`操作${index + 1}失败:`, result.reason
|
||||||
// .message);
|
// .message);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
// console.log("订阅消息成功");
|
||||||
resolve();
|
resolve();
|
||||||
}).catch((ex) => {
|
}).catch((ex) => {
|
||||||
// console.log("222222");
|
console.log("ex=",ex);
|
||||||
reject(ex);
|
reject(ex);
|
||||||
}).finally(() => {
|
}).finally(() => {
|
||||||
// console.log("finally")
|
// console.log("finally")
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// console.log("33333");
|
console.log("没有特征需要订阅");
|
||||||
resolve();
|
resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -845,16 +907,44 @@ class BleHelper {
|
|||||||
v.services = res.services;
|
v.services = res.services;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.updateCache();
|
//this.updateCache();
|
||||||
|
|
||||||
var promises = [];
|
var promises = [];
|
||||||
|
let s = null;
|
||||||
let se = res.services.find((v) => {
|
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) {
|
if (se) {
|
||||||
promises.push(this.getFeatrus(id, se.uuid, writeCharId,
|
console.log("合作供应商的",s)
|
||||||
notifyCharId));
|
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 {
|
} else {
|
||||||
|
console.log("预设的蓝牙服务和特征中找不到");
|
||||||
for (var i = 0; i < res.services.length; i++) {
|
for (var i = 0; i < res.services.length; i++) {
|
||||||
let service = res.services[i];
|
let service = res.services[i];
|
||||||
promises.push(this.getFeatrus(id, service.uuid,
|
promises.push(this.getFeatrus(id, service.uuid,
|
||||||
@ -873,13 +963,19 @@ class BleHelper {
|
|||||||
|
|
||||||
Promise.all(promises)
|
Promise.all(promises)
|
||||||
.then(results => {
|
.then(results => {
|
||||||
|
if (!s) {
|
||||||
|
//非指定供应商的设备,走订阅消息
|
||||||
|
return this.subScribe(id, true);
|
||||||
|
} else {
|
||||||
|
//指定供应商的设备已经订阅过了
|
||||||
|
return Promise.resolve();
|
||||||
|
}
|
||||||
|
|
||||||
return this.subScribe(id, true);
|
|
||||||
})
|
})
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
console.log('设备连接成功,初始化完成', res);
|
console.log('设备连接成功,初始化完成', this.data
|
||||||
console.log("LinkedList=", this.data
|
|
||||||
.LinkedList);
|
.LinkedList);
|
||||||
|
|
||||||
resolve();
|
resolve();
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
@ -925,28 +1021,47 @@ class BleHelper {
|
|||||||
deviceId: id,
|
deviceId: id,
|
||||||
serviceId: serviceId,
|
serviceId: serviceId,
|
||||||
success: (res) => {
|
success: (res) => {
|
||||||
|
|
||||||
console.log("获取到特征:" + JSON.stringify(res));
|
console.log("获取到特征:" + JSON.stringify(res));
|
||||||
res.characteristics.forEach((v) => {
|
// res.characteristics.forEach((v) => {
|
||||||
v.serviceId = serviceId;
|
// v.serviceId = serviceId;
|
||||||
});
|
// });
|
||||||
|
|
||||||
//写特征
|
//写特征
|
||||||
let writeChar = res.characteristics.find(char => {
|
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) {
|
// if (!writeChar) {
|
||||||
writeChar = res.characteristics.find(char => {
|
// writeChar = res.characteristics.find(char => {
|
||||||
return char.properties.write;
|
// return char.properties.write;
|
||||||
});
|
// });
|
||||||
}
|
// }
|
||||||
//通知特征
|
//通知特征
|
||||||
let notiChar = res.characteristics.find(char => {
|
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) {
|
// if (!notiChar) {
|
||||||
notiChar = res.characteristics.find(char => {
|
// notiChar = res.characteristics.find(char => {
|
||||||
return char.properties.notify;
|
// return char.properties.notify;
|
||||||
});
|
// });
|
||||||
}
|
// }
|
||||||
this.data.LinkedList.find(function(v) {
|
this.data.LinkedList.find(function(v) {
|
||||||
if (v.deviceId == id) {
|
if (v.deviceId == id) {
|
||||||
if (!v.Characteristics) {
|
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) {
|
if (!writeCharId) {
|
||||||
writeCharId = "xxxx"; // "FFE1";
|
writeCharId = "xxxx"; // "FFE1";
|
||||||
}
|
}
|
||||||
@ -1027,7 +1144,7 @@ class BleHelper {
|
|||||||
var linkDevice = () => {
|
var linkDevice = () => {
|
||||||
// 添加重试次数限制
|
// 添加重试次数限制
|
||||||
let retryCount = 0;
|
let retryCount = 0;
|
||||||
const maxRetries = 5; // 最大重试次数
|
|
||||||
|
|
||||||
const connect = () => {
|
const connect = () => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
@ -1075,8 +1192,7 @@ class BleHelper {
|
|||||||
deviceId: deviceId,
|
deviceId: deviceId,
|
||||||
mtu: 512,
|
mtu: 512,
|
||||||
success: (mtu) => {
|
success: (mtu) => {
|
||||||
console.log("mtu设置成功",
|
|
||||||
mtu);
|
|
||||||
resolve(true);
|
resolve(true);
|
||||||
},
|
},
|
||||||
fail: () => {
|
fail: () => {
|
||||||
@ -1095,7 +1211,7 @@ class BleHelper {
|
|||||||
},
|
},
|
||||||
fail: (ex) => {
|
fail: (ex) => {
|
||||||
ex = this.getError(ex);
|
ex = this.getError(ex);
|
||||||
console.log("蓝牙连接失败" + JSON.stringify(ex));
|
console.log("蓝牙" + deviceId + "连接失败" + JSON.stringify(ex));
|
||||||
|
|
||||||
// 连接超时后自动重试
|
// 连接超时后自动重试
|
||||||
if (ex.code === 10012 && retryCount < maxRetries) {
|
if (ex.code === 10012 && retryCount < maxRetries) {
|
||||||
|
|||||||
@ -96,7 +96,7 @@ class BleReceive {
|
|||||||
staticLevelText = '低档';
|
staticLevelText = '低档';
|
||||||
modeCurr = "low";
|
modeCurr = "low";
|
||||||
break;
|
break;
|
||||||
case 0x68:
|
case 0x64:
|
||||||
staticLevelText = '关闭';
|
staticLevelText = '关闭';
|
||||||
modeCurr = "close";
|
modeCurr = "close";
|
||||||
break;
|
break;
|
||||||
@ -274,7 +274,7 @@ class BleReceive {
|
|||||||
case 0x67:
|
case 0x67:
|
||||||
staticLevelText = 'low';
|
staticLevelText = 'low';
|
||||||
break
|
break
|
||||||
case 0x68:
|
case 0x64:
|
||||||
staticLevelText = 'close';
|
staticLevelText = 'close';
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|||||||
440
utils/Common.js
440
utils/Common.js
@ -1,218 +1,284 @@
|
|||||||
var cfg={
|
import request from "@/utils/request.js";
|
||||||
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环境
|
|
||||||
}
|
|
||||||
export default {
|
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) {
|
guid: function generateUUID() {
|
||||||
callback(res);
|
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);
|
||||||
showLoading:function(title,mask){
|
|
||||||
uni.showLoading({
|
|
||||||
title:title,
|
|
||||||
mask:mask,
|
|
||||||
})
|
|
||||||
},
|
|
||||||
hideLoading:function(){
|
|
||||||
uni.hideLoading();
|
|
||||||
},
|
|
||||||
showToast:function(title,mask,duration,callback){
|
|
||||||
if(!duration){
|
|
||||||
duration=1500;
|
|
||||||
}
|
|
||||||
if(mask==undefined){
|
|
||||||
mask=false;
|
|
||||||
}
|
|
||||||
uni.showToast({
|
|
||||||
title:title,
|
|
||||||
mask:mask,
|
|
||||||
duration:duration,
|
|
||||||
callback:callback,
|
|
||||||
icon: 'none'
|
|
||||||
})
|
|
||||||
},
|
|
||||||
GetData:function(url,data,method,contentType,succ,err,complete){
|
|
||||||
var these=this;
|
|
||||||
if(!url){
|
|
||||||
console.error("url为空");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(url.toLowerCase().indexOf('http://')==-1 || url.toLowerCase().indexOf('https://')==-1){
|
|
||||||
if(url.indexOf('/')==0){
|
|
||||||
url=url.substr(1,url.length-1);
|
|
||||||
}
|
}
|
||||||
let ServerPath=these.DevApi;
|
|
||||||
if(these.Version==='Dev'){
|
|
||||||
ServerPath=these.DevApi;
|
|
||||||
}
|
|
||||||
else if(these.Version==='Uat'){
|
|
||||||
ServerPath=these.UatApi;
|
|
||||||
}
|
|
||||||
else if(these.Version==='Relese'){
|
|
||||||
ServerPath=these.ReleseApi;
|
|
||||||
}else{
|
|
||||||
these.DevApi
|
|
||||||
}
|
|
||||||
url=ServerPath+url;
|
|
||||||
}
|
}
|
||||||
|
});
|
||||||
var these=this;
|
},
|
||||||
if(!method){
|
|
||||||
method='POST';
|
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();
|
let ServerPath = these.DevApi;
|
||||||
|
if (these.Version === 'Dev') {
|
||||||
if(!contentType){
|
ServerPath = these.DevApi;
|
||||||
contentType='application/json;charset=UTF-8';
|
} else if (these.Version === 'Uat') {
|
||||||
|
ServerPath = these.UatApi;
|
||||||
|
} else if (these.Version === 'Relese') {
|
||||||
|
ServerPath = these.ReleseApi;
|
||||||
|
} else {
|
||||||
|
these.DevApi
|
||||||
}
|
}
|
||||||
|
url = ServerPath + url;
|
||||||
these.checkLAN(
|
}
|
||||||
|
|
||||||
function(){
|
var these = this;
|
||||||
these.showLoading('请稍候..',true);
|
if (!method) {
|
||||||
setTimeout(function(){
|
method = 'POST';
|
||||||
|
}
|
||||||
|
method = method.toUpperCase();
|
||||||
|
|
||||||
|
if (!contentType) {
|
||||||
|
contentType = 'application/json;charset=UTF-8';
|
||||||
|
}
|
||||||
|
|
||||||
|
these.checkLAN(
|
||||||
|
|
||||||
|
function() {
|
||||||
|
these.showLoading('请稍候..', true);
|
||||||
|
setTimeout(function() {
|
||||||
uni.request({
|
uni.request({
|
||||||
url:url,
|
url: url,
|
||||||
data:data,
|
data: data,
|
||||||
header:{
|
header: {
|
||||||
"Content-Type":contentType
|
"Content-Type": contentType
|
||||||
},
|
},
|
||||||
method:method,
|
method: method,
|
||||||
timeout:60000,
|
timeout: 60000,
|
||||||
dataType:'json',
|
dataType: 'json',
|
||||||
success:function(json){
|
success: function(json) {
|
||||||
|
|
||||||
if(succ){
|
if (succ) {
|
||||||
succ(json);
|
succ(json);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
fail:function(ex){
|
fail: function(ex) {
|
||||||
|
|
||||||
if(err){
|
if (err) {
|
||||||
err(ex);
|
err(ex);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
complete:function(){
|
complete: function() {
|
||||||
|
|
||||||
if(complete){
|
if (complete) {
|
||||||
complete();
|
complete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
},0);
|
}, 0);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
,function(){
|
,
|
||||||
|
function() {
|
||||||
these.showToast('无网络连接');
|
these.showToast('无网络连接');
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
checkLAN:function(succ,error){
|
checkLAN: function(succ, error) {
|
||||||
uni.getNetworkType({
|
uni.getNetworkType({
|
||||||
success: (res) => {
|
success: (res) => {
|
||||||
const networkType = res.networkType;
|
const networkType = res.networkType;
|
||||||
|
|
||||||
|
|
||||||
// 判断网络是否连接
|
// 判断网络是否连接
|
||||||
if (networkType === 'none') {
|
if (networkType === 'none') {
|
||||||
console.error('无网络连接')
|
console.error('无网络连接')
|
||||||
if(error){
|
if (error) {
|
||||||
error();
|
error();
|
||||||
}
|
}
|
||||||
}else{
|
} else {
|
||||||
if(succ){
|
if (succ) {
|
||||||
succ();
|
succ();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
fail: (err) => {
|
fail: (err) => {
|
||||||
console.error('获取网络状态失败:', err);
|
console.error('获取网络状态失败:', err);
|
||||||
if(error){
|
if (error) {
|
||||||
error();
|
error();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
},
|
|
||||||
DateFormat: function(date, format) {
|
|
||||||
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -22,7 +22,7 @@ const request = (options) => {
|
|||||||
header: options.header || {},
|
header: options.header || {},
|
||||||
timeout: 30000,
|
timeout: 30000,
|
||||||
success: (res) => {
|
success: (res) => {
|
||||||
console.log("res=",res);
|
// console.log("res=",res);
|
||||||
resolve(res.data);
|
resolve(res.data);
|
||||||
},
|
},
|
||||||
fail: (err) => {
|
fail: (err) => {
|
||||||
|
|||||||
190
utils/update.js
190
utils/update.js
@ -1,43 +1,106 @@
|
|||||||
import request,{baseURL} from '@/utils/request.js'
|
import request, {
|
||||||
|
baseURL
|
||||||
|
} from '@/utils/request.js'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 检查并执行wgt热更新
|
* 检查并执行wgt热更新
|
||||||
* @param {String} updateUrl - 检查更新的接口地址
|
* @param {String} updateUrl - 检查更新的接口地址
|
||||||
*/
|
*/
|
||||||
function checkAndUpdateWgt(updateUrl) {
|
function checkAndUpdateWgt(updateUrl) {
|
||||||
if(!plus){
|
if (!plus) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// 显示加载提示
|
// 显示加载提示
|
||||||
|
|
||||||
|
let urls = ['http://114.55.111.217/app/CheckUpdate', 'https://t3v3e2xsjv.by.takin.cc/app/CheckUpdate'];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// 1. 获取当前应用版本信息
|
// 1. 获取当前应用版本信息
|
||||||
plus.runtime.getProperty(plus.runtime.appid, (widgetInfo) => {
|
plus.runtime.getProperty(plus.runtime.appid, (widgetInfo) => {
|
||||||
const currentVersion = widgetInfo.version;
|
const currentVersion = widgetInfo.version;
|
||||||
console.log("当前版本:" + currentVersion);
|
console.log("当前版本:" + currentVersion);
|
||||||
request({
|
|
||||||
url:'/app/auth/version',
|
|
||||||
method: 'get'
|
let callbck = (res) => {
|
||||||
}).then(res=>{
|
uni.hideLoading();
|
||||||
console.log("检查版本更新:",res);
|
// console.log("检查更新成功=", res)
|
||||||
let os=plus.os.name.toLowerCase();
|
if (res.statusCode === 200) {
|
||||||
if(res.code!=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;
|
return;
|
||||||
}
|
}
|
||||||
let f=res.data.find(v=>{
|
let f = res.data.find(v => {
|
||||||
if(v.dictLabel.toLowerCase()==os){
|
if (v.dictLabel.toLowerCase() == os) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
if(f){
|
if (f) {
|
||||||
if(f.dictValue==currentVersion){
|
if (f.dictValue == currentVersion) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
uni.showModal({
|
uni.showModal({
|
||||||
title: '检测到更新',
|
title: '检测到更新',
|
||||||
content: '当前版本“'+currentVersion+'”,发现新版本“'+f.dictValue+'”,是否立即更新?',
|
content: '当前版本“' + currentVersion + '”,发现新版本“' + f.dictValue + '”,是否立即更新?',
|
||||||
confirmText: '立即更新',
|
confirmText: '立即更新',
|
||||||
cancelText: '稍后更新',
|
cancelText: '稍后更新',
|
||||||
success: (modalRes) => {
|
success: (modalRes) => {
|
||||||
@ -47,58 +110,47 @@ function checkAndUpdateWgt(updateUrl) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}).catch(ex=>{
|
let Update1 = () => {
|
||||||
console.log("检查更新失败:",ex);
|
return request({
|
||||||
});
|
url: '/app/auth/version',
|
||||||
// 2. 调用后端接口检查是否有更新
|
method: 'get'
|
||||||
// uni.request({
|
});
|
||||||
// url: updateUrl,
|
}
|
||||||
// method: 'GET',
|
|
||||||
// data: {
|
|
||||||
// currentVersion: currentVersion,
|
let promises = [];
|
||||||
// platform: uni.getSystemInfoSync().platform
|
for (var i = 0; i < urls.length; i++) {
|
||||||
// },
|
promises.push(Update(urls[i]));
|
||||||
// success: (res) => {
|
}
|
||||||
// uni.hideLoading();
|
promises.push(Update1());
|
||||||
// console.log("res=", res)
|
|
||||||
// if (res.statusCode === 200) {
|
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) {
|
function downloadAndInstallWgt(wgtUrl) {
|
||||||
// 显示下载进度
|
// 显示下载进度
|
||||||
var wating=plus.nativeUI.showWaiting({
|
var wating = plus.nativeUI.showWaiting({
|
||||||
title:"下载中0%"
|
title: "下载中0%"
|
||||||
});
|
});
|
||||||
// uni.showLoading({
|
// uni.showLoading({
|
||||||
// title: '更新下载中...',
|
// title: '更新下载中...',
|
||||||
@ -182,7 +234,7 @@ function downloadAndInstallWgt(wgtUrl) {
|
|||||||
// 监听下载进度
|
// 监听下载进度
|
||||||
downloadTask.onProgressUpdate((progress) => {
|
downloadTask.onProgressUpdate((progress) => {
|
||||||
console.log('下载进度: ' + progress.progress + '%');
|
console.log('下载进度: ' + progress.progress + '%');
|
||||||
wating.setTitle("下载中"+ progress.progress + '%');
|
wating.setTitle("下载中" + progress.progress + '%');
|
||||||
// 可以在这里更新自定义进度条
|
// 可以在这里更新自定义进度条
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user