index.ts 7.8 KB

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