index.ts 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  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. props: {
  35. iosUpdateUrl: 'https://itunes.apple.com/lookup?id=6459789608'
  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: '/holdbank',
  157. component: Page,
  158. children: [
  159. {
  160. path: 'holdsign',
  161. name: 'hold-sign',
  162. component: () => import('../views/holdbank/holdsign/Index.vue'),
  163. },
  164. {
  165. path: 'holddeposit',
  166. name: 'hold-deposit',
  167. component: () => import('../views/holdbank/holddeposit/Index.vue'),
  168. }
  169. ]
  170. },
  171. {
  172. path: '/order',
  173. component: Page,
  174. children: [
  175. {
  176. path: 'list',
  177. name: 'order-list',
  178. component: () => import('../views/order/list/Index.vue'),
  179. },
  180. {
  181. path: 'position',
  182. name: 'order-position',
  183. component: () => import('../views/order/position/Index.vue'),
  184. },
  185. {
  186. path: 'delivery',
  187. name: 'order-delivery',
  188. component: () => import('../views/order/delivery/Index.vue'),
  189. },
  190. {
  191. path: 'performance',
  192. name: 'order-performance',
  193. component: () => import('@mobile/views/order/performance/Index.vue'),
  194. },
  195. ],
  196. },
  197. {
  198. path: '/mine',
  199. component: Page,
  200. children: [
  201. {
  202. path: 'address',
  203. name: 'mine-address',
  204. component: () => import('@mobile/views/mine/address/Index.vue'),
  205. },
  206. {
  207. path: 'invoice',
  208. name: 'mine-invoice',
  209. component: () => import('@mobile/views/mine/invoice/Index.vue'),
  210. },
  211. {
  212. path: 'profile',
  213. name: 'mine-profile',
  214. component: () => import('@mobile/views/mine/profile/Index.vue'),
  215. },
  216. {
  217. path: 'setting',
  218. name: 'mine-setting',
  219. component: () => import('@mobile/views/mine/setting/Index.vue'),
  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: '/report',
  246. component: Page,
  247. children: [
  248. {
  249. path: '',
  250. name: 'report',
  251. component: () => import('@mobile//views/report/index.vue'),
  252. }
  253. ]
  254. },
  255. {
  256. path: '/rules',
  257. component: Page,
  258. children: [
  259. {
  260. path: "zcxy",
  261. name: "rules-zcxy",
  262. component: () => import("@mobile/views/rules/zcxy/Index.vue"),
  263. meta: {
  264. ignoreAuth: true,
  265. },
  266. },
  267. {
  268. path: "yhkhfxgzs",
  269. name: "rules-yhkhfxgzs",
  270. component: () => import("@mobile/views/rules/fxgzs/Index.vue"),
  271. meta: {
  272. ignoreAuth: true,
  273. },
  274. },
  275. {
  276. path: "yszc",
  277. name: "rules-yszc",
  278. component: () => import("@mobile/views/rules/yszc/Index.vue"),
  279. meta: {
  280. ignoreAuth: true,
  281. },
  282. },
  283. {
  284. path: "gywm",
  285. name: "rules-gywm",
  286. component: () => import("@mobile/views/rules/gywm/Index.vue"),
  287. meta: {
  288. ignoreAuth: true,
  289. },
  290. },
  291. {
  292. path: "fwrx",
  293. name: "rules-fwrx",
  294. component: () => import("@mobile/views/rules/fwrx/Index.vue"),
  295. meta: {
  296. ignoreAuth: true,
  297. },
  298. },
  299. ]
  300. },
  301. ...pageRoutes
  302. ]
  303. const router = animateRouter.create({
  304. history: createWebHashHistory(),
  305. routes,
  306. })
  307. // 路由跳转拦截
  308. router.beforeEach((to, from, next) => {
  309. clearPending()
  310. // 判断服务是否加载完成
  311. if (service.isReady) {
  312. if (to.meta.ignoreAuth || loginStore.token) {
  313. next()
  314. } else {
  315. if (to.matched.some((e) => e.name === 'home')) {
  316. // 如果是主页导航页面,强制跳转到首页
  317. next({
  318. name: 'home-index',
  319. replace: true,
  320. })
  321. } else {
  322. next({
  323. name: 'user-login',
  324. query: { redirect: to.fullPath },
  325. })
  326. }
  327. }
  328. } else {
  329. if (to.name === 'boot' || to.name === 'user-login') {
  330. next()
  331. } else {
  332. next({
  333. name: 'boot',
  334. query: { redirect: to.fullPath },
  335. })
  336. }
  337. }
  338. })
  339. export default router