2026-06-14 16:49:18 +08:00
|
|
|
|
<!--
|
|
|
|
|
|
=============================================================================
|
2026-07-04 21:01:39 +08:00
|
|
|
|
IT智能服务台 — 管理员登录页 (v1.1, 2026-07-04)
|
2026-06-14 16:49:18 +08:00
|
|
|
|
=============================================================================
|
2026-07-04 21:01:39 +08:00
|
|
|
|
说明:从用户ID+姓名登录改为账号密码+OTP表单登录
|
2026-06-14 16:49:18 +08:00
|
|
|
|
- 复用坐席端登录 API(POST /api/agents/login)
|
|
|
|
|
|
- 登录后检查 role === 'admin',非 admin 提示"无管理权限"
|
2026-07-04 21:01:39 +08:00
|
|
|
|
- 支持账号密码+OTP认证
|
2026-06-14 16:49:18 +08:00
|
|
|
|
-->
|
|
|
|
|
|
<template>
|
|
|
|
|
|
<div class="login-page">
|
|
|
|
|
|
<!-- 背景装饰 -->
|
|
|
|
|
|
<div class="login-bg">
|
|
|
|
|
|
<div class="login-bg-gradient"></div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<!-- 登录卡片 -->
|
|
|
|
|
|
<div class="login-card">
|
|
|
|
|
|
<!-- Logo -->
|
|
|
|
|
|
<div class="login-logo">
|
|
|
|
|
|
<div class="login-logo-icon">
|
|
|
|
|
|
<el-icon :size="28"><Headset /></el-icon>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<h1 class="login-title">IT智能服务台</h1>
|
|
|
|
|
|
<p class="login-subtitle">管理后台</p>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<!-- 登录表单 -->
|
|
|
|
|
|
<el-form
|
|
|
|
|
|
ref="formRef"
|
|
|
|
|
|
:model="loginForm"
|
|
|
|
|
|
:rules="rules"
|
|
|
|
|
|
label-position="top"
|
|
|
|
|
|
@submit.prevent="handleLogin"
|
|
|
|
|
|
>
|
2026-07-04 21:01:39 +08:00
|
|
|
|
<el-form-item label="账号" prop="userId">
|
2026-06-14 16:49:18 +08:00
|
|
|
|
<el-input
|
|
|
|
|
|
v-model="loginForm.userId"
|
2026-07-04 21:01:39 +08:00
|
|
|
|
placeholder="请输入账号(如 sxn)"
|
2026-06-14 16:49:18 +08:00
|
|
|
|
size="large"
|
|
|
|
|
|
:prefix-icon="User"
|
|
|
|
|
|
@keydown.enter="handleLogin"
|
|
|
|
|
|
/>
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
|
2026-07-04 21:01:39 +08:00
|
|
|
|
<el-form-item label="密码" prop="password">
|
2026-06-14 16:49:18 +08:00
|
|
|
|
<el-input
|
2026-07-04 21:01:39 +08:00
|
|
|
|
v-model="loginForm.password"
|
|
|
|
|
|
type="password"
|
|
|
|
|
|
placeholder="请输入密码"
|
2026-06-14 16:49:18 +08:00
|
|
|
|
size="large"
|
2026-07-04 21:01:39 +08:00
|
|
|
|
:prefix-icon="Lock"
|
|
|
|
|
|
show-password
|
|
|
|
|
|
@keydown.enter="handleLogin"
|
|
|
|
|
|
/>
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
|
|
|
|
|
|
<!-- OTP 输入区: 仅在 requireOtp 时显示 -->
|
|
|
|
|
|
<el-form-item v-if="requireOtp" label="OTP 验证码" prop="otpCode">
|
|
|
|
|
|
<el-input
|
|
|
|
|
|
v-model="loginForm.otpCode"
|
|
|
|
|
|
placeholder="请输入 Google Authenticator 验证码"
|
|
|
|
|
|
size="large"
|
|
|
|
|
|
:prefix-icon="Key"
|
|
|
|
|
|
maxlength="6"
|
2026-06-14 16:49:18 +08:00
|
|
|
|
@keydown.enter="handleLogin"
|
|
|
|
|
|
/>
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
|
|
|
|
|
|
<el-form-item>
|
|
|
|
|
|
<el-button
|
|
|
|
|
|
type="primary"
|
|
|
|
|
|
size="large"
|
|
|
|
|
|
:loading="adminStore.logging"
|
|
|
|
|
|
:disabled="adminStore.logging"
|
|
|
|
|
|
@click="handleLogin"
|
|
|
|
|
|
class="login-btn"
|
|
|
|
|
|
>
|
2026-07-04 21:01:39 +08:00
|
|
|
|
{{ adminStore.logging ? '登录中...' : (requireOtp ? '验证 OTP' : '登录管理后台') }}
|
2026-06-14 16:49:18 +08:00
|
|
|
|
</el-button>
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
</el-form>
|
|
|
|
|
|
|
|
|
|
|
|
<!-- 错误提示 -->
|
|
|
|
|
|
<el-alert
|
|
|
|
|
|
v-if="errorMsg"
|
|
|
|
|
|
:title="errorMsg"
|
|
|
|
|
|
type="error"
|
|
|
|
|
|
show-icon
|
|
|
|
|
|
:closable="true"
|
|
|
|
|
|
@close="errorMsg = ''"
|
|
|
|
|
|
style="margin-top: 16px"
|
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
|
|
<!-- 提示信息 -->
|
|
|
|
|
|
<div class="login-tips">
|
|
|
|
|
|
<el-icon :size="14"><InfoFilled /></el-icon>
|
|
|
|
|
|
<span>仅限组长(admin角色)登录管理后台</span>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
|
|
|
|
|
// ==========================================================================
|
|
|
|
|
|
// 依赖导入
|
|
|
|
|
|
// ==========================================================================
|
|
|
|
|
|
import { ref, reactive } from 'vue'
|
2026-07-04 21:01:39 +08:00
|
|
|
|
import { useRouter } from 'vue-router'
|
|
|
|
|
|
import { ElMessage } from 'element-plus'
|
2026-06-14 16:49:18 +08:00
|
|
|
|
import { useAdminStore } from '@/stores/admin'
|
|
|
|
|
|
import type { FormInstance, FormRules } from 'element-plus'
|
2026-07-04 21:01:39 +08:00
|
|
|
|
import { User, Lock, Key, InfoFilled, Headset } from '@element-plus/icons-vue'
|
2026-06-14 16:49:18 +08:00
|
|
|
|
|
|
|
|
|
|
// ==========================================================================
|
|
|
|
|
|
// Store
|
|
|
|
|
|
// ==========================================================================
|
2026-07-04 21:01:39 +08:00
|
|
|
|
const router = useRouter()
|
2026-06-14 16:49:18 +08:00
|
|
|
|
const adminStore = useAdminStore()
|
|
|
|
|
|
|
|
|
|
|
|
// ==========================================================================
|
|
|
|
|
|
// 表单状态
|
|
|
|
|
|
// ==========================================================================
|
|
|
|
|
|
|
|
|
|
|
|
/** 表单引用 */
|
|
|
|
|
|
const formRef = ref<FormInstance>()
|
|
|
|
|
|
|
|
|
|
|
|
/** 登录表单数据 */
|
|
|
|
|
|
const loginForm = reactive({
|
|
|
|
|
|
userId: '',
|
2026-07-04 21:01:39 +08:00
|
|
|
|
password: '',
|
|
|
|
|
|
otpCode: '',
|
2026-06-14 16:49:18 +08:00
|
|
|
|
})
|
|
|
|
|
|
|
2026-07-04 21:01:39 +08:00
|
|
|
|
/** 是否需要 OTP 验证 */
|
|
|
|
|
|
const requireOtp = ref(false)
|
|
|
|
|
|
|
|
|
|
|
|
/** 错误信息 */
|
|
|
|
|
|
const errorMsg = ref<string>('')
|
|
|
|
|
|
|
2026-06-14 16:49:18 +08:00
|
|
|
|
/** 表单校验规则 */
|
|
|
|
|
|
const rules: FormRules = {
|
|
|
|
|
|
userId: [
|
2026-07-04 21:01:39 +08:00
|
|
|
|
{ required: true, message: '请输入账号', trigger: 'blur' },
|
2026-06-14 16:49:18 +08:00
|
|
|
|
],
|
2026-07-04 21:01:39 +08:00
|
|
|
|
password: [
|
|
|
|
|
|
{ required: true, message: '请输入密码', trigger: 'blur' },
|
|
|
|
|
|
],
|
|
|
|
|
|
otpCode: [
|
|
|
|
|
|
{ required: true, message: '请输入 OTP 验证码', trigger: 'blur' },
|
|
|
|
|
|
{ len: 6, message: '验证码为 6 位数字', trigger: 'blur' },
|
2026-06-14 16:49:18 +08:00
|
|
|
|
],
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ==========================================================================
|
|
|
|
|
|
// 方法
|
|
|
|
|
|
// ==========================================================================
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 处理登录
|
|
|
|
|
|
*/
|
|
|
|
|
|
async function handleLogin(): Promise<void> {
|
|
|
|
|
|
// 表单校验
|
|
|
|
|
|
const valid = await formRef.value?.validate().catch(() => false)
|
|
|
|
|
|
if (!valid) return
|
|
|
|
|
|
|
|
|
|
|
|
errorMsg.value = ''
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
2026-07-04 21:01:39 +08:00
|
|
|
|
await adminStore.login(
|
|
|
|
|
|
loginForm.userId.trim(),
|
|
|
|
|
|
loginForm.password,
|
|
|
|
|
|
loginForm.otpCode.trim() || undefined
|
|
|
|
|
|
)
|
2026-06-14 16:49:18 +08:00
|
|
|
|
} catch (error: unknown) {
|
2026-07-04 21:01:39 +08:00
|
|
|
|
// 检查是否需要 OTP 验证
|
|
|
|
|
|
if (error instanceof Error && error.message === 'require_otp') {
|
|
|
|
|
|
requireOtp.value = true
|
|
|
|
|
|
loginForm.otpCode = ''
|
|
|
|
|
|
ElMessage.info('请输入 OTP 验证码')
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-06-14 16:49:18 +08:00
|
|
|
|
const errMsg = error instanceof Error ? error.message : '登录失败,请重试'
|
|
|
|
|
|
errorMsg.value = errMsg
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
|
|
/* 登录页面容器 */
|
|
|
|
|
|
.login-page {
|
|
|
|
|
|
min-height: 100vh;
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
justify-content: center;
|
|
|
|
|
|
position: relative;
|
|
|
|
|
|
background: var(--bg-primary);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* 背景装饰 */
|
|
|
|
|
|
.login-bg {
|
|
|
|
|
|
position: absolute;
|
|
|
|
|
|
inset: 0;
|
|
|
|
|
|
overflow: hidden;
|
|
|
|
|
|
}
|
|
|
|
|
|
.login-bg-gradient {
|
|
|
|
|
|
position: absolute;
|
|
|
|
|
|
top: -50%;
|
|
|
|
|
|
left: -50%;
|
|
|
|
|
|
width: 200%;
|
|
|
|
|
|
height: 200%;
|
|
|
|
|
|
background: radial-gradient(ellipse at center, rgba(59, 130, 246, 0.08) 0%, transparent 60%);
|
|
|
|
|
|
animation: rotate 30s linear infinite;
|
|
|
|
|
|
}
|
|
|
|
|
|
@keyframes rotate {
|
|
|
|
|
|
from { transform: rotate(0deg); }
|
|
|
|
|
|
to { transform: rotate(360deg); }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* 登录卡片 */
|
|
|
|
|
|
.login-card {
|
|
|
|
|
|
position: relative;
|
|
|
|
|
|
z-index: 1;
|
|
|
|
|
|
width: 400px;
|
|
|
|
|
|
padding: 40px;
|
|
|
|
|
|
background: var(--bg-secondary);
|
|
|
|
|
|
border: 1px solid var(--border);
|
|
|
|
|
|
border-radius: var(--radius-lg);
|
|
|
|
|
|
box-shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Logo */
|
|
|
|
|
|
.login-logo {
|
|
|
|
|
|
text-align: center;
|
|
|
|
|
|
margin-bottom: 32px;
|
|
|
|
|
|
}
|
|
|
|
|
|
.login-logo-icon {
|
|
|
|
|
|
width: 56px;
|
|
|
|
|
|
height: 56px;
|
|
|
|
|
|
background: linear-gradient(135deg, #3b82f6, #8b5cf6);
|
|
|
|
|
|
border-radius: 14px;
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
justify-content: center;
|
|
|
|
|
|
color: white;
|
|
|
|
|
|
margin: 0 auto 16px;
|
|
|
|
|
|
}
|
|
|
|
|
|
.login-title {
|
|
|
|
|
|
font-size: 22px;
|
|
|
|
|
|
font-weight: 700;
|
|
|
|
|
|
color: var(--text-primary);
|
|
|
|
|
|
margin: 0 0 4px;
|
|
|
|
|
|
}
|
|
|
|
|
|
.login-subtitle {
|
|
|
|
|
|
font-size: 13px;
|
|
|
|
|
|
color: var(--text-muted);
|
|
|
|
|
|
margin: 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* 登录按钮 */
|
|
|
|
|
|
.login-btn {
|
|
|
|
|
|
width: 100%;
|
2026-07-04 21:01:39 +08:00
|
|
|
|
margin-top: 8px;
|
2026-06-14 16:49:18 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* 提示信息 */
|
|
|
|
|
|
.login-tips {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
justify-content: center;
|
|
|
|
|
|
gap: 6px;
|
|
|
|
|
|
margin-top: 20px;
|
|
|
|
|
|
font-size: 12px;
|
|
|
|
|
|
color: var(--text-muted);
|
|
|
|
|
|
}
|
|
|
|
|
|
</style>
|