Files
jczxw-pc/app/plugins/fetch-menu.ts
2026-05-10 01:33:46 +08:00

25 lines
758 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { getSiteInfo } from '@/api/cms/cmsWebsite'
import { useMenu, mapNavItem } from '@/composables/useMenu'
import type { CmsNavigation } from '@/api/cms/cmsNavigation/model'
/**
* 应用启动时获取站点信息(含导航菜单),写入 useMenu() 状态
*/
export default defineNuxtPlugin(async () => {
const menu = useMenu()
// 如果已有数据,跳过
if (menu.value.length) return
try {
const data = await getSiteInfo()
// getSiteInfo 返回 CmsWebsite其中 topNavs 是 CmsNavigation[]
const topNavs = (data as any)?.topNavs as CmsNavigation[] | undefined
if (topNavs?.length) {
menu.value = mapNavItem(topNavs)
}
} catch (e) {
console.warn('[fetch-menu] 获取导航菜单失败', e)
}
})