jekip / naive-ui-admin

Naive Ui Admin 是一款基于 Vue3、Vite3 和 TypeScript 的先进中后台解决方案,集成了前沿的前端技术栈和典型业务模型。它拥有二次封装组件、动态菜单、权限校验、粒子化权限控制等核心功能,旨在帮助企业快速构建高质量的中后台项目。无论在新技术运用或业务实践层面,都能为您提供有力支持,并将持续更新,以满足您不断变化的需求
https://naive-ui-admin.vercel.app
MIT License
5.04k stars 935 forks source link

登录切换为真实接口后,无法正常跳转 #274

Closed kimsmel closed 10 months ago

kimsmel commented 10 months ago

请看图,虽然是真实接口,但我返回结果已经完全设置成和要求的格式一致了,登录成功了却无法跳转,报路由错误,很奇怪

image
// 登录
    async login(params: any) {
      const response = await login(params);
      response.code = ResultEnum.SUCCESS
      response.result = {
        token: 'MKBMQTHUTWYWVPSEQNJNYNIWFDHOVSUD',
      };
      response.message = 'ok'
      response.type = 'success'
      delete response.data
      const { result, code } = response;
      if (code === ResultEnum.SUCCESS) {
        const ex = 7 * 24 * 60 * 60;
        storage.set(ACCESS_TOKEN, result.token, ex);
        storage.set(CURRENT_USER, result, ex);
        storage.set(IS_SCREENLOCKED, false);
        this.setToken(result.token);
        this.setUserInfo(result);
      }

      console.log(response, 1238)
      return response;
    }
try {
            const { code, message: msg } = await userStore.login(params);
            message.destroyAll();
            if (code == ResultEnum.SUCCESS) {
              const toPath = decodeURIComponent((route.query?.redirect || '/') as string);
              message.success('登录成功,即将进入系统');
              if (route.name == LOGIN_NAME) {
                router.replace('/');
              } else router.replace(toPath);
            } else {
              message.info(msg || '登录失败');
              storage.clear();
            }
          } catch (e) {
            console.log(e, 111);
          } finally {
            loading.value = false;
          }

麻烦作者帮忙分析下什么原因呢,由于这块文档没找到详细的,烦请赐教,谢谢

kimsmel commented 10 months ago

已找到原因,请求拦截器和响应拦截器中报错,打开console调试功能,就可以查到相应的报错了 VITE_DROP_CONSOLE