index.ts 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. import { createRouter, createWebHashHistory } from 'vue-router'
  2. import type { AntDesignOutlinedIconType } from '@ant-design/icons-vue/lib/icons/AntDesignOutlined'
  3. import {
  4. CloudOutlined,
  5. CodeOutlined,
  6. DatabaseOutlined,
  7. FileOutlined,
  8. FileTextOutlined,
  9. HomeOutlined,
  10. InfoCircleOutlined,
  11. SafetyCertificateOutlined,
  12. SettingOutlined,
  13. UserOutlined,
  14. } from '@ant-design/icons-vue'
  15. import NProgress from 'nprogress'
  16. import gettext from '@/gettext'
  17. import { useUserStore } from '@/pinia'
  18. import 'nprogress/nprogress.css'
  19. const { $gettext } = gettext
  20. export interface Route {
  21. path: string
  22. name: () => string
  23. component?: () => Promise<typeof import('*.vue')>
  24. redirect?: string
  25. meta?: {
  26. icon?: AntDesignOutlinedIconType
  27. hiddenInSidebar?: boolean
  28. hideChildren?: boolean
  29. noAuth?: boolean
  30. status_code?: number
  31. error?: () => string
  32. }
  33. children?: Route[]
  34. }
  35. export const routes: Route[] = [
  36. {
  37. path: '/',
  38. name: () => $gettext('Home'),
  39. component: () => import('@/layouts/BaseLayout.vue'),
  40. redirect: '/dashboard',
  41. children: [
  42. {
  43. path: 'dashboard',
  44. component: () => import('@/views/dashboard/DashBoard.vue'),
  45. name: () => $gettext('Dashboard'),
  46. meta: {
  47. icon: HomeOutlined,
  48. },
  49. },
  50. {
  51. path: 'domain',
  52. name: () => $gettext('Manage Sites'),
  53. component: () => import('@/layouts/BaseRouterView.vue'),
  54. meta: {
  55. icon: CloudOutlined,
  56. },
  57. redirect: '/domain/list',
  58. children: [{
  59. path: 'list',
  60. name: () => $gettext('Sites List'),
  61. component: () => import('@/views/domain/DomainList.vue'),
  62. }, {
  63. path: 'add',
  64. name: () => $gettext('Add Site'),
  65. component: () => import('@/views/domain/DomainAdd.vue'),
  66. }, {
  67. path: ':name',
  68. name: () => $gettext('Edit Site'),
  69. component: () => import('@/views/domain/DomainEdit.vue'),
  70. meta: {
  71. hiddenInSidebar: true,
  72. },
  73. }],
  74. },
  75. {
  76. path: 'config',
  77. name: () => $gettext('Manage Configs'),
  78. component: () => import('@/views/config/Config.vue'),
  79. meta: {
  80. icon: FileOutlined,
  81. hideChildren: true,
  82. },
  83. },
  84. {
  85. path: 'config/:name+/edit',
  86. name: () => $gettext('Edit Configuration'),
  87. component: () => import('@/views/config/ConfigEdit.vue'),
  88. meta: {
  89. hiddenInSidebar: true,
  90. },
  91. },
  92. {
  93. path: 'certificates',
  94. name: () => $gettext('Certificates'),
  95. component: () => import('@/layouts/BaseRouterView.vue'),
  96. meta: {
  97. icon: SafetyCertificateOutlined,
  98. },
  99. children: [
  100. {
  101. path: 'list',
  102. name: () => $gettext('Certificates List'),
  103. component: () => import('@/views/certificate/Certificate.vue'),
  104. },
  105. {
  106. path: 'dns_credential',
  107. name: () => $gettext('DNS Credentials'),
  108. component: () => import('@/views/certificate/DNSCredential.vue'),
  109. },
  110. ],
  111. },
  112. {
  113. path: 'terminal',
  114. name: () => $gettext('Terminal'),
  115. component: () => import('@/views/pty/Terminal.vue'),
  116. meta: {
  117. icon: CodeOutlined,
  118. },
  119. },
  120. {
  121. path: 'nginx_log',
  122. name: () => $gettext('Nginx Log'),
  123. meta: {
  124. icon: FileTextOutlined,
  125. },
  126. children: [{
  127. path: 'access',
  128. name: () => $gettext('Access Logs'),
  129. component: () => import('@/views/nginx_log/NginxLog.vue'),
  130. }, {
  131. path: 'error',
  132. name: () => $gettext('Error Logs'),
  133. component: () => import('@/views/nginx_log/NginxLog.vue'),
  134. }, {
  135. path: 'site',
  136. name: () => $gettext('Site Logs'),
  137. component: () => import('@/views/nginx_log/NginxLog.vue'),
  138. meta: {
  139. hiddenInSidebar: true,
  140. },
  141. }],
  142. },
  143. {
  144. path: 'environment',
  145. name: () => $gettext('Environment'),
  146. component: () => import('@/views/environment/Environment.vue'),
  147. meta: {
  148. icon: DatabaseOutlined,
  149. },
  150. },
  151. {
  152. path: 'user',
  153. name: () => $gettext('Manage Users'),
  154. component: () => import('@/views/user/User.vue'),
  155. meta: {
  156. icon: UserOutlined,
  157. },
  158. },
  159. {
  160. path: 'preference',
  161. name: () => $gettext('Preference'),
  162. component: () => import('@/views/preference/Preference.vue'),
  163. meta: {
  164. icon: SettingOutlined,
  165. },
  166. },
  167. {
  168. path: 'system',
  169. name: () => $gettext('System'),
  170. redirect: 'system/about',
  171. meta: {
  172. icon: InfoCircleOutlined,
  173. },
  174. children: [{
  175. path: 'about',
  176. name: () => $gettext('About'),
  177. component: () => import('@/views/system/About.vue'),
  178. }, {
  179. path: 'upgrade',
  180. name: () => $gettext('Upgrade'),
  181. component: () => import('@/views/system/Upgrade.vue'),
  182. }],
  183. },
  184. ],
  185. },
  186. {
  187. path: '/install',
  188. name: () => $gettext('Install'),
  189. component: () => import('@/views/other/Install.vue'),
  190. meta: { noAuth: true },
  191. },
  192. {
  193. path: '/login',
  194. name: () => $gettext('Login'),
  195. component: () => import('@/views/other/Login.vue'),
  196. meta: { noAuth: true },
  197. },
  198. {
  199. path: '/:pathMatch(.*)*',
  200. name: () => $gettext('Not Found'),
  201. component: () => import('@/views/other/Error.vue'),
  202. meta: { noAuth: true, status_code: 404, error: () => $gettext('Not Found') },
  203. },
  204. ]
  205. const router = createRouter({
  206. history: createWebHashHistory(),
  207. // @ts-expect-error routes type error
  208. routes,
  209. })
  210. NProgress.configure({ showSpinner: false })
  211. router.beforeEach((to, _, next) => {
  212. // @ts-expect-error name type
  213. document.title = `${to.name?.()} | Nginx UI`
  214. NProgress.start()
  215. const user = useUserStore()
  216. const { is_login } = user
  217. if (to.meta.noAuth || is_login)
  218. next()
  219. else
  220. next({ path: '/login', query: { next: to.fullPath } })
  221. })
  222. router.afterEach(() => {
  223. NProgress.done()
  224. })
  225. export default router