import Vue from 'vue'
import Router from 'vue-router'
import Layout from '../components/layout/Index'
import Login from '../views/login/index.vue'

Vue.use(Router)
/*****************************************************************************************************************8
 *  注意事项
 *  1. 名字为Layout的为框架组件，不可修改name名称
 *  2. 有子路由的,在children添加，没有子路由，不加children，否则报错
 *
 * %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%5%*/
export const constantRoutes = [
    {
        path: "/",
        name: 'login',
        component: Login,
    },
    {
        //Warning:  name:Layout，禁止修改！！！！
        path: "/Layout",
        name: 'Layout',
        redirect: "/dashboard",
        component: Layout,
        children: [
            {
                path: "/dashboard",
                name: "dashboard",
                show: true, //在导航栏是否显示
                component: () => import('@/views/dashboard/Dashboard'),
                meta: { name: "导航菜单", iconfont: "/images/img6.png" },
            }, {
                path: "/draw",
                name: "draw",
                show: false, //在导航栏是否显示
                component: () => import('@/views/data_draw/index'),
                meta: { name: "数据采集", iconfont: "/images/img6.png" },
            },{
                path: "/excel_data_upload",
                name: "excel_data_upload",
                show: false, //在导航栏是否显示
                component: () => import('@/views/data_draw/excel_data_upload'),
                meta: { name: "Excel", iconfont: "/images/img6.png" },
            },{
                path: "/shp_data_upload",
                name: "shp_data_upload",
                show: false, //在导航栏是否显示
                component: () => import('@/views/data_draw/shp_data_upload'),
                meta: { name: "Excel", iconfont: "/images/img6.png" },
            },
            {
                path: "/big-scene",
                name: "big-scene",
                show: false,//在导航栏是否显示
                component: () => import('@/views/big_scene/BigScene'),
                meta: { name: "监控中心", iconfont: "/images/img7.png" },
            },{
                path: "/monitor",
                name: "monitor",
                show: true,//在导航栏是否显示
                component: () => import('@/views/monitor/index'),
                meta: { name: "监控中心", iconfont: "/images/img7.png" },
            },{
                path: "/upload_type_selected",
                name: "upload_type_selected",
                show: true, //在导航栏是否显示
                component: () => import('@/views/data_manage/upload_type_selected'),
                meta: { name: "数据上传", iconfont: "/images/img6.png" },
            },{
                path: "/layer_style_config",
                name: "layer_style_config",
                show: false, //在导航栏是否显示
                component: () => import('@/views/data_manage/yangshi'),
                meta: { name: "样式配置", iconfont: "/images/img6.png" },
            },
            // {
            //     path: "/grid",
            //     name: "Grid",
            //     show: true,//在导航栏是否显示
            //     component: () => import('@/views/grid'),
            //     meta: { name: "网格员管理", iconfont: "/images/img9.png" },
            // },
            {
                path: "/burst-upload",
                name: "NewBurstUpload",
                show: false,//在导航栏是否显示
                component: () => import('@/views/burst_upload/BurstUpload'),
                meta: { name: "分片上传", iconfont: "/images/img9.png" },
            },
            {
                path: "/ServiceList",
                name: "Datadetails",
                show: true,//在导航栏是否显示
                component: () => import('@/views/ServiceList/Datadetails'),
                meta: { name: "服务中心", iconfont: "/images/img9.png" },
            },
            {
                path: "/applymanage",
                name: "applymanage",
                show: false,//在导航栏是否显示
                component: () => import('@/views/applymanage/applymanage'),
                meta: { name: "应用管理", iconfont: "/images/img9.png" },
            },
            {
                path: "/mars3d",
                name: "mars3d",
                component: () => import('@/views/mars3d/mars3d'),
                show: true,//在导航栏是否显示
                meta: { name: "应用管理", iconfont: "/images/img9.png" },
            },
            {
                path: "/mars3dcopy",
                name: "mars3dcopy",
                component: () => import('@/views/mars3d/mars3dcopy'),
                show: false,//在导航栏是否显示
                meta: { name: "测试", iconfont: "/images/img9.png" },
            },
            {
                path: "/loginout",
                name: "loginout",
                show: true,//在导航栏是否显示
                component: () => import('@/views/home/Home'),
                meta: { name: "退出", iconfont: "/images/img8.png" },
                // children: [
                //     {
                //         path: "/loginout",
                //         name: "loginout",
                //         // component: () => import('@/views/home/Home'),
                //         meta: { name: "退出", iconfont: "/images/img9.png" },
                //     }
                // ]
            },

        ]
    }
]
const createRouter = () => new Router({
    mode: 'hash',
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes
})

const router = createRouter()


export function resetRouter() {
    const newRouter = createRouter()
    router.matcher = newRouter.matcher
}

// 使用 router.beforeEach 注册一个全局前置守卫，判断用户是否登陆

router.beforeEach((to, from, next) => {
    // console.log(to);
    if (to.path == '/') {
        next();
    } else {
        let token = localStorage.getItem('X-Token');
        // console.log(!token);
        if (!token) {
            next('/');
        } else {
            next();
        }
    }
});
export default router
