Showing
2 changed files
with
75 additions
and
47 deletions
| 1 | import router from '@ohos.router' | 1 | import router from '@ohos.router' |
| 2 | -import { NetworkUtil, StringUtils, ToastUtils } from 'wdKit' | 2 | +import { BreakpointSystem, NetworkUtil, StringUtils, ToastUtils } from 'wdKit' |
| 3 | import { ParamType, TrackConstants, Tracking } from 'wdTracking/Index' | 3 | import { ParamType, TrackConstants, Tracking } from 'wdTracking/Index' |
| 4 | import SearcherAboutDataModel from '../../model/SearcherAboutDataModel' | 4 | import SearcherAboutDataModel from '../../model/SearcherAboutDataModel' |
| 5 | import { SearchHistoryItem } from '../../viewmodel/SearchHistoryItem' | 5 | import { SearchHistoryItem } from '../../viewmodel/SearchHistoryItem' |
| 6 | import { SearchRelatedItem } from '../../viewmodel/SearchRelatedItem' | 6 | import { SearchRelatedItem } from '../../viewmodel/SearchRelatedItem' |
| 7 | -import { EmptyComponent } from '../view/EmptyComponent' | ||
| 8 | import { SearchHistoryComponent } from './SearchHistoryComponent' | 7 | import { SearchHistoryComponent } from './SearchHistoryComponent' |
| 9 | import { SearchHotsComponent } from './SearchHotsComponent' | 8 | import { SearchHotsComponent } from './SearchHotsComponent' |
| 10 | import { SearchRelatedComponent } from './SearchRelatedComponent' | 9 | import { SearchRelatedComponent } from './SearchRelatedComponent' |
| @@ -34,7 +33,22 @@ export struct SearchComponent { | @@ -34,7 +33,22 @@ export struct SearchComponent { | ||
| 34 | @State isGetRequest:boolean = false | 33 | @State isGetRequest:boolean = false |
| 35 | @Link fromTabName: string | 34 | @Link fromTabName: string |
| 36 | 35 | ||
| 36 | + @StorageProp('currentBreakpoint') @Watch("currentChanged")currentBreakpoint: string = 'sm'; | ||
| 37 | + private breakpointSystem = new BreakpointSystem(); | ||
| 38 | + @State percent:number = 1 | ||
| 39 | + | ||
| 40 | + currentChanged(){ | ||
| 41 | + if(this.currentBreakpoint == "md" || this.currentBreakpoint == "lg"){ | ||
| 42 | + this.percent = 0.7 | ||
| 43 | + }else { | ||
| 44 | + this.percent = 1 | ||
| 45 | + } | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + | ||
| 37 | aboutToAppear() { | 49 | aboutToAppear() { |
| 50 | + this.breakpointSystem.register(); | ||
| 51 | + this.currentChanged() | ||
| 38 | //获取提示滚动 | 52 | //获取提示滚动 |
| 39 | this.getSearchHint() | 53 | this.getSearchHint() |
| 40 | //清除缓存 | 54 | //清除缓存 |
| @@ -49,6 +63,11 @@ export struct SearchComponent { | @@ -49,6 +63,11 @@ export struct SearchComponent { | ||
| 49 | }, 1000); | 63 | }, 1000); |
| 50 | } | 64 | } |
| 51 | 65 | ||
| 66 | + aboutToDisappear(): void { | ||
| 67 | + this.breakpointSystem.unregister(); | ||
| 68 | + } | ||
| 69 | + | ||
| 70 | + | ||
| 52 | getRelatedSearchContent() { | 71 | getRelatedSearchContent() { |
| 53 | if(StringUtils.isNotEmpty(this.searchText)){ | 72 | if(StringUtils.isNotEmpty(this.searchText)){ |
| 54 | SearcherAboutDataModel.getRelatedSearchContentData(encodeURI(this.searchText),getContext(this)).then((value) => { | 73 | SearcherAboutDataModel.getRelatedSearchContentData(encodeURI(this.searchText),getContext(this)).then((value) => { |
| @@ -134,19 +153,19 @@ export struct SearchComponent { | @@ -134,19 +153,19 @@ export struct SearchComponent { | ||
| 134 | //分隔符 | 153 | //分隔符 |
| 135 | Divider() | 154 | Divider() |
| 136 | .width('100%') | 155 | .width('100%') |
| 137 | - .height('1lpx') | 156 | + .height(`${this.calcHeight(1)}lpx`) |
| 138 | .color($r('app.color.color_EDEDED')) | 157 | .color($r('app.color.color_EDEDED')) |
| 139 | - .strokeWidth('1lpx') | 158 | + .strokeWidth(`${this.calcHeight(1)}lpx`) |
| 140 | } | 159 | } |
| 141 | 160 | ||
| 142 | - SearchHotsComponent({onGetSearchRes: (item): void => this.getSearchHotResData(item)}) | 161 | + SearchHotsComponent({onGetSearchRes: (item): void => this.getSearchHotResData(item),percent:this.percent}) |
| 143 | } | 162 | } |
| 144 | } | 163 | } |
| 145 | .scrollable(ScrollDirection.Vertical) | 164 | .scrollable(ScrollDirection.Vertical) |
| 146 | .scrollBar(BarState.Off) | 165 | .scrollBar(BarState.Off) |
| 147 | .width('100%') | 166 | .width('100%') |
| 148 | .height('100%') | 167 | .height('100%') |
| 149 | - .padding({ left: '31lpx', right: '31lpx' }) | 168 | + .padding({ left: `${this.calcHeight(31)}lpx`, right: `${this.calcHeight(31)}lpx` }) |
| 150 | } else { | 169 | } else { |
| 151 | if (this.hasChooseSearch) { | 170 | if (this.hasChooseSearch) { |
| 152 | //搜索结果 | 171 | //搜索结果 |
| @@ -244,14 +263,14 @@ export struct SearchComponent { | @@ -244,14 +263,14 @@ export struct SearchComponent { | ||
| 244 | Swiper(this.swiperController) { | 263 | Swiper(this.swiperController) { |
| 245 | ForEach(this.searchTextData, (item: string, index: number) => { | 264 | ForEach(this.searchTextData, (item: string, index: number) => { |
| 246 | Text(item) | 265 | Text(item) |
| 247 | - .fontWeight('400lpx') | ||
| 248 | - .fontSize('25lpx') | 266 | + .fontWeight(400) |
| 267 | + .fontSize(`${this.calcHeight(25)}lpx`) | ||
| 249 | .fontColor($r('app.color.color_666666')) | 268 | .fontColor($r('app.color.color_666666')) |
| 250 | - .lineHeight('35lpx') | 269 | + .lineHeight(`${this.calcHeight(35)}lpx`) |
| 251 | .textAlign(TextAlign.Start) | 270 | .textAlign(TextAlign.Start) |
| 252 | .maxLines(1) | 271 | .maxLines(1) |
| 253 | .textOverflow({ overflow: TextOverflow.Clip }) | 272 | .textOverflow({ overflow: TextOverflow.Clip }) |
| 254 | - .margin({ left: '40lpx' }) | 273 | + .margin({ left: `${this.calcHeight(40)}lpx` }) |
| 255 | }) | 274 | }) |
| 256 | } | 275 | } |
| 257 | .loop(true) | 276 | .loop(true) |
| @@ -268,9 +287,9 @@ export struct SearchComponent { | @@ -268,9 +287,9 @@ export struct SearchComponent { | ||
| 268 | Row(){ | 287 | Row(){ |
| 269 | Search({ value: this.searchText, placeholder: '', controller: this.controller}) | 288 | Search({ value: this.searchText, placeholder: '', controller: this.controller}) |
| 270 | .layoutWeight(1) | 289 | .layoutWeight(1) |
| 271 | - .height('69lpx') | 290 | + .height(`${this.calcHeight(69)}lpx`) |
| 272 | .backgroundColor($r('app.color.color_transparent')) | 291 | .backgroundColor($r('app.color.color_transparent')) |
| 273 | - .textFont({ size: "27lpx", weight: "400lpx" }) | 292 | + .textFont({ size: `${this.calcHeight(27)}lpx`, weight: 400 }) |
| 274 | // .defaultFocus(true) | 293 | // .defaultFocus(true) |
| 275 | .id("searchId") | 294 | .id("searchId") |
| 276 | .searchIcon({ | 295 | .searchIcon({ |
| @@ -318,15 +337,15 @@ export struct SearchComponent { | @@ -318,15 +337,15 @@ export struct SearchComponent { | ||
| 318 | } | 337 | } |
| 319 | } | 338 | } |
| 320 | }) | 339 | }) |
| 321 | - }.padding({right:'70lpx'}) | 340 | + }.padding({right:`${this.calcHeight(70)}lpx`}) |
| 322 | .layoutWeight(1) | 341 | .layoutWeight(1) |
| 323 | 342 | ||
| 324 | Image($r('app.media.search_input_del_icon')) | 343 | Image($r('app.media.search_input_del_icon')) |
| 325 | - .width("31lpx") | ||
| 326 | - .height("31lpx") | 344 | + .width(`${this.calcHeight(31)}lpx`) |
| 345 | + .height(`${this.calcHeight(31)}lpx`) | ||
| 327 | .objectFit(ImageFit.Auto) | 346 | .objectFit(ImageFit.Auto) |
| 328 | .interpolation(ImageInterpolation.Medium) | 347 | .interpolation(ImageInterpolation.Medium) |
| 329 | - .margin({left:"495lpx"}) | 348 | + .margin({left:`${this.calcHeight(495)}lpx`}) |
| 330 | .onClick(()=>{ | 349 | .onClick(()=>{ |
| 331 | this.searchText = "" | 350 | this.searchText = "" |
| 332 | }) | 351 | }) |
| @@ -336,24 +355,24 @@ export struct SearchComponent { | @@ -336,24 +355,24 @@ export struct SearchComponent { | ||
| 336 | .backgroundImage($r('app.media.search_page_input_bg')) | 355 | .backgroundImage($r('app.media.search_page_input_bg')) |
| 337 | .backgroundImageSize(ImageSize.Cover) | 356 | .backgroundImageSize(ImageSize.Cover) |
| 338 | .layoutWeight(1) | 357 | .layoutWeight(1) |
| 339 | - .height('69lpx') | 358 | + .height(`${this.calcHeight(69)}lpx`) |
| 340 | 359 | ||
| 341 | //TODO 需要修改输入法 换行 | 360 | //TODO 需要修改输入法 换行 |
| 342 | //右 | 361 | //右 |
| 343 | Text("取消") | 362 | Text("取消") |
| 344 | .textAlign(TextAlign.Center) | 363 | .textAlign(TextAlign.Center) |
| 345 | - .fontWeight('400lpx') | ||
| 346 | - .fontSize('31lpx') | ||
| 347 | - .lineHeight('58lpx') | 364 | + .fontWeight(400) |
| 365 | + .fontSize(`${this.calcHeight(31)}lpx`) | ||
| 366 | + .lineHeight(`${this.calcHeight(58)}lpx`) | ||
| 348 | .fontColor($r('app.color.color_222222')) | 367 | .fontColor($r('app.color.color_222222')) |
| 349 | - .width('125lpx') | ||
| 350 | - .height('58lpx') | 368 | + .width(`${this.calcHeight(125)}lpx`) |
| 369 | + .height(`${this.calcHeight(58)}lpx`) | ||
| 351 | .onClick(() => { | 370 | .onClick(() => { |
| 352 | router.back() | 371 | router.back() |
| 353 | }) | 372 | }) |
| 354 | } | 373 | } |
| 355 | - .height('85lpx') | ||
| 356 | - .padding({ left: '31lpx' }) | 374 | + .height(`${this.calcHeight(85)}lpx`) |
| 375 | + .padding({ left: `${this.calcHeight(31)}lpx` }) | ||
| 357 | .alignItems(VerticalAlign.Center) | 376 | .alignItems(VerticalAlign.Center) |
| 358 | } | 377 | } |
| 359 | 378 | ||
| @@ -395,6 +414,10 @@ export struct SearchComponent { | @@ -395,6 +414,10 @@ export struct SearchComponent { | ||
| 395 | this.isClickedInputSearch = false | 414 | this.isClickedInputSearch = false |
| 396 | this.isClickedHintSearch = false | 415 | this.isClickedHintSearch = false |
| 397 | } | 416 | } |
| 417 | + | ||
| 418 | + calcHeight(value:number): number{ | ||
| 419 | + return value * this.percent | ||
| 420 | + } | ||
| 398 | } | 421 | } |
| 399 | 422 | ||
| 400 | function trackSearchClick(upOneLevelPageName: string,keyword:string){ | 423 | function trackSearchClick(upOneLevelPageName: string,keyword:string){ |
| @@ -10,6 +10,7 @@ const TAG = "SearchHotsComponent" | @@ -10,6 +10,7 @@ const TAG = "SearchHotsComponent" | ||
| 10 | export struct SearchHotsComponent{ | 10 | export struct SearchHotsComponent{ |
| 11 | @State searchHotsData:SearchHotContentItem[] = [] | 11 | @State searchHotsData:SearchHotContentItem[] = [] |
| 12 | onGetSearchRes?: (item:string) => void; | 12 | onGetSearchRes?: (item:string) => void; |
| 13 | + @Prop percent:number = 1 | ||
| 13 | 14 | ||
| 14 | aboutToAppear(){ | 15 | aboutToAppear(){ |
| 15 | //获取搜索热词 | 16 | //获取搜索热词 |
| @@ -34,22 +35,22 @@ export struct SearchHotsComponent{ | @@ -34,22 +35,22 @@ export struct SearchHotsComponent{ | ||
| 34 | if(this.searchHotsData.length>0){ | 35 | if(this.searchHotsData.length>0){ |
| 35 | Row() { | 36 | Row() { |
| 36 | Image($r('app.media.search_hot_icon')) | 37 | Image($r('app.media.search_hot_icon')) |
| 37 | - .width('46lpx') | ||
| 38 | - .height('46lpx') | 38 | + .width(`${this.calcHeight(46)}lpx`) |
| 39 | + .height(`${this.calcHeight(46)}lpx`) | ||
| 39 | .objectFit(ImageFit.Auto) | 40 | .objectFit(ImageFit.Auto) |
| 40 | - .margin({right:'8lpx'}) | 41 | + .margin({right:`${this.calcHeight(8)}lpx`}) |
| 41 | .interpolation(ImageInterpolation.Medium) | 42 | .interpolation(ImageInterpolation.Medium) |
| 42 | 43 | ||
| 43 | Text("热门搜索") | 44 | Text("热门搜索") |
| 44 | .textAlign(TextAlign.Center) | 45 | .textAlign(TextAlign.Center) |
| 45 | .fontWeight(FontWeight.Bold) | 46 | .fontWeight(FontWeight.Bold) |
| 46 | - .fontSize('33lpx') | ||
| 47 | - .lineHeight('46lpx') | 47 | + .fontSize(`${this.calcHeight(33)}lpx`) |
| 48 | + .lineHeight(`${this.calcHeight(46)}lpx`) | ||
| 48 | .fontColor($r('app.color.color_222222')) | 49 | .fontColor($r('app.color.color_222222')) |
| 49 | - .height('46lpx') | 50 | + .height(`${this.calcHeight(46)}lpx`) |
| 50 | } | 51 | } |
| 51 | .width('100%') | 52 | .width('100%') |
| 52 | - .margin({bottom:"15lpx"}) | 53 | + .margin({bottom:`${this.calcHeight(15)}lpx`}) |
| 53 | } | 54 | } |
| 54 | 55 | ||
| 55 | List(){ | 56 | List(){ |
| @@ -60,49 +61,49 @@ export struct SearchHotsComponent{ | @@ -60,49 +61,49 @@ export struct SearchHotsComponent{ | ||
| 60 | Row(){ | 61 | Row(){ |
| 61 | if(item.sequence <=3){ | 62 | if(item.sequence <=3){ |
| 62 | 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')) | 63 | 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')) |
| 63 | - .width('27lpx') | ||
| 64 | - .height('35lpx') | 64 | + .width(`${this.calcHeight(27)}lpx`) |
| 65 | + .height(`${this.calcHeight(35)}lpx`) | ||
| 65 | .objectFit(ImageFit.Auto) | 66 | .objectFit(ImageFit.Auto) |
| 66 | - .margin({right:'12lpx'}) | 67 | + .margin({right:`${this.calcHeight(12)}lpx`}) |
| 67 | .interpolation(ImageInterpolation.High) | 68 | .interpolation(ImageInterpolation.High) |
| 68 | }else { | 69 | }else { |
| 69 | Text(`${item.sequence}`) | 70 | Text(`${item.sequence}`) |
| 70 | - .height('31lpx') | 71 | + .height(`${this.calcHeight(31)}lpx`) |
| 71 | .fontColor($r('app.color.color_666666')) | 72 | .fontColor($r('app.color.color_666666')) |
| 72 | - .fontSize('27lpx') | 73 | + .fontSize(`${this.calcHeight(27)}lpx`) |
| 73 | .fontWeight(FontWeight.Regular) | 74 | .fontWeight(FontWeight.Regular) |
| 74 | - .lineHeight('31lpx') | ||
| 75 | - .margin({right:'12lpx'}) | 75 | + .lineHeight(`${this.calcHeight(31)}lpx`) |
| 76 | + .margin({right:`${this.calcHeight(12)}lpx`}) | ||
| 76 | } | 77 | } |
| 77 | Text(`${item.hotEntry}`) | 78 | Text(`${item.hotEntry}`) |
| 78 | .textOverflow({ overflow: TextOverflow.Ellipsis }) | 79 | .textOverflow({ overflow: TextOverflow.Ellipsis }) |
| 79 | .fontColor($r('app.color.color_222222')) | 80 | .fontColor($r('app.color.color_222222')) |
| 80 | - .fontSize('31lpx') | 81 | + .fontSize(`${this.calcHeight(31)}lpx`) |
| 81 | .maxLines(1) | 82 | .maxLines(1) |
| 82 | .fontWeight(FontWeight.Regular) | 83 | .fontWeight(FontWeight.Regular) |
| 83 | - .lineHeight('42lpx') | 84 | + .lineHeight(`${this.calcHeight(42)}lpx`) |
| 84 | }.layoutWeight(1) | 85 | }.layoutWeight(1) |
| 85 | 86 | ||
| 86 | if(item.mark===1 || item.mark===2){ | 87 | if(item.mark===1 || item.mark===2){ |
| 87 | Image(item.mark===1?$r('app.media.search_hots_mark1'):$r('app.media.search_hots_mark2')) | 88 | Image(item.mark===1?$r('app.media.search_hots_mark1'):$r('app.media.search_hots_mark2')) |
| 88 | - .width('42lpx') | ||
| 89 | - .height('31lpx') | 89 | + .width(`${this.calcHeight(42)}lpx`) |
| 90 | + .height(`${this.calcHeight(31)}lpx`) | ||
| 90 | .objectFit(ImageFit.Auto) | 91 | .objectFit(ImageFit.Auto) |
| 91 | .interpolation(ImageInterpolation.High) | 92 | .interpolation(ImageInterpolation.High) |
| 92 | } | 93 | } |
| 93 | }.alignItems(VerticalAlign.Center) | 94 | }.alignItems(VerticalAlign.Center) |
| 94 | - .height('84lpx') | 95 | + .height(`${this.calcHeight(84)}lpx`) |
| 95 | .width('100%') | 96 | .width('100%') |
| 96 | .justifyContent(FlexAlign.SpaceBetween) | 97 | .justifyContent(FlexAlign.SpaceBetween) |
| 97 | 98 | ||
| 98 | if(index != this.searchHotsData.length-1 ){ | 99 | if(index != this.searchHotsData.length-1 ){ |
| 99 | Divider() | 100 | Divider() |
| 100 | .width('100%') | 101 | .width('100%') |
| 101 | - .height('1lpx') | 102 | + .height(`${this.calcHeight(1)}lpx`) |
| 102 | .color($r('app.color.color_F5F5F5')) | 103 | .color($r('app.color.color_F5F5F5')) |
| 103 | - .strokeWidth('1lpx') | 104 | + .strokeWidth(`${this.calcHeight(1)}lpx`) |
| 104 | } | 105 | } |
| 105 | - }.height('85lpx') | 106 | + }.height(`${this.calcHeight(85)}lpx`) |
| 106 | .width('100%') | 107 | .width('100%') |
| 107 | .alignItems(HorizontalAlign.Start) | 108 | .alignItems(HorizontalAlign.Start) |
| 108 | } | 109 | } |
| @@ -117,6 +118,10 @@ export struct SearchHotsComponent{ | @@ -117,6 +118,10 @@ export struct SearchHotsComponent{ | ||
| 117 | }).layoutWeight(1) | 118 | }).layoutWeight(1) |
| 118 | }.width('100%') | 119 | }.width('100%') |
| 119 | .height('100%') | 120 | .height('100%') |
| 120 | - .margin({top:'46lpx'}) | 121 | + .margin({top:`${this.calcHeight(46)}lpx`}) |
| 122 | + } | ||
| 123 | + | ||
| 124 | + calcHeight(value:number): number{ | ||
| 125 | + return value * this.percent | ||
| 121 | } | 126 | } |
| 122 | } | 127 | } |
-
Please register or login to post a comment