Showing
6 changed files
with
227 additions
and
9 deletions
| @@ -14,15 +14,19 @@ export class WDRouterRule { | @@ -14,15 +14,19 @@ export class WDRouterRule { | ||
| 14 | WDRouterRule.jumpWithPage(page, action) | 14 | WDRouterRule.jumpWithPage(page, action) |
| 15 | } | 15 | } |
| 16 | 16 | ||
| 17 | - static jumpWithPage(page?: WDRouterPage, params?: object) { | 17 | + static jumpWithPage(page?: WDRouterPage, params?: object, singleMode?: boolean) { |
| 18 | if (page) { | 18 | if (page) { |
| 19 | + let mode = router.RouterMode.Standard | ||
| 20 | + if (singleMode) { | ||
| 21 | + mode = router.RouterMode.Single | ||
| 22 | + } | ||
| 19 | if (params) { | 23 | if (params) { |
| 20 | // router.pushUrl({ url: 'pages/routerpage2', , params: params }) | 24 | // router.pushUrl({ url: 'pages/routerpage2', , params: params }) |
| 21 | console.log('page.url()==',page.url(),JSON.stringify(params)) | 25 | console.log('page.url()==',page.url(),JSON.stringify(params)) |
| 22 | router.pushUrl({ url: page.url(), params: params }) | 26 | router.pushUrl({ url: page.url(), params: params }) |
| 23 | } else { | 27 | } else { |
| 24 | - router.pushUrl({ url: page.url() }).catch((error:Error)=>{ | ||
| 25 | - console.log("err",JSON.stringify(error))//100002 uri is not exist | 28 | + router.pushUrl({ url: page.url() }, mode).catch((error: Error) => { |
| 29 | + console.log("err", JSON.stringify(error)) //100002 uri is not exist | ||
| 26 | }) | 30 | }) |
| 27 | } | 31 | } |
| 28 | } else { | 32 | } else { |
| 1 | +import { BottomNavDTO, NavigationBodyDTO, TopNavDTO } from 'wdBean/Index'; | ||
| 2 | +import { EmitterEventId, EmitterUtils, StringUtils } from 'wdKit/Index'; | ||
| 3 | +import { WDRouterPage } from '../router/WDRouterPage'; | ||
| 4 | +import { WDRouterRule } from '../router/WDRouterRule'; | ||
| 5 | +import { HashMap } from '@kit.ArkTS'; | ||
| 6 | + | ||
| 7 | +/** | ||
| 8 | + * 首页、频道相关跳转、处理 | ||
| 9 | + */ | ||
| 10 | +export class HomeChannelUtils { | ||
| 11 | + private bottomNavData: NavigationBodyDTO | null = null | ||
| 12 | + | ||
| 13 | + setBottomNavData(bottomNavData: NavigationBodyDTO) { | ||
| 14 | + this.bottomNavData = bottomNavData | ||
| 15 | + } | ||
| 16 | + | ||
| 17 | + /** | ||
| 18 | + * 切换到指定频道 | ||
| 19 | + * | ||
| 20 | + * @param channelId 频道id【顶导id】 | ||
| 21 | + * @param pageId 目标页面id | ||
| 22 | + */ | ||
| 23 | + jumpChannelTab(channelId: string, pageId: string) { | ||
| 24 | + // 1、首页所有展示频道遍历,找到目标频道 | ||
| 25 | + // 2、频道管理里的,非我的频道所有列表遍历,找到目标频道 【这步去掉,和this.bottomNavData重复了】 | ||
| 26 | + // 3、一级频道【1、2里找到目标】->【切换底导、切换频道/新增临时频道】 | ||
| 27 | + // 4、二级频道【1、2里都没有找到目标】->【跳转栏目页面-ColumnPageComponent】 | ||
| 28 | + | ||
| 29 | + // 1. 遍历查找目标channel | ||
| 30 | + if (this.bottomNavData == null || this.bottomNavData.bottomNavList == null || this.bottomNavData.bottomNavList.length <= 0) { | ||
| 31 | + this.jumpColumn(channelId, pageId) | ||
| 32 | + return | ||
| 33 | + } | ||
| 34 | + let bean = new AssignChannelParam() | ||
| 35 | + bean.channelId = channelId | ||
| 36 | + bean.pageId = pageId ? pageId : '' | ||
| 37 | + let bottomNavList = this.bottomNavData.bottomNavList | ||
| 38 | + for (let i = 0; i < bottomNavList.length; i++) { | ||
| 39 | + let bottomNavDTO: BottomNavDTO = bottomNavList[i] | ||
| 40 | + let channelList = bottomNavDTO.topNavChannelList | ||
| 41 | + if (channelList == null || channelList.length <= 0) { | ||
| 42 | + continue | ||
| 43 | + } | ||
| 44 | + for (let j = 0; j < channelList.length; j++) { | ||
| 45 | + let topNavDTO: TopNavDTO = channelList[j] | ||
| 46 | + if (topNavDTO.channelId.toString() === channelId) { | ||
| 47 | + bean.pageId = topNavDTO.pageId.toString() | ||
| 48 | + bean.bottomNavId = bottomNavDTO.id.toString() | ||
| 49 | + break | ||
| 50 | + } | ||
| 51 | + } | ||
| 52 | + } | ||
| 53 | + if (StringUtils.isEmpty(bean.bottomNavId)) { | ||
| 54 | + this.jumpColumn(channelId, pageId) | ||
| 55 | + } else { | ||
| 56 | + this.jumpHomeChannel(bean) | ||
| 57 | + } | ||
| 58 | + } | ||
| 59 | + | ||
| 60 | + jumpColumn(channelId: string, pageId: string) { | ||
| 61 | + let params: AssignChannelParam = new AssignChannelParam() | ||
| 62 | + params.pageId = pageId | ||
| 63 | + params.channelId = channelId | ||
| 64 | + WDRouterRule.jumpWithPage(WDRouterPage.columnPage, params) | ||
| 65 | + } | ||
| 66 | + | ||
| 67 | + jumpHomeChannel(param: AssignChannelParam) { | ||
| 68 | + // 跳转首页 | ||
| 69 | + WDRouterRule.jumpWithPage(WDRouterPage.mainPage, undefined, true) | ||
| 70 | + // 通知切换频道 | ||
| 71 | + EmitterUtils.sendEvent(EmitterEventId.JUMP_HOME_CHANNEL, JSON.stringify(param)) | ||
| 72 | + } | ||
| 73 | +} | ||
| 74 | + | ||
| 75 | +@Observed | ||
| 76 | +export class AssignChannelParam { | ||
| 77 | + pageId: string = ''; | ||
| 78 | + channelId: string = ''; | ||
| 79 | + bottomNavId: string = ''; | ||
| 80 | +} | ||
| 81 | + | ||
| 82 | +let homeChannelUtils = new HomeChannelUtils(); | ||
| 83 | + | ||
| 84 | +export default homeChannelUtils as HomeChannelUtils; |
| @@ -8,8 +8,7 @@ import { common, Want } from '@kit.AbilityKit'; | @@ -8,8 +8,7 @@ import { common, Want } from '@kit.AbilityKit'; | ||
| 8 | import { BusinessError } from '@kit.BasicServicesKit'; | 8 | import { BusinessError } from '@kit.BasicServicesKit'; |
| 9 | import { CompAdvMatInfoBean } from 'wdBean/src/main/ets/bean/adv/CompAdvInfoBean'; | 9 | import { CompAdvMatInfoBean } from 'wdBean/src/main/ets/bean/adv/CompAdvInfoBean'; |
| 10 | import { AdvertsBean } from 'wdBean/src/main/ets/bean/adv/AdvertsBean'; | 10 | import { AdvertsBean } from 'wdBean/src/main/ets/bean/adv/AdvertsBean'; |
| 11 | - | ||
| 12 | -// import { LiveModel } from '../viewmodel/LiveModel'; | 11 | +import HomeChannelUtils from './HomeChannelUtils'; |
| 13 | 12 | ||
| 14 | const TAG = 'ProcessUtils'; | 13 | const TAG = 'ProcessUtils'; |
| 15 | 14 | ||
| @@ -390,4 +389,13 @@ export class ProcessUtils { | @@ -390,4 +389,13 @@ export class ProcessUtils { | ||
| 390 | }; | 389 | }; |
| 391 | WDRouterRule.jumpWithAction(taskAction) | 390 | WDRouterRule.jumpWithAction(taskAction) |
| 392 | } | 391 | } |
| 392 | + | ||
| 393 | + /** | ||
| 394 | + * 切换到指定频道 | ||
| 395 | + * | ||
| 396 | + * @param channelId 频道id【顶导id】 | ||
| 397 | + */ | ||
| 398 | + public static jumpChannelTab(channelId: string, pageId: string) { | ||
| 399 | + HomeChannelUtils.jumpChannelTab(channelId, pageId) | ||
| 400 | + } | ||
| 393 | } | 401 | } |
| 1 | import { BottomNavi, CommonConstants } from 'wdConstant'; | 1 | import { BottomNavi, CommonConstants } from 'wdConstant'; |
| 2 | import { BottomNavDTO } from 'wdBean'; | 2 | import { BottomNavDTO } from 'wdBean'; |
| 3 | -import { Logger } from 'wdKit'; | 3 | +import { EmitterEventId, EmitterUtils, Logger } from 'wdKit'; |
| 4 | import { TopNavigationComponent } from './TopNavigationComponent'; | 4 | import { TopNavigationComponent } from './TopNavigationComponent'; |
| 5 | import { MinePageComponent } from './MinePageComponent'; | 5 | import { MinePageComponent } from './MinePageComponent'; |
| 6 | import { CompUtils } from '../../utils/CompUtils'; | 6 | import { CompUtils } from '../../utils/CompUtils'; |
| 7 | import PageViewModel from '../../viewmodel/PageViewModel'; | 7 | import PageViewModel from '../../viewmodel/PageViewModel'; |
| 8 | +import HomeChannelUtils, { AssignChannelParam } from 'wdRouter/src/main/ets/utils/HomeChannelUtils'; | ||
| 8 | 9 | ||
| 9 | const TAG = 'BottomNavigationComponent'; | 10 | const TAG = 'BottomNavigationComponent'; |
| 10 | let storage = LocalStorage.getShared(); | 11 | let storage = LocalStorage.getShared(); |
| @@ -39,6 +40,10 @@ export struct BottomNavigationComponent { | @@ -39,6 +40,10 @@ export struct BottomNavigationComponent { | ||
| 39 | * Component opacity value: 0.6. | 40 | * Component opacity value: 0.6. |
| 40 | */ | 41 | */ |
| 41 | readonly SIXTY_OPACITY: number = 0.6; | 42 | readonly SIXTY_OPACITY: number = 0.6; |
| 43 | + // 接收指定频道跳转的参数 | ||
| 44 | + @State assignChannel: AssignChannelParam = new AssignChannelParam() | ||
| 45 | + // 用于传参到顶导组件,【不用channelParam,主要是时序问题,需要先底导处理完,再延时触发顶导处理】 | ||
| 46 | + @State assignChannel1: AssignChannelParam = new AssignChannelParam() | ||
| 42 | 47 | ||
| 43 | async aboutToAppear() { | 48 | async aboutToAppear() { |
| 44 | Logger.info(TAG, `aboutToAppear currentNavIndex: ${this.currentNavIndex}`); | 49 | Logger.info(TAG, `aboutToAppear currentNavIndex: ${this.currentNavIndex}`); |
| @@ -49,6 +54,16 @@ export struct BottomNavigationComponent { | @@ -49,6 +54,16 @@ export struct BottomNavigationComponent { | ||
| 49 | bottomNav.bottomNavList = bottomNav.bottomNavList.filter(item => item.name !== '服务'); | 54 | bottomNav.bottomNavList = bottomNav.bottomNavList.filter(item => item.name !== '服务'); |
| 50 | this.bottomNavList = bottomNav.bottomNavList | 55 | this.bottomNavList = bottomNav.bottomNavList |
| 51 | } | 56 | } |
| 57 | + HomeChannelUtils.setBottomNavData(bottomNav) | ||
| 58 | + | ||
| 59 | + EmitterUtils.receiveEvent(EmitterEventId.JUMP_HOME_CHANNEL, (str?: string) => { | ||
| 60 | + Logger.debug(TAG, 'receiveEvent JUMP_HOME_CHANNEL: ' + str) | ||
| 61 | + if (str) { | ||
| 62 | + // 跳转指定频道场景,传参底导id、频道id | ||
| 63 | + this.assignChannel = JSON.parse(str) as AssignChannelParam | ||
| 64 | + this.changeBottomNav() | ||
| 65 | + } | ||
| 66 | + }) | ||
| 52 | } | 67 | } |
| 53 | 68 | ||
| 54 | aboutToDisappear() { | 69 | aboutToDisappear() { |
| @@ -69,8 +84,8 @@ export struct BottomNavigationComponent { | @@ -69,8 +84,8 @@ export struct BottomNavigationComponent { | ||
| 69 | topNavList: navItem.topNavChannelList.filter(item => item.channelId != 2073), | 84 | topNavList: navItem.topNavChannelList.filter(item => item.channelId != 2073), |
| 70 | _currentNavIndex: $currentNavIndex, | 85 | _currentNavIndex: $currentNavIndex, |
| 71 | currentBottomNavName: navItem.name, | 86 | currentBottomNavName: navItem.name, |
| 72 | - barBackgroundColor: $barBackgroundColor | ||
| 73 | - | 87 | + barBackgroundColor: $barBackgroundColor, |
| 88 | + assignChannel: this.assignChannel1 | ||
| 74 | }) | 89 | }) |
| 75 | } | 90 | } |
| 76 | 91 | ||
| @@ -145,4 +160,30 @@ export struct BottomNavigationComponent { | @@ -145,4 +160,30 @@ export struct BottomNavigationComponent { | ||
| 145 | // Logger.info(TAG, `onBottomNavigationDataUpdated currentNavIndex: ${this.currentNavIndex},length:${this.bottomNavItemList.length}`); | 160 | // Logger.info(TAG, `onBottomNavigationDataUpdated currentNavIndex: ${this.currentNavIndex},length:${this.bottomNavItemList.length}`); |
| 146 | this.onBottomNavigationIndexChange() | 161 | this.onBottomNavigationIndexChange() |
| 147 | } | 162 | } |
| 163 | + | ||
| 164 | + /** | ||
| 165 | + * 底导id变化,即指定频道跳转场景 | ||
| 166 | + */ | ||
| 167 | + changeBottomNav() { | ||
| 168 | + let index = -1 | ||
| 169 | + for (let i = 0; i < this.bottomNavList.length; i++) { | ||
| 170 | + let bottomNavDTO: BottomNavDTO = this.bottomNavList[i] | ||
| 171 | + if (bottomNavDTO.id.toString() === this.assignChannel.bottomNavId) { | ||
| 172 | + index = i | ||
| 173 | + break | ||
| 174 | + } | ||
| 175 | + } | ||
| 176 | + if (index >= 0 && index != this.currentNavIndex) { | ||
| 177 | + // 切底导 | ||
| 178 | + this.currentNavIndex = index | ||
| 179 | + } | ||
| 180 | + | ||
| 181 | + setTimeout(() => { | ||
| 182 | + // 底导切换后,触发顶导切换 | ||
| 183 | + this.assignChannel1 = new AssignChannelParam() | ||
| 184 | + this.assignChannel1.pageId = this.assignChannel.pageId | ||
| 185 | + this.assignChannel1.channelId = this.assignChannel.channelId | ||
| 186 | + this.assignChannel1.bottomNavId = this.assignChannel.bottomNavId | ||
| 187 | + }, 20) | ||
| 188 | + } | ||
| 148 | } | 189 | } |
| 1 | import { Action, CompDTO, Params, TopNavDTO } from 'wdBean'; | 1 | import { Action, CompDTO, Params, TopNavDTO } from 'wdBean'; |
| 2 | -import { LazyDataSource, Logger } from 'wdKit'; | 2 | +import { LazyDataSource, Logger, StringUtils } from 'wdKit'; |
| 3 | import { ProcessUtils } from 'wdRouter'; | 3 | import { ProcessUtils } from 'wdRouter'; |
| 4 | import { PageComponent } from './PageComponent'; | 4 | import { PageComponent } from './PageComponent'; |
| 5 | import { ChannelSubscriptionLayout } from './ChannelSubscriptionLayout'; | 5 | import { ChannelSubscriptionLayout } from './ChannelSubscriptionLayout'; |
| @@ -7,6 +7,7 @@ import { FirstTabTopSearchComponent } from '../search/FirstTabTopSearchComponent | @@ -7,6 +7,7 @@ import { FirstTabTopSearchComponent } from '../search/FirstTabTopSearchComponent | ||
| 7 | import window from '@ohos.window'; | 7 | import window from '@ohos.window'; |
| 8 | import { WindowModel } from 'wdKit'; | 8 | import { WindowModel } from 'wdKit'; |
| 9 | import { VideoChannelDetail } from 'wdDetailPlayShortVideo/Index'; | 9 | import { VideoChannelDetail } from 'wdDetailPlayShortVideo/Index'; |
| 10 | +import { AssignChannelParam } from 'wdRouter/src/main/ets/utils/HomeChannelUtils'; | ||
| 10 | 11 | ||
| 11 | const TAG = 'TopNavigationComponent'; | 12 | const TAG = 'TopNavigationComponent'; |
| 12 | 13 | ||
| @@ -49,6 +50,7 @@ export struct TopNavigationComponent { | @@ -49,6 +50,7 @@ export struct TopNavigationComponent { | ||
| 49 | // 地方频道列表 | 50 | // 地方频道列表 |
| 50 | @State localChannelList: TopNavDTO[] = [] | 51 | @State localChannelList: TopNavDTO[] = [] |
| 51 | readonly MAX_LINE: number = 1; | 52 | readonly MAX_LINE: number = 1; |
| 53 | + @ObjectLink @Watch('onAssignChannelChange') assignChannel: AssignChannelParam | ||
| 52 | 54 | ||
| 53 | //处理新闻tab顶导频道数据 | 55 | //处理新闻tab顶导频道数据 |
| 54 | topNavListHandle() { | 56 | topNavListHandle() { |
| @@ -308,4 +310,81 @@ export struct TopNavigationComponent { | @@ -308,4 +310,81 @@ export struct TopNavigationComponent { | ||
| 308 | onTopNavigationDataUpdated() { | 310 | onTopNavigationDataUpdated() { |
| 309 | Logger.info(TAG, `onTopNavigationDataUpdated currentTopNavIndex: ${this.currentTopNavSelectedIndex},topNavList.length:${this.topNavList.length}`); | 311 | Logger.info(TAG, `onTopNavigationDataUpdated currentTopNavIndex: ${this.currentTopNavSelectedIndex},topNavList.length:${this.topNavList.length}`); |
| 310 | } | 312 | } |
| 313 | + | ||
| 314 | + /** | ||
| 315 | + * 频道id变化,即指定频道跳转场景 | ||
| 316 | + */ | ||
| 317 | + onAssignChannelChange() { | ||
| 318 | + let channelId = this.assignChannel.channelId | ||
| 319 | + let index = -1 | ||
| 320 | + if (this._currentNavIndex === 0) { | ||
| 321 | + // 第一个,新闻,先拿我的,再拿其他 | ||
| 322 | + index = this.getChannelByMine(channelId) | ||
| 323 | + if (index == -1) { | ||
| 324 | + // 不在我的里,需要临时新增频道展示 | ||
| 325 | + let channel = this.getChannelByOthers(channelId) | ||
| 326 | + if (channel) { | ||
| 327 | + this.myChannelList.push(channel) | ||
| 328 | + setTimeout(() => { | ||
| 329 | + this.tabsController.changeIndex(this.myChannelList.length - 1) | ||
| 330 | + }, 20) | ||
| 331 | + } | ||
| 332 | + } else { | ||
| 333 | + // 直接切换 | ||
| 334 | + this.tabsController.changeIndex(index) | ||
| 335 | + } | ||
| 336 | + } else { | ||
| 337 | + index = this.getChannelByTopNav(channelId) | ||
| 338 | + if (index > -1) { | ||
| 339 | + // 找到了,直接切换,否则不处理 | ||
| 340 | + this.tabsController.changeIndex(index) | ||
| 341 | + } | ||
| 342 | + } | ||
| 343 | + | ||
| 344 | + } | ||
| 345 | + | ||
| 346 | + /** | ||
| 347 | + * 非新闻,从topNav里拿数据 | ||
| 348 | + */ | ||
| 349 | + private getChannelByTopNav(channelId: string) { | ||
| 350 | + for (let i = 0; i < this.topNavList.length; i++) { | ||
| 351 | + let topNavDTO: TopNavDTO = this.topNavList[i] | ||
| 352 | + if (topNavDTO.channelId.toString() === channelId) { | ||
| 353 | + return i | ||
| 354 | + } | ||
| 355 | + } | ||
| 356 | + return -1 | ||
| 357 | + } | ||
| 358 | + | ||
| 359 | + /** | ||
| 360 | + * 新闻,从myChannelList里拿数据 | ||
| 361 | + */ | ||
| 362 | + private getChannelByMine(channelId: string) { | ||
| 363 | + for (let i = 0; i < this.myChannelList.length; i++) { | ||
| 364 | + let topNavDTO: TopNavDTO = this.myChannelList[i] | ||
| 365 | + if (topNavDTO.channelId.toString() === channelId) { | ||
| 366 | + return i | ||
| 367 | + } | ||
| 368 | + } | ||
| 369 | + return -1 | ||
| 370 | + } | ||
| 371 | + | ||
| 372 | + /** | ||
| 373 | + * 新闻,从其他里拿数据 | ||
| 374 | + */ | ||
| 375 | + private getChannelByOthers(channelId: string) { | ||
| 376 | + for (let i = 0; i < this.moreChannelList.length; i++) { | ||
| 377 | + let topNavDTO: TopNavDTO = this.moreChannelList[i] | ||
| 378 | + if (topNavDTO.channelId.toString() === channelId) { | ||
| 379 | + return topNavDTO | ||
| 380 | + } | ||
| 381 | + } | ||
| 382 | + for (let j = 0; j < this.localChannelList.length; j++) { | ||
| 383 | + let topNavDTO: TopNavDTO = this.localChannelList[j] | ||
| 384 | + if (topNavDTO.channelId.toString() === channelId) { | ||
| 385 | + return topNavDTO | ||
| 386 | + } | ||
| 387 | + } | ||
| 388 | + return null | ||
| 389 | + } | ||
| 311 | } | 390 | } |
-
Please register or login to post a comment