checkIn.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. let res;
  57. if (this.data.type == verifyTypes.REPORT) {
  58. res = await Api.report({
  59. id: this.data.teamId,
  60. eStuId: this.data.eId,
  61. wifiName: this.data.current,
  62. // wifiName: this.data.wifi.dictLabel,
  63. wifiPassword: this.data.wifi.dictValue,
  64. });
  65. } else if (this.data.type == verifyTypes.CHECK_IN) {
  66. res = await Api.checkIn(this.data.cId, this.data.eId, this.data.current)
  67. }
  68. if (!res) {
  69. return;
  70. }
  71. this.setData({isOk: true});
  72. const eventChannel = this.getOpenerEventChannel()
  73. eventChannel.emit('check');
  74. wx.hideLoading();
  75. }
  76. })