Showing
11 changed files
with
294 additions
and
217 deletions
| @@ -16,7 +16,6 @@ export class KVStoreHelper { | @@ -16,7 +16,6 @@ export class KVStoreHelper { | ||
| 16 | private kvStore: distributedKVStore.SingleKVStore | undefined = undefined; | 16 | private kvStore: distributedKVStore.SingleKVStore | undefined = undefined; |
| 17 | 17 | ||
| 18 | private constructor() { | 18 | private constructor() { |
| 19 | - Logger.error(TAG, 'constructor') | ||
| 20 | } | 19 | } |
| 21 | 20 | ||
| 22 | static init(context: Context) { | 21 | static init(context: Context) { |
| 1 | -/** | ||
| 2 | - * 接口数据存储封装类 | ||
| 3 | - */ | ||
| 4 | import { DateTimeUtils, StringUtils } from 'wdKit/Index'; | 1 | import { DateTimeUtils, StringUtils } from 'wdKit/Index'; |
| 5 | import { CacheDataSaveUtil } from './CacheDataSaveUtil'; | 2 | import { CacheDataSaveUtil } from './CacheDataSaveUtil'; |
| 3 | +import { JSON } from '@kit.ArkTS'; | ||
| 6 | 4 | ||
| 5 | +/** | ||
| 6 | + * 接口数据存储封装类 | ||
| 7 | + */ | ||
| 7 | export class CacheData { | 8 | export class CacheData { |
| 9 | + /** | ||
| 10 | + * 底部导航栏缓存的数据key | ||
| 11 | + */ | ||
| 12 | + static bottomCacheKey = 'bottom_cache_data_key' | ||
| 13 | + /** | ||
| 14 | + * 头部频道缓存的数据key | ||
| 15 | + */ | ||
| 16 | + static channelCacheDataKey = 'channel_data_cache_id_' | ||
| 17 | + /** | ||
| 18 | + * 页面page组件的数据key | ||
| 19 | + */ | ||
| 20 | + static comPageInfoCacheKey = 'com_pageInfo_cache_id_' | ||
| 21 | + /** | ||
| 22 | + * 页面组件的数据key | ||
| 23 | + */ | ||
| 24 | + static compGroupInfoDataCacheKey = 'com_data_info_cache_id_' | ||
| 8 | // 接口返回数据 | 25 | // 接口返回数据 |
| 9 | networkData?: object; | 26 | networkData?: object; |
| 10 | // 数据更新时间戳 | 27 | // 数据更新时间戳 |
| @@ -48,16 +65,20 @@ export class CacheData { | @@ -48,16 +65,20 @@ export class CacheData { | ||
| 48 | success(null) | 65 | success(null) |
| 49 | return | 66 | return |
| 50 | } | 67 | } |
| 51 | - let ll = CacheDataSaveUtil.get(key) | ||
| 52 | - if (ll instanceof Promise) { | ||
| 53 | - ll.then((data) => { | ||
| 54 | - let str = data as string | ||
| 55 | - let cache = JSON.parse(str) as CacheData | ||
| 56 | - success(cache) | ||
| 57 | - }) | ||
| 58 | - } else { | 68 | + CacheDataSaveUtil.get(key).then((data) => { |
| 69 | + let str = data as string | ||
| 70 | + let cache = JSON.parse(str) as CacheData | ||
| 71 | + success(cache) | ||
| 72 | + }).catch(() => { | ||
| 59 | success(null) | 73 | success(null) |
| 60 | - } | 74 | + }) |
| 61 | }) | 75 | }) |
| 62 | } | 76 | } |
| 77 | + | ||
| 78 | + static getNetworkData(data: CacheData): string { | ||
| 79 | + if (data.networkData) { | ||
| 80 | + return JSON.stringify(data.networkData); | ||
| 81 | + } | ||
| 82 | + return ""; | ||
| 83 | + } | ||
| 63 | } | 84 | } |
| @@ -11,10 +11,18 @@ export class CacheDataSaveUtil { | @@ -11,10 +11,18 @@ export class CacheDataSaveUtil { | ||
| 11 | KVStoreHelper.default.put(key, value) | 11 | KVStoreHelper.default.put(key, value) |
| 12 | } | 12 | } |
| 13 | 13 | ||
| 14 | - static get(key: string) { | ||
| 15 | - if (StringUtils.isEmpty(key)) { | ||
| 16 | - return '' | ||
| 17 | - } | ||
| 18 | - return KVStoreHelper.default.get(key, '') | 14 | + static get(key: string): Promise<string> { |
| 15 | + return new Promise<string>((success) => { | ||
| 16 | + if (StringUtils.isEmpty(key)) { | ||
| 17 | + success('') | ||
| 18 | + } else { | ||
| 19 | + KVStoreHelper.default.get(key, '').then((data) => { | ||
| 20 | + let str = data as string | ||
| 21 | + success(str) | ||
| 22 | + }).catch(() => { | ||
| 23 | + success('') | ||
| 24 | + }) | ||
| 25 | + } | ||
| 26 | + }) | ||
| 19 | } | 27 | } |
| 20 | } | 28 | } |
| 1 | +import HomeChannelUtils from './src/main/ets/utils/HomeChannelUtils'; | ||
| 2 | + | ||
| 3 | +export default HomeChannelUtils; | ||
| 4 | + | ||
| 1 | export { WDRouterRule } from './src/main/ets/router/WDRouterRule' | 5 | export { WDRouterRule } from './src/main/ets/router/WDRouterRule' |
| 2 | 6 | ||
| 3 | export { WDRouterPage } from './src/main/ets/router/WDRouterPage' | 7 | export { WDRouterPage } from './src/main/ets/router/WDRouterPage' |
| @@ -6,4 +10,6 @@ export { registerRouter } from './src/main/ets/router/Action2Page' | @@ -6,4 +10,6 @@ export { registerRouter } from './src/main/ets/router/Action2Page' | ||
| 6 | 10 | ||
| 7 | export { ProcessUtils } from './src/main/ets/utils/ProcessUtils' | 11 | export { ProcessUtils } from './src/main/ets/utils/ProcessUtils' |
| 8 | 12 | ||
| 13 | +export { AssignChannelParam } from './src/main/ets/utils/HomeChannelUtils'; | ||
| 14 | + | ||
| 9 | export { RouterJumpInterceptor, JumpInterceptorAction } from './src/main/ets/router/RouterJumpInterceptor' | 15 | export { RouterJumpInterceptor, JumpInterceptorAction } from './src/main/ets/router/RouterJumpInterceptor' |
| @@ -2,7 +2,6 @@ import { BottomNavDTO, NavigationBodyDTO, TopNavDTO } from 'wdBean/Index'; | @@ -2,7 +2,6 @@ import { BottomNavDTO, NavigationBodyDTO, TopNavDTO } from 'wdBean/Index'; | ||
| 2 | import { EmitterEventId, EmitterUtils, StringUtils } from 'wdKit/Index'; | 2 | import { EmitterEventId, EmitterUtils, StringUtils } from 'wdKit/Index'; |
| 3 | import { WDRouterPage } from '../router/WDRouterPage'; | 3 | import { WDRouterPage } from '../router/WDRouterPage'; |
| 4 | import { WDRouterRule } from '../router/WDRouterRule'; | 4 | import { WDRouterRule } from '../router/WDRouterRule'; |
| 5 | -import { HashMap } from '@kit.ArkTS'; | ||
| 6 | 5 | ||
| 7 | /** | 6 | /** |
| 8 | * 首页、频道相关跳转、处理 | 7 | * 首页、频道相关跳转、处理 |
| @@ -4,17 +4,20 @@ import { TopNavDTO } from './TopNavDTO'; | @@ -4,17 +4,20 @@ import { TopNavDTO } from './TopNavDTO'; | ||
| 4 | /** | 4 | /** |
| 5 | * 导航Body数据 | 5 | * 导航Body数据 |
| 6 | */ | 6 | */ |
| 7 | -export interface NavigationBodyDTO { | ||
| 8 | - backgroundColor: string; // 迭代二新增-底部导航背景色(信息流频道) | ||
| 9 | - bottomNavList: BottomNavDTO[]; | ||
| 10 | - | 7 | +export class NavigationBodyDTO { |
| 8 | + backgroundColor: string = ''; // 迭代二新增-底部导航背景色(信息流频道) | ||
| 9 | + bottomNavList: BottomNavDTO[] = []; | ||
| 11 | // greyBottomNav: GreyBottomNav; // 灰度皮肤 | 10 | // greyBottomNav: GreyBottomNav; // 灰度皮肤 |
| 12 | - immersiveBackgroundColor: string; // 迭代二新增-底部导航背景色(沉浸式频道) | ||
| 13 | - nightBackgroundColor: string; // 迭代三新增-底部导航背景色(夜间模式) | 11 | + immersiveBackgroundColor: string = ''; // 迭代二新增-底部导航背景色(沉浸式频道) |
| 12 | + nightBackgroundColor: string = ''; // 迭代三新增-底部导航背景色(夜间模式) | ||
| 13 | + | ||
| 14 | + md5: string = '' | ||
| 14 | } | 15 | } |
| 15 | 16 | ||
| 16 | -export interface NavigationDetailDTO { | ||
| 17 | - id: string; // 迭代二新增-底部导航背景色(信息流频道) | ||
| 18 | - bottomNavCompList: BottomNavCompDTO[]; | ||
| 19 | - topNavChannelList: TopNavDTO[]; | 17 | +export class NavigationDetailDTO { |
| 18 | + id: string = ''; // 迭代二新增-底部导航背景色(信息流频道) | ||
| 19 | + bottomNavCompList: BottomNavCompDTO[] = []; | ||
| 20 | + topNavChannelList: TopNavDTO[] = []; | ||
| 21 | + | ||
| 22 | + md5: string = '' | ||
| 20 | } | 23 | } |
| 1 | /** | 1 | /** |
| 2 | * 顶导 | 2 | * 顶导 |
| 3 | */ | 3 | */ |
| 4 | -export interface TopNavDTO { | ||
| 5 | - channelId: number; | ||
| 6 | - channelStyle: number; | ||
| 7 | - channelType: number; // 频道样式;1-沉浸式;2-信息流;3-特殊频道(跳转指定页面的,如版面) | ||
| 8 | - defaultPermitted: number; | ||
| 9 | - delPermitted: number; | ||
| 10 | - fontCColor: string; // 频道展示样式颜色(选中状态) | ||
| 11 | - fontColor: string; // 频道展示样式颜色(未选中状态) | ||
| 12 | - headlinesOn: number; | ||
| 13 | - homeChannel: string; | ||
| 14 | - iconUrlSize: string; | ||
| 15 | - iconCUrlSize: string; | ||
| 16 | - iconUrl: string; // 频道图片展示样式图片相对地址(未选中状态) | ||
| 17 | - iconCUrl: string; //频道图片展示样式图片相对地址(选中状态 | ||
| 18 | - localChannel: string; | ||
| 19 | - moreChannel: string; | ||
| 20 | - movePermitted: number; | ||
| 21 | - myChannel: string; | ||
| 22 | - name: string; | ||
| 23 | - num: number; | ||
| 24 | - pageId: number; | ||
| 25 | - pageType: string; | ||
| 26 | - underlineCColor: string; // 选中下划线颜色 | 4 | +export class TopNavDTO { |
| 5 | + channelId: number = 0; | ||
| 6 | + channelStyle: number = 0; | ||
| 7 | + channelType: number = 0; // 频道样式;1-沉浸式;2-信息流;3-特殊频道(跳转指定页面的,如版面) | ||
| 8 | + defaultPermitted: number = 0; | ||
| 9 | + delPermitted: number = 0; | ||
| 10 | + fontCColor: string = ''; // 频道展示样式颜色(选中状态) | ||
| 11 | + fontColor: string = ''; // 频道展示样式颜色(未选中状态) | ||
| 12 | + headlinesOn: number = 0; | ||
| 13 | + homeChannel: string = ''; | ||
| 14 | + iconUrlSize: string = ''; | ||
| 15 | + iconCUrlSize: string = ''; | ||
| 16 | + iconUrl: string = ''; // 频道图片展示样式图片相对地址(未选中状态) | ||
| 17 | + iconCUrl: string = ''; //频道图片展示样式图片相对地址(选中状态 | ||
| 18 | + localChannel: string = ''; | ||
| 19 | + moreChannel: string = ''; | ||
| 20 | + movePermitted: number = 0; | ||
| 21 | + myChannel: string = ''; | ||
| 22 | + name: string = ''; | ||
| 23 | + num: number = 0; | ||
| 24 | + pageId: number = 0; | ||
| 25 | + pageType: string = ''; | ||
| 26 | + underlineCColor: string = ''; // 选中下划线颜色 | ||
| 27 | } | 27 | } |
| 1 | import { BottomNavi, CommonConstants } from 'wdConstant'; | 1 | import { BottomNavi, CommonConstants } from 'wdConstant'; |
| 2 | -import { BottomNavDTO, TopNavDTO } from 'wdBean'; | ||
| 3 | -import { DateTimeUtils, EmitterEventId, EmitterUtils, Logger } from 'wdKit'; | 2 | +import { BottomNavDTO, NavigationBodyDTO, TopNavDTO } from 'wdBean'; |
| 3 | +import { EmitterEventId, EmitterUtils, Logger } from 'wdKit'; | ||
| 4 | import { TopNavigationComponent } from './TopNavigationComponent'; | 4 | import { TopNavigationComponent } from './TopNavigationComponent'; |
| 5 | import { MinePageComponent } from './MinePageComponent'; | 5 | import { MinePageComponent } from './MinePageComponent'; |
| 6 | import { CompUtils } from '../../utils/CompUtils'; | 6 | import { CompUtils } from '../../utils/CompUtils'; |
| 7 | -import PageViewModel from '../../viewmodel/PageViewModel'; | ||
| 8 | -import HomeChannelUtils, { AssignChannelParam } from 'wdRouter/src/main/ets/utils/HomeChannelUtils'; | ||
| 9 | -import { Message } from 'wdJsBridge/src/main/ets/bean/Message'; | 7 | +import ChannelViewModel from '../../viewmodel/ChannelViewModel'; |
| 8 | +import HomeChannelUtils, { AssignChannelParam } from 'wdRouter'; | ||
| 10 | import { VideoChannelPage } from './VideoChannelPage'; | 9 | import { VideoChannelPage } from './VideoChannelPage'; |
| 11 | 10 | ||
| 12 | const TAG = 'BottomNavigationComponent'; | 11 | const TAG = 'BottomNavigationComponent'; |
| @@ -46,18 +45,12 @@ export struct BottomNavigationComponent { | @@ -46,18 +45,12 @@ export struct BottomNavigationComponent { | ||
| 46 | @State assignChannel: AssignChannelParam = new AssignChannelParam() | 45 | @State assignChannel: AssignChannelParam = new AssignChannelParam() |
| 47 | // 自动刷新触发(双击tab自动刷新) | 46 | // 自动刷新触发(双击tab自动刷新) |
| 48 | @State autoRefresh: number = 0 | 47 | @State autoRefresh: number = 0 |
| 48 | + // 顶导数据,从接口获取 TODO 顶导业务逻辑没看懂,暂时不替换顶导list。频道管理数据待梳理 | ||
| 49 | + @State topNavMap: Record<string, TopNavDTO[]> = {} | ||
| 49 | 50 | ||
| 50 | async aboutToAppear() { | 51 | async aboutToAppear() { |
| 51 | Logger.info(TAG, `aboutToAppear currentNavIndex: ${this.currentNavIndex}`); | 52 | Logger.info(TAG, `aboutToAppear currentNavIndex: ${this.currentNavIndex}`); |
| 52 | - let bottomNav = await PageViewModel.getBottomNavData(getContext(this)) | ||
| 53 | - if (bottomNav && bottomNav.bottomNavList != null) { | ||
| 54 | - Logger.info(TAG, `aboutToAppear, bottomNav.length: ${bottomNav.bottomNavList.length}`); | ||
| 55 | - // 使用filter方法移除name为'服务'的项 | ||
| 56 | - bottomNav.bottomNavList = bottomNav.bottomNavList.filter(item => item.name !== '服务'); | ||
| 57 | - this.bottomNavList = bottomNav.bottomNavList | ||
| 58 | - } | ||
| 59 | - this.getTopNavList(this.bottomNavList[0]?.id) | ||
| 60 | - HomeChannelUtils.setBottomNavData(bottomNav) | 53 | + this.getBottomData() |
| 61 | 54 | ||
| 62 | EmitterUtils.receiveEvent(EmitterEventId.JUMP_HOME_CHANNEL, (str?: string) => { | 55 | EmitterUtils.receiveEvent(EmitterEventId.JUMP_HOME_CHANNEL, (str?: string) => { |
| 63 | Logger.debug(TAG, 'receiveEvent JUMP_HOME_CHANNEL: ' + str) | 56 | Logger.debug(TAG, 'receiveEvent JUMP_HOME_CHANNEL: ' + str) |
| @@ -170,7 +163,7 @@ export struct BottomNavigationComponent { | @@ -170,7 +163,7 @@ export struct BottomNavigationComponent { | ||
| 170 | 163 | ||
| 171 | //请求顶导数据 | 164 | //请求顶导数据 |
| 172 | async getTopNavList(id: number) { | 165 | async getTopNavList(id: number) { |
| 173 | - let bottomNavDetail = await PageViewModel.getBottomNavDetailData(id) | 166 | + let bottomNavDetail = await ChannelViewModel.getBottomNavDetailData(id) |
| 174 | this.topNavList = bottomNavDetail?.topNavChannelList || [] | 167 | this.topNavList = bottomNavDetail?.topNavChannelList || [] |
| 175 | } | 168 | } |
| 176 | 169 | ||
| @@ -203,4 +196,62 @@ export struct BottomNavigationComponent { | @@ -203,4 +196,62 @@ export struct BottomNavigationComponent { | ||
| 203 | this.assignChannel.bottomNavId = assignChannel.bottomNavId | 196 | this.assignChannel.bottomNavId = assignChannel.bottomNavId |
| 204 | }, 20) | 197 | }, 20) |
| 205 | } | 198 | } |
| 199 | + | ||
| 200 | + private async getBottomData() { | ||
| 201 | + Logger.debug(TAG, 'getBottomData') | ||
| 202 | + // 1、缓存底导数据 | ||
| 203 | + let bottomCache = await ChannelViewModel.getBottomNavCacheData() | ||
| 204 | + if (bottomCache && bottomCache.bottomNavList != null) { | ||
| 205 | + Logger.debug(TAG, 'getBottomData cache success') | ||
| 206 | + this.setData(bottomCache) | ||
| 207 | + this.getBottomDetail() | ||
| 208 | + } | ||
| 209 | + // TODO 2、预置底导数据 | ||
| 210 | + // 3、接口底导数据 | ||
| 211 | + let bottomNav = await ChannelViewModel.getBottomNavData() | ||
| 212 | + if (bottomNav && bottomNav.bottomNavList != null) { | ||
| 213 | + Logger.debug(TAG, 'getBottomNavData') | ||
| 214 | + HomeChannelUtils.setBottomNavData(bottomNav) | ||
| 215 | + if (this.bottomNavList == null || this.bottomNavList.length <= 0) { | ||
| 216 | + // 底导没展示,则用接口数据(接口数据回来,不去覆盖缓存数据,没有缓存才加载) | ||
| 217 | + this.setData(bottomNav) | ||
| 218 | + this.getBottomDetail() | ||
| 219 | + } | ||
| 220 | + // 将数据保存本地 | ||
| 221 | + ChannelViewModel.saveBottomData(bottomNav) | ||
| 222 | + } | ||
| 223 | + } | ||
| 224 | + | ||
| 225 | + private getBottomDetail() { | ||
| 226 | + // 1、获取顶导缓存数据 | ||
| 227 | + // this.bottomNavList.forEach((value) => { | ||
| 228 | + // // 先用底导带回的list初始化 | ||
| 229 | + // this.topNavMap[value.id] = value.topNavChannelList | ||
| 230 | + // ChannelViewModel.getBottomNavDetailData(value?.id).then((bottomNavDetail) => { | ||
| 231 | + // let list = bottomNavDetail?.topNavChannelList || [] | ||
| 232 | + // // 将顶导数据,单独存储 | ||
| 233 | + // this.topNavMap[value.id] = list | ||
| 234 | + // }) | ||
| 235 | + // }) | ||
| 236 | + // // 2、获取顶导接口数据,返回后需要覆盖缓存数据 | ||
| 237 | + // this.bottomNavList.forEach((value) => { | ||
| 238 | + // ChannelViewModel.getBottomNavDetailData(value?.id).then((bottomNavDetail) => { | ||
| 239 | + // let list = bottomNavDetail?.topNavChannelList || [] | ||
| 240 | + // // 将顶导数据,单独存储 | ||
| 241 | + // this.topNavMap[value.id] = list | ||
| 242 | + // // 存储缓存 | ||
| 243 | + // ChannelViewModel.saveBottomDetailData(bottomNavDetail) | ||
| 244 | + // }) | ||
| 245 | + // }) | ||
| 246 | + } | ||
| 247 | + | ||
| 248 | + private setData(data: NavigationBodyDTO) { | ||
| 249 | + Logger.debug(TAG, 'setData') | ||
| 250 | + if (data && data.bottomNavList != null) { | ||
| 251 | + Logger.info(TAG, `setData, bottomNav.length: ${data.bottomNavList.length}`); | ||
| 252 | + // 使用filter方法移除name为'服务'的项 | ||
| 253 | + data.bottomNavList = data.bottomNavList.filter(item => item.name !== '服务'); | ||
| 254 | + this.bottomNavList = data.bottomNavList | ||
| 255 | + } | ||
| 256 | + } | ||
| 206 | } | 257 | } |
| 1 | +import { NavigationBodyDTO, NavigationDetailDTO, } from 'wdBean'; | ||
| 2 | + | ||
| 3 | +import { Logger } from 'wdKit'; | ||
| 4 | +import { CacheData, ResponseDTO } from 'wdNetwork'; | ||
| 5 | +import { PageRepository } from '../repository/PageRepository'; | ||
| 6 | + | ||
| 7 | +const TAG = 'ChannelViewModel'; | ||
| 8 | + | ||
| 9 | +/** | ||
| 10 | + * 首页底导、顶导相关 | ||
| 11 | + */ | ||
| 12 | +export class ChannelViewModel { | ||
| 13 | + /** | ||
| 14 | + * 获取底导缓存数据 | ||
| 15 | + */ | ||
| 16 | + async getBottomNavCacheData(): Promise<NavigationBodyDTO | null> { | ||
| 17 | + Logger.info(TAG, `getBottomNavCacheData start`); | ||
| 18 | + return new Promise<NavigationBodyDTO | null>((success) => { | ||
| 19 | + CacheData.getLocalCacheData(CacheData.bottomCacheKey).then((data) => { | ||
| 20 | + // Logger.debug(TAG, 'getBottomNavCacheData 333 ' + JSON.stringify(data)); | ||
| 21 | + if (data) { | ||
| 22 | + let navBean = JSON.parse(CacheData.getNetworkData(data)) as NavigationBodyDTO | ||
| 23 | + success(navBean) | ||
| 24 | + } else { | ||
| 25 | + success(null) | ||
| 26 | + } | ||
| 27 | + }).catch((err: object) => { | ||
| 28 | + Logger.error(TAG, 'getBottomNavCacheData catch err: ' + JSON.stringify(err)); | ||
| 29 | + success(null) | ||
| 30 | + }) | ||
| 31 | + }); | ||
| 32 | + } | ||
| 33 | + | ||
| 34 | + /** | ||
| 35 | + * 保存底导数据到缓存 | ||
| 36 | + */ | ||
| 37 | + saveBottomData(data: NavigationBodyDTO) { | ||
| 38 | + CacheData.saveCacheData(CacheData.bottomCacheKey, data, data.md5) | ||
| 39 | + } | ||
| 40 | + | ||
| 41 | + /** | ||
| 42 | + * 获取底导详情(顶导)缓存数据 | ||
| 43 | + */ | ||
| 44 | + getBottomNavDetailCacheData(id: number): Promise<NavigationDetailDTO | null> { | ||
| 45 | + return new Promise<NavigationDetailDTO | null>((success) => { | ||
| 46 | + CacheData.getLocalCacheData(CacheData.channelCacheDataKey + id).then((data) => { | ||
| 47 | + if (data) { | ||
| 48 | + let navBean = JSON.parse(CacheData.getNetworkData(data)) as NavigationDetailDTO | ||
| 49 | + success(navBean) | ||
| 50 | + } else { | ||
| 51 | + success(null) | ||
| 52 | + } | ||
| 53 | + }).catch((err: object) => { | ||
| 54 | + Logger.error(TAG, 'getBottomNavDetailCacheData catch err: ' + JSON.stringify(err)); | ||
| 55 | + success(null) | ||
| 56 | + }) | ||
| 57 | + }) | ||
| 58 | + } | ||
| 59 | + | ||
| 60 | + /** | ||
| 61 | + * 保存底导详情数据到缓存 | ||
| 62 | + */ | ||
| 63 | + saveBottomDetailData(data: NavigationDetailDTO) { | ||
| 64 | + CacheData.saveCacheData(CacheData.channelCacheDataKey + data?.id, data, data.md5) | ||
| 65 | + } | ||
| 66 | + | ||
| 67 | + /** | ||
| 68 | + * 获取底导接口数据 | ||
| 69 | + */ | ||
| 70 | + async getBottomNavData(): Promise<NavigationBodyDTO> { | ||
| 71 | + Logger.info(TAG, `getBottomNavData start`); | ||
| 72 | + return this.getNavData(); | ||
| 73 | + } | ||
| 74 | + | ||
| 75 | + /** | ||
| 76 | + * 获取底导详情(顶导)接口数据 | ||
| 77 | + */ | ||
| 78 | + async getBottomNavDetailData(id: number): Promise<NavigationDetailDTO> { | ||
| 79 | + Logger.info(TAG, `getBottomNavDetailData start`); | ||
| 80 | + return this.getNavDetailData(id); | ||
| 81 | + } | ||
| 82 | + | ||
| 83 | + private getNavData(): Promise<NavigationBodyDTO> { | ||
| 84 | + return new Promise<NavigationBodyDTO>((success, error) => { | ||
| 85 | + Logger.info(TAG, `getNavData start`); | ||
| 86 | + PageRepository.fetchNavigationDataApi().then((navResDTO: ResponseDTO<NavigationBodyDTO>) => { | ||
| 87 | + if (!navResDTO || !navResDTO.data) { | ||
| 88 | + Logger.error(TAG, 'getNavData then navResDTO is empty'); | ||
| 89 | + error('navResDTO is empty'); | ||
| 90 | + return | ||
| 91 | + } | ||
| 92 | + if (navResDTO.code != 0) { | ||
| 93 | + Logger.error(TAG, `getNavData then code:${navResDTO.code}, message:${navResDTO.message}`); | ||
| 94 | + error('navResDTO Response Code is failure'); | ||
| 95 | + return | ||
| 96 | + } | ||
| 97 | + // let navResStr = JSON.stringify(navResDTO); | ||
| 98 | + Logger.info(TAG, "getNavData then,navResDTO.timestamp:" + navResDTO.timestamp); | ||
| 99 | + navResDTO.data.md5 = navResDTO.meta?.md5 || '' | ||
| 100 | + success(navResDTO.data); | ||
| 101 | + }).catch((err: Error) => { | ||
| 102 | + Logger.error(TAG, `fetchNavigationDataApi catch, error.name : ${err.name}, error.message:${err.message}`); | ||
| 103 | + error(err); | ||
| 104 | + }) | ||
| 105 | + }) | ||
| 106 | + } | ||
| 107 | + | ||
| 108 | + private getNavDetailData(id: number): Promise<NavigationDetailDTO> { | ||
| 109 | + return new Promise<NavigationDetailDTO>((success, error) => { | ||
| 110 | + Logger.info(TAG, `getNavData start`); | ||
| 111 | + PageRepository.fetchNavigationDetailDataApi(id).then((navResDTO: ResponseDTO<NavigationDetailDTO>) => { | ||
| 112 | + if (!navResDTO || !navResDTO.data) { | ||
| 113 | + Logger.error(TAG, 'getNavData then navResDTO is empty'); | ||
| 114 | + error('navResDTO is empty'); | ||
| 115 | + return | ||
| 116 | + } | ||
| 117 | + if (navResDTO.code != 0) { | ||
| 118 | + Logger.error(TAG, `getNavData then code:${navResDTO.code}, message:${navResDTO.message}`); | ||
| 119 | + error('navResDTO Response Code is failure'); | ||
| 120 | + return | ||
| 121 | + } | ||
| 122 | + // let navResStr = JSON.stringify(navResDTO); | ||
| 123 | + Logger.info(TAG, "getNavData then,navResDTO.timestamp:" + navResDTO.timestamp); | ||
| 124 | + navResDTO.data.md5 = navResDTO.meta?.md5 || '' | ||
| 125 | + success(navResDTO.data); | ||
| 126 | + }).catch((err: Error) => { | ||
| 127 | + Logger.error(TAG, `fetchNavigationDataApi catch, error.name : ${err.name}, error.message:${err.message}`); | ||
| 128 | + error(err); | ||
| 129 | + }) | ||
| 130 | + }) | ||
| 131 | + } | ||
| 132 | +} | ||
| 133 | + | ||
| 134 | + | ||
| 135 | +let channelViewModel = new ChannelViewModel(); | ||
| 136 | + | ||
| 137 | +export default channelViewModel as ChannelViewModel; |
| @@ -22,11 +22,6 @@ import { PageRepository } from '../repository/PageRepository'; | @@ -22,11 +22,6 @@ import { PageRepository } from '../repository/PageRepository'; | ||
| 22 | import { BaseViewModel } from './BaseViewModel'; | 22 | import { BaseViewModel } from './BaseViewModel'; |
| 23 | 23 | ||
| 24 | const TAG = 'PageViewModel'; | 24 | const TAG = 'PageViewModel'; |
| 25 | -/** | ||
| 26 | - * mock数据开关,默认关。 | ||
| 27 | - * mock数据是本地json数据,可自行修改内容(‘entry\src\main\resources\rawfile\’目录) | ||
| 28 | - */ | ||
| 29 | -const mock_switch = false; | ||
| 30 | 25 | ||
| 31 | /** | 26 | /** |
| 32 | * 处理返回后的数据 | 27 | * 处理返回后的数据 |
| @@ -37,111 +32,10 @@ export class PageViewModel extends BaseViewModel { | @@ -37,111 +32,10 @@ export class PageViewModel extends BaseViewModel { | ||
| 37 | } | 32 | } |
| 38 | 33 | ||
| 39 | /** | 34 | /** |
| 40 | - * get Nav Data from Resource . | ||
| 41 | - * | ||
| 42 | - * @return BottomNavBean[] Nav Data List | ||
| 43 | - */ | ||
| 44 | - async getBottomNavData(context: Context): Promise<NavigationBodyDTO> { | ||
| 45 | - Logger.info(TAG, `getBottomNavData start`); | ||
| 46 | - if (mock_switch) { | ||
| 47 | - return this.getBottomNavDataMock(context); | ||
| 48 | - } | ||
| 49 | - return this.getNavData(); | ||
| 50 | - } | ||
| 51 | - | ||
| 52 | - async getBottomNavDetailData(id: number): Promise<NavigationDetailDTO> { | ||
| 53 | - Logger.info(TAG, `getBottomNavDetailData start`); | ||
| 54 | - return this.getNavDetailData(id); | ||
| 55 | - } | ||
| 56 | - | ||
| 57 | - async getBottomNavDataMock(context: Context): Promise<NavigationBodyDTO> { | ||
| 58 | - Logger.info(TAG, `getBottomNavDataMock start`); | ||
| 59 | - let compRes: ResponseDTO<NavigationBodyDTO> | null = | ||
| 60 | - await ResourcesUtils.getResourcesJson<ResponseDTO<NavigationBodyDTO>>(context, 'bottom_nav.json'); | ||
| 61 | - if (!compRes || !compRes.data) { | ||
| 62 | - Logger.info(TAG, `getBottomNavDataMock compRes bottomNavList is empty`); | ||
| 63 | - return {} as NavigationBodyDTO | ||
| 64 | - } | ||
| 65 | - Logger.info(TAG, `getBottomNavDataMock getResourcesJsonSync compRes : ${JSON.stringify(compRes)}`); | ||
| 66 | - return compRes.data | ||
| 67 | - } | ||
| 68 | - | ||
| 69 | - private getNavData(): Promise<NavigationBodyDTO> { | ||
| 70 | - return new Promise<NavigationBodyDTO>((success, error) => { | ||
| 71 | - Logger.info(TAG, `getNavData start`); | ||
| 72 | - PageRepository.fetchNavigationDataApi().then((navResDTO: ResponseDTO<NavigationBodyDTO>) => { | ||
| 73 | - if (!navResDTO || !navResDTO.data) { | ||
| 74 | - Logger.error(TAG, 'getNavData then navResDTO is empty'); | ||
| 75 | - error('navResDTO is empty'); | ||
| 76 | - return | ||
| 77 | - } | ||
| 78 | - if (navResDTO.code != 0) { | ||
| 79 | - Logger.error(TAG, `getNavData then code:${navResDTO.code}, message:${navResDTO.message}`); | ||
| 80 | - error('navResDTO Response Code is failure'); | ||
| 81 | - return | ||
| 82 | - } | ||
| 83 | - // let navResStr = JSON.stringify(navResDTO); | ||
| 84 | - Logger.info(TAG, "getNavData then,navResDTO.timestamp:" + navResDTO.timestamp); | ||
| 85 | - success(navResDTO.data); | ||
| 86 | - }).catch((err: Error) => { | ||
| 87 | - Logger.error(TAG, `fetchNavigationDataApi catch, error.name : ${err.name}, error.message:${err.message}`); | ||
| 88 | - error(err); | ||
| 89 | - }) | ||
| 90 | - }) | ||
| 91 | - } | ||
| 92 | - | ||
| 93 | - private getNavDetailData(id: number): Promise<NavigationDetailDTO> { | ||
| 94 | - return new Promise<NavigationDetailDTO>((success, error) => { | ||
| 95 | - Logger.info(TAG, `getNavData start`); | ||
| 96 | - PageRepository.fetchNavigationDetailDataApi(id).then((navResDTO: ResponseDTO<NavigationDetailDTO>) => { | ||
| 97 | - if (!navResDTO || !navResDTO.data) { | ||
| 98 | - Logger.error(TAG, 'getNavData then navResDTO is empty'); | ||
| 99 | - error('navResDTO is empty'); | ||
| 100 | - return | ||
| 101 | - } | ||
| 102 | - if (navResDTO.code != 0) { | ||
| 103 | - Logger.error(TAG, `getNavData then code:${navResDTO.code}, message:${navResDTO.message}`); | ||
| 104 | - error('navResDTO Response Code is failure'); | ||
| 105 | - return | ||
| 106 | - } | ||
| 107 | - // let navResStr = JSON.stringify(navResDTO); | ||
| 108 | - Logger.info(TAG, "getNavData then,navResDTO.timestamp:" + navResDTO.timestamp); | ||
| 109 | - success(navResDTO.data); | ||
| 110 | - }).catch((err: Error) => { | ||
| 111 | - Logger.error(TAG, `fetchNavigationDataApi catch, error.name : ${err.name}, error.message:${err.message}`); | ||
| 112 | - error(err); | ||
| 113 | - }) | ||
| 114 | - }) | ||
| 115 | - } | ||
| 116 | - | ||
| 117 | - /** | ||
| 118 | - * Get PageDTO data. | ||
| 119 | - * | ||
| 120 | - * @return {GroupDTO} compRes.data | ||
| 121 | - */ | ||
| 122 | - private async getPageData1(currentPage: number, context: Context): Promise<PageDTO> { | ||
| 123 | - if (currentPage > 1) { | ||
| 124 | - // 加载更多,返回无数据 | ||
| 125 | - return {} as PageDTO | ||
| 126 | - } | ||
| 127 | - let compRes: ResponseDTO<PageDTO> | null = | ||
| 128 | - await ResourcesUtils.getResourcesJson<ResponseDTO<PageDTO>>(context, 'comp_list0.json'); | ||
| 129 | - if (!compRes || !compRes.data) { | ||
| 130 | - Logger.info(TAG, `getCompList compRes is empty`); | ||
| 131 | - return {} as PageDTO | ||
| 132 | - } | ||
| 133 | - Logger.info(TAG, `getCompList getResourcesJson compRes : ${JSON.stringify(compRes)}`); | ||
| 134 | - return compRes.data | ||
| 135 | - } | ||
| 136 | - | ||
| 137 | - /** | ||
| 138 | * 获取【早晚报】数据 | 35 | * 获取【早晚报】数据 |
| 139 | */ | 36 | */ |
| 140 | async getMorningEveningPaperData(pageId: string): Promise<MorningEveningPaperDTO> { | 37 | async getMorningEveningPaperData(pageId: string): Promise<MorningEveningPaperDTO> { |
| 141 | Logger.debug(TAG, 'getPageData pageId: ' + pageId); | 38 | Logger.debug(TAG, 'getPageData pageId: ' + pageId); |
| 142 | - // if (mock_switch) { | ||
| 143 | - // return this.getPageData3(currentPage, context); | ||
| 144 | - // } | ||
| 145 | 39 | ||
| 146 | return new Promise<MorningEveningPaperDTO>((success, error) => { | 40 | return new Promise<MorningEveningPaperDTO>((success, error) => { |
| 147 | PageRepository.fetchMorningEveningPaperData(pageId) | 41 | PageRepository.fetchMorningEveningPaperData(pageId) |
| @@ -166,18 +60,6 @@ export class PageViewModel extends BaseViewModel { | @@ -166,18 +60,6 @@ export class PageViewModel extends BaseViewModel { | ||
| 166 | }) | 60 | }) |
| 167 | } | 61 | } |
| 168 | 62 | ||
| 169 | - private async getPageData2(context: Context): Promise<PageDTO> { | ||
| 170 | - let compRes: ResponseDTO<PageDTO> | null = | ||
| 171 | - await ResourcesUtils.getResourcesJson<ResponseDTO<PageDTO>>(context, 'comp_list2.json'); | ||
| 172 | - if (!compRes || !compRes.data) { | ||
| 173 | - Logger.info(TAG, `getCompList compRes is empty`); | ||
| 174 | - return {} as PageDTO | ||
| 175 | - } | ||
| 176 | - // router.push('') | ||
| 177 | - Logger.info(TAG, `getCompList getResourcesJson compRes : ${JSON.stringify(compRes)}`); | ||
| 178 | - return compRes.data | ||
| 179 | - } | ||
| 180 | - | ||
| 181 | /** | 63 | /** |
| 182 | * 获取页面楼层的组件信息 | 64 | * 获取页面楼层的组件信息 |
| 183 | * @param pageModel | 65 | * @param pageModel |
| @@ -309,36 +191,6 @@ export class PageViewModel extends BaseViewModel { | @@ -309,36 +191,6 @@ export class PageViewModel extends BaseViewModel { | ||
| 309 | }); | 191 | }); |
| 310 | } | 192 | } |
| 311 | 193 | ||
| 312 | - /** | ||
| 313 | - * @deprecated | ||
| 314 | - */ | ||
| 315 | - private resetInteract(interact: InteractDataDTO[], compList: CompDTO[]) { | ||
| 316 | - if (interact == null || interact.length == 0) { | ||
| 317 | - return | ||
| 318 | - } | ||
| 319 | - interact.forEach((interactData) => { | ||
| 320 | - let id = interactData.contentId; | ||
| 321 | - outer: for (let i = 0; i < compList.length; i++) { | ||
| 322 | - let comp = compList[i]; | ||
| 323 | - if (comp == null || comp.operDataList == null || comp.operDataList.length == 0) { | ||
| 324 | - continue; | ||
| 325 | - } | ||
| 326 | - for (let j = 0; j < comp.operDataList.length; j++) { | ||
| 327 | - let content = comp.operDataList[j]; | ||
| 328 | - if (content == null) { | ||
| 329 | - continue; | ||
| 330 | - } | ||
| 331 | - if (id == content.objectId) { | ||
| 332 | - content.interactData = interactData; | ||
| 333 | - // TODO 测试代码,待删除 | ||
| 334 | - // content.interactData.likeNum = Math.floor(Math.random() * Math.floor(999));; | ||
| 335 | - break outer; | ||
| 336 | - } | ||
| 337 | - } | ||
| 338 | - } | ||
| 339 | - }) | ||
| 340 | - } | ||
| 341 | - | ||
| 342 | private getInteractParams(compList: CompDTO[]): InteractParam { | 194 | private getInteractParams(compList: CompDTO[]): InteractParam { |
| 343 | if (compList == null || compList.length == 0) { | 195 | if (compList == null || compList.length == 0) { |
| 344 | return {} as InteractParam; | 196 | return {} as InteractParam; |
| @@ -482,7 +334,6 @@ export class PageViewModel extends BaseViewModel { | @@ -482,7 +334,6 @@ export class PageViewModel extends BaseViewModel { | ||
| 482 | }) | 334 | }) |
| 483 | }) | 335 | }) |
| 484 | } | 336 | } |
| 485 | - | ||
| 486 | } | 337 | } |
| 487 | 338 | ||
| 488 | 339 |
| @@ -3,6 +3,7 @@ import { WDPushNotificationManager } from 'wdHwAbility/Index' | @@ -3,6 +3,7 @@ import { WDPushNotificationManager } from 'wdHwAbility/Index' | ||
| 3 | import { DeviceUtil, | 3 | import { DeviceUtil, |
| 4 | EmitterEventId, | 4 | EmitterEventId, |
| 5 | EmitterUtils, | 5 | EmitterUtils, |
| 6 | + KVStoreHelper, | ||
| 6 | Logger, | 7 | Logger, |
| 7 | MpaasUtils, NetworkManager, | 8 | MpaasUtils, NetworkManager, |
| 8 | NetworkType, | 9 | NetworkType, |
| @@ -38,7 +39,8 @@ export class StartupManager { | @@ -38,7 +39,8 @@ export class StartupManager { | ||
| 38 | 39 | ||
| 39 | // KV存储 | 40 | // KV存储 |
| 40 | SPHelper.init(context); | 41 | SPHelper.init(context); |
| 41 | - | 42 | + // KV存储(较大数据,value<4M)(首页接口数据缓存用到) |
| 43 | + KVStoreHelper.init(context) | ||
| 42 | // 路由注册 | 44 | // 路由注册 |
| 43 | registerRouter(); | 45 | registerRouter(); |
| 44 | 46 |
-
Please register or login to post a comment