Showing
9 changed files
with
181 additions
and
0 deletions
| @@ -5,6 +5,7 @@ import { BottomNavDTO } from '../../repository/bean/BottomNavDTO'; | @@ -5,6 +5,7 @@ import { BottomNavDTO } from '../../repository/bean/BottomNavDTO'; | ||
| 5 | import { UIUtils } from '../../repository/UIUtils'; | 5 | import { UIUtils } from '../../repository/UIUtils'; |
| 6 | import { MinePageComponent } from './MinePageComponent'; | 6 | import { MinePageComponent } from './MinePageComponent'; |
| 7 | import PageViewModel from '../../viewmodel/PageViewModel'; | 7 | import PageViewModel from '../../viewmodel/PageViewModel'; |
| 8 | +import { FirstTabTopComponent } from './FirstTabTopComponent'; | ||
| 8 | 9 | ||
| 9 | const TAG = 'BottomNavigationComponent'; | 10 | const TAG = 'BottomNavigationComponent'; |
| 10 | 11 | ||
| @@ -51,6 +52,9 @@ export struct BottomNavigationComponent { | @@ -51,6 +52,9 @@ export struct BottomNavigationComponent { | ||
| 51 | // 我的页面组件数据列表 | 52 | // 我的页面组件数据列表 |
| 52 | MinePageComponent() | 53 | MinePageComponent() |
| 53 | } else { | 54 | } else { |
| 55 | + if(index === 0 ){ | ||
| 56 | + FirstTabTopComponent() | ||
| 57 | + } | ||
| 54 | TopNavigationComponent({ topNavList: navItem.topNavChannelList }) | 58 | TopNavigationComponent({ topNavList: navItem.topNavChannelList }) |
| 55 | } | 59 | } |
| 56 | } | 60 | } |
| 1 | +import SearcherAboutDataModel from '../../model/SearcherAboutDataModel' | ||
| 2 | +/** | ||
| 3 | + * 首页顶部搜索导航栏 | ||
| 4 | + * 竖向滚动实现方案 | ||
| 5 | + * 方案一 使用动画 + 定时器 | ||
| 6 | + * 方案二 使用容器组件Swiper(当前) | ||
| 7 | + */ | ||
| 8 | +const TAG = "FirstTabTopComponent" | ||
| 9 | +@Component | ||
| 10 | +export struct FirstTabTopComponent{ | ||
| 11 | + @State searchTextData :string[] = [] | ||
| 12 | + private swiperController: SwiperController = new SwiperController() | ||
| 13 | + | ||
| 14 | + aboutToAppear(){ | ||
| 15 | + this.getSearchHint() | ||
| 16 | + } | ||
| 17 | + | ||
| 18 | + getSearchHint(){ | ||
| 19 | + SearcherAboutDataModel.getSearchHintData(getContext(this)).then((value)=>{ | ||
| 20 | + if(value!=null){ | ||
| 21 | + this.searchTextData = value | ||
| 22 | + } | ||
| 23 | + }).catch((err:Error)=>{ | ||
| 24 | + console.log(TAG,JSON.stringify(err)) | ||
| 25 | + }) | ||
| 26 | + } | ||
| 27 | + | ||
| 28 | + build(){ | ||
| 29 | + Column(){ | ||
| 30 | + Row(){ | ||
| 31 | + Row(){ | ||
| 32 | + Image($r('app.media.search_icon')) | ||
| 33 | + .objectFit(ImageFit.Cover) | ||
| 34 | + .height('23lpx') | ||
| 35 | + .width('23lpx') | ||
| 36 | + .margin({right:'13lpx'}) | ||
| 37 | + .interpolation(ImageInterpolation.Medium) | ||
| 38 | + | ||
| 39 | + if(this.searchTextData!=null && this.searchTextData.length>0){ | ||
| 40 | + Swiper(this.swiperController) { | ||
| 41 | + ForEach(this.searchTextData, (item: string, index: number ) => { | ||
| 42 | + Text(item) | ||
| 43 | + .fontWeight('400lpx') | ||
| 44 | + .fontSize('25lpx') | ||
| 45 | + .fontColor($r('app.color.color_666666')) | ||
| 46 | + .lineHeight('35lpx') | ||
| 47 | + .textAlign(TextAlign.Start) | ||
| 48 | + .maxLines(1) | ||
| 49 | + .textOverflow({ overflow: TextOverflow.Clip}) | ||
| 50 | + }) | ||
| 51 | + } | ||
| 52 | + .loop(true) | ||
| 53 | + .autoPlay(true) | ||
| 54 | + .interval(3000) | ||
| 55 | + .indicator(false) | ||
| 56 | + .vertical(true) | ||
| 57 | + } | ||
| 58 | + }.width('257lpx') | ||
| 59 | + .height('61lpx') | ||
| 60 | + .padding({left:'31lpx'}) | ||
| 61 | + .backgroundImage($r('app.media.top_search_bg')) | ||
| 62 | + .backgroundImageSize(ImageSize.Cover) | ||
| 63 | + .alignItems(VerticalAlign.Center) | ||
| 64 | + | ||
| 65 | + Image($r('app.media.top_title_bg')) | ||
| 66 | + .objectFit(ImageFit.Auto) | ||
| 67 | + .height('58lpx') | ||
| 68 | + .width('152lpx') | ||
| 69 | + .interpolation(ImageInterpolation.Medium) | ||
| 70 | + | ||
| 71 | + Row(){ | ||
| 72 | + Text("早晚报") | ||
| 73 | + }.backgroundImage($r('app.media.top_right_bg')) | ||
| 74 | + .justifyContent(FlexAlign.Center) | ||
| 75 | + .backgroundImageSize(ImageSize.Cover) | ||
| 76 | + .width('257lpx') | ||
| 77 | + .height('61lpx') | ||
| 78 | + }.width('100%') | ||
| 79 | + .justifyContent(FlexAlign.SpaceBetween) | ||
| 80 | + }.height('73lpx') | ||
| 81 | + .width('100%') | ||
| 82 | + .justifyContent(FlexAlign.End) | ||
| 83 | + .backgroundColor($r('app.color.white')) | ||
| 84 | + } | ||
| 85 | + | ||
| 86 | +} |
| 1 | + | ||
| 2 | +import { Logger, ResourcesUtils } from 'wdKit'; | ||
| 3 | +import { ResponseDTO, WDHttp } from 'wdNetwork'; | ||
| 4 | +import HashMap from '@ohos.util.HashMap'; | ||
| 5 | +import { HttpUrlUtils } from '../network/HttpUrlUtils'; | ||
| 6 | +const TAG = "SearcherAboutDataModel" | ||
| 7 | + | ||
| 8 | +/** | ||
| 9 | + * 我的页面 所有数据 获取封装类 | ||
| 10 | + */ | ||
| 11 | +class SearcherAboutDataModel{ | ||
| 12 | + private static instance: SearcherAboutDataModel; | ||
| 13 | + | ||
| 14 | + private constructor() { } | ||
| 15 | + | ||
| 16 | + /** | ||
| 17 | + * 单例模式 | ||
| 18 | + * @returns | ||
| 19 | + */ | ||
| 20 | + public static getInstance(): SearcherAboutDataModel { | ||
| 21 | + if (!SearcherAboutDataModel.instance) { | ||
| 22 | + SearcherAboutDataModel.instance = new SearcherAboutDataModel(); | ||
| 23 | + } | ||
| 24 | + return SearcherAboutDataModel.instance; | ||
| 25 | + } | ||
| 26 | + | ||
| 27 | + /** | ||
| 28 | + * 首页 搜索提示滚动内容 | ||
| 29 | + */ | ||
| 30 | + getSearchHintData(context: Context): Promise<string[]> { | ||
| 31 | + return new Promise<string[]>((success, error) => { | ||
| 32 | + Logger.info(TAG, `getSearchHintData start`); | ||
| 33 | + this.fetchSearchHintData().then((navResDTO: ResponseDTO<string[]>) => { | ||
| 34 | + if (!navResDTO || navResDTO.code != 0) { | ||
| 35 | + success(this.getSearchHintDataLocal(context)) | ||
| 36 | + return | ||
| 37 | + } | ||
| 38 | + Logger.info(TAG, "getSearchHintData then,SearchHintDataResDTO.timeStamp:" + navResDTO.timestamp); | ||
| 39 | + let navigationBean = navResDTO.data as string[] | ||
| 40 | + success(navigationBean); | ||
| 41 | + }).catch((err: Error) => { | ||
| 42 | + Logger.error(TAG, `fetchSearchHintData catch, error.name : ${err.name}, error.message:${err.message}`); | ||
| 43 | + success(this.getSearchHintDataLocal(context)) | ||
| 44 | + }) | ||
| 45 | + }) | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + fetchSearchHintData() { | ||
| 49 | + let url = HttpUrlUtils.getSearchHintDataUrl() | ||
| 50 | + let headers: HashMap<string, string> = HttpUrlUtils.getYcgCommonHeaders(); | ||
| 51 | + return WDHttp.get<ResponseDTO<string[]>>(url, headers) | ||
| 52 | + }; | ||
| 53 | + | ||
| 54 | + async getSearchHintDataLocal(context: Context): Promise<string[]> { | ||
| 55 | + Logger.info(TAG, `getSearchHintDataLocal start`); | ||
| 56 | + let compRes: ResponseDTO<string[]> | null = await ResourcesUtils.getResourcesJson<ResponseDTO<string[]>>('search_hint_data.json' ,context); | ||
| 57 | + if (!compRes || !compRes.data) { | ||
| 58 | + Logger.info(TAG, `getSearchHintDataLocal compRes is empty`); | ||
| 59 | + return [] | ||
| 60 | + } | ||
| 61 | + Logger.info(TAG, `getSearchHintDataLocal compRes : ${JSON.stringify(compRes)}`); | ||
| 62 | + return compRes.data | ||
| 63 | + } | ||
| 64 | + | ||
| 65 | + | ||
| 66 | + | ||
| 67 | +} | ||
| 68 | + | ||
| 69 | +const searcherAboutDataModel = SearcherAboutDataModel.getInstance() | ||
| 70 | +export default searcherAboutDataModel as SearcherAboutDataModel |
| @@ -116,6 +116,11 @@ export class HttpUrlUtils { | @@ -116,6 +116,11 @@ export class HttpUrlUtils { | ||
| 116 | */ | 116 | */ |
| 117 | static readonly APPOINTMENT_OPERATION_STATUS_PATH: string = "/api/live-center-message/zh/c/live/subscribe"; | 117 | static readonly APPOINTMENT_OPERATION_STATUS_PATH: string = "/api/live-center-message/zh/c/live/subscribe"; |
| 118 | 118 | ||
| 119 | + /** | ||
| 120 | + * 首页 搜索提示 | ||
| 121 | + */ | ||
| 122 | + static readonly SEARCH_HINT_DATA_PATH: string = "/api/rmrb-search-api/zh/c/hints"; | ||
| 123 | + | ||
| 119 | private static hostUrl: string = HttpUrlUtils.HOST_UAT; | 124 | private static hostUrl: string = HttpUrlUtils.HOST_UAT; |
| 120 | 125 | ||
| 121 | static getCommonHeaders(): HashMap<string, string> { | 126 | static getCommonHeaders(): HashMap<string, string> { |
| @@ -298,6 +303,11 @@ export class HttpUrlUtils { | @@ -298,6 +303,11 @@ export class HttpUrlUtils { | ||
| 298 | return url | 303 | return url |
| 299 | } | 304 | } |
| 300 | 305 | ||
| 306 | + static getSearchHintDataUrl() { | ||
| 307 | + let url = HttpUrlUtils.HOST_SIT + HttpUrlUtils.SEARCH_HINT_DATA_PATH | ||
| 308 | + return url | ||
| 309 | + } | ||
| 310 | + | ||
| 301 | 311 | ||
| 302 | /** | 312 | /** |
| 303 | * 点赞操作 | 313 | * 点赞操作 |
818 Bytes
631 Bytes
565 Bytes
-
Please register or login to post a comment