app.js 1.7 KB

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