import Vue from 'vue'
import Router from 'vue-router'
// import store from '../store'
import auth from '../service/auth'

Vue.use(Router)

const router = new Router({
    mode: 'history', // 地址会不需要增加/#
    // mode: 'hash', // 地址会需要增加/#
    base: process.env.BASE_URL,
    routes: [
        {
            path: '/citySafeNoticBefore',
            name: 'citySafeNoticBefore',
            meta: {
                title: '城市安全通知公告'
            },
            component: () => import('@/pages/citySafeNotic/indexBefore.vue')
        },
        {
            path: '/cityDangerReportBefore',
            name: 'cityDangerReportBefore',
            meta: {
                title: '城市隐患上报前置'
            },
            component: () => import('@/pages/cityDangerReport/indexBefore.vue')
        },

        {
            path: '/citySafeNoticDetail',
            name: 'citySafeNoticDetail',
            meta: {
                title: '城市安全通知公告'
            },
            component: () => import('@/pages/citySafeNotic/detail.vue')
        },
        {
            path: '/citySafeNotic',
            name: 'citySafeNotic',
            meta: {
                title: '城市安全通知公告'
            },
            component: () => import('@/pages/citySafeNotic/index.vue')
        },

        {
            path: '/cityDangerReport',
            name: 'cityDangerReport',
            meta: {
                title: '城市隐患上报'
            },
            component: () => import('@/pages/cityDangerReport/index.vue')
        },

        {
            path: '/addcityDangerReport',
            name: 'addcityDangerReport',
            meta: {
                title: '城市隐患上报'
            },
            component: () => import('@/pages/cityDangerReport/add.vue')
        }

        // {
        //     path: '/venueRoom',
        //     name: 'venueRoom',
        //     meta: {
        //         title: '场馆列表'
        //     },
        //     component: () => import('@/pages/venue/index.vue')
        // },
    ]
})

// 无路由守卫
router.beforeEach((to, from, next) => {
//     if (to.path == "/") {
//         alert("点击确认浏览测试页面");
//         next("/login");
//     } else {
        next();
//     } // 修改显示标题
    console.log(to)
    document.title = to.matched[0].meta.title
})

// 路由守卫 拦截
const whiteList = ['citySafeNoticDetail', 'citySafeNoticBefore', 'cityDangerReportBefore', 'vistiorRegistration', 'login', 'register', 'QRcode', 'todo', 'webView', 'registerbycpyinfo', 'cityDangerReport', `addcityDangerReport`, 'citySafeNotic'] // 路由守卫白名单

// router.beforeEach((to, from, next) => {
//     /* 路由发生变化修改页面title */
//     if (to.meta.title) {
//         document.title = to.meta.title
//     }
//     if (whiteList.includes(to.name)) {
//         // 在免登录白名单，直接进入
//         next()
//     } else if (to.path == '/home/home') {
//         const uid = auth.uid()
//         if (uid) {
//             next()
//         } else {
//             next({
//                 path: '/cityDangerReportBefore',
//                 query: to.query
//             })
//         }
//     } else if (to.path !== '/citySafeNoticDetail') {
//         const uid = auth.uid()
//         if (auth.getUserType() === auth.TYPE_FRAME) {
//             if (uid) {
//                 if (to.path === '/') {
//                     next({
//                         path: '/home/home'
//                     })
//                 }
//                 next()
//             } else if (to.path === '/register') {
//                 next()
//             } else {
//                 next({
//                     path: '/citySafeNoticDetail'
//                 })
//             }
//         } else {
//             next({
//                 path: '/citySafeNoticDetail'
//             })
//         }
//     } else {
//         next()
//     }
// })

export default router
