#DAYU200体验官#ArkUI eTS实践开发一个管家服务系统(一) 原创 精华

Buty9147
发布于 2022-4-29 21:53
浏览
5收藏

上一期把DAYU200的开发板系统升级成了OpenHarmony3.1 Release 版,
这一期和大家分享,基于eTS 开发一个管家服务系统,其实设想是用DAYU200上实现全屋智能中控系统,也设想了一些功能,东西有点多,

全屋智能中控系统
#DAYU200体验官#ArkUI eTS实践开发一个管家服务系统(一)-鸿蒙开发者社区 #DAYU200体验官#ArkUI eTS实践开发一个管家服务系统(一)-鸿蒙开发者社区

先实现管家服务系统的两个UI效果:语音助手、提醒服务。
这一期实践了以下内容:
swiper组件、//切换多组页面的组件
Panel组件、//可以从底部弹出/收回/滑动的面板组件
@Builder、 //生成布局,可以方便的传递参数
import router from ‘@system.router’; //导入router用于跳转页面的系统组件
import { voiceAssistant } from ‘./voice_assistant’//导入自定义组件
export //作为组件库库导出

------------开发环境-------------------
DevEco Studio 3.0 Beta3
Build Version: 3.0.0.900, built on March 30, 2022
SDK:API Version 8

1.效果

#DAYU200体验官#ArkUI eTS实践开发一个管家服务系统(一)-鸿蒙开发者社区

#DAYU200体验官#ArkUI eTS实践开发一个管家服务系统(一)-鸿蒙开发者社区

#DAYU200体验官#ArkUI eTS实践开发一个管家服务系统(一)-鸿蒙开发者社区

2.界面代码

2.1 首页

import router from '@system.router';
import { HomeData, initHomeData } from '../pages/model/HomeDataModel'

@Entry
@Component
struct Index {
  @State data: HomeData = initHomeData()
  @State panelShow: boolean= false
  private swiperController: SwiperController = new SwiperController()

  build() {
    Stack({ alignContent: Alignment.Bottom }) {

      this.buildTopBar()
      this.buildSwiper()
      this.buildPanel()

    }
    .height('100%')
    .backgroundColor(Color.Black)

  }

  @Builder buildTopBar() {
    //panel bar
    Column() {
      Column() {
        Image($r('app.media.slide'))
          .objectFit(ImageFit.Contain)
          .height(50)
      }
      .height(50)
      .opacity(0.9)
      .backgroundColor('#1F71FF')
      .onClick(() => {
        this.panelShow = !this.panelShow
      })

    }.height('100%')
  }

  @Builder buildSwiper() {
    //swiper
    Column({ space: 5 }) {
      Swiper(this.swiperController) {
        //首页
        this.builderPageHome()
        //其它
        this.builderPageOther()

      }
      .index(0)
      .autoPlay(false)
      .interval(4000)
      .indicator(true) // 默认开启指示点
      .loop(false) // 默认开启循环播放
      .duration(1000)
      .vertical(false) // 默认横向切换
      .itemSpace(0)
      .onChange((index: number) => {
        console.info(index.toString())
      })
    }
    //.backgroundColor(Color.Blue)
  }

  @Builder builderPageHome() {
    //middle range
    Column() {
      //date  time
      Row() {
        Column() {
          //time/date
          Text(this.data.time)
            .fontSize(80)
            .fontWeight(FontWeight.Bolder)
            .fontColor(Color.White)


          //.backgroundColor(Color.Pink)
          Text(this.data.date + " " + this.data.week)
            .fontSize(40)
            .fontWeight(FontWeight.Bold)
            .fontColor(Color.White)
          //.backgroundColor(Color.Yellow)
        }.width('100%')

      }
      .width('100%')
      //.backgroundColor(Color.Brown)

      //weather info
      Row() {
        Column() {
          if (this.data.weather === 'cloud2sun') {
            Image($r("app.media.weather_cloud2sun"))
              .objectFit(ImageFit.Contain)
              .width('120')
              .height('120')
          }
          else if (this.data.weather === 'sun') {
            Image($r("app.media.weather_cloud2sun"))
              .objectFit(ImageFit.Contain)
              .width('120')
              .height('120')
          }
          Text(this.data.temperature)
            .fontSize(40)
            .fontWeight(FontWeight.Bold)
            .fontColor(Color.White)
            .textAlign(TextAlign.Center)

        }
        //.backgroundColor(Color.Blue)
      }

      //operation button
      Row() {
        Column() {
          Button() {
            Text('语音助手')
              .fontColor(Color.White)
              .textAlign(TextAlign.Center)
              .fontWeight(FontWeight.Bold)
              .fontSize(25)
              .width('100%')
          }
          .type(ButtonType.Normal)
          .borderRadius(15)
          .height('150')
          .width('90%')
          .opacity(0.9)
          .alignSelf(ItemAlign.Center)
          .onClick(() => {

            router.push({ uri: 'pages/voice_assistant', params: {
              switchMode: 'homeMode'
            } })
          })

        }
        .layoutWeight(1)

        Column() {
          Button() {
            Text('提醒服务')
              .fontColor(Color.White)
              .textAlign(TextAlign.Center)
              .fontWeight(FontWeight.Bold)
              .fontSize(25)
              .width('100%')
          }
          .type(ButtonType.Normal)
          .borderRadius(15)
          .height('150')
          .width('90%')
          .opacity(0.9)
          .alignSelf(ItemAlign.Center)
          .onClick(() => {
            router.push({ uri: 'pages/bssm' })
          })
        }
        .layoutWeight(1)

      }
      .padding(30)
      //.backgroundColor(Color.Grey)
    }
    .margin({ top: 52 })
    .height('90%')
  }

