DeerSearch.ets 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import { YTButton, yTRouter } from "basic"
  2. import testsuite from "../../../ohosTest/ets/test/List.test"
  3. import { CustomTextStyle } from "../style/CustomTextStyle"
  4. @ComponentV2
  5. export struct DeerSearch {
  6. @Param enable: boolean = true
  7. @Event onSearch: (text: string) => void
  8. @Event onChange: (text: string) => void
  9. @Local searchKey: string = ''
  10. Touch(){
  11. yTRouter.router2BookSearchPage()
  12. }
  13. onSubmit(){
  14. this.onSearch(this.searchKey)
  15. this.searchKey = ''
  16. }
  17. build() {
  18. Row({space: 7}) {
  19. Row({space: 12.5}){
  20. Image($r('[basic].media.icon_Search'))
  21. .width(16)
  22. .aspectRatio(1)
  23. .fillColor('#FECF2F')
  24. TextInput({text: $$this.searchKey, placeholder: '搜索图书/书单'})
  25. .padding(0)
  26. .fontSize(12)
  27. // .maxLength(20)
  28. .fontWeight(400)
  29. .layoutWeight(1)
  30. .borderRadius(0)
  31. .border({ width: 0 })
  32. .enabled(this.enable)
  33. .onSubmit(this.onSubmit)
  34. .backgroundColor(Color.Transparent)
  35. .placeholderFont({size: 12, weight: 400})
  36. .placeholderColor(this.enable ? '#B5B8BC' : Color.Black)
  37. }
  38. .borderRadius(31)
  39. .layoutWeight(1)
  40. .backgroundColor(Color.White)
  41. .border({width: 2, color: '#000000'})
  42. .padding({left: 13, right: 13, top: 3, bottom: 3})
  43. Text('搜索')
  44. .borderRadius(31)
  45. .backgroundColor('#FECF2F')
  46. .border({ width: 2, color: '#000000' })
  47. .padding({left: 18, right: 18, top: 9, bottom: 9})
  48. .attributeModifier(new CustomTextStyle({size: 12, weight: 600}))
  49. .onClick(() => {
  50. if(this.enable) this.onSubmit()
  51. else this.Touch()
  52. })
  53. }
  54. .width("100%")
  55. .onClick(() => {
  56. if(!this.enable) this.Touch()
  57. })
  58. }
  59. }