App.vue 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <script>
  2. export default {
  3. data() {
  4. return {
  5. timer: null,
  6. isOpenRfid: false
  7. }
  8. },
  9. onLaunch: function() {
  10. /* 无操作15分支后自动登出 */
  11. this.$storage.setStorage('outTime', new Date().getTime())
  12. setInterval(() => {
  13. let routes = getCurrentPages()
  14. if (routes[0]) {
  15. let curRoute = routes[routes.length - 1].route
  16. if (curRoute !== 'pages/login/login') {
  17. let outTime = this.$storage.getStorageSync('outTime')
  18. if ((new Date().getTime() - outTime) > 900000) {
  19. this.$http.LoginQuit().then(res => {
  20. if(res.code === 0) {
  21. this.$storage.removeStorageSync('token')
  22. this.$utils.openNew('/pages/login/login')
  23. }
  24. })
  25. }
  26. }
  27. }
  28. }, 60000)
  29. },
  30. onShow: function() {
  31. console.log(plus.runtime.version)
  32. clearTimeout(this.timer)
  33. if (!this.isOpenRfid) {
  34. this.$pda.uhfInit().then(() => {
  35. this.isOpenRfid = true
  36. }).catch(() => {
  37. {
  38. this.$msg.showToast('RFID初始化失败,请重启应用!')
  39. }
  40. })
  41. }
  42. uni.getNetworkType({
  43. success: res => {
  44. if (res.networkType === 'none') {
  45. this.$msg.showToast('当前无网络连接')
  46. }
  47. }
  48. })
  49. uni.onNetworkStatusChange(res => {
  50. if (!res.isConnected) {
  51. this.$msg.showToast('网络连接已断开')
  52. }
  53. })
  54. },
  55. onHide: function() {
  56. console.log('App Hide')
  57. // 一分钟未操作关闭rfid扫描 防止耗电量过高
  58. this.timer = setTimeout(() => {
  59. this.$pda.uhfDestroy()
  60. this.isOpenRfid = false
  61. console.log('rfid colse ------------')
  62. }, 60000)
  63. }
  64. }
  65. </script>
  66. <style lang="scss">
  67. /*每个页面公共css */
  68. @import "uview-ui/index.scss";
  69. @import "./static/css/global.scss";
  70. </style>