index.ts 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  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: 'product',
  130. name: 'product',
  131. component: () => import('../views/product/index.vue'),
  132. meta: {
  133. ignoreAuth: true,
  134. },
  135. },
  136. {
  137. path: 'productdetail',
  138. name: 'product-detail',
  139. component: () => import('../views/product/detail/index.vue'),
  140. meta: {
  141. ignoreAuth: true,
  142. },
  143. }
  144. ]
  145. },
  146. {
  147. path: '/goods',
  148. component: Page,
  149. children: [
  150. {
  151. path: 'details',
  152. name: 'goods-details',
  153. component: () => import('../views/goods/details/index.vue'),
  154. meta: {
  155. ignoreAuth: true,
  156. },
  157. }
  158. ]
  159. },
  160. {
  161. path: '/market',
  162. component: Page,
  163. children: [
  164. {
  165. path: '',
  166. name: 'market',
  167. component: () => import('../views/market/main/index.vue'),
  168. },
  169. {
  170. path: 'detail',
  171. name: 'market-detail',
  172. component: () => import('../views/market/details/index.vue'),
  173. }
  174. ]
  175. },
  176. {
  177. path: '/bank',
  178. component: Page,
  179. children: [
  180. {
  181. path: 'bank',
  182. name: 'bank-wallet',
  183. component: () => import('../views/bank/wallet/index.vue'),
  184. },
  185. {
  186. path: 'sign',
  187. name: 'bank-sign',
  188. component: () => import('../views/bank/sign/index.vue'),
  189. },
  190. {
  191. path: 'edit',
  192. name: 'add-banksign',
  193. component: () => import('../views/bank/sign/components/edit/index.vue'),
  194. },
  195. {
  196. path: 'statement',
  197. name: 'bank-statement',
  198. component: () => import('../views/bank/statement/index.vue'),
  199. },
  200. {
  201. path: 'hisstatement',
  202. name: 'bank-hisstatement',
  203. component: () => import('../views/bank/hisstatement/index.vue'),
  204. },
  205. ]
  206. },
  207. {
  208. path: '/order',
  209. component: Page,
  210. children: [
  211. {
  212. path: 'order',
  213. name: 'my-order',
  214. component: () => import('../views/mine/order/index.vue'),
  215. },
  216. {
  217. path: 'purchasetrade',
  218. name: 'purchase-trade',
  219. component: () => import('../views/mine/order/components/purchasetrade/index.vue'),
  220. },
  221. {
  222. path: 'wrorder',
  223. name: 'wr-order',
  224. component: () => import('../views/mine/order/components/wrorder/index.vue'),
  225. },
  226. {
  227. path: 'wrtrade',
  228. name: 'wr-trade',
  229. component: () => import('../views/mine/order/components/wrtrade/index.vue'),
  230. },
  231. {
  232. path: 'purchasetradedetail',
  233. name: 'purchase-trade-detail',
  234. component: () => import('../views/mine/order/purchasetradedetail/index.vue'),
  235. }
  236. ]
  237. },
  238. {
  239. path: '/rules',
  240. component: Page,
  241. children: [
  242. {
  243. path: 'ptgz',
  244. name: 'rules-ptgz',
  245. component: () => import('../views/rules/ptgz/index.vue'),
  246. },
  247. {
  248. path: 'myrz',
  249. name: 'rules-myrz',
  250. component: () => import('../views/rules/myrz/index.vue'),
  251. },
  252. {
  253. path: 'ccwl',
  254. name: 'rules-ccwl',
  255. component: () => import('../views/rules/ccwl/index.vue'),
  256. },
  257. {
  258. path: 'zcxy',
  259. name: 'rules-zcxy',
  260. component: () => import('../views/rules/zcxy/index.vue'),
  261. meta: {
  262. ignoreAuth: true,
  263. },
  264. },
  265. {
  266. path: 'yszc',
  267. name: 'rules-yszc',
  268. component: () => import('../views/rules/yszc/index.vue'),
  269. meta: {
  270. ignoreAuth: true,
  271. },
  272. },
  273. {
  274. path: 'gywm',
  275. name: 'rules-gywm',
  276. component: () => import('../views/rules/gywm/index.vue'),
  277. },
  278. ]
  279. },
  280. {
  281. path: '/credit',
  282. component: Page,
  283. children: [
  284. {
  285. path: 'signin',
  286. name: 'credit-signin',
  287. component: () => import('../views/credit/signin/index.vue'),
  288. },
  289. {
  290. path: 'statement',
  291. name: 'credit-statement',
  292. component: () => import('../views/credit/statement/index.vue'),
  293. },
  294. {
  295. path: 'lottery',
  296. name: 'credit-lottery',
  297. component: () => import('../views/credit/lottery/index.vue'),
  298. },
  299. ]
  300. },
  301. {
  302. path: '/mine',
  303. component: Page,
  304. children: [
  305. {
  306. path: 'generalize',
  307. name: 'mine-generalize',
  308. component: () => import('../views/mine/generalize/index.vue'),
  309. },
  310. {
  311. path: 'service',
  312. name: 'mine-service',
  313. component: () => import('../views/mine/service/index.vue'),
  314. },
  315. {
  316. path: 'address',
  317. name: 'mine-address',
  318. component: () => import('../views/mine/address/index.vue'),
  319. },
  320. ]
  321. },
  322. {
  323. path: '/setting',
  324. component: Page,
  325. children: [
  326. {
  327. path: '',
  328. name: 'setting',
  329. component: () => import('../views/setting/main/index.vue'),
  330. },
  331. {
  332. path: 'password',
  333. name: 'setting-password',
  334. component: () => import('../views/setting/password/index.vue'),
  335. },
  336. ]
  337. }
  338. ]
  339. const router = animateRouter.create({
  340. history: createWebHashHistory(),
  341. routes,
  342. })
  343. // 路由跳转拦截
  344. router.beforeEach((to, from, next) => {
  345. // 判断服务是否加载完成
  346. if (service.isReady) {
  347. if (to.meta.ignoreAuth || getToken()) {
  348. next();
  349. } else {
  350. next({
  351. name: 'login',
  352. query: { redirect: to.fullPath },
  353. });
  354. }
  355. } else {
  356. if (to.name === 'boot' || to.name === 'login') {
  357. next();
  358. } else {
  359. next({
  360. name: 'boot',
  361. query: { redirect: to.fullPath },
  362. });
  363. }
  364. }
  365. })
  366. export default router