Commit 51d671d5 by liangjianmin

js

parent 5f81aba0
Showing with 57 additions and 27 deletions
......@@ -103,10 +103,11 @@ export default {
fail: res => {
uni.hideLoading();
console.log('查找设备失败!');
uni.showToast({
icon: 'error',
title: '查找设备失败!',
duration: 3000
uni.showModal({
title: '提示',
content: '查找设备失败',
showCancel: false,
confirmText: '关闭'
});
}
});
......@@ -182,10 +183,11 @@ export default {
uni.setStorageSync('device', { name: this.deviceName, deviceId: this.deviceId });
},
fail: error => {
uni.showToast({
icon: 'error',
title: '连接设备失败!',
duration: 3000
uni.showModal({
title: '提示',
content: '连接设备失败',
showCancel: false,
confirmText: '关闭'
});
}
});
......@@ -197,27 +199,55 @@ export default {
uni.showLoading({
title: '连接设备中'
});
//先断开现有蓝牙连接
uni.closeBLEConnection({
deviceId: this.deviceId,
success: res => {
console.log('断开蓝牙连接:', JSON.stringify(res.errMsg));
this.deviceName = name; //设备名称
this.deviceId = deviceId; //设备id
this.current = index;
this.stopBluetoothDevicesDiscovery(); //先停止蓝牙搜索
//判断设备当前是否有连接
if (this.deviceId) {
//先断开现有蓝牙连接
uni.closeBLEConnection({
deviceId: deviceId,
success: res => {
console.log('断开蓝牙连接:', JSON.stringify(res.errMsg));
this.deviceName = name; //设备名称
this.deviceId = deviceId; //设备id
this.current = index;
//恢复蓝牙连接状态的初始值
if (this.textArr.length > 0) {
var tempArr = [];
for (let i = 0; i < this.textArr.length; i++) {
tempArr.push('连接');
this.stopBluetoothDevicesDiscovery(); //先停止蓝牙搜索
//恢复蓝牙连接状态的初始值
if (this.textArr.length > 0) {
var tempArr = [];
for (let i = 0; i < this.textArr.length; i++) {
tempArr.push('连接');
}
this.textArr = tempArr;
}
this.textArr = tempArr;
},
fail: error => {
uni.hideLoading();
uni.showModal({
title: '提示',
content: '断开设备失败',
showCancel: false,
confirmText: '关闭'
});
}
});
} else {
this.deviceName = name; //设备名称
this.deviceId = deviceId; //设备id
this.current = index;
this.stopBluetoothDevicesDiscovery(); //先停止蓝牙搜索
//恢复蓝牙连接状态的初始值
if (this.textArr.length > 0) {
var tempArr = [];
for (let i = 0; i < this.textArr.length; i++) {
tempArr.push('连接');
}
this.textArr = tempArr;
}
});
}
},
/**
* 刷新蓝牙列表
......@@ -228,7 +258,7 @@ export default {
console.log('停止搜索', JSON.stringify(res.errMsg));
this.list = [];
this.startBluetoothDeviceDiscovery();
//刷新图标交互
this.refreshTransition = true;
setTimeout(() => {
......
//const API_BASE = 'https://api.ichunt.com';
const API_BASE = 'http://api.liexin.com'
const API_BASE = 'https://api.ichunt.com';
//const API_BASE = 'http://api.liexin.com'
const API = {
/**
* 上传数据
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment