useNavigation.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. Copyright (C) 2025 QuantumNous
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU Affero General Public License as
  5. published by the Free Software Foundation, either version 3 of the
  6. License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Affero General Public License for more details.
  11. You should have received a copy of the GNU Affero General Public License
  12. along with this program. If not, see <https://www.gnu.org/licenses/>.
  13. For commercial licensing, please contact support@quantumnous.com
  14. */
  15. import { useMemo } from 'react';
  16. export const useNavigation = (t, docsLink, headerNavModules) => {
  17. const mainNavLinks = useMemo(
  18. () => {
  19. // 默认配置,如果没有传入配置则显示所有模块
  20. const defaultModules = {
  21. home: true,
  22. console: true,
  23. pricing: true,
  24. docs: true,
  25. about: true,
  26. };
  27. // 使用传入的配置或默认配置
  28. const modules = headerNavModules || defaultModules;
  29. const allLinks = [
  30. {
  31. text: t('首页'),
  32. itemKey: 'home',
  33. to: '/',
  34. },
  35. {
  36. text: t('控制台'),
  37. itemKey: 'console',
  38. to: '/console',
  39. },
  40. {
  41. text: t('模型广场'),
  42. itemKey: 'pricing',
  43. to: '/pricing',
  44. },
  45. ...(docsLink
  46. ? [
  47. {
  48. text: t('文档'),
  49. itemKey: 'docs',
  50. isExternal: true,
  51. externalLink: docsLink,
  52. },
  53. ]
  54. : []),
  55. {
  56. text: t('关于'),
  57. itemKey: 'about',
  58. to: '/about',
  59. },
  60. ];
  61. // 根据配置过滤导航链接
  62. return allLinks.filter(link => {
  63. if (link.itemKey === 'docs') {
  64. return docsLink && modules.docs;
  65. }
  66. if (link.itemKey === 'pricing') {
  67. // 支持新的pricing配置格式
  68. return typeof modules.pricing === 'object' ? modules.pricing.enabled : modules.pricing;
  69. }
  70. return modules[link.itemKey] === true;
  71. });
  72. },
  73. [t, docsLink, headerNavModules],
  74. );
  75. return {
  76. mainNavLinks,
  77. };
  78. };