App.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. <script>
  2. import { initAppDatabase } from '@/utils/appDb';
  3. import { getAccessToken } from '@/utils/auth';
  4. import {
  5. HOT_UPDATE_CHECK_INTERVAL,
  6. runWgtHotUpdate
  7. } from '@/utils/hot-update';
  8. import { useDataDictStore } from '@/store/modules/dataDict';
  9. let hotUpdateTimer = null;
  10. const stopHotUpdatePolling = () => {
  11. if (hotUpdateTimer) {
  12. clearInterval(hotUpdateTimer);
  13. hotUpdateTimer = null;
  14. }
  15. };
  16. const startHotUpdatePolling = () => {
  17. stopHotUpdatePolling();
  18. hotUpdateTimer = setInterval(() => {
  19. runWgtHotUpdate();
  20. }, HOT_UPDATE_CHECK_INTERVAL);
  21. };
  22. export default {
  23. onLaunch: (options) => {
  24. // 已登录用户在应用启动时预加载字典,避免依赖某个具体页面初始化。
  25. if (getAccessToken()) {
  26. useDataDictStore().loadDataDictList();
  27. }
  28. // #ifdef APP
  29. initAppDatabase();
  30. // #endif
  31. console.log('App Launch');
  32. console.log(options);
  33. // uni.onNetworkStatusChange((event) => {
  34. // console.log(event)
  35. // })
  36. // #ifdef H5
  37. // 保存钉钉消息传递的参数,参数可能存在path或query中
  38. if (options.query.type) {
  39. uni.setStorageSync('dingTalkJson', JSON.stringify(options.query));
  40. } else if (options.path && options.path.includes('type')) {
  41. const path = options.path;
  42. const args = path.split('&');
  43. const params = {};
  44. args.forEach((arg) => {
  45. const [key, value] = arg.split('=');
  46. if (key && value) {
  47. params[key] = value;
  48. }
  49. console.log(params);
  50. });
  51. uni.setStorageSync('dingTalkJson', JSON.stringify(params));
  52. }
  53. // #endif
  54. // #ifdef APP
  55. plus.globalEvent.addEventListener('newintent', () => {
  56. const args = plus.runtime.arguments;
  57. const parts = args.match(/^deepoil:\/\/([^/]+)\/([^/]+)$/);
  58. if (parts) {
  59. const type = parts[1];
  60. const id = parts[2];
  61. uni.setStorageSync('dingTalkJson', JSON.stringify({ type, id }));
  62. console.log('App: dingTalkJson -> ' + uni.getStorageSync('dingTalkJson'));
  63. }
  64. });
  65. // #endif
  66. // #ifdef APP-PLUS
  67. /**
  68. * 这里是本次新增的 .wgt 热更新入口。
  69. *
  70. * 为什么放在 App.vue 的 onLaunch:
  71. * 1. 这是整个项目真正的应用启动入口,热更新要尽量早执行,就应该接在这里。
  72. * 2. 现有项目的旧升级逻辑写在页面组件里,只会在登录页 / 首页 mounted 后才触发,
  73. * 对“启动即检查热更新”这个目标来说太晚了。
  74. * 3. 放在这里还能保证热更新和数据库初始化、scheme 监听这类“应用级逻辑”处于同一层级,
  75. * 后续维护时更容易看清启动链路。
  76. *
  77. * 为什么这里不 await:
  78. * 1. 原有 onLaunch 里的数据库初始化本身就是非阻塞调用,项目没有把启动流程串行化。
  79. * 2. 热更新检查失败时我们希望“静默降级,不阻断原有启动”。
  80. * 3. 因此这里直接触发即可,让原有启动逻辑保持原样继续往下走。
  81. */
  82. runWgtHotUpdate({ forceCheck: true });
  83. // #endif
  84. },
  85. onExit: () => {
  86. // #ifdef APP-PLUS
  87. stopHotUpdatePolling();
  88. // #endif
  89. // #ifdef APP
  90. // sqlite.closeDB('app')
  91. // #endif
  92. },
  93. onShow: function () {
  94. // #ifdef APP-PLUS
  95. // 进入前台立即检查一次,并在停留前台期间每 30 秒轮询。
  96. runWgtHotUpdate();
  97. startHotUpdatePolling();
  98. // #endif
  99. },
  100. onHide: function () {
  101. // #ifdef APP-PLUS
  102. // 后台不轮询,避免无效耗电和网络请求;再次进入前台会立即恢复。
  103. stopHotUpdatePolling();
  104. // #endif
  105. }
  106. };
  107. </script>
  108. <style lang="scss">
  109. /*每个页面公共css */
  110. @import './style/common.scss';
  111. @import './style/fonts.scss';
  112. /* uniapp组件 样式覆盖 */
  113. uni-button[type='primary'] {
  114. background: #004098 !important;
  115. }
  116. uni-button[disabled][type='primary'] {
  117. background: rgba(0, 64, 152, 0.6) !important;
  118. }
  119. uni-button[type='primary'][plain] {
  120. color: #004098 !important;
  121. border: 1px solid #004098 !important;
  122. background-color: transparent !important;
  123. }
  124. uni-page-body,
  125. body {
  126. width: 100%;
  127. height: 100%;
  128. box-sizing: border-box;
  129. position: relative;
  130. }
  131. :deep(.uni-tabbar-bottom .uni-tabbar) {
  132. box-shadow: 0px -2px 10px 0px rgba(0, 0, 0, 0.1);
  133. // padding-top: 9px !important;
  134. // padding-bottom: 10px !important;
  135. box-sizing: border-box;
  136. .uni-tabbar__icon {
  137. margin-top: 4px;
  138. }
  139. }
  140. .page {
  141. position: relative;
  142. padding: 20rpx;
  143. padding-top: 0;
  144. box-sizing: border-box;
  145. background: #f3f5f9;
  146. width: 100%;
  147. height: 100%;
  148. font-family: PingFangSC, PingFang SC;
  149. overflow: hidden;
  150. }
  151. .page-nopadding {
  152. position: relative;
  153. box-sizing: border-box;
  154. background: #f3f5f9;
  155. width: 100%;
  156. height: 100%;
  157. font-family: PingFangSC, PingFang SC;
  158. overflow: hidden;
  159. }
  160. .page-back {
  161. background-image: url('/static/common/1.png');
  162. background-repeat: no-repeat;
  163. background-size: 100% 100%;
  164. position: fixed;
  165. top: 0;
  166. left: 0;
  167. width: 100%;
  168. height: 350px;
  169. z-index: 0;
  170. }
  171. .navgator {
  172. width: 100%;
  173. height: $header-height;
  174. line-height: 1;
  175. position: fixed;
  176. top: $header-top-height;
  177. left: 0;
  178. background-color: transparent !important;
  179. padding-top: calc(7px + env(safe-area-inset-top));
  180. box-sizing: border-box;
  181. z-index: 22;
  182. .nav-title {
  183. font-family: PingFang-SC, PingFang-SC;
  184. font-weight: bold;
  185. font-size: 16px;
  186. color: #ffffff;
  187. line-height: 22px;
  188. text-align: right;
  189. font-style: normal;
  190. }
  191. .nav-back {
  192. width: 40rpx;
  193. line-height: 1;
  194. position: absolute;
  195. left: 20rpx;
  196. .uni-icons {
  197. color: #fff !important;
  198. }
  199. }
  200. }
  201. .page-content {
  202. position: relative;
  203. box-sizing: border-box;
  204. width: 100%;
  205. height: calc(100% - $header-height - $header-top-height);
  206. margin-top: calc($header-height + $header-top-height);
  207. overflow: hidden;
  208. overflow-y: auto;
  209. }
  210. .item {
  211. box-sizing: border-box;
  212. }
  213. </style>