yangchenggong1_wd

desc:搜索结果 显示主页

... ... @@ -185,12 +185,19 @@ export class HttpUrlUtils {
* 搜索联想词
*/
static readonly RELATED_SEARCH_CONTENT_DATA_PATH: string = "/api/rmrb-search-api/zh/c/suggestions/";
/**
* 直播详情
*/
static readonly LIVE_DETAILS_PATH: string = "/api/rmrb-bff-display-zh/content/zh/c/content/detail";
/**
* 搜索结果 显示tab 数
*/
static readonly SEARCH_RESULT_COUNT_DATA_PATH: string = "/api/rmrb-search-api/zh/c/count?keyword=";
/**
* 早晚报列表
* 根据页面id获取页面楼层列表
* https://pdapis.pdnews.cn/api/rmrb-bff-display-zh/display/zh/c/pageInfo?pageId=28927
... ... @@ -581,6 +588,11 @@ export class HttpUrlUtils {
return url
}
static getSearchResultCountDataUrl() {
let url = HttpUrlUtils._hostUrl + HttpUrlUtils.SEARCH_RESULT_COUNT_DATA_PATH
return url
}
// static getYcgCommonHeaders(): HashMap<string, string> {
// let headers: HashMap<string, string> = new HashMap<string, string>()
//
... ...
... ... @@ -53,6 +53,7 @@ export struct FollowSecondTabsComponent{
.width('100%')
}.width('100%')
.alignItems(VerticalAlign.Top)
.backgroundColor('#0FF')
}
@Builder TabBuilder(index: number, item: FollowSecondListItem) {
... ...
... ... @@ -6,6 +6,7 @@ import { SearchRelatedItem } from '../../viewmodel/SearchRelatedItem'
import { SearchHistoryComponent } from './SearchHistoryComponent'
import { SearchHotsComponent } from './SearchHotsComponent'
import { SearchRelatedComponent } from './SearchRelatedComponent'
import { SearchResultComponent } from './SearchResultComponent'
const TAG = "SearchComponent"
... ... @@ -23,6 +24,7 @@ export struct SearchComponent {
@State searchHistoryData: SearchHistoryItem[] = []
@State relatedSearchContentsData: SearchRelatedItem[] = []
scroller: Scroller = new Scroller()
@State count:string[] = []
aboutToAppear() {
//获取提示滚动
... ... @@ -110,9 +112,7 @@ export struct SearchComponent {
} else {
if (this.hasChooseSearch) {
//搜索结果
//搜索结果为null(空布局 + 为你推荐)
SearchResultComponent({count:this.count,searchText:this.searchText})
} else {
//联想搜索
SearchRelatedComponent({relatedSearchContentData:$relatedSearchContentsData,onGetSearchRes: (item): void => this.getSearchRelatedResData(item),searchText:this.searchText})
... ... @@ -145,10 +145,37 @@ export struct SearchComponent {
this.relatedSearchContentsData = []
//查询 操作 TODO
this.hasChooseSearch = true
this.getSearchResultCountData()
}
getSearchResultCountData() {
SearcherAboutDataModel.getSearchResultCountData(encodeURI(this.searchText),getContext(this)).then((value) => {
if (value != null) {
this.count = []
if(value.allTotal!=0){
this.count.push("全部")
}
if(value.cmsTotal!=0){
this.count.push("精选")
}
if(value.rmhTotal!=0){
this.count.push("人民号")
}
if(value.videoTotal!=0){
this.count.push("视频")
}
if(value.activityTotal!=0){
this.count.push("活动")
}
}
}).catch((err: Error) => {
console.log(TAG, JSON.stringify(err))
})
}
/**
* 点击联想搜索列表回调
* @param content
... ... @@ -227,6 +254,7 @@ export struct SearchComponent {
.onClick(()=>{
this.searchText = ""
this.hasInputContent = false
this.hasChooseSearch = false
})
}
}.padding({right:'30lpx'})
... ...
import SearcherAboutDataModel from '../../model/SearcherAboutDataModel'
import { SearchHotContentItem } from '../../viewmodel/SearchHotContentItem'
import { SearchRelatedItem } from '../../viewmodel/SearchRelatedItem'
const TAG = "SearchRelatedComponent"
... ...
const TAG = "SearchResultComponent"
/**
* 搜索结果
* 搜索结果为null(空布局 + 为你推荐)
*/
@Component
export struct SearchResultComponent{
@Prop count:string[] = []
@Prop searchText: string
@State currentIndex: number = 0
private controller: TabsController = new TabsController()
fontColor: string = '#999999'
selectedFontColor: string = '#000000'
build() {
Column() {
Tabs({ barPosition: BarPosition.Start, controller: this.controller }) {
ForEach(this.count, (item: string, index: number ) => {
TabContent(){
Text(item)
}.tabBar(this.TabBuilder(index,item))
}, (item: string, index: number) => index.toString())
}
.vertical(false)
.barMode(BarMode.Fixed)
.barWidth('100%')
.barHeight('84lpx')
.animationDuration(0)
.onChange((index: number) => {
this.currentIndex = index
})
.width('100%')
.layoutWeight(1)
}.width('100%')
.margin({ top: '12lpx' })
}
@Builder TabBuilder(index: number, item: string) {
Stack(){
Text(item)
.height('38lpx')
.fontSize('33lpx')
.fontWeight(this.currentIndex === index ? 600 : 400)
.fontColor(this.currentIndex === index ? this.selectedFontColor : this.fontColor)
.lineHeight('38lpx')
if(this.currentIndex === index){
Divider()
.width('31lpx')
.height('4lpx')
.color('#ED2800')
.strokeWidth('4lpx')
.margin({top:'50lpx'})
.id("divTag")
}
}.onClick(()=>{
this.currentIndex = index
this.controller.changeIndex(this.currentIndex)
})
.height('100%')
.margin({right:'9lpx'})
.padding({left:'31lpx',right:index === this.count.length-1?"31lpx":"0lpx"})
}
}
\ No newline at end of file
... ...
... ... @@ -4,6 +4,7 @@ import { HttpUrlUtils, ResponseDTO, WDHttp } from 'wdNetwork';
import HashMap from '@ohos.util.HashMap';
import { SearchHistoryItem } from '../viewmodel/SearchHistoryItem';
import { SearchHotContentItem } from '../viewmodel/SearchHotContentItem';
import { SearchResultCountItem } from '../viewmodel/SearchResultCountItem';
const TAG = "SearcherAboutDataModel"
... ... @@ -195,6 +196,43 @@ class SearcherAboutDataModel{
return compRes.data
}
/**
* 搜索结果 展示tab数量
*/
getSearchResultCountData(keyword:string,context: Context): Promise<SearchResultCountItem> {
return new Promise<SearchResultCountItem>((success, error) => {
Logger.info(TAG, `getSearchResultCountData start`);
this.fetchSearchResultCountData(keyword).then((navResDTO: ResponseDTO<SearchResultCountItem>) => {
if (!navResDTO || navResDTO.code != 0) {
success(this.getSearchResultCountDataLocal(context))
return
}
Logger.info(TAG, "getSearchResultCountData then,SearchHintDataResDTO.timeStamp:" + navResDTO.timestamp);
let navigationBean = navResDTO.data as SearchResultCountItem
success(navigationBean);
}).catch((err: Error) => {
Logger.error(TAG, `getSearchResultCountData catch, error.name : ${err.name}, error.message:${err.message}`);
success(this.getSearchResultCountDataLocal(context))
})
})
}
fetchSearchResultCountData(keyword:string) {
let url = HttpUrlUtils.getSearchResultCountDataUrl() + keyword
let headers: HashMap<string, string> = HttpUrlUtils.getCommonHeaders();
return WDHttp.get<ResponseDTO<SearchResultCountItem>>(url, headers)
};
async getSearchResultCountDataLocal(context: Context): Promise<SearchResultCountItem> {
Logger.info(TAG, `getSearchResultCountDataLocal start`);
let compRes: ResponseDTO<SearchResultCountItem> | null = await ResourcesUtils.getResourcesJson<ResponseDTO<SearchResultCountItem>>(context,'search_result_count_data.json' );
if (!compRes || !compRes.data) {
Logger.info(TAG, `getSearchResultCountDataLocal compRes is empty`);
return new SearchResultCountItem()
}
Logger.info(TAG, `getSearchResultCountDataLocal compRes : ${JSON.stringify(compRes)}`);
return compRes.data
}
}
... ...
/**
* 搜索结果 count 数量 ,某一个为0 就不展示对应 Tab
*/
export class SearchResultCountItem{
allTotal: number = 0 //所有tab总量
cmsTotal: number = 0 //精选总量
rmhTotal: number = 0 //人民号总量
videoTotal: number = 0 //视频总量
activityTotal: number = 0 //活动数据总量
}
\ No newline at end of file
... ...
{
"code": "0",
"data": {
"activityTotal": 0,
"allTotal": 2791778,
"cmsTotal": 240407,
"keyword": "大家",
"pageNum": 1,
"pageSize": 1,
"rmhTotal": 2551290,
"totalCount": 0,
"trueTotal": 0,
"videoTotal": 16775
},
"message": "Success",
"success": true,
"timestamp": 1712889165817
}
\ No newline at end of file
... ...