index.ts 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455
  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 './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: 'presale',
  44. name: 'home-presale',
  45. component: () => import('../views/presale/list/Index.vue'),
  46. },
  47. {
  48. path: 'transfer',
  49. name: 'home-transfer',
  50. component: () => import('../views/transfer/list/Index.vue'),
  51. },
  52. {
  53. path: 'swap',
  54. name: 'home-swap',
  55. component: () => import('../views/swap/list/Index.vue'),
  56. },
  57. {
  58. path: 'mine',
  59. name: 'home-mine',
  60. component: () => import('../views/mine/Index.vue'),
  61. }
  62. ]
  63. },
  64. ],
  65. },
  66. {
  67. path: '/user',
  68. component: Page,
  69. children: [
  70. {
  71. path: 'login',
  72. name: "user-login",
  73. component: () => import('../views/user/login/Index.vue'),
  74. meta: {
  75. ignoreAuth: true,
  76. },
  77. },
  78. {
  79. path: 'register',
  80. name: "user-register",
  81. component: () => import('../views/user/register/Index.vue'),
  82. meta: {
  83. ignoreAuth: true,
  84. },
  85. },
  86. {
  87. path: 'forget',
  88. name: "user-forget",
  89. component: () => import('../views/user/forget/Index.vue'),
  90. meta: {
  91. ignoreAuth: true,
  92. },
  93. },
  94. {
  95. path: 'cancel',
  96. name: 'user-cancel',
  97. component: () => import('../views/user/cancel/Index.vue'),
  98. },
  99. {
  100. path: 'password',
  101. name: 'user-password',
  102. component: () => import('../views/user/password/Index.vue'),
  103. },
  104. {
  105. path: 'avatar',
  106. name: 'user-avatar',
  107. component: () => import('../views/user/avatar/Index.vue'),
  108. },
  109. ],
  110. },
  111. {
  112. path: '/account',
  113. component: Page,
  114. children: [
  115. {
  116. path: 'certification',
  117. name: 'account-certification',
  118. component: () => import('../views/account/certification/Index.vue'),
  119. },
  120. ],
  121. },
  122. {
  123. path: '/news',
  124. component: Page,
  125. children: [
  126. {
  127. path: 'list',
  128. name: 'news-list',
  129. component: () => import('../views/news/list/Index.vue'),
  130. meta: {
  131. ignoreAuth: true,
  132. },
  133. },
  134. {
  135. path: 'detail',
  136. name: 'news-detail',
  137. component: () => import('../views/news/detail/Index.vue'),
  138. meta: {
  139. ignoreAuth: true,
  140. },
  141. },
  142. ],
  143. },
  144. {
  145. path: '/market',
  146. component: Page,
  147. children: [
  148. {
  149. path: 'list',
  150. name: 'market-list',
  151. component: () => import('../views/market/list/Index.vue'),
  152. },
  153. {
  154. path: 'detail',
  155. name: 'market-detail',
  156. component: () => import('../views/market/detail/Index.vue'),
  157. },
  158. ],
  159. },
  160. {
  161. path: '/presale',
  162. component: Page,
  163. children: [
  164. {
  165. path: 'detail',
  166. name: 'presale-detail',
  167. component: () => import('../views/presale/detail/Index.vue'),
  168. },
  169. ],
  170. },
  171. {
  172. path: '/transfer',
  173. component: Page,
  174. children: [
  175. {
  176. path: 'detail',
  177. name: 'transfer-detail',
  178. component: () => import('../views/transfer/detail/Index.vue'),
  179. },
  180. ],
  181. },
  182. {
  183. path: '/swap',
  184. component: Page,
  185. children: [
  186. {
  187. path: 'detail',
  188. name: 'swap-detail',
  189. component: () => import('../views/swap/detail/Index.vue'),
  190. },
  191. ],
  192. },
  193. {
  194. path: '/spot',
  195. component: Page,
  196. children: [
  197. {
  198. path: 'list',
  199. name: 'spot-list',
  200. component: () => import('../views/spot/list/Index.vue'),
  201. },
  202. {
  203. path: 'detail',
  204. name: 'spot-detail',
  205. component: () => import('../views/spot/detail/Index.vue'),
  206. },
  207. ],
  208. },
  209. {
  210. path: '/bank',
  211. component: Page,
  212. children: [
  213. {
  214. path: 'wallet',
  215. name: 'bank-wallet',
  216. component: () => import('../views/bank/wallet/Index.vue'),
  217. },
  218. {
  219. path: 'sign',
  220. name: 'bank-sign',
  221. component: () => import('../views/bank/sign/Index.vue'),
  222. },
  223. {
  224. path: 'statement',
  225. name: 'bank-statement',
  226. component: () => import('../views/bank/statement/Index.vue'),
  227. },
  228. {
  229. path: 'statement/history',
  230. name: 'bank-statement-history',
  231. component: () => import('../views/bank/statement/history/Index.vue'),
  232. },
  233. ],
  234. },
  235. {
  236. path: '/order',
  237. component: Page,
  238. children: [
  239. {
  240. path: 'list',
  241. name: 'order-list',
  242. component: () => import('../views/order/list/Index.vue'),
  243. },
  244. {
  245. path: 'position',
  246. name: 'order-position',
  247. component: () => import('../views/order/position/Index.vue'),
  248. },
  249. {
  250. path: 'delivery',
  251. name: 'order-delivery',
  252. component: () => import('../views/order/delivery/Index.vue'),
  253. },
  254. {
  255. path: 'performance',
  256. name: 'order-performance',
  257. component: () => import('../views/order/performance/Index.vue'),
  258. },
  259. ],
  260. },
  261. {
  262. path: '/mine',
  263. component: Page,
  264. children: [
  265. {
  266. path: 'address',
  267. name: 'mine-address',
  268. component: () => import('../views/mine/address/Index.vue'),
  269. },
  270. {
  271. path: 'invoice',
  272. name: 'mine-invoice',
  273. component: () => import('../views/mine/invoice/Index.vue'),
  274. },
  275. {
  276. path: 'profile',
  277. name: 'mine-profile',
  278. component: () => import('../views/mine/profile/Index.vue'),
  279. },
  280. {
  281. path: 'setting',
  282. name: 'mine-setting',
  283. component: () => import('../views/mine/setting/Index.vue'),
  284. },
  285. ],
  286. },
  287. {
  288. path: '/rules',
  289. component: Page,
  290. children: [
  291. {
  292. path: "ptgz",
  293. name: "rules-ptgz",
  294. component: () => import("../views/rules/ptgz/Index.vue"),
  295. meta: {
  296. ignoreAuth: true,
  297. },
  298. },
  299. {
  300. path: "myrz",
  301. name: "rules-myrz",
  302. component: () => import("../views/rules/myrz/Index.vue"),
  303. meta: {
  304. ignoreAuth: true,
  305. },
  306. },
  307. {
  308. path: "ccwl",
  309. name: "rules-ccwl",
  310. component: () => import("../views/rules/ccwl/Index.vue"),
  311. meta: {
  312. ignoreAuth: true,
  313. },
  314. },
  315. {
  316. path: "zcxy",
  317. name: "rules-zcxy",
  318. component: () => import("../views/rules/zcxy/Index.vue"),
  319. meta: {
  320. ignoreAuth: true,
  321. },
  322. },
  323. {
  324. path: "yhkhfxgzs",
  325. name: "rules-yhkhfxgzs",
  326. component: () => import("../views/rules/fxgzs/Index.vue"),
  327. meta: {
  328. ignoreAuth: true,
  329. },
  330. },
  331. {
  332. path: "yszc",
  333. name: "rules-yszc",
  334. component: () => import("../views/rules/yszc/Index.vue"),
  335. meta: {
  336. ignoreAuth: true,
  337. },
  338. },
  339. {
  340. path: "gywm",
  341. name: "rules-gywm",
  342. component: () => import("../views/rules/gywm/Index.vue"),
  343. meta: {
  344. ignoreAuth: true,
  345. },
  346. },
  347. {
  348. path: "fpsm",
  349. name: "rules-fpsm",
  350. component: () => import("../views/rules/fpsm/Index.vue"),
  351. meta: {
  352. ignoreAuth: true,
  353. },
  354. },
  355. {
  356. path: "fwrx",
  357. name: "rules-fwrx",
  358. component: () => import("../views/rules/fwrx/Index.vue"),
  359. meta: {
  360. ignoreAuth: true,
  361. },
  362. },
  363. {
  364. path: "buyrule",
  365. name: "rules-buyrule",
  366. component: () => import("../views/rules/buyrule/Index.vue"),
  367. meta: {
  368. ignoreAuth: true,
  369. },
  370. },
  371. {
  372. path: "sellrule",
  373. name: "rules-sellrule",
  374. component: () => import("../views/rules/sellrule/Index.vue"),
  375. meta: {
  376. ignoreAuth: true,
  377. },
  378. },
  379. {
  380. path: "djgz",
  381. name: "rules-dj",
  382. component: () => import("../views/rules/djgz/Index.vue"),
  383. meta: {
  384. ignoreAuth: true,
  385. },
  386. },
  387. {
  388. path: "jfgz",
  389. name: "rules-jf",
  390. component: () => import("../views/rules/jfgz/Index.vue"),
  391. meta: {
  392. ignoreAuth: true,
  393. },
  394. },
  395. {
  396. path: "cght",
  397. name: "rules-cght",
  398. component: () => import("../views/rules/cght/Index.vue"),
  399. meta: {
  400. ignoreAuth: true,
  401. },
  402. },
  403. {
  404. path: "zrht",
  405. name: "rules-zrht",
  406. component: () => import("../views/rules/zrht/Index.vue"),
  407. meta: {
  408. ignoreAuth: true,
  409. },
  410. },
  411. {
  412. path: "xhht",
  413. name: "rules-xhht",
  414. component: () => import("../views/rules/xhht/Index.vue"),
  415. meta: {
  416. ignoreAuth: true,
  417. },
  418. },
  419. ],
  420. },
  421. ]
  422. const router = animateRouter.create({
  423. history: createWebHashHistory(),
  424. routes,
  425. })
  426. // 路由跳转拦截
  427. router.beforeEach((to, from, next) => {
  428. clearPending()
  429. // 判断服务是否加载完成
  430. if (service.isReady) {
  431. if (to.meta.ignoreAuth || loginStore.token) {
  432. next()
  433. } else {
  434. next({
  435. name: 'user-login',
  436. query: { redirect: to.fullPath },
  437. })
  438. }
  439. } else {
  440. if (to.name === 'boot' || to.name === 'user-login') {
  441. next()
  442. } else {
  443. next({
  444. name: 'boot',
  445. query: { redirect: to.fullPath },
  446. })
  447. }
  448. }
  449. })
  450. export default router