index.ts 6.2 KB

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