WXL (wul)
2 天以前 4c44ccbdcbe25de7dc0725bf53f1290fba10edf7
测试完成
已添加1个文件
已修改1个文件
127 ■■■■■ 文件已修改
src/views/loginSSO.vue 123 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
vue.config.js 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/loginSSO.vue
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,123 @@
<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>
vue.config.js
@@ -38,8 +38,8 @@
        // target: `https://www.health-y.cn/lssf`,
        // target: `http://10.202.20.185:8095`,
        // target: `http://192.168.100.195:8095`,
        // target:`http://localhost:8095`,
        target:`http://35z1t16164.qicp.vip`,
        target:`http://localhost:8095`,
        // target:`http://35z1t16164.qicp.vip`,
        // target: `http://192.168.100.193:8095`,
        // target: `http://192.168.101.166:8093`,
        // target: `http://192.168.191.181:8095`,