import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router'
import equipmentaccount from './modules/deviceacc'
import telemetrystation from './modules/station'
import dataaudit from './modules/dataaudit'
import tstkmanagement from './modules/tstkmanagement'
import dictionarymanagement from './modules/systemdictionary'
import usermanagement from './modules/usermanagement'
import customermanagement from './modules/customermanagement'
import constructionmanagement from './modules/constructionmanagement'
import downlinktask from './modules/downlinktask'
import qualitymanagement from './modules/qualitymanagement'
import workdata from './modules/workdata'
// import systemconfiguration from './modules/systemconfiguration'
import { getToken } from '../until/auth'

//下面是客户的路由(临时先这么写,后续要灵活配置)
import customerstation from './modules/customer/customerstation'
import customerwork from './modules/customer/customerwork'
import customerdata from './modules/customer/customerdata'
import customermana from './modules/customer/customermana'
import customerunit from './modules/customer/customerunit'
import customerstationmana from './modules/customer/customerstationmana'
import customerstationcount from './modules/customer/customerstationcount'
import taskreview from './modules/customer/taskreview';
import tsetup from './modules/customer/tsetup';
import alarmdata from './modules/customer/alarmdata';
import filecenter from './modules/filecenter';
import accmana from './modules/accmana'

export const Layout = () => import('../Layout/index.vue')
/**
 * hidden 是否在导航栏显示    ture 不显示
 * meta        title: 名称    icon: 图标
 */
export const routes: Array<RouteRecordRaw> = [
    {
        path: '/login',
        name: 'Login',
        hidden: true,
        component: () => import('../views/login/index.vue'),
    },
    {
		path: "/userRegister",
        name: 'UserRegister',
        hidden: true,
		component: () => import('../views/customermanagement/userRegister/index.vue'),
		meta: {
			title: "注册"
		}
	},
    {
        path: '/',
        component: Layout,
        redirect: '/station',
        children: [{
            path: '/station',
            component: () => import('../views/station/stationdata/index.vue'),
            meta: { title: '站点数据', icon: 'icon iconfont icon-shuibiao', }
        }]
    },
    // {
    //     path: '/',
    //     component: Layout,
    //     redirect: '/dashboard',
    //     children: [{
    //         path: '/dashboard',
    //         component: () => import('../views/dashboard/index.vue'),
    //         meta: { title: '工作台', icon: 'el-icon-menu', }
    //     }]
    // },
    //equipmentaccount,
    accmana,
    workdata,
    telemetrystation,
    qualitymanagement,
    dataaudit,
    tstkmanagement,
    constructionmanagement,
    downlinktask,
    dictionarymanagement,
    usermanagement,
    customermanagement,
    filecenter,
    customerdata,
    customerstation,
    customerwork,
    customermana,
    customerunit,
    customerstationmana,
    customerstationcount,
    taskreview,
    tsetup,
    alarmdata,
    
]
// 在 Vue-router新版本中，需要使用createRouter来创建路由
export const router = createRouter({
    // 指定路由的模式,此处使用的是hash模式,createWebHistory为history模式
    history: createWebHashHistory(),
    // 路由地址
    routes
})
router.beforeEach((to, from, next) => {
    const role = getToken();
    if (!role && to.path !== '/login') {
        next('/login');
    } else if (to.meta.permission) {
        // 如果是管理员权限则可进入，这里只是简单的模拟管理员权限而已
        role === 'admin'
            ? next()
            : next('/403');
    } else {
        next();
    }
});
export default router