|
|
@@ -132,11 +132,21 @@
|
|
|
// compus: '', // 校区
|
|
|
ceshi: 'code',
|
|
|
changeDate: false, // 是否是手动选择日期
|
|
|
- get_Bluetooth_Bevice: false // 自动获取蓝牙设备,并列表
|
|
|
+ get_Bluetooth_Bevice: false, // 自动获取蓝牙设备,并列表
|
|
|
+ timer: -1,
|
|
|
+ test: this.$store.state.test
|
|
|
}
|
|
|
},
|
|
|
onLoad(options) {
|
|
|
// console.log(options);
|
|
|
+ // 系统正在维护...
|
|
|
+ if (this.test == 'weihuzhong') {
|
|
|
+ uni.redirectTo({
|
|
|
+ url: '../../pages/index/index'
|
|
|
+ })
|
|
|
+
|
|
|
+ return;
|
|
|
+ }
|
|
|
// 向用户发起授权请求
|
|
|
uni.authorize({
|
|
|
scope: 'scope.userLocation',
|
|
|
@@ -187,6 +197,7 @@
|
|
|
}
|
|
|
},
|
|
|
onShow() {
|
|
|
+ let _this = this;
|
|
|
// 充值后更新金额
|
|
|
this.amount = this.$store.state.reshui_amount
|
|
|
|
|
|
@@ -194,6 +205,55 @@
|
|
|
// 获取基本信息
|
|
|
this.get_base_info('options', 'onShow')
|
|
|
}
|
|
|
+
|
|
|
+ if (this.timer > -1) {
|
|
|
+ clearInterval(this.timer)
|
|
|
+ }
|
|
|
+ this.timer = setInterval(() => {
|
|
|
+ uni.openBluetoothAdapter({
|
|
|
+ success: (res) => { // 已打开
|
|
|
+ uni.getBluetoothAdapterState({ // 蓝牙的匹配状态
|
|
|
+ success: (res1) => {
|
|
|
+ // console.log(res1);
|
|
|
+ },
|
|
|
+ fail: (error) => {
|
|
|
+ // console.log(error)
|
|
|
+ uni.showToast({
|
|
|
+ title: '请开启手机蓝牙!',
|
|
|
+ icon: 'none',
|
|
|
+ duration: 2000
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+ fail: (err) => { // 未打开
|
|
|
+ // console.log(err)
|
|
|
+ if (err.errCode == 10001) {
|
|
|
+ uni.showToast({
|
|
|
+ title: '请开启手机蓝牙 或 授权蓝牙权限!',
|
|
|
+ icon: 'none',
|
|
|
+ duration: 2000
|
|
|
+ });
|
|
|
+
|
|
|
+ setTimeout(() => {
|
|
|
+ _this.setInit();
|
|
|
+ }, 100);
|
|
|
+ } else {
|
|
|
+ uni.showToast({
|
|
|
+ icon: 'none',
|
|
|
+ title: err.errMsg,
|
|
|
+ duration: 2000
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }, 3000);
|
|
|
+ },
|
|
|
+ onHide() {
|
|
|
+ clearInterval(this.timer)
|
|
|
+ },
|
|
|
+ onUnload() {
|
|
|
+ clearInterval(this.timer)
|
|
|
},
|
|
|
methods: {
|
|
|
/**
|
|
|
@@ -286,7 +346,7 @@
|
|
|
duration: 3000
|
|
|
});
|
|
|
|
|
|
- return
|
|
|
+ return;
|
|
|
}
|
|
|
}
|
|
|
} catch (e) {
|
|
|
@@ -307,7 +367,7 @@
|
|
|
}
|
|
|
|
|
|
// 获取code
|
|
|
- this.getCode(options, param)
|
|
|
+ this.getCode(options, param);
|
|
|
},
|
|
|
/**
|
|
|
* 获得code
|
|
|
@@ -495,6 +555,7 @@
|
|
|
* 开始或停止用水
|
|
|
*/
|
|
|
switchChange(e) {
|
|
|
+ let _this = this;
|
|
|
this.isChecked = e.target.value
|
|
|
if (this.isChecked) {
|
|
|
if (this.deviceId && this.serviceId && this.devices.length != 0) {
|
|
|
@@ -503,17 +564,17 @@
|
|
|
content: '确定要启动设备?',
|
|
|
success: (res) => {
|
|
|
if (res.confirm) {
|
|
|
- this.isChecked = true
|
|
|
+ this.isChecked = true;
|
|
|
|
|
|
// 开始连接匹配的蓝牙设备
|
|
|
setTimeout(async () => {
|
|
|
// 请求获取设备启动码
|
|
|
- this.request_device_start_code()
|
|
|
- }, 300)
|
|
|
+ _this.request_device_start_code()
|
|
|
+ }, 200);
|
|
|
} else if (res.cancel) {
|
|
|
setTimeout(() => {
|
|
|
- this.isChecked = false
|
|
|
- }, 300)
|
|
|
+ _this.isChecked = false;
|
|
|
+ }, 100);
|
|
|
}
|
|
|
}
|
|
|
})
|
|
|
@@ -521,7 +582,7 @@
|
|
|
setTimeout(() => {
|
|
|
this.isChecked = false
|
|
|
}, 200)
|
|
|
-
|
|
|
+
|
|
|
uni.showToast({
|
|
|
icon: 'none',
|
|
|
title: '先【扫码连接】,后【开启设备】',
|
|
|
@@ -535,14 +596,14 @@
|
|
|
title: '与设备连接中断!请在设备上手动停止即可!',
|
|
|
duration: 3000
|
|
|
})
|
|
|
-
|
|
|
+
|
|
|
setTimeout(() => {
|
|
|
this.setInit()
|
|
|
}, 300)
|
|
|
-
|
|
|
+
|
|
|
return
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
uni.showModal({
|
|
|
title: '提示',
|
|
|
content: '确定要关闭设备?',
|
|
|
@@ -654,17 +715,19 @@
|
|
|
return false
|
|
|
}
|
|
|
},
|
|
|
+
|
|
|
/**
|
|
|
* 111111111111111111111111111111
|
|
|
* 扫码连接设备
|
|
|
*/
|
|
|
scan() {
|
|
|
if (this.judgeBalance('scan') == false) {
|
|
|
- return
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
- this.scan_qr()
|
|
|
+ this.scan_qr();
|
|
|
},
|
|
|
+
|
|
|
/**
|
|
|
* 启动摄像头,扫描二维码
|
|
|
*/
|
|
|
@@ -683,14 +746,14 @@
|
|
|
// scanType: "QR_CODE"
|
|
|
this.device_code = res.result.split('=')[1]
|
|
|
|
|
|
+ this.isScan = false;
|
|
|
+
|
|
|
if (this.device_code === '') {
|
|
|
uni.showToast({
|
|
|
icon: 'success',
|
|
|
title: '获取设备码失败',
|
|
|
duration: 3000
|
|
|
- })
|
|
|
-
|
|
|
- this.isScan = false
|
|
|
+ });
|
|
|
} else {
|
|
|
// 初始化蓝牙
|
|
|
this.openBluetoothAdapter()
|
|
|
@@ -719,13 +782,10 @@
|
|
|
// console.log(error)
|
|
|
uni.showModal({
|
|
|
content: '请开启手机蓝牙!',
|
|
|
- showCancel: false,
|
|
|
- success() {
|
|
|
- // _this.myOpenBluetoothAdapter();
|
|
|
- }
|
|
|
+ showCancel: false
|
|
|
});
|
|
|
|
|
|
- this.isScan = false
|
|
|
+ this.isScan = false;
|
|
|
}
|
|
|
});
|
|
|
},
|
|
|
@@ -735,10 +795,7 @@
|
|
|
if (err.errCode == 10001) {
|
|
|
uni.showModal({
|
|
|
content: '请授权手机蓝牙!',
|
|
|
- showCancel: false,
|
|
|
- success() {
|
|
|
- // _this.myOpenBluetoothAdapter();
|
|
|
- }
|
|
|
+ showCancel: false
|
|
|
});
|
|
|
} else {
|
|
|
uni.showToast({
|
|
|
@@ -750,38 +807,6 @@
|
|
|
}
|
|
|
});
|
|
|
},
|
|
|
- /**
|
|
|
- * 让用户去手动授权
|
|
|
- */
|
|
|
- myOpenBluetoothAdapter() {
|
|
|
- // 可以通过 wx.getSetting 先查询一下用户是否授权了 "scope.bluetooth" 这个 scope
|
|
|
- uni.getSetting({
|
|
|
- success(res) {
|
|
|
- // console.log(res.authSetting)
|
|
|
- //判断是否有'scope.bluetooth'属性
|
|
|
- if (res.authSetting.hasOwnProperty('scope.bluetooth')) {
|
|
|
- //'scope.bluetooth'属性存在,且为false
|
|
|
- if (!res.authSetting['scope.bluetooth']) {
|
|
|
- //弹窗授权
|
|
|
- uni.openSetting({
|
|
|
- success(res) {
|
|
|
- console.log(res.authSetting)
|
|
|
- }
|
|
|
- })
|
|
|
- }
|
|
|
- } else
|
|
|
- //'scope.bluetooth'属性不存在,需要授权
|
|
|
- uni.authorize({
|
|
|
- scope: 'scope.bluetooth',
|
|
|
- success() {
|
|
|
- // 用户已经同意小程序使用手机蓝牙功能,后续调用 蓝牙 接口不会弹窗询问
|
|
|
- console.log(res.authSetting)
|
|
|
- }
|
|
|
- })
|
|
|
-
|
|
|
- }
|
|
|
- });
|
|
|
- },
|
|
|
|
|
|
/**
|
|
|
* 333333333333333333333333333
|