index.ts 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. import {createRouter, createWebHistory} from 'vue-router'
  2. import gettext from '../gettext'
  3. import {useUserStore} from '@/pinia'
  4. import {
  5. CloudOutlined,
  6. CodeOutlined,
  7. FileOutlined,
  8. HomeOutlined,
  9. InfoCircleOutlined,
  10. UserOutlined,
  11. FileTextOutlined,
  12. SettingOutlined,
  13. SafetyCertificateOutlined
  14. } from '@ant-design/icons-vue'
  15. const {$gettext} = gettext
  16. export const routes = [
  17. {
  18. path: '/',
  19. name: () => $gettext('Home'),
  20. component: () => import('@/layouts/BaseLayout.vue'),
  21. redirect: '/dashboard',
  22. children: [
  23. {
  24. path: 'dashboard',
  25. component: () => import('@/views/dashboard/DashBoard.vue'),
  26. name: () => $gettext('Dashboard'),
  27. meta: {
  28. // hiddenHeaderContent: true,
  29. icon: HomeOutlined
  30. }
  31. },
  32. {
  33. path: 'user',
  34. name: () => $gettext('Manage Users'),
  35. component: () => import('@/views/user/User.vue'),
  36. meta: {
  37. icon: UserOutlined
  38. }
  39. },
  40. {
  41. path: 'domain',
  42. name: () => $gettext('Manage Sites'),
  43. component: () => import('@/layouts/BaseRouterView.vue'),
  44. meta: {
  45. icon: CloudOutlined
  46. },
  47. redirect: '/domain/list',
  48. children: [{
  49. path: 'list',
  50. name: () => $gettext('Sites List'),
  51. component: () => import('@/views/domain/DomainList.vue')
  52. }, {
  53. path: 'add',
  54. name: () => $gettext('Add Site'),
  55. component: () => import('@/views/domain/DomainAdd.vue')
  56. }, {
  57. path: ':name',
  58. name: () => $gettext('Edit Site'),
  59. component: () => import('@/views/domain/DomainEdit.vue'),
  60. meta: {
  61. hiddenInSidebar: true
  62. }
  63. }]
  64. },
  65. {
  66. path: 'config',
  67. name: () => $gettext('Manage Configs'),
  68. component: () => import('@/views/config/Config.vue'),
  69. meta: {
  70. icon: FileOutlined,
  71. hideChildren: true
  72. }
  73. },
  74. {
  75. path: 'config/:name+/edit',
  76. name: () => $gettext('Edit Configuration'),
  77. component: () => import('@/views/config/ConfigEdit.vue'),
  78. meta: {
  79. hiddenInSidebar: true
  80. }
  81. },
  82. {
  83. path: 'cert',
  84. name: () => $gettext('Certification'),
  85. component: () => import('@/views/cert/Cert.vue'),
  86. meta: {
  87. icon: SafetyCertificateOutlined
  88. }
  89. },
  90. {
  91. path: 'terminal',
  92. name: () => $gettext('Terminal'),
  93. component: () => import('@/views/pty/Terminal.vue'),
  94. meta: {
  95. icon: CodeOutlined
  96. }
  97. },
  98. {
  99. path: 'nginx_log',
  100. name: () => $gettext('Nginx Log'),
  101. meta: {
  102. icon: FileTextOutlined
  103. },
  104. children: [{
  105. path: 'access',
  106. name: () => $gettext('Access Logs'),
  107. component: () => import('@/views/nginx_log/NginxLog.vue')
  108. }, {
  109. path: 'error',
  110. name: () => $gettext('Error Logs'),
  111. component: () => import('@/views/nginx_log/NginxLog.vue')
  112. }, {
  113. path: 'site',
  114. name: () => $gettext('Site Logs'),
  115. component: () => import('@/views/nginx_log/NginxLog.vue'),
  116. meta: {
  117. hiddenInSidebar: true
  118. }
  119. }]
  120. },
  121. {
  122. path: 'preference',
  123. name: () => $gettext('Preference'),
  124. component: () => import('@/views/preference/Preference.vue'),
  125. meta: {
  126. icon: SettingOutlined
  127. }
  128. },
  129. {
  130. path: 'about',
  131. name: () => $gettext('About'),
  132. component: () => import('@/views/other/About.vue'),
  133. meta: {
  134. icon: InfoCircleOutlined
  135. }
  136. }
  137. ]
  138. },
  139. {
  140. path: '/install',
  141. name: () => $gettext('Install'),
  142. component: () => import('@/views/other/Install.vue'),
  143. meta: {noAuth: true}
  144. },
  145. {
  146. path: '/login',
  147. name: () => $gettext('Login'),
  148. component: () => import('@/views/other/Login.vue'),
  149. meta: {noAuth: true}
  150. },
  151. {
  152. path: '/:pathMatch(.*)*',
  153. name: () => $gettext('Not Found'),
  154. component: () => import('@/views/other/Error.vue'),
  155. meta: {noAuth: true, status_code: 404, error: () => $gettext('Not Found')}
  156. }
  157. ]
  158. const router = createRouter({
  159. history: createWebHistory(),
  160. // @ts-ignore
  161. routes: routes
  162. })
  163. router.beforeEach((to, from, next) => {
  164. // @ts-ignore
  165. document.title = to.name?.() + ' | Nginx UI'
  166. const user = useUserStore()
  167. const {is_login} = user
  168. if (to.meta.noAuth || is_login) {
  169. next()
  170. } else {
  171. next({path: '/login', query: {next: to.fullPath}})
  172. }
  173. })
  174. export default router