Compare commits
23 Commits
ceafd10b72
...
main
Author | SHA1 | Date | |
---|---|---|---|
6ee45f6868 | |||
8108744d56 | |||
c537e17780 | |||
2f437e16b6 | |||
8460aa1be2 | |||
c4cd556bd4 | |||
9846fe2315 | |||
82ca470b2d | |||
49834be90d | |||
c2aa8bfa2f | |||
057858a132 | |||
09862e8e07 | |||
d2d68a0b39 | |||
8d97dcf121 | |||
f8a02b7f9f | |||
823c54aed7 | |||
64529bf573 | |||
fe5545b642 | |||
8e1a37dbea | |||
106320bfd5 | |||
9bac0995a3 | |||
a773823c3f | |||
e56bbfe674 |
43
App.vue
@ -1,14 +1,46 @@
|
||||
<script>
|
||||
import bleTool from '@/utils/BleHelper.js'
|
||||
import upgrade from '@/utils/update.js'
|
||||
export default {
|
||||
|
||||
onLaunch: function() {
|
||||
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"){
|
||||
// console.log("忽略登陆信息");
|
||||
// }else{
|
||||
// uni.removeStorageSync(val);
|
||||
// }
|
||||
// });
|
||||
//以上代码仅在开发时使用,否则会出现不可预知的问题。
|
||||
|
||||
uni.getSystemInfo({success:function(res){
|
||||
if(res.uniPlatform=='app'){
|
||||
upgrade.checkAndUpdateWgt("http://114.55.111.217/app/CheckUpdate");
|
||||
bleTool.getBleTool();
|
||||
}
|
||||
}});
|
||||
},
|
||||
onShow: function() {
|
||||
console.log('App Show')
|
||||
console.log('App Show');
|
||||
|
||||
},
|
||||
onHide: function() {
|
||||
console.log('App Hide')
|
||||
console.log('App Hide');
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@ -54,4 +86,9 @@
|
||||
.uni-picker-view-wrapper{
|
||||
background: rgba(42, 42, 42, 1);
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: "PingFang SC";
|
||||
src: url("~@/static/fonts/PingFangSC.ttf") format("opentype");
|
||||
}
|
||||
</style>
|
||||
|
@ -1,671 +0,0 @@
|
||||
export default {
|
||||
featrueValueCallback: null,//蓝牙特征变化回调
|
||||
BleChangeCallback:null,//蓝牙状态变化回调
|
||||
//引导用户打开蓝牙
|
||||
showBluetoothGuide: function(showTip) {
|
||||
let platform = process.env.UNI_PLATFORM;
|
||||
|
||||
|
||||
var openBlueSetting = function() {
|
||||
// 判断平台类型
|
||||
if (platform === 'mp-weixin') {
|
||||
uni.openSetting();
|
||||
} else if (platform === 'app-plus' || platform === 'app') {
|
||||
//----------------------------------------------------------------
|
||||
const osName = plus.os.name;
|
||||
|
||||
if (osName === 'iOS') {
|
||||
// iOS 平台打开蓝牙设置
|
||||
plus.runtime.openURL('App-Prefs:root=Bluetooth', function() {
|
||||
console.log('成功打开蓝牙设置');
|
||||
}, function(err) {
|
||||
console.error('打开蓝牙设置失败:' + err.message);
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: '无法自动打开蓝牙设置,请手动前往设置 > 蓝牙 进行操作。',
|
||||
showCancel: false
|
||||
});
|
||||
});
|
||||
} else if (osName === 'Android') {
|
||||
// Android 平台打开蓝牙设置
|
||||
try {
|
||||
const Intent = plus.android.importClass('android.content.Intent');
|
||||
const Settings = plus.android.importClass('android.provider.Settings');
|
||||
const main = plus.android.runtimeMainActivity();
|
||||
const intent = new Intent(Settings.ACTION_BLUETOOTH_SETTINGS);
|
||||
main.startActivity(intent);
|
||||
} catch (e) {
|
||||
console.error('打开蓝牙设置失败:' + e.message);
|
||||
// 尝试使用通用设置页面作为备选方案
|
||||
plus.runtime.openURL('settings://', function() {
|
||||
console.log('打开系统设置成功,请手动找到蓝牙选项');
|
||||
}, function() {
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: '无法自动打开蓝牙设置,请手动前往设置页面开启蓝牙。',
|
||||
showCancel: false
|
||||
});
|
||||
});
|
||||
}
|
||||
} else {
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: '当前系统不支持自动打开蓝牙设置,请手动操作。',
|
||||
showCancel: false
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
} else if (platform === 'mp-alipay') {
|
||||
uni.openSetting();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (showTip !== undefined) {
|
||||
openBlueSetting();
|
||||
return;
|
||||
}
|
||||
if (platform === 'mp-weixin' || platform === 'app-plus' || platform === 'mp-alipay' || platform === 'app') {
|
||||
uni.showModal({
|
||||
title: '蓝牙未开启',
|
||||
content: '请在系统设置中打开蓝牙以使用此功能',
|
||||
success: (res) => {
|
||||
if (res.confirm) {
|
||||
openBlueSetting();
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
console.log("当前平台不支持打开系统设置" + platform);
|
||||
}
|
||||
|
||||
|
||||
},
|
||||
//获取蓝牙适配器状态
|
||||
CheckBlue: function(callback) {
|
||||
|
||||
uni.getBluetoothAdapterState({
|
||||
success(res1) {
|
||||
|
||||
console.log("当前蓝牙适配器状态:" + JSON.stringify(res1))
|
||||
if (callback) {
|
||||
callback(res1);
|
||||
}
|
||||
|
||||
},
|
||||
fail(ex1) {
|
||||
console.log("检查蓝牙状态异常:" + JSON.stringify(ex1));
|
||||
if (callback) {
|
||||
if (ex1.code == 10000) {
|
||||
console.log("未初始化蓝牙适配器");
|
||||
}
|
||||
let res1 = {
|
||||
available: false,
|
||||
discovering: false
|
||||
}
|
||||
callback(res1);
|
||||
}
|
||||
},
|
||||
complete() {
|
||||
|
||||
}
|
||||
});
|
||||
},
|
||||
//初始化蓝牙模块
|
||||
OpenBlue: function(isCheckState, callback, availCallback) {
|
||||
|
||||
var these = this;
|
||||
|
||||
var init = function() {
|
||||
uni.openBluetoothAdapter({
|
||||
success: (res) => {
|
||||
console.log("蓝牙初始化成功:" + JSON.stringify(res));
|
||||
if (callback) {
|
||||
callback();
|
||||
}
|
||||
uni.onBluetoothAdapterStateChange(function(state) {
|
||||
console.log('蓝牙状态发生变化:' + JSON.stringify(state));
|
||||
if(this.BleChangeCallback){
|
||||
this.BleChangeCallback()
|
||||
}
|
||||
})
|
||||
},
|
||||
fail: function(ex2) {
|
||||
console.log("蓝牙初始化失败:" + JSON.stringify(ex2))
|
||||
if (ex2.code == '10001') {
|
||||
console.log("手机蓝牙未打开或设备不支持蓝牙");
|
||||
|
||||
|
||||
if (availCallback) {
|
||||
availCallback();
|
||||
} else {
|
||||
these.showBluetoothGuide();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
if (isCheckState) {
|
||||
this.CheckBlue(function(res1) {
|
||||
if (res1.available) {
|
||||
if (callback) {
|
||||
callback();
|
||||
}
|
||||
return;
|
||||
}
|
||||
init();
|
||||
})
|
||||
} else {
|
||||
init();
|
||||
}
|
||||
|
||||
|
||||
|
||||
},
|
||||
//关闭蓝牙模块,停止搜索、断开所有连接
|
||||
CloseBlue: function(callback) {
|
||||
|
||||
this.StopSearch();
|
||||
|
||||
this.disconnectDevice();
|
||||
|
||||
uni.closeBluetoothAdapter({
|
||||
success: () => {
|
||||
console.log("蓝牙模块已关闭");
|
||||
if (callback) {
|
||||
callback();
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
//开始搜索新设备
|
||||
StartSearch: function(callback) {
|
||||
|
||||
var these = this;
|
||||
|
||||
//发现新设备
|
||||
var onDeviceFound = function() {
|
||||
uni.onBluetoothDeviceFound(function(res) {
|
||||
console.log("发现新设备:" + JSON.stringify(res));
|
||||
if (callback) {
|
||||
callback(res);
|
||||
}
|
||||
})
|
||||
}
|
||||
//开始搜索
|
||||
var Search = function() {
|
||||
uni.startBluetoothDevicesDiscovery({
|
||||
services: ["0xFFE0"],
|
||||
allowDuplicatesKey: false,
|
||||
success: (res) => {
|
||||
console.log('开始搜索蓝牙设备成功');
|
||||
onDeviceFound();
|
||||
},
|
||||
fail: (err) => {
|
||||
console.log(`搜索蓝牙设备失败: ${err.errMsg}`);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
//先检查蓝牙状态是可用
|
||||
this.CheckBlue(function(res1) {
|
||||
if (res1.available) {
|
||||
if (!res1.discovering) {
|
||||
Search();
|
||||
} else {
|
||||
console.log("当前蓝牙正在搜索设备")
|
||||
}
|
||||
|
||||
} else {
|
||||
these.OpenBlue(false, Search, () => {
|
||||
these.showBluetoothGuide();
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
},
|
||||
//停止搜索
|
||||
StopSearch: function() {
|
||||
uni.stopBluetoothDevicesDiscovery({
|
||||
success: (res) => {
|
||||
console.log("停止搜索蓝牙设备成功")
|
||||
},
|
||||
fail() {
|
||||
console.log("无法停止蓝牙搜索")
|
||||
}
|
||||
});
|
||||
},
|
||||
//获取已连接的设备
|
||||
getLinkBlue: function(callback) {
|
||||
uni.getConnectedBluetoothDevices({
|
||||
services: ["0xFFE0"],
|
||||
success: (res) => {
|
||||
if (callback) {
|
||||
callback(res);
|
||||
|
||||
}
|
||||
},
|
||||
fail: function(ex) {
|
||||
console.log("获取已连接设备异常");
|
||||
if (callback) {
|
||||
callback({
|
||||
devices: []
|
||||
});
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
//连接某个设备
|
||||
LinkBlue: function(deviceId, callback, error) {
|
||||
|
||||
this.StopSearch();
|
||||
var these = this;
|
||||
let key = "linkedDevices";
|
||||
var store = uni.getStorageInfoSync();
|
||||
var f = store.keys.find(function(v) {
|
||||
return v == key;
|
||||
});
|
||||
var linkedDevices = [];
|
||||
if (f) {
|
||||
var str = uni.getStorageSync(key);
|
||||
if (str) {
|
||||
linkedDevices = JSON.parse(str);
|
||||
}else{
|
||||
linkedDevices=[];
|
||||
}
|
||||
|
||||
}
|
||||
//连接成功的回调
|
||||
var lindedCallback = function () {
|
||||
|
||||
let c = linkedDevices.find(function (v) {
|
||||
return v.deviceId == deviceId;
|
||||
});
|
||||
|
||||
if (c) {
|
||||
console.log("连接成功开始监听特征变化")
|
||||
//监听设备的特征变化
|
||||
uni.notifyBLECharacteristicValueChange({
|
||||
deviceId: deviceId,
|
||||
serviceId: c.notifyServiceid,
|
||||
characteristicId: c.notifyCharactId,
|
||||
state: true,
|
||||
success: function (res) {
|
||||
console.log("开始监听成功。。。。")
|
||||
if(res.errCode=='0'){
|
||||
//订阅特征值
|
||||
uni.onBLECharacteristicValueChange(function(data){
|
||||
// data.characteristicId
|
||||
// data.deviceId
|
||||
// data.serviceId
|
||||
// data.value
|
||||
console.log("监听到特征值:"+JSON.stringify(data));
|
||||
|
||||
if(these.featrueValueCallback){
|
||||
these.featrueValueCallback(data);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (callback) {
|
||||
callback(deviceId);
|
||||
}
|
||||
}
|
||||
|
||||
var linkState = function(res) {
|
||||
console.log("获取已连接的设备回调" + JSON.stringify(res))
|
||||
let flag = res.devices.find(function(v) {
|
||||
if (v.deviceId == deviceId) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
if (flag) {
|
||||
console.log("设备状态已连接");
|
||||
|
||||
lindedCallback(deviceId);
|
||||
|
||||
return;
|
||||
} else {
|
||||
console.log("设备未连接");
|
||||
linkDevice(deviceId);
|
||||
}
|
||||
}
|
||||
|
||||
var linkDevice = function(id) {
|
||||
console.log("正在连接"+id);
|
||||
uni.createBLEConnection({
|
||||
deviceId: id,
|
||||
timeout: 30000,
|
||||
success: function(info) {
|
||||
|
||||
console.log("连接成功");
|
||||
|
||||
uni.setBLEMTU({
|
||||
deviceId: id,
|
||||
mtu: 512,
|
||||
success: () => {
|
||||
console.log("mtu设置成功");
|
||||
if(linkedDevices){
|
||||
console.log("11111"+JSON.stringify(linkedDevices));
|
||||
f = linkedDevices.find(function (v) {
|
||||
return v.deviceId == id;
|
||||
});
|
||||
}else{
|
||||
console.log("22222")
|
||||
f=null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (!f) {
|
||||
console.log("缓存中没有找到该设备")
|
||||
|
||||
these.getLinkBlue(function (res) {
|
||||
if (res.devices && res.devices.length) {
|
||||
let f = res.devices.find(function (v) {
|
||||
return v.deviceId == id;
|
||||
});
|
||||
linkedDevices.push(f);
|
||||
uni.setStorageSync(key, JSON.stringify(linkedDevices));
|
||||
|
||||
getService(id);
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
} else {
|
||||
console.log("缓存中已连接过");
|
||||
if (!f.services) {
|
||||
getService(id);
|
||||
} else {
|
||||
|
||||
lindedCallback(id);
|
||||
|
||||
}
|
||||
}
|
||||
},
|
||||
fail: function() {
|
||||
console.log("mtu设置失败")
|
||||
}
|
||||
});
|
||||
|
||||
},
|
||||
fail: function(ex) {
|
||||
if (error) {
|
||||
console.log("蓝牙连接失败" + JSON.stringify(error));
|
||||
error(ex);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
//获取服务
|
||||
var getService = function(id) {
|
||||
|
||||
var repeatCnt = 0;
|
||||
var startgetService = function() {
|
||||
uni.getBLEDeviceServices({
|
||||
deviceId: id,
|
||||
success: function(res) {
|
||||
if (res.services && res.services.length > 0) {
|
||||
console.log("获取到服务:" + JSON.stringify(res));
|
||||
|
||||
linkedDevices.find(function(v) {
|
||||
if (v.deviceId == id) {
|
||||
v.services = res.services;
|
||||
}
|
||||
});
|
||||
uni.setStorageSync(key, JSON.stringify(linkedDevices));
|
||||
var promises = [];
|
||||
for (var i = 0; i < res.services.length; i++) {
|
||||
let service = res.services[i];
|
||||
promises.push(getFeatrus(id, service.uuid));
|
||||
}
|
||||
|
||||
Promise.all(promises)
|
||||
.then(results => {
|
||||
console.log('所有操作成功完成', results);
|
||||
|
||||
lindedCallback(id);
|
||||
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('至少一个操作失败', error);
|
||||
});
|
||||
|
||||
|
||||
} else {
|
||||
repeatCnt++;
|
||||
if (repeatCnt > 5) {
|
||||
|
||||
lindedCallback(id);
|
||||
|
||||
return;
|
||||
}
|
||||
setTimeout(function() {
|
||||
startgetService(id);
|
||||
}, 500);
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
setTimeout(function() {
|
||||
startgetService(id);
|
||||
}, 1000);
|
||||
}
|
||||
//获取特性
|
||||
var getFeatrus = function(id, serviceId) {
|
||||
var promise = new Promise((resolve, reject) => {
|
||||
uni.getBLEDeviceCharacteristics({
|
||||
deviceId: id,
|
||||
serviceId: serviceId,
|
||||
success: (res) => {
|
||||
console.log("获取到特征:" + JSON.stringify(res));
|
||||
|
||||
//写特征
|
||||
let writeChar = res.characteristics.find(char =>
|
||||
char.uuid.indexOf("FFE1") > -1
|
||||
);
|
||||
//通知特征
|
||||
let notiChar = res.characteristics.find(char =>
|
||||
char.uuid.indexOf("FFE2") > -1
|
||||
);
|
||||
|
||||
linkedDevices.find(function(v) {
|
||||
if (v.deviceId == id) {
|
||||
if (!v.Characteristics) {
|
||||
v.Characteristics = [];
|
||||
}
|
||||
v.Characteristics = v.Characteristics.concat(res
|
||||
.characteristics);
|
||||
|
||||
if (writeChar) {
|
||||
v.writeServiceId = serviceId;
|
||||
v.wirteCharactId = writeChar.uuid;
|
||||
}
|
||||
|
||||
if (notiChar) {
|
||||
v.notifyServiceid = serviceId;
|
||||
v.notifyCharactId = notiChar.uuid;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
uni.setStorageSync(key, JSON.stringify(linkedDevices));
|
||||
resolve(res);
|
||||
},
|
||||
fail: (ex) => {
|
||||
console.log("获取特征出现异常:" + JSON.stringify(ex));
|
||||
resolve(ex);
|
||||
}
|
||||
});
|
||||
});
|
||||
return promise;
|
||||
}
|
||||
|
||||
//监测蓝牙状态变化
|
||||
uni.onBLEConnectionStateChange(function(res) {
|
||||
if (!res.connected) {
|
||||
console.log("蓝牙断开连接" + res.deviceId + "");
|
||||
// lindDevice(res.deviceId);
|
||||
}
|
||||
});
|
||||
|
||||
console.log("正在获取蓝牙适配器状态")
|
||||
this.CheckBlue((res) => {
|
||||
console.log("蓝牙状态:" + JSON.stringify(res));
|
||||
if (res.available) {
|
||||
this.getLinkBlue(linkState);
|
||||
} else {
|
||||
console.log("蓝牙适配器不可用,正在初始化");
|
||||
this.OpenBlue(false, () => {
|
||||
this.getLinkBlue(linkState);
|
||||
}, () => {
|
||||
console.log("请引导用户打开蓝牙");
|
||||
these.showBluetoothGuide();
|
||||
})
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
},
|
||||
//断开连接
|
||||
disconnectDevice: function(deviceId) {
|
||||
|
||||
var disconnect = function(id) {
|
||||
uni.closeBLEConnection({
|
||||
deviceId: id,
|
||||
success: (res) => {
|
||||
console.log("蓝牙连接已断开");
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
if (deviceId) {
|
||||
disconnect(deviceId);
|
||||
return;
|
||||
}
|
||||
//断开所有已连接的设备
|
||||
this.getLinkBlue(function(res) {
|
||||
if (res.devices && res.devices.length > 0) {
|
||||
for (var i = 0; i < res.devices.length; i++) {
|
||||
let item = res.devices[i];
|
||||
disconnect(item.deviceId);
|
||||
}
|
||||
|
||||
} else {
|
||||
console.log("无连接设备");
|
||||
}
|
||||
});
|
||||
|
||||
},
|
||||
//发送二进制数据
|
||||
sendData: function(deviceid, buffer) {
|
||||
|
||||
console.log("准备向设备发送数据,deviceid=" + deviceid);
|
||||
return new Promise((resolve, reject) => {
|
||||
if (!deviceid) {
|
||||
reject(`deviceid为空,请输入要发送的设备`);
|
||||
return;
|
||||
}
|
||||
console.log("准备发送数据包");
|
||||
let key = "linkedDevices";
|
||||
var store = uni.getStorageInfoSync();
|
||||
var f = store.keys.find(function(v) {
|
||||
return v == key;
|
||||
});
|
||||
console.log("倒计时:5");
|
||||
var linkedDevices = [];
|
||||
if (f) {
|
||||
var str = uni.getStorageSync(key);
|
||||
if (str) {
|
||||
linkedDevices = JSON.parse(str);
|
||||
}
|
||||
|
||||
}
|
||||
console.log("倒计时:4");
|
||||
if (linkedDevices && linkedDevices.length && linkedDevices.length > 0) {
|
||||
console.log("倒计时:3");
|
||||
f = linkedDevices.find(function(v) {
|
||||
return v.deviceId == deviceid;
|
||||
|
||||
});
|
||||
console.log("f=" + JSON.stringify(f));
|
||||
// console.log("deviceid=" + deviceid);
|
||||
console.log("倒计时:2");
|
||||
if (f) {
|
||||
console.log("倒计时:1");
|
||||
uni.writeBLECharacteristicValue({
|
||||
deviceId: f.deviceId,
|
||||
serviceId: f.writeServiceId,
|
||||
characteristicId: f.wirteCharactId,
|
||||
value: buffer,
|
||||
success: () => {
|
||||
console.log("发送数据成功");
|
||||
resolve();
|
||||
},
|
||||
fail: (err) => {
|
||||
console.log("发送数据失败" + JSON.stringify(err));
|
||||
reject(`发送数据失败: ${err.errMsg}`);
|
||||
},
|
||||
complete: function() {
|
||||
console.log("发送数据complete");
|
||||
}
|
||||
});
|
||||
} else {
|
||||
reject(`已连接设备中无法找到此设备`);
|
||||
// console.log("警报:已连接设备中无法找到此设备")
|
||||
}
|
||||
|
||||
} else {
|
||||
console.log("检测到未与设备建立连接");
|
||||
reject(`检测到未与设备建立连接`);
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
},
|
||||
sendDataNew: function(deviceid, serviceId, characteristicId, buffer) {
|
||||
|
||||
console.log("准备向设备发送数据,deviceid=" + deviceid);
|
||||
return new Promise((resolve, reject) => {
|
||||
uni.writeBLECharacteristicValue({
|
||||
deviceId: deviceid,
|
||||
serviceId: serviceId,
|
||||
characteristicId: characteristicId,
|
||||
value: buffer,
|
||||
success: () => {
|
||||
console.log("发送数据成功");
|
||||
resolve();
|
||||
},
|
||||
fail: (err) => {
|
||||
console.log("发送数据失败" + JSON.stringify(err));
|
||||
reject(`发送数据失败: ${err.errMsg}`);
|
||||
},
|
||||
complete: function() {
|
||||
console.log("发送数据complete");
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -61,4 +61,13 @@ export function mapReverseGeocoding(data) {
|
||||
method: 'post',
|
||||
data: data
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// 或者设备状态
|
||||
export function deviceRealTimeStatus(params) {
|
||||
return request({
|
||||
url: `/app/device/realTimeStatus`,
|
||||
method: 'get',
|
||||
data:params
|
||||
})
|
||||
}
|
||||
|
94
api/670/HBY670.js
Normal file
@ -0,0 +1,94 @@
|
||||
import request, { baseURL } from '@/utils/request'
|
||||
|
||||
function getdata(data,url,method){
|
||||
return new Promise((resolve,reject)=>{
|
||||
if(!url){
|
||||
reject('url为空');
|
||||
return;
|
||||
}
|
||||
if(!method){
|
||||
method='POST';
|
||||
}
|
||||
request({
|
||||
url: url,
|
||||
method: method,
|
||||
data:data
|
||||
}).then((res)=>{
|
||||
console.log("res=",res);
|
||||
resolve(res);
|
||||
}).catch(ex=>{
|
||||
reject(ex);
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
//人员信息设置
|
||||
function sendUsr(data){
|
||||
let url="/app/xinghan/device/registerPersonInfo";
|
||||
return getdata(data,url,"POST");
|
||||
}
|
||||
|
||||
//报警信息
|
||||
function warnMsg(data){
|
||||
let url="/app/xinghan/device/sendAlarmMessage"
|
||||
return getdata(data,url,"POST");
|
||||
}
|
||||
|
||||
//开机图片
|
||||
function sendPic(data){
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
const token = uni.getStorageSync('token');
|
||||
const clientid = uni.getStorageSync('clientID');
|
||||
let config = {
|
||||
header: {}
|
||||
};
|
||||
if (token) {
|
||||
config.header['Authorization'] = 'Bearer ' + token;
|
||||
config.header['clientid'] = clientid;
|
||||
}
|
||||
|
||||
uni.uploadFile({
|
||||
|
||||
url: baseURL + '/app/xinghan/device/uploadLogo',
|
||||
filePath: data.picPath,
|
||||
name: 'file',
|
||||
formData: {
|
||||
deviceId: data.deviceId,
|
||||
deviceImei: data.deviceImei
|
||||
},
|
||||
header: config.header,
|
||||
timeout: 600000,
|
||||
fail: (ex) => {
|
||||
console.log("上传视频失败" ,ex);
|
||||
reject(ex);
|
||||
},
|
||||
success: (res) => {
|
||||
console.log("上传完成", res);
|
||||
if(res.statusCode==200){
|
||||
resolve(JSON.parse(res.data));
|
||||
}else{
|
||||
reject(res);
|
||||
}
|
||||
|
||||
},
|
||||
complete: () => {
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export default{
|
||||
sendUsr:sendUsr,
|
||||
warnMsg:warnMsg,
|
||||
sendPic:sendPic
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
55
api/670/History.js
Normal file
@ -0,0 +1,55 @@
|
||||
import request, { baseURL } from '@/utils/request'
|
||||
|
||||
function getdata(data,url,method){
|
||||
return new Promise((resolve,reject)=>{
|
||||
if(!url){
|
||||
reject('url为空');
|
||||
return;
|
||||
}
|
||||
if(!method){
|
||||
method='POST';
|
||||
}
|
||||
request({
|
||||
url: url,
|
||||
method: method,
|
||||
data:data
|
||||
}).then((res)=>{
|
||||
console.log("res=",res);
|
||||
resolve(res);
|
||||
}).catch(ex=>{
|
||||
console.log("ex=",ex);
|
||||
reject(ex);
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
//获取开关机数据
|
||||
function getSwithData(data){
|
||||
let url="";
|
||||
return getdata(data,url,"POST");
|
||||
}
|
||||
|
||||
//报警信息
|
||||
function getWarnData(data){
|
||||
let url=""
|
||||
return getdata(data,url,"POST");
|
||||
}
|
||||
|
||||
//故障信息
|
||||
function getFaulData(data){
|
||||
let url=""
|
||||
return getdata(data,url,"POST");
|
||||
}
|
||||
|
||||
export default{
|
||||
getSwithData:getSwithData,
|
||||
getWarnData:getWarnData,
|
||||
getFaulData:getFaulData
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -2,17 +2,14 @@
|
||||
<view class="message-popup" :class="{ 'show': config.show }">
|
||||
|
||||
<view class="mask" @click="closeMenu" :class="{ 'show': config.show }"
|
||||
:style="{backgroundColor:config.maskBgColor,display:(config.showMask?'':'none')}"
|
||||
>
|
||||
:style="{backgroundColor:config.maskBgColor,display:(config.showMask?'':'none')}">
|
||||
|
||||
</view>
|
||||
<view class="bottom-slide-menu" :style="{ backgroundColor: config.bgColor }" :class="{ 'show': config.show }"
|
||||
@touchmove.stop.prevent>
|
||||
<view class="menu-header" :class="config.showHeader?'':'displayNone'">
|
||||
<view class="title" :style="{ color: config.textColor}">{{ config.title }}</view>
|
||||
<view class="close-icon" @click="closeMenu"
|
||||
:style="{display:(config.showClose?'':'none')}"
|
||||
>
|
||||
<view class="close-icon" @click="closeMenu" :style="{display:(config.showClose?'':'none')}">
|
||||
<image src="/static/Images/public/close.png" mode="aspectFit"></image>
|
||||
</view>
|
||||
</view>
|
||||
@ -29,7 +26,13 @@
|
||||
<view class="p100" :style="{backgroundColor:config.activeIndex==index?config.itemBgColor:'',
|
||||
justifyContent:config.textAlign
|
||||
}">
|
||||
<image v-if="item.icon" :src="item.icon" mode="aspectFit"></image>
|
||||
<view class="imgContent" :style="{
|
||||
height:config.itemHeight,
|
||||
width:config.itemHeight
|
||||
}">
|
||||
<image v-if="item.icon" :src="item.icon" mode="aspectFit"></image>
|
||||
</view>
|
||||
|
||||
<text>{{ item.text }}</text>
|
||||
</view>
|
||||
|
||||
@ -61,34 +64,34 @@
|
||||
config: {
|
||||
type: Object,
|
||||
default: () => ({
|
||||
show: false,//是否显示
|
||||
showHeader: false,//是否显示标头
|
||||
showMask:true,//是否显示mask
|
||||
showDivider: false,//是否在两个项之间显示分隔线
|
||||
showBtn: false,//是否显示底部按钮
|
||||
showClose:false,//是否显示右上角关闭按钮
|
||||
maskBgColor:'',//mask的颜色
|
||||
menuItems: [],//菜单项 包含icon text
|
||||
activeIndex: -1,//当前已选中的项编号
|
||||
bgColor: '#2a2a2a',//主体背景
|
||||
itemBgColor: '#3a3a3a',//各项被选中后的背景
|
||||
textColor: '#ffffffde',//各项的文字颜色
|
||||
textAlign: 'flex-start',//各项的文字居中方式
|
||||
title: '',//header的文字
|
||||
dividerColor: '#00000000',//分隔线颜色
|
||||
dividerThickness: '0rpx',//分隔线宽度
|
||||
dividerMargin: '10rpx',//分隔线距离两边的宽度
|
||||
itemHeight: '80rpx',//各项的调试
|
||||
btnBgColor: "#bbe600",//按钮颜色
|
||||
btnText: "确定",//按钮文字
|
||||
btnTextColor: "#000000",//按钮文字颜色
|
||||
|
||||
show: false, //是否显示
|
||||
showHeader: false, //是否显示标头
|
||||
showMask: true, //是否显示mask
|
||||
showDivider: false, //是否在两个项之间显示分隔线
|
||||
showBtn: false, //是否显示底部按钮
|
||||
showClose: false, //是否显示右上角关闭按钮
|
||||
maskBgColor: '', //mask的颜色
|
||||
menuItems: [], //菜单项 包含icon text
|
||||
activeIndex: -1, //当前已选中的项编号
|
||||
bgColor: '#2a2a2a', //主体背景
|
||||
itemBgColor: '#3a3a3a', //各项被选中后的背景
|
||||
textColor: '#ffffffde', //各项的文字颜色
|
||||
textAlign: 'flex-start', //各项的文字居中方式
|
||||
title: '', //header的文字
|
||||
dividerColor: '#00000000', //分隔线颜色
|
||||
dividerThickness: '0rpx', //分隔线宽度
|
||||
dividerMargin: '10rpx', //分隔线距离两边的宽度
|
||||
itemHeight: '80rpx', //各项的调试
|
||||
btnBgColor: "#bbe600", //按钮颜色
|
||||
btnText: "确定", //按钮文字
|
||||
btnTextColor: "#000000", //按钮文字颜色
|
||||
|
||||
})
|
||||
},
|
||||
|
||||
|
||||
},
|
||||
|
||||
|
||||
methods: {
|
||||
closeMenu() {
|
||||
|
||||
@ -100,19 +103,18 @@
|
||||
this.$emit('itemClick', item, index);
|
||||
},
|
||||
btnClick() {
|
||||
|
||||
|
||||
let item = null;
|
||||
let index = null;
|
||||
if (this.config.activeIndex > -1) {
|
||||
item = this.config.menuItems[this.config.activeIndex];
|
||||
}
|
||||
index = this.config.activeIndex;
|
||||
this.$emit('btnClick', item, index);
|
||||
this.$emit('btnClick', item, index);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<style>
|
||||
@ -126,7 +128,7 @@
|
||||
}
|
||||
|
||||
.p100 {
|
||||
width: 100%;
|
||||
width: calc(100% - 20rpx);
|
||||
height: 100%;
|
||||
border-radius: 8rpx;
|
||||
display: flex;
|
||||
@ -136,7 +138,8 @@
|
||||
justify-content: flex-start;
|
||||
align-items: center;
|
||||
box-sizing: border-box;
|
||||
padding: 0rpx 20rpx;
|
||||
padding: 0rpx 20rpx 0rpx 0rpx;
|
||||
margin-left: 20rpx;
|
||||
}
|
||||
|
||||
.displayNone {
|
||||
@ -151,7 +154,7 @@
|
||||
z-index: 9999;
|
||||
transition: transform 0.3s ease-out;
|
||||
transform: translateY(100%);
|
||||
border-radius: 16rpx 16rpx 0 0;
|
||||
border-radius: 32rpx 32rpx 0 0;
|
||||
box-shadow: 0 -2rpx 10rpx rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
@ -217,11 +220,24 @@
|
||||
width: 100%;
|
||||
box-sizing: border-box;
|
||||
position: relative;
|
||||
margin-bottom: 20rpx;
|
||||
}
|
||||
|
||||
.menu-item image {
|
||||
width: 40rpx;
|
||||
height: 40rpx;
|
||||
|
||||
}
|
||||
|
||||
.imgContent {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
flex-wrap: nowrap;
|
||||
align-content: center;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
background: #4a4a4a;
|
||||
border-radius: 10rpx;
|
||||
margin-right: 20rpx;
|
||||
}
|
||||
|
||||
|
@ -177,17 +177,19 @@ export default {
|
||||
return styles[this.type][styleType]
|
||||
},
|
||||
handleButtonClick() {
|
||||
console.log('[MessagePopup] Button clicked with value:', this.inputValue)
|
||||
|
||||
this.$emit('buttonClick', this.inputValue)
|
||||
},
|
||||
handleMaskClick() {
|
||||
console.log('[MessagePopup] Mask clicked')
|
||||
|
||||
this.$emit('maskClick')
|
||||
},
|
||||
closeClick(){
|
||||
|
||||
this.$emit('closePop')
|
||||
},
|
||||
handleCancelClick(){
|
||||
|
||||
this.$emit('cancelPop');
|
||||
},
|
||||
handleInput(e) {
|
||||
|
194
components/TextToHex/TextToHex.vue
Normal file
@ -0,0 +1,194 @@
|
||||
<template>
|
||||
<view>
|
||||
<canvas type="2d" canvas-id="reusableCanvas" :width="currentCanvasWidth" :height="currentCanvasHeight"
|
||||
class="offscreen-canvas"></canvas>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
name: "TextToHexV1",
|
||||
props: {
|
||||
txts: {
|
||||
type: Array,
|
||||
default: () => [],
|
||||
validator: (value) => value.every(item => typeof item === 'string')
|
||||
},
|
||||
fontSize: {
|
||||
type: Number,
|
||||
default: 16,
|
||||
validator: (value) => value > 0 && value <= 100
|
||||
},
|
||||
bgColor: {
|
||||
type: String,
|
||||
default: "#ffffff"
|
||||
},
|
||||
color: {
|
||||
type: String,
|
||||
default: "#000000"
|
||||
}
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
// 当前Canvas的宽高(动态调整)
|
||||
currentCanvasWidth: 0,
|
||||
currentCanvasHeight: 0,
|
||||
// Canvas上下文(复用)
|
||||
ctx: null
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
validTxts() {
|
||||
return this.txts.filter(line => line.trim() !== '');
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
// 初始化Canvas上下文(只创建一次)
|
||||
this.ctx = uni.createCanvasContext('reusableCanvas', this);
|
||||
},
|
||||
methods: {
|
||||
/**
|
||||
* 估算单行文本所需的Canvas宽度
|
||||
*/
|
||||
calcLineWidth(textLine) {
|
||||
return textLine.length * this.fontSize;
|
||||
},
|
||||
|
||||
/**
|
||||
* 清除Canvas内容
|
||||
*/
|
||||
clearCanvas() {
|
||||
this.ctx.setFillStyle(this.bgColor);
|
||||
this.ctx.fillRect(0, 0, this.currentCanvasWidth, this.currentCanvasHeight);
|
||||
},
|
||||
|
||||
/**
|
||||
* 复用单个Canvas处理所有文本行
|
||||
*/
|
||||
async drawAndGetPixels() {
|
||||
|
||||
let convertCharToMatrix=function(imageData) {
|
||||
// console.log("imgData=",imageData)
|
||||
let matrix = [];
|
||||
|
||||
// 逐行处理
|
||||
for (let y = 0; y < 16; y++) {
|
||||
let byte1 = 0,
|
||||
byte2 = 0;
|
||||
|
||||
// 每行16个像素,分为两个字节
|
||||
for (let x = 0; x < 16; x++) {
|
||||
// 计算像素在imageData中的索引 (RGBA格式)
|
||||
let index = (y * 16 + x) * 4;
|
||||
let red = imageData[index];
|
||||
|
||||
// 黑色像素(R值较低)视为1,白色视为0
|
||||
let isBlack = red < 128;
|
||||
|
||||
if (x < 8) {
|
||||
// 第一个字节(左8位)
|
||||
if (isBlack) {
|
||||
byte1 |= 0x80 >> x; // 从左到右设置位
|
||||
}
|
||||
} else {
|
||||
// 第二个字节(右8位)
|
||||
if (isBlack) {
|
||||
byte2 |= 0x80 >> (x - 8);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 将字节转换为两位十六进制字符串
|
||||
matrix.push('0x' + byte1.toString(16).padStart(2, '0').toUpperCase());
|
||||
matrix.push('0x' + byte2.toString(16).padStart(2, '0').toUpperCase());
|
||||
}
|
||||
|
||||
return matrix;
|
||||
}
|
||||
|
||||
let drawTxt=async (textLine)=> {
|
||||
let result = {};
|
||||
let ctx = this.ctx;
|
||||
|
||||
// 1. 动态调整Canvas尺寸
|
||||
this.currentCanvasWidth = this.calcLineWidth(textLine);
|
||||
this.currentCanvasHeight = this.fontSize;
|
||||
|
||||
// 2. 清空Canvas(绘制背景)
|
||||
this.clearCanvas();
|
||||
|
||||
// 3. 设置文字样式
|
||||
ctx.setFillStyle(this.color);
|
||||
ctx.setTextBaseline('middle');
|
||||
ctx.setFontSize(this.fontSize);
|
||||
ctx.font = `${this.fontSize}px "PingFang SC", PingFang SC, Arial, sans-serif`;
|
||||
|
||||
// 4. 绘制当前行文本
|
||||
let currentX = 0;
|
||||
let currentY = this.fontSize / 2;
|
||||
for (let j = 0; j < textLine.length; j++) {
|
||||
let char = textLine[j];
|
||||
ctx.fillText(char, currentX, currentY);
|
||||
// 按实际字符宽度计算间距
|
||||
let charWidth = ctx.measureText(char).width;
|
||||
currentX += charWidth;
|
||||
}
|
||||
|
||||
// 5. 异步绘制并获取像素数据(串行处理避免冲突)
|
||||
await new Promise((resolve, reject) => {
|
||||
ctx.draw(false, () => {
|
||||
uni.canvasGetImageData({
|
||||
canvasId: 'reusableCanvas',
|
||||
x: 0,
|
||||
y: 0,
|
||||
width: this.currentCanvasWidth,
|
||||
height: this.currentCanvasHeight,
|
||||
success: res => {
|
||||
|
||||
result={
|
||||
line: textLine,
|
||||
pixelData: res.data,
|
||||
width: this.currentCanvasWidth,
|
||||
height: this.currentCanvasHeight
|
||||
};
|
||||
resolve();
|
||||
},
|
||||
fail: err => {
|
||||
// console.error(`处理第${i+1}行失败:`, err);
|
||||
reject(err)
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
let arr = [];
|
||||
// 循环处理每行文本
|
||||
for (let i = 0; i < this.validTxts.length; i++) {
|
||||
|
||||
let linePixls = [];
|
||||
let item = this.validTxts[i];
|
||||
console.log("item=",item);
|
||||
for (var j = 0; j < item.length; j++) {
|
||||
let result = await drawTxt(item[j]);
|
||||
linePixls.push(convertCharToMatrix(result.pixelData));
|
||||
}
|
||||
console.log("hexs=",linePixls.join(","));
|
||||
arr.push(linePixls);
|
||||
}
|
||||
|
||||
return arr;
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.offscreen-canvas {
|
||||
position: fixed;
|
||||
left: -9999px;
|
||||
top: -9999px;
|
||||
visibility: hidden;
|
||||
}
|
||||
</style>
|
194
components/TextToHex/TextToHexV1.vue
Normal file
@ -0,0 +1,194 @@
|
||||
<template>
|
||||
<view>
|
||||
<canvas type="2d" canvas-id="reusableCanvas" :width="currentCanvasWidth" :height="currentCanvasHeight"
|
||||
class="offscreen-canvas"></canvas>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
name: "TextToHexV1",
|
||||
props: {
|
||||
txts: {
|
||||
type: Array,
|
||||
default: () => [],
|
||||
validator: (value) => value.every(item => typeof item === 'string')
|
||||
},
|
||||
fontSize: {
|
||||
type: Number,
|
||||
default: 16,
|
||||
validator: (value) => value > 0 && value <= 100
|
||||
},
|
||||
bgColor: {
|
||||
type: String,
|
||||
default: "#ffffff"
|
||||
},
|
||||
color: {
|
||||
type: String,
|
||||
default: "#000000"
|
||||
}
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
// 当前Canvas的宽高(动态调整)
|
||||
currentCanvasWidth: 0,
|
||||
currentCanvasHeight: 0,
|
||||
// Canvas上下文(复用)
|
||||
ctx: null
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
validTxts() {
|
||||
return this.txts.filter(line => line.trim() !== '');
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
// 初始化Canvas上下文(只创建一次)
|
||||
this.ctx = uni.createCanvasContext('reusableCanvas', this);
|
||||
},
|
||||
methods: {
|
||||
/**
|
||||
* 估算单行文本所需的Canvas宽度
|
||||
*/
|
||||
calcLineWidth(textLine) {
|
||||
return textLine.length * this.fontSize;
|
||||
},
|
||||
|
||||
/**
|
||||
* 清除Canvas内容
|
||||
*/
|
||||
clearCanvas() {
|
||||
this.ctx.setFillStyle(this.bgColor);
|
||||
this.ctx.fillRect(0, 0, this.currentCanvasWidth, this.currentCanvasHeight);
|
||||
},
|
||||
|
||||
/**
|
||||
* 复用单个Canvas处理所有文本行
|
||||
*/
|
||||
async drawAndGetPixels() {
|
||||
|
||||
let convertCharToMatrix=function(imageData) {
|
||||
// console.log("imgData=",imageData)
|
||||
let matrix = [];
|
||||
|
||||
// 逐行处理
|
||||
for (let y = 0; y < 16; y++) {
|
||||
let byte1 = 0,
|
||||
byte2 = 0;
|
||||
|
||||
// 每行16个像素,分为两个字节
|
||||
for (let x = 0; x < 16; x++) {
|
||||
// 计算像素在imageData中的索引 (RGBA格式)
|
||||
let index = (y * 16 + x) * 4;
|
||||
let red = imageData[index];
|
||||
|
||||
// 黑色像素(R值较低)视为1,白色视为0
|
||||
let isBlack = red < 128;
|
||||
|
||||
if (x < 8) {
|
||||
// 第一个字节(左8位)
|
||||
if (isBlack) {
|
||||
byte1 |= 0x80 >> x; // 从左到右设置位
|
||||
}
|
||||
} else {
|
||||
// 第二个字节(右8位)
|
||||
if (isBlack) {
|
||||
byte2 |= 0x80 >> (x - 8);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 将字节转换为两位十六进制字符串
|
||||
matrix.push('0x' + byte1.toString(16).padStart(2, '0').toUpperCase());
|
||||
matrix.push('0x' + byte2.toString(16).padStart(2, '0').toUpperCase());
|
||||
}
|
||||
|
||||
return matrix;
|
||||
}
|
||||
|
||||
let drawTxt=async (textLine)=> {
|
||||
let result = {};
|
||||
let ctx = this.ctx;
|
||||
|
||||
// 1. 动态调整Canvas尺寸
|
||||
this.currentCanvasWidth = this.calcLineWidth(textLine);
|
||||
this.currentCanvasHeight = this.fontSize;
|
||||
|
||||
// 2. 清空Canvas(绘制背景)
|
||||
this.clearCanvas();
|
||||
|
||||
// 3. 设置文字样式
|
||||
ctx.setFillStyle(this.color);
|
||||
ctx.setTextBaseline('middle');
|
||||
ctx.setFontSize(this.fontSize);
|
||||
ctx.font = `${this.fontSize}px "PingFang SC", PingFang SC, Arial, sans-serif`;
|
||||
|
||||
// 4. 绘制当前行文本
|
||||
let currentX = 0;
|
||||
let currentY = this.fontSize / 2;
|
||||
for (let j = 0; j < textLine.length; j++) {
|
||||
let char = textLine[j];
|
||||
ctx.fillText(char, currentX, currentY);
|
||||
// 按实际字符宽度计算间距
|
||||
let charWidth = ctx.measureText(char).width;
|
||||
currentX += charWidth;
|
||||
}
|
||||
|
||||
// 5. 异步绘制并获取像素数据(串行处理避免冲突)
|
||||
await new Promise((resolve, reject) => {
|
||||
ctx.draw(false, () => {
|
||||
uni.canvasGetImageData({
|
||||
canvasId: 'reusableCanvas',
|
||||
x: 0,
|
||||
y: 0,
|
||||
width: this.currentCanvasWidth,
|
||||
height: this.currentCanvasHeight,
|
||||
success: res => {
|
||||
|
||||
result={
|
||||
line: textLine,
|
||||
pixelData: res.data,
|
||||
width: this.currentCanvasWidth,
|
||||
height: this.currentCanvasHeight
|
||||
};
|
||||
resolve();
|
||||
},
|
||||
fail: err => {
|
||||
// console.error(`处理第${i+1}行失败:`, err);
|
||||
reject(err)
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
let arr = [];
|
||||
// 循环处理每行文本
|
||||
for (let i = 0; i < this.validTxts.length; i++) {
|
||||
|
||||
let linePixls = [];
|
||||
let item = this.validTxts[i];
|
||||
console.log("item=",item);
|
||||
for (var j = 0; j < item.length; j++) {
|
||||
let result = await drawTxt(item[j]);
|
||||
linePixls.push(convertCharToMatrix(result.pixelData));
|
||||
}
|
||||
console.log("hexs=",linePixls.join(","));
|
||||
arr.push(linePixls);
|
||||
}
|
||||
|
||||
return arr;
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.offscreen-canvas {
|
||||
position: fixed;
|
||||
left: -9999px;
|
||||
top: -9999px;
|
||||
visibility: hidden;
|
||||
}
|
||||
</style>
|
199
components/global-loading/global-loading.vue
Normal file
@ -0,0 +1,199 @@
|
||||
<template>
|
||||
<view v-if="visible" class="loading-container" @touchmove.stop.prevent="handleTouchMove">
|
||||
<view class="loading-content">
|
||||
<!-- 刻度点容器 -->
|
||||
<view class="clock-container">
|
||||
<view v-for="(dot, index) in dots" :key="index" class="clock-dot" :style="{
|
||||
transform: `rotate(${index * angle}deg) translateY(-${radius}px)`,
|
||||
backgroundColor: getDotColor(index),
|
||||
animationDuration: `${duration}ms`,
|
||||
animationDelay: `${index * (duration / dotsCount)}ms`
|
||||
}"></view>
|
||||
</view>
|
||||
|
||||
<!-- 提示文本 -->
|
||||
<text class="loading-text" :class="text?'':'displayNone'" :style="{ color: textColor }">{{ text }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
visible: false,
|
||||
dotsCount: 12,
|
||||
dotColors: ['#CEF231'],
|
||||
text: '请稍候...',//文本文字
|
||||
textColor: '#FFFFFFde',//文本颜色
|
||||
radius: 32,//圆的半径
|
||||
duration: 1200,//动画的播放速度
|
||||
colorIndex: 0
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
// 计算每个点之间的角度
|
||||
angle() {
|
||||
return 360 / this.dotsCount
|
||||
},
|
||||
// 生成刻度点数组
|
||||
dots() {
|
||||
return Array.from({
|
||||
length: this.dotsCount
|
||||
})
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
// 获取刻度点颜色(实现无限循环变色)
|
||||
getDotColor(index) {
|
||||
// 根据当前颜色索引和刻度点位置计算颜色
|
||||
const colorIndex = (index + this.colorIndex) % this.dotColors.length
|
||||
return this.dotColors[colorIndex]
|
||||
},
|
||||
|
||||
// 更新颜色索引(实现循环变色)
|
||||
updateColorIndex() {
|
||||
this.colorIndex = (this.colorIndex + 1) % this.dotColors.length
|
||||
},
|
||||
|
||||
// 显示loading
|
||||
show(options) {
|
||||
|
||||
if(!options){
|
||||
options={};
|
||||
}
|
||||
|
||||
this.update(options)
|
||||
this.visible = true
|
||||
|
||||
// 启动颜色循环
|
||||
if (!this.colorTimer) {
|
||||
this.colorTimer = setInterval(() => {
|
||||
this.updateColorIndex()
|
||||
}, this.duration / this.dotColors.length)
|
||||
}
|
||||
},
|
||||
|
||||
// 隐藏loading
|
||||
hide() {
|
||||
|
||||
this.visible = false
|
||||
// 清除颜色循环定时器
|
||||
if (this.colorTimer) {
|
||||
clearInterval(this.colorTimer)
|
||||
this.colorTimer = null
|
||||
}
|
||||
},
|
||||
|
||||
// 更新loading配置
|
||||
update(options) {
|
||||
if(!options){
|
||||
options={a:1};
|
||||
}
|
||||
Object.keys(options).forEach(key => {
|
||||
if (this[key] !== undefined) {
|
||||
this[key] = options[key]
|
||||
}
|
||||
})
|
||||
|
||||
// 如果更新了颜色数组,重置颜色索引
|
||||
if (options.dotColors) {
|
||||
this.colorIndex = 0
|
||||
}
|
||||
},
|
||||
|
||||
// 阻止触摸移动事件
|
||||
handleTouchMove() {}
|
||||
},
|
||||
|
||||
beforeDestroy() {
|
||||
// 组件销毁前清除定时器
|
||||
if (this.colorTimer) {
|
||||
clearInterval(this.colorTimer)
|
||||
this.colorTimer = null
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
/* 全屏遮罩层 */
|
||||
.loading-container {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background-color: #000000c2;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
z-index: 99999999999;
|
||||
pointer-events: auto;
|
||||
box-sizing: border-box;
|
||||
padding-bottom: 70%;
|
||||
}
|
||||
|
||||
/* 内容居中 */
|
||||
.loading-content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
transform: translateZ(0);
|
||||
/* 启用GPU加速 */
|
||||
margin-top: -150rpx;
|
||||
}
|
||||
|
||||
/* 刻度容器 */
|
||||
.clock-container {
|
||||
position: relative;
|
||||
width: 200rpx;
|
||||
height: 200rpx;
|
||||
|
||||
}
|
||||
|
||||
/* 单个刻度点 */
|
||||
.clock-dot {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
width: 6rpx;
|
||||
height: 30rpx;
|
||||
border-radius: 12rpx;
|
||||
/* margin-top: -4rpx;
|
||||
margin-left: -4rpx; */
|
||||
transform-origin: 0 0;
|
||||
animation: colorScale infinite ease-in-out;
|
||||
box-shadow: 0 0 8rpx rgba(0, 0, 0, 0.2);
|
||||
}
|
||||
|
||||
/* 刻度点动画 - 颜色和大小变化 */
|
||||
@keyframes colorScale {
|
||||
0% {
|
||||
opacity: 0.05;
|
||||
|
||||
}
|
||||
|
||||
100% {
|
||||
opacity: 1;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/* 提示文本 */
|
||||
.loading-text {
|
||||
font-size: 32rpx;
|
||||
font-weight: 400;
|
||||
letter-spacing: 1.4rpx;
|
||||
text-align: center;
|
||||
max-width: 80vw;
|
||||
|
||||
|
||||
font-family: 'PingFang SC';
|
||||
}
|
||||
|
||||
.displayNone{
|
||||
display: none !important;
|
||||
}
|
||||
</style>
|
@ -6,7 +6,7 @@ const config = {
|
||||
API_PREFIX: '',
|
||||
// MQTT 配置
|
||||
MQTT_HOST: '47.120.79.150',
|
||||
MQTT_PORT: 8083,
|
||||
MQTT_PORT: 9083,
|
||||
MQTT_USERNAME: 'admin',
|
||||
MQTT_PASSWORD: '#YtvpSfCNG'
|
||||
},
|
||||
@ -16,7 +16,7 @@ const config = {
|
||||
API_PREFIX: '',
|
||||
// MQTT 配置
|
||||
MQTT_HOST: '47.120.79.150',
|
||||
MQTT_PORT: 8083,
|
||||
MQTT_PORT: 9083,
|
||||
MQTT_USERNAME: 'admin',
|
||||
MQTT_PASSWORD: '#YtvpSfCNG'
|
||||
}
|
||||
|
8
main.js
@ -1,15 +1,15 @@
|
||||
import App from './App'
|
||||
|
||||
// 引入 uView UI
|
||||
//// 引入 uView UI
|
||||
import uView from 'vk-uview-ui';
|
||||
import bleTool from '@/store/BLETools.js';
|
||||
|
||||
|
||||
// #ifndef VUE3
|
||||
import Vue from 'vue'
|
||||
import store from './store/store';
|
||||
import './uni.promisify.adaptor'
|
||||
Vue.config.productionTip = false
|
||||
Vue.prototype.$bleTool = bleTool;
|
||||
|
||||
App.mpType = 'app'
|
||||
const app = new Vue({
|
||||
store,
|
||||
@ -25,7 +25,7 @@ import {
|
||||
} from 'vue'
|
||||
export function createApp() {
|
||||
const app = createSSRApp(App)
|
||||
app.config.globalProperties.$bleTool = bleTool;
|
||||
|
||||
// 使用 uView UI
|
||||
app.use(uView)
|
||||
return {
|
||||
|
@ -2,7 +2,7 @@
|
||||
"name" : "JingQuan",
|
||||
"appid" : "__UNI__A21EF43",
|
||||
"description" : "设备管控",
|
||||
"versionName" : "1.0.0",
|
||||
"versionName" : "1.0.9",
|
||||
"versionCode" : "100",
|
||||
"transformPx" : false,
|
||||
/* 5+App特有相关 */
|
||||
@ -85,7 +85,7 @@
|
||||
"appkey_ios" : "065c43f02c7b627a74ad7dd23b16bb4f",
|
||||
"appkey_android" : "d7d852dbda2b95f6f796fb9a711a9fee"
|
||||
},
|
||||
"customStyle": true
|
||||
"customStyle" : true
|
||||
},
|
||||
"oauth" : {},
|
||||
"push" : {}
|
||||
|
10
package-lock.json
generated
@ -8,6 +8,7 @@
|
||||
"axios": "^1.9.0",
|
||||
"cordova-sqlite-storage": "^7.0.0",
|
||||
"iconv-lite": "^0.6.3",
|
||||
"mescroll-uni": "^1.3.7",
|
||||
"paho-mqtt": "^1.1.0",
|
||||
"text-encoding": "^0.7.0",
|
||||
"vk-uview-ui": "^1.5.2"
|
||||
@ -268,6 +269,12 @@
|
||||
"node": ">= 0.4"
|
||||
}
|
||||
},
|
||||
"node_modules/mescroll-uni": {
|
||||
"version": "1.3.7",
|
||||
"resolved": "https://registry.npmjs.org/mescroll-uni/-/mescroll-uni-1.3.7.tgz",
|
||||
"integrity": "sha512-1pQMtGA+iVRKhfJZZNXdBx05NnthIk6zm3hRbumswSA54eaKOMgpUDb9AQ2+rRdXmS6kLkEYSbW/fkb7/IyoAg==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/mime-db": {
|
||||
"version": "1.52.0",
|
||||
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz",
|
||||
@ -290,7 +297,8 @@
|
||||
"node_modules/paho-mqtt": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/paho-mqtt/-/paho-mqtt-1.1.0.tgz",
|
||||
"integrity": "sha512-KPbL9KAB0ASvhSDbOrZBaccXS+/s7/LIofbPyERww8hM5Ko71GUJQ6Nmg0BWqj8phAIT8zdf/Sd/RftHU9i2HA=="
|
||||
"integrity": "sha512-KPbL9KAB0ASvhSDbOrZBaccXS+/s7/LIofbPyERww8hM5Ko71GUJQ6Nmg0BWqj8phAIT8zdf/Sd/RftHU9i2HA==",
|
||||
"license": "EPL-1.0"
|
||||
},
|
||||
"node_modules/proxy-from-env": {
|
||||
"version": "1.1.0",
|
||||
|
@ -3,6 +3,7 @@
|
||||
"axios": "^1.9.0",
|
||||
"cordova-sqlite-storage": "^7.0.0",
|
||||
"iconv-lite": "^0.6.3",
|
||||
"mescroll-uni": "^1.3.7",
|
||||
"paho-mqtt": "^1.1.0",
|
||||
"text-encoding": "^0.7.0",
|
||||
"vk-uview-ui": "^1.5.2"
|
||||
|
111
pages.json
@ -8,13 +8,11 @@
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
|
||||
|
||||
{
|
||||
"path": "pages/common/index/index",
|
||||
"style": {
|
||||
"navigationStyle": "custom"
|
||||
"navigationStyle": "custom",
|
||||
"enablePullDownRefresh": true
|
||||
}
|
||||
},
|
||||
{
|
||||
@ -38,7 +36,8 @@
|
||||
{
|
||||
"path": "pages/common/send/index",
|
||||
"style": {
|
||||
"navigationBarTitleText": "发送信息"
|
||||
"navigationBarTitleText": "发送信息",
|
||||
"enablePullDownRefresh": true
|
||||
}
|
||||
},
|
||||
{
|
||||
@ -68,7 +67,8 @@
|
||||
{
|
||||
"path": "pages/6170/callPolice/index",
|
||||
"style": {
|
||||
"navigationBarTitleText": "报警"
|
||||
"navigationBarTitleText": "报警",
|
||||
"enablePullDownRefresh": true
|
||||
}
|
||||
},
|
||||
|
||||
@ -184,8 +184,105 @@
|
||||
"style": {
|
||||
"navigationBarTitleText": "历史记录"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "pages/210/call/index",
|
||||
"style": {
|
||||
"navigationBarTitleText": "呼叫"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "pages/BlueTooth/ModeSetting/VideoSend",
|
||||
"style": {
|
||||
"navigationBarTitleText": "发送视频"
|
||||
|
||||
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "pages/BlueTooth/ModeSetting/VideoSend_1",
|
||||
"style": {
|
||||
"navigationBarTitleText": "发送视频"
|
||||
|
||||
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "pages/BlueTooth/ModeSetting/VideoSend_670",
|
||||
"style": {
|
||||
"navigationBarTitleText": "发送视频"
|
||||
|
||||
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "pages/BlueTooth/ModeSetting/HBY650",
|
||||
"style": {
|
||||
"navigationBarTitleText": "HBY650"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "pages/BlueTooth/ModeSetting/HBY650_1",
|
||||
"style": {
|
||||
"navigationBarTitleText": "HBY650"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "pages/BlueTooth/ModeSetting/ModeSetting",
|
||||
"style": {
|
||||
"navigationBarTitleText": "7307-0.96TFT"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "pages/BlueTooth/ModeSetting/update",
|
||||
"style": {
|
||||
"navigationBarTitleText": "版本更新"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "pages/BlueTooth/ModeSetting/HBY6155",
|
||||
"style": {
|
||||
"navigationBarTitleText": "HBY6155"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "pages/BlueTooth/ModeSetting/HBY6155V1",
|
||||
"style": {
|
||||
"navigationBarTitleText": "HBY6155_V1"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "pages/BlueTooth/ModeSetting/HBY670V1",
|
||||
"style": {
|
||||
"navigationBarTitleText": "HBY670"
|
||||
}
|
||||
}, {
|
||||
"path": "pages/BlueTooth/ModeSetting/index",
|
||||
"style": {
|
||||
"navigationBarTitleText": "设备类型"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "pages/670/HBY670",
|
||||
"style": {
|
||||
"navigationBarTitleText": "HBY670",
|
||||
"navigationStyle": "custom"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "pages/650/HBY650",
|
||||
"style": {
|
||||
"navigationBarTitleText": "HBY650"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path" : "pages/670/History",
|
||||
"style" :
|
||||
{
|
||||
"navigationBarTitleText" : "历史记录"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
],
|
||||
"tabBar": {
|
||||
|
311
pages/210/call/index.vue
Normal file
@ -0,0 +1,311 @@
|
||||
<template>
|
||||
<view class="container">
|
||||
<!-- 设备列表 -->
|
||||
<scroll-view class="device-list" scroll-y>
|
||||
<view class="device-card" v-for="(item, index) in deviceList" :key="index" @click="toggleSelect(index)">
|
||||
<!-- 复选框 -->
|
||||
<view class="checkbox" :class="{ checked: item.checked }">
|
||||
<uni-icons v-if="item.checked" type="checkmarkempty" size="18" color="rgb(0, 0, 0)"></uni-icons>
|
||||
</view>
|
||||
<!-- 设备信息 -->
|
||||
<view class="device-content">
|
||||
<view class="device-header">
|
||||
<view class="deviceIMG">
|
||||
<image :src="item.devicePic" class="IMG" mode="aspectFit"></image>
|
||||
</view>
|
||||
<view class="device-name">
|
||||
<view>设备:{{item.deviceName}}</view>
|
||||
<view class="ID">
|
||||
<view class="ID">ID:{{item.deviceImei}}</view>
|
||||
<view class="onlines" v-if="item.onlineStatus==1">在线</view>
|
||||
<!-- 离线状态 -->
|
||||
<view class="unlines" v-if="item.onlineStatus==0">离线</view>
|
||||
<view>电量:{{item.battery || '0'}}%</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<view class="editInfmation">
|
||||
<button class="login-btn" @click="callMessage">呼叫设备</button>
|
||||
</view>
|
||||
</scroll-view>
|
||||
<!-- 成功提示弹框 -->
|
||||
<CustomPopup :show="showPopupFlag" :title="popupTitle" :message="popupMessage"
|
||||
icon="/static/images/common/bj_1.png" :confirm-text="popupConfirmText" :show-cancel="false"
|
||||
@confirm="onPopupConfirm" />
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import CustomPopup from '@/components/CustomPopup/CustomPopup.vue'
|
||||
import {
|
||||
deviceInfo,
|
||||
} from '@/api/common/index.js'
|
||||
import {
|
||||
deviceSendMessage
|
||||
} from '@/api/6170/deviceControl.js'
|
||||
export default {
|
||||
components: {
|
||||
CustomPopup
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
deviceList: [],
|
||||
showPopupFlag: false,
|
||||
popupTitle: '',
|
||||
popupMessage: '确定要呼叫所选设备!',
|
||||
popupConfirmText: '确认'
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
toggleSelect(index) {
|
||||
this.deviceList[index].checked = !this.deviceList[index].checked
|
||||
this.$forceUpdate()
|
||||
},
|
||||
// 获取设备列表
|
||||
getData(deviceType) {
|
||||
this.loading = true;
|
||||
let data = {
|
||||
pageNum: 1,
|
||||
pageSize: 20,
|
||||
deviceType: deviceType
|
||||
}
|
||||
deviceInfo(data).then((res) => {
|
||||
if (res.code == 200) {
|
||||
const newDevices = res.rows.map(device => ({
|
||||
...device,
|
||||
showConfirm: false,
|
||||
checked: false
|
||||
}));
|
||||
this.total = res.total;
|
||||
this.deviceList = newDevices
|
||||
}
|
||||
}).finally(() => {
|
||||
this.loading = false;
|
||||
});
|
||||
},
|
||||
//确认呼叫设备
|
||||
callMessage() {
|
||||
const selectedDevices = this.deviceList.filter(item => item.checked)
|
||||
if (selectedDevices.length === 0) {
|
||||
uni.showToast({
|
||||
title: '请选择一个设备',
|
||||
icon: 'none'
|
||||
});
|
||||
return;
|
||||
}
|
||||
this.showPopupFlag = true
|
||||
},
|
||||
//弹框确认
|
||||
onPopupConfirm() {
|
||||
const selectedDevices = this.deviceList.filter(item => item.checked)
|
||||
const deviceIds = selectedDevices.map(item => item.id);
|
||||
let data = {
|
||||
deviceIds: deviceIds
|
||||
}
|
||||
deviceSendMessage(data).then((res) => {
|
||||
if (res.code == 200) {
|
||||
this.showPopupFlag = false
|
||||
uni.navigateBack()
|
||||
} else {
|
||||
uni.showToast({
|
||||
title: res.msg,
|
||||
icon: 'none'
|
||||
});
|
||||
}
|
||||
})
|
||||
},
|
||||
},
|
||||
onLoad(options) {
|
||||
const eventChannel = this.getOpenerEventChannel();
|
||||
// 监听 'deviceSend' 事件,获取传过来的数据
|
||||
eventChannel.on('deviceCall', (data) => {
|
||||
console.log('Received detail data:', data);
|
||||
this.getData(data.data)
|
||||
});
|
||||
// 如果需要向调用页面返回数据,可以触发 'ack' 事件
|
||||
eventChannel.emit('ack', {})
|
||||
},
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.container {
|
||||
min-height: 100vh;
|
||||
background-color: rgb(18, 18, 18);
|
||||
box-sizing: border-box;
|
||||
overflow-x: hidden;
|
||||
|
||||
}
|
||||
|
||||
.device-list {
|
||||
flex: 1;
|
||||
padding: 0 20rpx;
|
||||
|
||||
}
|
||||
|
||||
.device-card {
|
||||
position: relative;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
width: 95%;
|
||||
margin-bottom: 20rpx;
|
||||
}
|
||||
|
||||
.checkbox {
|
||||
width: 40rpx;
|
||||
height: 40rpx;
|
||||
border: 2rpx solid rgba(255, 255, 255, 0.5);
|
||||
margin-right: 20rpx;
|
||||
border-radius: 4rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.checkbox.checked {
|
||||
background-color: rgb(187, 230, 0);
|
||||
border-color: rgb(187, 230, 0);
|
||||
}
|
||||
|
||||
.device-content {
|
||||
background-color: rgb(26, 26, 26);
|
||||
border-radius: 16rpx;
|
||||
position: relative;
|
||||
/* display: flex; */
|
||||
align-items: center;
|
||||
padding: 20rpx;
|
||||
width: 95%;
|
||||
}
|
||||
|
||||
.device-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
margin-bottom: 15rpx;
|
||||
}
|
||||
|
||||
.device-name {
|
||||
font-size: 32rpx;
|
||||
color: rgba(255, 255, 255, 0.87);
|
||||
margin-left: 12rpx;
|
||||
line-height: 50rpx;
|
||||
width: 83%;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.ID {
|
||||
color: rgba(255, 255, 255, 0.6);
|
||||
font-size: 26rpx;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.device-status {
|
||||
width: 122rpx;
|
||||
height: 52rpx;
|
||||
font-size: 26rpx;
|
||||
border-radius: 0px 8px 0px 8px;
|
||||
background-color: rgb(42, 42, 42);
|
||||
position: absolute;
|
||||
top: 0rpx;
|
||||
right: 0rpx;
|
||||
text-align: center;
|
||||
line-height: 52rpx;
|
||||
}
|
||||
|
||||
.online {
|
||||
color: rgb(187, 230, 0);
|
||||
}
|
||||
|
||||
.unline {
|
||||
color: rgba(255, 255, 255, 0.4);
|
||||
}
|
||||
|
||||
.device-info {
|
||||
display: flex;
|
||||
justify-content: space-evenly;
|
||||
font-size: 26rpx;
|
||||
color: rgba(255, 255, 255, 0.87);
|
||||
padding-top: 10rpx;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.deviceIMG {
|
||||
width: 100rpx;
|
||||
height: 100rpx;
|
||||
border-radius: 16rpx;
|
||||
position: relative;
|
||||
background-color: rgba(42, 42, 42, 0.6);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.IMG {
|
||||
width: 68rpx;
|
||||
height: 50rpx;
|
||||
margin-left: 17%;
|
||||
}
|
||||
|
||||
.onlines {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.onlines::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
width: 15rpx;
|
||||
height: 15rpx;
|
||||
background: rgb(0, 171, 103);
|
||||
border-radius: 50%;
|
||||
top: 20rpx;
|
||||
left: -20rpx
|
||||
}
|
||||
|
||||
.unlines {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.unlines::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
width: 15rpx;
|
||||
height: 15rpx;
|
||||
background: rgba(255, 255, 255, 0.4);
|
||||
border-radius: 50%;
|
||||
top: 20rpx;
|
||||
left: -20rpx
|
||||
}
|
||||
|
||||
.line {
|
||||
width: 2rpx;
|
||||
height: 24rpx;
|
||||
background: linear-gradient(90deg,
|
||||
rgba(0, 0, 0, 0) 0%,
|
||||
rgb(255, 255, 255) 50%,
|
||||
rgba(255, 255, 255, 0) 100%);
|
||||
margin-top: 12rpx;
|
||||
}
|
||||
|
||||
.ql-editor {
|
||||
color: rgba(255, 255, 255, 0.6);
|
||||
font-size: 30rpx;
|
||||
}
|
||||
|
||||
.editInfmation {
|
||||
padding: 20rpx;
|
||||
position: fixed;
|
||||
bottom: 50rpx;
|
||||
box-sizing: border-box;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.login-btn {
|
||||
margin-top: 30rpx;
|
||||
background-color: rgb(187, 230, 0);
|
||||
color: rgb(35, 35, 35);
|
||||
border-radius: 50rpx;
|
||||
width: 90%;
|
||||
}
|
||||
</style>
|
@ -128,9 +128,9 @@
|
||||
</view> -->
|
||||
<view class="mode-section">
|
||||
<view class="mode-buttons">
|
||||
<view v-for="(item, index) in modeItems" :key="index" class="mode-v1" :class="{ 'active-mode': selectedIndex === index }">
|
||||
<view class="mode-v2"
|
||||
@click="handleModeClick(index)">
|
||||
<view v-for="(item, index) in modeItems" :key="index" class="mode-v1"
|
||||
:class="{ 'active-mode': selectedIndex === index }">
|
||||
<view class="mode-v2" @click="handleModeClick(index)">
|
||||
<image :src="item.image" class="setIMG" mode="aspectFit"></image>
|
||||
<view>
|
||||
<view class="battery-v2">{{ item.title }}</view>
|
||||
@ -249,23 +249,31 @@
|
||||
<script>
|
||||
// 弹框配置中心
|
||||
const POPUP_CONFIGS = {
|
||||
// 人员信息发送
|
||||
person: {
|
||||
config: {
|
||||
icon: '/static/images/common/sendSucc.png',
|
||||
message: '信息发送成功',
|
||||
showCancel: false
|
||||
},
|
||||
confirm() {
|
||||
return true; // 直接关闭
|
||||
}
|
||||
|
||||
},
|
||||
// 开机log
|
||||
// 上传开机log
|
||||
logo: {
|
||||
config: {
|
||||
icon: '/static/images/common/upload.png',
|
||||
message: '上传成功',
|
||||
showCancel: false
|
||||
},
|
||||
confirm() {
|
||||
return true; // 直接关闭
|
||||
}
|
||||
|
||||
},
|
||||
// 电量低于20%.提示框
|
||||
bettery: {
|
||||
config: {
|
||||
title: '设备电量低于20%',
|
||||
@ -276,24 +284,24 @@
|
||||
confirmBtnBg: 'rgba(224, 52, 52, 1)',
|
||||
showCancel: true
|
||||
},
|
||||
onConfirm() {
|
||||
console.log('确认按钮');
|
||||
confirm() {
|
||||
return true; // 直接关闭
|
||||
}
|
||||
},
|
||||
|
||||
// 解除报警关闭的那个提示
|
||||
cancel: {
|
||||
config: {
|
||||
titleColor: 'rgba(224, 52, 52, 1)',
|
||||
icon: '/static/images/common/svg.png',
|
||||
icon: '/static/images/6170/svg.png',
|
||||
popupBorder: '1rpx solid rgba(224, 52, 52, 0.3)',
|
||||
confirmBtnBg: 'rgba(224, 52, 52, 1)',
|
||||
showCancel: true //取消按钮
|
||||
},
|
||||
onConfirm() {
|
||||
confirm() {
|
||||
console.log('解除报警确认');
|
||||
}
|
||||
},
|
||||
// 手动报警弹框
|
||||
del: {
|
||||
config: {
|
||||
message: '确定开启报警?',
|
||||
@ -302,8 +310,26 @@
|
||||
confirmBtnBg: 'rgba(255, 200, 78, 1)',
|
||||
showCancel: true
|
||||
},
|
||||
onConfirm() {
|
||||
console.log('删除确认');
|
||||
confirm() {
|
||||
return 'alarmCountdown'; //点击确认,再次弹框,解除报警,再次报警的类型
|
||||
}
|
||||
},
|
||||
// 手动报警再次弹框 再次报警,解除报警指令
|
||||
alarmCountdown: {
|
||||
config: {
|
||||
title: '报警倒计时',
|
||||
icon: '/static/images/6170/svg.png',
|
||||
message: '59秒',
|
||||
popupBorder: '1rpx solid rgba(224, 52, 52, 1)',
|
||||
confirmBtnBg: 'rgba(224, 52, 52, 1)',
|
||||
cancelBtnColor:"rgba(224, 52, 52, 1)",
|
||||
confirmBtnColor:"rgba(255, 255, 255, 0.87)",
|
||||
confirmText: '解除报警',
|
||||
cancelText:"再次报警",
|
||||
showCancel: true //取消按钮
|
||||
},
|
||||
confirm() {
|
||||
console.log('解除报警确认');
|
||||
}
|
||||
},
|
||||
// 自动报警
|
||||
@ -320,9 +346,8 @@
|
||||
confirmBtnColor: "rgba(255, 255, 255, 0.87)",
|
||||
showCancel: false,
|
||||
},
|
||||
onConfirm() {
|
||||
console.log('自动报警确认');
|
||||
// 这里可以添加自动报警的逻辑
|
||||
confirm() {
|
||||
console.log('自动报警解除报警的弹框');
|
||||
}
|
||||
}
|
||||
|
||||
@ -437,12 +462,19 @@
|
||||
this.currentPopup = {
|
||||
show: true,
|
||||
config: POPUP_CONFIGS[type].config,
|
||||
callback: POPUP_CONFIGS[type].onConfirm
|
||||
callback: POPUP_CONFIGS[type].confirm
|
||||
}
|
||||
},
|
||||
handleConfirm() {
|
||||
this.currentPopup.show = false;
|
||||
console.log('这是点击了确认');
|
||||
if (this.currentPopup.callback) {
|
||||
const nextPopupType = this.currentPopup.callback(); // 执行回调并获取下一个弹框类型
|
||||
this.currentPopup.show = false; // 关闭当前弹框
|
||||
if (nextPopupType) {
|
||||
this.showPopup(nextPopupType); // 打开下一个弹框
|
||||
}
|
||||
} else {
|
||||
this.currentPopup.show = false; // 默认关闭
|
||||
}
|
||||
},
|
||||
// 统一处理取消
|
||||
handleCancel() {
|
||||
@ -780,7 +812,7 @@
|
||||
uni.showLoading({
|
||||
title: '加载中...'
|
||||
})
|
||||
eventChannel.on('deviceControl', (data) => {
|
||||
eventChannel.on('detailData', (data) => {
|
||||
console.log(data, '这是传过来的惨呼啊');
|
||||
this.itemInfo = data.data;
|
||||
this.deviceID = data.data.id;
|
||||
@ -888,7 +920,8 @@
|
||||
.mode-v1.active-mode .battery-v2 {
|
||||
color: #BBE600 !important;
|
||||
}
|
||||
.mode-v1.active-mode .mode-v3{
|
||||
|
||||
.mode-v1.active-mode .mode-v3 {
|
||||
color: #BBE600 !important;
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
<view>
|
||||
<view class="device-page">
|
||||
<view class="sendFlex">
|
||||
<view class="Sendmessage" @click="location">呼叫</view>
|
||||
<view class="Sendmessage" @click="call">呼叫</view>
|
||||
<view class="Sendmessage" @click="handleSend">发送信息</view>
|
||||
</view>
|
||||
<scroll-view class="device-list" scroll-y @scrolltolower="onScrollToLower" :lower-threshold="100"
|
||||
@ -79,6 +79,20 @@
|
||||
}
|
||||
})
|
||||
},
|
||||
// 呼叫功能
|
||||
call(){
|
||||
uni.navigateTo({
|
||||
url: '/pages/210/call/index',
|
||||
events: {
|
||||
ack: function(data) {}
|
||||
},
|
||||
success: (res) => {
|
||||
res.eventChannel.emit('deviceCall', {
|
||||
data:this.deviceType
|
||||
});
|
||||
}
|
||||
})
|
||||
}
|
||||
},
|
||||
onShow() {
|
||||
this.getData()
|
||||
|
@ -25,18 +25,21 @@
|
||||
onLoad: function(option) {
|
||||
const eventChannel = this.getOpenerEventChannel();
|
||||
var these = this;
|
||||
eventChannel.on('checkImg', function(data) {
|
||||
eventChannel.on('checkImg', (data)=> {
|
||||
console.log("我收到你的消息了,消息内容是:" + JSON.stringify(data));
|
||||
these.src = data.data;
|
||||
this.src = data.data;
|
||||
console.log("我收到你的消息了,消息内容是:",data);
|
||||
})
|
||||
},
|
||||
methods: {
|
||||
handleCrop(e) {
|
||||
|
||||
var these = this;
|
||||
|
||||
this.Statu = true;
|
||||
console.log("裁剪完成");
|
||||
console.log(e.tempFilePath);
|
||||
|
||||
//
|
||||
const ctx = uni.createCanvasContext('splashCanvas', this);
|
||||
ctx.drawImage(
|
||||
e.tempFilePath,
|
||||
@ -53,11 +56,12 @@
|
||||
height: 80,
|
||||
success: (res) => {
|
||||
// 处理像素数据并发送
|
||||
const eventChannel = these.getOpenerEventChannel();
|
||||
console.log("res.data.length="+res.data.length);
|
||||
// this.processAndSendImageData(res.data).then(
|
||||
// resolve).catch(reject);
|
||||
const eventChannel = these.getOpenerEventChannel();
|
||||
eventChannel.emit('ImgCutOver',res.data);
|
||||
|
||||
|
||||
eventChannel.emit('ImgCutOver',{piexls:res.data,picPath:e.tempFilePath});
|
||||
|
||||
uni.navigateBack();
|
||||
},
|
||||
fail: (err) => {
|
||||
|
@ -143,7 +143,7 @@
|
||||
url: "/pages/6170/deviceControl/index",
|
||||
success: (res) => {
|
||||
// 页面跳转成功后的回调函数
|
||||
res.eventChannel.emit('deviceControl', {
|
||||
res.eventChannel.emit('detailData', {
|
||||
data: item,
|
||||
apiType: 'listB' // 自定义标识 // 自定义标识,详情哪里根据这个参数不同信息
|
||||
});
|
||||
@ -249,14 +249,10 @@
|
||||
},
|
||||
onLoad() {
|
||||
this.onIntall()
|
||||
// 绑定页面做了监听,新增成功,刷新页面
|
||||
uni.$on('refreshDeviceList', () => {
|
||||
this.onIntall()
|
||||
});
|
||||
},
|
||||
beforeDestroy() {
|
||||
// 组件销毁前移除监听器
|
||||
uni.$off('refreshDeviceList');
|
||||
|
||||
},
|
||||
}
|
||||
</script>
|
||||
|
@ -3,9 +3,10 @@
|
||||
<!-- 设备列表 -->
|
||||
<view class="allSelect" @click="selectAll"> 全选</view>
|
||||
<scroll-view class="device-list" scroll-y>
|
||||
<view class="device-card" v-for="(item, index) in deviceList" :key="index" @click="toggleSelect(index)">
|
||||
<view class="device-card" v-for="(item, index) in deviceList" :key="index"
|
||||
@click="item.onlineStatus === 1 ? toggleSelect(index) : null">
|
||||
<!-- 复选框 -->
|
||||
<view class="checkbox" :class="{ checked: item.checked }">
|
||||
<view class="checkbox" :class="{ checked: item.checked, disabled: item.onlineStatus !== 1 }">
|
||||
<uni-icons v-if="item.checked" type="checkmarkempty" size="18" color="rgb(0, 0, 0)"></uni-icons>
|
||||
</view>
|
||||
<!-- 设备信息 -->
|
||||
@ -15,13 +16,13 @@
|
||||
<image :src="item.devicePic" class="IMG" mode="aspectFit"></image>
|
||||
</view>
|
||||
<view class="device-name">
|
||||
<view>设备:{{item.deviceName}}</view>
|
||||
<view>设备:{{ item.deviceName }}</view>
|
||||
<view class="ID">
|
||||
<view class="ID">ID:{{item.deviceImei}}</view>
|
||||
<view class="onlines" v-if="item.onlineStatus==1">在线</view>
|
||||
<view class="ID">ID:{{ item.deviceImei }}</view>
|
||||
<view class="onlines" v-if="item.onlineStatus == 1">在线</view>
|
||||
<!-- 离线状态 -->
|
||||
<view class="unlines" v-if="item.onlineStatus==0">离线</view>
|
||||
<view>电量:{{item.battery || '0'}}%</view>
|
||||
<view class="unlines" v-if="item.onlineStatus == 0">离线</view>
|
||||
<view>电量:{{ item.battery || '0' }}%</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
@ -47,12 +48,19 @@
|
||||
|
||||
<script>
|
||||
import CustomPopup from '@/components/CustomPopup/CustomPopup.vue'
|
||||
import {
|
||||
generateShortId,
|
||||
getdeviceSTatus
|
||||
} from '@/utils/function.js';
|
||||
import {
|
||||
deviceInfo,
|
||||
} from '@/api/common/index.js'
|
||||
import {
|
||||
deviceSendAlarmMessage
|
||||
} from '@/api/6170/callPolice.js'
|
||||
import {
|
||||
deviceRealTimeStatus //设备状态
|
||||
} from '@/api/6170/deviceControl.js'
|
||||
export default {
|
||||
components: {
|
||||
CustomPopup
|
||||
@ -60,13 +68,13 @@
|
||||
data() {
|
||||
return {
|
||||
deviceList: [],
|
||||
messageToSend: '', //发送信息
|
||||
showPopupFlag: false,
|
||||
popupTitle: '',
|
||||
popupMessage: '确认要对所选设备开启强制报警?',
|
||||
popupConfirmText: '确认',
|
||||
popupType: 'force', // 'force' or 'cancel'
|
||||
pendingAlarmAction: ''
|
||||
pendingAlarmAction: '',
|
||||
sendInfo: ''
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
@ -97,7 +105,7 @@
|
||||
this.loading = true;
|
||||
let data = {
|
||||
pageNum: 1,
|
||||
pageSize: 20,
|
||||
pageSize: 50,
|
||||
deviceType: deviceType
|
||||
}
|
||||
deviceInfo(data).then((res) => {
|
||||
@ -117,7 +125,6 @@
|
||||
// 强制报警
|
||||
forceAlarm() {
|
||||
const selectedDevices = this.deviceList.filter(item => item.checked)
|
||||
const deviceIds = selectedDevices.map(item => item.id);
|
||||
if (selectedDevices.length === 0) {
|
||||
uni.showToast({
|
||||
title: '请选择一个设备',
|
||||
@ -146,18 +153,50 @@
|
||||
this.showPopupFlag = true;
|
||||
this.pendingAlarmAction = 0
|
||||
},
|
||||
sendAlarmCommand(type) {
|
||||
// 确认
|
||||
async sendAlarmCommand() {
|
||||
const selectedDevices = this.deviceList.filter(item => item.checked);
|
||||
const deviceIds = selectedDevices.map(item => item.id);
|
||||
const deviceImeiList = selectedDevices.map(item => item.deviceImei);
|
||||
const isAlarming = this.pendingAlarmAction == 1;
|
||||
try {
|
||||
|
||||
let data = {
|
||||
deviceIds: deviceIds,
|
||||
instructValue: this.pendingAlarmAction, // '强制或者解除'
|
||||
}
|
||||
deviceSendAlarmMessage(data).then((res) => {
|
||||
if (res.code == 200) {
|
||||
uni.showToast({
|
||||
title: res.msg,
|
||||
uni.showLoading({
|
||||
title: isAlarming ? '设备报警中...' : '解除报警中...',
|
||||
mask: true
|
||||
});
|
||||
// 2. 准备请求数据
|
||||
const batchId = generateShortId();
|
||||
const data = {
|
||||
deviceIds: deviceIds,
|
||||
typeName: this.sendInfo.typeName,
|
||||
deviceImeiList: deviceImeiList,
|
||||
batchId: batchId,
|
||||
instructValue: this.pendingAlarmAction == 1 ? '1' : '0'
|
||||
};
|
||||
const registerRes = await deviceSendAlarmMessage(data);
|
||||
if (registerRes.code !== 200) {
|
||||
uni.showToast({
|
||||
title: registerRes.msg,
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
// 4. 获取设备状态
|
||||
let deviceImei = this.sendInfo.deviceImei
|
||||
let typeName = this.sendInfo.typeName
|
||||
const statusRes = await getdeviceSTatus({
|
||||
functionMode: 2,
|
||||
batchId,
|
||||
typeName:'FunctionAccessBatchStatusRule',
|
||||
deviceImei,
|
||||
interval: 500
|
||||
},
|
||||
deviceRealTimeStatus
|
||||
);
|
||||
if (statusRes.data.functionAccess === 'OK') {
|
||||
uni.showToast({
|
||||
title: statusRes.msg,
|
||||
icon: 'none'
|
||||
});
|
||||
this.showPopupFlag = false
|
||||
@ -165,18 +204,19 @@
|
||||
setTimeout(() => {
|
||||
uni.navigateBack()
|
||||
}, 500)
|
||||
} else {
|
||||
uni.showToast({
|
||||
title: res.msg,
|
||||
icon: 'none'
|
||||
});
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
uni.showToast({
|
||||
title: error.message,
|
||||
icon: 'none'
|
||||
});
|
||||
} finally {
|
||||
uni.hideLoading();
|
||||
}
|
||||
},
|
||||
// 点击确认状态
|
||||
onPopupConfirm() {
|
||||
this.sendAlarmCommand(this.popupType);
|
||||
|
||||
// 处理确认逻辑
|
||||
},
|
||||
},
|
||||
@ -184,7 +224,8 @@
|
||||
const eventChannel = this.getOpenerEventChannel();
|
||||
// 监听 'deviceSend' 事件,获取传过来的数据
|
||||
eventChannel.on('devicePolice', (data) => {
|
||||
this.getData(data.data)
|
||||
this.getData(data.data.id)
|
||||
this.sendInfo = data.data
|
||||
});
|
||||
// 如果需要向调用页面返回数据,可以触发 'ack' 事件
|
||||
eventChannel.emit('ack', {})
|
||||
@ -195,7 +236,7 @@
|
||||
<style scoped>
|
||||
.container {
|
||||
min-height: 100vh;
|
||||
background-color: rgb(18, 18, 18);
|
||||
background-color:rgb(18, 18, 18);
|
||||
box-sizing: border-box;
|
||||
overflow-x: hidden;
|
||||
|
||||
@ -410,4 +451,17 @@
|
||||
border: 1px solid rgba(255, 255, 255, 0.87);
|
||||
background: rgba(18, 18, 18, 1);
|
||||
}
|
||||
|
||||
.checkbox.disabled {
|
||||
opacity: 0.5;
|
||||
background-color: rgba(255, 255, 255, 0.1) !important;
|
||||
border-color: rgba(255, 255, 255, 0.2) !important;
|
||||
pointer-events: none;
|
||||
/* 阻止点击事件 */
|
||||
}
|
||||
|
||||
/* 可选:离线设备的卡片整体置灰 */
|
||||
.device-card[data-offline="true"] {
|
||||
opacity: 0.6;
|
||||
}
|
||||
</style>
|
@ -1,23 +1,34 @@
|
||||
<template>
|
||||
<view class="share">
|
||||
<view class="device-title">已分享用户</view>
|
||||
<view class="device-info" v-for="(item, index) in deviceList" :key="index">
|
||||
<view class="device-header" @click.stop="handleFile(item)">
|
||||
<view class="deviceIMG">
|
||||
<image src="@/static/images/common/user.png" mode="aspectFit" class="IMG"></image>
|
||||
</view>
|
||||
<view class="device-name">
|
||||
<view>用户名:{{item.deviceName}}</view>
|
||||
<view class="ID">
|
||||
<view class="ID">{{item.phonenumber}}
|
||||
<!-- 下拉刷新区域 -->
|
||||
<mescroll-uni ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback" :up="upOption" :down="downOption">
|
||||
<view class="device-title">已分享用户</view>
|
||||
<view class="" v-if="deviceList.length>0">
|
||||
<view class="device-info" v-for="(item, index) in deviceList" :key="index">
|
||||
<view class="device-header" @click.stop="handleFile(item)">
|
||||
<view class="deviceIMG">
|
||||
<image src="@/static/images/common/user.png" mode="aspectFit" class="IMG"></image>
|
||||
</view>
|
||||
<view class="device-name">
|
||||
<view>用户名:{{item.deviceName}}</view>
|
||||
<view class="ID">
|
||||
<view class="ID">{{item.phonenumber}}
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<view class="device-delete">
|
||||
<text class="delete" @click.stop="handleDelete(item)">移除</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<view class="device-delete">
|
||||
<text class="delete" @click.stop="handleDelete(item)">移除</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<view v-else class="noDATA">
|
||||
<view> <uni-icons type="image-filled" size="120" color="rgba(255, 255, 255, 0.9)"></uni-icons>
|
||||
</view>
|
||||
暂无数据
|
||||
</view>
|
||||
</mescroll-uni>
|
||||
|
||||
<!-- 删除弹框 -->
|
||||
<view class="agreement-mask" v-if="deleteShow" @click="closePopup('delete')">
|
||||
<view class="agreement-popup" @click.stop>
|
||||
@ -42,16 +53,62 @@
|
||||
deviceShareList,
|
||||
deviceShareDelete
|
||||
} from '@/api/6170/share.js'
|
||||
import MescrollUni from 'mescroll-uni/mescroll-uni.vue'
|
||||
|
||||
export default {
|
||||
components: {
|
||||
MescrollUni
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
deviceList: [],
|
||||
deleteShow: false,
|
||||
delelteItemInfo: '',
|
||||
itemInfo: ''
|
||||
itemInfo: '',
|
||||
mescroll: null, // mescroll实例对象
|
||||
downOption: {
|
||||
auto: false // 不自动加载
|
||||
},
|
||||
upOption: {
|
||||
auto: false, // 不自动加载
|
||||
noMoreSize: 5, // 如果列表已无数据,可设置列表的总数量要大于等于5条才显示无更多数据
|
||||
empty: {
|
||||
tip: '暂无相关数据'
|
||||
}
|
||||
},
|
||||
page: 1, // 当前页码
|
||||
size: 10, // 每页条数
|
||||
total: 0 // 总数据量
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
// mescroll组件初始化的回调,可获取到mescroll对象
|
||||
mescrollInit(mescroll) {
|
||||
this.mescroll = mescroll;
|
||||
},
|
||||
// 下拉刷新的回调
|
||||
downCallback() {
|
||||
// 重置分页参数
|
||||
this.page = 1;
|
||||
this.getData(this.itemInfo.id).then(res => {
|
||||
// 数据请求成功后,隐藏下拉刷新的状态
|
||||
this.mescroll.endSuccess();
|
||||
}).catch(() => {
|
||||
// 请求失败,隐藏下拉刷新的状态
|
||||
this.mescroll.endErr();
|
||||
})
|
||||
},
|
||||
// 上拉加载的回调
|
||||
upCallback() {
|
||||
this.getData(this.itemInfo.id).then(res => {
|
||||
// 根据是否有数据来决定是否显示无更多数据的提示
|
||||
const hasNext = this.deviceList.length < this.total;
|
||||
this.mescroll.endSuccess(this.deviceList.length, hasNext);
|
||||
}).catch(() => {
|
||||
// 请求失败,隐藏上拉加载的状态
|
||||
this.mescroll.endErr();
|
||||
})
|
||||
},
|
||||
// 点击弹框外的区域关闭
|
||||
closePopup(type) {
|
||||
if (type === 'delete') {
|
||||
@ -73,25 +130,43 @@
|
||||
icon: 'none'
|
||||
})
|
||||
this.deleteShow = false
|
||||
this.getData()
|
||||
// 删除后刷新列表
|
||||
this.page = 1;
|
||||
this.getData(this.itemInfo.id).then(() => {
|
||||
this.mescroll.resetUpScroll();
|
||||
})
|
||||
} else {
|
||||
uni.showToast({
|
||||
title: res.msg,
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
|
||||
})
|
||||
//
|
||||
},
|
||||
getData(val) {
|
||||
let data = {
|
||||
deviceId: val
|
||||
}
|
||||
deviceShareList(data).then((res) => {
|
||||
if (res.code == 200) {
|
||||
this.deviceList = res.rows
|
||||
return new Promise((resolve, reject) => {
|
||||
let data = {
|
||||
deviceId: val,
|
||||
pageNum: this.page,
|
||||
pageSize: this.size,
|
||||
}
|
||||
deviceShareList(data).then((res) => {
|
||||
if (res.code == 200) {
|
||||
this.total = res.total;
|
||||
if (this.page === 1) {
|
||||
// 如果是第一页,直接替换数据
|
||||
this.deviceList = res.rows;
|
||||
} else {
|
||||
// 如果不是第一页,追加数据
|
||||
this.deviceList = this.deviceList.concat(res.rows);
|
||||
}
|
||||
resolve(res);
|
||||
} else {
|
||||
reject(res);
|
||||
}
|
||||
}).catch(err => {
|
||||
reject(err);
|
||||
})
|
||||
})
|
||||
},
|
||||
// 跳转分享详情
|
||||
@ -100,14 +175,13 @@
|
||||
url: "/pages/6170/deviceControl/index",
|
||||
success: (res) => {
|
||||
// 页面跳转成功后的回调函数
|
||||
res.eventChannel.emit('deviceControl', {
|
||||
res.eventChannel.emit('detailData', {
|
||||
data: item,
|
||||
apiType: 'listB' // 自定义标识 // 自定义标识,详情哪里根据这个参数不同信息
|
||||
});
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
},
|
||||
onLoad() {
|
||||
const eventChannel = this.getOpenerEventChannel();
|
||||
@ -115,7 +189,14 @@
|
||||
eventChannel.on('shareManagement', (data) => {
|
||||
console.log(data, 'data1t111');
|
||||
this.itemInfo = data.data;
|
||||
this.getData(this.itemInfo.id)
|
||||
// 初始化加载数据
|
||||
this.page = 1;
|
||||
this.getData(this.itemInfo.id).then(() => {
|
||||
// 数据加载完成后,如果需要可以手动触发下拉刷新结束
|
||||
if (this.mescroll) {
|
||||
this.mescroll.endSuccess();
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -130,7 +211,7 @@
|
||||
|
||||
.device-title {
|
||||
color: rgba(255, 255, 255, 0.87);
|
||||
padding: 30rpx 0;
|
||||
padding: 30rpx;
|
||||
}
|
||||
|
||||
.device-info {
|
||||
@ -162,7 +243,7 @@
|
||||
|
||||
.deviceIMG {
|
||||
/* width: 100rpx; */
|
||||
/* height: 100rpx; */
|
||||
/* height: 100rpx; */
|
||||
position: relative;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
@ -173,6 +254,12 @@
|
||||
width: 50%;
|
||||
}
|
||||
|
||||
.noDATA {
|
||||
text-align: center;
|
||||
color: rgba(255, 255, 255, 0.87);
|
||||
transform: translate(-0%, 100%);
|
||||
}
|
||||
|
||||
.delete {
|
||||
border-radius: 32px;
|
||||
background: rgba(255, 200, 78, 0.06);
|
||||
|
1841
pages/650/HBY650.vue
Normal file
2697
pages/670/HBY670.vue
Normal file
446
pages/670/History.vue
Normal file
@ -0,0 +1,446 @@
|
||||
<template>
|
||||
<view class="content contentBg">
|
||||
<view class="topTip">
|
||||
<view class="item" @click="tabChange(0)" :class="Status.tabIndex===0?'active':''">开机</view>
|
||||
<view class="item" @click="tabChange(1)" :class="Status.tabIndex===1?'active':''">报警</view>
|
||||
<view class="item" @click="tabChange(2)" :class="Status.tabIndex===2?'active':''">故障</view>
|
||||
</view>
|
||||
<view class="tabs">
|
||||
|
||||
<view class="tab" :class="Status.tabIndex===0?'active':''">
|
||||
<view class="li" v-for="item,index in SwithData">
|
||||
<view>
|
||||
<view class="label">开机时间</view>
|
||||
<view class="value">{{item['open']}}</view>
|
||||
</view>
|
||||
<view class="marginTop10">
|
||||
<view class="label">关机时间</view>
|
||||
<view class="value">{{item['close']}}</view>
|
||||
</view>
|
||||
|
||||
</view>
|
||||
</view>
|
||||
<view class="tab" :class="Status.tabIndex===1?'active':''">
|
||||
<view class="li warn" v-for="item,index in WarnData">
|
||||
<view class="row">
|
||||
<view class="label">报警事项:</view>
|
||||
<view class="value red">{{item['evtName']}}</view>
|
||||
</view>
|
||||
<view class="marginTop10 row">
|
||||
<view class="label">报警地点:</view>
|
||||
<view class="value">{{item['address']}}</view>
|
||||
</view>
|
||||
<view class="marginTop10 row">
|
||||
<view class="label">报警时间:</view>
|
||||
<view class="value">{{item['open']}}</view>
|
||||
</view>
|
||||
<view class="marginTop10 row">
|
||||
<view class="label">解除时间:</view>
|
||||
<view class="value">{{item['close']}}</view>
|
||||
</view>
|
||||
<view class="marginTop10 row">
|
||||
<view class="label">报警时长:</view>
|
||||
<view class="value">{{item['time']}}</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<view class="tab" :class="Status.tabIndex===2?'active':''">
|
||||
|
||||
<view class="li warn" v-for="item,index in FaultData">
|
||||
<view class="row">
|
||||
<view class="label">故障部位:</view>
|
||||
<view class="value red">{{item['evtName']}}</view>
|
||||
</view>
|
||||
|
||||
<view class="marginTop10 row">
|
||||
<view class="label">故障时间:</view>
|
||||
<view class="value">{{item['open']}}</view>
|
||||
</view>
|
||||
<view class="marginTop10 row">
|
||||
<view class="label">处理时间:</view>
|
||||
<view class="value">{{item['close']}}</view>
|
||||
</view>
|
||||
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<global-loading ref="loading"></global-loading>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import Common from '@/utils/Common.js';
|
||||
import api from '@/api/670/History.js'
|
||||
import {
|
||||
showLoading,
|
||||
hideLoading,
|
||||
updateLoading
|
||||
} from '@/utils/loading.js'
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
Status: {
|
||||
tabIndex: 1
|
||||
},
|
||||
device: {},
|
||||
SwithData: [], //开关机的数据
|
||||
FaultData: [], //故障数据
|
||||
WarnData: [], //报警数据
|
||||
}
|
||||
},
|
||||
onLoad() {
|
||||
var these = this;
|
||||
let channel = this.getOpenerEventChannel();
|
||||
channel.on('detailData', function(opt) {
|
||||
console.log("我收到你的数据了,谢谢你。", opt.data);
|
||||
these.device = opt.data;
|
||||
these.tabChange(these.Status.tabIndex, true);
|
||||
});
|
||||
},
|
||||
methods: {
|
||||
loadWarnData() { //加载报警数据
|
||||
var these = this;
|
||||
let promise1 = new Promise((resolve, reject) => {
|
||||
let arr = [];
|
||||
let endDate = new Date();
|
||||
|
||||
arr.push({
|
||||
evtName: '环境存在漏电电源',
|
||||
address: '湖北省武汉市洪山区关山街道国际企业中心聚星楼',
|
||||
open: Common.DateFormat(endDate),
|
||||
time: '00:00:59'
|
||||
});
|
||||
for (var i = 1; i < 10; i++) {
|
||||
arr.push({
|
||||
evtName: '环境存在漏电电源',
|
||||
address: '湖北省武汉市洪山区关山街道国际企业中心聚星楼',
|
||||
open: Common.DateFormat(endDate.setHours(i * -24)),
|
||||
time: '00:00:59'
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
for (var i = 0; i < arr.length; i++) {
|
||||
let item = new Date(arr[i].open);
|
||||
let close = Common.DateFormat(item.setHours(4));
|
||||
arr[i].close = close;
|
||||
|
||||
}
|
||||
resolve(arr);
|
||||
});
|
||||
let promise2 = new Promise((resolve, reject) => {
|
||||
api.getWarnData(this.device).then((res) => {
|
||||
resolve(res);
|
||||
}).catch((ex) => {
|
||||
console.log("获取数据异常", ex);
|
||||
reject(ex);
|
||||
});
|
||||
});
|
||||
|
||||
Promise.allSettled([promise1, promise2]).then(results => {
|
||||
if (results[1].status == 'fulfilled') {
|
||||
these.WarnData = results[1].value;
|
||||
} else {
|
||||
these.WarnData = results[0].value;
|
||||
}
|
||||
|
||||
});
|
||||
},
|
||||
loadSwithData() { //加载开关机数据
|
||||
var these = this;
|
||||
let promise1 = new Promise((resolve, reject) => {
|
||||
let arr = [];
|
||||
let endDate = new Date();
|
||||
|
||||
arr.push({
|
||||
open: Common.DateFormat(endDate)
|
||||
});
|
||||
for (var i = 1; i < 10; i++) {
|
||||
arr.push({
|
||||
open: Common.DateFormat(endDate.setHours(i * -24))
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
for (var i = 0; i < arr.length; i++) {
|
||||
let item = new Date(arr[i].open);
|
||||
let close = Common.DateFormat(item.setHours(4));
|
||||
arr[i].close = close;
|
||||
|
||||
}
|
||||
resolve(arr);
|
||||
});
|
||||
|
||||
|
||||
let promise2 = new Promise((resolve, reject) => {
|
||||
api.getSwithData(this.device).then((res) => {
|
||||
resolve(res);
|
||||
}).catch((ex) => {
|
||||
console.log("获取数据异常", ex);
|
||||
reject(ex);
|
||||
});
|
||||
});
|
||||
|
||||
Promise.allSettled([promise1, promise2]).then(results => {
|
||||
if (results[1].status == 'fulfilled') {
|
||||
these.SwithData = results[1].value;
|
||||
} else {
|
||||
these.SwithData = results[0].value;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
},
|
||||
loadFaultData() { //加载故障数据
|
||||
var these = this;
|
||||
let promise1 = new Promise((resolve, reject) => {
|
||||
let arr = [];
|
||||
let endDate = new Date();
|
||||
|
||||
let dic = ['报警灯', '蜂鸣器', '电池', '蓝牙模块', '定位器', '4G模块'];
|
||||
arr.push({
|
||||
evtName: '报警灯',
|
||||
|
||||
open: Common.DateFormat(endDate),
|
||||
|
||||
});
|
||||
for (var i = 1; i < 10; i++) {
|
||||
arr.push({
|
||||
evtName: dic[i % 6],
|
||||
|
||||
open: Common.DateFormat(endDate.setHours(i * -24)),
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
for (var i = 0; i < arr.length; i++) {
|
||||
let item = new Date(arr[i].open);
|
||||
let close = Common.DateFormat(item.setHours(72), "yyyy-MM-dd");
|
||||
arr[i].close = close;
|
||||
|
||||
}
|
||||
resolve(arr);
|
||||
});
|
||||
|
||||
let promise2 = new Promise((resolve, reject) => {
|
||||
api.getFaulData(this.device).then((res) => {
|
||||
resolve(res);
|
||||
}).catch((ex) => {
|
||||
console.log("获取数据异常", ex);
|
||||
reject(ex);
|
||||
});
|
||||
});
|
||||
|
||||
Promise.allSettled([promise1, promise2]).then(results => {
|
||||
if (results[1].status == 'fulfilled') {
|
||||
these.FaultData = results[1].value;
|
||||
} else {
|
||||
these.FaultData = results[0].value;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
},
|
||||
tabChange(index, ispostback) {
|
||||
if (this.Status.tabIndex === index && !ispostback) {
|
||||
return;
|
||||
}
|
||||
this.Status.tabIndex = index;
|
||||
showLoading(this);
|
||||
let promise = new Promise((resolve, reject) => {
|
||||
try {
|
||||
if (index === 0) {
|
||||
this.loadSwithData();
|
||||
} else if (index === 1) {
|
||||
this.loadWarnData();
|
||||
} else if (index === 2) {
|
||||
this.loadFaultData();
|
||||
}
|
||||
} catch (error) {
|
||||
//TODO handle the exception
|
||||
} finally {
|
||||
hideLoading(this);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.tab .warn .value {
|
||||
padding-left: 10rpx;
|
||||
}
|
||||
|
||||
.tab .warn .value.red {
|
||||
color: rgba(224, 52, 52, 1) !important;
|
||||
}
|
||||
|
||||
.tab .warn .row {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
flex-wrap: nowrap;
|
||||
align-content: center;
|
||||
justify-content: flex-start;
|
||||
align-items: flex-start;
|
||||
}
|
||||
|
||||
.marginTop10 {
|
||||
margin-top: 20rpx;
|
||||
}
|
||||
|
||||
.tab .li .value {
|
||||
color: rgba(255, 255, 255, 0.87);
|
||||
width: calc(100% - 110rpx);
|
||||
height: auto;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.tab .li .label {
|
||||
color: rgba(255, 255, 255, 0.6);
|
||||
white-space: nowrap;
|
||||
width: 110rpx;
|
||||
|
||||
}
|
||||
|
||||
.tab .li {
|
||||
font-family: 'PingFang SC';
|
||||
font-size: 24rpx;
|
||||
font-weight: 400;
|
||||
line-height: 35rpx;
|
||||
letter-spacing: 0.14rpx;
|
||||
|
||||
width: 100%;
|
||||
border-radius: 16rpx;
|
||||
margin-top: 24rpx;
|
||||
background: rgba(26, 26, 26, 1);
|
||||
box-sizing: border-box;
|
||||
padding: 20rpx 30rpx;
|
||||
}
|
||||
|
||||
.tab.active {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.tab {
|
||||
width: 100%;
|
||||
height: auto;
|
||||
display: none;
|
||||
}
|
||||
|
||||
.tabs {
|
||||
width: 100%;
|
||||
height: auto;
|
||||
}
|
||||
|
||||
.topTip .item.active {
|
||||
color: rgba(187, 230, 0, 1) !important;
|
||||
font-size: 36rpx !important;
|
||||
|
||||
}
|
||||
|
||||
.topTip .item.active::before {
|
||||
background: rgba(187, 230, 0, 1);
|
||||
}
|
||||
|
||||
.topTip .item::before {
|
||||
content: "";
|
||||
width: 50%;
|
||||
height: 4px;
|
||||
border-radius: 31px;
|
||||
position: absolute;
|
||||
background: #00000000;
|
||||
bottom: -10px;
|
||||
left: 25%;
|
||||
}
|
||||
|
||||
.topTip .item {
|
||||
color: rgba(255, 255, 255, 0.87);
|
||||
font-family: 'PingFang SC';
|
||||
font-size: 28rpx;
|
||||
font-weight: 400;
|
||||
letter-spacing: 0.14rpx;
|
||||
position: relative;
|
||||
|
||||
}
|
||||
|
||||
.topTip {
|
||||
padding: 30rpx 0rpx;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
flex-wrap: nowrap;
|
||||
align-content: center;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
position: sticky;
|
||||
background-color: #121212;
|
||||
height: 110rpx;
|
||||
z-index: 9999;
|
||||
margin-top: -30rpx;
|
||||
}
|
||||
|
||||
/* #ifdef H5 */
|
||||
/* 仅在 H5 平台生效的样式 */
|
||||
.topTip {
|
||||
top: 44px;
|
||||
|
||||
}
|
||||
|
||||
/* #endif */
|
||||
|
||||
/* #ifdef APP-PLUS */
|
||||
/* 仅在 App 平台生效的样式 */
|
||||
.topTip {
|
||||
top: 0rpx;
|
||||
}
|
||||
|
||||
/* #endif */
|
||||
|
||||
.content {
|
||||
padding: 30rpx;
|
||||
box-sizing: border-box;
|
||||
width: 100%;
|
||||
min-height: 100vh;
|
||||
height: auto;
|
||||
}
|
||||
|
||||
.contentBg {
|
||||
background-color: #121212;
|
||||
color: #ffffffde;
|
||||
}
|
||||
|
||||
.fleft {
|
||||
float: left;
|
||||
}
|
||||
|
||||
.fright {
|
||||
float: right;
|
||||
}
|
||||
|
||||
.clear {
|
||||
clear: both;
|
||||
}
|
||||
|
||||
.displayNone {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
.p100 {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.center {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
flex-wrap: nowrap;
|
||||
align-content: center;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
</style>
|
1947
pages/BlueTooth/ModeSetting/HBY6155.vue
Normal file
1925
pages/BlueTooth/ModeSetting/HBY6155V1.vue
Normal file
1892
pages/BlueTooth/ModeSetting/HBY650.vue
Normal file
1899
pages/BlueTooth/ModeSetting/HBY650_1.vue
Normal file
2837
pages/BlueTooth/ModeSetting/HBY670V1.vue
Normal file
1499
pages/BlueTooth/ModeSetting/ModeSetting.vue
Normal file
472
pages/BlueTooth/ModeSetting/VideoSend.vue
Normal file
@ -0,0 +1,472 @@
|
||||
<template>
|
||||
<view class="content">
|
||||
<canvas canvas-id="flashCanvas"
|
||||
style="width: 160px; height: 80px; z-index: 9999;position: fixed; top:-9999px;left:-9999px;"></canvas>
|
||||
|
||||
<f-video ref="compARef" :src="videoPath" :direction="-90" :autoplay="true" @shotVideoClick="shotVideoClick"
|
||||
:videoWidth="videoWidth" :videoHeight="videoHeight"></f-video>
|
||||
|
||||
|
||||
<view>
|
||||
<text>发送间隔</text>
|
||||
<input type="text" v-model="inteval" />
|
||||
</view>
|
||||
<view>
|
||||
<button @click="checkVideo">选择视频</button>
|
||||
<!-- <button @click="CutImg">发送</button> -->
|
||||
<button @click="uploadVideo">发送</button>
|
||||
</view>
|
||||
|
||||
|
||||
<view class="sending-progress" v-if="isSending">
|
||||
<view class="progress-bar">
|
||||
<view class="progress-fill" :style="{ width: progress + '%' }"></view>
|
||||
</view>
|
||||
<text>正在发送: {{ progress }}% ({{ currentPacket }}/{{ totalPackets }})</text>
|
||||
</view>
|
||||
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import Common from '@/utils/Common';
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
videoPath: '',
|
||||
inteval: 0,
|
||||
progress: 0,
|
||||
currentPacket: 0,
|
||||
totalPackets: 100,
|
||||
|
||||
connectedDeviceId: '',
|
||||
serviceId: '0xFFE1',
|
||||
writeCharacteristicId: '0xFFE1',
|
||||
notifyCharacteristicId: '0xFFE2',
|
||||
isSending: "",
|
||||
textProgress: "",
|
||||
|
||||
imgs: [],
|
||||
videoWidth: 320,
|
||||
videoHeight: 160,
|
||||
videoDuration: 2,
|
||||
|
||||
hexArray: []
|
||||
|
||||
}
|
||||
},
|
||||
onLoad() {
|
||||
const eventChannel = this.getOpenerEventChannel();
|
||||
|
||||
eventChannel.on('receiveDevice', (data) => {
|
||||
this.connectedDeviceId = data.connectedDeviceId;
|
||||
this.serviceId = data.serviceId;
|
||||
this.writeCharacteristicId = data.writeCharacteristicId;
|
||||
this.notifyCharacteristicId = data.notifyCharacteristicId;
|
||||
})
|
||||
},
|
||||
methods: {
|
||||
checkVideo: function() {
|
||||
uni.chooseVideo({
|
||||
sourceType: ['album', 'camera'],
|
||||
compressed: false,
|
||||
maxDuration: 2,
|
||||
camera: 'back',
|
||||
success: (res) => {
|
||||
this.videoPath = res.tempFilePath;
|
||||
|
||||
this.imgs = [];
|
||||
this.hexArray = [];
|
||||
this.$refs.compARef.base64 = [];
|
||||
this.videoWidth = res.width;
|
||||
this.videoHeight = res.height;
|
||||
this.videoDuration = res.duration;
|
||||
console.log("视频宽:" + res.width + ",视频高:" + res.height + ",视频时长:" + res.duration);
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
uploadVideo: function() {
|
||||
|
||||
if (this.hexArray.length > 0) {
|
||||
console.log("开始处理,无需上传");
|
||||
this.shotVideoClick(this.hexArray, 'rgb565');
|
||||
return;
|
||||
|
||||
}
|
||||
if(!this.videoPath){
|
||||
uni.showToast({
|
||||
title: "请选择视频",
|
||||
icon: 'fail'
|
||||
})
|
||||
return;
|
||||
}
|
||||
|
||||
console.log("正在上传视频");
|
||||
uni.showLoading({
|
||||
title: "上传中"
|
||||
});
|
||||
|
||||
let p2=new Promise((resolve,reject)=>{
|
||||
let start = new Date();
|
||||
console.log("Common.baseURL="+Common.baseURL);
|
||||
uni.uploadFile({
|
||||
url:Common.baseURL+'video/upload',
|
||||
filePath: this.videoPath,
|
||||
name: 'file',
|
||||
header: {
|
||||
"Method": "POST",
|
||||
"Content-Type": "multipart/form-data"
|
||||
},
|
||||
timeout: 600000,
|
||||
fail: (ex) => {
|
||||
//console.log("上传视频失败" + JSON.stringify(ex));
|
||||
uni.showToast({
|
||||
title: "视频文件上传失败了,请检查网络连接",
|
||||
icon: 'fail'
|
||||
})
|
||||
uni.hideLoading();
|
||||
reject(ex);
|
||||
},
|
||||
success: (res) => {
|
||||
let end = new Date();
|
||||
var diff = (end.getTime() - start.getTime()) / 1000;
|
||||
let s = diff % 60;
|
||||
let m = (diff - s) / 60;
|
||||
console.log("上传完成,耗时:" + m + "分" + s + "秒");
|
||||
uni.hideLoading();
|
||||
resolve(res);
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
let p1=this.HoldYouHand();
|
||||
|
||||
Promise.all([p2,p1]).then((arr)=>{
|
||||
|
||||
if(arr[1]===true){
|
||||
let res=arr[0];
|
||||
res = JSON.parse(res.data);
|
||||
|
||||
if (res.data) {
|
||||
this.hexArray = res.data;
|
||||
uni.showLoading({
|
||||
title: "正在发送"
|
||||
});
|
||||
|
||||
setTimeout(() => {
|
||||
this.shotVideoClick(res.data, 'rgb565');
|
||||
}, 0)
|
||||
|
||||
} else {
|
||||
console.log("res")
|
||||
uni.showModal({
|
||||
content: "服务器未返回RGB565数据",
|
||||
title: '错误'
|
||||
})
|
||||
}
|
||||
}else{
|
||||
uni.showModal({
|
||||
content:"与设备握手失败了",
|
||||
title:"错误"
|
||||
})
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
},
|
||||
|
||||
shotVideoClick: function(array, type) {
|
||||
//console.log("处理视频完成", array);
|
||||
//console.log("type=" + type)
|
||||
//console.log("array=", array);
|
||||
this.imgs = array;
|
||||
|
||||
|
||||
|
||||
var sendImagePackets = (imageData) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
this.isSending = true;
|
||||
this.progress = 0;
|
||||
this.currentPacket = 0;
|
||||
|
||||
// 总数据包数
|
||||
const totalPackets = 1536;
|
||||
this.totalPackets = totalPackets;
|
||||
let currentPacket = 1;
|
||||
|
||||
// 发送单个数据包
|
||||
const sendNextPacket = () => {
|
||||
////console.log("currentPacket="+currentPacket+",imageData.length="+imageData.length);
|
||||
if (currentPacket > totalPackets) {
|
||||
this.isSending = false;
|
||||
resolve();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// 计算当前包的数据
|
||||
let packetSize = 250;
|
||||
if (type == 'rgb565') {
|
||||
packetSize = 500;
|
||||
}
|
||||
|
||||
// 创建数据包
|
||||
const startIndex = (currentPacket - 1) * packetSize;
|
||||
const endIndex = Math.min(startIndex + packetSize, imageData.length);
|
||||
if (startIndex > endIndex) {
|
||||
resolve();
|
||||
return;
|
||||
}
|
||||
////console.log("111111");
|
||||
const packetData = imageData.slice(startIndex, endIndex);
|
||||
|
||||
// 构建数据包
|
||||
////console.log("packetData.length"+packetData.length);
|
||||
const bufferSize = 506; // 头部5字节 + 数据部分
|
||||
const buffer = new ArrayBuffer(bufferSize);
|
||||
const dataView = new DataView(buffer);
|
||||
|
||||
let sortNo = currentPacket.toString(16).padStart(4, '0');
|
||||
|
||||
// 填充头部
|
||||
dataView.setUint8(0, 0x55); // 帧头
|
||||
dataView.setUint8(1, 0x04); // 帧类型:开机画面
|
||||
dataView.setUint8(2, '0x' + sortNo.substring(0, 2)); // 包序号
|
||||
dataView.setUint8(3, '0x' + sortNo.substring(2, 4)); // 包序号
|
||||
|
||||
|
||||
dataView.setUint8(4, 0x01);
|
||||
dataView.setUint8(5, 0xF4);
|
||||
|
||||
|
||||
if (type == 'rgb565') {
|
||||
for (let i = 0; i < packetData.length; i++) {
|
||||
dataView.setUint8(6 + i, '0x' + packetData[i]);
|
||||
}
|
||||
} else {
|
||||
for (let i = 0; i < packetData.length; i++) {
|
||||
dataView.setUint16(6 + i * 2, packetData[i], false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
let inteval = parseInt(this.inteval ? this.inteval : 0);
|
||||
this.sendData(buffer).then(() => {
|
||||
// 更新进度
|
||||
this.currentPacket = currentPacket;
|
||||
this.progress = Math.round((currentPacket / totalPackets) *
|
||||
100);
|
||||
//console.log(`发送数据包完成 ${currentPacket}/${totalPackets}`);
|
||||
|
||||
// 发送下一个包(添加延迟避免蓝牙缓冲区溢出)
|
||||
currentPacket++;
|
||||
|
||||
|
||||
setTimeout(sendNextPacket, inteval);
|
||||
}).catch(err => {
|
||||
|
||||
// console.log(err.errMsg + ",发送失败了,正在补偿:" + currentPacket);
|
||||
setTimeout(sendNextPacket, inteval);
|
||||
// uni.showToast({
|
||||
// title:"发送失败"+JSON.stringify(err)
|
||||
// })
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
sendNextPacket();
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
if (type == 'rgb565') {
|
||||
let start = new Date();
|
||||
console.log("开始发送");
|
||||
sendImagePackets(array).then(() => {
|
||||
console.log("发送完成");
|
||||
let end = new Date();
|
||||
var diff = (end.getTime() - start.getTime()) / 1000;
|
||||
let s = diff % 60;
|
||||
let m = (diff-s) / 60;
|
||||
console.log("发送完成,耗时:" + m + "分" + s + "秒");
|
||||
uni.showToast({
|
||||
title: "发送完成,耗时:" + m + "分" + s + "秒",
|
||||
icon: 'success'
|
||||
})
|
||||
}).catch((ex1) => {
|
||||
//console.log("出现了异常", ex1)
|
||||
}).finally(() => {
|
||||
uni.hideLoading();
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
},
|
||||
HoldYouHand() {
|
||||
|
||||
var promise=new Promise((resolve,reject)=>{
|
||||
try{
|
||||
let start=new Date();
|
||||
var str = "video transmit start"; //握手的协议字符串
|
||||
console.log("开始握手:"+str)
|
||||
|
||||
// 1. 创建 ArrayBuffer 和 DataView
|
||||
const buffer = new ArrayBuffer(str.length);
|
||||
const dataView = new DataView(buffer);
|
||||
|
||||
// 2. 将字符串转换为 ASCII 码并写入 DataView
|
||||
for (let i = 0; i < str.length; i++) {
|
||||
dataView.setUint8(i, str.charCodeAt(i));
|
||||
}
|
||||
//console.log("111111");
|
||||
this.sendData(buffer).then(() => {
|
||||
// 开始发送第一个包
|
||||
setTimeout(()=>{
|
||||
|
||||
let end = new Date();
|
||||
var diff = (end.getTime() - start.getTime()) / 1000;
|
||||
let s = diff % 60;
|
||||
let m = (diff - s) / 60;
|
||||
|
||||
console.log("握手成功并完成2200ms等待,耗时"+m+"分"+s+"秒");
|
||||
|
||||
resolve(true);
|
||||
}, 2200);
|
||||
|
||||
}).catch(err => {
|
||||
//console.log("握手没有成功");
|
||||
reject(err);
|
||||
});
|
||||
}catch(ex){
|
||||
reject(ex);
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
|
||||
return promise;
|
||||
|
||||
},
|
||||
sendData(buffer) {
|
||||
////console.log("deviceId=" + this.connectedDeviceId);
|
||||
////console.log("serviceId=" + this.serviceId);
|
||||
|
||||
return new Promise(async (resolve, reject) => {
|
||||
|
||||
// //console.log("开始发送数据,buffer");
|
||||
|
||||
|
||||
var promise = new Promise((succ, err) => {
|
||||
uni.writeBLECharacteristicValue({
|
||||
deviceId: this.connectedDeviceId,
|
||||
serviceId: this.serviceId,
|
||||
characteristicId: this.writeCharacteristicId,
|
||||
value: buffer,
|
||||
writeType: plus.os.name == 'iOS' ? 'write' : 'writeNoResponse',
|
||||
success: () => {
|
||||
// //console.log("发送数据成功");
|
||||
succ();
|
||||
},
|
||||
fail: (ex) => {
|
||||
//console.log("发送数据失败", ex);
|
||||
err(ex);
|
||||
},
|
||||
complete: function() {
|
||||
// //console.log("123456");
|
||||
}
|
||||
});
|
||||
});
|
||||
if (plus.os.name == 'iOS') {
|
||||
|
||||
function timeout(ms) {
|
||||
return new Promise((_, err) => {
|
||||
setTimeout(() => {
|
||||
err({
|
||||
code: -1,
|
||||
errMsg: '超时了'
|
||||
})
|
||||
}, ms);
|
||||
});
|
||||
}
|
||||
|
||||
let inteval = parseInt(this.inteval ? this.inteval : 0);
|
||||
|
||||
Promise.race([promise, timeout(inteval)]).then(resolve).catch((ex) => {
|
||||
//console.log("ex=", ex);
|
||||
if (ex.code == -1) {
|
||||
resolve();
|
||||
} else {
|
||||
reject();
|
||||
}
|
||||
|
||||
}).finally(() => {
|
||||
//console.log("完成了")
|
||||
});
|
||||
} else {
|
||||
promise.then(resolve).catch(reject);
|
||||
}
|
||||
});
|
||||
},
|
||||
CutImg: function() {
|
||||
if (this.imgs.length == 30) {
|
||||
this.shotVideoClick(this.imgs, 'img');
|
||||
return;
|
||||
}
|
||||
//console.log("开始处理视频")
|
||||
uni.showLoading({
|
||||
title: '开始处理'
|
||||
});
|
||||
this.$refs.compARef.shotVideoClick(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.sending-progress {
|
||||
margin-top: 30rpx;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.progress-bar {
|
||||
height: 12rpx;
|
||||
background-color: #e0e0e0;
|
||||
border-radius: 6rpx;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.progress-fill {
|
||||
height: 100%;
|
||||
background-color: #409eff;
|
||||
transition: width 0.3s;
|
||||
}
|
||||
|
||||
input {
|
||||
border: 2rpx solid #000000;
|
||||
}
|
||||
|
||||
button {
|
||||
height: 100rpx;
|
||||
line-height: 100rpx;
|
||||
font-size: 28rpx;
|
||||
float: left;
|
||||
}
|
||||
|
||||
.content {
|
||||
width: 100vw;
|
||||
height: 300px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
</style>
|
517
pages/BlueTooth/ModeSetting/VideoSend_1.vue
Normal file
@ -0,0 +1,517 @@
|
||||
<template>
|
||||
<view class="content">
|
||||
<canvas canvas-id="flashCanvas"
|
||||
style="width: 160px; height: 80px; z-index: 9999;position: fixed; top:-9999px;left:-9999px;"></canvas>
|
||||
|
||||
<f-video ref="compARef" :src="videoPath" :direction="-90" :autoplay="true" @shotVideoClick="shotVideoClick"
|
||||
:videoWidth="videoWidth" :videoHeight="videoHeight"></f-video>
|
||||
|
||||
<view>
|
||||
<text>并发包数量</text>
|
||||
<input type="text" v-model="packgeCnt" />
|
||||
</view>
|
||||
<view>
|
||||
<text>发送间隔</text>
|
||||
<input type="text" v-model="inteval" />
|
||||
</view>
|
||||
<view>
|
||||
<button @click="checkVideo">选择视频</button>
|
||||
<!-- <button @click="CutImg">发送</button> -->
|
||||
<button @click="uploadVideo">发送</button>
|
||||
</view>
|
||||
|
||||
|
||||
<view class="sending-progress" v-if="isSending">
|
||||
<view class="progress-bar">
|
||||
<view class="progress-fill" :style="{ width: progress + '%' }"></view>
|
||||
</view>
|
||||
<text>正在发送: {{ progress }}% ({{ currentPacket }}/{{ totalPackets }})</text>
|
||||
</view>
|
||||
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
videoPath: '',
|
||||
packgeCnt: 20,
|
||||
inteval: 0,
|
||||
progress: 0,
|
||||
currentPacket: 0,
|
||||
totalPackets: 100,
|
||||
|
||||
connectedDeviceId: '',
|
||||
serviceId: '0xFFE1',
|
||||
writeCharacteristicId: '0xFFE1',
|
||||
notifyCharacteristicId: '0xFFE2',
|
||||
isSending: "",
|
||||
textProgress: "",
|
||||
|
||||
imgs: [],
|
||||
videoWidth: 320,
|
||||
videoHeight: 160,
|
||||
videoDuration: 2,
|
||||
|
||||
hexArray: []
|
||||
|
||||
}
|
||||
},
|
||||
onLoad() {
|
||||
const eventChannel = this.getOpenerEventChannel();
|
||||
|
||||
eventChannel.on('receiveDevice', (data) => {
|
||||
this.connectedDeviceId = data.connectedDeviceId;
|
||||
this.serviceId = data.serviceId;
|
||||
this.writeCharacteristicId = data.writeCharacteristicId;
|
||||
this.notifyCharacteristicId = data.notifyCharacteristicId;
|
||||
})
|
||||
},
|
||||
methods: {
|
||||
checkVideo: function() {
|
||||
uni.chooseVideo({
|
||||
sourceType: ['album', 'camera'],
|
||||
compressed: false,
|
||||
maxDuration: 2,
|
||||
camera: 'back',
|
||||
success: (res) => {
|
||||
this.videoPath = res.tempFilePath;
|
||||
|
||||
this.imgs = [];
|
||||
this.hexArray = [];
|
||||
this.$refs.compARef.base64 = [];
|
||||
this.videoWidth = res.width;
|
||||
this.videoHeight = res.height;
|
||||
this.videoDuration = res.duration;
|
||||
console.log("视频宽:" + res.width + ",视频高:" + res.height + ",视频时长:" + res.duration);
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
uploadVideo: function() {
|
||||
|
||||
if (this.hexArray.length > 0) {
|
||||
console.log("开始处理,无需上传");
|
||||
this.shotVideoClick(this.hexArray, 'rgb565');
|
||||
return;
|
||||
|
||||
}
|
||||
if(!this.videoPath){
|
||||
uni.showToast({
|
||||
title: "请选择视频",
|
||||
icon: 'fail'
|
||||
})
|
||||
return;
|
||||
}
|
||||
|
||||
console.log("正在上传视频");
|
||||
uni.showLoading({
|
||||
title: "上传中"
|
||||
});
|
||||
|
||||
let p2=new Promise((resolve,reject)=>{
|
||||
console.log("Common.baseURL="+Common.baseURL);
|
||||
let start = new Date();
|
||||
uni.uploadFile({
|
||||
url: Common.baseURL+'video/upload',
|
||||
// url: 'http://192.168.110.169:5000/video/upload',
|
||||
filePath: this.videoPath,
|
||||
name: 'file',
|
||||
header: {
|
||||
"Method": "POST",
|
||||
"Content-Type": "multipart/form-data"
|
||||
},
|
||||
timeout: 600000,
|
||||
fail: (ex) => {
|
||||
//console.log("上传视频失败" + JSON.stringify(ex));
|
||||
uni.showToast({
|
||||
title: "视频文件上传失败了,请检查网络连接",
|
||||
icon: 'fail'
|
||||
})
|
||||
uni.hideLoading();
|
||||
reject(ex);
|
||||
},
|
||||
success: (res) => {
|
||||
let end = new Date();
|
||||
var diff = (end.getTime() - start.getTime()) / 1000;
|
||||
let s = diff % 60;
|
||||
let m = (diff - s) / 60;
|
||||
console.log("上传完成,耗时:" + m + "分" + s + "秒");
|
||||
uni.hideLoading();
|
||||
resolve(res);
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
let p1=this.HoldYouHand();
|
||||
|
||||
Promise.all([p2,p1]).then((arr)=>{
|
||||
if(arr[1]===true){
|
||||
let res=arr[0];
|
||||
res = JSON.parse(res.data);
|
||||
|
||||
if (res.data) {
|
||||
this.hexArray = res.data;
|
||||
uni.showLoading({
|
||||
title: "正在发送"
|
||||
});
|
||||
|
||||
setTimeout(() => {
|
||||
this.shotVideoClick(res.data, 'rgb565');
|
||||
}, 0)
|
||||
|
||||
} else {
|
||||
console.log("res")
|
||||
uni.showModal({
|
||||
content: "服务器未返回RGB565数据",
|
||||
title: '错误'
|
||||
})
|
||||
}
|
||||
}else{
|
||||
uni.showModal({
|
||||
content:"与设备握手失败了",
|
||||
title:"错误"
|
||||
})
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
},
|
||||
pause(e) {
|
||||
////console.log('pause--------------------------', e);
|
||||
},
|
||||
shotVideoClick: function(array, type) {
|
||||
//console.log("处理视频完成", array);
|
||||
//console.log("type=" + type)
|
||||
//console.log("array=", array);
|
||||
this.imgs = array;
|
||||
|
||||
|
||||
|
||||
var sendImagePackets = (imageData) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
this.isSending = true;
|
||||
this.progress = 0;
|
||||
this.currentPacket = 0;
|
||||
|
||||
// 总数据包数
|
||||
const totalPackets = 1536;
|
||||
this.totalPackets = totalPackets;
|
||||
let currentPacket = 1;
|
||||
let promises = [];
|
||||
// 发送单个数据包
|
||||
const sendNextPacket = () => {
|
||||
////console.log("currentPacket="+currentPacket+",imageData.length="+imageData.length);
|
||||
if (currentPacket > totalPackets) {
|
||||
this.isSending = false;
|
||||
resolve();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// 计算当前包的数据
|
||||
let packetSize = 250;
|
||||
if (type == 'rgb565') {
|
||||
packetSize = 500;
|
||||
}
|
||||
|
||||
// 创建数据包
|
||||
const startIndex = (currentPacket - 1) * packetSize;
|
||||
const endIndex = Math.min(startIndex + packetSize, imageData.length);
|
||||
if (startIndex > endIndex) {
|
||||
resolve();
|
||||
return;
|
||||
}
|
||||
////console.log("111111");
|
||||
const packetData = imageData.slice(startIndex, endIndex);
|
||||
|
||||
// 构建数据包
|
||||
////console.log("packetData.length"+packetData.length);
|
||||
const bufferSize = 506; // 头部5字节 + 数据部分
|
||||
const buffer = new ArrayBuffer(bufferSize);
|
||||
const dataView = new DataView(buffer);
|
||||
|
||||
let sortNo = currentPacket.toString(16).padStart(4, '0');
|
||||
|
||||
// 填充头部
|
||||
dataView.setUint8(0, 0x55); // 帧头
|
||||
dataView.setUint8(1, 0x04); // 帧类型:开机画面
|
||||
dataView.setUint8(2, '0x' + sortNo.substring(0, 2)); // 包序号
|
||||
dataView.setUint8(3, '0x' + sortNo.substring(2, 4)); // 包序号
|
||||
|
||||
|
||||
dataView.setUint8(4, 0x01);
|
||||
dataView.setUint8(5, 0xF4);
|
||||
|
||||
|
||||
if (type == 'rgb565') {
|
||||
for (let i = 0; i < packetData.length; i++) {
|
||||
dataView.setUint8(6 + i, '0x' + packetData[i]);
|
||||
}
|
||||
} else {
|
||||
for (let i = 0; i < packetData.length; i++) {
|
||||
dataView.setUint16(6 + i * 2, packetData[i], false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
let inteval = parseInt(this.inteval ? this.inteval : 0);
|
||||
let promise = this.sendData(buffer);
|
||||
promises.push(promise);
|
||||
let packgeCnt = parseInt(this.packgeCnt || 20);
|
||||
if (currentPacket % packgeCnt == 0 || (currentPacket >= totalPackets &&
|
||||
promises.length > 0)) {
|
||||
Promise.all(promises).then(() => {
|
||||
if (currentPacket >= totalPackets) {
|
||||
this.isSending = false;
|
||||
resolve();
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
this.currentPacket = currentPacket;
|
||||
this.progress = Math.round((currentPacket / totalPackets) *
|
||||
100);
|
||||
currentPacket++;
|
||||
setTimeout(sendNextPacket, inteval);
|
||||
})
|
||||
} else {
|
||||
currentPacket++;
|
||||
sendNextPacket();
|
||||
}
|
||||
// .then(() => {
|
||||
// // 更新进度
|
||||
// this.currentPacket = currentPacket;
|
||||
// this.progress = Math.round((currentPacket / totalPackets) *
|
||||
// 100);
|
||||
|
||||
// currentPacket++;
|
||||
|
||||
|
||||
// setTimeout(sendNextPacket, inteval);
|
||||
// }).catch(err => {
|
||||
|
||||
// console.log(err.errMsg+",发送失败了,正在补偿:" + currentPacket);
|
||||
// setTimeout(sendNextPacket, inteval);
|
||||
|
||||
// });
|
||||
};
|
||||
|
||||
//
|
||||
|
||||
|
||||
sendNextPacket();
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
if (type == 'rgb565') {
|
||||
let start = new Date();
|
||||
console.log("开始发送");
|
||||
sendImagePackets(array).then(() => {
|
||||
|
||||
let end = new Date();
|
||||
|
||||
var diff = (end.getTime() - start.getTime()) / 1000;
|
||||
let s = diff % 60;
|
||||
let m = (diff - s) / 60;
|
||||
console.log("发送完成,耗时:" + m + "分" + s + "秒");
|
||||
uni.showToast({
|
||||
title: "发送完成,耗时:" + m + "分" + s + "秒",
|
||||
icon: 'success',
|
||||
|
||||
})
|
||||
}).catch((ex1) => {
|
||||
//console.log("出现了异常", ex1)
|
||||
}).finally(() => {
|
||||
uni.hideLoading();
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
},
|
||||
HoldYouHand() {
|
||||
|
||||
var promise=new Promise((resolve,reject)=>{
|
||||
try{
|
||||
let start=new Date();
|
||||
var str = "video transmit start"; //握手的协议字符串
|
||||
console.log("开始握手:"+str)
|
||||
|
||||
// 1. 创建 ArrayBuffer 和 DataView
|
||||
const buffer = new ArrayBuffer(str.length);
|
||||
const dataView = new DataView(buffer);
|
||||
|
||||
// 2. 将字符串转换为 ASCII 码并写入 DataView
|
||||
for (let i = 0; i < str.length; i++) {
|
||||
dataView.setUint8(i, str.charCodeAt(i));
|
||||
}
|
||||
//console.log("111111");
|
||||
this.sendData(buffer).then(() => {
|
||||
// 开始发送第一个包
|
||||
setTimeout(()=>{
|
||||
|
||||
let end = new Date();
|
||||
var diff = (end.getTime() - start.getTime()) / 1000;
|
||||
let s = diff % 60;
|
||||
let m = (diff - s) / 60;
|
||||
|
||||
console.log("握手成功并完成2200ms等待,耗时"+m+"分"+s+"秒");
|
||||
|
||||
resolve(true);
|
||||
}, 2200);
|
||||
|
||||
}).catch(err => {
|
||||
//console.log("握手没有成功");
|
||||
reject(err);
|
||||
});
|
||||
}catch(ex){
|
||||
reject(ex);
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
|
||||
return promise;
|
||||
|
||||
},
|
||||
sendData(buffer) {
|
||||
let sendBuffer = () => {
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
var promise = new Promise((succ, err) => {
|
||||
uni.writeBLECharacteristicValue({
|
||||
deviceId: this.connectedDeviceId,
|
||||
serviceId: this.serviceId,
|
||||
characteristicId: this.writeCharacteristicId,
|
||||
value: buffer,
|
||||
writeType: plus.os.name == 'iOS' ? 'write' : 'writeNoResponse',
|
||||
success: () => {
|
||||
// console.log("发送数据成功");
|
||||
succ();
|
||||
},
|
||||
fail: (ex) => {
|
||||
if (ex.code == '10007') {
|
||||
// console.log("失败重试");
|
||||
setTimeout(() => {
|
||||
sendBuffer().then(succ).catch(err);
|
||||
}, this.inteval || 0)
|
||||
// succ()
|
||||
|
||||
} else
|
||||
|
||||
{
|
||||
// console.log("发送数据失败",ex);
|
||||
err(ex);
|
||||
}
|
||||
},
|
||||
complete: function() {
|
||||
//console.log("123456");
|
||||
}
|
||||
});
|
||||
});
|
||||
if (plus.os.name == 'iOS') {
|
||||
|
||||
function timeout(ms) {
|
||||
return new Promise((_, err) => {
|
||||
setTimeout(() => {
|
||||
err({
|
||||
code: -1,
|
||||
errMsg: '超时了'
|
||||
})
|
||||
}, ms);
|
||||
});
|
||||
}
|
||||
|
||||
Promise.race([promise, timeout(this.inteval ? this.inteval : 0)]).then(() => {
|
||||
// console.log("成功了");
|
||||
resolve();
|
||||
})
|
||||
.catch((ex) => {
|
||||
|
||||
if (ex.code == -1) {
|
||||
// console.log("超时了")
|
||||
resolve();
|
||||
} else {
|
||||
reject(ex);
|
||||
// console.log("异常了", ex);
|
||||
//sendBuffer().then(resolve).catch(reject);
|
||||
}
|
||||
|
||||
});
|
||||
} else {
|
||||
|
||||
promise.then(() => {
|
||||
//console.log("then........")
|
||||
resolve();
|
||||
}).catch(() => {
|
||||
//console.log("catch.........")
|
||||
reject()
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
return sendBuffer();
|
||||
},
|
||||
CutImg: function() {
|
||||
if (this.imgs.length == 30) {
|
||||
this.shotVideoClick(this.imgs, 'img');
|
||||
return;
|
||||
}
|
||||
//console.log("开始处理视频")
|
||||
uni.showLoading({
|
||||
title: '开始处理'
|
||||
});
|
||||
this.$refs.compARef.shotVideoClick(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.sending-progress {
|
||||
margin-top: 30rpx;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.progress-bar {
|
||||
height: 12rpx;
|
||||
background-color: #e0e0e0;
|
||||
border-radius: 6rpx;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.progress-fill {
|
||||
height: 100%;
|
||||
background-color: #409eff;
|
||||
transition: width 0.3s;
|
||||
}
|
||||
|
||||
input {
|
||||
border: 2rpx solid #000000;
|
||||
}
|
||||
|
||||
button {
|
||||
height: 100rpx;
|
||||
line-height: 100rpx;
|
||||
font-size: 28rpx;
|
||||
float: left;
|
||||
}
|
||||
|
||||
.content {
|
||||
width: 100vw;
|
||||
height: 300px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
</style>
|
537
pages/BlueTooth/ModeSetting/VideoSend_670.vue
Normal file
@ -0,0 +1,537 @@
|
||||
<template>
|
||||
<view class="content">
|
||||
<canvas canvas-id="flashCanvas"
|
||||
style="width: 160px; height: 80px; z-index: 9999;position: fixed; top:-9999px;left:-9999px;"></canvas>
|
||||
|
||||
<view>
|
||||
<view>
|
||||
选择的视频:{{videoPath}}</view>
|
||||
</view>
|
||||
<view>
|
||||
重发包序号:{{reSendNumber}}
|
||||
</view>
|
||||
<view>
|
||||
<text>发送间隔</text>
|
||||
<input type="text" v-model="inteval" />
|
||||
</view>
|
||||
<view>
|
||||
<button @click="checkVideo">选择视频</button>
|
||||
|
||||
<button @click="uploadVideo">发送</button>
|
||||
</view>
|
||||
|
||||
|
||||
<view class="sending-progress" v-if="isSending">
|
||||
<view class="progress-bar">
|
||||
<view class="progress-fill" :style="{ width: progress + '%' }"></view>
|
||||
</view>
|
||||
<text>正在发送: {{ progress }}% ({{ currentPacket }}/{{ totalPackets }})</text>
|
||||
</view>
|
||||
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import Common from '../../../utils/Common';
|
||||
var mqttClient=null;
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
videoPath: '',
|
||||
inteval: 0,
|
||||
progress: 0,
|
||||
currentPacket: 0,
|
||||
totalPackets: 100,
|
||||
|
||||
connectedDeviceId: '',
|
||||
serviceId: '0xFFE1',
|
||||
writeCharacteristicId: '0xFFE1',
|
||||
notifyCharacteristicId: '0xFFE2',
|
||||
isSending: "",
|
||||
textProgress: "",
|
||||
netMode:"ble",
|
||||
IMEI:"",
|
||||
|
||||
|
||||
imgs: [],
|
||||
videoWidth: 320,
|
||||
videoHeight: 160,
|
||||
videoDuration: 2,
|
||||
|
||||
hexArray: [],
|
||||
reSendNumber:""
|
||||
}
|
||||
},
|
||||
onLoad() {
|
||||
const eventChannel = this.getOpenerEventChannel();
|
||||
|
||||
eventChannel.on('receiveDevice', (data) => {
|
||||
this.connectedDeviceId = data.connectedDeviceId;
|
||||
this.serviceId = data.serviceId;
|
||||
this.writeCharacteristicId = data.writeCharacteristicId;
|
||||
this.notifyCharacteristicId = data.notifyCharacteristicId;
|
||||
this.netMode=data.netMode;
|
||||
mqttClient=data.mqttClient;
|
||||
this.IMEI=data.IMEI;
|
||||
});
|
||||
|
||||
eventChannel.on('ReSendVideo',(data)=>{
|
||||
//重新发送某一包
|
||||
this.reSendNumber=data.videoNo;
|
||||
setTimeout(()=>{
|
||||
this.shotVideoClick(this.hexArray,'rgb565',data.videoNo);
|
||||
},0);
|
||||
|
||||
|
||||
});
|
||||
},
|
||||
methods: {
|
||||
checkVideo: function() {
|
||||
uni.chooseVideo({
|
||||
sourceType: ['album', 'camera'],
|
||||
compressed: false,
|
||||
maxDuration: 2,
|
||||
camera: 'back',
|
||||
success: (res) => {
|
||||
this.videoPath = res.tempFilePath;
|
||||
|
||||
this.imgs = [];
|
||||
this.hexArray = [];
|
||||
|
||||
this.videoWidth = res.width;
|
||||
this.videoHeight = res.height;
|
||||
this.videoDuration = res.duration;
|
||||
console.log("视频宽:" + res.width + ",视频高:" + res.height + ",视频时长:" + res.duration);
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
uploadVideo: function() {
|
||||
|
||||
if (this.hexArray.length > 0) {
|
||||
console.log("开始处理,无需上传");
|
||||
this.shotVideoClick(this.hexArray, 'rgb565');
|
||||
return;
|
||||
|
||||
}
|
||||
if(!this.videoPath){
|
||||
uni.showToast({
|
||||
title: "请选择视频",
|
||||
icon: 'fail'
|
||||
})
|
||||
return;
|
||||
}
|
||||
|
||||
console.log("正在上传视频");
|
||||
uni.showLoading({
|
||||
title: "上传中"
|
||||
});
|
||||
|
||||
let p2=new Promise((resolve,reject)=>{
|
||||
let start = new Date();
|
||||
console.log("Common.baseURL="+Common.baseURL);
|
||||
uni.uploadFile({
|
||||
url:Common.baseURL+'video/upload',
|
||||
filePath: this.videoPath,
|
||||
name: 'file',
|
||||
header: {
|
||||
"Method": "POST",
|
||||
"Content-Type": "multipart/form-data"
|
||||
},
|
||||
timeout: 600000,
|
||||
fail: (ex) => {
|
||||
//console.log("上传视频失败" + JSON.stringify(ex));
|
||||
uni.showToast({
|
||||
title: "视频文件上传失败了,请检查网络连接",
|
||||
icon: 'fail'
|
||||
})
|
||||
uni.hideLoading();
|
||||
reject(ex);
|
||||
},
|
||||
success: (res) => {
|
||||
let end = new Date();
|
||||
var diff = (end.getTime() - start.getTime()) / 1000;
|
||||
let s = diff % 60;
|
||||
let m = (diff - s) / 60;
|
||||
console.log("上传完成,耗时:" + m + "分" + s + "秒");
|
||||
uni.hideLoading();
|
||||
resolve(res);
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
let p1=this.HoldYouHand();
|
||||
|
||||
Promise.all([p2,p1]).then((arr)=>{
|
||||
|
||||
if(arr[1]===true){
|
||||
let res=arr[0];
|
||||
res = JSON.parse(res.data);
|
||||
|
||||
if (res.data) {
|
||||
this.hexArray = res.data;
|
||||
uni.showLoading({
|
||||
title: "正在发送"
|
||||
});
|
||||
|
||||
setTimeout(() => {
|
||||
this.shotVideoClick(res.data, 'rgb565');
|
||||
}, 0)
|
||||
|
||||
} else {
|
||||
console.log("res")
|
||||
uni.showModal({
|
||||
content: "服务器未返回RGB565数据",
|
||||
title: '错误'
|
||||
})
|
||||
}
|
||||
}else{
|
||||
uni.showModal({
|
||||
content:"与设备握手失败了",
|
||||
title:"错误"
|
||||
})
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
},
|
||||
|
||||
shotVideoClick: function(array, type,ReSendNo) {
|
||||
//console.log("处理视频完成", array);
|
||||
//console.log("type=" + type)
|
||||
//console.log("array=", array);
|
||||
this.imgs = array;
|
||||
|
||||
|
||||
|
||||
var sendImagePackets = (imageData) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
this.isSending = true;
|
||||
this.progress = 0;
|
||||
this.currentPacket = 0;
|
||||
|
||||
// 总数据包数
|
||||
var totalPackets = 1536;
|
||||
this.totalPackets = totalPackets;
|
||||
let currentPacket = 1;
|
||||
if(ReSendNo){
|
||||
this.progress = ReSendNo-1;
|
||||
this.currentPacket = ReSendNo-1;
|
||||
currentPacket=ReSendNo;
|
||||
totalPackets=ReSendNo;
|
||||
this.totalPackets=ReSendNo;
|
||||
}
|
||||
// 发送单个数据包
|
||||
const sendNextPacket = () => {
|
||||
////console.log("currentPacket="+currentPacket+",imageData.length="+imageData.length);
|
||||
if (currentPacket > totalPackets) {
|
||||
this.isSending = false;
|
||||
if(!ReSendNo){
|
||||
this.bleSendComplete();
|
||||
}else{
|
||||
// this.reSendNumber="";
|
||||
}
|
||||
|
||||
resolve();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// 计算当前包的数据
|
||||
let packetSize = 250;
|
||||
if (type == 'rgb565') {
|
||||
packetSize = 500;
|
||||
}
|
||||
|
||||
// 创建数据包
|
||||
const startIndex = (currentPacket - 1) * packetSize;
|
||||
const endIndex = Math.min(startIndex + packetSize, imageData.length);
|
||||
if (startIndex > endIndex) {
|
||||
resolve();
|
||||
return;
|
||||
}
|
||||
////console.log("111111");
|
||||
const packetData = imageData.slice(startIndex, endIndex);
|
||||
|
||||
// 构建数据包
|
||||
////console.log("packetData.length"+packetData.length);
|
||||
const bufferSize = 506; // 头部5字节 + 数据部分
|
||||
const buffer = new ArrayBuffer(bufferSize);
|
||||
const dataView = new DataView(buffer);
|
||||
|
||||
let sortNo = currentPacket.toString(16).padStart(4, '0');
|
||||
|
||||
// 填充头部
|
||||
dataView.setUint8(0, 0x55); // 帧头
|
||||
dataView.setUint8(1, 0x04); // 帧类型:开机画面
|
||||
dataView.setUint8(2, '0x' + sortNo.substring(0, 2)); // 包序号
|
||||
dataView.setUint8(3, '0x' + sortNo.substring(2, 4)); // 包序号
|
||||
|
||||
|
||||
dataView.setUint8(4, 0x01);
|
||||
dataView.setUint8(5, 0xF4);
|
||||
|
||||
|
||||
if (type == 'rgb565') {
|
||||
for (let i = 0; i < packetData.length; i++) {
|
||||
dataView.setUint8(6 + i, '0x' + packetData[i]);
|
||||
}
|
||||
} else {
|
||||
for (let i = 0; i < packetData.length; i++) {
|
||||
dataView.setUint16(6 + i * 2, packetData[i], false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
let inteval = parseInt(this.inteval ? this.inteval : 0);
|
||||
this.sendData(buffer).then(() => {
|
||||
// 更新进度
|
||||
this.currentPacket = currentPacket;
|
||||
this.progress = Math.round((currentPacket / totalPackets) *
|
||||
100);
|
||||
console.log(`发送数据包完成 ${currentPacket}/${totalPackets}`);
|
||||
|
||||
// 发送下一个包(添加延迟避免蓝牙缓冲区溢出)
|
||||
currentPacket++;
|
||||
|
||||
|
||||
setTimeout(sendNextPacket, inteval);
|
||||
}).catch(err => {
|
||||
|
||||
console.log(err.errMsg + ",发送失败了,正在补偿:" + currentPacket);
|
||||
setTimeout(sendNextPacket, inteval);
|
||||
// uni.showToast({
|
||||
// title:"发送失败"+JSON.stringify(err)
|
||||
// })
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
sendNextPacket();
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
if (type == 'rgb565') {
|
||||
let start = new Date();
|
||||
console.log("开始发送");
|
||||
sendImagePackets(array).then(() => {
|
||||
console.log("发送完成");
|
||||
let end = new Date();
|
||||
var diff = (end.getTime() - start.getTime()) / 1000;
|
||||
let s = diff % 60;
|
||||
let m = (diff-s) / 60;
|
||||
console.log("发送完成,耗时:" + m + "分" + s + "秒");
|
||||
uni.showModal({
|
||||
content: "发送完成,耗时:" + m + "分" + s + "秒",
|
||||
title: 'success'
|
||||
});
|
||||
|
||||
}).catch((ex1) => {
|
||||
console.log("出现了异常", ex1)
|
||||
}).finally(() => {
|
||||
uni.hideLoading();
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
},
|
||||
HoldYouHand() {
|
||||
|
||||
var promise=new Promise((resolve,reject)=>{
|
||||
try{
|
||||
let start=new Date();
|
||||
var str = "video transmit start"; //握手的协议字符串
|
||||
console.log("开始握手:"+str)
|
||||
|
||||
// 1. 创建 ArrayBuffer 和 DataView
|
||||
const buffer = new ArrayBuffer(str.length);
|
||||
const dataView = new DataView(buffer);
|
||||
|
||||
// 2. 将字符串转换为 ASCII 码并写入 DataView
|
||||
for (let i = 0; i < str.length; i++) {
|
||||
dataView.setUint8(i, str.charCodeAt(i));
|
||||
}
|
||||
//console.log("111111");
|
||||
this.sendData(buffer).then(() => {
|
||||
// 开始发送第一个包
|
||||
setTimeout(()=>{
|
||||
|
||||
let end = new Date();
|
||||
var diff = (end.getTime() - start.getTime()) / 1000;
|
||||
let s = diff % 60;
|
||||
let m = (diff - s) / 60;
|
||||
|
||||
console.log("握手成功并完成2200ms等待,耗时"+m+"分"+s+"秒");
|
||||
|
||||
resolve(true);
|
||||
}, 2200);
|
||||
|
||||
}).catch(err => {
|
||||
//console.log("握手没有成功");
|
||||
reject(err);
|
||||
});
|
||||
}catch(ex){
|
||||
reject(ex);
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
|
||||
return promise;
|
||||
|
||||
},
|
||||
bleSendComplete() {
|
||||
var str = "transmit complete"; //握手的协议字符串
|
||||
let buffer = new ArrayBuffer(str.length);
|
||||
let dataView = new DataView(buffer);
|
||||
for (let i = 0; i < str.length; i++) {
|
||||
dataView.setUint8(i, str.charCodeAt(i));
|
||||
}
|
||||
setTimeout(()=>{
|
||||
this.sendData(buffer).then(() => {
|
||||
console.log("完成指令发送成功");
|
||||
}).catch(err => {
|
||||
console.log("完成指令发送失败");
|
||||
});
|
||||
},1500)
|
||||
|
||||
},
|
||||
sendData(buffer) {
|
||||
if(this.netMode=='ble'){
|
||||
return this.sendBle(buffer);
|
||||
|
||||
}
|
||||
|
||||
return this.sendMQ(buffer);
|
||||
},
|
||||
sendBle(buffer){
|
||||
return new Promise(async (resolve, reject) => {
|
||||
|
||||
// //console.log("开始发送数据,buffer");
|
||||
|
||||
|
||||
var promise = new Promise((succ, err) => {
|
||||
uni.writeBLECharacteristicValue({
|
||||
deviceId: this.connectedDeviceId,
|
||||
serviceId: this.serviceId,
|
||||
characteristicId: this.writeCharacteristicId,
|
||||
value: buffer,
|
||||
writeType: plus.os.name == 'iOS' ? 'write' : 'writeNoResponse',
|
||||
success: () => {
|
||||
// //console.log("发送数据成功");
|
||||
succ();
|
||||
},
|
||||
fail: (ex) => {
|
||||
//console.log("发送数据失败", ex);
|
||||
err(ex);
|
||||
},
|
||||
complete: function() {
|
||||
// //console.log("123456");
|
||||
}
|
||||
});
|
||||
});
|
||||
if (plus.os.name == 'iOS') {
|
||||
|
||||
function timeout(ms) {
|
||||
return new Promise((_, err) => {
|
||||
setTimeout(() => {
|
||||
err({
|
||||
code: -1,
|
||||
errMsg: '超时了'
|
||||
})
|
||||
}, ms);
|
||||
});
|
||||
}
|
||||
|
||||
let inteval = parseInt(this.inteval ? this.inteval : 0);
|
||||
|
||||
Promise.race([promise, timeout(inteval)]).then(resolve).catch((ex) => {
|
||||
//console.log("ex=", ex);
|
||||
if (ex.code == -1) {
|
||||
resolve();
|
||||
} else {
|
||||
reject();
|
||||
}
|
||||
|
||||
}).finally(() => {
|
||||
//console.log("完成了")
|
||||
});
|
||||
} else {
|
||||
promise.then(resolve).catch(reject);
|
||||
}
|
||||
});
|
||||
},
|
||||
sendMQ(message) {
|
||||
|
||||
const topic = `B/${this.IMEI}`;
|
||||
return new Promise((resolve, reject) => {
|
||||
if(!mqttClient){
|
||||
reject("MQTT未连接");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
let flag=mqttClient.publish(topic, message, {
|
||||
qos: 1
|
||||
});
|
||||
if(flag){
|
||||
resolve();
|
||||
return;
|
||||
}
|
||||
reject("MQTT未连接,无法发布消息");
|
||||
} catch (error) {
|
||||
reject(error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.sending-progress {
|
||||
margin-top: 30rpx;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.progress-bar {
|
||||
height: 12rpx;
|
||||
background-color: #e0e0e0;
|
||||
border-radius: 6rpx;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.progress-fill {
|
||||
height: 100%;
|
||||
background-color: #409eff;
|
||||
transition: width 0.3s;
|
||||
}
|
||||
|
||||
input {
|
||||
border: 2rpx solid #000000;
|
||||
}
|
||||
|
||||
button {
|
||||
height: 100rpx;
|
||||
line-height: 100rpx;
|
||||
font-size: 28rpx;
|
||||
float: left;
|
||||
}
|
||||
|
||||
.content {
|
||||
width: 100vw;
|
||||
height: 300px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
</style>
|
115
pages/BlueTooth/ModeSetting/index.vue
Normal file
@ -0,0 +1,115 @@
|
||||
<template>
|
||||
<view class="container">
|
||||
<view class="grid">
|
||||
<view class="cell" @click="goToDetail(item.name)" v-for="item,index in options">{{item.url}}</view>
|
||||
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
options: [{
|
||||
name: '/pages/BlueTooth/ModeSetting/ModeSetting',
|
||||
url: '7307'
|
||||
},
|
||||
{
|
||||
name: '/pages/BlueTooth/ModeSetting/HBY650',
|
||||
url: 'HBY650'
|
||||
},
|
||||
{
|
||||
name: '/pages/BlueTooth/ModeSetting/HBY650_1',
|
||||
url: 'HBY650_V1'
|
||||
},
|
||||
|
||||
{
|
||||
name: '/pages/BlueTooth/ModeSetting/HBY6155',
|
||||
url: '6155'
|
||||
},
|
||||
{
|
||||
name: '/pages/BlueTooth/ModeSetting/HBY6155V1',
|
||||
url: '6155_V1'
|
||||
},
|
||||
{
|
||||
name: "/pages/BlueTooth/ModeSetting/HBY670V1",
|
||||
url: 'HBY670'
|
||||
},
|
||||
|
||||
{
|
||||
name: '/pages/MapTest/MapTest',
|
||||
url: '地图测试'
|
||||
},
|
||||
{
|
||||
name: '',
|
||||
url: '更多'
|
||||
}
|
||||
|
||||
]
|
||||
|
||||
}
|
||||
},
|
||||
onShow: () => {
|
||||
|
||||
},
|
||||
methods: {
|
||||
goToDetail: function(url) {
|
||||
console.log("url=" + url)
|
||||
let qd = () => {
|
||||
uni.showToast({
|
||||
title: '敬请期待',
|
||||
duration: 2000,
|
||||
icon: "none"
|
||||
});
|
||||
|
||||
};
|
||||
if (url) {
|
||||
uni.navigateTo({
|
||||
url: url,
|
||||
success: () => {
|
||||
|
||||
},
|
||||
fail: () => {
|
||||
qd();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
qd();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.container {
|
||||
padding: 15px;
|
||||
background-color: #f5f5f5;
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
.grid {
|
||||
display: flex;
|
||||
align-content: space-around;
|
||||
align-items: stretch;
|
||||
justify-items: center;
|
||||
flex-direction: row;
|
||||
flex-wrap: wrap;
|
||||
justify-content: flex-start;
|
||||
}
|
||||
|
||||
.cell {
|
||||
padding: 0rpx 20rpx;
|
||||
border: 2rpx solid rgba(0, 0, 0, 0.3);
|
||||
border-radius: 15rpx;
|
||||
font-size: 28rpx;
|
||||
height: 70rpx;
|
||||
line-height: 70rpx;
|
||||
margin-left: 30rpx;
|
||||
margin-top: 20rpx;
|
||||
}
|
||||
</style>
|
273
pages/BlueTooth/ModeSetting/update.vue
Normal file
@ -0,0 +1,273 @@
|
||||
<template>
|
||||
<view class="update-container">
|
||||
<!-- 进度条 -->
|
||||
<view v-if="showProgress" class="progress-container">
|
||||
<view class="progress-title">正在更新 {{ progress }}%</view>
|
||||
<view class="progress-bar">
|
||||
<view class="progress" :style="{ width: progress + '%' }"></view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 更新提示弹窗 -->
|
||||
<view v-if="showUpdateDialog" class="dialog-mask">
|
||||
<view class="dialog">
|
||||
<view class="dialog-title">发现新版本 v{{ newVersion }}</view>
|
||||
<view class="dialog-content">{{ updateInfo.desc || '有新的功能和优化,建议立即更新' }}</view>
|
||||
<view class="dialog-buttons">
|
||||
<button v-if="!updateInfo.force" class="cancel-btn" @click="showUpdateDialog = false">稍后更新</button>
|
||||
<button class="confirm-btn" @click="startUpdate">立即更新</button>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
// 当前版本
|
||||
currentVersion: '',
|
||||
// 最新版本
|
||||
newVersion: '',
|
||||
// 更新信息
|
||||
updateInfo: {},
|
||||
// 是否显示更新弹窗
|
||||
showUpdateDialog: false,
|
||||
// 是否显示进度条
|
||||
showProgress: false,
|
||||
// 更新进度
|
||||
progress: 0
|
||||
};
|
||||
},
|
||||
|
||||
onLoad() {
|
||||
// 初始化时检查版本
|
||||
this.checkVersion();
|
||||
},
|
||||
|
||||
methods: {
|
||||
/**
|
||||
* 检查当前版本
|
||||
*/
|
||||
async checkVersion() {
|
||||
try {
|
||||
// 获取当前应用版本
|
||||
const versionInfo = plus.runtime.version;
|
||||
this.currentVersion = versionInfo;
|
||||
console.log('当前版本:', this.currentVersion);
|
||||
|
||||
// 调用后端接口检查最新版本
|
||||
// 这里替换为你的后端接口地址
|
||||
const res = await this.$http.get('/api/checkVersion', {
|
||||
platform: uni.getSystemInfoSync().platform,
|
||||
version: this.currentVersion
|
||||
});
|
||||
|
||||
if (res.code === 0 && res.data.hasUpdate) {
|
||||
this.newVersion = res.data.version;
|
||||
this.updateInfo = res.data;
|
||||
// 显示更新提示
|
||||
this.showUpdateDialog = true;
|
||||
} else {
|
||||
console.log('当前已是最新版本');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('版本检查失败:', error);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 开始更新
|
||||
*/
|
||||
startUpdate() {
|
||||
if (!this.updateInfo.downloadUrl) {
|
||||
uni.showToast({
|
||||
title: '更新地址不存在',
|
||||
icon: 'none'
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
this.showUpdateDialog = false;
|
||||
this.showProgress = true;
|
||||
this.downloadWgt(this.updateInfo.downloadUrl);
|
||||
},
|
||||
|
||||
/**
|
||||
* 下载wgt包
|
||||
*/
|
||||
downloadWgt(url) {
|
||||
const downloadTask = uni.downloadFile({
|
||||
url: url,
|
||||
success: (downloadResult) => {
|
||||
if (downloadResult.statusCode === 200) {
|
||||
// 下载成功,安装wgt包
|
||||
this.installWgt(downloadResult.tempFilePath);
|
||||
} else {
|
||||
this.showProgress = false;
|
||||
uni.showToast({
|
||||
title: '下载失败',
|
||||
icon: 'none'
|
||||
});
|
||||
}
|
||||
},
|
||||
fail: (err) => {
|
||||
this.showProgress = false;
|
||||
console.error('下载失败:', err);
|
||||
uni.showToast({
|
||||
title: '下载失败,请稍后重试',
|
||||
icon: 'none'
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// 监听下载进度
|
||||
downloadTask.onProgressUpdate((res) => {
|
||||
this.progress = res.progress;
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* 安装wgt包
|
||||
*/
|
||||
installWgt(path) {
|
||||
plus.runtime.install(
|
||||
path,
|
||||
{
|
||||
force: false // 是否强制安装
|
||||
},
|
||||
() => {
|
||||
console.log('安装成功');
|
||||
this.showProgress = false;
|
||||
|
||||
// 安装成功后提示重启
|
||||
uni.showModal({
|
||||
title: '更新完成',
|
||||
content: '应用已更新,是否立即重启?',
|
||||
showCancel: !this.updateInfo.force,
|
||||
success: (res) => {
|
||||
if (res.confirm) {
|
||||
// 重启应用
|
||||
plus.runtime.restart();
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
(err) => {
|
||||
console.error('安装失败:', err);
|
||||
this.showProgress = false;
|
||||
uni.showToast({
|
||||
title: '更新失败: ' + err.message,
|
||||
icon: 'none',
|
||||
duration: 3000
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.update-container {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
pointer-events: none;
|
||||
z-index: 9999;
|
||||
}
|
||||
|
||||
/* 进度条样式 */
|
||||
.progress-container {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
background-color: #fff;
|
||||
padding: 10rpx 20rpx;
|
||||
pointer-events: auto;
|
||||
}
|
||||
|
||||
.progress-title {
|
||||
font-size: 28rpx;
|
||||
color: #333;
|
||||
margin-bottom: 10rpx;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.progress-bar {
|
||||
height: 8rpx;
|
||||
background-color: #eee;
|
||||
border-radius: 4rpx;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.progress {
|
||||
height: 100%;
|
||||
background-color: #007aff;
|
||||
transition: width 0.3s ease;
|
||||
}
|
||||
|
||||
/* 弹窗样式 */
|
||||
.dialog-mask {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background-color: rgba(0, 0, 0, 0.5);
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
pointer-events: auto;
|
||||
}
|
||||
|
||||
.dialog {
|
||||
width: 600rpx;
|
||||
background-color: #fff;
|
||||
border-radius: 16rpx;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.dialog-title {
|
||||
font-size: 36rpx;
|
||||
font-weight: bold;
|
||||
color: #333;
|
||||
padding: 30rpx;
|
||||
text-align: center;
|
||||
border-bottom: 1px solid #eee;
|
||||
}
|
||||
|
||||
.dialog-content {
|
||||
font-size: 32rpx;
|
||||
color: #666;
|
||||
padding: 40rpx 30rpx;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.dialog-buttons {
|
||||
display: flex;
|
||||
border-top: 1px solid #eee;
|
||||
}
|
||||
|
||||
.cancel-btn, .confirm-btn {
|
||||
flex: 1;
|
||||
height: 100rpx;
|
||||
line-height: 100rpx;
|
||||
font-size: 32rpx;
|
||||
border: none;
|
||||
background-color: transparent;
|
||||
}
|
||||
|
||||
.cancel-btn {
|
||||
color: #666;
|
||||
border-right: 1px solid #eee;
|
||||
}
|
||||
|
||||
.confirm-btn {
|
||||
color: #007aff;
|
||||
}
|
||||
</style>
|
@ -1,22 +1,308 @@
|
||||
<template>
|
||||
<view>
|
||||
|
||||
<view class="content">
|
||||
<view class="deviceDetail">
|
||||
<view class="imgContent">
|
||||
<image src="/static/images/BLEAdd/addBleDevice.png" class="titleIco" mode="aspectFit">
|
||||
</image>
|
||||
</view>
|
||||
<view class="deviceName">
|
||||
蓝牙名:{{device.name}}
|
||||
</view>
|
||||
<view class="deviceName">
|
||||
设备名:{{device.deviceName}}
|
||||
</view>
|
||||
<view class="deviceId">
|
||||
ID:{{device.deviceId}}
|
||||
</view>
|
||||
<view class="bound" v-bind:class="boundStatu">
|
||||
{{Statu.boundRemark}}
|
||||
</view>
|
||||
</view>
|
||||
<view class="btnLink" @click="Link()">
|
||||
连接
|
||||
</view>
|
||||
|
||||
<global-loading ref="loading" />
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import request from '@/utils/request.js';
|
||||
import bleTool from '@/utils/BleHelper.js';
|
||||
import {
|
||||
showLoading,
|
||||
hideLoading,
|
||||
updateLoading
|
||||
} from '@/utils/loading.js';
|
||||
|
||||
const pagePath="pages/common/addBLE/LinkBle";
|
||||
|
||||
var these = null;
|
||||
var eventChannel = null;
|
||||
var ble = null;
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
|
||||
Statu: {
|
||||
bound: null
|
||||
},
|
||||
device: {
|
||||
"deviceId": "",
|
||||
"name": "",
|
||||
"deviceName": "",
|
||||
"RSSI": -37,
|
||||
"localName": "",
|
||||
"advertisServiceUUIDs": [
|
||||
|
||||
],
|
||||
"linkStatu": false,
|
||||
"macAddress": ""
|
||||
}
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
computed: {
|
||||
boundStatu: function() {
|
||||
if (this.Statu.bound === null) {
|
||||
return "displayNone"
|
||||
}
|
||||
if (this.Statu.bound) {
|
||||
return "green"
|
||||
} else {
|
||||
return "red";
|
||||
}
|
||||
}
|
||||
},
|
||||
onBackPress() {
|
||||
console.log("返回时断开蓝牙连接,取消订阅");
|
||||
ble.disconnectDevice(these.device.deviceId);
|
||||
ble.removeReceiveCallback(pagePath);
|
||||
},
|
||||
onUnload() {
|
||||
console.log("返回时断开蓝牙连接,取消订阅");
|
||||
ble.removeReceiveCallback(pagePath);
|
||||
},
|
||||
onLoad(option) {
|
||||
these = this;
|
||||
ble = bleTool.getBleTool();
|
||||
ble.addReceiveCallback((receive,f,path) => {
|
||||
console.log("收到设备消息,", receive);
|
||||
if (these.device.deviceId == receive.deviceId) {
|
||||
// console.log("11111");
|
||||
|
||||
if (receive.bytes[0] == 0xFC || receive.str.indexOf('mac address:') == 0) {
|
||||
if (f && f.macAddress) {
|
||||
these.device.macAddress = f.macAddress;
|
||||
// console.log("222222");
|
||||
these.initDevice();
|
||||
}
|
||||
}
|
||||
}
|
||||
},pagePath);
|
||||
eventChannel = this.getOpenerEventChannel();
|
||||
eventChannel.on('LinkItem', function(data) {
|
||||
console.log("data=",data);
|
||||
let f = ble.data.LinkedList.find((v) => {
|
||||
return v.deviceId == data.deviceId;
|
||||
});
|
||||
if (f) {
|
||||
let keys=Object.keys(f);
|
||||
keys.forEach((v,index)=>{
|
||||
these.device[v]=f[v];
|
||||
})
|
||||
console.log("LinkedList=",ble.data.LinkedList)
|
||||
console.log("f=", f);
|
||||
console.log("获取到设备", these.device);
|
||||
if (f.macAddress) {
|
||||
these.device.macAddress = f.macAddress;
|
||||
|
||||
these.initDevice();
|
||||
}
|
||||
} else {
|
||||
console.log("未获取到设备");
|
||||
}
|
||||
})
|
||||
},
|
||||
methods: {
|
||||
|
||||
initDevice: function() {
|
||||
showLoading(these, {
|
||||
text: '正在获取设备信息'
|
||||
});
|
||||
console.log("these.device=",these.device);
|
||||
request({
|
||||
url: '/app/device/getDeviceInfoByDeviceMac',
|
||||
method: 'GET',
|
||||
data: {
|
||||
deviceMac: these.device.macAddress
|
||||
}
|
||||
}).then(res => {
|
||||
console.log("获取设备信息", res);
|
||||
if (res && res.code == 200) {
|
||||
let data = res.data;
|
||||
if (data) {
|
||||
let keys = Object.keys(data);
|
||||
ble.data.LinkedList.find((v) => {
|
||||
if(v.deviceId == these.device.deviceId){
|
||||
for (var i = 0; i < keys.length; i++) {
|
||||
let key = keys[i];
|
||||
v[key] = data[key];
|
||||
// console.log("key="+key);
|
||||
// console.log("value="+data[key]);
|
||||
|
||||
|
||||
these.$set(these.device, key, data[key]);
|
||||
|
||||
}
|
||||
|
||||
ble.setBleData();
|
||||
}
|
||||
});
|
||||
|
||||
console.log("device=",these.device);
|
||||
console.log("LinkedList=",ble.data.LinkedList);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}).catch((ex) => {
|
||||
console.log("获取设备出现异常:", ex);
|
||||
}).finally(() => {
|
||||
hideLoading(these);
|
||||
});
|
||||
},
|
||||
Link() {
|
||||
// 调用绑定设备接口
|
||||
|
||||
let f = ble.data.LinkedList.find((v) => {
|
||||
return v.deviceId == these.device.deviceId;
|
||||
});
|
||||
if (!f) {
|
||||
these.Statu.bound = false;
|
||||
these.Statu.boundRemark = "蓝牙连接不成功";
|
||||
return;
|
||||
}
|
||||
if (!f.macAddress) {
|
||||
these.Statu.bound = false;
|
||||
these.Statu.boundRemark = "设备上报Mac地址异常";
|
||||
return;
|
||||
}
|
||||
these.Statu.bound = null;
|
||||
these.Statu.boundRemark = "";
|
||||
showLoading(these, {
|
||||
|
||||
text: "连接中..."
|
||||
})
|
||||
let promise = request({
|
||||
url: '/app/device/bind',
|
||||
method: 'POST',
|
||||
data: {
|
||||
deviceImei: '',
|
||||
deviceMac: these.device.macAddress,
|
||||
communicationMode: '1', //0是4g,1是蓝牙
|
||||
}
|
||||
});
|
||||
promise.then((res) => {
|
||||
console.log("1111" + JSON.stringify(res));
|
||||
if (res.code == 200) {
|
||||
these.Statu.bound = true;
|
||||
these.Statu.boundRemark = "设备绑定成功!";
|
||||
ble.removeReceiveCallback(pagePath);
|
||||
|
||||
uni.$emit("refreshDeviceList");
|
||||
setTimeout(() => {
|
||||
uni.switchTab({
|
||||
url: "/pages/common/index/index"
|
||||
});
|
||||
}, 500);
|
||||
} else {
|
||||
these.Statu.bound = false;
|
||||
these.Statu.boundRemark = res.msg;
|
||||
}
|
||||
}).catch((ex) => {
|
||||
these.Statu.bound = false;
|
||||
these.Statu.boundRemark = '出现了未知的异常,操作失败';
|
||||
}).finally(() => {
|
||||
hideLoading(this);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.content {
|
||||
background-color: #1d1d1d;
|
||||
color: #ffffffde;
|
||||
box-sizing: border-box;
|
||||
overflow: hidden;
|
||||
width: 100%;
|
||||
min-height: 100vh;
|
||||
height: auto;
|
||||
font-family: "PingFang SC";
|
||||
}
|
||||
|
||||
</style>
|
||||
.deviceDetail {
|
||||
margin: 200rpx auto;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
flex-wrap: nowrap;
|
||||
align-content: center;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.imgContent,
|
||||
.titleIco {
|
||||
width: 120rpx;
|
||||
height: 120rpx;
|
||||
}
|
||||
|
||||
.deviceId {
|
||||
color: rgba(255, 255, 255, 0.87);
|
||||
font-size: 32rpx;
|
||||
|
||||
line-height: 44rpx;
|
||||
letter-spacing: 0.14rpx;
|
||||
margin-top: 5rpx;
|
||||
}
|
||||
|
||||
.btnLink {
|
||||
position: fixed;
|
||||
bottom: 30rpx;
|
||||
left: 30rpx;
|
||||
right: 30rpx;
|
||||
width: calc(100% - 60rpx);
|
||||
border-radius: 91px;
|
||||
height: 90rpx;
|
||||
background: rgba(187, 230, 0, 1);
|
||||
color: rgba(35, 35, 35, 1);
|
||||
|
||||
|
||||
font-size: 32rpx;
|
||||
line-height: 90rpx;
|
||||
letter-spacing: 12rpx;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.bound,
|
||||
.deviceName {
|
||||
font-size: 32rpx;
|
||||
font-weight: 400;
|
||||
line-height: 44rpx;
|
||||
letter-spacing: 0.14rpx;
|
||||
margin-top: 5rpx;
|
||||
}
|
||||
|
||||
.displayNone {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
.green {
|
||||
color: rgba(187, 230, 0, 1);
|
||||
}
|
||||
|
||||
.red {
|
||||
color: rgba(245, 80, 80, 1);
|
||||
}
|
||||
</style>
|
@ -81,13 +81,22 @@
|
||||
</view>
|
||||
</view>
|
||||
</BottomSlideMenuPlus>
|
||||
|
||||
<global-loading ref="loading" />
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import ble from '../../../api/6155/BlueHelper.js';
|
||||
import request from '../../../utils/request.js';
|
||||
|
||||
import bleTool from '@/utils/BleHelper.js';
|
||||
import request from '@/utils/request.js';
|
||||
import {
|
||||
showLoading,
|
||||
hideLoading,
|
||||
updateLoading
|
||||
} from '@/utils/loading.js'
|
||||
const pagePath="pages/common/addBLE/addEquip";
|
||||
var ble = null;
|
||||
var these = null;
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
@ -127,72 +136,70 @@
|
||||
},
|
||||
onHide: function() {
|
||||
ble.StopSearch();
|
||||
|
||||
},
|
||||
onBackPress: (e) => {
|
||||
ble.StopSearch();
|
||||
ble.disconnectDevice();
|
||||
ble.removeDeviceFound(pagePath);
|
||||
ble.removeReceiveCallback(pagePath);
|
||||
},
|
||||
onUnload(){
|
||||
ble.StopSearch();
|
||||
|
||||
},
|
||||
onLoad() {
|
||||
these = this;
|
||||
ble = bleTool.getBleTool();
|
||||
ble.addDeviceFound((arr) => {
|
||||
|
||||
arr = arr.devices;
|
||||
for (var i = 0; i < arr.length; i++) {
|
||||
|
||||
onShow: function() {
|
||||
// return;
|
||||
var these = this;
|
||||
uni.getStorage({
|
||||
key: "linkedDevices",
|
||||
success: (res) => {
|
||||
this.PairEquip = JSON.parse(res.data);
|
||||
},
|
||||
fail: (ex) => {
|
||||
this.PairEquip = [];
|
||||
}
|
||||
});
|
||||
|
||||
if (process.env.UNI_PLATFORM == 'mp-weixin' ||
|
||||
process.env.UNI_PLATFORM == 'mp-alipay' ||
|
||||
process.env.UNI_PLATFORM == 'app-plus' ||
|
||||
process.env.UNI_PLATFORM == 'app'
|
||||
|
||||
) {
|
||||
//打开蓝牙开始搜索设备
|
||||
ble.OpenBlue(true, () => {
|
||||
ble.StartSearch(function(arr) {
|
||||
|
||||
arr = arr.devices;
|
||||
for (var i = 0; i < arr.length; i++) {
|
||||
|
||||
arr[i].linkStatu = false;
|
||||
let f = these.EquipMents.find(function(v) {
|
||||
return v.deviceId == arr[i].deviceId;
|
||||
});
|
||||
|
||||
if (!f) {
|
||||
these.EquipMents.push(arr[i]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
console.log("设备列表:" + JSON.stringify(these.EquipMents));
|
||||
});
|
||||
},
|
||||
() => {
|
||||
these.showOpenSetting();
|
||||
arr[i].linkStatu = false;
|
||||
if(!arr[i].name){
|
||||
continue;
|
||||
}
|
||||
let f = these.EquipMents.find(function(v) {
|
||||
return v.deviceId == arr[i].deviceId;
|
||||
});
|
||||
|
||||
if (!f) {
|
||||
|
||||
these.EquipMents.push(arr[i]);
|
||||
} else {
|
||||
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
|
||||
} else {
|
||||
console.log('当前环境:' + process.env.UNI_PLATFORM + '不支持蓝牙');
|
||||
}
|
||||
}
|
||||
},pagePath);
|
||||
// ble.addReceiveCallback((receivData) => {
|
||||
// console.log("收到数据了:", receivData);//数据格式:{bytes:[109,97],str:"",hexs:"FA 01"}
|
||||
|
||||
// // let data=uni.getStorageSync(ble.StorageKey);
|
||||
// console.log("LinkedList=",ble.data.LinkedList);
|
||||
// },pagePath);
|
||||
},
|
||||
|
||||
onShow: function() {
|
||||
|
||||
|
||||
this.EquipMents=[];
|
||||
this.PairEquip=[];
|
||||
ble.StartSearch().catch((ex) => {
|
||||
if (ex.code == 10001) {
|
||||
these.showOpenSetting();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
},
|
||||
methods: {
|
||||
isItemLink: function(item, index) {
|
||||
let src = '/static/images/BLEAdd/noLink.png';
|
||||
if (this.PairEquip && this.PairEquip instanceof Array) {
|
||||
|
||||
if (this.PairEquip && this.PairEquip.length) {
|
||||
if (this.PairEquip.length > 0) {
|
||||
let f = this.PairEquip.find(function(v) {
|
||||
return v.deviceId == item.deviceId;
|
||||
@ -206,114 +213,56 @@
|
||||
}
|
||||
return src;
|
||||
},
|
||||
alert: function(title, content, callback) {
|
||||
if (!title) {
|
||||
title = '提示'
|
||||
}
|
||||
if (!content) {
|
||||
content = title;
|
||||
}
|
||||
|
||||
uni.showModal({
|
||||
title: title,
|
||||
content: content,
|
||||
success: function(res) {
|
||||
if (res.confirm) {
|
||||
console.log('用户点击确定');
|
||||
} else if (res.cancel) {
|
||||
console.log('用户点击取消');
|
||||
}
|
||||
|
||||
if (callback) {
|
||||
callback(res);
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
showOpenSetting: function() {
|
||||
this.Status.BottomMenu.show = true;
|
||||
},
|
||||
gotoSetting: function() {
|
||||
this.Status.BottomMenu.show = false;
|
||||
ble.showBluetoothGuide(false);
|
||||
ble.showBlueSetting(false);
|
||||
},
|
||||
Link: function(item, index) {
|
||||
var these = this;
|
||||
if (process.env.UNI_PLATFORM == 'mp-weixin' ||
|
||||
process.env.UNI_PLATFORM == 'mp-alipay' ||
|
||||
process.env.UNI_PLATFORM == 'app-plus' ||
|
||||
process.env.UNI_PLATFORM == 'app'
|
||||
) {
|
||||
|
||||
uni.showLoading({
|
||||
title: "正在连接",
|
||||
mask: true
|
||||
});
|
||||
setTimeout(() => {
|
||||
|
||||
|
||||
ble.LinkBlue(item.deviceId, function() {
|
||||
let c = these.PairEquip.find(function(v) {
|
||||
return v.deviceId == item.deviceId;
|
||||
});
|
||||
if (!c) {
|
||||
these.PairEquip.push(item);
|
||||
uni.setStorage({
|
||||
key: 'linkedDevices',
|
||||
data: JSON.stringify(these.PairEquip),
|
||||
success: () => {}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// 调用绑定设备接口
|
||||
let promise = request({
|
||||
url: '/app/device/bind',
|
||||
method: 'POST',
|
||||
data: {
|
||||
deviceImei: '',
|
||||
deviceMac: item.deviceId,
|
||||
communicationMode: '1', //0是4g,1是蓝牙
|
||||
}
|
||||
});
|
||||
promise.then((res) => {
|
||||
console.log("1111" + JSON.stringify(res));
|
||||
if (res.code == 0) {
|
||||
|
||||
uni.hideLoading()
|
||||
uni.showToast({
|
||||
title: res.data,
|
||||
icon: 'success'
|
||||
});
|
||||
|
||||
|
||||
} else {
|
||||
uni.showToast({
|
||||
title: res.msg,
|
||||
});
|
||||
}
|
||||
}).catch((ex) => {
|
||||
|
||||
uni.showToast({
|
||||
title: '出现了未知的异常,操作失败',
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}, (ex) => {
|
||||
uni.hideLoading();
|
||||
|
||||
showLoading(this,{
|
||||
text: "正在连接"
|
||||
});
|
||||
setTimeout(() => {
|
||||
let serviceid=null;
|
||||
if(item.advertisServiceUUIDs.length>0){
|
||||
serviceid=item.advertisServiceUUIDs[0];
|
||||
}
|
||||
ble.LinkBlue(item.deviceId,serviceid).then((res) => {
|
||||
let c = these.PairEquip.find(function(v) {
|
||||
return v.deviceId == item.deviceId;
|
||||
});
|
||||
}, 0);
|
||||
if (!c) {
|
||||
|
||||
these.PairEquip.push(item);
|
||||
}
|
||||
console.log("连接成功");
|
||||
uni.navigateTo({
|
||||
url:"/pages/common/addBLE/LinkBle",
|
||||
events:{
|
||||
|
||||
},
|
||||
success(res) {
|
||||
|
||||
res.eventChannel.emit('LinkItem', item);
|
||||
}
|
||||
});
|
||||
|
||||
}).catch((ex) => {
|
||||
console.log("ex=",ex)
|
||||
uni.showModal({
|
||||
content:"连接失败:"+ex.msg
|
||||
});
|
||||
}).finally(()=>{
|
||||
hideLoading(this);
|
||||
});
|
||||
}, 0);
|
||||
|
||||
|
||||
} else {
|
||||
these.alert("提示", "当前平台不支持蓝牙");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -451,7 +400,7 @@
|
||||
|
||||
.mainContent .lblTitle {
|
||||
color: #ffffffde;
|
||||
font-family: PingFang SC;
|
||||
font-family: "PingFang SC";
|
||||
font-size: 28rpx;
|
||||
font-weight: 700;
|
||||
text-align: left;
|
||||
@ -516,7 +465,7 @@
|
||||
|
||||
.list .item .name {
|
||||
color: #ffffffde;
|
||||
font-family: PingFang SC;
|
||||
font-family: "PingFang SC";
|
||||
font-size: 26rpx;
|
||||
font-weight: 400;
|
||||
line-height: 50rpx;
|
||||
@ -525,7 +474,7 @@
|
||||
|
||||
.list .item .id {
|
||||
color: #ffffff99;
|
||||
font-family: PingFang SC;
|
||||
font-family: "PingFang SC";
|
||||
font-size: 24rpx;
|
||||
font-weight: 400;
|
||||
line-height: 30rpx;
|
||||
@ -547,7 +496,7 @@
|
||||
|
||||
.openBlue .txt {
|
||||
color: rgba(255, 255, 255, 0.87);
|
||||
font-family: PingFang SC;
|
||||
font-family: "PingFang SC";
|
||||
font-size: 28rpx;
|
||||
font-weight: 400;
|
||||
letter-spacing: 0.14rpx;
|
||||
@ -572,7 +521,7 @@
|
||||
width: 25%;
|
||||
height: 60rpx;
|
||||
text-align: center;
|
||||
font-family: PingFang SC;
|
||||
font-family: "PingFang SC";
|
||||
font-size: 28rpx;
|
||||
letter-spacing: 12rpx;
|
||||
display: flex !important;
|
||||
@ -584,10 +533,12 @@
|
||||
justify-content: center;
|
||||
|
||||
}
|
||||
|
||||
.openBlue .cancel {
|
||||
border: 1px solid rgba(255, 255, 255, 1);
|
||||
color: rgba(255, 255, 255, 1);
|
||||
}
|
||||
|
||||
.openBlue .ok {
|
||||
background-color: #BBE600;
|
||||
color: #232323;
|
||||
|
@ -19,7 +19,7 @@
|
||||
</view>
|
||||
</view>
|
||||
<view class="sendFlex"
|
||||
v-if="activeTab && activeTab.id !== ''&& activeTabInfo.communicationMode==0 && activeTabInfo.typeName=='BJQ6170'">
|
||||
v-if="activeTab && activeTab.id !== ''&& activeTabInfo.communicationMode==0">
|
||||
<view class="callpolice" @click="callpolice">报警</view>
|
||||
<view class="Sendmessage" @click="location">位置</view>
|
||||
<view class="Sendmessage" @click="handleSend">发送信息</view>
|
||||
@ -31,7 +31,7 @@
|
||||
<block v-for="(item, index) in deviceList" :key="index" :ref="'swipeItem_' + index">
|
||||
<uni-swipe-action-item :right-options="Options"
|
||||
@click="handleSwipeClick($event, item, index)" class="device-card"
|
||||
:style="{ border: item.communicationMode==0 && item.onlineStatus==0 ? '1px solid rgba(224, 52, 52, 1)' : 'none' }">
|
||||
:style="{ border: item.communicationMode==0 && item.onlineStatus==1 && item.alarmStatus==1 ? '1px solid rgba(224, 52, 52, 1)' : 'none' }">
|
||||
<view @click.stop="handleFile(item)">
|
||||
<view class="device-header">
|
||||
<view class="deviceIMG">
|
||||
@ -54,7 +54,8 @@
|
||||
</view>
|
||||
</view>
|
||||
<view class="device-callpolice"
|
||||
v-if="item.communicationMode==0 && item.onlineStatus==0">报警中</view>
|
||||
v-if="item.communicationMode==0 && item.onlineStatus==1 && item.alarmStatus==1">
|
||||
报警中</view>
|
||||
<view v-if="item.communicationMode==1">
|
||||
<view class="device-status online">已连接</view>
|
||||
<view class="device-status unline">未连接</view>
|
||||
@ -144,6 +145,10 @@
|
||||
deviceReName
|
||||
} from '@/api/common/index.js'
|
||||
export default {
|
||||
onPullDownRefresh() {
|
||||
// 执行下拉刷新时的操作,比如重新获取数据
|
||||
this.onIntall();
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
navBarHeight: 70 + uni.getSystemInfoSync().statusBarHeight,
|
||||
@ -313,16 +318,18 @@
|
||||
this.showTooltip = false; // 关闭弹窗
|
||||
switch (item.action) {
|
||||
case 'scan':
|
||||
// uni.navigateTo({
|
||||
// url: '/pages/common/scan/scan'
|
||||
// });
|
||||
// 扫一扫
|
||||
uni.scanCode({
|
||||
success: (res) => {
|
||||
console.log('条码内容:' + res.result);
|
||||
console.log('条码内容:', res);
|
||||
// 清除之前的数据
|
||||
this.previousScanResult = null;
|
||||
// 处理新的扫码结果
|
||||
const cleanedResult = res.result.trim();
|
||||
console.log('扫码结果:', cleanedResult);
|
||||
// 跳转并传递扫描结果
|
||||
uni.navigateTo({
|
||||
url: `/pages/common/qrcode/qrcode?deviceId=${encodeURIComponent(res.result)}`
|
||||
url: `/pages/common/qrcode/qrcode?deviceId=${encodeURIComponent(cleanedResult)}`
|
||||
});
|
||||
},
|
||||
fail: (err) => {
|
||||
@ -426,7 +433,7 @@
|
||||
}
|
||||
})
|
||||
},
|
||||
// 报警
|
||||
// 报警
|
||||
callpolice() {
|
||||
const currentTab = this.tabs[this.activeTab];
|
||||
const deviceType = currentTab.id || '';
|
||||
@ -438,7 +445,7 @@
|
||||
},
|
||||
success: (res) => {
|
||||
res.eventChannel.emit('devicePolice', {
|
||||
data: deviceType
|
||||
data: currentTab
|
||||
});
|
||||
}
|
||||
})
|
||||
@ -455,7 +462,8 @@
|
||||
},
|
||||
success: (res) => {
|
||||
res.eventChannel.emit('deviceSend', {
|
||||
data: deviceType
|
||||
//data: deviceType,
|
||||
data: currentTab
|
||||
});
|
||||
}
|
||||
})
|
||||
@ -475,58 +483,39 @@
|
||||
}
|
||||
})
|
||||
},
|
||||
// 列表跳转
|
||||
handleFile(item) {
|
||||
// communicationMode 0是4G 1是蓝牙,考虑多个4g设备
|
||||
if (item.typeName == 'BJQ6170') {
|
||||
uni.navigateTo({
|
||||
url: "/pages/6170/deviceControl/index",
|
||||
events: {
|
||||
ack: function(data) {}
|
||||
},
|
||||
success: (res) => {
|
||||
// 页面跳转成功后的回调函数
|
||||
res.eventChannel.emit('deviceControl', {
|
||||
data: item,
|
||||
apiType: 'listA' // 自定义标识,详情哪里根据这个参数不同信息
|
||||
});
|
||||
}
|
||||
})
|
||||
} else if (item.typeName == 'HBY210') {
|
||||
const currentTab = this.tabs[this.activeTab];
|
||||
const deviceType = currentTab.id || '';
|
||||
uni.navigateTo({
|
||||
url: "/pages/210/deviceControl/index",
|
||||
events: {
|
||||
ack: function(data) {}
|
||||
},
|
||||
success: (res) => {
|
||||
// 页面跳转成功后的回调函数
|
||||
res.eventChannel.emit('deviceControl', {
|
||||
data: item,
|
||||
deviceType: deviceType,
|
||||
apiType: 'listA' // 自定义标识
|
||||
});
|
||||
}
|
||||
})
|
||||
}
|
||||
if (item.typeName == '6155') {
|
||||
uni.navigateTo({
|
||||
url: "/pages/6155/deviceDetail",
|
||||
events: {
|
||||
ack: function(data) {}
|
||||
},
|
||||
success: (res) => {
|
||||
res.eventChannel.emit('detailData', {
|
||||
data: item
|
||||
});
|
||||
}
|
||||
})
|
||||
}
|
||||
let url = item.detailPageUrl;
|
||||
// console.log("url=",url);
|
||||
// if(!url){
|
||||
//url="/pages/670/HBY670"
|
||||
// }
|
||||
uni.navigateTo({
|
||||
url: url,
|
||||
events: {
|
||||
ack: function(data) {}
|
||||
},
|
||||
success: (res) => {
|
||||
// 页面跳转成功后的回调函数
|
||||
res.eventChannel.emit('detailData', {
|
||||
data: item,
|
||||
deviceType: this.tabs[this.activeTab].id || '',
|
||||
apiType: 'listA' //标识,根据这个参数,区分普通详情,分享跳转详情,查不一样的权限信息
|
||||
});
|
||||
},fail(ex) {
|
||||
console.log("ex=",ex);
|
||||
}
|
||||
})
|
||||
},
|
||||
onIntall() {
|
||||
this.page = 1;
|
||||
this.finished = false;
|
||||
this.getData(this.deviceType); // 重新加载第一页数据
|
||||
const deviceType = this.activeTabInfo?.id === '' ? undefined : this.activeTabInfo?.id;
|
||||
this.getData(deviceType); // 重新加载第一页数据
|
||||
setTimeout(() => {
|
||||
// 停止下拉刷新动画
|
||||
uni.stopPullDownRefresh();
|
||||
}, 800);
|
||||
},
|
||||
updateDeviceStatus(data) {
|
||||
this.deviceList = this.deviceList
|
||||
|
@ -69,6 +69,29 @@
|
||||
showAgreement: false, // 控制弹窗显示
|
||||
}
|
||||
},
|
||||
onLoad(){
|
||||
if(uni.getStorageSync("token") && uni.getStorageSync("clientID")){//免登陆
|
||||
|
||||
let time=uni.getStorageSync("tokenTime");
|
||||
if(!time){
|
||||
time=0;
|
||||
}
|
||||
let currTime=new Date().getTime();
|
||||
if(currTime<time){
|
||||
console.log("登陆过,并且没过期,自动进入设备页");
|
||||
uni.switchTab({
|
||||
url: '/pages/common/index/index'
|
||||
});
|
||||
return;
|
||||
}else{
|
||||
//token过期了
|
||||
uni.removeStorageSync("token")
|
||||
uni.removeStorageSync("clientID")
|
||||
uni.removeStorageSync("tokenTime")
|
||||
}
|
||||
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
// 获取验证码
|
||||
async getPhoneCode() {
|
||||
@ -145,11 +168,9 @@
|
||||
return false
|
||||
}
|
||||
try {
|
||||
|
||||
uni.showLoading({
|
||||
title: '登录中...'
|
||||
})
|
||||
console.log('44444');
|
||||
// 调用登录接口
|
||||
const res = await login({
|
||||
phonenumber: this.phone,
|
||||
@ -157,10 +178,10 @@
|
||||
tenantId: '894078' //租户ID
|
||||
})
|
||||
if (res.code == 200) {
|
||||
console.log(res, 'ressss');
|
||||
uni.hideLoading()
|
||||
uni.setStorageSync('token', res.data.access_token) // 缓存token
|
||||
uni.setStorageSync('clientID', res.data.client_id) // 缓存token
|
||||
uni.setStorageSync('tokenTime',new Date().getTime()+86400000);//过期时间
|
||||
uni.showToast({
|
||||
title: '登录成功',
|
||||
icon: 'success'
|
||||
@ -170,19 +191,18 @@
|
||||
})
|
||||
} else {
|
||||
uni.showToast({
|
||||
title: res.msg,
|
||||
title: res.msg || '服务器异常,请稍后重试',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
uni.hideLoading()
|
||||
console.log('捕获错误:', error);
|
||||
uni.showToast({
|
||||
title: error.msg,
|
||||
title: error.msg || '登录失败',
|
||||
icon: 'none'
|
||||
});
|
||||
uni.hideLoading()
|
||||
}
|
||||
|
||||
},
|
||||
// 跳转到协议页面
|
||||
goToPage(type) {
|
||||
|
@ -5,17 +5,13 @@
|
||||
<image src="/static/images/common/svg.png" class="svg"></image>
|
||||
<view class="scanT">ID: {{ deviceId }}</view>
|
||||
</view>
|
||||
|
||||
<!-- 连接中状态 -->
|
||||
<view class="connecting-container" v-else>
|
||||
<view class="device-info">
|
||||
<view class="">
|
||||
<image src="/static/images/common/svg.png" class="svg"></image>
|
||||
</view>
|
||||
<!-- <view>
|
||||
<image src="/static/images/bip.6.png" class="bip"></image>
|
||||
</view> -->
|
||||
|
||||
|
||||
<text class="device-name">设备名:{{deviceId}}</text>
|
||||
<text class="device-model1">ID:{{deviceId}}</text>
|
||||
</view>
|
||||
@ -71,6 +67,7 @@
|
||||
})
|
||||
console.log(this.deviceId, 'deerer ere');
|
||||
if (res.code == 200) {
|
||||
|
||||
this.isConnectNo = false
|
||||
this.isSuccess = true
|
||||
uni.hideLoading()
|
||||
|
@ -2,9 +2,10 @@
|
||||
<view class="container">
|
||||
<!-- 设备列表 -->
|
||||
<scroll-view class="device-list" scroll-y>
|
||||
<view class="device-card" v-for="(item, index) in deviceList" :key="index" @click="toggleSelect(index)">
|
||||
<view class="device-card" v-for="(item, index) in deviceList" :key="index"
|
||||
@click="item.onlineStatus === 1 ? toggleSelect(index) : null">
|
||||
<!-- 复选框 -->
|
||||
<view class="checkbox" :class="{ checked: item.checked }">
|
||||
<view class="checkbox" :class="{ checked: item.checked, disabled: item.onlineStatus !== 1 }">
|
||||
<uni-icons v-if="item.checked" type="checkmarkempty" size="18" color="rgb(0, 0, 0)"></uni-icons>
|
||||
</view>
|
||||
<!-- 设备信息 -->
|
||||
@ -14,15 +15,13 @@
|
||||
<image :src="item.devicePic" class="IMG" mode="aspectFit"></image>
|
||||
</view>
|
||||
<view class="device-name">
|
||||
<view>设备:{{item.deviceName}}</view>
|
||||
<view>设备:{{ item.deviceName }}</view>
|
||||
<view class="ID">
|
||||
<view class="ID">ID:{{item.deviceImei}}</view>
|
||||
<view class="onlines"
|
||||
v-if="item.onlineStatus==1">在线</view>
|
||||
<view class="ID">ID:{{ item.deviceImei }}</view>
|
||||
<view class="onlines" v-if="item.onlineStatus == 1">在线</view>
|
||||
<!-- 离线状态 -->
|
||||
<view class="unlines"
|
||||
v-if="item.onlineStatus==0">离线</view>
|
||||
<view>电量:{{item.battery || '0'}}%</view>
|
||||
<view class="unlines" v-if="item.onlineStatus == 0">离线</view>
|
||||
<view>电量:{{ item.battery || '0' }}%</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
@ -32,314 +31,381 @@
|
||||
<view class="ql-editor">编辑信息</view>
|
||||
<view class="ql-input">
|
||||
<textarea placeholder-style="color:rgba(255, 255, 255, 0.4)" placeholder="请输入内容" class="textarea"
|
||||
v-model="messageToSend" :maxlength="20"/>
|
||||
v-model="messageToSend" :maxlength="20" />
|
||||
</view>
|
||||
<button class="login-btn" @click="sendTextMessage">发送</button>
|
||||
<button class="login-btn" @click.stop="sendTextMessage">发送</button>
|
||||
</view>
|
||||
</scroll-view>
|
||||
<!-- 成功提示弹框 -->
|
||||
<CustomPopup :show="showPopupFlag" :title="popupTitle" :message="popupMessage" icon="/static/images/common/sendSucc.png"
|
||||
:confirm-text="popupConfirmText" :show-cancel="false" @confirm="onPopupConfirm" />
|
||||
<CustomPopup :show="showPopupFlag" :title="popupTitle" :message="popupMessage"
|
||||
icon="/static/images/common/sendSucc.png" :confirm-text="popupConfirmText" :show-cancel="false"
|
||||
@confirm="onPopupConfirm" />
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import CustomPopup from '@/components/CustomPopup/CustomPopup.vue'
|
||||
import {
|
||||
deviceInfo,
|
||||
} from '@/api/common/index.js'
|
||||
import {
|
||||
deviceSendMessage
|
||||
} from '@/api/6170/deviceControl.js'
|
||||
export default {
|
||||
components: {
|
||||
CustomPopup
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
deviceList: [],
|
||||
messageToSend: '', //发送信息
|
||||
showPopupFlag: false,
|
||||
popupTitle: '',
|
||||
popupMessage: '信息发送成功!',
|
||||
popupConfirmText: '确认'
|
||||
import CustomPopup from '@/components/CustomPopup/CustomPopup.vue'
|
||||
import {
|
||||
deviceInfo,
|
||||
} from '@/api/common/index.js'
|
||||
import {
|
||||
deviceSendMessage,
|
||||
deviceRealTimeStatus //设备状态
|
||||
} from '@/api/6170/deviceControl.js'
|
||||
import {
|
||||
generateShortId,
|
||||
getdeviceSTatus
|
||||
} from '@/utils/function.js';
|
||||
export default {
|
||||
components: {
|
||||
CustomPopup
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
deviceList: [],
|
||||
messageToSend: '', //发送信息
|
||||
showPopupFlag: false,
|
||||
popupTitle: '',
|
||||
popupMessage: '信息发送成功!',
|
||||
popupConfirmText: '确认',
|
||||
isSending: false,
|
||||
sendInfo: {}
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
onPullDownRefresh() {
|
||||
// 执行下拉刷新时的操作,比如重新获取数据
|
||||
this.getData();
|
||||
},
|
||||
toggleSelect(index) {
|
||||
this.deviceList[index].checked = !this.deviceList[index].checked
|
||||
this.$forceUpdate()
|
||||
},
|
||||
// 获取设备列表
|
||||
getData(deviceType) {
|
||||
this.loading = true;
|
||||
let data = {
|
||||
pageNum: 1,
|
||||
pageSize: 50,
|
||||
deviceType: deviceType
|
||||
}
|
||||
deviceInfo(data).then((res) => {
|
||||
if (res.code == 200) {
|
||||
const newDevices = res.rows.map(device => ({
|
||||
...device,
|
||||
showConfirm: false,
|
||||
checked: false
|
||||
}));
|
||||
this.total = res.total;
|
||||
this.deviceList = newDevices
|
||||
}
|
||||
}).finally(() => {
|
||||
this.loading = false;
|
||||
});
|
||||
},
|
||||
// 发送文本消息
|
||||
async sendTextMessage() {
|
||||
// 防重复提交
|
||||
if (this.isSending) return;
|
||||
const selectedDevices = this.deviceList.filter(item => item.checked)
|
||||
const deviceIds = selectedDevices.map(item => item.id);
|
||||
const deviceImeiList = selectedDevices.map(item => item.deviceImei);
|
||||
if (selectedDevices.length === 0) {
|
||||
uni.showToast({
|
||||
title: '请选择一个设备',
|
||||
icon: 'none'
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (!this.messageToSend) {
|
||||
uni.showToast({
|
||||
title: '请输入要发送的文字',
|
||||
icon: 'none'
|
||||
});
|
||||
return;
|
||||
}
|
||||
this.isSending = true;
|
||||
let loadingShown = false;
|
||||
try {
|
||||
uni.showLoading({
|
||||
title: '发送中...',
|
||||
mask: true
|
||||
});
|
||||
loadingShown = true;
|
||||
// 2. 准备请求数据
|
||||
const batchId = generateShortId();
|
||||
const data = {
|
||||
sendMsg: this.messageToSend,
|
||||
deviceIds: deviceIds,
|
||||
batchId: batchId,
|
||||
typeName: this.sendInfo.typeName,
|
||||
batchId: batchId,
|
||||
deviceImeiList: deviceImeiList
|
||||
};
|
||||
// 3.人员信息
|
||||
const registerRes = await deviceSendMessage(data);
|
||||
if (registerRes.code !== 200) {
|
||||
uni.showToast({
|
||||
title: registerRes.msg,
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
// 4. 获取设备状态
|
||||
let deviceImei = this.sendInfo.deviceImei
|
||||
let typeName = this.sendInfo.typeName
|
||||
const statusRes = await getdeviceSTatus({
|
||||
functionMode: 2,
|
||||
batchId,
|
||||
typeName:'FunctionAccessBatchStatusRule',
|
||||
deviceImei,
|
||||
interval: 500
|
||||
},
|
||||
deviceRealTimeStatus
|
||||
);
|
||||
if (statusRes.data.functionAccess === 'OK') {
|
||||
// 5. 显示成功弹窗
|
||||
this.showPopupFlag = true
|
||||
}
|
||||
} catch (error) {
|
||||
uni.showToast({
|
||||
title: error.message,
|
||||
icon: 'none'
|
||||
});
|
||||
} finally {
|
||||
uni.hideLoading();
|
||||
this.isSending = false;
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
toggleSelect(index) {
|
||||
this.deviceList[index].checked = !this.deviceList[index].checked
|
||||
this.$forceUpdate()
|
||||
},
|
||||
// 获取设备列表
|
||||
getData(deviceType) {
|
||||
this.loading = true;
|
||||
let data = {
|
||||
pageNum: 1,
|
||||
pageSize: 20,
|
||||
deviceType: deviceType
|
||||
}
|
||||
deviceInfo(data).then((res) => {
|
||||
if (res.code == 200) {
|
||||
const newDevices = res.rows.map(device => ({
|
||||
...device,
|
||||
showConfirm: false,
|
||||
checked: false
|
||||
}));
|
||||
this.total = res.total;
|
||||
this.deviceList = newDevices
|
||||
}
|
||||
}).finally(() => {
|
||||
this.loading = false;
|
||||
});
|
||||
},
|
||||
// 发送文本消息
|
||||
sendTextMessage() {
|
||||
const selectedDevices = this.deviceList.filter(item => item.checked)
|
||||
const deviceIds = selectedDevices.map(item => item.id);
|
||||
if (selectedDevices.length === 0) {
|
||||
uni.showToast({
|
||||
title: '请选择一个设备',
|
||||
icon: 'none'
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (!this.messageToSend) {
|
||||
uni.showToast({
|
||||
title: '请输入要发送的内容',
|
||||
icon: 'none'
|
||||
});
|
||||
return;
|
||||
}
|
||||
let data = {
|
||||
sendMsg: this.messageToSend,
|
||||
deviceIds: deviceIds
|
||||
}
|
||||
deviceSendMessage(data).then((res) => {
|
||||
if (res.code == 200) {
|
||||
this.showPopupFlag = true
|
||||
} else {
|
||||
uni.showToast({
|
||||
title: res.msg,
|
||||
icon: 'none'
|
||||
});
|
||||
}
|
||||
})
|
||||
},
|
||||
onPopupConfirm() {
|
||||
this.showPopupFlag = false
|
||||
uni.navigateBack()
|
||||
console.log('用户点击了确定')
|
||||
// 处理确认逻辑
|
||||
},
|
||||
onPopupConfirm() {
|
||||
this.showPopupFlag = false
|
||||
uni.navigateBack()
|
||||
console.log('用户点击了确定')
|
||||
// 处理确认逻辑
|
||||
},
|
||||
onLoad(options) {
|
||||
const eventChannel = this.getOpenerEventChannel();
|
||||
// 监听 'deviceSend' 事件,获取传过来的数据
|
||||
eventChannel.on('deviceSend', (data) => {
|
||||
console.log('Received detail data:', data);
|
||||
this.getData(data.data)
|
||||
});
|
||||
// 如果需要向调用页面返回数据,可以触发 'ack' 事件
|
||||
eventChannel.emit('ack', {})
|
||||
},
|
||||
}
|
||||
},
|
||||
onLoad(options) {
|
||||
const eventChannel = this.getOpenerEventChannel();
|
||||
// 监听 'deviceSend' 事件,获取传过来的数据
|
||||
eventChannel.on('deviceSend', (data) => {
|
||||
console.log('Received detail data:', data);
|
||||
this.getData(data.data.id)
|
||||
this.sendInfo = data.data
|
||||
});
|
||||
// 如果需要向调用页面返回数据,可以触发 'ack' 事件
|
||||
eventChannel.emit('ack', {})
|
||||
},
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.container {
|
||||
min-height: 100vh;
|
||||
background-color: rgb(18, 18, 18);
|
||||
box-sizing: border-box;
|
||||
overflow-x: hidden;
|
||||
.container {
|
||||
min-height: 100vh;
|
||||
background-color: rgb(18, 18, 18);
|
||||
box-sizing: border-box;
|
||||
overflow-x: hidden;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
.device-list {
|
||||
flex: 1;
|
||||
padding: 0 20rpx;
|
||||
.device-list {
|
||||
flex: 1;
|
||||
padding: 0 20rpx;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
.device-card {
|
||||
position: relative;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
width: 95%;
|
||||
margin-bottom: 20rpx;
|
||||
}
|
||||
.device-card {
|
||||
position: relative;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
width: 95%;
|
||||
margin-bottom: 20rpx;
|
||||
}
|
||||
|
||||
.checkbox {
|
||||
width: 40rpx;
|
||||
height: 40rpx;
|
||||
border: 2rpx solid rgba(255, 255, 255, 0.5);
|
||||
margin-right: 20rpx;
|
||||
border-radius: 4rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
.checkbox {
|
||||
width: 40rpx;
|
||||
height: 40rpx;
|
||||
border: 2rpx solid rgba(255, 255, 255, 0.5);
|
||||
margin-right: 20rpx;
|
||||
border-radius: 4rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.checkbox.checked {
|
||||
background-color: rgb(187, 230, 0);
|
||||
border-color: rgb(187, 230, 0);
|
||||
}
|
||||
.checkbox.checked {
|
||||
background-color: rgb(187, 230, 0);
|
||||
border-color: rgb(187, 230, 0);
|
||||
}
|
||||
|
||||
.device-content {
|
||||
background-color: rgb(26, 26, 26);
|
||||
border-radius: 16rpx;
|
||||
position: relative;
|
||||
/* display: flex; */
|
||||
align-items: center;
|
||||
padding: 20rpx;
|
||||
width: 95%;
|
||||
}
|
||||
.device-content {
|
||||
background-color: rgb(26, 26, 26);
|
||||
border-radius: 16rpx;
|
||||
position: relative;
|
||||
/* display: flex; */
|
||||
align-items: center;
|
||||
padding: 20rpx;
|
||||
width: 95%;
|
||||
}
|
||||
|
||||
.device-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
margin-bottom: 15rpx;
|
||||
}
|
||||
.device-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
margin-bottom: 15rpx;
|
||||
}
|
||||
|
||||
.device-name {
|
||||
font-size: 32rpx;
|
||||
color: rgba(255, 255, 255, 0.87);
|
||||
margin-left: 12rpx;
|
||||
line-height: 50rpx;
|
||||
width: 83%;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.device-name {
|
||||
font-size: 32rpx;
|
||||
color: rgba(255, 255, 255, 0.87);
|
||||
margin-left: 12rpx;
|
||||
line-height: 50rpx;
|
||||
width: 83%;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.ID {
|
||||
color: rgba(255, 255, 255, 0.6);
|
||||
font-size: 26rpx;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
position: relative;
|
||||
}
|
||||
.ID {
|
||||
color: rgba(255, 255, 255, 0.6);
|
||||
font-size: 26rpx;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.device-status {
|
||||
width: 122rpx;
|
||||
height: 52rpx;
|
||||
font-size: 26rpx;
|
||||
border-radius: 0px 8px 0px 8px;
|
||||
background-color: rgb(42, 42, 42);
|
||||
position: absolute;
|
||||
top: 0rpx;
|
||||
right: 0rpx;
|
||||
text-align: center;
|
||||
line-height: 52rpx;
|
||||
}
|
||||
.device-status {
|
||||
width: 122rpx;
|
||||
height: 52rpx;
|
||||
font-size: 26rpx;
|
||||
border-radius: 0px 8px 0px 8px;
|
||||
background-color: rgb(42, 42, 42);
|
||||
position: absolute;
|
||||
top: 0rpx;
|
||||
right: 0rpx;
|
||||
text-align: center;
|
||||
line-height: 52rpx;
|
||||
}
|
||||
|
||||
.online {
|
||||
color: rgb(187, 230, 0);
|
||||
}
|
||||
.online {
|
||||
color: rgb(187, 230, 0);
|
||||
}
|
||||
|
||||
.unline {
|
||||
color: rgba(255, 255, 255, 0.4);
|
||||
}
|
||||
.unline {
|
||||
color: rgba(255, 255, 255, 0.4);
|
||||
}
|
||||
|
||||
.device-info {
|
||||
display: flex;
|
||||
justify-content: space-evenly;
|
||||
font-size: 26rpx;
|
||||
color: rgba(255, 255, 255, 0.87);
|
||||
padding-top: 10rpx;
|
||||
position: relative;
|
||||
}
|
||||
.device-info {
|
||||
display: flex;
|
||||
justify-content: space-evenly;
|
||||
font-size: 26rpx;
|
||||
color: rgba(255, 255, 255, 0.87);
|
||||
padding-top: 10rpx;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.deviceIMG {
|
||||
width: 100rpx;
|
||||
height: 100rpx;
|
||||
border-radius: 16rpx;
|
||||
position: relative;
|
||||
background-color: rgba(42, 42, 42, 0.6);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
.deviceIMG {
|
||||
width: 100rpx;
|
||||
height: 100rpx;
|
||||
border-radius: 16rpx;
|
||||
position: relative;
|
||||
background-color: rgba(42, 42, 42, 0.6);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.IMG {
|
||||
width: 68rpx;
|
||||
height: 50rpx;
|
||||
margin-left: 17%;
|
||||
}
|
||||
.IMG {
|
||||
width: 68rpx;
|
||||
height: 50rpx;
|
||||
margin-left: 17%;
|
||||
}
|
||||
|
||||
.onlines {
|
||||
position: relative;
|
||||
}
|
||||
.onlines {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.onlines::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
width: 15rpx;
|
||||
height: 15rpx;
|
||||
background: rgb(0, 171, 103);
|
||||
border-radius: 50%;
|
||||
top: 20rpx;
|
||||
left: -20rpx
|
||||
}
|
||||
.onlines::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
width: 15rpx;
|
||||
height: 15rpx;
|
||||
background: rgb(0, 171, 103);
|
||||
border-radius: 50%;
|
||||
top: 20rpx;
|
||||
left: -20rpx
|
||||
}
|
||||
|
||||
.unlines {
|
||||
position: relative;
|
||||
}
|
||||
.unlines {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.unlines::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
width: 15rpx;
|
||||
height: 15rpx;
|
||||
background: rgba(255, 255, 255, 0.4);
|
||||
border-radius: 50%;
|
||||
top: 20rpx;
|
||||
left: -20rpx
|
||||
}
|
||||
.unlines::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
width: 15rpx;
|
||||
height: 15rpx;
|
||||
background: rgba(255, 255, 255, 0.4);
|
||||
border-radius: 50%;
|
||||
top: 20rpx;
|
||||
left: -20rpx
|
||||
}
|
||||
|
||||
.line {
|
||||
width: 2rpx;
|
||||
height: 24rpx;
|
||||
background: linear-gradient(90deg,
|
||||
rgba(0, 0, 0, 0) 0%,
|
||||
rgb(255, 255, 255) 50%,
|
||||
rgba(255, 255, 255, 0) 100%);
|
||||
margin-top: 12rpx;
|
||||
}
|
||||
.line {
|
||||
width: 2rpx;
|
||||
height: 24rpx;
|
||||
background: linear-gradient(90deg,
|
||||
rgba(0, 0, 0, 0) 0%,
|
||||
rgb(255, 255, 255) 50%,
|
||||
rgba(255, 255, 255, 0) 100%);
|
||||
margin-top: 12rpx;
|
||||
}
|
||||
|
||||
.ql-editor {
|
||||
color: rgba(255, 255, 255, 0.6);
|
||||
font-size: 30rpx;
|
||||
}
|
||||
.ql-editor {
|
||||
color: rgba(255, 255, 255, 0.6);
|
||||
font-size: 30rpx;
|
||||
}
|
||||
|
||||
.ql-input {
|
||||
width: 95.9%;
|
||||
height: 200rpx;
|
||||
margin-top: 30rpx;
|
||||
box-sizing: border-box;
|
||||
padding: 30rpx;
|
||||
border-radius: 16rpx;
|
||||
background: rgb(26, 26, 26);
|
||||
}
|
||||
.ql-input {
|
||||
width: 95.9%;
|
||||
height: 200rpx;
|
||||
margin-top: 30rpx;
|
||||
box-sizing: border-box;
|
||||
padding: 30rpx;
|
||||
border-radius: 16rpx;
|
||||
background: rgb(26, 26, 26);
|
||||
}
|
||||
|
||||
.textarea {
|
||||
color: rgba(255, 255, 255, 0.8);
|
||||
background: rgba(42, 42, 42, 1);
|
||||
border-radius: 16rpx;
|
||||
padding: 10rpx;
|
||||
height: 150rpx;
|
||||
}
|
||||
.textarea {
|
||||
color: rgba(255, 255, 255, 0.8);
|
||||
background: rgba(42, 42, 42, 1);
|
||||
border-radius: 16rpx;
|
||||
padding: 10rpx;
|
||||
height: 150rpx;
|
||||
}
|
||||
|
||||
.editInfmation {
|
||||
padding: 20rpx;
|
||||
border-radius: 40rpx 40rpx 0px 0px;
|
||||
background: rgba(28, 28, 28, 1);
|
||||
position: fixed;
|
||||
bottom: 50rpx;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
.editInfmation {
|
||||
padding: 20rpx;
|
||||
border-radius: 40rpx 40rpx 0px 0px;
|
||||
background: rgba(28, 28, 28, 1);
|
||||
position: fixed;
|
||||
bottom: 50rpx;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.login-btn {
|
||||
margin-top: 30rpx;
|
||||
background-color: rgb(187, 230, 0);
|
||||
color: rgb(35, 35, 35);
|
||||
border-radius: 50rpx;
|
||||
width: 90%;
|
||||
}
|
||||
.login-btn {
|
||||
margin-top: 30rpx;
|
||||
background-color: rgb(187, 230, 0);
|
||||
color: rgb(35, 35, 35);
|
||||
border-radius: 50rpx;
|
||||
width: 90%;
|
||||
}
|
||||
|
||||
.checkbox.disabled {
|
||||
opacity: 0.5;
|
||||
background-color: rgba(255, 255, 255, 0.1) !important;
|
||||
border-color: rgba(255, 255, 255, 0.2) !important;
|
||||
pointer-events: none;
|
||||
/* 阻止点击事件 */
|
||||
}
|
||||
|
||||
/* 可选:离线设备的卡片整体置灰 */
|
||||
.device-card[data-offline="true"] {
|
||||
opacity: 0.6;
|
||||
}
|
||||
</style>
|
@ -6,7 +6,7 @@
|
||||
<image src="/static/images/common/logo.png" class="logo"></image>
|
||||
</view>
|
||||
<view class="user-right">
|
||||
<view class="user-title">富源晟科技</view>
|
||||
<view class="user-title">武汉星汉</view>
|
||||
<view class="ID">ID:123456</view>
|
||||
</view>
|
||||
</view>
|
||||
|
BIN
static/fonts/PingFangSC.ttf
Normal file
BIN
static/images/6155/DeviceDetail/Hby650.png
Normal file
After Width: | Height: | Size: 12 KiB |
BIN
static/images/6155/DeviceDetail/close.png
Normal file
After Width: | Height: | Size: 1.3 KiB |
BIN
static/images/6155/DeviceDetail/uploadErr.png
Normal file
After Width: | Height: | Size: 2.2 KiB |
BIN
static/images/6155/DeviceDetail/warnning.png
Normal file
After Width: | Height: | Size: 2.5 KiB |
BIN
static/images/670/jieN.png
Normal file
After Width: | Height: | Size: 1.3 KiB |
BIN
static/images/670/jieNActive.png
Normal file
After Width: | Height: | Size: 1.8 KiB |
BIN
static/images/670/qiang.png
Normal file
After Width: | Height: | Size: 2.0 KiB |
BIN
static/images/670/qiangActive.png
Normal file
After Width: | Height: | Size: 3.1 KiB |
BIN
static/images/670/rb.png
Normal file
After Width: | Height: | Size: 754 B |
BIN
static/images/670/rbActive.png
Normal file
After Width: | Height: | Size: 999 B |
BIN
static/images/670/ruo.png
Normal file
After Width: | Height: | Size: 1.6 KiB |
BIN
static/images/670/ruoActive.png
Normal file
After Width: | Height: | Size: 2.6 KiB |
BIN
static/images/670/sg.png
Normal file
After Width: | Height: | Size: 968 B |
BIN
static/images/670/sgActive.png
Normal file
After Width: | Height: | Size: 1.3 KiB |
BIN
static/images/BLEAdd/addBleDevice.png
Normal file
After Width: | Height: | Size: 867 B |
BIN
static/images/common/bj_1.png
Normal file
After Width: | Height: | Size: 2.9 KiB |
BIN
static/images/common/msg.png
Normal file
After Width: | Height: | Size: 1.6 KiB |
@ -1,8 +1,8 @@
|
||||
|
||||
var isReady=false;var onReadyCallbacks=[];
|
||||
var isServiceReady=false;var onServiceReadyCallbacks=[];
|
||||
var __uniConfig = {"pages":["pages/common/login/index","pages/common/index/index","pages/common/user/index","pages/common/scan/scan","pages/common/qrcode/qrcode","pages/common/send/index","pages/common/userAgreement/index","pages/common/privacyAgreement/index","pages/common/aboutUs/index","pages/6170/deviceControl/index","pages/6170/callPolice/index","pages/210/deviceControl/index","pages/common/operationVideo/index","pages/common/addvideo/index","pages/common/operatingInstruct/index","pages/common/productDes/index","pages/common/addBLE/addEquip","pages/common/addBLE/LinkBle","pages/6155/deviceDetail","pages/6155/ImgCrop","pages/common/map/index","pages/common/allType/index","pages/6170/allShare/index","pages/6170/share/index","pages/6170/shareDevices/index","pages/6170/shareManagement/index","pages/210/onlineDevice/index","pages/210/addDevice/index"],"window":{"navigationBarTextStyle":"white","navigationBarTitleText":"uni-app","navigationBarBackgroundColor":"#121212","backgroundColor":"#121212"},"tabBar":{"color":"#fff","selectedColor":"#BBE600","backgroundColor":"#202020","list":[{"pagePath":"pages/common/index/index","text":"我的设备","iconPath":"/static/tabs/device.png","selectedIconPath":"/static/tabs/device-HL.png"},{"pagePath":"pages/common/user/index","text":"我的","iconPath":"/static/tabs/my.png","selectedIconPath":"/static/tabs/my-HL.png"}]},"darkmode":false,"nvueCompiler":"uni-app","nvueStyleCompiler":"uni-app","renderer":"auto","splashscreen":{"alwaysShowBeforeRender":true,"autoclose":false},"appname":"JingQuan","compilerVersion":"4.66","entryPagePath":"pages/common/login/index","networkTimeout":{"request":60000,"connectSocket":60000,"uploadFile":60000,"downloadFile":60000}};
|
||||
var __uniRoutes = [{"path":"/pages/common/login/index","meta":{"isQuit":true},"window":{"navigationStyle":"custom"}},{"path":"/pages/common/index/index","meta":{"isQuit":true,"isTabBar":true},"window":{"navigationStyle":"custom"}},{"path":"/pages/common/user/index","meta":{"isQuit":true,"isTabBar":true},"window":{"navigationBarTitleText":"我的"}},{"path":"/pages/common/scan/scan","meta":{},"window":{"navigationBarTitleText":"扫描"}},{"path":"/pages/common/qrcode/qrcode","meta":{},"window":{"navigationBarTitleText":"扫描到的设备"}},{"path":"/pages/common/send/index","meta":{},"window":{"navigationBarTitleText":"发送信息"}},{"path":"/pages/common/userAgreement/index","meta":{},"window":{"navigationBarTitleText":"用户协议"}},{"path":"/pages/common/privacyAgreement/index","meta":{},"window":{"navigationBarTitleText":"隐私协议"}},{"path":"/pages/common/aboutUs/index","meta":{},"window":{"navigationBarTitleText":"关于我们"}},{"path":"/pages/6170/deviceControl/index","meta":{},"window":{"navigationStyle":"custom"}},{"path":"/pages/6170/callPolice/index","meta":{},"window":{"navigationBarTitleText":"报警"}},{"path":"/pages/210/deviceControl/index","meta":{},"window":{"navigationStyle":"custom"}},{"path":"/pages/common/operationVideo/index","meta":{},"window":{"navigationStyle":"custom"}},{"path":"/pages/common/addvideo/index","meta":{},"window":{"navigationStyle":"custom"}},{"path":"/pages/common/operatingInstruct/index","meta":{},"window":{"navigationStyle":"custom"}},{"path":"/pages/common/productDes/index","meta":{},"window":{"navigationStyle":"custom"}},{"path":"/pages/common/addBLE/addEquip","meta":{},"window":{"navigationBarTitleText":"添加设备"}},{"path":"/pages/common/addBLE/LinkBle","meta":{},"window":{"navigationBarTitleText":"扫描到的设备"}},{"path":"/pages/6155/deviceDetail","meta":{},"window":{"navigationBarTitleText":"HBY 6155"}},{"path":"/pages/6155/ImgCrop","meta":{},"window":{"navigationBarTitleText":"图像裁剪","navigationStyle":"custom","fullscreen":true}},{"path":"/pages/common/map/index","meta":{},"window":{"navigationBarTitleText":"地图"}},{"path":"/pages/common/allType/index","meta":{},"window":{"navigationBarTitleText":"所有类型"}},{"path":"/pages/6170/allShare/index","meta":{},"window":{"navigationBarTitleText":"所有分享"}},{"path":"/pages/6170/share/index","meta":{},"window":{"navigationBarTitleText":"分享"}},{"path":"/pages/6170/shareDevices/index","meta":{},"window":{"navigationBarTitleText":"分享设备"}},{"path":"/pages/6170/shareManagement/index","meta":{},"window":{"navigationBarTitleText":"分享管理"}},{"path":"/pages/210/onlineDevice/index","meta":{},"window":{"navigationBarTitleText":"联机设备"}},{"path":"/pages/210/addDevice/index","meta":{},"window":{"navigationBarTitleText":"添加联机设备"}}];
|
||||
var __uniConfig = {"pages":["pages/common/login/index","pages/common/index/index","pages/common/user/index","pages/common/scan/scan","pages/common/qrcode/qrcode","pages/common/send/index","pages/common/userAgreement/index","pages/common/privacyAgreement/index","pages/common/aboutUs/index","pages/6170/deviceControl/index","pages/6170/callPolice/index","pages/210/deviceControl/index","pages/common/operationVideo/index","pages/common/addvideo/index","pages/common/operatingInstruct/index","pages/common/productDes/index","pages/common/addBLE/addEquip","pages/common/addBLE/LinkBle","pages/6155/deviceDetail","pages/6155/ImgCrop","pages/common/map/index","pages/common/allType/index","pages/6170/allShare/index","pages/6170/share/index","pages/6170/shareDevices/index","pages/6170/shareManagement/index","pages/210/onlineDevice/index","pages/210/addDevice/index","pages/210/historyRecords/index","pages/210/call/index"],"window":{"navigationBarTextStyle":"white","navigationBarTitleText":"uni-app","navigationBarBackgroundColor":"#121212","backgroundColor":"#121212"},"tabBar":{"color":"#fff","selectedColor":"#BBE600","backgroundColor":"#202020","list":[{"pagePath":"pages/common/index/index","text":"我的设备","iconPath":"/static/tabs/device.png","selectedIconPath":"/static/tabs/device-HL.png"},{"pagePath":"pages/common/user/index","text":"我的","iconPath":"/static/tabs/my.png","selectedIconPath":"/static/tabs/my-HL.png"}]},"darkmode":false,"nvueCompiler":"uni-app","nvueStyleCompiler":"uni-app","renderer":"auto","splashscreen":{"alwaysShowBeforeRender":true,"autoclose":false},"appname":"JingQuan","compilerVersion":"4.66","entryPagePath":"pages/common/login/index","networkTimeout":{"request":60000,"connectSocket":60000,"uploadFile":60000,"downloadFile":60000}};
|
||||
var __uniRoutes = [{"path":"/pages/common/login/index","meta":{"isQuit":true},"window":{"navigationStyle":"custom"}},{"path":"/pages/common/index/index","meta":{"isQuit":true,"isTabBar":true},"window":{"navigationStyle":"custom","enablePullDownRefresh":true}},{"path":"/pages/common/user/index","meta":{"isQuit":true,"isTabBar":true},"window":{"navigationBarTitleText":"我的"}},{"path":"/pages/common/scan/scan","meta":{},"window":{"navigationBarTitleText":"扫描"}},{"path":"/pages/common/qrcode/qrcode","meta":{},"window":{"navigationBarTitleText":"扫描到的设备"}},{"path":"/pages/common/send/index","meta":{},"window":{"navigationBarTitleText":"发送信息"}},{"path":"/pages/common/userAgreement/index","meta":{},"window":{"navigationBarTitleText":"用户协议"}},{"path":"/pages/common/privacyAgreement/index","meta":{},"window":{"navigationBarTitleText":"隐私协议"}},{"path":"/pages/common/aboutUs/index","meta":{},"window":{"navigationBarTitleText":"关于我们"}},{"path":"/pages/6170/deviceControl/index","meta":{},"window":{"navigationStyle":"custom"}},{"path":"/pages/6170/callPolice/index","meta":{},"window":{"navigationBarTitleText":"报警"}},{"path":"/pages/210/deviceControl/index","meta":{},"window":{"navigationStyle":"custom"}},{"path":"/pages/common/operationVideo/index","meta":{},"window":{"navigationStyle":"custom"}},{"path":"/pages/common/addvideo/index","meta":{},"window":{"navigationStyle":"custom"}},{"path":"/pages/common/operatingInstruct/index","meta":{},"window":{"navigationStyle":"custom"}},{"path":"/pages/common/productDes/index","meta":{},"window":{"navigationStyle":"custom"}},{"path":"/pages/common/addBLE/addEquip","meta":{},"window":{"navigationBarTitleText":"添加设备"}},{"path":"/pages/common/addBLE/LinkBle","meta":{},"window":{"navigationBarTitleText":"扫描到的设备"}},{"path":"/pages/6155/deviceDetail","meta":{},"window":{"navigationBarTitleText":"HBY 6155"}},{"path":"/pages/6155/ImgCrop","meta":{},"window":{"navigationBarTitleText":"图像裁剪","navigationStyle":"custom","fullscreen":true}},{"path":"/pages/common/map/index","meta":{},"window":{"navigationBarTitleText":"地图"}},{"path":"/pages/common/allType/index","meta":{},"window":{"navigationBarTitleText":"所有类型"}},{"path":"/pages/6170/allShare/index","meta":{},"window":{"navigationBarTitleText":"所有分享"}},{"path":"/pages/6170/share/index","meta":{},"window":{"navigationBarTitleText":"分享"}},{"path":"/pages/6170/shareDevices/index","meta":{},"window":{"navigationBarTitleText":"分享设备"}},{"path":"/pages/6170/shareManagement/index","meta":{},"window":{"navigationBarTitleText":"分享管理"}},{"path":"/pages/210/onlineDevice/index","meta":{},"window":{"navigationBarTitleText":"联机设备"}},{"path":"/pages/210/addDevice/index","meta":{},"window":{"navigationBarTitleText":"添加联机设备"}},{"path":"/pages/210/historyRecords/index","meta":{},"window":{"navigationBarTitleText":"历史记录"}},{"path":"/pages/210/call/index","meta":{},"window":{"navigationBarTitleText":"呼叫"}}];
|
||||
__uniConfig.onReady=function(callback){if(__uniConfig.ready){callback()}else{onReadyCallbacks.push(callback)}};Object.defineProperty(__uniConfig,"ready",{get:function(){return isReady},set:function(val){isReady=val;if(!isReady){return}const callbacks=onReadyCallbacks.slice(0);onReadyCallbacks.length=0;callbacks.forEach(function(callback){callback()})}});
|
||||
__uniConfig.onServiceReady=function(callback){if(__uniConfig.serviceReady){callback()}else{onServiceReadyCallbacks.push(callback)}};Object.defineProperty(__uniConfig,"serviceReady",{get:function(){return isServiceReady},set:function(val){isServiceReady=val;if(!isServiceReady){return}const callbacks=onServiceReadyCallbacks.slice(0);onServiceReadyCallbacks.length=0;callbacks.forEach(function(callback){callback()})}});
|
||||
service.register("uni-app-config",{create(a,b,c){if(!__uniConfig.viewport){var d=b.weex.config.env.scale,e=b.weex.config.env.deviceWidth,f=Math.ceil(e/d);Object.assign(__uniConfig,{viewport:f,defaultFontSize:Math.round(f/20)})}return{instance:{__uniConfig:__uniConfig,__uniRoutes:__uniRoutes,global:void 0,window:void 0,document:void 0,frames:void 0,self:void 0,location:void 0,navigator:void 0,localStorage:void 0,history:void 0,Caches:void 0,screen:void 0,alert:void 0,confirm:void 0,prompt:void 0,fetch:void 0,XMLHttpRequest:void 0,WebSocket:void 0,webkit:void 0,print:void 0}}}});
|
||||
|
6885
unpackage/dist/dev/app-plus/app-service.js
vendored
4889
unpackage/dist/dev/app-plus/app-view.js
vendored
2
unpackage/dist/dev/app-plus/manifest.json
vendored
1274
utils/BleHelper.js
Normal file
413
utils/BleReceive.js
Normal file
@ -0,0 +1,413 @@
|
||||
class BleReceive {
|
||||
constructor() {
|
||||
this.StorageKey = "linkedDevices";
|
||||
|
||||
}
|
||||
|
||||
getCurrentPagePath() {
|
||||
|
||||
const pages = getCurrentPages();
|
||||
|
||||
if (pages.length === 0) {
|
||||
console.log("pages.length=0");
|
||||
return "";
|
||||
}
|
||||
|
||||
const currentPage = pages[pages.length - 1];
|
||||
console.log("currentPage=", currentPage.route);
|
||||
return currentPage.route;
|
||||
}
|
||||
|
||||
|
||||
setBleFormData(data,f) {
|
||||
if(data){
|
||||
let linkedList=uni.getStorageSync(this.StorageKey);
|
||||
linkedList.find((v)=>{
|
||||
if(f.deviceId==v.deviceId){
|
||||
let keys=Object.keys(data);
|
||||
keys.forEach((key)=>{
|
||||
if(!v.formData){
|
||||
v.formData={};
|
||||
}
|
||||
if(!f.formData){
|
||||
f.formData={};
|
||||
}
|
||||
v.formData[key]=data[key];
|
||||
f.formData[key]=data[key];
|
||||
});
|
||||
|
||||
uni.setStorageSync(this.StorageKey,linkedList);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
ReceiveData(receive,f,path) {
|
||||
if(f && f.macAddress && f.id){
|
||||
let data={};
|
||||
if(f.detailPageUrl=='/pages/6155/deviceDetail'){
|
||||
// console.log("该设备是6155");
|
||||
data= this.Receive_6155(receive,f,path);
|
||||
}
|
||||
|
||||
if(f.detailPageUrl=='/pages/650/HBY650'){
|
||||
// console.log("该设备是650");
|
||||
data= this.Receive_650(receive,f,path);
|
||||
}
|
||||
if(f.detailPageUrl=='/pages/670/HBY670'){
|
||||
// console.log("该设备是670");
|
||||
data= this.Receive_670(receive,f,path);
|
||||
}
|
||||
// console.log("收到数据并处理完毕,",data);
|
||||
return data;
|
||||
}
|
||||
// console.log("已收到该消息,但无法处理",receive);
|
||||
return receive;
|
||||
|
||||
}
|
||||
|
||||
Receive_650(receive,f,path) {
|
||||
console.log("通用程序正在处理650的数据",receive);
|
||||
|
||||
var parseData = () => {
|
||||
let bytes = receive.bytes;
|
||||
if (bytes[0] == 0x55) {
|
||||
|
||||
try {
|
||||
|
||||
let staticLevelByte = bytes[1];
|
||||
let staticLevelText = '未知';
|
||||
let modeCurr = "";
|
||||
|
||||
switch (staticLevelByte) {
|
||||
case 0x65:
|
||||
staticLevelText = '高档';
|
||||
modeCurr = "hight";
|
||||
break;
|
||||
case 0x66:
|
||||
staticLevelText = '中档';
|
||||
modeCurr = "center";
|
||||
break;
|
||||
case 0x67:
|
||||
staticLevelText = '低档';
|
||||
modeCurr = "low";
|
||||
break;
|
||||
case 0x68:
|
||||
staticLevelText = '关闭';
|
||||
modeCurr = "close";
|
||||
break;
|
||||
}
|
||||
|
||||
// 解析照明档位
|
||||
let lightingLevelByte = bytes[2];
|
||||
let lightingLevelText = lightingLevelByte === 0x6e ? '开启' : '关闭';
|
||||
|
||||
|
||||
// 解析剩余照明时间(第三和第四字节,大端序)
|
||||
let lightingTime = (bytes[3] << 8) | bytes[4];
|
||||
let hours = Math.floor(lightingTime / 60);
|
||||
let remainingMinutes = lightingTime % 60;
|
||||
let xuhang = '0分';
|
||||
// 处理不同情况的显示
|
||||
if (hours === 0) {
|
||||
xuhang = `${remainingMinutes}分`;
|
||||
} else if (remainingMinutes === 0) {
|
||||
xuhang = `${hours}小时`;
|
||||
} else {
|
||||
xuhang = `${hours}小时${remainingMinutes}分`;
|
||||
}
|
||||
|
||||
// 解析剩余电量
|
||||
let batteryLevelByte = bytes[5];
|
||||
// 电量百分比范围检查
|
||||
let batteryLevel = Math.max(0, Math.min(100, batteryLevelByte));
|
||||
let iswarn = false;
|
||||
let warn = bytes[6];
|
||||
if (warn == 0x00) {
|
||||
warn = '无预警';
|
||||
} else if (warn == 0x01) {
|
||||
warn = '弱预警';
|
||||
} else if (warn == 0x02) {
|
||||
iswarn = true;
|
||||
warn = '中预警';
|
||||
} else if (warn == 0x03) {
|
||||
iswarn = true;
|
||||
warn = '强预警';
|
||||
} else if (warn == 0x04) {
|
||||
iswarn = true;
|
||||
warn = '非常强预警';
|
||||
}
|
||||
|
||||
let formData={};
|
||||
formData.battary = batteryLevel;
|
||||
formData.xuhang = xuhang;
|
||||
formData.cMode = lightingLevelByte === 0x6e;
|
||||
formData.modeCurr = modeCurr;
|
||||
formData.warnLevel = warn;
|
||||
formData.iswarn = iswarn;
|
||||
this.setBleFormData(formData,f);
|
||||
|
||||
let route=this.getCurrentPagePath();
|
||||
console.log("f=",f);
|
||||
console.log("route="+route);
|
||||
if (iswarn && f.detailPageUrl.indexOf(route)==-1 ) {
|
||||
uni.showModal({
|
||||
content:"环境存在漏电电源",
|
||||
title:"警告",
|
||||
success(res){
|
||||
if(res.confirm){
|
||||
|
||||
if(f){
|
||||
uni.navigateTo({
|
||||
url: f.detailPageUrl,
|
||||
events: {
|
||||
ack: function(data) {}
|
||||
},
|
||||
success: (res) => {
|
||||
res.eventChannel.emit('detailData', {
|
||||
data: f,
|
||||
deviceType: '',
|
||||
apiType: 'listA'
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}else{
|
||||
console.log("当前全局不处理此消息");
|
||||
}
|
||||
return formData;
|
||||
} catch (error) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
if (receive.str) {
|
||||
try {
|
||||
|
||||
let str = receive.str;
|
||||
|
||||
if (str.indexOf('mac address:') == 0) {
|
||||
let formData={};
|
||||
formData.macAddress = str.split(':')[1];
|
||||
this.setBleFormData(formData,f);
|
||||
return formData;
|
||||
}
|
||||
else{
|
||||
let receiveData={a:1};
|
||||
try {
|
||||
let json=JSON.parse(str);
|
||||
|
||||
if("staBlue_picture" in json){
|
||||
//重发图片
|
||||
console.log("收到重新发送图片的命令");
|
||||
receiveData=json;
|
||||
}
|
||||
else if("staBlue_text" in json){
|
||||
//重发文本
|
||||
console.log("收到重新发送文本的命令");
|
||||
receiveData=json;
|
||||
}
|
||||
else if("staBlue_vidio" in json){
|
||||
//重发视频
|
||||
console.log("收到重新发送视频的命令");
|
||||
receiveData=json;
|
||||
}
|
||||
else if("staBlue" in json){
|
||||
if(json.staBlue=="finish"){
|
||||
console.log("收到设备回复,全部传输完成");
|
||||
receiveData=json;
|
||||
}
|
||||
|
||||
}
|
||||
else{
|
||||
receiveData={};
|
||||
console.log("无法解析该文本");
|
||||
}
|
||||
|
||||
|
||||
|
||||
} catch (error) {
|
||||
receiveData={};
|
||||
console.log("文本解析失败")
|
||||
}
|
||||
return receiveData;
|
||||
}
|
||||
return null;
|
||||
} catch (ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
let data=parseData(receive.bytes);
|
||||
console.log("data=",data);
|
||||
return data;
|
||||
|
||||
}
|
||||
|
||||
Receive_670(receive,f,path){
|
||||
|
||||
var todo = (bytes) =>{
|
||||
// console.log("todo",receive);
|
||||
let receiveData = {};
|
||||
if (bytes[0] == 0x55) {
|
||||
try {
|
||||
// console.log("todo");
|
||||
// 跳过帧头(第一个字节),从第二个字节开始解析
|
||||
let staticLevelByte = bytes[1];
|
||||
let staticLevelText = '';
|
||||
switch (staticLevelByte) {
|
||||
case 0x65:
|
||||
staticLevelText = 'hight';
|
||||
break
|
||||
case 0x66:
|
||||
staticLevelText = 'center';
|
||||
break
|
||||
case 0x67:
|
||||
staticLevelText = 'low';
|
||||
break
|
||||
case 0x68:
|
||||
staticLevelText = 'close';
|
||||
break
|
||||
}
|
||||
// console.log("todo");
|
||||
// 解析照明档位
|
||||
let lightingLevelByte = bytes[2];
|
||||
let lightingLevelText = lightingLevelByte === 0x6d ? 'hight': lightingLevelByte === 0x6e ? 'low': 'close';
|
||||
|
||||
// 解析剩余照明时间(第三和第四字节,小端序)
|
||||
let lightingTime = (bytes[3] << 8) | bytes[4];
|
||||
|
||||
// 解析剩余电量 // 电量百分比范围检查
|
||||
let batteryLevelByte = bytes[5];
|
||||
|
||||
let batteryLevel = Math.max(0, Math.min(100, batteryLevelByte));
|
||||
// console.log("todo");
|
||||
let warn = bytes[6];
|
||||
if (warn == 0x00) {
|
||||
warn = 'none';
|
||||
} else if (warn == 0x01) {
|
||||
warn = 'ruo';
|
||||
} else if (warn == 0x02) {
|
||||
warn = 'center';
|
||||
} else if (warn == 0x03) {
|
||||
warn = 'hight';
|
||||
} else if (warn == 0x04) {
|
||||
warn = 'veryhight';
|
||||
}
|
||||
|
||||
let staticWarn = bytes[7] == 0x01;//静止报警
|
||||
let fourGStrenth = bytes[8]; //4g信号强度
|
||||
let sosTxt = bytes[9] == 0x00 ? 'close' : bytes[9] == 0x01 ? 'sg' : 'rb';
|
||||
// console.log("todo");
|
||||
receiveData.modeCurr = staticLevelText;
|
||||
receiveData.lightCurr = lightingLevelText;
|
||||
receiveData.xuhang = lightingTime ;
|
||||
receiveData.battary = batteryLevel;
|
||||
receiveData.warnLevel = warn;
|
||||
receiveData.staticWarn = staticWarn;
|
||||
receiveData.fourGStrenth = fourGStrenth;
|
||||
receiveData.SOS=sosTxt;
|
||||
} catch(error) {
|
||||
console.log('数据解析错误:', error);
|
||||
}
|
||||
// console.log("todo");
|
||||
} else {
|
||||
try {
|
||||
let uint8Array = new Uint8Array(receive.value);
|
||||
let str = '';
|
||||
for (let i = 0; i < uint8Array.length; i++) {
|
||||
// 将每个字节转换为对应的字符
|
||||
str += String.fromCharCode(uint8Array[i]);
|
||||
}
|
||||
if (str.indexOf('mac address:') == 0) {
|
||||
receiveData.macAddress = str.split(':').slice(1).join(":");
|
||||
console.log('收到mac地址:', +this.receiveData.macAddress);
|
||||
} else if (str.indexOf('imei:') == 0) {
|
||||
receiveData.imei = str.split(':')[1];
|
||||
console.log('收到IEMI:', +this.receiveData.macAddress);
|
||||
|
||||
} else if (str.indexOf('longitude:') == 0) {
|
||||
receiveData.Lon = str.split(':')[1];
|
||||
console.log('收到经度:', +this.receiveData.macAddress);
|
||||
} else if (str.indexOf('latitude:') == 0) {
|
||||
receiveData.Lat = str.split(':')[1];
|
||||
console.log('收到纬度:', +this.receiveData.macAddress);
|
||||
} else {
|
||||
try {
|
||||
// console.log("str=",str);
|
||||
let json=JSON.parse(str);
|
||||
if("staBlue_picture" in json){
|
||||
//重发图片
|
||||
console.log("收到重新发送图片的命令");
|
||||
receiveData=json;
|
||||
}
|
||||
else if("staBlue_text" in json){
|
||||
//重发文本
|
||||
console.log("收到重新发送文本的命令");
|
||||
receiveData=json;
|
||||
}
|
||||
else if("staBlue_vidio" in json){
|
||||
//重发视频
|
||||
console.log("收到重新发送视频的命令");
|
||||
receiveData=json;
|
||||
}
|
||||
else if("staBlue" in json){
|
||||
if(json.staBlue=="finish"){
|
||||
console.log("收到设备回复,全部传输完成");
|
||||
receiveData=json;
|
||||
}
|
||||
|
||||
}
|
||||
else{
|
||||
receiveData={};
|
||||
console.log("无法解析该文本");
|
||||
}
|
||||
|
||||
|
||||
|
||||
} catch (error) {
|
||||
receiveData={};
|
||||
// console.log("文本解析失败",error)
|
||||
}
|
||||
}
|
||||
} catch(ex) {
|
||||
receiveData={};
|
||||
console.log('将数据转文本失败', ex);
|
||||
}
|
||||
}
|
||||
// console.log("todo",receiveData);
|
||||
this.setBleFormData(receiveData,f);
|
||||
return receiveData;
|
||||
}
|
||||
|
||||
|
||||
let data=todo(receive.bytes);
|
||||
|
||||
return data;
|
||||
}
|
||||
Receive_6155() {
|
||||
console.log("通用程序正在处理6155的数据");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
let receiveInstance = null;
|
||||
export default {
|
||||
getBleReceive: function(found, receive) {
|
||||
if (!receiveInstance) {
|
||||
receiveInstance = new BleReceive();
|
||||
|
||||
}
|
||||
return receiveInstance;
|
||||
}
|
||||
}
|
218
utils/Common.js
Normal file
@ -0,0 +1,218 @@
|
||||
var cfg={
|
||||
Version:'Uat',//Dev:开发环境,Uat:Uat环境,Relese正式环境
|
||||
DevApi:'http://192.168.110.54:8000/',//开发环境
|
||||
UatApi:'http://114.55.111.217/',//UAT环境
|
||||
ReleseApi:'http://relese:3169/api/'//Relese环境
|
||||
}
|
||||
export default {
|
||||
baseURL : cfg.Version=='Dev'?cfg.DevApi:(cfg.Version=='Uat'?cfg.UatApi:cfg.ReleseApi),
|
||||
guid:function generateUUID() {
|
||||
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
|
||||
const r = Math.random() * 16 | 0;
|
||||
const v = c === 'x' ? r : (r & 0x3 | 0x8);
|
||||
return v.toString(16);
|
||||
});
|
||||
},
|
||||
alert: function(title, content, callback) {
|
||||
if(!title){
|
||||
title='提示'
|
||||
}
|
||||
if(!content){
|
||||
content=title;
|
||||
}
|
||||
|
||||
uni.showModal({
|
||||
title: title,
|
||||
content: content,
|
||||
success: function(res) {
|
||||
if (res.confirm) {
|
||||
console.log('用户点击确定');
|
||||
} else if (res.cancel) {
|
||||
console.log('用户点击取消');
|
||||
}
|
||||
|
||||
if (callback) {
|
||||
callback(res);
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
showLoading:function(title,mask){
|
||||
uni.showLoading({
|
||||
title:title,
|
||||
mask:mask,
|
||||
})
|
||||
},
|
||||
hideLoading:function(){
|
||||
uni.hideLoading();
|
||||
},
|
||||
showToast:function(title,mask,duration,callback){
|
||||
if(!duration){
|
||||
duration=1500;
|
||||
}
|
||||
if(mask==undefined){
|
||||
mask=false;
|
||||
}
|
||||
uni.showToast({
|
||||
title:title,
|
||||
mask:mask,
|
||||
duration:duration,
|
||||
callback:callback,
|
||||
icon: 'none'
|
||||
})
|
||||
},
|
||||
GetData:function(url,data,method,contentType,succ,err,complete){
|
||||
var these=this;
|
||||
if(!url){
|
||||
console.error("url为空");
|
||||
return;
|
||||
}
|
||||
|
||||
if(url.toLowerCase().indexOf('http://')==-1 || url.toLowerCase().indexOf('https://')==-1){
|
||||
if(url.indexOf('/')==0){
|
||||
url=url.substr(1,url.length-1);
|
||||
}
|
||||
let ServerPath=these.DevApi;
|
||||
if(these.Version==='Dev'){
|
||||
ServerPath=these.DevApi;
|
||||
}
|
||||
else if(these.Version==='Uat'){
|
||||
ServerPath=these.UatApi;
|
||||
}
|
||||
else if(these.Version==='Relese'){
|
||||
ServerPath=these.ReleseApi;
|
||||
}else{
|
||||
these.DevApi
|
||||
}
|
||||
url=ServerPath+url;
|
||||
}
|
||||
|
||||
var these=this;
|
||||
if(!method){
|
||||
method='POST';
|
||||
}
|
||||
method=method.toUpperCase();
|
||||
|
||||
if(!contentType){
|
||||
contentType='application/json;charset=UTF-8';
|
||||
}
|
||||
|
||||
these.checkLAN(
|
||||
|
||||
function(){
|
||||
these.showLoading('请稍候..',true);
|
||||
setTimeout(function(){
|
||||
uni.request({
|
||||
url:url,
|
||||
data:data,
|
||||
header:{
|
||||
"Content-Type":contentType
|
||||
},
|
||||
method:method,
|
||||
timeout:60000,
|
||||
dataType:'json',
|
||||
success:function(json){
|
||||
|
||||
if(succ){
|
||||
succ(json);
|
||||
}
|
||||
},
|
||||
fail:function(ex){
|
||||
|
||||
if(err){
|
||||
err(ex);
|
||||
}
|
||||
},
|
||||
complete:function(){
|
||||
|
||||
if(complete){
|
||||
complete();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
},0);
|
||||
|
||||
}
|
||||
|
||||
,function(){
|
||||
these.showToast('无网络连接');
|
||||
});
|
||||
},
|
||||
checkLAN:function(succ,error){
|
||||
uni.getNetworkType({
|
||||
success: (res) => {
|
||||
const networkType = res.networkType;
|
||||
|
||||
|
||||
// 判断网络是否连接
|
||||
if (networkType === 'none') {
|
||||
console.error('无网络连接')
|
||||
if(error){
|
||||
error();
|
||||
}
|
||||
}else{
|
||||
if(succ){
|
||||
succ();
|
||||
}
|
||||
|
||||
}
|
||||
},
|
||||
fail: (err) => {
|
||||
console.error('获取网络状态失败:', err);
|
||||
if(error){
|
||||
error();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
},
|
||||
DateFormat: function(date, format) {
|
||||
if(!date){
|
||||
date=new Date();
|
||||
}
|
||||
if(!format){
|
||||
format='yyyy-MM-dd HH:mm:ss';
|
||||
}
|
||||
// 处理参数默认值
|
||||
if (typeof date === 'string' || typeof date === 'number') {
|
||||
date = new Date(date);
|
||||
}
|
||||
date = date instanceof Date ? date : new Date();
|
||||
format = format || 'yyyy-MM-dd';
|
||||
|
||||
// 检查日期是否有效
|
||||
if (isNaN(date.getTime())) {
|
||||
return 'Invalid Date';
|
||||
}
|
||||
|
||||
// 定义格式化映射
|
||||
const formatMap = {
|
||||
'yyyy': date.getFullYear(),
|
||||
'MM': String(date.getMonth() + 1).padStart(2, '0'),
|
||||
'dd': String(date.getDate()).padStart(2, '0'),
|
||||
'HH': String(date.getHours()).padStart(2, '0'),
|
||||
'mm': String(date.getMinutes()).padStart(2, '0'),
|
||||
'ss': String(date.getSeconds()).padStart(2, '0'),
|
||||
'SSS': String(date.getMilliseconds()).padStart(3, '0'),
|
||||
'M': date.getMonth() + 1,
|
||||
'd': date.getDate(),
|
||||
'H': date.getHours(),
|
||||
'm': date.getMinutes(),
|
||||
's': date.getSeconds(),
|
||||
'S': date.getMilliseconds()
|
||||
};
|
||||
|
||||
// 替换格式字符串中的占位符
|
||||
return format.replace(/(yyyy|MM|dd|HH|mm|ss|SSS|M|d|H|m|s|S)/g, (match) => {
|
||||
return formatMap[match];
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
68
utils/function.js
Normal file
@ -0,0 +1,68 @@
|
||||
/**
|
||||
* 生成短ID (16位字符)
|
||||
*/
|
||||
export const generateShortId = () => {
|
||||
const crypto = window.crypto || window.msCrypto;
|
||||
|
||||
if (crypto?.getRandomValues) {
|
||||
return Array.from(crypto.getRandomValues(new Uint32Array(3)))
|
||||
.map(n => n.toString(36))
|
||||
.join('')
|
||||
.slice(0, 16);
|
||||
}
|
||||
|
||||
return Date.now().toString(36) + Math.random().toString(36).substr(2, 8);
|
||||
};
|
||||
export default generateShortId;
|
||||
|
||||
// 获取设备实时状态的
|
||||
/**
|
||||
* 获取设备状态(带自动轮询)
|
||||
* @param {Object} options - 配置对象
|
||||
* @param {number} options.functionMode - 功能模式
|
||||
* @param {string} options.batchId - 批次ID
|
||||
* @param {Object} options.sendInfo - 设备信息
|
||||
* @param {string} options.sendInfo.typeName - 类型名称
|
||||
* @param {string} options.sendInfo.deviceImei - 设备IMEI
|
||||
* @param {number} [options.interval=500] - 轮询间隔(毫秒)
|
||||
* @param {Function} apiClient - 接口调用函数
|
||||
*/
|
||||
export async function getdeviceSTatus({
|
||||
functionMode,
|
||||
batchId,
|
||||
typeName,
|
||||
deviceImei,
|
||||
interval
|
||||
}, apiClient) {
|
||||
const checkStatus = async () => {
|
||||
try {
|
||||
const res = await apiClient({
|
||||
functionMode,
|
||||
batchId,
|
||||
typeName,
|
||||
deviceImei
|
||||
});
|
||||
if (res.code !== 200) {
|
||||
throw new Error(res.msg || '请求失败');
|
||||
}
|
||||
switch (res.data.functionAccess) {
|
||||
case 'OK':
|
||||
return res;
|
||||
case 'ACTIVE':
|
||||
await new Promise(r => setTimeout(r, interval));
|
||||
return checkStatus();
|
||||
case 'FAILED':
|
||||
throw new Error('设备操作失败');
|
||||
case 'TIMEOUT':
|
||||
throw new Error('设备响应超时');
|
||||
default:
|
||||
throw new Error('未知状态');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('设备状态轮询错误:', error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
return checkStatus();
|
||||
}
|
122
utils/gbk.js
Normal file
42
utils/loading.js
Normal file
@ -0,0 +1,42 @@
|
||||
// utils/loading.js
|
||||
|
||||
// 显示loading
|
||||
export const showLoading = (ev,options) => {
|
||||
if(!ev){
|
||||
return;
|
||||
}
|
||||
let defaultTxt="请稍候...";
|
||||
if(!options){
|
||||
options={text:defaultTxt};
|
||||
}
|
||||
if(!options.text && options.title){
|
||||
options.text=options.title;
|
||||
}
|
||||
if(!options.text){
|
||||
options.text=defaultTxt;
|
||||
}
|
||||
ev.$refs.loading.show(options);
|
||||
}
|
||||
|
||||
// 隐藏loading
|
||||
export const hideLoading = (ev) => {
|
||||
|
||||
if(!ev){
|
||||
return;
|
||||
}
|
||||
ev.$refs.loading.hide();
|
||||
|
||||
|
||||
}
|
||||
|
||||
// 更新loading配置
|
||||
export const updateLoading = (ev,options) => {
|
||||
if(!ev){
|
||||
return;
|
||||
}
|
||||
if(!options){
|
||||
options={a:1};
|
||||
}
|
||||
ev.$refs.loading.update(options)
|
||||
|
||||
}
|
@ -121,7 +121,6 @@ import allConfigs from '../config/index.js';
|
||||
// 根据环境选择正确的配置
|
||||
const env = 'production'; //production //开发of线上 改这里就行
|
||||
const config = allConfigs[env];
|
||||
|
||||
class MqttClient {
|
||||
constructor() {
|
||||
this.client = null;
|
||||
@ -171,12 +170,16 @@ class MqttClient {
|
||||
potentialJsons.forEach(jsonString => {
|
||||
if (jsonString.trim() === '') return;
|
||||
if (this.messageCallbacks.has(topic)) {
|
||||
this.messageCallbacks.get(topic)(jsonString);
|
||||
this.messageCallbacks.get(topic)(jsonString,message);
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
isConnected() {
|
||||
return this.client && this.client.isConnected();
|
||||
}
|
||||
|
||||
connect(onConnectCallback) {
|
||||
if (this.client && this.client.isConnected()) {
|
||||
console.log('MQTT客户端已连接。');
|
||||
@ -281,8 +284,10 @@ class MqttClient {
|
||||
mqttMessage.qos = 1;
|
||||
this.client.send(mqttMessage);
|
||||
console.log(`成功发布消息到主题 ${topic}: ${message}`);
|
||||
return true;
|
||||
} else {
|
||||
console.error('MQTT未连接,无法发布');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -20,11 +20,13 @@ const request = (options) => {
|
||||
method: options.method || 'GET',
|
||||
data: options.method !== 'GET' ? options.data : {},
|
||||
header: options.header || {},
|
||||
timeout: 10000,
|
||||
timeout: 30000,
|
||||
success: (res) => {
|
||||
console.log("res=",res);
|
||||
resolve(res.data);
|
||||
},
|
||||
fail: (err) => {
|
||||
console.log("ex=",err);
|
||||
reject(err);
|
||||
}
|
||||
};
|
||||
|
153
utils/update.js
Normal file
@ -0,0 +1,153 @@
|
||||
/**
|
||||
* 检查并执行wgt热更新
|
||||
* @param {String} updateUrl - 检查更新的接口地址
|
||||
*/
|
||||
function checkAndUpdateWgt(updateUrl) {
|
||||
if(!plus){
|
||||
return;
|
||||
}
|
||||
// 显示加载提示
|
||||
|
||||
|
||||
// 1. 获取当前应用版本信息
|
||||
plus.runtime.getProperty(plus.runtime.appid, (widgetInfo) => {
|
||||
const currentVersion = widgetInfo.version;
|
||||
console.log("当前版本:" + currentVersion);
|
||||
// 2. 调用后端接口检查是否有更新
|
||||
uni.request({
|
||||
url: updateUrl,
|
||||
method: 'GET',
|
||||
data: {
|
||||
currentVersion: currentVersion,
|
||||
platform: uni.getSystemInfoSync().platform
|
||||
},
|
||||
success: (res) => {
|
||||
uni.hideLoading();
|
||||
console.log("res=", res)
|
||||
if (res.statusCode === 200) {
|
||||
|
||||
const updateInfo = res.data.data;
|
||||
if (!updateInfo.hasUpdate) {
|
||||
return;
|
||||
}
|
||||
// 3. 显示更新提示
|
||||
uni.showModal({
|
||||
title: '检测到更新',
|
||||
content: updateInfo.description || '有新版本可用,是否立即更新?',
|
||||
confirmText: '立即更新',
|
||||
cancelText: '稍后更新',
|
||||
success: (modalRes) => {
|
||||
if (modalRes.confirm) {
|
||||
downloadAndInstallWgt(updateInfo.downloadUrl);
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
uni.showToast({
|
||||
title: '当前已是最新版本',
|
||||
icon: 'none',
|
||||
duration: 2000
|
||||
});
|
||||
}
|
||||
},
|
||||
fail: (err) => {
|
||||
uni.hideLoading();
|
||||
uni.showToast({
|
||||
title: '检查更新失败',
|
||||
icon: 'none',
|
||||
duration: 2000
|
||||
});
|
||||
console.error('检查更新失败:', err);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载并安装wgt更新包
|
||||
* @param {String} wgtUrl - wgt包下载地址
|
||||
*/
|
||||
function downloadAndInstallWgt(wgtUrl) {
|
||||
// 显示下载进度
|
||||
var wating=plus.nativeUI.showWaiting({
|
||||
title:"下载中0%"
|
||||
});
|
||||
// uni.showLoading({
|
||||
// title: '更新下载中...',
|
||||
// mask: true
|
||||
// });
|
||||
|
||||
// 1. 下载wgt包
|
||||
const downloadTask = uni.downloadFile({
|
||||
url: wgtUrl,
|
||||
success: (downloadRes) => {
|
||||
wating.setTitle("下载完成,正在安装");
|
||||
if (downloadRes.statusCode === 200) {
|
||||
// 2. 安装wgt包
|
||||
plus.runtime.install(downloadRes.tempFilePath, {
|
||||
force: true // 是否强制安装
|
||||
}, () => {
|
||||
uni.removeSavedFile({
|
||||
filePath: downloadRes.tempFilePath,
|
||||
success() {
|
||||
console.log("临时文件已删除");
|
||||
},
|
||||
fail() {
|
||||
console.log("无法删除临时文件");
|
||||
},
|
||||
complete() {
|
||||
wating.close();
|
||||
uni.showModal({
|
||||
title: '更新完成',
|
||||
content: '应用已更新,是否重启应用?',
|
||||
showCancel: false,
|
||||
success: () => {
|
||||
// 3. 重启应用
|
||||
plus.runtime.restart();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
}, (error) => {
|
||||
|
||||
wating.close();
|
||||
uni.showToast({
|
||||
title: '安装失败: ' + error.message,
|
||||
icon: 'none',
|
||||
duration: 3000
|
||||
});
|
||||
console.error('wgt安装失败:', error);
|
||||
});
|
||||
|
||||
} else {
|
||||
wating.close();
|
||||
uni.showToast({
|
||||
title: '下载失败',
|
||||
icon: 'none',
|
||||
duration: 2000
|
||||
});
|
||||
}
|
||||
},
|
||||
fail: (err) => {
|
||||
uni.hideLoading();
|
||||
uni.showToast({
|
||||
title: '下载失败: ' + err.errMsg,
|
||||
icon: 'none',
|
||||
duration: 2000
|
||||
});
|
||||
console.error('wgt下载失败:', err);
|
||||
}
|
||||
});
|
||||
|
||||
// 监听下载进度
|
||||
downloadTask.onProgressUpdate((progress) => {
|
||||
console.log('下载进度: ' + progress.progress + '%');
|
||||
wating.setTitle("下载中"+ progress.progress + '%');
|
||||
// 可以在这里更新自定义进度条
|
||||
});
|
||||
}
|
||||
|
||||
export default {
|
||||
checkAndUpdateWgt
|
||||
};
|
@ -164,6 +164,11 @@ math-intrinsics@^1.1.0:
|
||||
resolved "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz"
|
||||
integrity sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g==
|
||||
|
||||
mescroll-uni@^1.3.7:
|
||||
version "1.3.7"
|
||||
resolved "https://registry.npmjs.org/mescroll-uni/-/mescroll-uni-1.3.7.tgz"
|
||||
integrity sha512-1pQMtGA+iVRKhfJZZNXdBx05NnthIk6zm3hRbumswSA54eaKOMgpUDb9AQ2+rRdXmS6kLkEYSbW/fkb7/IyoAg==
|
||||
|
||||
mime-db@1.52.0:
|
||||
version "1.52.0"
|
||||
resolved "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz"
|
||||
|