Showing
22 changed files
with
561 additions
and
6 deletions
| @@ -14,6 +14,7 @@ | @@ -14,6 +14,7 @@ | ||
| 14 | "pages/LaunchPage", | 14 | "pages/LaunchPage", |
| 15 | "pages/LaunchAdvertisingPage", | 15 | "pages/LaunchAdvertisingPage", |
| 16 | "pages/PrivacyPage", | 16 | "pages/PrivacyPage", |
| 17 | - "pages/OtherNormalUserHomePage" | 17 | + "pages/OtherNormalUserHomePage", |
| 18 | + "pages/SearchPage" | ||
| 18 | ] | 19 | ] |
| 19 | -} | 20 | +} |
| 1 | +{ | ||
| 2 | + "code": "0", | ||
| 3 | + "data": [ | ||
| 4 | + { | ||
| 5 | + "hotEntry": "习语", | ||
| 6 | + "mark": 1, | ||
| 7 | + "sequence": 1 | ||
| 8 | + }, | ||
| 9 | + { | ||
| 10 | + "hotEntry": "党史学习教育工作", | ||
| 11 | + "mark": 1, | ||
| 12 | + "sequence": 2 | ||
| 13 | + }, | ||
| 14 | + { | ||
| 15 | + "hotEntry": "2024年全国两会新闻中心启用", | ||
| 16 | + "mark": 1, | ||
| 17 | + "sequence": 3 | ||
| 18 | + }, | ||
| 19 | + { | ||
| 20 | + "hotEntry": "第二艘国产大型邮轮后年底交付", | ||
| 21 | + "mark": 0, | ||
| 22 | + "sequence": 4 | ||
| 23 | + }, | ||
| 24 | + { | ||
| 25 | + "hotEntry": "268名跨境电诈犯罪嫌疑人移交", | ||
| 26 | + "mark": 0, | ||
| 27 | + "sequence": 5 | ||
| 28 | + }, | ||
| 29 | + { | ||
| 30 | + "hotEntry": "高考倒计时100天", | ||
| 31 | + "mark": 2, | ||
| 32 | + "sequence": 6 | ||
| 33 | + }, | ||
| 34 | + { | ||
| 35 | + "hotEntry": "日本开始第四轮核污染水排放", | ||
| 36 | + "mark": 0, | ||
| 37 | + "sequence": 7 | ||
| 38 | + }, | ||
| 39 | + { | ||
| 40 | + "hotEntry": "国台办点名管碧玲", | ||
| 41 | + "mark": 0, | ||
| 42 | + "sequence": 8 | ||
| 43 | + }, | ||
| 44 | + { | ||
| 45 | + "hotEntry": "美方称不会向乌克兰派兵", | ||
| 46 | + "mark": 2, | ||
| 47 | + "sequence": 9 | ||
| 48 | + }, | ||
| 49 | + { | ||
| 50 | + "hotEntry": "电动车乱停乱充电", | ||
| 51 | + "mark": 2, | ||
| 52 | + "sequence": 10 | ||
| 53 | + } | ||
| 54 | + ], | ||
| 55 | + "message": "Success", | ||
| 56 | + "success": true, | ||
| 57 | + "timestamp": 1712631086296 | ||
| 58 | +} |
| @@ -44,4 +44,6 @@ export { FollowFirstTabsComponent } from "./components/page/mine/follow/FollowFi | @@ -44,4 +44,6 @@ export { FollowFirstTabsComponent } from "./components/page/mine/follow/FollowFi | ||
| 44 | 44 | ||
| 45 | export { MyHomeComponent } from "./components/page/mine/home/MyHomeComponent" | 45 | export { MyHomeComponent } from "./components/page/mine/home/MyHomeComponent" |
| 46 | 46 | ||
| 47 | -export { OtherUserHomeComponent } from "./components/page/mine/home/OtherUserHomeComponent" | ||
| 47 | +export { OtherUserHomeComponent } from "./components/page/mine/home/OtherUserHomeComponent" | ||
| 48 | + | ||
| 49 | +export { SearchComponent } from "./components/page/search/SearchComponent" |
| 1 | import SearcherAboutDataModel from '../../model/SearcherAboutDataModel' | 1 | import SearcherAboutDataModel from '../../model/SearcherAboutDataModel' |
| 2 | +import RouteManager from '../../utils/RouteManager' | ||
| 2 | /** | 3 | /** |
| 3 | * 首页顶部搜索导航栏 | 4 | * 首页顶部搜索导航栏 |
| 4 | * 竖向滚动实现方案 | 5 | * 竖向滚动实现方案 |
| @@ -61,6 +62,9 @@ export struct FirstTabTopComponent{ | @@ -61,6 +62,9 @@ export struct FirstTabTopComponent{ | ||
| 61 | .backgroundImage($r('app.media.top_search_bg')) | 62 | .backgroundImage($r('app.media.top_search_bg')) |
| 62 | .backgroundImageSize(ImageSize.Cover) | 63 | .backgroundImageSize(ImageSize.Cover) |
| 63 | .alignItems(VerticalAlign.Center) | 64 | .alignItems(VerticalAlign.Center) |
| 65 | + .onClick(()=>{ | ||
| 66 | + RouteManager.jumpNewPage("pages/SearchPage") | ||
| 67 | + }) | ||
| 64 | 68 | ||
| 65 | Image($r('app.media.top_title_bg')) | 69 | Image($r('app.media.top_title_bg')) |
| 66 | .objectFit(ImageFit.Auto) | 70 | .objectFit(ImageFit.Auto) |
| 1 | +import router from '@ohos.router' | ||
| 2 | +import { StringUtils } from 'wdKit/src/main/ets/utils/StringUtils' | ||
| 3 | +import SearcherAboutDataModel from '../../../model/SearcherAboutDataModel' | ||
| 4 | +import { SearchHistoryItem } from '../../../viewmodel/SearchHistoryItem' | ||
| 5 | +import { SearchHistoryComponent } from './SearchHistoryComponent' | ||
| 6 | +import { SearchHotsComponent } from './SearchHotsComponent' | ||
| 7 | + | ||
| 8 | +const TAG = "SearchComponent" | ||
| 9 | + | ||
| 10 | +@Component | ||
| 11 | +export struct SearchComponent { | ||
| 12 | + @State searchTextData: string[] = [] | ||
| 13 | + @State hasInputContent: boolean = false | ||
| 14 | + @State hasChooseSearch: boolean = false | ||
| 15 | + private swiperController: SwiperController = new SwiperController() | ||
| 16 | + @State searchText: string = '' | ||
| 17 | + controller: TextInputController = new TextInputController() | ||
| 18 | + @State searchHistoryData: SearchHistoryItem[] = [] | ||
| 19 | + scroller: Scroller = new Scroller() | ||
| 20 | + | ||
| 21 | + aboutToAppear() { | ||
| 22 | + //获取提示滚动 | ||
| 23 | + this.getSearchHint() | ||
| 24 | + //获取搜索历史 | ||
| 25 | + this.getSearchHistoryData() | ||
| 26 | + } | ||
| 27 | + | ||
| 28 | + getSearchHint() { | ||
| 29 | + SearcherAboutDataModel.getSearchHintData(getContext(this)).then((value) => { | ||
| 30 | + if (value != null) { | ||
| 31 | + this.searchTextData = value | ||
| 32 | + } | ||
| 33 | + }).catch((err: Error) => { | ||
| 34 | + console.log(TAG, JSON.stringify(err)) | ||
| 35 | + }) | ||
| 36 | + } | ||
| 37 | + | ||
| 38 | + getSearchHistoryData() { | ||
| 39 | + this.searchHistoryData = SearcherAboutDataModel.getSearchHistoryData() | ||
| 40 | + } | ||
| 41 | + | ||
| 42 | + build() { | ||
| 43 | + Column() { | ||
| 44 | + this.searchInputComponent() | ||
| 45 | + if (!this.hasInputContent) { | ||
| 46 | + Scroll(this.scroller) { | ||
| 47 | + Column() { | ||
| 48 | + SearchHistoryComponent({ searchHistoryData: $searchHistoryData }) | ||
| 49 | + | ||
| 50 | + //分隔符 | ||
| 51 | + Divider() | ||
| 52 | + .width('100%') | ||
| 53 | + .height('1lpx') | ||
| 54 | + .color($r('app.color.color_EDEDED')) | ||
| 55 | + .strokeWidth('1lpx') | ||
| 56 | + | ||
| 57 | + SearchHotsComponent() | ||
| 58 | + } | ||
| 59 | + } | ||
| 60 | + .scrollable(ScrollDirection.Vertical) | ||
| 61 | + .scrollBar(BarState.Off) | ||
| 62 | + .width('100%') | ||
| 63 | + .height('100%') | ||
| 64 | + .padding({ left: '31lpx', right: '31lpx' }) | ||
| 65 | + } else { | ||
| 66 | + if (this.hasChooseSearch) { | ||
| 67 | + //搜索结果 | ||
| 68 | + | ||
| 69 | + //搜索结果为null(空布局 + 为你推荐) | ||
| 70 | + } else { | ||
| 71 | + //联想搜索 | ||
| 72 | + } | ||
| 73 | + } | ||
| 74 | + }.height('100%') | ||
| 75 | + .width('100%') | ||
| 76 | + } | ||
| 77 | + | ||
| 78 | + //搜索框 | ||
| 79 | + @Builder searchInputComponent() { | ||
| 80 | + Row() { | ||
| 81 | + //左 | ||
| 82 | + Stack({ alignContent: Alignment.Start }) { | ||
| 83 | + if (this.searchTextData != null && this.searchTextData.length > 0 && !this.hasInputContent) { | ||
| 84 | + Swiper(this.swiperController) { | ||
| 85 | + ForEach(this.searchTextData, (item: string, index: number) => { | ||
| 86 | + Text(item) | ||
| 87 | + .fontWeight('400lpx') | ||
| 88 | + .fontSize('25lpx') | ||
| 89 | + .fontColor($r('app.color.color_666666')) | ||
| 90 | + .lineHeight('35lpx') | ||
| 91 | + .textAlign(TextAlign.Start) | ||
| 92 | + .maxLines(1) | ||
| 93 | + .textOverflow({ overflow: TextOverflow.Clip }) | ||
| 94 | + .margin({ left: '40lpx' }) | ||
| 95 | + }) | ||
| 96 | + } | ||
| 97 | + .loop(true) | ||
| 98 | + .autoPlay(true) | ||
| 99 | + .interval(3000) | ||
| 100 | + .indicator(false) | ||
| 101 | + .vertical(true) | ||
| 102 | + .enabled(false) | ||
| 103 | + .focusable(false) | ||
| 104 | + } | ||
| 105 | + TextInput({ text: this.searchText, placeholder: '', controller: this.controller }) | ||
| 106 | + .caretColor(Color.Pink) | ||
| 107 | + .fontSize('27lpx') | ||
| 108 | + .fontColor(Color.Black) | ||
| 109 | + .onChange((value: string) => { | ||
| 110 | + this.searchText = value | ||
| 111 | + if (this.searchText.length > 0) { | ||
| 112 | + this.hasInputContent = false | ||
| 113 | + } else { | ||
| 114 | + this.hasInputContent = true | ||
| 115 | + } | ||
| 116 | + }) | ||
| 117 | + .backgroundColor($r('app.color.color_transparent')) | ||
| 118 | + } | ||
| 119 | + .backgroundImage($r('app.media.search_page_input_bg')) | ||
| 120 | + .backgroundImageSize(ImageSize.Cover) | ||
| 121 | + .layoutWeight(1) | ||
| 122 | + .height('69lpx') | ||
| 123 | + | ||
| 124 | + //右 | ||
| 125 | + Text("取消") | ||
| 126 | + .textAlign(TextAlign.Center) | ||
| 127 | + .fontWeight('400lpx') | ||
| 128 | + .fontSize('31lpx') | ||
| 129 | + .lineHeight('58lpx') | ||
| 130 | + .fontColor($r('app.color.color_222222')) | ||
| 131 | + .width('125lpx') | ||
| 132 | + .height('58lpx') | ||
| 133 | + .onClick(() => { | ||
| 134 | + router.back() | ||
| 135 | + // SearcherAboutDataModel.putSearchHistoryData(this.searchText) | ||
| 136 | + // if(StringUtils.isNotEmpty(this.searchText)){ | ||
| 137 | + // if(this.searchHistoryData.length===10){ | ||
| 138 | + // this.searchHistoryData.pop() | ||
| 139 | + // } | ||
| 140 | + // this.searchHistoryData.push(new SearchHistoryItem(this.searchText)) | ||
| 141 | + // } | ||
| 142 | + }) | ||
| 143 | + } | ||
| 144 | + .height('85lpx') | ||
| 145 | + .padding({ left: '31lpx' }) | ||
| 146 | + .alignItems(VerticalAlign.Center) | ||
| 147 | + .margin({ bottom: '36lpx' }) | ||
| 148 | + } | ||
| 149 | +} |
PeopleDaily_Harmony/wdComponent/src/main/ets/components/page/search/SearchHistoryComponent.ets
0 → 100644
| 1 | +import { SearchHistoryItem } from '../../../viewmodel/SearchHistoryItem' | ||
| 2 | + | ||
| 3 | + | ||
| 4 | +/** | ||
| 5 | + * 搜索历史 | ||
| 6 | + */ | ||
| 7 | +@Component | ||
| 8 | +export struct SearchHistoryComponent{ | ||
| 9 | + @Link searchHistoryData:SearchHistoryItem[] | ||
| 10 | + | ||
| 11 | + build(){ | ||
| 12 | + Column(){ | ||
| 13 | + Row(){ | ||
| 14 | + Text("搜索历史") | ||
| 15 | + .textAlign(TextAlign.Center) | ||
| 16 | + .fontWeight('400lpx') | ||
| 17 | + .fontSize('27lpx') | ||
| 18 | + .lineHeight('38lpx') | ||
| 19 | + .fontColor($r('app.color.color_999999')) | ||
| 20 | + .height('38lpx') | ||
| 21 | + | ||
| 22 | + Image($r('app.media.search_delete_icon')) | ||
| 23 | + .height('31lpx') | ||
| 24 | + .width('31lpx') | ||
| 25 | + .objectFit(ImageFit.Auto) | ||
| 26 | + .onClick(()=>{ | ||
| 27 | + //清空记录 | ||
| 28 | + }) | ||
| 29 | + }.justifyContent(FlexAlign.SpaceBetween) | ||
| 30 | + .margin({bottom:'17lpx'}) | ||
| 31 | + .width('100%') | ||
| 32 | + | ||
| 33 | + Grid(){ | ||
| 34 | + ForEach(this.searchHistoryData,(item:SearchHistoryItem,index:number)=>{ | ||
| 35 | + GridItem(){ | ||
| 36 | + Row(){ | ||
| 37 | + Text(`${item.searchContent}`) | ||
| 38 | + .height('23lpx') | ||
| 39 | + .fontColor($r('app.color.color_222222')) | ||
| 40 | + .fontSize('23lpx') | ||
| 41 | + .maxLines(1) | ||
| 42 | + .constraintSize({maxWidth:index%2 === 0?'270lpx':'250lpx'}) | ||
| 43 | + .textOverflow({ overflow: TextOverflow.Ellipsis }) | ||
| 44 | + .textAlign(TextAlign.Start) | ||
| 45 | + | ||
| 46 | + Image($r('app.media.search_item_delete_icon')) | ||
| 47 | + .width('46lpx') | ||
| 48 | + .height('46lpx') | ||
| 49 | + .margin({right:'31lpx',left:'4lpx'}) | ||
| 50 | + .interpolation(ImageInterpolation.Medium) | ||
| 51 | + .objectFit(ImageFit.Auto) | ||
| 52 | + | ||
| 53 | + Blank() | ||
| 54 | + | ||
| 55 | + if(index%2 === 0 && index != this.searchHistoryData.length-1 ){ | ||
| 56 | + Divider() | ||
| 57 | + .width('2lpx') | ||
| 58 | + .height('23lpx') | ||
| 59 | + .color($r('app.color.color_CCCCCC')) | ||
| 60 | + .strokeWidth('2lpx') | ||
| 61 | + .vertical(true) | ||
| 62 | + } | ||
| 63 | + }.height('100%') | ||
| 64 | + .alignItems(VerticalAlign.Center) | ||
| 65 | + .width('100%') | ||
| 66 | + .margin({left:index%2 === 1?'23lpx':'0lpx'}) | ||
| 67 | + }.onClick(()=>{ | ||
| 68 | + }) | ||
| 69 | + .height('46lpx') | ||
| 70 | + }) | ||
| 71 | + } | ||
| 72 | + .height(this.getCategoryViewHeight()) | ||
| 73 | + .rowsTemplate(this.getCategoryRowTmpl()) | ||
| 74 | + .columnsTemplate('1fr 1fr') | ||
| 75 | + .rowsGap('23lpx') | ||
| 76 | + } | ||
| 77 | + .margin({bottom:'46lpx'}) | ||
| 78 | + } | ||
| 79 | + | ||
| 80 | + getCategoryRowCount() { | ||
| 81 | + return Math.ceil(this.searchHistoryData.length / 2); | ||
| 82 | + } | ||
| 83 | + | ||
| 84 | + getCategoryRowTmpl() { | ||
| 85 | + const count = this.getCategoryRowCount(); | ||
| 86 | + const arr: string[] = new Array(count || 1).fill('1fr'); | ||
| 87 | + console.log('tmpl ', arr.join(' ')) | ||
| 88 | + return arr.join(' '); | ||
| 89 | + } | ||
| 90 | + | ||
| 91 | + getCategoryViewHeight() { | ||
| 92 | + return `${46 * this.getCategoryRowCount()}lpx`; | ||
| 93 | + } | ||
| 94 | +} |
PeopleDaily_Harmony/wdComponent/src/main/ets/components/page/search/SearchHotsComponent.ets
0 → 100644
| 1 | +import SearcherAboutDataModel from '../../../model/SearcherAboutDataModel' | ||
| 2 | +import { SearchHotContentItem } from '../../../viewmodel/SearchHotContentItem' | ||
| 3 | + | ||
| 4 | +const TAG = "SearchHotsComponent" | ||
| 5 | + | ||
| 6 | +/** | ||
| 7 | + * 热门搜索 | ||
| 8 | + */ | ||
| 9 | +@Component | ||
| 10 | +export struct SearchHotsComponent{ | ||
| 11 | + @State searchHotsData:SearchHotContentItem[] = [] | ||
| 12 | + | ||
| 13 | + aboutToAppear(){ | ||
| 14 | + //获取搜索热词 | ||
| 15 | + this.getSearchHotsData() | ||
| 16 | + } | ||
| 17 | + | ||
| 18 | + getSearchHotsData(){ | ||
| 19 | + SearcherAboutDataModel.getSearchHotsData(getContext(this)).then((value)=>{ | ||
| 20 | + if(value!=null){ | ||
| 21 | + this.searchHotsData = value | ||
| 22 | + } | ||
| 23 | + }).catch((err:Error)=>{ | ||
| 24 | + console.log(TAG,JSON.stringify(err)) | ||
| 25 | + }) | ||
| 26 | + } | ||
| 27 | + | ||
| 28 | + build(){ | ||
| 29 | + Column(){ | ||
| 30 | + Row() { | ||
| 31 | + Image($r('app.media.search_hot_icon')) | ||
| 32 | + .width('46lpx') | ||
| 33 | + .height('46lpx') | ||
| 34 | + .objectFit(ImageFit.Auto) | ||
| 35 | + .margin({right:'8lpx'}) | ||
| 36 | + .interpolation(ImageInterpolation.Medium) | ||
| 37 | + | ||
| 38 | + Text("热门搜索") | ||
| 39 | + .textAlign(TextAlign.Center) | ||
| 40 | + .fontWeight('600lpx') | ||
| 41 | + .fontSize('33lpx') | ||
| 42 | + .lineHeight('46lpx') | ||
| 43 | + .fontColor($r('app.color.color_222222')) | ||
| 44 | + .height('38lpx') | ||
| 45 | + } | ||
| 46 | + .width('100%') | ||
| 47 | + | ||
| 48 | + List(){ | ||
| 49 | + ForEach(this.searchHotsData,(item:SearchHotContentItem,index:number)=>{ | ||
| 50 | + ListItem(){ | ||
| 51 | + Column(){ | ||
| 52 | + Column(){ | ||
| 53 | + Row(){ | ||
| 54 | + Row(){ | ||
| 55 | + if(item.sequence <=3){ | ||
| 56 | + Image(item.sequence===1?$r('app.media.search_hot_num1'):item.sequence===2?$r('app.media.search_hot_num2'):$r('app.media.search_hot_num3')) | ||
| 57 | + .width('27lpx') | ||
| 58 | + .height('35lpx') | ||
| 59 | + .objectFit(ImageFit.Auto) | ||
| 60 | + .margin({right:'12lpx'}) | ||
| 61 | + }else { | ||
| 62 | + Text(`${item.sequence}`) | ||
| 63 | + .height('31lpx') | ||
| 64 | + .fontColor($r('app.color.color_666666')) | ||
| 65 | + .fontSize('27lpx') | ||
| 66 | + .fontWeight('400lpx') | ||
| 67 | + .lineHeight('31lpx') | ||
| 68 | + .margin({right:'12lpx'}) | ||
| 69 | + } | ||
| 70 | + Text(`${item.hotEntry}`) | ||
| 71 | + .textOverflow({ overflow: TextOverflow.Ellipsis }) | ||
| 72 | + .fontColor($r('app.color.color_222222')) | ||
| 73 | + .fontSize('31lpx') | ||
| 74 | + .maxLines(1) | ||
| 75 | + .fontWeight('400lpx') | ||
| 76 | + .lineHeight('42lpx') | ||
| 77 | + }.layoutWeight(1) | ||
| 78 | + if(item.mark!=0){ | ||
| 79 | + Image(item.mark===1?$r('app.media.search_hots_mark1'):$r('app.media.search_hots_mark2')) | ||
| 80 | + .width('42lpx') | ||
| 81 | + .height('31lpx') | ||
| 82 | + .objectFit(ImageFit.Auto) | ||
| 83 | + .interpolation(ImageInterpolation.Medium) | ||
| 84 | + } | ||
| 85 | + }.alignItems(VerticalAlign.Center) | ||
| 86 | + .height('84lpx') | ||
| 87 | + .justifyContent(FlexAlign.SpaceBetween) | ||
| 88 | + | ||
| 89 | + if(index != this.searchHotsData.length-1 ){ | ||
| 90 | + Divider() | ||
| 91 | + .width('100%') | ||
| 92 | + .height('1lpx') | ||
| 93 | + .color($r('app.color.color_F5F5F5')) | ||
| 94 | + .strokeWidth('1lpx') | ||
| 95 | + } | ||
| 96 | + }.height('108lpx') | ||
| 97 | + .justifyContent(FlexAlign.Center) | ||
| 98 | + .alignItems(HorizontalAlign.Start) | ||
| 99 | + .padding({left:'27lpx'}) | ||
| 100 | + } | ||
| 101 | + } | ||
| 102 | + .onClick(()=>{ | ||
| 103 | + }) | ||
| 104 | + .height('117lpx') | ||
| 105 | + }) | ||
| 106 | + }.onScrollFrameBegin((offset, state) => { | ||
| 107 | + return { offsetRemain: 0 } | ||
| 108 | + }).layoutWeight(1) | ||
| 109 | + }.width('100%') | ||
| 110 | + .height('100%') | ||
| 111 | + .margin({top:'46lpx'}) | ||
| 112 | + } | ||
| 113 | +} |
| @@ -3,6 +3,8 @@ import { Logger, ResourcesUtils } from 'wdKit'; | @@ -3,6 +3,8 @@ import { Logger, ResourcesUtils } from 'wdKit'; | ||
| 3 | import { ResponseDTO, WDHttp } from 'wdNetwork'; | 3 | import { ResponseDTO, WDHttp } from 'wdNetwork'; |
| 4 | import HashMap from '@ohos.util.HashMap'; | 4 | import HashMap from '@ohos.util.HashMap'; |
| 5 | import { HttpUrlUtils } from '../network/HttpUrlUtils'; | 5 | import { HttpUrlUtils } from '../network/HttpUrlUtils'; |
| 6 | +import { SearchHistoryItem } from '../viewmodel/SearchHistoryItem'; | ||
| 7 | +import { SearchHotContentItem } from '../viewmodel/SearchHotContentItem'; | ||
| 6 | const TAG = "SearcherAboutDataModel" | 8 | const TAG = "SearcherAboutDataModel" |
| 7 | 9 | ||
| 8 | /** | 10 | /** |
| @@ -10,6 +12,7 @@ const TAG = "SearcherAboutDataModel" | @@ -10,6 +12,7 @@ const TAG = "SearcherAboutDataModel" | ||
| 10 | */ | 12 | */ |
| 11 | class SearcherAboutDataModel{ | 13 | class SearcherAboutDataModel{ |
| 12 | private static instance: SearcherAboutDataModel; | 14 | private static instance: SearcherAboutDataModel; |
| 15 | + searchHistoryData:SearchHistoryItem[] = [] | ||
| 13 | 16 | ||
| 14 | private constructor() { } | 17 | private constructor() { } |
| 15 | 18 | ||
| @@ -25,6 +28,53 @@ class SearcherAboutDataModel{ | @@ -25,6 +28,53 @@ class SearcherAboutDataModel{ | ||
| 25 | } | 28 | } |
| 26 | 29 | ||
| 27 | /** | 30 | /** |
| 31 | + * 静态搜索历史记录 | ||
| 32 | + */ | ||
| 33 | + getSearchHistoryData():SearchHistoryItem[]{ | ||
| 34 | + if(this.searchHistoryData.length > 0){ | ||
| 35 | + return this.searchHistoryData | ||
| 36 | + } | ||
| 37 | + this.searchHistoryData.push(new SearchHistoryItem("评论")) | ||
| 38 | + this.searchHistoryData.push(new SearchHistoryItem("关注关注")) | ||
| 39 | + this.searchHistoryData.push(new SearchHistoryItem("收藏收藏收藏")) | ||
| 40 | + this.searchHistoryData.push(new SearchHistoryItem("历史")) | ||
| 41 | + this.searchHistoryData.push(new SearchHistoryItem("消息消息消息消息消息")) | ||
| 42 | + this.searchHistoryData.push(new SearchHistoryItem("留言板留言板留言板留言板留言板")) | ||
| 43 | + this.searchHistoryData.push(new SearchHistoryItem("预约")) | ||
| 44 | + return this.searchHistoryData | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + // async putSearchHistoryData(content:string){ | ||
| 48 | + // let history = await SPHelper.default.get(SearcherAboutDataModel.SEARCH_HISTORY_KEY, '[]') as string; | ||
| 49 | + // this.searchHistoryData = JSON.parse(history) | ||
| 50 | + // this.searchHistoryData.push(new SearchHistoryItem(content)) | ||
| 51 | + // await SPHelper.default.save(SearcherAboutDataModel.SEARCH_HISTORY_KEY, JSON.stringify(this.searchHistoryData)); | ||
| 52 | + // } | ||
| 53 | + | ||
| 54 | + // getSearchHistoryData():Promise<SearchHistoryItem[]>{ | ||
| 55 | + // return new Promise<SearchHistoryItem[]>(async (success, error) => { | ||
| 56 | + // if(this.searchHistoryData!=null && this.searchHistoryData.length>0){ | ||
| 57 | + // success(this.searchHistoryData) | ||
| 58 | + // return | ||
| 59 | + // } | ||
| 60 | + // try { | ||
| 61 | + // let history = await SPHelper.default.get(SearcherAboutDataModel.SEARCH_HISTORY_KEY, '') as string; | ||
| 62 | + // console.log('ycg',history); | ||
| 63 | + // }catch (error){ | ||
| 64 | + // console.log('ycg',"1111"); | ||
| 65 | + // } | ||
| 66 | + // | ||
| 67 | + // this.searchHistoryData = JSON.parse(history) | ||
| 68 | + // this.searchHistoryData.push(new SearchHistoryItem("评论")) | ||
| 69 | + // this.searchHistoryData.push(new SearchHistoryItem("关注关注")) | ||
| 70 | + // this.searchHistoryData.push(new SearchHistoryItem("收藏收藏收藏")) | ||
| 71 | + // | ||
| 72 | + // success(this.searchHistoryData) | ||
| 73 | + // }) | ||
| 74 | + // } | ||
| 75 | + | ||
| 76 | + | ||
| 77 | + /** | ||
| 28 | * 首页 搜索提示滚动内容 | 78 | * 首页 搜索提示滚动内容 |
| 29 | */ | 79 | */ |
| 30 | getSearchHintData(context: Context): Promise<string[]> { | 80 | getSearchHintData(context: Context): Promise<string[]> { |
| @@ -62,6 +112,45 @@ class SearcherAboutDataModel{ | @@ -62,6 +112,45 @@ class SearcherAboutDataModel{ | ||
| 62 | return compRes.data | 112 | return compRes.data |
| 63 | } | 113 | } |
| 64 | 114 | ||
| 115 | + /** | ||
| 116 | + * 搜索主页 热词 | ||
| 117 | + */ | ||
| 118 | + getSearchHotsData(context: Context): Promise<SearchHotContentItem[]> { | ||
| 119 | + return new Promise<SearchHotContentItem[]>((success, error) => { | ||
| 120 | + Logger.info(TAG, `getSearchHintData start`); | ||
| 121 | + this.fetchSearchHotsData().then((navResDTO: ResponseDTO<SearchHotContentItem[]>) => { | ||
| 122 | + if (!navResDTO || navResDTO.code != 0) { | ||
| 123 | + success(this.getSearchHotsDataLocal(context)) | ||
| 124 | + return | ||
| 125 | + } | ||
| 126 | + Logger.info(TAG, "getSearchHotsData then,getSearchHotsData.timeStamp:" + navResDTO.timestamp); | ||
| 127 | + let navigationBean = navResDTO.data as SearchHotContentItem[] | ||
| 128 | + success(navigationBean); | ||
| 129 | + }).catch((err: Error) => { | ||
| 130 | + Logger.error(TAG, `getSearchHotsData catch, error.name : ${err.name}, error.message:${err.message}`); | ||
| 131 | + success(this.getSearchHotsDataLocal(context)) | ||
| 132 | + }) | ||
| 133 | + }) | ||
| 134 | + } | ||
| 135 | + | ||
| 136 | + fetchSearchHotsData() { | ||
| 137 | + let url = HttpUrlUtils.getSearchHotsDataUrl() | ||
| 138 | + let headers: HashMap<string, string> = HttpUrlUtils.getYcgCommonHeaders(); | ||
| 139 | + return WDHttp.get<ResponseDTO<SearchHotContentItem[]>>(url, headers) | ||
| 140 | + }; | ||
| 141 | + | ||
| 142 | + async getSearchHotsDataLocal(context: Context): Promise<SearchHotContentItem[]> { | ||
| 143 | + Logger.info(TAG, `getSearchHotsDataLocal start`); | ||
| 144 | + let compRes: ResponseDTO<SearchHotContentItem[]> | null = await ResourcesUtils.getResourcesJson<ResponseDTO<SearchHotContentItem[]>>('search_hots_data.json' ,context); | ||
| 145 | + if (!compRes || !compRes.data) { | ||
| 146 | + Logger.info(TAG, `getSearchHotsDataLocal compRes is empty`); | ||
| 147 | + return [] | ||
| 148 | + } | ||
| 149 | + Logger.info(TAG, `getSearchHotsDataLocal compRes : ${JSON.stringify(compRes)}`); | ||
| 150 | + return compRes.data | ||
| 151 | + } | ||
| 152 | + | ||
| 153 | + | ||
| 65 | 154 | ||
| 66 | 155 | ||
| 67 | } | 156 | } |
| @@ -121,6 +121,11 @@ export class HttpUrlUtils { | @@ -121,6 +121,11 @@ export class HttpUrlUtils { | ||
| 121 | */ | 121 | */ |
| 122 | static readonly SEARCH_HINT_DATA_PATH: string = "/api/rmrb-search-api/zh/c/hints"; | 122 | static readonly SEARCH_HINT_DATA_PATH: string = "/api/rmrb-search-api/zh/c/hints"; |
| 123 | 123 | ||
| 124 | + /** | ||
| 125 | + * 搜索主页 热词 | ||
| 126 | + */ | ||
| 127 | + static readonly SEARCH_HOTS_DATA_PATH: string = "/api/rmrb-search-api/zh/c/hots"; | ||
| 128 | + | ||
| 124 | private static hostUrl: string = HttpUrlUtils.HOST_UAT; | 129 | private static hostUrl: string = HttpUrlUtils.HOST_UAT; |
| 125 | 130 | ||
| 126 | static getCommonHeaders(): HashMap<string, string> { | 131 | static getCommonHeaders(): HashMap<string, string> { |
| @@ -308,6 +313,10 @@ export class HttpUrlUtils { | @@ -308,6 +313,10 @@ export class HttpUrlUtils { | ||
| 308 | return url | 313 | return url |
| 309 | } | 314 | } |
| 310 | 315 | ||
| 316 | + static getSearchHotsDataUrl() { | ||
| 317 | + let url = HttpUrlUtils.HOST_SIT + HttpUrlUtils.SEARCH_HOTS_DATA_PATH | ||
| 318 | + return url | ||
| 319 | + } | ||
| 311 | 320 | ||
| 312 | /** | 321 | /** |
| 313 | * 点赞操作 | 322 | * 点赞操作 |
| @@ -40,7 +40,7 @@ export class PageViewModel extends BaseViewModel { | @@ -40,7 +40,7 @@ export class PageViewModel extends BaseViewModel { | ||
| 40 | if (mock_switch) { | 40 | if (mock_switch) { |
| 41 | return this.getBottomNavDataMock(context); | 41 | return this.getBottomNavDataMock(context); |
| 42 | } | 42 | } |
| 43 | - return this.getNavData(); | 43 | + return this.getNavData(context); |
| 44 | } | 44 | } |
| 45 | 45 | ||
| 46 | async getBottomNavDataMock(context?: Context): Promise<NavigationBodyDTO> { | 46 | async getBottomNavDataMock(context?: Context): Promise<NavigationBodyDTO> { |
| @@ -54,12 +54,13 @@ export class PageViewModel extends BaseViewModel { | @@ -54,12 +54,13 @@ export class PageViewModel extends BaseViewModel { | ||
| 54 | return compRes.data | 54 | return compRes.data |
| 55 | } | 55 | } |
| 56 | 56 | ||
| 57 | - private getNavData(): Promise<NavigationBodyDTO> { | 57 | + private getNavData(context?: Context): Promise<NavigationBodyDTO> { |
| 58 | return new Promise<NavigationBodyDTO>((success, error) => { | 58 | return new Promise<NavigationBodyDTO>((success, error) => { |
| 59 | Logger.info(TAG, `getNavData start`); | 59 | Logger.info(TAG, `getNavData start`); |
| 60 | PageRepository.fetchNavigationDataApi().then((navResDTO: ResponseDTO<NavigationBodyDTO>) => { | 60 | PageRepository.fetchNavigationDataApi().then((navResDTO: ResponseDTO<NavigationBodyDTO>) => { |
| 61 | if (this.isRespondsInvalid(navResDTO, 'getNavData')) { | 61 | if (this.isRespondsInvalid(navResDTO, 'getNavData')) { |
| 62 | - error("page data invalid"); | 62 | + // error("page data invalid"); |
| 63 | + success(this.getBottomNavDataMock(context)) | ||
| 63 | return | 64 | return |
| 64 | } | 65 | } |
| 65 | Logger.info(TAG, "getNavData then,navResDTO.timeStamp:" + navResDTO.timestamp); | 66 | Logger.info(TAG, "getNavData then,navResDTO.timeStamp:" + navResDTO.timestamp); |
| 1 | +export class SearchHistoryItem{ | ||
| 2 | + searchContent:string = "" | ||
| 3 | + searchUserId:string = "" | ||
| 4 | + searchTime:string = "" | ||
| 5 | + | ||
| 6 | + constructor(searchContent: string,searchUserId?:string,searchTime?:string) { | ||
| 7 | + this.searchContent = searchContent | ||
| 8 | + this.searchUserId = searchUserId | ||
| 9 | + this.searchTime = searchTime | ||
| 10 | + } | ||
| 11 | +} |
239 Bytes
627 Bytes
348 Bytes
379 Bytes
408 Bytes
902 Bytes
863 Bytes
-
Please register or login to post a comment