index.ts 9.7 KB

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