index.ts 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  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('@mobile/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: '/news',
  111. component: Page,
  112. children: [
  113. {
  114. path: '',
  115. name: 'news-list',
  116. component: () => import('@mobile/views/news/list/Index.vue'),
  117. meta: {
  118. ignoreAuth: true,
  119. },
  120. },
  121. {
  122. path: 'detail',
  123. name: 'news-detail',
  124. component: () => import('@mobile/views/news/detail/Index.vue'),
  125. meta: {
  126. ignoreAuth: true,
  127. },
  128. },
  129. ],
  130. },
  131. {
  132. path: '/bank',
  133. component: Page,
  134. children: [
  135. {
  136. path: 'wallet',
  137. name: 'bank-wallet',
  138. component: () => import('@mobile/views/bank/wallet/Index.vue'),
  139. },
  140. {
  141. path: 'sign',
  142. name: 'bank-sign',
  143. component: () => import('@mobile/views/bank/sign/Index.vue'),
  144. },
  145. {
  146. path: 'capital',
  147. name: 'bank-capital',
  148. component: () => import('@mobile/views/bank/capital/index.vue'),
  149. }
  150. ]
  151. },
  152. {
  153. path: '/order',
  154. component: Page,
  155. children: [
  156. {
  157. path: 'list',
  158. name: 'order-list',
  159. component: () => import('../views/order/list/Index.vue'),
  160. },
  161. {
  162. path: 'position',
  163. name: 'order-position',
  164. component: () => import('../views/order/position/Index.vue'),
  165. },
  166. {
  167. path: 'delivery',
  168. name: 'order-delivery',
  169. component: () => import('../views/order/delivery/Index.vue'),
  170. },
  171. {
  172. path: 'performance',
  173. name: 'order-performance',
  174. component: () => import('@mobile/views/order/performance/Index.vue'),
  175. },
  176. ],
  177. },
  178. {
  179. path: '/mine',
  180. component: Page,
  181. children: [
  182. {
  183. path: 'address',
  184. name: 'mine-address',
  185. component: () => import('@mobile/views/mine/address/Index.vue'),
  186. },
  187. {
  188. path: 'invoice',
  189. name: 'mine-invoice',
  190. component: () => import('@mobile/views/mine/invoice/Index.vue'),
  191. },
  192. {
  193. path: 'profile',
  194. name: 'mine-profile',
  195. component: () => import('@mobile/views/mine/profile/Index.vue'),
  196. },
  197. {
  198. path: 'setting',
  199. name: 'mine-setting',
  200. component: () => import('@mobile/views/mine/setting/Index.vue'),
  201. },
  202. {
  203. path: 'wechat',
  204. name: 'mine-wechat',
  205. component: () => import('@mobile/views/mine/wechat/Index.vue'),
  206. },
  207. {
  208. path: 'email',
  209. name: 'mine-email',
  210. component: () => import('@mobile/views/mine/email/Index.vue'),
  211. }
  212. ],
  213. },
  214. {
  215. path: '/notice',
  216. component: Page,
  217. children: [
  218. {
  219. path: '',
  220. name: 'notice-list',
  221. component: () => import('@mobile/views/notice/list/index.vue'),
  222. },
  223. ],
  224. },
  225. {
  226. path: '/report',
  227. component: Page,
  228. children: [
  229. {
  230. path: '',
  231. name: 'report',
  232. component: () => import('@mobile/views/report/index.vue'),
  233. }
  234. ]
  235. },
  236. {
  237. path: '/rules',
  238. component: Page,
  239. children: [
  240. {
  241. path: "zcxy",
  242. name: "rules-zcxy",
  243. component: () => import("@mobile/views/rules/zcxy/Index.vue"),
  244. meta: {
  245. ignoreAuth: true,
  246. },
  247. },
  248. {
  249. path: "yhkhfxgzs",
  250. name: "rules-yhkhfxgzs",
  251. component: () => import("@mobile/views/rules/fxgzs/Index.vue"),
  252. meta: {
  253. ignoreAuth: true,
  254. },
  255. },
  256. {
  257. path: "yszc",
  258. name: "rules-yszc",
  259. component: () => import("@mobile/views/rules/yszc/Index.vue"),
  260. meta: {
  261. ignoreAuth: true,
  262. },
  263. },
  264. {
  265. path: "gywm",
  266. name: "rules-gywm",
  267. component: () => import("@mobile/views/rules/gywm/Index.vue"),
  268. meta: {
  269. ignoreAuth: true,
  270. },
  271. },
  272. {
  273. path: "fwrx",
  274. name: "rules-fwrx",
  275. component: () => import("@mobile/views/rules/fwrx/Index.vue"),
  276. meta: {
  277. ignoreAuth: true,
  278. },
  279. },
  280. ]
  281. },
  282. ...pageRoutes
  283. ]
  284. const router = animateRouter.create({
  285. history: createWebHashHistory(),
  286. routes,
  287. })
  288. // 路由跳转拦截
  289. router.beforeEach((to, from, next) => {
  290. clearPending()
  291. // 判断服务是否加载完成
  292. if (service.isReady) {
  293. if (to.meta.ignoreAuth || loginStore.token) {
  294. next()
  295. } else {
  296. if (to.matched.some((e) => e.name === 'home')) {
  297. // 如果是主页导航页面,强制跳转到首页
  298. next({
  299. name: 'home-index',
  300. replace: true,
  301. })
  302. } else {
  303. next({
  304. name: 'user-login',
  305. query: { redirect: to.fullPath },
  306. })
  307. }
  308. }
  309. } else {
  310. if (to.name === 'boot' || to.name === 'user-login') {
  311. next()
  312. } else {
  313. next({
  314. name: 'boot',
  315. query: { redirect: to.fullPath },
  316. })
  317. }
  318. }
  319. })
  320. export default router