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. let title = options.title;
  20. wx.setNavigationBarTitle({title})
  21. this.setData({
  22. type: options.type,
  23. name: options.name,
  24. title,
  25. cId: options.cId,
  26. teamId: options.teamId,
  27. eId: options.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 onPullDownRefresh() {
  38. await this.getData();
  39. wx.stopPullDownRefresh();
  40. },
  41. async clickBtn(e) {
  42. if (this.data.isOk) {
  43. return
  44. }
  45. showLoading();
  46. try {
  47. const wifiData = await wx.startWifi();
  48. const res = await wx.getConnectedWifi();
  49. let msg = res.wifi.SSID;
  50. let flag = (msg == this.data.wifi.dictLabel);
  51. this.setData({
  52. wifiOk: flag,
  53. current: res.msg
  54. })
  55. } catch (e) {
  56. console.log(e);
  57. toast("请检查手机WIFI和GPS定位是否打开后重试")
  58. return;
  59. }
  60. if (this.data.type == verifyTypes.REPORT) {
  61. await Api.report({
  62. id: this.data.teamId,
  63. eStuId: this.data.eId,
  64. wifiName: this.data.current,
  65. wifiPassword: this.data.wifi.dictValue,
  66. })
  67. } else if (this.data.type == verifyTypes.CHECK_IN) {
  68. await Api.checkIn(this.data.cId, this.data.eId, this.data.current)
  69. }
  70. this.setData({isOk: true});
  71. const eventChannel = this.getOpenerEventChannel()
  72. eventChannel.emit('check');
  73. wx.hideLoading();
  74. }
  75. })