App.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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. APK 与 WGT 更新都由全局更新服务处理,不依赖登录页、首页或其他业务页面挂载组件。
  73. * 3. 放在这里还能保证热更新和数据库初始化、scheme 监听这类“应用级逻辑”处于同一层级,
  74. * 后续维护时更容易看清启动链路。
  75. *
  76. * 为什么这里不 await:
  77. * 1. 原有 onLaunch 里的数据库初始化本身就是非阻塞调用,项目没有把启动流程串行化。
  78. * 2. 热更新检查失败时我们希望“静默降级,不阻断原有启动”。
  79. * 3. 因此这里直接触发即可,让原有启动逻辑保持原样继续往下走。
  80. */
  81. runWgtHotUpdate({ forceCheck: true });
  82. // #endif
  83. },
  84. onExit: () => {
  85. // #ifdef APP-PLUS
  86. stopHotUpdatePolling();
  87. // #endif
  88. // #ifdef APP
  89. // sqlite.closeDB('app')
  90. // #endif
  91. },
  92. onShow: function () {
  93. // #ifdef APP-PLUS
  94. // 进入前台立即检查一次,并在停留前台期间每 30 秒轮询。
  95. runWgtHotUpdate();
  96. startHotUpdatePolling();
  97. // #endif
  98. },
  99. onHide: function () {
  100. // #ifdef APP-PLUS
  101. // 后台不轮询,避免无效耗电和网络请求;再次进入前台会立即恢复。
  102. stopHotUpdatePolling();
  103. // #endif
  104. }
  105. };
  106. </script>
  107. <style lang="scss">
  108. /*每个页面公共css */
  109. @import './style/common.scss';
  110. @import './style/fonts.scss';
  111. /* uniapp组件 样式覆盖 */
  112. uni-button[type='primary'] {
  113. background: #004098 !important;
  114. }
  115. uni-button[disabled][type='primary'] {
  116. background: rgba(0, 64, 152, 0.6) !important;
  117. }
  118. uni-button[type='primary'][plain] {
  119. color: #004098 !important;
  120. border: 1px solid #004098 !important;
  121. background-color: transparent !important;
  122. }
  123. uni-page-body,
  124. body {
  125. width: 100%;
  126. height: 100%;
  127. box-sizing: border-box;
  128. position: relative;
  129. }
  130. :deep(.uni-tabbar-bottom .uni-tabbar) {
  131. box-shadow: 0px -2px 10px 0px rgba(0, 0, 0, 0.1);
  132. // padding-top: 9px !important;
  133. // padding-bottom: 10px !important;
  134. box-sizing: border-box;
  135. .uni-tabbar__icon {
  136. margin-top: 4px;
  137. }
  138. }
  139. .page {
  140. position: relative;
  141. padding: 20rpx;
  142. padding-top: 0;
  143. box-sizing: border-box;
  144. background: #f3f5f9;
  145. width: 100%;
  146. height: 100%;
  147. font-family: PingFangSC, PingFang SC;
  148. overflow: hidden;
  149. }
  150. .page-nopadding {
  151. position: relative;
  152. box-sizing: border-box;
  153. background: #f3f5f9;
  154. width: 100%;
  155. height: 100%;
  156. font-family: PingFangSC, PingFang SC;
  157. overflow: hidden;
  158. }
  159. .page-back {
  160. background-image: url('/static/common/1.png');
  161. background-repeat: no-repeat;
  162. background-size: 100% 100%;
  163. position: fixed;
  164. top: 0;
  165. left: 0;
  166. width: 100%;
  167. height: 350px;
  168. z-index: 0;
  169. }
  170. .navgator {
  171. width: 100%;
  172. height: $header-height;
  173. line-height: 1;
  174. position: fixed;
  175. top: $header-top-height;
  176. left: 0;
  177. background-color: transparent !important;
  178. padding-top: calc(7px + env(safe-area-inset-top));
  179. box-sizing: border-box;
  180. z-index: 22;
  181. .nav-title {
  182. font-family: PingFang-SC, PingFang-SC;
  183. font-weight: bold;
  184. font-size: 16px;
  185. color: #ffffff;
  186. line-height: 22px;
  187. text-align: right;
  188. font-style: normal;
  189. }
  190. .nav-back {
  191. width: 40rpx;
  192. line-height: 1;
  193. position: absolute;
  194. left: 20rpx;
  195. .uni-icons {
  196. color: #fff !important;
  197. }
  198. }
  199. }
  200. .page-content {
  201. position: relative;
  202. box-sizing: border-box;
  203. width: 100%;
  204. height: calc(100% - $header-height - $header-top-height);
  205. margin-top: calc($header-height + $header-top-height);
  206. overflow: hidden;
  207. overflow-y: auto;
  208. }
  209. .item {
  210. box-sizing: border-box;
  211. }
  212. </style>