routerConfig.ts 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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 === '/launchSystemNew') { //当切换一级菜单的辅助跳转
  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('/launchSystemNew'))) {
  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 === '/launchSystemV3') { //当切换一级菜单的辅助跳转
  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('/launchSystemV3'))) {
  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. if (history?.location?.pathname === '/toutiao') { //当切换一级菜单的辅助跳转
  35. history?.goBack()
  36. initialState?.menu?.data.forEach((item: { roles: string[], path: string, routes: { path: string, routes: any[] }[] }) => {
  37. if (item?.routes?.some((i: { path: string }) => i.path?.includes('/toutiao'))) {
  38. 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
  39. isPhone ? history.push(path) : window.open(location.origin + '/#' + path)
  40. }
  41. })
  42. }
  43. }
  44. //返回按钮路由
  45. function btnFun(items: any) {
  46. return items?.childrenBtn?.map((btn: any,) => {
  47. return { name: btn.meta.title, key: btn?.menuId }
  48. })
  49. }
  50. //返回子路由
  51. function routeFun(items: any) {
  52. return items.children.map((route: any) => {//循环重组
  53. // console.log(route)
  54. if (route?.children?.length > 0) {
  55. let arr = routeFun(route)
  56. return { path: route.path, name: route.meta.title, component: route.component, routes: arr, icon: route.meta.icon, key: route?.menuId }
  57. }
  58. if (route?.childrenBtn?.length > 0) {
  59. let arr = btnFun(route)
  60. return { path: route.path, name: route.meta.title, component: route.component, routes: arr, icon: route.meta.icon, key: route?.menuId }
  61. }
  62. return { path: route.path, name: route.meta.title, component: route.component, icon: route.icon, key: route?.menuId }
  63. })
  64. }
  65. /**获取线上菜单并重组路由格式和权限*/
  66. function getMyMenu(code: any, data: any,) {
  67. let newData: any = []
  68. // let roles = userInfo?.roles.map((role: any) => role.roleKey)//权限从个人信息中取,以防路由列表中有错误
  69. if (code === 200) {
  70. let new_data: any[] = []
  71. // 循环判断不为空的主菜单加入
  72. Object.keys(data)?.reverse()?.map((key) => {
  73. if (Array.isArray(data[key]) && data[key]?.length > 0) {
  74. new_data.push(data[key][0])
  75. }
  76. })
  77. // 处理顺序
  78. new_data = new_data?.sort((a, b) => {
  79. let v1 = a.orderNum
  80. let v2 = b.orderNum
  81. return v1 - v2
  82. })
  83. new_data?.forEach((items: any) => {
  84. if (items?.children?.length === 0) {//假如路由的子路由只有一个代表当前组件没有子路由,将children中的component组件路径给外层component
  85. 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
  86. }
  87. if (items?.children?.length >= 0) {//假如路由的子路由个数大于1代表有子路由
  88. let arr: any[] = routeFun(items)
  89. newData.push({ path: items.path, name: items.meta.title, icon: items.meta.icon, routes: arr, key: items.menuId })//最后添加进routes , roles: roles
  90. }
  91. })
  92. }
  93. return newData
  94. }
  95. /** 投放系统 */
  96. const launchSystem = {
  97. path: '/launchSystemNew',
  98. routes: [
  99. {
  100. path: '/launchSystemNew/adMonitorList',
  101. name: '广告监控',
  102. component: './adMonitor/adMonitorList',
  103. access: 'adMonitorList',
  104. },
  105. {
  106. path: '/launchSystemNew/account',
  107. name: '广告账户管理',
  108. access: 'account',
  109. routes: [
  110. {
  111. name: '小说',
  112. path: '/launchSystemNew/account/novel',
  113. access: 'novel',
  114. component: './launchSystemNew/account/novel',
  115. },
  116. {
  117. name: '游戏',
  118. path: '/launchSystemNew/account/game',
  119. access: 'game',
  120. component: './launchSystemNew/account/game',
  121. },
  122. ],
  123. },
  124. {
  125. path: '/launchSystemNew/adq',
  126. name: '腾讯广告',
  127. component: './launchSystemNew/adq',
  128. access: 'adq',
  129. },
  130. {
  131. path: '/launchSystemNew/sysWarningRule',
  132. name: '监控告警',
  133. component: './launchSystemNew/sysWarningRule',
  134. access: 'sysWarningRule',
  135. },
  136. {
  137. path: '/launchSystemNew/launchManage',
  138. name: '广告投放',
  139. access: 'launchManage',
  140. routes: [
  141. {
  142. path: '/launchSystemNew/launchManage/localAd',
  143. name: '广告模板',
  144. access: 'localAd',
  145. component: './launchSystemNew/launchManage/localAd',
  146. },
  147. {
  148. path: '/launchSystemNew/launchManage/createAd',
  149. name: '创建广告',
  150. access: 'createAd',
  151. component: './launchSystemNew/launchManage/createAd',
  152. },
  153. {
  154. path: '/launchSystemNew/launchManage/taskList',
  155. name: '任务列表',
  156. access: 'taskList',
  157. component: './launchSystemNew/launchManage/taskList',
  158. }
  159. ]
  160. },
  161. {
  162. path: '/launchSystemNew/material',
  163. name: '素材管理',
  164. access: 'material',
  165. icon: 'DatabaseOutlined',
  166. routes: [
  167. {
  168. name: '本地素材',
  169. path: '/launchSystemNew/material/cloud',
  170. access: 'cloud',
  171. component: './launchSystemNew/material/cloud',
  172. },
  173. ],
  174. },
  175. {
  176. path: '/launchSystemNew/adminSpecialUseConsume',
  177. name: '管理员拉消耗专用',
  178. component: './launchSystemNew/adminSpecialUseConsume',
  179. access: 'adminSpecialUseConsume',
  180. },
  181. ],
  182. }
  183. const launchSystemV3 = {
  184. path: '/launchSystemV3',
  185. routes: [
  186. {
  187. path: '/launchSystemV3/adMonitorListV3',
  188. name: '广告监控',
  189. component: './launchSystemV3/adMonitorListV3',
  190. access: 'adMonitorListV3',
  191. },
  192. {
  193. path: '/launchSystemV3/adqv3',
  194. name: '腾讯广告',
  195. component: './launchSystemV3/adqv3',
  196. access: 'adqv3',
  197. },
  198. {
  199. path: '/launchSystemV3/tencentAdPutIn',
  200. name: '广告投放',
  201. access: 'tencentAdPutIn',
  202. routes: [
  203. {
  204. name: '广告创建',
  205. path: '/launchSystemV3/tencentAdPutIn/create',
  206. access: 'create',
  207. component: './launchSystemV3/tencentAdPutIn/create',
  208. },
  209. {
  210. name: '任务列表',
  211. path: '/launchSystemV3/tencentAdPutIn/taskList',
  212. access: 'taskList',
  213. component: './launchSystemV3/tencentAdPutIn/taskList',
  214. },
  215. ],
  216. },
  217. {
  218. path: '/launchSystemV3/tencenTasset',
  219. name: '资产',
  220. access: 'tencenTasset',
  221. routes: [
  222. {
  223. name: '定向模板',
  224. path: '/launchSystemV3/tencenTasset/targeting',
  225. access: 'targeting',
  226. component: './launchSystemV3/tencenTasset/targeting',
  227. },
  228. {
  229. name: '品牌形象',
  230. path: '/launchSystemV3/tencenTasset/brand',
  231. access: 'brand',
  232. component: './launchSystemV3/tencenTasset/brand',
  233. }
  234. ],
  235. },
  236. ]
  237. }
  238. /** 头条 */
  239. const adMonitor = {
  240. path: '/toutiao',
  241. routes: [
  242. {
  243. path: '/toutiao/ttAccountManage',
  244. name: '广告监控',
  245. component: './toutiao/ttAccountManage',
  246. access: 'ttAccountManage',
  247. },
  248. ]
  249. }
  250. export {
  251. headrRouter,
  252. getMyMenu,
  253. launchSystem,
  254. adMonitor,
  255. launchSystemV3
  256. }