App.uvue 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. }
  13. else {
  14. // 已登录:正常进入首页
  15. uni.switchTab({ url: '/pages/homepage/console' });
  16. }
  17. },
  18. onShow() {
  19. console.log('App Show', " at App.uvue:22");
  20. },
  21. onHide() {
  22. console.log('App Hide', " at App.uvue:25");
  23. },
  24. onLastPageBackPress() {
  25. console.log('App LastPageBackPress', " at App.uvue:29");
  26. if (firstBackTime == 0) {
  27. uni.showToast({
  28. title: '再按一次退出应用',
  29. position: 'bottom',
  30. });
  31. firstBackTime = Date.now();
  32. setTimeout(() => {
  33. firstBackTime = 0;
  34. }, 2000);
  35. }
  36. else if (Date.now() - firstBackTime < 2000) {
  37. firstBackTime = Date.now();
  38. uni.exit();
  39. }
  40. },
  41. onExit() {
  42. console.log('App Exit', " at App.uvue:46");
  43. },
  44. });
  45. export default __sfc__;
  46. const GenAppStyles = [_uM([["uni-row", _pS(_uM([["flexDirection", "row"]]))], ["uni-column", _pS(_uM([["flexDirection", "column"]]))]])];
  47. //# sourceMappingURL=App.uvue.map