新增
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
import type { Router } from 'vue-router'
|
||||
|
||||
const modules = import.meta.glob('./*.ts', { eager: true })
|
||||
|
||||
export function registerRouteGuard(router: Router) {
|
||||
Object.keys(modules).forEach((key) => {
|
||||
const fn = (modules[key] as any).default
|
||||
if (typeof fn === 'function') {
|
||||
fn(router)
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
import type { Router } from 'vue-router'
|
||||
|
||||
import useAppStore from '@/stores/modules/app'
|
||||
|
||||
export default function createInitGuard(router: Router) {
|
||||
router.beforeEach(async () => {
|
||||
const appStore = useAppStore()
|
||||
if (Object.keys(appStore.config).length == 0) {
|
||||
// 获取配置
|
||||
const data: any = await appStore.getConfig()
|
||||
|
||||
// 设置网站logo
|
||||
let favicon: HTMLLinkElement = document.querySelector('link[rel="icon"]')!
|
||||
if (favicon) {
|
||||
favicon.href = data.web_favicon
|
||||
}
|
||||
favicon = document.createElement('link')
|
||||
favicon.rel = 'icon'
|
||||
favicon.href = data.web_favicon
|
||||
document.head.appendChild(favicon)
|
||||
}
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user