Showing
3 changed files
with
10 additions
and
615 deletions
| @@ -14,8 +14,6 @@ export { PageComponent } from "./src/main/ets/components/page/PageComponent" | @@ -14,8 +14,6 @@ export { PageComponent } from "./src/main/ets/components/page/PageComponent" | ||
| 14 | 14 | ||
| 15 | export { LikeComponent } from "./src/main/ets/components/view/LikeComponent" | 15 | export { LikeComponent } from "./src/main/ets/components/view/LikeComponent" |
| 16 | 16 | ||
| 17 | -export { TopNavigationComponent } from "./src/main/ets/components/page/TopNavigationComponent" | ||
| 18 | - | ||
| 19 | export { TopNavigationComponentNew } from "./src/main/ets/components/page/TopNavigationComponentNew" | 17 | export { TopNavigationComponentNew } from "./src/main/ets/components/page/TopNavigationComponentNew" |
| 20 | 18 | ||
| 21 | export { LabelComponent } from "./src/main/ets/components/view/LabelComponent" | 19 | export { LabelComponent } from "./src/main/ets/components/view/LabelComponent" |
sight_harmony/features/wdComponent/src/main/ets/components/page/TopNavigationComponent.ets
deleted
100644 → 0
| 1 | -import { BottomNavDTO, CompDTO, TopNavDTO } from 'wdBean'; | ||
| 2 | -import { SpConstants } from 'wdConstant'; | ||
| 3 | -import { DisplayUtils, LazyDataSource, Logger, NetworkUtil, SPHelper, ToastUtils } from 'wdKit'; | ||
| 4 | -import { ProcessUtils, WDRouterPage, WDRouterRule } from 'wdRouter'; | ||
| 5 | -import { PageComponent } from './PageComponent'; | ||
| 6 | -import { ChannelSubscriptionLayout } from './ChannelSubscriptionLayout'; | ||
| 7 | -import { FirstTabTopSearchComponent } from '../search/FirstTabTopSearchComponent'; | ||
| 8 | -import { AssignChannelParam } from 'wdRouter/src/main/ets/utils/HomeChannelUtils'; | ||
| 9 | -import { PeopleShipMainComponent } from '../peopleShip/PeopleShipMainComponent'; | ||
| 10 | -import { channelSkeleton } from '../skeleton/channelSkeleton'; | ||
| 11 | -import { TrackingButton, TrackConstants } from 'wdTracking/Index'; | ||
| 12 | - | ||
| 13 | -const TAG = 'TopNavigationComponent'; | ||
| 14 | - | ||
| 15 | -PersistentStorage.persistProp('channelIds', ''); | ||
| 16 | -PersistentStorage.persistProp('indexSettingChannelId', 2002); | ||
| 17 | - | ||
| 18 | -const storage = LocalStorage.getShared(); | ||
| 19 | - | ||
| 20 | -/** | ||
| 21 | - * 顶部页签导航栏/顶导 | ||
| 22 | - */ | ||
| 23 | -@Entry(storage) | ||
| 24 | -@Component | ||
| 25 | -export struct TopNavigationComponent { | ||
| 26 | - private groupId: number = 0 | ||
| 27 | - private currentBottomNavName: string = '' | ||
| 28 | - private tabsController: TabsController = new TabsController() | ||
| 29 | - @Consume isLayoutFullScreen: boolean | ||
| 30 | - @Consume bottomRectHeight: number | ||
| 31 | - @Consume topRectHeight: number | ||
| 32 | - @Consume currentBottomNavInfo: BottomNavDTO // 当前底导信息 | ||
| 33 | - @Consume barBackgroundColor: Color | ||
| 34 | - @State bottomSafeHeight: number = AppStorage.get<number>('bottomSafeHeight') || 0 | ||
| 35 | - @State topSafeHeight: number = AppStorage.get<number>('topSafeHeight') || 0 | ||
| 36 | - @Link _currentNavIndex?: number; | ||
| 37 | - // 顶导当前选中/焦点下标 | ||
| 38 | - @State currentTopNavSelectedIndex: number = 0; | ||
| 39 | - /** | ||
| 40 | - * @deprecated TODO,没地方用到,是否弃用 | ||
| 41 | - */ | ||
| 42 | - @State currentTopNavName: string = ''; | ||
| 43 | - @State currentTopNavItem: TopNavDTO = {} as TopNavDTO | ||
| 44 | - // 顶导数据 | ||
| 45 | - @State @Watch('onTopNavigationDataUpdated') topNavList: TopNavDTO[] = [] | ||
| 46 | - @State compList: LazyDataSource<CompDTO> = new LazyDataSource(); | ||
| 47 | - @StorageProp('indexSettingChannelId') indexSettingChannelId: number = 2002 | ||
| 48 | - //我的频道id列表 | ||
| 49 | - @State channelIds: number[] = [] | ||
| 50 | - //本地缓存频道id列表 | ||
| 51 | - @StorageProp('channelIds') storageChannelIds: string = '' | ||
| 52 | - @State homeChannelList: TopNavDTO[] = [] | ||
| 53 | - // 我的频道列表 | ||
| 54 | - @State myChannelList: TopNavDTO[] = [] | ||
| 55 | - // 更多频道列表 | ||
| 56 | - @State moreChannelList: TopNavDTO[] = [] | ||
| 57 | - // 地方频道列表 | ||
| 58 | - @State localChannelList: TopNavDTO[] = [] | ||
| 59 | - readonly MAX_LINE: number = 1; | ||
| 60 | - @ObjectLink @Watch('onAssignChannelChange') assignChannel: AssignChannelParam | ||
| 61 | - // 底导传递过来的自动刷新通知 | ||
| 62 | - @Prop @Watch('onAutoRefresh') autoRefresh: number = 0 | ||
| 63 | - // 传递给page的自动刷新通知 | ||
| 64 | - @State autoRefresh2Page: number = 0 | ||
| 65 | - // 当前底导index | ||
| 66 | - @State navIndex: number = 0 | ||
| 67 | - @State animationDuration: number = 0 | ||
| 68 | - @State indicatorLeftMargin: number = 0 | ||
| 69 | - @State indicatorWidth: number = 0 | ||
| 70 | - private tabsWidth: number = 0 | ||
| 71 | - // 标识,是否为点击触发的tab切换,临时变量 | ||
| 72 | - private changeByClick: boolean = false | ||
| 73 | - | ||
| 74 | - //处理新闻tab顶导频道数据 | ||
| 75 | - topNavListHandle() { | ||
| 76 | - let cityName = SPHelper.default.getSync(SpConstants.LOCATION_CITY_NAME, '') as string | ||
| 77 | - | ||
| 78 | - let _channelIds: number [] = [] | ||
| 79 | - let _myChannelList: TopNavDTO [] = [] | ||
| 80 | - let _storageChannelIds: string [] = [] //list1 | ||
| 81 | - let defaultMyChannelList: TopNavDTO[] = [] | ||
| 82 | - let defaultList = [...this.topNavList] | ||
| 83 | - defaultList.sort((a, b) => { | ||
| 84 | - return a.num - b.num; | ||
| 85 | - }); | ||
| 86 | - | ||
| 87 | - //defaultMyChannelList | ||
| 88 | - defaultList.forEach(item => { | ||
| 89 | - if (item.defaultPermitted === 1 || item.movePermitted === 0 || item.delPermitted === 0 || | ||
| 90 | - item.headlinesOn === 1) { | ||
| 91 | - defaultMyChannelList.push(item); | ||
| 92 | - } | ||
| 93 | - if (item.defaultPermitted === 1) { | ||
| 94 | - this.homeChannelList.push(item) | ||
| 95 | - } | ||
| 96 | - }) | ||
| 97 | - | ||
| 98 | - //有缓存频道id | ||
| 99 | - if (this.storageChannelIds) { | ||
| 100 | - _storageChannelIds = this.storageChannelIds.split(',') | ||
| 101 | - } | ||
| 102 | - | ||
| 103 | - defaultMyChannelList.forEach(item => { | ||
| 104 | - item.myChannel = '1' | ||
| 105 | - if (item.defaultPermitted === 1) { | ||
| 106 | - item.homeChannel = '1' | ||
| 107 | - } | ||
| 108 | - let index = defaultList.findIndex(_item => _item.channelId === item.channelId) | ||
| 109 | - if (index !== -1) { | ||
| 110 | - defaultList.splice(index, 1) | ||
| 111 | - } | ||
| 112 | - }) | ||
| 113 | - defaultList.unshift(...defaultMyChannelList) | ||
| 114 | - | ||
| 115 | - defaultList.forEach((item, index) => { | ||
| 116 | - if (this.storageChannelIds && _storageChannelIds.includes(String(item.channelId))) { | ||
| 117 | - item.myChannel = '1' | ||
| 118 | - } | ||
| 119 | - if (item.channelType === 2) { | ||
| 120 | - if (cityName.includes(item.name)) { | ||
| 121 | - item.myChannel = '1' | ||
| 122 | - } | ||
| 123 | - item.localChannel = '1' | ||
| 124 | - } | ||
| 125 | - if (index >= 11) { | ||
| 126 | - if (item.channelType === 1) { | ||
| 127 | - item.moreChannel = '1' | ||
| 128 | - } | ||
| 129 | - } else { | ||
| 130 | - if (item.channelType === 1 && item.myChannel !== '1') { | ||
| 131 | - item.moreChannel = '1' | ||
| 132 | - } | ||
| 133 | - } | ||
| 134 | - | ||
| 135 | - //频道分类 | ||
| 136 | - if (item.name !== '播报') { //暂时隐藏播报 | ||
| 137 | - if (item.myChannel === '1') { | ||
| 138 | - _myChannelList.push(item) | ||
| 139 | - _channelIds.push(item.channelId) | ||
| 140 | - } else if (item.moreChannel === '1') { | ||
| 141 | - this.moreChannelList.push(item) | ||
| 142 | - } else if (item.localChannel === '1' && item.myChannel !== '1') { | ||
| 143 | - this.localChannelList.push(item) | ||
| 144 | - } | ||
| 145 | - } | ||
| 146 | - | ||
| 147 | - }) | ||
| 148 | - | ||
| 149 | - if (cityName) { | ||
| 150 | - let index = _myChannelList.findIndex(ele => cityName.includes(ele.name)) | ||
| 151 | - const localChannelitem = _myChannelList.splice(index, 1)[0]; | ||
| 152 | - // 将当前地区频道插入到第四个 | ||
| 153 | - _myChannelList.splice(3, 0, localChannelitem); | ||
| 154 | - } | ||
| 155 | - | ||
| 156 | - this.channelIds = _channelIds | ||
| 157 | - this.myChannelList = _myChannelList | ||
| 158 | - | ||
| 159 | - // 崩溃 | ||
| 160 | - // this.currentTopNavName = this._currentNavIndex === 0 ? this.myChannelList[0].name : this.topNavList[0].name | ||
| 161 | - if (this._currentNavIndex === 0 && this.myChannelList && this.myChannelList.length > 0 && this.myChannelList[0] && | ||
| 162 | - this.myChannelList[0].name) { | ||
| 163 | - this.currentTopNavName = this.myChannelList[0].name | ||
| 164 | - } else if (this._currentNavIndex != 0 && this.topNavList && this.topNavList.length > 0 && this.topNavList[0].name) { | ||
| 165 | - this.currentTopNavName = this.topNavList[0].name | ||
| 166 | - } | ||
| 167 | - | ||
| 168 | - //缓存首页频道 | ||
| 169 | - let index = this.myChannelList.findIndex(_item => _item?.channelId === this.indexSettingChannelId) | ||
| 170 | - if (index > -1) { | ||
| 171 | - this.currentTopNavSelectedIndex = index | ||
| 172 | - this.currentTopNavName = this.myChannelList[index].name | ||
| 173 | - } | ||
| 174 | - this.currentTopNavItem = this.myChannelList[this.currentTopNavSelectedIndex] | ||
| 175 | - } | ||
| 176 | - | ||
| 177 | - isBroadcast(item?: TopNavDTO) { | ||
| 178 | - // TODO 用id channelId = '2066' | ||
| 179 | - return item?.name === '播报' | ||
| 180 | - } | ||
| 181 | - | ||
| 182 | - isLayout(item?: TopNavDTO) { | ||
| 183 | - // TODO 用id channelId = '2006' | ||
| 184 | - return item?.name === '版面' | ||
| 185 | - } | ||
| 186 | - | ||
| 187 | - isSpecialChannel(item?: TopNavDTO) { | ||
| 188 | - // 版面、播报,可以用这个判断 | ||
| 189 | - return item?.channelType === 3 | ||
| 190 | - } | ||
| 191 | - | ||
| 192 | - | ||
| 193 | - build() { | ||
| 194 | - Column() { | ||
| 195 | - // 顶部搜索、日报logo、早晚报 | ||
| 196 | - Column() { | ||
| 197 | - Row() { | ||
| 198 | - FirstTabTopSearchComponent() | ||
| 199 | - | ||
| 200 | - Image($r('app.media.icon_ren_min_ri_bao')) | ||
| 201 | - .width(72) | ||
| 202 | - .height(29) | ||
| 203 | - .onClick(() => { | ||
| 204 | - ProcessUtils.gotoENewsPaper() | ||
| 205 | - }) | ||
| 206 | - Stack({ alignContent: Alignment.Center }) { | ||
| 207 | - Image($r('app.media.background_read_paper_home')) | ||
| 208 | - .width('100%') | ||
| 209 | - .height('100%') | ||
| 210 | - .objectFit(ImageFit.Contain) | ||
| 211 | - Row() { | ||
| 212 | - Image($r('app.media.icon_read_paper_home')) | ||
| 213 | - .width(18) | ||
| 214 | - .height(18) | ||
| 215 | - Text('早晚报') | ||
| 216 | - .fontColor("#666666") | ||
| 217 | - .fontSize($r('app.float.font_size_13')) | ||
| 218 | - } | ||
| 219 | - .alignItems(VerticalAlign.Center) | ||
| 220 | - .justifyContent(FlexAlign.Center) | ||
| 221 | - } | ||
| 222 | - .height(30) | ||
| 223 | - .width(124) | ||
| 224 | - .onClick(() => { | ||
| 225 | - if (NetworkUtil.isNetConnected()) { | ||
| 226 | - ProcessUtils.gotoMorningEveningPaper() | ||
| 227 | - } else { | ||
| 228 | - ToastUtils.showToast('网络出小差了,请检查网络后重试', 1000) | ||
| 229 | - } | ||
| 230 | - }) | ||
| 231 | - }.width('100%') | ||
| 232 | - .justifyContent(FlexAlign.SpaceBetween) | ||
| 233 | - } | ||
| 234 | - .width('100%') | ||
| 235 | - .height(40) | ||
| 236 | - .padding({ top: 10 }) | ||
| 237 | - .backgroundColor($r('app.color.white')) | ||
| 238 | - .visibility(this._currentNavIndex == 0 ? Visibility.Visible : Visibility.None) | ||
| 239 | - | ||
| 240 | - // 频道分类list | ||
| 241 | - Stack({ alignContent: Alignment.TopEnd }) { | ||
| 242 | - Tabs({ index: this.currentTopNavSelectedIndex, controller: this.tabsController }) { | ||
| 243 | - ForEach(this.currentBottomNavName === '新闻' ? this.myChannelList : this.topNavList, | ||
| 244 | - (navItem: TopNavDTO, index: number) => { | ||
| 245 | - TabContent() { | ||
| 246 | - if (this.currentBottomNavName === '人民号' && navItem.name === '关注') { | ||
| 247 | - PeopleShipMainComponent({ | ||
| 248 | - currentTopNavSelectedIndex: $currentTopNavSelectedIndex, | ||
| 249 | - navIndex: index, | ||
| 250 | - pageId: navItem.pageId + '', | ||
| 251 | - channelId: navItem.channelId + '', | ||
| 252 | - }) | ||
| 253 | - } else | ||
| 254 | - if (!this.isBroadcast(navItem) && !this.isLayout(navItem)) { | ||
| 255 | - PageComponent({ | ||
| 256 | - currentTopNavSelectedIndex: $currentTopNavSelectedIndex, | ||
| 257 | - navIndex: index, | ||
| 258 | - pageId: navItem.pageId + '', | ||
| 259 | - channelId: navItem.channelId + '', | ||
| 260 | - autoRefresh: this.autoRefresh2Page | ||
| 261 | - }) | ||
| 262 | - } else { | ||
| 263 | - channelSkeleton() | ||
| 264 | - } | ||
| 265 | - } | ||
| 266 | - .tabBar(this.tabBarBuilder(navItem, index)) | ||
| 267 | - | ||
| 268 | - }, (navItem: TopNavDTO) => JSON.stringify(navItem)); | ||
| 269 | - } | ||
| 270 | - .barHeight($r('app.float.top_tab_bar_height')) | ||
| 271 | - .height(this._currentNavIndex == 0 ? DisplayUtils.getDeviceHeight() - vp2px(48.3) : | ||
| 272 | - '100%') | ||
| 273 | - .barMode(BarMode.Scrollable) | ||
| 274 | - .vertical(false) | ||
| 275 | - .barBackgroundColor(this.barBackgroundColor) | ||
| 276 | - .onAreaChange((oldValue: Area, newValue: Area) => { | ||
| 277 | - let width = Number.parseFloat(newValue.width.toString()) | ||
| 278 | - this.tabsWidth = Number.isNaN(width) ? 0 : width | ||
| 279 | - }) | ||
| 280 | - .onChange((index: number) => { | ||
| 281 | - this.currentTopNavName = | ||
| 282 | - this._currentNavIndex === 0 ? this.myChannelList[index].name : this.topNavList[index].name | ||
| 283 | - Logger.info(TAG, `onChange index : ${index}`); | ||
| 284 | - if (!this.isBroadcast(this._currentNavIndex === 0 ? this.myChannelList[index] : this.topNavList[index]) && | ||
| 285 | - !this.isLayout(this._currentNavIndex === 0 ? this.myChannelList[index] : this.topNavList[index]) | ||
| 286 | - ) { | ||
| 287 | - //在 tab 切换之前意图共享 | ||
| 288 | - // this.topNavInsightIntentShare(this.currentTopNavItem) | ||
| 289 | - | ||
| 290 | - this.currentTopNavSelectedIndex = index; | ||
| 291 | - this.currentTopNavItem = this.myChannelList[index] | ||
| 292 | - } | ||
| 293 | - if (this.isBroadcast(this._currentNavIndex === 0 ? this.myChannelList[index] : this.topNavList[index])) { | ||
| 294 | - // 跳转到播报页面 | ||
| 295 | - ProcessUtils.gotoBroadcastPage(this.myChannelList[index].pageId) | ||
| 296 | - this.tabsController.changeIndex(this.currentTopNavSelectedIndex) | ||
| 297 | - } | ||
| 298 | - if (this.isLayout(this._currentNavIndex === 0 ? this.myChannelList[index] : this.topNavList[index])) { | ||
| 299 | - ProcessUtils.gotoENewsPaper() | ||
| 300 | - if (!this.changeByClick) { | ||
| 301 | - // 识别左滑右滑,跳过版面,到下一个 | ||
| 302 | - let nextIndex = this.currentTopNavSelectedIndex > index ? index - 1 : index + 1 | ||
| 303 | - this.tabsController.changeIndex(nextIndex) | ||
| 304 | - } else { | ||
| 305 | - this.tabsController.changeIndex(this.currentTopNavSelectedIndex) | ||
| 306 | - // 重置标识 | ||
| 307 | - this.changeByClick = false | ||
| 308 | - } | ||
| 309 | - } | ||
| 310 | - }) | ||
| 311 | - // .onAnimationStart((index: number, targetIndex: number, event: TabsAnimationEvent) => { | ||
| 312 | - // if (!this.isBroadcast(this._currentNavIndex === 0 ? this.myChannelList[index] : this.topNavList[index]) && | ||
| 313 | - // !this.isLayout(this._currentNavIndex === 0 ? this.myChannelList[index] : this.topNavList[index]) | ||
| 314 | - // ) { | ||
| 315 | - // return | ||
| 316 | - // } | ||
| 317 | - // this.currentTopNavSelectedIndex = targetIndex | ||
| 318 | - // // 切换动画开始时触发该回调。下划线跟着页面一起滑动,同时宽度渐变。 | ||
| 319 | - // let targetIndexInfo = this.getTextInfo(targetIndex) | ||
| 320 | - // this.startAnimateTo(this.animationDuration, targetIndexInfo.left, targetIndexInfo.width) | ||
| 321 | - // }) | ||
| 322 | - // .onAnimationEnd((index: number, event: TabsAnimationEvent) => { | ||
| 323 | - // if (!this.isBroadcast(this._currentNavIndex === 0 ? this.myChannelList[index] : this.topNavList[index]) && | ||
| 324 | - // !this.isLayout(this._currentNavIndex === 0 ? this.myChannelList[index] : this.topNavList[index]) | ||
| 325 | - // ) { | ||
| 326 | - // return | ||
| 327 | - // } | ||
| 328 | - // // 切换动画结束时触发该回调。下划线动画停止。 | ||
| 329 | - // let currentIndicatorInfo = this.getCurrentIndicatorInfo(index, event) | ||
| 330 | - // this.startAnimateTo(0, currentIndicatorInfo.left, currentIndicatorInfo.width) | ||
| 331 | - // }) | ||
| 332 | - // .onGestureSwipe((index: number, event: TabsAnimationEvent) => { | ||
| 333 | - // if (!this.isBroadcast(this._currentNavIndex === 0 ? this.myChannelList[index] : this.topNavList[index]) && | ||
| 334 | - // !this.isLayout(this._currentNavIndex === 0 ? this.myChannelList[index] : this.topNavList[index]) | ||
| 335 | - // ) { | ||
| 336 | - // return | ||
| 337 | - // } | ||
| 338 | - // // 在页面跟手滑动过程中,逐帧触发该回调。 | ||
| 339 | - // let currentIndicatorInfo = this.getCurrentIndicatorInfo(index, event) | ||
| 340 | - // this.currentTopNavSelectedIndex = currentIndicatorInfo.index | ||
| 341 | - // this.indicatorLeftMargin = currentIndicatorInfo.left | ||
| 342 | - // this.indicatorWidth = currentIndicatorInfo.width | ||
| 343 | - // }) | ||
| 344 | - | ||
| 345 | - // 分类列表最右侧频道设置 | ||
| 346 | - if (this._currentNavIndex === 0) { | ||
| 347 | - ChannelSubscriptionLayout({ | ||
| 348 | - currentTopNavSelectedIndex: $currentTopNavSelectedIndex, | ||
| 349 | - indexSettingChannelId: this.indexSettingChannelId, | ||
| 350 | - homeChannelList: this.homeChannelList, | ||
| 351 | - myChannelList: $myChannelList, | ||
| 352 | - moreChannelList: $moreChannelList, | ||
| 353 | - localChannelList: $localChannelList, | ||
| 354 | - channelIds: $channelIds, | ||
| 355 | - changeTab: (index) => { | ||
| 356 | - this.tabsController.changeIndex(index) | ||
| 357 | - } | ||
| 358 | - }) | ||
| 359 | - } else { | ||
| 360 | - Row() { | ||
| 361 | - Image($r('app.media.icon_search')) | ||
| 362 | - .width('24vp') | ||
| 363 | - .height('24vp') | ||
| 364 | - } | ||
| 365 | - .height('40vp') | ||
| 366 | - .width('40vp') | ||
| 367 | - .margin({ right: 10 }) | ||
| 368 | - .alignItems(VerticalAlign.Center) | ||
| 369 | - .justifyContent(FlexAlign.Center) | ||
| 370 | - .onClick(() => { | ||
| 371 | - WDRouterRule.jumpWithPage(WDRouterPage.searchPage) | ||
| 372 | - }) | ||
| 373 | - } | ||
| 374 | - } | ||
| 375 | - } | ||
| 376 | - } | ||
| 377 | - | ||
| 378 | - @Builder | ||
| 379 | - tabBarBuilder(item: TopNavDTO, index: number) { | ||
| 380 | - Column() { | ||
| 381 | - Text(item?.name) | ||
| 382 | - .fontSize($r('app.float.selected_text_size')) | ||
| 383 | - .fontWeight(this.currentTopNavSelectedIndex === index ? FontWeight.Bold : FontWeight.Normal) | ||
| 384 | - .fontColor(this.currentTopNavSelectedIndex === index ? Color.Black : "#999999") | ||
| 385 | - .padding({ top: $r('app.float.top_tab_item_padding_top'), bottom: $r('app.float.top_tab_item_padding_bottom') }) | ||
| 386 | - .maxLines(this.MAX_LINE) | ||
| 387 | - .id(index.toString()) | ||
| 388 | - .onAreaChange((oldValue: Area, newValue: Area) => { | ||
| 389 | - if (this.currentTopNavSelectedIndex === index && | ||
| 390 | - (this.indicatorLeftMargin === 0 || this.indicatorWidth === 0)) { | ||
| 391 | - if (newValue.position.x != undefined) { | ||
| 392 | - let positionX = Number.parseFloat(newValue.position.x.toString()) | ||
| 393 | - this.indicatorLeftMargin = Number.isNaN(positionX) ? 0 : positionX | ||
| 394 | - } | ||
| 395 | - let width = Number.parseFloat(newValue.width.toString()) | ||
| 396 | - this.indicatorWidth = Number.isNaN(width) ? 0 : width | ||
| 397 | - } | ||
| 398 | - }) | ||
| 399 | - // .backgroundImage(this.currentTopNavSelectedIndex === index ? item.iconCUrl : item.iconUrl) | ||
| 400 | - if (this.currentTopNavSelectedIndex === index) { | ||
| 401 | - Row() | ||
| 402 | - .width(20) | ||
| 403 | - .height(3) | ||
| 404 | - .backgroundImage($r('app.media.icon_channel_active'), ImageRepeat.NoRepeat) | ||
| 405 | - .backgroundImageSize(ImageSize.Contain) | ||
| 406 | - } | ||
| 407 | - } | ||
| 408 | - .hoverEffect(HoverEffect.Highlight) | ||
| 409 | - .constraintSize({ | ||
| 410 | - minWidth: $r('app.float.top_tab_item_min_width'), | ||
| 411 | - maxWidth: $r('app.float.top_tab_item_max_width') | ||
| 412 | - }) | ||
| 413 | - // .backgroundColor(Color.Transparent) | ||
| 414 | - .padding({ | ||
| 415 | - left: $r('app.float.top_tab_item_padding_horizontal'), | ||
| 416 | - right: $r('app.float.top_tab_item_padding_horizontal'), | ||
| 417 | - }) | ||
| 418 | - .id(`col_tabBar${index}`) | ||
| 419 | - .margin({ right: this.myChannelList.length === index + 1 ? 36 : 0 }) | ||
| 420 | - .onClick(() => { | ||
| 421 | - Logger.debug(TAG, `onClick, index: ${index}`); | ||
| 422 | - if (this.currentTopNavSelectedIndex === index) { | ||
| 423 | - // 当前tab,单击事件 | ||
| 424 | - this.doAutoRefresh() | ||
| 425 | - } else { | ||
| 426 | - this.changeByClick = true | ||
| 427 | - this.tabsController.changeIndex(index) | ||
| 428 | - } | ||
| 429 | - | ||
| 430 | - }) | ||
| 431 | - } | ||
| 432 | - | ||
| 433 | - | ||
| 434 | - aboutToAppear() { | ||
| 435 | - //处理新闻tab顶导频道数据 | ||
| 436 | - this.topNavListHandle() | ||
| 437 | - } | ||
| 438 | - | ||
| 439 | - aboutToDisappear() { | ||
| 440 | - AppStorage.set('channelIds', this.channelIds.join(',')) | ||
| 441 | - } | ||
| 442 | - | ||
| 443 | - onTopNavigationDataUpdated() { | ||
| 444 | - Logger.info(TAG, | ||
| 445 | - `onTopNavigationDataUpdated currentTopNavIndex: ${this.currentTopNavSelectedIndex},topNavList.length:${this.topNavList.length}`); | ||
| 446 | - } | ||
| 447 | - | ||
| 448 | - onAutoRefresh() { | ||
| 449 | - if (this.navIndex != this._currentNavIndex) { | ||
| 450 | - return | ||
| 451 | - } | ||
| 452 | - // 通知page刷新 | ||
| 453 | - this.autoRefresh2Page++ | ||
| 454 | - } | ||
| 455 | - | ||
| 456 | - private doAutoRefresh() { | ||
| 457 | - // 通知page刷新 | ||
| 458 | - this.autoRefresh2Page++ | ||
| 459 | - } | ||
| 460 | - | ||
| 461 | - /** | ||
| 462 | - * 判断是否当前页面处理逻辑,如消息通知,只需要切换到当前底导的处理,过滤掉非当前。 | ||
| 463 | - */ | ||
| 464 | - private isCurrentPage(): boolean { | ||
| 465 | - return this._currentNavIndex === this.navIndex | ||
| 466 | - } | ||
| 467 | - | ||
| 468 | - /** | ||
| 469 | - * 频道id变化,即指定频道跳转场景 | ||
| 470 | - */ | ||
| 471 | - onAssignChannelChange() { | ||
| 472 | - if (!this.isCurrentPage()) { | ||
| 473 | - return | ||
| 474 | - } | ||
| 475 | - let channelId = this.assignChannel.channelId | ||
| 476 | - let index = -1 | ||
| 477 | - if (this._currentNavIndex === 0) { | ||
| 478 | - // 第一个,新闻,先拿我的,再拿其他 | ||
| 479 | - index = this.getChannelByMine(channelId) | ||
| 480 | - if (index == -1) { | ||
| 481 | - // 不在我的里,需要临时新增频道展示 | ||
| 482 | - let channel = this.getChannelByOthers(channelId) | ||
| 483 | - if (channel) { | ||
| 484 | - this.myChannelList.push(channel) | ||
| 485 | - setTimeout(() => { | ||
| 486 | - this.tabsController.changeIndex(this.myChannelList.length - 1) | ||
| 487 | - }, 20) | ||
| 488 | - } | ||
| 489 | - } else { | ||
| 490 | - // 直接切换 | ||
| 491 | - this.tabsController.changeIndex(index) | ||
| 492 | - } | ||
| 493 | - } else { | ||
| 494 | - index = this.getChannelByTopNav(channelId) | ||
| 495 | - if (index > -1) { | ||
| 496 | - // 找到了,直接切换,否则不处理 | ||
| 497 | - this.tabsController.changeIndex(index) | ||
| 498 | - } | ||
| 499 | - } | ||
| 500 | - | ||
| 501 | - } | ||
| 502 | - | ||
| 503 | - /** | ||
| 504 | - * 非新闻,从topNav里拿数据 | ||
| 505 | - */ | ||
| 506 | - private getChannelByTopNav(channelId: string) { | ||
| 507 | - for (let i = 0; i < this.topNavList.length; i++) { | ||
| 508 | - let topNavDTO: TopNavDTO = this.topNavList[i] | ||
| 509 | - if (topNavDTO.channelId.toString() === channelId) { | ||
| 510 | - return i | ||
| 511 | - } | ||
| 512 | - } | ||
| 513 | - return -1 | ||
| 514 | - } | ||
| 515 | - | ||
| 516 | - /** | ||
| 517 | - * 新闻,从myChannelList里拿数据 | ||
| 518 | - */ | ||
| 519 | - private getChannelByMine(channelId: string) { | ||
| 520 | - for (let i = 0; i < this.myChannelList.length; i++) { | ||
| 521 | - let topNavDTO: TopNavDTO = this.myChannelList[i] | ||
| 522 | - if (topNavDTO.channelId.toString() === channelId) { | ||
| 523 | - return i | ||
| 524 | - } | ||
| 525 | - } | ||
| 526 | - return -1 | ||
| 527 | - } | ||
| 528 | - | ||
| 529 | - /** | ||
| 530 | - * 新闻,从其他里拿数据 | ||
| 531 | - */ | ||
| 532 | - private getChannelByOthers(channelId: string) { | ||
| 533 | - for (let i = 0; i < this.moreChannelList.length; i++) { | ||
| 534 | - let topNavDTO: TopNavDTO = this.moreChannelList[i] | ||
| 535 | - if (topNavDTO.channelId.toString() === channelId) { | ||
| 536 | - return topNavDTO | ||
| 537 | - } | ||
| 538 | - } | ||
| 539 | - for (let j = 0; j < this.localChannelList.length; j++) { | ||
| 540 | - let topNavDTO: TopNavDTO = this.localChannelList[j] | ||
| 541 | - if (topNavDTO.channelId.toString() === channelId) { | ||
| 542 | - return topNavDTO | ||
| 543 | - } | ||
| 544 | - } | ||
| 545 | - return null | ||
| 546 | - } | ||
| 547 | - | ||
| 548 | - // private getTextInfo(index: number): Record<string, number> { | ||
| 549 | - // let strJson = getInspectorByKey(index.toString()) | ||
| 550 | - // try { | ||
| 551 | - // let obj: Record<string, string> = JSON.parse(strJson) | ||
| 552 | - // let rectInfo: number[][] = JSON.parse('[' + obj.$rect + ']') | ||
| 553 | - // return { 'left': px2vp(rectInfo[0][0]), 'width': px2vp(rectInfo[1][0] - rectInfo[0][0]) } | ||
| 554 | - // } catch (error) { | ||
| 555 | - // return { 'left': 0, 'width': 0 } | ||
| 556 | - // } | ||
| 557 | - // } | ||
| 558 | - // | ||
| 559 | - // private getCurrentIndicatorInfo(index: number, event: TabsAnimationEvent): Record<string, number> { | ||
| 560 | - // let nextIndex = index | ||
| 561 | - // if (index > 0 && event.currentOffset > 0) { | ||
| 562 | - // nextIndex-- | ||
| 563 | - // } else if (index < 3 && event.currentOffset < 0) { | ||
| 564 | - // nextIndex++ | ||
| 565 | - // } | ||
| 566 | - // let indexInfo = this.getTextInfo(index) | ||
| 567 | - // let nextIndexInfo = this.getTextInfo(nextIndex) | ||
| 568 | - // let swipeRatio = Math.abs(event.currentOffset / this.tabsWidth) | ||
| 569 | - // let currentIndex = swipeRatio > 0.5 ? nextIndex : index // 页面滑动超过一半,tabBar切换到下一页。 | ||
| 570 | - // let currentLeft = indexInfo.left + (nextIndexInfo.left - indexInfo.left) * swipeRatio | ||
| 571 | - // let currentWidth = indexInfo.width + (nextIndexInfo.width - indexInfo.width) * swipeRatio | ||
| 572 | - // return { 'index': currentIndex, 'left': currentLeft, 'width': currentWidth } | ||
| 573 | - // } | ||
| 574 | - | ||
| 575 | - // private startAnimateTo(duration: number, leftMargin: number, width: number) { | ||
| 576 | - // animateTo({ | ||
| 577 | - // duration: duration, // 动画时长 | ||
| 578 | - // curve: Curve.Linear, // 动画曲线 | ||
| 579 | - // iterations: 1, // 播放次数 | ||
| 580 | - // playMode: PlayMode.Normal, // 动画模式 | ||
| 581 | - // onFinish: () => { | ||
| 582 | - // console.info('play end') | ||
| 583 | - // } | ||
| 584 | - // }, () => { | ||
| 585 | - // this.indicatorLeftMargin = leftMargin | ||
| 586 | - // this.indicatorWidth = width | ||
| 587 | - // }) | ||
| 588 | - // } | ||
| 589 | -} |
| @@ -4,7 +4,7 @@ import { EmitterEventId, EmitterUtils, Logger, StringUtils } from 'wdKit'; | @@ -4,7 +4,7 @@ import { EmitterEventId, EmitterUtils, Logger, StringUtils } from 'wdKit'; | ||
| 4 | import { HttpUtils } from 'wdNetwork/Index'; | 4 | import { HttpUtils } from 'wdNetwork/Index'; |
| 5 | import HomeChannelUtils, { AssignChannelParam } from 'wdRouter/Index'; | 5 | import HomeChannelUtils, { AssignChannelParam } from 'wdRouter/Index'; |
| 6 | import { MinePageComponent } from 'wdComponent/src/main/ets/components/page/MinePageComponent'; | 6 | import { MinePageComponent } from 'wdComponent/src/main/ets/components/page/MinePageComponent'; |
| 7 | -import { CompUtils, TopNavigationComponent, TopNavigationComponentNew } from 'wdComponent/Index'; | 7 | +import { CompUtils, TopNavigationComponentNew } from 'wdComponent/Index'; |
| 8 | import { VideoChannelPage } from './VideoChannelPage'; | 8 | import { VideoChannelPage } from './VideoChannelPage'; |
| 9 | import ChannelViewModel from 'wdComponent/src/main/ets/viewmodel/ChannelViewModel'; | 9 | import ChannelViewModel from 'wdComponent/src/main/ets/viewmodel/ChannelViewModel'; |
| 10 | import { ALL, ImageKnifeComponent, ImageKnifeOption, NONE } from '@ohos/imageknife'; | 10 | import { ALL, ImageKnifeComponent, ImageKnifeOption, NONE } from '@ohos/imageknife'; |
| @@ -21,7 +21,6 @@ let storage = LocalStorage.getShared(); | @@ -21,7 +21,6 @@ let storage = LocalStorage.getShared(); | ||
| 21 | @Entry(storage) | 21 | @Entry(storage) |
| 22 | @Component | 22 | @Component |
| 23 | export struct BottomNavigationComponent { | 23 | export struct BottomNavigationComponent { |
| 24 | - private isNewTopPage = true // TODO 顶导重构页面开关,false,则用原来的顶导 | ||
| 25 | @Provide bottomRectHeight: number = 0 | 24 | @Provide bottomRectHeight: number = 0 |
| 26 | @Provide topRectHeight: number = 0 | 25 | @Provide topRectHeight: number = 0 |
| 27 | @Provide isLayoutFullScreen: boolean = false | 26 | @Provide isLayoutFullScreen: boolean = false |
| @@ -87,28 +86,15 @@ export struct BottomNavigationComponent { | @@ -87,28 +86,15 @@ export struct BottomNavigationComponent { | ||
| 87 | autoRefresh: this.autoRefresh | 86 | autoRefresh: this.autoRefresh |
| 88 | }) | 87 | }) |
| 89 | } else { | 88 | } else { |
| 90 | - if (this.isNewTopPage) { | ||
| 91 | - TopNavigationComponentNew({ | ||
| 92 | - groupId: navItem.id, | ||
| 93 | - topNavList: navItem.topNavChannelList.filter(item => item.channelId != 2073), | ||
| 94 | - _currentNavIndex: $currentNavIndex, | ||
| 95 | - bottomNavIndex: index, | ||
| 96 | - currentBottomNavName: navItem.name, | ||
| 97 | - assignChannel: this.assignChannel, | ||
| 98 | - autoRefresh: this.autoRefresh | ||
| 99 | - }) | ||
| 100 | - } else { | ||
| 101 | - TopNavigationComponent({ | ||
| 102 | - groupId: navItem.id, | ||
| 103 | - topNavList: navItem.topNavChannelList.filter(item => item.channelId != 2073), | ||
| 104 | - _currentNavIndex: $currentNavIndex, | ||
| 105 | - navIndex: index, | ||
| 106 | - currentBottomNavName: navItem.name, | ||
| 107 | - assignChannel: this.assignChannel, | ||
| 108 | - autoRefresh: this.autoRefresh | ||
| 109 | - }) | ||
| 110 | - } | ||
| 111 | - | 89 | + TopNavigationComponentNew({ |
| 90 | + groupId: navItem.id, | ||
| 91 | + topNavList: navItem.topNavChannelList.filter(item => item.channelId != 2073), | ||
| 92 | + _currentNavIndex: $currentNavIndex, | ||
| 93 | + bottomNavIndex: index, | ||
| 94 | + currentBottomNavName: navItem.name, | ||
| 95 | + assignChannel: this.assignChannel, | ||
| 96 | + autoRefresh: this.autoRefresh | ||
| 97 | + }) | ||
| 112 | } | 98 | } |
| 113 | } | 99 | } |
| 114 | .tabBar(this.tabBarBuilder(navItem, index)) | 100 | .tabBar(this.tabBarBuilder(navItem, index)) |
-
Please register or login to post a comment