app.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. //app.js
  2. const net = require("utils/net.js");
  3. const { api_app_config } = require("utils/api.js");
  4. App({
  5. onLaunch: function () {
  6. this.checkGetSystemInfo();
  7. this.getAppConfig();
  8. this.checkForUpdate();
  9. },
  10. checkGetSystemInfo: function () {
  11. const self = this;
  12. wx.getSystemInfo({
  13. success: function (res) {
  14. wx.setStorageSync("SYSTEMINFO", res);
  15. self.globalData.windowHeight = res.windowHeight;
  16. },
  17. });
  18. },
  19. getAppConfig() {
  20. const self = this;
  21. let params = {};
  22. params.url = api_app_config;
  23. params.data = { type: 2 };
  24. net.req(params, true).then((data) => {
  25. self.globalData.isRelease = !!data.config.tips.add;
  26. });
  27. },
  28. checkForUpdate: function () {
  29. if (wx.canIUse("getUpdateManager")) {
  30. const updateManager = wx.getUpdateManager();
  31. updateManager.onCheckForUpdate(function (res) {
  32. // 请求完新版本信息的回调
  33. if (res.hasUpdate) {
  34. updateManager.onUpdateReady(function () {
  35. wx.showModal({
  36. title: "更新提示",
  37. content: "新版本已经准备好,是否重启应用?",
  38. success: function (res) {
  39. if (res.confirm) {
  40. // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  41. updateManager.applyUpdate();
  42. }
  43. },
  44. });
  45. });
  46. updateManager.onUpdateFailed(function () {
  47. // 新的版本下载失败
  48. wx.showModal({
  49. title: "已经有新版本了哟~",
  50. content: "新版本已经上线啦~,请您删除当前小程序,重新搜索打开哟~",
  51. });
  52. });
  53. }
  54. });
  55. } else {
  56. wx.showModal({
  57. title: "提示",
  58. content:
  59. "当前微信版本过低,无法使用该功能,请升级到最新微信版本后重试。",
  60. });
  61. }
  62. },
  63. globalData: {
  64. isRelease: false,
  65. windowHeight: 0,
  66. },
  67. });