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: 'audit'
                },
                {
                    path: '/404',
                    name: '404',
                    component: () => import(/* webpackChunkName: "404" */ '@/views/404.vue')
                },
                {
                    path: '/dashboard',
                    name: 'dashboard',
                    component: () => import(/* webpackChunkName: "dashboard" */ '@/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: '/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: '/dataTypeEdit',
                    name: 'DataTypeEdit',
                    component: () => import(/* webpackChunkName: "dataTypeEdit" */ '@/views/DataTypeEdit.vue'),
                    meta: {
                        title: '数据类型编辑'
                    }
                },
                {
                    path: '/dataTypeList',
                    name: 'DataTypeList',
                    component: () => import(/* webpackChunkName: "dataTypeList" */ '@/views/DataTypeList.vue'),
                    meta: {
                        title: '数据类型管理'
                    }
                },
                {
                    path: '/articleEdit',
                    name: 'ArticleEdit',
                    component: () => import(/* webpackChunkName: "articleEdit" */ '@/views/ArticleEdit.vue'),
                    meta: {
                        title: '文章编辑'
                    }
                },
                {
                    path: '/articleList',
                    name: 'ArticleList',
                    component: () => import(/* webpackChunkName: "articleList" */ '@/views/ArticleList.vue'),
                    meta: {
                        title: '内容管理'
                    }
                },
                {
                    path: '/policyEdit',
                    name: 'PolicyEdit',
                    component: () => import(/* webpackChunkName: "policyEdit" */ '@/views/PolicyEdit.vue'),
                    meta: {
                        title: '政策管理编辑'
                    }
                },
                {
                    path: '/policyList',
                    name: 'PolicyList',
                    component: () => import(/* webpackChunkName: "policyList" */ '@/views/PolicyList.vue'),
                    meta: {
                        title: '政策管理'
                    }
                },
                {
                    path: '/orgInfoEdit',
                    name: 'OrgInfoEdit',
                    component: () => import(/* webpackChunkName: "orgInfoEdit" */ '@/views/OrgInfoEdit.vue'),
                    meta: {
                        title: '企业信息编辑'
                    }
                },
                {
                    path: '/orgInfoList',
                    name: 'OrgInfoList',
                    component: () => import(/* webpackChunkName: "orgInfoList" */ '@/views/OrgInfoList.vue'),
                    meta: {
                        title: '企业列表'
                    }
                },
                {
                    path: '/orgInfoAudit',
                    name: 'OrgInfoAudit',
                    component: () => import(/* webpackChunkName: "orgInfoAudit" */ '@/views/OrgInfoAudit.vue'),
                    meta: {
                        title: '企业认证'
                    }
                },
                {
                    path: '/policyAudit',
                    name: 'PolicyAudit',
                    component: () => import(/* webpackChunkName: "PolicyAudit" */ '@/views/PolicyAudit.vue'),
                    meta: {
                        title: '政策审核'
                    }
                },
                {
                    path: '/articleAudit',
                    name: 'ArticleAudit',
                    component: () => import(/* webpackChunkName: "ArticleAudit" */ '@/views/ArticleAudit.vue'),
                    meta: {
                        title: '发布管理'
                    }
                },

                {
                    path: '/authorityEdit',
                    name: 'AuthorityEdit',
                    component: () => import(/* webpackChunkName: "authorityEdit" */ './views/AuthorityEdit.vue'),
                    meta: {
                        title: '角色编辑'
                    }
                },
                {
                    path: '/authorityList',
                    name: 'AuthorityList',
                    component: () => import(/* webpackChunkName: "authorityList" */ './views/AuthorityList.vue'),
                    meta: {
                        title: '角色管理'
                    }
                },
                {
                    path: '/agency',
                    name: 'agency',
                    component: () => import(/* webpackChunkName: "agency" */ './views/agency.vue'),
                    meta: {
                        title: '待办列表'
                    }
                },
                {
                    path: '/resourceSupplyAndDemandList',
                    name: 'resourceSupplyAndDemandList',
                    component: () =>
                        import(
                            /* webpackChunkName: "resourceSupplyAndDemandList" */ './views/ResourceSupplyAndDemandList.vue'
                        ),
                    meta: {
                        title: '资源供需列表'
                    }
                },
                {
                    path: '/resourceSupplyAndDemandAudit',
                    name: 'resourceSupplyAndDemandAudit',
                    component: () =>
                        import(
                            /* webpackChunkName: "resourceSupplyAndDemandAudit" */ './views/ResourceSupplyAndDemandAudit.vue'
                        ),
                    meta: {
                        title: '资源供需审核'
                    }
                },
                {
                    path: '/resourceSupplyAndDemandEdit',
                    name: 'resourceSupplyAndDemandEdit',
                    component: () =>
                        import(
                            /* webpackChunkName: "resourceSupplyAndDemandEdit" */ './views/ResourceSupplyAndDemandEdit.vue'
                        ),
                    meta: {
                        title: '资源供需编辑'
                    }
                },
                {
                    path: '/postList',
                    name: 'postList',
                    component: () => import(/* webpackChunkName: "postList" */ './views/PostList.vue'),
                    meta: {
                        title: '民政互动列表'
                    }
                },
                {
                    path: '/postAudit',
                    name: 'postAudit',
                    component: () => import(/* webpackChunkName: "postAudit" */ './views/PostAudit.vue'),
                    meta: {
                        title: '民政互动审核'
                    }
                },
                {
                    path: '/postEdit',
                    name: 'postEdit',
                    component: () => import(/* webpackChunkName: "postEdit" */ './views/PostEdit.vue'),
                    meta: {
                        title: '民政互动编辑'
                    }
                },
                {
                    path: '/techTradeStatEdit',
                    name: 'TechTradeStatEdit',
                    component: () =>
                        import(/* webpackChunkName: "techTradeStatEdit" */ '@/views/TechTradeStatEdit.vue'),
                    meta: {
                        title: '技术交易编辑'
                    }
                },
                {
                    path: '/techTradeStatList',
                    name: 'TechTradeStatList',
                    component: () =>
                        import(/* webpackChunkName: "techTradeStatList" */ '@/views/TechTradeStatList.vue'),
                    meta: {
                        title: '技术交易'
                    }
                },
                {
                    path: '/articleTypeEdit',
                    name: 'ArticleTypeEdit',
                    component: () => import(/* webpackChunkName: "articleTypeEdit" */ '@/views/ArticleTypeEdit.vue'),
                    meta: {
                        title: '类型编辑'
                    }
                },
                {
                    path: '/articleTypeList',
                    name: 'ArticleTypeList',
                    component: () => import(/* webpackChunkName: "articleTypeList" */ '@/views/ArticleTypeList.vue'),
                    meta: {
                        title: '类型管理'
                    }
                },
                {
                    path: '/editingEdit',
                    name: 'EditingEdit',
                    component: () => import(/* webpackChunkName: "editingEdit" */ '@/views/EditingEdit.vue'),
                    meta: {
                        title: '采编管理编辑'
                    }
                },
                {
                    path: '/editingList',
                    name: 'EditingList',
                    component: () => import(/* webpackChunkName: "editingList" */ '@/views/EditingList.vue'),
                    meta: {
                        title: '采编管理'
                    }
                },
                {
                    path: '/operationLogEdit',
                    name: 'OperationLogEdit',
                    component: () => import(/* webpackChunkName: "operationLogEdit" */ '@/views/OperationLogEdit.vue'),
                    meta: {
                        title: '操作日志编辑'
                    }
                },
                {
                    path: '/operationLogList',
                    name: 'OperationLogList',
                    component: () => import(/* webpackChunkName: "operationLogList" */ '@/views/OperationLogList.vue'),
                    meta: {
                        title: '操作日志'
                    }
                },
                {
                    path: '/exceptionLogEdit',
                    name: 'ExceptionLogEdit',
                    component: () => import(/* webpackChunkName: "exceptionLogEdit" */ '@/views/ExceptionLogEdit.vue'),
                    meta: {
                        title: '异常日志编辑'
                    }
                },
                {
                    path: '/exceptionLogList',
                    name: 'ExceptionLogList',
                    component: () => import(/* webpackChunkName: "exceptionLogList" */ '@/views/ExceptionLogList.vue'),
                    meta: {
                        title: '异常日志'
                    }
                },
                {
                    path: '/loginLogList',
                    name: 'LoginLogList',
                    component: () => import(/* webpackChunkName: "loginLogList" */ '@/views/LoginLogList.vue'),
                    meta: {
                        title: '登录日志'
                    }
                },
                {
                    path: '/advertise',
                    name: 'Advertise',
                    component: () => import(/* webpackChunkName: "advertise" */ '@/views/consult/Advertise.vue'),
                    meta: {
                        title: '宣传推介'
                    }
                },
                {
                    path: '/projectApply',
                    name: 'ProjectApply',
                    component: () => import(/* webpackChunkName: "projectApply" */ '@/views/consult/ProjectApply.vue'),
                    meta: {
                        title: '项目申报'
                    }
                },
                {
                    path: '/policyService',
                    name: 'PolicyService',
                    component: () =>
                        import(/* webpackChunkName: "policyService" */ '@/views/consult/PolicyService.vue'),
                    meta: {
                        title: '政策服务'
                    }
                },
                {
                    path: '/startupService',
                    name: 'StartupService',
                    component: () =>
                        import(/* webpackChunkName: "startupService" */ '@/views/consult/StartupService.vue'),
                    meta: {
                        title: '创业服务'
                    }
                },
                {
                    path: '/knowledgeService',
                    name: 'KnowledgeService',
                    component: () =>
                        import(/* webpackChunkName: "knowledgeService" */ '@/views/consult/KnowledgeService.vue'),
                    meta: {
                        title: '知识服务'
                    }
                },
                {
                    path: '/requirementService',
                    name: 'RequirementService',
                    component: () =>
                        import(/* webpackChunkName: "requirementService" */ '@/views/consult/RequirementService.vue'),
                    meta: {
                        title: '需求服务'
                    }
                },
                {
                    path: '/projectManagementList',
                    name: 'ProjectManagementList',
                    component: () =>
                        import(/* webpackChunkName: "projectManagementList" */ '@/views/ProjectManagementList.vue'),
                    meta: {
                        title: '项目管理'
                    }
                },
                {
                    path: '/projectManagementEdit',
                    name: 'ProjectManagementEdit',
                    component: () =>
                        import(/* webpackChunkName: "projectManagementEdit" */ '@/views/ProjectManagementEdit.vue'),
                    meta: {
                        title: '项目编辑'
                    }
                },
                {
                    path: '/projectReview',
                    name: 'ProjectReview',
                    component: () => import(/* webpackChunkName: "projectReview" */ '@/views/ProjectReview.vue'),
                    meta: {
                        title: '项目评审'
                    }
                },
                {
                    path: '/projectAudit',
                    name: 'ProjectAudit',
                    component: () => import(/* webpackChunkName: "projectAudit" */ '@/views/ProjectAudit.vue'),
                    meta: {
                        title: '项目审核'
                    }
                },
                {
                    path: '/cityDataEdit',
                    name: 'CityDataEdit',
                    component: () => import(/* webpackChunkName: "cityDataEdit" */ '@/views/CityDataEdit.vue'),
                    meta: {
                        title: '城市数据编辑'
                    }
                },
                {
                    path: '/cityDataList',
                    name: 'CityDataList',
                    component: () => import(/* webpackChunkName: "cityDataList" */ '@/views/CityDataList.vue'),
                    meta: {
                        title: '城市数据'
                    }
                },
                {
                    path: '/approvalEdit',
                    name: 'ApprovalEdit',
                    component: () => import(/* webpackChunkName: "approvalEdit" */ '@/views/ApprovalEdit.vue'),
                    meta: {
                        title: '审批管理编辑'
                    }
                },
                {
                    path: '/approvalList',
                    name: 'ApprovalList',
                    component: () => import(/* webpackChunkName: "approvalList" */ '@/views/ApprovalList.vue'),
                    meta: {
                        title: '审批管理'
                    }
                },
                {
                    path: '/approvalProcessEdit',
                    name: 'ApprovalProcessEdit',
                    component: () =>
                        import(/* webpackChunkName: "approvalProcessEdit" */ '@/views/ApprovalProcessEdit.vue'),
                    meta: {
                        title: '审批流程编辑'
                    }
                },
                {
                    path: '/approvalProcessList',
                    name: 'ApprovalProcessList',
                    component: () =>
                        import(/* webpackChunkName: "approvalProcessList" */ '@/views/ApprovalProcessList.vue'),
                    meta: {
                        title: '审批列表'
                    }
                },
                {
                    path: '/approver',
                    name: 'Approver',
                    component: () => import(/* webpackChunkName: "approver" */ '@/views/Approver.vue'),
                    meta: {
                        title: '审批人员配置'
                    }
                },
                {
                    path: '/audit',
                    name: 'audit',
                    component: () => import(/* webpackChunkName: "audit" */ '@/views/audit.vue'),
                    meta: {
                        title: '待办列表'
                    }
                },
                {
                    path: '/metricEdit',
                    name: 'MetricEdit',
                    component: () => import(/* webpackChunkName: "metricEdit" */ '@/views/MetricEdit.vue'),
                    meta: {
                        title: '指标管理编辑'
                    }
                },
                {
                    path: '/metricList',
                    name: 'MetricList',
                    component: () => import(/* webpackChunkName: "metricList" */ '@/views/MetricList.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: '专家'
                    }
                },
                {
                    path: '/extLinkEdit',
                    name: 'ExtLinkEdit',
                    component: () => import(/* webpackChunkName: "extLinkEdit" */ '@/views/ExtLinkEdit.vue'),
                    meta: {
                        title: '友情链接编辑'
                    }
                },
                {
                    path: '/extLinkList',
                    name: 'ExtLinkList',
                    component: () => import(/* webpackChunkName: "extLinkList" */ '@/views/ExtLinkList.vue'),
                    meta: {
                        title: '友情链接'
                    }
                },
                {
                    path: '/analyeScoreEdit',
                    name: 'AnalyeScoreEdit',
                    component: () => import(/* webpackChunkName: "analyeScoreEdit" */ '@/views/AnalyeScoreEdit.vue'),
                    meta: {
                        title: '指标分值编辑'
                    }
                },
                {
                    path: '/analyeScoreList',
                    name: 'AnalyeScoreList',
                    component: () => import(/* webpackChunkName: "analyeScoreList" */ '@/views/AnalyeScoreList.vue'),
                    meta: {
                        title: '指标分值'
                    }
                },
                {
                    path: '/analyzeStateEdit',
                    name: 'AnalyzeStateEdit',
                    component: () => import(/* webpackChunkName: "analyzeStateEdit" */ '@/views/AnalyzeStateEdit.vue'),
                    meta: {
                        title: '指标数据编辑'
                    }
                },
                {
                    path: '/analyzeStateList',
                    name: 'AnalyzeStateList',
                    component: () => import(/* webpackChunkName: "analyzeStateList" */ '@/views/AnalyzeStateList.vue'),
                    meta: {
                        title: '指标数据'
                    }
                },
                {
                    path: '/analyeScoreEdit',
                    name: 'AnalyeScoreEdit',
                    component: () => import(/* webpackChunkName: "analyeScoreEdit" */ '@/views/AnalyeScoreEdit.vue'),
                    meta: {
                        title: '指标分值编辑'
                    }
                },
                {
                    path: '/analyeScoreList',
                    name: 'AnalyeScoreList',
                    component: () => import(/* webpackChunkName: "analyeScoreList" */ '@/views/AnalyeScoreList.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 => {
                if (res.data.authorities.find(i => i.name === 'ROLE_ADMIN')) {
                    store.commit('updateIsAdmin', true);
                }
                store.commit('updateUserInfo', res.data);
                next();
                return;
            })
            .catch(e => {
                console.log('eeeee', e);
                localStorage.removeItem('token');
                next('/login');
            });
    } else if (!to.matched.length) {
        next('/404');
    } else {
        next();
    }
});
export default router;
