refactor(frontend): merge authserver web login
This commit is contained in:
@@ -7,45 +7,11 @@
|
||||
xinfra
|
||||
</div>
|
||||
<h2>统一基础设施平台</h2>
|
||||
<p>LDAP 账号登录</p>
|
||||
<p>正在跳转到 SSO 登录</p>
|
||||
</div>
|
||||
<el-form
|
||||
ref="formRef"
|
||||
:model="form"
|
||||
:rules="rules"
|
||||
label-position="top"
|
||||
@submit.prevent="handleLogin"
|
||||
>
|
||||
<el-form-item label="用户名" prop="username">
|
||||
<el-input
|
||||
v-model="form.username"
|
||||
placeholder="请输入用户名"
|
||||
prefix-icon="User"
|
||||
size="large"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="密码" prop="password">
|
||||
<el-input
|
||||
v-model="form.password"
|
||||
type="password"
|
||||
placeholder="请输入密码"
|
||||
prefix-icon="Lock"
|
||||
size="large"
|
||||
show-password
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button
|
||||
type="primary"
|
||||
size="large"
|
||||
:loading="loading"
|
||||
@click="handleLogin"
|
||||
style="width: 100%"
|
||||
>
|
||||
登录
|
||||
</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<el-button type="primary" size="large" style="width: 100%" @click="redirectToSSO()">
|
||||
重新跳转
|
||||
</el-button>
|
||||
<div class="login-footer">
|
||||
<p>统一 LDAP 账号,同账号同密码</p>
|
||||
</div>
|
||||
@@ -54,42 +20,10 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, reactive } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { useAuth } from '@/composables/useAuth'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import type { FormInstance, FormRules } from 'element-plus'
|
||||
import { onMounted } from 'vue'
|
||||
import { redirectToSSO } from '@/utils/sso'
|
||||
|
||||
const router = useRouter()
|
||||
const { login } = useAuth()
|
||||
const formRef = ref<FormInstance>()
|
||||
const loading = ref(false)
|
||||
|
||||
const form = reactive({
|
||||
username: '',
|
||||
password: '',
|
||||
})
|
||||
|
||||
const rules: FormRules = {
|
||||
username: [{ required: true, message: '请输入用户名', trigger: 'blur' }],
|
||||
password: [{ required: true, message: '请输入密码', trigger: 'blur' }],
|
||||
}
|
||||
|
||||
const handleLogin = async () => {
|
||||
const valid = await formRef.value?.validate().catch(() => false)
|
||||
if (!valid) return
|
||||
|
||||
loading.value = true
|
||||
try {
|
||||
await login(form.username, form.password)
|
||||
ElMessage.success('登录成功')
|
||||
router.push('/')
|
||||
} catch {
|
||||
// 错误已由 request 拦截器统一处理
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
onMounted(() => redirectToSSO())
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
import { ref, onMounted } from 'vue'
|
||||
import { subsystemApi, type Subsystem } from '@/api/subsystem'
|
||||
import SubsystemCard from '@/components/SubsystemCard.vue'
|
||||
import { consumeOpenApp } from '@/utils/sso'
|
||||
|
||||
const subsystems = ref<Subsystem[]>([])
|
||||
|
||||
@@ -27,6 +28,15 @@ onMounted(async () => {
|
||||
try {
|
||||
const { data } = await subsystemApi.getSubsystems()
|
||||
subsystems.value = data
|
||||
const openApp = consumeOpenApp()
|
||||
if (openApp) {
|
||||
const targetName = openApp === 'clouddm' ? 'CloudDM' : 'Wayne'
|
||||
const target = data.find((item) => item.name === targetName)
|
||||
if (target) {
|
||||
const response = await subsystemApi.getSSOUrl(target.id)
|
||||
window.location.assign(response.data.sso_url)
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
// 错误已由 request 拦截器统一处理
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user