import Vue          from 'vue';
import Router       from 'vue-router';
import { getAuth }  from '@/utils/auth';
import { getGuide } from '@/utils/guide';
import {
    getTenantCode, getSystemConfig,
    getUserIcon, shitiStatusControl,
    saveHistoryPaths,
}                   from '@/utils/common';

Vue.use(Router);

const router = new Router({
                              mode:   'history',
                              base:   process.env.BASE_URL,
                              routes: [
                                  {
                                      path:     '/',
                                      redirect: '/index',
                                  },
                                  {
                                      name:      'index',
                                      path:      '/index',
                                      component: () => {
                                          return import(/* webpackChunkName: "index" */ './views/client/Index.vue');
                                      },
                                  },
                                  {
                                      name:      'Login',
                                      path:      '/login',
                                      component: () => {
                                          return import(/* webpackChunkName: "Login" */ './views/management/Login/index.vue');
                                      },
                                  },
                                  {
                                      path:'/c',
                                      component: () => import(/* webpackChunkName: "Cframe" */ './components/client/common/Cframe.vue'),
                                      children:  [
                                          {
                                              name:      '考试平台',
                                              path:      'examPlatform',
                                              meta:      {
                                                  parentPath: 'croot',
                                                  breadcrumb: {
                                                      display: '考试平台',
                                                  },
                                              },
                                              component: () => {
                                                  return import(/* webpackChunkName: "index" */ './views/client/examPlatform.vue');
                                              },
                                          },
                                          {
                                              name:      '培训平台',
                                              path:      'peixunPlatform',
                                              meta:      {
                                                  parentPath: 'croot',
                                                  breadcrumb: {
                                                      display: '培训平台',
                                                  },
                                              },
                                              component: () => {
                                                  return import(/* webpackChunkName: "index" */ './views/client/peixunPlatform.vue');
                                              },
                                          },
                                          {
                                              name:      '课程开发',
                                              path:      'courseDev',
                                              meta:      {
                                                  parentPath: 'croot',
                                                  breadcrumb: {
                                                      display: '课程列表',
                                                  },
                                              },
                                              component: () => {
                                                  return import(/* webpackChunkName: "index" */ './views/client/CourseDev.vue');
                                              },
                                          },
                                          {
                                              name:      '新闻资讯',
                                              path:      'newsInfor',
                                              meta:      {
                                                  parentPath: 'croot',
                                                  breadcrumb: {
                                                      display: '新闻资讯',
                                                  },
                                              },
                                              component: () => {
                                                  return import(/* webpackChunkName: "index" */ './views/client/newsInfor.vue');
                                              },
                                          },
                                          {
                                              name:      '帮助中心',
                                              path:      'helpCenter',
                                              meta:      {
                                                  parentPath: 'croot',
                                                  breadcrumb: {
                                                      display: '帮助中心',
                                                  },
                                              },
                                              component: () => {
                                                  return import(/* webpackChunkName: "index" */ './views/client/helpCenter.vue');
                                              },
                                          },
                                          {
                                              name:      '关于我们',
                                              path:      'aboutUs',
                                              meta:      {
                                                  parentPath: 'croot',
                                                  breadcrumb: {
                                                      display: '关于我们',
                                                  },
                                              },
                                              component: () => {
                                                  return import(/* webpackChunkName: "index" */ './views/client/aboutUs.vue');
                                              },
                                          },
                                          {
                                              path: 'newsInforDetails',
                                              name: 'newsInforDetails',
                                              meta:      {
                                                  parentPath: 'croot',
                                                  breadcrumb: {
                                                      display: '行业详情',
                                                  },
                                              },
                                              component: () => {
                                                  return import(/* webpackChunkName: "index" */ './views/client/newsInforDetails.vue');
                                              },
                                          },
                                      ],

                                  },

                                  {
                                      name:      'admin',
                                      path:      '/admin',
                                      meta: {
                                          icon: "el-icon-platform-eleme",
                                          title: "页面管理"
                                      },
                                      isAdminMenu: true,
                                      component: () => {
                                          return import(/* webpackChunkName: "Home" */ './views/management/Home/index.vue');
                                      },
                                      children:  [
                                          {
                                              path: '/news',
                                              name: 'news',
                                              meta: {
                                                  icon: "",
                                                  title: "新闻资讯"
                                              },
                                              isAdminMenu: true,
                                              component: () => {
                                                  return import(/* webpackChunkName: "HangYeZiXun" */ './views/management/HangYeZiXun/index.vue');
                                              },
                                          },
                                          {
                                              path: '/news/config',
                                              name: 'newsConfig',
                                              component: () => {
                                                  return import(/* webpackChunkName: "HangYeZiXun" */ './views/management/HangYeZiXun/HangYeZiXunConfig/index.vue');
                                              },
                                          },
                                          {
                                              path: '/blogroll',
                                              name: 'blogroll',
                                              meta: {
                                                  icon: "",
                                                  title: "友情链接"
                                              },
                                              isAdminMenu: true,
                                              component: () => {
                                                  return import(/* webpackChunkName: "HangYeZiXun" */ './views/management/YouQingLianJie/index.vue');
                                              },
                                          },
                                          {
                                              path: '/newsClassify',
                                              name: 'newsClassify',
                                              meta: {
                                                  icon: "",
                                                  title: "新闻分类"
                                              },
                                              isAdminMenu: true,
                                              component: () => {
                                                  return import(/* webpackChunkName: "HangYeZiXun" */ './views/management/XinWenFenLei/index.vue');
                                              },
                                          },
                                      ],
                                  },
                              ],
                          });

function dispatchScss(path) {
    if (!path) {
        return;
    }
    if (path.indexOf('/a/') > -1) {
        require('@/assets/css/main/main-a.scss');
    } else if (path.indexOf('/c/') > -1) {
        require('@/assets/css/main/main-c.scss');
    } else {
        require('@/assets/css/main/main-z.scss');
    }
}


router.beforeEach((to, from, next) => {
    dispatchScss(to.fullPath);
    getAuth();
    getGuide();
    // getTenantCode();
    getSystemConfig();
    if (getSystemConfig()) {
        document.title = getSystemConfig().logoText; //  describe: 更改title（刷新问题待优化） author: Wgy date:2019-12-04
    }
    //个人头像
    getUserIcon();
    shitiStatusControl(to);
    saveHistoryPaths(to, from, next);
    next();
});

export default router;
