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

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

相关推荐
tedcloud12319 小时前
wifi-densepose部署教程:构建无线人体感知系统
服务器·javascript·网络·typescript·ocr
奇奇怪怪的问题21 小时前
学习ts笔记(二):属性修饰符,泛型,接口
前端·typescript
阿正的梦工坊1 天前
【Typescript】04-数组元组枚举与字面量类型
javascript·ubuntu·typescript
狼丶宇先森1 天前
vue-sign-canvas v2 重构复盘:从 Vue 2 签名板到 Vue 3 + TypeScript 组件库
前端·vue.js·重构·typescript·开源软件·canvas
muddjsv1 天前
前端开发语言使用流行度排行与分析
前端·javascript·typescript
Joy T1 天前
【Web3】Hardhat工程架构中Solidity与TypeChain的协作机制
git·架构·typescript·web3·智能合约·hardhat·typechain
烛阴2 天前
Cocos Creator 3.x 装饰器实战:让你的代码优雅 10 倍
typescript·cocos creator
吃西瓜的年年2 天前
TypeScript
javascript·ubuntu·typescript
Restart-AHTCM2 天前
AI时代大前端Agent开发LangChain.js
typescript·langchain·memory·rag·tools
Edwardwu2 天前
写了个y-mxgraph:给 draw.io 接上了 Yjs,顺便解决了部署在 iframe 里的一堆问题
前端·typescript