index.ts 9.8 KB

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