index.ts 8.6 KB

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