index.ts 9.0 KB

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