tremble 3 년 전
부모
커밋
1fed3fb837

+ 31 - 2
app.js

@@ -1,19 +1,48 @@
 // app.js
+var events = require('./utils/event')
+
 App({
+  events,
   onLaunch() {
     // 展示本地存储能力
     const logs = wx.getStorageSync('logs') || []
     logs.unshift(Date.now())
     wx.setStorageSync('logs', logs)
-
+    this.globalData.userInfo =  wx.getSystemInfoSync()
     // 登录
     wx.login({
       success: res => {
         // 发送 res.code 到后台换取 openId, sessionKey, unionId
       }
     })
+
+    wx.getNetworkType({
+      success: (res)=> {
+        let networkType = res.networkType
+        if (networkType=='unknown'||networkType=='none') {
+          wx.showLoading({
+            title: '请连接网络',
+            mask: true
+          });
+        }
+      }
+    })
+
+    wx.onNetworkStatusChange( (res)=> {
+      this.events.emit('network',res.isConnected)
+      if (res.isConnected) {
+          wx.hideLoading({fail(){}});
+      }else{
+        wx.showLoading({
+          title: '请连接网络',
+          mask: true
+        });
+      }
+    })
   },
   globalData: {
-    userInfo: null
+    userInfo: null,
+    AllExample:[],
+    isConnected: true
   }
 })

+ 5 - 0
app.json

@@ -9,5 +9,10 @@
     "navigationBarTextStyle": "black"
   },
   "style": "v2",
+  "permission":{
+    "scope.userLocation":{
+      "desc":"您的位置信息将用于定位效果展示"
+    }
+  },
   "sitemapLocation": "sitemap.json"
 }

+ 26 - 22
components/audio-play/audio-play.js

@@ -1,6 +1,9 @@
 // components/audio-play.js
 import { CDN_URL,API_BASE_URL,G_AUDIO } from '../../config/index';
