zhangbo1_wd

顶导添加判空保护

... ... @@ -35,6 +35,9 @@ export struct TopNavigationComponent {
@Link _currentNavIndex?: number;
// 顶导当前选中/焦点下标
@State currentTopNavSelectedIndex: number = 0;
/**
* @deprecated TODO,没地方用到,是否弃用
*/
@State currentTopNavName: string = '';
@State currentTopNavItem: TopNavDTO = {} as TopNavDTO
// 顶导数据
... ... @@ -154,7 +157,7 @@ export struct TopNavigationComponent {
// 崩溃
// this.currentTopNavName = this._currentNavIndex === 0 ? this.myChannelList[0].name : this.topNavList[0].name
if (this._currentNavIndex === 0 && this.myChannelList && this.myChannelList.length > 0 &&
if (this._currentNavIndex === 0 && this.myChannelList && this.myChannelList.length > 0 && this.myChannelList[0] &&
this.myChannelList[0].name) {
this.currentTopNavName = this.myChannelList[0].name
} else if (this._currentNavIndex != 0 && this.topNavList && this.topNavList.length > 0 && this.topNavList[0].name) {
... ... @@ -170,19 +173,19 @@ export struct TopNavigationComponent {
this.currentTopNavItem = this.myChannelList[this.currentTopNavSelectedIndex]
}
isBroadcast(item: TopNavDTO) {
isBroadcast(item?: TopNavDTO) {
// TODO 用id channelId = '2066'
return item.name === '播报'
return item?.name === '播报'
}
isLayout(item: TopNavDTO) {
isLayout(item?: TopNavDTO) {
// TODO 用id channelId = '2006'
return item.name === '版面'
return item?.name === '版面'
}
isSpecialChannel(item: TopNavDTO) {
isSpecialChannel(item?: TopNavDTO) {
// 版面、播报,可以用这个判断
return item.channelType === 3
return item?.channelType === 3
}
... ... @@ -374,7 +377,7 @@ export struct TopNavigationComponent {
@Builder
tabBarBuilder(item: TopNavDTO, index: number) {
Column() {
Text(item.name)
Text(item?.name)
.fontSize($r('app.float.selected_text_size'))
.fontWeight(this.currentTopNavSelectedIndex === index ? FontWeight.Bold : FontWeight.Normal)
.fontColor(this.currentTopNavSelectedIndex === index ? Color.Black : "#999999")
... ...