index.ts 7.1 KB

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