1
0
forked from dyf/APP

018A添加报警日志

This commit is contained in:
liub
2026-04-24 08:51:26 +08:00
parent 1f88de4710
commit 5128c29d86
10 changed files with 1260 additions and 54 deletions

61
App.vue
View File

@ -36,7 +36,7 @@
// #ifdef APP|APP-PLUS
let system=uni.getSystemInfoSync();
let system = uni.getSystemInfoSync();
let initOS = () => {
@ -52,7 +52,7 @@
}
});
if (!uni.setAppBadgeNumber) { //兼容鸿蒙的写法
if(plus){
if (plus) {
uni.setAppBadgeNumber = plus.runtime.setBadgeNumber;
}
@ -84,7 +84,7 @@
console.log("system=",system);
console.log("system=", system);
// #endif
},
onShow: function() {
@ -105,11 +105,11 @@
}
uni.setKeepScreenOn({
keepScreenOn:true
}).then(res=>{
keepScreenOn: true
}).then(res => {
console.log("已设置屏幕常亮");
}).catch(ex=>{
console.error("设置屏幕常亮失败,ex=",ex)
}).catch(ex => {
console.error("设置屏幕常亮失败,ex=", ex)
})
// #endif
@ -120,11 +120,11 @@
// #ifdef APP|APP-PLUS
uni.setKeepScreenOn({
keepScreenOn:false
}).then(res=>{
keepScreenOn: false
}).then(res => {
console.log("已关闭屏幕常亮");
}).catch(ex=>{
console.error("设置屏幕常亮失败,ex=",ex)
}).catch(ex => {
console.error("设置屏幕常亮失败,ex=", ex)
})
// 上传中不主动断开:语音上传进行中则不断开蓝牙
@ -231,9 +231,10 @@
color: #ffffffde;
}
.uni-app--maxwidth,.uni-body{
background-color: #121212;
}
.uni-app--maxwidth,
.uni-body {
background-color: #121212;
}
.fleft {
float: left;
@ -264,14 +265,32 @@
align-items: center;
}
@font-face {
font-family: "PingFang SC";
src: url("~@/static/fonts/PingFangSC.ttf") format("opentype");
.navbarRight .img {
width: 35rpx;
height: 35rpx;
margin-right: 30rpx;
}
@font-face {
font-family: "PingFangBold";
src: url("~@/static/fonts/PingFangBold.ttf") format("opentype");
.uni-navbar--fixed {
top: 0rpx;
}
::v-deep .uni-navbar--fixed {
top: 0px;
}
::v-deep .uni-navbar__placeholder {
display: none !important;
}
// @font-face {
// font-family: "PingFang SC";
// src: url("~@/static/fonts/PingFangSC.ttf") format("opentype");
// }
// @font-face {
// font-family: "PingFangBold";
// src: url("~@/static/fonts/PingFangBold.ttf") format("opentype");
// }
</style>

View File

@ -478,13 +478,27 @@
{
"path": "pages/common/sosSet/TxtMsgSetting",
"style": {
"navigationBarTitleText": "短信设置"
"navigationBarTitleText": "短信设置",
"navigationStyle": "custom"
}
},
{
"path": "pages/common/sosSet/LinkManSetting",
"style": {
"navigationBarTitleText": "紧急联系人"
"navigationBarTitleText": "紧急联系人",
"navigationStyle": "custom"
}
},
{
"path": "pages/common/sosSet/remark",
"style": {
"navigationBarTitleText": ""
}
},
{
"path": "pages/018A/018AMsg",
"style": {
"navigationBarTitleText": "报警记录"
}
}

330
pages/018A/018AMsg.vue Normal file
View File

@ -0,0 +1,330 @@
<template>
<view class="maincontent1 contentBg">
<!-- <view class="tab">
<view class="tabItem" :class="{active:Status.tabIndex===0}" @click.stop="tabChange(0)">报警</view>
<view class="tabItem" :class="{active:Status.tabIndex===1}" @click.stop="tabChange(1)">通话</view>
<view class="tabItem" :class="{active:Status.tabIndex===2}" @click.stop="tabChange(2)">开机</view>
<view class="tabItem" :class="{active:Status.tabIndex===3}" @click.stop="tabChange(3)">故障</view>
</view> -->
<view class="list">
<mescroll-uni class="device-list" @init="mescrollInit" @down="downCallback" @up="upCallback" :up="upOption"
:down="downOption" :fixed="false">
<view v-for="item,index in list" class="listItem">
<view v-if="Status.tabIndex==0">
<view class="row">
<view class="label">报警事项:</view>
<view class="red value">{{item.content}}</view>
</view>
<view class="row">
<view class="label">报警地点:</view>
<view class="value">{{item.location}}</view>
</view>
<view class="row">
<view class="label">报警时间:</view>
<view class="value">{{item.startTime}}</view>
</view>
<view class="row">
<view class="label">解除时间:</view>
<view class="value">{{item.finishTime}}</view>
</view>
<view class="row">
<view class="label">报警时长:</view>
<view class="value">{{item.durationTime}}</view>
</view>
</view>
<view v-if="Status.tabIndex==1">
</view>
<view v-if="Status.tabIndex==2">
</view>
<view v-if="Status.tabIndex==3">
</view>
</view>
</mescroll-uni>
</view>
</view>
</template>
<script>
var timeout = null;
import request from '@/utils/request.js';
export default {
data() {
return {
Status: {
tabIndex: 0
},
list: [],
mescroll: null,
downOption: {
auto: true,
autoShowLoading: false,
},
upOption: {
auto: false,
noMoreSize: 0,
offset: 10,
isLock: false,
empty: {
tip: '暂无数据',
hideScroll: false,
icon: '/static/images/common/empty.png'
},
textNoMore: '没有更多数据了'
},
device: {
}
}
},
onLoad() {
let eventChannel = this.getOpenerEventChannel();
eventChannel.on('detailData', (data) => {
debugger;
if (data) {
this.device = data;
}
});
},
methods: {
mescrollInit(mescroll) {
this.mescroll = mescroll;
},
// 下拉刷新
downCallback() {
if (this.mescroll) {
this.mescroll.resetUpScroll(false);
this.mescroll.scrollTo(0, 0);
}
this.getData();
},
// 上拉加载
upCallback() {
this.getData();
},
getWarList(data) {
return request({
url: '/app/device/AlarmList',
method: 'get',
data: data
});
},
getNotifyList() {
return new Promise((resolve, reject) => {
resolve({
code: 200,
total: 0,
rows: []
})
});
},
getTrun() {
return new Promise((resolve, reject) => {
resolve({
total: 0,
rows: []
})
});
},
getGuzhang() {
return new Promise((resolve, reject) => {
resolve({
total: 0,
rows: []
})
});
},
getData() {
let task = () => {
debugger;
let data = {
deviceId:(this.device&& this.device.id)?this.device.id:"00000000",
pageNum: this.mescroll.num,
pageSize: 10,
}
console.log("device=", JSON.stringify(this.device));
console.log("data", JSON.stringify(data));
if (!data.pageNum) {
this.mescroll.endSuccess(0, false);
return;
}
let arr = {
"0": this.getWarList.bind(this),
"1": this.getNotifyList.bind(this),
"2": this.getTrun.bind(this),
"3": this.getGuzhang.bind(this),
}
let apiCall = arr[this.Status.tabIndex + ''];
apiCall(data).then((res) => {
if (res.code == 200) {
if (data.pageNum === 1) {
this.list = res.rows;
} else {
this.list = this.list.concat(res.rows);
}
this.total = res.total;
let hasNext = true;
// 判断是否已加载全部数据
if (res.rows.length < this.size || this.list.length >= this.total) {
hasNext = false;
} else {
this.page++;
hasNext = true;
}
this.mescroll.endSuccess(res.rows.length, hasNext);
} else {
this.mescroll.endSuccess(0, false);
}
}).finally(() => {
this.loading = false;
});
}
clearTimeout(timeout);
timeout = setTimeout(task, 50);
},
tabChange(index) {
if (this.Status.tabIndex === index) {
return;
}
this.Status.tabIndex = index
this.downCallback();
}
}
}
</script>
<style>
/* #ifdef WEB|H5 */
.maincontent1 {
height: calc(100vh - 45px);
}
/* #endif */
.maincontent1 {
height: 100vh;
width: 100%;
padding: 30rpx;
box-sizing: border-box;
}
.listItem {
border-radius: 8px;
background: rgba(26, 26, 26, 1);
width: 100%;
height: auto;
margin-bottom: 20rpx;
padding: 15rpx 20rpx;
}
.listItem .label {
color: rgba(255, 255, 255, 0.6);
font-family: "PingFang SC";
font-style: Regular;
font-size: 26rpx;
font-weight: 400;
line-height: 30rpx;
letter-spacing: 0.14rpx;
width: 120rpx;
text-align: left;
white-space: nowrap;
}
.listItem .value {
color: rgba(255, 255, 255, 0.87);
font-family: "PingFang SC";
font-style: Regular;
font-size: 26rpx;
font-weight: 400;
line-height: 30rpx;
letter-spacing: 0.14rpx;
text-align: left;
}
.listItem .row {
display: flex;
flex-direction: row;
flex-wrap: nowrap;
align-content: flex-start;
justify-content: flex-start;
align-items: flex-start;
height: auto;
padding: 5rpx 0rpx;
}
.list {
width: 100%;
height: 100%;
}
.tab {
width: 100%;
height: 40rpx;
line-height: 40rpx;
display: flex;
flex-direction: row;
flex-wrap: nowrap;
align-content: center;
justify-content: flex-start;
align-items: center;
color: rgba(255, 255, 255, 0.87);
font-family: "PingFang SC";
font-style: Regular;
font-size: 28rpx;
font-weight: 400;
}
.tab .tabItem {
position: relative;
padding: 0rpx 30rpx;
}
.tab .tabItem::after {
position: absolute;
content: "";
width: 50%;
height: 8rpx;
border-radius: 30px;
top: 100%;
left: 25%;
margin-top: 5rpx;
background: #00000000;
}
.tab .tabItem.active::after {
background: rgba(187, 230, 0, 1);
}
.tab .tabItem.active {
color: rgba(174, 214, 0, 1);
font-style: Bold;
font-size: 32rpx;
}
</style>

View File

@ -1,5 +1,20 @@
<template>
<view class="content contentBg">
<uni-nav-bar :border="false" @clickLeft="prevPage" fixed="true" statusBar="true" background-color="#121212"
color="#FFFFFF" :title="Status.navbar.title">
<template v-slot:left>
<view>
<uni-icons type="left" size="24" color="#FFFFFF"></uni-icons>
</view>
</template>
<block slot="right">
<view class="navbarRight center">
<image @click.stop="handleRightClick(index,item)" v-for="item,index in Status.navbar.icons"
class="img" :src="item.src" mode="aspectFit"></image>
</view>
</block>
</uni-nav-bar>
<view class="eq">
<view class="leftImg" @click.stop="previewImg(device.devicePic?device.devicePic:formData.img)">
<image class="img" :src="device.devicePic?device.devicePic:formData.img" mode="aspectFit"></image>
@ -189,9 +204,19 @@
curr: 0,
total: 0,
pageHide: false,
usrToggle: false
usrToggle: false,
navbar: {
icons: [{
src: '/static/images/common/msg.png'
},
{
src: '/static/images/common/shape.png'
}
],
title: 'HBY018A',
showBack: true,
height: 90
},
},
formData: {
img: '/static/images/common/HBY018A.png',
@ -264,7 +289,8 @@
contact1Phone: "",
contact2Phone: "",
sosSmsMsg: ""
}
},
permissions: []
}
},
@ -296,7 +322,15 @@
// console.log("收到父页面的参数:" + JSON.stringify(data));
var device = data.data;
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(',');
}
}
});
}
this.getDeviceDetail();
let f = these.getDevice();
if (!f) {
@ -389,6 +423,41 @@
},
methods: {
prevPage() {
uni.navigateBack({
});
},
handleRightClick(s, e) {
if (s === 0) {
uni.navigateTo({
url: '/pages/018A/018AMsg',
success(res) {
res.eventChannel.emit('detailData', these.device);
}
});
return;
} else if (s === 1) {
console.log("分享");
uni.navigateTo({
url: '/pages/common/share/index',
events: {
ack: function(data) {}
},
success: (res) => {
let json = {
persissonType: '018A'
};
Object.assign(json, these.device);
res.eventChannel.emit('share', {
data: json
});
}
})
}
},
closeAction() {
for (let index = 0; index < this.dic.actionSheets.length; index++) {
let menu = this.dic.actionSheets[index];
@ -610,11 +679,13 @@
this.device.longitude = lnglat[0];
this.device.latitude = lnglat[1];
this.formData.sta_longitude = lnglat[0];
this.formData.sta_latitude = lnglat[1];
Common.regeo(lnglat[0], lnglat[1]).then(res => {
this.formData.address = res.regeocode.formatted_address
this.formData.address = res.regeocode.formatted_address;
this.setBleFormData();
}).catch(ex => {
console.error("逆地理失败了")
}).finally(this.routePlan);
@ -631,6 +702,12 @@
reGeoTime = setTimeout(task, 500);
},
gotoPage(page) {
if (!this.permissions.includes('57') && this.Status.apiType !== 'listA') {
MsgError('无操作权限', '确定', these);
return;
}
uni.navigateTo({
url: '/pages/common/sosSet/' + page,
success(res) {
@ -771,7 +848,7 @@
this.device.longitude = this.formData.sta_longitude;
this.device.latitude = this.formData.sta_latitude;
console.log("device=",this.device);
console.log("device=", this.device);
uni.navigateTo({
url: '/pages/common/map/index',
events: {
@ -790,6 +867,11 @@
},
LighSetting(item, index) {
if (!this.permissions.includes('51') && this.Status.apiType !== 'listA') {
MsgError('无操作权限', '确定', these);
return;
}
let val = item.key;
if (item.key === this.formData.sta_Side_Light) {
val = 0;
@ -818,7 +900,11 @@
sosToggle(type) {
if (!this.permissions.includes('46') && this.Status.apiType !== 'listA') {
MsgError('无操作权限', '确定', these);
return;
}
if (this.formData.sta_ShakeBit != 1 && this.formData.sta_ShakeBit != 0) {
MsgError("设备正在报警中", '', these);
return;

View File

@ -241,22 +241,22 @@
show: false,
showHeader: true,
menuItems: [{
text: '2M',
text: '低档',
value: 'status_2M',
icon: ''
},
{
text: '4M',
text: '中档',
value: 'status_4M',
icon: ''
},
{
text: '7M',
text: '高档',
value: 'status_7M',
icon: ''
},
{
text: '10M',
text: '超强',
value: 'status_10M',
icon: ''
},

View File

@ -300,22 +300,22 @@
show: false,
showHeader: true,
menuItems: [{
text: '2M',
text: '低档',
value: 2,
icon: ''
},
{
text: '4M',
text: '中档',
value: 4,
icon: ''
},
{
text: '7M',
text: '高档',
value: 7,
icon: ''
},
{
text: '10M',
text: '超强',
value: 10,
icon: ''
},

View File

@ -284,6 +284,7 @@
var mq = null;
var pagePath = "pages/6075J/BJQ6075J";
var brightnessTimer = null;
var reGeoTime=null;
export default {
components: {
TextToHexV1
@ -663,7 +664,7 @@
totalPackets = ReSendNo;
currentPacket = ReSendNo;
}
this.totalPackets = totalPackets;
// 发送单个数据包
const sendNextVideoPacket = () => {
// console.log("准备发送一段数据");
@ -1446,6 +1447,7 @@
let sendLaser = () => {
this.sendData(json, null, 'string').then(res => {
this.formData.sta_laser = val;
this.formData.sta_LightGrade=6;
this.setBleFormData();
}).catch(ex => {
console.error("出现错误", ex)
@ -1482,6 +1484,9 @@
this.sendData(json, null, 'string').then((res) => {
let key = li.key.replace(/ins_/g, 'sta_');
this.formData[key] = li.value;
if(li.value!=6){
this.formData.sta_laser=0;
}
this.setBleFormData();
this.formData.sta_brightness = 100;
}).catch((ex) => {
@ -1973,9 +1978,43 @@
this.$set(this.dic.actionSheets[0], 'value', this.formData.sta_LightGrade);
this.$set(this.dic.actionSheets[1], 'value', this.formData.sta_Side_Light);
if ('sta_longitude' in data) {
this.reGeo();
}
this.setBleFormData();
},
reGeo() {
console.log("经纬度发生变化,执行逆地理")
let task = () => {
if (this.formData.sta_longitude && this.formData.sta_latitude) {
let promise = lnglatConvert.wgs84_to_gcj02(this.formData.sta_longitude, this.formData
.sta_latitude);
promise.then(lnglat => {
this.device.longitude = lnglat[0];
this.device.latitude = lnglat[1];
this.formData.sta_longitude=lnglat[0];
this.formData.sta_latitude=lnglat[1];
Common.regeo(lnglat[0], lnglat[1]).then(res => {
this.formData.address = res.regeocode.formatted_address
this.setBleFormData();
}).catch(ex => {
console.error("逆地理失败了")
});
}).catch(err => {
console.error("坐标转换失败了");
});
} else {
console.error("经纬度缺失");
}
}
clearTimeout(reGeoTime);
reGeoTime = setTimeout(task, 500);
},
setBleFormData() {
if (!ble) {
return;
@ -2097,7 +2136,7 @@
},
gotoMap() {
let promise = lnglatConvert.wgs84_to_gcj02(this.formData.sta_longitude, this.formData.sta_latitude);
let promise =Promise.resolve([this.formData.sta_longitude, this.formData.sta_latitude]); //lnglatConvert.wgs84_to_gcj02(this.formData.sta_longitude, this.formData.sta_latitude);
promise.then(lnglat => {
this.detailData.longitude = lnglat[0];

View File

@ -0,0 +1,22 @@
<template>
<view class="content contentBg">
</view>
</template>
<script>
export default {
data() {
return {
}
},
methods: {
}
}
</script>
<style>
</style>

View File

@ -282,7 +282,7 @@ export default {
value: "46",
label: "手动报警",
checked: false,
type: ['210', '102', '6170']
type: ['210', '102', '6170','018A']
},
{
value: "47",
@ -314,7 +314,7 @@ export default {
value: "51",
label: "警示灯",
checked: false,
type: ['100', '100J']
type: ['100', '100J','018A']
},
{
@ -348,6 +348,12 @@ export default {
checked: false,
type: ['100J']
},
{
value: "57",
label: "紧急联系设置",
checked: false,
type: ['018A']
}
]
let arr = [];

690
utils/SendBatchData.js Normal file
View File

@ -0,0 +1,690 @@
import request, {
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';
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;
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(
() => {
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);
}
});
}
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();
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);
});
}
});
}
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));
}
});
}
});
}
SendUsr(){
let these=this.these;
let f=this.f;
let ble=this.ble;
these.formData.textLines = [these.formData.company, these.formData.usrname, these.formData.job];
console.log("data=", these.formData.textLines);
showLoading(these, {
text: "发送中"
});
//握手
let holdHand = (hexs, time) => {
return new Promise((resolve, reject) => {
these.sendData(hexs, 'ble', "string").then(res => {
setTimeout(() => {
resolve(res)
}, time);
}).catch(ex => {
reject(ex)
});
});
}
//画图
let drawText = () => {
return new Promise((resolve, reject) => {
these.$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);
these.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);
}
}