App.vue 5.3 KB

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