YTSearch.ets 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. @Component
  2. export struct YTSearch {
  3. //----搜索栏属性
  4. @State searchValue:string = ''
  5. //是否可以输入内容
  6. isEnable:boolean = true
  7. searchHeight:number = 36
  8. searchPadding:Padding|Length = {left:14,right:14}
  9. placeHolder:string = '请输入搜索内容'
  10. placeholderColor:ResourceColor = '#CC333333'
  11. placeholderFont:Font = {size:12}
  12. needLeftBuilder:boolean = true
  13. //----默认搜索图片属性 在传入leftBuilder或needLeftBuilder=false后无效
  14. src:ResourceStr = $r('app.media.search')
  15. imgWidth:Length = 24
  16. //----提交函数,回调以回传输入内容
  17. submit=(_:string)=>{
  18. }
  19. //----整体点击的处理函数
  20. click=()=>{
  21. }
  22. @BuilderParam leftBuilder:()=>void = this.defaultLeftBuilder
  23. @BuilderParam rightBuilder?:()=>void
  24. build() {
  25. Row(){
  26. if (this.needLeftBuilder){
  27. this.leftBuilder()
  28. }
  29. TextInput({text:$$this.searchValue,placeholder:this.placeHolder})
  30. .backgroundColor(Color.Transparent)
  31. .height('100%')
  32. .layoutWeight(1)
  33. .fontSize(12)
  34. .borderRadius(0)
  35. .placeholderFont(this.placeholderFont)
  36. .placeholderColor(this.placeholderColor)
  37. .padding(0)
  38. .caretColor('app.color.main_ac_color_dark')
  39. .enabled(this.isEnable)
  40. .onSubmit(()=>{
  41. this.submit(this.searchValue)
  42. })
  43. if (this.rightBuilder){
  44. this.rightBuilder()
  45. }
  46. }
  47. .padding(this.searchPadding)
  48. .borderRadius(this.searchHeight/2)
  49. .height(this.searchHeight)
  50. .width('100%')
  51. .border({width:1,color:$r('app.color.main_ac_color_dark')})
  52. .onClick(this.click)
  53. }
  54. @Builder
  55. defaultLeftBuilder(){
  56. Image(this.src)
  57. .width(this.imgWidth)
  58. .aspectRatio(1)
  59. .margin({right:4})
  60. }
  61. }