routerConfig.ts 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  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 === '/iaaData') { //当切换一级菜单的辅助跳转
  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('/iaaData'))) {
  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. isPhone ? history.push(path) : window.open(location.origin + '/#' + path)
  22. }
  23. })
  24. }
  25. if (history?.location?.pathname === '/iaaSystem') { //当切换一级菜单的辅助跳转
  26. history?.goBack()
  27. initialState?.menu?.data.forEach((item: { roles: string[], path: string, routes: { path: string, routes: any[] }[] }) => {
  28. if (item?.routes?.some((i: { path: string }) => i.path?.includes('/iaaSystem'))) {
  29. 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
  30. isPhone ? history.push(path) : window.open(location.origin + '/#' + path)
  31. }
  32. })
  33. }
  34. }
  35. //返回按钮路由
  36. function btnFun(items: any) {
  37. return items?.childrenBtn?.map((btn: any,) => {
  38. return { name: btn.meta.title, key: btn?.menuId }
  39. })
  40. }
  41. //返回子路由
  42. function routeFun(items: any) {
  43. return items.children.map((route: any) => {//循环重组
  44. if (route?.children?.length > 0) {
  45. let arr = routeFun(route)
  46. return { path: route.path, name: route.meta.title, component: route.component, routes: arr, icon: route.meta.icon, key: route?.menuId }
  47. }
  48. if (route?.childrenBtn?.length > 0) {
  49. let arr = btnFun(route)
  50. return { path: route.path, name: route.meta.title, component: route.component, routes: arr, icon: route.meta.icon, key: route?.menuId }
  51. }
  52. return { path: route.path, name: route.meta.title, component: route.component, icon: route.meta.icon, key: route?.menuId }
  53. })
  54. }
  55. /**获取线上菜单并重组路由格式和权限*/
  56. function getMyMenu(code: any, data: any,) {
  57. let newData: any = []
  58. // let roles = userInfo?.roles.map((role: any) => role.roleKey)//权限从个人信息中取,以防路由列表中有错误
  59. if (code === 200) {
  60. let new_data: any[] = []
  61. // 循环判断不为空的主菜单加入
  62. Object.keys(data).reverse().map((key) => {
  63. if (Array.isArray(data[key]) && data[key]?.length > 0) {
  64. new_data.push(data[key][0])
  65. }
  66. })
  67. // 处理顺序
  68. new_data = new_data.sort((a, b) => {
  69. let v1 = a.orderNum
  70. let v2 = b.orderNum
  71. return v1 - v2
  72. })
  73. new_data.forEach((items: any) => {
  74. if (items?.children?.length === 0) {//假如路由的子路由只有一个代表当前组件没有子路由,将children中的component组件路径给外层component
  75. 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
  76. }
  77. if (items?.children?.length >= 0) {//假如路由的子路由个数大于1代表有子路由
  78. let arr: any[] = routeFun(items)
  79. newData.push({ path: items.path, name: items.meta.title, icon: items.meta.icon, routes: arr, key: items.menuId })//最后添加进routes , roles: roles
  80. }
  81. })
  82. }
  83. return newData
  84. }
  85. const iaaSystem = {
  86. path: '/iaaSystem',
  87. routes: [
  88. {
  89. path: '/iaaSystem/manage',
  90. name: 'IAA后台管理',
  91. routes: [
  92. {
  93. path: '/iaaSystem/manage/useApp',
  94. name: '应用管理',
  95. component: './iaaSystem/manage/useApp',
  96. },
  97. {
  98. path: '/iaaSystem/manage/power',
  99. name: '角色分配',
  100. component: './iaaSystem/manage/power',
  101. },
  102. {
  103. path: '/iaaSystem/manage/application',
  104. name: '应用管理',
  105. component: './iaaSystem/manage/application',
  106. },
  107. {
  108. path: '/iaaSystem/manage/channel',
  109. name: '渠道管理',
  110. component: './iaaSystem/manage/channel',
  111. },
  112. {
  113. path: '/iaaSystem/manage/backPolicy',
  114. name: '回传策略管理',
  115. component: './iaaSystem/manage/backPolicy',
  116. }
  117. ]
  118. }
  119. ]
  120. }
  121. /** 游戏 */
  122. const iaaGameData = [
  123. {
  124. path: '/iaaData/game/tencent',
  125. name: '腾讯',
  126. routes: [
  127. {
  128. path: '/iaaData/game/tencent/home',
  129. name: '首页',
  130. component: './iaaData/game/tencent/home',
  131. },
  132. {
  133. path: '/iaaData/game/tencent/adList',
  134. name: '广告列表',
  135. component: './iaaData/game/tencent/adList',
  136. },
  137. {
  138. path: '/iaaData/game/tencent/dynamic',
  139. name: '创意列表',
  140. component: './iaaData/game/tencent/dynamic',
  141. },
  142. {
  143. path: '/iaaData/game/tencent/appEveryDayData',
  144. name: '应用每日数据',
  145. component: './iaaData/game/tencent/appEveryDayData',
  146. },
  147. {
  148. path: '/iaaData/game/tencent/appCashTrend',
  149. name: '应用变现趋势',
  150. component: './iaaData/game/tencent/appCashTrend',
  151. },
  152. {
  153. path: '/iaaData/game/tencent/appCashRetained',
  154. name: '应用变现留存',
  155. component: './iaaData/game/tencent/appCashRetained',
  156. },
  157. {
  158. path: '/iaaData/game/tencent/appCashAssay',
  159. name: '应用变现分析',
  160. component: './iaaData/game/tencent/appCashAssay',
  161. },
  162. {
  163. path: '/iaaData/game/tencent/pitcherEveryDay',
  164. name: '投手每日数据',
  165. component: './iaaData/game/tencent/pitcherEveryDay',
  166. },
  167. ]
  168. },
  169. {
  170. path: '/iaaData/game/ocenaengine',
  171. name: '头条',
  172. routes: [
  173. {
  174. path: '/iaaData/game/ocenaengine/home',
  175. name: '首页',
  176. component: './iaaData/game/ocenaengine/home'
  177. },
  178. {
  179. path: '/iaaData/game/ocenaengine/adList',
  180. name: '广告列表',
  181. component: './iaaData/game/ocenaengine/adList'
  182. },
  183. {
  184. path: '/iaaData/game/ocenaengine/appEveryDayData',
  185. name: '应用每日数据',
  186. component: './iaaData/game/ocenaengine/appEveryDayData'
  187. },
  188. {
  189. path: '/iaaData/game/ocenaengine/appCashTrendRoi',
  190. name: '应用变现趋势-ROI',
  191. component: './iaaData/game/ocenaengine/appCashTrendRoi'
  192. },
  193. {
  194. path: '/iaaData/game/ocenaengine/appCashTrendRetained',
  195. name: '应用变现趋势-留存',
  196. component: './iaaData/game/ocenaengine/appCashTrendRetained'
  197. },
  198. {
  199. path: '/iaaData/game/ocenaengine/appCashTrendLTV',
  200. name: '应用变现趋势-LTV',
  201. component: './iaaData/game/ocenaengine/appCashTrendLTV'
  202. }
  203. ]
  204. }
  205. ]
  206. /** 小说 */
  207. const iaaNovelData = [
  208. {
  209. path: '/iaaData/novel/tencent',
  210. name: '腾讯',
  211. routes: [
  212. {
  213. path: '/iaaData/novel/tencent/home',
  214. name: '首页',
  215. component: './iaaData/novel/tencent/home',
  216. },
  217. {
  218. path: '/iaaData/novel/tencent/adList',
  219. name: '广告列表',
  220. component: './iaaData/novel/tencent/adList',
  221. },
  222. {
  223. path: '/iaaData/novel/tencent/dynamic',
  224. name: '创意列表',
  225. component: './iaaData/novel/tencent/dynamic',
  226. },
  227. {
  228. path: '/iaaData/novel/tencent/pitcherEveryDay',
  229. name: '投手每日数据',
  230. component: './iaaData/novel/tencent/pitcherEveryDay',
  231. },
  232. {
  233. path: '/iaaData/novel/tencent/pitcherEveryDayGroup',
  234. name: '投手每日汇总',
  235. component: './iaaData/novel/tencent/pitcherEveryDayGroup',
  236. },
  237. {
  238. path: '/iaaData/novel/tencent/appEveryDayData',
  239. name: '应用每日数据',
  240. component: './iaaData/novel/tencent/appEveryDayData',
  241. }
  242. ]
  243. }
  244. ]
  245. /** 短剧 */
  246. const iaaPlayletData = [
  247. {
  248. path: '/iaaData/playlet/tencent',
  249. name: '腾讯',
  250. routes: [
  251. {
  252. path: '/iaaData/playlet/tencent/home',
  253. name: '首页',
  254. component: './iaaData/playlet/tencent/home',
  255. },
  256. {
  257. path: '/iaaData/playlet/tencent/adList',
  258. name: '广告列表',
  259. component: './iaaData/playlet/tencent/adList',
  260. },
  261. {
  262. path: '/iaaData/playlet/tencent/dynamic',
  263. name: '创意列表',
  264. component: './iaaData/playlet/tencent/dynamic',
  265. },
  266. {
  267. path: '/iaaData/playlet/tencent/pitcherEveryDay',
  268. name: '投手每日数据',
  269. component: './iaaData/playlet/tencent/pitcherEveryDay',
  270. },
  271. {
  272. path: '/iaaData/playlet/tencent/pitcherEveryDayGroup',
  273. name: '投手每日汇总',
  274. component: './iaaData/playlet/tencent/pitcherEveryDayGroup',
  275. },
  276. {
  277. path: '/iaaData/playlet/tencent/appEveryDayData',
  278. name: '应用每日数据',
  279. component: './iaaData/playlet/tencent/appEveryDayData',
  280. }
  281. ]
  282. }
  283. ]
  284. const iaaData = {
  285. path: '/iaaData',
  286. routes: [
  287. ...iaaGameData,
  288. ...iaaNovelData,
  289. ...iaaPlayletData
  290. ]
  291. }
  292. export {
  293. headrRouter,
  294. getMyMenu,
  295. iaaSystem,
  296. iaaData
  297. }