初始化
This commit is contained in:
commit
3a4e81a070
43 files changed
+10871
No files matched your search
@@ -0,0 +1,164 @@
|
||||
<template>
|
||||
<main class="login-screen" aria-labelledby="loginTitle">
|
||||
<div class="login-panel">
|
||||
<header class="login-brand">
|
||||
<span class="brand-mark" aria-hidden="true"><i></i><i></i></span>
|
||||
<span>
|
||||
<strong>零差云控</strong>
|
||||
<small>ZEROERR · 财务管理平台</small>
|
||||
</span>
|
||||
</header>
|
||||
|
||||
<div class="login-layout">
|
||||
<section class="login-copy" aria-describedby="loginIntro">
|
||||
<span class="eyebrow">FINANCE WORKSPACE</span>
|
||||
<h1 id="loginTitle">让每一笔报销,<br><b>清晰地走完全流程</b></h1>
|
||||
<p id="loginIntro">统一管理报销申请、审批进度与财务处理,让每一个环节都有据可查。</p>
|
||||
<div class="login-points" aria-label="平台能力">
|
||||
<span><b aria-hidden="true">01</b>申请与审批状态清晰可见</span>
|
||||
<span><b aria-hidden="true">02</b>收单与付款记录独立留痕</span>
|
||||
<span><b aria-hidden="true">03</b>企业统一身份认证,安全访问</span>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="login-card" aria-labelledby="loginCardTitle" aria-describedby="loginCardDescription">
|
||||
<div class="feishu-logo" aria-hidden="true">飞</div>
|
||||
<span class="eyebrow">AUTHORIZED ENTRY</span>
|
||||
<h2 id="loginCardTitle">使用飞书账号登录</h2>
|
||||
<p id="loginCardDescription">通过飞书授权验证身份后即可进入系统;通讯录同步用于员工资料与业务管理,不作为登录条件。每日首次访问需重新完成授权。</p>
|
||||
|
||||
<div v-if="loading" class="login-loading" role="status" aria-live="polite">
|
||||
<p>正在验证身份…</p>
|
||||
<small>{{ loadingMessage }}</small>
|
||||
</div>
|
||||
|
||||
<div v-else>
|
||||
<div v-if="loginError" class="inline-alert danger" role="alert">
|
||||
<b aria-hidden="true">!</b>
|
||||
<span>{{ loginError }}</span>
|
||||
</div>
|
||||
<button
|
||||
class="btn"
|
||||
type="button"
|
||||
:disabled="feishuLoading"
|
||||
:aria-busy="feishuLoading"
|
||||
@click="handleFeishuLogin"
|
||||
>
|
||||
{{ feishuLoading ? '正在前往飞书…' : '飞书授权登录' }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="login-card-foot">
|
||||
登录信息由飞书授权提供,本平台不单独维护登录密码
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<footer class="login-foot">企业财务工作台 · 飞书统一身份认证</footer>
|
||||
</div>
|
||||
</main>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { onMounted, ref } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { authApi } from '@/api/auth'
|
||||
import { useUserStore } from '@/store/user'
|
||||
import { useWorkbenchStore } from '@/store/workbench'
|
||||
|
||||
const router = useRouter()
|
||||
const route = useRoute()
|
||||
const userStore = useUserStore()
|
||||
const workbench = useWorkbenchStore()
|
||||
const feishuLoading = ref(false)
|
||||
const loading = ref(true)
|
||||
const loadingMessage = ref('')
|
||||
const loginError = ref('')
|
||||
|
||||
const handleFeishuLogin = async () => {
|
||||
const attempt = userStore.beginFeishuLogin()
|
||||
feishuLoading.value = true
|
||||
loginError.value = ''
|
||||
try {
|
||||
const response = await authApi.getAuthUrl()
|
||||
if (!response.authUrl) throw new Error('获取飞书授权地址失败')
|
||||
window.location.assign(response.authUrl)
|
||||
} catch (e: any) {
|
||||
// request.ts already reports HTTP/network failures; avoid duplicating those toasts.
|
||||
const message = e?.message === '获取飞书授权地址失败'
|
||||
? e.message
|
||||
: '暂时无法连接认证服务,请稍后重试'
|
||||
loginError.value = message
|
||||
if (e?.message === '获取飞书授权地址失败') ElMessage.error(e.message)
|
||||
userStore.clearFeishuLogin(attempt)
|
||||
} finally {
|
||||
feishuLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
const token = route.query.token as string | undefined
|
||||
const code = route.query.code as string | undefined
|
||||
const state = route.query.state as string | undefined
|
||||
const error = route.query.error as string | undefined
|
||||
|
||||
// Do not leave OAuth credentials or one-time codes in browser history.
|
||||
if (token || code || error) window.history.replaceState({}, document.title, window.location.pathname)
|
||||
|
||||
if (error) {
|
||||
const attempt = sessionStorage.getItem('feishuOAuthAttempt')
|
||||
if (!attempt || userStore.isCurrentFeishuLogin(attempt)) {
|
||||
userStore.logout()
|
||||
userStore.clearFeishuLogin(attempt)
|
||||
}
|
||||
workbench.reset()
|
||||
loading.value = false
|
||||
loginError.value = error
|
||||
ElMessage.error(error)
|
||||
return
|
||||
}
|
||||
|
||||
if (token) {
|
||||
loadingMessage.value = '正在获取用户信息…'
|
||||
try {
|
||||
// A token callback can follow an expired session or a different user.
|
||||
// Clear business data before loading the new identity to prevent data
|
||||
// from the previous session flashing in lists and notifications.
|
||||
workbench.reset()
|
||||
await userStore.setToken(token)
|
||||
ElMessage.success('登录成功')
|
||||
router.replace('/dashboard')
|
||||
} catch (e: any) {
|
||||
userStore.logout()
|
||||
workbench.reset()
|
||||
loading.value = false
|
||||
loginError.value = e?.message || '登录验证失败,请重新授权'
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if (code) {
|
||||
const attempt = sessionStorage.getItem('feishuOAuthAttempt')
|
||||
loadingMessage.value = '正在交换授权码…'
|
||||
try {
|
||||
workbench.reset()
|
||||
await userStore.feishuLogin(code, state, attempt || undefined)
|
||||
ElMessage.success('登录成功')
|
||||
await router.replace('/dashboard')
|
||||
} catch (e: any) {
|
||||
if (!attempt || userStore.isCurrentFeishuLogin(attempt)) {
|
||||
userStore.logout()
|
||||
userStore.clearFeishuLogin(attempt)
|
||||
}
|
||||
workbench.reset()
|
||||
loading.value = false
|
||||
loginError.value = e?.message || '登录失败,请重试'
|
||||
ElMessage.error(loginError.value)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
loading.value = false
|
||||
})
|
||||
</script>
|
||||