yuyinzhushou.ets 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. @Component
  2. export struct VoiceAssistant {
  3. @State isShowAssistant: boolean = true
  4. @State voiceText: string = ""
  5. @State isListening: boolean = true
  6. // 添加缩放动画状态
  7. @State scaleValue: number = 1.0
  8. @State isScalingUp: boolean = true
  9. aboutToAppear() {
  10. this.startBreathingAnimation()
  11. }
  12. startBreathingAnimation() {
  13. // 使用setInterval实现呼吸动画
  14. setInterval(() => {
  15. if (this.isScalingUp) {
  16. this.scaleValue = 1.2
  17. } else {
  18. this.scaleValue = 1.0
  19. }
  20. // this.isScalingUp = !this.isScalingUp
  21. }, 1000) // 每1秒切换一次
  22. }
  23. build() {
  24. Stack() {
  25. // 只在显示时才渲染
  26. if (this.isShowAssistant) {
  27. Column() {
  28. Column(){
  29. }
  30. .width('100%')
  31. .height('70%')
  32. .backgroundColor(Color.Transparent)
  33. .onClick(() => {
  34. this.isShowAssistant = false
  35. })
  36. Row() {
  37. Image($r('app.media.state_microphone'))
  38. .fillColor($r('app.color.FFFFFF'))
  39. .width(50)
  40. .height(50)
  41. .scale({ x: this.scaleValue, y: this.scaleValue })
  42. .animation({ // 添加动画修饰器
  43. duration: 1000,
  44. curve: Curve.EaseInOut,
  45. iterations: -1,
  46. playMode: PlayMode.Alternate
  47. })
  48. Text('')
  49. // TextInput({ placeholder: '' })
  50. // .type(InputType.Normal)
  51. // .placeholderFont({ size: $r('app.float.fontSize_16') })
  52. // .placeholderColor($r('app.color.30FFFFFF'))
  53. // .fontSize($r('app.float.fontSize_16'))
  54. // .fontColor($r('app.color.FFFFFF'))
  55. // //.enableKeyboardOnFocus(false)
  56. // .layoutWeight(1) // 占据剩余空间
  57. // .onClick((event: ClickEvent) => {
  58. // event.; // 关键!阻止事件冒泡到透明背景层
  59. // })
  60. }
  61. .width('90%')
  62. .padding(10)
  63. .backgroundColor($r('app.color.000000')) // 半透明背景
  64. .borderRadius(20)
  65. }
  66. .width('100%')
  67. .height('100%')
  68. .justifyContent(FlexAlign.End) // 内容底部对齐
  69. .padding(20)
  70. }
  71. }
  72. }
  73. }