index.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. import Vue from 'vue'
  2. import VueRouter from 'vue-router'
  3. import { getUser } from '@/utils/auth'
  4. const Index = () => import('@/pages/index');
  5. const Login = () => import('@/pages/login');
  6. // 首页
  7. const Home = () => import('@/pages/subPages/home');
  8. const order = () => import('@/pages/subPages/order');
  9. const balance = () => import('@/pages/subPages/balance');
  10. const Message = () => import('@/pages/subPages/message');
  11. const View = () => import('@/pages/subPages/view');
  12. // 油卡充值
  13. const OilCard = () => import('@/pages/subPages/oilCard');
  14. // 手机卡充值
  15. const MobileCard = () => import('@/pages/subPages/mobileCard');
  16. // 接口文档
  17. const InterfaceDoc = () => import('@/pages/subPages/interfaceDoc')
  18. // 对账管理
  19. const Reconciliation = () =>import('@/pages/subPages/reconciliation');
  20. // 手机
  21. const phoneIndex = () => import('@/pages/phoneIndex');
  22. // 首页
  23. const phoneHome = () => import('@/pages/phoneSubPages/phoneHome');
  24. const phoneBalance = () => import('@/pages/phoneSubPages/phoneBalance');
  25. const phoneOrder = () => import('@/pages/phoneSubPages/phoneOrder');
  26. const phoneMessage = () => import('@/pages/phoneSubPages/phoneMessage');
  27. const phoneOilCard = () => import('@/pages/phoneSubPages/phoneOilCard');
  28. const phoneMobileCard = () => import('@/pages/phoneSubPages/phoneMobileCard');
  29. const phoneReconciliation = () => import('@/pages/phoneSubPages/phoneReconciliation');
  30. const phoneView = () => import('@/pages/phoneSubPages/phoneView');
  31. const phoneDoc = () => import('@/pages/phoneSubPages/phoneDoc');
  32. Vue.use(VueRouter)
  33. const routes = [
  34. {
  35. path: '/',
  36. name: 'Index',
  37. component: Index,
  38. // redirect:'/login',
  39. // redirect:'/order',
  40. children:[
  41. // 主页
  42. {
  43. path: '',
  44. name: 'home',
  45. component: Home
  46. },
  47. // 订单统计
  48. {
  49. path:'/order',
  50. name:'order',
  51. component:order
  52. },
  53. // 余额充值
  54. {
  55. path:'/balance',
  56. name:'balance',
  57. component:balance
  58. },
  59. // 实时动账
  60. {
  61. path:'/message',
  62. name:'message',
  63. component:Message
  64. },
  65. // 开发者设置
  66. {
  67. path:'/view',
  68. name:'view',
  69. component:View
  70. },
  71. // 油卡充值
  72. {
  73. path:'/oilCard',
  74. name:'oilCard',
  75. component:OilCard
  76. },
  77. // 话费充值
  78. {
  79. path:'/mobileCard',
  80. name:'mobileCard',
  81. component:MobileCard
  82. },
  83. // 接口文档
  84. {
  85. path:'/interfaceDoc',
  86. name:'interfaceDoc',
  87. component:InterfaceDoc
  88. },
  89. // 对账管理
  90. {
  91. path:'/reconciliation',
  92. name:'reconciliation',
  93. component:Reconciliation
  94. }
  95. ]
  96. },
  97. {
  98. path: '/login',
  99. name: 'Login',
  100. component: Login
  101. },
  102. {
  103. path: '/phoneIndex',
  104. name: 'phoneIndex',
  105. component: phoneIndex,
  106. redirect:'/phoneHome',
  107. children: [
  108. // 主页
  109. {
  110. path: '/phoneHome',
  111. name: 'phoneHome',
  112. component: phoneHome
  113. },
  114. // 余额充值
  115. {
  116. path:'/phoneBalance',
  117. name:'phoneBalance',
  118. component:phoneBalance
  119. },
  120. // 订单管理
  121. {
  122. path:'/phoneOrder',
  123. name:'phoneOrder',
  124. component:phoneOrder
  125. },
  126. // 账户日志 phoneMessage
  127. {
  128. path:'/phoneMessage',
  129. name:'phoneMessage',
  130. component:phoneMessage
  131. },
  132. // 油卡充值
  133. {
  134. path:'/phoneOilCard',
  135. name:'phoneOilCard',
  136. component: phoneOilCard
  137. },
  138. // 手机卡充值 phoneMobileCard
  139. {
  140. path:'/phoneMobileCard',
  141. name:'phoneMobileCard',
  142. component: phoneMobileCard
  143. },
  144. // 对账管理 phoneReconciliation
  145. {
  146. path:'/phoneReconciliation',
  147. name:'phoneReconciliation',
  148. component: phoneReconciliation
  149. },
  150. // 设置 phoneView
  151. {
  152. path:'/phoneView',
  153. name:'phoneView',
  154. component: phoneView
  155. },
  156. // 接口文档 phoneDoc
  157. {
  158. path:'/phoneDoc',
  159. name:'phoneDoc',
  160. component: phoneDoc
  161. }
  162. ]
  163. }
  164. ]
  165. const router = new VueRouter({
  166. routes,
  167. mode: 'hash',
  168. base: '/mchsrv'
  169. })
  170. /* 判断PC或移动端 */
  171. function IsPC() {
  172. var userAgentInfo = navigator.userAgent;
  173. var Agents = ["Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod"];
  174. var flag = true;
  175. for (var v = 0; v < Agents.length; v++) {
  176. if (userAgentInfo.indexOf(Agents[v]) > 0) {
  177. flag = false;
  178. break;
  179. }
  180. }
  181. return flag;
  182. }
  183. router.beforeEach((to,from,next)=>{
  184. if (to.path !== '/login' && !getUser('name')) {
  185. next('/login')
  186. }
  187. if (IsPC() && to.path.indexOf('phone')>0) {
  188. next('/login')
  189. }
  190. next();
  191. });
  192. export default router