app.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. this.checkEnvVersion();
  28. },
  29. onShow() {},
  30. checkEnvVersion() {
  31. let v = wx.getAccountInfoSync();
  32. let appVersion = wx.getStorageSync("appVersion");
  33. let { envVersion } = v.miniProgram;
  34. if (appVersion != envVersion) {
  35. // 获取场景值
  36. let scene = wx.getLaunchOptionsSync();
  37. // 判断scene.path 是否有sharePage/sharePage
  38. wx.clearStorage({
  39. success: (res) => {
  40. wx.setStorageSync("appVersion", envVersion);
  41. if (scene.path.indexOf("sharePage/sharePage") === -1) {
  42. wx.setStorageSync("appVersion", envVersion);
  43. wx.redirectTo({
  44. url: "/pages/index/index",
  45. });
  46. }
  47. },
  48. });
  49. }
  50. wxSetSessionKey();
  51. },
  52. });