index.ts 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. import { createWebHashHistory, RouteRecordRaw } from 'vue-router'
  2. import { useLoginStore } from '@/stores'
  3. import { clearPending } from '@/services/http/pending'
  4. import service from '@/services'
  5. import Page from '@mobile/components/layouts/page/index.vue'
  6. import animateRouter from '@mobile/router/animateRouter'
  7. const loginStore = useLoginStore()
  8. const routes: Array<RouteRecordRaw> = [
  9. {
  10. path: '/:pathMatch(.*)*',
  11. name: 'error',
  12. component: () => import('../views/error/404.vue'),
  13. meta: {
  14. ignoreAuth: true,
  15. },
  16. },
  17. {
  18. path: '/boot',
  19. name: 'boot',
  20. component: () => import('../views/boot/Index.vue'),
  21. meta: {
  22. ignoreAuth: true,
  23. },
  24. },
  25. {
  26. path: '/',
  27. component: Page,
  28. children: [
  29. {
  30. path: '',
  31. name: 'home',
  32. component: () => import('../views/home/Index.vue'),
  33. children: [
  34. {
  35. path: '',
  36. name: 'home-index',
  37. component: () => import('../views/home/main/Index.vue'),
  38. meta: {
  39. ignoreAuth: true,
  40. },
  41. },
  42. {
  43. path: 'goods',
  44. name: 'home-goods',
  45. component: () => import('../views/goods/list/index.vue'),
  46. },
  47. {
  48. path: 'trade',
  49. name: 'home-trade',
  50. component: () => import('../views/goods/detail/index.vue'),
  51. props: {
  52. showBackButton: false
  53. }
  54. },
  55. {
  56. path: 'mine',
  57. name: 'home-mine',
  58. component: () => import('../views/mine/Index.vue'),
  59. }
  60. ]
  61. },
  62. ],
  63. },
  64. {
  65. path: '/user',
  66. component: Page,
  67. children: [
  68. {
  69. path: 'login',
  70. name: 'user-login',
  71. component: () => import('../views/user/login/Index.vue'),
  72. meta: {
  73. ignoreAuth: true,
  74. },
  75. },
  76. {
  77. path: 'register',
  78. name: 'user-register',
  79. component: () => import('@mobile/views/user/register/Index.vue'),
  80. meta: {
  81. ignoreAuth: true,
  82. },
  83. },
  84. {
  85. path: 'forget',
  86. name: 'user-forget',
  87. component: () => import('@mobile/views/user/forget/Index.vue'),
  88. meta: {
  89. ignoreAuth: true,
  90. },
  91. },
  92. {
  93. path: 'cancel',
  94. name: 'user-cancel',
  95. component: () => import('@mobile/views/user/cancel/Index.vue'),
  96. },
  97. {
  98. path: 'password',
  99. name: 'user-password',
  100. component: () => import('@mobile/views/user/password/Index.vue'),
  101. },
  102. {
  103. path: 'avatar',
  104. name: 'user-avatar',
  105. component: () => import('@mobile/views/user/avatar/Index.vue'),
  106. },
  107. ],
  108. },
  109. {
  110. path: '/account',
  111. component: Page,
  112. children: [
  113. {
  114. path: 'certification',
  115. name: 'account-certification',
  116. component: () => import('@mobile/views/account/certification/Index.vue'),
  117. },
  118. ],
  119. },
  120. {
  121. path: '/news',
  122. component: Page,
  123. children: [
  124. {
  125. path: '',
  126. name: 'news-list',
  127. component: () => import('@mobile/views/news/list/Index.vue'),
  128. meta: {
  129. ignoreAuth: true,
  130. },
  131. },
  132. {
  133. path: 'detail',
  134. name: 'news-detail',
  135. component: () => import('@mobile/views/news/detail/Index.vue'),
  136. meta: {
  137. ignoreAuth: true,
  138. },
  139. },
  140. ],
  141. },
  142. {
  143. path: '/goods',
  144. component: Page,
  145. children: [
  146. {
  147. path: 'detail',
  148. name: 'goods-detail',
  149. component: () => import('../views/goods/detail/index.vue'),
  150. },
  151. {
  152. path: 'trade',
  153. name: 'goods-trade',
  154. component: () => import('@mobile/views/goods/trade/index.vue'),
  155. },
  156. ],
  157. },
  158. {
  159. path: '/bank',
  160. component: Page,
  161. children: [
  162. {
  163. path: 'wallet',
  164. name: 'bank-wallet',
  165. component: () => import('@mobile/views/bank/wallet/Index.vue'),
  166. },
  167. {
  168. path: 'sign',
  169. name: 'bank-sign',
  170. component: () => import('@mobile/views/bank/sign/Index.vue'),
  171. },
  172. {
  173. path: 'capital',
  174. name: 'bank-capital',
  175. component: () => import('@mobile/views/bank/capital/index.vue'),
  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('@mobile/views/order/performance/Index.vue'),
  202. },
  203. ],
  204. },
  205. {
  206. path: '/mine',
  207. component: Page,
  208. children: [
  209. {
  210. path: 'address',
  211. name: 'mine-address',
  212. component: () => import('@mobile/views/mine/address/Index.vue'),
  213. },
  214. {
  215. path: 'invoice',
  216. name: 'mine-invoice',
  217. component: () => import('@mobile/views/mine/invoice/Index.vue'),
  218. },
  219. {
  220. path: 'profile',
  221. name: 'mine-profile',
  222. component: () => import('@mobile/views/mine/profile/Index.vue'),
  223. },
  224. {
  225. path: 'setting',
  226. name: 'mine-setting',
  227. component: () => import('@mobile/views/mine/setting/Index.vue'),
  228. },
  229. ],
  230. },
  231. {
  232. path: '/notice',
  233. component: Page,
  234. children: [
  235. {
  236. path: '',
  237. name: 'notice-list',
  238. component: () => import('@mobile/views/notice/list/index.vue'),
  239. },
  240. ],
  241. },
  242. {
  243. path: '/rules',
  244. component: Page,
  245. children: [
  246. {
  247. path: "zcxy",
  248. name: "rules-zcxy",
  249. component: () => import("@mobile/views/rules/zcxy/Index.vue"),
  250. meta: {
  251. ignoreAuth: true,
  252. },
  253. },
  254. {
  255. path: "yhkhfxgzs",
  256. name: "rules-yhkhfxgzs",
  257. component: () => import("@mobile/views/rules/fxgzs/Index.vue"),
  258. meta: {
  259. ignoreAuth: true,
  260. },
  261. },
  262. {
  263. path: "yszc",
  264. name: "rules-yszc",
  265. component: () => import("@mobile/views/rules/yszc/Index.vue"),
  266. meta: {
  267. ignoreAuth: true,
  268. },
  269. },
  270. {
  271. path: "gywm",
  272. name: "rules-gywm",
  273. component: () => import("@mobile/views/rules/gywm/Index.vue"),
  274. meta: {
  275. ignoreAuth: true,
  276. },
  277. },
  278. {
  279. path: "fwrx",
  280. name: "rules-fwrx",
  281. component: () => import("@mobile/views/rules/fwrx/Index.vue"),
  282. meta: {
  283. ignoreAuth: true,
  284. },
  285. },
  286. ]
  287. }
  288. ]
  289. const router = animateRouter.create({
  290. history: createWebHashHistory(),
  291. routes,
  292. })
  293. // 路由跳转拦截
  294. router.beforeEach((to, from, next) => {
  295. clearPending()
  296. // 判断服务是否加载完成
  297. if (service.isReady) {
  298. if (to.meta.ignoreAuth || loginStore.token) {
  299. next()
  300. } else {
  301. next({
  302. name: 'user-login',
  303. query: { redirect: to.fullPath },
  304. })
  305. }
  306. } else {
  307. if (to.name === 'boot' || to.name === 'user-login') {
  308. next()
  309. } else {
  310. next({
  311. name: 'boot',
  312. query: { redirect: to.fullPath },
  313. })
  314. }
  315. }
  316. })
  317. export default router