index.ts 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  1. import type { RouteRecordRaw } from 'vue-router'
  2. import { useNProgress } from '@/lib/nprogress/nprogress'
  3. import { useSettingsStore, useUserStore } from '@/pinia'
  4. import {
  5. BellOutlined,
  6. CloudOutlined,
  7. CodeOutlined,
  8. DatabaseOutlined,
  9. FileOutlined,
  10. FileTextOutlined,
  11. HomeOutlined,
  12. InfoCircleOutlined,
  13. SafetyCertificateOutlined,
  14. SettingOutlined,
  15. ShareAltOutlined,
  16. UserOutlined,
  17. } from '@ant-design/icons-vue'
  18. import { createRouter, createWebHashHistory } from 'vue-router'
  19. import 'nprogress/nprogress.css'
  20. export const routes: RouteRecordRaw[] = [
  21. {
  22. path: '/',
  23. name: 'Home',
  24. component: () => import('@/layouts/BaseLayout.vue'),
  25. redirect: '/dashboard',
  26. meta: {
  27. name: () => $gettext('Home'),
  28. },
  29. children: [
  30. {
  31. path: 'dashboard',
  32. component: () => import('@/views/dashboard/DashBoard.vue'),
  33. name: 'Dashboard',
  34. meta: {
  35. name: () => $gettext('Dashboard'),
  36. icon: HomeOutlined,
  37. },
  38. },
  39. {
  40. path: 'sites',
  41. name: 'Manage Sites',
  42. component: () => import('@/layouts/BaseRouterView.vue'),
  43. meta: {
  44. name: () => $gettext('Manage Sites'),
  45. icon: CloudOutlined,
  46. },
  47. redirect: '/sites/list',
  48. children: [{
  49. path: 'list',
  50. name: 'Sites List',
  51. component: () => import('@/views/site/site_list/SiteList.vue'),
  52. meta: {
  53. name: () => $gettext('Sites List'),
  54. },
  55. }, {
  56. path: 'add',
  57. name: 'Add Site',
  58. component: () => import('@/views/site/SiteAdd.vue'),
  59. meta: {
  60. name: () => $gettext('Add Site'),
  61. lastRouteName: 'Sites List',
  62. },
  63. }, {
  64. path: 'categories',
  65. name: 'Site Categories',
  66. component: () => import('@/views/site/site_category/SiteCategory.vue'),
  67. meta: {
  68. name: () => $gettext('Site Categories'),
  69. },
  70. }, {
  71. path: ':name',
  72. name: 'Edit Site',
  73. component: () => import('@/views/site/site_edit/SiteEdit.vue'),
  74. meta: {
  75. name: () => $gettext('Edit Site'),
  76. hiddenInSidebar: true,
  77. lastRouteName: 'Sites List',
  78. },
  79. }],
  80. },
  81. {
  82. path: 'streams',
  83. name: 'Manage Streams',
  84. component: () => import('@/views/stream/StreamList.vue'),
  85. meta: {
  86. name: () => $gettext('Manage Streams'),
  87. icon: ShareAltOutlined,
  88. },
  89. },
  90. {
  91. path: 'stream/:name',
  92. name: 'Edit Stream',
  93. component: () => import('@/views/stream/StreamEdit.vue'),
  94. meta: {
  95. name: () => $gettext('Edit Stream'),
  96. hiddenInSidebar: true,
  97. lastRouteName: 'Manage Streams',
  98. },
  99. },
  100. {
  101. path: 'config',
  102. name: 'Manage Configs',
  103. component: () => import('@/views/config/ConfigList.vue'),
  104. meta: {
  105. name: () => $gettext('Manage Configs'),
  106. icon: FileOutlined,
  107. hideChildren: true,
  108. },
  109. },
  110. {
  111. path: 'config/add',
  112. name: 'Add Configuration',
  113. component: () => import('@/views/config/ConfigEditor.vue'),
  114. meta: {
  115. name: () => $gettext('Add Configuration'),
  116. hiddenInSidebar: true,
  117. lastRouteName: 'Manage Configs',
  118. },
  119. },
  120. {
  121. path: 'config/:name+/edit',
  122. name: 'Edit Configuration',
  123. component: () => import('@/views/config/ConfigEditor.vue'),
  124. meta: {
  125. name: () => $gettext('Edit Configuration'),
  126. hiddenInSidebar: true,
  127. lastRouteName: 'Manage Configs',
  128. },
  129. },
  130. {
  131. path: 'certificates',
  132. name: 'Certificates',
  133. component: () => import('@/layouts/BaseRouterView.vue'),
  134. redirect: '/certificates/list',
  135. meta: {
  136. name: () => $gettext('Certificates'),
  137. icon: SafetyCertificateOutlined,
  138. },
  139. children: [
  140. {
  141. path: 'acme_users',
  142. name: 'ACME User',
  143. component: () => import('@/views/certificate/ACMEUser.vue'),
  144. meta: {
  145. name: () => $gettext('ACME User'),
  146. },
  147. },
  148. {
  149. path: 'list',
  150. name: 'Certificates List',
  151. component: () => import('@/views/certificate/CertificateList/Certificate.vue'),
  152. meta: {
  153. name: () => $gettext('Certificates List'),
  154. },
  155. },
  156. {
  157. path: ':id',
  158. name: 'Modify Certificate',
  159. component: () => import('@/views/certificate/CertificateEditor.vue'),
  160. meta: {
  161. name: () => $gettext('Modify Certificate'),
  162. hiddenInSidebar: true,
  163. lastRouteName: 'Certificates List',
  164. },
  165. },
  166. {
  167. path: 'import',
  168. name: 'Import Certificate',
  169. component: () => import('@/views/certificate/CertificateEditor.vue'),
  170. meta: {
  171. name: () => $gettext('Import Certificate'),
  172. hiddenInSidebar: true,
  173. lastRouteName: 'Certificates List',
  174. },
  175. },
  176. {
  177. path: 'dns_credential',
  178. name: 'DNS Credentials',
  179. component: () => import('@/views/certificate/DNSCredential.vue'),
  180. meta: {
  181. name: () => $gettext('DNS Credentials'),
  182. },
  183. },
  184. ],
  185. },
  186. {
  187. path: 'terminal',
  188. name: 'Terminal',
  189. component: () => import('@/views/terminal/Terminal.vue'),
  190. meta: {
  191. name: () => $gettext('Terminal'),
  192. icon: CodeOutlined,
  193. },
  194. },
  195. {
  196. path: 'nginx_log',
  197. name: 'Nginx Log',
  198. meta: {
  199. name: () => $gettext('Nginx Log'),
  200. icon: FileTextOutlined,
  201. },
  202. children: [{
  203. path: 'access',
  204. name: 'Access Logs',
  205. component: () => import('@/views/nginx_log/NginxLog.vue'),
  206. meta: {
  207. name: () => $gettext('Access Logs'),
  208. },
  209. }, {
  210. path: 'error',
  211. name: 'Error Logs',
  212. component: () => import('@/views/nginx_log/NginxLog.vue'),
  213. meta: {
  214. name: () => $gettext('Error Logs'),
  215. },
  216. }, {
  217. path: 'site',
  218. name: 'Site Logs',
  219. component: () => import('@/views/nginx_log/NginxLog.vue'),
  220. meta: {
  221. name: () => $gettext('Site Logs'),
  222. hiddenInSidebar: true,
  223. },
  224. }],
  225. },
  226. {
  227. path: 'environments',
  228. name: 'Environments',
  229. component: () => import('@/views/environment/Environment.vue'),
  230. meta: {
  231. name: () => $gettext('Environments'),
  232. icon: DatabaseOutlined,
  233. hiddenInSidebar: (): boolean => {
  234. const settings = useSettingsStore()
  235. return settings.is_remote
  236. },
  237. },
  238. },
  239. {
  240. path: 'notifications',
  241. name: 'Notifications',
  242. component: () => import('@/views/notification/Notification.vue'),
  243. meta: {
  244. name: () => $gettext('Notifications'),
  245. icon: BellOutlined,
  246. },
  247. },
  248. {
  249. path: 'user',
  250. name: 'Manage Users',
  251. component: () => import('@/views/user/User.vue'),
  252. meta: {
  253. name: () => $gettext('Manage Users'),
  254. icon: UserOutlined,
  255. },
  256. },
  257. {
  258. path: 'preference',
  259. name: 'Preference',
  260. component: () => import('@/views/preference/Preference.vue'),
  261. meta: {
  262. name: () => $gettext('Preference'),
  263. icon: SettingOutlined,
  264. },
  265. },
  266. {
  267. path: 'system',
  268. name: 'System',
  269. redirect: 'system/about',
  270. meta: {
  271. name: () => $gettext('System'),
  272. icon: InfoCircleOutlined,
  273. },
  274. children: [{
  275. path: 'self_check',
  276. name: 'Self Check',
  277. component: () => import('@/views/system/SelfCheck/SelfCheck.vue'),
  278. meta: {
  279. name: () => $gettext('Self Check'),
  280. },
  281. }, {
  282. path: 'about',
  283. name: 'About',
  284. component: () => import('@/views/system/About.vue'),
  285. meta: {
  286. name: () => $gettext('About'),
  287. },
  288. }, {
  289. path: 'upgrade',
  290. name: 'Upgrade',
  291. component: () => import('@/views/system/Upgrade.vue'),
  292. meta: {
  293. name: () => $gettext('Upgrade'),
  294. hiddenInSidebar: (): boolean => {
  295. const settings = useSettingsStore()
  296. return settings.is_remote
  297. },
  298. },
  299. }],
  300. },
  301. ],
  302. },
  303. {
  304. path: '/install',
  305. name: 'Install',
  306. component: () => import('@/views/other/Install.vue'),
  307. meta: { name: () => $gettext('Install'), noAuth: true },
  308. },
  309. {
  310. path: '/login',
  311. name: 'Login',
  312. component: () => import('@/views/other/Login.vue'),
  313. meta: { name: () => $gettext('Login'), noAuth: true },
  314. },
  315. {
  316. path: '/:pathMatch(.*)*',
  317. name: 'Not Found',
  318. component: () => import('@/views/other/Error.vue'),
  319. meta: { name: () => $gettext('Not Found'), noAuth: true, status_code: 404, error: () => $gettext('Not Found') },
  320. },
  321. ]
  322. const router = createRouter({
  323. history: createWebHashHistory(),
  324. routes,
  325. })
  326. const nprogress = useNProgress()
  327. router.beforeEach((to, _, next) => {
  328. document.title = `${to?.meta.name?.() ?? ''} | Nginx UI`
  329. nprogress.start()
  330. const user = useUserStore()
  331. if (to.meta.noAuth || user.isLogin)
  332. next()
  333. else
  334. next({ path: '/login', query: { next: to.fullPath } })
  335. })
  336. router.afterEach(() => {
  337. nprogress.done()
  338. })
  339. export default router