index.ts 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  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: 'swap',
  44. name: 'home-swap',
  45. component: () => import('@mobile/views/swap/list/Index.vue'),
  46. },
  47. {
  48. path: 'spot',
  49. name: 'home-spot',
  50. component: () => import('@mobile/views/spot/list/Index.vue'),
  51. },
  52. {
  53. path: 'market',
  54. name: 'home-market',
  55. component: () => import('@mobile/views/market/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('@mobile/views/user/register/Index.vue'),
  82. meta: {
  83. ignoreAuth: true,
  84. },
  85. },
  86. {
  87. path: 'forget',
  88. name: 'user-forget',
  89. component: () => import('@mobile/views/user/forget/Index.vue'),
  90. meta: {
  91. ignoreAuth: true,
  92. },
  93. },
  94. {
  95. path: 'cancel',
  96. name: 'user-cancel',
  97. component: () => import('@mobile/views/user/cancel/Index.vue'),
  98. },
  99. {
  100. path: 'password',
  101. name: 'user-password',
  102. component: () => import('@mobile/views/user/password/Index.vue'),
  103. },
  104. {
  105. path: 'avatar',
  106. name: 'user-avatar',
  107. component: () => import('@mobile/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. path: 'protocol',
  122. name: 'account-protocol',
  123. component: () => import('../views/account/protocol/Index.vue'),
  124. }
  125. ],
  126. },
  127. {
  128. path: '/report',
  129. component: Page,
  130. children: [
  131. {
  132. path: '',
  133. name: 'report',
  134. component: () => import('@mobile//views/report/index.vue'),
  135. }
  136. ]
  137. },
  138. {
  139. path: '/news',
  140. component: Page,
  141. children: [
  142. {
  143. path: '',
  144. name: 'news-list',
  145. component: () => import('@mobile/views/news/list/Index.vue'),
  146. meta: {
  147. ignoreAuth: true,
  148. },
  149. },
  150. {
  151. path: 'detail',
  152. name: 'news-detail',
  153. component: () => import('@mobile/views/news/detail/Index.vue'),
  154. meta: {
  155. ignoreAuth: true,
  156. },
  157. },
  158. ],
  159. },
  160. {
  161. path: '/market',
  162. component: Page,
  163. children: [
  164. {
  165. path: 'detail',
  166. name: 'market-detail',
  167. component: () => import('@mobile/views/market/detail/Index.vue'),
  168. }
  169. ]
  170. },
  171. {
  172. path: '/swap',
  173. component: Page,
  174. children: [
  175. {
  176. path: 'detail',
  177. name: 'swap-detail',
  178. component: () => import('@mobile/views/swap/detail/Index.vue'),
  179. }
  180. ]
  181. },
  182. {
  183. path: '/spot',
  184. component: Page,
  185. children: [
  186. {
  187. path: 'detail',
  188. name: 'spot-detail',
  189. component: () => import('@mobile/views/spot/detail/Index.vue'),
  190. },
  191. {
  192. path: 'add',
  193. name: 'spot-add',
  194. component: () => import('@mobile/views/spot/add/index.vue'),
  195. },
  196. ],
  197. },
  198. {
  199. path: '/bank',
  200. component: Page,
  201. children: [
  202. {
  203. path: 'wallet',
  204. name: 'bank-wallet',
  205. component: () => import('@mobile/views/bank/wallet/Index.vue'),
  206. },
  207. {
  208. path: 'sign',
  209. name: 'bank-sign',
  210. component: () => import('@mobile/views/bank/sign/Index.vue'),
  211. },
  212. {
  213. path: 'capital',
  214. name: 'bank-capital',
  215. component: () => import('@mobile/views/bank/capital/index.vue'),
  216. }
  217. ]
  218. },
  219. {
  220. path: '/order',
  221. component: Page,
  222. children: [
  223. {
  224. path: 'list',
  225. name: 'order-list',
  226. component: () => import('../views/order/list/Index.vue'),
  227. },
  228. {
  229. path: 'position',
  230. name: 'order-position',
  231. component: () => import('../views/order/position/Index.vue'),
  232. },
  233. {
  234. path: 'delivery',
  235. name: 'order-delivery',
  236. component: () => import('../views/order/delivery/Index.vue'),
  237. },
  238. {
  239. path: 'performance',
  240. name: 'order-performance',
  241. component: () => import('@mobile/views/order/performance/Index.vue'),
  242. },
  243. ],
  244. },
  245. {
  246. path: '/mine',
  247. component: Page,
  248. children: [
  249. {
  250. path: 'address',
  251. name: 'mine-address',
  252. component: () => import('@mobile/views/mine/address/Index.vue'),
  253. },
  254. {
  255. path: 'invoice',
  256. name: 'mine-invoice',
  257. component: () => import('@mobile/views/mine/invoice/Index.vue'),
  258. },
  259. {
  260. path: 'profile',
  261. name: 'mine-profile',
  262. component: () => import('@mobile/views/mine/profile/Index.vue'),
  263. },
  264. {
  265. path: 'setting',
  266. name: 'mine-setting',
  267. component: () => import('@mobile/views/mine/setting/Index.vue'),
  268. props: {
  269. showCancel: false
  270. }
  271. },
  272. {
  273. path: 'wechat',
  274. name: 'mine-wechat',
  275. component: () => import('@mobile/views/mine/wechat/Index.vue'),
  276. },
  277. {
  278. path: 'email',
  279. name: 'mine-email',
  280. component: () => import('@mobile/views/mine/email/Index.vue'),
  281. }
  282. ]
  283. },
  284. {
  285. path: '/notice',
  286. component: Page,
  287. children: [
  288. {
  289. path: '',
  290. name: 'notice-list',
  291. component: () => import('@mobile/views/notice/list/index.vue'),
  292. }
  293. ]
  294. },
  295. {
  296. path: '/rules',
  297. component: Page,
  298. children: [
  299. {
  300. path: "zcxy",
  301. name: "rules-zcxy",
  302. component: () => import("@mobile/views/rules/zcxy/Index.vue"),
  303. meta: {
  304. ignoreAuth: true,
  305. },
  306. },
  307. {
  308. path: "yhkhfxgzs",
  309. name: "rules-yhkhfxgzs",
  310. component: () => import("@mobile/views/rules/fxgzs/Index.vue"),
  311. meta: {
  312. ignoreAuth: true,
  313. },
  314. },
  315. {
  316. path: "yszc",
  317. name: "rules-yszc",
  318. component: () => import("@mobile/views/rules/yszc/Index.vue"),
  319. meta: {
  320. ignoreAuth: true,
  321. },
  322. },
  323. {
  324. path: "gywm",
  325. name: "rules-gywm",
  326. component: () => import("@mobile/views/rules/gywm/Index.vue"),
  327. meta: {
  328. ignoreAuth: true,
  329. },
  330. },
  331. {
  332. path: "fwrx",
  333. name: "rules-fwrx",
  334. component: () => import("@mobile/views/rules/fwrx/Index.vue"),
  335. meta: {
  336. ignoreAuth: true,
  337. }
  338. }
  339. ]
  340. }
  341. ]
  342. const router = animateRouter.create({
  343. history: createWebHashHistory(),
  344. routes,
  345. })
  346. // 路由跳转拦截
  347. router.beforeEach((to, from, next) => {
  348. clearPending()
  349. // 判断服务是否加载完成
  350. if (service.isReady) {
  351. if (to.meta.ignoreAuth || loginStore.token) {
  352. next()
  353. } else {
  354. if (to.matched.some((e) => e.name === 'home')) {
  355. // 如果是主页导航页面,强制跳转到首页
  356. next({
  357. name: 'home-index',
  358. replace: true,
  359. })
  360. } else {
  361. next({
  362. name: 'user-login',
  363. query: { redirect: to.fullPath },
  364. })
  365. }
  366. }
  367. } else {
  368. if (to.name === 'boot' || to.name === 'user-login') {
  369. next()
  370. } else {
  371. next({
  372. name: 'boot',
  373. query: { redirect: to.fullPath },
  374. })
  375. }
  376. }
  377. })
  378. export default router