app.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import { wxSetSessionKey } from "./utils/wxUtils";
  2. App({
  3. onLaunch: function () {
  4. const updateManager = wx.getUpdateManager();
  5. updateManager.onCheckForUpdate(function (res) {
  6. // 请求完新版本信息的回调
  7. });
  8. updateManager.onUpdateReady(function () {
  9. wx.showModal({
  10. title: "更新提示",
  11. content: "新版本已经准备好,是否重启应用?",
  12. success: function (res) {
  13. if (res.confirm) {
  14. // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  15. updateManager.applyUpdate();
  16. }
  17. },
  18. });
  19. });
  20. updateManager.onUpdateFailed(function () {
  21. // 新版本下载失败
  22. });
  23. wx.cloud.init({
  24. traceUser: true,
  25. });
  26. this.globalData = {};
  27. },
  28. onShow() {
  29. this.checkEnvVersion();
  30. },
  31. checkEnvVersion() {
  32. let v = wx.getAccountInfoSync();
  33. let appVersion = wx.getStorageSync("appVersion");
  34. let { envVersion } = v.miniProgram;
  35. if (appVersion != envVersion) {
  36. wx.clearStorage({
  37. success: (res) => {
  38. wx.setStorageSync("appVersion", envVersion);
  39. wx.redirectTo({
  40. url: "/pages/index/index",
  41. });
  42. },
  43. });
  44. }
  45. wxSetSessionKey();
  46. },
  47. });