app.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. var sysT = require('tools/sys-tool.js')
  2. const updateManager = wx.getUpdateManager()
  3. var businessT = require('tools/business-tool.js')
  4. App({
  5. onLaunch: function () {
  6. sysT.adaptor()
  7. this.getUpdateReady()
  8. this.getNetworkStatus()
  9. },
  10. onShow: function (e) {
  11. //console.log(e)
  12. if (e.scene == 1037) {
  13. wx.reportAnalytics('source_applet', {
  14. source_app_id: e.referrerInfo.appId,
  15. });
  16. }
  17. },
  18. getUpdateReady: function () {
  19. updateManager.onUpdateReady(function () {
  20. wx.showModal({
  21. title: '更新提示',
  22. content: '新版本已经准备好,是否重启应用?',
  23. showCancel: false,
  24. success: function (res) {
  25. if (res.confirm) {
  26. // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  27. updateManager.applyUpdate()
  28. }
  29. }
  30. })
  31. })
  32. },
  33. getNetworkStatus: function () {
  34. var that = this
  35. wx.getNetworkType({
  36. success: function (res) {
  37. // 返回网络类型, 有效值:
  38. // wifi/2g/3g/4g/unknown(Android下不常见的网络类型)/none(无网络)
  39. that.networkStatus.type = res.networkType
  40. if (that.networkStatus.type == 'none') {
  41. that.networkStatus.connected = false
  42. } else {
  43. that.networkStatus.connected = true
  44. }
  45. businessT.debugLog(that.networkStatus)
  46. }
  47. })
  48. wx.onNetworkStatusChange(function (res) {
  49. that.networkStatus.type = res.networkType
  50. that.networkStatus.connected = res.isConnected
  51. businessT.debugLog(that.networkStatus)
  52. })
  53. },
  54. globalData: {
  55. userInfo: null
  56. },
  57. networkStatus: {
  58. type: 'none',
  59. connected: false
  60. },
  61. result: [],
  62. medical: {
  63. s: false,
  64. rebate: 0
  65. }
  66. })