import Vue from 'vue'
import Router from 'vue-router'
import utils from '@/utils/utils'

Vue.use(Router)
const router = new Router({
    routes: [
        // 首页(innerBox)
        {
            path: '/',
            name: 'Home',
            component: () =>
                import ('../views/Home/Home'),
            meta: {
                isLogin: true
            }
        },
        // 登录
        {
            path: '/login',
            name: 'Login',
            component: () =>
                import ("@/views/Login/LoginBox")
        },
        // 注册
        {
            path: '/reg',
            name: 'Reg',
            component: () =>
                import ("@/views/Reg/Reg")
        },
        // 忘记密码
        {
            path: '/forget',
            name: 'Forget',
            component: () =>
                import ("@/views/Forget/Forget")
        },
        // 快速登录账号密码
        {
            path: '/visitor',
            name: 'Visitor',
            component: () =>
                import ("@/views/Visitor/Visitor"),
            // meta: {
            //     isLogin: true
            // }
        },
        // 游戏内充值
        {
            path: '/gamepay',
            name: 'GamePay',
            component: () =>
                import ("@/views/GamePay/GamePay"),
            meta: {
                isLogin: true
            }
        },
        // 收银台
        {
            path: '/counter',
            name: 'Counter',
            component: () =>
                import ("@/views/Counter/CounterBox"),
            // meta: {
            //     isLogin: true
            // }
        },

        // 红包活动
        {
            path: '/activity_hb',
            name: 'ActivityHb',
            component: () =>
                import ("@/views/Active/Hb/Hb"),
            meta: {
                isLogin: true
            }
        },
        // 鸿币充值
        {
            path: '/hb_recharge',
            name: 'HbRecharge',
            component: () =>
                import ("@/views/HbRecharge/HbRecharge"),
            meta: {
                isLogin: true
            }
        },
    ]
});
// 全局前置守卫
router.beforeEach((to, from, next) => {
    // const isLogin = localStorage.getItem("userInfo");
    const isLogin = utils.readStorage("", "userInfo");

    if (to.matched.some(item => item.meta.isLogin)) {
        if (isLogin) {
            next();
            return;
        }
        next('/login')
    } else {
        next();
    }
});
export default router;