|
@@ -3,11 +3,6 @@ import store from './store'
|
|
|
import NProgress from 'nprogress' // progress bar
|
|
import NProgress from 'nprogress' // progress bar
|
|
|
import 'nprogress/nprogress.css' // progress bar style
|
|
import 'nprogress/nprogress.css' // progress bar style
|
|
|
import { cancelRequest } from './utils/request'
|
|
import { cancelRequest } from './utils/request'
|
|
|
-import {
|
|
|
|
|
- subscribe,
|
|
|
|
|
- unsubscribe
|
|
|
|
|
-} from './utils/mqtt'
|
|
|
|
|
-import { Notification } from 'element-ui'
|
|
|
|
|
|
|
|
|
|
NProgress.configure({ showSpinner: false }) // NProgress Configuration
|
|
NProgress.configure({ showSpinner: false }) // NProgress Configuration
|
|
|
|
|
|
|
@@ -20,20 +15,16 @@ router.beforeEach((to, from, next) => {
|
|
|
|
|
|
|
|
if (store.getters.isValid) {
|
|
if (store.getters.isValid) {
|
|
|
if (to.path === '/error') {
|
|
if (to.path === '/error') {
|
|
|
- startMonitor()
|
|
|
|
|
// redirect to the home page
|
|
// redirect to the home page
|
|
|
next({ path: '/' })
|
|
next({ path: '/' })
|
|
|
NProgress.done() // hack: https://github.com/PanJiaChen/vue-element-admin/pull/2939
|
|
NProgress.done() // hack: https://github.com/PanJiaChen/vue-element-admin/pull/2939
|
|
|
} else {
|
|
} else {
|
|
|
- to?.meta?.dashboard ? stopMonitor() : startMonitor()
|
|
|
|
|
next()
|
|
next()
|
|
|
}
|
|
}
|
|
|
} else if (whiteList.includes(to.path)) {
|
|
} else if (whiteList.includes(to.path)) {
|
|
|
- to?.meta?.dashboard ? stopMonitor() : startMonitor()
|
|
|
|
|
// in the free login whitelist, go directly
|
|
// in the free login whitelist, go directly
|
|
|
next()
|
|
next()
|
|
|
} else {
|
|
} else {
|
|
|
- stopMonitor()
|
|
|
|
|
// other pages that do not have permission to access are redirected to the login page.
|
|
// other pages that do not have permission to access are redirected to the login page.
|
|
|
next('/error')
|
|
next('/error')
|
|
|
NProgress.done()
|
|
NProgress.done()
|
|
@@ -44,38 +35,3 @@ router.afterEach(() => {
|
|
|
// finish progress bar
|
|
// finish progress bar
|
|
|
NProgress.done()
|
|
NProgress.done()
|
|
|
})
|
|
})
|
|
|
-
|
|
|
|
|
-let notify = false
|
|
|
|
|
-
|
|
|
|
|
-function startMonitor () {
|
|
|
|
|
- if (notify) {
|
|
|
|
|
- return
|
|
|
|
|
- }
|
|
|
|
|
- console.log('start monitor')
|
|
|
|
|
- notify = true
|
|
|
|
|
- subscribe(['dashboard/event'], onMessage)
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-function stopMonitor () {
|
|
|
|
|
- if (!notify) {
|
|
|
|
|
- return
|
|
|
|
|
- }
|
|
|
|
|
- console.log('stop monitor')
|
|
|
|
|
- notify = false
|
|
|
|
|
- unsubscribe(['dashboard/event'], onMessage)
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-function onMessage (topic, message) {
|
|
|
|
|
- if (topic === 'dashboard/event') {
|
|
|
|
|
- message = message && JSON.parse(message)
|
|
|
|
|
- if (message.level > 1) {
|
|
|
|
|
- Notification({
|
|
|
|
|
- type: 'warning',
|
|
|
|
|
- position: 'bottom-right',
|
|
|
|
|
- duration: 0,
|
|
|
|
|
- title: '紧急告警',
|
|
|
|
|
- message: `${message.deviceName} 于 ${message.happenTime} 发生 ${message.bugName}`
|
|
|
|
|
- })
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|