ArkTS+UI登录页面

#鸿蒙前端登录页面
功能:没啥功能,没有数据库(假的也没有),登录时需要同时满足username和password有值,否则会弹窗提示(AlertDialog.show),
输入后会弹窗并显示用户名
背景是一张图片,然后用了属性backgroundBlurStyle(BlurStyle.Thick)来增加模糊感
@State声明状态变量,当变量更改时也会刷新页面UI当前变量渲染
onChange方法会在inputText组件的内容发生改变的时候即时更新到声明的变量中

效果

在这里插入图片描述在这里插入图片描述

代码

@Entry
@Component
struct firstPage {

  @State users:string[] = ['admin']

  // 选择的登录类型
  @State loginType: number = 0
  // 输入的username
  @State username: string = ''
  // 输入的密码
  @State password: string = ''
  // 点击登录的回调
  private loginUser = async () => {
    console.log('username',this.username)
    console.log('password',this.password)
    if (!this.username || !this.password) {
      // 弹框组件 自带的 不需要引入
      AlertDialog.show(
        {
          title: '温馨提示',
          message: '请输入用户名或者密码',
          autoCancel: true,
          alignment: DialogAlignment.Center,
          gridCount: 3,
          confirm: {
            value: '确认',
            action: () => {
              console.info('Button-clicking callback')
            }
          },
          cancel: () => {
            console.info('Closed callbacks')
          }
        }
      )
    } else {
      // 发送请求
      AlertDialog.show({
        message:`欢迎您,用户${this.username}`
      })
    }
  }

  build() {
    Column({ space:10}) {

      Image($r('app.media.img9'))
        .height(200)
        .width(200)
        .margin({
          top:250
        })
        .borderRadius(100)
      TextInput({
        text:this.username,
        placeholder:'username'
      })
        .onChange((e) => { // 必须要写这个才能实现啊数据绑定
          this.username = e
        })
        .type(InputType.Normal)
        .id('username')
      TextInput({
        text:this.password,
        placeholder:'password'
      })
        .type(InputType.Password)
        .id('password')
        .onChange((e) => { // 必须要写这个才能实现啊数据绑定
          this.password = e
        })
      Button('Login')
        .id('loginBtn')
        .width(200)
        .onClick(this.loginUser)
      Row({space:10}){
        Text('前往注册')
          .id('goRegister')
        Text('忘记密码')
          .id('forgetPassword')
      }
      Image($r('app.media.ic_public_quit'))
        .height(30)
        .fillColor(Color.Gray)
        .id('quitBtn')
        .position({right:0,bottom:0})
    }
    .height('100%')
    .padding({ left:20,right:20 })
    .backgroundImage($r('app.media.ying_and_shenlilinghua'))
    .backgroundBlurStyle(BlurStyle.Thick)
    .backgroundImageSize(ImageSize.Cover)

  }
}

  • 6
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值