index.ts 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. import { createWebHashHistory, RouteRecordRaw } from 'vue-router'
  2. import { useLoginStore } from '@/stores'
  3. import service from '@/services'
  4. import Page from '@mobile/components/layouts/page/index.vue'
  5. import animateRouter from './animateRouter'
  6. const { getToken } = useLoginStore()
  7. const routes: Array<RouteRecordRaw> = [
  8. {
  9. path: '/:pathMatch(.*)*',
  10. name: 'error',
  11. component: () => import('../views/error/404.vue'),
  12. meta: {
  13. ignoreAuth: true,
  14. },
  15. },
  16. {
  17. path: '/boot',
  18. name: 'boot',
  19. component: () => import('../views/boot/index.vue'),
  20. meta: {
  21. ignoreAuth: true,
  22. },
  23. },
  24. {
  25. path: '/',
  26. component: Page,
  27. children: [
  28. {
  29. path: '',
  30. name: 'home',
  31. component: () => import('../views/home/index.vue'),
  32. }
  33. ]
  34. },
  35. {
  36. path: '/login',
  37. component: Page,
  38. children: [
  39. {
  40. path: '',
  41. name: 'login',
  42. component: () => import('../views/user/login/index.vue'),
  43. meta: {
  44. ignoreAuth: true,
  45. },
  46. }
  47. ]
  48. },
  49. {
  50. path: '/logoff',
  51. component: Page,
  52. children: [
  53. {
  54. path: '',
  55. name: 'logoff',
  56. component: () => import('../views/user/logoff/index.vue'),
  57. }
  58. ]
  59. },
  60. {
  61. path: '/register',
  62. component: Page,
  63. children: [
  64. {
  65. path: '',
  66. name: 'register',
  67. component: () => import('../views/user/register/index.vue'),
  68. meta: {
  69. ignoreAuth: true,
  70. },
  71. }
  72. ]
  73. },
  74. {
  75. path: '/forget',
  76. component: Page,
  77. children: [
  78. {
  79. path: '',
  80. name: 'forget',
  81. component: () => import('../views/user/forget/index.vue'),
  82. meta: {
  83. ignoreAuth: true,
  84. },
  85. },
  86. ]
  87. },
  88. {
  89. path: '/account',
  90. component: Page,
  91. children: [
  92. {
  93. path: 'certification',
  94. name: 'account-certification',
  95. component: () => import('../views/account/certification/index.vue'),
  96. meta: {
  97. ignoreAuth: true,
  98. },
  99. }
  100. ]
  101. },
  102. {
  103. path: '/news',
  104. component: Page,
  105. children: [
  106. {
  107. path: 'details',
  108. name: 'news-details',
  109. component: () => import('../views/news/details/index.vue'),
  110. meta: {
  111. ignoreAuth: true,
  112. },
  113. }
  114. ]
  115. },
  116. {
  117. path: '/market',
  118. component: Page,
  119. children: [
  120. {
  121. path: '',
  122. name: 'market',
  123. component: () => import('../views/market/main/index.vue'),
  124. },
  125. {
  126. path: 'detail',
  127. name: 'market-detail',
  128. component: () => import('../views/market/details/index.vue'),
  129. }
  130. ]
  131. },
  132. {
  133. path: '/bank',
  134. component: Page,
  135. children: [
  136. {
  137. path: 'bank',
  138. name: 'bank-wallet',
  139. component: () => import('../views/bank/wallet/index.vue'),
  140. },
  141. {
  142. path: 'sign',
  143. name: 'bank-sign',
  144. component: () => import('../views/bank/sign/index.vue'),
  145. },
  146. {
  147. path: 'edit',
  148. name: 'add-banksign',
  149. component: () => import('../views/bank/sign/components/edit/index.vue'),
  150. },
  151. {
  152. path: 'statement',
  153. name: 'bank-statement',
  154. component: () => import('../views/bank/statement/index.vue'),
  155. },
  156. ]
  157. },
  158. {
  159. path: '/rules',
  160. component: Page,
  161. children: [
  162. {
  163. path: 'ptgz',
  164. name: 'rules-ptgz',
  165. component: () => import('../views/rules/ptgz/index.vue'),
  166. },
  167. {
  168. path: 'myrz',
  169. name: 'rules-myrz',
  170. component: () => import('../views/rules/myrz/index.vue'),
  171. },
  172. {
  173. path: 'ccwl',
  174. name: 'rules-ccwl',
  175. component: () => import('../views/rules/ccwl/index.vue'),
  176. },
  177. {
  178. path: 'zcxy',
  179. name: 'rules-zcxy',
  180. component: () => import('../views/rules/zcxy/index.vue'),
  181. meta: {
  182. ignoreAuth: true,
  183. },
  184. },
  185. {
  186. path: 'yszc',
  187. name: 'rules-yszc',
  188. component: () => import('../views/rules/yszc/index.vue'),
  189. meta: {
  190. ignoreAuth: true,
  191. },
  192. },
  193. {
  194. path: 'gywm',
  195. name: 'rules-gywm',
  196. component: () => import('../views/rules/gywm/index.vue'),
  197. },
  198. ]
  199. },
  200. {
  201. path: '/credit',
  202. component: Page,
  203. children: [
  204. {
  205. path: 'signin',
  206. name: 'credit-signin',
  207. component: () => import('../views/credit/signin/index.vue'),
  208. },
  209. {
  210. path: 'statement',
  211. name: 'credit-statement',
  212. component: () => import('../views/credit/statement/index.vue'),
  213. },
  214. ]
  215. },
  216. {
  217. path: '/mine',
  218. component: Page,
  219. children: [
  220. {
  221. path: 'generalize',
  222. name: 'mine-generalize',
  223. component: () => import('../views/mine/generalize/index.vue'),
  224. },
  225. {
  226. path: 'service',
  227. name: 'mine-service',
  228. component: () => import('../views/mine/service/index.vue'),
  229. },
  230. {
  231. path: 'address',
  232. name: 'mine-address',
  233. component: () => import('../views/mine/address/index.vue'),
  234. },
  235. ]
  236. },
  237. {
  238. path: '/setting',
  239. component: Page,
  240. children: [
  241. {
  242. path: '',
  243. name: 'setting',
  244. component: () => import('../views/setting/main/index.vue'),
  245. },
  246. {
  247. path: 'password',
  248. name: 'setting-password',
  249. component: () => import('../views/setting/password/index.vue'),
  250. },
  251. ]
  252. }
  253. ]
  254. const router = animateRouter.create({
  255. history: createWebHashHistory(),
  256. routes,
  257. })
  258. // 路由跳转拦截
  259. router.beforeEach((to, from, next) => {
  260. // 判断服务是否加载完成
  261. if (service.isReady) {
  262. if (to.meta.ignoreAuth || getToken()) {
  263. next();
  264. } else {
  265. next({
  266. name: 'login',
  267. query: { redirect: to.fullPath },
  268. });
  269. }
  270. } else {
  271. if (to.name === 'boot' || to.name === 'login') {
  272. next();
  273. } else {
  274. next({
  275. name: 'boot',
  276. query: { redirect: to.fullPath },
  277. });
  278. }
  279. }
  280. })
  281. export default router