|
@@ -1,6 +1,7 @@
|
|
|
|
|
|
|
|
|
const app = getApp()
|
|
|
+import Toast from '../../miniprogram/miniprogram_npm/vant-weapp/toast/toast'
|
|
|
|
|
|
Page({
|
|
|
data: {
|
|
@@ -9,8 +10,7 @@ Page({
|
|
|
sucmsg: false,
|
|
|
warmsg: false,
|
|
|
errmsg: '',
|
|
|
- list: [],
|
|
|
- placeList: []
|
|
|
+ toast: {},
|
|
|
},
|
|
|
|
|
|
bindViewTap: function () {
|
|
@@ -19,12 +19,11 @@ Page({
|
|
|
})
|
|
|
},
|
|
|
onLoad: function (option) {
|
|
|
- this.stopDiscovery();
|
|
|
- this.startDiscover();
|
|
|
this.setData({
|
|
|
type: option.type
|
|
|
})
|
|
|
- this.getPlaceList();
|
|
|
+ this.stopDiscovery();
|
|
|
+ this.startDiscover();
|
|
|
},
|
|
|
addsuc: function () {
|
|
|
this.setData({
|
|
@@ -34,28 +33,32 @@ Page({
|
|
|
},
|
|
|
addmsg: function (errmsg) {
|
|
|
let msg = '';
|
|
|
- if (errmsg.errCode == '11001' || errmsg.errCode === 11001) msg = '请打开蓝牙功能,重新进入';
|
|
|
+ if (errmsg.errCode == '11001' || errmsg.errCode === 11001) msg = '请打开蓝牙功能,请开启蓝牙功能后按"签到"按钮';
|
|
|
else if (errmsg.errCode == '11003' || errmsg.errCode === 11003) msg = '已经开始搜索';
|
|
|
else if (errmsg.errCode == '11004' || errmsg.errCode === 11004) msg = '还未开始搜索';
|
|
|
else msg = errmsg.errMsg;
|
|
|
-
|
|
|
this.setData({
|
|
|
warmsg: true,
|
|
|
sucmsg: false,
|
|
|
errmsg: msg,
|
|
|
});
|
|
|
},
|
|
|
- ibeaconBtn: function () {
|
|
|
- var that = this;
|
|
|
- wx.showLoading({
|
|
|
- title: '正在签到',
|
|
|
- mask: true,
|
|
|
+ reSearch() {
|
|
|
+ this.stopDiscovery();
|
|
|
+ this.setData({
|
|
|
+ sucmsg: false,
|
|
|
+ warmsg: false,
|
|
|
+ errmsg: '重新扫描',
|
|
|
})
|
|
|
+ this.startDiscover();
|
|
|
+ },
|
|
|
+ toSign: function (ibeacon) {
|
|
|
let newdata = {
|
|
|
openid: app.globalData.openid,
|
|
|
- type: that.data.type,
|
|
|
- ibeacon: that.data.list.map(i => i.minor)
|
|
|
+ type: this.data.type,
|
|
|
+ ibeacon: [ibeacon]
|
|
|
};
|
|
|
+
|
|
|
wx.request({
|
|
|
url: app.globalData.contentpath + 'api/train/attendance/attendancecreate',
|
|
|
header: {
|
|
@@ -64,28 +67,53 @@ Page({
|
|
|
data: newdata,
|
|
|
method: 'POST',
|
|
|
dataType: 'json',
|
|
|
- success: function (res) {
|
|
|
+ success: (res) => {
|
|
|
if (res.data.errcode == 0) {
|
|
|
- that.addsuc();
|
|
|
+ this.addsuc();
|
|
|
} else {
|
|
|
console.log('签到失败' + res.data.errmsg);
|
|
|
- that.addmsg({ errMsg: res.data.errmsg });
|
|
|
+ this.addmsg({ errMsg: res.data.errmsg });
|
|
|
}
|
|
|
},
|
|
|
- fail: function (err) {
|
|
|
+ fail: (err) => {
|
|
|
console.log('签到失败' + err);
|
|
|
- that.addmsg(err);
|
|
|
+ this.addmsg(err);
|
|
|
},
|
|
|
- complete: function () {
|
|
|
- wx.hideLoading()
|
|
|
+ complete: () => {
|
|
|
+ const toast = this.data.toast;
|
|
|
+ toast.clear();
|
|
|
}
|
|
|
+
|
|
|
})
|
|
|
},
|
|
|
- startDiscover() {
|
|
|
-
|
|
|
+ async startDiscover() {
|
|
|
+ const user = app.globalData.userInfo;
|
|
|
+ if (!user) {
|
|
|
+ Toast({
|
|
|
+ duration: 3000,
|
|
|
+ message: "未找到用户信息,请重新进入小程序"
|
|
|
+ })
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ let toast = Toast({
|
|
|
+ type: 'loading',
|
|
|
+ duration: 0,
|
|
|
+ message: '准备扫描中',
|
|
|
+ forbidClick: true,
|
|
|
+ })
|
|
|
+ this.setData({
|
|
|
+ toast: toast
|
|
|
+ })
|
|
|
wx.startBeaconDiscovery({
|
|
|
uuids: ['FDA50693-A4E2-4FB1-AFCF-C6EB07647825'],
|
|
|
success: (res) => {
|
|
|
+ toast.setData({
|
|
|
+ message: '正在搜索设备,请稍后...'
|
|
|
+ })
|
|
|
+ const countId = setTimeout(() => {
|
|
|
+ this.stopDiscovery()
|
|
|
+ this.addmsg({ errMsg: '未扫描到指定设备,请按"签到"重新扫描' })
|
|
|
+ }, 30 * 1000)
|
|
|
wx.onBeaconUpdate(res => {
|
|
|
wx.getBeacons({
|
|
|
success: (result) => {
|
|
@@ -94,42 +122,36 @@ Page({
|
|
|
var limit = 30;
|
|
|
for (var i = 0; i < beacons.length; i++) {
|
|
|
var beacon = beacons[i];
|
|
|
- if (beacon.accuracy < limit) {
|
|
|
- const r = this.data.placeList.find(f => f.ibeacon === `${beacon.minor}`)
|
|
|
- if (r) {
|
|
|
- if (this.data.type === '0') {
|
|
|
- const { name } = r
|
|
|
- beaconList.push(name);
|
|
|
- } else {
|
|
|
- const { code, floor } = r
|
|
|
- let name;
|
|
|
- let remark = 'C区';
|
|
|
- if (code.includes('后楼')) {
|
|
|
- if (code.includes('-')) remark = "B区"
|
|
|
- if (floor) name = `后楼${remark}${floor.includes('楼') ? floor : `${floor}楼`}`
|
|
|
- else name = `后楼${remark}${beacon.minor}`
|
|
|
- } else if (code.includes('前楼')) {
|
|
|
- if (floor) name = `前楼${floor.includes('楼') ? floor : `${floor}楼`}`
|
|
|
- else name = `前楼${beacon.minor}`
|
|
|
- } else name = code
|
|
|
- beaconList.push(name);
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
+ if (beacon.accuracy <= limit) {
|
|
|
+ beaconList.push(`${beacon.minor}`)
|
|
|
}
|
|
|
}
|
|
|
- this.setData({
|
|
|
- list: beaconList
|
|
|
- })
|
|
|
-
|
|
|
- console.log(result)
|
|
|
+ const type = this.data.type;
|
|
|
+ let needIbeacon = '';
|
|
|
+ let place = '';
|
|
|
+ if (type == '0') {
|
|
|
+
|
|
|
+ needIbeacon = `${user.jsibeacon}`
|
|
|
+ place = user.jsname
|
|
|
+ } else {
|
|
|
+ needIbeacon = `${user.bedroomibeacon}`
|
|
|
+ place = user.bedroomname
|
|
|
+ }
|
|
|
+ if (beaconList.includes(needIbeacon)) {
|
|
|
+ toast.setData({
|
|
|
+ message: `已搜索到${place}设备,正在签到,请稍后.....`
|
|
|
+ })
|
|
|
+ this.toSign(needIbeacon);
|
|
|
+ clearTimeout(countId)
|
|
|
+ this.stopDiscovery();
|
|
|
+ }
|
|
|
},
|
|
|
})
|
|
|
})
|
|
|
|
|
|
},
|
|
|
- fail: (error) => {
|
|
|
- console.log(error)
|
|
|
+ fail: async (error) => {
|
|
|
+ await toast.clear();
|
|
|
this.addmsg(error);
|
|
|
}
|
|
|
})
|
|
@@ -137,45 +159,11 @@ Page({
|
|
|
stopDiscovery() {
|
|
|
wx.stopBeaconDiscovery({
|
|
|
success: (res) => {
|
|
|
+ const toast = this.data.toast;
|
|
|
+ toast.clear();
|
|
|
console.log('停止扫描');
|
|
|
},
|
|
|
})
|
|
|
},
|
|
|
- getPlaceList() {
|
|
|
- let model;
|
|
|
- if (this.data.type === '1' || this.data.type === 1) {
|
|
|
- model = 'bedroom'
|
|
|
- } else {
|
|
|
- model = 'location'
|
|
|
- }
|
|
|
- let uri = `api/train/${model}`
|
|
|
- wx.request({
|
|
|
- url: `${app.globalData.contentpath}${uri}`,
|
|
|
- header: {
|
|
|
- "Content-Type": "application/json"
|
|
|
- },
|
|
|
- method: 'GET',
|
|
|
- dataType: 'json',
|
|
|
- success: (res) => {
|
|
|
- if (res.data.errcode == 0) {
|
|
|
- console.log(res);
|
|
|
- const { data } = res.data;
|
|
|
- if (data) {
|
|
|
- const list = data.filter(f => f.ibeacon)
|
|
|
- this.setData({
|
|
|
- placeList: list
|
|
|
- })
|
|
|
- console.log(this.data.placeList);
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- } else {
|
|
|
- }
|
|
|
- },
|
|
|
- fail: function (err) {
|
|
|
- that.addmsg(err);
|
|
|
- },
|
|
|
- })
|
|
|
- }
|
|
|
|
|
|
})
|