index.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. import Vue from 'vue'
  2. import VueRouter from 'vue-router'
  3. // 加载条
  4. import NProgress from 'nprogress'
  5. import 'nprogress/nprogress.css'
  6. import VueAMap from 'vue-amap';
  7. Vue.use(VueRouter);
  8. // Vue.use(VueAMap);
  9. // VueAMap.initAMapApiLoader({
  10. // key: 'your amap key',
  11. // plugin: ['AMap.Autocomplete', 'AMap.PlaceSearch', 'AMap.Scale', 'AMap.OverView', 'AMap.ToolBar', 'AMap.MapType', 'AMap.PolyEditor', 'AMap.CircleEditor'],
  12. // // 默认高德 sdk 版本为 1.4.4
  13. // v: '1.4.4'
  14. // });
  15. const routes = [
  16. {
  17. path: '/',
  18. component: () => import( '../views/Index.vue'),
  19. children: [
  20. {
  21. path: '/',
  22. name: 'Main',
  23. component: () => import('@/views/Main.vue'),
  24. meta: {
  25. title: "首页",
  26. }
  27. },{
  28. path: '/member',
  29. name: 'Member',
  30. component: () => import('@/views/Member.vue'),
  31. meta: {
  32. title: "会员管理",
  33. }
  34. },{
  35. path: '/lesson',
  36. name: 'Lesson',
  37. component: () => import('@/views/Lesson.vue'),
  38. meta: {
  39. title: "课程模板",
  40. }
  41. },{
  42. path: '/lessonTable',
  43. name: 'lessonTable',
  44. component: () => import('@/views/LessonTable.vue'),
  45. meta: {
  46. title: "课程表模板",
  47. }
  48. },{
  49. path: '/editLessonTable',
  50. name: 'EditLessonTable.vue',
  51. component: () => import('@/views/EditLessonTable.vue'),
  52. meta: {
  53. title: "编辑课程表模板",
  54. }
  55. },{
  56. path: '/adminManage',
  57. name: 'AdminManage',
  58. component: () => import('@/views/AdminManage.vue'),
  59. meta: {
  60. title: "用户管理",
  61. }
  62. },{
  63. path: '/log',
  64. name: 'Log',
  65. component: () => import('@/views/Log.vue'),
  66. meta: {
  67. title: "操作日志",
  68. }
  69. },{
  70. path: '/shopManage',
  71. name: 'ShopManage',
  72. component: () => import('@/views/ShopManage.vue'),
  73. meta: {
  74. title: "店面管理",
  75. }
  76. },{
  77. path: '/adminSetting',
  78. name: 'AdminSetting',
  79. component: () => import('@/views/AdminSetting.vue'),
  80. meta: {
  81. title: "系统设置",
  82. }
  83. },{
  84. path: '/lessonManage',
  85. name: 'lessonManage',
  86. component: () => import('@/views/lessonManage.vue'),
  87. meta: {
  88. title: "课程表管理",
  89. }
  90. },{
  91. path: '/coach',
  92. name: 'coach',
  93. component: () => import('@/views/coach.vue'),
  94. meta: {
  95. title: "教练管理",
  96. }
  97. },{
  98. path: '/yhgl',
  99. name: 'Yhgl',
  100. component: () => import('@/views/Yhgl.vue'),
  101. meta: {
  102. title: "用户管理",
  103. }
  104. },{
  105. path: '/mockPage',
  106. name: 'MockPage',
  107. component: () => import('@/views/MockPage.vue'),
  108. meta: {
  109. title: "用户管理",
  110. }
  111. },{
  112. path: '/chart',
  113. name: 'Chart',
  114. component: () => import('@/views/Chart.vue'),
  115. meta: {
  116. title: "图表效果",
  117. }
  118. },{
  119. path: '/test',
  120. name: 'Test',
  121. component: () => import('@/views/Test.vue'),
  122. meta: {
  123. title: "Test",
  124. }
  125. },{
  126. path: '/aboutUs',
  127. name: 'AboutUs',
  128. component: () => import('@/views/AboutUs.vue'),
  129. meta: {
  130. title: "关于我们",
  131. }
  132. },{
  133. path: '/pwd',
  134. name: 'Pwd',
  135. component: () => import('@/views/Pwd.vue'),
  136. meta: {
  137. title: "密码修改",
  138. }
  139. },{
  140. path: '/basic',
  141. name: 'Basic',
  142. component: () => import('@/views/Basic.vue'),
  143. meta: {
  144. title: "基本设置",
  145. }
  146. },{
  147. path: '/upload',
  148. name: 'Upload',
  149. component: () => import('@/views/Upload.vue'),
  150. meta: {
  151. title: "上传文件",
  152. }
  153. },
  154. ]
  155. }, {
  156. path: '/login',
  157. name: 'Login',
  158. component: () => import( '../views/Login.vue')
  159. },, {
  160. path: '*',
  161. name: '404',
  162. component: () => import( '../views/404.vue')
  163. },
  164. ]
  165. const originalPush = VueRouter.prototype.push;
  166. VueRouter.prototype.push = function push(location) {
  167. return originalPush.call(this, location).catch(err => err)
  168. };
  169. const router = new VueRouter({
  170. mode: 'history',
  171. base: process.env.BASE_URL,
  172. routes
  173. });
  174. // 路由守卫
  175. router.beforeEach((to,from,next)=>{
  176. NProgress.start()
  177. const isLogin = localStorage.token? true : false;
  178. if(to.path == '/login' || to.path == '/register'){//'login'和'register'相当于是路由白名单
  179. next();
  180. }else{
  181. //如果token存在,就正常跳转,如果不存在,则说明未登陆,则跳转到'login'
  182. isLogin? next() : next("/login");
  183. }
  184. });
  185. router.afterEach(() => {
  186. NProgress.done()
  187. })
  188. export default router