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
|
|
|
|
// 说明: 从扫码登录改为账号密码+OTP表单登录
|
2026-06-21 00:46:50 +08:00
|
|
|
|
//
|
|
|
|
|
|
// 流程:
|
2026-07-04 21:01:39 +08:00
|
|
|
|
// 1. 用户输入账号 + 密码
|
|
|
|
|
|
// 2. 点击登录 → 调用后端 /api/agents/login
|
|
|
|
|
|
// 3. 若 require_otp=true,显示 OTP 输入框
|
|
|
|
|
|
// 4. 用户输入 OTP 后再次提交
|
|
|
|
|
|
// 5. 登录成功 → 存 token → 跳 /workspace
|
2026-06-14 16:49:18 +08:00
|
|
|
|
// ============================================================================= -->
|
|
|
|
|
|
|
|
|
|
|
|
<template>
|
2026-06-21 00:46:50 +08:00
|
|
|
|
<div class="login-page">
|
2026-06-14 16:49:18 +08:00
|
|
|
|
<div class="login-card">
|
2026-06-21 00:46:50 +08:00
|
|
|
|
<!-- 标题区 -->
|
2026-06-14 16:49:18 +08:00
|
|
|
|
<div class="login-title">
|
|
|
|
|
|
<h1>🛠️ IT智能服务台</h1>
|
2026-07-04 21:01:39 +08:00
|
|
|
|
<p>坐席工作台 · 账号登录</p>
|
2026-06-14 16:49:18 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
|
2026-07-04 21:01:39 +08:00
|
|
|
|
<!-- 登录表单 -->
|
|
|
|
|
|
<el-form
|
|
|
|
|
|
ref="formRef"
|
|
|
|
|
|
:model="loginForm"
|
|
|
|
|
|
:rules="rules"
|
|
|
|
|
|
label-position="top"
|
|
|
|
|
|
@submit.prevent="handleLogin"
|
|
|
|
|
|
>
|
|
|
|
|
|
<el-form-item label="账号" prop="userId">
|
2026-06-14 16:49:18 +08:00
|
|
|
|
<el-input
|
2026-07-04 21:01:39 +08:00
|
|
|
|
v-model="loginForm.userId"
|
|
|
|
|
|
placeholder="请输入账号(如 sxn)"
|
|
|
|
|
|
size="large"
|
|
|
|
|
|
:prefix-icon="User"
|
|
|
|
|
|
@keydown.enter="handleLogin"
|
2026-06-14 16:49:18 +08:00
|
|
|
|
/>
|
2026-07-04 21:01:39 +08:00
|
|
|
|
</el-form-item>
|
2026-06-14 16:49:18 +08:00
|
|
|
|
|
2026-07-04 21:01:39 +08:00
|
|
|
|
<el-form-item label="密码" prop="password">
|
|
|
|
|
|
<el-input
|
|
|
|
|
|
v-model="loginForm.password"
|
|
|
|
|
|
type="password"
|
|
|
|
|
|
placeholder="请输入密码"
|
|
|
|
|
|
size="large"
|
|
|
|
|
|
:prefix-icon="Lock"
|
|
|
|
|
|
show-password
|
|
|
|
|
|
@keydown.enter="handleLogin"
|
|
|
|
|
|
/>
|
|
|
|
|
|
</el-form-item>
|
2026-06-21 00:46:50 +08:00
|
|
|
|
|
2026-07-04 21:01:39 +08:00
|
|
|
|
<!-- OTP 输入区: 仅在 require_otp 时显示 -->
|
|
|
|
|
|
<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"
|
|
|
|
|
|
@keydown.enter="handleLogin"
|
|
|
|
|
|
/>
|
|
|
|
|
|
</el-form-item>
|
2026-06-21 00:46:50 +08:00
|
|
|
|
|
2026-07-04 21:01:39 +08:00
|
|
|
|
<el-form-item>
|
2026-06-14 16:49:18 +08:00
|
|
|
|
<el-button
|
|
|
|
|
|
type="primary"
|
2026-07-04 21:01:39 +08:00
|
|
|
|
size="large"
|
|
|
|
|
|
:loading="logging"
|
|
|
|
|
|
:disabled="logging"
|
|
|
|
|
|
@click="handleLogin"
|
|
|
|
|
|
class="login-btn"
|
2026-06-14 16:49:18 +08:00
|
|
|
|
>
|
2026-07-04 21:01:39 +08:00
|
|
|
|
{{ logging ? '登录中...' : (requireOtp ? '验证 OTP' : '登录') }}
|
2026-06-14 16:49:18 +08:00
|
|
|
|
</el-button>
|
2026-07-04 21:01:39 +08:00
|
|
|
|
</el-form-item>
|
|
|
|
|
|
</el-form>
|
2026-06-14 16:49:18 +08:00
|
|
|
|
|
2026-07-04 21:01:39 +08:00
|
|
|
|
<!-- 错误提示 -->
|
|
|
|
|
|
<el-alert
|
|
|
|
|
|
v-if="errorMsg"
|
|
|
|
|
|
:title="errorMsg"
|
|
|
|
|
|
type="error"
|
|
|
|
|
|
show-icon
|
|
|
|
|
|
:closable="true"
|
|
|
|
|
|
@close="errorMsg = ''"
|
|
|
|
|
|
style="margin-top: 16px"
|
|
|
|
|
|
/>
|
2026-06-21 00:46:50 +08:00
|
|
|
|
|
2026-07-04 21:01:39 +08:00
|
|
|
|
<!-- 提示信息 -->
|
2026-06-14 16:49:18 +08:00
|
|
|
|
<div class="login-hint">
|
2026-06-21 00:46:50 +08:00
|
|
|
|
<p>登录即表示同意《IT智能服务台使用规范》</p>
|
2026-06-14 16:49:18 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
|
|
|
|
|
// ============================================================================
|
|
|
|
|
|
// 导入
|
|
|
|
|
|
// ============================================================================
|
2026-07-04 21:01:39 +08:00
|
|
|
|
import { ref, reactive } from 'vue'
|
2026-06-21 00:46:50 +08:00
|
|
|
|
import { useRouter } from 'vue-router'
|
2026-06-14 16:49:18 +08:00
|
|
|
|
import { ElMessage } from 'element-plus'
|
2026-07-04 21:01:39 +08:00
|
|
|
|
import type { FormInstance, FormRules } from 'element-plus'
|
|
|
|
|
|
import { User, Lock, Key } from '@element-plus/icons-vue'
|
|
|
|
|
|
import { useAgentStore } from '@/stores/agent'
|
2026-06-14 16:49:18 +08:00
|
|
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
|
|
// 状态
|
|
|
|
|
|
// ============================================================================
|
2026-06-21 00:46:50 +08:00
|
|
|
|
const router = useRouter()
|
2026-07-04 21:01:39 +08:00
|
|
|
|
const agentStore = useAgentStore()
|
2026-06-14 16:49:18 +08:00
|
|
|
|
|
2026-07-04 21:01:39 +08:00
|
|
|
|
/** 表单引用 */
|
|
|
|
|
|
const formRef = ref<FormInstance>()
|
2026-06-21 00:46:50 +08:00
|
|
|
|
|
2026-07-04 21:01:39 +08:00
|
|
|
|
/** 登录表单数据 */
|
|
|
|
|
|
const loginForm = reactive({
|
|
|
|
|
|
userId: '',
|
|
|
|
|
|
password: '',
|
|
|
|
|
|
otpCode: '',
|
2026-06-21 00:46:50 +08:00
|
|
|
|
})
|
|
|
|
|
|
|
2026-07-04 21:01:39 +08:00
|
|
|
|
/** 是否需要 OTP 验证 */
|
|
|
|
|
|
const requireOtp = ref(false)
|
|
|
|
|
|
|
|
|
|
|
|
/** 登录中状态 */
|
|
|
|
|
|
const logging = ref(false)
|
|
|
|
|
|
|
|
|
|
|
|
/** 错误信息 */
|
|
|
|
|
|
const errorMsg = ref<string>('')
|
|
|
|
|
|
|
|
|
|
|
|
/** 表单校验规则 */
|
|
|
|
|
|
const rules: FormRules = {
|
|
|
|
|
|
userId: [
|
|
|
|
|
|
{ required: true, message: '请输入账号', trigger: 'blur' },
|
|
|
|
|
|
],
|
|
|
|
|
|
password: [
|
|
|
|
|
|
{ required: true, message: '请输入密码', trigger: 'blur' },
|
|
|
|
|
|
],
|
|
|
|
|
|
otpCode: [
|
|
|
|
|
|
{ required: true, message: '请输入 OTP 验证码', trigger: 'blur' },
|
|
|
|
|
|
{ len: 6, message: '验证码为 6 位数字', trigger: 'blur' },
|
|
|
|
|
|
],
|
2026-06-21 00:46:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ============================================================================
|
2026-07-04 21:01:39 +08:00
|
|
|
|
// 方法
|
2026-06-21 00:46:50 +08:00
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
2026-07-04 21:01:39 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 处理登录
|
|
|
|
|
|
*/
|
|
|
|
|
|
async function handleLogin(): Promise<void> {
|
|
|
|
|
|
// 表单校验
|
|
|
|
|
|
const valid = await formRef.value?.validate().catch(() => false)
|
|
|
|
|
|
if (!valid) return
|
|
|
|
|
|
|
|
|
|
|
|
logging.value = true
|
|
|
|
|
|
errorMsg.value = ''
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
const result = await agentStore.login(
|
|
|
|
|
|
loginForm.userId.trim(),
|
|
|
|
|
|
loginForm.password,
|
|
|
|
|
|
loginForm.otpCode.trim() || undefined
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
// 检查是否需要 OTP 验证
|
|
|
|
|
|
if (result && result.require_otp) {
|
|
|
|
|
|
requireOtp.value = true
|
|
|
|
|
|
loginForm.otpCode = ''
|
|
|
|
|
|
ElMessage.info('请输入 OTP 验证码')
|
|
|
|
|
|
logging.value = false
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 登录成功
|
|
|
|
|
|
ElMessage.success('登录成功')
|
|
|
|
|
|
router.push('/workspace')
|
|
|
|
|
|
} catch (error: unknown) {
|
|
|
|
|
|
const errMsg = error instanceof Error ? error.message : '登录失败,请重试'
|
|
|
|
|
|
errorMsg.value = errMsg
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
logging.value = false
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-06-14 16:49:18 +08:00
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<style scoped>
|
2026-06-21 00:46:50 +08:00
|
|
|
|
/* 登录页面容器:全屏居中 */
|
|
|
|
|
|
.login-page {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
justify-content: center;
|
|
|
|
|
|
min-height: 100vh;
|
|
|
|
|
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
|
|
|
|
padding: 24px;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* 登录卡片 */
|
|
|
|
|
|
.login-card {
|
|
|
|
|
|
width: 100%;
|
2026-07-04 21:01:39 +08:00
|
|
|
|
max-width: 400px;
|
2026-06-21 00:46:50 +08:00
|
|
|
|
background: var(--bg-secondary, #ffffff);
|
|
|
|
|
|
border-radius: 16px;
|
|
|
|
|
|
padding: 40px 32px;
|
|
|
|
|
|
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* 标题区 */
|
|
|
|
|
|
.login-title {
|
|
|
|
|
|
text-align: center;
|
|
|
|
|
|
margin-bottom: 32px;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.login-title h1 {
|
|
|
|
|
|
font-size: 24px;
|
|
|
|
|
|
font-weight: 700;
|
|
|
|
|
|
color: var(--text-primary, #303133);
|
|
|
|
|
|
margin: 0 0 8px 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.login-title p {
|
|
|
|
|
|
font-size: 14px;
|
|
|
|
|
|
color: var(--text-tertiary, #909399);
|
|
|
|
|
|
margin: 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-07-04 21:01:39 +08:00
|
|
|
|
/* 登录按钮 */
|
|
|
|
|
|
.login-btn {
|
2026-06-21 00:46:50 +08:00
|
|
|
|
width: 100%;
|
2026-07-04 21:01:39 +08:00
|
|
|
|
margin-top: 8px;
|
2026-06-21 00:46:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* 底部提示 */
|
2026-06-14 16:49:18 +08:00
|
|
|
|
.login-hint {
|
|
|
|
|
|
text-align: center;
|
2026-06-21 00:46:50 +08:00
|
|
|
|
color: var(--text-placeholder, #c0c4cc);
|
2026-06-14 16:49:18 +08:00
|
|
|
|
font-size: 12px;
|
2026-06-21 00:46:50 +08:00
|
|
|
|
line-height: 1.6;
|
|
|
|
|
|
border-top: 1px solid var(--border-color-lighter, #ebeef5);
|
|
|
|
|
|
padding-top: 16px;
|
2026-07-04 21:01:39 +08:00
|
|
|
|
margin-top: 24px;
|
2026-06-14 16:49:18 +08:00
|
|
|
|
}
|
2026-06-21 00:46:50 +08:00
|
|
|
|
|
|
|
|
|
|
.login-hint p {
|
|
|
|
|
|
margin: 4px 0;
|
|
|
|
|
|
}
|
2026-07-04 21:01:39 +08:00
|
|
|
|
</style>
|