最新鸿蒙HarmonyOS4.0开发登陆的界面2

登陆功能

代码如下:

typescript 复制代码
import router from '@ohos.router';
@Entry
@Component
struct Index {
  @State message: string = 'XXAPP登陆'
  @State userName: string = '';
  @State password: string = '';
  build() {
    Row() {
      Column({space:50}) {
        Image($r('app.media.icon')).width(200).interpolation(ImageInterpolation.High)
        Text(this.message).fontSize(50).fontWeight(FontWeight.Bold)
         TextInput({placeholder:'用户名'}) .onChange((value: string) => {
           this.userName = value;
         })
        TextInput({placeholder:'密码'}).onChange((value: string) => {
          this.password = value;
        })
        Button('确定').onClick(()=>{
          if(isLoginButtonClickable(this.userName,this.password)){
            router.pushUrl({
              url: 'pages/Myprofile'
            })
          }else{

            AlertDialog.show(
              {
                title: '提示',
                message: '用户名或密码错',
                autoCancel: true,
                alignment: DialogAlignment.Bottom,
                offset: { dx: 0, dy: -20 },
                confirm: {
                  value: '确认',
                  action: () => {
                    console.info('Callback when confirm button is clicked');
                  }
                },
                cancel: () => {
                  console.info('Closed callbacks')
                }
              }
            )
          }
        })

      }.justifyContent(FlexAlign.Center).height('100%')
    }
  }
}

/**
 * 根据用户名和密码的输入计算登录按钮是否可点击。
 *
 * @param {string} userName - 用户名,要求为手机的格式。
 * @param {string} password - 密码。
 * @return {boolean} 是否可点击登录按钮。
 */
function isLoginButtonClickable(userName: string, password: string): boolean {
  // 在这里添加检查用户名是否为手机格式的逻辑
  // 例如,可以使用正则表达式验证用户名是否符合手机格式
  const isUserNameValid = /\d{11}/.test(userName)
  return isUserNameValid && password !== ''
}

相关代码可以下载:下载代码

相关推荐
酷酷的阿云12 分钟前
动画与过渡效果:UnoCSS内置动画库的实战应用
前端·css·typescript
三棵杨树2 小时前
TypeScript从零开始(一):初识TS
typescript
菜鸟码猿1 天前
TS内置工具类型
前端·typescript
鸿蒙开发工程师—阿辉2 天前
HarmonyOS Next元服务网络请求封装实践
网络·华为·typescript·harmonyos·元服务
MurphyChen2 天前
TypeScript 官方宣布弃用 Enum?Enum 何罪之有?
前端·javascript·typescript
Homilier2 天前
开发vue小游戏:数字华龙道
前端·vue.js·typescript·数字华龙道
慢知行2 天前
TypeScript 封装 Date 格式化函数:简洁又高效
前端·javascript·typescript
我去买橘子3 天前
TypeScript类型检查与语法树分析探索
typescript
Hamm3 天前
前端不在TypeScript使用类,如何写出清晰优雅的代码?
前端·vue.js·typescript
shmily_yy3 天前
TS为什么被叫做类型体操
typescript