feat(chat-training): 优化员工培训agent工作区交互
This commit is contained in:
1 parent
37e08c83d8
commit
5bef77f86c
10 files changed
+126
-165
No files matched your search
@@ -1,9 +1,9 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* features/chat/components/TrainingWorkspacePanel.vue
|
||||
* 用途:在培训 Agent 的聊天页顶部提供“学员考试流 + HR 管理流”一体化工作区。
|
||||
* 用途:在培训 Agent 的聊天页顶部提供“员工培训 + 培训管理”一体化工作区。
|
||||
* 依赖:useTrainingWorkspace、lucide 图标、聊天页 currentAgent/currentUser。
|
||||
* 逻辑:只在培训 Agent 下渲染;学员端负责前端交互闭环,HR 端负责本地筛选统计与 Excel 导出,并可把上下文同步回聊天区。
|
||||
* 逻辑:只在培训 Agent 下渲染;员工角色默认直达展开工作区,管理角色保留问答视图,培训答题不再走聊天链路。
|
||||
*/
|
||||
import { computed, reactive, ref, watch, type ShallowUnwrapRef } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
@@ -18,7 +18,6 @@ import {
|
||||
RefreshCcw,
|
||||
ShieldCheck,
|
||||
Target,
|
||||
Users,
|
||||
XCircle,
|
||||
} from 'lucide-vue-next';
|
||||
import { useTrainingWorkspace } from '@/features/chat/composables/useTrainingWorkspace';
|
||||
@@ -28,13 +27,11 @@ const props = defineProps<{
|
||||
currentAgent: Record<string, unknown> | null;
|
||||
currentUser: Record<string, unknown> | null;
|
||||
agentGuides: TrainingGuideLike[];
|
||||
hasMessages: boolean;
|
||||
newSessionTick: number;
|
||||
training: ShallowUnwrapRef<ReturnType<typeof useTrainingWorkspace>>;
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
'push-local-assistant-message': [content: string];
|
||||
'open-guide': [guideId?: number];
|
||||
'update:expanded': [expanded: boolean];
|
||||
}>();
|
||||
@@ -64,7 +61,8 @@ const stageItems = computed(() => ([
|
||||
{ key: 'result', label: 'chat.training.steps.result', icon: ShieldCheck },
|
||||
]));
|
||||
|
||||
const userExpandedOverride = ref(false);
|
||||
const userExpandedOverride = ref<boolean | null>(null);
|
||||
const shouldDefaultExpanded = computed(() => workspace.isTrainingAgent && !workspace.isAdminViewer);
|
||||
|
||||
const handleVideoTimeUpdate = (e: Event) => {
|
||||
const video = e.target as HTMLVideoElement;
|
||||
@@ -91,7 +89,7 @@ const setWorkspaceExpanded = (expanded: boolean, manual = false) => {
|
||||
if (manual) {
|
||||
userExpandedOverride.value = expanded;
|
||||
} else if (!expanded) {
|
||||
userExpandedOverride.value = false;
|
||||
userExpandedOverride.value = null;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -103,53 +101,30 @@ const currentAnswerLabel = computed(() => {
|
||||
|
||||
const trainingExamPdfGuide = computed(() => resolveTrainingExamPdfGuide(props.agentGuides));
|
||||
|
||||
// 默认进入 Chat 聊天页面(即收起工作区状态)
|
||||
const workspaceExpanded = ref(false);
|
||||
|
||||
const autoSyncInitialPrompt = () => {
|
||||
if (
|
||||
workspace.isTrainingAgent
|
||||
&& workspace.isHydrated
|
||||
&& !props.hasMessages
|
||||
&& workspace.shouldShowNewSessionReminder
|
||||
) {
|
||||
emit('push-local-assistant-message', workspace.newSessionReminderMessage);
|
||||
}
|
||||
const applyDefaultExpandedState = () => {
|
||||
const nextExpanded = userExpandedOverride.value ?? shouldDefaultExpanded.value;
|
||||
workspaceExpanded.value = nextExpanded;
|
||||
emit('update:expanded', nextExpanded);
|
||||
};
|
||||
|
||||
// 监听 Agent 切换,重置所有本地交互状态,确保每次进入都是初始、收起且触发引导的状态
|
||||
// 监听 Agent/角色切换,重置本地展开态:员工默认展开工作区,培训管理角色默认保留问答视图。
|
||||
watch(
|
||||
() => props.currentAgent?.id,
|
||||
() => [props.currentAgent?.id, workspace.isAdminViewer],
|
||||
() => {
|
||||
userExpandedOverride.value = false;
|
||||
workspaceExpanded.value = false;
|
||||
emit('update:expanded', false);
|
||||
userExpandedOverride.value = null;
|
||||
applyDefaultExpandedState();
|
||||
},
|
||||
{ immediate: true }
|
||||
);
|
||||
|
||||
watch(() => props.hasMessages, () => {
|
||||
// 如果用户没有手动展开,且消息状态变化,我们保持在聊天模式(收起工作区)
|
||||
if (!userExpandedOverride.value) {
|
||||
workspaceExpanded.value = false;
|
||||
emit('update:expanded', false);
|
||||
}
|
||||
});
|
||||
|
||||
watch(
|
||||
() => workspace.isHydrated,
|
||||
(ready) => {
|
||||
if (ready && workspace.isTrainingAgent && !props.hasMessages) {
|
||||
autoSyncInitialPrompt();
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
watch(
|
||||
() => props.newSessionTick,
|
||||
(tick, prevTick) => {
|
||||
if (!tick || tick === prevTick) return;
|
||||
autoSyncInitialPrompt();
|
||||
userExpandedOverride.value = null;
|
||||
applyDefaultExpandedState();
|
||||
},
|
||||
);
|
||||
|
||||
@@ -177,6 +152,21 @@ const ruleItems = computed(() => ([
|
||||
t('chat.training.rules.rule3', { passScore: workspace.passScore }),
|
||||
t('chat.training.rules.rule4'),
|
||||
]));
|
||||
const learnerIdentityItems = computed(() => ([
|
||||
{ key: 'name', label: t('chat.training.learnerCard.name'), value: workspace.currentUserName },
|
||||
{ key: 'employee-id', label: t('chat.training.learnerCard.employeeId'), value: workspace.currentUserEmployeeId },
|
||||
{ key: 'department', label: t('chat.training.learnerCard.department'), value: workspace.currentUserDepartment },
|
||||
]));
|
||||
const examQuestionItems = computed(() => Array.from({ length: workspace.totalQuestionCount }, (_, index) => ({
|
||||
index,
|
||||
label: String(index + 1).padStart(2, '0'),
|
||||
isActive: workspace.currentQuestionIndex === index,
|
||||
})));
|
||||
const canNavigateExamQuestions = computed(() => workspace.stage === 'exam');
|
||||
const jumpToExamQuestion = (index: number) => {
|
||||
if (!canNavigateExamQuestions.value) return;
|
||||
workspace.currentQuestionIndex = index;
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -262,10 +252,14 @@ const ruleItems = computed(() => ([
|
||||
· {{ $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>
|
||||
<div
|
||||
v-if="workspace.activeView === 'learner'"
|
||||
class="mt-1 flex flex-wrap gap-x-4 gap-y-1 text-xs leading-5 text-secondary"
|
||||
>
|
||||
<span v-for="item in learnerIdentityItems" :key="item.key">
|
||||
{{ item.label }}: {{ item.value }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex flex-wrap items-center gap-2 text-xs">
|
||||
@@ -350,6 +344,14 @@ const ruleItems = computed(() => ([
|
||||
· {{ $t('chat.training.learnerCard.name') }}: {{ workspace.currentUserName }}
|
||||
</template>
|
||||
</div>
|
||||
<div
|
||||
v-if="workspace.activeView === 'learner'"
|
||||
class="mt-1 flex flex-wrap gap-x-4 gap-y-1 text-xs leading-5 text-secondary"
|
||||
>
|
||||
<span v-for="item in learnerIdentityItems" :key="item.key">
|
||||
{{ item.label }}: {{ item.value }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex flex-wrap items-center gap-2 text-xs">
|
||||
<div class="rounded-full bg-white px-3 py-1.5 font-medium text-primary shadow-sm">
|
||||
@@ -636,22 +638,30 @@ const ruleItems = computed(() => ([
|
||||
<div class="min-w-0 md:sticky md:top-4 md:self-start">
|
||||
<div class="rounded-2xl border border-default bg-white p-3 shadow-sm">
|
||||
<div class="flex items-center gap-2">
|
||||
<Users class="h-4 w-4 text-brand-600" />
|
||||
<div class="text-sm font-semibold text-primary">{{ $t('chat.training.learnerCard.title') }}</div>
|
||||
<ClipboardCheck class="h-4 w-4 text-brand-600" />
|
||||
<div class="text-sm font-semibold text-primary">{{ $t('chat.training.examQuestionCard.title') }}</div>
|
||||
</div>
|
||||
<div class="mt-2.5 grid gap-1.5 text-sm text-secondary">
|
||||
<div class="flex items-center justify-between rounded-xl bg-surface-soft px-3 py-2">
|
||||
<span>{{ $t('chat.training.learnerCard.name') }}</span>
|
||||
<span class="font-medium text-primary">{{ workspace.currentUserName }}</span>
|
||||
</div>
|
||||
<div class="flex items-center justify-between rounded-xl bg-surface-soft px-3 py-2">
|
||||
<span>{{ $t('chat.training.learnerCard.employeeId') }}</span>
|
||||
<span class="font-medium text-primary">{{ workspace.currentUserEmployeeId }}</span>
|
||||
</div>
|
||||
<div class="flex items-center justify-between rounded-xl bg-surface-soft px-3 py-2">
|
||||
<span>{{ $t('chat.training.learnerCard.department') }}</span>
|
||||
<span class="font-medium text-primary">{{ workspace.currentUserDepartment }}</span>
|
||||
</div>
|
||||
<div class="mt-2 text-xs leading-5 text-secondary">
|
||||
{{ $t('chat.training.examQuestionCard.hint') }}
|
||||
</div>
|
||||
<div class="mt-3 grid grid-cols-4 gap-2">
|
||||
<button
|
||||
v-for="item in examQuestionItems"
|
||||
:key="item.index"
|
||||
type="button"
|
||||
class="flex h-10 items-center justify-center rounded-xl border text-sm font-semibold transition"
|
||||
:class="[
|
||||
item.isActive
|
||||
? 'border-brand-500 bg-brand-600 text-white shadow-sm'
|
||||
: canNavigateExamQuestions
|
||||
? 'border-brand-200 bg-brand-50/60 text-brand-700 hover:bg-brand-100'
|
||||
: 'cursor-not-allowed border-default bg-surface-soft text-muted',
|
||||
]"
|
||||
:disabled="!canNavigateExamQuestions"
|
||||
@click="jumpToExamQuestion(item.index)"
|
||||
>
|
||||
{{ item.label }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="my-3 h-px bg-slate-100" />
|
||||
|
||||
Reference in new issue
Block a user