| | |
| | | </template> |
| | | |
| | | <script> |
| | | import { setToken } from '@/utils/auth' |
| | | import { setToken } from "@/utils/auth"; |
| | | |
| | | export default { |
| | | name: 'SSORedirect', |
| | | name: "SSORedirect", |
| | | data() { |
| | | return { |
| | | errorMessage: '', |
| | | loading: true |
| | | } |
| | | errorMessage: "", |
| | | loading: true, |
| | | }; |
| | | }, |
| | | created() { |
| | | this.handleSSORedirect() |
| | | this.handleSSORedirect(); |
| | | }, |
| | | methods: { |
| | | // 匹配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", ""); |
| | | } |
| | | }, |
| | | async handleSSORedirect() { |
| | | try { |
| | | console.log(11); |
| | | // 从URL参数中获取token和机构信息 |
| | | const { token, orgid, orgname, ZuHuID, deptCode, redirect } = this.$route.query |
| | | |
| | | // 验证必要参数 |
| | | let { token, orgid, orgname, ZuHuID, deptCode, redirect } = |
| | | this.$route.query; |
| | | // token = |
| | | // "eyJhbGciOiJIUzUxMiJ9.eyJsb2dpbl91c2VyX2tleSI6Ijc5MWVkODNlLWE2MWYtNDI2MS05ZDZlLTNhOTVjYTU2YjZhMiJ9.q6jrRj8fwtb3FOqqwaxIFDr824hf85DW8heCj4qWYgRE55Pn0vkmcujFsYMrz9qqo047Gl7lv3rnok8pk7SKYQ"; // 验证必要参数 |
| | | // orgid = "30001002"; |
| | | if (!token) { |
| | | throw new Error('缺少认证令牌(token)') |
| | | throw new Error("缺少认证令牌(token)"); |
| | | } |
| | | setToken(token) |
| | | this.$store.commit('SET_TOKEN', token) |
| | | this.mateOrgid(orgid); |
| | | setToken(token); |
| | | this.$store.commit("SET_TOKEN", token); |
| | | |
| | | // 存储机构信息到localStorage |
| | | if (orgid) { |
| | | localStorage.setItem('orgid', orgid) |
| | | this.$store.dispatch('UpdateOrgId', 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) |
| | | if (orgname) localStorage.setItem("orgname", orgname); |
| | | if (ZuHuID) localStorage.setItem("ZuHuID", ZuHuID); |
| | | if (deptCode) localStorage.setItem("deptCode", deptCode); |
| | | |
| | | // 获取用户信息 |
| | | await this.$store.dispatch('GetInfo') |
| | | await this.$store.dispatch("GetInfo"); |
| | | |
| | | // 确定重定向路径 |
| | | let redirectPath = '/index' |
| | | let redirectPath = "/index"; |
| | | if (redirect) { |
| | | redirectPath = decodeURIComponent(redirect) |
| | | 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' |
| | | if (roles.includes("admin") || username === "admin") { |
| | | redirectPath = "/index"; |
| | | } else { |
| | | redirectPath = '/followvisit/discharge' |
| | | redirectPath = "/followvisit/discharge"; |
| | | } |
| | | } |
| | | |
| | | // 跳转到目标页面 |
| | | this.$router.replace({ path: redirectPath }) |
| | | |
| | | this.$router.replace({ path: redirectPath }); |
| | | } catch (error) { |
| | | console.error('SSO登录失败:', error) |
| | | this.errorMessage = `单点登录失败: ${error.message || '未知错误'}` |
| | | this.loading = false |
| | | console.error("SSO登录失败:", error); |
| | | this.errorMessage = `单点登录失败: ${error.message || "未知错误"}`; |
| | | this.loading = false; |
| | | |
| | | // 5秒后跳转到普通登录页 |
| | | setTimeout(() => { |
| | | this.$router.replace('/login') |
| | | }, 5000) |
| | | this.$router.replace("/login"); |
| | | }, 5000); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | }, |
| | | }; |
| | | </script> |
| | | |
| | | <style scoped> |
| | |
| | | |
| | | .el-icon-loading { |
| | | font-size: 40px; |
| | | color: #409EFF; |
| | | color: #409eff; |
| | | margin-bottom: 10px; |
| | | } |
| | | |