index.ts 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /*
  2. * Copyright (c) 2024 LangChat. TyCoding All Rights Reserved.
  3. *
  4. * Licensed under the GNU Affero General Public License, Version 3 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * https://www.gnu.org/licenses/agpl-3.0.html
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. import type { App } from 'vue';
  17. import type { RouteRecordRaw } from 'vue-router';
  18. import { createRouter, createWebHashHistory } from 'vue-router';
  19. import { Layout } from '@/layout';
  20. import { setupPageGuard } from '@/router/permission';
  21. const routes: RouteRecordRaw[] = [
  22. {
  23. path: '/',
  24. name: 'Root',
  25. component: Layout,
  26. redirect: '/home',
  27. children: [
  28. {
  29. path: '/home',
  30. name: 'Home',
  31. meta: {
  32. label: '首页',
  33. icon: 'tabler:smart-home',
  34. },
  35. component: () => import('@/views/modules/home/index.vue'),
  36. },
  37. {
  38. path: '/chat/:uuid?',
  39. name: 'Chat',
  40. meta: {
  41. label: '聊天助手',
  42. icon: 'bx:chat',
  43. },
  44. component: () => import('@/views/modules/chat/index.vue'),
  45. },
  46. {
  47. path: '/doc',
  48. name: 'Doc',
  49. meta: {
  50. label: '文档分析',
  51. icon: 'mingcute:doc-line',
  52. },
  53. component: () => import('@/views/modules/doc/index.vue'),
  54. },
  55. {
  56. path: '/write',
  57. name: 'Write',
  58. meta: {
  59. label: '文本撰写',
  60. icon: 'solar:document-add-linear',
  61. },
  62. component: () => import('@/views/modules/write/index.vue'),
  63. },
  64. {
  65. path: '/image',
  66. name: 'Image',
  67. meta: {
  68. label: 'AI 文生图',
  69. icon: 'radix-icons:image',
  70. },
  71. component: () => import('@/views/modules/image/index.vue'),
  72. },
  73. {
  74. path: '/mindmap',
  75. name: 'MindMap',
  76. meta: {
  77. label: '思维导图',
  78. icon: 'ri:mind-map',
  79. },
  80. component: () => import('@/views/modules/mindmap/index.vue'),
  81. },
  82. ],
  83. },
  84. ];
  85. const baseRoutes: RouteRecordRaw[] = [
  86. {
  87. path: '/profile',
  88. component: Layout,
  89. children: [
  90. {
  91. path: 'index',
  92. name: 'Profile',
  93. meta: {
  94. label: '个人中心',
  95. },
  96. component: () => import('@/views/profile/index.vue'),
  97. },
  98. ],
  99. },
  100. {
  101. path: '/login',
  102. name: 'Login',
  103. component: () => import('@/views/login/index.vue'),
  104. },
  105. {
  106. path: '/forget',
  107. name: 'Forget',
  108. component: () => import('@/views/login/Forget.vue'),
  109. },
  110. {
  111. path: '/404',
  112. name: '404',
  113. component: () => import('@/views/exception/404/index.vue'),
  114. },
  115. {
  116. path: '/500',
  117. name: '500',
  118. component: () => import('@/views/exception/500/index.vue'),
  119. },
  120. {
  121. path: '/:pathMatch(.*)*',
  122. name: 'notFound',
  123. redirect: '/404',
  124. },
  125. ];
  126. export const routesConst: RouteRecordRaw[] = routes.flatMap((route) => route.children ?? []);
  127. export const router = createRouter({
  128. history: createWebHashHistory(),
  129. routes: [...baseRoutes, ...routes],
  130. scrollBehavior: () => ({ left: 0, top: 0 }),
  131. });
  132. export async function setupRouter(app: App) {
  133. app.use(router);
  134. // await router.isReady()
  135. setupPageGuard(router);
  136. }