import Vue from 'vue'
import VueRouter from 'vue-router'
// 加载条
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'

Vue.use(VueRouter);

const routes = [
    {
        path: '/',
        component: () => import( '../views/Index.vue'),
        children: [
            {
                path: '/',
                name: 'Main',
                component: () => import('@/views/Main.vue'),
                meta: {
                    title: "首页",
                    // clmid: "1",
                }
            }, {
                path: '/member',
                name: 'Member',
                component: () => import('@/views/Member.vue'),
                meta: {
                    title: "会员管理",
                    // clmid: "2",
                }
            },
            {
                path: '/tempUser',
                name: 'tempUser',
                component: () => import('@/views/tempUser.vue'),
                meta: {
                    title: "临时会员",
                    // clmid: "33",
                }
            },{
                path: '/lesson',
                name: 'Lesson',
                component: () => import('@/views/Lesson.vue'),
                meta: {
                    title: "课程模板",
                    // clmid: "3",
                }
            }, {
                path: '/lessonTable',
                name: 'lessonTable',
                component: () => import('@/views/LessonTable.vue'),
                meta: {
                    title: "课程表模板",
                    // clmid: "4",
                }
            }, {
                path: '/editLessonTable',
                name: 'EditLessonTable',
                component: () => import('@/views/EditLessonTable.vue'),
                meta: {
                    title: "编辑课程表模板",
                    // clmid: "4",
                }
            }, {
                path: '/editLessonManage',
                name: 'EditLessonManage',
                component: () => import('@/views/EditLessonManage.vue'),
                meta: {
                    title: "编辑课程表",
                    // clmid: "5",
                }
            }, {
                path: '/adminManage',
                name: 'AdminManage',
                component: () => import('@/views/AdminManage.vue'),
                meta: {
                    title: "管理员管理",
                    // clmid: "13",
                }
            }, {
                path: '/log',
                name: 'Log',
                component: () => import('@/views/Log.vue'),
                meta: {
                    title: "操作日志",
                    // clmid: "14",
                }
            }, {
                path: '/demoDevice',
                name: 'demoDevice',
                component: () => import('@/views/demoDevice.vue'),
                meta: {
                    title: "演示设备",
                    // clmid: "15",
                }
            }, {
                path: '/shopManage',
                name: 'ShopManage',
                component: () => import('@/views/ShopManage.vue'),
                meta: {
                    title: "店面管理",
                    // clmid: "12",
                }
            }, {
                path: '/adminSetting',
                name: 'AdminSetting',
                component: () => import('@/views/AdminSetting.vue'),
                meta: {
                    title: "系统设置",
                    // clmid: "22",
                }
            }, {
                path: '/lessonManage',
                name: 'lessonManage',
                component: () => import('@/views/lessonManage.vue'),
                meta: {
                    title: "课程表管理",
                    // clmid: "5",
                }
            }, {
                path: '/coach',
                name: 'coach',
                component: () => import('@/views/coach.vue'),
                meta: {
                    title: "教练管理",
                    // clmid: "6",
                }
            }, {
                path: '/appoint',
                name: 'appoint',
                component: () => import('@/views/appoint.vue'),
                meta: {
                    title: "预约管理",
                    // clmid: "7",
                }
            }, {
                path: '/record',
                name: 'record',
                component: () => import('@/views/record.vue'),
                meta: {
                    title: "预约记录",
                    // clmid: "8",
                }
            }, {
                path: '/cost',
                name: 'cost',
                component: () => import('@/views/cost.vue'),
                meta: {
                    title: "消费记录",
                    // clmid: "9",
                }
            }, {
                path: '/ratingManage',
                name: 'ratingManage',
                component: () => import('@/views/ActionGroups.vue'),
                meta: {
                    title: "动作分组",
                    // clmid: "9",
                }
            },{
                path: '/actionExercise',
                name: 'actionExercise',
                component: () => import('@/views/ActionExercise.vue'),
                meta: {
                    title: "锻炼动作",
                    // clmid: "9",
                }
            },{
                path: '/actionManage',
                name: 'actionManage',
                component: () => import('@/views/ActionManage.vue'),
                meta: {
                    title: "动作管理",
                    // clmid: "9",
                }
            },{
                path: '/actionGroupManage',
                name: 'actionGroupManage',
                component: () => import('@/views/ActionGroupManage.vue'),
                meta: {
                    title: "动作管理",
                    // clmid: "9",
                }
            },{
                path: '/bodyNode',
                name: 'bodyNode',
                component: () => import('@/views/BodyNode.vue'),
                meta: {
                    title: "身体节点",
                    // clmid: "9",
                }
            },{
                path: '/actionScore',
                name: 'actionScore',
                component: () => import('@/views/ActionScore.vue'),
                meta: {
                    title: "动作评分",
                    // clmid: "9",
                }
            },{
                path: '/scoreResult',
                name: 'scoreResult',
                component: () => import('@/views/ScoreResult.vue'),
                meta: {
                    title: "评分结果",
                    // clmid: "9",
                }
            },{
                path: '/setting',
                name: 'setting',
                component: () => import('@/views/setting.vue'),
                meta: {
                    title: "系统设置",
                    // clmid: "22",
                }
            }, {
                path: '/finish',
                name: 'finish',
                component: () => import('@/views/finish.vue'),
                meta: {
                    title: "下课管理",
                    // clmid: "10",
                }
            }, {
                path: '/finishDetail',
                name: 'finishDetail',
                component: () => import('@/views/finishDetail.vue'),
                meta: {
                    title: "下课管理",
                    // clmid: "10",
                }
            }, {
                path: '/courses',
                name: 'courses',
                component: () => import('@/views/courses.vue'),
                meta: {
                    title: "课程管理",
                    // clmid: "10",
                }
            },{
                path: '/coursesHistory',
                name: 'coursesHistory',
                component: () => import('@/views/coursesHistory.vue'),
                meta: {
                    title: "课程管理 历史记录",
                    // clmid: "10",
                }
            }, {
                path: '/classPrepare',
                name: 'classPrepare',
                component: () => import('@/views/classPrepare.vue'),
                meta: {
                    title: "准备上课",
                    // clmid: "10",
                }
            }, {
                path: '/classInfoDetail',
                name: 'classInfoDetail',
                component: () => import('@/views/classInfoDetail.vue'),
                meta: {
                    title: "课程成绩",
                    // clmid: "10",
                }
            }, {
                path: '/courseEdit',
                name: 'courseEdit',
                component: () => import('@/views/courseEdit.vue'),
                meta: {
                    title: "课程管理",
                    // clmid: "10",
                }
            }, {
                path: '/heartEquip',
                name: 'heartEquip',
                component: () => import('@/views/heartEquip.vue'),
                meta: {
                    title: "心率设备",
                    // clmid: "10",
                }
            }, {
                path: '/heartEquipPerson',
                name: 'heartEquipPerson',
                component: () => import('@/views/heartEquipPerson.vue'),
                meta: {
                    title: "私有心率设备",
                    // clmid: "10",
                }
            }, {
                path: '/heartLog',
                name: 'heartLog',
                component: () => import('@/views/heartLog.vue'),
                meta: {
                    title: "设备记录",
                    // clmid: "10",
                }
            }, {
                path: '/bindRecord',
                name: 'bindRecord',
                component: () => import('@/views/bindRecord.vue'),
                meta: {
                    title: "绑定记录",
                    // clmid: "10",
                }
            }, {
                path: '/region',
                name: 'region',
                component: () => import('@/views/region.vue'),
                meta: {
                    title: "区域管理",
                    // clmid: "10",
                }
            },{
                path: '/test',
                name: 'Test',
                component: () => import('@/views/Test.vue'),
                meta: {
                    title: "test",
                    // clmid: "10",
                }
            }, {
                path: '/regionEquip',
                name: 'regionEquip',
                component: () => import('@/views/regionEquip.vue'),
                meta: {
                    title: "区域设备",
                    // clmid: "10",
                }
            }, {
                path: '/relevancePhone',
                name: 'relevancePhone',
                component: () => import('@/views/relevancePhone.vue'),
                meta: {
                    title: "关联手机",
                    // clmid: "2",
                }
            },{
                path: '/AcrossVip',
                name: 'AcrossVip',
                component: () => import('@/views/AcrossVip.vue'),
                meta: {
                    title: "跨店会员",
                    // clmid: "11",
                }
            },{
                path: '/online',
                name: 'online',
                component: () => import('@/views/online.vue'),
                meta: {
                    title: "在线上课",
                    // clmid: "3",
                }
            },{
                path: '/versionControlMefisto',
                name: 'versionControlMefisto',
                component: () => import('@/views/versionControlMefisto.vue'),
                meta: {
                    title: "app版本控制",
                    // clmid: "999",
                }
            },{
                path: '/versionControlVideo',
                name: 'versionControlVideo',
                component: () => import('@/views/versionControlVideo.vue'),
                meta: {
                    title: "视频app版本控制",
                    // clmid: "999",
                }
            },{
                path: '/classTime',
                name: 'classTime',
                component: () => import('@/views/ClassTime.vue'),
                meta: {
                    title: "课时管理",
                    // clmid: "999",
                }
            },{
                path: '/classChange',
                name: 'classChange',
                component: () => import('@/views/classChange.vue'),
                meta: {
                    title: "课时调整",
                    // clmid: "999",
                }
            },
        ]
    }, {
        path: '/login',
        name: 'Login',
        component: () => import( '../views/Login.vue')
    }, , {
        path: '*',
        name: '404',
        component: () => import( '../views/404.vue')
    },
]

const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
    return originalPush.call(this, location).catch(err => err)
};

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

// 路由守卫
router.beforeEach((to, from, next) => {
    NProgress.start()
    const isLogin = localStorage.token ? true : false;
    if (to.path == '/login' || to.path == '/register') {//'login'和'register'相当于是路由白名单
        next();
    } else {
        //如果token存在，就正常跳转，如果不存在，则说明未登陆，则跳转到'login'
        isLogin ? next() : next("/login");
    }
});

router.afterEach(() => {
    NProgress.done()
})

export default router
