index.ts 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. import {createRouter, createWebHashHistory} from 'vue-router'
  2. import gettext from '../gettext'
  3. import {useUserStore} from '@/pinia'
  4. import {
  5. CloudOutlined,
  6. CodeOutlined,
  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 '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('@/layouts/BaseRouterView.vue'),
  88. meta: {
  89. icon: SafetyCertificateOutlined
  90. },
  91. children: [
  92. {
  93. path: 'list',
  94. name: () => $gettext('Certification List'),
  95. component: () => import('@/views/cert/Cert.vue')
  96. },
  97. {
  98. path: 'dns_credential',
  99. name: () => $gettext('DNS Credentials'),
  100. component: () => import('@/views/cert/DNSCredential.vue')
  101. }
  102. ]
  103. },
  104. {
  105. path: 'terminal',
  106. name: () => $gettext('Terminal'),
  107. component: () => import('@/views/pty/Terminal.vue'),
  108. meta: {
  109. icon: CodeOutlined
  110. }
  111. },
  112. {
  113. path: 'nginx_log',
  114. name: () => $gettext('Nginx Log'),
  115. meta: {
  116. icon: FileTextOutlined
  117. },
  118. children: [{
  119. path: 'access',
  120. name: () => $gettext('Access Logs'),
  121. component: () => import('@/views/nginx_log/NginxLog.vue')
  122. }, {
  123. path: 'error',
  124. name: () => $gettext('Error Logs'),
  125. component: () => import('@/views/nginx_log/NginxLog.vue')
  126. }, {
  127. path: 'site',
  128. name: () => $gettext('Site Logs'),
  129. component: () => import('@/views/nginx_log/NginxLog.vue'),
  130. meta: {
  131. hiddenInSidebar: true
  132. }
  133. }]
  134. },
  135. {
  136. path: 'preference',
  137. name: () => $gettext('Preference'),
  138. component: () => import('@/views/preference/Preference.vue'),
  139. meta: {
  140. icon: SettingOutlined
  141. }
  142. },
  143. {
  144. path: 'system',
  145. name: () => $gettext('System'),
  146. redirect: 'system/about',
  147. meta: {
  148. icon: InfoCircleOutlined
  149. },
  150. children: [{
  151. path: 'about',
  152. name: () => $gettext('About'),
  153. component: () => import('@/views/system/About.vue')
  154. }, {
  155. path: 'upgrade',
  156. name: () => $gettext('Upgrade'),
  157. component: () => import('@/views/system/Upgrade.vue')
  158. }]
  159. }
  160. ]
  161. },
  162. {
  163. path: '/install',
  164. name: () => $gettext('Install'),
  165. component: () => import('@/views/other/Install.vue'),
  166. meta: {noAuth: true}
  167. },
  168. {
  169. path: '/login',
  170. name: () => $gettext('Login'),
  171. component: () => import('@/views/other/Login.vue'),
  172. meta: {noAuth: true}
  173. },
  174. {
  175. path: '/:pathMatch(.*)*',
  176. name: () => $gettext('Not Found'),
  177. component: () => import('@/views/other/Error.vue'),
  178. meta: {noAuth: true, status_code: 404, error: () => $gettext('Not Found')}
  179. }
  180. ]
  181. const router = createRouter({
  182. history: createWebHashHistory(),
  183. // @ts-ignore
  184. routes: routes
  185. })
  186. NProgress.configure({showSpinner: false})
  187. router.beforeEach((to, from, next) => {
  188. // @ts-ignore
  189. document.title = to.name?.() + ' | Nginx UI'
  190. NProgress.start()
  191. const user = useUserStore()
  192. const {is_login} = user
  193. if (to.meta.noAuth || is_login) {
  194. next()
  195. } else {
  196. next({path: '/login', query: {next: to.fullPath}})
  197. }
  198. })
  199. router.afterEach(() => {
  200. NProgress.done()
  201. })
  202. export default router