App.vue 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. clearTimeout(this.timer)
  32. if (!this.isOpenRfid) {
  33. this.$pda.uhfInit().then(() => {
  34. this.isOpenRfid = true
  35. }).catch(() => {
  36. {
  37. this.$msg.showToast('RFID初始化失败,请重启应用!')
  38. }
  39. })
  40. }
  41. uni.getNetworkType({
  42. success: res => {
  43. if (res.networkType === 'none') {
  44. this.$msg.showToast('当前无网络连接')
  45. }
  46. }
  47. })
  48. uni.onNetworkStatusChange(res => {
  49. if (!res.isConnected) {
  50. this.$msg.showToast('网络连接已断开')
  51. }
  52. })
  53. },
  54. onHide: function() {
  55. console.log('App Hide')
  56. // 一分钟未操作关闭rfid扫描 防止耗电量过高
  57. this.timer = setTimeout(() => {
  58. this.$pda.uhfDestroy()
  59. this.isOpenRfid = false
  60. console.log('rfid colse ------------')
  61. }, 60000)
  62. }
  63. }
  64. </script>
  65. <style lang="scss">
  66. /*每个页面公共css */
  67. @import "uview-ui/index.scss";
  68. @import "./static/css/global.scss";
  69. </style>