<template>
|
<div class="sso-redirect">
|
<div class="loading-container">
|
<el-alert
|
v-if="errorMessage"
|
:title="errorMessage"
|
type="error"
|
:closable="false"
|
show-icon
|
></el-alert>
|
<div v-else class="loading-content">
|
<i class="el-icon-loading"></i>
|
<p>单点登录中,请稍候...</p>
|
</div>
|
</div>
|
</div>
|
</template>
|
|
<script>
|
import { setToken } from '@/utils/auth'
|
|
export default {
|
name: 'SSORedirect',
|
data() {
|
return {
|
errorMessage: '',
|
loading: true
|
}
|
},
|
created() {
|
this.handleSSORedirect()
|
},
|
methods: {
|
async handleSSORedirect() {
|
try {
|
// 从URL参数中获取token和机构信息
|
const { token, orgid, orgname, ZuHuID, deptCode, redirect } = this.$route.query
|
|
// 验证必要参数
|
if (!token) {
|
throw new Error('缺少认证令牌(token)')
|
}
|
setToken(token)
|
this.$store.commit('SET_TOKEN', token)
|
|
// 存储机构信息到localStorage
|
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) {
|
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'
|
}
|
}
|
|
// 跳转到目标页面
|
this.$router.replace({ path: redirectPath })
|
|
} catch (error) {
|
console.error('SSO登录失败:', error)
|
this.errorMessage = `单点登录失败: ${error.message || '未知错误'}`
|
this.loading = false
|
|
// 5秒后跳转到普通登录页
|
setTimeout(() => {
|
this.$router.replace('/login')
|
}, 5000)
|
}
|
}
|
}
|
}
|
</script>
|
|
<style scoped>
|
.sso-redirect {
|
display: flex;
|
justify-content: center;
|
align-items: center;
|
height: 100vh;
|
background-color: #f5f7fa;
|
}
|
|
.loading-container {
|
text-align: center;
|
padding: 20px;
|
background: white;
|
border-radius: 4px;
|
box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
|
}
|
|
.loading-content {
|
padding: 20px;
|
}
|
|
.el-icon-loading {
|
font-size: 40px;
|
color: #409EFF;
|
margin-bottom: 10px;
|
}
|
|
p {
|
margin: 0;
|
color: #606266;
|
}
|
</style>
|