import Vue from 'vue';
import Router from 'vue-router';
import Admin from '@/views/Admin';
import store from './store';
import http from './plugins/http';

Vue.use(Router);

const router = new Router({
    mode: 'history',
    base: process.env.BASE_URL,
    routes: [
        {
            path: '/',
            component: Admin,
            children: [
                {
                    path: '/',
                    redirect: 'dashboard'
                },
                {
                    path: '/404',
                    name: '404',
                    component: () => import(/* webpackChunkName: "404" */ '@/views/404.vue')
                },
                {
                    path: '/dashboard',
                    name: 'dashboard',
                    component: () => import(/* webpackChunkName: "404" */ '@/views/Dashboard.vue'),
                    meta: {
                        title: '首页'
                    }
                },
                {
                    path: '/api',
                    name: 'api',
                    component: () => import(/* webpackChunkName: "api" */ '@/views/Api.vue'),
                    meta: {
                        title: '接口调试'
                    }
                },
                {
                    path: '/genCodeEdit',
                    name: 'genCodeEdit',
                    component: () => import(/* webpackChunkName: "genCodeEdit" */ '@/views/GenCodeEdit.vue'),
                    meta: {
                        title: '代码生成编辑'
                    }
                },
                {
                    path: '/genCodeList',
                    name: 'genCodeList',
                    component: () => import(/* webpackChunkName: "genCodeList" */ '@/views/GenCodeList.vue'),
                    meta: {
                        title: '代码生成'
                    }
                },
                {
                    path: '/menus',
                    name: 'menus',
                    component: () => import(/* webpackChunkName: "menus" */ '@/views/Menus.vue'),
                    meta: {
                        title: '菜单配置'
                    }
                },
                {
                    path: '/menuAuthority',
                    name: 'menuAuthority',
                    component: () => import(/* webpackChunkName: "menuAuthority" */ '@/views/MenuAuthority.vue'),
                    meta: {
                        title: '菜单权限'
                    }
                },
                {
                    path: '/settings',
                    name: 'Settings',
                    component: () => import(/* webpackChunkName: "settingList" */ '@/views/Settings.vue'),
                    meta: {
                        title: '分类设置'
                    }
                },
                {
                    path: '/navigations',
                    name: 'Navigations',
                    component: () => import(/* webpackChunkName: "navigations" */ '@/views/Navigations.vue'),
                    meta: {
                        title: '导航设置'
                    }
                },
                {
                    path: '/userEdit',
                    name: 'userEdit',
                    component: () => import(/* webpackChunkName: "userEdit" */ '@/views/UserEdit.vue'),
                    meta: {
                        title: '用户编辑'
                    }
                },
                {
                    path: '/userList',
                    name: 'userList',
                    component: () => import(/* webpackChunkName: "userList" */ '@/views/UserList.vue'),
                    meta: {
                        title: '用户管理'
                    }
                },
                {
                    path: '/sysConfigList',
                    name: 'sysConfigList',
                    component: () => import(/* webpackChunkName: "sysConfigList" */ '@/views/SysConfigList.vue'),
                    meta: {
                        title: '参数配置'
                    }
                },
                {
                    path: '/upload',
                    name: 'upload',
                    component: () => import(/* webpackChunkName: "upload" */ '@/views/Upload.vue'),
                    meta: {
                        title: '上传'
                    }
                },
                {
                    path: '/testClassEdit',
                    name: 'TestClassEdit',
                    component: () => import(/* webpackChunkName: "testClassEdit" */ '@/views/TestClassEdit.vue'),
                    meta: {
                        title: '测试编辑'
                    }
                },
                {
                    path: '/testClassList',
                    name: 'TestClassList',
                    component: () => import(/* webpackChunkName: "testClassList" */ '@/views/TestClassList.vue'),
                    meta: {
                        title: '测试'
                    }
                },
                {
                    path: '/operationLogList',
                    name: 'OperationLogList',
                    component: () => import(/* webpackChunkName: "operationLogList" */ '@/views/OperationLogList.vue'),
                    meta: {
                        title: '操作日志'
                    }
                },
                {
                    path: '/exceptionLogList',
                    name: 'ExceptionLogList',
                    component: () => import(/* webpackChunkName: "exceptionLogList" */ '@/views/ExceptionLogList.vue'),
                    meta: {
                        title: '异常日志'
                    }
                },
                {
                    path: '/technologyProductEdit',
                    name: 'TechnologyProductEdit',
                    component: () =>
                        import(
                            /* webpackChunkName: "technologyProductEdit" */ '@/views/supply/TechnologyProductEdit.vue'
                        ),
                    meta: {
                        title: '编辑'
                    }
                },
                {
                    path: '/technologyList',
                    name: 'TechnologyList',
                    component: () =>
                        import(/* webpackChunkName: "technologyList" */ '@/views/supply/TechnologyList.vue'),
                    meta: {
                        title: '技术'
                    }
                },
                {
                    path: '/productList',
                    name: 'ProductList',
                    component: () => import(/* webpackChunkName: "productList" */ '@/views/supply/ProductList.vue'),
                    meta: {
                        title: '产品'
                    }
                },
                {
                    path: '/technicalManagerEdit',
                    name: 'TechnicalManagerEdit',
                    component: () =>
                        import(
                            /* webpackChunkName: "technicalManagerEdit" */ '@/views/supply/TechnicalManagerEdit.vue'
                        ),
                    meta: {
                        title: '技术经理人编辑'
                    }
                },
                {
                    path: '/technicalManagerList',
                    name: 'TechnicalManagerList',
                    component: () =>
                        import(
                            /* webpackChunkName: "technicalManagerList" */ '@/views/supply/TechnicalManagerList.vue'
                        ),
                    meta: {
                        title: '技术经理人'
                    }
                },
                // {
                //     path: '/expertList',
                //     name: 'ExpertList',
                //     component: () => import(/* webpackChunkName: "expertList" */ '@/views/resource/ExpertList.vue'),
                //     meta: {
                //         title: '专家'
                //     }
                // },
                // {
                //     path: '/expertEdit',
                //     name: 'ExpertEdit',
                //     component: () => import(/* webpackChunkName: "expertEdit" */ '@/views/resource/ExpertEdit.vue'),
                //     meta: {
                //         title: '专家编辑'
                //     }
                // },
                {
                    path: '/fundingEdit',
                    name: 'FundingEdit',
                    component: () => import(/* webpackChunkName: "fundingEdit" */ '@/views/demand/FundingEdit.vue'),
                    meta: {
                        title: '资金编辑'
                    }
                },
                {
                    path: '/fundingList',
                    name: 'FundingList',
                    component: () => import(/* webpackChunkName: "fundingList" */ '@/views/demand/FundingList.vue'),
                    meta: {
                        title: '资金'
                    }
                },
                {
                    path: '/copyrightEdit',
                    name: 'CopyrightEdit',
                    component: () => import(/* webpackChunkName: "copyrightEdit" */ '@/views/supply/CopyrightEdit.vue'),
                    meta: {
                        title: '编辑'
                    }
                },
                {
                    path: '/copyrightList',
                    name: 'CopyrightList',
                    component: () => import(/* webpackChunkName: "copyrightList" */ '@/views/supply/CopyrightList.vue'),
                    meta: {
                        title: '版权'
                    }
                },
                {
                    path: '/softCopyrightList',
                    name: 'SoftCopyrightList',
                    component: () =>
                        import(/* webpackChunkName: "copyrightList" */ '@/views/supply/SoftCopyrightList.vue'),
                    meta: {
                        title: '软著'
                    }
                },
                {
                    path: '/copyrightDemandEdit',
                    name: 'CopyrightDemandEdit',
                    component: () =>
                        import(/* webpackChunkName: "copyrightDemandEdit" */ '@/views/demand/CopyrightDemandEdit.vue'),
                    meta: {
                        title: '编辑'
                    }
                },
                {
                    path: '/copyrightDemandList',
                    name: 'CopyrightDemandList',
                    component: () =>
                        import(/* webpackChunkName: "copyrightDemandList" */ '@/views/demand/CopyrightDemandList.vue'),
                    meta: {
                        title: '版权'
                    }
                },
                {
                    path: '/softCopyrightDemandList',
                    name: 'SoftCopyrightDemandList',
                    component: () =>
                        import(
                            /* webpackChunkName: "copyrightDemandList" */ '@/views/demand/SoftCopyrightDemandList.vue'
                        ),
                    meta: {
                        title: '软著'
                    }
                },
                {
                    path: '/serviceDemandList',
                    name: 'ServiceDemandList',
                    component: () =>
                        import(/* webpackChunkName: "copyrightDemandList" */ '@/views/demand/ServiceDemandList.vue'),
                    meta: {
                        title: '服务'
                    }
                },
                {
                    path: '/logoDemandEdit',
                    name: 'LogoDemandEdit',
                    component: () =>
                        import(/* webpackChunkName: "logoDemandEdit" */ '@/views/demand/LogoDemandEdit.vue'),
                    meta: {
                        title: '商标编辑'
                    }
                },
                {
                    path: '/logoDemandList',
                    name: 'LogoDemandList',
                    component: () =>
                        import(/* webpackChunkName: "logoDemandList" */ '@/views/demand/LogoDemandList.vue'),
                    meta: {
                        title: '商标'
                    }
                },
                {
                    path: '/patentDemandEdit',
                    name: 'PatentDemandEdit',
                    component: () =>
                        import(/* webpackChunkName: "patentDemandEdit" */ '@/views/demand/PatentDemandEdit.vue'),
                    meta: {
                        title: '专利编辑'
                    }
                },
                {
                    path: '/patentDemandList',
                    name: 'PatentDemandList',
                    component: () =>
                        import(/* webpackChunkName: "patentDemandList" */ '@/views/demand/PatentDemandList.vue'),
                    meta: {
                        title: '脱密专利'
                    }
                },
                {
                    path: '/generalPatentDemandList',
                    name: 'GeneralPatentDemandList',
                    component: () =>
                        import(/* webpackChunkName: "patentDemandList" */ '@/views/demand/GeneralPatentDemandList.vue'),
                    meta: {
                        title: '普通专利'
                    }
                },
                {
                    path: '/techProductDemandEdit',
                    name: 'TechProductDemandEdit',
                    component: () =>
                        import(
                            /* webpackChunkName: "techProductDemandEdit" */ '@/views/demand/TechProductDemandEdit.vue'
                        ),
                    meta: {
                        title: '编辑'
                    }
                },
                {
                    path: '/technologyDemandList',
                    name: 'TechnologyDemandList',
                    component: () =>
                        import(
                            /* webpackChunkName: "technologyDemandList" */ '@/views/demand/TechnologyDemandList.vue'
                        ),
                    meta: {
                        title: '技术'
                    }
                },
                {
                    path: '/productDemandList',
                    name: 'ProductDemandList',
                    component: () =>
                        import(/* webpackChunkName: "productDemandList" */ '@/views/demand/ProductDemandList.vue'),
                    meta: {
                        title: '产品'
                    }
                },
                {
                    path: '/logoEdit',
                    name: 'LogoEdit',
                    component: () => import(/* webpackChunkName: "logoEdit" */ '@/views/supply/LogoEdit.vue'),
                    meta: {
                        title: '商标编辑'
                    }
                },
                {
                    path: '/logoList',
                    name: 'LogoList',
                    component: () => import(/* webpackChunkName: "logoList" */ '@/views/supply/LogoList.vue'),
                    meta: {
                        title: '商标'
                    }
                },
                {
                    path: '/patentEdit',
                    name: 'PatentEdit',
                    component: () => import(/* webpackChunkName: "patentEdit" */ '@/views/supply/PatentEdit.vue'),
                    meta: {
                        title: '专利编辑'
                    }
                },
                {
                    path: '/patentList',
                    name: 'PatentList',
                    component: () => import(/* webpackChunkName: "patentList" */ '@/views/supply/PatentList.vue'),
                    meta: {
                        title: '脱密专利'
                    }
                },
                {
                    path: '/generalPatentList',
                    name: 'GeneralPatentList',
                    component: () =>
                        import(/* webpackChunkName: "patentList" */ '@/views/supply/GeneralPatentList.vue'),
                    meta: {
                        title: '普通专利'
                    }
                },
                {
                    path: '/serviceProviderEdit',
                    name: 'ServiceProviderEdit',
                    component: () =>
                        import(/* webpackChunkName: "serviceProviderEdit" */ '@/views/supply/ServiceProviderEdit.vue'),
                    meta: {
                        title: '服务机构编辑'
                    }
                },
                {
                    path: '/serviceProviderList',
                    name: 'ServiceProviderList',
                    component: () =>
                        import(/* webpackChunkName: "serviceProviderList" */ '@/views/supply/ServiceProviderList.vue'),
                    meta: {
                        title: '服务机构'
                    }
                },
                {
                    path: '/institutionEdit',
                    name: 'InstitutionEdit',
                    component: () => import(/* webpackChunkName: "institutionEdit" */ '@/views/InstitutionEdit.vue'),
                    meta: {
                        title: '机构认证编辑'
                    }
                },
                {
                    path: '/institutionList',
                    name: 'InstitutionList',
                    component: () => import(/* webpackChunkName: "institutionList" */ '@/views/InstitutionList.vue'),
                    meta: {
                        title: '机构认证'
                    }
                },
                {
                    path: '/personalEdit',
                    name: 'PersonalEdit',
                    component: () => import(/* webpackChunkName: "personalEdit" */ '@/views/PersonalEdit.vue'),
                    meta: {
                        title: '个人认证编辑'
                    }
                },
                {
                    path: '/personalList',
                    name: 'PersonalList',
                    component: () => import(/* webpackChunkName: "personalList" */ '@/views/PersonalList.vue'),
                    meta: {
                        title: '个人认证'
                    }
                },
                {
                    path: '/policyLawEdit',
                    name: 'PolicyLawEdit',
                    component: () =>
                        import(/* webpackChunkName: "policyLawEdit" */ '@/views/resource/PolicyLawEdit.vue'),
                    meta: {
                        title: '编辑'
                    }
                },
                {
                    path: '/policyList',
                    name: 'PolicyList',
                    component: () => import(/* webpackChunkName: "policyLawList" */ '@/views/resource/PolicyList.vue'),
                    meta: {
                        title: '政策'
                    }
                },
                {
                    path: '/lawList',
                    name: 'LawList',
                    component: () => import(/* webpackChunkName: "LawList" */ '@/views/resource/LawList.vue'),
                    meta: {
                        title: '法律'
                    }
                },
                {
                    path: '/newsList',
                    name: 'NewsList',
                    component: () => import(/* webpackChunkName: "NewsList" */ '@/views/resource/NewsList.vue'),
                    meta: {
                        title: '新闻'
                    }
                },
                {
                    path: '/purchaseEdit',
                    name: 'PurchaseEdit',
                    component: () => import(/* webpackChunkName: "purchaseEdit" */ '@/views/resource/PurchaseEdit.vue'),
                    meta: {
                        title: '军采信息编辑'
                    }
                },
                {
                    path: '/purchaseList',
                    name: 'PurchaseList',
                    component: () => import(/* webpackChunkName: "purchaseList" */ '@/views/resource/PurchaseList.vue'),
                    meta: {
                        title: '军采信息'
                    }
                },
                {
                    path: '/digitalEdit',
                    name: 'DigitalEdit',
                    component: () => import(/* webpackChunkName: "digitalEdit" */ '@/views/resource/DigitalEdit.vue'),
                    meta: {
                        title: '编辑'
                    }
                },
                {
                    path: '/digitalList',
                    name: 'DigitalList',
                    component: () => import(/* webpackChunkName: "digitalList" */ '@/views/resource/DigitalList.vue'),
                    meta: {
                        title: '技术'
                    }
                },
                {
                    path: '/digitalProductList',
                    name: 'DigitalProductList',
                    component: () =>
                        import(/* webpackChunkName: "digitalProductList" */ '@/views/resource/DigitalProductList.vue'),
                    meta: {
                        title: '产品'
                    }
                },
                {
                    path: '/companyList',
                    name: 'CompanyList',
                    component: () => import(/* webpackChunkName: "companyList" */ '@/views/resource/CompanyList.vue'),
                    meta: {
                        title: '企业'
                    }
                },
                {
                    path: '/companyEdit',
                    name: 'CompanyEdit',
                    component: () => import(/* webpackChunkName: "companyEdit" */ '@/views/resource/CompanyEdit.vue'),
                    meta: {
                        title: '企业'
                    }
                },
                {
                    path: '/intellectualPropertyEdit',
                    name: 'IntellectualPropertyEdit',
                    component: () =>
                        import(
                            /* webpackChunkName: "intellectualPropertyEdit" */ '@/views/resource/IntellectualPropertyEdit.vue'
                        ),
                    meta: {
                        title: '知产编辑'
                    }
                },
                {
                    path: '/intellectualPropertyList',
                    name: 'IntellectualPropertyList',
                    component: () =>
                        import(
                            /* webpackChunkName: "intellectualPropertyList" */ '@/views/resource/IntellectualPropertyList.vue'
                        ),
                    meta: {
                        title: '知产'
                    }
                },
                {
                    path: '/successCaseEdit',
                    name: 'SuccessCaseEdit',
                    component: () =>
                        import(/* webpackChunkName: "successCaseEdit" */ '@/views/case/SuccessCaseEdit.vue'),
                    meta: {
                        title: '成交案例编辑'
                    }
                },
                {
                    path: '/patentCaseList',
                    name: 'PatentCaseList',
                    component: () => import(/* webpackChunkName: "patentCaseList" */ '@/views/case/PatentCaseList.vue'),
                    meta: {
                        title: '脱密专利'
                    }
                },
                {
                    path: '/generalPatentCaseList',
                    name: 'GeneralPatentCaseList',
                    component: () =>
                        import(
                            /* webpackChunkName: "generalPatentCaseList" */ '@/views/case/GeneralPatentCaseList.vue'
                        ),
                    meta: {
                        title: '普通专利'
                    }
                },
                {
                    path: '/logoCaseList',
                    name: 'LogoCaseList',
                    component: () => import(/* webpackChunkName: "logoCaseList" */ '@/views/case/LogoCaseList.vue'),
                    meta: {
                        title: '商标'
                    }
                },
                {
                    path: '/copyrightCaseList',
                    name: 'CopyrightCaseList',
                    component: () =>
                        import(/* webpackChunkName: "copyrightCaseList" */ '@/views/case/CopyrightCaseList.vue'),
                    meta: {
                        title: '版权'
                    }
                },
                {
                    path: '/softCopyrightCaseList',
                    name: 'SoftCopyrightCaseList',
                    component: () =>
                        import(
                            /* webpackChunkName: "softCopyrightCaseList" */ '@/views/case/SoftCopyrightCaseList.vue'
                        ),
                    meta: {
                        title: '软著'
                    }
                },
                {
                    path: '/technologyCaseList',
                    name: 'TechnologyCaseList',
                    component: () =>
                        import(/* webpackChunkName: "technologyCaseList" */ '@/views/case/TechnologyCaseList.vue'),
                    meta: {
                        title: '技术'
                    }
                },
                {
                    path: '/productCaseList',
                    name: 'ProductCaseList',
                    component: () =>
                        import(/* webpackChunkName: "productCaseList" */ '@/views/case/ProductCaseList.vue'),
                    meta: {
                        title: '产品'
                    }
                },
                {
                    path: '/serviceCaseList',
                    name: 'ServiceCaseList',
                    component: () =>
                        import(/* webpackChunkName: "serviceCaseList" */ '@/views/case/ServiceCaseList.vue'),
                    meta: {
                        title: '服务'
                    }
                },
                {
                    path: '/messageEdit',
                    name: 'MessageEdit',
                    component: () => import(/* webpackChunkName: "messageEdit" */ '@/views/MessageEdit.vue'),
                    meta: {
                        title: '留言编辑'
                    }
                },
                {
                    path: '/messageList',
                    name: 'MessageList',
                    component: () => import(/* webpackChunkName: "messageList" */ '@/views/MessageList.vue'),
                    meta: {
                        title: '留言'
                    }
                },
                {
                    path: '/bannerEdit',
                    name: 'BannerEdit',
                    component: () => import(/* webpackChunkName: "bannerEdit" */ '@/views/BannerEdit.vue'),
                    meta: {
                        title: 'banner编辑'
                    }
                },
                {
                    path: '/bannerList',
                    name: 'BannerList',
                    component: () => import(/* webpackChunkName: "bannerList" */ '@/views/BannerList.vue'),
                    meta: {
                        title: 'banner'
                    }
                },
                {
                    path: '/bannerEdit',
                    name: 'BannerEdit',
                    component: () => import(/* webpackChunkName: "bannerEdit" */ '@/views/BannerEdit.vue'),
                    meta: {
                        title: '轮播图编辑'
                    }
                },
                {
                    path: '/bannerList',
                    name: 'BannerList',
                    component: () => import(/* webpackChunkName: "bannerList" */ '@/views/BannerList.vue'),
                    meta: {
                        title: '轮播图'
                    }
                },
                {
                    path: '/bannerEdit',
                    name: 'BannerEdit',
                    component: () => import(/* webpackChunkName: "bannerEdit" */ '@/views/BannerEdit.vue'),
                    meta: {
                        title: 'banner图编辑'
                    }
                },
                {
                    path: '/bannerList',
                    name: 'BannerList',
                    component: () => import(/* webpackChunkName: "bannerList" */ '@/views/BannerList.vue'),
                    meta: {
                        title: 'banner图'
                    }
                },
                {
                    path: '/serviceDetailEdit',
                    name: 'ServiceDetailEdit',
                    component: () =>
                        import(/* webpackChunkName: "serviceDetailEdit" */ '@/views/ServiceDetailEdit.vue'),
                    meta: {
                        title: '全维服务编辑'
                    }
                },
                {
                    path: '/serviceDetailList',
                    name: 'ServiceDetailList',
                    component: () =>
                        import(/* webpackChunkName: "serviceDetailList" */ '@/views/ServiceDetailList.vue'),
                    meta: {
                        title: '全维服务'
                    }
                },
                {
                    path: '/partnerEdit',
                    name: 'PartnerEdit',
                    component: () => import(/* webpackChunkName: "partnerEdit" */ '@/views/PartnerEdit.vue'),
                    meta: {
                        title: '客户编辑'
                    }
                },
                {
                    path: '/partnerList',
                    name: 'PartnerList',
                    component: () => import(/* webpackChunkName: "partnerList" */ '@/views/PartnerList.vue'),
                    meta: {
                        title: '客户'
                    }
                },
                {
                    path: '/expertEdit',
                    name: 'ExpertEdit',
                    component: () => import(/* webpackChunkName: "expertEdit" */ '@/views/ExpertEdit.vue'),
                    meta: {
                        title: '专家编辑'
                    }
                },
                {
                    path: '/expertList',
                    name: 'ExpertList',
                    component: () => import(/* webpackChunkName: "expertList" */ '@/views/ExpertList.vue'),
                    meta: {
                        title: '专家'
                    }
                }
                /**INSERT_LOCATION**/
            ]
        },
        {
            path: '/login',
            name: 'login',
            component: () => import('@/views/Login'),
            meta: {
                title: '登录'
            }
        }
    ]
});
router.beforeEach((to, from, next) => {
    //console.log(to);
    if (/^\/http/.test(to.path)) {
        console.log(Vue.$baseUrl);
        let url = to.path.replace('/', '');
        let params = [];
        if (to.query) {
            for (let key in to.query) {
                if (to.query.hasOwnProperty(key)) {
                    params.push(`${key}=${to.query[key]}`);
                }
            }
        }
        if (params.length > 0) {
            url += `?${params.join('&')}`;
        }
        window.open(url);
        return;
    }
    if (!store.state.userInfo && to.path !== '/login') {
        http.axios
            .get('/user/my')
            .then(res => {
                store.commit('updateUserInfo', res.data);
                next();
                return;
            })
            .catch(() => {
                localStorage.removeItem('token');
                next('/login');
            });
    } else if (!to.matched.length) {
        next('/404');
    } else {
        next();
    }
});

export default router;
