Files
panel_admin/src/views/auth/feishu-callback.vue
T
2025-11-19 18:01:09 +08:00

60 lines
1.7 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<template>
<div class="feishu-callback">
<div v-if="loading">正在登录,请稍候...</div>
<div v-else-if="error">{{ error }}</div>
<div v-else>登录成功,正在跳转...</div>
</div>
</template>
<script setup lang="ts">
import { onMounted, ref } from 'vue'
import { useRouter } from 'vue-router'
import { useUserStore } from '@/store/modules/user'
import { UserService } from '@/api/usersApi'
const loading = ref(true)
const error = ref('')
const userStore = useUserStore()
const router = useRouter()
onMounted(async () => {
const urlParams = new URLSearchParams(window.location.search)
const code = urlParams.get('code')
const state = urlParams.get('state')
if (!code) {
error.value = '未获取到飞书授权 code'
loading.value = false
return
}
try {
// 调用后端接口换 token,接口路径请根据实际情况调整
const { data } = await UserService.login({
feishu_code: code
})
// 存储token和用户信息
userStore.setToken(data.access_token, data.refresh_token, data.expires_in)
const userInfo = await UserService.getUserInfo()
userStore.setUserInfo(userInfo)
userStore.setLoginStatus(true)
userStore.sethome_page(data.home_url)
localStorage.setItem('home_page', data.home_url)
router.push(data.home_url)
// router.replace('/')
} catch (e: any) {
error.value = e?.response?.data?.message || '登录失败,请重试'
router.replace('/')
} finally {
loading.value = false
}
})
</script>
<style scoped>
.feishu-callback {
min-height: 200px;
display: flex;
align-items: center;
justify-content: center;
font-size: 18px;
color: #333;
}
</style>