import Vue from "vue";
import VueRouter from "vue-router";
import Home from "../views/Home.vue";
Vue.use(VueRouter);

const routes = [{
        path: "/", //默认路由
        redirect: "/login",
        hidden: true,
        meta: {
            title: "默认路由",
            keepAlive: false,
            level: 0
        }
    },
    //登录
    {
        path: "/login",
        name: "login",
        component: r => require.ensure([], () => r(require("../views/login/Login.vue")), "Login"),
        hidden: true,
        meta: {
            title: "登录",
            keepAlive: false,
            level: 0
        }
    }, {
        path: "*", //输错路由回首页
        redirect: "/404",
        hidden: true,
        meta: {
            title: "输错路由回首页",
            keepAlive: false,
            level: 0 //判断是否缓存 0为不缓存 1为缓存 2为详情页
        }
    },
    //404
    {
        path: "/404",
        name: "notFound",
        component: r => require.ensure([], () => r(require("../views/error/NotFound.vue")), "NotFound"),
        hidden: true,
        meta: {
            title: "404",
            keepAlive: false,
            level: 0
        }
    },
    {
        path: "/alarmList",
        name: "alarmList",
        component: Home,
        redirect: '/alarmList',
        hidden: false,
        meta: {
            title: "报警信息",
            keepAlive: false,
            level: 0
        },
        children: [{
            path: "/goods/goodsList",
            component: () => import("../views/goods/goodsList.vue"),
            name: "goodsList",
            hidden: false,
            meta: {
                title: "报警列表",
                keepAlive: false,
                level: 0
            }
        }, ]
    },
    {
        path: "/config",
        name: "config",
        component: Home,
     
        hidden: false,
        meta: {
            title: "配置功能",
            keepAlive: false,
            level: 0
        },
        children: [{
                path: "/config/rule/list",
                component: () => import("../views/rule/list.vue"),
                name: "ruleList",
                hidden: false,
                meta: {
                    title: "报警配置",
                    keepAlive: false,
                    level: 0
                }
            },
            {
                path: "/config/pointList",
                component: () => import("../views/goods/goodsList.vue"),
                name: "testPointList",
                hidden: false,
                meta: {
                    title: "测点配置",
                    keepAlive: false,
                    level: 0
                }
            },
            {
                path: "/config/userList",
                component: () => import("../views/goods/goodsList.vue"),
                name: "testPointList",
                hidden: false,
                meta: {
                    title: "用户管理",
                    keepAlive: false,
                    level: 0
                }
            },
        ]
    },


    //监视容器路由
    {
        path: '/Viewer',
        component: () => import('../views/xDesigner/viewer.vue'),
        hidden: true,
    },

    {
        hidden: true,
        path: '/XDesigner',
        name: '组态设计器',
        meta: {
            title: "XDesigner",
            keepAlive: false,
            level: 0 //判断是否缓存 0为不缓存 1为缓存 2为详情页
        },
        component: () => import("../views/xDesigner/xdesigner.vue")
    },

    {
        path: '/AppDesign',
        component: () => import('../views/xDesigner/AppDesign.vue'),
        hidden: true,
    },
]

const router = new VueRouter({
    // mode: "history",
    base: process.env.BASE_URL,
    routes
});

// 全局路由守卫、路由拦截
// router.beforeEach((to, from, next) => {
//     const isLogin = localStorage.token ? true : false;
//     if (to.path === "/login" || to.path === "/forgotPassword") {
//         next();
//     } else {
//         isLogin ? next() : next("/");
//     }
// });

export default router;