app.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. require("./utils/string.js")
  2. const ald = require('./libs/ald-stat.js')
  3. import {
  4. updataStorageData
  5. } from './utils/storage.js'
  6. var startTime = Date.now(); //启动时间
  7. App({
  8. onLaunch: function(options) {
  9. this.aldstat.sendEvent('小程序的启动时长', {
  10. time: Date.now() - startTime
  11. })
  12. // 小程序版本更新
  13. if (wx.getUpdateManager) {
  14. const updateManager = wx.getUpdateManager()
  15. updateManager.onCheckForUpdate((res) => {
  16. // 请求完新版本信息的回调
  17. console.log(res.hasUpdate)
  18. })
  19. updateManager.onUpdateReady(() => {
  20. wx.showModal({
  21. title: '更新提示',
  22. content: '新版本已经准备好,是否重启应用?',
  23. success: (res) => {
  24. if (res.confirm) {
  25. // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  26. wx.removeStorageSync("user_id");
  27. wx.removeStorageSync("member_id");
  28. wx.removeStorageSync("user_token");
  29. wx.removeStorageSync("userInfo");
  30. this.globalData.userId = '';
  31. this.globalData.userToken = '';
  32. this.globalData.memberId = '';
  33. this.globalData.userInfo = null;
  34. updateManager.applyUpdate()
  35. }
  36. }
  37. })
  38. })
  39. updateManager.onUpdateFailed(function() {
  40. // 新版本下载失败
  41. })
  42. } else {
  43. wx.showModal({
  44. title: '提示',
  45. content: '当前微信版本过低,部分功能可能无法使用,请升级到最新微信版本后重试。'
  46. })
  47. }
  48. },
  49. onShow(options) {
  50. console.log("rr", options)
  51. //群聊信息
  52. if (options.shareTicket) {
  53. this.getShareInfo(options.shareTicket)
  54. }
  55. },
  56. globalData: {
  57. openId: '',
  58. userInfo: null,
  59. userId: '',
  60. userToken: '',
  61. memberId: "",
  62. sessionKey: '',
  63. city: updataStorageData('city') || '无锡'
  64. },
  65. //页面分享
  66. onShareAppMessage: function() {
  67. wx.showShareMenu({
  68. withShareTicket: true,
  69. success: (res) => { // 成功后要做的事情
  70. console.log(res)
  71. },
  72. fail: function(res) {
  73. console.log(res)
  74. }
  75. })
  76. },
  77. //获取群聊分享信息
  78. getShareInfo(shareTicket) {
  79. wx.getShareInfo({
  80. shareTicket: shareTicket,
  81. success: (res) => {
  82. //需后台解析数据 encryptedData iv
  83. console.log(res)
  84. },
  85. fail: function(res) {
  86. console.log(res)
  87. },
  88. complete: function(res) {}
  89. })
  90. },
  91. // 跳转登录页面
  92. goLogin() {
  93. wx.navigateTo({
  94. url: '/pages/login/login',
  95. })
  96. },
  97. })