<template>
  <div>
    <p v-if="loading">正在跳转，请稍候...</p>
    <p v-if="error" class="error">{{ errorMessage }}</p>
  </div>
</template>

<script>
import axios from 'axios'

export default {
  data() {
    return {
      loading: true,
      error: false,
      errorMessage: ''
    }
  },
  created() {
    this.fetchCode()
  },
  methods: {
    async fetchCode() {
      try {
        // 替换为你的实际API地址
        const response = await axios.post('/userbasic/sso/getCode', {})
        const code = response.data.result
        if (code) {
          // 替换为你的目标外部链接，并确保参数名称正确
          const redirectUrl = `https://lexiangla.com?company_from=d1f3b156e9ed11ef9dc9720f77c5afa9&login_way=sso&sso_auth_code=${encodeURIComponent(code)}`
          window.location.href = redirectUrl
        } else {
          this.handleError('未获取到有效code')
        }
      } catch (error) {
        this.handleError(`请求失败: ${error.message}`)
      }
    },
    handleError(message) {
      this.loading = false
      this.error = true
      this.errorMessage = message
    }
  }
}
</script>

<style>
.error {
  color: red;
  font-weight: bold;
}
</style>
