Showing
3 changed files
with
98 additions
and
34 deletions
| 1 | import { BottomNavDTO, NavigationDetailDTO, TopNavDTO } from 'wdBean'; | 1 | import { BottomNavDTO, NavigationDetailDTO, TopNavDTO } from 'wdBean'; |
| 2 | -import { Logger, NetworkUtil, SPHelper, ToastUtils, WindowModel } from 'wdKit'; | 2 | +import { Logger, NetworkUtil, SPHelper, ToastUtils } from 'wdKit'; |
| 3 | import { ProcessUtils, WDRouterPage, WDRouterRule } from 'wdRouter'; | 3 | import { ProcessUtils, WDRouterPage, WDRouterRule } from 'wdRouter'; |
| 4 | import { PageComponent } from './PageComponent'; | 4 | import { PageComponent } from './PageComponent'; |
| 5 | import { ChannelSubscriptionLayout } from './ChannelSubscriptionLayout'; | 5 | import { ChannelSubscriptionLayout } from './ChannelSubscriptionLayout'; |
| @@ -12,6 +12,8 @@ import DailyPaperTopicModel from '../../model/DailyPaperTopicModel'; | @@ -12,6 +12,8 @@ import DailyPaperTopicModel from '../../model/DailyPaperTopicModel'; | ||
| 12 | import { CompUtils } from '../../utils/CompUtils'; | 12 | import { CompUtils } from '../../utils/CompUtils'; |
| 13 | import ChannelViewModel from '../../viewmodel/ChannelViewModel'; | 13 | import ChannelViewModel from '../../viewmodel/ChannelViewModel'; |
| 14 | import { ColorUtils } from '../../utils/ColorUtils'; | 14 | import { ColorUtils } from '../../utils/ColorUtils'; |
| 15 | +import { ImageKnifeComponent } from '@ohos/imageknife'; | ||
| 16 | +import { CommonUtils } from '../../utils/CommonUtils'; | ||
| 15 | 17 | ||
| 16 | const TAG = 'TopNavigationComponent'; | 18 | const TAG = 'TopNavigationComponent'; |
| 17 | 19 | ||
| @@ -330,8 +332,10 @@ export struct TopNavigationComponentNew { | @@ -330,8 +332,10 @@ export struct TopNavigationComponentNew { | ||
| 330 | 332 | ||
| 331 | if (item.iconUrl && item.iconCUrl) { | 333 | if (item.iconUrl && item.iconCUrl) { |
| 332 | // 有图 | 334 | // 有图 |
| 333 | - Image(this.currentTopNavSelectedIndex === index ? item.iconUrl : item.iconCUrl) | 335 | + ImageKnifeComponent({ imageKnifeOption: CommonUtils.getTopImageKnifeOption(item, this.currentTopNavSelectedIndex === index) }) |
| 334 | .height(36) | 336 | .height(36) |
| 337 | + .width(CommonUtils.calTopTabWidth(36,item.iconUrlSize)) | ||
| 338 | + .enabled(false) | ||
| 335 | } else { | 339 | } else { |
| 336 | // 无图 | 340 | // 无图 |
| 337 | Text(item?.name) | 341 | Text(item?.name) |
| @@ -352,7 +356,6 @@ export struct TopNavigationComponentNew { | @@ -352,7 +356,6 @@ export struct TopNavigationComponentNew { | ||
| 352 | } | 356 | } |
| 353 | } | 357 | } |
| 354 | 358 | ||
| 355 | - | ||
| 356 | } | 359 | } |
| 357 | .hoverEffect(HoverEffect.Highlight) | 360 | .hoverEffect(HoverEffect.Highlight) |
| 358 | .constraintSize({ | 361 | .constraintSize({ |
| @@ -362,8 +365,8 @@ export struct TopNavigationComponentNew { | @@ -362,8 +365,8 @@ export struct TopNavigationComponentNew { | ||
| 362 | .height('100%') | 365 | .height('100%') |
| 363 | // .backgroundColor(Color.Transparent) | 366 | // .backgroundColor(Color.Transparent) |
| 364 | .padding({ | 367 | .padding({ |
| 365 | - left: $r('app.float.top_tab_item_padding_horizontal'), | ||
| 366 | - right: $r('app.float.top_tab_item_padding_horizontal'), | 368 | + left: item.iconUrl && item.iconCUrl ? 0 : $r('app.float.top_tab_item_padding_horizontal'), |
| 369 | + right: item.iconUrl && item.iconCUrl ? 0 : $r('app.float.top_tab_item_padding_horizontal'), | ||
| 367 | }) | 370 | }) |
| 368 | .justifyContent(FlexAlign.Center) | 371 | .justifyContent(FlexAlign.Center) |
| 369 | .id(`col_tabBar${index}`) | 372 | .id(`col_tabBar${index}`) |
| @@ -379,6 +382,8 @@ export struct TopNavigationComponentNew { | @@ -379,6 +382,8 @@ export struct TopNavigationComponentNew { | ||
| 379 | }) | 382 | }) |
| 380 | } | 383 | } |
| 381 | 384 | ||
| 385 | + | ||
| 386 | + | ||
| 382 | /** | 387 | /** |
| 383 | * 频道文字颜色 | 388 | * 频道文字颜色 |
| 384 | * @returns | 389 | * @returns |
| 1 | +import { ALL, ImageKnifeOption } from '@ohos/imageknife'; | ||
| 2 | +import { TopNavDTO } from 'wdBean/Index'; | ||
| 3 | + | ||
| 4 | +/** | ||
| 5 | + * 通用工具类,只记录处理build里面组件业务计算逻辑 | ||
| 6 | + */ | ||
| 7 | +export class CommonUtils{ | ||
| 8 | + | ||
| 9 | + | ||
| 10 | + /** | ||
| 11 | + * 获取顶部导航栏的频道option | ||
| 12 | + * @param item | ||
| 13 | + * @param isSelect | ||
| 14 | + * @returns | ||
| 15 | + */ | ||
| 16 | + public static getTopImageKnifeOption(item: TopNavDTO, isSelect: boolean): ImageKnifeOption { | ||
| 17 | + // let defaultIcon = this.getBottomLocalIcon(navItem, isSelect) | ||
| 18 | + let url = isSelect ? item.iconCUrl:item.iconUrl // this.getBottomIcon(navItem, isSelect) | ||
| 19 | + | ||
| 20 | + let imageKnifeOption: ImageKnifeOption = { | ||
| 21 | + loadSrc: url, | ||
| 22 | + // // 占位图使用本地资源 | ||
| 23 | + // placeholderSrc: defaultIcon, | ||
| 24 | + // // 失败占位图使用本地资源 | ||
| 25 | + // errorholderSrc: defaultIcon, | ||
| 26 | + // 是否开启一级内存缓存 | ||
| 27 | + isCacheable: true, | ||
| 28 | + // 磁盘缓存 | ||
| 29 | + strategy: new ALL(), | ||
| 30 | + gif: { | ||
| 31 | + playTimes: 1 | ||
| 32 | + } | ||
| 33 | + }; | ||
| 34 | + return imageKnifeOption | ||
| 35 | + } | ||
| 36 | + | ||
| 37 | + /** | ||
| 38 | + * 计算 频道tab 宽度 | ||
| 39 | + * @param height 已知高度 | ||
| 40 | + * @returns | ||
| 41 | + */ | ||
| 42 | + public static calTopTabWidth(height:number,scale:string):number{ | ||
| 43 | + if(scale){ | ||
| 44 | + | ||
| 45 | + if(scale.includes('*')){ | ||
| 46 | + let scaleArray = scale.split('*'); | ||
| 47 | + return height*Number.parseInt(scaleArray[0])/parseInt(scaleArray[1]) | ||
| 48 | + } | ||
| 49 | + } | ||
| 50 | + return height*210/60 | ||
| 51 | + | ||
| 52 | + } | ||
| 53 | + | ||
| 54 | +} |
| @@ -2,15 +2,16 @@ | @@ -2,15 +2,16 @@ | ||
| 2 | * 视频频道,包含视频和直播 | 2 | * 视频频道,包含视频和直播 |
| 3 | * 视频为沉浸式,直播同新闻页面 | 3 | * 视频为沉浸式,直播同新闻页面 |
| 4 | */ | 4 | */ |
| 5 | -import { BottomNavDTO, TopNavDTO } from 'wdBean/Index' | 5 | +import { BottomNavDTO, TopNavDTO } from 'wdBean/Index'; |
| 6 | import { VideoChannelDetail } from 'wdDetailPlayShortVideo/Index'; | 6 | import { VideoChannelDetail } from 'wdDetailPlayShortVideo/Index'; |
| 7 | import { WDRouterPage, WDRouterRule } from 'wdRouter'; | 7 | import { WDRouterPage, WDRouterRule } from 'wdRouter'; |
| 8 | import { DisplayDirection } from 'wdConstant/Index'; | 8 | import { DisplayDirection } from 'wdConstant/Index'; |
| 9 | import { CompUtils, PageComponent } from 'wdComponent/Index'; | 9 | import { CompUtils, PageComponent } from 'wdComponent/Index'; |
| 10 | -import { TrackingButton, TrackConstants } from 'wdTracking/Index'; | ||
| 11 | -import { Logger, WindowModel } from 'wdKit'; | ||
| 12 | -import { ParamType, Tracking } from 'wdTracking/Index'; | 10 | +import { ParamType, TrackConstants, Tracking, TrackingButton } from 'wdTracking/Index'; |
| 11 | +import { Logger } from 'wdKit'; | ||
| 13 | import { ColorUtils } from 'wdComponent/src/main/ets/utils/ColorUtils'; | 12 | import { ColorUtils } from 'wdComponent/src/main/ets/utils/ColorUtils'; |
| 13 | +import { ImageKnifeComponent } from '@ohos/imageknife'; | ||
| 14 | +import { CommonUtils } from 'wdComponent/src/main/ets/utils/CommonUtils'; | ||
| 14 | 15 | ||
| 15 | const TAG = 'VideoChannelPage' | 16 | const TAG = 'VideoChannelPage' |
| 16 | 17 | ||
| @@ -39,7 +40,6 @@ export struct VideoChannelPage { | @@ -39,7 +40,6 @@ export struct VideoChannelPage { | ||
| 39 | navItem: BottomNavDTO = {} as BottomNavDTO | 40 | navItem: BottomNavDTO = {} as BottomNavDTO |
| 40 | // 背景高度 | 41 | // 背景高度 |
| 41 | @State backgroundImageH: number = 0 | 42 | @State backgroundImageH: number = 0 |
| 42 | - | ||
| 43 | @Consume @Watch('setBarBackgroundColor') pageShow: number | 43 | @Consume @Watch('setBarBackgroundColor') pageShow: number |
| 44 | 44 | ||
| 45 | async aboutToAppear() { | 45 | async aboutToAppear() { |
| @@ -48,7 +48,6 @@ export struct VideoChannelPage { | @@ -48,7 +48,6 @@ export struct VideoChannelPage { | ||
| 48 | this.setBarBackgroundColor() | 48 | this.setBarBackgroundColor() |
| 49 | } | 49 | } |
| 50 | 50 | ||
| 51 | - | ||
| 52 | /** | 51 | /** |
| 53 | * 顶导、底导切换下标都到改变背景色,进入或退出沉浸式 | 52 | * 顶导、底导切换下标都到改变背景色,进入或退出沉浸式 |
| 54 | */ | 53 | */ |
| @@ -57,16 +56,15 @@ export struct VideoChannelPage { | @@ -57,16 +56,15 @@ export struct VideoChannelPage { | ||
| 57 | if (this.isImmerseChannel() && CompUtils.isVideo(this.currentBottomNavInfo)) { | 56 | if (this.isImmerseChannel() && CompUtils.isVideo(this.currentBottomNavInfo)) { |
| 58 | this.barBackgroundColor = Color.Black | 57 | this.barBackgroundColor = Color.Black |
| 59 | this.isImmersive = true | 58 | this.isImmersive = true |
| 60 | - ColorUtils.changeTopStatusBarColor(0,0)// 沉浸页面顶部导航栏颜色固定黑色 | 59 | + ColorUtils.changeTopStatusBarColor(0, 0) // 沉浸页面顶部导航栏颜色固定黑色 |
| 61 | } else { | 60 | } else { |
| 62 | this.isImmersive = false | 61 | this.isImmersive = false |
| 63 | this.barBackgroundColor = Color.White | 62 | this.barBackgroundColor = Color.White |
| 64 | - ColorUtils.changeTopStatusBarColor(this.navItem.statusBarColor,1) | 63 | + ColorUtils.changeTopStatusBarColor(this.navItem.statusBarColor, 1) |
| 65 | } | 64 | } |
| 66 | 65 | ||
| 67 | } | 66 | } |
| 68 | 67 | ||
| 69 | - | ||
| 70 | /** | 68 | /** |
| 71 | * 得到顶导文字颜色 | 69 | * 得到顶导文字颜色 |
| 72 | * @param item | 70 | * @param item |
| @@ -114,28 +112,35 @@ export struct VideoChannelPage { | @@ -114,28 +112,35 @@ export struct VideoChannelPage { | ||
| 114 | Row() { | 112 | Row() { |
| 115 | ForEach(this.topNavList, (item: TopNavDTO, index: number) => { | 113 | ForEach(this.topNavList, (item: TopNavDTO, index: number) => { |
| 116 | Column() { | 114 | Column() { |
| 117 | - | ||
| 118 | - Text(item.name) | ||
| 119 | - .fontSize($r('app.float.selected_text_size')) | ||
| 120 | - .fontWeight(this.currentTopNavSelectedIndex === index ? FontWeight.Bold : FontWeight.Normal) | ||
| 121 | - .fontColor(this.getTopNavFontColor(item, index)) | ||
| 122 | - .padding({ | ||
| 123 | - top: $r('app.float.top_tab_item_padding_top'), | ||
| 124 | - bottom: $r('app.float.top_tab_item_padding_bottom') | 115 | + if (item.iconUrl && item.iconCUrl) { |
| 116 | + // 有图 | ||
| 117 | + ImageKnifeComponent({ | ||
| 118 | + imageKnifeOption: CommonUtils.getTopImageKnifeOption(item, this.currentTopNavSelectedIndex === index) | ||
| 125 | }) | 119 | }) |
| 126 | - .maxLines(this.MAX_LINE) | ||
| 127 | - | ||
| 128 | - | ||
| 129 | - Image($r('app.media.icon_channel_active')) | ||
| 130 | - // .colorFilter(ColorUtils.getDrawingColorFilter(this.getBothColor(""))) | ||
| 131 | - .width(20) | ||
| 132 | - .height(3).visibility(this.currentTopNavSelectedIndex === index ? Visibility.Visible : Visibility.Hidden) | ||
| 133 | - | 120 | + .height(36) |
| 121 | + .width(CommonUtils.calTopTabWidth(36, item.iconUrlSize)) | ||
| 122 | + .enabled(false) | ||
| 123 | + } else { | ||
| 124 | + Text(item.name) | ||
| 125 | + .fontSize($r('app.float.selected_text_size')) | ||
| 126 | + .fontWeight(this.currentTopNavSelectedIndex === index ? FontWeight.Bold : FontWeight.Normal) | ||
| 127 | + .fontColor(this.getTopNavFontColor(item, index)) | ||
| 128 | + .padding({ | ||
| 129 | + top: $r('app.float.top_tab_item_padding_top'), | ||
| 130 | + bottom: $r('app.float.top_tab_item_padding_bottom') | ||
| 131 | + }) | ||
| 132 | + .maxLines(this.MAX_LINE) | ||
| 133 | + | ||
| 134 | + Image($r('app.media.icon_channel_active'))// .colorFilter(ColorUtils.getDrawingColorFilter(this.getBothColor(""))) | ||
| 135 | + .width(20) | ||
| 136 | + .height(3) | ||
| 137 | + .visibility(this.currentTopNavSelectedIndex === index ? Visibility.Visible : Visibility.Hidden) | ||
| 134 | 138 | ||
| 139 | + } | ||
| 135 | } | 140 | } |
| 136 | .padding({ | 141 | .padding({ |
| 137 | - left: $r('app.float.top_tab_item_padding_horizontal'), | ||
| 138 | - right: $r('app.float.top_tab_item_padding_horizontal'), | 142 | + left: item.iconUrl && item.iconCUrl ? 0 : $r('app.float.top_tab_item_padding_horizontal'), |
| 143 | + right: item.iconUrl && item.iconCUrl ? 0 : $r('app.float.top_tab_item_padding_horizontal'), | ||
| 139 | }) | 144 | }) |
| 140 | .onClick(() => { | 145 | .onClick(() => { |
| 141 | // 视频tab埋点 | 146 | // 视频tab埋点 |
| @@ -197,7 +202,7 @@ export struct VideoChannelPage { | @@ -197,7 +202,7 @@ export struct VideoChannelPage { | ||
| 197 | * 检测是否是沉浸式频道 | 202 | * 检测是否是沉浸式频道 |
| 198 | * @returns | 203 | * @returns |
| 199 | */ | 204 | */ |
| 200 | - isImmerseChannel():boolean{ | 205 | + isImmerseChannel(): boolean { |
| 201 | 206 | ||
| 202 | return this.navItem.topNavChannelList[this.currentTopNavSelectedIndex].channelStyle === 1; | 207 | return this.navItem.topNavChannelList[this.currentTopNavSelectedIndex].channelStyle === 1; |
| 203 | } | 208 | } |
| @@ -215,7 +220,7 @@ export struct VideoChannelPage { | @@ -215,7 +220,7 @@ export struct VideoChannelPage { | ||
| 215 | pageSwiperView() { | 220 | pageSwiperView() { |
| 216 | Swiper(this.swiperController) { | 221 | Swiper(this.swiperController) { |
| 217 | ForEach(this.topNavList, (item: TopNavDTO, index: number) => { | 222 | ForEach(this.topNavList, (item: TopNavDTO, index: number) => { |
| 218 | - if (item.channelStyle===1) { | 223 | + if (item.channelStyle === 1) { |
| 219 | // 视频 | 224 | // 视频 |
| 220 | VideoChannelDetail({ | 225 | VideoChannelDetail({ |
| 221 | bottomNavIndex: $_currentNavIndex, | 226 | bottomNavIndex: $_currentNavIndex, |
-
Please register or login to post a comment