From e06cd3953ba8a6e0eee11c235bce9ced419a2800 Mon Sep 17 00:00:00 2001
From: WXL (wul) <wl_5969728@163.com>
Date: 星期三, 03 六月 2026 14:05:08 +0800
Subject: [PATCH] 测试完成

---
 src/views/loginSSO.vue |  316 +++++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 235 insertions(+), 81 deletions(-)

diff --git a/src/views/loginSSO.vue b/src/views/loginSSO.vue
index 6cd082c..d195a79 100644
--- a/src/views/loginSSO.vue
+++ b/src/views/loginSSO.vue
@@ -11,13 +11,14 @@
       <div v-else class="loading-content">
         <i class="el-icon-loading"></i>
         <p>鍗曠偣鐧诲綍涓紝璇风◢鍊�...</p>
+        <p class="loading-detail">{{ loadingDetail }}</p>
       </div>
     </div>
   </div>
 </template>
 
 <script>
-import { setToken } from "@/utils/auth";
+import { setToken, removeToken } from "@/utils/auth";
 
 export default {
   name: "SSORedirect",
@@ -25,96 +26,205 @@
     return {
       errorMessage: "",
       loading: true,
+      loadingDetail: "姝e湪澶勭悊SSO浠ょ墝...",
     };
   },
   created() {
     this.handleSSORedirect();
   },
   methods: {
-    // 鍖归厤orgid
+    // 鍖归厤orgid - 浼樺寲涓哄璞℃槧灏�
     mateOrgid(orgid) {
-      if (orgid == "30001002") {
-        localStorage.setItem("orgname", "娴欐睙鐪佺珛鍚屽痉鍖婚櫌缈犺嫅闄㈠尯");
-        localStorage.setItem("ZuHuID", "1400361376454545408");
-        localStorage.setItem("deptCode", "1017");
-      } else if (orgid == "30001003") {
-        localStorage.setItem("orgname", "娴欐睙鐪佺珛鍚屽痉鍖婚櫌涔嬫睙闄㈠尯");
-        localStorage.setItem("ZuHuID", "1400360867068907520");
-        localStorage.setItem("deptCode", "01040201");
-      } else if (orgid == "30001004") {
-        localStorage.setItem("orgname", "娴欐睙鐪佺珛鍚屽痉鍖婚櫌闂叉灄闄㈠尯");
-        localStorage.setItem("ZuHuID", "1429338802177000002");
-        localStorage.setItem("deptCode", "");
-      } else if (orgid == "30001005") {
-        localStorage.setItem("orgname", "娴欐睙鐪佺珛鍚屽痉鍖婚櫌澶╃洰灞辫矾闄㈠尯");
-        localStorage.setItem("ZuHuID", "1429338802177000003");
-        localStorage.setItem("deptCode", "");
-      } else if (orgid == "30001006") {
-        localStorage.setItem("orgname", "娴欐睙鐪佺珛鍚屽痉鍖婚櫌闈掑北婀栭櫌鍖�");
-        localStorage.setItem("ZuHuID", "1429338802177000004");
-        localStorage.setItem("deptCode", "");
-      } else if (orgid == "30001007") {
-        localStorage.setItem("orgname", "娴嬭瘯闄㈠尯");
-        localStorage.setItem("ZuHuID", "1429338802177000005");
-        localStorage.setItem("deptCode", "");
+      const orgMap = {
+        "30001002": {
+          orgname: "鐪佺珛鍚屽痉缈犺嫅闄㈠尯",
+          ZuHuID: "1400361376454545408",
+          deptCode: "1017",
+        },
+        "30001003": {
+          orgname: "鐪佺珛鍚屽痉涔嬫睙闄㈠尯",
+          ZuHuID: "1400360867068907520",
+          deptCode: "01040201",
+        },
+        "30001004": {
+          orgname: "鐪佺珛鍚屽痉闂叉灄闄㈠尯",
+          ZuHuID: "1429338802177000002",
+          deptCode: "",
+        },
+        "30001005": {
+          orgname: "鐪佺珛鍚屽痉澶╃洰灞辫矾闄㈠尯",
+          ZuHuID: "1429338802177000003",
+          deptCode: "",
+        },
+        "30001006": {
+          orgname: "鐪佺珛鍚屽痉闈掑北婀栭櫌鍖�",
+          ZuHuID: "1429338802177000004",
+          deptCode: "",
+        },
+        "30001007": {
+          orgname: "娴嬭瘯闄㈠尯",
+          ZuHuID: "1429338802177000005",
+          deptCode: "",
+        },
+      };
+
+      const orgInfo = orgMap[orgid];
+      if (orgInfo) {
+        localStorage.setItem("orgname", orgInfo.orgname);
+        localStorage.setItem("ZuHuID", orgInfo.ZuHuID);
+        localStorage.setItem("deptCode", orgInfo.deptCode);
+        return orgInfo;
       }
+      return null;
     },
-    async handleSSORedirect() {
+
+    // 娓呯悊鏃х郴缁熺殑鏈湴瀛樺偍
+    clearOldSystemData() {
+      // 娓呯悊鍙兘鍐茬獊鐨勬棫绯荤粺鏁版嵁
+      const oldKeys = ["old-token", "old-user-info", "old-session"];
+      oldKeys.forEach((key) => {
+        localStorage.removeItem(key);
+        sessionStorage.removeItem(key);
+      });
+
+      // 娓呯悊鐗瑰畾鍓嶇紑鐨勫瓨鍌�
+      Object.keys(localStorage).forEach((key) => {
+        if (key.startsWith("old-system-") || key.startsWith("legacy-")) {
+          localStorage.removeItem(key);
+        }
+      });
+    },
+
+    // 鑾峰彇榛樿閲嶅畾鍚戣矾寰�
+    getDefaultRedirectPath() {
       try {
-        console.log(11);
-        // 浠嶶RL鍙傛暟涓幏鍙杢oken鍜屾満鏋勪俊鎭�
-        let { token, orgid, orgname, ZuHuID, deptCode } = this.$route.query;
-        // token =
-        //   "eyJhbGciOiJIUzUxMiJ9.eyJsb2dpbl91c2VyX2tleSI6Ijc5MWVkODNlLWE2MWYtNDI2MS05ZDZlLTNhOTVjYTU2YjZhMiJ9.q6jrRj8fwtb3FOqqwaxIFDr824hf85DW8heCj4qWYgRE55Pn0vkmcujFsYMrz9qqo047Gl7lv3rnok8pk7SKYQ"; // 楠岃瘉蹇呰鍙傛暟
-        // orgid = "30001002";
-        if (!token) {
-          throw new Error("缂哄皯璁よ瘉浠ょ墝(token)");
-        }
-        console.log(token);
-        console.log(orgid);
-        console.log(orgname);
-        // console.log(redirect,'redirect');
-
-        this.mateOrgid(orgid);
-        setToken(token);
-        this.$store.commit("SET_TOKEN", token);
-
-        // 瀛樺偍鏈烘瀯淇℃伅鍒發ocalStorage
-        if (orgid) {
-          localStorage.setItem("orgid", orgid);
-          this.$store.dispatch("UpdateOrgId", orgid);
-        }
-        if (orgname) localStorage.setItem("orgname", orgname);
-        if (ZuHuID) localStorage.setItem("ZuHuID", ZuHuID);
-        if (deptCode) localStorage.setItem("deptCode", deptCode);
-
-        // 鑾峰彇鐢ㄦ埛淇℃伅
-        await this.$store.dispatch("GetInfo");
-
-        // 纭畾閲嶅畾鍚戣矾寰�
-        let redirectPath = "/index";
-        // if (redirect) {
-        //   console.log(redirect,'888');
-
-        //   redirectPath = decodeURIComponent(redirect);
-        // } else {
-        // 鏍规嵁鐢ㄦ埛瑙掕壊鍐冲畾榛樿璺宠浆椤甸潰
-        const roles = this.$store.state.user.roles;
-        const username = this.$store.state.user.name;
+        const roles = this.$store.state.user?.roles || [];
+        const username = this.$store.state.user?.name || "";
 
         if (roles.includes("admin") || username === "admin") {
-          redirectPath = "/index";
-        } else {
-          redirectPath = "/followvisit/discharge";
+          return "/index";
         }
-        // }
+        return "/followvisit/discharge";
+      } catch (error) {
+        console.warn("鑾峰彇榛樿閲嶅畾鍚戣矾寰勫け璐�:", error);
+        return "/followvisit/discharge";
+      }
+    },
 
-        // 璺宠浆鍒扮洰鏍囬〉闈�
-        this.$router.replace({ path: redirectPath });
+    // 楠岃瘉SSO鍙傛暟
+    validateSSOParams(params) {
+      const { token, orgid } = params;
+
+      if (!token) {
+        throw new Error("缂哄皯璁よ瘉浠ょ墝(token)");
+      }
+
+      if (!orgid) {
+        console.warn("SSO鐧诲綍缂哄皯orgid鍙傛暟");
+      }
+
+      // 楠岃瘉token鏍煎紡锛堢畝鍗曢獙璇侊級
+      if (token.length < 10) {
+        throw new Error("浠ょ墝鏍煎紡鏃犳晥");
+      }
+
+      return true;
+    },
+
+    // 涓诲鐞嗗嚱鏁�
+    async handleSSORedirect() {
+      try {
+        console.log("SSO閲嶅畾鍚戝紑濮嬪鐞�...");
+
+        // 1. 鑾峰彇URL鍙傛暟
+        const params = this.$route.query;
+        console.log("SSO鍙傛暟:", params);
+
+        // 2. 楠岃瘉蹇呰鍙傛暟
+        this.validateSSOParams(params);
+        this.loadingDetail = "楠岃瘉浠ょ墝涓�...";
+
+        // 3. 娓呯悊鏃х郴缁熸暟鎹�
+        this.clearOldSystemData();
+
+        const { token, orgid, orgname, ZuHuID, deptCode, redirect } = params;
+
+        // 4. 瀛樺偍token
+        setToken(token);
+        this.$store.commit("SET_TOKEN", token);
+        this.loadingDetail = "璁剧疆鐢ㄦ埛浠ょ墝...";
+
+        // 5. 澶勭悊鏈烘瀯淇℃伅
+        if (orgid) {
+          // 浼樺厛浣跨敤mateOrgid鏄犲皠
+          const orgInfo = this.mateOrgid(orgid);
+          if (!orgInfo) {
+            // 濡傛灉娌℃湁鏄犲皠锛屼娇鐢ㄤ紶鍏ョ殑鍙傛暟
+            if (orgname) localStorage.setItem("orgname", orgname);
+            if (ZuHuID) localStorage.setItem("ZuHuID", ZuHuID);
+            if (deptCode) localStorage.setItem("deptCode", deptCode);
+          }
+
+          localStorage.setItem("orgid", orgid);
+          if (this.$store.dispatch && typeof this.$store.dispatch === "function") {
+            await this.$store.dispatch("UpdateOrgId", orgid);
+          }
+        }
+        this.loadingDetail = "璁剧疆鏈烘瀯淇℃伅...";
+
+        // 6. 鑾峰彇鐢ㄦ埛淇℃伅
+        if (this.$store.dispatch && typeof this.$store.dispatch === "function") {
+          await this.$store.dispatch("GetInfo");
+        }
+        this.loadingDetail = "鑾峰彇鐢ㄦ埛淇℃伅...";
+
+        // 7. 澶勭悊閲嶅畾鍚戣矾寰�
+        let redirectPath = "/followvisit/discharge";
+
+        if (redirect) {
+          // 瑙g爜浼犲叆鐨勯噸瀹氬悜璺緞
+          try {
+            redirectPath = decodeURIComponent(redirect);
+            console.log("浣跨敤浼犲叆鐨勯噸瀹氬悜璺緞:", redirectPath);
+          } catch (e) {
+            console.error("瑙g爜閲嶅畾鍚戣矾寰勫け璐�:", e);
+            redirectPath = this.getDefaultRedirectPath();
+          }
+        } else {
+          redirectPath = this.getDefaultRedirectPath();
+        }
+
+        // 8. 绉婚櫎URL涓殑token鍙傛暟锛堝畨鍏ㄨ�冭檻锛�
+        this.$router.replace({ query: {} });
+
+        // 9. 寤惰繜璺宠浆锛岀‘淇濈姸鎬佸凡鏇存柊
+        setTimeout(() => {
+          this.loadingDetail = "璺宠浆鍒扮洰鏍囬〉闈�...";
+          console.log("鍑嗗璺宠浆鍒�:", redirectPath);
+
+          // 鉁� 浣跨敤 push 鑰屼笉鏄� replace锛屼繚鐣欏巻鍙茶褰�
+          this.$router.push({ path: redirectPath }).then(() => {
+            console.log("SSO鐧诲綍鎴愬姛锛岃烦杞畬鎴�");
+          }).catch((error) => {
+            console.error("璺敱璺宠浆澶辫触:", error);
+            // 鍥為��鍒伴粯璁ら〉闈�
+            this.$router.push({ path: "/followvisit/discharge" });
+          });
+        }, 500);
+
       } catch (error) {
         console.error("SSO鐧诲綍澶辫触:", error);
         this.errorMessage = `鍗曠偣鐧诲綍澶辫触: ${error.message || "鏈煡閿欒"}`;
         this.loading = false;
+
+        // 娓呯悊token
+        removeToken();
+        this.$store.commit("SET_TOKEN", "");
+
+        // 鏄剧ず閿欒璇︽儏锛堝紑鍙戠幆澧冿級
+        if (process.env.NODE_ENV === "development") {
+          this.errorMessage += ` (璇︽儏: ${error.toString()})`;
+        }
 
         // 5绉掑悗璺宠浆鍒版櫘閫氱櫥褰曢〉
         setTimeout(() => {
@@ -132,29 +242,73 @@
   justify-content: center;
   align-items: center;
   height: 100vh;
+  min-height: 500px;
+  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
   background-color: #f5f7fa;
+  padding: 20px;
+  box-sizing: border-box;
 }
 
 .loading-container {
   text-align: center;
-  padding: 20px;
-  background: white;
-  border-radius: 4px;
-  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
+  padding: 40px 60px;
+  background: rgba(255, 255, 255, 0.95);
+  border-radius: 12px;
+  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
+  min-width: 400px;
+  max-width: 500px;
+  backdrop-filter: blur(10px);
+  border: 1px solid rgba(255, 255, 255, 0.2);
 }
 
 .loading-content {
-  padding: 20px;
+  padding: 30px 20px;
 }
 
 .el-icon-loading {
-  font-size: 40px;
+  font-size: 60px;
   color: #409eff;
-  margin-bottom: 10px;
+  margin-bottom: 20px;
+  animation: spin 1.5s linear infinite;
 }
 
-p {
+@keyframes spin {
+  0% { transform: rotate(0deg); }
+  100% { transform: rotate(360deg); }
+}
+
+.loading-content p {
   margin: 0;
   color: #606266;
+  font-size: 16px;
+  line-height: 1.6;
+}
+
+.loading-detail {
+  margin-top: 10px !important;
+  font-size: 14px !important;
+  color: #909399 !important;
+  opacity: 0.8;
+}
+
+/* 鍝嶅簲寮忚璁� */
+@media (max-width: 768px) {
+  .sso-redirect {
+    padding: 10px;
+  }
+
+  .loading-container {
+    padding: 30px 20px;
+    min-width: 300px;
+    max-width: 90vw;
+  }
+
+  .el-icon-loading {
+    font-size: 50px;
+  }
+
+  .loading-content p {
+    font-size: 15px;
+  }
 }
 </style>

--
Gitblit v1.9.3