app.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. // app.js
  2. const homeApi_empower = "https://aipush.aidsleep.cn";
  3. App({
  4. onLaunch() {
  5. // 在需要隐藏 tabBar 的页面的脚本中调用
  6. wx.hideTabBar({
  7. animation: false, // 是否需要动画效果,默认为 false
  8. success: function () {
  9. console.log('TabBar 已经被隐藏');
  10. },
  11. fail: function (err) {
  12. console.error('隐藏 TabBar 失败', err);
  13. }
  14. });
  15. // 展示本地存储能力
  16. // const logs = wx.getStorageSync('logs') || []
  17. // logs.unshift(Date.now())
  18. // wx.setStorageSync('logs', logs)
  19. // this.globalData.selectedTabIndex = wx.getStorageSync("selectedTabIndex") || 0;
  20. // 登录
  21. wx.login({
  22. success: res => {
  23. // 发送 res.code 到后台换取 openId, sessionKey, unionId
  24. wx.request({
  25. url: `${homeApi_empower}/wxssk`,
  26. method: 'POST',
  27. data: {
  28. code: res.code,
  29. },
  30. success: function (loginRes) {
  31. // 处理服务器返回的结果
  32. console.log('登录获取结果:', loginRes.data);
  33. if (loginRes.data) {
  34. wx.setStorageSync("openid", loginRes.data.openid);
  35. wx.setStorageSync("token", loginRes.data.token);
  36. wx.setStorageSync("unionid", loginRes.data.unionid);
  37. // 判断扫码控制权限
  38. wx.request({
  39. url: `${homeApi_empower}/wxstatus`,
  40. data: {
  41. unionid: wx.getStorageSync('unionid'),
  42. openid: wx.getStorageSync('openid'),
  43. token: wx.getStorageSync('token'),
  44. },
  45. method: 'POST',
  46. success: function (intervalRes) {
  47. console.log('intervalRes=' + JSON.stringify(intervalRes));
  48. console.log('intervalRes.data=' + JSON.stringify(intervalRes.data));
  49. //empower.js? [sm]:152 intervalRes.data={"st":"success","status":"0"}
  50. if (intervalRes.data && intervalRes.data.st && intervalRes.data.status && intervalRes.data.st == 'success' && intervalRes.data.status == '1') {
  51. wx.setStorageSync('hasHotelAuth', true);
  52. wx.setStorageSync('hotelEmpower', intervalRes.data.hotel);
  53. wx.setStorageSync('roomEmpower', intervalRes.data.room);
  54. wx.setStorageSync('hname', intervalRes.data.hname);
  55. wx.setStorageSync('rname', intervalRes.data.rname);
  56. } else {
  57. wx.setStorageSync('hasHotelAuth', false);
  58. }
  59. },
  60. fail: function (error) {
  61. }
  62. });
  63. // 判断今日睡眠报告权限
  64. wx.request({
  65. url: 'https://aipush.aidsleep.cn/srpwithrange',
  66. method: 'POST',
  67. data: {
  68. token: "89835e65993fee4a6a6cbbe4c271da51e5521822934e13769e61cadabaed72c3" || wx.getStorageSync('token'),
  69. udi: wx.getStorageSync('unionid'),
  70. pg: 1,
  71. lm: 1
  72. },
  73. success: (res) => {
  74. var loadData = res.data.data;
  75. if ((Array.isArray(loadData) && loadData.length > 0) || (loadData && !Array.isArray(loadData)) ) {
  76. wx.setStorageSync('hasReportAuth', true);
  77. } else {
  78. wx.setStorageSync('hasReportAuth', false);
  79. }
  80. },
  81. fail: () => {
  82. wx.setStorageSync('hasReportAuth', false);
  83. }
  84. });
  85. }
  86. }
  87. })
  88. }
  89. })
  90. },
  91. onShow() {
  92. wx.hideTabBar()
  93. },
  94. globalData: {
  95. userInfo: null,
  96. selectedTabIndex: 0
  97. }
  98. })