routerConfig.ts 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  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 === '/launchSystemV3') { //当切换一级菜单的辅助跳转
  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('/launchSystemV3'))) {
  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 === '/launchSystemNew') { //当切换一级菜单的辅助跳转
  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('/launchSystemNew'))) {
  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. new_data?.forEach((items: any) => {
  78. if (items?.children?.length === 0) {//假如路由的子路由只有一个代表当前组件没有子路由,将children中的component组件路径给外层component
  79. 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
  80. }
  81. if (items?.children?.length >= 0) {//假如路由的子路由个数大于1代表有子路由
  82. let arr: any[] = routeFun(items)
  83. newData.push({ path: items.path, name: items.meta.title, icon: items.meta.icon, routes: arr, key: items.menuId })//最后添加进routes , roles: roles
  84. }
  85. })
  86. }
  87. return newData
  88. }
  89. const launchSystemV3 = {
  90. path: '/launchSystemV3',
  91. routes: [
  92. {
  93. path: '/launchSystemV3/adMonitorListV3',
  94. name: '广告监控',
  95. component: './launchSystemV3/adMonitorListV3',
  96. access: 'adMonitorListV3',
  97. },
  98. {
  99. path: '/launchSystemV3/adqv3',
  100. name: '腾讯广告',
  101. component: './launchSystemV3/adqv3',
  102. access: 'adqv3',
  103. },
  104. {
  105. path: '/launchSystemV3/account',
  106. name: '广告账户管理',
  107. access: 'account',
  108. routes: [
  109. {
  110. name: '小说',
  111. path: '/launchSystemV3/account/novel',
  112. access: 'novel',
  113. component: './launchSystemNew/account/novel',
  114. },
  115. {
  116. name: '游戏',
  117. path: '/launchSystemV3/account/game',
  118. access: 'game',
  119. component: './launchSystemNew/account/game',
  120. },
  121. ],
  122. },
  123. {
  124. path: '/launchSystemV3/tencentAdPutIn',
  125. name: '广告投放',
  126. access: 'tencentAdPutIn',
  127. routes: [
  128. {
  129. name: '广告创建',
  130. path: '/launchSystemV3/tencentAdPutIn/create',
  131. access: 'create',
  132. component: './launchSystemV3/tencentAdPutIn/create',
  133. },
  134. {
  135. name: '任务列表',
  136. path: '/launchSystemV3/tencentAdPutIn/taskList',
  137. access: 'taskList',
  138. component: './launchSystemV3/tencentAdPutIn/taskList',
  139. },
  140. ],
  141. },
  142. {
  143. path: '/launchSystemV3/tencenTasset',
  144. name: '资产',
  145. access: 'tencenTasset',
  146. routes: [
  147. {
  148. name: '定向模板',
  149. path: '/launchSystemV3/tencenTasset/targeting',
  150. access: 'targeting',
  151. component: './launchSystemV3/tencenTasset/targeting',
  152. },
  153. {
  154. name: '品牌形象',
  155. path: '/launchSystemV3/tencenTasset/brand',
  156. access: 'brand',
  157. component: './launchSystemV3/tencenTasset/brand',
  158. },
  159. {
  160. name: '头像昵称跳转页',
  161. path: '/launchSystemV3/tencenTasset/profiles',
  162. access: 'profiles',
  163. component: './launchSystemV3/tencenTasset/profiles',
  164. },
  165. {
  166. name: '原生推广页',
  167. path: '/launchSystemV3/tencenTasset/wechatCanvasPage',
  168. access: 'wechatCanvasPage',
  169. component: './launchSystemV3/tencenTasset/wechatCanvasPage',
  170. },
  171. {
  172. name: '微信小程序',
  173. path: '/launchSystemV3/tencenTasset/miniProgramWechat',
  174. access: 'miniProgramWechat',
  175. component: './launchSystemV3/tencenTasset/miniProgramWechat',
  176. },
  177. {
  178. name: '企业微信',
  179. path: '/launchSystemV3/tencenTasset/corpWechat',
  180. access: 'corpWechat',
  181. component: './launchSystemV3/tencenTasset/corpWechat',
  182. }
  183. ],
  184. },
  185. {
  186. path: '/launchSystemV3/material',
  187. name: '素材库',
  188. access: 'material',
  189. icon: 'DatabaseOutlined',
  190. routes: [
  191. {
  192. name: '本地素材',
  193. path: '/launchSystemV3/material/cloud',
  194. access: 'cloud',
  195. component: './launchSystemNew/material/cloud',
  196. },
  197. {
  198. name: '云端素材',
  199. path: '/launchSystemV3/material/tencent',
  200. access: 'tencent',
  201. component: './launchSystemV3/material/tencent',
  202. },
  203. {
  204. name: '素材库',
  205. path: '/launchSystemV3/material/cloudNew',
  206. access: 'cloud',
  207. component: './launchSystemV3/material/cloudNew',
  208. },
  209. ],
  210. },
  211. ]
  212. }
  213. /** 投放系统 */
  214. const launchSystem = {
  215. path: '/launchSystemNew',
  216. routes: [
  217. {
  218. path: '/launchSystemNew/adMonitorList',
  219. name: '广告监控',
  220. component: './adMonitor/adMonitorList',
  221. access: 'adMonitorList',
  222. },
  223. {
  224. path: '/launchSystemNew/account',
  225. name: '广告账户管理',
  226. access: 'account',
  227. routes: [
  228. {
  229. name: '小说',
  230. path: '/launchSystemNew/account/novel',
  231. access: 'novel',
  232. component: './launchSystemNew/account/novel',
  233. },
  234. {
  235. name: '游戏',
  236. path: '/launchSystemNew/account/game',
  237. access: 'game',
  238. component: './launchSystemNew/account/game',
  239. },
  240. ],
  241. },
  242. {
  243. path: '/launchSystemNew/adq',
  244. name: '腾讯广告',
  245. component: './launchSystemNew/adq',
  246. access: 'adq',
  247. },
  248. {
  249. path: '/launchSystemNew/sysWarningRule',
  250. name: '监控告警',
  251. component: './launchSystemNew/sysWarningRule',
  252. access: 'sysWarningRule',
  253. },
  254. {
  255. path: '/launchSystemNew/launchManage',
  256. name: '广告投放',
  257. access: 'launchManage',
  258. routes: [
  259. {
  260. path: '/launchSystemNew/launchManage/localAd',
  261. name: '广告模板',
  262. access: 'localAd',
  263. component: './launchSystemNew/launchManage/localAd',
  264. },
  265. {
  266. path: '/launchSystemNew/launchManage/createAd',
  267. name: '创建广告',
  268. access: 'createAd',
  269. component: './launchSystemNew/launchManage/createAd',
  270. },
  271. {
  272. path: '/launchSystemNew/launchManage/taskList',
  273. name: '任务列表',
  274. access: 'taskList',
  275. component: './launchSystemNew/launchManage/taskList',
  276. }
  277. ]
  278. },
  279. {
  280. path: '/launchSystemNew/material',
  281. name: '素材管理',
  282. access: 'material',
  283. icon: 'DatabaseOutlined',
  284. routes: [
  285. {
  286. name: '本地素材',
  287. path: '/launchSystemNew/material/cloud',
  288. access: 'cloud',
  289. component: './launchSystemNew/material/cloud',
  290. },
  291. ],
  292. },
  293. {
  294. path: '/launchSystemNew/adminSpecialUseConsume',
  295. name: '管理员拉消耗专用',
  296. component: './launchSystemNew/adminSpecialUseConsume',
  297. access: 'adminSpecialUseConsume',
  298. },
  299. ],
  300. }
  301. /** 头条 */
  302. const adMonitor = {
  303. path: '/toutiao',
  304. routes: [
  305. {
  306. path: '/toutiao/ttAccountManage',
  307. name: '广告监控',
  308. component: './toutiao/ttAccountManage',
  309. access: 'ttAccountManage',
  310. },
  311. ]
  312. }
  313. export {
  314. headrRouter,
  315. getMyMenu,
  316. launchSystemV3,
  317. launchSystem,
  318. adMonitor
  319. }