App.uvue.ts 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. let firstBackTime = 0
  2. const __sfc__ = defineApp({
  3. onLaunch() {
  4. console.log('App Launch', " at App.uvue:7")
  5. // 1. 从本地缓存读取 token(或用户信息)
  6. const token = uni.getStorageSync('token');
  7. console.log(token, 'token', " at App.uvue:10");
  8. // 2. 判断登录态
  9. if (token === '' || token === null || token === 'undefined') {
  10. // 未登录:跳转到默认登录页
  11. uni.reLaunch({ url: '/pages/login/login' })
  12. } else {
  13. // 已登录:正常进入首页
  14. uni.switchTab({ url: '/pages/homepage/console' })
  15. }
  16. },
  17. onShow() {
  18. console.log('App Show', " at App.uvue:22")
  19. },
  20. onHide() {
  21. console.log('App Hide', " at App.uvue:25")
  22. },
  23. onLastPageBackPress() {
  24. console.log('App LastPageBackPress', " at App.uvue:29")
  25. if (firstBackTime == 0) {
  26. uni.showToast({
  27. title: '再按一次退出应用',
  28. position: 'bottom',
  29. })
  30. firstBackTime = Date.now()
  31. setTimeout(() => {
  32. firstBackTime = 0
  33. }, 2000)
  34. } else if (Date.now() - firstBackTime < 2000) {
  35. firstBackTime = Date.now()
  36. uni.exit()
  37. }
  38. },
  39. onExit() {
  40. console.log('App Exit', " at App.uvue:46")
  41. },
  42. })
  43. export default __sfc__
  44. const GenAppStyles = [_uM([["uni-row", _pS(_uM([["flexDirection", "row"]]))], ["uni-column", _pS(_uM([["flexDirection", "column"]]))]])]