menuConfig.ts 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. import type { DefaultTheme } from 'vitepress/theme'
  2. interface Page {
  3. title: string;
  4. path: string;
  5. child?: Page[];
  6. collapsed?: boolean, // 添加折叠,false:显示,true:隐藏
  7. }
  8. const menu : Page[] = [
  9. {
  10. title: '硬件产品',
  11. path: '/Hardware',
  12. child: [
  13. {
  14. title: 'Gate',
  15. path: '/Gate',
  16. collapsed: false,
  17. child: [
  18. {
  19. title: 'aGate 1.0/1.1',
  20. path: '/aGate_1.0.md'
  21. },
  22. {
  23. title: 'aGate 1.2',
  24. path: '/aGate_1.2.md'
  25. },
  26. {
  27. title: 'aGate 1.3',
  28. path: '/aGate_1.3.md'
  29. },
  30. {
  31. title: 'aGate 1.3.1',
  32. path: '/aGate_1.3.1.md'
  33. },
  34. {
  35. title: 'MSA-C',
  36. path: '/MSA_C.md'
  37. },
  38. {
  39. title: 'MSA-C2',
  40. path: '/MSA_C2.md'
  41. }
  42. ]
  43. },
  44. {
  45. title: 'Power',
  46. path: '/Power',
  47. collapsed: false,
  48. child: [
  49. {
  50. title: 'aPower 1.0',
  51. path: '/aPower_1.0.md'
  52. },
  53. {
  54. title: 'aPower 1.2',
  55. path: '/aPower_1.2.md'
  56. },
  57. {
  58. title: 'aPower 1.3',
  59. path: '/aPower_1.3.md'
  60. },
  61. {
  62. title: 'aPower 2',
  63. path: '/aPower_2.md'
  64. },
  65. {
  66. title: 'aPower S',
  67. path: '/aPower_S.md'
  68. }
  69. ]
  70. },
  71. {
  72. title: '配件',
  73. path: '/Other',
  74. collapsed: false,
  75. child: [
  76. {
  77. title: 'aPbox 1.0',
  78. path: '/aPbox_1.0.md'
  79. },
  80. {
  81. title: 'aPbox 2.0',
  82. path: '/aPbox_2.0.md'
  83. },
  84. {
  85. title: 'Meter Kit',
  86. path: '/MeterKit.md'
  87. },
  88. {
  89. title: 'Generator Module',
  90. path: '/GeneratorModule.md'
  91. },
  92. {
  93. title: 'Split CT',
  94. path: '/SplitCT.md'
  95. }
  96. ]
  97. }
  98. ]
  99. },
  100. {
  101. title: '软件功能',
  102. path: '/Software',
  103. child: [
  104. {
  105. title: '模式管理',
  106. path: '/ModeManagement.md'
  107. },
  108. {
  109. title: 'PCS',
  110. path: '/PCS.md'
  111. },
  112. {
  113. title: '黑启动',
  114. path: '/BlackStart.md'
  115. },
  116. {
  117. title: '光伏调频',
  118. path: '/PV_FreqWatt.md'
  119. },
  120. {
  121. title: '电池加热',
  122. path: '/BatteryHeating.md'
  123. },
  124. {
  125. title: 'SOC均衡',
  126. path: '/SocBalance.md'
  127. },
  128. {
  129. title: '调度配置脚本化',
  130. path: '/ScriptingForSchedulingConfiguration.md'
  131. },
  132. {
  133. title: '能量统计',
  134. path: '/EnergyStatistics.md'
  135. },
  136. {
  137. title: '在线升级(OTA)',
  138. path: '/OTA.md'
  139. },
  140. {
  141. title: '虚拟电厂(VPP)',
  142. path: '/VPP.md'
  143. },
  144. {
  145. title: '参数同步',
  146. path: '/ParamSync.md'
  147. },
  148. {
  149. title: '设备编址',
  150. path: '/AddressAssignment.md'
  151. }
  152. ]
  153. },
  154. {
  155. title: '系统',
  156. path: '/System',
  157. child: [
  158. {
  159. title: '系统搭配',
  160. path: '/SystemConfig.md'
  161. },
  162. {
  163. title: '系统配电',
  164. path: '/SystemDistribution.md'
  165. },
  166. {
  167. title: '告警表',
  168. path: '/AlarmTable.md'
  169. },
  170. {
  171. title: '事件推送',
  172. path: '/EventMessage.md'
  173. }
  174. ]
  175. },
  176. {
  177. title: '其他',
  178. path: '/Other',
  179. child: [
  180. {
  181. title: '资费套餐模版',
  182. path: '/TariffScheduleTemplates.md'
  183. },
  184. {
  185. title: '上位机软件',
  186. path: '/HostSideSoftware.md'
  187. }
  188. ]
  189. }
  190. ]
  191. type NavItem = DefaultTheme.NavItem
  192. type ChildNavItem = (DefaultTheme.NavItemComponent | DefaultTheme.NavItemChildren | DefaultTheme.NavItemWithLink)
  193. type SubChildNavItem = DefaultTheme.NavItemWithLink
  194. type SidebarItem = DefaultTheme.SidebarItem
  195. type SidebarMulti = DefaultTheme.SidebarMulti
  196. interface MenuConfig {
  197. nav?: NavItem[],
  198. sidebar?: SidebarMulti
  199. }
  200. // 遍历导航栏,items最大深度3
  201. function traverseNavigation(pages: Page[]): NavItem[] | undefined {
  202. const navItem = pages.map<NavItem>(item => {
  203. if (item.child && item.child.length > 0) {
  204. const parentPath = item.path
  205. const childNavItem = item.child.map<ChildNavItem>(childItem => {
  206. if (childItem.child && childItem.child.length > 0) {
  207. const childPath = parentPath + childItem.path
  208. const subChildItem = childItem.child.map<SubChildNavItem>(subChildItem => {
  209. return {
  210. text: subChildItem.title,
  211. link: childPath + subChildItem.path
  212. }
  213. })
  214. return {
  215. text: childItem.title,
  216. items: subChildItem
  217. }
  218. } else {
  219. return {
  220. text: childItem.title,
  221. link: parentPath + childItem.path
  222. }
  223. }
  224. })
  225. return {
  226. text: item.title,
  227. items: childNavItem
  228. }
  229. } else {
  230. return {
  231. text: item.title,
  232. link: item.path
  233. }
  234. }
  235. })
  236. if (navItem.length === 0) {
  237. return undefined
  238. } else {
  239. return navItem
  240. }
  241. }
  242. function traverseSidebar(path: string, pages: Page[]): SidebarItem[] {
  243. let config : SidebarItem[] = []
  244. for (const page of pages) {
  245. // 将当前页面加入配置中
  246. if (page.child && page.child.length > 0) {
  247. const childConfig = traverseSidebar(path + page.path, page.child); // 递归遍历子页面
  248. config.push({
  249. text: page.title,
  250. link: path + page.path,
  251. collapsed: page.collapsed,
  252. items: childConfig
  253. })
  254. } else {
  255. config.push({
  256. text: page.title,
  257. link: path + page.path,
  258. collapsed: page.collapsed
  259. })
  260. }
  261. }
  262. return config
  263. }
  264. function traverseMainSidebar(pages: Page[]): SidebarMulti {
  265. let config : SidebarMulti = {}
  266. for (const page of pages) {
  267. // 将当前页面加入配置中
  268. if (page.child && page.child.length > 0) {
  269. const childConfig = traverseSidebar("", page.child); // 递归遍历子页面
  270. config[page.path] = {
  271. base: page.path,
  272. items: [
  273. {
  274. text: page.title,
  275. items: childConfig
  276. }
  277. ]
  278. }
  279. } else {
  280. config[page.path] = {
  281. base: page.path,
  282. items: [
  283. {
  284. text: page.title
  285. }
  286. ]
  287. }
  288. }
  289. }
  290. return config
  291. }
  292. const config : MenuConfig = {
  293. nav: traverseNavigation(menu),
  294. // sidebar: [
  295. // {
  296. // text: '目录',
  297. // items: traverseSidebar('', menu)
  298. // }
  299. // ]
  300. sidebar: traverseMainSidebar(menu)
  301. }
  302. export default config