index.ts 7.0 KB

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