670完成
25
App.vue
@ -5,8 +5,31 @@
|
||||
export default {
|
||||
|
||||
onLaunch: function() {
|
||||
var ble = bleTool.getBleTool();
|
||||
//以下代码仅在开发时使用,否则会出现不可预知的问题。
|
||||
// uni.clearStorageSync();
|
||||
var ble = bleTool.getBleTool();
|
||||
// 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);
|
||||
// }
|
||||
// });
|
||||
|
||||
|
||||
},
|
||||
onShow: function() {
|
||||
console.log('App Show');
|
||||
|
@ -1,708 +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({
|
||||
success: (res) => {
|
||||
if (callback) {
|
||||
callback(res);
|
||||
|
||||
}
|
||||
},
|
||||
fail: function(ex) {
|
||||
console.log("获取已连接设备异常",ex);
|
||||
if (callback) {
|
||||
callback({
|
||||
devices: []
|
||||
});
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
//连接某个设备
|
||||
LinkBlue: function(deviceId, callback, error) {
|
||||
//console.log("deviceId="+deviceId)
|
||||
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(id,flag) {
|
||||
|
||||
let c = linkedDevices.find(function(v) {
|
||||
return v.deviceId == deviceId;
|
||||
});
|
||||
|
||||
if (c && !flag) {
|
||||
console.log("连接成功开始监听特征变化,deviceid="+deviceId+',serviceId='+c.notifyServiceid+',characteristicId='+c.notifyCharactId)
|
||||
//监听设备的特征变化
|
||||
setTimeout(()=>{
|
||||
uni.notifyBLECharacteristicValueChange({
|
||||
deviceId: deviceId,
|
||||
serviceId: c.notifyServiceid,
|
||||
characteristicId: c.notifyCharactId,
|
||||
state: true,
|
||||
success: function(res) {
|
||||
console.log("开始监听成功。。。。",res)
|
||||
//订阅特征值
|
||||
|
||||
uni.onBLECharacteristicValueChange(function(data) {
|
||||
// data.characteristicId
|
||||
// data.deviceId
|
||||
// data.serviceId
|
||||
// data.value
|
||||
console.log("监听到特征值:" + JSON.stringify(data));
|
||||
|
||||
if (these.featrueValueCallback) {
|
||||
these.featrueValueCallback(data);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
},1000);
|
||||
|
||||
}
|
||||
|
||||
if (callback) {
|
||||
callback(deviceId,flag);
|
||||
}
|
||||
}
|
||||
|
||||
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,true);
|
||||
|
||||
return;
|
||||
} else {
|
||||
console.log("设备未连接:"+deviceId);
|
||||
linkDevice(deviceId);
|
||||
}
|
||||
}
|
||||
|
||||
var linkDevice = function() {
|
||||
console.log("正在连接" + deviceId);
|
||||
uni.createBLEConnection({
|
||||
deviceId: deviceId,
|
||||
timeout: 30000,
|
||||
success: function(info) {
|
||||
|
||||
console.log("连接成功");
|
||||
|
||||
var call = () => {
|
||||
if (linkedDevices) {
|
||||
console.log("11111" + JSON.stringify(linkedDevices));
|
||||
f = linkedDevices.find(function(v) {
|
||||
return v.deviceId == deviceId;
|
||||
});
|
||||
} 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 == deviceId;
|
||||
});
|
||||
linkedDevices.push(f);
|
||||
uni.setStorageSync(key, JSON.stringify(
|
||||
linkedDevices));
|
||||
|
||||
getService(deviceId);
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
} else {
|
||||
console.log("缓存中已连接过");
|
||||
if (!f.services) {
|
||||
getService(deviceId);
|
||||
} else {
|
||||
|
||||
lindedCallback(deviceId,false);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
let os = uni.getSystemInfoSync().osName;
|
||||
if (os == 'android') {
|
||||
uni.setBLEMTU({
|
||||
deviceId: deviceId,
|
||||
mtu: 512,
|
||||
success: () => {
|
||||
//console.log("mtu设置成功");
|
||||
},
|
||||
fail: function() {
|
||||
console.log("mtu设置失败")
|
||||
},
|
||||
complete: function() {
|
||||
call();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
call();
|
||||
}
|
||||
|
||||
},
|
||||
fail: function(ex) {
|
||||
if (ex) {
|
||||
console.log("蓝牙连接失败" + JSON.stringify(ex));
|
||||
if(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,false);
|
||||
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('至少一个操作失败', error);
|
||||
});
|
||||
|
||||
|
||||
} else {
|
||||
repeatCnt++;
|
||||
if (repeatCnt > 5) {
|
||||
|
||||
lindedCallback(id,false);
|
||||
|
||||
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");
|
||||
these.sendDataNew(f.deviceId,f.writeServiceId,f.wirteCharactId,buffer).then(succ).catch(err);
|
||||
} else {
|
||||
reject(`已连接设备中无法找到此设备`);
|
||||
// console.log("警报:已连接设备中无法找到此设备")
|
||||
}
|
||||
|
||||
} else {
|
||||
console.log("检测到未与设备建立连接");
|
||||
reject(`检测到未与设备建立连接`);
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
},
|
||||
sendDataNew: function(deviceid, serviceId, characteristicId, buffer) {
|
||||
|
||||
//console.log("准备向设备发送数据,deviceid=" + deviceid+',serviceId='+serviceId+',characteristicId='+characteristicId);
|
||||
return new Promise((resolve, reject) => {
|
||||
let promise = new Promise((succ, err) => {
|
||||
uni.writeBLECharacteristicValue({
|
||||
deviceId: deviceid,
|
||||
serviceId: serviceId,
|
||||
characteristicId: characteristicId,
|
||||
value: buffer,
|
||||
success: () => {
|
||||
//console.log("发送数据成功");
|
||||
succ();
|
||||
},
|
||||
fail: (ex) => {
|
||||
console.log("发送数据失败" + JSON.stringify(ex));
|
||||
err(ex);
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
if (uni.getSystemInfoSync().osName.toLowerCase() == 'ios') {
|
||||
|
||||
//专业给IOS填坑,uni.writeBLECharacteristicValue在IOS上不进入任何回调
|
||||
|
||||
function timeout(ms) {
|
||||
return new Promise((_, err) => {
|
||||
setTimeout(() => {
|
||||
err({
|
||||
code: -1,
|
||||
errMsg: '超时了'
|
||||
})
|
||||
}, ms);
|
||||
});
|
||||
}
|
||||
|
||||
Promise.race([promise, timeout(50)]).then(resolve).catch((ex) => {
|
||||
console.log("ex=", ex);
|
||||
if (ex.code == -1) {
|
||||
resolve();
|
||||
} else {
|
||||
reject(ex);
|
||||
}
|
||||
|
||||
}).finally(() => {
|
||||
console.log("完成了")
|
||||
});
|
||||
} else {
|
||||
promise.then(resolve).catch(reject);
|
||||
}
|
||||
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
44
api/670/HBY670.js
Normal file
@ -0,0 +1,44 @@
|
||||
import request from '@/utils/request'
|
||||
|
||||
function getdata(url,method,data){
|
||||
return new Promise((resolve,reject)=>{
|
||||
if(!url){
|
||||
reject('url为空');
|
||||
return;
|
||||
}
|
||||
if(!method){
|
||||
method='POST';
|
||||
}
|
||||
request({
|
||||
url: url,
|
||||
method: method,
|
||||
data:data
|
||||
}).then((res)=>{
|
||||
resolve(res);
|
||||
}).catch(ex=>{
|
||||
reject(ex);
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
//档位设置
|
||||
function gearSetting(data){
|
||||
let url="";
|
||||
return getdata(url,"POST",data);
|
||||
}
|
||||
|
||||
//人员信息设置
|
||||
function sendUsr(data){
|
||||
let url="/app/xinghan/device/registerPersonInfo";
|
||||
return getdata(url,"POST",data);
|
||||
}
|
||||
|
||||
export default{
|
||||
gearSetting:gearSetting,
|
||||
sendUsr:sendUsr
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
"name" : "晶全-物联",
|
||||
"appid" : "__UNI__A21EF43",
|
||||
"description" : "设备管控",
|
||||
"versionName" : "1.0.8",
|
||||
"versionName" : "1.0.9",
|
||||
"versionCode" : "100",
|
||||
"transformPx" : false,
|
||||
/* 5+App特有相关 */
|
||||
|
32
pages.json
@ -1,12 +1,11 @@
|
||||
{
|
||||
"pages": [
|
||||
|
||||
{
|
||||
"path": "pages/common/login/index",
|
||||
"style": {
|
||||
"navigationStyle": "custom"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "pages/common/login/index",
|
||||
"style": {
|
||||
"navigationStyle": "custom"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path" : "pages/BlueTooth/ModeSetting/index",
|
||||
"style" :
|
||||
@ -14,6 +13,15 @@
|
||||
"navigationBarTitleText" : "设备类型"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path" : "pages/670/HBY670",
|
||||
"style" :
|
||||
{
|
||||
"navigationBarTitleText" : "HBY670"
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
{
|
||||
"path": "pages/common/index/index",
|
||||
"style": {
|
||||
@ -200,13 +208,7 @@
|
||||
"navigationBarTitleText": "呼叫"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path" : "pages/670/HBY670",
|
||||
"style" :
|
||||
{
|
||||
"navigationBarTitleText" : "HBY670"
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
|
||||
|
||||
@ -271,7 +273,7 @@
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "pages/BlueTooth/ModeSetting/HBY670",
|
||||
"path": "pages/BlueTooth/ModeSetting/HBY670V1",
|
||||
"style": {
|
||||
"navigationBarTitleText": "HBY670"
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ var mqttClient=null;
|
||||
videoDuration: 2,
|
||||
|
||||
hexArray: [],
|
||||
reSendNumber:""
|
||||
reSendNumber:""
|
||||
}
|
||||
},
|
||||
onLoad() {
|
||||
@ -401,7 +401,7 @@ reSendNumber:""
|
||||
}).catch(err => {
|
||||
console.log("完成指令发送失败");
|
||||
});
|
||||
},500)
|
||||
},1500)
|
||||
|
||||
},
|
||||
sendData(buffer) {
|
||||
|
@ -33,7 +33,7 @@
|
||||
url: '6155_V1'
|
||||
},
|
||||
{
|
||||
name: "/pages/BlueTooth/ModeSetting/HBY670",
|
||||
name: "/pages/BlueTooth/ModeSetting/HBY670V1",
|
||||
url: 'HBY670'
|
||||
},
|
||||
|
||||
|
@ -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() {
|
||||
@ -148,26 +171,7 @@
|
||||
|
||||
|
||||
console.log('44444');
|
||||
if(uni.getStorageSync("token") && uni.getStorageSync("clientID")){//免登陆
|
||||
|
||||
let time=uni.getStorageSync("tokenTime");
|
||||
if(!time){
|
||||
time=0;
|
||||
}
|
||||
let currTime=new Date().getTime();
|
||||
if(currTime<time){
|
||||
uni.switchTab({
|
||||
url: '/pages/common/index/index'
|
||||
});
|
||||
return;
|
||||
}else{
|
||||
//token过期了
|
||||
uni.removeStorageSync("token")
|
||||
uni.removeStorageSync("clientID")
|
||||
uni.removeStorageSync("tokenTime")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
uni.showLoading({
|
||||
title: '登录中...'
|
||||
})
|
||||
|
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 |
@ -362,6 +362,7 @@ class BleHelper {
|
||||
success: (args) => {
|
||||
console.log("蓝牙初始化成功:" + JSON.stringify(args));
|
||||
this.data.isOpenBlue = true;
|
||||
this.data.available=true;
|
||||
resolve(true);
|
||||
|
||||
if (this.data.isSubscribe) { //整个App生命周期,只订阅一次
|
||||
@ -939,6 +940,10 @@ class BleHelper {
|
||||
resolve(false);
|
||||
return;
|
||||
}
|
||||
if(!this.data.available){
|
||||
reject(this.getError({code:10001}));
|
||||
return;
|
||||
}
|
||||
console.log("正在连接" + deviceId);
|
||||
uni.createBLEConnection({
|
||||
deviceId: deviceId,
|
||||
|
@ -257,25 +257,25 @@ class BleReceive {
|
||||
try {
|
||||
// 跳过帧头(第一个字节),从第二个字节开始解析
|
||||
let staticLevelByte = bytes[1];
|
||||
let staticLevelText = '未知';
|
||||
let staticLevelText = '';
|
||||
switch (staticLevelByte) {
|
||||
case 0x65:
|
||||
staticLevelText = '高档';
|
||||
staticLevelText = 'hight';
|
||||
break
|
||||
case 0x66:
|
||||
staticLevelText = '中档';
|
||||
staticLevelText = 'center';
|
||||
break
|
||||
case 0x67:
|
||||
staticLevelText = '低档';
|
||||
staticLevelText = 'low';
|
||||
break
|
||||
case 0x68:
|
||||
staticLevelText = '关闭';
|
||||
staticLevelText = 'close';
|
||||
break
|
||||
}
|
||||
|
||||
// 解析照明档位
|
||||
let lightingLevelByte = bytes[2];
|
||||
let lightingLevelText = lightingLevelByte === 0x6d ? '强光': lightingLevelByte === 0x6e ? '弱光': '关闭';
|
||||
let lightingLevelText = lightingLevelByte === 0x6d ? 'hight': lightingLevelByte === 0x6e ? 'low': 'close';
|
||||
|
||||
// 解析剩余照明时间(第三和第四字节,小端序)
|
||||
let lightingTime = (bytes[3] << 8) | bytes[4];
|
||||
@ -286,26 +286,26 @@ class BleReceive {
|
||||
let batteryLevel = Math.max(0, Math.min(100, batteryLevelByte));
|
||||
|
||||
let warn = bytes[6];
|
||||
if (warn == 0x00) {
|
||||
warn = '无预警';
|
||||
} else if (warn == 0x01) {
|
||||
warn = '弱预警';
|
||||
} else if (warn == 0x02) {
|
||||
warn = '中预警';
|
||||
} else if (warn == 0x03) {
|
||||
warn = '强预警';
|
||||
} else if (warn == 0x04) {
|
||||
warn = '非常强预警';
|
||||
}
|
||||
// if (warn == 0x00) {
|
||||
// warn = '无预警';
|
||||
// } else if (warn == 0x01) {
|
||||
// warn = '弱预警';
|
||||
// } else if (warn == 0x02) {
|
||||
// warn = '中预警';
|
||||
// } else if (warn == 0x03) {
|
||||
// warn = '强预警';
|
||||
// } else if (warn == 0x04) {
|
||||
// warn = '非常强预警';
|
||||
// }
|
||||
|
||||
let staticWarn = bytes[7] == 0x01 ? '静止报警': '无静止报警';
|
||||
let staticWarn = bytes[7] == 0x01;//静止报警
|
||||
let fourGStrenth = bytes[8]; //4g信号强度
|
||||
let sosTxt = bytes[9] == 0x00 ? '关闭' : bytes[9] == 0x01 ? '爆闪模式' : '红蓝模式';
|
||||
let sosTxt = bytes[9] == 0x00 ? '关闭' : bytes[9] == 0x01 ? 'sg' : 'rb';
|
||||
|
||||
receiveData.staticLevel = staticLevelText;
|
||||
receiveData.lightingLevel = lightingLevelText;
|
||||
receiveData.lightingTime = lightingTime ;
|
||||
receiveData.batteryLevel = batteryLevel;
|
||||
receiveData.modeCurr = staticLevelText;
|
||||
receiveData.lightCurr = lightingLevelText;
|
||||
receiveData.xuhang = lightingTime ;
|
||||
receiveData.battary = batteryLevel;
|
||||
receiveData.warnLevel = warn;
|
||||
receiveData.staticWarn = staticWarn;
|
||||
receiveData.fourGStrenth = fourGStrenth;
|
||||
|