首页 > 其他分享 >HarmonyOS NEXT模拟登录页,华为账号一键登录

HarmonyOS NEXT模拟登录页,华为账号一键登录

时间:2024-10-09 15:25:01浏览次数:1  
标签:10 登录 width 用户 NEXT HarmonyOS state height

一、介绍
基于鸿蒙Next模拟账号一键登录,免去账号注册环节
二、场景需求
1. 用户场景
新用户: 需要快速注册并登录,以体验华为的服务。
老用户: 希望快速登录,不用每次输入用户名和密码。
2. 界面设计
Logo和标题: 页面顶部展示华为的Logo及"一键登录"或"华为账号登录"的标题。
3. 功能需求:短信/邮箱验证码:
4. 安全性
二次验证: 可选启用二次验证,如在高风险环境下(新设备登录等),要求用户通过邮件或短信进行确认。
5. 适应性
响应式设计: 确保在不同设备(手机、平板、电脑)上的良好展示。
多语言支持: 提供多种语言选项,方便不同地区用户使用。
6. 用户反馈
操作反馈: 无论是按钮点击还是输入错误,都需要及时反馈用户操作状态。
常见问题解答链接: 用户如果在登录时遇到问题,可以快速找到帮助。

三、业务步骤
第一步:点击“一键登录”,获取登录信息
第二步:拉起授权弹窗
第三步:获取授权,获取用户信息
第四步:展示用户信息,显示功能选项
四、效果展示

五:代码展示:
`import { authentication } from '@kit.AccountKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
import { util } from '@kit.ArkTS';
import { BusinessError } from '@kit.BasicServicesKit';

//自定义
import { Mine_SystemItem_Type,CommonConstants } from "../common/CommonConstant"

@Entry
@Component
struct Index06 {
@State tabMineItem:Mine_SystemItem_Type[] = CommonConstants.MINE_SYSTEM_ITEM_LIST
@State isLogin: boolean = false
@State userImg: string|Resource|undefined = $r("app.media.app_icon") // 登录头像
@State userName: string|undefined = '昵称001' // 用户昵称
@State btnTitle: string = '华为账号一键登录' // 用户昵称

getHuaWeiAccount(){
// 创建授权请求,并设置参数
let authRequest = new authentication.HuaweiIDProvider().createAuthorizationWithHuaweiIDRequest();
// 获取头像昵称需要传如下scope
authRequest.scopes = ['profile','phone'];
// 若开发者需要进行服务端开发,则需传如下permission获取authorizationCode
authRequest.permissions = ['serviceauthcode'];
// 用户是否需要登录授权,该值为true且用户未登录或未授权时,会拉起用户登录或授权页面
authRequest.forceAuthorization = true;
// 用于防跨站点请求伪造。
authRequest.state = util.generateRandomUUID();
// 执行授权请求
try {
let controller = new authentication.AuthenticationController(getContext(this));
controller.executeRequest(authRequest).then((data) => {
let authorizationWithHuaweiIDResponse = data as authentication.AuthorizationWithHuaweiIDResponse;
let state = authorizationWithHuaweiIDResponse.state;
if (state != undefined && authRequest.state != state) {
hilog.error(0x0000, 'testTag', Failed to authorize. The state is different, response state: ${state});
return;
}
hilog.info(0x0000, 'testTag', 'Succeeded in authentication: %{public}s',
JSON.stringify(authorizationWithHuaweiIDResponse));
this.isLogin = !this.isLogin
this.btnTitle = '退出'
this.userImg = authorizationWithHuaweiIDResponse.data!.avatarUri;
this.userName = authorizationWithHuaweiIDResponse.data!.nickName;

  }).catch((err: BusinessError) => {
    this.dealAllError(err);
  });
} catch (error) {
  this.dealAllError(error);
}

}
// 错误处理
dealAllError(error: BusinessError): void {
hilog.error(0x0000, 'testTag', Failed to auth. Code: ${error.code}, message: ${error.message});
}

build() {
Column() {
Column() {
//头像
Column() {
Image(this.userImg)
.objectFit(ImageFit.Cover)
.height(72)
.width(72)
.borderRadius(36)
Row().height(20)

        Text(this.userName).fontSize(16)

      }
      .width('90%')
      .borderRadius(12)
      .alignItems(HorizontalAlign.Center)
      .justifyContent(FlexAlign.Center)
      .backgroundColor(0xFFFFFF)
      .shadow({
        radius: 10,
        color: "#dddddd",
        offsetX: 6,
        offsetY: 6
      })
      .margin({ top: 15, bottom: 10 })
      .padding({ top: 30, bottom: 30 })
    }
    .justifyContent(FlexAlign.Start)
    .alignItems(HorizontalAlign.Center)

    Button(this.btnTitle)
      .width('70%')
      .height(30)
      .onClick(()=>{
        this.getHuaWeiAccount()
        // this.isLogin = !this.isLogin
        // this.btnTitle = '退出'
      })
      .margin({ top:10,bottom:20 })

    if (this.isLogin){
    Column(){
      //功能选项
      ForEach(this.tabMineItem,(item:Mine_SystemItem_Type,index:number)=>{
        Row(){
          Text(item.itemTitle).fontSize(16).fontColor(0x161616)
          Blank()
          Image($r("app.media.ic_right_back_greyWhite")).width(24).height(24)
        }.width('100%')
        .height(48)
        .padding({left:15,right:10})
        .stateStyles({
          normal:{.backgroundColor(0xFFFFFF)},
          pressed:{.backgroundColor(0xEFEFEF)}
        })
      },(item:string)=>item)
      Row(){
        Text('隐私声明').fontSize(16).fontColor(0x161616)
        Blank()
        Image($r("app.media.ic_right_back_greyWhite")).width(24).height(24)
      }.width('100%')
      .height(48)
      .padding({left:15,right:10})
      .stateStyles({
        normal:{.backgroundColor(0xFFFFFF)},
        pressed:{.backgroundColor(0xEFEFEF)}
      })

    }.width('90%')
    .justifyContent(FlexAlign.Start)
    .alignItems(HorizontalAlign.Center)
    .backgroundColor(0xFFFFFF)
    .shadow({radius:10,color:"#dddddd",offsetX:6,offsetY:6})
    .padding({top:10,bottom:10})
    .borderRadius(12)
    }

  }.width('100%')
.height('100%')
.justifyContent(FlexAlign.Start)
.backgroundColor(0xEEEEEE)

}

}`

