index.ts 9.2 KB

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