封装发送照片、视频、文字,各设备调用公共模块
This commit is contained in:
52
App.vue
52
App.vue
@ -9,32 +9,34 @@
|
||||
export default {
|
||||
|
||||
onLaunch: function() {
|
||||
//以下代码仅在开发时使用,否则会出现不可预知的问题。
|
||||
//清除登陆之外的所有信息;
|
||||
// let store=uni.getStorageInfoSync();
|
||||
// store.keys.forEach((val,index,array)=>{
|
||||
// if(val=="tokenTime"){
|
||||
// let time=uni.getStorageSync(val);
|
||||
// if(!time){
|
||||
// time=0;
|
||||
// }
|
||||
// let currTime=new Date().getTime();
|
||||
// if(currTime>=time){
|
||||
// uni.removeStorageSync(val);
|
||||
// uni.removeStorageSync("token");
|
||||
// uni.removeStorageSync("clientID");
|
||||
// }
|
||||
// }
|
||||
// else if(val=="token" || val=="clientID" || val=='phone'){
|
||||
// console.log("忽略登陆信息");
|
||||
// }else{
|
||||
// uni.removeStorageSync(val);
|
||||
// }
|
||||
// });
|
||||
// uni.clearStorageSync();
|
||||
//以上代码仅在开发时使用,否则会出现不可预知的问题。
|
||||
|
||||
|
||||
// #ifdef APP|APP-PLUS
|
||||
let appid = plus.runtime.appid;
|
||||
console.log("appid=", appid);
|
||||
|
||||
if (appid === 'HBuilder') {
|
||||
let store = uni.getStorageInfoSync();
|
||||
store.keys.forEach((val, index, array) => {
|
||||
if (val == "tokenTime") {
|
||||
let time = uni.getStorageSync(val);
|
||||
if (!time) {
|
||||
time = 0;
|
||||
}
|
||||
let currTime = new Date().getTime();
|
||||
if (currTime >= time) {
|
||||
uni.removeStorageSync(val);
|
||||
uni.removeStorageSync("token");
|
||||
uni.removeStorageSync("clientID");
|
||||
}
|
||||
} else if (val == "token" || val == "clientID" || val == 'phone') {
|
||||
console.log("忽略登陆信息");
|
||||
} else {
|
||||
uni.removeStorageSync(val);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
let system = uni.getSystemInfoSync();
|
||||
|
||||
|
||||
@ -365,7 +365,8 @@
|
||||
"path" : "pages/018A/HBY018A",
|
||||
"style" :
|
||||
{
|
||||
"navigationBarTitleText" : "HBY018A"
|
||||
"navigationBarTitleText" : "HBY018A",
|
||||
"navigationStyle": "custom"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
||||
@ -37,6 +37,10 @@
|
||||
<text class="lbl">设备名称</text>
|
||||
<text class="value">{{device.deviceName}}</text>
|
||||
</view>
|
||||
<view class="item">
|
||||
<text class="lbl">IMEI</text>
|
||||
<text class="value">{{device.deviceImei}}</text>
|
||||
</view>
|
||||
<view class="item">
|
||||
<text class="lbl">Mac地址</text>
|
||||
<text class="value">{{device.deviceMac}}</text>
|
||||
@ -57,12 +61,12 @@
|
||||
<text class="lbl">定位信息</text>
|
||||
<view class="multiValue" @click.stop="gotoMap()">
|
||||
<view class="valueItem valueFont">
|
||||
{{formData.sta_longitude}}
|
||||
{{formData?formData.sta_longitude:""}}
|
||||
|
||||
</view>
|
||||
<view class="valueItem valueFont">
|
||||
|
||||
{{formData.sta_latitude}}
|
||||
{{formData?formData.sta_latitude:""}}
|
||||
|
||||
</view>
|
||||
<view class="valueItem">
|
||||
@ -70,7 +74,7 @@
|
||||
<view style="width:80%;float: right;text-align: right;" class="valueFont">
|
||||
<uni-icons type="location" size="17" color="rgba(255, 255, 255, 0.8)"
|
||||
style="vertical-align: bottom;" />
|
||||
{{formData.address}}
|
||||
{{formData?formData.address:''}}
|
||||
</view>
|
||||
<view class="clear"></view>
|
||||
</view>
|
||||
@ -318,10 +322,11 @@
|
||||
let eventChannel = this.getOpenerEventChannel();
|
||||
|
||||
eventChannel.on('detailData', (data) => {
|
||||
|
||||
this.initWatch();
|
||||
// console.log("收到父页面的参数:" + JSON.stringify(data));
|
||||
var device = data.data;
|
||||
these.device = device;
|
||||
these.Status.apiType = data.apiType;
|
||||
if (data.apiType !== 'listA') {
|
||||
Common.getdeviceShareId(data.data.id).then(res => {
|
||||
if (res.code == 200) {
|
||||
@ -364,7 +369,7 @@
|
||||
these.setBleFormData();
|
||||
|
||||
|
||||
this.initWatch();
|
||||
|
||||
});
|
||||
|
||||
},
|
||||
@ -736,7 +741,7 @@
|
||||
console.log("this.formData[key] =", this.formData[key]);
|
||||
}
|
||||
},
|
||||
bleSend(json, validWarn = true) {
|
||||
bleSend(json, validWarn = true,bleLink) {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (this.formData.sta_ShakeBit != '' && this.formData.sta_ShakeBit != '0' && validWarn) {
|
||||
reject({
|
||||
@ -750,8 +755,10 @@
|
||||
reject({
|
||||
code: -1
|
||||
});
|
||||
|
||||
this.showBleUnConnect();
|
||||
if(bleLink){
|
||||
this.showBleUnConnect();
|
||||
}
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
@ -882,10 +889,8 @@
|
||||
let json = {
|
||||
ins_Side_Light: val
|
||||
}
|
||||
this.bleSend(json, true).then(() => {}).catch(ex => {
|
||||
if (ex.code == -1) {
|
||||
return;
|
||||
}
|
||||
this.bleSend(json, true,false).then(() => {}).catch(ex => {
|
||||
|
||||
console.log("蓝牙发送失败,尝试用mq发送");
|
||||
this.mqSend(json, true).catch(err => {
|
||||
if (err.code == -1) {
|
||||
@ -933,10 +938,8 @@
|
||||
ins_ShakeBit: type
|
||||
};
|
||||
|
||||
this.bleSend(json, false).catch(ex => {
|
||||
if (ex.code == -1) {
|
||||
return;
|
||||
}
|
||||
this.bleSend(json, false,false).catch(ex => {
|
||||
|
||||
|
||||
this.mqSend(json, false).catch(err => {
|
||||
if (err.code == -1) {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -10,7 +10,7 @@
|
||||
<view slot="right">
|
||||
<view class="navbarRight center">
|
||||
<view class="imgContent" :class="{'visibilityHidden':Status.apiType!=item.apiType}"
|
||||
@click.stop="handleRightClick(item,index)" v-for="item,index in Status.navbar.icons">
|
||||
@click.stop="handleRightClick(item,index)" v-for="item,index in Status.navbar.icons">
|
||||
<image class="img" :src="item.src" mode="aspectFit"></image>
|
||||
<view class="baber" v-if="item.math">{{item.math>9?'9+':item.math}}</view>
|
||||
</view>
|
||||
@ -95,13 +95,13 @@
|
||||
|
||||
<view class="lampMode">
|
||||
<view class="mode fleft " v-for="item,index in dic.SOS"
|
||||
:class="{active:formData.sta_SOSType===item.val,marginLeft:index%2==1}"
|
||||
v-on:click.stop="sosSetting(item,index)">
|
||||
:class="{active:formData.sta_SOSType===item.val,marginLeft:index%2==1}"
|
||||
v-on:click.stop="sosSetting(item,index)">
|
||||
<view class="leftImg">
|
||||
<image class="img" :class="(formData.sta_SOSType!==item.val || !item.activeImg)?'':'displayNone'"
|
||||
:src="item.img" mode="aspectFit"></image>
|
||||
:src="item.img" mode="aspectFit"></image>
|
||||
<image class="img" :class="(formData.sta_SOSType===item.val && item.activeImg)?'':'displayNone'"
|
||||
:src="item.activeImg" mode="aspectFit"></image>
|
||||
:src="item.activeImg" mode="aspectFit"></image>
|
||||
</view>
|
||||
<view class="rightTxt">
|
||||
<text class="bigTxt">{{item['text']}}</text>
|
||||
@ -109,7 +109,16 @@
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="mode fleft " :class="{active:Status.sendDisc}" v-on:click.stop="discern()">
|
||||
<view class="leftImg">
|
||||
<image class="img" src="/static/images/common/svg.png" mode="aspectFit"></image>
|
||||
|
||||
</view>
|
||||
<view class="rightTxt">
|
||||
<text class="bigTxt">识别设备</text>
|
||||
<text class="smallTxt" v-show="Status.sendDisc">蓝光闪烁中</text>
|
||||
</view>
|
||||
</view>
|
||||
<view class="clear"></view>
|
||||
</view>
|
||||
|
||||
@ -128,8 +137,8 @@
|
||||
<view class="lampMode">
|
||||
<view class="colorContent">
|
||||
<view v-for="item,index in formData.groups" class="item"
|
||||
:class="{active:item.id==formData.sta_GroupType,marginNoLeft:index%3===0}"
|
||||
@click.stop="groupSetting(item,index)">
|
||||
:class="{active:item.id==formData.sta_GroupType,marginNoLeft:index%3===0}"
|
||||
@click.stop="groupSetting(item,index)">
|
||||
|
||||
<view class="polygon" :style="{backgroundColor:item.hex}">
|
||||
|
||||
@ -153,7 +162,7 @@
|
||||
<view class="modeSetting">
|
||||
|
||||
<view class="arrow" @click.stop="ArrowModeSet('right_off')"
|
||||
:class="formData.sta_ArrowMode=='right_off'?'active':''">
|
||||
:class="formData.sta_ArrowMode=='right_off'?'active':''">
|
||||
<view class="outCircle">
|
||||
<view class="item">
|
||||
<image class="img nomal" src="/static/images/4877/arrow.png" mode="aspectFit"></image>
|
||||
@ -164,13 +173,13 @@
|
||||
<view class="text">朝左</view>
|
||||
</view>
|
||||
<view class="arrow" @click.stop="ArrowModeSet('right_on')"
|
||||
:class="formData.sta_ArrowMode=='right_on'?'active':''">
|
||||
:class="formData.sta_ArrowMode=='right_on'?'active':''">
|
||||
<view class="outCircle">
|
||||
<view class="item">
|
||||
<image class="img nomal translate" src="/static/images/4877/arrow.png" mode="aspectFit">
|
||||
</image>
|
||||
<image class="img activity translate" src="/static/images/4877/arrowActive.png"
|
||||
mode="aspectFit"></image>
|
||||
mode="aspectFit"></image>
|
||||
</view>
|
||||
</view>
|
||||
<view class="text">朝右</view>
|
||||
@ -185,7 +194,7 @@
|
||||
<view class="modeSetting">
|
||||
|
||||
<view class="arrow" @click.stop="ArrowSet('red_front')"
|
||||
:class="formData.sta_ArrowType=='red_front'?'redactive':''">
|
||||
:class="formData.sta_ArrowType=='red_front'?'redactive':''">
|
||||
<view class="outCircle">
|
||||
<view class="item">
|
||||
<view class="text">红色</view>
|
||||
@ -194,7 +203,7 @@
|
||||
|
||||
</view>
|
||||
<view class="arrow" @click.stop="ArrowSet('green_back')"
|
||||
:class="formData.sta_ArrowType=='green_back'?'greenactive':''">
|
||||
:class="formData.sta_ArrowType=='green_back'?'greenactive':''">
|
||||
<view class="outCircle">
|
||||
<view class="item">
|
||||
<view class="text">绿色</view>
|
||||
@ -217,7 +226,7 @@
|
||||
<view class="modeSetting">
|
||||
|
||||
<view class="arrow" @click.stop="ArrowSet('red_all')"
|
||||
:class="formData.sta_ArrowType=='red_all'?'active':''">
|
||||
:class="formData.sta_ArrowType=='red_all'?'active':''">
|
||||
<view class="outCircle">
|
||||
<view class="item">
|
||||
<image class="img nomal" src="/static/images/4877/arrowLR.png" mode="aspectFit"></image>
|
||||
@ -228,13 +237,13 @@
|
||||
<view class="text">红色双向</view>
|
||||
</view>
|
||||
<view class="arrow" @click.stop="ArrowSet('green_all')"
|
||||
:class="formData.sta_ArrowType=='green_all'?'active':''">
|
||||
:class="formData.sta_ArrowType=='green_all'?'active':''">
|
||||
<view class="outCircle">
|
||||
<view class="item">
|
||||
<image class="img nomal translate" src="/static/images/4877/arrowLR.png" mode="aspectFit">
|
||||
</image>
|
||||
<image class="img activity translate" src="/static/images/4877/arrowLRActive.png"
|
||||
mode="aspectFit"></image>
|
||||
mode="aspectFit"></image>
|
||||
</view>
|
||||
</view>
|
||||
<view class="text">绿色双向</view>
|
||||
@ -247,16 +256,16 @@
|
||||
|
||||
<!-- 弹窗通知 -->
|
||||
<MessagePopup :visible="Status.Pop.showPop" :type="Status.Pop.popType" :bgColor="Status.Pop.bgColor"
|
||||
:borderColor="Status.Pop.borderColor" :textColor="Status.Pop.textColor"
|
||||
:buttonBgColor="Status.Pop.buttonBgColor" :buttonTextColor="Status.Pop.buttonTextColor"
|
||||
:iconUrl="Status.Pop.iconUrl" :message="Status.Pop.message" :buttonText="Status.Pop.buttonText"
|
||||
@buttonClick="HidePop" :visiblePrompt="Status.Pop.visiblePrompt" :promptTitle="Status.Pop.promptTitle"
|
||||
v-model="Status.Pop.modelValue" @closePop="closePop" :buttonCancelText="Status.Pop.buttonCancelText"
|
||||
:showCancel="Status.Pop.showCancel" @cancelPop="closePop" :showSlot="Status.Pop.showSlot">
|
||||
:borderColor="Status.Pop.borderColor" :textColor="Status.Pop.textColor"
|
||||
:buttonBgColor="Status.Pop.buttonBgColor" :buttonTextColor="Status.Pop.buttonTextColor"
|
||||
:iconUrl="Status.Pop.iconUrl" :message="Status.Pop.message" :buttonText="Status.Pop.buttonText"
|
||||
@buttonClick="HidePop" :visiblePrompt="Status.Pop.visiblePrompt" :promptTitle="Status.Pop.promptTitle"
|
||||
v-model="Status.Pop.modelValue" @closePop="closePop" :buttonCancelText="Status.Pop.buttonCancelText"
|
||||
:showCancel="Status.Pop.showCancel" @cancelPop="closePop" :showSlot="Status.Pop.showSlot">
|
||||
<view v-if="Status.ShowEditChannel" class="popup-prompt">
|
||||
<text class="popup-prompt-title">修改信道</text>
|
||||
<input class="popup-prompt-input" type="number" placeholder="1-125的整数"
|
||||
placeholder-class="popup-prompt-input-placeHolder" v-model="formData.sta_Channel" />
|
||||
placeholder-class="popup-prompt-input-placeHolder" v-model="formData.sta_Channel" />
|
||||
|
||||
</view>
|
||||
</MessagePopup>
|
||||
@ -285,15 +294,15 @@
|
||||
} from '@/api/4877/BJQ4877.js';
|
||||
|
||||
import MqTool from '@/utils/MqHelper.js'
|
||||
import {
|
||||
MsgSuccess,
|
||||
MsgError,
|
||||
MsgClose,
|
||||
MsgWarning,
|
||||
showPop,
|
||||
MsgInfo,
|
||||
import {
|
||||
MsgSuccess,
|
||||
MsgError,
|
||||
MsgClose,
|
||||
MsgWarning,
|
||||
showPop,
|
||||
MsgInfo,
|
||||
MsgClear
|
||||
} from '@/utils/MsgPops.js'
|
||||
} from '@/utils/MsgPops.js'
|
||||
const pagePath = "/pages/4877/BJQ4877";
|
||||
|
||||
var ble = null;
|
||||
@ -306,6 +315,7 @@
|
||||
data() {
|
||||
return {
|
||||
Status: {
|
||||
sendDisc: '',
|
||||
apiType: '',
|
||||
navbar: {
|
||||
icons: [{
|
||||
@ -398,6 +408,7 @@
|
||||
groups: [
|
||||
|
||||
]
|
||||
|
||||
},
|
||||
dic: {
|
||||
SOS: [{
|
||||
@ -563,15 +574,15 @@
|
||||
},
|
||||
onShow() {
|
||||
this.Status.pageHide = false;
|
||||
|
||||
let f=this.getDevice();
|
||||
if(f){
|
||||
these.formData.bleStatu = 'connecting';
|
||||
ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId).then(res => {
|
||||
console.log("连接成功")
|
||||
these.formData.bleStatu = true;
|
||||
});
|
||||
}
|
||||
|
||||
let f = this.getDevice();
|
||||
if (f) {
|
||||
these.formData.bleStatu = 'connecting';
|
||||
ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId).then(res => {
|
||||
console.log("连接成功")
|
||||
these.formData.bleStatu = true;
|
||||
});
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
getbleStatu() {
|
||||
@ -707,7 +718,7 @@
|
||||
buttonBgColor: "#E03434",
|
||||
okCallback: null,
|
||||
buttonText: "确定"
|
||||
},these)
|
||||
}, these)
|
||||
return;
|
||||
}
|
||||
|
||||
@ -738,7 +749,7 @@
|
||||
cancelCallback: () => {
|
||||
this.Status.ShowEditChannel = false;
|
||||
}
|
||||
},these);
|
||||
}, these);
|
||||
},
|
||||
onChannelChanging() {
|
||||
let regex = /^(0|([1-9]\d?)|1[01]\d|12[0-5])$/;
|
||||
@ -788,7 +799,7 @@
|
||||
buttonBgColor: "#E03434",
|
||||
okCallback: null,
|
||||
buttonText: "确定"
|
||||
},these)
|
||||
}, these)
|
||||
return;
|
||||
}
|
||||
|
||||
@ -851,7 +862,7 @@
|
||||
buttonBgColor: "#E03434",
|
||||
okCallback: null,
|
||||
buttonText: "确定"
|
||||
},these)
|
||||
}, these)
|
||||
return;
|
||||
}
|
||||
uni.navigateTo({
|
||||
@ -934,7 +945,7 @@
|
||||
buttonBgColor: "#E03434",
|
||||
okCallback: null,
|
||||
buttonText: "确定"
|
||||
},these)
|
||||
}, these)
|
||||
return;
|
||||
}
|
||||
|
||||
@ -982,7 +993,45 @@
|
||||
this.formData.warnTime = 0;
|
||||
}
|
||||
},
|
||||
discern() {
|
||||
//识别设备,连续发送20次识别指令
|
||||
let f = this.getDevice();
|
||||
if (!f) {
|
||||
this.showBleUnConnect();
|
||||
|
||||
return;
|
||||
}
|
||||
var json = {
|
||||
ins_disc: 1
|
||||
}
|
||||
let index = 0;
|
||||
let total = 20;
|
||||
|
||||
console.error("发送识别指令:", json);
|
||||
this.Status.sendDisc = true;
|
||||
|
||||
let sendNextPacket = () => {
|
||||
if(index>total){
|
||||
this.Status.sendDisc = false;
|
||||
|
||||
return;
|
||||
}
|
||||
ble.sendString(f.deviceId, json, f.writeServiceId, f.wirteCharactId, 30).then(res => {
|
||||
index++;
|
||||
setTimeout(sendNextPacket,300);
|
||||
}).catch(err => {
|
||||
if (err.code == '10007') {
|
||||
setTimeout(sendNextPacket, 800);
|
||||
return;
|
||||
}
|
||||
if(index==0){
|
||||
MsgError(err.msg,'',these);
|
||||
}
|
||||
this.Status.sendDisc = false;
|
||||
});
|
||||
}
|
||||
sendNextPacket();
|
||||
},
|
||||
sosSetting(item, index) {
|
||||
if (!this.permissions.includes('42') && this.Status.apiType !== 'listA') {
|
||||
|
||||
@ -993,7 +1042,7 @@
|
||||
buttonBgColor: "#E03434",
|
||||
okCallback: null,
|
||||
buttonText: "确定"
|
||||
},these)
|
||||
}, these)
|
||||
return;
|
||||
}
|
||||
let f = this.getDevice();
|
||||
@ -1035,7 +1084,7 @@
|
||||
buttonText: (this.formData.sta_SOSType === 'sos' ? '关闭' : '开启'),
|
||||
showCancel: true,
|
||||
buttonCancelText: '取消'
|
||||
},these);
|
||||
}, these);
|
||||
}
|
||||
if (item.val === 'sos') {
|
||||
confirmTask();
|
||||
@ -1085,9 +1134,9 @@
|
||||
// return;
|
||||
// }
|
||||
if (res.deviceId == these.formData.deviceId) {
|
||||
if(res.device){
|
||||
if (res.device) {
|
||||
these.formData.bleStatu = 'connecting';
|
||||
}else{
|
||||
} else {
|
||||
this.formData.bleStatu = false;
|
||||
}
|
||||
setTimeout(() => {
|
||||
@ -1181,7 +1230,7 @@
|
||||
if (receive.deviceId !== this.formData.deviceId) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
console.log("收到设备的数据", receive)
|
||||
let data = recei.ReceiveData(receive, device, pagePath, recArr);
|
||||
console.log("处理后的数据:", data);
|
||||
@ -1225,8 +1274,8 @@
|
||||
},
|
||||
getDevice: function() {
|
||||
|
||||
// console.log("LinkedList=", ble.data.LinkedList);
|
||||
// console.log("formData=", these.formData);
|
||||
console.log("LinkedList=", ble.data.LinkedList);
|
||||
console.log("formData=", these.device);
|
||||
let f = ble.data.LinkedList.find((v) => {
|
||||
return v.macAddress == these.device.deviceMac;
|
||||
});
|
||||
@ -1255,7 +1304,7 @@
|
||||
borderColor: "#e034344d",
|
||||
buttonBgColor: "#E03434",
|
||||
buttonText: '去连接',
|
||||
buttonTextColor: '#FFFFFFde',
|
||||
buttonTextColor: '#FFFFFFde',
|
||||
okCallback: function() {
|
||||
|
||||
uni.navigateTo({
|
||||
@ -1277,10 +1326,10 @@
|
||||
}
|
||||
})
|
||||
}
|
||||
},these);
|
||||
}, these);
|
||||
},
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -1302,62 +1351,61 @@
|
||||
this.Status.Pop.okCallback();
|
||||
}
|
||||
},
|
||||
showPop: function (option) {
|
||||
hideLoading(this);
|
||||
let def = {
|
||||
showPop: true, //是否显示弹窗
|
||||
popType: 'custom',
|
||||
bgColor: '#383934bd',
|
||||
borderColor: '#BBE600',
|
||||
textColor: '#ffffffde',
|
||||
buttonBgColor: '#BBE600',
|
||||
buttonTextColor: '#232323DE',
|
||||
iconUrl: '',
|
||||
message: '',
|
||||
buttonText: '确定',
|
||||
clickEvt: '',
|
||||
visiblePrompt: false,
|
||||
promptTitle: '',
|
||||
modelValue: '',
|
||||
visibleClose: false,
|
||||
okCallback: null,
|
||||
showSlot: false,
|
||||
buttonCancelText: '',
|
||||
showCancel: false,
|
||||
}
|
||||
|
||||
let keys = Object.keys(def);
|
||||
|
||||
for (let i = 0; i < keys.length; i++) {
|
||||
let key = keys[i];
|
||||
if (key in option) {
|
||||
continue;
|
||||
}
|
||||
this.Status.Pop[key] = def[key];
|
||||
}
|
||||
if (option) {
|
||||
keys = Object.keys(option);
|
||||
for (let i = 0; i < keys.length; i++) {
|
||||
let key = keys[i];
|
||||
|
||||
this.Status.Pop[key] = option[key];
|
||||
}
|
||||
}
|
||||
|
||||
if (!option.borderColor) {
|
||||
option.borderColor = '#BBE600';
|
||||
option.buttonBgColor = '#BBE600';
|
||||
}
|
||||
these.Status.Pop.showPop = true;
|
||||
},
|
||||
|
||||
|
||||
showMsg(msg, isSucc) {
|
||||
if (isSucc) {
|
||||
MsgSuccess(msg,'',this);
|
||||
showPop: function(option) {
|
||||
hideLoading(this);
|
||||
let def = {
|
||||
showPop: true, //是否显示弹窗
|
||||
popType: 'custom',
|
||||
bgColor: '#383934bd',
|
||||
borderColor: '#BBE600',
|
||||
textColor: '#ffffffde',
|
||||
buttonBgColor: '#BBE600',
|
||||
buttonTextColor: '#232323DE',
|
||||
iconUrl: '',
|
||||
message: '',
|
||||
buttonText: '确定',
|
||||
clickEvt: '',
|
||||
visiblePrompt: false,
|
||||
promptTitle: '',
|
||||
modelValue: '',
|
||||
visibleClose: false,
|
||||
okCallback: null,
|
||||
showSlot: false,
|
||||
buttonCancelText: '',
|
||||
showCancel: false,
|
||||
}
|
||||
else{
|
||||
MsgError(msg,'',this);
|
||||
|
||||
let keys = Object.keys(def);
|
||||
|
||||
for (let i = 0; i < keys.length; i++) {
|
||||
let key = keys[i];
|
||||
if (key in option) {
|
||||
continue;
|
||||
}
|
||||
this.Status.Pop[key] = def[key];
|
||||
}
|
||||
if (option) {
|
||||
keys = Object.keys(option);
|
||||
for (let i = 0; i < keys.length; i++) {
|
||||
let key = keys[i];
|
||||
|
||||
this.Status.Pop[key] = option[key];
|
||||
}
|
||||
}
|
||||
|
||||
if (!option.borderColor) {
|
||||
option.borderColor = '#BBE600';
|
||||
option.buttonBgColor = '#BBE600';
|
||||
}
|
||||
these.Status.Pop.showPop = true;
|
||||
},
|
||||
|
||||
|
||||
showMsg(msg, isSucc) {
|
||||
if (isSucc) {
|
||||
MsgSuccess(msg, '', this);
|
||||
} else {
|
||||
MsgError(msg, '', this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1569,7 +1617,7 @@
|
||||
border-color: #aed600 !important;
|
||||
}
|
||||
|
||||
.lampMode .mode.active .bigTxt {
|
||||
.lampMode .mode.active .bigTxt,.lampMode .mode.active .smallTxt {
|
||||
|
||||
color: #aed600 !important;
|
||||
}
|
||||
@ -1724,7 +1772,7 @@
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
.slider-container {
|
||||
|
||||
@ -276,15 +276,19 @@
|
||||
import BleTool from '@/utils/BleHelper.js'
|
||||
import BleReceive from '@/utils/BleReceive';
|
||||
import MqttClient from '@/utils/mqtt.js';
|
||||
import lnglatConvert from '@/utils/wgs84_to_gcj02.js'
|
||||
import lnglatConvert from '@/utils/wgs84_to_gcj02.js';
|
||||
import SendBatchData from '@/utils/SendBatchData.js';
|
||||
var batchTool=null;
|
||||
var eventChannel = null;
|
||||
var these = null;
|
||||
var ble = null;
|
||||
|
||||
var recei = null;
|
||||
var mq = null;
|
||||
var pagePath = "pages/6075J/BJQ6075J";
|
||||
var brightnessTimer = null;
|
||||
var reGeoTime=null;
|
||||
|
||||
export default {
|
||||
components: {
|
||||
TextToHexV1
|
||||
@ -644,340 +648,15 @@
|
||||
|
||||
let f = this.getDevice();
|
||||
|
||||
let timeDelayCloseLoading = () => {
|
||||
setTimeout(() => {
|
||||
hideLoading(these);
|
||||
}, 1500);
|
||||
if(!f){
|
||||
this.showBleUnConnect();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
let sendVideoPackets = (ReSendNo) => {
|
||||
console.log("开始发送分片数据");
|
||||
return new Promise((resolve, reject) => {
|
||||
if (f) {
|
||||
// 总数据包数
|
||||
var totalPackets = 1536; //36;
|
||||
|
||||
let currentPacket = 1;
|
||||
console.log("发送数据准备中,总共" + totalPackets);
|
||||
if (ReSendNo) {
|
||||
totalPackets = ReSendNo;
|
||||
currentPacket = ReSendNo;
|
||||
}
|
||||
|
||||
// 发送单个数据包
|
||||
const sendNextVideoPacket = () => {
|
||||
// console.log("准备发送一段数据");
|
||||
if (currentPacket > totalPackets) {
|
||||
if (!ReSendNo) {
|
||||
setTimeout(() => {
|
||||
|
||||
ble.sendString(f.deviceId, "transmit complete", f
|
||||
.writeServiceId, f.wirteCharactId, 20)
|
||||
.then(
|
||||
() => {
|
||||
console.log("全部发送完毕")
|
||||
}).catch((ex) => {
|
||||
console.log("出现异常", ex);
|
||||
});
|
||||
}, 500);
|
||||
|
||||
}
|
||||
|
||||
hideLoading(these);
|
||||
showPop({
|
||||
showPop: true,
|
||||
message: "上传成功",
|
||||
iconUrl: "/static/images/common/success.png"
|
||||
}, these);
|
||||
these.videoHexArray = null;
|
||||
resolve();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// 计算当前包的数据
|
||||
let packetSize = 500;
|
||||
|
||||
|
||||
// 创建数据包
|
||||
const startIndex = (currentPacket - 1) * packetSize;
|
||||
const endIndex = Math.min(startIndex + packetSize, these.videoHexArray
|
||||
.length);
|
||||
if (startIndex > endIndex) {
|
||||
resolve();
|
||||
return;
|
||||
}
|
||||
////console.log("111111");
|
||||
const packetData = these.videoHexArray.slice(startIndex, endIndex);
|
||||
|
||||
// 构建数据包
|
||||
////console.log("packetData.length"+packetData.length);
|
||||
const bufferSize = 504; // 头部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);
|
||||
|
||||
for (let i = 0; i < packetData.length; i++) {
|
||||
dataView.setUint8(4 + i, '0x' + packetData[i]);
|
||||
}
|
||||
|
||||
let inteval = 60;
|
||||
|
||||
ble.sendData(f.deviceId, buffer, f.writeServiceId, f
|
||||
.wirteCharactId, 10).then(() => {
|
||||
|
||||
updateLoading(these, {
|
||||
text: "正在发送:" + currentPacket + "/" +
|
||||
totalPackets
|
||||
});
|
||||
|
||||
currentPacket++;
|
||||
|
||||
// console.log("发送一段成功,发送下一段");
|
||||
setTimeout(sendNextVideoPacket, inteval);
|
||||
}).catch(err => {
|
||||
console.log("发送失败了", err);
|
||||
if (err.code == '10007') { //遇到这个错误自动重新发送
|
||||
console.log(err.errMsg + ",发送失败了,正在补偿:" +
|
||||
currentPacket);
|
||||
setTimeout(sendNextVideoPacket, 800);
|
||||
} else {
|
||||
|
||||
hideLoading(these);
|
||||
|
||||
showPop({
|
||||
showPop: true,
|
||||
message: err.msg + ",发送失败了",
|
||||
borderColor: "#e034344d",
|
||||
buttonBgColor: "#E03434",
|
||||
buttonText: "确定",
|
||||
iconUrl: "/static/images/common/uploadErr.png"
|
||||
}, these);
|
||||
reject(err);
|
||||
these.videoHexArray = null;
|
||||
return;
|
||||
}
|
||||
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
sendNextVideoPacket();
|
||||
|
||||
|
||||
} else {
|
||||
console.log("Fail.......")
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
var sendVideo = (videoPath) => {
|
||||
let uploadVideo = () => {
|
||||
|
||||
these.videoHexArray = [];
|
||||
console.log("开始处理,正在上传");
|
||||
|
||||
showLoading(these, {
|
||||
text: "上传中"
|
||||
});
|
||||
let p1 = new Promise((resolve, reject) => {
|
||||
|
||||
ble.sendString(f.deviceId, "video transmit start", f
|
||||
.writeServiceId, f.wirteCharactId).then(res => {
|
||||
|
||||
setTimeout(() => {
|
||||
console.log("握手成功了");
|
||||
resolve(true);
|
||||
}, 2200)
|
||||
}).catch(ex => {
|
||||
reject(ex);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
let p2 = new Promise((succ, err) => {
|
||||
|
||||
const token = uni.getStorageSync('token');
|
||||
const clientid = uni.getStorageSync('clientID');
|
||||
if (!token) {
|
||||
err({
|
||||
code: 401,
|
||||
msg: "请先登陆后再试"
|
||||
});
|
||||
hideLoading(these);
|
||||
return;
|
||||
}
|
||||
console.log("baseURL=", baseURL);
|
||||
console.log("token", token);
|
||||
console.log("clientID", clientid);
|
||||
uni.uploadFile({
|
||||
// url: 'http://114.55.111.217/video/upload',
|
||||
url: baseURL + "/app/video/upload",
|
||||
filePath: videoPath,
|
||||
name: 'file',
|
||||
header: {
|
||||
"Method": "POST",
|
||||
"Content-Type": "multipart/form-data",
|
||||
"Authorization": 'Bearer ' + token,
|
||||
"clientid": clientid
|
||||
},
|
||||
timeout: 600000,
|
||||
fail: (ex) => {
|
||||
console.log("上传视频失败" + JSON.stringify(ex));
|
||||
|
||||
err(ex);
|
||||
},
|
||||
success: (res) => {
|
||||
|
||||
console.log("上传完成,向蓝牙设备发送");
|
||||
succ(res);
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
Promise.all([p1, p2]).then((arr) => {
|
||||
|
||||
if (arr[0].status == 'rejected') {
|
||||
MsgError("设备准备未就绪,请重试",'',these);
|
||||
return;
|
||||
}
|
||||
if(arr[1].status== 'rejected'){
|
||||
MsgError("读取视频失败",'',these);
|
||||
return;
|
||||
}
|
||||
let res = arr[1];
|
||||
// console.log("11111111111111111111111",res);
|
||||
res = JSON.parse(res.data);
|
||||
// console.log("22222222222222222222");
|
||||
if (res.data) {
|
||||
these.videoHexArray = res.data;
|
||||
updateLoading(these, {
|
||||
text: "正在发送:0/1536"
|
||||
});
|
||||
|
||||
|
||||
|
||||
shotVideoClick(res.data);
|
||||
|
||||
|
||||
} else {
|
||||
console.log("服务器未返回正确的数据");
|
||||
|
||||
|
||||
showPop({
|
||||
message: "与服务器连接出现异常,请检查网络设置",
|
||||
iconUrl: "/static/images/common/uploadErr.png",
|
||||
borderColor: "#e034344d",
|
||||
buttonBgColor: "#E03434",
|
||||
}, these);
|
||||
}
|
||||
|
||||
}).catch((ex) => {
|
||||
console.log("出现异常,", ex)
|
||||
hideLoading(these);
|
||||
showPop({
|
||||
message: "出现异常," + ex.msg,
|
||||
iconUrl: "/static/images/common/uploadErr.png",
|
||||
borderColor: "#e034344d",
|
||||
buttonBgColor: "#E03434",
|
||||
}, these);
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
let shotVideoClick = () => {
|
||||
console.log("正在开始发送");
|
||||
sendVideoPackets().then(() => {
|
||||
console.log("发送完成");
|
||||
|
||||
}).catch((ex1) => {
|
||||
//console.log("出现了异常", ex1)
|
||||
}).finally(() => {
|
||||
hideLoading(these);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
uploadVideo();
|
||||
|
||||
}
|
||||
|
||||
uni.chooseVideo({
|
||||
sourceType: ['album'],
|
||||
compressed: false, // 关闭视频压缩,确保上传原始文件
|
||||
success: function(res) {
|
||||
console.log("res=", res);
|
||||
let path = res.tempFilePath;
|
||||
// iOS可能返回浮点数,需要转换为整数进行比较
|
||||
let width = Math.round(res.width);
|
||||
let height = Math.round(res.height);
|
||||
let duration = res.duration;
|
||||
|
||||
// 获取平台信息
|
||||
const systemInfo = uni.getSystemInfoSync();
|
||||
const platform = systemInfo.platform;
|
||||
const isIOS = platform === 'ios';
|
||||
|
||||
console.log("平台:", platform, "uni.chooseVideo返回 - 宽度:", width, "高度:", height,
|
||||
"时长:", duration);
|
||||
|
||||
// iOS特殊处理:如果返回的是80*40,很可能是160*80的一半(iOS的bug)
|
||||
if (isIOS && width === 80 && height === 40) {
|
||||
console.log("检测到iOS特殊情况:返回80*40,实际应该是160*80,进行修正");
|
||||
width = 160;
|
||||
height = 80;
|
||||
}
|
||||
|
||||
// 检查分辨率是否符合要求
|
||||
let checkResolution = (w, h) => {
|
||||
// 使用容差比较,允许1像素的误差
|
||||
return Math.abs(w - 160) <= 1 && Math.abs(h - 80) <= 1;
|
||||
};
|
||||
|
||||
let err = [];
|
||||
if (duration < 2) {
|
||||
err.push("视频时长至少2秒");
|
||||
}
|
||||
|
||||
if (!checkResolution(width, height)) {
|
||||
err.push("视频宽高必须是160*80,当前分辨率:" + width + "*" + height);
|
||||
}
|
||||
|
||||
if (err.length > 0) {
|
||||
err = err.join(";");
|
||||
showPop({
|
||||
message: err,
|
||||
iconUrl: "/static/images/common/uploadErr.png",
|
||||
borderColor: "#e034344d",
|
||||
buttonBgColor: "#E03434",
|
||||
}, these);
|
||||
return;
|
||||
}
|
||||
|
||||
showLoading(these, {
|
||||
text: '正在上传'
|
||||
});
|
||||
setTimeout(() => {
|
||||
sendVideo(path);
|
||||
}, 0);
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
if(!batchTool){
|
||||
batchTool=new SendBatchData(these,f,ble);
|
||||
}
|
||||
batchTool.SendVideo(504);
|
||||
},
|
||||
sendImg() {
|
||||
if (!this.permissions.includes('3') && this.Status.apiType !== 'listA') {
|
||||
@ -987,179 +666,20 @@
|
||||
}
|
||||
|
||||
let f = this.getDevice();
|
||||
|
||||
|
||||
var sendImagePackets = function(ReSendNo) {
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
// 总数据包数
|
||||
let totalPackets = 52;
|
||||
let currentPacket = 1;
|
||||
|
||||
if (ReSendNo) {
|
||||
totalPackets = ReSendNo;
|
||||
currentPacket = ReSendNo;
|
||||
}
|
||||
|
||||
if (f) {
|
||||
// 发送单个数据包
|
||||
const sendNextPacket = () => {
|
||||
if (currentPacket > totalPackets) {
|
||||
hideLoading(these);
|
||||
these.closeAction();
|
||||
showPop({
|
||||
showPop: true,
|
||||
message: "上传成功",
|
||||
iconUrl: "/static/images/common/success.png",
|
||||
});
|
||||
|
||||
setTimeout(() => {
|
||||
ble.sendString(f.deviceId, "transmit complete", f
|
||||
.writeServiceId, f
|
||||
.wirteCharactId);
|
||||
}, 1000);
|
||||
|
||||
these.rgb565Data = null;
|
||||
resolve();
|
||||
return;
|
||||
}
|
||||
|
||||
// 计算当前包的数据
|
||||
let packetSize = 250;
|
||||
// if (currentPacket <= 51) {
|
||||
// packetSize = 250; // 前51个包每个500字节
|
||||
// } else {
|
||||
// packetSize = 50; // 最后一个包100字节
|
||||
// }
|
||||
|
||||
// 创建数据包
|
||||
const startIndex = (currentPacket - 1) * packetSize;
|
||||
const endIndex = Math.min(startIndex + packetSize, these.rgb565Data
|
||||
.length);
|
||||
if (startIndex > endIndex) {
|
||||
return;
|
||||
}
|
||||
const packetData = these.rgb565Data.slice(startIndex,
|
||||
endIndex);
|
||||
// 构建数据包
|
||||
const bufferSize = 505; // 5 + packetData.length * 2; // 头部5字节 + 数据部分
|
||||
const buffer = new ArrayBuffer(bufferSize);
|
||||
const dataView = new DataView(buffer);
|
||||
|
||||
// 填充头部
|
||||
dataView.setUint8(0, 0x55); // 帧头
|
||||
dataView.setUint8(1, 0x02); // 帧类型:开机画面
|
||||
dataView.setUint8(2, '0x' + currentPacket.toString(16).padStart(2,
|
||||
'0')); // 包序号
|
||||
|
||||
|
||||
dataView.setUint16(3, packetData.length*2,false); // 包t长度
|
||||
|
||||
// 填充数据(每个RGB565值占2字节)
|
||||
for (let i = 0; i < packetData.length; i++) {
|
||||
dataView.setUint16(5 + i * 2, packetData[i], false); // 大端字节序
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//发送数据包
|
||||
ble.sendData(f.deviceId, buffer, f.writeServiceId, f.wirteCharactId,
|
||||
10)
|
||||
.then(() => {
|
||||
|
||||
|
||||
updateLoading(these, {
|
||||
text: "正在发送:" + currentPacket + "/" +
|
||||
totalPackets
|
||||
})
|
||||
currentPacket++;
|
||||
|
||||
setTimeout(sendNextPacket, these.inteval);
|
||||
}).catch(err => {
|
||||
console.log("发送数据包失败了" + JSON.stringify(err));
|
||||
if (err.code == '10007') {
|
||||
setTimeout(sendNextPacket, these.inteval);
|
||||
return;
|
||||
}
|
||||
these.closeAction();
|
||||
showPop({
|
||||
message: err.msg,
|
||||
iconUrl: "/static/images/common/uploadErr.png",
|
||||
borderColor: "#e034344d",
|
||||
buttonBgColor: "#E03434",
|
||||
});
|
||||
hideLoading(these);
|
||||
these.rgb565Data = null;
|
||||
reject(err);
|
||||
});
|
||||
}
|
||||
|
||||
if (ReSendNo) {
|
||||
sendNextPacket(ReSendNo);
|
||||
return;
|
||||
}
|
||||
// 开始牵手
|
||||
ble.sendString(f.deviceId, "picture transmit start", f.writeServiceId,
|
||||
f.wirteCharactId).then(() => {
|
||||
setTimeout(sendNextPacket, 120);
|
||||
|
||||
}).catch((err) => {
|
||||
console.log("握手没有成功");
|
||||
showPop({
|
||||
message: err.msg,
|
||||
iconUrl: "/static/images/common/uploadErr.png",
|
||||
borderColor: "#e034344d",
|
||||
buttonBgColor: "#E03434",
|
||||
});
|
||||
hideLoading(these);
|
||||
reject(err);
|
||||
});
|
||||
}
|
||||
});
|
||||
if(!f){
|
||||
this.showBleUnConnect();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
uni.chooseImage({
|
||||
count: 1,
|
||||
sizeType: ['original', 'compressed'],
|
||||
sourceType: ['album','camera'],
|
||||
success: function(res) {
|
||||
uni.navigateTo({
|
||||
url: "/pages/common/ImgCrop/ImgCrop",
|
||||
events: {
|
||||
ImgCutOver: function(data) {
|
||||
|
||||
showLoading(these, {
|
||||
text: "正在发送0/52"
|
||||
});
|
||||
|
||||
|
||||
these.rgb565Data = Common.convertToRGB565(data.piexls);
|
||||
|
||||
setTimeout(function() {
|
||||
sendImagePackets().catch(() => {
|
||||
|
||||
});
|
||||
}, 0)
|
||||
|
||||
}
|
||||
},
|
||||
success(ev) {
|
||||
ev.eventChannel.emit('checkImg', {
|
||||
data: res.tempFiles[0].path
|
||||
})
|
||||
},
|
||||
fail(ex) {
|
||||
console.log("跳转页面失败" + JSON.stringify(ex));
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
if(!batchTool){
|
||||
batchTool=new SendBatchData(these,f,ble);
|
||||
}
|
||||
|
||||
|
||||
batchTool.SendImg();
|
||||
|
||||
return ;
|
||||
|
||||
},
|
||||
sliderChanging(e) {
|
||||
this.formData.sta_brightness = e.detail.value;
|
||||
@ -1508,152 +1028,10 @@
|
||||
}
|
||||
|
||||
|
||||
let toByteValue = (value) => {
|
||||
if (typeof value === 'number') {
|
||||
return value;
|
||||
}
|
||||
if (typeof value === 'string') {
|
||||
if (value.startsWith('0x') || value.startsWith('0X')) {
|
||||
return parseInt(value, 16);
|
||||
}
|
||||
return parseInt(`0x${value}`, 16);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
this.formData.textLines = [this.formData.company, this.formData.usrname, this.formData.job];
|
||||
console.log("data=", this.formData.textLines);
|
||||
showLoading(these, {
|
||||
text: "发送中"
|
||||
});
|
||||
//握手
|
||||
let holdHand = (hexs, time) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
|
||||
this.sendData(hexs, 'ble', "string").then(res => {
|
||||
setTimeout(() => {
|
||||
resolve(res)
|
||||
}, time);
|
||||
|
||||
}).catch(ex => {
|
||||
reject(ex)
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
//画图
|
||||
let drawText = () => {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.$refs.textToHex.drawAndGetPixels().then(allPixels => {
|
||||
if (!allPixels) {
|
||||
reject("文本初始化失败");
|
||||
return;
|
||||
}
|
||||
console.log("画图成功");
|
||||
resolve(allPixels);
|
||||
}).catch(compEx => {
|
||||
reject(compEx);
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
//发送3个分包的数据
|
||||
let task = (allPixels) => {
|
||||
try {
|
||||
let combinedData = [];
|
||||
for (let i = 0; i < 4; i++) {
|
||||
let linePixels = (allPixels[i] || []).flat(Infinity).map(item =>
|
||||
typeof item === 'string' ? toByteValue(item) : item
|
||||
);
|
||||
|
||||
for (var j = linePixels.length; j < 256; j++) {
|
||||
linePixels.push(0x00);
|
||||
}
|
||||
linePixels = [0xFA, 0x06, 0x03, i + 1].concat(linePixels);
|
||||
|
||||
linePixels.push(0xFF)
|
||||
|
||||
combinedData.push(linePixels);
|
||||
}
|
||||
|
||||
|
||||
let curr = 1;
|
||||
let len = combinedData.length;
|
||||
|
||||
|
||||
|
||||
//分包发送
|
||||
let sendPacket = () => {
|
||||
|
||||
if (combinedData.length === curr - 1) {
|
||||
setTimeout(()=>{
|
||||
holdHand('transmit complete', 200).then(res => {
|
||||
MsgSuccess("人员信息发送成功", "确定", these);
|
||||
hideLoading(these);
|
||||
this.setBleFormData();
|
||||
});
|
||||
},300);
|
||||
|
||||
hideLoading();
|
||||
return;
|
||||
}
|
||||
|
||||
let array = combinedData[curr - 1];
|
||||
|
||||
|
||||
console.log("array=", array);
|
||||
ble.sendHexs(f.deviceId, array, null, null, 15).then(
|
||||
res => {
|
||||
curr++;
|
||||
console.log("发送成功", curr);
|
||||
updateLoading(these, {
|
||||
text: '发送中,' + (curr - 1) + '/' + combinedData.length
|
||||
})
|
||||
setTimeout(sendPacket, 250);
|
||||
}).catch(err => {
|
||||
console.err("发送失败", err);
|
||||
if (err.code == '10007') {
|
||||
setTimeout(sendPacket, 250);
|
||||
} else {
|
||||
console.log("err:", err);
|
||||
MsgError('发送失败' + (err.msg || err.code), '确定', these);
|
||||
hideLoading();
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
setTimeout(sendPacket, 0);
|
||||
// 5. 发送成功处理
|
||||
|
||||
|
||||
} catch (ex) {
|
||||
MsgError('发送失败' + (ex.msg || ex.code), '确定', these);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
setTimeout(() => {
|
||||
Promise.allSettled([holdHand('word transmit start', 2200), drawText()]).then(results => {
|
||||
if (results[0].status == 'rejected') {
|
||||
MsgError("与蓝牙设备握手失败,请重试",'',these);
|
||||
setTimeout(() => {
|
||||
hideLoading(these)
|
||||
}, 500);
|
||||
return;
|
||||
}
|
||||
if (results[1].status == 'rejected') {
|
||||
MsgError("读取文字点阵失败,请重试",'',these);
|
||||
return;
|
||||
}
|
||||
|
||||
task(results[1].value);
|
||||
})
|
||||
|
||||
}, 0);
|
||||
if(!batchTool){
|
||||
batchTool=new SendBatchData(these,f,ble);
|
||||
}
|
||||
batchTool.SendUsr(3);
|
||||
},
|
||||
sendMsg() {
|
||||
debugger;
|
||||
@ -2038,6 +1416,8 @@
|
||||
}
|
||||
if (res.deviceId == these.formData.deviceId) {
|
||||
this.formData.bleStatu = true;
|
||||
|
||||
batchTool=new SendBatchData(this,res,ble);
|
||||
setTimeout(() => {
|
||||
hideLoading(these, 1000);
|
||||
});
|
||||
@ -2053,6 +1433,7 @@
|
||||
// return;
|
||||
// }
|
||||
if (res.deviceId == these.formData.deviceId) {
|
||||
batchTool=null;
|
||||
if (res.device) {
|
||||
these.formData.bleStatu = 'connecting';
|
||||
} else {
|
||||
|
||||
@ -113,7 +113,7 @@
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="mode marginLeft fleft" :class="formData.cMode=='mode'?'':'active'"
|
||||
<view class="mode marginLeft fleft"
|
||||
v-on:click.stop="ShowUpload()">
|
||||
<view class="leftImg">
|
||||
<image class="img" src="/static/images/6155/DeviceDetail/open.png" mode="aspectFit"></image>
|
||||
@ -166,13 +166,6 @@
|
||||
<!-- 下方菜单 -->
|
||||
<BottomSlideMenuPlus :config="Status.BottomMenu" @close="closeMenu" @itemClick="handleItemClick"
|
||||
@btnClick="btnClick">
|
||||
<view>
|
||||
<view class="addIco">
|
||||
<view class="icoContent center" v-on:click.stop="checkImgUpload()">
|
||||
<image mode="aspectFit" class="img" src="/static/images/6155/DeviceDetail/add.png"></image>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</BottomSlideMenuPlus>
|
||||
|
||||
<global-loading ref="loading" />
|
||||
@ -202,7 +195,8 @@ import request, { baseURL } from '@/utils/request.js';
|
||||
MsgInfo
|
||||
} from '@/utils/MsgPops.js'
|
||||
const pagePath = "/pages/650/HBY650";
|
||||
|
||||
import SendBatchData from '@/utils/SendBatchData.js';
|
||||
var batchTool=null;
|
||||
var ble = null;
|
||||
var these = null;
|
||||
var recei = null;
|
||||
@ -226,16 +220,12 @@ import request, { baseURL } from '@/utils/request.js';
|
||||
show: false,
|
||||
showHeader: true,
|
||||
menuItems: [{
|
||||
text: '强光',
|
||||
icon: '/static/images/lightImg/qiang.png'
|
||||
text: '照片',
|
||||
value:'img'
|
||||
},
|
||||
{
|
||||
text: '弱光',
|
||||
icon: '/static/images/lightImg/ruo.png'
|
||||
},
|
||||
{
|
||||
text: '爆闪',
|
||||
icon: '/static/images/lightImg/shan.png'
|
||||
text: '动画',
|
||||
value:'flash'
|
||||
}
|
||||
],
|
||||
activeIndex: -1,
|
||||
@ -864,8 +854,31 @@ import request, { baseURL } from '@/utils/request.js';
|
||||
},
|
||||
|
||||
checkImgUpload: function(type, index) {
|
||||
console.log("123213213213");
|
||||
let f = these.getDevice();
|
||||
if(!f){
|
||||
this.showBleUnConnect();
|
||||
return;
|
||||
}
|
||||
|
||||
if(!batchTool){
|
||||
batchTool=new SendBatchData(these,f,ble);
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (type) {
|
||||
if (type == 'img') {
|
||||
// sendImagePackets(index);
|
||||
batchTool.SendImg();
|
||||
} else{
|
||||
// sendVideoPackets(index);
|
||||
batchTool.SendVideo(506);
|
||||
}
|
||||
|
||||
}
|
||||
return;
|
||||
console.log("123213213213");
|
||||
|
||||
// 分包发送图片数据
|
||||
var sendImagePackets = function(ReSendNo) {
|
||||
|
||||
@ -1337,12 +1350,11 @@ import request, { baseURL } from '@/utils/request.js';
|
||||
},these)
|
||||
return;
|
||||
}
|
||||
//上传开机画面
|
||||
this.Status.BottomMenu.menuItems = [];
|
||||
//上传开机画面
|
||||
this.Status.BottomMenu.title = "上传开机画面";
|
||||
this.Status.BottomMenu.type = "checkImg";
|
||||
this.Status.BottomMenu.show = true;
|
||||
this.formData.cMode = "img";
|
||||
this.Status.BottomMenu.activeIndex=0;
|
||||
},
|
||||
|
||||
showMenu(flag) {
|
||||
@ -1352,8 +1364,8 @@ import request, { baseURL } from '@/utils/request.js';
|
||||
this.Status.BottomMenu.show = false;
|
||||
},
|
||||
btnClick(item, index) {
|
||||
|
||||
|
||||
this.Status.BottomMenu.show = false;
|
||||
this.checkImgUpload(item.value,index);
|
||||
|
||||
|
||||
},
|
||||
@ -1365,14 +1377,7 @@ import request, { baseURL } from '@/utils/request.js';
|
||||
},
|
||||
handleItemClick(item, index) {
|
||||
|
||||
switch (this.Status.BottomMenu.type) {
|
||||
case "main":
|
||||
|
||||
break;
|
||||
case "fu":
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
this.Status.BottomMenu.activeIndex = index;
|
||||
|
||||
},
|
||||
|
||||
@ -258,13 +258,7 @@
|
||||
<!-- 下方菜单 -->
|
||||
<BottomSlideMenuPlus :config="Status.BottomMenu" @close="closeMenu" @itemClick="handleItemClick"
|
||||
@btnClick="btnClick">
|
||||
<view>
|
||||
<view class="addIco">
|
||||
<view class="icoContent center" v-on:click.stop="checkImgUpload()">
|
||||
<image mode="aspectFit" class="img" src="/static/images/6155/DeviceDetail/add.png"></image>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
</BottomSlideMenuPlus>
|
||||
|
||||
<!-- 弹窗通知 -->
|
||||
@ -304,6 +298,8 @@
|
||||
MsgInfo
|
||||
} from '@/utils/MsgPops.js'
|
||||
const pagePath = "/pages/670/HBY670";
|
||||
import SendBatchData from '@/utils/SendBatchData.js';
|
||||
var batchTool=null;
|
||||
var ble = null;
|
||||
var these = null;
|
||||
var recei = null;
|
||||
@ -358,16 +354,12 @@
|
||||
show: false,
|
||||
showHeader: true,
|
||||
menuItems: [{
|
||||
text: '强光',
|
||||
icon: '/static/images/lightImg/qiang.png'
|
||||
text: '照片',
|
||||
value:'img'
|
||||
},
|
||||
{
|
||||
text: '弱光',
|
||||
icon: '/static/images/lightImg/ruo.png'
|
||||
},
|
||||
{
|
||||
text: '爆闪',
|
||||
icon: '/static/images/lightImg/shan.png'
|
||||
text: '动画',
|
||||
value:'flash'
|
||||
}
|
||||
],
|
||||
activeIndex: -1,
|
||||
@ -1694,7 +1686,26 @@
|
||||
checkImgUpload: function(type, index) {
|
||||
console.log("123213213213");
|
||||
let f = these.getDevice();
|
||||
|
||||
if(!f){
|
||||
this.showBleUnConnect();
|
||||
return;
|
||||
}
|
||||
|
||||
if(!batchTool){
|
||||
batchTool=new SendBatchData(these,f,ble);
|
||||
}
|
||||
|
||||
if (type) {
|
||||
if (type == 'img') {
|
||||
// sendImagePackets(index);
|
||||
batchTool.SendImg();
|
||||
} else {
|
||||
// sendVideoPackets(index);
|
||||
batchTool.SendVideo(506);
|
||||
}
|
||||
|
||||
}
|
||||
return;
|
||||
var sendImgByRequest = () => {
|
||||
return new Promise((resolve, reject) => {
|
||||
api.sendPic({
|
||||
@ -2208,11 +2219,12 @@
|
||||
return;
|
||||
}
|
||||
//上传开机画面
|
||||
this.Status.BottomMenu.menuItems = [];
|
||||
|
||||
this.Status.BottomMenu.title = "上传开机画面";
|
||||
this.Status.BottomMenu.type = "checkImg";
|
||||
this.Status.BottomMenu.show = true;
|
||||
this.Status.BottomMenu.showBtn = false;
|
||||
this.Status.BottomMenu.showBtn = true;
|
||||
this.Status.BottomMenu.activeIndex=0;
|
||||
},
|
||||
|
||||
showMenu(flag) {
|
||||
@ -2222,10 +2234,8 @@
|
||||
this.Status.BottomMenu.show = false;
|
||||
},
|
||||
btnClick(item, index) {
|
||||
|
||||
|
||||
|
||||
|
||||
this.Status.BottomMenu.show = false;
|
||||
this.checkImgUpload(item.value,index);
|
||||
},
|
||||
setMode(mode) {
|
||||
|
||||
|
||||
@ -272,7 +272,7 @@
|
||||
}
|
||||
console.log("处理蓝牙不可用");
|
||||
hideLoading(these);
|
||||
console.error("1111111111")
|
||||
|
||||
these.PairEquip = [];
|
||||
these.EquipMents = [];
|
||||
uni.showToast({
|
||||
@ -285,13 +285,15 @@
|
||||
|
||||
//蓝牙恢复可用的回调
|
||||
ble.addStateRecoveryCallback(res => {
|
||||
console.log("蓝牙恢复可用");
|
||||
these.Status.BottomMenu.show = false;
|
||||
these.PairEquip = [];
|
||||
these.EquipMents = [];
|
||||
|
||||
if (these.Status.isPageHidden) {
|
||||
return;
|
||||
}
|
||||
these.Status.BottomMenu.show = false;
|
||||
console.error("1111111111")
|
||||
these.PairEquip = [];
|
||||
these.EquipMents = [];
|
||||
|
||||
uni.showToast({
|
||||
icon: 'fail',
|
||||
title: '蓝牙恢复可用'
|
||||
|
||||
@ -871,7 +871,7 @@ class BleHelper {
|
||||
if (!state.available) { //蓝牙状态不可用了,将所有设备标记为断开连接
|
||||
// 系统关蓝牙后原生 BLE 适配器已销毁;若仍认为 isOpenBlue=true,OpenBlue 会跳过重开,
|
||||
// 再开蓝牙后无法 createBLEConnection / 一直报 10001 适配器不可用
|
||||
this.data.isOpenBlue = false;
|
||||
// this.data.isOpenBlue = false;
|
||||
console.log("蓝牙模块不可用了,将所有设备标记为断开连接");
|
||||
this.data.connectingDevices = {}; //清空连接锁
|
||||
this.data.LinkedList.filter((v) => {
|
||||
|
||||
@ -1,68 +1,70 @@
|
||||
import request, {
|
||||
baseURL
|
||||
} from '@/utils/request.js';
|
||||
import {
|
||||
showLoading,
|
||||
hideLoading,
|
||||
updateLoading
|
||||
} from '@/utils/loading.js';
|
||||
baseURL
|
||||
} from '@/utils/request.js';
|
||||
import {
|
||||
showLoading,
|
||||
hideLoading,
|
||||
updateLoading
|
||||
} from '@/utils/loading.js';
|
||||
|
||||
import {
|
||||
MsgSuccess,
|
||||
MsgError,
|
||||
MsgClose,
|
||||
MsgWarning,
|
||||
showPop
|
||||
} from '@/utils/MsgPops.js';
|
||||
import Common from '@/utils/Common.js';
|
||||
|
||||
import {
|
||||
MsgSuccess,
|
||||
MsgError,
|
||||
MsgClose,
|
||||
MsgWarning,
|
||||
showPop
|
||||
} from '@/utils/MsgPops.js';
|
||||
import Common from '@/utils/Common.js';
|
||||
|
||||
class SendBatchData{
|
||||
|
||||
constructor(_these,_f,_ble){
|
||||
this.videoHexArray=[];
|
||||
this.rgb565Data=[];
|
||||
this.these=_these;
|
||||
this.f=_f;
|
||||
this.ble=_ble;
|
||||
|
||||
class SendBatchData {
|
||||
|
||||
constructor(_these, _f, _ble) {
|
||||
this.videoHexArray = [];
|
||||
this.rgb565Data = [];
|
||||
this.these = _these;
|
||||
this.f = _f;
|
||||
this.ble = _ble;
|
||||
}
|
||||
|
||||
|
||||
SendVideo(){
|
||||
|
||||
let these=this.these;
|
||||
let f=this.f;
|
||||
let ble=this.ble;
|
||||
|
||||
|
||||
//发送开机视频
|
||||
SendVideo(bufferSize) {
|
||||
|
||||
let these = this.these;
|
||||
let f = this.f;
|
||||
let ble = this.ble;
|
||||
if (!bufferSize) {
|
||||
bufferSize = 504;
|
||||
}
|
||||
let timeDelayCloseLoading = () => {
|
||||
setTimeout(() => {
|
||||
hideLoading(these);
|
||||
}, 1500);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
let sendVideoPackets = (ReSendNo) => {
|
||||
console.log("开始发送分片数据");
|
||||
return new Promise((resolve, reject) => {
|
||||
if (f) {
|
||||
// 总数据包数
|
||||
var totalPackets = 1536; //36;
|
||||
|
||||
|
||||
let currentPacket = 1;
|
||||
console.log("发送数据准备中,总共" + totalPackets);
|
||||
if (ReSendNo) {
|
||||
totalPackets = ReSendNo;
|
||||
currentPacket = ReSendNo;
|
||||
}
|
||||
|
||||
|
||||
// 发送单个数据包
|
||||
const sendNextVideoPacket = () => {
|
||||
// console.log("准备发送一段数据");
|
||||
if (currentPacket > totalPackets) {
|
||||
if (!ReSendNo) {
|
||||
setTimeout(() => {
|
||||
|
||||
|
||||
ble.sendString(f.deviceId, "transmit complete", f
|
||||
.writeServiceId, f.wirteCharactId, 20)
|
||||
.then(
|
||||
@ -72,9 +74,9 @@ class SendBatchData{
|
||||
console.log("出现异常", ex);
|
||||
});
|
||||
}, 500);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
hideLoading(these);
|
||||
showPop({
|
||||
showPop: true,
|
||||
@ -83,14 +85,14 @@ class SendBatchData{
|
||||
}, these);
|
||||
these.videoHexArray = null;
|
||||
resolve();
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// 计算当前包的数据
|
||||
let packetSize = 500;
|
||||
|
||||
|
||||
|
||||
|
||||
// 创建数据包
|
||||
const startIndex = (currentPacket - 1) * packetSize;
|
||||
const endIndex = Math.min(startIndex + packetSize, these.videoHexArray
|
||||
@ -101,40 +103,43 @@ class SendBatchData{
|
||||
}
|
||||
////console.log("111111");
|
||||
const packetData = these.videoHexArray.slice(startIndex, endIndex);
|
||||
|
||||
|
||||
// 构建数据包
|
||||
////console.log("packetData.length"+packetData.length);
|
||||
const bufferSize = 504; // 头部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);
|
||||
|
||||
for (let i = 0; i < packetData.length; i++) {
|
||||
dataView.setUint8(4 + i, '0x' + packetData[i]);
|
||||
dataView.setUint16(2, currentPacket, false); // 包序号
|
||||
let beginIndex = 4;
|
||||
if (bufferSize == 506) {
|
||||
beginIndex = 6;
|
||||
dataView.setUint16(4, packetSize, false); //数据长度
|
||||
}
|
||||
|
||||
let inteval = 60;
|
||||
|
||||
|
||||
|
||||
|
||||
for (let i = 0; i < packetData.length; i++) {
|
||||
dataView.setUint8(beginIndex + i, packetData[i]);
|
||||
}
|
||||
|
||||
let inteval = 80;
|
||||
|
||||
ble.sendData(f.deviceId, buffer, f.writeServiceId, f
|
||||
.wirteCharactId, 10).then(() => {
|
||||
|
||||
|
||||
updateLoading(these, {
|
||||
text: "正在发送:" + currentPacket + "/" +
|
||||
totalPackets
|
||||
});
|
||||
|
||||
|
||||
currentPacket++;
|
||||
|
||||
|
||||
// console.log("发送一段成功,发送下一段");
|
||||
setTimeout(sendNextVideoPacket, inteval);
|
||||
}).catch(err => {
|
||||
@ -144,9 +149,9 @@ class SendBatchData{
|
||||
currentPacket);
|
||||
setTimeout(sendNextVideoPacket, 800);
|
||||
} else {
|
||||
|
||||
|
||||
hideLoading(these);
|
||||
|
||||
|
||||
showPop({
|
||||
showPop: true,
|
||||
message: err.msg + ",发送失败了",
|
||||
@ -159,34 +164,34 @@ class SendBatchData{
|
||||
these.videoHexArray = null;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
sendNextVideoPacket();
|
||||
|
||||
|
||||
|
||||
|
||||
} else {
|
||||
console.log("Fail.......")
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
var sendVideo = (videoPath) => {
|
||||
let uploadVideo = () => {
|
||||
|
||||
|
||||
these.videoHexArray = [];
|
||||
console.log("开始处理,正在上传");
|
||||
|
||||
|
||||
showLoading(these, {
|
||||
text: "上传中"
|
||||
});
|
||||
let p1 = new Promise((resolve, reject) => {
|
||||
|
||||
|
||||
ble.sendString(f.deviceId, "video transmit start", f
|
||||
.writeServiceId, f.wirteCharactId).then(res => {
|
||||
|
||||
|
||||
setTimeout(() => {
|
||||
console.log("握手成功了");
|
||||
resolve(true);
|
||||
@ -195,10 +200,10 @@ class SendBatchData{
|
||||
reject(ex);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
let p2 = new Promise((succ, err) => {
|
||||
|
||||
|
||||
const token = uni.getStorageSync('token');
|
||||
const clientid = uni.getStorageSync('clientID');
|
||||
if (!token) {
|
||||
@ -226,26 +231,26 @@ class SendBatchData{
|
||||
timeout: 600000,
|
||||
fail: (ex) => {
|
||||
console.log("上传视频失败" + JSON.stringify(ex));
|
||||
|
||||
|
||||
err(ex);
|
||||
},
|
||||
success: (res) => {
|
||||
|
||||
|
||||
console.log("上传完成,向蓝牙设备发送");
|
||||
succ(res);
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Promise.all([p1, p2]).then((arr) => {
|
||||
|
||||
if (arr[0].status == 'rejected') {
|
||||
MsgError("设备准备未就绪,请重试",'',these);
|
||||
|
||||
if (arr[0].status == 'rejected') {
|
||||
MsgError("设备准备未就绪,请重试", '', these);
|
||||
return;
|
||||
}
|
||||
if(arr[1].status== 'rejected'){
|
||||
MsgError("读取视频失败",'',these);
|
||||
if (arr[1].status == 'rejected') {
|
||||
MsgError("读取视频失败", '', these);
|
||||
return;
|
||||
}
|
||||
let res = arr[1];
|
||||
@ -257,16 +262,16 @@ class SendBatchData{
|
||||
updateLoading(these, {
|
||||
text: "正在发送:0/1536"
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
shotVideoClick(res.data);
|
||||
|
||||
|
||||
|
||||
|
||||
} else {
|
||||
console.log("服务器未返回正确的数据");
|
||||
|
||||
|
||||
|
||||
|
||||
showPop({
|
||||
message: "与服务器连接出现异常,请检查网络设置",
|
||||
iconUrl: "/static/images/common/uploadErr.png",
|
||||
@ -274,7 +279,7 @@ class SendBatchData{
|
||||
buttonBgColor: "#E03434",
|
||||
}, these);
|
||||
}
|
||||
|
||||
|
||||
}).catch((ex) => {
|
||||
console.log("出现异常,", ex)
|
||||
hideLoading(these);
|
||||
@ -286,27 +291,27 @@ class SendBatchData{
|
||||
}, these);
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
let shotVideoClick = () => {
|
||||
console.log("正在开始发送");
|
||||
sendVideoPackets().then(() => {
|
||||
console.log("发送完成");
|
||||
|
||||
|
||||
}).catch((ex1) => {
|
||||
//console.log("出现了异常", ex1)
|
||||
}).finally(() => {
|
||||
hideLoading(these);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
uploadVideo();
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
uni.chooseVideo({
|
||||
sourceType: ['album'],
|
||||
compressed: false, // 关闭视频压缩,确保上传原始文件
|
||||
@ -317,37 +322,37 @@ class SendBatchData{
|
||||
let width = Math.round(res.width);
|
||||
let height = Math.round(res.height);
|
||||
let duration = res.duration;
|
||||
|
||||
|
||||
// 获取平台信息
|
||||
const systemInfo = uni.getSystemInfoSync();
|
||||
const platform = systemInfo.platform;
|
||||
const isIOS = platform === 'ios';
|
||||
|
||||
|
||||
console.log("平台:", platform, "uni.chooseVideo返回 - 宽度:", width, "高度:", height,
|
||||
"时长:", duration);
|
||||
|
||||
|
||||
// iOS特殊处理:如果返回的是80*40,很可能是160*80的一半(iOS的bug)
|
||||
if (isIOS && width === 80 && height === 40) {
|
||||
console.log("检测到iOS特殊情况:返回80*40,实际应该是160*80,进行修正");
|
||||
width = 160;
|
||||
height = 80;
|
||||
}
|
||||
|
||||
|
||||
// 检查分辨率是否符合要求
|
||||
let checkResolution = (w, h) => {
|
||||
// 使用容差比较,允许1像素的误差
|
||||
return Math.abs(w - 160) <= 1 && Math.abs(h - 80) <= 1;
|
||||
};
|
||||
|
||||
|
||||
let err = [];
|
||||
if (duration < 2) {
|
||||
err.push("视频时长至少2秒");
|
||||
}
|
||||
|
||||
|
||||
if (!checkResolution(width, height)) {
|
||||
err.push("视频宽高必须是160*80,当前分辨率:" + width + "*" + height);
|
||||
}
|
||||
|
||||
|
||||
if (err.length > 0) {
|
||||
err = err.join(";");
|
||||
showPop({
|
||||
@ -358,59 +363,65 @@ class SendBatchData{
|
||||
}, these);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
showLoading(these, {
|
||||
text: '正在上传'
|
||||
});
|
||||
setTimeout(() => {
|
||||
sendVideo(path);
|
||||
}, 0);
|
||||
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
SendImg(){
|
||||
let these=this.these;
|
||||
let f=this.f;
|
||||
let ble=this.ble;
|
||||
|
||||
|
||||
|
||||
//发送图片,
|
||||
SendImg() {
|
||||
let these = this.these;
|
||||
let f = this.f;
|
||||
let ble = this.ble;
|
||||
|
||||
var sendImagePackets = function(ReSendNo) {
|
||||
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
|
||||
// 总数据包数
|
||||
let totalPackets = 52;
|
||||
let currentPacket = 1;
|
||||
|
||||
|
||||
if (ReSendNo) {
|
||||
totalPackets = ReSendNo;
|
||||
currentPacket = ReSendNo;
|
||||
}
|
||||
|
||||
|
||||
if (f) {
|
||||
// 发送单个数据包
|
||||
const sendNextPacket = () => {
|
||||
if (currentPacket > totalPackets) {
|
||||
hideLoading(these);
|
||||
these.closeAction();
|
||||
if (these.closeAction) {
|
||||
these.closeAction();
|
||||
}
|
||||
|
||||
|
||||
showPop({
|
||||
showPop: true,
|
||||
message: "上传成功",
|
||||
iconUrl: "/static/images/common/success.png",
|
||||
});
|
||||
|
||||
}, these);
|
||||
|
||||
setTimeout(() => {
|
||||
ble.sendString(f.deviceId, "transmit complete", f
|
||||
.writeServiceId, f
|
||||
.wirteCharactId);
|
||||
}, 1000);
|
||||
|
||||
|
||||
these.rgb565Data = null;
|
||||
resolve();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// 计算当前包的数据
|
||||
let packetSize = 250;
|
||||
// if (currentPacket <= 51) {
|
||||
@ -418,7 +429,7 @@ class SendBatchData{
|
||||
// } else {
|
||||
// packetSize = 50; // 最后一个包100字节
|
||||
// }
|
||||
|
||||
|
||||
// 创建数据包
|
||||
const startIndex = (currentPacket - 1) * packetSize;
|
||||
const endIndex = Math.min(startIndex + packetSize, these.rgb565Data
|
||||
@ -432,57 +443,54 @@ class SendBatchData{
|
||||
const bufferSize = 505; // 5 + packetData.length * 2; // 头部5字节 + 数据部分
|
||||
const buffer = new ArrayBuffer(bufferSize);
|
||||
const dataView = new DataView(buffer);
|
||||
|
||||
|
||||
// 填充头部
|
||||
dataView.setUint8(0, 0x55); // 帧头
|
||||
dataView.setUint8(1, 0x02); // 帧类型:开机画面
|
||||
dataView.setUint8(2, '0x' + currentPacket.toString(16).padStart(2,
|
||||
'0')); // 包序号
|
||||
|
||||
|
||||
dataView.setUint16(3, packetData.length*2,false); // 包t长度
|
||||
|
||||
dataView.setUint8(2, currentPacket); // 包序号
|
||||
|
||||
|
||||
dataView.setUint16(3, packetData.length * 2, false); // 包t长度
|
||||
|
||||
// 填充数据(每个RGB565值占2字节)
|
||||
for (let i = 0; i < packetData.length; i++) {
|
||||
dataView.setUint16(5 + i * 2, packetData[i], false); // 大端字节序
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//发送数据包
|
||||
ble.sendData(f.deviceId, buffer, f.writeServiceId, f.wirteCharactId,
|
||||
10)
|
||||
.then(() => {
|
||||
|
||||
|
||||
|
||||
|
||||
updateLoading(these, {
|
||||
text: "正在发送:" + currentPacket + "/" +
|
||||
totalPackets
|
||||
})
|
||||
currentPacket++;
|
||||
|
||||
setTimeout(sendNextPacket, these.inteval);
|
||||
|
||||
setTimeout(sendNextPacket, these.inteval ? these.inteval : 80);
|
||||
}).catch(err => {
|
||||
console.log("发送数据包失败了" + JSON.stringify(err));
|
||||
if (err.code == '10007') {
|
||||
setTimeout(sendNextPacket, these.inteval);
|
||||
setTimeout(sendNextPacket, 800);
|
||||
return;
|
||||
}
|
||||
these.closeAction();
|
||||
if (these.closeAction) {
|
||||
these.closeAction();
|
||||
}
|
||||
showPop({
|
||||
message: err.msg,
|
||||
iconUrl: "/static/images/common/uploadErr.png",
|
||||
borderColor: "#e034344d",
|
||||
buttonBgColor: "#E03434",
|
||||
});
|
||||
}, these);
|
||||
hideLoading(these);
|
||||
these.rgb565Data = null;
|
||||
reject(err);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
if (ReSendNo) {
|
||||
sendNextPacket(ReSendNo);
|
||||
return;
|
||||
@ -491,7 +499,7 @@ class SendBatchData{
|
||||
ble.sendString(f.deviceId, "picture transmit start", f.writeServiceId,
|
||||
f.wirteCharactId).then(() => {
|
||||
setTimeout(sendNextPacket, 120);
|
||||
|
||||
|
||||
}).catch((err) => {
|
||||
console.log("握手没有成功");
|
||||
showPop({
|
||||
@ -499,38 +507,38 @@ class SendBatchData{
|
||||
iconUrl: "/static/images/common/uploadErr.png",
|
||||
borderColor: "#e034344d",
|
||||
buttonBgColor: "#E03434",
|
||||
});
|
||||
}, these);
|
||||
hideLoading(these);
|
||||
reject(err);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
uni.chooseImage({
|
||||
count: 1,
|
||||
sizeType: ['original', 'compressed'],
|
||||
sourceType: ['album','camera'],
|
||||
sourceType: ['album', 'camera'],
|
||||
success: function(res) {
|
||||
uni.navigateTo({
|
||||
url: "/pages/common/ImgCrop/ImgCrop",
|
||||
events: {
|
||||
ImgCutOver: function(data) {
|
||||
|
||||
|
||||
showLoading(these, {
|
||||
text: "正在发送0/52"
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
these.rgb565Data = Common.convertToRGB565(data.piexls);
|
||||
|
||||
|
||||
setTimeout(function() {
|
||||
sendImagePackets().catch(() => {
|
||||
|
||||
|
||||
});
|
||||
}, 0)
|
||||
|
||||
|
||||
}
|
||||
},
|
||||
success(ev) {
|
||||
@ -542,18 +550,40 @@ class SendBatchData{
|
||||
console.log("跳转页面失败" + JSON.stringify(ex));
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
SendUsr(){
|
||||
|
||||
let these=this.these;
|
||||
let f=this.f;
|
||||
let ble=this.ble;
|
||||
|
||||
|
||||
//发送人员信息
|
||||
SendUsr(totalRows) {
|
||||
|
||||
let these = this.these;
|
||||
let f = this.f;
|
||||
let ble = this.ble;
|
||||
if (!totalRows) {
|
||||
totalRows = 3;
|
||||
}
|
||||
let toByteValue = (value) => {
|
||||
if (typeof value === 'number') {
|
||||
return value;
|
||||
}
|
||||
if (typeof value === 'string') {
|
||||
if (value.startsWith('0x') || value.startsWith('0X')) {
|
||||
return parseInt(value, 16);
|
||||
}
|
||||
return parseInt(`0x${value}`, 16);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
these.formData.textLines = [these.formData.company, these.formData.usrname, these.formData.job];
|
||||
if (totalRows == 4) {
|
||||
these.formData.textLines.push(these.formData.usrid);
|
||||
}
|
||||
|
||||
|
||||
console.log("data=", these.formData.textLines);
|
||||
showLoading(these, {
|
||||
text: "发送中"
|
||||
@ -561,17 +591,18 @@ class SendBatchData{
|
||||
//握手
|
||||
let holdHand = (hexs, time) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
|
||||
|
||||
|
||||
these.sendData(hexs, 'ble', "string").then(res => {
|
||||
setTimeout(() => {
|
||||
resolve(res)
|
||||
}, time);
|
||||
|
||||
|
||||
}).catch(ex => {
|
||||
console.error("握手失败")
|
||||
reject(ex)
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
}
|
||||
//画图
|
||||
@ -587,53 +618,53 @@ class SendBatchData{
|
||||
}).catch(compEx => {
|
||||
reject(compEx);
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
}
|
||||
//发送3个分包的数据
|
||||
let task = (allPixels) => {
|
||||
try {
|
||||
let combinedData = [];
|
||||
for (let i = 0; i < 4; i++) {
|
||||
for (let i = 0; i < totalRows; i++) {
|
||||
let linePixels = (allPixels[i] || []).flat(Infinity).map(item =>
|
||||
typeof item === 'string' ? toByteValue(item) : item
|
||||
);
|
||||
|
||||
|
||||
for (var j = linePixels.length; j < 256; j++) {
|
||||
linePixels.push(0x00);
|
||||
}
|
||||
linePixels = [0xFA, 0x06, 0x03, i + 1].concat(linePixels);
|
||||
|
||||
|
||||
linePixels.push(0xFF)
|
||||
|
||||
|
||||
combinedData.push(linePixels);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
let curr = 1;
|
||||
let len = combinedData.length;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//分包发送
|
||||
let sendPacket = () => {
|
||||
|
||||
|
||||
if (combinedData.length === curr - 1) {
|
||||
setTimeout(()=>{
|
||||
setTimeout(() => {
|
||||
holdHand('transmit complete', 200).then(res => {
|
||||
MsgSuccess("人员信息发送成功", "确定", these);
|
||||
hideLoading(these);
|
||||
these.setBleFormData();
|
||||
});
|
||||
},300);
|
||||
|
||||
hideLoading();
|
||||
MsgSuccess("人员信息发送成功", "确定", these);
|
||||
hideLoading(these);
|
||||
these.setBleFormData();
|
||||
});
|
||||
}, 300);
|
||||
|
||||
hideLoading(these);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
let array = combinedData[curr - 1];
|
||||
|
||||
|
||||
|
||||
|
||||
console.log("array=", array);
|
||||
ble.sendHexs(f.deviceId, array, null, null, 15).then(
|
||||
res => {
|
||||
@ -644,47 +675,69 @@ class SendBatchData{
|
||||
})
|
||||
setTimeout(sendPacket, 250);
|
||||
}).catch(err => {
|
||||
console.err("发送失败", err);
|
||||
|
||||
console.error("err:", err);
|
||||
|
||||
if (err.code == '10007') {
|
||||
setTimeout(sendPacket, 250);
|
||||
} else {
|
||||
console.log("err:", err);
|
||||
MsgError('发送失败' + (err.msg || err.code), '确定', these);
|
||||
hideLoading();
|
||||
console.error("err:", err);
|
||||
MsgError('发送失败:' + (err.msg || err.code), 'OK', these);
|
||||
hideLoading(these);
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
setTimeout(sendPacket, 0);
|
||||
// 5. 发送成功处理
|
||||
|
||||
|
||||
|
||||
|
||||
} catch (ex) {
|
||||
console.error("ex=", ex)
|
||||
MsgError('发送失败' + (ex.msg || ex.code), '确定', these);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
setTimeout(() => {
|
||||
Promise.allSettled([holdHand('word transmit start', 2200), drawText()]).then(results => {
|
||||
if (results[0].status == 'rejected') {
|
||||
MsgError("与蓝牙设备握手失败,请重试",'',these);
|
||||
MsgError("与蓝牙设备握手失败,请重试", '', these);
|
||||
setTimeout(() => {
|
||||
hideLoading(these)
|
||||
}, 500);
|
||||
return;
|
||||
}
|
||||
if (results[1].status == 'rejected') {
|
||||
MsgError("读取文字点阵失败,请重试",'',these);
|
||||
MsgError("读取文字点阵失败,请重试", '', these);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
task(results[1].value);
|
||||
})
|
||||
|
||||
|
||||
}, 0);
|
||||
}
|
||||
|
||||
}
|
||||
//发送识别指令
|
||||
SendDisc() {
|
||||
let these = this.these;
|
||||
let f = this.f;
|
||||
let ble = this.ble;
|
||||
|
||||
var json = {
|
||||
ins_disc: 1
|
||||
}
|
||||
|
||||
ble.sendString(f.deviceId, json, f.writeServiceId, f.wirteCharactId, 30).then(res => {
|
||||
|
||||
}).catch(ex => {
|
||||
console.error("蓝牙发送失败", ex);
|
||||
}).finally(() => {
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export default SendBatchData;
|
||||
Reference in New Issue
Block a user