import * as EnumType from '@/common/constants/routerName'; import Main from '@/layout/components/main.vue'; import Layout from '@/layout/index.vue'; import { isLogin } from '@/services/bus/login'; import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router'; import eventBus from '../utils/eventBus'; const routes: Array = [ { path: '/login', name: 'login', component: () => import('@/views/account/login.vue'), }, { path: '/logon', name: 'logon', component: () => import('@/views/account/logon.vue'), }, { path: '/resetPassword', name: 'resetPassword', component: () => import('@/views/account/resetPassword.vue'), }, { path: '/', component: Layout, props: true, redirect: '/login', children: [ { path: '/home', name: 'home', component: () => import('@/views/home.vue'), }, { path: '/futures', name: 'forward', component: () => import('@/views/market/forward/index.vue'), }, { path: '/warehouse-trade', name: 'warehouseTrade', component: () => import('@/views/market/warehouseTrade/index.vue'), }, { path: 'custom_info', name: 'custom_info', component: Main, meta: { requireAuth: true, }, redirect: (to) => { return { name: 'custom_info_unsubmit' }; }, children: [ { path: '/custom_info/normal', name: 'custom_info_normal', component: () => import('@/views/information/custom/list/normal-use/index.vue'), meta: { requireAuth: true, }, }, { path: '/custom_info/stop', name: 'custom_info_disabled', component: () => import('@/views/information/custom/list/stop-use/index.vue'), meta: { requireAuth: true, }, }, { path: '/custom_info/checkpending', name: 'custom_info_checkpending', component: () => import('@/views/information/custom/list/checkpending/index.vue'), meta: { requireAuth: true, }, }, { path: '/custom_info/unsubmit', name: 'custom_info_unsubmit', component: () => import('@/views/information/custom/list/unsubmit/index.vue'), meta: { requireAuth: true, }, }, ], }, { path: 'goods_info', name: 'goods_info', component: Main, meta: { requireAuth: true, }, redirect: (to) => { return { name: 'goods_info_spot' }; }, children: [ { path: '/goods_info/spot', name: 'goods_info_spot', component: () => import('@/views/information/goods/list/spot-variety/index.vue'), meta: { requireAuth: true, }, }, { path: '/goods_info/hedging', name: 'goods_info_hedge', component: () => import('@/views/information/goods/list/hedging-variety/index.vue'), meta: { requireAuth: true, }, }, ], }, { path: '/spot_contract', name: 'spot_contract', component: Main, meta: { requireAuth: true, }, redirect: (to) => { return { name: 'spot_contract_unsubmitted' }; }, children: [ { path: '/spot_contract/unsubmitted', name: 'spot_contract_unsubmitted', component: () => import('@/views/information/spot-contract/list/unsubmitted/index.vue'), meta: { requireAuth: true, }, }, { path: '/spot_contract/checkpending', name: 'spot_contract_checkpending', component: () => import('@/views/information/spot-contract/list/checkpending/index.vue'), meta: { requireAuth: true, }, }, { path: '/spot_contract/performance', name: 'spot_contract_performance', component: () => import('@/views/information/spot-contract/list/performance/index.vue'), meta: { requireAuth: true, }, }, { path: '/spot_contract/finished', name: 'spot_contract_finished', component: () => import('@/views/information/spot-contract/list/finished/index.vue'), meta: { requireAuth: true, }, }, ], }, { path: '/account_info', name: 'account_info', component: Main, meta: { requireAuth: true, }, redirect: (to) => { return { name: 'account_info_business' }; }, children: [ { path: '/account_info/business', name: 'account_info_business', component: () => import('@/views/information/account_info/list/account_info_business/index.vue'), meta: { requireAuth: true, }, }, { path: '/account_info/futures', name: 'account_info_futures', component: () => import('@/views/information/account_info/list/account_info_futures/index.vue'), meta: { requireAuth: true, }, }, { path: '/account_info/managers', name: 'account_info_manager', component: () => import('@/views/information/account_info/list/account_info_manager/index.vue'), meta: { requireAuth: true, }, }, { path: '/account_info/trade', name: 'account_info_trade', component: () => import('@/views/information/account_info/list/account_info_trade/index.vue'), meta: { requireAuth: true, }, }, ], }, { path: '/warehouse_info', name: 'warehouse_info', component: Main, meta: { requireAuth: true, }, redirect: (to) => { return { name: 'warehouse_info_normal' }; }, children: [ { path: '/warehouse_info/normal', name: 'warehouse_info_normal', component: () => import('@/views/information/warehouse-info/list/normal-use/index.vue'), meta: { requireAuth: true, }, }, { path: '/warehouse_info/stop', name: 'warehouse_info_disabled', component: () => import('@/views/information/warehouse-info/list/stop-use/index.vue'), meta: { requireAuth: true, }, }, ], }, { path: '/outaccount_status', name: 'outaccount_status', component: () => import('@/views/search/outaccount_status/index.vue'), meta: { requireAuth: true, }, }, { path: '/inventory', name: 'inventory', component: () => import('@/views/search/inventory/index.vue'), meta: { requireAuth: true, }, }, { path: '/purchase', name: 'purchase', component: Main, meta: { requireAuth: true, }, redirect: { name: 'purchase_pending' }, children: [ { path: '/purchase/pending', name: 'purchase_pending', component: () => import('@/views/business/purchase/list/pending/index.vue'), meta: { requireAuth: true, }, }, { path: '/purchase/performance', name: 'purchase_performance', component: () => import('@/views/business/purchase/list/performance/index.vue'), meta: { requireAuth: true, }, }, { path: '/purchase/all', name: 'purchase_all', component: () => import('@/views/business/purchase/list/all/index.vue'), meta: { requireAuth: true, }, }, ], }, { path: '/sell', name: 'sell', component: Main, meta: { requireAuth: true, }, redirect: { name: 'sell_pending' }, children: [ { path: '/sell/pending', name: 'sell_pending', component: () => import('@/views/business/sell/list/pending/index.vue'), meta: { requireAuth: true, }, }, { path: '/sell/performance', name: EnumType.Sell.performance, component: () => import('@/views/business/sell/list/performance/index.vue'), meta: { requireAuth: true, }, }, { path: '/sell/all', name: EnumType.Sell.all, component: () => import('@/views/business/sell/list/all/index.vue'), meta: { requireAuth: true, }, }, ], }, { path: '/exposure', name: 'exposure', component: Main, meta: { requireAuth: true, }, redirect: { name: EnumType.Exposure.realTime }, children: [ { path: '/exposure/realTime', name: EnumType.Exposure.realTime, component: () => import('@/views/business/exposure/list/realTime/index.vue'), meta: { requireAuth: true, }, }, { path: '/exposure/spot', name: EnumType.Exposure.spot, component: () => import('@/views/business/exposure/list/spot/index.vue'), meta: { requireAuth: true, }, }, { path: '/exposure/futures', name: EnumType.Exposure.futures, component: () => import('@/views/business/exposure/list/futures/index.vue'), meta: { requireAuth: true, }, }, { path: '/exposure/history', name: EnumType.Exposure.history, component: () => import('@/views/business/exposure/list/history/index.vue'), meta: { requireAuth: true, }, }, ], }, { path: '/plan', name: 'plan', component: Main, meta: { requireAuth: true, }, redirect: { name: 'plan_uncommitted' }, children: [ { path: '/plan/uncommitted', name: 'plan_uncommitted', component: () => import('@/views/business/plan/list/uncommitted/index.vue'), meta: { requireAuth: true, }, }, { path: '/plan/audit', name: 'plan_audit', component: () => import('@/views/business/plan/list/audit/index.vue'), meta: { requireAuth: true, }, }, { path: '/plan/running', name: 'plan_running', component: () => import('@/views/business/plan/list/running/index.vue'), meta: { requireAuth: true, }, }, ], }, { path: 'review', name: 'business_review', component: Main, meta: { requireAuth: true, }, redirect: { name: 'business_review_someprice' }, children: [ { path: '/review/someprice', name: 'business_review_someprice', component: () => import('@/views/manage/business-review/list/someprice/index.vue'), meta: { requireAuth: true, }, }, { path: '/review/settlement', name: 'business_review_settlement', component: () => import('@/views/manage/business-review/list/settlement/index.vue'), meta: { requireAuth: true, }, }, ] }, { path: '/finance_review', name: 'finance_review', component: Main, meta: { requireAuth: true, }, redirect: { name: 'finance_review_funds' }, children: [ { path: '/review/funds', name: 'finance_review_funds', component: () => import('@/views/manage/finance-review/list/funds/index.vue'), meta: { requireAuth: true, }, }, { path: '/review/invoice', name: 'finance_review_invoice', component: () => import('@/views/manage/finance-review/list/invoice/index.vue'), meta: { requireAuth: true, }, }, ] }, { path: '/inventory_review', name: 'inventory_review', component: Main, meta: { requireAuth: true, }, redirect: { name: 'inventory_review_checkin' }, children: [ { path: '/inventory_review/checkin', name: 'inventory_review_checkin', component: () => import('@/views/manage/inventory-review/list/checkin/index.vue'), meta: { requireAuth: true, }, }, { path: '/inventory_review/checkout', name: 'inventory_review_checkout', component: () => import('@/views/manage/inventory-review/list/checkout/index.vue'), meta: { requireAuth: true, }, }, ] }, { path: '/exposure_report', name: 'exposure_report', component: () => import('@/views/report/exposure-report/index.vue'), meta: { requireAuth: true, }, }, { path: '/finance_report', name: 'finance_report', component: () => import('@/views/report/finance-report/index.vue'), meta: { requireAuth: true, }, }, { path: '/inventory_report', name: 'inventory_report', component: () => import('@/views/report/inventory-report/index.vue'), meta: { requireAuth: true, }, }, { path: '/spot_report', name: 'spot_report', component: () => import('@/views/report/spot-report/index.vue'), meta: { requireAuth: true, }, }, ], }, { path: '/test', name: 'test', component: () => import('@/views/test/index.vue'), }, { // VueRouter 匹配规则是从上往下 建议把*放最后 path: '/:pathMatch(.*)*', name: '404', component: () => import('@/views/error-page/404.vue'), }, ]; const router = createRouter({ history: createWebHashHistory(), routes, }); // 路由拦截 router.beforeEach((to, from, next) => { // 前往登录页时 直接走登出流程 if (to.fullPath === '/login') { eventBus.$emit('logout'); next(); } else { // 前往其他页 判断是否是登录状态 if (isLogin()) return next(); // 不是登录状态不能去'我的'页面,跳至首页 // if (to.fullPath.indexOf('/mine') !== -1) next('/'); else next(); } }); export default router;