最新鸿蒙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 !== ''
}

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

相关推荐
胡译胡说3 小时前
会写TypeScript就能理解日语语法——Typed Japanese项目能做到(吗?)
typescript·编程语言
Moment7 小时前
TS 高级类型:Partial 使用及实现原理
前端·javascript·typescript
亦黑迷失1 天前
实现 canvas 交互(元素的事件处理)
前端·typescript·canvas
Superxpang1 天前
JavaScript `new Date()` 方法移动端 `兼容 ios`,ios环境new Date()返回NaN
开发语言·前端·javascript·ios·typescript·安卓
阿里云云原生1 天前
Typescript AI 通义灵码 VSCode插件安装与功能详解
typescript
用户王建国1 天前
TypeScript 基础学习
前端·typescript
程序员小续2 天前
TypeScript中any、unknown、never的区别
前端·面试·typescript
云草桑2 天前
C# net CMS相关开源软件 技术选型 可行性分析
typescript·c#·cms
y_y2 天前
TypeScript不要背,炸至两面金黄,隔壁小孩都学哭了...
typescript
Chaoran2 天前
vue 插槽的使用和插槽的本质
前端·vue.js·typescript