import Vue from 'vue'
import Router from 'vue-router'
import store from '../vuex'
import axios from 'axios'

Vue.use(Router);

const router = new Router({
    routes: [{
            path: '/',
            component: () =>
                import ('../pages/App'),
            children: [{
                    path: '/',
                    redirect: 'dashboard'
                },
                {
                    path: '/404',
                    name: '404',
                    component: () =>
                        import ('../pages/404')
                },
                {
                    path: '/dashboard',
                    name: 'dashboard',
                    component: () =>
                        import ('../pages/Dashboard')
                },
                {
                    path: '/users',
                    name: 'users',
                    component: () =>
                        import ('../pages/Users')
                },
                {
                    path: '/user',
                    name: 'user',
                    component: () =>
                        import ('../pages/User')
                },
                {
                    path: '/menus',
                    name: 'menus',
                    component: () =>
                        import ('../pages/Menus')
                },
                {
                    path: '/roles',
                    name: 'roles',
                    component: () =>
                        import ('../pages/Roles')
                },
                {
                    path: '/role',
                    name: 'role',
                    component: () =>
                        import ('../pages/Role')
                },
                {
                    path: '/api',
                    name: 'api',
                    component: () =>
                        import ('../pages/Api')
                },
                {
                    path: '/genCodes',
                    name: 'genCodes',
                    component: () =>
                        import ('../pages/GenCodes')
                },
                {
                    path: '/genCode',
                    name: 'genCode',
                    component: () =>
                        import ('../pages/GenCode')
                },
                {
                    path: '/permissions',
                    name: 'permissions',
                    component: () =>
                        import ('../pages/Permissions')
                },
                {
                    path: '/permission',
                    name: 'permission',
                    component: () =>
                        import ('../pages/Permission')
                },
                {
                    path: '/departs',
                    name: 'departs',
                    component: () =>
                        import ('../pages/Departs')
                },
                {
                    path: '/lineChart',
                    name: 'lineChart',
                    component: () =>
                        import ('../pages/LineChart')
                },
                {
                    path: '/barChart',
                    name: 'barChart',
                    component: () =>
                        import ('../pages/BarChart')
                },
                {
                    path: '/polarAreaChart',
                    name: 'polarAreaChart',
                    component: () =>
                        import ('../pages/PolarAreaChart')
                },
                {
                    path: '/pieChart',
                    name: 'pieChart',
                    component: () =>
                        import ('../pages/PieChart')
                },
                {
                    path: '/radarChart',
                    name: 'radarChart',
                    component: () =>
                        import ('../pages/RadarChart')
                },
                {
                    path: '/bubbleChart',
                    name: 'bubbleChart',
                    component: () =>
                        import ('../pages/BubbleChart')
                },
                {
                    path: '/processModels',
                    name: 'processModels',
                    component: () =>
                        import ('../pages/ProcessModels')
                },
                {
                    path: '/processDefinitions',
                    name: 'processDefinitions',
                    component: () =>
                        import ('../pages/ProcessDefinitions')
                },
                {
                    path: '/myProcesses',
                    name: 'myProcesses',
                    component: () =>
                        import ('../pages/MyProcesses')
                },
                {
                    path: '/myTasks',
                    name: 'myTasks',
                    component: () =>
                        import ('../pages/MyTasks')
                },
                {
                    path: '/completeTaskDynamic',
                    name: 'CompleteTaskDynamic',
                    component: () =>
                        import ('../pages/CompleteTaskDynamic')
                },
                {
                    path: '/commonQuerys',
                    name: 'commonQuerys',
                    component: () =>
                        import ('../pages/CommonQuerys')
                },
                {
                    path: '/commonQuery',
                    name: 'commonQuery',
                    component: () =>
                        import ('../pages/CommonQuery')
                },
                {
                    path: '/commonIframe',
                    name: 'commonIframe',
                    component: () =>
                        import ('../pages/CommonIframe')
                },
                {
                    path: '/queryConfigs',
                    name: 'queryConfigs',
                    component: () =>
                        import ('../pages/QueryConfigs')
                },
                {
                    path: '/queryConfig',
                    name: 'queryConfig',
                    component: () =>
                        import ('../pages/QueryConfig')
                },
                {
                    path: '/dataSourceInfos',
                    name: 'dataSourceInfos',
                    component: () =>
                        import ('../pages/DataSourceInfos')
                },
                {
                    path: '/dataSourceInfo',
                    name: 'dataSourceInfo',
                    component: () =>
                        import ('../pages/DataSourceInfo')
                },
                {
                    path: '/deploySystem',
                    name: 'DeploySystem',
                    component: () =>
                        import ('../pages/DeploySystem')
                },
                {
                    path: '/myCanvas',
                    name: 'MyCanvas',
                    component: () =>
                        import ('../pages/MyCanvas')
                },
                {
                    path: '/drugArea',
                    name: 'drugArea',
                    component: () =>
                        import ('../pages/DrugAreaCanvas')
                },
                {
                    path: '/drugAreaCanvas',
                    name: 'drugAreaCanvas',
                    component: () =>
                        import ('../pages/DrugAreaCanvas')
                },
                {
                    path: '/drugContent',
                    name: 'drugContent',
                    component: () =>
                        import ('../pages/DrugContentCanvas')
                },
                {
                    path: '/drugContentCanvas',
                    name: 'drugContentCanvas',
                    component: () =>
                        import ('../pages/DrugContentCanvas')
                },
                {
                    path: '/arContentTemplate',
                    name: 'arContentTemplate',
                    component: () =>
                        import ('../pages/ArContentTemplate')
                },
                {
                    path: '/arContentTemplates',
                    name: 'arContentTemplates',
                    component: () =>
                        import ('../pages/ArContentTemplates')
                },
                {
                    path: '/marketMap',
                    name: 'MarketMap',
                    component: () =>
                        import ('../pages/MarketMap')
                },
                {
                    path: '/marketMaps',
                    name: 'MarketMaps',
                    component: () =>
                        import ('../pages/MarketMaps')
                },
                {
                    path: '/marketMapBox',
                    name: 'MarketMapBox',
                    component: () =>
                        import ('../pages/MarketMapBox')
                },
                {
                    path: '/marketMapBoxs',
                    name: 'MarketMapBoxs',
                    component: () =>
                        import ('../pages/MarketMapBoxs')
                },
                {
                    path: '/marketMapBoxDes',
                    name: 'MarketMapBoxDes',
                    component: () =>
                        import ('../pages/MarketMapBoxDes')
                },
                {
                    path: '/marketMapBoxDess',
                    name: 'MarketMapBoxDess',
                    component: () =>
                        import ('../pages/MarketMapBoxDess')
                },
                {
                    path: '/guideTipImage',
                    name: 'GuideTipImage',
                    component: () =>
                        import ('../pages/GuideTipImage')
                },
                {
                    path: '/guideTipImages',
                    name: 'GuideTipImages',
                    component: () =>
                        import ('../pages/GuideTipImages')
                },
                {
                    path: '/marketAimPlace',
                    name: 'MarketAimPlace',
                    component: () =>
                        import ('../pages/MarketAimPlace')
                },
                {
                    path: '/marketAimPlaces',
                    name: 'MarketAimPlaces',
                    component: () =>
                        import ('../pages/MarketAimPlaces')
                },
                {
                    path: '/landMark',
                    name: 'LandMark',
                    component: () =>
                        import ('../pages/LandMark')
                },
                {
                    path: '/landMarks',
                    name: 'LandMarks',
                    component: () =>
                        import ('../pages/LandMarks')
                }, {

                    path: '/landMarkCreate',
                    name: 'landMarkCreate',
                    component: () =>
                        import ('../pages/LandMarkCreate')
                },
                {
                    path: '/landMarkLevel',
                    name: 'LandMarkLevel',
                    component: () =>
                        import ('../pages/LandMarkLevel')
                },
                {
                    path: '/landMarkLevels',
                    name: 'LandMarkLevels',
                    component: () =>
                        import ('../pages/LandMarkLevels')
                },
                {
                    path: '/vuforiaImageGroup',
                    name: 'VuforiaImageGroup',
                    component: () =>
                        import ('../pages/VuforiaImageGroup')
                },
                {
                    path: '/vuforiaImageGroups',
                    name: 'VuforiaImageGroups',
                    component: () =>
                        import ('../pages/VuforiaImageGroups')
                },
                {
                    path: '/vuforiaImageType',
                    name: 'VuforiaImageType',
                    component: () =>
                        import ('../pages/VuforiaImageType')
                },
                {
                    path: '/vuforiaImageTypes',
                    name: 'VuforiaImageTypes',
                    component: () =>
                        import ('../pages/VuforiaImageTypes')
                },
                {
                    path: '/vuforiaImageInfo',
                    name: 'VuforiaImageInfo',
                    component: () =>
                        import ('../pages/VuforiaImageInfo')
                },
                {
                    path: '/vuforiaImageInfos',
                    name: 'VuforiaImageInfos',
                    component: () =>
                        import ('../pages/VuforiaImageInfos')
                },
                {
                    path: '/arContent',
                    name: 'ArContent',
                    component: () =>
                        import ('../pages/ArContent')
                },
                {
                    path: '/arContents',
                    name: 'ArContents',
                    component: () =>
                        import ('../pages/ArContents')
                },
                {
                    path: '/aimPlaceContent',
                    name: 'AimPlaceContent',
                    component: () =>
                        import ('../pages/AimPlaceContent')
                },
                {
                    path: '/aimPlaceContents',
                    name: 'AimPlaceContents',
                    component: () =>
                        import ('../pages/AimPlaceContents')
                },
                {
                    path: '/aimPlaceContentChild',
                    name: 'AimPlaceContentChild',
                    component: () =>
                        import ('../pages/AimPlaceContentChild')
                },
                {
                    path: '/aimPlaceContentChilds',
                    name: 'AimPlaceContentChilds',
                    component: () =>
                        import ('../pages/AimPlaceContentChilds')
                },
                {
                    path: '/aimPlacePosition',
                    name: 'AimPlacePosition',
                    component: () =>
                        import ('../pages/AimPlacePosition')
                },
                {
                    path: '/aimPlacePositions',
                    name: 'AimPlacePositions',
                    component: () =>
                        import ('../pages/AimPlacePositions')
                },
                {
                    path: '/aimPlacePositionLevel',
                    name: 'AimPlacePositionLevel',
                    component: () =>
                        import ('../pages/AimPlacePositionLevel')
                },
                {
                    path: '/aimPlacePositionLevels',
                    name: 'AimPlacePositionLevels',
                    component: () =>
                        import ('../pages/AimPlacePositionLevels')
                },
                {
                    path: '/cityInfo',
                    name: 'CityInfo',
                    component: () =>
                        import ('../pages/CityInfo')
                },
                {
                    path: '/cityInfos',
                    name: 'CityInfos',
                    component: () =>
                        import ('../pages/CityInfos')
                },
                {
                    path: '/arContentChild',
                    name: 'ArContentChild',
                    component: () =>
                        import ('../pages/ArContentChild')
                },
                {
                    path: '/arContentChilds',
                    name: 'ArContentChilds',
                    component: () =>
                        import ('../pages/ArContentChilds')
                },
                {
                    path: '/landmarkType',
                    name: 'LandmarkType',
                    component: () =>
                        import ('../pages/LandmarkType')
                },
                {
                    path: '/landmarkTypes',
                    name: 'LandmarkTypes',
                    component: () =>
                        import ('../pages/LandmarkTypes')
                },
                {
                    path: '/aimTemplate',
                    name: 'AimTemplate',
                    component: () =>
                        import ('../pages/AimTemplate')
                },
                {
                    path: '/aimTemplates',
                    name: 'AimTemplates',
                    component: () =>
                        import ('../pages/AimTemplates')
                },
                {
                    path: '/aimTemplateAim',
                    name: 'AimTemplateAim',
                    component: () =>
                        import ('../pages/AimTemplateAim')
                },
                {
                    path: '/aimTemplateAims',
                    name: 'AimTemplateAims',
                    component: () =>
                        import ('../pages/AimTemplateAims')
                },
                {
                    path: '/aimTemplateAr',
                    name: 'AimTemplateAr',
                    component: () =>
                        import ('../pages/AimTemplateAr')
                },
                {
                    path: '/aimTemplateArs',
                    name: 'AimTemplateArs',
                    component: () =>
                        import ('../pages/AimTemplateArs')
                },
                {
                    path: '/areaInfo',
                    name: 'AreaInfo',
                    component: () =>
                        import ('../pages/AreaInfo')
                },
                {
                    path: '/areaInfos',
                    name: 'AreaInfos',
                    component: () =>
                        import ('../pages/AreaInfos')
                },
                {
                    path: '/thingInfo',
                    name: 'ThingInfo',
                    component: () =>
                        import ('../pages/ThingInfo')
                },
                {
                    path: '/thingInfos',
                    name: 'ThingInfos',
                    component: () =>
                        import ('../pages/ThingInfos')
                },
                {
                    path: '/aimGroupInfo',
                    name: 'AimGroupInfo',
                    component: () =>
                        import ('../pages/AimGroupInfo')
                },
                {
                    path: '/aimGroupInfos',
                    name: 'AimGroupInfos',
                    component: () =>
                        import ('../pages/AimGroupInfos')
                },
                {
                    path: '/areaShowPoint',
                    name: 'AreaShowPoint',
                    component: () =>
                        import ('../pages/AreaShowPoint')
                },
                {
                    path: '/areaShowPoints',
                    name: 'AreaShowPoints',
                    component: () =>
                        import ('../pages/AreaShowPoints')
                },
                {
                    path: '/aimPlaceInfo',
                    name: 'AimPlaceInfo',
                    component: () =>
                        import ('../pages/AimPlaceInfo')
                },
                {
                    path: '/aimPlaceInfos',
                    name: 'AimPlaceInfos',
                    component: () =>
                        import ('../pages/AimPlaceInfos')
                },
                {
                    path: '/userFileInfo',
                    name: 'UserFileInfo',
                    component: () =>
                        import ('../pages/UserFileInfo')
                },
                {
                    path: '/userFileInfos',
                    name: 'UserFileInfos',
                    component: () =>
                        import ('../pages/UserFileInfos')
                },
                {
                    path: '/arContentType',
                    name: 'ArContentType',
                    component: () =>
                        import ('../pages/ArContentType')
                },
                {
                    path: '/arContentTypes',
                    name: 'ArContentTypes',
                    component: () =>
                        import ('../pages/ArContentTypes')
                }
                /**INSERT_LOCATION**/
            ]
        },
        {
            path: '/login',
            name: 'login',
            component: () =>
                import ('../pages/Login')
        }
    ]
});
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') {
        axios.get('/userInfo/getUserInfo').then(res => {
            if (res.status === 200) {
                if (res.data.success && res.data.data) {
                    store.commit('updateUserInfo', res.data.data);
                    next();
                    return;
                }
            }
            next('/login');
        }).catch(() => {
            next('/login');
        })
    } else if (!to.matched.length) {
        next('/404');
    } else {
        next();
    }
});
router.afterEach((to, from) => {
    window.onresize();
});

export default router;