App.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <script>
  2. import { mount, setBar, setLink } from "./utils/tool.js";
  3. export default {
  4. onLaunch: function (options) {
  5. if (options.query) console.log("onLaunch", options.query);
  6. // 使用异步方式初始化,避免阻塞
  7. this.initApp();
  8. // 检查小程序更新
  9. this.checkForUpdate();
  10. },
  11. onShow: function () { },
  12. onHide: function () { },
  13. globalData: {
  14. systemInitIsComplete: null,
  15. HomePageStartRendering: [],
  16. systemclient: "mdyxb",
  17. _initTimer: null // 初始化定时器引用
  18. },
  19. methods: {
  20. // 异步初始化应用
  21. async initApp() {
  22. try {
  23. // 设置系统信息
  24. setBar();
  25. setLink(this.globalData.systemclient);
  26. // 挂载工具函数
  27. mount();
  28. // 设置初始化超时保护(15秒后自动标记完成)
  29. this.globalData._initTimer = setTimeout(() => {
  30. if (!this.globalData.systemInitIsComplete) {
  31. console.warn('初始化超时,标记为完成状态');
  32. this.globalData.systemInitIsComplete = true;
  33. this.globalData.HomePageStartRendering.forEach(v => {
  34. try { v(); } catch (e) { console.error(e); }
  35. });
  36. }
  37. }, 15000);
  38. } catch (error) {
  39. console.error('应用初始化失败:', error);
  40. // 初始化失败时标记完成,避免一直等待
  41. this.globalData.systemInitIsComplete = true;
  42. }
  43. },
  44. // 检查小程序更新
  45. checkForUpdate() {
  46. // #ifdef MP-WEIXIN
  47. const updateManager = uni.getUpdateManager();
  48. updateManager.onCheckForUpdate((res) => {
  49. console.log('检查更新结果:', res);
  50. });
  51. updateManager.onUpdateReady(() => {
  52. uni.showModal({
  53. title: '更新完成',
  54. content: '新版本已下载完成,是否立即重启应用?',
  55. showCancel: true,
  56. cancelText: '稍后重启',
  57. confirmText: '立即重启',
  58. success: (modalRes) => {
  59. if (modalRes.confirm) {
  60. updateManager.applyUpdate();
  61. }
  62. },
  63. fail: () => {
  64. updateManager.applyUpdate();
  65. }
  66. });
  67. });
  68. updateManager.onUpdateFailed(() => {
  69. console.log('新版本下载失败');
  70. uni.showToast({
  71. title: '新版本下载失败,请稍后重试',
  72. icon: 'none'
  73. });
  74. });
  75. // #endif
  76. }
  77. }
  78. };
  79. </script>
  80. <style lang="scss">
  81. /* 注意要写在第一行,同时给style标签加入lang="scss"属性 */
  82. @import "uview-ui/index.scss";
  83. @import "static/iconfont/iconfont.css";
  84. body,
  85. page {
  86. background: #f7f7f7;
  87. font-size: 14px;
  88. }
  89. /deep/.u-tabs {
  90. height: 44px;
  91. // background: #052E5D;
  92. background: #ffffff;
  93. .u-tabs__wrapper__nav {
  94. height: 44px;
  95. align-items: center;
  96. .u-tabs__wrapper__nav__item {
  97. height: 44px;
  98. flex-shrink: 0 !important;
  99. .u-tabs__wrapper__nav__item__text {
  100. font-size: 15px;
  101. }
  102. }
  103. }
  104. }
  105. </style>