app.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import { wxSetSessionKey } from "./utils/wxUtils";
  2. import { postApi } from "./apis/api";
  3. App({
  4. onLaunch: function () {
  5. const updateManager = wx.getUpdateManager();
  6. updateManager.onCheckForUpdate(function (res) {
  7. // 请求完新版本信息的回调
  8. });
  9. updateManager.onUpdateReady(function () {
  10. wx.showModal({
  11. title: "更新提示",
  12. content: "新版本已经准备好,是否重启应用?",
  13. success: function (res) {
  14. if (res.confirm) {
  15. // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  16. updateManager.applyUpdate();
  17. }
  18. },
  19. });
  20. });
  21. updateManager.onUpdateFailed(function () {
  22. // 新版本下载失败
  23. });
  24. // wx.cloud.init({
  25. // traceUser: true,
  26. // });
  27. this.globalData = {};
  28. this.checkEnvVersion();
  29. },
  30. onShow() {},
  31. async checkEnvVersion() {
  32. let v = wx.getAccountInfoSync();
  33. let appVersion = wx.getStorageSync("appVersion");
  34. let { envVersion } = v.miniProgram;
  35. console.log(envVersion);
  36. wx.showToast({
  37. title: "正在初始化登录信息...",
  38. icon: "none",
  39. });
  40. let { openId, status } = await wxSetSessionKey();
  41. let scene = wx.getLaunchOptionsSync(); // 获取场景值
  42. let timer = setTimeout(() => {
  43. wx.hideLoading();
  44. if (appVersion != envVersion) {
  45. console.log("清除缓存");
  46. wx.clearStorage({
  47. success: (res) => {},
  48. });
  49. }
  50. wx.setStorageSync("appVersion", envVersion);
  51. wx.setStorageSync("openId", openId);
  52. // 判断scene.path 是否有sharePage/sharePage
  53. // if (scene.path.indexOf("sharePage/sharePage") === -1) {
  54. // wx.setStorageSync("appVersion", envVersion);
  55. // wx.redirectTo({
  56. // url: "/pages/index/index",
  57. // });
  58. // }
  59. clearTimeout(timer);
  60. }, 1000);
  61. },
  62. });