index.ts 7.6 KB

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