helloheil
helloheil
  • 发布:2022-12-13 10:27
  • 更新:2023-06-30 09:13
  • 阅读:635

【报Bug】登录拦截重定向到登录页面,底部tabbar不隐藏

分类:uni-app

产品分类: uniapp/App

PC开发环境操作系统: Mac

PC开发环境操作系统版本号: 12.4 (21F79)

HBuilderX类型: 正式

HBuilderX版本号: 3.6.13

手机系统: Android

手机系统版本号: Android 8.1

手机厂商: 小米

手机机型: 小米手机MI 5X

页面类型: vue

vue版本: vue2

打包方式: 云端

项目创建方式: HBuilderX

示例代码:
登录拦截代码  
const whiteList = [  
    '/pages/login/login'  
];  
const list = ['navigateTo', 'redirectTo', 'reLaunch', 'switchTab'];  

/**  
 * 是否允许访问  
 * @param url  
 * @returns {boolean}  
 */  
const hasPermission = (url) => {  
    if (whiteList.indexOf(url) > -1 || Store.getters.token) {  
      return true;  
    }  
    return false;  
}  

list.forEach(item => {  
  uni.addInterceptor(item, {  
      invoke: (e) => {  
        console.log('陆游路径', e);  
        if (!hasPermission(e.url)) {  
            // 将用户的目标路径保存下来  
            // 这样可以实现 用户登录之后,直接跳转到目标页面  
            uni.setStorageSync("URL", e.url)  
            uni.navigateTo({  
                url: "/pages/login/login",  
                success: res => {  
                  uni.hideTabBar();  
                }  
            });  
            return false;  
        }  
        return true;  
      }  
  });  
});  
pages.json设置如下:  
"pages": [  
    {  
      "path": "pages/index/index",  
      "style": {  
        "navigationBarBackgroundColor": "#006dfe",  
        "navigationBarTextStyle": "white",  
        "navigationBarTitleText": "首页",  
        "enablePullDownRefresh": false  
      }  
    },  
    {  
      "path": "pages/user/user",  
      "style": {  
        "navigationBarTitleText": "我的",  
        "navigationBarBackgroundColor": "#006dfe",  
        "navigationBarTextStyle": "white",  
        "enablePullDownRefresh": false  
      }  
    },  
    {  
      "path": "pages/login/login",  
      "style": {  
        "navigationBarTitleText": "登录",  
        "navigationBarBackgroundColor": "#006dfe",  
        "navigationBarTextStyle": "white",  
        "navigationStyle": "custom",  
        "enablePullDownRefresh": false  
      }  
    }  
  ]

操作步骤:

未登录的情况下打开app(即token不存在),app在跳转到首页的过程中被重定向到login页面,但是此时底部首页的tabbar没有隐藏

预期结果:

未登录重定向到login页面的时候,首页tabbar隐藏

实际结果:

未登录重定向到login页面的时候,首页tabba未隐藏

bug描述:

通过拦截器定义uni跳转方式,实现未登录拦截跳转到登录页面。重定向到登录页面后首页底部tabbar还存在。
在跳转过程中,或者在login页面使用uni.hideTabBar()也无效

2022-12-13 10:27 负责人:无 分享
已邀请:
FullStack

FullStack - 【插件开发】【专治疑难杂症】【ios上架、马甲包、白包、过审、已成功上架过几百个】【多款插件已上架:https://ext.dcloud.net.cn/publisher?id=22130】【非诚勿扰】QQ:543610866

跳转之后,再隐藏看看,在login写

加个fail失败回调,看什么原因

  • helloheil (作者)

    hideTabBar:fail not TabBar page

    这个hideTabBar只能在tabBar页面使用qvq

    关键是重定向到login页面的时候tabbar他又不自己隐藏,无解吗?

    2022-12-13 11:07

  • 2***@qq.com

    回复 helloheil: 您好 请问您是怎么解决的

    2024-04-19 12:57

小脑斧

小脑斧

这个原因是首次启动app的时候,虽然先跳转到了pages/index/index页面,但是index页面并没有渲染(跳转太快了,可以在index页面上加个onload就知道了,onload并不会执行),然后就跳转到login页面了,此时tabbar就会被误挂载到login页面上了。目前解决方案就是在判断跳转前加一个settimeout,让index先执行到onload,tabbar就会挂载到index页面了,login页面就不会出现tabbar了。
uni.addInterceptor(item, {
invoke(to) {
setTimeout(() => {
////执行判断token是否有效&跳转页面代码
}, 50)
},
fail(err) {
console.log(err)
}
})

该问题目前已经被锁定, 无法添加新回复