chenjun3_wd

动态获取早晚报pageId

1 // import { FrontLinkObject, MorningEveningPaperDTO, PageInfoBean } from 'wdBean'; 1 // import { FrontLinkObject, MorningEveningPaperDTO, PageInfoBean } from 'wdBean';
2 import { CompList, PageInfoBean } from 'wdBean'; 2 import { CompList, PageInfoBean } from 'wdBean';
3 -import { DateTimeUtils, Logger } from 'wdKit/Index'; 3 +import { DateTimeUtils, Logger, SPHelper } from 'wdKit/Index';
4 import { PaperReaderSimpleDialog } from '../../dialog/PaperReaderDialog'; 4 import { PaperReaderSimpleDialog } from '../../dialog/PaperReaderDialog';
5 import { MorningEveningViewModel } from '../../viewmodel/MorningEveningViewModel'; 5 import { MorningEveningViewModel } from '../../viewmodel/MorningEveningViewModel';
6 // import { AudioBarView } from './AudioBarView'; 6 // import { AudioBarView } from './AudioBarView';
@@ -21,6 +21,7 @@ export struct MorningEveningPaperComponent { @@ -21,6 +21,7 @@ export struct MorningEveningPaperComponent {
21 // @State compInfoBean: CompInfoBean = {} as CompInfoBean 21 // @State compInfoBean: CompInfoBean = {} as CompInfoBean
22 @State compListItem: CompList = {} as CompList 22 @State compListItem: CompList = {} as CompList
23 @State audioPlayUrl: string = "" 23 @State audioPlayUrl: string = ""
  24 + // @Consume dailyPaperTopicPageId: number
24 // @Provide compListItem: CompList = {} as CompList 25 // @Provide compListItem: CompList = {} as CompList
25 // @State morningEveningPaperDTO: MorningEveningPaperDTO = { 26 // @State morningEveningPaperDTO: MorningEveningPaperDTO = {
26 // name: "新闻夜读", 27 // name: "新闻夜读",
@@ -92,13 +93,14 @@ export struct MorningEveningPaperComponent { @@ -92,13 +93,14 @@ export struct MorningEveningPaperComponent {
92 } 93 }
93 94
94 async aboutToAppear() { 95 async aboutToAppear() {
95 - console.info(TAG, `aboutToAppear`)  
96 - 96 + let dailyPaperTopicPageId = await SPHelper.default.getSync('dailyPaperTopicPageId', "") as String
  97 + console.info(TAG, `aboutToAppear = ` + dailyPaperTopicPageId)
97 const currentTime = new Date().getTime() 98 const currentTime = new Date().getTime()
98 Logger.info(TAG, "currentTime = " + currentTime) 99 Logger.info(TAG, "currentTime = " + currentTime)
99 Logger.info(TAG, `currentTime = ${currentTime}`) 100 Logger.info(TAG, `currentTime = ${currentTime}`)
100 try { 101 try {
101 - let pageInfoBean = await MorningEveningViewModel.getMorningEveningPageInfo("25091") 102 + // let pageInfoBean = await MorningEveningViewModel.getMorningEveningPageInfo("" + this.dailyPaperTopicPageId)
  103 + let pageInfoBean = await MorningEveningViewModel.getMorningEveningPageInfo("" + dailyPaperTopicPageId)
102 this.pageInfoBean = pageInfoBean; 104 this.pageInfoBean = pageInfoBean;
103 this.title = this.pageInfoBean?.topicInfo?.title 105 this.title = this.pageInfoBean?.topicInfo?.title
104 let dateTime = DateTimeUtils.parseDate(this.pageInfoBean?.topicInfo?.topicDate ?? '', DateTimeUtils.PATTERN_DATE_HYPHEN); 106 let dateTime = DateTimeUtils.parseDate(this.pageInfoBean?.topicInfo?.topicDate ?? '', DateTimeUtils.PATTERN_DATE_HYPHEN);
@@ -4,45 +4,52 @@ @@ -4,45 +4,52 @@
4 * 方案一 使用动画 + 定时器 4 * 方案一 使用动画 + 定时器
5 * 方案二 使用容器组件Swiper(当前) 5 * 方案二 使用容器组件Swiper(当前)
6 */ 6 */
  7 +import { SPHelper } from 'wdKit/Index'
7 import { WDRouterPage, WDRouterRule } from 'wdRouter' 8 import { WDRouterPage, WDRouterRule } from 'wdRouter'
  9 +import DailyPaperTopicModel from '../../model/DailyPaperTopicModel'
8 import SearcherAboutDataModel from '../../model/SearcherAboutDataModel' 10 import SearcherAboutDataModel from '../../model/SearcherAboutDataModel'
9 11
10 const TAG = "FirstTabTopSearchComponent" 12 const TAG = "FirstTabTopSearchComponent"
  13 +
11 @Component 14 @Component
12 -export struct FirstTabTopSearchComponent{  
13 - @State searchTextData :string[] = [] 15 +export struct FirstTabTopSearchComponent {
  16 + @State searchTextData: string[] = []
14 private swiperController: SwiperController = new SwiperController() 17 private swiperController: SwiperController = new SwiperController()
15 18
16 - aboutToAppear(){ 19 + async aboutToAppear() {
17 this.getSearchHint() 20 this.getSearchHint()
  21 + let dailyPaperTopicBean = await DailyPaperTopicModel.getDailyPaperTopic()
  22 + if (dailyPaperTopicBean) {
  23 + SPHelper.default.saveSync('dailyPaperTopicPageId', dailyPaperTopicBean.id);
  24 + }
18 } 25 }
19 26
20 - getSearchHint(){  
21 - SearcherAboutDataModel.getSearchHintData(getContext(this)).then((value)=>{  
22 - if(value!=null){ 27 + getSearchHint() {
  28 + SearcherAboutDataModel.getSearchHintData(getContext(this)).then((value) => {
  29 + if (value != null) {
23 this.searchTextData = value 30 this.searchTextData = value
24 } 31 }
25 - }).catch((err:Error)=>{  
26 - console.log(TAG,JSON.stringify(err)) 32 + }).catch((err: Error) => {
  33 + console.log(TAG, JSON.stringify(err))
27 }) 34 })
28 } 35 }
29 36
30 - build(){  
31 - Row(){ 37 + build() {
  38 + Row() {
32 Image($r('app.media.icon_search')) 39 Image($r('app.media.icon_search'))
33 .width(18) 40 .width(18)
34 .height(18) 41 .height(18)
35 42
36 - if(this.searchTextData!=null && this.searchTextData.length>0){ 43 + if (this.searchTextData != null && this.searchTextData.length > 0) {
37 Swiper(this.swiperController) { 44 Swiper(this.swiperController) {
38 - ForEach(this.searchTextData, (item: string, index: number ) => { 45 + ForEach(this.searchTextData, (item: string, index: number) => {
39 Text(item) 46 Text(item)
40 .fontWeight(400) 47 .fontWeight(400)
41 .fontColor($r('app.color.color_B0B0B0')) 48 .fontColor($r('app.color.color_B0B0B0'))
42 .fontSize($r('app.float.font_size_13')) 49 .fontSize($r('app.float.font_size_13'))
43 .textAlign(TextAlign.Start) 50 .textAlign(TextAlign.Start)
44 .maxLines(1) 51 .maxLines(1)
45 - .textOverflow({ overflow: TextOverflow.Clip}) 52 + .textOverflow({ overflow: TextOverflow.Clip })
46 }) 53 })
47 } 54 }
48 .loop(true) 55 .loop(true)
@@ -52,14 +59,14 @@ export struct FirstTabTopSearchComponent{ @@ -52,14 +59,14 @@ export struct FirstTabTopSearchComponent{
52 .vertical(true) 59 .vertical(true)
53 .height(30) 60 .height(30)
54 } 61 }
55 - }.height(30) 62 + }
  63 + .height(30)
56 .width(124) 64 .width(124)
57 - .padding({left:15}) 65 + .padding({ left: 15 })
58 .backgroundImage($r('app.media.background_search')) 66 .backgroundImage($r('app.media.background_search'))
59 .backgroundImageSize(ImageSize.Cover) 67 .backgroundImageSize(ImageSize.Cover)
60 - .onClick(()=>{ 68 + .onClick(() => {
61 WDRouterRule.jumpWithPage(WDRouterPage.searchPage) 69 WDRouterRule.jumpWithPage(WDRouterPage.searchPage)
62 }) 70 })
63 } 71 }
64 -  
65 } 72 }
  1 +import { PageInfoBean } from 'wdBean/Index';
  2 +import { Logger } from 'wdKit/Index';
  3 +import { ResponseDTO } from 'wdNetwork/Index';
  4 +import { PageRepository } from '../repository/PageRepository';
  5 +
  6 +const TAG = "SearcherAboutDataModel"
  7 +
  8 +class DailyPaperTopicModel {
  9 + private static instance: DailyPaperTopicModel;
  10 +
  11 + /**
  12 + * 单例模式
  13 + * @returns
  14 + */
  15 + public static getInstance(): DailyPaperTopicModel {
  16 + if (!DailyPaperTopicModel.instance) {
  17 + DailyPaperTopicModel.instance = new DailyPaperTopicModel();
  18 + }
  19 + return DailyPaperTopicModel.instance;
  20 + }
  21 +
  22 + /**
  23 + * 首页 搜索提示滚动内容
  24 + */
  25 + // getSearchHintData(context: Context): Promise<string[]> {
  26 + // return new Promise<string[]>((success, error) => {
  27 + // Logger.info(TAG, `getSearchHintData start`);
  28 + // this.fetchSearchHintData().then((navResDTO: ResponseDTO<string[]>) => {
  29 + // // if (!navResDTO || navResDTO.code != 0) {
  30 + // // success(this.getSearchHintDataLocal(context))
  31 + // // return
  32 + // // }
  33 + // Logger.info(TAG, "getSearchHintData then,SearchHintDataResDTO.timeStamp:" + navResDTO.timestamp);
  34 + // let navigationBean = navResDTO.data as string[]
  35 + // success(navigationBean);
  36 + // }).catch((err: Error) => {
  37 + // Logger.error(TAG, `fetchSearchHintData catch, error.name : ${err.name}, error.message:${err.message}`);
  38 + // success(this.getSearchHintDataLocal(context))
  39 + // })
  40 + // })
  41 + // }
  42 + public async getDailyPaperTopic(): Promise<PageInfoBean> {
  43 + return new Promise<PageInfoBean>((success, error) => {
  44 + Logger.info(TAG, `getDailyPaperTopic pageInfo start`);
  45 + PageRepository.fetchDailyPaperTopic()
  46 + .then((resDTO: ResponseDTO<PageInfoBean>) => {
  47 + if (!resDTO || !resDTO.data) {
  48 + Logger.error(TAG, 'getDailyPaperTopic then navResDTO is empty');
  49 + error('resDTO is empty');
  50 + return
  51 + }
  52 + if (resDTO.code != 0) {
  53 + Logger.error(TAG, `getDailyPaperTopic then code:${resDTO.code}, message:${resDTO.message}`);
  54 + error('resDTO Response Code is failure');
  55 + return
  56 + }
  57 + // let navResStr = JSON.stringify(navResDTO);
  58 + Logger.info(TAG, "getDailyPaperTopic then,navResDTO.timestamp:" + resDTO.timestamp);
  59 + success(resDTO.data);
  60 + })
  61 + .catch((err: Error) => {
  62 + Logger.error(TAG, `getDailyPaperTopic catch, error.name : ${err.name}, error.message:${err.message}`);
  63 + error(err);
  64 + })
  65 + })
  66 + }
  67 +}
  68 +
  69 +const dailyPaperTopicModel = DailyPaperTopicModel.getInstance()
  70 +
  71 +export default dailyPaperTopicModel as DailyPaperTopicModel