import Vue from 'vue' import VueRouter from 'vue-router' const Login = () => import('@/views/login/index') const Logining = () => import('@/views/login/logining') const Home = () => import('@/views/home/Home') const Welcome = () => import('@/views/welcome/Welcome') // 销售模块 const ClientsManage = () => import('@/views/clients/customer/clientsManage') const ClueIndex = () => import('@/views/clients/clue/ClueIndex') const ContactsIndex = () => import('@/views/clients/contacts/ContactsIndex') const BusinessIndex = () => import('@/views/clients/business/BusinessIndex') const ContractIndex = () => import('@/views/clients/contract/ContractIndex') const OfferIndex = () => import('@/views/clients/offers/OfferIndex') const ProductIndex = () => import('@/views/clients/product/ProductIndex') const EmployeeManage = () => import('@/views/company/employeeManage/EmployeeManage') const OffcialAuthority = () => import('@/views/company/offcialAuthority') const StaffLog = () => import('@/views/company/staffLog') const ApartmentManage = () => import('@/views/company/ApartmentManage') const SystemSetting = () => import('@/views/company/systemSetting') const ModuleManage = () => import('@/views/module/ModuleManage') // 人事模块 const SealContractIndex = () => import('@/views/clients/sealContract/SealContractIndex') const SealOfferIndex = () => import('@/views/clients/sealOffers/SealOfferIndex') // 商务模块 const BusinessCustomerManage = () => import('@/views/clients/businessCustomer/BusinessCustomerManage') const BusinessChancesIndex = () => import('@/views/clients/businessChances/BusinessChancesIndex') const BusinessContractsIndex = () => import('@/views/clients/businessContracts/BusinessContractsIndex') // PWS API const EwsAnalyze = () => import('@/views/PWS/EwsAnalyze') const Subscriptions = () => import('@/views/PWS/Subscriptions') Vue.use(VueRouter) const routes = [{ path: '', redirect: '/login' }, { path: '/login', component: Login }, { path: '/logining', component: Logining }, { path: '/home', component: Home, redirect: '/welcome', children: [{ path: '/welcome', component: Welcome }, { path: '/ModuleManage', component: ModuleManage }, { path: '/clientsManage', component: ClientsManage }, { path: '/ClueIndex', component: ClueIndex }, { path: '/ContactsIndex', component: ContactsIndex }, { path: '/BusinessIndex', component: BusinessIndex }, { path: '/ContractIndex', component: ContractIndex }, { path: '/OfferIndex', component: OfferIndex }, { path: '/SealContractIndex', component: SealContractIndex }, { path: '/SealOfferIndex', component: SealOfferIndex }, { path: '/BusinessCustomerManage', component: BusinessCustomerManage }, { path: '/BusinessChancesIndex', component: BusinessChancesIndex }, { path: '/BusinessContractsIndex', component: BusinessContractsIndex }, { path: '/ProductIndex', component: ProductIndex }, { path: '/ApartmentManage', component: ApartmentManage }, { path: '/offcialAuthority', component: OffcialAuthority }, { path: '/staffLog', component: StaffLog }, { path: '/EmployeeManage', component: EmployeeManage }, { path: '/systemSetting', component: SystemSetting }, { path: '/ewsAnalyze', component: EwsAnalyze }, { path: '/Subscriptions', component: Subscriptions } ] } ] const router = new VueRouter({ routes, mode: 'hash' }) // 路由导航守卫,在跳转前判断 router.beforeEach((to, from, next) => { if (window.location.href.indexOf('code') >= 0) { // 如果code存在 // 如果url中包含code split?分割成数组,取第二个 let code = window.location.href.split('?')[1] console.log(window.location.href) code = code.substring(5, code.indexOf('&')) // 截取字符串第6位开始截取直到&出现截取成功 console.log(code) sessionStorage.setItem('code', code) next() } else { if (to.path === '/login') { // 如果是登录页 localStorage.removeItem('token') } if (!localStorage.getItem('token') && to.path !== '/login') { // 如果token不存在 并且 不是mylogin页面 next({ path: '/login' }) } else { next() } } }) export default router