|
@@ -0,0 +1,123 @@
|
|
|
+//index.js
|
|
|
+//获取应用实例
|
|
|
+const app = getApp()
|
|
|
+
|
|
|
+Page({
|
|
|
+ data: {
|
|
|
+ motto: 'Hello World',
|
|
|
+ type: '',
|
|
|
+ sucmsg: false,
|
|
|
+ warmsg: false,
|
|
|
+ errmsg: '',
|
|
|
+ },
|
|
|
+ //事件处理函数
|
|
|
+ bindViewTap: function () {
|
|
|
+ wx.navigateTo({
|
|
|
+ url: '../logs/logs'
|
|
|
+ })
|
|
|
+ },
|
|
|
+ onLoad: function (option) {
|
|
|
+ console.log(app.globalData.userInfo)
|
|
|
+ this.setData({
|
|
|
+ type: option.type
|
|
|
+ })
|
|
|
+ },
|
|
|
+ addsuc: function () {
|
|
|
+ this.setData({
|
|
|
+ sucmsg: true,
|
|
|
+ warmsg: false,
|
|
|
+ });
|
|
|
+ },
|
|
|
+ addmsg: function (errmsg) {
|
|
|
+ let msg = '';
|
|
|
+ if (errmsg.errCode == 11001) msg = '请打开蓝牙功能';
|
|
|
+ else msg = errmsg.errMsg;
|
|
|
+ this.setData({
|
|
|
+ warmsg: true,
|
|
|
+ sucmsg: false,
|
|
|
+ errmsg: msg,
|
|
|
+ });
|
|
|
+ },
|
|
|
+ ibeaconBtn: function () {
|
|
|
+ console.log(111);
|
|
|
+ var that = this;
|
|
|
+ wx.startBeaconDiscovery({
|
|
|
+ uuids: ['FDA50693-A4E2-4FB1-AFCF-C6EB07647825'],
|
|
|
+ success(res) {
|
|
|
+ console.log(res);
|
|
|
+ wx.onBeaconUpdate(function (beacons) {
|
|
|
+ console.log('onBeaconUpdate')
|
|
|
+ wx.getBeacons({
|
|
|
+ success: function (res) {
|
|
|
+ console.log('getBeacons');
|
|
|
+ console.log(res)
|
|
|
+ if (res.errMsg != 'getBeacons:ok') {
|
|
|
+ that.addmsg({ errMsg: '获取蓝牙设备失败' });
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ var master = 100000;
|
|
|
+ var mastername = '0';
|
|
|
+ var beaconList = [];
|
|
|
+ var limit = 5;
|
|
|
+ for (var i = 0; i < res.beacons.length; i++) {
|
|
|
+ var beacon = res.beacons[i];
|
|
|
+ if (beacon.accuracy < limit) {
|
|
|
+ beaconList.push(beacon.minor);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ console.log(res.beacons)
|
|
|
+ console.log('附近--');
|
|
|
+ console.log(beaconList);
|
|
|
+ wx.stopBeaconDiscovery({
|
|
|
+ success: function (res) {
|
|
|
+ console.log('停止扫描');
|
|
|
+ // console.log('距离啊距离-->' + master);
|
|
|
+ // if (master < limit) {
|
|
|
+ console.log('请求啊请求' + master);
|
|
|
+ let newdata = {
|
|
|
+ openid: app.globalData.openid,
|
|
|
+ type: that.data.type,
|
|
|
+ ibeacon: beaconList
|
|
|
+ };
|
|
|
+ wx.request({
|
|
|
+ url: app.globalData.contentpath + 'api/train/attendance/attendancecreate',
|
|
|
+ header: {//请求头
|
|
|
+ "Content-Type": "application/json"
|
|
|
+ },
|
|
|
+ data: newdata,
|
|
|
+ method: 'POST',
|
|
|
+ dataType: 'json',
|
|
|
+ success: function (res) {
|
|
|
+ //res.data相当于ajax里面的data,为后台返回的数据
|
|
|
+ //如果在sucess直接写this就变成了wx.request()的this了
|
|
|
+ //必须为getdata函数的this,不然无法重置调用函数
|
|
|
+ console.log(res);
|
|
|
+ if (res.data.errcode == 0) {
|
|
|
+ that.addsuc();
|
|
|
+ } else {
|
|
|
+ console.log('签到失败' + res.data.errmsg);
|
|
|
+ that.addmsg({ errMsg: res.data.errmsg });
|
|
|
+ }
|
|
|
+ },
|
|
|
+ fail: function (err) {
|
|
|
+ console.log('签到失败' + err);
|
|
|
+ that.addmsg(err);
|
|
|
+ },//请求失败
|
|
|
+ complete: function () { }//请求完成后执行的函数
|
|
|
+ })
|
|
|
+ // }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ })
|
|
|
+ })
|
|
|
+
|
|
|
+ },
|
|
|
+ fail(res) {
|
|
|
+ console.log('function in fail')
|
|
|
+ console.log(res);
|
|
|
+ that.addmsg(res);
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+})
|