/**
 * @author CaoJin
 * @date 2021/9/12
 * @Description: 权限管理store
 */
import { asyncRoutes } from '@/router/index'
import { setMenus, setDictype, setSysConfig } from '@/utils/auth'
import { menulist, dictypeData, getSysConfig } from '@/api/user'
import Layout from '@/layout'

/**
 * 根据权限过滤路由
 * @param asyncRoutes
 * @param roles
 */
export function filterAsyncRoutes(asyncRoutes, roles) {
    const filterFn = (routes) => {
        const filterRoutes = []
        routes.forEach(route => {
            let children = []
            if (route.children) {
                children = filterFn(route.children)
            }
            if (!route.meta || !route.meta.role || roles.includes(route.meta.role)) {
                if (route.children) {
                    if (children.length > 0) {
                        filterRoutes.push({
                            ...route,
                            children
                        })
                    }
                } else {
                    filterRoutes.push(route)
                }
            }
        })
        return filterRoutes
    }
    return filterFn(asyncRoutes)
}

/**
 * 根据路由配置项生成菜单项
 * @param routes
 */
export function getMenusByRoutes() {
}

/**
 * 改造路由
 * 如果当前路由未配置component属性，且存在children属性，
 * 则将children放到到其父级
 * 用于多级路由配置
 * @param routes
 */
function remakeRoute(routes) {
    const rtnRoutes = [...routes]
    rtnRoutes.forEach((route, index) => {
        if (route.children) {
            rtnRoutes[index] = { ...route }
            rtnRoutes[index].children = remakeRoute(rtnRoutes[index].children)
        }
        if (!route.component && route.children) {
            rtnRoutes.splice(index + 1, 0, ...route.children.map(item => ({
                ...item,
                path: item.path.indexOf('/') !== 0 ? route.path + '/' + item.path : item.path
            })))
            rtnRoutes[index].children = null
        }
    })
    return rtnRoutes
}