标签:10,登录,width,用户,NEXT,HarmonyOS,state,height
From: https://www.cnblogs.com/liyang-jltf/p/18454348

相关文章

  • 【Next.js 入门教程系列】01-基础知识
    原文链接CSDN的排版/样式可能有问题,去我的博客查看原文系列吧,觉得有用的话,给我的库点个star,关注一下吧 基础知识本篇包括以下内容:Next.js是什么创建Next.js项目客户端组件和服务器端组件数据获取缓存静态渲染与动态渲染Next.js​Next.jsisa framework forb......
  • linux_ssh免密登录
    SSH(SecureShell)协议是一种安全的网络协议,认证原理是基于用户名密码和基于密钥对两种认证方式,本次讲解基于密钥对的认证方式,也就是免密登录免密登录原理.ssh文件夹下的文件功能解释.ssh路径一般在用户的家目录下文件解释known_hosts记录ssh访问过计算机的公钥(publi......
  • [瑞吉外卖]02-登录登出
    登录功能需求分析查看原型需求分析代码开发准备实体类Employee,和employee表进行映射packagecom.itheima.reggie.entity;importcom.baomidou.mybatisplus.annotation.FieldFill;importcom.baomidou.mybatisplus.annotation.TableField;importlombok.Data;i......
  • 鸿蒙 Next 实战: 烟花模拟器
    前言通过上一篇文章可以看出,要在鸿蒙应用中实现特别炫的特效还是比较复杂。动画固然重要,但如果在赶工期的情况下,大家都会优先业务,那有没有简单快速的方法呢?有的,也用像Android和iOS里WebView的方式,h5的特效现在是应有尽有,把他嵌入鸿蒙Next应用里就可以,那如何在鸿蒙Next......
  • 宝塔面板怎么登录不上
    如果你遇到无法登录宝塔面板的情况,可以尝试以下几个步骤来解决问题:检查网络连接:确保服务器和客户端的网络连接正常。尝试刷新页面或更换浏览器。确认面板端口是否正确:默认情况下,宝塔面板的访问端口为8888。如果修改过端口,请确保使用正确的端口进行访问。检查防火......
  • SpringBootWeb登录认证
    SpringBootWeb登录认证基础登录功能思路代码实现测试前后端联调登录校验会话跟踪方案JWT令牌生成校验登录后下发令牌代码测试过滤器快速入门执行流程拦截路径过滤器链登录校验Filter流程代码Interceptor快速入门拦截路径执行流程登录校验Interceptor......
  • 订单交易平台五:短信登录验证界面(从0到1的过程)
    1.短信验证界面(版本一)1.1视图函数accont.py中#先定义form类classSmsLoginForm(forms.Form):role=forms.ChoiceField(required=True,label='角色',choices=(('2','客户'),('1','管理员')),w......
  • <免费开题>登录网站验证码的生成与识别系统(django)|全套源码+文章lw+毕业设计+课程设计
    <免费开题>登录网站验证码的生成与识别系统(django)|全套源码+文章lw+毕业设计+课程设计+数据库+ppt摘要近年来随着互联网应用技术的飞速发展,为了确保网站系统平台的安全性,各类网站相继推出了验证码应用技术,通过验证码的应用来帮助缓解暴力破解账户密码、垃圾邮件攻击以及在......
  • 鸿蒙 Next 实战: 电子木鱼
    前言正所谓:HelloWord是程序员学任何一门语言的第一个程序实践。这其实也是一个不错的正反馈,那如何让学习鸿蒙Next更有成就感呢?下面就演示一下从零开发一个鸿蒙Next版的电子木鱼,主打就是一个抽象! 实现要点页面布局木鱼点击木鱼音效动画特效自定义弹窗 开始实......
  • QQ登录(第三方登录)
    login.html<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><htmlxmlns="http://www.w3.org/1999/xhtml"xml:lang="en"><head>......