index.ts 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  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('@mobile/views/error/404.vue'),
  13. meta: {
  14. ignoreAuth: true,
  15. },
  16. },
  17. {
  18. path: '/boot',
  19. name: 'boot',
  20. component: () => import('../../sbyj/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: 'market',
  44. name: 'home-market',
  45. component: () => import('../../sbyj/views/market/list/index.vue'),
  46. meta: {
  47. ignoreAuth: true,
  48. },
  49. },
  50. {
  51. path: 'news',
  52. name: 'home-news',
  53. component: () => import('../../sjgj/views/news/list/Index.vue'),
  54. meta: {
  55. ignoreAuth: true,
  56. },
  57. props: {
  58. showBackButton: false,
  59. columnid: 2,
  60. title: '研报'
  61. }
  62. },
  63. {
  64. path: 'mine',
  65. name: 'home-mine',
  66. component: () => import('../../sbyj/views/mine/index.vue'),
  67. }
  68. ]
  69. },
  70. ],
  71. },
  72. {
  73. path: '/user',
  74. component: Page,
  75. children: [
  76. {
  77. path: 'login',
  78. name: 'user-login',
  79. component: () => import('../views/user/login/index.vue'),
  80. meta: {
  81. ignoreAuth: true,
  82. },
  83. },
  84. {
  85. path: 'register',
  86. name: 'user-register',
  87. component: () => import('@mobile/views/user/register/Index.vue'),
  88. meta: {
  89. ignoreAuth: true,
  90. },
  91. },
  92. {
  93. path: 'forget',
  94. name: 'user-forget',
  95. component: () => import('@mobile/views/user/forget/Index.vue'),
  96. meta: {
  97. ignoreAuth: true,
  98. },
  99. },
  100. {
  101. path: 'cancel',
  102. name: 'user-cancel',
  103. component: () => import('@mobile/views/user/cancel/Index.vue'),
  104. },
  105. {
  106. path: 'password',
  107. name: 'user-password',
  108. component: () => import('@mobile/views/user/password/Index.vue'),
  109. },
  110. {
  111. path: 'avatar',
  112. name: 'user-avatar',
  113. component: () => import('@mobile/views/user/avatar/Index.vue'),
  114. },
  115. ],
  116. },
  117. {
  118. path: '/account',
  119. component: Page,
  120. children: [
  121. {
  122. path: 'certification',
  123. name: 'account-certification',
  124. component: () => import('../../sbyj/views/account/certification/Index.vue'),
  125. },
  126. {
  127. path: 'authresult',
  128. name: 'account-authresult',
  129. component: () => import('@mobile/views/account/authresult/Index.vue'),
  130. },
  131. {
  132. path: 'protocol',
  133. name: 'account-protocol',
  134. component: () => import('../../sbyj/views/account/protocol/Index.vue'),
  135. }
  136. ],
  137. },
  138. {
  139. path: '/news',
  140. component: Page,
  141. children: [
  142. {
  143. path: '',
  144. name: 'news-list',
  145. component: () => import('../../sjgj/views/news/list/Index.vue'),
  146. meta: {
  147. ignoreAuth: true,
  148. },
  149. props: {
  150. title: '业务公告',
  151. columnid: 1
  152. }
  153. },
  154. {
  155. path: 'detail',
  156. name: 'news-detail',
  157. component: () => import('@mobile/views/news/detail/Index.vue'),
  158. meta: {
  159. ignoreAuth: true,
  160. },
  161. },
  162. ],
  163. },
  164. {
  165. path: '/market',
  166. component: Page,
  167. children: [
  168. {
  169. path: '',
  170. name: 'market-list',
  171. component: () => import('../../sbyj/views/market/list/index.vue'),
  172. meta: {
  173. ignoreAuth: true,
  174. },
  175. },
  176. {
  177. path: 'detail',
  178. name: 'market-detail',
  179. component: () => import('../../sbyj/views/market/detail/index.vue'),
  180. },
  181. {
  182. path: 'chart',
  183. name: 'market-chart',
  184. component: () => import('@mobile/views/market/detail/Index.vue'),
  185. },
  186. ],
  187. },
  188. {
  189. path: '/bank',
  190. component: Page,
  191. children: [
  192. {
  193. path: 'wallet',
  194. name: 'bank-wallet',
  195. component: () => import('../../sbyj/views/bank/wallet/index.vue'),
  196. },
  197. {
  198. path: 'sign',
  199. name: 'bank-sign',
  200. component: () => import('@mobile/views/bank/sign/Index.vue'),
  201. },
  202. {
  203. path: 'capital',
  204. name: 'bank-capital',
  205. component: () => import('@mobile/views/bank/capital/index.vue'),
  206. }
  207. ]
  208. },
  209. {
  210. path: '/order',
  211. component: Page,
  212. children: [
  213. {
  214. path: '',
  215. name: 'order-list',
  216. component: () => import('../../sbyj/views/order/list/index.vue'),
  217. },
  218. {
  219. path: 'history',
  220. name: 'history-list',
  221. component: () => import('../../sbyj/views/order/history/index.vue'),
  222. },
  223. {
  224. path: 'close',
  225. name: 'close-list',
  226. component: () => import('../../sbyj/views/order/close/index.vue'),
  227. }
  228. ]
  229. },
  230. {
  231. path: '/delivery',
  232. component: Page,
  233. children: [
  234. {
  235. path: '',
  236. name: 'delivery-list',
  237. component: () => import('../../sbyj/views/delivery/index.vue'),
  238. props: {
  239. title: '交料订单',
  240. buyorsell: 1
  241. }
  242. }
  243. ]
  244. },
  245. {
  246. path: '/inventory',
  247. component: Page,
  248. children: [
  249. {
  250. path: '',
  251. name: 'inventory-list',
  252. component: () => import('../../sbyj/views/inventory/index.vue'),
  253. props: {
  254. title: '我的库存'
  255. }
  256. }
  257. ]
  258. },
  259. {
  260. path: '/pickup',
  261. component: Page,
  262. children: [
  263. {
  264. path: '',
  265. name: 'pickup-list',
  266. component: () => import('../../sbyj/views/delivery/index.vue'),
  267. props: {
  268. title: '提料订单',
  269. buyorsell: 0
  270. }
  271. }
  272. ]
  273. },
  274. {
  275. path: '/mine',
  276. component: Page,
  277. children: [
  278. {
  279. path: 'address',
  280. name: 'mine-address',
  281. component: () => import('@mobile/views/mine/address/Index.vue'),
  282. },
  283. {
  284. path: 'invoice',
  285. name: 'mine-invoice',
  286. component: () => import('@mobile/views/mine/invoice/Index.vue'),
  287. },
  288. {
  289. path: 'profile',
  290. name: 'mine-profile',
  291. component: () => import('@mobile/views/mine/profile/Index.vue'),
  292. },
  293. {
  294. path: 'setting',
  295. name: 'mine-setting',
  296. component: () => import('@mobile/views/mine/setting/Index.vue'),
  297. },
  298. {
  299. path: 'wechat',
  300. name: 'mine-wechat',
  301. component: () => import('@mobile/views/mine/wechat/Index.vue'),
  302. },
  303. {
  304. path: 'email',
  305. name: 'mine-email',
  306. component: () => import('@mobile/views/mine/email/Index.vue'),
  307. }
  308. ],
  309. },
  310. {
  311. path: '/notice',
  312. component: Page,
  313. children: [
  314. {
  315. path: '',
  316. name: 'notice-list',
  317. component: () => import('@mobile/views/notice/list/index.vue'),
  318. },
  319. ],
  320. },
  321. {
  322. path: '/rules',
  323. component: Page,
  324. children: [
  325. {
  326. path: "zcxy",
  327. name: "rules-zcxy",
  328. component: () => import("@mobile/views/rules/zcxy/Index.vue"),
  329. meta: {
  330. ignoreAuth: true,
  331. },
  332. },
  333. {
  334. path: "yhkhfxgzs",
  335. name: "rules-yhkhfxgzs",
  336. component: () => import("@mobile/views/rules/fxgzs/Index.vue"),
  337. meta: {
  338. ignoreAuth: true,
  339. },
  340. },
  341. {
  342. path: "yszc",
  343. name: "rules-yszc",
  344. component: () => import("@mobile/views/rules/yszc/Index.vue"),
  345. meta: {
  346. ignoreAuth: true,
  347. },
  348. },
  349. {
  350. path: "gywm",
  351. name: "rules-gywm",
  352. component: () => import("@mobile/views/rules/gywm/Index.vue"),
  353. meta: {
  354. ignoreAuth: true,
  355. },
  356. },
  357. {
  358. path: "fwrx",
  359. name: "rules-fwrx",
  360. component: () => import("@mobile/views/rules/fwrx/Index.vue"),
  361. meta: {
  362. ignoreAuth: true,
  363. },
  364. },
  365. ]
  366. }
  367. ]
  368. const router = animateRouter.create({
  369. history: createWebHashHistory(),
  370. routes,
  371. })
  372. // 路由跳转拦截
  373. router.beforeEach((to, from, next) => {
  374. clearPending()
  375. // 判断服务是否加载完成
  376. if (service.isReady) {
  377. if (to.meta.ignoreAuth || loginStore.token) {
  378. next()
  379. } else {
  380. if (to.matched.some((e) => e.name === 'home')) {
  381. // 如果是主页导航页面,强制跳转到首页
  382. next({
  383. name: 'home-market',
  384. replace: true,
  385. })
  386. } else {
  387. next({
  388. name: 'user-login',
  389. query: { redirect: to.fullPath },
  390. })
  391. }
  392. }
  393. } else {
  394. if (to.name === 'boot' || to.name === 'user-login') {
  395. next()
  396. } else {
  397. next({
  398. name: 'boot',
  399. query: { redirect: to.fullPath },
  400. })
  401. }
  402. }
  403. })
  404. export default router