| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316 |
- import type { DefaultTheme } from 'vitepress/theme'
- interface Page {
- title: string;
- path: string;
- child?: Page[];
- collapsed?: boolean, // 添加折叠,false:显示,true:隐藏
- }
- const menu : Page[] = [
- {
- title: '硬件产品',
- path: '/Hardware',
- child: [
- {
- title: 'Gate',
- path: '/Gate',
- collapsed: false,
- child: [
- {
- title: 'aGate 1.0/1.1',
- path: '/aGate_1.0.md'
- },
- {
- title: 'aGate 1.2',
- path: '/aGate_1.2.md'
- },
- {
- title: 'aGate 1.3',
- path: '/aGate_1.3.md'
- },
- {
- title: 'aGate 1.3.1',
- path: '/aGate_1.3.1.md'
- },
- {
- title: 'MSA-C',
- path: '/MSA_C.md'
- },
- {
- title: 'MSA-C2',
- path: '/MSA_C2.md'
- }
- ]
- },
- {
- title: 'Power',
- path: '/Power',
- collapsed: false,
- child: [
- {
- title: 'aPower 1.0',
- path: '/aPower_1.0.md'
- },
- {
- title: 'aPower 1.2',
- path: '/aPower_1.2.md'
- },
- {
- title: 'aPower 1.3',
- path: '/aPower_1.3.md'
- },
- {
- title: 'aPower 2',
- path: '/aPower_2.md'
- },
- {
- title: 'aPower S',
- path: '/aPower_S.md'
- }
- ]
- },
- {
- title: '配件',
- path: '/Other',
- collapsed: false,
- child: [
- {
- title: 'aPbox 1.0',
- path: '/aPbox_1.0.md'
- },
- {
- title: 'aPbox 2.0',
- path: '/aPbox_2.0.md'
- },
- {
- title: 'Meter Kit',
- path: '/MeterKit.md'
- },
- {
- title: 'Generator Module',
- path: '/GeneratorModule.md'
- },
- {
- title: 'Split CT',
- path: '/SplitCT.md'
- }
- ]
- }
- ]
- },
- {
- title: '软件功能',
- path: '/Software',
- child: [
- {
- title: '模式管理',
- path: '/ModeManagement.md'
- },
- {
- title: 'PCS',
- path: '/PCS.md'
- },
- {
- title: '黑启动',
- path: '/BlackStart.md'
- },
- {
- title: '光伏调频',
- path: '/PV_FreqWatt.md'
- },
- {
- title: '电池加热',
- path: '/BatteryHeating.md'
- },
- {
- title: 'SOC均衡',
- path: '/SocBalance.md'
- },
- {
- title: '调度配置脚本化',
- path: '/ScriptingForSchedulingConfiguration.md'
- },
- {
- title: '能量统计',
- path: '/EnergyStatistics.md'
- },
- {
- title: '在线升级(OTA)',
- path: '/OTA.md'
- },
- {
- title: '虚拟电厂(VPP)',
- path: '/VPP.md'
- },
- {
- title: '参数同步',
- path: '/ParamSync.md'
- },
- {
- title: '设备编址',
- path: '/AddressAssignment.md'
- }
- ]
- },
- {
- title: '系统',
- path: '/System',
- child: [
- {
- title: '系统搭配',
- path: '/SystemConfig.md'
- },
- {
- title: '系统配电',
- path: '/SystemDistribution.md'
- },
- {
- title: '告警表',
- path: '/AlarmTable.md'
- },
- {
- title: '事件推送',
- path: '/EventMessage.md'
- }
- ]
- },
- {
- title: '其他',
- path: '/Other',
- child: [
- {
- title: '资费套餐模版',
- path: '/TariffScheduleTemplates.md'
- },
- {
- title: '上位机软件',
- path: '/HostSideSoftware.md'
- }
- ]
- }
- ]
- type NavItem = DefaultTheme.NavItem
- type ChildNavItem = (DefaultTheme.NavItemComponent | DefaultTheme.NavItemChildren | DefaultTheme.NavItemWithLink)
- type SubChildNavItem = DefaultTheme.NavItemWithLink
- type SidebarItem = DefaultTheme.SidebarItem
- type SidebarMulti = DefaultTheme.SidebarMulti
- interface MenuConfig {
- nav?: NavItem[],
- sidebar?: SidebarMulti
- }
- // 遍历导航栏,items最大深度3
- function traverseNavigation(pages: Page[]): NavItem[] | undefined {
- const navItem = pages.map<NavItem>(item => {
- if (item.child && item.child.length > 0) {
- const parentPath = item.path
- const childNavItem = item.child.map<ChildNavItem>(childItem => {
- if (childItem.child && childItem.child.length > 0) {
- const childPath = parentPath + childItem.path
- const subChildItem = childItem.child.map<SubChildNavItem>(subChildItem => {
- return {
- text: subChildItem.title,
- link: childPath + subChildItem.path
- }
- })
- return {
- text: childItem.title,
- items: subChildItem
- }
- } else {
- return {
- text: childItem.title,
- link: parentPath + childItem.path
- }
- }
- })
- return {
- text: item.title,
- items: childNavItem
- }
- } else {
- return {
- text: item.title,
- link: item.path
- }
- }
- })
- if (navItem.length === 0) {
- return undefined
- } else {
- return navItem
- }
- }
- function traverseSidebar(path: string, pages: Page[]): SidebarItem[] {
- let config : SidebarItem[] = []
- for (const page of pages) {
- // 将当前页面加入配置中
-
- if (page.child && page.child.length > 0) {
- const childConfig = traverseSidebar(path + page.path, page.child); // 递归遍历子页面
- config.push({
- text: page.title,
- link: path + page.path,
- collapsed: page.collapsed,
- items: childConfig
- })
- } else {
- config.push({
- text: page.title,
- link: path + page.path,
- collapsed: page.collapsed
- })
- }
- }
- return config
- }
- function traverseMainSidebar(pages: Page[]): SidebarMulti {
- let config : SidebarMulti = {}
- for (const page of pages) {
- // 将当前页面加入配置中
-
- if (page.child && page.child.length > 0) {
- const childConfig = traverseSidebar("", page.child); // 递归遍历子页面
- config[page.path] = {
- base: page.path,
- items: [
- {
- text: page.title,
- items: childConfig
- }
- ]
- }
- } else {
- config[page.path] = {
- base: page.path,
- items: [
- {
- text: page.title
- }
- ]
- }
- }
- }
- return config
- }
- const config : MenuConfig = {
- nav: traverseNavigation(menu),
- // sidebar: [
- // {
- // text: '目录',
- // items: traverseSidebar('', menu)
- // }
- // ]
- sidebar: traverseMainSidebar(menu)
- }
- export default config
|