index.ts 7.5 KB

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