
/**头部路由一级菜单点击逻辑 */
function headrRouter(initialState: any, history: any) {
    let ok = true
    let u = navigator?.userAgent
    let isPhone = !!u.match(/AppleWebKit.*Mobile.*/) || u?.indexOf('iPad') > -1
    //登录时指向/辅助处理看当前用户的一级菜单有哪些，找到第一个符合的跳转
    initialState?.menu?.data.forEach((item: { roles: string[], path: string, routes: { path: string, routes: any[] }[] }) => {
        if (ok) {
            ok = false
            let path = item?.routes?.length > 0 ? item?.routes[0]?.routes?.length > 0 ? item?.routes[0]?.routes[0]?.path ? item?.routes[0]?.routes[0]?.path : item?.routes[0].path : item?.routes[0].path : item?.routes[0].path
            if (history?.location?.pathname === '/') {
                history.push(path)
            }
        }
    })
    if (history?.location?.pathname === '/gameDataStatistics') { //当切换一级菜单的辅助跳转
        history?.goBack()
        initialState?.menu?.data.forEach((item: { roles: string[], path: string, routes: { path: string, routes: any[] }[] }) => {
            if (item?.routes?.some((i: { path: string }) => i.path?.includes('/gameDataStatistics'))) {
                let path = item?.routes?.length > 0 ? (item?.routes[0]?.routes?.length > 0 && item?.routes[0]?.routes[0]?.path) ? item?.routes[0]?.routes[0]?.path : item?.routes[0].path : item?.routes[0].path
                isPhone ? history.push(path) : window.open(location.origin + '/#' + path)
            }
        })
    }
    if (history?.location?.pathname === '/gsData') { //当切换一级菜单的辅助跳转
        history?.goBack()
        initialState?.menu?.data.forEach((item: { roles: string[], path: string, routes: { path: string, routes: any[] }[] }) => {
            if (item?.routes?.some((i: { path: string }) => i.path?.includes('/gsData'))) {
                let path = item?.routes?.length > 0 ? (item?.routes[0]?.routes?.length > 0 && item?.routes[0]?.routes[0]?.path) ? item?.routes[0]?.routes[0]?.path : item?.routes[0].path : item?.routes[0].path
                isPhone ? history.push(path) : window.open(location.origin + '/#' + path)
            }
        })
    }
}
//返回按钮路由
function btnFun(items: any) {
    return items?.childrenBtn?.map((btn: any,) => {
        return { name: btn.meta.title, key: btn?.menuId }
    })
}
//返回子路由
function routeFun(items: any) {
    return items.children.map((route: any) => {//循环重组
        if (route?.children?.length > 0) {
            let arr = routeFun(route)
            return { path: route.path, name: route.meta.title, component: route.component, routes: arr, icon: route.meta.icon, key: route?.menuId }
        }
        if (route?.childrenBtn?.length > 0) {
            let arr = btnFun(route)
            return { path: route.path, name: route.meta.title, component: route.component, routes: arr, icon: route.meta.icon, key: route?.menuId }
        }
        return { path: route.path, name: route.meta.title, component: route.component, icon: route.meta.icon, key: route?.menuId }
    })
}
/**获取线上菜单并重组路由格式和权限*/
function getMyMenu(code: any, data: any,) {
    let newData: any = []
    // let roles = userInfo?.roles.map((role: any) => role.roleKey)//权限从个人信息中取，以防路由列表中有错误
    if (code === 200) {
        let new_data: any[] = []
        // 循环判断不为空的主菜单加入
        Object.keys(data).reverse().map((key) => {
            if (Array.isArray(data[key]) && data[key]?.length > 0) {
                new_data.push(data[key][0])
            }
        })
        // 处理顺序
        new_data = new_data.sort((a, b) => {
            let v1 = a.orderNum
            let v2 = b.orderNum
            return v1 - v2
        })
        new_data.forEach((items: any) => {
            if (items?.children?.length === 0) {//假如路由的子路由只有一个代表当前组件没有子路由，将children中的component组件路径给外层component
                newData.push({ path: items.children[0].path, name: items.meta.title, icon: items.meta.icon, component: items.children[0].component, key: items.menuId })  // roles: roles
            }
            if (items?.children?.length >= 0) {//假如路由的子路由个数大于1代表有子路由
                let arr: any[] = routeFun(items)
                newData.push({ path: items.path, name: items.meta.title, icon: items.meta.icon, routes: arr, key: items.menuId })//最后添加进routes , roles: roles
            }
        })
    }
    return newData
}
const gameDataStatistics = {
    path: '/gameDataStatistics',
    routes: [
        {
            path: '/gameDataStatistics/allSurvey',
            name: '整体概况',
            access: 'allSurvey',
            component: './gameDataStatistics/allSurvey',
        },
        {
            path: '/gameDataStatistics/rankingList',
            name: '排行榜',
            access: 'rankingList',
            routes: [
                {
                    path: '/gameDataStatistics/rankingList/gamer',
                    name: '玩家充值排行榜',
                    access: 'gamer',
                    component: './gameDataStatistics/rankingList/gamer',
                },
                {
                    path: '/gameDataStatistics/rankingList/game',
                    name: '游戏充值排行榜',
                    access: 'game',
                    component: './gameDataStatistics/rankingList/game',
                },
                {
                    path: '/gameDataStatistics/rankingList/channel',
                    name: '推广渠道充值排行榜',
                    access: 'channel',
                    component: './gameDataStatistics/rankingList/channel',
                },
                {
                    path: '/gameDataStatistics/rankingList/account',
                    name: '推广账号消耗排行榜',
                    access: 'account',
                    component: './gameDataStatistics/rankingList/account',
                }
            ]
        },
        {
            path: '/gameDataStatistics/roleOperate',
            name: '角色运营管理',
            access: 'roleOperate',
            routes: [
                {
                    path: '/gameDataStatistics/roleOperate/roleRechargeRanking',
                    name: '角色充值排行榜',
                    access: 'roleRechargeRanking',
                    component: './gameDataStatistics/roleOperate/roleRechargeRanking',
                },
                {
                    path: '/gameDataStatistics/roleOperate/roleFightingRanking',
                    name: '角色战力排行榜',
                    access: 'roleFightingRanking',
                    component: './gameDataStatistics/roleOperate/roleFightingRanking',
                },
                {
                    path: '/gameDataStatistics/roleOperate/gameServer',
                    name: '游戏区服',
                    access: 'gameServer',
                    component: './gameDataStatistics/roleOperate/gameServer',
                },
                {
                    path: '/gameDataStatistics/roleOperate/pack',
                    name: '礼包',
                    access: 'pack',
                    component: './gameDataStatistics/roleOperate/pack',
                },
                {
                    path: '/gameDataStatistics/roleOperate/createRoleConfig',
                    name: '有效创角配置',
                    access: 'createRoleConfig',
                    component: './gameDataStatistics/roleOperate/createRoleConfig',
                },
                {
                    path: '/gameDataStatistics/roleOperate/vip',
                    name: '游戏VIP档位',
                    access: 'vip',
                    component: './gameDataStatistics/roleOperate/vip',
                },
                {
                    path: '/gameDataStatistics/roleOperate/strategy',
                    name: '游戏策略配置',
                    access: 'strategy',
                    component: './gameDataStatistics/roleOperate/strategy',
                },
                {
                    path: '/gameDataStatistics/roleOperate/codeSender',
                    name: '游戏发码器',
                    access: 'codeSender',
                    component: './gameDataStatistics/roleOperate/codeSender',
                },
                {
                    path: '/gameDataStatistics/roleOperate/playrWhiteList',
                    name: '玩家充值白名单',
                    access: 'playrWhiteList',
                    component: './gameDataStatistics/roleOperate/playrWhiteList',
                }
            ]
        },
        {
            path: '/gameDataStatistics/extensionData',
            name: '推广数据',
            access: 'extensionData',
            routes: [
                {
                    path: '/gameDataStatistics/extensionData/total',
                    name: '推广总数据',
                    access: 'total',
                    component: './gameDataStatistics/extensionData/total',
                },
                {
                    path: '/gameDataStatistics/extensionData/everyday',
                    name: '推广每日数据',
                    access: 'everyday',
                    component: './gameDataStatistics/extensionData/everyday',
                },
            ]
        },
        {
            path: '/gameDataStatistics/adlist',
            name: '广告列表',
            access: 'adlist',
            routes: [
                {
                    path: '/gameDataStatistics/adlist/monitor',
                    name: '头条广告监控',
                    access: 'monitor',
                    component: './gameDataStatistics/adlist/monitor',
                },
                {
                    path: '/gameDataStatistics/adlist/tencentMonitor',
                    name: '腾讯广告监控',
                    access: 'tencentMonitor',
                    component: './gameDataStatistics/adlist/tencentMonitor',
                },
                {
                    path: '/gameDataStatistics/adlist/strategy',
                    name: '游戏广告策略',
                    access: 'strategy',
                    component: './gameDataStatistics/adlist/strategy',
                }
            ]
        },
        {
            path: '/gameDataStatistics/dynamic',
            name: '创意列表',
            access: 'dynamic',
            routes: [
                {
                    path: '/gameDataStatistics/dynamic/tencentMonitor',
                    name: '腾讯创意监控',
                    access: 'tencentMonitor',
                    component: './gameDataStatistics/dynamic/tencentMonitor',
                }
            ]
        },
        {
            path: '/gameDataStatistics/gameData',
            name: '游戏数据',
            access: 'gameData',
            routes: [
                {
                    path: '/gameDataStatistics/gameData/total',
                    name: '游戏总数据',
                    access: 'total',
                    component: './gameDataStatistics/gameData/total',
                },
                {
                    path: '/gameDataStatistics/gameData/everyday',
                    name: '游戏每日数据',
                    access: 'everyday',
                    component: './gameDataStatistics/gameData/everyday',
                },
                {
                    path: '/gameDataStatistics/gameData/h5Recharge',
                    name: 'H5游戏充值表',
                    access: 'h5Recharge',
                    component: './gameDataStatistics/gameData/h5Recharge',
                },
                {
                    path: '/gameDataStatistics/gameData/flowingWater',
                    name: '每日流水贡献',
                    access: 'flowingWater',
                    component: './gameDataStatistics/gameData/flowingWater',
                },
                {
                    path: '/gameDataStatistics/gameData/ltv',
                    name: 'LTV',
                    access: 'ltv',
                    component: './gameDataStatistics/gameData/ltv',
                },
                {
                    path: '/gameDataStatistics/gameData/again',
                    name: '游戏首日复充',
                    access: 'again',
                    component: './gameDataStatistics/gameData/again',
                },
                {
                    path: '/gameDataStatistics/gameData/active',
                    name: '游戏留存数据',
                    access: 'active',
                    component: './gameDataStatistics/gameData/active',
                },
                {
                    path: '/gameDataStatistics/gameData/activeM',
                    name: '每月留存数据',
                    access: 'activeM',
                    component: './gameDataStatistics/gameData/activeM',
                },
            ]
        },
        {
            path: '/gameDataStatistics/pitcher',
            name: '投手数据',
            access: 'pitcher',
            routes: [
                {
                    path: '/gameDataStatistics/pitcher/total',
                    name: '投手总数据',
                    access: 'total',
                    component: './gameDataStatistics/pitcher/total',
                },
                {
                    path: '/gameDataStatistics/pitcher/everyDay',
                    name: '投手每日数据',
                    access: 'everyDay',
                    component: './gameDataStatistics/pitcher/everyDay',
                },
                {
                    path: '/gameDataStatistics/pitcher/totalGame',
                    name: '投手游戏总数据',
                    access: 'totalGame',
                    component: './gameDataStatistics/pitcher/totalGame',
                },
                {
                    path: '/gameDataStatistics/pitcher/everyDayGame',
                    name: '投手游戏每日数据',
                    access: 'everyDayGame',
                    component: './gameDataStatistics/pitcher/everyDayGame',
                },
            ]
        },
        {
            path: '/gameDataStatistics/medium',
            name: '媒体数据',
            access: 'medium',
            routes: [
                {
                    path: '/gameDataStatistics/medium/promotionEvery',
                    name: '推广媒体每日数据',
                    access: 'promotionEvery',
                    component: './gameDataStatistics/medium/promotionEvery',
                },
                {
                    path: '/gameDataStatistics/medium/promotionTotal',
                    name: '推广媒体总数据',
                    access: 'promotionTotal',
                    component: './gameDataStatistics/medium/promotionTotal',
                },
                {
                    path: '/gameDataStatistics/medium/pitcherEvery',
                    name: '投手媒体每日数据',
                    access: 'pitcherEvery',
                    component: './gameDataStatistics/medium/pitcherEvery',
                },
                {
                    path: '/gameDataStatistics/medium/pitcherTotal',
                    name: '投手媒体总数据',
                    access: 'pitcherTotal',
                    component: './gameDataStatistics/medium/pitcherTotal',
                },
                {
                    path: '/gameDataStatistics/medium/gameEvery',
                    name: '游戏媒体每日数据',
                    access: 'gameEvery',
                    component: './gameDataStatistics/medium/gameEvery',
                },
                {
                    path: '/gameDataStatistics/medium/gameTotal',
                    name: '游戏媒体总数据',
                    access: 'gameTotal',
                    component: './gameDataStatistics/medium/gameTotal',
                },
                {
                    path: '/gameDataStatistics/medium/mediumActive',
                    name: '游戏媒体留存数据',
                    access: 'mediumActive',
                    component: './gameDataStatistics/medium/mediumActive',
                },
            ]
        },
        {
            path: '/gameDataStatistics/player',
            name: '玩家数据',
            access: 'player',
            routes: [
                {
                    path: '/gameDataStatistics/player/list',
                    name: '玩家列表',
                    access: 'list',
                    component: './gameDataStatistics/player/list',
                },
                {
                    path: '/gameDataStatistics/player/role',
                    name: '玩家角色',
                    access: 'role',
                    component: './gameDataStatistics/player/role',
                },
                {
                    path: '/gameDataStatistics/player/loginLog',
                    name: '玩家登录日志',
                    access: 'loginLog',
                    component: './gameDataStatistics/player/loginLog',
                },
                {
                    path: '/gameDataStatistics/player/banGamePlayerManage',
                    name: '封禁玩家管理',
                    access: 'banGamePlayerManage',
                    component: './gameDataStatistics/player/banGamePlayerManage',
                },
                {
                    path: '/gameDataStatistics/player/banIpManage',
                    name: '封禁IP管理',
                    access: 'banIpManage',
                    component: './gameDataStatistics/player/banIpManage',
                },
                {
                    path: '/gameDataStatistics/player/chatList',
                    name: '玩家聊天记录',
                    access: 'chatList',
                    component: './gameDataStatistics/player/chatList',
                }
            ]
        },
        {
            path: '/gameDataStatistics/gameServer',
            name: '游戏区服',
            access: 'gameServer',
            routes: [
                {
                    path: '/gameDataStatistics/gameServer/serverData',
                    name: '区服数据',
                    access: 'serverData',
                    component: './gameDataStatistics/gameServer/serverData',
                },
                {
                    path: '/gameDataStatistics/gameServer/serverEveryData',
                    name: '区服每日数据',
                    access: 'serverEveryData',
                    component: './gameDataStatistics/gameServer/serverEveryData',
                },
                {
                    path: '/gameDataStatistics/gameServer/serverGsData',
                    name: 'GS区服',
                    access: 'serverGsData',
                    component: './gameDataStatistics/gameServer/serverGsData',
                }
            ]
        },
        {
            path: '/gameDataStatistics/stream',
            name: '流水监控',
            access: 'stream',
            routes: [
                {
                    path: '/gameDataStatistics/stream/recharge',
                    name: '充值历史',
                    access: 'recharge',
                    component: './gameDataStatistics/stream/recharge',
                }
            ]
        },
        {
            path: '/gameDataStatistics/order',
            name: '订单',
            access: 'order',
            component: './gameDataStatistics/order',
        },
    ]
}

