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

Vue.use(VueRouter);

//控制的是content中tab页的标题
const routes = [
    {
        path: '/',
        component: () => import( '../views/Index/Index'),
        children: [
            {
                path: '/',
                name: 'Main',
                component: () => import('@/views/Index/Main.vue'),
                meta: {
                    title: "系统首页",
                    // clmid: "1",
                }
            },
            //会员管理相关页面
            {
                path: '/memberFull',
                name: 'memberFull',
                component: () => import('@/views/Member/MemberFull.vue'),
                meta: {
                    title: "正式会员",
                }
            }, {
                path: '/relevancePhone',
                name: 'relevancePhone',
                component: () => import('@/views/Member/RelevancePhone.vue'),
                meta: {
                    title: "关联手机",
                }
            }, {
                path: '/memberTemporary',
                name: 'memberTemporary',
                component: () => import('@/views/Member/MemberTemporary.vue'),
                meta: {
                    title: "临时会员",
                }
            }, {
                path: '/memberCost',
                name: 'memberCost',
                component: () => import('@/views/Member/MemberCost.vue'),
                meta: {
                    title: "会员消费",
                }
            },
            //课程管理相关页面
            {
                path: '/lessonManage',
                name: 'lessonManage',
                component: () => import('@/views/Class/LessonManage.vue'),
                meta: {
                    title: "课目管理",
                }
            }, {
                path: '/lessonTableTemplate',
                name: 'lessonTableTemplate',
                component: () => import('@/views/Class/LessonTableTemplate.vue'),
                meta: {
                    title: "课程表模板",
                }
            }, {
                path: '/lessonTableTemplateEdit',
                name: 'lessonTableTemplateEdit',
                component: () => import('@/views/Class/LessonTableTemplateEdit.vue'),
                meta: {
                    title: "编辑课程表模板",
                }
            }, {
                path: '/lessonTableManage',
                name: 'lessonTableManage',
                component: () => import('@/views/Class/LessonTableManage.vue'),
                meta: {
                    title: "课程表管理",
                }
            }, {
                path: '/lessonTableManageEdit',
                name: 'lessonTableManageEdit',
                component: () => import('@/views/Class/LessonTableManageEdit.vue'),
                meta: {
                    title: "课程表编辑",
                }
            }, {
                path: '/classManage',
                name: 'classManage',
                component: () => import('@/views/Class/ClassManage.vue'),
                meta: {
                    title: "上课管理",
                }
            }, {
                path: '/classEdit',
                name: 'classEdit',
                component: () => import('@/views/Class/ClassEdit.vue'),
                meta: {
                    title: "课程管理",
                }
            }, {
                path: '/classHistory',
                name: 'classHistory',
                component: () => import('@/views/Class/ClassHistory.vue'),
                meta: {
                    title: "历史记录",
                }
            }, {
                path: '/classInfoDetail',
                name: 'classInfoDetail',
                component: () => import('@/views/Class/ClassInfoDetail.vue'),
                meta: {
                    title: "课程成绩",
                }
            }, {
                path: '/classFinishManage',
                name: 'classFinishManage',
                component: () => import('@/views/Class/ClassFinishManage.vue'),
                meta: {
                    title: "下课管理",
                }
            }, {
                path: '/classFinishDetail',
                name: 'classFinishDetail',
                component: () => import('@/views/Class/ClassFinishDetail.vue'),
                meta: {
                    title: "下课详情",
                }
            }, {
                path: '/online',
                name: 'online',
                component: () => import('@/views/Class/ClassOnLine.vue'),
                meta: {
                    title: "在线上课",
                }
            }, {
                path: '/videoClass',
                name: 'videoClass',
                component: () => import('@/views/Class/VideoClass.vue'),
                meta: {
                    title: "视频上课",
                }
            },
            //预约管理相关页面
            {
                path: '/appointManage',
                name: 'appointManage',
                component: () => import('@/views/Appointment/AppointManage.vue'),
                meta: {
                    title: "预约管理",
                }
            }, {
                path: '/appointRecord',
                name: 'appointRecord',
                component: () => import('@/views/Appointment/AppointRecord.vue'),
                meta: {
                    title: "预约记录",
                }
            },
            //运动评估相关页面
            // {
            //     path: '/movementManage',
            //     name: 'movementManage',
            //     component: () => import('@/views/assessment/movementManage.vue'),
            //     meta: {
            //         title: "动作管理",
            //     }
            // }, {
            //     path: '/nodeMange',
            //     name: 'nodeMange',
            //     component: () => import('@/views/assessment/nodeMange.vue'),
            //     meta: {
            //         title: "节点管理",
            //     }
            // }, {
            //     path: '/actionNode',
            //     name: 'actionNode',
            //     component: () => import('@/views/assessment/actionNode.vue'),
            //     meta: {
            //         title: "动作节点",
            //     }
            // }, {
            //     path: '/actionKeyFrame',
            //     name: 'actionKeyFrame',
            //     component: () => import('@/views/assessment/actionKeyFrame.vue'),
            //     meta: {
            //         title: "动作关键帧",
            //     }
            // }, {
            //     path: '/lessonAction',
            //     name: 'lessonAction',
            //     component: () => import('@/views/assessment/lessonAction.vue'),
            //     meta: {
            //         title: "课程动作",
            //     }
            // },{
            //     path: '/movementScore',
            //     name: 'movementScore',
            //     component: () => import('@/views/assessment/movementScore.vue'),
            //     meta: {
            //         title: "动作评分",
            //     }
            // },
            //心率管理相关页面
            {
                path: '/hrSensor',
                name: 'hrSensor',
                component: () => import('@/views/HrSensor/HrSensor.vue'),
                meta: {
                    title: "心率设备",
                }
            }, {
                path: '/hrSensorPrivate',
                name: 'hrSensorPrivate',
                component: () => import('@/views/HrSensor/HrSensorPrivate.vue'),
                meta: {
                    title: "私有心率设备",
                }
            // }, {
            //     path: '/hrSensorLog',
            //     name: 'hrSensorLog',
            //     component: () => import('@/views/HrSensor/HrSensorLog.vue'),
            //     meta: {
            //         title: "心率记录",
            //     }
            }, {
                path: '/bindRecord',
                name: 'bindRecord',
                component: () => import('@/views/HrSensor/BindRecord.vue'),
                meta: {
                    title: "绑定记录",
                }
            }, {
                path: '/demoDevice',
                name: 'demoDevice',
                component: () => import('@/views/HrSensor/DemoDevice.vue'),
                meta: {
                    title: "演示设备",
                }
            },
            //报表统计相关页面
            {
                path: '/classHourStatistics',
                name: 'classHourStatistics',
                component: () => import('@/views/Report/ClassHourStatistics.vue'),
                meta: {
                    title: "课时统计",
                }
            },
            // {
            //     path: '/memberStatistics',
            //     name: 'memberStatistics',
            //     component: () => import('@/views/Report/memberStatistics.vue'),
            //     meta: {
            //         title: "会员统计",
            //     }
            // },{
            //     path: '/appointStatistics',
            //     name: 'appointStatistics',
            //     component: () => import('@/views/Report/appointStatistics.vue'),
            //     meta: {
            //         title: "预约统计",
            //     }
            // },
            {
                path: '/coachHourStatistics',
                name: 'coachHourStatistics',
                component: () => import('@/views/Report/CoachHourStatistics.vue'),
                meta: {
                    title: "教练课时统计",
                }
            },

            //系统管理相关页面
            {
                path: '/operateLog',
                name: 'operateLog',
                component: () => import('@/views/SystemManage/OperateLog.vue'),
                meta: {
                    title: "操作日志",
                }
            },
            {
                path: '/shopSetting',
                name: 'shopSetting',
                component: () => import('@/views/SystemManage/ShopSetting.vue'),
                meta: {
                    title: "商家设置",
                }
            },
            // {
            //     path: '/accountManage',
            //     name: 'accountManage',
            //     component: () => import('@/views/SystemManage/accountManage.vue'),
            //     meta: {
            //         title: "账号管理",
            //     }
            // },
            {
                path: '/shopRegion',
                name: 'shopRegion',
                component: () => import('@/views/SystemManage/ShopRegion.vue'),
                meta: {
                    title: "商家区域",
                }
            },
            {
                path: '/shopDevice',
                name: 'shopDevice',
                component: () => import('@/views/SystemManage/ShopDevice.vue'),
                meta: {
                    title: "商家设备",
                }
            },

            //总店相关页面
            {
                path: '/adminShopSetting',
                name: 'adminShopSetting',
                component: () => import('@/views/AdminManage/AdminShopSetting.vue'),
                meta: {
                    title: "商家设置",
                }
            },
            {
                path: '/adminUserManage',
                name: 'adminUserManage',
                component: () => import('@/views/AdminManage/AdminUserManage.vue'),
                meta: {
                    title: "管理员管理",
                }
            }, {
                path: '/memberCross',
                name: 'memberCross',
                component: () => import('@/views/AdminManage/MemberCross.vue'),
                meta: {
                    title: "跨店会员",
                }
            },
            // {
            //     path: '/adminShopArea',
            //     name: 'adminShopArea',
            //     component: () => import('@/views/AdminManage/adminShopArea.vue'),
            //     meta: {
            //         title: "商家区域",
            //     }
            // },{
            //     path: '/groupManage',
            //     name: 'groupManage',
            //     component: () => import('@/views/AdminManage/groupManage.vue'),
            //     meta: {
            //         title: "分组管理",
            //     }
            // },
            {
                path: '/coachManage',
                name: 'coachManage',
                component: () => import('@/views/SystemManage/CoachManage.vue'),
                meta: {
                    title: "教练管理",
                }
            }, {
                path: '/versionControlMefisto',
                name: 'versionControlMefisto',
                component: () => import('@/views/Other/versionControlMefisto.vue'),
                meta: {
                    title: "app版本控制",
                }
            }, {
                path: '/versionControlVideo',
                name: 'versionControlVideo',
                component: () => import('@/views/Other/versionControlVideo.vue'),
                meta: {
                    title: "视频app版本控制",
                }
            }, {
                path: '/test',
                name: 'Test',
                component: () => import('@/views/Other/Test.vue'),
                meta: {
                    title: "test",
                }
            }
        ]
    }, {
        path: '/login',
        name: 'Login',
        component: () => import( '../views/Auth/Login.vue')
    }, , {
        path: '*',
        name: '404',
        component: () => import( '../views/Auth/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
