|
|
@@ -1,6 +1,7 @@
|
|
|
import { ref, Ref, onUnmounted } from 'vue'
|
|
|
import { onBeforeRouteLeave } from 'vue-router'
|
|
|
import { v4 } from 'uuid'
|
|
|
+import { useLoginStore } from '@/stores'
|
|
|
|
|
|
// 缓存已打开的组件实例
|
|
|
const componentInstanceMap = new Map<string, Ref>()
|
|
|
@@ -12,6 +13,7 @@ const componentInstanceMap = new Map<string, Ref>()
|
|
|
* @returns
|
|
|
*/
|
|
|
export function useComponent(callback?: (componentName?: string) => void, routeListener = true) {
|
|
|
+ const loginStore = useLoginStore()
|
|
|
const uuid = v4()
|
|
|
const components = new Set<string>() // 已打开的组件列表
|
|
|
const componentId = ref<string>() // 当前显示的组件
|
|
|
@@ -84,10 +86,15 @@ export function useComponent(callback?: (componentName?: string) => void, routeL
|
|
|
* 路由守卫,离开页面前关闭组件
|
|
|
*/
|
|
|
onBeforeRouteLeave((to, from, next) => {
|
|
|
- if (closeComponentEach()) {
|
|
|
- next()
|
|
|
+ if ((to.meta.ignoreAuth && from.meta.ignoreAuth) || loginStore.token) {
|
|
|
+ if (closeComponentEach()) {
|
|
|
+ next()
|
|
|
+ } else {
|
|
|
+ next(false)
|
|
|
+ }
|
|
|
} else {
|
|
|
- next(false)
|
|
|
+ components.clear()
|
|
|
+ next()
|
|
|
}
|
|
|
})
|
|
|
|