app.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. //app.js
  2. import http from './utils/http'
  3. App({
  4. onLaunch: function () {
  5. var userinfo = wx.getStorageSync('sg-userinfo')
  6. if (!userinfo) {
  7. wx.redirectTo({
  8. url: '/pages/login/index',
  9. })
  10. } else {
  11. this.globalData.userInfo = userinfo
  12. }
  13. // 展示本地存储能力
  14. // var logs = wx.getStorageSync('logs') || []
  15. // logs.unshift(Date.now())
  16. // wx.setStorageSync('logs', logs)
  17. // 登录
  18. // wx.login({
  19. // success: res => {
  20. // 发送 res.code 到后台换取 openId, sessionKey, unionId
  21. // }
  22. // })
  23. // 获取用户信息
  24. // wx.getSetting({
  25. // success: res => {
  26. // if (res.authSetting['scope.userInfo']) {
  27. // // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
  28. // wx.getUserInfo({
  29. // success: res => {
  30. // // 可以将 res 发送给后台解码出 unionId
  31. // this.globalData.userInfo = res.userInfo
  32. // // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
  33. // // 所以此处加入 callback 以防止这种情况
  34. // if (this.userInfoReadyCallback) {
  35. // this.userInfoReadyCallback(res)
  36. // }
  37. // }
  38. // })
  39. // }
  40. // }
  41. // })
  42. },
  43. globalData: {
  44. userInfo: null
  45. },
  46. updateUserInfo: function (info) {
  47. this.globalData.userInfo = info
  48. wx.setStorageSync('sg-userinfo', info)
  49. },
  50. logout: function (res) {
  51. this.globalData.userInfo = null
  52. wx.setStorageSync('sg-userinfo', null)
  53. wx.navigateTo({
  54. url: '/pages/login/index'
  55. })
  56. },
  57. resetFilter: function () {
  58. var data = {
  59. project_ids: [''],
  60. work_point_ids: [''],
  61. device_id: '',
  62. device_name_id: '',
  63. spec_id: ''
  64. }
  65. wx.setStorageSync('sg-device-filters', data)
  66. },
  67. resetDataFilter: function () {
  68. var data = {
  69. devices: [],
  70. device_ids: [''],
  71. names: [],
  72. device_name_ids: [''],
  73. specs: [],
  74. spec_ids: [''],
  75. rent_types: [],
  76. rent_type_ids: ['']
  77. }
  78. wx.setStorageSync('sg-data-filters', data)
  79. },
  80. navigate(e) {
  81. var url = e.currentTarget.dataset.url
  82. wx.navigateTo({
  83. url: url,
  84. })
  85. },
  86. updateInput(that, e) {
  87. var name = e.currentTarget.dataset.name
  88. var val = e.detail.value
  89. that.setData({
  90. [name]: val
  91. })
  92. },
  93. loginCallback: function(data) {
  94. this.updateUserInfo(data)
  95. wx.switchTab({
  96. url: '/pages/index/index',
  97. })
  98. }
  99. })