import { createRouter, createWebHashHistory } from 'vue-router'
import { ElMessageBox, ElMessage } from 'element-plus'
import LeftLayout from "@/views/LeftLayout"
const routes = [{
        path: "/left",
        name: 'left',
        component: LeftLayout,
        children: [
            {
                meta: {
                    action: "menuList",
                    title: '权限菜单'
                },
                path: 'menuList',
                name: 'menuList',
                component: () =>
                    import ('@views/menu/index.vue')
            },
            {
                meta: {
                    action: "roleList",
                    title: '权限菜单'
                },
                path: 'roleList',
                name: 'roleList',
                component: () =>
                    import ('@views/role/index.vue')
            },
           
            {
                meta: {
                    action: "websiteList",
                    title: '站点列表'
                },
                path: 'websiteList',
                name: 'websiteList',
                component: () =>
                    import ('@views/website/index.vue')
            },
            {
                meta: {
                    action: "websiteRole",
                    title: '站点角色'
                },
                path: 'websiteRole/:Id',
                name: 'websiteRole',
                component: () =>
                    import ('@views/websiteRole/index.vue')
            },
            {
                meta: {
                    action: "websiteRoleUser",
                    title: '站点角色用户'
                },
                path: 'websiteRoleUser/:websiteId/:roleId',
                name: 'websiteRoleUser',
                component: () =>
                    import ('@views/websiteRoleUser/index.vue')
            },
            {
                meta: {
                    action: "websiteColumn",
                    title: '栏目管理'
                },
                path: 'websiteColumn',
                name: 'websiteColumn',
                component: () =>
                    import ('@views/websiteColumn/index.vue')
            },
            {
                meta: {
                    action: "memberList",
                    title: '会员列表'
                },
                path: 'memberList',
                name: 'memberList',
                component: () =>
                    import ('@views/member/index.vue')
            },
            {
                meta: {
                    action: "levelList",
                    title: '会员等级'
                },
                path: 'levelList',
                name: 'levelList',
                component: () =>
                    import ('@views/level/index.vue')
            },
            {
                meta: {
                    action: "cityList",
                    title: '会员等级'
                },
                path: 'cityList',
                name: 'cityList',
                component: () =>
                    import ('@views/city/index.vue')
            }
            ,
            {
                meta: {
                    action: "newsList",
                    title: '资讯列表'
                },
                path: 'newsList',
                name: 'newsList',
                component: () =>
                    import ('@views/news/index.vue')
            }
            ,
            {
                meta: {
                    action: "categoryList",
                    title: '栏目列表'
                },
                path: 'categoryList',
                name: 'categoryList',
                component: () =>
                    import ('@views/category/index.vue')
            } ,
            {
                meta: {
                    action: "linkList",
                    title: '友情链接'
                },
                path: 'linkList',
                name: 'linkList',
                component: () =>
                    import ('@views/link/index.vue')
            },
            {
                meta: {
                    action: "adPlaceList",
                    title: '广告位'
                },
                path: 'adPlaceList',
                name: 'adPlaceList',
                component: () =>
                    import ('@views/adPlace/index.vue')
            } ,
            {
                meta: {
                    action: "adList",
                    title: '广告'
                },
                path: 'adList/:pid?',
                name: 'adList',
                component: () =>
                    import ('@views/ad/index.vue')
            } ,
            {
                meta: {
                    action: "chat",
                    title: '聊天'
                },
                path: 'chat',
                name: 'chat',
                component: () =>
                    import ('@views/chat/index.vue')
            } ,
            {
                meta: {
                    action: "complaintList",
                    title: '投诉列表'
                },
                path: 'complaintList',
                name: 'complaintList',
                component: () =>
                    import ('@views/complaint/index.vue')
            } ,
            {
                meta: {
                    action: "complaintCategory",
                    title: '投诉分类'
                },
                path: 'complaintCategory',
                name: 'complaintCategory',
                component: () =>
                    import ('@views/complaintCategory/index.vue')
            } ,

           
        ]
    },

    //======================================
    {
        meta: {
            action: "login",
            title: '登录',
            activity: true,
            requireAuth:false
        },
        path: '/login',
        name: 'login',
        component: () =>
            import ('@views/login/index.vue'),
    
    }
]

const router = createRouter({
    history: createWebHashHistory(),
    routes
})

const getCookie = function(objName) { //获取指定名称的cookie的值
    var arrStr = document.cookie.split("; ");
    for (var i = 0; i < arrStr.length; i++) {
        var temp = arrStr[i].split("=");
        if (temp[0] == objName) return unescape(temp[1]); //解码
    }
    return "";
}
router.beforeEach((to, from) => {
       if(to.meta.requireAuth){
        if(!document.getCookie("token")){
            router.push('/login');
        }
    }
})
router.afterEach((to, from) => {
    if (to.meta && to.meta.title) {
        document.title = to.meta.title
    }
})
export default router