xiaohaizhao 1 年間 前
コミット
d9976a266c
1 ファイル変更45 行追加2 行削除
  1. 45 2
      Bluetooth/index/index.vue

+ 45 - 2
Bluetooth/index/index.vue

@@ -14,7 +14,7 @@
       <u-loading-icon v-if="beSearching" size="21" />
       <view v-else class="anew" @click="startBluetooth"> 继续搜索 </view>
     </view>
-    <My_listbox ref="List" :empty="empty" :pullDown="false">
+    <My_listbox ref="List" :pullDown="false">
       <view class="device" v-for="item in devices" :key="item.deviceId">
         <view class="left">
           <text class="iconfont icon-shuifa" />
@@ -55,6 +55,23 @@
           <text v-else>连接</text>
         </view>
       </view>
+      <view v-if="empty" class="empty">
+        <u-empty />
+        <view class="title"> 如果长时间未搜索到设备 </view>
+        <view class="row"> 1.请检查设备是否开启蓝牙与地理位置 </view>
+        <view class="row">
+          2.授权小程序蓝牙和位置想信息授权
+          <text style="margin-left: 4px; font-weight: 700" @click="openSetting"
+            >去设置</text
+          >
+        </view>
+        <view class="row">
+          3.搜索全部蓝牙设备
+          <text style="margin-left: 4px; font-weight: 700" @click="setServices"
+            >设置</text
+          >
+        </view>
+      </view>
     </My_listbox>
   </view>
 </template>
@@ -73,7 +90,7 @@ export default {
     };
   },
   onLoad(options) {
-    this.services = JSON.parse(options.services);
+    if (options.services) this.services = JSON.parse(options.services);
     this.startBluetooth();
     this.$refs.List.setHeight();
   },
@@ -81,6 +98,16 @@ export default {
     this.stopBluetooth();
   },
   methods: {
+    setServices() {
+      this.services = [];
+      this.stopBluetooth();
+      setTimeout(() => {
+        this.startBluetooth();
+      });
+    },
+    openSetting() {
+      uni.openSetting();
+    },
     /* 开始搜索 */
     startBluetooth() {
       let that = this;
@@ -377,4 +404,20 @@ export default {
     margin-right: 20px;
   }
 }
+
+.empty {
+  text-align: center;
+  color: #fff;
+  padding-top: 30px;
+
+  .title {
+    font-weight: 700;
+    margin-top: 40px;
+  }
+
+  .row {
+    margin-top: 14px;
+    font-size: 12px;
+  }
+}
 </style>