Merge branch 'dev' of https://gitee.com/justop/hxops into dev
This commit is contained in:
commit
b89f9bafb6
22 files changed
+492
-244
No files matched your search
@@ -38,6 +38,7 @@ def build_dify_inputs_for_context(ctx: ChatStreamContext) -> dict[str, Any]:
|
||||
session_id=str(getattr(ctx.session, 'session_id', '') or ''),
|
||||
request_id=ctx.request_id,
|
||||
trigger_source='frontend_chat',
|
||||
user_role=str(getattr(ctx.user, 'role', '') or '').strip() or None,
|
||||
adapter_hints=ctx.adapter_hints,
|
||||
user_role=getattr(ctx.user, 'role', None),
|
||||
)
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
| Chat 内培训工作区 | 前端已实现 | 在培训 Agent 聊天页顶部提供视频学习、知识点复盘、逐题考试、成绩结算的一体化工作区 |
|
||||
| Chat 内 HR 管理面板 | 已实现 | 仅具备培训 HR 管理权限的用户可在同一聊天页查看真实培训统计、筛选记录并导出 Excel;权限支持角色默认值与前端用户配置共同控制 |
|
||||
| 培训题库后台配置 | 已实现 | Agent 管理表单支持维护及格线、复盘要点、考前清单与题库;员工培训页优先读取 `extra_config.training_config`,未配置时才回退前端默认题库 |
|
||||
| 培训聊天常见问题分角色配置 | 已实现 | Agent 管理表单支持分别维护普通员工与 HR 管理员进入“员工培训”聊天页时看到的常见问题;聊天欢迎区会按 `training_hr_manage` 权限自动切换对应问题集 |
|
||||
| 管理端培训模式配置 | 已实现 | Agent 管理表单支持显式开启培训工作区;平台应用说明页支持上传并标记“员工培训视频 / 员工培训试题 PDF”,并可直接把试题 PDF 解析导入题库表单;扫描件 PDF 在 OCR 依赖齐备时也可回退识别 |
|
||||
| 首页培训推荐入口 | 前端已实现 | 当 Agent 开启培训模式后,工作台首页会在应用列表上方展示培训强入口卡片 |
|
||||
| 培训记录后端落库 | 已实现 | 已新增培训记录模型、迁移与用户/管理端 API,考试进度、结果、统计与导出均可走后端数据源 |
|
||||
|
||||
@@ -14,6 +14,10 @@ import type { AgentFormState, AgentGuideSummary, AgentRow } from '@/features/adm
|
||||
import type { ScheduleTask } from '@/shared/types/schedule.types';
|
||||
import type { AgentTypeCatalogEntry, IntentRouteOption } from '../composables/useAgentsAdminRegistry';
|
||||
import type { AdminContentProfileOption } from '@/features/admin/api/admin.api';
|
||||
import {
|
||||
DEFAULT_TRAINING_EMPLOYEE_CHAT_QUESTIONS,
|
||||
DEFAULT_TRAINING_HR_CHAT_QUESTIONS,
|
||||
} from '@/features/chat/training/trainingChatQuestions';
|
||||
import {
|
||||
applyCatalogDefaultsToForm,
|
||||
applyContentProfileTemplate,
|
||||
@@ -183,6 +187,12 @@ const applySelectedContentProfileTemplate = (force = false) => {
|
||||
const handleTrainingWorkspaceToggle = () => {
|
||||
if (props.form.training_workspace_enabled) {
|
||||
props.form.content_profile = 'training';
|
||||
if (!props.form.training_employee_chat_questions_text.trim()) {
|
||||
props.form.training_employee_chat_questions_text = DEFAULT_TRAINING_EMPLOYEE_CHAT_QUESTIONS.join('\n');
|
||||
}
|
||||
if (!props.form.training_hr_chat_questions_text.trim()) {
|
||||
props.form.training_hr_chat_questions_text = DEFAULT_TRAINING_HR_CHAT_QUESTIONS.join('\n');
|
||||
}
|
||||
} else if (props.form.content_profile === 'training') {
|
||||
props.form.content_profile = '';
|
||||
}
|
||||
@@ -634,200 +644,225 @@ const handleTrainingQuestionTypeChange = (form: AgentFormState, index: number) =
|
||||
{{ form.training_workspace_enabled ? t('admin.agent.training.enableHint') : t('admin.agent.training.disabledHint') }}
|
||||
</p>
|
||||
|
||||
<div class="mt-4 grid grid-cols-1 gap-4 md:grid-cols-3">
|
||||
<div class="space-y-2">
|
||||
<label class="text-xs font-semibold text-secondary">{{ t('admin.agent.training.passScore') }}</label>
|
||||
<input
|
||||
v-model.number="form.training_pass_score"
|
||||
type="number"
|
||||
min="0"
|
||||
max="100"
|
||||
step="1"
|
||||
class="w-full input-field text-sm"
|
||||
/>
|
||||
<p class="text-xs leading-5 text-muted">{{ t('admin.agent.training.passScoreHint') }}</p>
|
||||
</div>
|
||||
<div class="space-y-2 md:col-span-2">
|
||||
<label class="text-xs font-semibold text-secondary">{{ t('admin.agent.training.summaryPoints') }}</label>
|
||||
<textarea
|
||||
v-model="form.training_summary_points_text"
|
||||
rows="5"
|
||||
class="w-full input-field text-sm"
|
||||
:placeholder="t('admin.agent.training.summaryPointsPlaceholder')"
|
||||
/>
|
||||
</div>
|
||||
<div class="space-y-2 md:col-span-3">
|
||||
<label class="text-xs font-semibold text-secondary">{{ t('admin.agent.training.summaryChecklist') }}</label>
|
||||
<textarea
|
||||
v-model="form.training_summary_checklist_text"
|
||||
rows="4"
|
||||
class="w-full input-field text-sm"
|
||||
:placeholder="t('admin.agent.training.summaryChecklistPlaceholder')"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mt-5 space-y-3">
|
||||
<div class="flex flex-wrap items-center justify-between gap-3">
|
||||
<div>
|
||||
<div class="text-sm font-semibold text-primary">{{ t('admin.agent.training.questionBank') }}</div>
|
||||
<p class="mt-1 text-xs leading-5 text-muted">{{ t('admin.agent.training.questionHint') }}</p>
|
||||
<template v-if="form.training_workspace_enabled">
|
||||
<div class="mt-4 grid grid-cols-1 gap-4 md:grid-cols-3">
|
||||
<div class="space-y-2">
|
||||
<label class="text-xs font-semibold text-secondary">{{ t('admin.agent.training.passScore') }}</label>
|
||||
<input
|
||||
v-model.number="form.training_pass_score"
|
||||
type="number"
|
||||
min="0"
|
||||
max="100"
|
||||
step="1"
|
||||
class="w-full input-field text-sm"
|
||||
/>
|
||||
<p class="text-xs leading-5 text-muted">{{ t('admin.agent.training.passScoreHint') }}</p>
|
||||
</div>
|
||||
<div class="flex flex-wrap items-center gap-2">
|
||||
<button
|
||||
type="button"
|
||||
class="inline-flex items-center gap-1 rounded-lg border border-default bg-white px-3 py-1.5 text-xs font-medium text-secondary transition-colors hover:bg-surface-soft disabled:cursor-not-allowed disabled:opacity-60"
|
||||
:disabled="!isEditing || trainingExamPdfGuides.length === 0 || isImportingTrainingPdf"
|
||||
@click="emit('importTrainingPdf', trainingExamPdfGuides[0]?.id || null)"
|
||||
>
|
||||
<FileDown class="h-4 w-4" />
|
||||
{{ isImportingTrainingPdf ? t('admin.agent.training.importingPdf') : t('admin.agent.training.importFromPdf') }}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="inline-flex items-center gap-1 rounded-lg border border-default bg-white px-3 py-1.5 text-xs font-medium text-secondary transition-colors hover:bg-surface-soft"
|
||||
@click="emit('addTrainingQuestion')"
|
||||
>
|
||||
<Plus class="h-4 w-4" />
|
||||
{{ t('admin.agent.training.addQuestion') }}
|
||||
</button>
|
||||
<div class="space-y-2 md:col-span-2">
|
||||
<label class="text-xs font-semibold text-secondary">{{ t('admin.agent.training.summaryPoints') }}</label>
|
||||
<textarea
|
||||
v-model="form.training_summary_points_text"
|
||||
rows="5"
|
||||
class="w-full input-field text-sm"
|
||||
:placeholder="t('admin.agent.training.summaryPointsPlaceholder')"
|
||||
/>
|
||||
</div>
|
||||
<div class="space-y-2 md:col-span-3">
|
||||
<label class="text-xs font-semibold text-secondary">{{ t('admin.agent.training.summaryChecklist') }}</label>
|
||||
<textarea
|
||||
v-model="form.training_summary_checklist_text"
|
||||
rows="4"
|
||||
class="w-full input-field text-sm"
|
||||
:placeholder="t('admin.agent.training.summaryChecklistPlaceholder')"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p class="text-xs leading-5 text-muted">
|
||||
{{
|
||||
!isEditing
|
||||
? t('admin.agent.training.importPdfCreateFirst')
|
||||
: trainingExamPdfGuides.length > 0
|
||||
? t('admin.agent.training.importPdfHint', { fileName: trainingExamPdfGuides[0]?.file_name || '--' })
|
||||
: t('admin.agent.training.importPdfMissing')
|
||||
}}
|
||||
</p>
|
||||
|
||||
<div v-if="form.training_question_bank.length === 0" class="rounded-xl border border-dashed border-default bg-white px-4 py-5 text-sm text-muted">
|
||||
{{ t('admin.agent.training.emptyQuestionBank') }}
|
||||
<div class="mt-4 grid grid-cols-1 gap-4 md:grid-cols-2">
|
||||
<div class="space-y-2">
|
||||
<label class="text-xs font-semibold text-secondary">{{ t('admin.agent.training.employeeChatQuestions') }}</label>
|
||||
<textarea
|
||||
v-model="form.training_employee_chat_questions_text"
|
||||
rows="6"
|
||||
class="w-full input-field text-sm"
|
||||
:placeholder="t('admin.agent.training.employeeChatQuestionsPlaceholder')"
|
||||
/>
|
||||
<p class="text-xs leading-5 text-muted">{{ t('admin.agent.training.employeeChatQuestionsHint') }}</p>
|
||||
</div>
|
||||
<div class="space-y-2">
|
||||
<label class="text-xs font-semibold text-secondary">{{ t('admin.agent.training.hrChatQuestions') }}</label>
|
||||
<textarea
|
||||
v-model="form.training_hr_chat_questions_text"
|
||||
rows="6"
|
||||
class="w-full input-field text-sm"
|
||||
:placeholder="t('admin.agent.training.hrChatQuestionsPlaceholder')"
|
||||
/>
|
||||
<p class="text-xs leading-5 text-muted">{{ t('admin.agent.training.hrChatQuestionsHint') }}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-else class="space-y-4">
|
||||
<div
|
||||
v-for="(question, questionIndex) in form.training_question_bank"
|
||||
:key="questionIndex"
|
||||
class="rounded-2xl border border-default bg-white p-4"
|
||||
>
|
||||
<div class="mb-4 flex flex-wrap items-center justify-between gap-3">
|
||||
<div class="text-sm font-semibold text-primary">
|
||||
{{ t('admin.agent.training.questionCardTitle', { index: questionIndex + 1 }) }}
|
||||
</div>
|
||||
<div class="mt-5 space-y-3">
|
||||
<div class="flex flex-wrap items-center justify-between gap-3">
|
||||
<div>
|
||||
<div class="text-sm font-semibold text-primary">{{ t('admin.agent.training.questionBank') }}</div>
|
||||
<p class="mt-1 text-xs leading-5 text-muted">{{ t('admin.agent.training.questionHint') }}</p>
|
||||
</div>
|
||||
<div class="flex flex-wrap items-center gap-2">
|
||||
<button
|
||||
type="button"
|
||||
class="inline-flex items-center gap-1 rounded-lg border border-red-200 bg-red-50 px-3 py-1.5 text-xs font-medium text-red-600 transition-colors hover:bg-red-100"
|
||||
@click="emit('removeTrainingQuestion', questionIndex)"
|
||||
class="inline-flex items-center gap-1 rounded-lg border border-default bg-white px-3 py-1.5 text-xs font-medium text-secondary transition-colors hover:bg-surface-soft disabled:cursor-not-allowed disabled:opacity-60"
|
||||
:disabled="!isEditing || trainingExamPdfGuides.length === 0 || isImportingTrainingPdf"
|
||||
@click="emit('importTrainingPdf', trainingExamPdfGuides[0]?.id || null)"
|
||||
>
|
||||
<Trash2 class="h-4 w-4" />
|
||||
{{ t('admin.agent.training.removeQuestion') }}
|
||||
<FileDown class="h-4 w-4" />
|
||||
{{ isImportingTrainingPdf ? t('admin.agent.training.importingPdf') : t('admin.agent.training.importFromPdf') }}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="inline-flex items-center gap-1 rounded-lg border border-default bg-white px-3 py-1.5 text-xs font-medium text-secondary transition-colors hover:bg-surface-soft"
|
||||
@click="emit('addTrainingQuestion')"
|
||||
>
|
||||
<Plus class="h-4 w-4" />
|
||||
{{ t('admin.agent.training.addQuestion') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-1 gap-4 md:grid-cols-3">
|
||||
<div class="space-y-2">
|
||||
<label class="text-xs font-semibold text-secondary">{{ t('admin.agent.training.questionId') }}</label>
|
||||
<input
|
||||
v-model="question.id"
|
||||
type="text"
|
||||
class="w-full input-field text-sm"
|
||||
:placeholder="t('admin.agent.training.questionIdPlaceholder')"
|
||||
/>
|
||||
</div>
|
||||
<div class="space-y-2">
|
||||
<label class="text-xs font-semibold text-secondary">{{ t('admin.agent.training.questionType') }}</label>
|
||||
<select
|
||||
v-model="question.type"
|
||||
class="w-full input-field text-sm"
|
||||
@change="handleTrainingQuestionTypeChange(form, questionIndex)"
|
||||
<p class="text-xs leading-5 text-muted">
|
||||
{{
|
||||
!isEditing
|
||||
? t('admin.agent.training.importPdfCreateFirst')
|
||||
: trainingExamPdfGuides.length > 0
|
||||
? t('admin.agent.training.importPdfHint', { fileName: trainingExamPdfGuides[0]?.file_name || '--' })
|
||||
: t('admin.agent.training.importPdfMissing')
|
||||
}}
|
||||
</p>
|
||||
|
||||
<div v-if="form.training_question_bank.length === 0" class="rounded-xl border border-dashed border-default bg-white px-4 py-5 text-sm text-muted">
|
||||
{{ t('admin.agent.training.emptyQuestionBank') }}
|
||||
</div>
|
||||
|
||||
<div v-else class="space-y-4">
|
||||
<div
|
||||
v-for="(question, questionIndex) in form.training_question_bank"
|
||||
:key="questionIndex"
|
||||
class="rounded-2xl border border-default bg-white p-4"
|
||||
>
|
||||
<div class="mb-4 flex flex-wrap items-center justify-between gap-3">
|
||||
<div class="text-sm font-semibold text-primary">
|
||||
{{ t('admin.agent.training.questionCardTitle', { index: questionIndex + 1 }) }}
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
class="inline-flex items-center gap-1 rounded-lg border border-red-200 bg-red-50 px-3 py-1.5 text-xs font-medium text-red-600 transition-colors hover:bg-red-100"
|
||||
@click="emit('removeTrainingQuestion', questionIndex)"
|
||||
>
|
||||
<option value="single">{{ t('admin.agent.training.single') }}</option>
|
||||
<option value="boolean">{{ t('admin.agent.training.boolean') }}</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="space-y-2">
|
||||
<label class="text-xs font-semibold text-secondary">{{ t('admin.agent.training.correctAnswer') }}</label>
|
||||
<select v-model="question.answer" class="w-full input-field text-sm">
|
||||
<template v-if="question.type === 'boolean'">
|
||||
<option value="true">{{ t('admin.agent.training.booleanTrue') }}</option>
|
||||
<option value="false">{{ t('admin.agent.training.booleanFalse') }}</option>
|
||||
</template>
|
||||
<template v-else>
|
||||
<option
|
||||
v-for="(_, optionIndex) in question.options.filter((item) => String(item || '').trim())"
|
||||
:key="`${questionIndex}-${optionIndex}`"
|
||||
:value="String.fromCharCode(97 + optionIndex)"
|
||||
>
|
||||
{{ t('admin.agent.training.optionLabel', { label: optionLabels[optionIndex] || optionIndex + 1 }) }}
|
||||
</option>
|
||||
</template>
|
||||
</select>
|
||||
<Trash2 class="h-4 w-4" />
|
||||
{{ t('admin.agent.training.removeQuestion') }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="space-y-2 md:col-span-3">
|
||||
<label class="text-xs font-semibold text-secondary">{{ t('admin.agent.training.questionPrompt') }}</label>
|
||||
<textarea
|
||||
v-model="question.prompt"
|
||||
rows="3"
|
||||
class="w-full input-field text-sm"
|
||||
:placeholder="t('admin.agent.training.questionPromptPlaceholder')"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="space-y-2 md:col-span-3">
|
||||
<label class="text-xs font-semibold text-secondary">{{ t('admin.agent.training.questionExplanation') }}</label>
|
||||
<textarea
|
||||
v-model="question.explanation"
|
||||
rows="3"
|
||||
class="w-full input-field text-sm"
|
||||
:placeholder="t('admin.agent.training.questionExplanationPlaceholder')"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div v-if="question.type === 'single'" class="space-y-3 md:col-span-3">
|
||||
<div class="flex flex-wrap items-center justify-between gap-3">
|
||||
<label class="text-xs font-semibold text-secondary">{{ t('admin.agent.training.questionOptions') }}</label>
|
||||
<button
|
||||
type="button"
|
||||
class="inline-flex items-center gap-1 rounded-lg border border-default bg-surface-soft px-3 py-1.5 text-xs font-medium text-secondary transition-colors hover:bg-slate-100"
|
||||
@click="emit('addTrainingOption', questionIndex)"
|
||||
<div class="grid grid-cols-1 gap-4 md:grid-cols-3">
|
||||
<div class="space-y-2">
|
||||
<label class="text-xs font-semibold text-secondary">{{ t('admin.agent.training.questionId') }}</label>
|
||||
<input
|
||||
v-model="question.id"
|
||||
type="text"
|
||||
class="w-full input-field text-sm"
|
||||
:placeholder="t('admin.agent.training.questionIdPlaceholder')"
|
||||
/>
|
||||
</div>
|
||||
<div class="space-y-2">
|
||||
<label class="text-xs font-semibold text-secondary">{{ t('admin.agent.training.questionType') }}</label>
|
||||
<select
|
||||
v-model="question.type"
|
||||
class="w-full input-field text-sm"
|
||||
@change="handleTrainingQuestionTypeChange(form, questionIndex)"
|
||||
>
|
||||
<Plus class="h-4 w-4" />
|
||||
{{ t('admin.agent.training.addOption') }}
|
||||
</button>
|
||||
<option value="single">{{ t('admin.agent.training.single') }}</option>
|
||||
<option value="boolean">{{ t('admin.agent.training.boolean') }}</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="space-y-2">
|
||||
<label class="text-xs font-semibold text-secondary">{{ t('admin.agent.training.correctAnswer') }}</label>
|
||||
<select v-model="question.answer" class="w-full input-field text-sm">
|
||||
<template v-if="question.type === 'boolean'">
|
||||
<option value="true">{{ t('admin.agent.training.booleanTrue') }}</option>
|
||||
<option value="false">{{ t('admin.agent.training.booleanFalse') }}</option>
|
||||
</template>
|
||||
<template v-else>
|
||||
<option
|
||||
v-for="(_, optionIndex) in question.options.filter((item) => String(item || '').trim())"
|
||||
:key="`${questionIndex}-${optionIndex}`"
|
||||
:value="String.fromCharCode(97 + optionIndex)"
|
||||
>
|
||||
{{ t('admin.agent.training.optionLabel', { label: optionLabels[optionIndex] || optionIndex + 1 }) }}
|
||||
</option>
|
||||
</template>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="grid gap-3 md:grid-cols-2">
|
||||
<div
|
||||
v-for="(_, optionIndex) in question.options"
|
||||
:key="`${questionIndex}-option-${optionIndex}`"
|
||||
class="flex items-center gap-2 rounded-xl border border-default bg-surface-soft/40 p-3"
|
||||
>
|
||||
<span class="min-w-6 text-xs font-semibold text-muted">{{ optionLabels[optionIndex] || optionIndex + 1 }}.</span>
|
||||
<input
|
||||
v-model="question.options[optionIndex]"
|
||||
type="text"
|
||||
class="w-full input-field text-sm"
|
||||
:placeholder="t('admin.agent.training.optionPlaceholder')"
|
||||
/>
|
||||
<div class="space-y-2 md:col-span-3">
|
||||
<label class="text-xs font-semibold text-secondary">{{ t('admin.agent.training.questionPrompt') }}</label>
|
||||
<textarea
|
||||
v-model="question.prompt"
|
||||
rows="3"
|
||||
class="w-full input-field text-sm"
|
||||
:placeholder="t('admin.agent.training.questionPromptPlaceholder')"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="space-y-2 md:col-span-3">
|
||||
<label class="text-xs font-semibold text-secondary">{{ t('admin.agent.training.questionExplanation') }}</label>
|
||||
<textarea
|
||||
v-model="question.explanation"
|
||||
rows="3"
|
||||
class="w-full input-field text-sm"
|
||||
:placeholder="t('admin.agent.training.questionExplanationPlaceholder')"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div v-if="question.type === 'single'" class="space-y-3 md:col-span-3">
|
||||
<div class="flex flex-wrap items-center justify-between gap-3">
|
||||
<label class="text-xs font-semibold text-secondary">{{ t('admin.agent.training.questionOptions') }}</label>
|
||||
<button
|
||||
type="button"
|
||||
class="inline-flex h-10 w-10 items-center justify-center rounded-lg border border-red-200 bg-red-50 text-red-600 transition-colors hover:bg-red-100"
|
||||
@click="emit('removeTrainingOption', questionIndex, optionIndex)"
|
||||
class="inline-flex items-center gap-1 rounded-lg border border-default bg-surface-soft px-3 py-1.5 text-xs font-medium text-secondary transition-colors hover:bg-slate-100"
|
||||
@click="emit('addTrainingOption', questionIndex)"
|
||||
>
|
||||
<Trash2 class="h-4 w-4" />
|
||||
<Plus class="h-4 w-4" />
|
||||
{{ t('admin.agent.training.addOption') }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="grid gap-3 md:grid-cols-2">
|
||||
<div
|
||||
v-for="(_, optionIndex) in question.options"
|
||||
:key="`${questionIndex}-option-${optionIndex}`"
|
||||
class="flex items-center gap-2 rounded-xl border border-default bg-surface-soft/40 p-3"
|
||||
>
|
||||
<span class="min-w-6 text-xs font-semibold text-muted">{{ optionLabels[optionIndex] || optionIndex + 1 }}.</span>
|
||||
<input
|
||||
v-model="question.options[optionIndex]"
|
||||
type="text"
|
||||
class="w-full input-field text-sm"
|
||||
:placeholder="t('admin.agent.training.optionPlaceholder')"
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
class="inline-flex h-10 w-10 items-center justify-center rounded-lg border border-red-200 bg-red-50 text-red-600 transition-colors hover:bg-red-100"
|
||||
@click="emit('removeTrainingOption', questionIndex, optionIndex)"
|
||||
>
|
||||
<Trash2 class="h-4 w-4" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
|
||||
<AgentToolRunProgressConfig
|
||||
|
||||
@@ -24,6 +24,9 @@ import {
|
||||
} from '@/features/admin/api/admin.api';
|
||||
import { listAdminSchedules } from '@/features/admin/api/schedule.api';
|
||||
import { useMessage } from '@/shared/composables/useMessage';
|
||||
import {
|
||||
resolveTrainingRoleChatQuestions,
|
||||
} from '@/features/chat/training/trainingChatQuestions';
|
||||
import type { AdminUserRow } from '@/features/admin/types/admin.types';
|
||||
import type {
|
||||
AgentFormState,
|
||||
@@ -115,21 +118,30 @@ const parseTrainingConfigFromExtra = (extra: Record<string, unknown> | undefined
|
||||
const hasTrainingContent = questionBank.length > 0
|
||||
|| Boolean(toMultilineText(merged.summary_points ?? merged.summaryPoints))
|
||||
|| Boolean(toMultilineText(merged.summary_checklist ?? merged.summaryChecklist));
|
||||
const workspaceEnabled =
|
||||
extra?.training_workspace_enabled === true
|
||||
|| extra?.training_workspace_enabled === 'true'
|
||||
|| extra?.training_mode === true
|
||||
|| extra?.training_mode === 'true'
|
||||
|| extra?.training_agent === true
|
||||
|| extra?.training_agent === 'true'
|
||||
|| hasTrainingContent;
|
||||
const employeeQuestions = resolveTrainingRoleChatQuestions(extra, 'employee');
|
||||
const hrQuestions = resolveTrainingRoleChatQuestions(extra, 'hr');
|
||||
|
||||
return {
|
||||
training_workspace_enabled:
|
||||
extra?.training_workspace_enabled === true
|
||||
|| extra?.training_workspace_enabled === 'true'
|
||||
|| extra?.training_mode === true
|
||||
|| extra?.training_mode === 'true'
|
||||
|| extra?.training_agent === true
|
||||
|| extra?.training_agent === 'true'
|
||||
|| hasTrainingContent,
|
||||
training_workspace_enabled: workspaceEnabled,
|
||||
training_pass_score: Number.isFinite(Number(merged.pass_score ?? merged.passScore))
|
||||
? Math.max(0, Math.min(100, Math.round(Number(merged.pass_score ?? merged.passScore))))
|
||||
: 90,
|
||||
training_summary_points_text: toMultilineText(merged.summary_points ?? merged.summaryPoints),
|
||||
training_summary_checklist_text: toMultilineText(merged.summary_checklist ?? merged.summaryChecklist),
|
||||
training_employee_chat_questions_text: employeeQuestions.configured || workspaceEnabled
|
||||
? toMultilineText(employeeQuestions.questions)
|
||||
: '',
|
||||
training_hr_chat_questions_text: hrQuestions.configured || workspaceEnabled
|
||||
? toMultilineText(hrQuestions.questions)
|
||||
: '',
|
||||
training_question_bank: questionBank,
|
||||
};
|
||||
};
|
||||
@@ -170,6 +182,8 @@ const hasTrainingConfigContent = (form: AgentFormState) => (
|
||||
form.training_workspace_enabled
|
||||
|| Boolean(form.training_summary_points_text.trim())
|
||||
|| Boolean(form.training_summary_checklist_text.trim())
|
||||
|| Boolean(form.training_employee_chat_questions_text.trim())
|
||||
|| Boolean(form.training_hr_chat_questions_text.trim())
|
||||
|| form.training_question_bank.length > 0
|
||||
);
|
||||
|
||||
@@ -461,6 +475,8 @@ export function useAgentsAdmin() {
|
||||
pass_score: Math.max(0, Math.min(100, Math.round(Number(form.value.training_pass_score) || 90))),
|
||||
summary_points: splitMultilineText(form.value.training_summary_points_text),
|
||||
summary_checklist: splitMultilineText(form.value.training_summary_checklist_text),
|
||||
employee_chat_suggested_questions: splitMultilineText(form.value.training_employee_chat_questions_text),
|
||||
hr_chat_suggested_questions: splitMultilineText(form.value.training_hr_chat_questions_text),
|
||||
question_bank: form.value.training_question_bank.map((question, index) => buildTrainingQuestionPayload(question, index)),
|
||||
};
|
||||
} else {
|
||||
|
||||
@@ -123,6 +123,8 @@ export interface AgentFormState {
|
||||
training_pass_score: number;
|
||||
training_summary_points_text: string;
|
||||
training_summary_checklist_text: string;
|
||||
training_employee_chat_questions_text: string;
|
||||
training_hr_chat_questions_text: string;
|
||||
training_question_bank: AgentTrainingQuestionFormItem[];
|
||||
directory_member_ids: number[];
|
||||
}
|
||||
@@ -179,6 +181,8 @@ export const createEmptyAgentForm = (
|
||||
training_pass_score: 90,
|
||||
training_summary_points_text: '',
|
||||
training_summary_checklist_text: '',
|
||||
training_employee_chat_questions_text: '',
|
||||
training_hr_chat_questions_text: '',
|
||||
training_question_bank: [],
|
||||
directory_member_ids: [],
|
||||
});
|
||||
@@ -26,6 +26,7 @@ const {
|
||||
suggestedQuestionsStyle: 'plain' | 'styled';
|
||||
styledSections: WelcomeQuestionSection[];
|
||||
suggestedQuestions: WelcomeQuestionItem[];
|
||||
hideWelcomeTitle?: boolean;
|
||||
showThinkingBubble: boolean;
|
||||
isThinking: boolean;
|
||||
showChatRating: boolean;
|
||||
@@ -104,6 +105,7 @@ const isLatestAssistantMessage = (items: ChatMessage[], index: number) => {
|
||||
:suggested-questions-style="suggestedQuestionsStyle"
|
||||
:styled-sections="styledSections"
|
||||
:suggested-questions="suggestedQuestions"
|
||||
:hide-title="hideWelcomeTitle"
|
||||
@select-question="emit('select-question', $event)"
|
||||
/>
|
||||
|
||||
|
||||
@@ -45,7 +45,8 @@ const embeddedIframeSrc = computed(() => {
|
||||
return url ? String(url) : undefined;
|
||||
});
|
||||
const canManageMaintenance = computed(() => ['admin', 'maintenance_manager'].includes(String(page.currentUser?.role || '')));
|
||||
const hideWelcomePanel = computed(() => isTrainingAgentPage.value);
|
||||
const hideWelcomePanel = computed(() => false);
|
||||
const hideWelcomeTitle = computed(() => isTrainingAgentPage.value);
|
||||
const isTrainingWorkspaceExpanded = ref(false);
|
||||
const maintenancePanel = ref<'ledger' | 'record' | null>(null);
|
||||
const maintenanceEditRecord = ref<MaintenanceRecord | null>(null);
|
||||
@@ -243,6 +244,7 @@ watch(() => page.currentAgentId, () => {
|
||||
:tool-run-progress-title="page.toolRunProgressTitle"
|
||||
:show-scroll-to-bottom="page.showScrollToBottom"
|
||||
:hide-welcome-panel="hideWelcomePanel"
|
||||
:hide-welcome-title="hideWelcomeTitle"
|
||||
:pin-messages-to-bottom="!isTrainingAgentPage"
|
||||
:scroll-container-holder="page.scrollContainerHolder"
|
||||
@copy="page.copyToClipboard($event.message, $event.index)"
|
||||
|
||||
@@ -23,6 +23,7 @@ const props = defineProps<{
|
||||
suggestedQuestionsStyle: 'plain' | 'styled';
|
||||
styledSections: WelcomeQuestionSection[];
|
||||
suggestedQuestions: WelcomeQuestionItem[];
|
||||
hideTitle?: boolean;
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
@@ -32,18 +33,19 @@ const emit = defineEmits<{
|
||||
const { t } = useI18n();
|
||||
|
||||
const displayAgentName = computed(() => props.agentName || t('chat.assistantLabel'));
|
||||
const shouldShowTitle = computed(() => !props.hideTitle);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex h-full min-h-0 w-full flex-col items-center px-4 pb-2 pt-2 md:pb-3">
|
||||
<template v-if="suggestedQuestionsStyle === 'styled' && styledSections.length > 0">
|
||||
<h2 class="mb-8 mt-12 shrink-0 text-center text-2xl font-bold text-primary md:mt-16 md:text-3xl">
|
||||
<h2 v-if="shouldShowTitle" class="mb-8 mt-12 shrink-0 text-center text-2xl font-bold text-primary md:mt-16 md:text-3xl">
|
||||
<span>{{ $t('chat.welcomeAgentTitlePrefix') }}</span>
|
||||
<span class="mx-1 text-brand-600">{{ displayAgentName }}</span>
|
||||
<span>{{ $t('chat.welcomeAgentTitleSuffix') }}</span>
|
||||
</h2>
|
||||
|
||||
<div class="min-h-0 w-full flex-1 overflow-y-auto pb-2">
|
||||
<div class="min-h-0 w-full flex-1 overflow-y-auto pb-2" :class="shouldShowTitle ? '' : 'pt-4 md:pt-8'">
|
||||
<div class="mx-auto grid w-full max-w-4xl grid-cols-1 gap-4 md:grid-cols-2">
|
||||
<div
|
||||
v-for="(section, sectionIndex) in styledSections"
|
||||
@@ -74,13 +76,13 @@ const displayAgentName = computed(() => props.agentName || t('chat.assistantLabe
|
||||
</template>
|
||||
|
||||
<template v-else-if="suggestedQuestions.length > 0">
|
||||
<h2 class="mb-8 mt-12 shrink-0 text-center text-2xl font-bold text-primary md:mt-16 md:text-3xl">
|
||||
<h2 v-if="shouldShowTitle" class="mb-8 mt-12 shrink-0 text-center text-2xl font-bold text-primary md:mt-16 md:text-3xl">
|
||||
<span>{{ $t('chat.welcomeAgentTitlePrefix') }}</span>
|
||||
<span class="mx-1 text-brand-600">{{ displayAgentName }}</span>
|
||||
<span>{{ $t('chat.welcomeAgentTitleSuffix') }}</span>
|
||||
</h2>
|
||||
|
||||
<div class="min-h-0 w-full flex-1 overflow-y-auto pb-2">
|
||||
<div class="min-h-0 w-full flex-1 overflow-y-auto pb-2" :class="shouldShowTitle ? '' : 'pt-6 md:pt-10'">
|
||||
<div class="mx-auto mt-2 flex w-full max-w-3xl flex-wrap justify-center gap-3">
|
||||
<button
|
||||
v-for="(item, index) in suggestedQuestions"
|
||||
@@ -96,7 +98,7 @@ const displayAgentName = computed(() => props.agentName || t('chat.assistantLabe
|
||||
</template>
|
||||
|
||||
<template v-else>
|
||||
<h2 class="mt-12 text-center text-2xl font-bold text-primary md:mt-16 md:text-3xl">
|
||||
<h2 v-if="shouldShowTitle" class="mt-12 text-center text-2xl font-bold text-primary md:mt-16 md:text-3xl">
|
||||
<span>{{ $t('chat.welcomeAgentTitlePrefix') }}</span>
|
||||
<span class="mx-1 text-brand-600">{{ displayAgentName }}</span>
|
||||
<span>{{ $t('chat.welcomeAgentTitleSuffix') }}</span>
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* features/chat/components/TrainingWorkspacePanel.vue
|
||||
* 用途:在培训 Agent 的聊天页顶部提供“员工培训 + 培训管理”一体化工作区。
|
||||
* 依赖:useTrainingWorkspace、lucide 图标、聊天页 currentAgent/currentUser。
|
||||
* 逻辑:只在培训 Agent 下渲染;员工角色默认直达展开工作区,管理角色保留问答视图,培训答题不再走聊天链路。
|
||||
* 逻辑:只在培训 Agent 下渲染;普通员工首次进入默认展开工作区,但新建/切换会话后保持收起,避免聊天过程中被自动展开打断。
|
||||
*/
|
||||
import { computed, reactive, ref, watch, type ShallowUnwrapRef } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
@@ -123,7 +123,8 @@ watch(
|
||||
() => props.newSessionTick,
|
||||
(tick, prevTick) => {
|
||||
if (!tick || tick === prevTick) return;
|
||||
userExpandedOverride.value = null;
|
||||
// [STEP 1] 新建对话或切换会话后统一收起工作区,避免聊天中因视图重建被自动展开。
|
||||
userExpandedOverride.value = false;
|
||||
applyDefaultExpandedState();
|
||||
},
|
||||
);
|
||||
@@ -138,7 +139,7 @@ const compactSummary = computed(() => {
|
||||
if (workspace.stage === 'summary') return t('chat.training.summary.title');
|
||||
if (workspace.stage === 'exam') {
|
||||
return t('chat.training.exam.questionCounter', {
|
||||
current: workspace.answeredCount + 1,
|
||||
current: workspace.currentQuestionNumber,
|
||||
total: workspace.totalQuestionCount,
|
||||
});
|
||||
}
|
||||
@@ -165,7 +166,15 @@ const examQuestionItems = computed(() => Array.from({ length: workspace.totalQue
|
||||
const canNavigateExamQuestions = computed(() => workspace.stage === 'exam');
|
||||
const jumpToExamQuestion = (index: number) => {
|
||||
if (!canNavigateExamQuestions.value) return;
|
||||
workspace.currentQuestionIndex = index;
|
||||
workspace.syncExamQuestionIndex(index);
|
||||
};
|
||||
const canSwitchToStage = (stageKey: string) => {
|
||||
if (stageKey !== 'result') return true;
|
||||
return workspace.canEnterResultStage;
|
||||
};
|
||||
const handleStageCardClick = (stageKey: string) => {
|
||||
if (!canSwitchToStage(stageKey)) return;
|
||||
workspace.stage = stageKey as typeof workspace.stage;
|
||||
};
|
||||
</script>
|
||||
|
||||
@@ -333,16 +342,10 @@ const jumpToExamQuestion = (index: number) => {
|
||||
<div class="truncate text-sm font-semibold text-primary">
|
||||
{{ compactSummary }}
|
||||
</div>
|
||||
<div class="mt-1 text-xs leading-5 text-secondary">
|
||||
<template v-if="workspace.activeView === 'admin'">
|
||||
{{ $t('chat.training.hr.filters.keywordLabel') }}: {{ workspace.hrKeyword || $t('chat.training.hr.filters.noLimit') }}
|
||||
· {{ $t('chat.training.hr.filters.departmentLabel') }}:
|
||||
{{ workspace.hrDepartmentFilter === 'all' ? $t('chat.training.hr.filters.allDepartments') : workspace.hrDepartmentFilter }}
|
||||
</template>
|
||||
<template v-else>
|
||||
{{ $t('chat.training.progressPercent') }}: {{ workspace.learnerProgressPercent }}%
|
||||
· {{ $t('chat.training.learnerCard.name') }}: {{ workspace.currentUserName }}
|
||||
</template>
|
||||
<div v-if="workspace.activeView === 'admin'" class="mt-1 text-xs leading-5 text-secondary">
|
||||
{{ $t('chat.training.hr.filters.keywordLabel') }}: {{ workspace.hrKeyword || $t('chat.training.hr.filters.noLimit') }}
|
||||
· {{ $t('chat.training.hr.filters.departmentLabel') }}:
|
||||
{{ workspace.hrDepartmentFilter === 'all' ? $t('chat.training.hr.filters.allDepartments') : workspace.hrDepartmentFilter }}
|
||||
</div>
|
||||
<div
|
||||
v-if="workspace.activeView === 'learner'"
|
||||
@@ -387,8 +390,11 @@ const jumpToExamQuestion = (index: number) => {
|
||||
v-for="(item, index) in stageItems"
|
||||
:key="item.key"
|
||||
class="rounded-xl border px-3 py-2.5 transition cursor-pointer hover:border-brand-300"
|
||||
:class="stageStep >= index + 1 ? 'border-brand-200 bg-brand-50/70' : 'border-default bg-surface-soft/70'"
|
||||
@click="workspace.stage = item.key as any"
|
||||
:class="[
|
||||
stageStep >= index + 1 ? 'border-brand-200 bg-brand-50/70' : 'border-default bg-surface-soft/70',
|
||||
canSwitchToStage(String(item.key)) ? 'cursor-pointer hover:border-brand-300' : 'cursor-not-allowed opacity-60',
|
||||
]"
|
||||
@click="handleStageCardClick(String(item.key))"
|
||||
>
|
||||
<div class="flex items-center gap-2">
|
||||
<div
|
||||
@@ -492,7 +498,7 @@ const jumpToExamQuestion = (index: number) => {
|
||||
{{ $t('chat.training.exam.title') }}
|
||||
</div>
|
||||
<h3 class="mt-1 text-lg font-semibold text-primary">
|
||||
{{ $t('chat.training.exam.questionCounter', { current: workspace.answeredCount + 1, total: workspace.totalQuestionCount }) }}
|
||||
{{ $t('chat.training.exam.questionCounter', { current: workspace.currentQuestionNumber, total: workspace.totalQuestionCount }) }}
|
||||
</h3>
|
||||
</div>
|
||||
<div class="flex flex-wrap gap-2 text-sm text-secondary">
|
||||
@@ -528,7 +534,6 @@ const jumpToExamQuestion = (index: number) => {
|
||||
? 'border-emerald-300 bg-emerald-50 text-emerald-700'
|
||||
: 'border-default bg-white text-secondary hover:border-brand-200 hover:bg-brand-50/40',
|
||||
]"
|
||||
:disabled="workspace.answerLocked"
|
||||
@click="workspace.selectAnswer(option.id)"
|
||||
>
|
||||
<div class="flex items-start justify-between gap-3">
|
||||
@@ -564,12 +569,12 @@ const jumpToExamQuestion = (index: number) => {
|
||||
<button
|
||||
type="button"
|
||||
class="inline-flex items-center gap-2 rounded-xl bg-brand-600 px-4 py-2.5 text-sm font-medium text-white transition hover:bg-brand-700"
|
||||
@click="workspace.moveToNextQuestion"
|
||||
@click="workspace.examReadyToSubmit ? workspace.submitExam() : workspace.moveToNextQuestion()"
|
||||
>
|
||||
<ClipboardCheck class="h-4 w-4" />
|
||||
{{
|
||||
workspace.answeredCount >= workspace.totalQuestionCount
|
||||
? $t('chat.training.exam.finishExam')
|
||||
workspace.examReadyToSubmit
|
||||
? $t('chat.training.exam.submitPaper')
|
||||
: $t('chat.training.exam.nextQuestion')
|
||||
}}
|
||||
</button>
|
||||
|
||||
@@ -138,7 +138,7 @@ const emit = defineEmits<{
|
||||
? 'border-emerald-200 bg-emerald-50/50 text-emerald-600'
|
||||
: 'border-slate-200 bg-white text-slate-600 hover:border-brand-200 hover:bg-brand-50/30 hover:text-brand-700',
|
||||
]"
|
||||
:disabled="answerLocked || isThinking"
|
||||
:disabled="isThinking"
|
||||
@click="emit('select', option.id)"
|
||||
>
|
||||
<span class="font-medium">{{ option.label }}</span>
|
||||
|
||||
@@ -12,6 +12,7 @@ import {
|
||||
type AgentRegistryFields,
|
||||
} from '@/shared/utils/agent-registry.utils';
|
||||
import { matchesTrainingAgent } from '../training/trainingWorkspace.utils';
|
||||
import { resolveTrainingRoleChatQuestions } from '../training/trainingChatQuestions';
|
||||
import type { ChatDeps } from './chat.deps';
|
||||
import type { UseChatGuidesReturn } from './useChatGuides';
|
||||
|
||||
@@ -26,13 +27,6 @@ const ERP_KB = 'ERP知识库';
|
||||
const TRAINING_AGENT_DESCRIPTION =
|
||||
'我是你的新人培训助手,会在同一个聊天页面内带你完成视频学习、知识点复盘、逐题考试和结果复盘。';
|
||||
|
||||
const TRAINING_AGENT_QUESTIONS: AgentSuggestedQuestionItem[] = [
|
||||
{ question: '这次员工培训主要学习什么内容?', group: '培训问答' },
|
||||
{ question: '员工培训的通过规则是什么?', group: '培训问答' },
|
||||
{ question: '这次培训的试题范围有哪些?', group: '培训问答' },
|
||||
{ question: '培训记录会如何统计?', group: '培训问答' },
|
||||
];
|
||||
|
||||
const normalizeAgentSuggestedQuestions = (value: unknown): AgentSuggestedQuestionItem[] => {
|
||||
if (!Array.isArray(value)) return [];
|
||||
return value
|
||||
@@ -53,11 +47,12 @@ const normalizeAgentSuggestedQuestions = (value: unknown): AgentSuggestedQuestio
|
||||
export interface UseChatAgentOptions {
|
||||
deps: ChatDeps;
|
||||
currentAgentId: ComputedRef<number>;
|
||||
currentUser: ComputedRef<Record<string, unknown> | null>;
|
||||
chatGuides: Pick<UseChatGuidesReturn, 'loadGuides' | 'clearGuides'>;
|
||||
}
|
||||
|
||||
export function useChatAgent(options: UseChatAgentOptions) {
|
||||
const { deps, currentAgentId, chatGuides } = options;
|
||||
const { deps, currentAgentId, currentUser, chatGuides } = options;
|
||||
const { t, msg, router } = deps;
|
||||
|
||||
const currentAgent = ref<AgentRegistryFields | null>(null);
|
||||
@@ -98,6 +93,10 @@ export function useChatAgent(options: UseChatAgentOptions) {
|
||||
: kbOptions.filter((option) => option !== ERP_KB)
|
||||
));
|
||||
const kbDropdownDisabled = computed(() => availableKbOptions.value.length <= 1);
|
||||
const isTrainingAdminViewer = computed(() => Boolean(
|
||||
(currentUser.value as { feature_permissions?: { training_hr_manage?: boolean } } | null)
|
||||
?.feature_permissions?.training_hr_manage,
|
||||
));
|
||||
|
||||
watch(canSelectErpKnowledgeBase, (allowed) => {
|
||||
if (allowed) {
|
||||
@@ -129,8 +128,18 @@ export function useChatAgent(options: UseChatAgentOptions) {
|
||||
const configured = normalizeAgentSuggestedQuestions(
|
||||
currentAgent.value?.suggested_questions,
|
||||
);
|
||||
if (matchesTrainingAgent(currentAgent.value)) {
|
||||
const roleQuestions = resolveTrainingRoleChatQuestions(
|
||||
currentAgent.value?.extra_config,
|
||||
isTrainingAdminViewer.value ? 'hr' : 'employee',
|
||||
);
|
||||
if (roleQuestions.configured) {
|
||||
return roleQuestions.questions.map((question) => ({ question, group: '' }));
|
||||
}
|
||||
if (configured.length > 0) return configured;
|
||||
return roleQuestions.questions.map((question) => ({ question, group: '' }));
|
||||
}
|
||||
if (configured.length > 0) return configured;
|
||||
if (matchesTrainingAgent(currentAgent.value)) return TRAINING_AGENT_QUESTIONS;
|
||||
return [];
|
||||
});
|
||||
|
||||
|
||||
@@ -149,7 +149,7 @@ export function useChatPage() {
|
||||
};
|
||||
|
||||
const chatGuides = useChatGuides({ currentAgentId });
|
||||
const agent = useChatAgent({ deps, currentAgentId, chatGuides });
|
||||
const agent = useChatAgent({ deps, currentAgentId, currentUser: computed(() => currentUser.value), chatGuides });
|
||||
const attachmentApi = useChatAttachments({
|
||||
deps,
|
||||
currentAgentId,
|
||||
|
||||
@@ -199,10 +199,20 @@ export function useTrainingWorkspace(options: UseTrainingWorkspaceOptions) {
|
||||
|
||||
const currentQuestion = computed(() => questionBank.value[currentQuestionIndex.value] || null);
|
||||
const totalQuestionCount = computed(() => questionBank.value.length);
|
||||
const currentQuestionNumber = computed(() => {
|
||||
if (totalQuestionCount.value <= 0) return 0;
|
||||
return Math.min(currentQuestionIndex.value + 1, totalQuestionCount.value);
|
||||
});
|
||||
const answeredCount = computed(() => answerRecords.value.length);
|
||||
const correctCount = computed(() => answerRecords.value.filter((item) => item.correct).length);
|
||||
const wrongCount = computed(() => answerRecords.value.filter((item) => !item.correct).length);
|
||||
const isPassed = computed(() => score.value >= passScore.value);
|
||||
const examReadyToSubmit = computed(() => (
|
||||
stage.value === 'exam'
|
||||
&& totalQuestionCount.value > 0
|
||||
&& answeredCount.value >= totalQuestionCount.value
|
||||
));
|
||||
const canEnterResultStage = computed(() => stage.value === 'result');
|
||||
|
||||
const learnerProgressPercent = computed(() => {
|
||||
if (stage.value === 'video') return 25;
|
||||
@@ -295,6 +305,29 @@ export function useTrainingWorkspace(options: UseTrainingWorkspaceOptions) {
|
||||
].join('\n');
|
||||
};
|
||||
|
||||
/**
|
||||
* 基于当前答题记录重算成绩,保证“修改答案”后分数与结果页口径一致。
|
||||
* AI 触发时机:当培训考试支持点击题号返回修改答案时,不能再用“上一题答对就直接 +1”的增量算法。
|
||||
*/
|
||||
const recalculateScoreFromAnswers = (records: TrainingAnswerRecord[]) => calculateTrainingScore(
|
||||
records.filter((item) => item.correct).length,
|
||||
totalQuestionCount.value,
|
||||
);
|
||||
|
||||
/**
|
||||
* 覆盖或新增当前题的作答记录,避免同一道题在进度里出现重复答案。
|
||||
* AI 触发时机:当员工返回已答题修改答案时,必须覆盖旧答案而不是重复追加,否则分数和已答题数都会失真。
|
||||
*/
|
||||
const upsertAnswerRecord = (nextRecord: TrainingAnswerRecord) => {
|
||||
const existingIndex = answerRecords.value.findIndex((item) => item.questionId === nextRecord.questionId);
|
||||
if (existingIndex >= 0) {
|
||||
answerRecords.value.splice(existingIndex, 1, nextRecord);
|
||||
return true;
|
||||
}
|
||||
answerRecords.value.push(nextRecord);
|
||||
return false;
|
||||
};
|
||||
|
||||
const syncAnswerStateForCurrentQuestion = () => {
|
||||
const questionId = currentQuestion.value?.id;
|
||||
const currentAnswer = questionId
|
||||
@@ -305,6 +338,21 @@ export function useTrainingWorkspace(options: UseTrainingWorkspaceOptions) {
|
||||
currentFeedbackCorrect.value = Boolean(currentAnswer?.correct);
|
||||
};
|
||||
|
||||
/**
|
||||
* 切换考试题目时,同步左侧题干、已答状态和反馈展示。
|
||||
* AI 触发时机:当员工点击右侧题号导航或后端恢复考试进度时,必须保证“当前题序号、选中项、答题对错反馈”完全一致。
|
||||
*/
|
||||
const syncExamQuestionIndex = (nextIndex: number) => {
|
||||
if (totalQuestionCount.value <= 0) {
|
||||
currentQuestionIndex.value = 0;
|
||||
syncAnswerStateForCurrentQuestion();
|
||||
return;
|
||||
}
|
||||
const normalizedIndex = Math.min(Math.max(nextIndex, 0), totalQuestionCount.value - 1);
|
||||
currentQuestionIndex.value = normalizedIndex;
|
||||
syncAnswerStateForCurrentQuestion();
|
||||
};
|
||||
|
||||
const applyProgressRecord = (record: TrainingProgressRecord | null) => {
|
||||
if (!record) {
|
||||
stage.value = 'video';
|
||||
@@ -314,7 +362,7 @@ export function useTrainingWorkspace(options: UseTrainingWorkspaceOptions) {
|
||||
return;
|
||||
}
|
||||
stage.value = record.stage;
|
||||
currentQuestionIndex.value = record.currentQuestionIndex;
|
||||
syncExamQuestionIndex(record.currentQuestionIndex);
|
||||
score.value = Number(record.score || 0);
|
||||
attemptCount.value = Number(record.attempts || 0);
|
||||
answerRecords.value = Array.isArray(record.answerDetails) ? record.answerDetails : [];
|
||||
@@ -506,42 +554,42 @@ export function useTrainingWorkspace(options: UseTrainingWorkspaceOptions) {
|
||||
void persistProgress();
|
||||
};
|
||||
|
||||
/**
|
||||
* 记录当前题答案;首次作答沿用自动推进,回看题目时则覆盖旧答案并实时重算分数。
|
||||
* AI 触发时机:当员工在逐题考试阶段点击右侧题号返回某题时,需要允许直接改答且不破坏“提交答卷后才结算”的流程。
|
||||
*/
|
||||
const selectAnswer = (optionId: string) => {
|
||||
if (answerLocked.value || !currentQuestion.value) return;
|
||||
if (!currentQuestion.value) return;
|
||||
const answeredQuestion = currentQuestion.value;
|
||||
const hadExistingAnswer = answerRecords.value.some((item) => item.questionId === answeredQuestion.id);
|
||||
selectedOptionId.value = optionId;
|
||||
answerLocked.value = true;
|
||||
const isCorrect = optionId === answeredQuestion.answer;
|
||||
currentFeedbackCorrect.value = isCorrect;
|
||||
const nextCorrectAnswerCount = correctCount.value + (isCorrect ? 1 : 0);
|
||||
const nextScore = calculateTrainingScore(nextCorrectAnswerCount, totalQuestionCount.value);
|
||||
score.value = nextScore;
|
||||
const answerRecord: TrainingAnswerRecord = {
|
||||
questionId: answeredQuestion.id,
|
||||
selectedOptionId: optionId,
|
||||
correct: isCorrect,
|
||||
};
|
||||
answerRecords.value.push(answerRecord);
|
||||
upsertAnswerRecord(answerRecord);
|
||||
const nextScore = recalculateScoreFromAnswers(answerRecords.value);
|
||||
score.value = nextScore;
|
||||
latestExamFeedback.value = buildExamFeedback(answeredQuestion, answerRecord, nextScore);
|
||||
|
||||
// [STEP 1] 最后一题直接进入结算,对齐文档里的“答完即公布最终成绩”。
|
||||
if (currentQuestionIndex.value >= totalQuestionCount.value - 1) {
|
||||
stage.value = 'result';
|
||||
completionDate.value = formatDate(new Date());
|
||||
latestSettledResult.value = {
|
||||
score: nextScore,
|
||||
correctCount: answerRecords.value.filter((item) => item.correct).length,
|
||||
wrongCount: answerRecords.value.filter((item) => !item.correct).length,
|
||||
isPassed: nextScore >= passScore.value,
|
||||
};
|
||||
// [STEP 1] 已答题被回看并改答时,停留在当前题,方便继续检查或跳到其他题。
|
||||
if (hadExistingAnswer) {
|
||||
void persistProgress();
|
||||
return;
|
||||
}
|
||||
|
||||
// [STEP 2] 非最后一题则在聊天流里自动反馈上一题,并紧接着展示下一题。
|
||||
currentQuestionIndex.value += 1;
|
||||
selectedOptionId.value = '';
|
||||
answerLocked.value = false;
|
||||
currentFeedbackCorrect.value = false;
|
||||
// [STEP 2] 最后一题首次答完后先停留在考试阶段,必须点击“提交答卷”才能进入结算结果。
|
||||
if (currentQuestionIndex.value >= totalQuestionCount.value - 1) {
|
||||
void persistProgress();
|
||||
return;
|
||||
}
|
||||
|
||||
// [STEP 3] 首次作答且不是最后一题时,自动推进到下一题。
|
||||
syncExamQuestionIndex(currentQuestionIndex.value + 1);
|
||||
void persistProgress();
|
||||
};
|
||||
|
||||
@@ -552,19 +600,30 @@ export function useTrainingWorkspace(options: UseTrainingWorkspaceOptions) {
|
||||
const moveToNextQuestion = () => {
|
||||
if (!answerLocked.value) return;
|
||||
if (currentQuestionIndex.value >= totalQuestionCount.value - 1) {
|
||||
stage.value = 'result';
|
||||
completionDate.value = formatDate(new Date());
|
||||
void persistProgress();
|
||||
return;
|
||||
}
|
||||
currentQuestionIndex.value += 1;
|
||||
selectedOptionId.value = '';
|
||||
answerLocked.value = false;
|
||||
currentFeedbackCorrect.value = false;
|
||||
syncExamQuestionIndex(currentQuestionIndex.value + 1);
|
||||
latestExamFeedback.value = null;
|
||||
void persistProgress();
|
||||
};
|
||||
|
||||
/**
|
||||
* 统一提交整份答卷并进入结算结果。
|
||||
* AI 触发时机:当员工已完成全部题目但尚未结算时,必须显式点击“提交答卷”后才允许进入第 4 阶段。
|
||||
*/
|
||||
const submitExam = () => {
|
||||
if (!examReadyToSubmit.value) return;
|
||||
stage.value = 'result';
|
||||
completionDate.value = formatDate(new Date());
|
||||
latestSettledResult.value = {
|
||||
score: score.value,
|
||||
correctCount: answerRecords.value.filter((item) => item.correct).length,
|
||||
wrongCount: answerRecords.value.filter((item) => !item.correct).length,
|
||||
isPassed: score.value >= passScore.value,
|
||||
};
|
||||
void persistProgress();
|
||||
};
|
||||
|
||||
const restartExam = () => {
|
||||
stage.value = 'video';
|
||||
resetExamState();
|
||||
@@ -645,6 +704,7 @@ export function useTrainingWorkspace(options: UseTrainingWorkspaceOptions) {
|
||||
activeView,
|
||||
stage,
|
||||
currentQuestionIndex,
|
||||
currentQuestionNumber,
|
||||
currentQuestion,
|
||||
totalQuestionCount,
|
||||
passScore,
|
||||
@@ -654,6 +714,8 @@ export function useTrainingWorkspace(options: UseTrainingWorkspaceOptions) {
|
||||
selectedOptionId,
|
||||
answerLocked,
|
||||
currentFeedbackCorrect,
|
||||
examReadyToSubmit,
|
||||
canEnterResultStage,
|
||||
latestExamFeedback,
|
||||
latestSettledResult,
|
||||
answerRecords,
|
||||
@@ -681,7 +743,9 @@ export function useTrainingWorkspace(options: UseTrainingWorkspaceOptions) {
|
||||
markVideoCompleted,
|
||||
startExam,
|
||||
selectAnswer,
|
||||
syncExamQuestionIndex,
|
||||
moveToNextQuestion,
|
||||
submitExam,
|
||||
restartExam,
|
||||
exportRecords,
|
||||
showVideoModal,
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
/**
|
||||
* features/chat/training/trainingChatQuestions.ts
|
||||
* 用途:统一维护员工培训 Agent 的员工版 / HR 版聊天常见问题默认值与解析逻辑。
|
||||
* 依赖:被 Admin 后台培训配置表单与 Chat 欢迎区共同引用,避免默认问题与字段名出现多份散落副本。
|
||||
* 逻辑:优先读取 extra_config.training_config 中的角色化问题列表;未配置时回退到内置示例,显式保存空数组时尊重为空。
|
||||
*/
|
||||
|
||||
export type TrainingChatQuestionRole = 'employee' | 'hr';
|
||||
|
||||
const TRAINING_ROLE_QUESTION_KEYS: Record<TrainingChatQuestionRole, string[]> = {
|
||||
employee: ['employee_chat_suggested_questions', 'learner_chat_suggested_questions'],
|
||||
hr: ['hr_chat_suggested_questions', 'admin_chat_suggested_questions'],
|
||||
};
|
||||
|
||||
export const DEFAULT_TRAINING_EMPLOYEE_CHAT_QUESTIONS = [
|
||||
'这次员工培训主要学习什么内容?',
|
||||
'完成培训需要经过哪些步骤?',
|
||||
'员工培训的通过规则是什么?',
|
||||
'开始考试前需要注意什么?',
|
||||
];
|
||||
|
||||
export const DEFAULT_TRAINING_HR_CHAT_QUESTIONS = [
|
||||
'现在有多少人参加了培训?',
|
||||
'当前培训通过率是多少?',
|
||||
'哪些员工还没有完成培训?',
|
||||
'我想查看本月培训成绩统计',
|
||||
];
|
||||
|
||||
const asRecord = (value: unknown): Record<string, unknown> => (
|
||||
value && typeof value === 'object' && !Array.isArray(value)
|
||||
? value as Record<string, unknown>
|
||||
: {}
|
||||
);
|
||||
|
||||
const cloneQuestions = (questions: string[]) => questions.map((item) => String(item || '').trim()).filter(Boolean);
|
||||
|
||||
/**
|
||||
* 归一化后台保存的常见问题数组。
|
||||
* AI 触发时机:培训配置允许 string[] 与 { question }[] 混存时,需要统一还原成纯文本列表供表单和聊天欢迎区复用。
|
||||
*/
|
||||
const normalizeTrainingChatQuestionList = (value: unknown): string[] => {
|
||||
if (!Array.isArray(value)) return [];
|
||||
return value
|
||||
.map((item) => {
|
||||
if (typeof item === 'string') return item.trim();
|
||||
if (!item || typeof item !== 'object') return '';
|
||||
return String((item as Record<string, unknown>).question || (item as Record<string, unknown>).text || '').trim();
|
||||
})
|
||||
.filter(Boolean);
|
||||
};
|
||||
|
||||
const getDefaultQuestions = (role: TrainingChatQuestionRole) => (
|
||||
role === 'hr'
|
||||
? cloneQuestions(DEFAULT_TRAINING_HR_CHAT_QUESTIONS)
|
||||
: cloneQuestions(DEFAULT_TRAINING_EMPLOYEE_CHAT_QUESTIONS)
|
||||
);
|
||||
|
||||
/**
|
||||
* 读取培训配置中的角色化聊天常见问题。
|
||||
* AI 触发时机:员工培训 Agent 需要按当前用户角色切换欢迎区问题时,必须先判断后台是否显式配置该角色问题,再决定是否回退默认示例。
|
||||
*/
|
||||
export const resolveTrainingRoleChatQuestions = (
|
||||
extraConfig: unknown,
|
||||
role: TrainingChatQuestionRole,
|
||||
): { configured: boolean; questions: string[] } => {
|
||||
const trainingConfig = asRecord(asRecord(extraConfig).training_config);
|
||||
const keys = TRAINING_ROLE_QUESTION_KEYS[role];
|
||||
const matchedKey = keys.find((key) => Object.prototype.hasOwnProperty.call(trainingConfig, key));
|
||||
if (!matchedKey) {
|
||||
return {
|
||||
configured: false,
|
||||
questions: getDefaultQuestions(role),
|
||||
};
|
||||
}
|
||||
return {
|
||||
configured: true,
|
||||
questions: normalizeTrainingChatQuestionList(trainingConfig[matchedKey]),
|
||||
};
|
||||
};
|
||||
@@ -283,6 +283,12 @@
|
||||
"summaryPointsPlaceholder": "One item per line, for example: Salary is paid on the 15th of each month",
|
||||
"summaryChecklist": "Must know before the exam",
|
||||
"summaryChecklistPlaceholder": "One item per line, for example: Scores below 90 require a retake",
|
||||
"employeeChatQuestions": "Employee chat questions",
|
||||
"employeeChatQuestionsPlaceholder": "One question per line, for example: What are the passing rules for this training?",
|
||||
"employeeChatQuestionsHint": "When a normal employee opens the employee training chat page, these questions are shown first.",
|
||||
"hrChatQuestions": "HR chat questions",
|
||||
"hrChatQuestionsPlaceholder": "One question per line, for example: Which employees have not completed the training yet?",
|
||||
"hrChatQuestionsHint": "When a user with training management permission opens the employee training chat page, these questions are shown first.",
|
||||
"questionBank": "Question bank",
|
||||
"questionHint": "Supports single choice and true or false questions. Employees will use the updated bank immediately after saving.",
|
||||
"emptyQuestionBank": "No question bank configured yet. The employee view will fall back to the default bank.",
|
||||
|
||||
@@ -526,6 +526,7 @@
|
||||
"selectedAnswer": "Your answer: {answer}",
|
||||
"correctAnswer": "Correct answer: {answer}",
|
||||
"nextQuestion": "Next Question",
|
||||
"submitPaper": "Submit Paper",
|
||||
"finishExam": "Finish Exam"
|
||||
},
|
||||
"result": {
|
||||
@@ -551,7 +552,7 @@
|
||||
},
|
||||
"examQuestionCard": {
|
||||
"title": "Exam Questions",
|
||||
"hint": "Shows all question numbers. They become clickable only during the step-by-step exam stage."
|
||||
"hint": "Shows all question numbers. They become clickable only during the step-by-step exam stage, and answered questions can be revisited and changed."
|
||||
},
|
||||
"rules": {
|
||||
"title": "Exam rules",
|
||||
|
||||
@@ -283,6 +283,12 @@
|
||||
"summaryPointsPlaceholder": "หนึ่งบรรทัดต่อหนึ่งข้อ เช่น เงินเดือนจ่ายทุกวันที่ 15",
|
||||
"summaryChecklist": "สิ่งที่ต้องรู้ก่อนสอบ",
|
||||
"summaryChecklistPlaceholder": "หนึ่งบรรทัดต่อหนึ่งข้อ เช่น คะแนนต่ำกว่า 90 ต้องสอบใหม่",
|
||||
"employeeChatQuestions": "คำถามแนะนำสำหรับพนักงาน",
|
||||
"employeeChatQuestionsPlaceholder": "หนึ่งคำถามต่อหนึ่งบรรทัด เช่น เกณฑ์ผ่านของการอบรมนี้คืออะไร?",
|
||||
"employeeChatQuestionsHint": "เมื่อพนักงานทั่วไปเปิดหน้าแชตการอบรมพนักงาน ระบบจะแสดงคำถามชุดนี้ก่อน",
|
||||
"hrChatQuestions": "คำถามแนะนำสำหรับ HR",
|
||||
"hrChatQuestionsPlaceholder": "หนึ่งคำถามต่อหนึ่งบรรทัด เช่น ยังมีพนักงานคนใดที่ยังไม่จบการอบรมบ้าง?",
|
||||
"hrChatQuestionsHint": "เมื่อผู้ใช้ที่มีสิทธิ์จัดการอบรมเปิดหน้าแชตการอบรมพนักงาน ระบบจะแสดงคำถามชุดนี้ก่อน",
|
||||
"questionBank": "คลังข้อสอบ",
|
||||
"questionHint": "รองรับข้อสอบแบบปรนัยและถูกหรือผิด หลังบันทึกแล้วพนักงานจะใช้ชุดข้อสอบใหม่นี้ทันที",
|
||||
"emptyQuestionBank": "ยังไม่ได้ตั้งค่าคลังข้อสอบ ฝั่งพนักงานจะใช้คลังข้อสอบเริ่มต้นแทน",
|
||||
|
||||
@@ -526,6 +526,7 @@
|
||||
"selectedAnswer": "คำตอบของคุณ: {answer}",
|
||||
"correctAnswer": "คำตอบที่ถูกต้อง: {answer}",
|
||||
"nextQuestion": "ข้อถัดไป",
|
||||
"submitPaper": "ส่งข้อสอบ",
|
||||
"finishExam": "จบการสอบ"
|
||||
},
|
||||
"result": {
|
||||
@@ -551,7 +552,7 @@
|
||||
},
|
||||
"examQuestionCard": {
|
||||
"title": "ข้อสอบ",
|
||||
"hint": "แสดงหมายเลขข้อทั้งหมด และจะกดได้เฉพาะในขั้นตอนสอบทีละข้อเท่านั้น"
|
||||
"hint": "แสดงหมายเลขข้อทั้งหมด และจะกดได้เฉพาะในขั้นตอนสอบทีละข้อเท่านั้น พร้อมรองรับการย้อนกลับไปแก้คำตอบ"
|
||||
},
|
||||
"rules": {
|
||||
"title": "กติกาการสอบ",
|
||||
|
||||
@@ -284,6 +284,12 @@
|
||||
"summaryPointsPlaceholder": "每行一条,例如:工资每月 15 号发放",
|
||||
"summaryChecklist": "考前必知",
|
||||
"summaryChecklistPlaceholder": "每行一条,例如:低于 90 分必须重新考试",
|
||||
"employeeChatQuestions": "员工聊天常见问题",
|
||||
"employeeChatQuestionsPlaceholder": "每行一个问题,例如:员工培训的通过规则是什么?",
|
||||
"employeeChatQuestionsHint": "普通员工进入员工培训聊天页时,会优先看到这里配置的常见问题。",
|
||||
"hrChatQuestions": "HR聊天常见问题",
|
||||
"hrChatQuestionsPlaceholder": "每行一个问题,例如:哪些员工还没有完成培训?",
|
||||
"hrChatQuestionsHint": "拥有培训管理权限的 HR 进入员工培训聊天页时,会优先看到这里配置的常见问题。",
|
||||
"questionBank": "题库",
|
||||
"questionHint": "支持单选题和判断题;保存后员工考试会即时使用新的题库。",
|
||||
"emptyQuestionBank": "暂未配置题库,员工端会回退到默认题库。",
|
||||
|
||||
@@ -526,6 +526,7 @@
|
||||
"selectedAnswer": "你的答案:{answer}",
|
||||
"correctAnswer": "正确答案:{answer}",
|
||||
"nextQuestion": "下一题",
|
||||
"submitPaper": "提交答卷",
|
||||
"finishExam": "完成考试"
|
||||
},
|
||||
"result": {
|
||||
@@ -551,7 +552,7 @@
|
||||
},
|
||||
"examQuestionCard": {
|
||||
"title": "考试题目",
|
||||
"hint": "展示全部题目序号;仅在“逐题考试”阶段可点击切换。"
|
||||
"hint": "展示全部题目序号;仅在“逐题考试”阶段可点击切换,并支持返回修改答案。"
|
||||
},
|
||||
"rules": {
|
||||
"title": "考试规则",
|
||||
|
||||
@@ -283,6 +283,12 @@
|
||||
"summaryPointsPlaceholder": "每行一條,例如:工資每月 15 號發放",
|
||||
"summaryChecklist": "考前必知",
|
||||
"summaryChecklistPlaceholder": "每行一條,例如:低於 90 分必須重新考試",
|
||||
"employeeChatQuestions": "員工聊天常見問題",
|
||||
"employeeChatQuestionsPlaceholder": "每行一個問題,例如:員工培訓的通過規則是什麼?",
|
||||
"employeeChatQuestionsHint": "普通員工進入員工培訓聊天頁時,會優先看到這裡配置的常見問題。",
|
||||
"hrChatQuestions": "HR聊天常見問題",
|
||||
"hrChatQuestionsPlaceholder": "每行一個問題,例如:哪些員工還沒有完成培訓?",
|
||||
"hrChatQuestionsHint": "擁有培訓管理權限的 HR 進入員工培訓聊天頁時,會優先看到這裡配置的常見問題。",
|
||||
"questionBank": "題庫",
|
||||
"questionHint": "支援單選題和判斷題;保存後員工考試會即時使用新的題庫。",
|
||||
"emptyQuestionBank": "暫未配置題庫,員工端會回退到預設題庫。",
|
||||
|
||||
@@ -526,6 +526,7 @@
|
||||
"selectedAnswer": "你的答案:{answer}",
|
||||
"correctAnswer": "正確答案:{answer}",
|
||||
"nextQuestion": "下一題",
|
||||
"submitPaper": "提交答卷",
|
||||
"finishExam": "完成考試"
|
||||
},
|
||||
"result": {
|
||||
@@ -551,7 +552,7 @@
|
||||
},
|
||||
"examQuestionCard": {
|
||||
"title": "考試題目",
|
||||
"hint": "顯示全部題目序號;僅在「逐題考試」階段可點擊切換。"
|
||||
"hint": "展示全部題目序號;僅在“逐題考試”階段可點擊切換,並支援返回修改答案。"
|
||||
},
|
||||
"rules": {
|
||||
"title": "考試規則",
|
||||
|
||||
Reference in new issue
Block a user