DeerSearch.ets 1.9 KB

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