一、自定义tabs
// home页
import Home from './Home'
// Work页
import Work from './Work'
// mine页
import Mine from './Mine'
@Entry
@Component
struct TabsExample {
@State currentIndex: number = 0;
private tabsController: TabsController = new TabsController();
@Builder TabBuilder(title: string,targetIndex: number,selectedImg: Resource,normalImg: Resource) {
Column() {
Image(this.currentIndex === targetIndex ? selectedImg : normalImg)
.size({ width: 25,height: 25 })
Text(title)
.fontColor(this.currentIndex === targetIndex ? '#3774c6' : '#6B6B6B')
}
.width('100%')
.height(50)
.height(50)
.justifyContent(FlexAlign.Center)
.onClick(() => {
this.currentIndex = targetIndex;
this.tabsController.changeIndex(this.currentIndex);
})
}
build() {
Tabs({ barPosition: BarPosition.End,controller: this.tabsController }) {
TabContent() {
Home()
}
.tabBar(this.TabBuilder('首页',$r('app.media.ic_tab_home_selected'),$r('app.media.ic_tab_home_normal')))
TabContent() {
Work()
}.tabBar(this.TabBuilder('工作台',1,$r('app.media.ic_tab_work_selected'),$r('app.media.ic_tab_work_normal')))
TabContent() {
Mine()
}.tabBar(this.TabBuilder('我的',2,$r('app.media.ic_tab_mine_selected'),$r('app.media.ic_tab_mine_normal')))
}
.barWidth('100%')
.barHeight(50)
.onChange((index: number) => {
this.currentIndex = index;
})
}
}
效果
二、路由跳转
router.pushUrl({url:'pages/Mine'}) 有历史记录,可以通过router.back()返回 router.replaceUrl({url:'pages/Mine'}) 无历史记录 @State msg:string = router.getParams()?.['msg']可以接收router.pushUrl传递的数据
三、登录页
import router from '@ohos.router';
import prompt from '@system.prompt';
let msg: String = 'login页面传来的数据'
@Entry
@Component
struct RowPage {
@State account: string = ''
@State password: string = ''
build() {
Column({ space: 10 }) {
Image($r('app.media.logo'))
.width(78)
.height(78)
.margin({ top: 120,bottom: 20 })
Text('登录')
.fontSize(24)
.fontWeight(FontWeight.Medium)
.fontColor('#182431')
Text('登录账号以使用更多服务')
.fontSize(16)
.fontColor('#798189')
.margin({ top: 20,bottom: 20 })
TextInput({ placeholder: '请输入账号' })
.maxLength(11)
.type(InputType.Number)
.onChange((value: string) => {
this.account = value;
})
.backgroundColor('#F0F2F4')
.border({ color: '#3774c6',width: '100%' })
TextInput({ placeholder: '请输入密码' })
.type(InputType.Password)
.maxLength(9)
.showPasswordIcon(true)
.onChange((value: string) => {
this.password = value;
})
.backgroundColor('#F0F2F4')
.border({ color: '#3774c6',width: '100%' })
Row() {
Text('短信验证码登录')
.fontColor('#3774c6')
.onClick(()=>{
router.pushUrl({url:'pages/LoginPhone'})
})
Text('忘记密码?')
.fontColor('#3774c6')
.onClick(()=>{
router.pushUrl({url:'pages/ForgetPassword'})
})
}.width('100%')
.margin({ top: 10 })
.justifyContent(FlexAlign.SpaceBetween)
Button('登录')
.onClick(() => {
if (this.account != '' && this.password != '') {
router.pushUrl({
url: 'pages/Index',params: {
msg: msg,}
})
} else {
prompt.showToast({
message: '请输入账号密码!',duration: 2000,});
}
}
)
.width('100%')
.margin({ top: 50,bottom: 10 })
.backgroundColor('#3774c6')
Text('注册账号')
.fontColor('#3774c6')
}.height('100%')
.width('100%')
.padding(10)
.backgroundColor('#F1F3F5')
}
}
效果
四、短信验证码登录
import router from '@ohos.router';
import prompt from '@system.prompt';
@Entry
@Component
struct RowPage {
@State phone: string = ''
@State verifyCode: string = ''
build() {
Column({ space: 10 }) {
Image($r('app.media.logo'))
.width(78)
.height(78)
.margin({ top: 120,bottom: 20 })
Text('短信验证码登录')
.fontSize(24)
.fontWeight(FontWeight.Medium)
.fontColor('#182431')
Text('登录账号以使用更多服务')
.fontSize(16)
.fontColor('#798189')
.margin({ top: 20,bottom: 20 })
TextInput({ placeholder: '请输入手机号' })
.maxLength(11)
.type(InputType.PhoneNumber)
.onChange((value: string) => {
this.phone = value;
})
.backgroundColor('#F0F2F4')
.border({ color: '#3774c6',width: '100%' })
Text('点击获取验证码').onClick(() => {
console.log('获取验证码')
}).fontSize(16)
.fontColor('#3774c6').position({ x: 220,y: 343 })
TextInput({ placeholder: '请输入短信验证码' })
.type(InputType.Normal)
.onChange((value: string) => {
this.verifyCode = value;
})
.backgroundColor('#F0F2F4')
.border({ color: '#3774c6',width: '100%' })
Row() {
Text('账号密码登录')
.fontColor('#3774c6')
.onClick(() => {
router.pushUrl({ url: 'pages/Login' })
})
Text('忘记账号?')
.fontColor('#3774c6')
.onClick(() => {
router.pushUrl({ url: 'pages/ForgetPassword' })
})
}.width('100%')
.margin({ top: 10 })
.justifyContent(FlexAlign.SpaceBetween)
Button('登录')
.onClick(() => {
if (this.phone != '') {
if (this.verifyCode != '') {
router.pushUrl({
url: 'pages/Index',})
} else {
prompt.showToast({
message: '请输入验证码!',});
}
} else {
prompt.showToast({
message: '请输入手机号!',});
}
}
)
.width('100%')
.margin({ top: 50,bottom: 10 })
.backgroundColor('#3774c6')
}.height('100%')
.width('100%')
.padding(10)
.backgroundColor('#F1F3F5')
}
}
效果
五、忘记密码
import router from '@ohos.router';
import prompt from '@system.prompt';
@Entry
@Component
struct RowPage {
@State phone: string = ''
@State verifyCode: string = ''
@State newPassword: string = ''
@State password: string = ''
build() {
Column({ space: 10 }) {
Image($r('app.media.logo'))
.width(78)
.height(78)
.margin({ top: 120,bottom: 20 })
Text('忘记密码')
.fontSize(24)
.fontWeight(FontWeight.Medium)
.fontColor('#182431')
Text('登录账号以使用更多服务')
.fontSize(16)
.fontColor('#798189')
.margin({ top: 20,width: '100%' })
TextInput({ placeholder: '请输入新密码' })
.type(InputType.Normal)
.maxLength(9)
.showPasswordIcon(true)
.onChange((value: string) => {
this.newPassword = value;
})
.backgroundColor('#F0F2F4')
.border({ color: '#3774c6',width: '100%' })
TextInput({ placeholder: '请确认新密码' })
.type(InputType.Normal)
.maxLength(9)
.showPasswordIcon(true)
.onChange((value: string) => {
this.password = value;
})
.backgroundColor('#F0F2F4')
.border({ color: '#3774c6',width: '100%' })
Row() {
Text('账号密码登录')
.fontColor('#3774c6')
.onClick(() => {
router.pushUrl({ url: 'pages/Login' })
})
}.width('100%')
.margin({ top: 10 })
.justifyContent(FlexAlign.SpaceBetween)
Button('重置密码')
.onClick(() => {
if (this.phone != '') {
if (this.verifyCode != '') {
if (this.newPassword !== '' && this.password !== '') {
if (this.newPassword !== this.password) {
prompt.showToast({
message: '两次输入密码不一致!',});
} else {
prompt.showToast({
message: '重置密码成功,请重新登录!',});
setTimeout(() => {
router.pushUrl({
url: 'pages/Login',})
},1000)
}
} else {
prompt.showToast({
message: '请输入密码!',});
}
} else {
prompt.showToast({
message: '请输入验证码!',});
}
} else {
prompt.showToast({
message: '请输入手机号',bottom: 10 })
.backgroundColor('#3774c6')
}.height('100%')
.width('100%')
.padding(10)
.backgroundColor('#F1F3F5')
}
}
效果
原文地址:https://blog.csdn.net/qq_43751614/article/details/135391217
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。