app.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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(function (res) {
  16. // 请求完新版本信息的回调
  17. console.log(res.hasUpdate)
  18. })
  19. updateManager.onUpdateReady(function () {
  20. wx.showModal({
  21. title: '更新提示',
  22. content: '新版本已经准备好,是否重启应用?',
  23. success(res) {
  24. if (res.confirm) {
  25. // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  26. updateManager.applyUpdate()
  27. }
  28. }
  29. })
  30. })
  31. updateManager.onUpdateFailed(function () {
  32. // 新版本下载失败
  33. })
  34. } else {
  35. wx.showModal({
  36. title: '提示',
  37. content: '当前微信版本过低,部分功能可能无法使用,请升级到最新微信版本后重试。'
  38. })
  39. }
  40. },
  41. onShow(options) {
  42. console.log("rr", options)
  43. //群聊信息
  44. if (options.shareTicket) {
  45. this.getShareInfo(options.shareTicket)
  46. }
  47. },
  48. globalData: {
  49. openId: '',
  50. userInfo: null,
  51. userId: '',
  52. userToken: '',
  53. sessionKey: '',
  54. city: updataStorageData('city') || '无锡'
  55. },
  56. //页面分享
  57. onShareAppMessage: function () {
  58. wx.showShareMenu({
  59. withShareTicket: true,
  60. success: (res) => { // 成功后要做的事情
  61. console.log(res)
  62. },
  63. fail: function (res) {
  64. console.log(res)
  65. }
  66. })
  67. },
  68. //获取群聊分享信息
  69. getShareInfo(shareTicket) {
  70. wx.getShareInfo({
  71. shareTicket: shareTicket,
  72. success: (res) => {
  73. //需后台解析数据 encryptedData iv
  74. console.log(res)
  75. },
  76. fail: function (res) {
  77. console.log(res)
  78. },
  79. complete: function (res) { }
  80. })
  81. },
  82. // 跳转登录页面
  83. goLogin() {
  84. wx.navigateTo({
  85. url: '/pages/login/login',
  86. })
  87. },
  88. })