const gsData = {
    path: '/gsData',
    routes: [
        {
            path: '/gsData/bidREveryday',
            name: '大R每日充值比',
            access: 'bidREveryday',
            component: './gsData/bidREveryday',
        },
        {
            path: '/gsData/rolePayRetained',
            name: 'GS角色付费留存',
            access: 'rolePayRetained',
            component: './gsData/rolePayRetained',
        },
        {
            path: '/gsData/serverPayRetained',
            name: 'GS区服付费留存',
            access: 'serverPayRetained',
            component: './gsData/serverPayRetained',
        },
        {
            path: '/gsData/roleRemoveMonitor',
            name: '角色流失监控',
            access: 'roleRemoveMonitor',
            component: './gsData/roleRemoveMonitor',
        },
        {
            path: '/gsData/roleManage',
            name: '游戏角色管理',
            access: 'roleManage',
            component: './gsData/roleManage',
        },
        {
            path: '/gsData/serverManage',
            name: '游戏区服管理',
            access: 'serverManage',
            component: './gsData/serverManage',
        },
        {
            path: '/gsData/xjRoleGrade',
            name: '角色等级表(仙剑)',
            access: 'xjRoleGrade',
            component: './gsData/xjRoleGrade',
        },
        {
            path: '/gsData/roleIpMonitor',
            name: '角色IP风险监控',
            access: 'roleIpMonitor',
            component: './gsData/roleIpMonitor',
        },
        {
            path: '/gsData/gandRole',
            name: '游戏帮派角色表(仙剑)',
            access: 'gandRole',
            component: './gsData/gandRole',
        },
        {
            path: '/gsData/roleChatNum',
            name: '角色日维度聊天数量统计',
            access: 'roleChatNum',
            component: './gsData/roleChatNum',
        }
    ]
}

export {
    headrRouter,
    getMyMenu,
    gameDataStatistics,
    gsData
}