App.vue 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <script>
  2. import {
  3. getToken
  4. } from './utils/auth.js'
  5. import {
  6. getDayTime,
  7. timeToDate
  8. } from '@/utils/date.js'
  9. export default {
  10. onLaunch: function() {
  11. //console.log('App Launch')
  12. const token = getToken()
  13. if (token) {
  14. // #ifdef APP-PLUS
  15. uni.reLaunch({
  16. // url: "/pages/reportForm/index",
  17. url: "/pages/homePage/index",
  18. success: () => {
  19. // #ifdef APP-PLUS
  20. plus.navigator.closeSplashscreen();
  21. // #endif
  22. }
  23. })
  24. // #endif
  25. } else {
  26. uni.reLaunch({
  27. url: "/pages/login/index",
  28. success: () => {
  29. // #ifdef APP-PLUS
  30. plus.navigator.closeSplashscreen();
  31. // #endif
  32. }
  33. })
  34. }
  35. //定时器获得用户的报警信息
  36. setInterval(function(){
  37. let dDate = getDayTime();
  38. let queryParams={
  39. startDate:'',
  40. endDate:''
  41. }
  42. queryParams.startDate = timeToDate(dDate[0])
  43. queryParams.endDate = timeToDate(dDate[1])
  44. uni.$http.get('/mobileAlarm/loadAllAlarmData', queryParams).then(res => {
  45. const data = res.data
  46. if (data.code === 200) {
  47. console.log(data)
  48. }
  49. })
  50. },60000)
  51. //定时器获取未读报警数量
  52. setInterval(function(){
  53. uni.$http.get('/mobileAlarm/getNotReadAlarmUserLogCount').then(res => {
  54. const data = res.data
  55. if (data.code === 200) {
  56. if(data.data.notReadCount>0){
  57. uni.setTabBarBadge({
  58. index:2,
  59. text:data.data.notReadCount + ''
  60. })
  61. }else{
  62. uni.removeTabBarBadge({
  63. index:2
  64. })
  65. }
  66. }
  67. })
  68. },5000)
  69. },
  70. onShow: function() {
  71. //console.log('App Show')
  72. },
  73. onHide: function() {
  74. //console.log('App Hide')
  75. }
  76. }
  77. </script>
  78. <style>
  79. /*每个页面公共css */
  80. @import '@/uni_modules/uview-ui/theme.scss';
  81. uni-button:after {
  82. border: none;
  83. }
  84. uni-page-head .uni-page-head__title{
  85. font-size: 18px !important;
  86. }
  87. </style>