checkIn.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import Api from "../../model/api";
  2. import Config from "../../model/config";
  3. import {showLoading, toast} from "../../utils/utils";
  4. import {verifyTypes} from "../../model/enum";
  5. Page({
  6. data: {
  7. wifiOk: false,
  8. current: '',
  9. wifi: {},
  10. isOk: false,
  11. name: '',
  12. type: '',
  13. title: '',
  14. cId: '',
  15. teamId: '',
  16. eId: ''
  17. },
  18. async onLoad(options) {
  19. const {title, type, name, cId, teamId, eId} = options;
  20. wx.setNavigationBarTitle({title})
  21. this.setData({
  22. type,
  23. name,
  24. title,
  25. cId,
  26. teamId,
  27. eId,
  28. })
  29. await this.getData();
  30. },
  31. async getData() {
  32. const data = await Api.getPulishDict(Config.DICT.WIFI, true);
  33. this.setData({
  34. wifi: data.data[0],
  35. })
  36. },
  37. async clickBtn(e) {
  38. if (this.data.isOk) {
  39. return
  40. }
  41. showLoading();
  42. try {
  43. const wifiData = await wx.startWifi();
  44. const res = await wx.getConnectedWifi();
  45. let msg = res.wifi.SSID;
  46. let flag = (msg == this.data.wifi.dictLabel);
  47. this.setData({
  48. wifiOk: flag,
  49. current: msg
  50. })
  51. } catch (e) {
  52. console.log(e);
  53. toast("请检查手机WIFI和GPS定位是否打开后重试")
  54. return;
  55. }
  56. if (this.data.type == verifyTypes.REPORT) {
  57. await Api.report({
  58. id: this.data.teamId,
  59. eStuId: this.data.eId,
  60. wifiName: this.data.current,
  61. wifiPassword: this.data.wifi.dictValue,
  62. })
  63. } else if (this.data.type == verifyTypes.CHECK_IN) {
  64. await Api.checkIn(this.data.cId, this.data.eId, this.data.current)
  65. }
  66. this.setData({isOk: true});
  67. const eventChannel = this.getOpenerEventChannel()
  68. eventChannel.emit('check');
  69. wx.hideLoading();
  70. }
  71. })