zhangbo1_wd

新增跳转频道功能

... ... @@ -8,5 +8,7 @@ export enum EmitterEventId {
NETWORK_CONNECTED = 2,
// 网络断开,事件id
NETWORK_DISCONNECTED = 3,
// 跳转首页指定频道,事件id
JUMP_HOME_CHANNEL = 4,
}
... ...
... ... @@ -14,15 +14,19 @@ export class WDRouterRule {
WDRouterRule.jumpWithPage(page, action)
}
static jumpWithPage(page?: WDRouterPage, params?: object) {
static jumpWithPage(page?: WDRouterPage, params?: object, singleMode?: boolean) {
if (page) {
let mode = router.RouterMode.Standard
if (singleMode) {
mode = router.RouterMode.Single
}
if (params) {
// router.pushUrl({ url: 'pages/routerpage2', , params: params })
console.log('page.url()==',page.url(),JSON.stringify(params))
router.pushUrl({ url: page.url(), params: params })
} else {
router.pushUrl({ url: page.url() }).catch((error:Error)=>{
console.log("err",JSON.stringify(error))//100002 uri is not exist
router.pushUrl({ url: page.url() }, mode).catch((error: Error) => {
console.log("err", JSON.stringify(error)) //100002 uri is not exist
})
}
} else {
... ...
import { BottomNavDTO, NavigationBodyDTO, TopNavDTO } from 'wdBean/Index';
import { EmitterEventId, EmitterUtils, StringUtils } from 'wdKit/Index';
import { WDRouterPage } from '../router/WDRouterPage';
import { WDRouterRule } from '../router/WDRouterRule';
import { HashMap } from '@kit.ArkTS';
/**
* 首页、频道相关跳转、处理
*/
export class HomeChannelUtils {
private bottomNavData: NavigationBodyDTO | null = null
setBottomNavData(bottomNavData: NavigationBodyDTO) {
this.bottomNavData = bottomNavData
}
/**
* 切换到指定频道
*
* @param channelId 频道id【顶导id】
* @param pageId 目标页面id
*/
jumpChannelTab(channelId: string, pageId: string) {
// 1、首页所有展示频道遍历,找到目标频道
// 2、频道管理里的,非我的频道所有列表遍历,找到目标频道 【这步去掉,和this.bottomNavData重复了】
// 3、一级频道【1、2里找到目标】->【切换底导、切换频道/新增临时频道】
// 4、二级频道【1、2里都没有找到目标】->【跳转栏目页面-ColumnPageComponent】
// 1. 遍历查找目标channel
if (this.bottomNavData == null || this.bottomNavData.bottomNavList == null || this.bottomNavData.bottomNavList.length <= 0) {
this.jumpColumn(channelId, pageId)
return
}
let bean = new AssignChannelParam()
bean.channelId = channelId
bean.pageId = pageId ? pageId : ''
let bottomNavList = this.bottomNavData.bottomNavList
for (let i = 0; i < bottomNavList.length; i++) {
let bottomNavDTO: BottomNavDTO = bottomNavList[i]
let channelList = bottomNavDTO.topNavChannelList
if (channelList == null || channelList.length <= 0) {
continue
}
for (let j = 0; j < channelList.length; j++) {
let topNavDTO: TopNavDTO = channelList[j]
if (topNavDTO.channelId.toString() === channelId) {
bean.pageId = topNavDTO.pageId.toString()
bean.bottomNavId = bottomNavDTO.id.toString()
break
}
}
}
if (StringUtils.isEmpty(bean.bottomNavId)) {
this.jumpColumn(channelId, pageId)
} else {
this.jumpHomeChannel(bean)
}
}
jumpColumn(channelId: string, pageId: string) {
let params: AssignChannelParam = new AssignChannelParam()
params.pageId = pageId
params.channelId = channelId
WDRouterRule.jumpWithPage(WDRouterPage.columnPage, params)
}
jumpHomeChannel(param: AssignChannelParam) {
// 跳转首页
WDRouterRule.jumpWithPage(WDRouterPage.mainPage, undefined, true)
// 通知切换频道
EmitterUtils.sendEvent(EmitterEventId.JUMP_HOME_CHANNEL, JSON.stringify(param))
}
}
@Observed
export class AssignChannelParam {
pageId: string = '';
channelId: string = '';
bottomNavId: string = '';
}
let homeChannelUtils = new HomeChannelUtils();
export default homeChannelUtils as HomeChannelUtils;
\ No newline at end of file
... ...
... ... @@ -8,8 +8,7 @@ import { common, Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { CompAdvMatInfoBean } from 'wdBean/src/main/ets/bean/adv/CompAdvInfoBean';
import { AdvertsBean } from 'wdBean/src/main/ets/bean/adv/AdvertsBean';
// import { LiveModel } from '../viewmodel/LiveModel';
import HomeChannelUtils from './HomeChannelUtils';
const TAG = 'ProcessUtils';
... ... @@ -390,4 +389,13 @@ export class ProcessUtils {
};
WDRouterRule.jumpWithAction(taskAction)
}
/**
* 切换到指定频道
*
* @param channelId 频道id【顶导id】
*/
public static jumpChannelTab(channelId: string, pageId: string) {
HomeChannelUtils.jumpChannelTab(channelId, pageId)
}
}
... ...
import { BottomNavi, CommonConstants } from 'wdConstant';
import { BottomNavDTO } from 'wdBean';
import { Logger } from 'wdKit';
import { EmitterEventId, EmitterUtils, Logger } from 'wdKit';
import { TopNavigationComponent } from './TopNavigationComponent';
import { MinePageComponent } from './MinePageComponent';
import { CompUtils } from '../../utils/CompUtils';
import PageViewModel from '../../viewmodel/PageViewModel';
import HomeChannelUtils, { AssignChannelParam } from 'wdRouter/src/main/ets/utils/HomeChannelUtils';
const TAG = 'BottomNavigationComponent';
let storage = LocalStorage.getShared();
... ... @@ -39,6 +40,10 @@ export struct BottomNavigationComponent {
* Component opacity value: 0.6.
*/
readonly SIXTY_OPACITY: number = 0.6;
// 接收指定频道跳转的参数
@State assignChannel: AssignChannelParam = new AssignChannelParam()
// 用于传参到顶导组件,【不用channelParam,主要是时序问题,需要先底导处理完,再延时触发顶导处理】
@State assignChannel1: AssignChannelParam = new AssignChannelParam()
async aboutToAppear() {
Logger.info(TAG, `aboutToAppear currentNavIndex: ${this.currentNavIndex}`);
... ... @@ -49,6 +54,16 @@ export struct BottomNavigationComponent {
bottomNav.bottomNavList = bottomNav.bottomNavList.filter(item => item.name !== '服务');
this.bottomNavList = bottomNav.bottomNavList
}
HomeChannelUtils.setBottomNavData(bottomNav)
EmitterUtils.receiveEvent(EmitterEventId.JUMP_HOME_CHANNEL, (str?: string) => {
Logger.debug(TAG, 'receiveEvent JUMP_HOME_CHANNEL: ' + str)
if (str) {
// 跳转指定频道场景,传参底导id、频道id
this.assignChannel = JSON.parse(str) as AssignChannelParam
this.changeBottomNav()
}
})
}
aboutToDisappear() {
... ... @@ -69,8 +84,8 @@ export struct BottomNavigationComponent {
topNavList: navItem.topNavChannelList.filter(item => item.channelId != 2073),
_currentNavIndex: $currentNavIndex,
currentBottomNavName: navItem.name,
barBackgroundColor: $barBackgroundColor
barBackgroundColor: $barBackgroundColor,
assignChannel: this.assignChannel1
})
}
... ... @@ -145,4 +160,30 @@ export struct BottomNavigationComponent {
// Logger.info(TAG, `onBottomNavigationDataUpdated currentNavIndex: ${this.currentNavIndex},length:${this.bottomNavItemList.length}`);
this.onBottomNavigationIndexChange()
}
/**
* 底导id变化,即指定频道跳转场景
*/
changeBottomNav() {
let index = -1
for (let i = 0; i < this.bottomNavList.length; i++) {
let bottomNavDTO: BottomNavDTO = this.bottomNavList[i]
if (bottomNavDTO.id.toString() === this.assignChannel.bottomNavId) {
index = i
break
}
}
if (index >= 0 && index != this.currentNavIndex) {
// 切底导
this.currentNavIndex = index
}
setTimeout(() => {
// 底导切换后,触发顶导切换
this.assignChannel1 = new AssignChannelParam()
this.assignChannel1.pageId = this.assignChannel.pageId
this.assignChannel1.channelId = this.assignChannel.channelId
this.assignChannel1.bottomNavId = this.assignChannel.bottomNavId
}, 20)
}
}
\ No newline at end of file
... ...
import { Action, CompDTO, Params, TopNavDTO } from 'wdBean';
import { LazyDataSource, Logger } from 'wdKit';
import { LazyDataSource, Logger, StringUtils } from 'wdKit';
import { ProcessUtils } from 'wdRouter';
import { PageComponent } from './PageComponent';
import { ChannelSubscriptionLayout } from './ChannelSubscriptionLayout';
... ... @@ -7,6 +7,7 @@ import { FirstTabTopSearchComponent } from '../search/FirstTabTopSearchComponent
import window from '@ohos.window';
import { WindowModel } from 'wdKit';
import { VideoChannelDetail } from 'wdDetailPlayShortVideo/Index';
import { AssignChannelParam } from 'wdRouter/src/main/ets/utils/HomeChannelUtils';
const TAG = 'TopNavigationComponent';
... ... @@ -49,6 +50,7 @@ export struct TopNavigationComponent {
// 地方频道列表
@State localChannelList: TopNavDTO[] = []
readonly MAX_LINE: number = 1;
@ObjectLink @Watch('onAssignChannelChange') assignChannel: AssignChannelParam
//处理新闻tab顶导频道数据
topNavListHandle() {
... ... @@ -308,4 +310,81 @@ export struct TopNavigationComponent {
onTopNavigationDataUpdated() {
Logger.info(TAG, `onTopNavigationDataUpdated currentTopNavIndex: ${this.currentTopNavSelectedIndex},topNavList.length:${this.topNavList.length}`);
}
/**
* 频道id变化,即指定频道跳转场景
*/
onAssignChannelChange() {
let channelId = this.assignChannel.channelId
let index = -1
if (this._currentNavIndex === 0) {
// 第一个,新闻,先拿我的,再拿其他
index = this.getChannelByMine(channelId)
if (index == -1) {
// 不在我的里,需要临时新增频道展示
let channel = this.getChannelByOthers(channelId)
if (channel) {
this.myChannelList.push(channel)
setTimeout(() => {
this.tabsController.changeIndex(this.myChannelList.length - 1)
}, 20)
}
} else {
// 直接切换
this.tabsController.changeIndex(index)
}
} else {
index = this.getChannelByTopNav(channelId)
if (index > -1) {
// 找到了,直接切换,否则不处理
this.tabsController.changeIndex(index)
}
}
}
/**
* 非新闻,从topNav里拿数据
*/
private getChannelByTopNav(channelId: string) {
for (let i = 0; i < this.topNavList.length; i++) {
let topNavDTO: TopNavDTO = this.topNavList[i]
if (topNavDTO.channelId.toString() === channelId) {
return i
}
}
return -1
}
/**
* 新闻,从myChannelList里拿数据
*/
private getChannelByMine(channelId: string) {
for (let i = 0; i < this.myChannelList.length; i++) {
let topNavDTO: TopNavDTO = this.myChannelList[i]
if (topNavDTO.channelId.toString() === channelId) {
return i
}
}
return -1
}
/**
* 新闻,从其他里拿数据
*/
private getChannelByOthers(channelId: string) {
for (let i = 0; i < this.moreChannelList.length; i++) {
let topNavDTO: TopNavDTO = this.moreChannelList[i]
if (topNavDTO.channelId.toString() === channelId) {
return topNavDTO
}
}
for (let j = 0; j < this.localChannelList.length; j++) {
let topNavDTO: TopNavDTO = this.localChannelList[j]
if (topNavDTO.channelId.toString() === channelId) {
return topNavDTO
}
}
return null
}
}
\ No newline at end of file
... ...