update.js 661 B

123456789101112131415161718192021222324252627282930
  1. module.exports = {
  2. update: update
  3. }
  4. var isShowed = false;
  5. //检测版本是否更新
  6. function update() {
  7. if (isShowed) {
  8. return;
  9. }
  10. //检测版本更新
  11. const manager = wx.getUpdateManager();
  12. //检测版本是否更新
  13. manager.onCheckForUpdate(function (e) {});
  14. //版本更新
  15. manager.onUpdateReady(function (e) {
  16. isShowed = true;
  17. wx.showModal({
  18. title: '更新提示',
  19. content: '新版本已准备好,是否重启应用?',
  20. success: function (res) {
  21. if (res.confirm) {
  22. manager.applyUpdate();
  23. }
  24. }
  25. });
  26. });
  27. //版本更新失败
  28. manager.onUpdateFailed(function (e) {});
  29. };