const state = {
    routes: [],
    menus: [],
    roles: []
}
const mutations = {
    SET_ROUTES: (state, routes) => {
        state.routes = routes
    },
    SET_MENUS: (state, menus) => {
        state.menus = menus
    },
    SET_ROLES: (state, roles) => {
        state.roles = roles
    }
}
const actions = {
    async generateRoutes({ commit, dispatch/*, rootGetters */ }) {
        const roles = ['admin']
        commit('SET_ROLES', roles)
        let accessedRoutes = filterAsyncRoutes(asyncRoutes, roles)
        if (process.env.NODE_ENV === 'development') {
            accessedRoutes = asyncRoutes
        }
        if (accessedRoutes.length === 0) { // 没有任何菜单的权限
            return Promise.reject({ errCode: 403 })
        }

        return new Promise(resolve => {
            // var response ={
            //   "code": "A0000",
            //   "message": "路由菜单,成功",
            //   "data": [{
            //     "functionIndex": "e25a6dcf209e4ddc9212060eec832678",
            //     "parentNode": "0",
            //     "routeName": "home",
            //     "routePath": "/home",
            //     "title": "驾驶舱",
            //     "icon": "dashboard",
            //     "sort": 0,
            //     "children": [{
            //       "functionIndex": "8c0f6eb38df3441db33683ee830a436c",
            //       "parentNode": "e25a6dcf209e4ddc9212060eec832678",
            //       "routeName": "index",
            //       "routePath": "/dashboard/index",
            //       "title": "默认首页",
            //       "icon": "tree",
            //       "sort": 0,
            //       "children": null
            //     }, {
            //       "functionIndex": "cf17caf18fa64acf91774de4fa0e8bd5",
            //       "parentNode": "e25a6dcf209e4ddc9212060eec832678",
            //       "routeName": "home2",
            //       "routePath": "/home/screen1/home2",
            //       "title": "省级系统",
            //       "icon": "tree",
            //       "sort": 1,
            //       "children": null
            //     }, {
            //       "functionIndex": "99e267680e9245d5ae45fd5f2d656f67",
            //       "parentNode": "e25a6dcf209e4ddc9212060eec832678",
            //       "routeName": "home1",
            //       "routePath": "/home/buju5/home1",
            //       "title": "丰田研发中心",
            //       "icon": "tree",
            //       "sort": 2,
            //       "children": null
            //     }, {
            //       "functionIndex": "9509b188182e4f45afe9ef0ec9d52f6b",
            //       "parentNode": "e25a6dcf209e4ddc9212060eec832678",
            //       "routeName": "home1",
            //       "routePath": "/home/screen2/home1",
            //       "title": "长水机场",
            //       "icon": "tree",
            //       "sort": 3,
            //       "children": null
            //     }, {
            //       "functionIndex": "57b3e004bc4a4db1ab9ce270bced4bd1",
            //       "parentNode": "e25a6dcf209e4ddc9212060eec832678",
            //       "routeName": "home3",
            //       "routePath": "/home/screen1/home3",
            //       "title": "运采系统",
            //       "icon": "tree",
            //       "sort": 4,
            //       "children": null
            //     }, {
            //       "functionIndex": "7f171205dec54229b24c4d39792e1f14",
            //       "parentNode": "e25a6dcf209e4ddc9212060eec832678",
            //       "routeName": "home1",
            //       "routePath": "/home/screen1/home1",
            //       "title": "灿能数据中心",
            //       "icon": "tree",
            //       "sort": 5,
            //       "children": null
            //     }]
            //   }, {
            //     "functionIndex": "669a98c0651a48dab7dc89b7b7a07dae",
            //     "parentNode": "0",
            //     "routeName": "/harmonic-boot",
            //     "routePath": "/harmonic-boot",
            //     "title": "谐波监测系统",
            //     "icon": "客流趋势",
            //     "sort": 1,
            //     "children": [{
            //       "functionIndex": "267fc6ea3282450bb7e1344495640c8b",
            //       "parentNode": "669a98c0651a48dab7dc89b7b7a07dae",
            //       "routeName": "/harmonic-boot/monitor",
            //       "routePath": "/harmonic-boot/monitor",
            //       "title": "监测点",
            //       "icon": "监测点管理",
            //       "sort": 1,
            //       "children": [{
            //         "functionIndex": "58077cd372944cba8a5c485aa036ef96",
            //         "parentNode": "267fc6ea3282450bb7e1344495640c8b",
            //         "routeName": "/harmonic-boot/monitor/online",
            //         "routePath": "/harmonic-boot/monitor/online",
            //         "title": "在线监测点",
            //         "icon": "监测点对比分析",
            //         "sort": 1,
            //         "children": []
            //       }, {
            //         "functionIndex": "27dfa39713154a66865083fb81f75ed2",
            //         "parentNode": "267fc6ea3282450bb7e1344495640c8b",
            //         "routeName": "/harmonic-boot/monitor/offline",
            //         "routePath": "/harmonic-boot/monitor/offline",
            //         "title": "离线监测点",
            //         "icon": "网吧离线",
            //         "sort": 2,
            //         "children": []
            //       }]
            //     }, {
            //       "functionIndex": "21dbd156ca164715a661499c24085458",
            //       "parentNode": "669a98c0651a48dab7dc89b7b7a07dae",
            //       "routeName": "/harmonic-boot/area",
            //       "routePath": "/harmonic-boot/area",
            //       "title": "区域",
            //       "icon": "区域 (1)",
            //       "sort": 2,
            //       "children": [{
            //         "functionIndex": "7902e0a4d4d941c48fe34fca22e93768",
            //         "parentNode": "21dbd156ca164715a661499c24085458",
            //         "routeName": "/harmonic-boot/area/powerAssessment",
            //         "routePath": "/harmonic-boot/area/powerAssessment",
            //         "title": "电能质量评估",
            //         "icon": "form",
            //         "sort": 1,
            //         "children": []
            //       }, {
            //         "functionIndex": "866c3d8be92845c983cad22b982f7f2b",
            //         "parentNode": "21dbd156ca164715a661499c24085458",
            //         "routeName": "/harmonic-boot/area/qualifiedRate",
            //         "routePath": "/harmonic-boot/area/qualifiedRate",
            //         "title": "稳态合格率统计",
            //         "icon": "excel",
            //         "sort": 2,
            //         "children": []
            //       }, {
            //         "functionIndex": "cdf7e69733f84cfdbe34eeee5b6449e3",
            //         "parentNode": "21dbd156ca164715a661499c24085458",
            //         "routeName": "/harmonic-boot/area/integralityTable",
            //         "routePath": "/harmonic-boot/area/integralityTable",
            //         "title": "数据完整性统计",
            //         "icon": "监测点对比分析",
            //         "sort": 3,
            //         "children": []
            //       }, {
            //         "functionIndex": "de821290d3ec4c69b356d5f2505257cf",
            //         "parentNode": "21dbd156ca164715a661499c24085458",
            //         "routeName": "/harmonic-boot/area/harmonicDistortionRate",
            //         "routePath": "/harmonic-boot/area/harmonicDistortionRate",
            //         "title": "谐波畸变率统计",
            //         "icon": "guide",
            //         "sort": 4,
            //         "children": []
            //       }, {
            //         "functionIndex": "7b19e22ed90b41bfa45d0a11f9016633",
            //         "parentNode": "21dbd156ca164715a661499c24085458",
            //         "routeName": "/harmonic-boot/area/SteadyState",
            //         "routePath": "/harmonic-boot/area/SteadyState",
            //         "title": "稳态超标占比",
            //         "icon": "eye-open",
            //         "sort": 5,
            //         "children": []
            //       }, {
            //         "functionIndex": "efbb1c49ed69444fa1ab888bdc8fa069",
            //         "parentNode": "21dbd156ca164715a661499c24085458",
            //         "routeName": "/harmonic-boot/area/TerminalOnlineRate",
            //         "routePath": "/harmonic-boot/area/TerminalOnlineRate",
            //         "title": "终端状态统计",
            //         "icon": "inputGroup",
            //         "sort": 6,
            //         "children": []
            //       }, {
            //         "functionIndex": "8f64c6481c9b4bc6a89d082e64465457",
            //         "parentNode": "21dbd156ca164715a661499c24085458",
            //         "routeName": "/harmonic-boot/area/OnlineRate",
            //         "routePath": "/harmonic-boot/area/OnlineRate",
            //         "title": "终端在线率",
            //         "icon": "logo",
            //         "sort": 7,
            //         "children": []
            //       }, {
            //         "functionIndex": "17a3def7325a4abf90c1816fd579275a",
            //         "parentNode": "21dbd156ca164715a661499c24085458",
            //         "routeName": "/harmonic-boot/area/TransientEventList",
            //         "routePath": "/harmonic-boot/area/TransientEventList",
            //         "title": "暂态事件列表",
            //         "icon": "link",
            //         "sort": 8,
            //         "children": []
            //       }]
            //     }, {
            //       "functionIndex": "71419d426a8f44008ecbac71f5c2485f",
            //       "parentNode": "669a98c0651a48dab7dc89b7b7a07dae",
            //       "routeName": "/harmonic-boot/detailedAnalysis",
            //       "routePath": "/harmonic-boot/detailedAnalysis",
            //       "title": "详细分析",
            //       "icon": "logo",
            //       "sort": 3,
            //       "children": [{
            //         "functionIndex": "92dee0947b8a425a9f0a9933722196b0",
            //         "parentNode": "71419d426a8f44008ecbac71f5c2485f",
            //         "routeName": "/harmonic-boot/detailedAnalysis/contrast",
            //         "routePath": "/harmonic-boot/detailedAnalysis/contrast",
            //         "title": "区域稳态超标统计",
            //         "icon": "excel",
            //         "sort": 1,
            //         "children": []
            //       }, {
            //         "functionIndex": "9c9ad9752c0949c69ad667a9b6f2ff01",
            //         "parentNode": "71419d426a8f44008ecbac71f5c2485f",
            //         "routeName": "/harmonic-boot/detailedAnalysis/station",
            //         "routePath": "/harmonic-boot/detailedAnalysis/station",
            //         "title": "告警电站统计",
            //         "icon": "link",
            //         "sort": 2,
            //         "children": []
            //       }, {
            //         "functionIndex": "b001b12fb8cc4023bece4caba5976cf0",
            //         "parentNode": "71419d426a8f44008ecbac71f5c2485f",
            //         "routeName": "/harmonic-boot/detailedAnalysis/pollution",
            //         "routePath": "/harmonic-boot/detailedAnalysis/pollution",
            //         "title": "电能质量污区图",
            //         "icon": "nested",
            //         "sort": 3,
            //         "children": []
            //       }, {
            //         "functionIndex": "3ab2e721e2d24ef58df93bc79525c83d",
            //         "parentNode": "71419d426a8f44008ecbac71f5c2485f",
            //         "routeName": "/harmonic-boot/detailedAnalysis/details",
            //         "routePath": "/harmonic-boot/detailedAnalysis/details",
            //         "title": "稳态指标超标明细",
            //         "icon": "export",
            //         "sort": 4,
            //         "children": []
            //       }]
            //     }, {
            //       "functionIndex": "104add893166468a8c2272912e2222b2",
            //       "parentNode": "669a98c0651a48dab7dc89b7b7a07dae",
            //       "routeName": "/harmonic-boot/run",
            //       "routePath": "/harmonic-boot/run",
            //       "title": "运行管理",
            //       "icon": "正常运行",
            //       "sort": 4,
            //       "children": [{
            //         "functionIndex": "73be7e6715554834a40b00517d8cfbd8",
            //         "parentNode": "104add893166468a8c2272912e2222b2",
            //         "routeName": "/harmonic-boot/run/devicemessage",
            //         "routePath": "/harmonic-boot/run/devicemessage",
            //         "title": "监测点台账信息",
            //         "icon": "dashboard",
            //         "sort": 1,
            //         "children": []
            //       }, {
            //         "functionIndex": "e5b40e6f963c46618d3da386c5292087",
            //         "parentNode": "104add893166468a8c2272912e2222b2",
            //         "routeName": "/harmonic-boot/run/terminalmessage",
            //         "routePath": "/harmonic-boot/run/terminalmessage",
            //         "title": "终端台账信息",
            //         "icon": "eye-open",
            //         "sort": 2,
            //         "children": []
            //       }, {
            //         "functionIndex": "77d12f5e703049e8899f5e53b1ca39f1",
            //         "parentNode": "104add893166468a8c2272912e2222b2",
            //         "routeName": "/harmonic-boot/run/terminalconts",
            //         "routePath": "/harmonic-boot/run/terminalconts",
            //         "title": "终端数量统计",
            //         "icon": "export",
            //         "sort": 3,
            //         "children": []
            //       }]
            //     }, {
            //       "functionIndex": "10af32592a544166b6b3c5f094899f4b",
            //       "parentNode": "669a98c0651a48dab7dc89b7b7a07dae",
            //       "routeName": "/harmonic-boot/report",
            //       "routePath": "/harmonic-boot/report",
            //       "title": "稳态报表",
            //       "icon": "form",
            //       "sort": 5,
            //       "children": [{
            //         "functionIndex": "b8a77ba0efc54f0483d1126762d44c58",
            //         "parentNode": "10af32592a544166b6b3c5f094899f4b",
            //         "routeName": "/harmonic-boot/report/excel",
            //         "routePath": "/harmonic-boot/report/excel",
            //         "title": "Excle报表",
            //         "icon": "excel",
            //         "sort": 1,
            //         "children": []
            //       }, {
            //         "functionIndex": "d983af91da144f4abca111add8711a14",
            //         "parentNode": "10af32592a544166b6b3c5f094899f4b",
            //         "routeName": "/harmonic-boot/report/word",
            //         "routePath": "/harmonic-boot/report/word",
            //         "title": "World报告",
            //         "icon": "editor",
            //         "sort": 2,
            //         "children": []
            //       }]
            //     }]
            //   }, {
            //     "functionIndex": "48f8e4b49435452eaab0641110ddece7",
            //     "parentNode": "0",
            //     "routeName": "/event-boot",
            //     "routePath": "/event-boot",
            //     "title": "电压暂降系统",
            //     "icon": "下降趋势",
            //     "sort": 2,
            //     "children": [{
            //       "functionIndex": "bcb05756e2ec4dc3a802533a114b656a",
            //       "parentNode": "48f8e4b49435452eaab0641110ddece7",
            //       "routeName": "/event-boot/monitor",
            //       "routePath": "/event-boot/monitor",
            //       "title": "监测点",
            //       "icon": "null",
            //       "sort": 1,
            //       "children": [{
            //         "functionIndex": "40f17d40be5540359a084b83557e808f",
            //         "parentNode": "bcb05756e2ec4dc3a802533a114b656a",
            //         "routeName": "/event-boot/monitor/online",
            //         "routePath": "/event-boot/monitor/online",
            //         "title": "在线监测点",
            //         "icon": "null",
            //         "sort": 1,
            //         "children": []
            //       }]
            //     }, {
            //       "functionIndex": "2533ec76a6614d419ed799eb830505b2",
            //       "parentNode": "48f8e4b49435452eaab0641110ddece7",
            //       "routeName": "/event-boot/area",
            //       "routePath": "/event-boot/area",
            //       "title": "区域",
            //       "icon": "null",
            //       "sort": 2,
            //       "children": [{
            //         "functionIndex": "f05d3986857f4f8dbd5b01b6a18bb506",
            //         "parentNode": "2533ec76a6614d419ed799eb830505b2",
            //         "routeName": "/event-boot/area/overview",
            //         "routePath": "/event-boot/area/overview",
            //         "title": "区域概览",
            //         "icon": "null",
            //         "sort": 1,
            //         "children": []
            //       }, {
            //         "functionIndex": "7b895dce11be487786afc27c3db53180",
            //         "parentNode": "2533ec76a6614d419ed799eb830505b2",
            //         "routeName": "/event-boot/area/statistics",
            //         "routePath": "/event-boot/area/statistics",
            //         "title": "区域统计",
            //         "icon": "null",
            //         "sort": 2,
            //         "children": []
            //       }]
            //     }, {
            //       "functionIndex": "a718580aaf8c447b8d7f87f2a6e3dbe0",
            //       "parentNode": "48f8e4b49435452eaab0641110ddece7",
            //       "routeName": "/event-boot/advancedAnalysis",
            //       "routePath": "/event-boot/advancedAnalysis",
            //       "title": "高级分析",
            //       "icon": "null",
            //       "sort": 3,
            //       "children": [{
            //         "functionIndex": "3280c07bb7664946b9a95587aa4b79c3",
            //         "parentNode": "a718580aaf8c447b8d7f87f2a6e3dbe0",
            //         "routeName": "/event-boot/advancedAnalysis/eventCorrelation",
            //         "routePath": "/event-boot/advancedAnalysis/eventCorrelation",
            //         "title": "事件关联分析",
            //         "icon": "null",
            //         "sort": 1,
            //         "children": []
            //       }, {
            //         "functionIndex": "c2ee65e798a04d389905e499e49cdf12",
            //         "parentNode": "a718580aaf8c447b8d7f87f2a6e3dbe0",
            //         "routeName": "/event-boot/advancedAnalysis/scopeInfluence",
            //         "routePath": "/event-boot/advancedAnalysis/scopeInfluence",
            //         "title": "影响范围分析",
            //         "icon": "null",
            //         "sort": 2,
            //         "children": []
            //       }, {
            //         "functionIndex": "031de2930a6f4e8f981fd42bfac6e10c",
            //         "parentNode": "a718580aaf8c447b8d7f87f2a6e3dbe0",
            //         "routeName": "/event-boot/advancedAnalysis/eventWaves",
            //         "routePath": "/event-boot/advancedAnalysis/eventWaves",
            //         "title": "事件波形分析",
            //         "icon": "null",
            //         "sort": 3,
            //         "children": []
            //       }]
            //     }, {
            //       "functionIndex": "ea2e007797574624b732417667afaf23",
            //       "parentNode": "48f8e4b49435452eaab0641110ddece7",
            //       "routeName": "/event-boot/report",
            //       "routePath": "/event-boot/report",
            //       "title": "暂态报告",
            //       "icon": "null",
            //       "sort": 4,
            //       "children": [{
            //         "functionIndex": "8ebf0a342a984abeaeeb408e19ab2954",
            //         "parentNode": "ea2e007797574624b732417667afaf23",
            //         "routeName": "/event-boot/report/weeklyReport",
            //         "routePath": "/event-boot/report/weeklyReport",
            //         "title": "周报",
            //         "icon": "null",
            //         "sort": 1,
            //         "children": []
            //       }, {
            //         "functionIndex": "8de9b2b0eaef4dfabf8bfba877332b42",
            //         "parentNode": "ea2e007797574624b732417667afaf23",
            //         "routeName": "/event-boot/report/monitorReport",
            //         "routePath": "/event-boot/report/monitorReport",
            //         "title": "监测点报告",
            //         "icon": "null",
            //         "sort": 2,
            //         "children": []
            //       }, {
            //         "functionIndex": "8c23fa8e76514da9a0e4ca9cd94bf410",
            //         "parentNode": "ea2e007797574624b732417667afaf23",
            //         "routeName": "/event-boot/report/areaReport",
            //         "routePath": "/event-boot/report/areaReport",
            //         "title": "区域报告",
            //         "icon": "null",
            //         "sort": 3,
            //         "children": []
            //       }]
            //     }, {
            //       "functionIndex": "9490da398f3a45239405bebc9cd20d84",
            //       "parentNode": "48f8e4b49435452eaab0641110ddece7",
            //       "routeName": "/event-boot/descentlist",
            //       "routePath": "/event-boot/descentlist",
            //       "title": "暂降事件列表",
            //       "icon": "系统推送",
            //       "sort": 5,
            //       "children": []
            //     }]
            //   }, {
            //     "functionIndex": "f799f0f7ef3d48c382af28351c22e263",
            //     "parentNode": "0",
            //     "routeName": "/sys",
            //     "routePath": "/sys",
            //     "title": "系统管理员",
            //     "icon": "user",
            //     "sort": 4,
            //     "children": [{
            //       "functionIndex": "ab3903e521704607ba89382aa281ab7f",
            //       "parentNode": "f799f0f7ef3d48c382af28351c22e263",
            //       "routeName": "/user-boot",
            //       "routePath": "/user-boot",
            //       "title": "权限分配",
            //       "icon": "权限",
            //       "sort": 3,
            //       "children": [{
            //         "functionIndex": "2437843d7881409b8b5b3075f1b217e7",
            //         "parentNode": "ab3903e521704607ba89382aa281ab7f",
            //         "routeName": "/user-boot/palt/theme",
            //         "routePath": "/user-boot/palt/theme",
            //         "title": "主题配置管理",
            //         "icon": "角色管理 (3)",
            //         "sort": 28,
            //         "children": []
            //       }, {
            //         "functionIndex": "e79d330e857a4d91a4f230f9749b1bad",
            //         "parentNode": "ab3903e521704607ba89382aa281ab7f",
            //         "routeName": "/user-boot/dic/dicType",
            //         "routePath": "/user-boot/dic/dicType",
            //         "title": "字典管理",
            //         "icon": "1台账管理",
            //         "sort": 35,
            //         "children": []
            //       }, {
            //         "functionIndex": "4c40f196f24543079bafe60b0cf74057",
            //         "parentNode": "ab3903e521704607ba89382aa281ab7f",
            //         "routeName": "/user-boot/area/mange",
            //         "routePath": "/user-boot/area/mange",
            //         "title": "区域配置",
            //         "icon": "dept",
            //         "sort": 36,
            //         "children": []
            //       },{
            //         "functionIndex": "4c40f196f24543079bafe60b0cf78907",
            //         "parentNode": "ab3903e521704607ba89382aa281ab7f",
            //         "routeName": "/user-boot/compment/mange",
            //         "routePath": "/user-boot/commpent/mange",
            //         "title": "组件管理",
            //         "icon": "dept",
            //         "sort": 37,
            //         "children": []
            //       },{
            //         "functionIndex": "4c40f196f24543079bafe60b0cf78907",
            //         "parentNode": "ab3903e521704607ba89382aa281ab7f",
            //         "routeName": "/user-boot/depts/getDeptsTree",
            //         "routePath": "/user-boot/depts/getDeptsTree",
            //         "title": "部门管理",
            //         "icon": "dept",
            //         "sort": 38,
            //         "children": []
            //       },{
            //         "functionIndex": "4c40f196f24543079bafe60b0cf70945",
            //         "parentNode": "ab3903e521704607ba89382aa281sd6u",
            //         "routeName": "/user-boot/user/getUserList",
            //         "routePath": "/user-boot/user/getUserList",
            //         "title": "用户管理",
            //         "icon": "dept",
            //         "sort": 39,
            //         "children": []
            //       },{
            //         "functionIndex": "4c40f196f24543079bafe60b0cf77890",
            //         "parentNode": "ab3903e521704607ba89382aa281sd7u",
            //         "routeName": "/user-boot/check/getUncheckedUser",
            //         "routePath": "/user-boot/check/getUncheckedUser",
            //         "title": "审核管理",
            //         "icon": "dept",
            //         "sort": 40,
            //         "children": []
            //       },{
            //         "functionIndex": "4c40f196f24543079bafe60b0cf89890",
            //         "parentNode": "ab3903e521704607ba89382aa281hd7u",
            //         "routeName": "/user-boot/function/list",
            //         "routePath": "/user-boot/function/list",
            //         "title": "菜单管理",
            //         "icon": "dept",
            //         "sort": 41,
            //         "children": []
            //       },{
            //         "functionIndex": "4c40f196f24543079bafe60b0cf89780",
            //         "parentNode": "ab3903e521704607ba89382aa286yd7u",
            //         "routeName": "/user-boot/role/getRoles",
            //         "routePath": "/user-boot/role/getRoles",
            //         "title": "角色管理",
            //         "icon": "dept",
            //         "sort": 42,
            //         "children": []
            //       }]
            //     }]
            //   }, {
            //     "functionIndex": "36aa9f38a13f49e4bff286ab41dd0aa2",
            //     "parentNode": "0",
            //     "routeName": "/device-boot",
            //     "routePath": "/device-boot",
            //     "title": "业务管理员",
            //     "icon": "角色修改",
            //     "sort": 5,
            //     "children": [{
            //       "functionIndex": "cae088e1f11e46c291fcd31b183ab70b",
            //       "parentNode": "36aa9f38a13f49e4bff286ab41dd0aa2",
            //       "routeName": "/device-boot/device",
            //       "routePath": "/device-boot/device",
            //       "title": "终端管理",
            //       "icon": "设备",
            //       "sort": 1,
            //       "children": [{
            //         "functionIndex": "4fa83608368d40e68654e17e5197ea60",
            //         "parentNode": "cae088e1f11e46c291fcd31b183ab70b",
            //         "routeName": "/device-boot/device",
            //         "routePath": "/device-boot/device",
            //         "title": "终端台账管理",
            //         "icon": "form",
            //         "sort": 1,
            //         "children": []
            //       }]
            //     }]
            //   }, {
            //     "functionIndex": "edc0609b67f94d6c92743891517aaa99",
            //     "parentNode": "0",
            //     "routeName": "/mxgraph",
            //     "routePath": "/mxgraph",
            //     "title": "组态管理",
            //     "icon": "components",
            //     "sort": 8,
            //     "children": [{
            //       "functionIndex": "f8f99a6f623f4ce68da4de112dec8cfa",
            //       "parentNode": "edc0609b67f94d6c92743891517aaa99",
            //       "routeName": "/mxgraph/grapheditor",
            //       "routePath": "/mxgraph/grapheditor",
            //       "title": "创建组态",
            //       "icon": "editor",
            //       "sort": 1,
            //       "children": []
            //     }, {
            //       "functionIndex": "fbf22a98bda64e0ba835f530477d59b1",
            //       "parentNode": "edc0609b67f94d6c92743891517aaa99",
            //       "routeName": "/mxgraph/graph-list",
            //       "routePath": "/mxgraph/graph-list",
            //       "title": "组态列表",
            //       "icon": "form",
            //       "sort": 2,
            //       "children": []
            //     }]
            //   }, {
            //     "functionIndex": "1e42d2d1338a4f9bb5864ee357b44669",
            //     "parentNode": "0",
            //     "routeName": "/energy-system",
            //     "routePath": "/energy-system",
            //     "title": "用能管理系统",
            //     "icon": "chart",
            //     "sort": 9,
            //     "children": [{
            //       "functionIndex": "4308fea3f3e04967a6de41a1aace86cb",
            //       "parentNode": "1e42d2d1338a4f9bb5864ee357b44669",
            //       "routeName": "/energy-system/electricenergy",
            //       "routePath": "/energy-system/electricenergy",
            //       "title": "用采管理",
            //       "icon": "tree",
            //       "sort": 1,
            //       "children": []
            //     }, {
            //       "functionIndex": "aee19d6a22fd46b192f41c196c11abdc",
            //       "parentNode": "1e42d2d1338a4f9bb5864ee357b44669",
            //       "routeName": "/energy-system/device",
            //       "routePath": "/energy-system/device",
            //       "title": "设备管理",
            //       "icon": "台账地图导出",
            //       "sort": 2,
            //       "children": []
            //     }, {
            //       "functionIndex": "75afbaffef194dbbaa964493113d0ecf",
            //       "parentNode": "1e42d2d1338a4f9bb5864ee357b44669",
            //       "routeName": "/energy-system/devicejk",
            //       "routePath": "/energy-system/devicejk",
            //       "title": "设备监控",
            //       "icon": "监测点管理",
            //       "sort": 3,
            //       "children": []
            //     }, {
            //       "functionIndex": "19bdb8b7ff2b40c2856d65662303212e",
            //       "parentNode": "1e42d2d1338a4f9bb5864ee357b44669",
            //       "routeName": "/energy-system/airmanagement",
            //       "routePath": "/energy-system/airmanagement",
            //       "title": "空调管理",
            //       "icon": "logo",
            //       "sort": 4,
            //       "children": []
            //     }, {
            //       "functionIndex": "fd195b741ff94cafbcb01b03c03d688c",
            //       "parentNode": "1e42d2d1338a4f9bb5864ee357b44669",
            //       "routeName": "/energy-system/datagroup1",
            //       "routePath": "/energy-system/datagroup1",
            //       "title": "数据分组",
            //       "icon": "nested",
            //       "sort": 5,
            //       "children": []
            //     }, {
            //       "functionIndex": "9bb4b0b88cec43a280f10244ed43b3d9",
            //       "parentNode": "1e42d2d1338a4f9bb5864ee357b44669",
            //       "routeName": "/energy-system/table",
            //       "routePath": "/energy-system/table",
            //       "title": "模板表格",
            //       "icon": "export",
            //       "sort": 6,
            //       "children": []
            //     }, {
            //       "functionIndex": "fe5eb4407173417a81248dfb0e37cfd7",
            //       "parentNode": "1e42d2d1338a4f9bb5864ee357b44669",
            //       "routeName": "/energy-system/echarts",
            //       "routePath": "/energy-system/echarts",
            //       "title": "模板图表",
            //       "icon": "chart",
            //       "sort": 7,
            //       "children": []
            //     }, {
            //       "functionIndex": "a944ffc38610481b9d76ddfd8d60642f",
            //       "parentNode": "1e42d2d1338a4f9bb5864ee357b44678",
            //       "routeName": "/energy-system/echarts2",
            //       "routePath": "/energy-system/echarts2",
            //       "title": "测试图表",
            //       "icon": "components",
            //       "sort": 8,
            //       "children": []
            //     }, {
            //       "functionIndex": "c136c0e1181c47e9812912713522c5d1",
            //       "parentNode": "1e42d2d1338a4f9bb5864ee357b44669",
            //       "routeName": "/energy-system/test",
            //       "routePath": "/energy-system/test",
            //       "title": "测试树与树表模板",
            //       "icon": "components",
            //       "sort": 9,
            //       "children": []
            //     },{
            //       "functionIndex": "c136c0e1181j34w9812912713522c5d1",
            //       "parentNode": "67y5d2d1338a4f9bb5864ee357b44669",
            //       "routeName": "/energy-system/test4",
            //       "routePath": "/energy-system/test4",
            //       "title": "上传测试",
            //       "icon": "components",
            //       "sort": 10,
            //       "children": []
            //     }]
            //   }]
            // }
            // const menus = response.data
            // const homeRoute = { path: '/', redirect: menus[0] ? menus[0].routePath : '/404' }
            // accessedRoutes.unshift(homeRoute) // 添加首页
            // accessedRoutes = remakeRoute(accessedRoutes)
            // setMenus(JSON.stringify(menus))
            // commit('SET_MENUS', menus)
            // commit('SET_ROUTES', accessedRoutes)
            // resolve(accessedRoutes)
            //路由菜单接口


            menulist().then(response => {
                const menus = response.data
                const homeRoute = { path: '/', redirect: menus[0] ? menus[0].routePath : '/404' }
                accessedRoutes.unshift(homeRoute) // 添加首页
                accessedRoutes = remakeRoute(accessedRoutes)
                setMenus(JSON.stringify(menus))
                commit('SET_MENUS', menus)
                commit('SET_ROUTES', accessedRoutes)
                resolve(accessedRoutes)
            })
            dictypeData().then(response => {
                const dictType = response.data
                setDictype(JSON.stringify(dictType))
            })
            getSysConfig().then(res => {
                const sysdata = res.data
                setSysConfig(JSON.stringify(sysdata))
            })
        })
    },
    resetRoute({ commit }) {
        commit('SET_ROUTES', [])
    }
}

export default {
    namespaced: true,
    state,
    mutations,
    actions
}
