routerConfig.ts 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. /**头部路由一级菜单点击逻辑 */
  2. function headrRouter(initialState: any, history: any) {
  3. let ok = true
  4. let u = navigator?.userAgent
  5. let isPhone = !!u.match(/AppleWebKit.*Mobile.*/) || u?.indexOf('iPad') > -1
  6. //登录时指向/辅助处理看当前用户的一级菜单有哪些,找到第一个符合的跳转
  7. initialState?.menu?.data.forEach((item: { roles: string[], path: string, routes: { path: string, routes: any[] }[] }) => {
  8. if (ok) {
  9. ok = false
  10. 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
  11. if (history?.location?.pathname === '/') {
  12. history.push(path)
  13. }
  14. }
  15. })
  16. if (history?.location?.pathname === '/gameDataStatistics') { //当切换一级菜单的辅助跳转
  17. history?.goBack()
  18. initialState?.menu?.data.forEach((item: { roles: string[], path: string, routes: { path: string, routes: any[] }[] }) => {
  19. if (item?.routes?.some((i: { path: string }) => i.path?.includes('/gameDataStatistics'))) {
  20. 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
  21. // history.push(path)
  22. isPhone ? history.push(path) : window.open(location.origin + '/#' + path)
  23. // window.open(location.origin+'/#'+path)
  24. }
  25. })
  26. // localStorage.setItem('bg', 'light')
  27. }
  28. }
  29. //返回按钮路由
  30. function btnFun(items: any) {
  31. return items?.childrenBtn?.map((btn: any,) => {
  32. return { name: btn.meta.title, key: btn?.menuId }
  33. })
  34. }
  35. //返回子路由
  36. function routeFun(items: any) {
  37. return items.children.map((route: any) => {//循环重组
  38. if (route?.children?.length > 0) {
  39. let arr = routeFun(route)
  40. return { path: route.path, name: route.meta.title, component: route.component, routes: arr, icon: route.meta.icon, key: route?.menuId }
  41. }
  42. if (route?.childrenBtn?.length > 0) {
  43. let arr = btnFun(route)
  44. return { path: route.path, name: route.meta.title, component: route.component, routes: arr, icon: route.meta.icon, key: route?.menuId }
  45. }
  46. return { path: route.path, name: route.meta.title, component: route.component, icon: items.meta.icon, key: route?.menuId }
  47. })
  48. }
  49. /**获取线上菜单并重组路由格式和权限*/
  50. function getMyMenu(code: any, data: any,) {
  51. let newData: any = []
  52. // let roles = userInfo?.roles.map((role: any) => role.roleKey)//权限从个人信息中取,以防路由列表中有错误
  53. if (code === 200) {
  54. let new_data: any[] = []
  55. // 循环判断不为空的主菜单加入
  56. Object.keys(data).reverse().map((key) => {
  57. if (Array.isArray(data[key]) && data[key]?.length > 0) {
  58. new_data.push(data[key][0])
  59. }
  60. })
  61. // 处理顺序
  62. new_data = new_data.sort((a, b) => {
  63. let v1 = a.orderNum
  64. let v2 = b.orderNum
  65. return v1 - v2
  66. })
  67. new_data.forEach((items: any) => {
  68. if (items?.children?.length === 0) {//假如路由的子路由只有一个代表当前组件没有子路由,将children中的component组件路径给外层component
  69. 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
  70. }
  71. if (items?.children?.length >= 0) {//假如路由的子路由个数大于1代表有子路由
  72. let arr: any[] = routeFun(items)
  73. newData.push({ path: items.path, name: items.meta.title, icon: items.meta.icon, routes: arr, key: items.menuId })//最后添加进routes , roles: roles
  74. }
  75. })
  76. }
  77. return newData
  78. }
  79. const gameDataStatistics = {
  80. path: '/gameDataStatistics',
  81. routes: [
  82. {
  83. path: '/gameDataStatistics/allSurvey',
  84. name: '整体概况',
  85. access: 'allSurvey',
  86. component: './gameDataStatistics/allSurvey',
  87. },
  88. {
  89. path: '/gameDataStatistics/rankingList',
  90. name: '排行榜',
  91. access: 'rankingList',
  92. routes: [
  93. {
  94. path: '/gameDataStatistics/rankingList/gamer',
  95. name: '玩家充值排行榜',
  96. access: 'gamer',
  97. component: './gameDataStatistics/rankingList/gamer',
  98. },
  99. {
  100. path: '/gameDataStatistics/rankingList/game',
  101. name: '游戏充值排行榜',
  102. access: 'game',
  103. component: './gameDataStatistics/rankingList/game',
  104. },
  105. {
  106. path: '/gameDataStatistics/rankingList/channel',
  107. name: '推广渠道充值排行榜',
  108. access: 'channel',
  109. component: './gameDataStatistics/rankingList/channel',
  110. },
  111. {
  112. path: '/gameDataStatistics/rankingList/account',
  113. name: '推广账号消耗排行榜',
  114. access: 'account',
  115. component: './gameDataStatistics/rankingList/account',
  116. }
  117. ]
  118. },
  119. {
  120. path: '/gameDataStatistics/extensionData',
  121. name: '推广数据',
  122. access: 'extensionData',
  123. routes: [
  124. {
  125. path: '/gameDataStatistics/extensionData/total',
  126. name: '推广总数据',
  127. access: 'total',
  128. component: './gameDataStatistics/extensionData/total',
  129. },
  130. {
  131. path: '/gameDataStatistics/extensionData/everyday',
  132. name: '推广每日数据',
  133. access: 'everyday',
  134. component: './gameDataStatistics/extensionData/everyday',
  135. },
  136. ]
  137. },
  138. {
  139. path: '/gameDataStatistics/adlist',
  140. name: '广告列表',
  141. access: 'adlist',
  142. routes: [
  143. {
  144. path: '/gameDataStatistics/adlist/monitor',
  145. name: '头条广告监控',
  146. access: 'monitor',
  147. component: './gameDataStatistics/adlist/monitor',
  148. },
  149. {
  150. path: '/gameDataStatistics/adlist/tencentMonitor',
  151. name: '腾讯广告监控',
  152. access: 'tencentMonitor',
  153. component: './gameDataStatistics/adlist/tencentMonitor',
  154. }
  155. ]
  156. },
  157. {
  158. path: '/gameDataStatistics/gameData',
  159. name: '游戏数据',
  160. access: 'gameData',
  161. routes: [
  162. {
  163. path: '/gameDataStatistics/gameData/total',
  164. name: '游戏总数据',
  165. access: 'total',
  166. component: './gameDataStatistics/gameData/total',
  167. },
  168. {
  169. path: '/gameDataStatistics/gameData/everyday',
  170. name: '游戏每日数据',
  171. access: 'everyday',
  172. component: './gameDataStatistics/gameData/everyday',
  173. },
  174. {
  175. path: '/gameDataStatistics/gameData/h5Recharge',
  176. name: 'H5游戏充值表',
  177. access: 'h5Recharge',
  178. component: './gameDataStatistics/gameData/h5Recharge',
  179. },
  180. {
  181. path: '/gameDataStatistics/gameData/flowingWater',
  182. name: '每日流水贡献',
  183. access: 'flowingWater',
  184. component: './gameDataStatistics/gameData/flowingWater',
  185. },
  186. {
  187. path: '/gameDataStatistics/gameData/ltv',
  188. name: 'LTV',
  189. access: 'ltv',
  190. component: './gameDataStatistics/gameData/ltv',
  191. },
  192. {
  193. path: '/gameDataStatistics/gameData/again',
  194. name: '游戏首日复充',
  195. access: 'again',
  196. component: './gameDataStatistics/gameData/again',
  197. },
  198. ]
  199. },
  200. {
  201. path: '/gameDataStatistics/gameServer',
  202. name: '游戏区服',
  203. access: 'gameServer',
  204. routes: [
  205. {
  206. path: '/gameDataStatistics/gameServer/serverData',
  207. name: '区服数据',
  208. access: 'serverData',
  209. component: './gameDataStatistics/gameServer/serverData',
  210. },
  211. ]
  212. },
  213. {
  214. path: '/gameDataStatistics/order',
  215. name: '订单',
  216. access: 'order',
  217. component: './gameDataStatistics/order',
  218. },
  219. ]
  220. }
  221. export {
  222. headrRouter,
  223. getMyMenu,
  224. gameDataStatistics
  225. }