Toggle navigation
Toggle navigation
This project
Loading...
Sign in
developOne
/
harmonyPool
Go to a project
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
liyubing
2024-06-19 20:41:37 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
863634556e894b73e6d6efc4a1e9fe8eb11beaa6
86363455
1 parent
ab23eb8e
feat:
1)新闻tab的顶导数据 存储处理
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
75 additions
and
15 deletions
sight_harmony/features/wdComponent/src/main/ets/components/page/TopNavigationComponentNew.ets
sight_harmony/features/wdComponent/src/main/ets/components/page/TopNavigationComponentNew.ets
View file @
8636345
import { BottomNavDTO, TopNavDTO } from 'wdBean';
import { SpConstants } from 'wdConstant';
import { BottomNavDTO, NavigationDetailDTO, TopNavDTO } from 'wdBean';
import { Logger, NetworkUtil, SPHelper, ToastUtils } from 'wdKit';
import { ProcessUtils, WDRouterPage, WDRouterRule } from 'wdRouter';
import { PageComponent } from './PageComponent';
...
...
@@ -422,7 +421,6 @@ export struct TopNavigationComponentNew {
async aboutToAppear() {
if (CompUtils.isNews(this.navItem)) {
// 请求顶导网络数据
...
...
@@ -619,20 +617,51 @@ export struct TopNavigationComponentNew {
//请求顶导数据
async getTopNavList(id: number) {
Logger.debug(TAG, 'getTopNavList=存储=>' + this.storageChannelIds)
// 1 、使用存储数据
let bottomDetailCache = await ChannelViewModel.getBottomNavDetailCacheData(id)
if (bottomDetailCache != null && bottomDetailCache.topNavChannelList.length > 0) {
Logger.debug(TAG, '使用缓存数据')
this.processTopNewsTapData(bottomDetailCache, false)
}
// 2、请求网络数据
let bottomNavDetail = await ChannelViewModel.getBottomNavDetailData(id, this.storageChannelIds)
if (bottomNavDetail != null) {
// 3、 接口数据md5和存储数据md5对比,一致不更新
if (bottomNavDetail.md5 == bottomDetailCache?.md5) {
Logger.debug(TAG, '不使用接口数据')
} else {
Logger.debug(TAG, '使用接口数据')
this.processTopNewsTapData(bottomNavDetail, true)
//存储
ChannelViewModel.saveBottomDetailData(bottomNavDetail)
}
}
}
/**
* 加工新闻tab 顶导数据
* @param bottomNavDetail
*/
private processTopNewsTapData(bottomNavDetail: NavigationDetailDTO, isNetData: boolean) {
let topNavList = bottomNavDetail?.topNavChannelList || []
//let provinceName = SPHelper.default.getSync(SpConstants.LOCATION_PROVINCE_NAME, '') as string
let _myChannelList: TopNavDTO [] = []
this.homeChannelList = []
this.moreChannelList = []
this.localChannelList = []
topNavList.forEach(item => {
if (item.defaultPermitted === 1) {
console.debug('TopNavigationComponent', '--homeChannelList--->' + item.name)
this.homeChannelList.push(item)
}
//TODO 暂时隐藏播报
if (item.name !== '播报') {
if (item.myChannel === '1') {
...
...
@@ -645,6 +674,33 @@ export struct TopNavigationComponentNew {
}
})
//根据缓存数组排序
if (this.storageChannelIds && !isNetData) {
Logger.debug(TAG, '根据存储内容')
let sortedyChannelList: TopNavDTO [] = []
let _storageChannelIds = this.storageChannelIds.split(',')
_storageChannelIds.forEach((channelId) => {
for (let a of _myChannelList) {
if (channelId == String(a.channelId)) {
let startIndex = _myChannelList.findIndex(b => b.channelId == a.channelId)
_myChannelList.splice(startIndex, 1)
sortedyChannelList.push(a)
break;
}
}
})
// 依据存储的我的频道中频道id集合,过滤出符合条件频道,剩余的频道,针对本地频道处理,每次删除,再次进入存储的频道详情信息里面我的频道栏目的信息集合都有本地频道
if (_myChannelList.length > 0) {
_myChannelList.forEach((localChannelBean) => {
localChannelBean.localChannel = '1'
})
this.localChannelList.unshift(..._myChannelList)
}
_myChannelList = sortedyChannelList
}
this.myChannelList = _myChannelList
//缓存首页频道
...
...
@@ -653,13 +709,17 @@ export struct TopNavigationComponentNew {
this.currentTopNavSelectedIndex = index
}
// 存储我的频道栏目中的频道id信息
let channelIds: number [] = []
this.myChannelList.forEach(item => {
if (item != undefined && item.channelId != undefined) {
channelIds.push(item.channelId)
}
})
AppStorage.setOrCreate('channelIds', channelIds.join(','))
if (isNetData) {
// 存储我的频道栏目中的频道id信息
Logger.debug(TAG, '存储我的频道栏目数据')
let channelIds: number [] = []
this.myChannelList.forEach(item => {
if (item != undefined && item.channelId != undefined) {
channelIds.push(item.channelId)
}
})
AppStorage.setOrCreate('channelIds', channelIds.join(','))
}
}
}
\ No newline at end of file
...
...
Please
register
or
login
to post a comment