Skip to content
Snippets Groups Projects
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
LoginPage.ets 2.31 KiB
// 登陆页面
import { router, promptAction } from '@kit.ArkUI'
import CommonConstants from '../common/CommonConstant'
import './RegisterPage'
import Register from './RegisterPage';

@Component
export struct Login {
  @Provide('loginPageStack') LoginPageStack: NavPathStack = new NavPathStack(); //router

  @Builder
  PageMap(name1: string) {
    if(name1 == 'Register') {
      Register()
    }
  }

  @State phone: string = ''
  @State pwd: string = ''

  // 提交
  handleSubmit() {
    if(this.phone === '' || this.pwd === '') {
      promptAction.showToast({ message: '手机号或密码不能为空' })
    }else {
      // 登录接口逻辑...

      promptAction.showToast({ message: '登录成功' })
      setTimeout(() => {
        router.replaceUrl({ url: 'pages/Index' })
      }, 2000)
    }
  }

  build() {
    Navigation(this.LoginPageStack) {
      Column() {
        Column({space: 10}) {
          Image('media/startIcon.png').height(40).width(40)
          Text('欢迎登录Todolist').fontSize(18).fontColor(CommonConstants.base_blue).margin({top:10})
        }
        .margin({top: 50})
        Column({space: 15}) {
          TextInput({placeholder: '手机号'})
            .onChange((value) => {
              this.phone = value
            })
          TextInput({placeholder: '密码'}).type(InputType.Password)
            .onChange((value) => {
              this.pwd = value
            })
          Button('登录').height(45).width('100%')
            .onClick(() => {
              this.handleSubmit()
            })
            .margin({top: 8})
        }
        .margin({top: 20})
        .width('80%')
        Row({space: 15}) {
          Text('忘记密码').fontSize(14).opacity(0.5)
            .onClick(()=>{
              promptAction.showToast({ message: '忘了就重新注册一个吧...' })
            })
          Text('注册账号').fontSize(14).opacity(0.5)
            .onClick(() => {
              this.LoginPageStack.pushDestination({name: 'Register', onPop: ()=> {
                // this.totalTasks = DataModel.getData() //返回时更新数据(应对删除数据的情况)
              }})
            })
        }
        .margin({top: 20})
      }
      .height('100%')
      .width('100%')
    }
    .hideTitleBar(true)
    .navDestination(this.PageMap)
    .mode(NavigationMode.Stack)
  }
}