App.uvue 861 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <script lang="uts">
  2. let firstBackTime = 0
  3. export default {
  4. onLaunch: function () {
  5. console.log('App Launch')
  6. },
  7. onShow: function () {
  8. console.log('App Show')
  9. },
  10. onHide: function () {
  11. console.log('App Hide')
  12. },
  13. // #ifdef APP-ANDROID
  14. onLastPageBackPress: function () {
  15. console.log('App LastPageBackPress')
  16. if (firstBackTime == 0) {
  17. uni.showToast({
  18. title: '再按一次退出应用',
  19. position: 'bottom',
  20. })
  21. firstBackTime = Date.now()
  22. setTimeout(() => {
  23. firstBackTime = 0
  24. }, 2000)
  25. } else if (Date.now() - firstBackTime < 2000) {
  26. firstBackTime = Date.now()
  27. uni.exit()
  28. }
  29. },
  30. // #endif
  31. onExit: function () {
  32. console.log('App Exit')
  33. },
  34. }
  35. </script>
  36. <style>
  37. /*每个页面公共css */
  38. .uni-row {
  39. flex-direction: row;
  40. }
  41. .uni-column {
  42. flex-direction: column;
  43. }
  44. </style>