用工小程序前端代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.3 KiB

6 months ago
3 months ago
6 months ago
3 months ago
6 months ago
3 months ago
6 months ago
  1. <script>
  2. export default {
  3. onLaunch: function() {
  4. this.checkUpdate();
  5. },
  6. onShow: function() {
  7. },
  8. onHide: function() {
  9. },
  10. methods: {
  11. checkUpdate() {
  12. if (wx.getUpdateManager) {
  13. const updateManager = wx.getUpdateManager();
  14. // 监听是否有新版本
  15. updateManager.onCheckForUpdate((res) => {
  16. console.log("是否有新版本:", res.hasUpdate);
  17. });
  18. // 监听新版本下载完成
  19. updateManager.onUpdateReady(() => {
  20. wx.showModal({
  21. title: "更新提示",
  22. content: "新版本已经准备好,是否重启应用?",
  23. success: (res) => {
  24. if (res.confirm) {
  25. updateManager.applyUpdate(); // 强制应用新版本
  26. }
  27. },
  28. });
  29. });
  30. // 监听更新失败
  31. updateManager.onUpdateFailed(() => {
  32. wx.showModal({
  33. title: "更新失败",
  34. content: "请删除小程序后重新打开。",
  35. });
  36. });
  37. } else {
  38. console.log("当前基础库版本不支持更新管理");
  39. }
  40. },
  41. }
  42. }
  43. </script>
  44. <style lang="scss">
  45. @import "@/uni_modules/uview-ui/index.scss";
  46. @import './styles/index.scss';
  47. </style>