¶Ô±ÈÐÂÎļþ |
| | |
| | | <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> |