Commit 51d671d5 by liangjianmin

js

parent 5f81aba0
Showing with 57 additions and 27 deletions
...@@ -103,10 +103,11 @@ export default { ...@@ -103,10 +103,11 @@ export default {
fail: res => { fail: res => {
uni.hideLoading(); uni.hideLoading();
console.log('查找设备失败!'); console.log('查找设备失败!');
uni.showToast({ uni.showModal({
icon: 'error', title: '提示',
title: '查找设备失败!', content: '查找设备失败',
duration: 3000 showCancel: false,
confirmText: '关闭'
}); });
} }
}); });
...@@ -182,10 +183,11 @@ export default { ...@@ -182,10 +183,11 @@ export default {
uni.setStorageSync('device', { name: this.deviceName, deviceId: this.deviceId }); uni.setStorageSync('device', { name: this.deviceName, deviceId: this.deviceId });
}, },
fail: error => { fail: error => {
uni.showToast({ uni.showModal({
icon: 'error', title: '提示',
title: '连接设备失败!', content: '连接设备失败',
duration: 3000 showCancel: false,
confirmText: '关闭'
}); });
} }
}); });
...@@ -197,27 +199,55 @@ export default { ...@@ -197,27 +199,55 @@ export default {
uni.showLoading({ uni.showLoading({
title: '连接设备中' 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;
//恢复蓝牙连接状态的初始值 this.stopBluetoothDevicesDiscovery(); //先停止蓝牙搜索
if (this.textArr.length > 0) {
var tempArr = []; //恢复蓝牙连接状态的初始值
for (let i = 0; i < this.textArr.length; i++) { if (this.textArr.length > 0) {
tempArr.push('连接'); 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 { ...@@ -228,7 +258,7 @@ export default {
console.log('停止搜索', JSON.stringify(res.errMsg)); console.log('停止搜索', JSON.stringify(res.errMsg));
this.list = []; this.list = [];
this.startBluetoothDeviceDiscovery(); this.startBluetoothDeviceDiscovery();
//刷新图标交互 //刷新图标交互
this.refreshTransition = true; this.refreshTransition = true;
setTimeout(() => { setTimeout(() => {
......
//const API_BASE = 'https://api.ichunt.com'; const API_BASE = 'https://api.ichunt.com';
const API_BASE = 'http://api.liexin.com' //const API_BASE = 'http://api.liexin.com'
const API = { 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