liyubing

feat:

1)新闻tab的顶导数据  存储处理
1 -import { BottomNavDTO, TopNavDTO } from 'wdBean';  
2 -import { SpConstants } from 'wdConstant'; 1 +import { BottomNavDTO, NavigationDetailDTO, TopNavDTO } from 'wdBean';
3 import { Logger, NetworkUtil, SPHelper, ToastUtils } from 'wdKit'; 2 import { Logger, NetworkUtil, SPHelper, ToastUtils } from 'wdKit';
4 import { ProcessUtils, WDRouterPage, WDRouterRule } from 'wdRouter'; 3 import { ProcessUtils, WDRouterPage, WDRouterRule } from 'wdRouter';
5 import { PageComponent } from './PageComponent'; 4 import { PageComponent } from './PageComponent';
@@ -422,7 +421,6 @@ export struct TopNavigationComponentNew { @@ -422,7 +421,6 @@ export struct TopNavigationComponentNew {
422 421
423 async aboutToAppear() { 422 async aboutToAppear() {
424 423
425 -  
426 if (CompUtils.isNews(this.navItem)) { 424 if (CompUtils.isNews(this.navItem)) {
427 425
428 // 请求顶导网络数据 426 // 请求顶导网络数据
@@ -619,20 +617,51 @@ export struct TopNavigationComponentNew { @@ -619,20 +617,51 @@ export struct TopNavigationComponentNew {
619 //请求顶导数据 617 //请求顶导数据
620 async getTopNavList(id: number) { 618 async getTopNavList(id: number) {
621 619
  620 +
622 Logger.debug(TAG, 'getTopNavList=存储=>' + this.storageChannelIds) 621 Logger.debug(TAG, 'getTopNavList=存储=>' + this.storageChannelIds)
623 622
  623 + // 1 、使用存储数据
  624 + let bottomDetailCache = await ChannelViewModel.getBottomNavDetailCacheData(id)
  625 +
  626 + if (bottomDetailCache != null && bottomDetailCache.topNavChannelList.length > 0) {
  627 + Logger.debug(TAG, '使用缓存数据')
  628 + this.processTopNewsTapData(bottomDetailCache, false)
  629 + }
  630 +
  631 + // 2、请求网络数据
624 let bottomNavDetail = await ChannelViewModel.getBottomNavDetailData(id, this.storageChannelIds) 632 let bottomNavDetail = await ChannelViewModel.getBottomNavDetailData(id, this.storageChannelIds)
  633 +
  634 + if (bottomNavDetail != null) {
  635 + // 3、 接口数据md5和存储数据md5对比,一致不更新
  636 + if (bottomNavDetail.md5 == bottomDetailCache?.md5) {
  637 + Logger.debug(TAG, '不使用接口数据')
  638 + } else {
  639 + Logger.debug(TAG, '使用接口数据')
  640 + this.processTopNewsTapData(bottomNavDetail, true)
  641 + //存储
  642 + ChannelViewModel.saveBottomDetailData(bottomNavDetail)
  643 + }
  644 +
  645 + }
  646 +
  647 + }
  648 +
  649 + /**
  650 + * 加工新闻tab 顶导数据
  651 + * @param bottomNavDetail
  652 + */
  653 + private processTopNewsTapData(bottomNavDetail: NavigationDetailDTO, isNetData: boolean) {
  654 +
625 let topNavList = bottomNavDetail?.topNavChannelList || [] 655 let topNavList = bottomNavDetail?.topNavChannelList || []
626 656
627 - //let provinceName = SPHelper.default.getSync(SpConstants.LOCATION_PROVINCE_NAME, '') as string  
628 let _myChannelList: TopNavDTO [] = [] 657 let _myChannelList: TopNavDTO [] = []
629 - 658 + this.homeChannelList = []
  659 + this.moreChannelList = []
  660 + this.localChannelList = []
630 topNavList.forEach(item => { 661 topNavList.forEach(item => {
631 if (item.defaultPermitted === 1) { 662 if (item.defaultPermitted === 1) {
632 - console.debug('TopNavigationComponent', '--homeChannelList--->' + item.name)  
633 this.homeChannelList.push(item) 663 this.homeChannelList.push(item)
634 } 664 }
635 -  
636 //TODO 暂时隐藏播报 665 //TODO 暂时隐藏播报
637 if (item.name !== '播报') { 666 if (item.name !== '播报') {
638 if (item.myChannel === '1') { 667 if (item.myChannel === '1') {
@@ -645,6 +674,33 @@ export struct TopNavigationComponentNew { @@ -645,6 +674,33 @@ export struct TopNavigationComponentNew {
645 } 674 }
646 }) 675 })
647 676
  677 + //根据缓存数组排序
  678 + if (this.storageChannelIds && !isNetData) {
  679 + Logger.debug(TAG, '根据存储内容')
  680 + let sortedyChannelList: TopNavDTO [] = []
  681 + let _storageChannelIds = this.storageChannelIds.split(',')
  682 + _storageChannelIds.forEach((channelId) => {
  683 + for (let a of _myChannelList) {
  684 + if (channelId == String(a.channelId)) {
  685 + let startIndex = _myChannelList.findIndex(b => b.channelId == a.channelId)
  686 + _myChannelList.splice(startIndex, 1)
  687 + sortedyChannelList.push(a)
  688 + break;
  689 + }
  690 + }
  691 + })
  692 + // 依据存储的我的频道中频道id集合,过滤出符合条件频道,剩余的频道,针对本地频道处理,每次删除,再次进入存储的频道详情信息里面我的频道栏目的信息集合都有本地频道
  693 + if (_myChannelList.length > 0) {
  694 +
  695 + _myChannelList.forEach((localChannelBean) => {
  696 + localChannelBean.localChannel = '1'
  697 + })
  698 + this.localChannelList.unshift(..._myChannelList)
  699 + }
  700 +
  701 + _myChannelList = sortedyChannelList
  702 + }
  703 +
648 this.myChannelList = _myChannelList 704 this.myChannelList = _myChannelList
649 705
650 //缓存首页频道 706 //缓存首页频道
@@ -653,7 +709,9 @@ export struct TopNavigationComponentNew { @@ -653,7 +709,9 @@ export struct TopNavigationComponentNew {
653 this.currentTopNavSelectedIndex = index 709 this.currentTopNavSelectedIndex = index
654 } 710 }
655 711
  712 + if (isNetData) {
656 // 存储我的频道栏目中的频道id信息 713 // 存储我的频道栏目中的频道id信息
  714 + Logger.debug(TAG, '存储我的频道栏目数据')
657 let channelIds: number [] = [] 715 let channelIds: number [] = []
658 this.myChannelList.forEach(item => { 716 this.myChannelList.forEach(item => {
659 if (item != undefined && item.channelId != undefined) { 717 if (item != undefined && item.channelId != undefined) {
@@ -662,4 +720,6 @@ export struct TopNavigationComponentNew { @@ -662,4 +720,6 @@ export struct TopNavigationComponentNew {
662 }) 720 })
663 AppStorage.setOrCreate('channelIds', channelIds.join(',')) 721 AppStorage.setOrCreate('channelIds', channelIds.join(','))
664 } 722 }
  723 +
  724 + }
665 } 725 }