chore: 整理项目结构,清理归档文件,更新部署配置
This commit is contained in:
@@ -43,7 +43,7 @@ export interface TroubleshootingTemplate {
|
||||
estimated_time?: number
|
||||
difficulty?: number
|
||||
tags?: string[]
|
||||
root_node: FlowchartNode
|
||||
flowchart: FlowchartNode
|
||||
version?: string
|
||||
status?: 'draft' | 'published'
|
||||
created_at?: string
|
||||
@@ -76,7 +76,7 @@ export async function listTemplates(): Promise<TroubleshootingTemplate[]> {
|
||||
const res = await http.get<ApiResponse<TroubleshootingTemplate[]>>(
|
||||
'/troubleshooting-templates'
|
||||
)
|
||||
return res.data.data || []
|
||||
return res.data.data?.items || []
|
||||
}
|
||||
|
||||
/** GET /api/troubleshooting-templates/{id} — 获取模板详情 */
|
||||
|
||||
@@ -192,7 +192,7 @@ const EMPTY_TEMPLATE: TroubleshootingTemplate = {
|
||||
estimated_time: 5,
|
||||
difficulty: 2,
|
||||
tags: [],
|
||||
root_node: {
|
||||
flowchart: {
|
||||
id: 'fc-new-1',
|
||||
type: 'step',
|
||||
label: '请修改此步骤',
|
||||
@@ -235,8 +235,8 @@ const dialogTitle = computed(() => {
|
||||
})
|
||||
|
||||
const stats = computed(() => ({
|
||||
nodes: parseOk.value && parsedData.value ? countNodes(parsedData.value.root_node) : 0,
|
||||
decisions: parseOk.value && parsedData.value ? countDecisions(parsedData.value.root_node) : 0,
|
||||
nodes: parseOk.value && parsedData.value ? countNodes(parsedData.value.flowchart) : 0,
|
||||
decisions: parseOk.value && parsedData.value ? countDecisions(parsedData.value.flowchart) : 0,
|
||||
}))
|
||||
|
||||
const rootPath = computed(() => 'root')
|
||||
|
||||
@@ -59,22 +59,30 @@ export const useAdminStore = defineStore('admin', () => {
|
||||
|
||||
/**
|
||||
* 管理员登录
|
||||
* 复用坐席端登录 API(POST /api/agents/login),但额外校验 role === 'admin'
|
||||
* 复用坐席端登录 API(POST /api/agents/login),支持账号密码+OTP认证
|
||||
*
|
||||
* @param inputUserId - 企微用户ID
|
||||
* @param inputName - 管理员姓名
|
||||
* @param inputUserId - 账号/用户名
|
||||
* @param password - 密码
|
||||
* @param otpCode - OTP 动态码(可选,首次登录不需要)
|
||||
*/
|
||||
async function login(inputUserId: string, inputName: string): Promise<void> {
|
||||
async function login(inputUserId: string, password: string, otpCode?: string): Promise<void> {
|
||||
logging.value = true
|
||||
try {
|
||||
const response = await apiClient.post('/agents/login', {
|
||||
user_id: inputUserId,
|
||||
name: inputName,
|
||||
password: password,
|
||||
otp_code: otpCode || undefined,
|
||||
})
|
||||
|
||||
const data = response.data.data
|
||||
const agentInfoData = data.agent_info || data
|
||||
|
||||
// 检查是否需要 OTP 验证
|
||||
if ('require_otp' in data && data.require_otp) {
|
||||
logging.value = false
|
||||
throw new Error('require_otp')
|
||||
}
|
||||
|
||||
// 校验角色是否为管理员
|
||||
if (agentInfoData.role !== 'admin') {
|
||||
throw new Error('无管理权限:该账号非管理员角色')
|
||||
@@ -96,6 +104,12 @@ export const useAdminStore = defineStore('admin', () => {
|
||||
router.push('/dashboard')
|
||||
} catch (error: unknown) {
|
||||
console.error('管理员登录失败:', error)
|
||||
|
||||
// 如果是 require_otp 错误,直接抛出让 UI 处理
|
||||
if (error instanceof Error && error.message === 'require_otp') {
|
||||
throw error
|
||||
}
|
||||
|
||||
const errMsg = error instanceof Error ? error.message : '登录失败,请重试'
|
||||
throw new Error(errMsg)
|
||||
} finally {
|
||||
|
||||
@@ -163,7 +163,7 @@ async function loadList() {
|
||||
// 附加节点数(便于表格展示)
|
||||
flowcharts.value = list.map((t) => ({
|
||||
...t,
|
||||
nodeCount: countNodes(t.root_node),
|
||||
nodeCount: countNodes(t.flowchart),
|
||||
}))
|
||||
} catch (e) {
|
||||
ElMessage.error('加载流程图列表失败')
|
||||
@@ -287,8 +287,8 @@ async function handleFileSelected(event: Event) {
|
||||
const result = JSON.parse(text) as TroubleshootingTemplate
|
||||
|
||||
// 简单校验
|
||||
if (!result.name || !result.category || !result.root_node) {
|
||||
throw new Error('JSON 缺少必要字段(name/category/root_node)')
|
||||
if (!result.name || !result.category || !result.flowchart) {
|
||||
throw new Error('JSON 缺少必要字段(name/category/flowchart)')
|
||||
}
|
||||
|
||||
// 把导入的 JSON 当作"新建"打开,让用户确认/编辑
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
<!--
|
||||
=============================================================================
|
||||
企微IT智能服务台 — 管理员登录页
|
||||
IT智能服务台 — 管理员登录页 (v1.1, 2026-07-04)
|
||||
=============================================================================
|
||||
说明:管理员登录页面
|
||||
说明:从用户ID+姓名登录改为账号密码+OTP表单登录
|
||||
- 复用坐席端登录 API(POST /api/agents/login)
|
||||
- 登录后检查 role === 'admin',非 admin 提示"无管理权限"
|
||||
- 使用 admin Store 的 login 方法
|
||||
- 支持账号密码+OTP认证
|
||||
-->
|
||||
<template>
|
||||
<div class="login-page">
|
||||
@@ -33,22 +33,36 @@
|
||||
label-position="top"
|
||||
@submit.prevent="handleLogin"
|
||||
>
|
||||
<el-form-item label="企微用户ID" prop="userId">
|
||||
<el-form-item label="账号" prop="userId">
|
||||
<el-input
|
||||
v-model="loginForm.userId"
|
||||
placeholder="请输入企微用户ID(如 SongXian)"
|
||||
placeholder="请输入账号(如 sxn)"
|
||||
size="large"
|
||||
:prefix-icon="User"
|
||||
@keydown.enter="handleLogin"
|
||||
/>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="姓名" prop="name">
|
||||
<el-form-item label="密码" prop="password">
|
||||
<el-input
|
||||
v-model="loginForm.name"
|
||||
placeholder="请输入您的姓名"
|
||||
v-model="loginForm.password"
|
||||
type="password"
|
||||
placeholder="请输入密码"
|
||||
size="large"
|
||||
:prefix-icon="Avatar"
|
||||
: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"
|
||||
@keydown.enter="handleLogin"
|
||||
/>
|
||||
</el-form-item>
|
||||
@@ -62,7 +76,7 @@
|
||||
@click="handleLogin"
|
||||
class="login-btn"
|
||||
>
|
||||
{{ adminStore.logging ? '登录中...' : '登录管理后台' }}
|
||||
{{ adminStore.logging ? '登录中...' : (requireOtp ? '验证 OTP' : '登录管理后台') }}
|
||||
</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
@@ -92,13 +106,16 @@
|
||||
// 依赖导入
|
||||
// ==========================================================================
|
||||
import { ref, reactive } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { useAdminStore } from '@/stores/admin'
|
||||
import type { FormInstance, FormRules } from 'element-plus'
|
||||
import { User, Avatar, InfoFilled } from '@element-plus/icons-vue'
|
||||
import { User, Lock, Key, InfoFilled, Headset } from '@element-plus/icons-vue'
|
||||
|
||||
// ==========================================================================
|
||||
// Store
|
||||
// ==========================================================================
|
||||
const router = useRouter()
|
||||
const adminStore = useAdminStore()
|
||||
|
||||
// ==========================================================================
|
||||
@@ -111,22 +128,30 @@ const formRef = ref<FormInstance>()
|
||||
/** 登录表单数据 */
|
||||
const loginForm = reactive({
|
||||
userId: '',
|
||||
name: '',
|
||||
password: '',
|
||||
otpCode: '',
|
||||
})
|
||||
|
||||
/** 是否需要 OTP 验证 */
|
||||
const requireOtp = ref(false)
|
||||
|
||||
/** 错误信息 */
|
||||
const errorMsg = ref<string>('')
|
||||
|
||||
/** 表单校验规则 */
|
||||
const rules: FormRules = {
|
||||
userId: [
|
||||
{ required: true, message: '请输入企微用户ID', trigger: 'blur' },
|
||||
{ required: true, message: '请输入账号', trigger: 'blur' },
|
||||
],
|
||||
name: [
|
||||
{ required: true, message: '请输入姓名', trigger: 'blur' },
|
||||
password: [
|
||||
{ required: true, message: '请输入密码', trigger: 'blur' },
|
||||
],
|
||||
otpCode: [
|
||||
{ required: true, message: '请输入 OTP 验证码', trigger: 'blur' },
|
||||
{ len: 6, message: '验证码为 6 位数字', trigger: 'blur' },
|
||||
],
|
||||
}
|
||||
|
||||
/** 错误信息 */
|
||||
const errorMsg = ref<string>('')
|
||||
|
||||
// ==========================================================================
|
||||
// 方法
|
||||
// ==========================================================================
|
||||
@@ -142,8 +167,20 @@ async function handleLogin(): Promise<void> {
|
||||
errorMsg.value = ''
|
||||
|
||||
try {
|
||||
await adminStore.login(loginForm.userId.trim(), loginForm.name.trim())
|
||||
await adminStore.login(
|
||||
loginForm.userId.trim(),
|
||||
loginForm.password,
|
||||
loginForm.otpCode.trim() || undefined
|
||||
)
|
||||
} catch (error: unknown) {
|
||||
// 检查是否需要 OTP 验证
|
||||
if (error instanceof Error && error.message === 'require_otp') {
|
||||
requireOtp.value = true
|
||||
loginForm.otpCode = ''
|
||||
ElMessage.info('请输入 OTP 验证码')
|
||||
return
|
||||
}
|
||||
|
||||
const errMsg = error instanceof Error ? error.message : '登录失败,请重试'
|
||||
errorMsg.value = errMsg
|
||||
}
|
||||
@@ -224,6 +261,7 @@ async function handleLogin(): Promise<void> {
|
||||
/* 登录按钮 */
|
||||
.login-btn {
|
||||
width: 100%;
|
||||
margin-top: 8px;
|
||||
}
|
||||
|
||||
/* 提示信息 */
|
||||
|
||||
Reference in New Issue
Block a user