HarmonyOS 鸿蒙Next在半屏登录页面,隐私协议跳转异常
HarmonyOS 鸿蒙Next在半屏登录页面,隐私协议跳转异常
在半屏登录页面,有个隐私协议跳转,是个普通的H5页面。使用的Navigation页面路由,半屏登录使用的bindSheet。现在跳转隐私协议的时候,跳转页面显示在了登录页面下面。
期望场景:隐私协议能直接覆盖显示在登录页面上面。
2 回复
目前的bindsheet规格不支持此操作,这边可以使用navigation的dialog模式,或者使用stack来模拟一个弹框 参考demo:
import router from '@ohos.router';
@Entry
@Component
struct First {
@State textValue: string = 'Hello World'
// 显隐控制设置为不占用
@State visible: Visibility = Visibility.None
build() {
// 使用stack可以实现假的dialog覆盖原页面上面
Stack() {
Row() {
// 初始页面
Column() {
Text('Hello World')
.fontSize(50)
.fontWeight(FontWeight.Bold)
// 触发dialog的地方
Button('click')
.onClick(() => {
//用于检测点击事件是否透传到原来的页面,我测了一下是没有透传的,符合dialog规范
console.log("hit me!")
if (this.visible == Visibility.Visible) {
this.visible = Visibility.None
} else {
this.visible = Visibility.Visible
}
})
.backgroundColor(0x777474)
.fontColor(0x000000)
}
.width('100%')
}
.height('100%')
.backgroundColor(0x885555)
//这里开始是构造弹窗效果主要需要修改的地方,首先是加了一个半透明灰色的蒙层效果
Text('')
.onClick(() => {
if (this.visible == Visibility.Visible) {
this.visible = Visibility.None
} else {
this.visible = Visibility.Visible
}
})
.width('100%')
.height('100%')
// 透明度可以自己调节一下
.opacity(0.16)
.backgroundColor(0x000000)
.visibility(this.visible)
Column() {
// 这个可以调节对话框效果,栅格布局,xs,sm,md,lg分别为四种规格
// 下面的breakpoints是用来区别当前属于哪个类型的断点
// gridRow里的栅格数量为总数,gridCol里的就是偏移和假Dialog所占据的栅格数
GridRow({
columns:{xs:1 ,sm: 4, md: 8, lg: 12},
breakpoints: { value: ["400vp", "600vp", "800vp"],
reference: BreakpointsReference.WindowSize },
})
{
GridCol({
span:{xs:1 ,sm: 2, md: 4, lg: 8},
offset:{xs:0 ,sm: 1, md: 2, lg: 2}
}){
// 这里放的就是原Dialog里的column里的东西,稍微改改应该就可以用了
Column() {
Text('Change text').fontSize(20).margin({ top: 10, bottom: 10 })
TextInput({ placeholder: '', text: this.textValue }).height(60).width('90%')
.onChange((value: string) => {
this.textValue = value
})
Text('Whether to change a text?').fontSize(16).margin({ bottom: 10 })
Flex({ justifyContent: FlexAlign.SpaceAround }) {
Button('cancel')
.onClick(() => {
if (this.visible == Visibility.Visible) {
this.visible = Visibility.None
} else {
this.visible = Visibility.Visible
}
}).backgroundColor(0xffffff).fontColor(Color.Black)
Button('jump')
.onClick(() => {
router.pushUrl({
url: 'pages/Second'
})
}).backgroundColor(0xffffff).fontColor(Color.Red)
}.margin({ bottom: 10 })
}
.backgroundColor(0xffffff)
.visibility(this.visible)
.clip(true)
.borderRadius(20)
}
}
}.width('95%')//设置弹窗宽度
}
}
}
更多关于HarmonyOS 鸿蒙Next在半屏登录页面,隐私协议跳转异常的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html
针对HarmonyOS 鸿蒙Next在半屏登录页面隐私协议跳转异常的问题,以下是一些可能的解决方案:
- 检查路由配置:确保隐私协议页面已使用@Entry修饰,且路由配置正确。同时,跳转到hsp中的页面时,必须使用@bundle全路径。
- 验证参数传递:如果在跳转过程中传递了参数,请检查参数类型是否正确,并遵循HarmonyOS的传参规范。错误的参数类型或格式可能导致跳转失败。
- 检查白名单配置:确认是否已正确配置白名单,以允许从登录页面跳转到隐私协议页面。如果白名单配置有误,可能导致拦截合法的页面跳转请求。
- 异常处理:使用HarmonyOS提供的errorManager模块进行全局异常处理,及时捕获并上报异常信息,以便定位问题。
此外,还需确保鸿蒙系统、开发工具以及项目依赖都是最新版本,且配置正确。
如果问题依旧没法解决请联系官网客服,官网地址是:https://www.itying.com/category-93-b0.html 。