You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
|
|
|
/**
|
|
|
|
* Used to monitor routing changes to change the status of menus and tabs. There is no need to monitor the route, because the route status change is affected by the page rendering time, which will be slow
|
|
|
|
*/
|
|
|
|
|
|
|
|
import type { RouteLocationNormalized } from 'vue-router'
|
|
|
|
import mitt from '@/utils/mitt'
|
|
|
|
import { getRawRoute } from '@/utils'
|
|
|
|
|
|
|
|
const emitter = mitt()
|
|
|
|
|
|
|
|
const key = Symbol('route-change')
|
|
|
|
|
|
|
|
let lastChangeTab: RouteLocationNormalized
|
|
|
|
|
|
|
|
export function setRouteChange(lastChangeRoute: RouteLocationNormalized) {
|
|
|
|
const r = getRawRoute(lastChangeRoute)
|
|
|
|
emitter.emit(key, r)
|
|
|
|
lastChangeTab = r
|
|
|
|
}
|
|
|
|
|
|
|
|
export function listenerRouteChange(callback: (route: RouteLocationNormalized) => void, immediate = true) {
|
|
|
|
emitter.on(key, callback)
|
|
|
|
immediate && lastChangeTab && callback(lastChangeTab)
|
|
|
|
}
|
|
|
|
|
|
|
|
export function removeTabChangeListener() {
|
|
|
|
emitter.clear()
|
|
|
|
}
|