index.ts 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553
  1. import * as EnumType from '@/common/constants/routerName';
  2. import Main from '@/layout/components/main.vue';
  3. import Layout from '@/layout/index.vue';
  4. import { isLogin } from '@/services/bus/login';
  5. import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router';
  6. import eventBus from '../utils/eventBus';
  7. const routes: Array<RouteRecordRaw> = [
  8. {
  9. path: '/login',
  10. name: 'login',
  11. component: () => import('@/views/account/login.vue'),
  12. },
  13. {
  14. path: '/logon',
  15. name: 'logon',
  16. component: () => import('@/views/account/logon.vue'),
  17. },
  18. {
  19. path: '/resetPassword',
  20. name: 'resetPassword',
  21. component: () => import('@/views/account/resetPassword.vue'),
  22. },
  23. {
  24. path: '/',
  25. component: Layout,
  26. props: true,
  27. redirect: '/login',
  28. children: [
  29. {
  30. path: '/home',
  31. name: 'home',
  32. component: () => import('@/views/home.vue'),
  33. },
  34. {
  35. path: '/futures',
  36. name: 'forward',
  37. component: () => import('@/views/market/forward/index.vue'),
  38. },
  39. {
  40. path: '/warehouse-trade',
  41. name: 'warehouseTrade',
  42. component: () => import('@/views/market/warehouseTrade/index.vue'),
  43. },
  44. {
  45. path: 'custom_info',
  46. name: 'custom_info',
  47. component: Main,
  48. meta: {
  49. requireAuth: true,
  50. },
  51. redirect: (to) => {
  52. return { name: 'custom_info_unsubmit' };
  53. },
  54. children: [
  55. {
  56. path: '/custom_info/normal',
  57. name: 'custom_info_normal',
  58. component: () => import('@/views/information/custom/list/normal-use/index.vue'),
  59. meta: {
  60. requireAuth: true,
  61. },
  62. },
  63. {
  64. path: '/custom_info/stop',
  65. name: 'custom_info_disabled',
  66. component: () => import('@/views/information/custom/list/stop-use/index.vue'),
  67. meta: {
  68. requireAuth: true,
  69. },
  70. },
  71. {
  72. path: '/custom_info/checkpending',
  73. name: 'custom_info_checkpending',
  74. component: () => import('@/views/information/custom/list/checkpending/index.vue'),
  75. meta: {
  76. requireAuth: true,
  77. },
  78. },
  79. {
  80. path: '/custom_info/unsubmit',
  81. name: 'custom_info_unsubmit',
  82. component: () => import('@/views/information/custom/list/unsubmit/index.vue'),
  83. meta: {
  84. requireAuth: true,
  85. },
  86. },
  87. ],
  88. },
  89. {
  90. path: 'goods_info',
  91. name: 'goods_info',
  92. component: Main,
  93. meta: {
  94. requireAuth: true,
  95. },
  96. redirect: (to) => {
  97. return { name: 'goods_info_spot' };
  98. },
  99. children: [
  100. {
  101. path: '/goods_info/spot',
  102. name: 'goods_info_spot',
  103. component: () => import('@/views/information/goods/list/spot-variety/index.vue'),
  104. meta: {
  105. requireAuth: true,
  106. },
  107. },
  108. {
  109. path: '/goods_info/hedging',
  110. name: 'goods_info_hedge',
  111. component: () => import('@/views/information/goods/list/hedging-variety/index.vue'),
  112. meta: {
  113. requireAuth: true,
  114. },
  115. },
  116. ],
  117. },
  118. {
  119. path: '/spot_contract',
  120. name: 'spot_contract',
  121. component: Main,
  122. meta: {
  123. requireAuth: true,
  124. },
  125. redirect: (to) => {
  126. return { name: 'spot_contract_unsubmitted' };
  127. },
  128. children: [
  129. {
  130. path: '/spot_contract/unsubmitted',
  131. name: 'spot_contract_unsubmitted',
  132. component: () => import('@/views/information/spot-contract/list/unsubmitted/index.vue'),
  133. meta: {
  134. requireAuth: true,
  135. },
  136. },
  137. {
  138. path: '/spot_contract/checkpending',
  139. name: 'spot_contract_checkpending',
  140. component: () => import('@/views/information/spot-contract/list/checkpending/index.vue'),
  141. meta: {
  142. requireAuth: true,
  143. },
  144. },
  145. {
  146. path: '/spot_contract/performance',
  147. name: 'spot_contract_performance',
  148. component: () => import('@/views/information/spot-contract/list/performance/index.vue'),
  149. meta: {
  150. requireAuth: true,
  151. },
  152. },
  153. {
  154. path: '/spot_contract/finished',
  155. name: 'spot_contract_finished',
  156. component: () => import('@/views/information/spot-contract/list/finished/index.vue'),
  157. meta: {
  158. requireAuth: true,
  159. },
  160. },
  161. ],
  162. },
  163. {
  164. path: '/account_info',
  165. name: 'account_info',
  166. component: Main,
  167. meta: {
  168. requireAuth: true,
  169. },
  170. redirect: (to) => {
  171. return { name: 'account_info_business' };
  172. },
  173. children: [
  174. {
  175. path: '/account_info/business',
  176. name: 'account_info_business',
  177. component: () => import('@/views/information/account_info/list/account_info_business/index.vue'),
  178. meta: {
  179. requireAuth: true,
  180. },
  181. },
  182. {
  183. path: '/account_info/futures',
  184. name: 'account_info_futures',
  185. component: () => import('@/views/information/account_info/list/account_info_futures/index.vue'),
  186. meta: {
  187. requireAuth: true,
  188. },
  189. },
  190. {
  191. path: '/account_info/managers',
  192. name: 'account_info_manager',
  193. component: () => import('@/views/information/account_info/list/account_info_manager/index.vue'),
  194. meta: {
  195. requireAuth: true,
  196. },
  197. },
  198. {
  199. path: '/account_info/trade',
  200. name: 'account_info_trade',
  201. component: () => import('@/views/information/account_info/list/account_info_trade/index.vue'),
  202. meta: {
  203. requireAuth: true,
  204. },
  205. },
  206. ],
  207. },
  208. {
  209. path: '/warehouse_info',
  210. name: 'warehouse_info',
  211. component: Main,
  212. meta: {
  213. requireAuth: true,
  214. },
  215. redirect: (to) => {
  216. return { name: 'warehouse_info_normal' };
  217. },
  218. children: [
  219. {
  220. path: '/warehouse_info/normal',
  221. name: 'warehouse_info_normal',
  222. component: () => import('@/views/information/warehouse-info/list/normal-use/index.vue'),
  223. meta: {
  224. requireAuth: true,
  225. },
  226. },
  227. {
  228. path: '/warehouse_info/stop',
  229. name: 'warehouse_info_disabled',
  230. component: () => import('@/views/information/warehouse-info/list/stop-use/index.vue'),
  231. meta: {
  232. requireAuth: true,
  233. },
  234. },
  235. ],
  236. },
  237. {
  238. path: '/outaccount_status',
  239. name: 'outaccount_status',
  240. component: () => import('@/views/search/outaccount_status/index.vue'),
  241. meta: {
  242. requireAuth: true,
  243. },
  244. },
  245. {
  246. path: '/inventory',
  247. name: 'inventory',
  248. component: () => import('@/views/search/inventory/index.vue'),
  249. meta: {
  250. requireAuth: true,
  251. },
  252. },
  253. {
  254. path: '/purchase',
  255. name: 'purchase',
  256. component: Main,
  257. meta: {
  258. requireAuth: true,
  259. },
  260. redirect: { name: 'purchase_pending' },
  261. children: [
  262. {
  263. path: '/purchase/pending',
  264. name: 'purchase_pending',
  265. component: () => import('@/views/business/purchase/list/pending/index.vue'),
  266. meta: {
  267. requireAuth: true,
  268. },
  269. },
  270. {
  271. path: '/purchase/performance',
  272. name: 'purchase_performance',
  273. component: () => import('@/views/business/purchase/list/performance/index.vue'),
  274. meta: {
  275. requireAuth: true,
  276. },
  277. },
  278. {
  279. path: '/purchase/all',
  280. name: 'purchase_all',
  281. component: () => import('@/views/business/purchase/list/all/index.vue'),
  282. meta: {
  283. requireAuth: true,
  284. },
  285. },
  286. ],
  287. },
  288. {
  289. path: '/sell',
  290. name: 'sell',
  291. component: Main,
  292. meta: {
  293. requireAuth: true,
  294. },
  295. redirect: { name: 'sell_pending' },
  296. children: [
  297. {
  298. path: '/sell/pending',
  299. name: 'sell_pending',
  300. component: () => import('@/views/business/sell/list/pending/index.vue'),
  301. meta: {
  302. requireAuth: true,
  303. },
  304. },
  305. {
  306. path: '/sell/performance',
  307. name: EnumType.Sell.performance,
  308. component: () => import('@/views/business/sell/list/performance/index.vue'),
  309. meta: {
  310. requireAuth: true,
  311. },
  312. },
  313. {
  314. path: '/sell/all',
  315. name: EnumType.Sell.all,
  316. component: () => import('@/views/business/sell/list/all/index.vue'),
  317. meta: {
  318. requireAuth: true,
  319. },
  320. },
  321. ],
  322. },
  323. {
  324. path: '/exposure',
  325. name: 'exposure',
  326. component: Main,
  327. meta: {
  328. requireAuth: true,
  329. },
  330. redirect: { name: EnumType.Exposure.realTime },
  331. children: [
  332. {
  333. path: '/exposure/realTime',
  334. name: EnumType.Exposure.realTime,
  335. component: () => import('@/views/business/exposure/list/realTime/index.vue'),
  336. meta: {
  337. requireAuth: true,
  338. },
  339. },
  340. {
  341. path: '/exposure/spot',
  342. name: EnumType.Exposure.spot,
  343. component: () => import('@/views/business/exposure/list/spot/index.vue'),
  344. meta: {
  345. requireAuth: true,
  346. },
  347. },
  348. {
  349. path: '/exposure/futures',
  350. name: EnumType.Exposure.futures,
  351. component: () => import('@/views/business/exposure/list/futures/index.vue'),
  352. meta: {
  353. requireAuth: true,
  354. },
  355. },
  356. {
  357. path: '/exposure/history',
  358. name: EnumType.Exposure.history,
  359. component: () => import('@/views/business/exposure/list/history/index.vue'),
  360. meta: {
  361. requireAuth: true,
  362. },
  363. },
  364. ],
  365. },
  366. {
  367. path: '/plan',
  368. name: 'plan',
  369. component: Main,
  370. meta: {
  371. requireAuth: true,
  372. },
  373. redirect: { name: 'plan_uncommitted' },
  374. children: [
  375. {
  376. path: '/plan/uncommitted',
  377. name: 'plan_uncommitted',
  378. component: () => import('@/views/business/plan/list/uncommitted/index.vue'),
  379. meta: {
  380. requireAuth: true,
  381. },
  382. },
  383. {
  384. path: '/plan/audit',
  385. name: 'plan_audit',
  386. component: () => import('@/views/business/plan/list/audit/index.vue'),
  387. meta: {
  388. requireAuth: true,
  389. },
  390. },
  391. {
  392. path: '/plan/running',
  393. name: 'plan_running',
  394. component: () => import('@/views/business/plan/list/running/index.vue'),
  395. meta: {
  396. requireAuth: true,
  397. },
  398. },
  399. ],
  400. },
  401. {
  402. path: 'review',
  403. name: 'business_review',
  404. component: Main,
  405. meta: {
  406. requireAuth: true,
  407. },
  408. redirect: { name: 'business_review_someprice' },
  409. children: [
  410. {
  411. path: '/review/someprice',
  412. name: 'business_review_someprice',
  413. component: () => import('@/views/manage/business-review/list/someprice/index.vue'),
  414. meta: {
  415. requireAuth: true,
  416. },
  417. },
  418. {
  419. path: '/review/settlement',
  420. name: 'business_review_settlement',
  421. component: () => import('@/views/manage/business-review/list/settlement/index.vue'),
  422. meta: {
  423. requireAuth: true,
  424. },
  425. },
  426. ]
  427. },
  428. {
  429. path: '/finance_review',
  430. name: 'finance_review',
  431. component: Main,
  432. meta: {
  433. requireAuth: true,
  434. },
  435. redirect: { name: 'finance_review_funds' },
  436. children: [
  437. {
  438. path: '/review/funds',
  439. name: 'finance_review_funds',
  440. component: () => import('@/views/manage/finance-review/list/funds/index.vue'),
  441. meta: {
  442. requireAuth: true,
  443. },
  444. },
  445. {
  446. path: '/review/invoice',
  447. name: 'finance_review_invoice',
  448. component: () => import('@/views/manage/finance-review/list/invoice/index.vue'),
  449. meta: {
  450. requireAuth: true,
  451. },
  452. },
  453. ]
  454. },
  455. {
  456. path: '/inventory_review',
  457. name: 'inventory_review',
  458. component: Main,
  459. meta: {
  460. requireAuth: true,
  461. },
  462. redirect: { name: 'inventory_review_checkin' },
  463. children: [
  464. {
  465. path: '/inventory_review/checkin',
  466. name: 'inventory_review_checkin',
  467. component: () => import('@/views/manage/inventory-review/list/checkin/index.vue'),
  468. meta: {
  469. requireAuth: true,
  470. },
  471. },
  472. {
  473. path: '/inventory_review/checkout',
  474. name: 'inventory_review_checkout',
  475. component: () => import('@/views/manage/inventory-review/list/checkout/index.vue'),
  476. meta: {
  477. requireAuth: true,
  478. },
  479. },
  480. ]
  481. },
  482. {
  483. path: '/exposure_report',
  484. name: 'exposure_report',
  485. component: () => import('@/views/report/exposure-report/index.vue'),
  486. meta: {
  487. requireAuth: true,
  488. },
  489. },
  490. {
  491. path: '/finance_report',
  492. name: 'finance_report',
  493. component: () => import('@/views/report/finance-report/index.vue'),
  494. meta: {
  495. requireAuth: true,
  496. },
  497. },
  498. {
  499. path: '/inventory_report',
  500. name: 'inventory_report',
  501. component: () => import('@/views/report/inventory-report/index.vue'),
  502. meta: {
  503. requireAuth: true,
  504. },
  505. },
  506. {
  507. path: '/spot_report',
  508. name: 'spot_report',
  509. component: () => import('@/views/report/spot-report/index.vue'),
  510. meta: {
  511. requireAuth: true,
  512. },
  513. },
  514. ],
  515. },
  516. {
  517. path: '/test',
  518. name: 'test',
  519. component: () => import('@/views/test/index.vue'),
  520. },
  521. {
  522. // VueRouter 匹配规则是从上往下 建议把*放最后
  523. path: '/:pathMatch(.*)*',
  524. name: '404',
  525. component: () => import('@/views/error-page/404.vue'),
  526. },
  527. ];
  528. const router = createRouter({
  529. history: createWebHashHistory(),
  530. routes,
  531. });
  532. // 路由拦截
  533. router.beforeEach((to, from, next) => {
  534. // 前往登录页时 直接走登出流程
  535. if (to.fullPath === '/login') {
  536. eventBus.$emit('logout');
  537. next();
  538. } else {
  539. // 前往其他页 判断是否是登录状态
  540. if (isLogin()) return next();
  541. // 不是登录状态不能去'我的'页面,跳至首页
  542. // if (to.fullPath.indexOf('/mine') !== -1) next('/');
  543. else next();
  544. }
  545. });
  546. export default router;