index.1.js 19.7 KB
import Vue from 'vue'
import Router from 'vue-router'
import * as Cookies from 'js-cookie'
Vue.use(Router)

const router = new Router({
        // mode: 'history',
        routes: [{
                path: '/home',
                // component: home,
                component: resolve => require(['@/views/home'], resolve),
                redirect: '/account',
                children: [{
                    path: '/account',
                    // name: 'account',
                    // component: Account,
                    component: resolve => require(['@/views/account/acc'], resolve),
                    children: [{
                        path: '/',
                        name: 'acc_daily',
                        // component: accountDaily
                        component: resolve => require(['@/views/account/daily'], resolve)
                    }, {
                        path: '/account/weekly',
                        name: 'acc_weekly',
                        // component: accountWeekly
                        component: resolve => require(['@/views/account/weekly'], resolve),
                    }, {
                        path: '/account/monthly',
                        name: 'acc_monthly',
                        // component: accountMonthly
                        component: resolve => require(['@/views/account/Monthly'], resolve),
                    }, {
                        path: '/account/yearly',
                        name: 'acc_yearly',
                        // component: accountYearly
                        component: resolve => require(['@/views/account/yearly'], resolve),
                    }]
                }, {
                    path: '/mall',
                    // name: 'mall',
                    component: resolve => require(['@/views/Mall/mall'], resolve),
                    children: [{
                        path: '/',
                        name: 'mall_daily',
                        // component: mallDaily
                        component: resolve => require(['@/views/Mall/daily'], resolve),
                    }, {
                        path: '/mall/weekly',
                        name: 'mall_weekly',
                        // component: mallWeekly
                        component: resolve => require(['@/views/Mall/weekly'], resolve),
                    }, {
                        path: '/mall/monthly',
                        name: 'mall_monthly',
                        component: resolve => require(['@/views/Mall/Monthly'], resolve),
                        // component: mallMonthly
                    }, {
                        path: '/mall/yearly',
                        name: 'mall_yearly',
                        // component: mallYearly
                        component: resolve => require(['@/views/Mall/yearly'], resolve),
                    }]
                }, {
                    path: '/floor',
                    // name: 'floor',
                    // component: Floor,
                    component: resolve => require(['@/views/Floor/floor'], resolve),
                    children: [{
                        path: '/',
                        name: 'floor_daily',
                        component: resolve => require(['@/views/Floor/daily'], resolve),
                        // component: floorDaily
                    }, {
                        path: '/floor/weekly',
                        name: 'floor_weekly',
                        component: resolve => require(['@/views/Floor/weekly'], resolve),
                        // component: floorWeekly
                    }, {
                        path: '/floor/monthly',
                        name: 'floor_monthly',
                        component: resolve => require(['@/views/Floor/Monthly'], resolve),
                        // component: floorMonthly
                    }, {
                        path: '/floor/yearly',
                        name: 'floor_yearly',
                        component: resolve => require(['@/views/Floor/yearly'], resolve),
                        // component: floorYearly
                    }]
                }, {
                    path: '/shop',
                    // name: 'shop',
                    component: resolve => require(['@/views/Shop/shop'], resolve),
                    // component: Shop,
                    children: [{
                        path: '/',
                        name: 'shop_daily',
                        component: resolve => require(['@/views/Shop/daily'], resolve),
                        // component: shopDaily
                    }, {
                        path: '/shop/weekly',
                        name: 'shop_weekly',
                        component: resolve => require(['@/views/Shop/weekly'], resolve),
                        // component: shopWeekly
                    }, {
                        path: '/shop/monthly',
                        name: 'shop_monthly',
                        component: resolve => require(['@/views/Shop/Monthly'], resolve),
                        // component: shopMonthly
                    }, {
                        path: '/shop/yearly',
                        name: 'shop_yearly',
                        component: resolve => require(['@/views/Shop/yearly'], resolve),
                        // component: shopYearly
                    }]
                }, {
                    path: '/analysis',
                    component: resolve => require(['@/views/Analysis/analysis'], resolve),
                    // component: Analysis,
                    children: [{
                            path: '/analysis/seqasis',
                            // name: 'seq_analysis',
                            component: resolve => require(['@/views/Analysis/SeqAnalysis/seqanalysis'], resolve),
                            // component: seqAnalysis,
                            children: [{
                                path: 'daily',
                                name: 'seq_daily',
                                component: resolve => require(['@/views/Analysis/SeqAnalysis/daily'], resolve),
                                // component: seqDaily
                            }, {
                                path: 'weekly',
                                name: 'seq_weekly',
                                component: resolve => require(['@/views/Analysis/SeqAnalysis/weekly'], resolve),
                                // component: seqWeekly
                            }, {
                                path: 'monthly',
                                name: 'seq_monthly',
                                component: resolve => require(['@/views/Analysis/SeqAnalysis/monthly'], resolve),
                                // component: seqMonthly
                            }, {
                                path: 'yearly',
                                name: 'seq_yearly',
                                component: resolve => require(['@/views/Analysis/SeqAnalysis/yearly'], resolve),
                                // component: seqYearly
                            }]
                        }, {
                            path: '/analysis/timeheat',
                            component: resolve => require(['@/views/Analysis/TimeHeat/timeheat'], resolve),
                            // component: timeHeat,
                            children: [{
                                path: 'weekly',
                                name: 'timeheat_weekly',
                                component: resolve => require(['@/views/Analysis/TimeHeat/weekly'], resolve),
                                // component: timeheatWeekly
                            }, {
                                path: 'monthly',
                                name: 'timeheat_monthly',
                                component: resolve => require(['@/views/Analysis/TimeHeat/monthly'], resolve),
                                // component: timeheatMonthly
                            }, {
                                path: 'yearly',
                                name: 'timeheat_yearly',
                                component: resolve => require(['@/views/Analysis/TimeHeat/yearly'], resolve),
                                // component: timeheatYearly
                            }, {
                                path: 'customly',
                                name: 'timeheat_customly',
                                component: resolve => require(['@/views/Analysis/TimeHeat/customly'], resolve),
                                // component: timeheatCustomly
                            }]
                        }, {
                            path: '/analysis/weatherasis',
                            component: resolve => require(['@/views/Analysis/WeatherAsis/weatherasis'], resolve),
                            // component: weatherAsis,
                            children: [{
                                path: 'monthly',
                                name: 'weather_monthly',
                                component: resolve => require(['@/views/Analysis/WeatherAsis/monthly'], resolve),
                                // component: weaMonthly
                            }, {
                                path: 'yearly',
                                name: 'weather_yearly',
                                component: resolve => require(['@/views/Analysis/WeatherAsis/yearly'], resolve),
                                // component: weaYearly
                            }]
                        },
                        //  {
                        //     path: '/analysis/holidayAsis',
                        //     component: resolve => require(['@/views/account/acc'], resolve),
                        //     // component: weatherAsis,
                        //     children: [{
                        //         path: 'monthly',
                        //         name: 'holiday_monthly',
                        //         component: resolve => require(['@/views/account/acc'], resolve),
                        //         // component: holiMonthly
                        //     }, {
                        //         path: 'yearly',
                        //         name: 'holiday_yearly',
                        //         component: resolve => require(['@/views/account/acc'], resolve),
                        //         // component: holiYearly
                        //     }]
                        // }, 
                        {
                            path: '/analysis/comprehen',
                            component: resolve => require(['@/views/Analysis/Comprehen/comprehen'], resolve),
                            // component: comprehen,
                            children: [{
                                path: 'daily',
                                name: 'comprehen_daily',
                                component: resolve => require(['@/views/Analysis/Comprehen/daily'], resolve),
                                // component: comprehenDaily
                            }, {
                                path: 'weekly',
                                name: 'comprehen_weekly',
                                component: resolve => require(['@/views/Analysis/Comprehen/weekly'], resolve),
                                // component: comprehenWeekly
                            }, {
                                path: 'monthly',
                                name: 'comprehen_monthly',
                                component: resolve => require(['@/views/Analysis/Comprehen/monthly'], resolve),
                                // component: comprehenMonthly
                            }, {
                                path: 'yearly',
                                name: 'comprehen_yearly',
                                component: resolve => require(['@/views/Analysis/Comprehen/yearly'], resolve),
                                // component: comprehenYearly
                            }, {
                                path: 'customly',
                                name: 'comprehen_custom',
                                component: resolve => require(['@/views/Analysis/Comprehen/customly'], resolve),
                                // component: comprehenCustom
                            }]
                        }, {
                            path: '/analysis/comtasis',
                            component: resolve => require(['@/views/Analysis/CompareTime/compareTime'], resolve),
                            // component: comtasis,
                            children: [{
                                path: 'contrast',
                                name: 'comt_contrast',
                                component: resolve => require(['@/views/Analysis/CompareTime/comtContrast'], resolve),
                                // component: comtContrast
                            }]
                        }, {
                            path: '/analysis/weekComp',
                            component: resolve => require(['@/views/Analysis/WeekComp/weekcomp'], resolve),
                            // component: WeekComp,
                            children: [{
                                path: 'wecomp',
                                name: 'We_Comp',
                                component: resolve => require(['@/views/Analysis/WeekComp/wecomp'], resolve),
                                // component: WeComp
                            }]
                        }, {
                            path: '/analysis/baseasis',
                            component: resolve => require(['@/views/Analysis/BasicAsis/baseAsis'], resolve),
                            // component: BaseAsis,
                            children: [{
                                path: 'daily',
                                name: 'base_daily',
                                component: resolve => require(['@/views/Analysis/BasicAsis/daily'], resolve),
                                // component: baseDaily
                            }, {
                                path: 'weekly',
                                name: 'base_weekly',
                                component: resolve => require(['@/views/Analysis/BasicAsis/weekly'], resolve),
                                // component: baseWeekly
                            }, {
                                path: 'monthly',
                                name: 'base_monthly',
                                component: resolve => require(['@/views/Analysis/BasicAsis/monthly'], resolve),
                                // component: baseMonthly
                            }, {
                                path: 'yearly',
                                name: 'base_yearly',
                                component: resolve => require(['@/views/Analysis/BasicAsis/yearly'], resolve),
                                // component: baseYearly
                            }, {
                                path: 'customly',
                                name: 'base_custom',
                                component: resolve => require(['@/views/Analysis/BasicAsis/customly'], resolve),
                                // component: baseCustom
                            }]
                        }
                        // , {
                        //     path: '/analysis/addheatmap',
                        //     component: AddHeatmap
                        // }
                    ]
                }, {
                    path: '/behavior',
                    component: resolve => require(['@/views/Behavior'], resolve),
                    // component: Behavior,
                }, {
                    path: '/manage',
                    component: resolve => require(['@/views/Management/manage'], resolve),
                    // component: Management,
                    children: [{
                        path: 'usermanage',
                        name: 'user_manage',
                        component: resolve => require(['@/views/Management/UserManage/userManage'], resolve),
                        // component: UserManage
                    }, {
                        path: 'blocmanage',
                        name: 'bloc_manage',
                        component: resolve => require(['@/views/Management/BlocManage/blocManage'], resolve),
                        // component: BlocManage
                    }, {
                        path: 'devicestatus',
                        name: 'device_status',
                        component: resolve => require(['@/views/Management/DeviceStatus/deviceStatus'], resolve),
                        // component: DeviceStatus
                    }, {
                        path: 'floormanage',
                        name: 'floor_manage',
                        component: resolve => require(['@/views/Management/FloorManage/floorManage'], resolve),
                        // component: FloorManage
                    }, {
                        path: 'gatebind',
                        name: 'gate_bind',
                        component: resolve => require(['@/views/Management/GateBind/gateBind'], resolve),
                        // component: GateBind
                    }, {
                        path: 'gatemanage',
                        name: 'gate_manage',
                        component: resolve => require(['@/views/Management/GateManage/gateManage'], resolve),
                        // component: GateManage
                    }, {
                        path: 'groupmanage',
                        name: 'group_manage',
                        component: resolve => require(['@/views/Management/GroupManage/groupManage'], resolve),
                        // component: GroupManage
                    }, {
                        path: 'mallmanage',
                        name: 'mall_manage',
                        component: resolve => require(['@/views/Management/MallManage/mallManage'], resolve),
                        // component: MallManage
                    }, {
                        path: 'zoneManage',
                        name: 'zone_manage',
                        component: resolve => require(['@/views/Management/ZoneManage/zoneManage'], resolve),
                        // component: ZoneManage
                    }]
                }]
            }, {
                path: '/',
                name: 'login',
                component: resolve => require(['@/views/login/login'], resolve),
                // component: Login,
                children: []
            }]
            // , {
            //     path: '/',
            //     name: 'login',
            //     component: Login,
            //     children: []
            // }

    })
    // 全局路由守卫
router.beforeEach((to, from, next) => {
    // console.log('router before:', to.path, to, from, Cookies.get())
    if (to.path === '/') {
        next();
    } else {
        if (Cookies.get('atoken')) {
            next();
        } else {
            router.push('/');
        }
    }
    console.log('navigation-guards');
    // to: Route: 即将要进入的目标 路由对象
    // from: Route: 当前导航正要离开的路由
    // next: Function: 一定要调用该方法来 resolve 这个钩子。执行效果依赖 next 方法的调用参数。
    // const nextRoute = ['home', 'account', 'analysis', 'behavior', 'manage'];
    // let isLogin = global.isLogin; // 是否登录
    // 未登录状态;当路由到nextRoute指定页时,跳转至login
    // console.log('beforeRoute:', to, to.path, nextRoute.indexOf(to.path), isLogin);
    // if (nextRoute.indexOf(to.path) >= 0) {
    //     if (!isLogin) {
    //         console.log('what fuck');
    //         router.push({ name: 'login' })
    //     }
    // }
    // 已登录状态;当路由到login时,跳转至home 
    // if (to.name === 'login') {
    //     if (isLogin) {
    //         router.push({ name: 'home' });
    //     }
    // }
});

export default router;