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 | 303 +++++++++++++++++++++++++++++++++++++++++---------
1 files changed, 247 insertions(+), 56 deletions(-)
diff --git a/src/views/loginSSO.vue b/src/views/loginSSO.vue
index 21f7317..d195a79 100644
--- a/src/views/loginSSO.vue
+++ b/src/views/loginSSO.vue
@@ -11,82 +11,229 @@
<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',
+ name: "SSORedirect",
data() {
return {
- errorMessage: '',
- loading: true
- }
+ errorMessage: "",
+ loading: true,
+ loadingDetail: "姝e湪澶勭悊SSO浠ょ墝...",
+ };
},
created() {
- this.handleSSORedirect()
+ this.handleSSORedirect();
},
methods: {
+ // 鍖归厤orgid - 浼樺寲涓哄璞℃槧灏�
+ mateOrgid(orgid) {
+ 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;
+ },
+
+ // 娓呯悊鏃х郴缁熺殑鏈湴瀛樺偍
+ 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 {
+ const roles = this.$store.state.user?.roles || [];
+ const username = this.$store.state.user?.name || "";
+
+ if (roles.includes("admin") || username === "admin") {
+ return "/index";
+ }
+ return "/followvisit/discharge";
+ } catch (error) {
+ console.warn("鑾峰彇榛樿閲嶅畾鍚戣矾寰勫け璐�:", error);
+ return "/followvisit/discharge";
+ }
+ },
+
+ // 楠岃瘉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 {
- // 浠嶶RL鍙傛暟涓幏鍙杢oken鍜屾満鏋勪俊鎭�
- const { token, orgid, orgname, ZuHuID, deptCode, redirect } = this.$route.query
+ console.log("SSO閲嶅畾鍚戝紑濮嬪鐞�...");
- // 楠岃瘉蹇呰鍙傛暟
- if (!token) {
- throw new Error('缂哄皯璁よ瘉浠ょ墝(token)')
- }
- setToken(token)
- this.$store.commit('SET_TOKEN', token)
+ // 1. 鑾峰彇URL鍙傛暟
+ const params = this.$route.query;
+ console.log("SSO鍙傛暟:", params);
- // 瀛樺偍鏈烘瀯淇℃伅鍒發ocalStorage
+ // 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) {
- 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)
+ // 浼樺厛浣跨敤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);
+ }
- // 鑾峰彇鐢ㄦ埛淇℃伅
- await this.$store.dispatch('GetInfo')
-
- // 纭畾閲嶅畾鍚戣矾寰�
- let redirectPath = '/index'
- if (redirect) {
- redirectPath = decodeURIComponent(redirect)
- } else {
- // 鏍规嵁鐢ㄦ埛瑙掕壊鍐冲畾榛樿璺宠浆椤甸潰
- 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'
+ localStorage.setItem("orgid", orgid);
+ if (this.$store.dispatch && typeof this.$store.dispatch === "function") {
+ await this.$store.dispatch("UpdateOrgId", orgid);
}
}
+ this.loadingDetail = "璁剧疆鏈烘瀯淇℃伅...";
- // 璺宠浆鍒扮洰鏍囬〉闈�
- this.$router.replace({ path: redirectPath })
+ // 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
+ 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(() => {
- this.$router.replace('/login')
- }, 5000)
+ this.$router.replace("/login");
+ }, 5000);
}
- }
- }
-}
+ },
+ },
+};
</script>
<style scoped>
@@ -95,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;
- color: #409EFF;
- margin-bottom: 10px;
+ font-size: 60px;
+ color: #409eff;
+ 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