App.vue 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <script setup>
  2. import { onLaunch, onShow, onHide } from '@dcloudio/uni-app'
  3. import {
  4. store
  5. } from '@/store/index.js'
  6. import { useGlobalEventRemove, useInit } from '@/utils/useBarcodeModule.js'
  7. import { useRouteMonitor } from '@/utils/useRouteMonitor.js'
  8. onLaunch(() => {
  9. console.log('App Launch')
  10. // 尝试去获取本地的 token 和用户信息,填充到 store 中
  11. if (!store.token) {
  12. let token = uni.getStorageSync('token')
  13. if (token) {
  14. store.setToken(token)
  15. let userInfo = uni.getStorageSync('userInfo')
  16. if (userInfo) {
  17. if (userInfo.userId) {
  18. store.setUserInfo(userInfo)
  19. }
  20. }
  21. }
  22. }
  23. // #ifdef APP-PLUS
  24. // 初始化扫码模块
  25. useInit()
  26. // #endif
  27. })
  28. onShow(() => {
  29. console.log('App Show');
  30. // #ifdef APP-PLUS
  31. // 页面显示时重新添加全局监听
  32. useRouteMonitor((url, from) => {
  33. console.log('onShow', url, from)
  34. // #ifdef APP-PLUS
  35. // 页面隐藏时移除全局监听
  36. useGlobalEventRemove()
  37. // #endif
  38. })
  39. // #endif
  40. })
  41. onHide(() => {
  42. console.log('App Hide');
  43. })
  44. </script>
  45. <style lang="scss">
  46. @import "@/uni_modules/uview-plus/index.scss";
  47. @import "@/static/css/mystyle.css";
  48. @import '@/static/css/common.scss';
  49. /*每个页面公共css */
  50. page {
  51. background: #F5F6FA;
  52. height: 100%;
  53. }
  54. </style>