730 Star 5.9K Fork 4.6K

若依 / RuoYi-App

 / 详情

登录过期,弹窗一个接着一个怎么办

已完成
创建于  
2023-03-31 09:10

如果登录过期了,我请求的接口有3个它会弹三次登录过期弹窗

评论 (11)

cc 创建了任务

我也遇到了这个问题 :persevere:

有解决了吗?

我的原因是因为启用了二级路径,但在后台中没有配置相应的路径引起的。
输入图片说明

应该不是这个问题吧, 三次接口都去请求后端,在request.js中如果都为401状态码则会这样

我用的是:uni.hideLoading(), 直接把所有弹窗关闭掉 :sweat_smile:

完整代码:
// 使用防抖函数控制弹窗的执行次数
debounce(() => {
isLoginExpiredDialogShown = true;
uni.hideLoading();
showConfirm('登录状态已过期,您可以继续留在该页面,或者重新登录?').then(res => {
if (res.confirm) {
isLoginExpiredDialogShown = false;
store.dispatch('LogOut').then(res => {
uni.redirectTo({
url: '/pages/login'
})
})
}
})
}, 500)();

// 防抖
function debounce(func, wait) {
let timeout;
return function () {
const context = this;
const args = arguments;
clearTimeout(timeout);
timeout = setTimeout(() => {
timeout = null;
func.apply(context, args);
}, wait);
};
}

老哥您好,我这边使用了你的代码后只在app端出现了异常,不知道该如何调试。
异常信息
[JS Framework] Failed to execute the callback function:[ERROR] : [JS Framework] Failed to execute the callback function:ReferenceError: Can't find variable: isLoginExpiredDialogShown __ERROR

测试了一下H5 和小程序,调用两个接口,清空缓存数据,登录过期只会弹出一个,没有你说的问题,

无法复现的问题,请提供具体的步骤和相关能复现问题的全部示例代码。

若依 任务状态待办的 修改为已完成

示例代码:

onLoad(){
    /** 
    * 此时每个请求都返回401
    * 此时这三个请求都到达 request.js中的 if(code === 401) 中
    * if(code === 401) 中的代码执行 三遍
    */
    this.demo1();
    this.demo2();
    this.demo3();
},
methods:{
    demo1(){
        request(...).then();
    },
    demo2(){
        request(...).then();
    },
    demo3(){
        request(...).then();
    }
}

我就是这么测试的,以个人中心为例,并没有出现三次,你可以提供真实复现示例代码出来看看。

<template>
  <view class="container">
    <uni-list>
      <uni-list-item showExtraIcon="true" :extraIcon="{type: 'person-filled'}" title="昵称" :rightText="user.nickName" />
      <uni-list-item showExtraIcon="true" :extraIcon="{type: 'phone-filled'}" title="手机号码" :rightText="user.phonenumber" />
      <uni-list-item showExtraIcon="true" :extraIcon="{type: 'email-filled'}" title="邮箱" :rightText="user.email" />
      <uni-list-item showExtraIcon="true" :extraIcon="{type: 'auth-filled'}" title="岗位" :rightText="postGroup" />
      <uni-list-item showExtraIcon="true" :extraIcon="{type: 'staff-filled'}" title="角色" :rightText="roleGroup" />
      <uni-list-item showExtraIcon="true" :extraIcon="{type: 'calendar-filled'}" title="创建日期" :rightText="user.createTime" />
    </uni-list>
  </view>
</template>

<script>
  import { getUserProfile } from "@/api/system/user"

  export default {
    data() {
      return {
        user: {},
        roleGroup: "",
        postGroup: ""
      }
    },
    onLoad() {
      this.getUser()
      this.getUser()
      this.getUser()
    },
    methods: {
      getUser() {
        getUserProfile().then(response => {
          this.user = response.data
          this.roleGroup = response.roleGroup
          this.postGroup = response.postGroup
        })
      }
    }
  }
</script>

<style lang="scss">
  page {
    background-color: #ffffff;
  }
</style>

在request.js中拦截到了401的话就会让你选择是否登出,选择了是的话,会去调用登出接口,但是登出接口也返回401的话就又会被request.js拦截,导致一直卡住

登录 后才可以发表评论

状态
负责人
里程碑
Pull Requests
关联的 Pull Requests 被合并后可能会关闭此 issue
分支
开始日期   -   截止日期
-
置顶选项
优先级
参与者(6)
9813640 zeng weitao 1657525265 1151004 y project 1578942802
Java
1
https://gitee.com/y_project/RuoYi-App.git
git@gitee.com:y_project/RuoYi-App.git
y_project
RuoYi-App
RuoYi-App

搜索帮助