liyubing

fix:1)搜索 输入wuhuhuan,全部tab未显示,看图

... ... @@ -29,24 +29,22 @@ export struct SearchComponent {
@State searchHistoryData: SearchHistoryItem[] = []
@State relatedSearchContentsData: SearchRelatedItem[] = []
scroller: Scroller = new Scroller()
@State count:string[] = []
@State isGetRequest:boolean = false
@State count: string[] = []
@State isGetRequest: boolean = false
@Link fromTabName: string
@State sameSearch:number = 0 //再次搜索
@StorageProp('currentBreakpoint') @Watch("currentChanged")currentBreakpoint: string = 'sm';
@State sameSearch: number = 0 //再次搜索
@StorageProp('currentBreakpoint') @Watch("currentChanged") currentBreakpoint: string = 'sm';
private breakpointSystem = new BreakpointSystem();
@State percent:number = 1
@State percent: number = 1
currentChanged(){
if(this.currentBreakpoint == "md" || this.currentBreakpoint == "lg"){
currentChanged() {
if (this.currentBreakpoint == "md" || this.currentBreakpoint == "lg") {
this.percent = 0.7
}else {
} else {
this.percent = 1
}
}
aboutToAppear() {
this.breakpointSystem.register();
this.currentChanged()
... ... @@ -68,43 +66,42 @@ export struct SearchComponent {
this.breakpointSystem.unregister();
}
getRelatedSearchContent() {
if(StringUtils.isNotEmpty(this.searchText)){
SearcherAboutDataModel.getRelatedSearchContentData(encodeURI(this.searchText),getContext(this)).then((value) => {
if (StringUtils.isNotEmpty(this.searchText)) {
SearcherAboutDataModel.getRelatedSearchContentData(encodeURI(this.searchText), getContext(this)).then((value) => {
if (value != null && value.length > 0) {
this.relatedSearchContentsData = []
value.forEach(item=>{
let tempValue:string = item
value.forEach(item => {
let tempValue: string = item
let tempArr: string[] = []
if (tempValue.indexOf(this.searchText) === -1) {
tempArr.push(item)
this.relatedSearchContentsData.push(new SearchRelatedItem(item,tempArr))
}else {
while (tempValue.indexOf(this.searchText) != -1){
this.relatedSearchContentsData.push(new SearchRelatedItem(item, tempArr))
} else {
while (tempValue.indexOf(this.searchText) != -1) {
let index = tempValue.indexOf(this.searchText)
if(index === 0){
if (index === 0) {
try {
tempArr.push(this.searchText)
tempValue = tempValue.substring(this.searchText.length,tempValue.length)
tempValue = tempValue.substring(this.searchText.length, tempValue.length)
} catch (e) {
}
}else {
} else {
try {
tempArr.push(tempValue.substring(0,index))
tempArr.push(tempValue.substring(0, index))
tempArr.push(this.searchText)
tempValue = tempValue.substring(index+this.searchText.length,tempValue.length)
tempValue = tempValue.substring(index + this.searchText.length, tempValue.length)
} catch (e) {
}
}
}
if(StringUtils.isNotEmpty(tempValue)){
if (StringUtils.isNotEmpty(tempValue)) {
tempArr.push(tempValue)
}
this.relatedSearchContentsData.push(new SearchRelatedItem(item,tempArr))
this.relatedSearchContentsData.push(new SearchRelatedItem(item, tempArr))
}
})
}else{
} else {
this.hasInputContent = false
this.relatedSearchContentsData = []
}
... ... @@ -125,8 +122,9 @@ export struct SearchComponent {
this.setDefaultHitData()
})
}
setDefaultHitData(){
if(this.searchTextData.length === 0){
setDefaultHitData() {
if (this.searchTextData.length === 0) {
this.hasNoSearchTextData = true
this.searchTextData.push("搜索感兴趣的内容")
}
... ... @@ -136,7 +134,7 @@ export struct SearchComponent {
this.searchHistoryData = SearcherAboutDataModel.getSearchHistoryData()
}
stopInput(){
stopInput() {
this.controller.stopEditing()
}
... ... @@ -146,11 +144,17 @@ export struct SearchComponent {
if (!this.hasInputContent) {
Scroll(this.scroller) {
Column() {
if(this.searchHistoryData!=null && this.searchHistoryData.length>0){
SearchHistoryComponent({ searchHistoryData: $searchHistoryData, onDelHistory: (): void => this.getSearchHistoryData(),onGetSearchRes: (item,index): void => this.getSearchHistoryResData(item,index),onCloseInput : (): void => this.stopInput(),percent:this.percent })
if (this.searchHistoryData != null && this.searchHistoryData.length > 0) {
SearchHistoryComponent({
searchHistoryData: $searchHistoryData,
onDelHistory: (): void => this.getSearchHistoryData(),
onGetSearchRes: (item, index): void => this.getSearchHistoryResData(item, index),
onCloseInput: (): void => this.stopInput(),
percent: this.percent
})
}
if(this.searchHistoryData.length>0){
if (this.searchHistoryData.length > 0) {
//分隔符
Divider()
.width('100%')
... ... @@ -159,7 +163,10 @@ export struct SearchComponent {
.strokeWidth(`${this.calcHeight(1)}lpx`)
}
SearchHotsComponent({onGetSearchRes: (item): void => this.getSearchHotResData(item),percent:this.percent})
SearchHotsComponent({
onGetSearchRes: (item): void => this.getSearchHotResData(item),
percent: this.percent
})
}
}
.scrollable(ScrollDirection.Vertical)
... ... @@ -170,16 +177,28 @@ export struct SearchComponent {
} else {
if (this.hasChooseSearch) {
//搜索结果
SearchResultComponent({count:this.count,searchText:this.searchText,isGetRequest:this.isGetRequest,onClickTryAgain: (): void => {
if(StringUtils.isNotEmpty(this.searchText)){
SearchResultComponent({
count: this.count,
searchText: this.searchText,
isGetRequest: this.isGetRequest,
onClickTryAgain: (): void => {
if (StringUtils.isNotEmpty(this.searchText)) {
SearcherAboutDataModel.putSearchHistoryData(this.searchText)
this.getSearchHistoryData()
this.getSearchInputResData(this.searchText)
}
},percent:this.percent,sameSearch:this.sameSearch})
},
percent: this.percent,
sameSearch: this.sameSearch
})
} else {
//联想搜索
SearchRelatedComponent({relatedSearchContentData:$relatedSearchContentsData,onGetSearchRes: (item): void => this.getSearchRelatedResData(item),searchText:this.searchText,percent:this.percent})
SearchRelatedComponent({
relatedSearchContentData: $relatedSearchContentsData,
onGetSearchRes: (item): void => this.getSearchRelatedResData(item),
searchText: this.searchText,
percent: this.percent
})
}
}
}.height('100%')
... ... @@ -190,19 +209,19 @@ export struct SearchComponent {
* 点击搜索记录列表回调
* @param content
*/
getSearchHistoryResData(content:string,index:number){
getSearchHistoryResData(content: string, index: number) {
//删除单条记录
SearcherAboutDataModel.delSearchSingleHistoryData(index)
this.isClickedHistorySearch = true
this.searchResData(content)
}
searchResData(content:string){
trackSearchClick(this.fromTabName,content)
searchResData(content: string) {
trackSearchClick(this.fromTabName, content)
//赋值
this.searchText = content
if(StringUtils.isNotEmpty(this.searchText)){
if (StringUtils.isNotEmpty(this.searchText)) {
this.hasInputContent = true
}
... ... @@ -223,7 +242,7 @@ export struct SearchComponent {
* 点击hint搜索列表回调
* @param content
*/
getSearchHintResData(content:string){
getSearchHintResData(content: string) {
this.isClickedHintSearch = true
this.searchResData(content)
}
... ... @@ -232,7 +251,7 @@ export struct SearchComponent {
* 点击联想搜索列表回调
* @param content
*/
getSearchRelatedResData(content:string){
getSearchRelatedResData(content: string) {
this.isClickedRelatedSearch = true
this.searchResData(content)
}
... ... @@ -241,7 +260,7 @@ export struct SearchComponent {
* 点击热词搜索列表回调
* @param content
*/
getSearchHotResData(content:string){
getSearchHotResData(content: string) {
this.isClickedHotSearch = true
this.searchResData(content)
}
... ... @@ -250,17 +269,19 @@ export struct SearchComponent {
* 点击输入法搜索搜索列表回调
* @param content
*/
getSearchInputResData(content:string){
getSearchInputResData(content: string) {
this.isClickedInputSearch = true
this.searchResData(content)
}
//搜索框
@Builder searchInputComponent() {
@Builder
searchInputComponent() {
Row() {
//左
Stack({ alignContent: Alignment.Start }) {
if (this.searchTextData != null && this.searchTextData.length > 0 && !this.hasInputContent && StringUtils.isEmpty(this.searchText)) {
if (this.searchTextData != null && this.searchTextData.length > 0 && !this.hasInputContent &&
StringUtils.isEmpty(this.searchText)) {
Swiper(this.swiperController) {
ForEach(this.searchTextData, (item: string, index: number) => {
Text(item)
... ... @@ -285,42 +306,42 @@ export struct SearchComponent {
this.curHintSearchData = this.searchTextData[index]
})
}
Row(){
Search({ value: this.searchText, placeholder: '', controller: this.controller})
Row() {
Search({ value: this.searchText, placeholder: '', controller: this.controller })
.layoutWeight(1)
.height(`${this.calcHeight(69)}lpx`)
.backgroundColor($r('app.color.color_transparent'))
.textFont({ size: `${this.calcHeight(27)}lpx`, weight: 400 })
// .defaultFocus(true)
.textFont({ size: `${this.calcHeight(27)}lpx`, weight: 400 })// .defaultFocus(true)
.id("searchId")
.searchIcon({
size:0
size: 0
})
.cancelButton({
style:CancelButtonStyle.INVISIBLE
style: CancelButtonStyle.INVISIBLE
})
.caretStyle({color:Color.Pink})
.caretStyle({ color: Color.Pink })
.onSubmit((value: string) => {
if(StringUtils.isNotEmpty(this.searchText)){
if (StringUtils.isNotEmpty(this.searchText)) {
SearcherAboutDataModel.putSearchHistoryData(this.searchText)
this.getSearchHistoryData()
this.getSearchInputResData(this.searchText)
}else{
if(!this.hasNoSearchTextData){
if(StringUtils.isEmpty(this.curHintSearchData)){
} else {
if (!this.hasNoSearchTextData) {
if (StringUtils.isEmpty(this.curHintSearchData)) {
this.curHintSearchData = this.searchTextData[0]
}
this.getSearchHintResData(this.curHintSearchData)
}else{
} else {
ToastUtils.shortToast("请输入搜索关键词")
}
}
})
.onChange((value: string) => {
this.searchText = value
if(this.isClickedHistorySearch || this.isClickedHotSearch || this.isClickedRelatedSearch || this.isClickedInputSearch|| this.isClickedHintSearch){
if (this.isClickedHistorySearch || this.isClickedHotSearch || this.isClickedRelatedSearch ||
this.isClickedInputSearch || this.isClickedHintSearch) {
this.hasChooseSearch = true
}else{
} else {
this.hasChooseSearch = false
}
... ... @@ -330,10 +351,11 @@ export struct SearchComponent {
this.hasInputContent = false
}
if(this.isClickedHistorySearch || this.isClickedHotSearch || this.isClickedRelatedSearch || this.isClickedInputSearch|| this.isClickedHintSearch){
if (this.isClickedHistorySearch || this.isClickedHotSearch || this.isClickedRelatedSearch ||
this.isClickedInputSearch || this.isClickedHintSearch) {
this.resetSearch()
}else{
if(this.hasInputContent){
} else {
if (this.hasInputContent) {
this.getRelatedSearchContent()
}
}
... ... @@ -344,14 +366,14 @@ export struct SearchComponent {
.height(`${this.calcHeight(31)}lpx`)
.objectFit(ImageFit.Auto)
.interpolation(ImageInterpolation.Medium)
.onClick(()=>{
.onClick(() => {
this.searchText = ""
})
.offset({x:10})
.offset({ x: 10 })
.enabled(true)
.visibility(StringUtils.isEmpty(this.searchText) ? Visibility.Hidden : Visibility.Visible)
}.padding({right:`${this.calcHeight(70)}lpx`})
}.padding({ right: `${this.calcHeight(70)}lpx` })
.layoutWeight(1)
.justifyContent(FlexAlign.SpaceBetween)
}
... ... @@ -379,21 +401,29 @@ export struct SearchComponent {
.alignItems(VerticalAlign.Center)
}
getSearchResultCountData() {
SearcherAboutDataModel.getSearchResultCountData(encodeURI(this.searchText),getContext(this)).then((value) => {
SearcherAboutDataModel.getSearchResultCountData(encodeURI(this.searchText), getContext(this)).then((value) => {
if (value != null) {
this.count = []
if(value.allTotal!=0){
/*
全部 tab, allTotal> 0 或其它的tab有一个出现
*/
let haveAll = false
if (value.cmsTotal != 0 || value.rmhTotal != 0 || value.videoTotal != 0 || value.activityTotal != 0) {
haveAll = true
}
if (value.allTotal != 0 || haveAll) {
this.count.push("全部")
}
if(value.cmsTotal!=0){
if (value.cmsTotal != 0) {
this.count.push("精选")
}
if(value.rmhTotal!=0){
if (value.rmhTotal != 0) {
this.count.push("人民号")
}
if(value.videoTotal!=0){
if (value.videoTotal != 0) {
this.count.push("视频")
}
//屏蔽活动
... ... @@ -411,7 +441,7 @@ export struct SearchComponent {
})
}
resetSearch(){
resetSearch() {
this.isClickedHistorySearch = false
this.isClickedHotSearch = false
this.isClickedRelatedSearch = false
... ... @@ -419,12 +449,12 @@ export struct SearchComponent {
this.isClickedHintSearch = false
}
calcHeight(value:number): number{
calcHeight(value: number): number {
return value * this.percent
}
}
function trackSearchClick(upOneLevelPageName: string,keyword:string){
function trackSearchClick(upOneLevelPageName: string, keyword: string) {
let params: ParamType = {}
params["keyword"] = keyword
... ...