index.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. import Vue from 'vue'
  2. import VueRouter from 'vue-router'
  3. import axios from 'axios'
  4. import store from '@/lib/store'
  5. Vue.use(VueRouter)
  6. export const routes = [
  7. {
  8. path: '/',
  9. name: '首页',
  10. component: () => import('@/layouts/BaseLayout'),
  11. redirect: '/dashboard',
  12. children: [
  13. {
  14. path: 'dashboard',
  15. component: () => import('@/views/DashBoard'),
  16. name: '仪表盘',
  17. meta: {
  18. //hiddenHeaderContent: true,
  19. icon: 'home'
  20. }
  21. },
  22. {
  23. path: 'domain',
  24. name: '网站管理',
  25. component: () => import('@/layouts/BaseRouterView'),
  26. meta: {
  27. icon: 'cloud'
  28. },
  29. redirect: '/domain/list',
  30. children: [{
  31. path: 'list',
  32. name: '网站列表',
  33. component: () => import('@/views/Domain.vue'),
  34. }, {
  35. path: 'add',
  36. name: '添加站点',
  37. component: () => import('@/views/domain_edit/DomainEdit.vue'),
  38. }, {
  39. path: ':name',
  40. name: '编辑站点',
  41. component: () => import('@/views/domain_edit/DomainEdit.vue'),
  42. meta: {
  43. hiddenInSidebar: true
  44. }
  45. }, ]
  46. },
  47. {
  48. path: 'config',
  49. name: '配置管理',
  50. component: () => import('@/views/Config.vue'),
  51. meta: {
  52. icon: 'file'
  53. },
  54. },
  55. {
  56. path: 'config/:name',
  57. name: '配置编辑',
  58. component: () => import('@/views/ConfigEdit.vue'),
  59. meta: {
  60. hiddenInSidebar: true
  61. },
  62. },
  63. {
  64. path: 'about',
  65. name: '关于',
  66. component: () => import('@/views/About.vue'),
  67. meta: {
  68. icon: 'info-circle'
  69. }
  70. },
  71. ]
  72. },
  73. {
  74. path: '/login',
  75. name: '登录',
  76. component: () => import('@/views/Login'),
  77. meta: {noAuth: true}
  78. },
  79. {
  80. path: '/404',
  81. name: '404 Not Found',
  82. component: () => import('@/views/Error'),
  83. meta: {noAuth: true, status_code: 404, error: 'Not Found'}
  84. },
  85. {
  86. path: '*',
  87. name: '未找到页面',
  88. redirect: '/404',
  89. meta: {noAuth: true}
  90. }
  91. ]
  92. const router = new VueRouter({
  93. routes
  94. })
  95. router.beforeEach((to, from, next) => {
  96. document.title = 'Nginx UI | ' + to.name
  97. if (process.env.NODE_ENV === 'production') {
  98. axios.get('/version.json?' + Date.now()).then(r => {
  99. if (!(process.env.VUE_APP_VERSION === r.data.version
  100. && Number(process.env.VUE_APP_BUILD_ID) === r.data.build_id)) {
  101. Vue.prototype.$info({
  102. title: '系统信息',
  103. content: '检测到版本更新,将会自动刷新本页',
  104. onOk() {
  105. location.reload()
  106. },
  107. okText: '好的'
  108. })
  109. }
  110. })
  111. }
  112. if (to.meta.noAuth || store.getters.token) {
  113. next()
  114. } else {
  115. next({path: '/login', query: {next: to.fullPath}})
  116. }
  117. })
  118. export {router}