用工小程序前端代码
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

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