index.ts 10 KB

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