liyubing

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

@@ -29,24 +29,22 @@ export struct SearchComponent { @@ -29,24 +29,22 @@ export struct SearchComponent {
29 @State searchHistoryData: SearchHistoryItem[] = [] 29 @State searchHistoryData: SearchHistoryItem[] = []
30 @State relatedSearchContentsData: SearchRelatedItem[] = [] 30 @State relatedSearchContentsData: SearchRelatedItem[] = []
31 scroller: Scroller = new Scroller() 31 scroller: Scroller = new Scroller()
32 - @State count:string[] = []  
33 - @State isGetRequest:boolean = false 32 + @State count: string[] = []
  33 + @State isGetRequest: boolean = false
34 @Link fromTabName: string 34 @Link fromTabName: string
35 - @State sameSearch:number = 0 //再次搜索  
36 -  
37 - @StorageProp('currentBreakpoint') @Watch("currentChanged")currentBreakpoint: string = 'sm'; 35 + @State sameSearch: number = 0 //再次搜索
  36 + @StorageProp('currentBreakpoint') @Watch("currentChanged") currentBreakpoint: string = 'sm';
38 private breakpointSystem = new BreakpointSystem(); 37 private breakpointSystem = new BreakpointSystem();
39 - @State percent:number = 1 38 + @State percent: number = 1
40 39
41 - currentChanged(){  
42 - if(this.currentBreakpoint == "md" || this.currentBreakpoint == "lg"){ 40 + currentChanged() {
  41 + if (this.currentBreakpoint == "md" || this.currentBreakpoint == "lg") {
43 this.percent = 0.7 42 this.percent = 0.7
44 - }else { 43 + } else {
45 this.percent = 1 44 this.percent = 1
46 } 45 }
47 } 46 }
48 47
49 -  
50 aboutToAppear() { 48 aboutToAppear() {
51 this.breakpointSystem.register(); 49 this.breakpointSystem.register();
52 this.currentChanged() 50 this.currentChanged()
@@ -68,43 +66,42 @@ export struct SearchComponent { @@ -68,43 +66,42 @@ export struct SearchComponent {
68 this.breakpointSystem.unregister(); 66 this.breakpointSystem.unregister();
69 } 67 }
70 68
71 -  
72 getRelatedSearchContent() { 69 getRelatedSearchContent() {
73 - if(StringUtils.isNotEmpty(this.searchText)){  
74 - SearcherAboutDataModel.getRelatedSearchContentData(encodeURI(this.searchText),getContext(this)).then((value) => { 70 + if (StringUtils.isNotEmpty(this.searchText)) {
  71 + SearcherAboutDataModel.getRelatedSearchContentData(encodeURI(this.searchText), getContext(this)).then((value) => {
75 if (value != null && value.length > 0) { 72 if (value != null && value.length > 0) {
76 this.relatedSearchContentsData = [] 73 this.relatedSearchContentsData = []
77 - value.forEach(item=>{  
78 - let tempValue:string = item 74 + value.forEach(item => {
  75 + let tempValue: string = item
79 let tempArr: string[] = [] 76 let tempArr: string[] = []
80 if (tempValue.indexOf(this.searchText) === -1) { 77 if (tempValue.indexOf(this.searchText) === -1) {
81 tempArr.push(item) 78 tempArr.push(item)
82 - this.relatedSearchContentsData.push(new SearchRelatedItem(item,tempArr))  
83 - }else {  
84 - while (tempValue.indexOf(this.searchText) != -1){ 79 + this.relatedSearchContentsData.push(new SearchRelatedItem(item, tempArr))
  80 + } else {
  81 + while (tempValue.indexOf(this.searchText) != -1) {
85 let index = tempValue.indexOf(this.searchText) 82 let index = tempValue.indexOf(this.searchText)
86 - if(index === 0){ 83 + if (index === 0) {
87 try { 84 try {
88 tempArr.push(this.searchText) 85 tempArr.push(this.searchText)
89 - tempValue = tempValue.substring(this.searchText.length,tempValue.length) 86 + tempValue = tempValue.substring(this.searchText.length, tempValue.length)
90 } catch (e) { 87 } catch (e) {
91 } 88 }
92 - }else { 89 + } else {
93 try { 90 try {
94 - tempArr.push(tempValue.substring(0,index)) 91 + tempArr.push(tempValue.substring(0, index))
95 tempArr.push(this.searchText) 92 tempArr.push(this.searchText)
96 - tempValue = tempValue.substring(index+this.searchText.length,tempValue.length) 93 + tempValue = tempValue.substring(index + this.searchText.length, tempValue.length)
97 } catch (e) { 94 } catch (e) {
98 } 95 }
99 } 96 }
100 } 97 }
101 - if(StringUtils.isNotEmpty(tempValue)){ 98 + if (StringUtils.isNotEmpty(tempValue)) {
102 tempArr.push(tempValue) 99 tempArr.push(tempValue)
103 } 100 }
104 - this.relatedSearchContentsData.push(new SearchRelatedItem(item,tempArr)) 101 + this.relatedSearchContentsData.push(new SearchRelatedItem(item, tempArr))
105 } 102 }
106 }) 103 })
107 - }else{ 104 + } else {
108 this.hasInputContent = false 105 this.hasInputContent = false
109 this.relatedSearchContentsData = [] 106 this.relatedSearchContentsData = []
110 } 107 }
@@ -125,8 +122,9 @@ export struct SearchComponent { @@ -125,8 +122,9 @@ export struct SearchComponent {
125 this.setDefaultHitData() 122 this.setDefaultHitData()
126 }) 123 })
127 } 124 }
128 - setDefaultHitData(){  
129 - if(this.searchTextData.length === 0){ 125 +
  126 + setDefaultHitData() {
  127 + if (this.searchTextData.length === 0) {
130 this.hasNoSearchTextData = true 128 this.hasNoSearchTextData = true
131 this.searchTextData.push("搜索感兴趣的内容") 129 this.searchTextData.push("搜索感兴趣的内容")
132 } 130 }
@@ -136,7 +134,7 @@ export struct SearchComponent { @@ -136,7 +134,7 @@ export struct SearchComponent {
136 this.searchHistoryData = SearcherAboutDataModel.getSearchHistoryData() 134 this.searchHistoryData = SearcherAboutDataModel.getSearchHistoryData()
137 } 135 }
138 136
139 - stopInput(){ 137 + stopInput() {
140 this.controller.stopEditing() 138 this.controller.stopEditing()
141 } 139 }
142 140
@@ -146,11 +144,17 @@ export struct SearchComponent { @@ -146,11 +144,17 @@ export struct SearchComponent {
146 if (!this.hasInputContent) { 144 if (!this.hasInputContent) {
147 Scroll(this.scroller) { 145 Scroll(this.scroller) {
148 Column() { 146 Column() {
149 - if(this.searchHistoryData!=null && this.searchHistoryData.length>0){  
150 - SearchHistoryComponent({ searchHistoryData: $searchHistoryData, onDelHistory: (): void => this.getSearchHistoryData(),onGetSearchRes: (item,index): void => this.getSearchHistoryResData(item,index),onCloseInput : (): void => this.stopInput(),percent:this.percent }) 147 + if (this.searchHistoryData != null && this.searchHistoryData.length > 0) {
  148 + SearchHistoryComponent({
  149 + searchHistoryData: $searchHistoryData,
  150 + onDelHistory: (): void => this.getSearchHistoryData(),
  151 + onGetSearchRes: (item, index): void => this.getSearchHistoryResData(item, index),
  152 + onCloseInput: (): void => this.stopInput(),
  153 + percent: this.percent
  154 + })
151 } 155 }
152 156
153 - if(this.searchHistoryData.length>0){ 157 + if (this.searchHistoryData.length > 0) {
154 //分隔符 158 //分隔符
155 Divider() 159 Divider()
156 .width('100%') 160 .width('100%')
@@ -159,7 +163,10 @@ export struct SearchComponent { @@ -159,7 +163,10 @@ export struct SearchComponent {
159 .strokeWidth(`${this.calcHeight(1)}lpx`) 163 .strokeWidth(`${this.calcHeight(1)}lpx`)
160 } 164 }
161 165
162 - SearchHotsComponent({onGetSearchRes: (item): void => this.getSearchHotResData(item),percent:this.percent}) 166 + SearchHotsComponent({
  167 + onGetSearchRes: (item): void => this.getSearchHotResData(item),
  168 + percent: this.percent
  169 + })
163 } 170 }
164 } 171 }
165 .scrollable(ScrollDirection.Vertical) 172 .scrollable(ScrollDirection.Vertical)
@@ -170,16 +177,28 @@ export struct SearchComponent { @@ -170,16 +177,28 @@ export struct SearchComponent {
170 } else { 177 } else {
171 if (this.hasChooseSearch) { 178 if (this.hasChooseSearch) {
172 //搜索结果 179 //搜索结果
173 - SearchResultComponent({count:this.count,searchText:this.searchText,isGetRequest:this.isGetRequest,onClickTryAgain: (): void => {  
174 - if(StringUtils.isNotEmpty(this.searchText)){  
175 - SearcherAboutDataModel.putSearchHistoryData(this.searchText)  
176 - this.getSearchHistoryData()  
177 - this.getSearchInputResData(this.searchText)  
178 - }  
179 - },percent:this.percent,sameSearch:this.sameSearch}) 180 + SearchResultComponent({
  181 + count: this.count,
  182 + searchText: this.searchText,
  183 + isGetRequest: this.isGetRequest,
  184 + onClickTryAgain: (): void => {
  185 + if (StringUtils.isNotEmpty(this.searchText)) {
  186 + SearcherAboutDataModel.putSearchHistoryData(this.searchText)
  187 + this.getSearchHistoryData()
  188 + this.getSearchInputResData(this.searchText)
  189 + }
  190 + },
  191 + percent: this.percent,
  192 + sameSearch: this.sameSearch
  193 + })
180 } else { 194 } else {
181 //联想搜索 195 //联想搜索
182 - SearchRelatedComponent({relatedSearchContentData:$relatedSearchContentsData,onGetSearchRes: (item): void => this.getSearchRelatedResData(item),searchText:this.searchText,percent:this.percent}) 196 + SearchRelatedComponent({
  197 + relatedSearchContentData: $relatedSearchContentsData,
  198 + onGetSearchRes: (item): void => this.getSearchRelatedResData(item),
  199 + searchText: this.searchText,
  200 + percent: this.percent
  201 + })
183 } 202 }
184 } 203 }
185 }.height('100%') 204 }.height('100%')
@@ -190,19 +209,19 @@ export struct SearchComponent { @@ -190,19 +209,19 @@ export struct SearchComponent {
190 * 点击搜索记录列表回调 209 * 点击搜索记录列表回调
191 * @param content 210 * @param content
192 */ 211 */
193 - getSearchHistoryResData(content:string,index:number){ 212 + getSearchHistoryResData(content: string, index: number) {
194 //删除单条记录 213 //删除单条记录
195 SearcherAboutDataModel.delSearchSingleHistoryData(index) 214 SearcherAboutDataModel.delSearchSingleHistoryData(index)
196 this.isClickedHistorySearch = true 215 this.isClickedHistorySearch = true
197 this.searchResData(content) 216 this.searchResData(content)
198 } 217 }
199 218
200 - searchResData(content:string){  
201 - trackSearchClick(this.fromTabName,content) 219 + searchResData(content: string) {
  220 + trackSearchClick(this.fromTabName, content)
202 //赋值 221 //赋值
203 this.searchText = content 222 this.searchText = content
204 223
205 - if(StringUtils.isNotEmpty(this.searchText)){ 224 + if (StringUtils.isNotEmpty(this.searchText)) {
206 this.hasInputContent = true 225 this.hasInputContent = true
207 } 226 }
208 227
@@ -223,7 +242,7 @@ export struct SearchComponent { @@ -223,7 +242,7 @@ export struct SearchComponent {
223 * 点击hint搜索列表回调 242 * 点击hint搜索列表回调
224 * @param content 243 * @param content
225 */ 244 */
226 - getSearchHintResData(content:string){ 245 + getSearchHintResData(content: string) {
227 this.isClickedHintSearch = true 246 this.isClickedHintSearch = true
228 this.searchResData(content) 247 this.searchResData(content)
229 } 248 }
@@ -232,7 +251,7 @@ export struct SearchComponent { @@ -232,7 +251,7 @@ export struct SearchComponent {
232 * 点击联想搜索列表回调 251 * 点击联想搜索列表回调
233 * @param content 252 * @param content
234 */ 253 */
235 - getSearchRelatedResData(content:string){ 254 + getSearchRelatedResData(content: string) {
236 this.isClickedRelatedSearch = true 255 this.isClickedRelatedSearch = true
237 this.searchResData(content) 256 this.searchResData(content)
238 } 257 }
@@ -241,7 +260,7 @@ export struct SearchComponent { @@ -241,7 +260,7 @@ export struct SearchComponent {
241 * 点击热词搜索列表回调 260 * 点击热词搜索列表回调
242 * @param content 261 * @param content
243 */ 262 */
244 - getSearchHotResData(content:string){ 263 + getSearchHotResData(content: string) {
245 this.isClickedHotSearch = true 264 this.isClickedHotSearch = true
246 this.searchResData(content) 265 this.searchResData(content)
247 } 266 }
@@ -250,17 +269,19 @@ export struct SearchComponent { @@ -250,17 +269,19 @@ export struct SearchComponent {
250 * 点击输入法搜索搜索列表回调 269 * 点击输入法搜索搜索列表回调
251 * @param content 270 * @param content
252 */ 271 */
253 - getSearchInputResData(content:string){ 272 + getSearchInputResData(content: string) {
254 this.isClickedInputSearch = true 273 this.isClickedInputSearch = true
255 this.searchResData(content) 274 this.searchResData(content)
256 } 275 }
257 276
258 //搜索框 277 //搜索框
259 - @Builder searchInputComponent() { 278 + @Builder
  279 + searchInputComponent() {
260 Row() { 280 Row() {
261 //左 281 //左
262 Stack({ alignContent: Alignment.Start }) { 282 Stack({ alignContent: Alignment.Start }) {
263 - if (this.searchTextData != null && this.searchTextData.length > 0 && !this.hasInputContent && StringUtils.isEmpty(this.searchText)) { 283 + if (this.searchTextData != null && this.searchTextData.length > 0 && !this.hasInputContent &&
  284 + StringUtils.isEmpty(this.searchText)) {
264 Swiper(this.swiperController) { 285 Swiper(this.swiperController) {
265 ForEach(this.searchTextData, (item: string, index: number) => { 286 ForEach(this.searchTextData, (item: string, index: number) => {
266 Text(item) 287 Text(item)
@@ -285,42 +306,42 @@ export struct SearchComponent { @@ -285,42 +306,42 @@ export struct SearchComponent {
285 this.curHintSearchData = this.searchTextData[index] 306 this.curHintSearchData = this.searchTextData[index]
286 }) 307 })
287 } 308 }
288 - Row(){  
289 - Search({ value: this.searchText, placeholder: '', controller: this.controller}) 309 + Row() {
  310 + Search({ value: this.searchText, placeholder: '', controller: this.controller })
290 .layoutWeight(1) 311 .layoutWeight(1)
291 .height(`${this.calcHeight(69)}lpx`) 312 .height(`${this.calcHeight(69)}lpx`)
292 .backgroundColor($r('app.color.color_transparent')) 313 .backgroundColor($r('app.color.color_transparent'))
293 - .textFont({ size: `${this.calcHeight(27)}lpx`, weight: 400 })  
294 - // .defaultFocus(true) 314 + .textFont({ size: `${this.calcHeight(27)}lpx`, weight: 400 })// .defaultFocus(true)
295 .id("searchId") 315 .id("searchId")
296 .searchIcon({ 316 .searchIcon({
297 - size:0 317 + size: 0
298 }) 318 })
299 .cancelButton({ 319 .cancelButton({
300 - style:CancelButtonStyle.INVISIBLE 320 + style: CancelButtonStyle.INVISIBLE
301 }) 321 })
302 - .caretStyle({color:Color.Pink}) 322 + .caretStyle({ color: Color.Pink })
303 .onSubmit((value: string) => { 323 .onSubmit((value: string) => {
304 - if(StringUtils.isNotEmpty(this.searchText)){ 324 + if (StringUtils.isNotEmpty(this.searchText)) {
305 SearcherAboutDataModel.putSearchHistoryData(this.searchText) 325 SearcherAboutDataModel.putSearchHistoryData(this.searchText)
306 this.getSearchHistoryData() 326 this.getSearchHistoryData()
307 this.getSearchInputResData(this.searchText) 327 this.getSearchInputResData(this.searchText)
308 - }else{  
309 - if(!this.hasNoSearchTextData){  
310 - if(StringUtils.isEmpty(this.curHintSearchData)){  
311 - this.curHintSearchData = this.searchTextData[0] 328 + } else {
  329 + if (!this.hasNoSearchTextData) {
  330 + if (StringUtils.isEmpty(this.curHintSearchData)) {
  331 + this.curHintSearchData = this.searchTextData[0]
312 } 332 }
313 this.getSearchHintResData(this.curHintSearchData) 333 this.getSearchHintResData(this.curHintSearchData)
314 - }else{ 334 + } else {
315 ToastUtils.shortToast("请输入搜索关键词") 335 ToastUtils.shortToast("请输入搜索关键词")
316 } 336 }
317 } 337 }
318 }) 338 })
319 .onChange((value: string) => { 339 .onChange((value: string) => {
320 this.searchText = value 340 this.searchText = value
321 - if(this.isClickedHistorySearch || this.isClickedHotSearch || this.isClickedRelatedSearch || this.isClickedInputSearch|| this.isClickedHintSearch){ 341 + if (this.isClickedHistorySearch || this.isClickedHotSearch || this.isClickedRelatedSearch ||
  342 + this.isClickedInputSearch || this.isClickedHintSearch) {
322 this.hasChooseSearch = true 343 this.hasChooseSearch = true
323 - }else{ 344 + } else {
324 this.hasChooseSearch = false 345 this.hasChooseSearch = false
325 } 346 }
326 347
@@ -330,10 +351,11 @@ export struct SearchComponent { @@ -330,10 +351,11 @@ export struct SearchComponent {
330 this.hasInputContent = false 351 this.hasInputContent = false
331 } 352 }
332 353
333 - if(this.isClickedHistorySearch || this.isClickedHotSearch || this.isClickedRelatedSearch || this.isClickedInputSearch|| this.isClickedHintSearch){ 354 + if (this.isClickedHistorySearch || this.isClickedHotSearch || this.isClickedRelatedSearch ||
  355 + this.isClickedInputSearch || this.isClickedHintSearch) {
334 this.resetSearch() 356 this.resetSearch()
335 - }else{  
336 - if(this.hasInputContent){ 357 + } else {
  358 + if (this.hasInputContent) {
337 this.getRelatedSearchContent() 359 this.getRelatedSearchContent()
338 } 360 }
339 } 361 }
@@ -344,14 +366,14 @@ export struct SearchComponent { @@ -344,14 +366,14 @@ export struct SearchComponent {
344 .height(`${this.calcHeight(31)}lpx`) 366 .height(`${this.calcHeight(31)}lpx`)
345 .objectFit(ImageFit.Auto) 367 .objectFit(ImageFit.Auto)
346 .interpolation(ImageInterpolation.Medium) 368 .interpolation(ImageInterpolation.Medium)
347 - .onClick(()=>{ 369 + .onClick(() => {
348 this.searchText = "" 370 this.searchText = ""
349 }) 371 })
350 - .offset({x:10}) 372 + .offset({ x: 10 })
351 .enabled(true) 373 .enabled(true)
352 .visibility(StringUtils.isEmpty(this.searchText) ? Visibility.Hidden : Visibility.Visible) 374 .visibility(StringUtils.isEmpty(this.searchText) ? Visibility.Hidden : Visibility.Visible)
353 375
354 - }.padding({right:`${this.calcHeight(70)}lpx`}) 376 + }.padding({ right: `${this.calcHeight(70)}lpx` })
355 .layoutWeight(1) 377 .layoutWeight(1)
356 .justifyContent(FlexAlign.SpaceBetween) 378 .justifyContent(FlexAlign.SpaceBetween)
357 } 379 }
@@ -379,21 +401,29 @@ export struct SearchComponent { @@ -379,21 +401,29 @@ export struct SearchComponent {
379 .alignItems(VerticalAlign.Center) 401 .alignItems(VerticalAlign.Center)
380 } 402 }
381 403
382 -  
383 getSearchResultCountData() { 404 getSearchResultCountData() {
384 - SearcherAboutDataModel.getSearchResultCountData(encodeURI(this.searchText),getContext(this)).then((value) => { 405 + SearcherAboutDataModel.getSearchResultCountData(encodeURI(this.searchText), getContext(this)).then((value) => {
385 if (value != null) { 406 if (value != null) {
386 this.count = [] 407 this.count = []
387 - if(value.allTotal!=0){ 408 +
  409 + /*
  410 + 全部 tab, allTotal> 0 或其它的tab有一个出现
  411 + */
  412 + let haveAll = false
  413 + if (value.cmsTotal != 0 || value.rmhTotal != 0 || value.videoTotal != 0 || value.activityTotal != 0) {
  414 + haveAll = true
  415 + }
  416 +
  417 + if (value.allTotal != 0 || haveAll) {
388 this.count.push("全部") 418 this.count.push("全部")
389 } 419 }
390 - if(value.cmsTotal!=0){ 420 + if (value.cmsTotal != 0) {
391 this.count.push("精选") 421 this.count.push("精选")
392 } 422 }
393 - if(value.rmhTotal!=0){ 423 + if (value.rmhTotal != 0) {
394 this.count.push("人民号") 424 this.count.push("人民号")
395 } 425 }
396 - if(value.videoTotal!=0){ 426 + if (value.videoTotal != 0) {
397 this.count.push("视频") 427 this.count.push("视频")
398 } 428 }
399 //屏蔽活动 429 //屏蔽活动
@@ -411,7 +441,7 @@ export struct SearchComponent { @@ -411,7 +441,7 @@ export struct SearchComponent {
411 }) 441 })
412 } 442 }
413 443
414 - resetSearch(){ 444 + resetSearch() {
415 this.isClickedHistorySearch = false 445 this.isClickedHistorySearch = false
416 this.isClickedHotSearch = false 446 this.isClickedHotSearch = false
417 this.isClickedRelatedSearch = false 447 this.isClickedRelatedSearch = false
@@ -419,12 +449,12 @@ export struct SearchComponent { @@ -419,12 +449,12 @@ export struct SearchComponent {
419 this.isClickedHintSearch = false 449 this.isClickedHintSearch = false
420 } 450 }
421 451
422 - calcHeight(value:number): number{ 452 + calcHeight(value: number): number {
423 return value * this.percent 453 return value * this.percent
424 } 454 }
425 } 455 }
426 456
427 -function trackSearchClick(upOneLevelPageName: string,keyword:string){ 457 +function trackSearchClick(upOneLevelPageName: string, keyword: string) {
428 let params: ParamType = {} 458 let params: ParamType = {}
429 459
430 params["keyword"] = keyword 460 params["keyword"] = keyword