index.ts 8.5 KB

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