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: true,
        meta: {
            title: "报警信息",
            keepAlive: false,
            level: 0
        },
        children: []
    },
    {
        path: "/home/viewer",
        name: "homeviewer",
        component: Home,
        hidden: true,
        meta: {
            title: "监视页面",
            keepAlive: false,
            level: 0
        },
        children: [
            {
                path: "/home/viewer",
                component: () => import("../views/xDesigner/viewer.vue"),
                name: "watchView",
                hidden: false,
                meta: {
                    title: "监视页面",
                    keepAlive: false,
                    level: 0
                }
            },
            // {
            //     path: "/home/jump",
            //     component: () => import("../components/jump.vue"),
            //     name: "jump",
            //     hidden: true,
            //     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: "/list",
        name: "datalist",
        component: Home,
        hidden: false,
        meta: {
            title: "数据列表",
            keepAlive: false,
            level: 0
        },
        children: [
            {
                path: "/list/nodeslist",
                component: () => import("../views/nodes/nodeslist.vue"),
                name: "nodesdatalist",
                hidden: false,
                meta: {
                    title: "采集点列表",
                    keepAlive: false,
                    level: 0
                }
            },
            {
                path: "/list/alertlist",
                component: () => import("../views/alert/alertList.vue"),
                name: "alertslist",
                hidden: false,
                meta: {
                    title: "报警列表",
                    keepAlive: false,
                    level: 0
                }
            }
        ]
    },
    {
        path: "/AppDesign",
        name: "组态设计",
        hidden: false,
        meta: {
            title: "组态设计器",
            keepAlive: false,
            level: 0
        },
        component: () => import("../views/xDesigner/AppDesign.vue"),
    },
    // {
    //     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;