-var AllExample = [];
+
+let app =  getApp();
+
+
 Component({
   /**
    * 组件的属性列表
@@ -16,11 +19,11 @@ Component({
    */
   data: {
     cdn_url:CDN_URL,
-    durationTime: '00:00',
-    currentTime: '00:00',
+    currentTime: '',
     isPlay: false,
     audioExample: null,
     G_AUDIO,
+    timer:null,
     progress: 0,
     allAudio: [],
     api_base_url:API_BASE_URL,
@@ -35,16 +38,17 @@ Component({
     toggleMusic() {
       // 全部暂停
       if (!this.data.isPlay) {
-        AllExample.forEach(simpleAudio => {
-          simpleAudio.pause();
-        })
-  
         this.data.audioExample.autoplay = true;
-        this.data.audioExample.src = G_AUDIO[this.properties.audio] && G_AUDIO[this.properties.audio].audio;
+        this.data.audioExample.src = G_AUDIO[this.properties.audio] && (G_AUDIO[this.properties.audio].audio +`?${Math.random()}`);
         this.data.audioExample.play();
         this.setData({
           isPlay: true
         })
+        app.globalData.AllExample.forEach((simpleAudio) => {
+          if (simpleAudio.src && simpleAudio.src!=this.data.audioExample.src) {
+            simpleAudio.src && simpleAudio.pause();
+          }
+        })
         this.loadProgress()
       }
       else{
@@ -57,29 +61,25 @@ Component({
     },
     // 播放中
     loadProgress() {
-      this.data.audioExample.onCanplay((e) => {
-        this.data.audioExample.duration; //必须写,不然获取不到。。。
-        var timer = setInterval(() => {
+      this.data.audioExample.onCanplay(() => {
+        this.data.timer = setInterval(() => {
           // 只要音频暂停了,定时器(假的)不执行
           if (this.data.audioExample.paused) return;
           var currentime = this.data.audioExample.currentTime;
-          var duration = this.data.audioExample.duration;
           var currTimeStr = this.formatTime(currentime);
-          var duraTimeStr = this.formatTime(duration);
           var progress = parseInt((this.data.audioExample.currentTime / this.data.audioExample.duration) * 100)
+          console.log(this.data.audioExample.currentTime, this.data.audioExample.duration,'111111');
           if (progress === 100 || isNaN(this.data.progress)) {
-            clearInterval(timer)
-            console.log('停止了')
+            clearInterval(this.data.timer)
             this.setData({
               isPlay: false,
               progress: 0,
-              currentTime: "00:00",
+              currentTime: "",
             })
           } else {
             this.setData({
               progress,
-              currentTime: currTimeStr,
-              durationTime: duraTimeStr
+              currentTime: currTimeStr
             })
           }
         }, 1000);
@@ -97,9 +97,13 @@ Component({
   },
   attached: function () {
     //组件显示初始化函数
-    this.data.audioExample = wx.createInnerAudioContext();
+    let tt = wx.createInnerAudioContext()
+    tt.src = 'none'
+    this.setData({
+      audioExample: tt
+    })
     //所有组件实例都放在一个容器AllExample里
-    AllExample.push(this.data.audioExample);
+    app.globalData.AllExample.push(this.data.audioExample);
     this.data.audioExample.onPlay(function () {
       console.log('播放中。。。')
     })
@@ -115,10 +119,11 @@ Component({
     // 每个组件实例播放结束
     this.data.audioExample.onEnded(() => {
       this.setData({
-        currentTime: "00:00",
+        currentTime: "",
         isPlay: false,
         progress: 0,
       })
+      clearInterval(this.data.timer)
     })
     // 在组件实例进入页面节点树时执行
   },
@@ -126,6 +131,5 @@ Component({
     // 在组件实例被从页面节点树移除时执行
     // 卸载
     this.data.audioExample.destroy();
-    AllExample = [];
   }
 })

+ 11 - 11
components/audio-play/audio-play.wxml

@@ -1,20 +1,20 @@
 <!--components/audio-play.wxml-->
 <view>
   <view class="audio">
-    <image class="bg-img" mode="aspectFill" src="{{cdn_url}}/project/audio_guide/audio_thumb.jpg"></image>
+    <image class="bg-img" mode="aspectFill" src="{{cdn_url}}/project/audio_guide/thumb_ad/{{G_AUDIO[audio].img}}"></image>
 
-    <image class="icon-img"
-    bindtap="toggleMusic"
-    src="{{cdn_url}}/project/audio_guide/{{isPlay?'start':'pause'}}.png">
-    </image>
+      <image class="icon-img"
+      bindtap="toggleMusic"
+      src="{{cdn_url}}/project/audio_guide/{{isPlay?'start':'pause'}}.png">
+      </image>
 
-    <view class="free-MusicProgress">
-      <view class="before-progress">
-        <view class="progress" style="width:{{progress}}%;"></view>
+      <view class="free-MusicProgress">
+        <view class="before-progress">
+          <view class="progress" style="width:{{progress}}%;"></view>
+        </view>
+        <view class="durationTime">{{currentTime || G_AUDIO[audio].time}}</view>
       </view>
-      <view class="durationTime">{{currentTime}}</view>
-    </view>
-</view>  
+  </view>
   <view class="title">{{G_AUDIO[audio].name}}</view>
 
 </view>

+ 8 - 1
components/big-pic/big-pic.js

@@ -1,5 +1,6 @@
 import { CDN_URL,API_BASE_URL,DISTRIBUTION } from '../../config/index';
 import http from '../../utils/http';
+let app =  getApp();
 
 
 Component({
@@ -61,6 +62,10 @@ Component({
       let {tag,index} = e.mark;
       let data = this.data.audioList
 
+      if (!tag) {
+        return
+      }
+
       if (data[index]['tag'] == tag) {
         tag = ''
       }
@@ -75,5 +80,7 @@ Component({
     //获取语音
     // this.getAudiosList();
   },
-  detached: function () {}
+  detached: function () {
+    app.globalData.AllExample = [];
+  }
 })

+ 4 - 4
components/big-pic/big-pic.wxml

@@ -1,12 +1,12 @@
 <view class="content">
-  <view class="column {{item.tag==item.id?'hide_col':''}}" wx:for='{{audioList}}' wx:key="index">
+  <view class="column {{item.tag==item.id?'hide_col':''}}" wx:for='{{audioList}}' bindtap="tapTitle" wx:key="index">
     <view class="title" mark:tag="{{item.id}}" mark:index="{{index}}">
-      <text class="txt" bindtap="tapTitle">{{item.title}}</text>
-      <image class="title-img" bindtap="tapTitle" mode="aspectFit" src="{{cdn_url}}/project/icon-bottom.png"></image>
+      <text class="txt" >{{item.title}}</text>
+      <image class="title-img {{item.tag==item.id?'imgactive':''}}" mode="aspectFit" src="{{cdn_url}}/project/icon-bottom.png"></image>
     </view>
     <view class="con-list">
       <view class="citem" wx:for='{{item.position}}' wx:for-item="sub" wx:key="index">
-        <audio-play audio="{{sub}}"></audio-play>
+        <audio-play audio="{{sub}}" ></audio-play>
       </view>
     </view>
   </view>

+ 4 - 0
components/big-pic/big-pic.wxss

@@ -37,6 +37,10 @@
   height: 24rpx;
   margin-left: 16rpx;
 }
+.content .column .title .imgactive {
+  transform: rotate(180deg) translate(6rpx,-6rpx);
+}
+
 
 .content .column .con-list {
   margin: 0 4%;

+ 30 - 20
components/list-audio/list-audio.js

@@ -1,6 +1,8 @@
 // components/audio-play.js
 import { CDN_URL,API_BASE_URL,G_AUDIO } from '../../config/index';
-var AllExample = [];
+let app =  getApp();
+
+
 Component({
   /**
    * 组件的属性列表
@@ -16,13 +18,13 @@ Component({
    */
   data: {
     cdn_url:CDN_URL,
-    durationTime: '00:00',
     currentTime: '00:00',
     isPlay: false,
     audioExample: null,
     progress: 0,
     allAudio: [],
     G_AUDIO,
+    timer:null,
     api_base_url:API_BASE_URL,
     targetUrl:API_BASE_URL+'/data/'
   },
@@ -35,13 +37,16 @@ Component({
     toggleMusic() {
       // 全部暂停
       if (!this.data.isPlay) {
-        AllExample.forEach(simpleAudio => {
-          simpleAudio.pause();
-        })
-  
+        
         this.data.audioExample.autoplay = true;
         this.data.audioExample.src = G_AUDIO[this.properties.audio].audio;
         this.data.audioExample.play();
+
+        app.globalData.AllExample.forEach((simpleAudio) => {
+          if (simpleAudio.src && simpleAudio.src!=this.data.audioExample.src) {
+            simpleAudio.src && simpleAudio.pause();
+          }
+        })
         this.setData({
           isPlay: true
         })
@@ -49,7 +54,6 @@ Component({
       }
       else{
         this.data.audioExample.pause();
-        console.log('结束音乐')
         this.setData({
           isPlay: false
         })
@@ -57,18 +61,15 @@ Component({
     },
     // 播放中
     loadProgress() {
-      this.data.audioExample.onCanplay((e) => {
-        this.data.audioExample.duration; //必须写,不然获取不到。。。
-        var timer = setInterval(() => {
+      this.data.audioExample.onCanplay(() => {
+        this.data.timer = setInterval(() => {
           // 只要音频暂停了,定时器(假的)不执行
           if (this.data.audioExample.paused) return;
           var currentime = this.data.audioExample.currentTime;
-          var duration = this.data.audioExample.duration;
           var currTimeStr = this.formatTime(currentime);
-          var duraTimeStr = this.formatTime(duration);
           var progress = parseInt((this.data.audioExample.currentTime / this.data.audioExample.duration) * 100)
           if (progress === 100 || isNaN(this.data.progress)) {
-            clearInterval(timer)
+            clearInterval(this.data.timer)
             console.log('停止了')
             this.setData({
               isPlay: false,
@@ -78,8 +79,7 @@ Component({
           } else {
             this.setData({
               progress,
-              currentTime: currTimeStr,
-              durationTime: duraTimeStr
+              currentTime: currTimeStr
             })
           }
         }, 1000);
@@ -96,10 +96,14 @@ Component({
     }
   },
   attached: function () {
-    //组件显示初始化函数
-    this.data.audioExample = wx.createInnerAudioContext();
+    let tt = wx.createInnerAudioContext()
+    tt.src = 'none'
+    this.setData({
+      audioExample: tt
+    })
+    // this.data.audioExample = wx.createInnerAudioContext();
     //所有组件实例都放在一个容器AllExample里
-    AllExample.push(this.data.audioExample);
+    app.globalData.AllExample.push(this.data.audioExample);
     this.data.audioExample.onPlay(function () {
       console.log('播放中。。。')
     })
@@ -107,7 +111,8 @@ Component({
       console.log('监听进度。。')
     })
     //控制单个实例的isPlay
-    this.data.audioExample.onPause( ()=> {
+    this.data.audioExample.onPause(()=> {
+      console.log('onPause。。。')
       this.setData({
         isPlay: false
       })
@@ -119,6 +124,7 @@ Component({
         isPlay: false,
         progress: 0,
       })
+      clearInterval(this.data.timer)
     })
     // 在组件实例进入页面节点树时执行
   },
@@ -126,6 +132,10 @@ Component({
     // 在组件实例被从页面节点树移除时执行
     // 卸载
     this.data.audioExample.destroy();
-    AllExample = [];
+    this.setData({
+      currentTime: "00:00",
+      isPlay: false,
+      progress: 0,
+    })
   }
 })

+ 1 - 1
components/list-audio/list-audio.wxml

@@ -9,6 +9,6 @@
     <view class="free-MusicProgress">
         <view class="progress" style="width:{{progress}}%;"></view>
     </view>
-    <view class="durationTime">{{currentTime}}</view>
+    <view class="durationTime">{{currentTime}} / {{G_AUDIO[audio].time}}</view>
   </view>
 </view>

+ 1 - 1
components/list-audio/list-audio.wxss

@@ -23,7 +23,7 @@
 }
 
 .audio .free-MusicProgress {
-  width:72%;
+  width:62%;
   height:8rpx;
   background: rgba(112, 112, 112, 0.5);
   border-radius: 6rpx;

+ 7 - 1
components/list/list.js

@@ -1,6 +1,7 @@
 import { CDN_URL,API_BASE_URL,DISTRIBUTION } from '../../config/index';
 import http from '../../utils/http';
 
+let app =  getApp();
 
 Component({
   /**
@@ -60,6 +61,9 @@ Component({
     tapTitle(e){
       let {tag,index} = e.mark;
       let data = this.data.audioList
+      if (!tag) {
+        return
+      }
 
       if (data[index]['tag'] == tag) {
         tag = ''
@@ -75,5 +79,7 @@ Component({
     //获取语音
     // this.getAudiosList();
   },
-  detached: function () {}
+  detached: function () {
+    app.globalData.AllExample = [];
+  }
 })

+ 4 - 4
components/list/list.wxml

@@ -1,12 +1,12 @@
 <!--components/list/list.wxml-->
 <view class="content">
-  <view class="column {{item.tag==item.id?'hide_col':''}}" wx:for='{{audioList}}' wx:key="index">
+  <view class="column {{item.tag==item.id?'hide_col':''}}" wx:for='{{audioList}}' bindtap="tapTitle" wx:key="index">
     <view class="title" mark:tag="{{item.id}}" mark:index="{{index}}">
-      <text class="txt" bindtap="tapTitle">{{item.title}}</text>
-      <image class="title-img" bindtap="tapTitle" mode="aspectFit" src="{{cdn_url}}/project/icon-bottom.png"></image>
+      <text class="txt" >{{item.title}}</text>
+      <image class="title-img {{item.tag==item.id?'imgactive':''}}" mode="aspectFit" src="{{cdn_url}}/project/icon-bottom.png"></image>
     </view>
     <view class="con-list">
-      <view class="citem" wx:for='{{item.position}}' wx:for-item="sub" wx:key="index">
+      <view class="citem" wx:for='{{item.position}}' wx:for-item="sub" wx:key="*this">
         <list-audio audio="{{sub}}"></list-audio>
       </view>
     </view>

+ 4 - 0
components/list/list.wxss

@@ -38,6 +38,10 @@
   margin-left: 16rpx;
 }
 
+.content .column .title .imgactive {
+  transform: rotate(180deg) translate(6rpx,-6rpx);
+}
+
 .content .column .con-list {
   margin: 0 4%;
   border-top: 1px solid rgba(112, 112, 112, 0.25);

+ 173 - 155
components/map-sense/map-sense.js

@@ -1,15 +1,16 @@
 // components/map-sense.js
 
 let innerAudioContext = wx.createInnerAudioContext({
-  useWebAudioImplement: true
+  useWebAudioImplement: true,
 });
-import http from "../../utils/http";
 import { promisify, BeaconUtils } from "../../utils/util";
+
+
 let openBluetoothAdapter = promisify(wx.openBluetoothAdapter);
-let closeBluetoothAdapter = promisify(wx.closeBluetoothAdapter);
 let startBeaconDiscovery = promisify(wx.startBeaconDiscovery);
 let stopBeaconDiscovery = promisify(wx.stopBeaconDiscovery);
 
+let app = getApp();
 
 import {
   CDN_URL,
@@ -17,6 +18,7 @@ import {
   STATUS_TEXT,
   API_BASE_URL,
   DISTRIBUTION,
+  AudioAddress,
 } from "../../config/index";
 
 const STATUS_PIC = {
@@ -26,12 +28,19 @@ const STATUS_PIC = {
   3: "fail",
 };
 
-let audioInterruptionCb = ()=>{}
-let bluetoothAdapterStateChangeCb = ()=>{}
+let audioInterruptionCb = () => {};
+let bluetoothAdapterStateChangeCb = () => {};
+
+let isCollect = false;
+let hadshowModal = false
+
+let checkCollect = null
+let checkTimeout = null
+let updateingBeacon = false
 
-let isCollect = false
+let updateTO = null
 
-let changeTO = null
+let changeTO = null;
 
 // 选择6档
 const TXPOWER = -55;
@@ -44,15 +53,13 @@ const R = 3.4; //设定感应范围半径
 
 const RSSIVAL = 70; //rssi信号过滤临界点
 
-
 let AveLength = 10;
 
 let group = [
   ["10001", "10002"],
   ["10003"],
   ["10004"],
-  ["10005"],
-  ["10006"],
+  ["10005", "10006"],
   ["10007"],
   ["10008"],
   ["10009"],
@@ -80,30 +87,6 @@ let group = [
 // 18:['10020','10021'],19:['10022'],
 // 20:['10023'],21:['10024']
 
-let AudioAddress = {
-  0: "https://culture.4dage.com/demo/audio/1.2.mp3",
-  1: "https://culture.4dage.com/demo/audio/3.mp3",
-  2: "https://culture.4dage.com/demo/audio/4.mp3",
-  3: "https://culture.4dage.com/demo/audio/5.mp3",
-  4: "https://culture.4dage.com/demo/audio/6.mp3",
-  5: "https://culture.4dage.com/demo/audio/7.mp3",
-  6: "https://culture.4dage.com/demo/audio/8.mp3",
-  7: "https://culture.4dage.com/demo/audio/9.mp3",
-  8: "https://culture.4dage.com/demo/audio/10.mp3",
-  9: "https://culture.4dage.com/demo/audio/11.mp3",
-  10: "https://culture.4dage.com/demo/audio/12.13.mp3",
-  11: "https://culture.4dage.com/demo/audio/14.mp3",
-  12: "https://culture.4dage.com/demo/audio/15.mp3",
-  13: "https://culture.4dage.com/demo/audio/16.mp3",
-  14: "https://culture.4dage.com/demo/audio/17.mp3",
-  15: "https://culture.4dage.com/demo/audio/18.mp3",
-  16: "https://culture.4dage.com/demo/audio/19.mp3",
-  17: "https://culture.4dage.com/demo/audio/20.21.mp3",
-  18: "https://culture.4dage.com/demo/audio/22.mp3",
-  19: "https://culture.4dage.com/demo/audio/23.mp3",
-  20: "https://culture.4dage.com/demo/audio/24.mp3",
-};
-
 Component({
   /**
    * 组件的属性列表
@@ -115,6 +98,7 @@ Component({
    */
   data: {
     status: "0",
+    isAndroid:app.globalData.userInfo.system.toLowerCase().indexOf("android")>-1,
     cdn_url: CDN_URL,
     connect_status: CONNECT_STATUS,
     status_text: STATUS_TEXT,
@@ -140,11 +124,29 @@ Component({
 
       openBluetoothAdapter().then(
         (res) => {
-          wx.hideLoading({fail(){}});
+          wx.hideLoading({ fail() {} });
           cb(res);
+          // if (app.globalData.userInfo.system.toLowerCase().indexOf("android")>-1) {
+          //   wx.getLocation({
+          //     type: "gcj02", //返回可以用于wx.openLocation的经纬度
+          //     success: () => {
+          //       cb(res);
+          //     },
+          //     fail: (err) => {
+          //       console.log(err);
+          //       wx.showToast({
+          //         title: "请打开手机定位服务",
+          //         icon: "error",
+          //         duration: 500,
+          //       });
+          //     },
+          //   });
+          // } else {
+          //   cb(res);
+          // }
         },
         () => {
-          wx.hideLoading({fail(){}});
+          wx.hideLoading({ fail() {} });
           wx.showToast({
             title: "请打开蓝牙",
             icon: "error",
@@ -169,25 +171,63 @@ Component({
           uuids: ["FDA50693-A4E2-4FB1-AFCF-C6EB07647825"],
         })
           .then(() => {
-            wx.hideLoading({fail(){}});
+            wx.hideLoading({ fail() {} });
             this.setData({
               status: "2",
             });
-            isCollect = true
+            isCollect = true;
+            updateingBeacon = false
+
+            if (this.data.isAndroid) {
+              checkCollect && clearInterval(checkCollect)
+              checkTimeout && clearTimeout(checkTimeout)
+              checkTimeout = setTimeout(() => {
+              checkCollect = setInterval(() => {
+                  if (!updateingBeacon) {
+                    if (!hadshowModal) {
+                      hadshowModal = true
+                      wx.showModal({
+                        title: "定位功能已停止,请检查手机定位服务和蓝牙是否保持打开状态",
+                        showCancel: false,
+                        success:()=>{
+                          this.resetPage()
+                          checkCollect && clearInterval(checkCollect)
+                          checkTimeout && clearTimeout(checkTimeout)
+                          hadshowModal = false
+                        }
+                      });
+                    }
+                  }
+                }, 1000)
+              }, 2000);
+            }
+
             wx.onBeaconUpdate((data) => {
+              console.log(data, "onBeaconUpdate");
               if (!isCollect) {
-                return
+                return;
               }
-              console.log('还在收集…………');
+              if (this.data.isAndroid) {
+                updateTO && clearTimeout(updateTO)
+
+                updateTO = setTimeout(() => {
+                  console.log('重置updateingBeacon');
+                  updateingBeacon = false
+                }, 3000);
+
+                updateingBeacon = true
+              }
+
+              console.log("还在收集…………");
               // 需要收集十组数据,索引号最大的组是最旧的
               if (!aveArr.includes(data.beacons)) {
                 if (aveArr.length >= AveLength) {
                   //当超过十组时,应该将索引号大的组淘汰掉
-                  aveArr.pop()
+                  aveArr.pop();
                 }
                 aveArr.unshift(BeaconUtils.clone(data.beacons)); //在队列前面插入
               }
-              
+
               let all = []; //获取所有data.beacons数据
               for (let i = 0; i < aveArr.length; i++) {
                 let ele = aveArr[i];
@@ -198,7 +238,7 @@ Component({
                     if (Math.abs(item.rssi) < RSSIVAL) {
                       // console.log(item.proximity,item.rssi);
                       if (!all.includes(item)) {
-                        all.push(BeaconUtils.clone(item))
+                        all.push(BeaconUtils.clone(item));
                       }
                     }
                   }
@@ -235,7 +275,6 @@ Component({
                   );
                 }
 
-
                 //计算高斯模糊后的rssi值
                 let rssiArr = []; //模糊后的rssi数组
                 for (let i = 0; i < arr.length; ++i) {
@@ -250,8 +289,6 @@ Component({
                   rssiArr.push(sum);
                 }
 
-
-
                 //时间加权后求rssi平均值
                 let aveOnTime = BeaconUtils.arrayAverage(
                   rssiArr
@@ -259,34 +296,24 @@ Component({
                     .concat(rssiArr)
                 );
 
-
-
                 //测距,根据时间加权后的rssi计算距离
                 // classfiy[key].forEach((item) => {
-                  let tmp = BeaconUtils.calculateAccuracy(
-                    TXPOWER,
-                    aveOnTime,
-                    N
-                  );
+                let tmp = BeaconUtils.calculateAccuracy(TXPOWER, aveOnTime, N);
 
-              
-                  if (!accuracyList[key]) {
-                    //如果还没有对应的“信标号”
-                    accuracyList[key] = [tmp];
-                  }else{
-                    accuracyList[key].push(tmp);
-                  }
+                if (!accuracyList[key]) {
+                  //如果还没有对应的“信标号”
+                  accuracyList[key] = [tmp];
+                } else {
+                  accuracyList[key].push(tmp);
+                }
                 // });
-
-
               });
 
+              Object.keys(accuracyList).forEach((item) => {
+                console.log(accuracyList[item] + "---------" + item);
+              });
 
-              // Object.keys(accuracyList).forEach(item=>{
-              //   console.log(accuracyList[item]+'---------'+item);
-              // })
-              
-              // console.log('--------分隔--------');
+              console.log("--------分隔--------");
 
               // 筛选器,筛选出配对的一组信标
               let signSelect = new Array(21).fill(0); //记录各组的信标出现数量,投票选择最多的,依次是prologue,annexHall,mainHall
@@ -294,39 +321,37 @@ Component({
               // const annexHall = ['10003','10004','10005','10006','10007']                    //附厅
               // const mainHall = ['10008']                     //主厅
 
-        
-
               Object.keys(accuracyList).forEach((key) => {
                 let aveAccuracy = BeaconUtils.arrayAverage(accuracyList[key]);
 
                 if (aveAccuracy < R) {
                   for (let i = 0; i < group.length; i++) {
                     if (group[i].includes(key)) {
-                      signSelect[i] += 1/(aveAccuracy+0.01); //取距离的反比例函数值,距离越近,值越大,+0.01是为了防止除数为0
+                      signSelect[i] += 1 / (aveAccuracy + 0.01); //取距离的反比例函数值,距离越近,值越大,+0.01是为了防止除数为0
                     }
                   }
                 }
               });
-              // console.log(signSelect);
+              console.log(signSelect);
               //对小于预设半径的信号进行数量投票
               result = BeaconUtils.maxIndex(signSelect);
 
-              // console.log("result", result);
+              console.log("result", result);
               if (result != null && result !== oldResult) {
-                wx.hideLoading({fail(){}})
-                this.playAudio(AudioAddress[result])
+                wx.hideLoading({ fail() {} });
+                this.playAudio(AudioAddress[result]);
                 oldResult = result;
               }
-              if (result === null && oldResult!=-1) {
+              if (result === null && oldResult != -1) {
                 wx.showLoading({
                   title: "音频切换中…",
                   mask: true,
                 });
-                changeTO && clearTimeout(changeTO)
+                changeTO && clearTimeout(changeTO);
                 changeTO = setTimeout(() => {
-                  wx.hideLoading({fail(){}})
+                  wx.hideLoading({ fail() {} });
                 }, 4000);
-                this.stopAndDestroyAudio()
+                this.stopAndDestroyAudio();
               }
 
               let temp = DISTRIBUTION.find((item) => {
@@ -336,72 +361,81 @@ Component({
               this.setData({
                 classfiy,
                 targetObj: temp || {},
-                result
+                result,
               });
             });
           })
-          .catch(() => {
-            wx.showToast({
-              title: "连接失败",
-              icon: "error",
-              duration: 500,
-            });
+          .catch((err) => {
+            console.log(err,'1111');
+            if (err.errCode == 11002) {
+              wx.showToast({
+                title: "请打开手机定位服务",
+                icon: "error",
+                duration: 500,
+              });
+            } else {
+              wx.showToast({
+                title: "连接失败",
+                icon: "error",
+                duration: 500,
+              });
+            }
           });
       });
     },
 
     stopAndDestroyAudio() {
-      console.log(innerAudioContext,'innerAudioContext');
+      oldResult = -1;
       if (!innerAudioContext) {
-        return
+        return;
       }
-     
-      innerAudioContext.pause()
+
+      innerAudioContext.pause();
       innerAudioContext.stop();
-      innerAudioContext.src = null
+      innerAudioContext.src = null;
       innerAudioContext.destroy();
-      innerAudioContext = null
-      oldResult = -1
+      innerAudioContext = null;
     },
 
-
     playAudio(src) {
       if (!innerAudioContext) {
         innerAudioContext = wx.createInnerAudioContext({
-          useWebAudioImplement: true
-        })
+          useWebAudioImplement: true,
+        });
       }
 
-
       innerAudioContext.src = src;
       innerAudioContext.loop = true;
-      innerAudioContext.onCanplay(()=>{
+      innerAudioContext.onCanplay(() => {
         innerAudioContext.play();
-      })
+      });
       // innerAudioContext.play();
     },
 
-    stopBeaconDiscovery(notips=null) {
+    stopBeaconDiscovery(notips = null) {
       console.log("这是取消连接");
       // 取消连接 停止播放音乐 目标对象置为{} 设置为第一次进入
-      
+      checkCollect && clearInterval(checkCollect)
+      checkTimeout && clearTimeout(checkTimeout)
+      updateTO && clearTimeout(updateTO)
       this.stopAndDestroyAudio();
       this.reset();
-      isCollect = false
-      stopBeaconDiscovery().then(() => {
-        !notips && wx.showToast({
-          title: "取消连接成功",
-          icon: "error",
-          duration: 1000,
+      isCollect = false;
+      stopBeaconDiscovery()
+        .then(() => {
+          !notips &&
+            wx.showToast({
+              title: "取消连接成功",
+              icon: "error",
+              duration: 1000,
+            });
+        })
+        .catch((err) => {
+          console.log(err);
         });
-        
-      })
-      .catch((err) => {
-        console.log(err);
-      });
     },
 
-    reset(){
+    reset() {
       this.setData({
         status: "0",
         targetObj: {},
@@ -414,11 +448,11 @@ Component({
         isScanPlay: true,
       });
       wx.scanCode({
-        success: res=> {
-          this.stopBeaconDiscovery(true)
-          this.playAudio(res["result"])
+        success: (res) => {
+          this.stopBeaconDiscovery(true);
+          this.playAudio(res["result"]);
         },
-        fail:  ()=> {
+        fail: () => {
           console.log("fail innerAudioContext", innerAudioContext);
           this.setData({
             isScanPlay: false,
@@ -433,57 +467,41 @@ Component({
       });
     },
 
-    resetPage(){
+    resetPage() {
       this.stopBeaconDiscovery(true);
     },
 
-    getAudios() {
-      http.get("/api/web/getAudioIndex").then((res) => {
-        let { data } = res,
-          target = {};
-        data.forEach((item) => {
-          switch (item.type) {
-            case 1:
-              target["10001"] = `${this.data.api_base_url}/data/${item.audio}`;
-              break;
-            case 2:
-              target["10002"] = `${this.data.api_base_url}/data/${item.audio}`;
-              break;
-            case 3:
-              target["10003"] = `${this.data.api_base_url}/data/${item.audio}`;
-              break;
-            default:
-              break;
-          }
-        });
-        this.setData({
-          audio_address: target,
-        });
-      });
-    },
   },
   lifetimes: {
     attached: function () {
-      audioInterruptionCb = ()=>{
+      audioInterruptionCb = () => {
         console.log(innerAudioContext);
         if (innerAudioContext) {
-          this.resetPage()
+          this.resetPage();
         }
-      }
-      bluetoothAdapterStateChangeCb=(res)=>{
+      };
+      bluetoothAdapterStateChangeCb = (res) => {
         if (!Boolean(res.available)) {
-            this.resetPage()
+          this.resetPage();
         }
-      }
-      wx.onAudioInterruptionEnd(audioInterruptionCb)
-      wx.onBluetoothAdapterStateChange(bluetoothAdapterStateChangeCb)
-      wx.onAppShow(audioInterruptionCb)
+      };
+
+      wx.onAudioInterruptionEnd(audioInterruptionCb);
+      wx.onBluetoothAdapterStateChange(bluetoothAdapterStateChangeCb);
+      wx.onAppShow(audioInterruptionCb);
+      app.events.on('network', this, (data) =>{
+        if (!data) {
+          this.resetPage();
+        }
+      })
     },
     detached: function () {
-      this.resetPage()
-      wx.offAudioInterruptionEnd(audioInterruptionCb)
-      wx.offBluetoothAdapterStateChange(bluetoothAdapterStateChangeCb)
-      wx.offAppShow(audioInterruptionCb)
-    }
+      this.resetPage();
+      wx.offAudioInterruptionEnd(audioInterruptionCb);
+      wx.offBluetoothAdapterStateChange(bluetoothAdapterStateChangeCb);
+      wx.offAppShow(audioInterruptionCb);
+      app.events.remove('network',this)
+
+    },
   },
 });

+ 1 - 1
components/map-sense/map-sense.wxml

@@ -40,7 +40,7 @@
   </view>
   <view class="text">
     蓝牙成功连接后,走到相应区域则会播放不同的音频
-    注:请确保蓝牙保持打开状态。
+    注:请确保手机定位服务和蓝牙保持打开状态。
   </view>
   <view style="text-align:center;">
     <view class="bottom">

+ 91 - 41
config/index.js

@@ -18,103 +18,153 @@ export const DISTRIBUTION = [
   {
     id:'xuting',
     title:'序厅',
-    position:[0,19]
+    position:[0]
   },
   {
     id:'zhuting',
     title:'主厅',
-    position:[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,20]
+    position:[1,2,3,4,5,19,6,7,8,9,10,11,12,13,14,15]
   },
   {
     id:'futing',
     title:'附厅',
-    position:[17,18]
+    position:[16,17,18]
   }
 ]
 
-export const G_AUDIO={
+
+ let g_ad={
   0:{
     name:'序厅',
-    audio:'https://culture.4dage.com/demo/audio/1.2.mp3'
+    time:'0:34',
+    audio:'https://culture.4dage.com/demo/audio/1.2.mp3',
+    img:'1.2.jpg'
   },
   1:{
     name:'第一部分 胜利回归,奉命组建',
-    audio:'https://culture.4dage.com/demo/audio/3.mp3'
+    time:'0:44',
+    audio:'https://culture.4dage.com/demo/audio/3.mp3',
+    img:'3.jpg'
   },
   2:{
     name:'伟大决策',
-    audio:'https://culture.4dage.com/demo/audio/4.mp3'
+    time:'0:25',
+    audio:'https://culture.4dage.com/demo/audio/4.mp3',
+    img:'4.jpg'
   },
   3:{
     name:'筹备组建',
-    audio:'https://culture.4dage.com/demo/audio/5.mp3'
+    time:'0:48',
+    audio:'https://culture.4dage.com/demo/audio/5.6.mp3',
+    img:'5.6.jpg'
   },
   4:{
     name:'公开亮相',
-    audio:'https://culture.4dage.com/demo/audio/6.mp3'
+    time:'0:19',
+    audio:'https://culture.4dage.com/demo/audio/7.mp3',
+    img:'7.jpg'
   },
   5:{
     name:'第二部分 神圣进驻,不辱使命',
-    audio:'https://culture.4dage.com/demo/audio/7.mp3'
+    time:'0:29',
+    audio:'https://culture.4dage.com/demo/audio/8.mp3',
+    img:'8.jpg'
   },
+  
   6:{
-    name:'第二部分 神圣进驻,不辱使命',
-    audio:'https://culture.4dage.com/demo/audio/8.mp3'
-  },
-  7:{
     name:'龙成激情岁月',
-    audio:'https://culture.4dage.com/demo/audio/9.mp3'
+    time:'0:25',
+    audio:'https://culture.4dage.com/demo/audio/9.mp3',
+    img:'9.jpg'
   },
-  8:{
+  7:{
     name:'锻造濠江卫士',
-    audio:'https://culture.4dage.com/demo/audio/10.mp3'
+    time:'0:21',
+    audio:'https://culture.4dage.com/demo/audio/10.mp3',
+    img:'10.jpg'
   },
-  9:{
+  8:{
     name:'树立文明形象',
-    audio:'https://culture.4dage.com/demo/audio/11.mp3'
+    time:'0:29',
+    audio:'https://culture.4dage.com/demo/audio/11.mp3',
+    img:'11.jpg'
   },
-  10:{
+  9:{
     name:'第三部分 强军兴军,定海神针',
-    audio:'https://culture.4dage.com/demo/audio/12.13.mp3'
+    time:'0:44',
+    audio:'https://culture.4dage.com/demo/audio/12.13.mp3',
+    img:'12.13.jpg'
   },
-  11:{
+  10:{
     name:'聚力练兵备战 锻造防务精兵',
-    audio:'https://culture.4dage.com/demo/audio/14.mp3'
+    time:'0:29',
+    audio:'https://culture.4dage.com/demo/audio/14.mp3',
+    img:'14.jpg'
   },
-  12:{
+  11:{
     name:'走出国门对外交流',
-    audio:'https://culture.4dage.com/demo/audio/15.mp3'
+    time:'0:21',
+    audio:'https://culture.4dage.com/demo/audio/15.mp3',
+    img:'15.jpg'
   },
-  13:{
+  12:{
     name:'风雨同舟 守望相助',
-    audio:'https://culture.4dage.com/demo/audio/16.mp3'
+    time:'0:29',
+    audio:'https://culture.4dage.com/demo/audio/16.mp3',
+    img:'16.jpg'
   },
-  14:{
+  13:{
     name:'严守法规纪律 树好窗口形象',
-    audio:'https://culture.4dage.com/demo/audio/17.mp3'
+    time:'0:24',
+    audio:'https://culture.4dage.com/demo/audio/17.mp3',
+    img:'17.jpg'
   },
-  15:{
+  14:{
     name:'瞄准一流抓建 夯实部队根基',
-    audio:'https://culture.4dage.com/demo/audio/18.mp3'
+    time:'0:34',
+    audio:'https://culture.4dage.com/demo/audio/18.mp3',
+    img:'18.jpg'
   },
-  16:{
+  15:{
     name:'真情爱澳亲民 热心公益事业',
-    audio:'https://culture.4dage.com/demo/audio/19.mp3'
+    time:'0:49',
+    audio:'https://culture.4dage.com/demo/audio/19.mp3',
+    img:'19.jpg'
   },
-  17:{
+  16:{
     name:'亲切关怀 巨大鼓舞',
-    audio:'https://culture.4dage.com/demo/audio/20.21.mp3'
+    time:'0:19',
+    audio:'https://culture.4dage.com/demo/audio/20.21.mp3',
+    img:'20.21.jpg'
   },
-  18:{
+  17:{
     name:'功勋荣誉',
-    audio:'https://culture.4dage.com/demo/audio/22.mp3'
+    time:'0:36',
+    audio:'https://culture.4dage.com/demo/audio/22.mp3',
+    img:'22.jpg'
   },
-  19:{
+  18:{
     name:'驻澳门部队精神',
-    audio:'https://culture.4dage.com/demo/audio/23.mp3'
+    time:'1:05',
+    audio:'https://culture.4dage.com/demo/audio/23.mp3',
+    img:'23.jpg'
   },
-  20:{
+  19:{
     name:'大型景观《进驻澳门》',
-    audio:'https://culture.4dage.com/demo/audio/24.mp3'
+    time:'0:30',
+    audio:'https://culture.4dage.com/demo/audio/24.mp3',
+    img:'24.jpg'
   }
 }
+
+
+let audioadr = Object.keys(g_ad).map((item,i)=>{
+      let tmp= g_ad[item].audio
+      return tmp
+})
+
+export const G_AUDIO =  g_ad
+export const AudioAddress = audioadr
+
+
+ 

+ 37 - 0
utils/event.js

@@ -0,0 +1,37 @@
+var events = {};
+
+function on(name, self, callback) {
+    var tuple = [self, callback];
+    var callbacks = events[name];
+    if (Array.isArray(callbacks)) {
+        callbacks.push(tuple);
+    }
+    else {
+        events[name] = [tuple];
+    }
+}
+
+function remove(name, self) {
+    var callbacks = events[name];
+    if (Array.isArray(callbacks)) {
+        events[name] = callbacks.filter((tuple) => {
+            return tuple[0] != self;
+        })
+    }
+}
+
+function emit(name, data) {
+    var callbacks = events[name];
+    if (Array.isArray(callbacks)) {
+        console.log(callbacks,'callbacks');
+        callbacks.map((tuple) => {
+            var self = tuple[0];
+            var callback = tuple[1];
+            callback.call(self, data);
+        })
+    }
+}
+
+exports.on = on;
+exports.remove = remove;
+exports.emit = emit;