index.ts 9.3 KB

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