index.ts 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  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. path: 'details',
  153. name: 'contract-details',
  154. component: () => import('../views/contract/details/index.vue'),
  155. }
  156. ]
  157. },
  158. {
  159. path: '/bank',
  160. component: Page,
  161. children: [
  162. {
  163. path: 'bank',
  164. name: 'bank-wallet',
  165. component: () => import('../views/bank/wallet/index.vue'),
  166. },
  167. {
  168. path: 'sign',
  169. name: 'bank-sign',
  170. component: () => import('../views/bank/sign/index.vue'),
  171. },
  172. {
  173. path: 'edit',
  174. name: 'add-banksign',
  175. component: () => import('../views/bank/sign/components/edit/index.vue'),
  176. },
  177. {
  178. path: 'statement',
  179. name: 'bank-statement',
  180. component: () => import('../views/bank/statement/index.vue'),
  181. },
  182. {
  183. path: 'hisstatement',
  184. name: 'bank-hisstatement',
  185. component: () => import('../views/bank/hisstatement/index.vue'),
  186. },
  187. ]
  188. },
  189. {
  190. path: '/order',
  191. component: Page,
  192. children: [
  193. {
  194. path: '',
  195. name: 'my-order',
  196. component: () => import('../views/mine/order/list/index.vue'),
  197. },
  198. {
  199. path: 'purchasetradedetail',
  200. name: 'purchase-trade-detail',
  201. component: () => import('../views/mine/order/detail/purchasetrade/index.vue'),
  202. },
  203. {
  204. path: 'wrtradedetail',
  205. name: 'wrtrade-detail',
  206. component: () => import('../views/mine/order/detail/wrtrade/index.vue'),
  207. },
  208. {
  209. path: 'wrorderdetail',
  210. name: 'wrorder-detail',
  211. component: () => import('../views/mine/order/detail/wrorder/index.vue'),
  212. },
  213. {
  214. path: 'transferdetail',
  215. name: 'transfer-detail',
  216. component: () => import('../views/mine/order/detail/transfer/index.vue'),
  217. }
  218. ]
  219. },
  220. {
  221. path: '/wareorder',
  222. component: Page,
  223. children: [
  224. {
  225. path: '',
  226. name: 'my-wareorder',
  227. component: () => import('../views/mine/wareorder/list/index.vue'),
  228. },
  229. {
  230. path: 'wroutinapplydetail',
  231. name: 'wroutinapply-detail',
  232. component: () => import('../views/mine/wareorder/wroutinapplydetail/index.vue'),
  233. },
  234. {
  235. path: 'pickup',
  236. name: 'warehouse-pickup',
  237. component: () => import('../views/mine/wareorder/pickup/index.vue'),
  238. },
  239. {
  240. path: 'listing',
  241. name: 'warehouse-listing',
  242. component: () => import('../views/mine/wareorder/listing/index.vue'),
  243. }
  244. ]
  245. },
  246. {
  247. path: '/rules',
  248. component: Page,
  249. children: [
  250. {
  251. path: 'ptgz',
  252. name: 'rules-ptgz',
  253. component: () => import('../views/rules/ptgz/index.vue'),
  254. },
  255. {
  256. path: 'myrz',
  257. name: 'rules-myrz',
  258. component: () => import('../views/rules/myrz/index.vue'),
  259. },
  260. {
  261. path: 'ccwl',
  262. name: 'rules-ccwl',
  263. component: () => import('../views/rules/ccwl/index.vue'),
  264. },
  265. {
  266. path: 'zcxy',
  267. name: 'rules-zcxy',
  268. component: () => import('../views/rules/zcxy/index.vue'),
  269. meta: {
  270. ignoreAuth: true,
  271. },
  272. },
  273. {
  274. path: 'yhkhfxgzs',
  275. name: 'rules-yhkhfxgzs',
  276. component: () => import('../views/rules/fxgzs/index.vue'),
  277. meta: {
  278. ignoreAuth: true,
  279. },
  280. },
  281. {
  282. path: 'yszc',
  283. name: 'rules-yszc',
  284. component: () => import('../views/rules/yszc/index.vue'),
  285. meta: {
  286. ignoreAuth: true,
  287. },
  288. },
  289. {
  290. path: 'gywm',
  291. name: 'rules-gywm',
  292. component: () => import('../views/rules/gywm/index.vue'),
  293. },
  294. {
  295. path: 'fpsm',
  296. name: 'rules-fpsm',
  297. component: () => import('../views/rules/fpsm/index.vue'),
  298. },
  299. {
  300. path: 'fwrx',
  301. name: 'rules-fwrx',
  302. component: () => import('../views/rules/fwrx/index.vue'),
  303. },
  304. ]
  305. },
  306. {
  307. path: '/credit',
  308. component: Page,
  309. children: [
  310. {
  311. path: 'signin',
  312. name: 'credit-signin',
  313. component: () => import('../views/credit/signin/index.vue'),
  314. },
  315. {
  316. path: 'statement',
  317. name: 'credit-statement',
  318. component: () => import('../views/credit/statement/index.vue'),
  319. },
  320. {
  321. path: 'lottery',
  322. name: 'credit-lottery',
  323. component: () => import('../views/credit/lottery/index.vue'),
  324. },
  325. ]
  326. },
  327. {
  328. path: '/mine',
  329. component: Page,
  330. children: [
  331. {
  332. path: 'generalize',
  333. name: 'mine-generalize',
  334. component: () => import('../views/mine/generalize/index.vue'),
  335. },
  336. {
  337. path: 'promotion',
  338. name: 'promotion-detail',
  339. component: () => import('../views/mine/generalize/detail/index.vue'),
  340. },
  341. {
  342. path: 'service',
  343. name: 'mine-service',
  344. component: () => import('../views/mine/service/index.vue'),
  345. },
  346. {
  347. path: 'address',
  348. name: 'mine-address',
  349. component: () => import('../views/mine/address/index.vue'),
  350. },
  351. {
  352. path: 'invoice',
  353. name: 'mine-invoice',
  354. component: () => import('../views/mine/invoice/index.vue'),
  355. },
  356. ]
  357. },
  358. {
  359. path: '/setting',
  360. component: Page,
  361. children: [
  362. {
  363. path: '',
  364. name: 'setting',
  365. component: () => import('../views/setting/main/index.vue'),
  366. },
  367. {
  368. path: 'password',
  369. name: 'setting-password',
  370. component: () => import('../views/setting/password/index.vue'),
  371. },
  372. ]
  373. }
  374. ]
  375. const router = animateRouter.create({
  376. history: createWebHashHistory(),
  377. routes,
  378. })
  379. // 路由跳转拦截
  380. router.beforeEach((to, from, next) => {
  381. // 判断服务是否加载完成
  382. if (service.isReady) {
  383. if (to.meta.ignoreAuth || getToken()) {
  384. next();
  385. } else {
  386. next({
  387. name: 'login',
  388. query: { redirect: to.fullPath },
  389. });
  390. }
  391. } else {
  392. if (to.name === 'boot' || to.name === 'login') {
  393. next();
  394. } else {
  395. next({
  396. name: 'boot',
  397. query: { redirect: to.fullPath },
  398. });
  399. }
  400. }
  401. })
  402. export default router