
Harmony鸿蒙实战开发-个人记事本app「密码登录保护-简介版」【源码在文末】文章目录Harmony鸿蒙实战开发-个人记事本app「密码登录保护-简介版」【源码在文末】一、运行演示1、登录创建密码2、首页3、编辑4、编辑成功二、部分代码三、源码运行工具DevEco Studio一、运行演示1、登录创建密码2、首页3、编辑4、编辑成功二、部分代码import PreferenceUtil from ../../utils/preference/PreferencesLogInfo import router from ohos.router import promptAction from ohos.promptAction; Entry Component struct Login { private preference PreferenceUtil State password: string ; State firstLogin:boolean false; // 检查是否首次打开应用 onPageShow() { this.preference.firstLogin().then((f){ this.firstLogin f; }) } build(){ Column(){ Image($r(app.media.icon)) .width(144) .height(144) .margin({ top: 70, bottom:70}) .align(Alignment.Center) if(this.firstLogin){ Text($r(app.string.createPassword)) .fontSize(30) .margin({bottom:20}) } else{ Text($r(app.string.inputPassword)) .fontSize(30) .margin({bottom:20}) } TextInput({placeholder:$r(app.string.inputPassword)}) .width(70%) .height(5%) .type(InputType.Password) .onChange((value: string) { this.password value; }) Button(($r(app.string.loginButton)), { type: ButtonType.Capsule }) .margin(50) .width(30%) .onClick((){ if(this.firstLogin){ this.createPassword(); } else{ this.checkLogin(); } }) } .width(100%) .height(100%) .backgroundColor(#ffe6eaea) } // 首次打开创建密码 createPassword(){ if(this.password ! ) { this.preference.putPreference(password,${this.password}) router.replaceUrl({ url: pages/main, }) } else{ promptAction.showToast({ message: $r(app.string.emptyInputPrompt), duration: 2000 }); } } // 检查密码 checkLogin(){ this.preference.checkPassword(this.password) } }三、源码相关鸿蒙项目点此专栏通过百度网盘分享的文件…zip 链接百度网盘 请输入提取码文件已经加密请点击下方名片获取源码或Lvnvn0508