chenjun3_wd

动态获取早晚报pageId

// import { FrontLinkObject, MorningEveningPaperDTO, PageInfoBean } from 'wdBean';
import { CompList, PageInfoBean } from 'wdBean';
import { DateTimeUtils, Logger } from 'wdKit/Index';
import { DateTimeUtils, Logger, SPHelper } from 'wdKit/Index';
import { PaperReaderSimpleDialog } from '../../dialog/PaperReaderDialog';
import { MorningEveningViewModel } from '../../viewmodel/MorningEveningViewModel';
// import { AudioBarView } from './AudioBarView';
... ... @@ -21,6 +21,7 @@ export struct MorningEveningPaperComponent {
// @State compInfoBean: CompInfoBean = {} as CompInfoBean
@State compListItem: CompList = {} as CompList
@State audioPlayUrl: string = ""
// @Consume dailyPaperTopicPageId: number
// @Provide compListItem: CompList = {} as CompList
// @State morningEveningPaperDTO: MorningEveningPaperDTO = {
// name: "新闻夜读",
... ... @@ -92,13 +93,14 @@ export struct MorningEveningPaperComponent {
}
async aboutToAppear() {
console.info(TAG, `aboutToAppear`)
let dailyPaperTopicPageId = await SPHelper.default.getSync('dailyPaperTopicPageId', "") as String
console.info(TAG, `aboutToAppear = ` + dailyPaperTopicPageId)
const currentTime = new Date().getTime()
Logger.info(TAG, "currentTime = " + currentTime)
Logger.info(TAG, `currentTime = ${currentTime}`)
try {
let pageInfoBean = await MorningEveningViewModel.getMorningEveningPageInfo("25091")
// let pageInfoBean = await MorningEveningViewModel.getMorningEveningPageInfo("" + this.dailyPaperTopicPageId)
let pageInfoBean = await MorningEveningViewModel.getMorningEveningPageInfo("" + dailyPaperTopicPageId)
this.pageInfoBean = pageInfoBean;
this.title = this.pageInfoBean?.topicInfo?.title
let dateTime = DateTimeUtils.parseDate(this.pageInfoBean?.topicInfo?.topicDate ?? '', DateTimeUtils.PATTERN_DATE_HYPHEN);
... ...
... ... @@ -4,62 +4,69 @@
* 方案一 使用动画 + 定时器
* 方案二 使用容器组件Swiper(当前)
*/
import { SPHelper } from 'wdKit/Index'
import { WDRouterPage, WDRouterRule } from 'wdRouter'
import DailyPaperTopicModel from '../../model/DailyPaperTopicModel'
import SearcherAboutDataModel from '../../model/SearcherAboutDataModel'
const TAG = "FirstTabTopSearchComponent"
@Component
export struct FirstTabTopSearchComponent{
@State searchTextData :string[] = []
export struct FirstTabTopSearchComponent {
@State searchTextData: string[] = []
private swiperController: SwiperController = new SwiperController()
aboutToAppear(){
async aboutToAppear() {
this.getSearchHint()
let dailyPaperTopicBean = await DailyPaperTopicModel.getDailyPaperTopic()
if (dailyPaperTopicBean) {
SPHelper.default.saveSync('dailyPaperTopicPageId', dailyPaperTopicBean.id);
}
}
getSearchHint(){
SearcherAboutDataModel.getSearchHintData(getContext(this)).then((value)=>{
if(value!=null){
getSearchHint() {
SearcherAboutDataModel.getSearchHintData(getContext(this)).then((value) => {
if (value != null) {
this.searchTextData = value
}
}).catch((err:Error)=>{
console.log(TAG,JSON.stringify(err))
}).catch((err: Error) => {
console.log(TAG, JSON.stringify(err))
})
}
build(){
Row(){
Image($r('app.media.icon_search'))
.width(18)
.height(18)
build() {
Row() {
Image($r('app.media.icon_search'))
.width(18)
.height(18)
if(this.searchTextData!=null && this.searchTextData.length>0){
Swiper(this.swiperController) {
ForEach(this.searchTextData, (item: string, index: number ) => {
Text(item)
.fontWeight(400)
.fontColor($r('app.color.color_B0B0B0'))
.fontSize($r('app.float.font_size_13'))
.textAlign(TextAlign.Start)
.maxLines(1)
.textOverflow({ overflow: TextOverflow.Clip})
})
}
.loop(true)
.autoPlay(true)
.interval(3000)
.indicator(false)
.vertical(true)
.height(30)
}
}.height(30)
.width(124)
.padding({left:15})
.backgroundImage($r('app.media.background_search'))
.backgroundImageSize(ImageSize.Cover)
.onClick(()=>{
WDRouterRule.jumpWithPage(WDRouterPage.searchPage)
})
if (this.searchTextData != null && this.searchTextData.length > 0) {
Swiper(this.swiperController) {
ForEach(this.searchTextData, (item: string, index: number) => {
Text(item)
.fontWeight(400)
.fontColor($r('app.color.color_B0B0B0'))
.fontSize($r('app.float.font_size_13'))
.textAlign(TextAlign.Start)
.maxLines(1)
.textOverflow({ overflow: TextOverflow.Clip })
})
}
.loop(true)
.autoPlay(true)
.interval(3000)
.indicator(false)
.vertical(true)
.height(30)
}
}
.height(30)
.width(124)
.padding({ left: 15 })
.backgroundImage($r('app.media.background_search'))
.backgroundImageSize(ImageSize.Cover)
.onClick(() => {
WDRouterRule.jumpWithPage(WDRouterPage.searchPage)
})
}
}
\ No newline at end of file
... ...
import { PageInfoBean } from 'wdBean/Index';
import { Logger } from 'wdKit/Index';
import { ResponseDTO } from 'wdNetwork/Index';
import { PageRepository } from '../repository/PageRepository';
const TAG = "SearcherAboutDataModel"
class DailyPaperTopicModel {
private static instance: DailyPaperTopicModel;
/**
* 单例模式
* @returns
*/
public static getInstance(): DailyPaperTopicModel {
if (!DailyPaperTopicModel.instance) {
DailyPaperTopicModel.instance = new DailyPaperTopicModel();
}
return DailyPaperTopicModel.instance;
}
/**
* 首页 搜索提示滚动内容
*/
// getSearchHintData(context: Context): Promise<string[]> {
// return new Promise<string[]>((success, error) => {
// Logger.info(TAG, `getSearchHintData start`);
// this.fetchSearchHintData().then((navResDTO: ResponseDTO<string[]>) => {
// // if (!navResDTO || navResDTO.code != 0) {
// // success(this.getSearchHintDataLocal(context))
// // return
// // }
// Logger.info(TAG, "getSearchHintData then,SearchHintDataResDTO.timeStamp:" + navResDTO.timestamp);
// let navigationBean = navResDTO.data as string[]
// success(navigationBean);
// }).catch((err: Error) => {
// Logger.error(TAG, `fetchSearchHintData catch, error.name : ${err.name}, error.message:${err.message}`);
// success(this.getSearchHintDataLocal(context))
// })
// })
// }
public async getDailyPaperTopic(): Promise<PageInfoBean> {
return new Promise<PageInfoBean>((success, error) => {
Logger.info(TAG, `getDailyPaperTopic pageInfo start`);
PageRepository.fetchDailyPaperTopic()
.then((resDTO: ResponseDTO<PageInfoBean>) => {
if (!resDTO || !resDTO.data) {
Logger.error(TAG, 'getDailyPaperTopic then navResDTO is empty');
error('resDTO is empty');
return
}
if (resDTO.code != 0) {
Logger.error(TAG, `getDailyPaperTopic then code:${resDTO.code}, message:${resDTO.message}`);
error('resDTO Response Code is failure');
return
}
// let navResStr = JSON.stringify(navResDTO);
Logger.info(TAG, "getDailyPaperTopic then,navResDTO.timestamp:" + resDTO.timestamp);
success(resDTO.data);
})
.catch((err: Error) => {
Logger.error(TAG, `getDailyPaperTopic catch, error.name : ${err.name}, error.message:${err.message}`);
error(err);
})
})
}
}
const dailyPaperTopicModel = DailyPaperTopicModel.getInstance()
export default dailyPaperTopicModel as DailyPaperTopicModel
... ...