routerConfig.ts 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  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/monitorEWList',
  100. name: '企微客服组监控',
  101. component: './launchSystemV3/monitorEWList',
  102. access: 'monitorEWList',
  103. },
  104. {
  105. path: '/launchSystemV3/adqv3',
  106. name: '腾讯广告',
  107. component: './launchSystemV3/adqv3',
  108. access: 'adqv3',
  109. },
  110. {
  111. path: '/launchSystemV3/account',
  112. name: '广告账户管理',
  113. access: 'account',
  114. component: './launchSystemV3/account',
  115. },
  116. {
  117. path: '/launchSystemV3/tencentAdPutIn',
  118. name: '广告投放',
  119. access: 'tencentAdPutIn',
  120. routes: [
  121. {
  122. name: '广告创建',
  123. path: '/launchSystemV3/tencentAdPutIn/create',
  124. access: 'create',
  125. component: './launchSystemV3/tencentAdPutIn/create',
  126. },
  127. {
  128. name: '任务列表',
  129. path: '/launchSystemV3/tencentAdPutIn/taskList',
  130. access: 'taskList',
  131. component: './launchSystemV3/tencentAdPutIn/taskList',
  132. },
  133. ],
  134. },
  135. {
  136. path: '/launchSystemV3/tencenTasset',
  137. name: '资产',
  138. access: 'tencenTasset',
  139. routes: [
  140. {
  141. name: '定向模板',
  142. path: '/launchSystemV3/tencenTasset/targeting',
  143. access: 'targeting',
  144. component: './launchSystemV3/tencenTasset/targeting',
  145. },
  146. {
  147. name: '品牌形象',
  148. path: '/launchSystemV3/tencenTasset/brand',
  149. access: 'brand',
  150. component: './launchSystemV3/tencenTasset/brand',
  151. },
  152. {
  153. name: '头像昵称跳转页',
  154. path: '/launchSystemV3/tencenTasset/profiles',
  155. access: 'profiles',
  156. component: './launchSystemV3/tencenTasset/profiles',
  157. },
  158. {
  159. name: '原生推广页',
  160. path: '/launchSystemV3/tencenTasset/wechatCanvasPage',
  161. access: 'wechatCanvasPage',
  162. component: './launchSystemV3/tencenTasset/wechatCanvasPage',
  163. },
  164. {
  165. name: '微信小程序',
  166. path: '/launchSystemV3/tencenTasset/miniProgramWechat',
  167. access: 'miniProgramWechat',
  168. component: './launchSystemV3/tencenTasset/miniProgramWechat',
  169. },
  170. {
  171. name: '企业微信',
  172. path: '/launchSystemV3/tencenTasset/corpWechat',
  173. access: 'corpWechat',
  174. routes: [
  175. {
  176. name: '企业微信管理',
  177. path: '/launchSystemV3/tencenTasset/corpWechat/manage',
  178. access: 'manage',
  179. component: './launchSystemV3/tencenTasset/corpWechat/manage',
  180. },
  181. {
  182. name: '客服号轮换策略',
  183. path: '/launchSystemV3/tencenTasset/corpWechat/userRotatePolicy',
  184. access: 'userRotatePolicy',
  185. component: './launchSystemV3/tencenTasset/corpWechat/userRotatePolicy',
  186. },
  187. {
  188. name: '客服组',
  189. path: '/launchSystemV3/tencenTasset/corpWechat/csgroup',
  190. access: 'csgroup',
  191. component: './launchSystemV3/tencenTasset/corpWechat/csgroup',
  192. }
  193. ]
  194. },
  195. {
  196. name: '游戏库',
  197. path: '/launchSystemV3/tencenTasset/game',
  198. access: 'game',
  199. component: './launchSystemV3/tencenTasset/game',
  200. },
  201. {
  202. name: '账户资产共享',
  203. path: '/launchSystemV3/tencenTasset/accountAssetSharing',
  204. access: 'accountAssetSharing',
  205. component: './launchSystemV3/tencenTasset/accountAssetSharing',
  206. },
  207. {
  208. name: '文案库',
  209. path: '/launchSystemV3/tencenTasset/copyWriting',
  210. access: 'copyWriting',
  211. component: './launchSystemV3/tencenTasset/copyWriting',
  212. },
  213. {
  214. name: '推广应用',
  215. path: '/launchSystemV3/tencenTasset/application',
  216. access: 'application',
  217. component: './launchSystemV3/tencenTasset/application',
  218. },
  219. {
  220. name: '创意组件',
  221. path: '/launchSystemV3/tencenTasset/manageComponent',
  222. access: 'manageComponent',
  223. component: './launchSystemV3/tencenTasset/manageComponent',
  224. }
  225. ],
  226. },
  227. {
  228. path: '/launchSystemV3/material',
  229. name: '素材库',
  230. access: 'material',
  231. icon: 'DatabaseOutlined',
  232. routes: [
  233. {
  234. name: '本地素材',
  235. path: '/launchSystemV3/material/cloud',
  236. access: 'cloud',
  237. component: './launchSystemNew/material/cloud',
  238. },
  239. {
  240. name: '云端素材',
  241. path: '/launchSystemV3/material/tencent',
  242. access: 'tencent',
  243. component: './launchSystemV3/material/tencent',
  244. },
  245. {
  246. name: '素材库',
  247. path: '/launchSystemV3/material/cloudNew',
  248. access: 'cloud',
  249. component: './launchSystemV3/material/cloudNew',
  250. },
  251. ],
  252. },
  253. ]
  254. }
  255. /** 投放系统 */
  256. const launchSystem = {
  257. path: '/launchSystemNew',
  258. routes: [
  259. {
  260. path: '/launchSystemNew/adMonitorList',
  261. name: '广告监控',
  262. component: './adMonitor/adMonitorList',
  263. access: 'adMonitorList',
  264. },
  265. {
  266. path: '/launchSystemNew/account',
  267. name: '广告账户管理',
  268. access: 'account',
  269. routes: [
  270. {
  271. name: '小说',
  272. path: '/launchSystemNew/account/novel',
  273. access: 'novel',
  274. component: './launchSystemNew/account/novel',
  275. },
  276. {
  277. name: '游戏',
  278. path: '/launchSystemNew/account/game',
  279. access: 'game',
  280. component: './launchSystemNew/account/game',
  281. },
  282. ],
  283. },
  284. {
  285. path: '/launchSystemNew/adq',
  286. name: '腾讯广告',
  287. component: './launchSystemNew/adq',
  288. access: 'adq',
  289. },
  290. {
  291. path: '/launchSystemNew/sysWarningRule',
  292. name: '监控告警',
  293. component: './launchSystemNew/sysWarningRule',
  294. access: 'sysWarningRule',
  295. },
  296. {
  297. path: '/launchSystemNew/launchManage',
  298. name: '广告投放',
  299. access: 'launchManage',
  300. routes: [
  301. {
  302. path: '/launchSystemNew/launchManage/localAd',
  303. name: '广告模板',
  304. access: 'localAd',
  305. component: './launchSystemNew/launchManage/localAd',
  306. },
  307. {
  308. path: '/launchSystemNew/launchManage/createAd',
  309. name: '创建广告',
  310. access: 'createAd',
  311. component: './launchSystemNew/launchManage/createAd',
  312. },
  313. {
  314. path: '/launchSystemNew/launchManage/taskList',
  315. name: '任务列表',
  316. access: 'taskList',
  317. component: './launchSystemNew/launchManage/taskList',
  318. }
  319. ]
  320. },
  321. {
  322. path: '/launchSystemNew/material',
  323. name: '素材管理',
  324. access: 'material',
  325. icon: 'DatabaseOutlined',
  326. routes: [
  327. {
  328. name: '本地素材',
  329. path: '/launchSystemNew/material/cloud',
  330. access: 'cloud',
  331. component: './launchSystemNew/material/cloud',
  332. },
  333. ],
  334. },
  335. {
  336. path: '/launchSystemNew/adminSpecialUseConsume',
  337. name: '管理员拉消耗专用',
  338. component: './launchSystemNew/adminSpecialUseConsume',
  339. access: 'adminSpecialUseConsume',
  340. },
  341. ],
  342. }
  343. /** 头条 */
  344. const adMonitor = {
  345. path: '/toutiao',
  346. routes: [
  347. {
  348. path: '/toutiao/ttAccountManage',
  349. name: '广告监控',
  350. component: './toutiao/ttAccountManage',
  351. access: 'ttAccountManage',
  352. },
  353. ]
  354. }
  355. export {
  356. headrRouter,
  357. getMyMenu,
  358. launchSystemV3,
  359. launchSystem,
  360. adMonitor
  361. }