Browse Source

修改前的提交

程志平 3 years ago
parent
commit
3c36641737
2 changed files with 58 additions and 22 deletions
  1. 1 8
      pages/index/index.vue
  2. 57 14
      pages/reshui/reshui.vue

+ 1 - 8
pages/index/index.vue

@@ -13,8 +13,7 @@
 					<image src="../../static/images/recharge2x.png" mode=""></image>
 					<image src="../../static/images/recharge2x.png" mode=""></image>
 					<text>水电充值</text>
 					<text>水电充值</text>
 				</navigator>
 				</navigator>
-				<!-- <navigator :url="'/pagesAir/shareAir/shareAir'" open-type="navigate" class="menu_item"> -->
-				<navigator url="" open-type="navigate" class="menu_item" @tap="deving">
+				<navigator :url="'/pagesAir/shareAir/shareAir'" open-type="navigate" class="menu_item">
 					<image src="../../static/images/air.png" mode=""></image>
 					<image src="../../static/images/air.png" mode=""></image>
 					<text>共享空调</text>
 					<text>共享空调</text>
 				</navigator>
 				</navigator>
@@ -70,12 +69,6 @@
 			}
 			}
 		},
 		},
 		methods: {
 		methods: {
-			deving() {
-				uni.showToast({
-					title: '正在开发中...',
-					duration: 2000
-				})
-			},
 			/**
 			/**
 			 * 控制环境,test为true测试环境,false则是正式环境
 			 * 控制环境,test为true测试环境,false则是正式环境
 			 */
 			 */

+ 57 - 14
pages/reshui/reshui.vue

@@ -26,8 +26,7 @@
 						<text class="iconfont icon-qian"></text>
 						<text class="iconfont icon-qian"></text>
 						<!-- <navigator url="/pagesWater/reshuiDetails/reshuiDetails" open-type="navigate"
 						<!-- <navigator url="/pagesWater/reshuiDetails/reshuiDetails" open-type="navigate"
 							class="start_mid_txt">¥{{amount}}</navigator> -->
 							class="start_mid_txt">¥{{amount}}</navigator> -->
-						<navigator url="" open-type="navigate"
-							class="start_mid_txt">¥{{amount}}</navigator>
+						<navigator url="" open-type="navigate" class="start_mid_txt">¥{{amount}}</navigator>
 					</view>
 					</view>
 					<view class="start_payamount" @tap="chongzhi_yemian()" hover-class="scan_hover">
 					<view class="start_payamount" @tap="chongzhi_yemian()" hover-class="scan_hover">
 						<text>点击充值</text>
 						<text>点击充值</text>
@@ -691,6 +690,7 @@
 			 * 初始化蓝牙
 			 * 初始化蓝牙
 			 */
 			 */
 			openBluetoothAdapter() {
 			openBluetoothAdapter() {
+				let _this = this;
 				uni.openBluetoothAdapter({
 				uni.openBluetoothAdapter({
 					success: (res) => { // 已打开
 					success: (res) => { // 已打开
 						uni.getBluetoothAdapterState({ // 蓝牙的匹配状态
 						uni.getBluetoothAdapterState({ // 蓝牙的匹配状态
@@ -703,11 +703,13 @@
 							},
 							},
 							fail: (error) => {
 							fail: (error) => {
 								// console.log(error)
 								// console.log(error)
-								uni.showToast({
-									title: "请开启手机蓝牙",
-									icon: "none",
-									duration: 3000
-								})
+								uni.showModal({
+									content: '请开启手机蓝牙!',
+									showCancel: false,
+									success() {
+										// _this.myOpenBluetoothAdapter();
+									}
+								});
 
 
 								this.isScan = false
 								this.isScan = false
 							}
 							}
@@ -715,12 +717,15 @@
 					},
 					},
 					fail: (err) => { // 未打开
 					fail: (err) => { // 未打开
 						// console.log(err)
 						// console.log(err)
-						this.isScan = false
+						this.isScan = false;
 						if (err.errCode == 10001) {
 						if (err.errCode == 10001) {
 							uni.showModal({
 							uni.showModal({
-								content: '请开启手机蓝牙!',
-								showCancel: false
-							})
+								content: '请授权手机蓝牙!',
+								showCancel: false,
+								success() {
+									// _this.myOpenBluetoothAdapter();
+								}
+							});
 						} else {
 						} else {
 							uni.showToast({
 							uni.showToast({
 								icon: 'none',
 								icon: 'none',
@@ -731,6 +736,38 @@
 					}
 					}
 				});
 				});
 			},
 			},
+			/**
+			 * 让用户去手动授权
+			 */
+			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
 			 * 333333333333333333333333333
@@ -858,7 +895,7 @@
 								this.stopBluetoothDevicesDiscovery()
 								this.stopBluetoothDevicesDiscovery()
 							}, 2000)
 							}, 2000)
 						} catch (e) {
 						} catch (e) {
-							console.log('发现外围设备:' + e.message);
+							// console.log('发现外围设备:' + e.message);
 						}
 						}
 					})
 					})
 				});
 				});
@@ -1045,9 +1082,15 @@
 
 
 						uni.showToast({
 						uni.showToast({
 							icon: 'none',
 							icon: 'none',
-							title: '要启动,请点【开启设备】开关',
-							duration: 3000
+							title: '要启动水表,请手动【开启设备】右侧开关',
+							duration: 5000
 						})
 						})
+						// uni.showModal({
+						// 	title: '提示',
+						// 	content: '要启动水表,请手动点击【开启设备】右侧开关!',
+						// 	showCancel: false,
+						// 	confirmText: '好,知道'
+						// })
 
 
 						this.isScan = false
 						this.isScan = false
 						// console.log('通知启用(notifyBLECharacteristicValueChange)',res);
 						// console.log('通知启用(notifyBLECharacteristicValueChange)',res);