Selaa lähdekoodia

fix: 修复redirectUri重定向逻辑错误

- 修复空字符串导致的重定向错误
- 修复重复的重定向判断逻辑
- 删除死代码
- 添加调试日志

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
hushuyu 6 kuukautta sitten
vanhempi
commit
350bd78742
1 muutettua tiedostoa jossa 18 lisäystä ja 19 poistoa
  1. 18 19
      src/views/AuthPage/components/AuthCard.vue

+ 18 - 19
src/views/AuthPage/components/AuthCard.vue

@@ -351,6 +351,9 @@ export default {
               // 2. Set redirect_uri cookie if 'from' exists
               if (from) {
                 document.cookie = `redirect_uri=${encodeURIComponent(from)}; path=/; max-age=300`;
+                console.log('设置redirect_uri cookie:', from);
+              } else {
+                console.log('URL中没有from参数');
               }
               const params = {
                 phone: this.cardForm.phone,
@@ -358,10 +361,15 @@ export default {
               };
               this.$apis.loginAPI(params)
                 .then((res) => {
+                  console.log('登录响应:', res.data.data);
                   if (res.data.code === 0) {
-                    if(res.data.data.redirectUri !== null){
+                    // 清理redirect_uri cookie
+                    setCookie({redirect_uri: ""}, -1);
+
+                    // 检查是否需要重定向
+                    if (res.data.data.redirectUri && res.data.data.redirectUri.trim() !== '') {
+                      console.log('准备重定向到:', res.data.data.redirectUri);
                       // 跳转到外部系统的home页面,并携带token
-                      console.log(res.data.data);
                       if(res.data.data.redirectUri === REQUEST_BASE_URL_EAI) {
                         window.location.href = `${res.data.data.redirectUri}/home?token=${encodeURIComponent(res.data.data.token)}`;
                       } else {
@@ -390,25 +398,16 @@ export default {
                       type: "success",
                       duration: 1000,
                     });
-                    
+
                     setTimeout(() => {
-                      if (!res.data.data.redirectUri) {
-                        if (this.$route.params.login_to) {
-                          this.$router.push(String(this.$route.params.login_to));
-                        } else {
-                          if(res.data.data.user.role === "ADMIN"){
-                            this.$router.push("/root");
-                          }else{
-                            this.$router.push("/portal");
-                          }
-                        }
+                      if (this.$route.params.login_to) {
+                        this.$router.push(String(this.$route.params.login_to));
                       } else {
-                        let p = new Promise(function (resolve, reject) {
-                          setCookie({redirect_uri: ""}, -1);
-                          resolve();
-                        }).then(r => {
-                          window.location.href = res.data.data.redirectUri + "?id_token=" + res.data.data.token;
-                        });
+                        if(res.data.data.user.role === "ADMIN"){
+                          this.$router.push("/root");
+                        }else{
+                          this.$router.push("/portal");
+                        }
                       }
                     }, 500);
                   } else {