  @Builder builderPageOther() {
    Column() {
      Text('welcome to you')
        .fontColor(Color.White)
        .fontSize(30)
        .width('100%')
        .height('100%')
        .textAlign(TextAlign.Center)
        .backgroundColor(Color.Black)
    }
    .height('90%')
    .margin({ top: 52 })
  }

  @Builder buildPanel() {
    //button panel
    Panel(this.panelShow) {
      Column() {
        //first line
        Row() {
          Column() {
            Image($r('app.media.home'))
              .objectFit(ImageFit.Contain)
              .width('50').height('50')
            Text('彩光')
              .fontColor(Color.White)
              .textAlign(TextAlign.Center)
              .fontWeight(FontWeight.Bold)
              .fontSize(25)
              .width('50%')
          }
          .layoutWeight(1)
          .borderRadius(15)
          .width('20%')
          .padding(10)
          .opacity(0.9)
          .onClick(() => {
            router.push({ uri: 'pages/lanls_colorful' })
          })
          .backgroundColor(Color.Gray)

          Column() {
            Image($r('app.media.setting'))
              .objectFit(ImageFit.Contain)
              .width('50').height('50')
            Text('白光')
              .fontColor(Color.White)
              .textAlign(TextAlign.Center)
              .fontWeight(FontWeight.Bold)
              .fontSize(25)
              .width('50%')
          }
          .layoutWeight(1)
          .borderRadius(15)
          .width('20%')
          .padding(10)
          .opacity(0.9)
          .onClick(() => {
            router.push({ uri: 'pages/lanls_lighting' })
          })
          .backgroundColor(Color.Gray)

          Column() {
            Image($r('app.media.screen'))
              .objectFit(ImageFit.Contain)
              .width('50').height('50')
            Text('语音管家')
              .fontColor(Color.White)
              .textAlign(TextAlign.Center)
              .fontWeight(FontWeight.Bold)
              .fontSize(25)
              .width('100%')
          }
          .layoutWeight(1)
          .borderRadius(15)
          .width('20%')
          .padding(10)
          .opacity(0.9)
          .onClick(() => {

            console.log("------------route")
            router.push({ uri: 'pages/voice_assistant' })
          })
          .backgroundColor(Color.Gray)

        }
        //second line
        Row() {
          Column() {
            Image($r('app.media.sync'))
              .objectFit(ImageFit.Contain)
              .width('50').height('50')
            Text('场景')
              .fontColor(Color.White)
              .textAlign(TextAlign.Center)
              .fontWeight(FontWeight.Bold)
              .fontSize(25)
              .width('50%')
          }
          .layoutWeight(1)
          .borderRadius(15)
          .width('20%')
          .padding(10)
          .opacity(0.9)
          .onClick(() => {
            router.push({ uri: 'pages/lanls_scenes' })
          })
          .backgroundColor(Color.Gray)

          Column() {
            Image($r('app.media.sensor'))
              .objectFit(ImageFit.Contain)
              .width('50').height('50')
            Text('通知')
              .fontColor(Color.White)
              .textAlign(TextAlign.Center)
              .fontWeight(FontWeight.Bold)
              .fontSize(25)
              .width('50%')
          }
          .layoutWeight(1)
          .borderRadius(15)
          .width('20%')
          .padding(10)
          .opacity(0.9)
          .onClick(() => {
            router.push({ uri: 'pages/bssm' })
          })
          .backgroundColor(Color.Gray)

          Column() {
            Image($r('app.media.theme'))
              .objectFit(ImageFit.Contain)
              .width('50').height('50')
            Text('主题')
              .fontColor(Color.White)
              .textAlign(TextAlign.Center)
              .fontWeight(FontWeight.Bold)
              .fontSize(25)
              .width('50%')
          }
          .layoutWeight(1)
          .borderRadius(15)
          .width('20%')
          .padding(10)
          .onClick(() => {
            router.push({ uri: 'pages/index' })
          })
          .backgroundColor(Color.Gray)
        }
      }
      .height('100%')
    }
    .type(PanelType.Foldable)
    .mode(PanelMode.Half)
    .halfHeight(500)
    .dragBar(true) // 默认开启
    .onChange((value: any) => {
      console.info(`width:${value.width},height:${value.height},mode:${value.mode}`)
    })
    .height('90%')
    .backgroundColor(Color.Gray)
  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67.
  • 68.
  • 69.
  • 70.
  • 71.
  • 72.
  • 73.
  • 74.
  • 75.
  • 76.
  • 77.
  • 78.
  • 79.
  • 80.
  • 81.
  • 82.
  • 83.
  • 84.
  • 85.
  • 86.
  • 87.
  • 88.
  • 89.
  • 90.
  • 91.
  • 92.
  • 93.
  • 94.
  • 95.
  • 96.
  • 97.
  • 98.
  • 99.
  • 100.
  • 101.
  • 102.
  • 103.
  • 104.
  • 105.
  • 106.
  • 107.
  • 108.
  • 109.
  • 110.
  • 111.
  • 112.
  • 113.
  • 114.
  • 115.
  • 116.
  • 117.
  • 118.
  • 119.
  • 120.
  • 121.
  • 122.
  • 123.
  • 124.
  • 125.
  • 126.
  • 127.
  • 128.
  • 129.
  • 130.
  • 131.
  • 132.
  • 133.
  • 134.
  • 135.
  • 136.
  • 137.
  • 138.
  • 139.
  • 140.
  • 141.
  • 142.
  • 143.
  • 144.
  • 145.
  • 146.
  • 147.
  • 148.
  • 149.
  • 150.
  • 151.
  • 152.
  • 153.
  • 154.
  • 155.
  • 156.
  • 157.
  • 158.
  • 159.
  • 160.
  • 161.
  • 162.
  • 163.
  • 164.
  • 165.
  • 166.
  • 167.
  • 168.
  • 169.
  • 170.
  • 171.
  • 172.
  • 173.
  • 174.
  • 175.
  • 176.
  • 177.
  • 178.
  • 179.
  • 180.
  • 181.
  • 182.
  • 183.
  • 184.
  • 185.
  • 186.
  • 187.
  • 188.
  • 189.
  • 190.
  • 191.
  • 192.
  • 193.
  • 194.
  • 195.
  • 196.
  • 197.
  • 198.
  • 199.
  • 200.
  • 201.
  • 202.
  • 203.
  • 204.
  • 205.
  • 206.
  • 207.
  • 208.
  • 209.
  • 210.
  • 211.
  • 212.
  • 213.
  • 214.
  • 215.
  • 216.
  • 217.
  • 218.
  • 219.
  • 220.
  • 221.
  • 222.
  • 223.
  • 224.
  • 225.
  • 226.
  • 227.
  • 228.
  • 229.
  • 230.
  • 231.
  • 232.
  • 233.
  • 234.
  • 235.
  • 236.
  • 237.
  • 238.
  • 239.
  • 240.
  • 241.
  • 242.
  • 243.
  • 244.
  • 245.
  • 246.
  • 247.
  • 248.
  • 249.
  • 250.
  • 251.
  • 252.
  • 253.
  • 254.
  • 255.
  • 256.
  • 257.
  • 258.
  • 259.
  • 260.
  • 261.
  • 262.
  • 263.
  • 264.
  • 265.
  • 266.
  • 267.
  • 268.
  • 269.
  • 270.
  • 271.
  • 272.
  • 273.
  • 274.
  • 275.
  • 276.
  • 277.
  • 278.
  • 279.
  • 280.
  • 281.
  • 282.
  • 283.
  • 284.
  • 285.
  • 286.
  • 287.
  • 288.
  • 289.
  • 290.
  • 291.
  • 292.
  • 293.
  • 294.
  • 295.
  • 296.
  • 297.
  • 298.
  • 299.
  • 300.
  • 301.
  • 302.
  • 303.
  • 304.
  • 305.
  • 306.
  • 307.
  • 308.
  • 309.
  • 310.
  • 311.
  • 312.
  • 313.
  • 314.
  • 315.
  • 316.
  • 317.
  • 318.
  • 319.
  • 320.
  • 321.
  • 322.
  • 323.
  • 324.
  • 325.
  • 326.
  • 327.
  • 328.
  • 329.
  • 330.
  • 331.
  • 332.
  • 333.
  • 334.
  • 335.
  • 336.

2.2 语音助手

voice_assistant.ets

@Entry
@Component
struct voiceAssistant {
  @State listening: boolean= false
  @State answer: string= '您好,有什么吩咐!'
  private listeningWord: string= '我正在聆听..'
  private doneWord: string= '好的,已经帮您打开'

  build() {
    Column() {
      Row() {
        Image($r('app.media.ready'))
          .objectFit(ImageFit.Contain)
          .height('100%')
          .width('100%')
      }
      .alignItems(VerticalAlign.Bottom)
      .height('60%')
      //.backgroundColor(Color.Red)
      .onClick(() => {
        if (this.listening) {
          this.answer = this.doneWord
          this.listening = false
        } else {
          this.answer = this.listeningWord;
          this.listening = true
        }
      })

      Row() {
        Text(this.answer)
          .fontSize('35')
          .fontColor(Color.White)
          .textAlign(TextAlign.Center)
          .width('100%')
          .padding(10)

      }
      .height('40%')
      //.backgroundColor(Color.Gray)
    }
    .backgroundColor(Color.Black)
  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.

2.2 提醒服务

smart_reminder.ets

import router from '@system.router';
@Entry
@Component
struct bssm {
  @State notice:string='快递已经到家,快到门口去拿!\n'

  build() {
    Column() {
      this.buildNotice()
    }
    .height('100%')
    .backgroundColor(Color.Black)
  }

  @Builder buildNotice() {
    Column() {
      Column() {
        //image
        Row() {
          Image($r('app.media.img_6'))
            //.width('20%')
            //.height('20%')
            .objectFit(ImageFit.Contain)
            .width('100%')
            .height('70%')
            .margin('2%')
        }
        .height('45%')
        //.backgroundColor(Color.Red)
        //date
        Row() {
          Text('19:32 04/20')
            .fontSize('25')
            .fontColor(Color.White)
            .textAlign(TextAlign.Center)
            .width('100%')
        }
        .height('10%')
        //.backgroundColor(Color.Green)
        //notice
        Row() {
          Text(this.notice)
            .fontSize('25')
            .fontColor(Color.White)
            .textAlign(TextAlign.Center)
            .textOverflow({overflow:TextOverflow.Ellipsis})//超长省略号代替
            .maxLines(3)
            .padding('2%')
            .width('100%')
        }
        .height('20%')
        //.backgroundColor(Color.Red)
      }
      .width('95%')
      .margin({ top: '3%' })
      .borderRadius(10)
      .backgroundColor('#2c3134')

      Row() {
        Button() {
          Text('好的').fontSize(20).fontColor(Color.White)
        }
        .type(ButtonType.Normal)
        .borderRadius(5)
        .height('70%')
        .width('100%')
        .onClick(() => {
          router.push({ uri: 'pages/index' })
        })
      }
      .margin('1%')
      .width('95%')
      .height('15%')
      //.backgroundColor(Color.Pink)
    }
    .height('100%')
    .width('100%')
    .borderRadius(10)
    .alignItems(HorizontalAlign.Center)
    .backgroundColor(Color.Black)
  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67.
  • 68.
  • 69.
  • 70.
  • 71.
  • 72.
  • 73.
  • 74.
  • 75.
  • 76.
  • 77.
  • 78.
  • 79.
  • 80.
  • 81.
  • 82.

3.总结

1.eTS声明式的语法用着还是挺舒服的,调试布局可以通过设定组件的backgroundColor来验证
2.后续根据自己的想法再慢慢加一些功能进去,比如结合一些AI能力进去,还有消息通知效果策略等,随便发挥把

©著作权归作者所有,如需转载,请注明出处,否则将追究法律责任
已于2022-4-29 21:53:47修改
8
收藏 5
回复
举报
8
2
5
2条回复
按时间正序
/
按时间倒序
红叶亦知秋
红叶亦知秋

DAYU200的可玩性还是丰富

回复
2022-4-30 20:45:53
Whyalone
Whyalone

希望大佬能够把界面上所有功能都搞定,那就无敌了

回复
2022-5-1 11:18:50


回复
    相关推荐