feat(aihr): complete phase two pilot readiness

This commit is contained in:
2026-07-10 19:13:31 +08:00
parent 0219de6fa8
commit 13230e6b9a
48 changed files with 7040 additions and 1647 deletions
@@ -0,0 +1,432 @@
<template>
<view class="page assign-page">
<view class="subpage-header">
<button class="subpage-back-button" aria-label="返回" title="返回" :disabled="assigning" @click="goBack">←</button>
<view class="subpage-heading">
<text class="page-title">指派专项</text>
<text class="page-subtitle">{{ selectedTargetLabel }}</text>
</view>
</view>
<view v-if="message && !accessDenied" class="status-message">{{ message }}</view>
<view v-if="accessDenied" class="panel supervisor-access-panel">
<text class="panel-title">无主管权限</text>
<text class="muted supervisor-access-copy">当前账号不是主管或项目经理,无法查看团队训练数据。</text>
<view class="supervisor-access-actions">
<button class="secondary-button" @click="goToEmployee">返回员工端</button>
<button class="primary-button" @click="switchAccount">切换账号</button>
</view>
</view>
<view v-else-if="!loggedIn" class="panel login-panel">
<view>
<text class="panel-title">需要登录</text>
<text class="muted block">登录后指派并查看最近专项。</text>
</view>
<button class="primary-button login-button" @click="goLogin">去登录</button>
</view>
<template v-else>
<view class="panel assignment-form">
<text class="field-label">训练对象</text>
<input
v-model="targetExtPartyId"
class="input field-input"
maxlength="32"
placeholder="输入手机号或外部ID"
@input="targetName = ''"
/>
<input
v-model="targetName"
class="input field-input"
maxlength="40"
placeholder="员工姓名(可选)"
/>
<text class="field-label section-label">训练场景</text>
<view class="scenario-row">
<button
v-for="item in supervisorScenarioOptions"
:key="item.id"
class="chip scenario-chip"
:class="{ active: assignmentScenarioId === item.id }"
:disabled="assigning"
@click="assignmentScenarioId = item.id"
>
{{ item.name }}
</button>
</view>
<text class="field-label section-label">指派原因</text>
<textarea
v-model="assignmentReason"
class="textarea reason-input"
maxlength="180"
placeholder="填写本次专项训练原因"
/>
<button class="primary-button submit-button" :disabled="assigning || historyLoading" @click="assignPractice">
{{ assigning ? '指派中' : '确认指派' }}
</button>
</view>
<view class="panel history-panel">
<view class="section-head">
<text class="panel-title">最近专项</text>
<button
class="ghost-button refresh-button"
:disabled="historyLoading || assigning"
@click="loadAssignments()"
>
{{ historyLoading ? '刷新中' : '刷新' }}
</button>
</view>
<view v-if="recentAssignments.length" class="assignment-list">
<view v-for="item in recentAssignments" :key="item.id" class="assignment-row">
<view class="assignment-copy">
<text class="assignment-title">{{ item.traineeName }} · {{ item.scenarioName }}</text>
<text class="assignment-desc">{{ assignmentSummary(item) }}</text>
</view>
<text class="assignment-source">{{ assignmentSourceLabel(item.source) }}</text>
</view>
</view>
<view v-else-if="!historyLoading" class="empty compact-empty">暂无专项指派记录</view>
</view>
</template>
</view>
</template>
<script setup lang="ts">
import { computed, onBeforeUnmount, ref } from 'vue';
import { onLoad, onShow } from '@dcloudio/uni-app';
import type { PracticeAssignment } from '@/types/api';
import { clearAuth, isLoggedIn, rememberLoginRedirect } from '@/services/auth';
import { resetPageScroll } from '@/services/navigation';
import { createPracticeAssignment, getPracticeTeamSnapshot } from '@/services/practice';
import {
createAsyncGenerationGuard,
inferSupervisorScenarioId,
isSupervisorAccessDenied,
manualPracticeAssignments,
supervisorScenarioOptions,
type SupervisorScenarioId
} from '@/services/supervisor-view';
const basePath = '/pages/supervisor/assign/index';
const targetExtPartyId = ref('');
const targetName = ref('');
const assignmentScenarioId = ref<SupervisorScenarioId>('fee-parking');
const assignmentReason = ref('');
const assignments = ref<PracticeAssignment[]>([]);
const loggedIn = ref(false);
const accessDenied = ref(false);
const assigning = ref(false);
const historyLoading = ref(false);
const message = ref('');
const historyRequests = createAsyncGenerationGuard();
const selectedTargetLabel = computed(() => {
if (!loggedIn.value) return '选择员工并配置训练任务';
const target = targetExtPartyId.value.trim();
if (!target) return '选择员工并配置训练任务';
return targetName.value.trim() ? `${targetName.value.trim()} · ${target}` : target;
});
const recentAssignments = computed(() => manualPracticeAssignments(assignments.value).slice(0, 10));
const queryText = (value: unknown) => {
if (typeof value !== 'string') return '';
try {
return decodeURIComponent(value).trim();
} catch {
return value.trim();
}
};
const isScenarioId = (value: string): value is SupervisorScenarioId =>
supervisorScenarioOptions.some((item) => item.id === value);
const refreshAuthState = () => {
loggedIn.value = isLoggedIn();
};
const resetDraft = () => {
targetExtPartyId.value = '';
targetName.value = '';
assignmentScenarioId.value = 'fee-parking';
assignmentReason.value = '';
};
const clearPrivateState = () => {
resetDraft();
assignments.value = [];
historyLoading.value = false;
historyRequests.invalidate();
};
const handleRequestError = (error: unknown, fallback: string) => {
if (isSupervisorAccessDenied(error)) {
clearPrivateState();
accessDenied.value = true;
message.value = '';
return;
}
refreshAuthState();
if (!loggedIn.value) {
accessDenied.value = false;
clearPrivateState();
message.value = '登录已过期,请重新登录';
return;
}
message.value = error instanceof Error ? error.message : fallback;
};
const loadAssignments = async (force = false) => {
refreshAuthState();
if (!loggedIn.value) {
accessDenied.value = false;
clearPrivateState();
return;
}
if (!force && (historyLoading.value || assigning.value)) return;
const generation = historyRequests.begin();
historyLoading.value = true;
try {
const snapshot = await getPracticeTeamSnapshot();
if (historyRequests.isCurrent(generation)) {
accessDenied.value = false;
assignments.value = snapshot.assignments;
}
} catch (error) {
if (historyRequests.isCurrent(generation)) {
handleRequestError(error, '最近专项加载失败');
}
} finally {
if (historyRequests.isCurrent(generation)) {
historyLoading.value = false;
}
}
};
const loadPage = () => {
refreshAuthState();
message.value = '';
if (!loggedIn.value) {
clearPrivateState();
return;
}
void loadAssignments();
};
const assignPractice = async () => {
if (assigning.value || historyLoading.value) return;
const extPartyId = targetExtPartyId.value.trim();
if (!extPartyId) {
message.value = '请填写员工手机号或外部ID';
return;
}
assigning.value = true;
message.value = '';
try {
const scenario = supervisorScenarioOptions.find((item) => item.id === assignmentScenarioId.value);
await createPracticeAssignment({
extPartyId,
traineeName: targetName.value.trim() || `手机用户${extPartyId.slice(-4)}`,
scenarioId: assignmentScenarioId.value,
scenarioName: scenario?.name,
reason: assignmentReason.value.trim() || '主管派发专项训练'
});
resetDraft();
uni.showToast({ title: '已指派', icon: 'none' });
await loadAssignments(true);
} catch (error) {
handleRequestError(error, '指派失败');
} finally {
assigning.value = false;
}
};
const assignmentSourceLabel = (source: string) => {
if (source === 'retry') return '再练';
if (source === 'camp') return '训练营';
return '专项';
};
const assignmentSummary = (item: PracticeAssignment) => {
const reason = item.reason?.trim() || '主管派发专项训练';
return `${item.createTime} · ${item.status} · ${reason}`;
};
const goLogin = () => {
rememberLoginRedirect(basePath);
uni.redirectTo({ url: '/pages/auth/login/index' });
};
const goToEmployee = () => {
uni.switchTab({ url: '/pages/user/today/index' });
};
const switchAccount = () => {
clearAuth();
rememberLoginRedirect(basePath);
uni.redirectTo({ url: '/pages/auth/login/index' });
};
const goBack = () => {
if (assigning.value) return;
if (getCurrentPages().length <= 1) {
uni.redirectTo({ url: '/pages/supervisor/index/index' });
return;
}
uni.navigateBack({
delta: 1,
fail: () => uni.redirectTo({ url: '/pages/supervisor/index/index' })
});
};
onLoad((query) => {
targetExtPartyId.value = queryText(query?.extPartyId);
targetName.value = queryText(query?.name);
assignmentReason.value = queryText(query?.reason);
const requestedScenario = queryText(query?.scenarioId);
assignmentScenarioId.value = isScenarioId(requestedScenario)
? requestedScenario
: inferSupervisorScenarioId(assignmentReason.value);
});
onShow(() => {
resetPageScroll();
loadPage();
});
onBeforeUnmount(() => {
historyRequests.dispose();
});
</script>
<style scoped>
.assign-page {
padding-bottom: 42px;
background: #f4f7fb;
}
.login-panel,
.section-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
}
.login-button {
min-width: 104px;
}
.refresh-button {
min-width: 82px;
padding: 0 10px;
font-size: 13px;
}
.block {
display: block;
margin-top: 8px;
font-size: 14px;
line-height: 1.5;
}
.field-label {
display: block;
color: #334155;
font-size: 13px;
font-weight: 800;
}
.section-label {
margin-top: 16px;
}
.field-input,
.reason-input,
.scenario-row,
.submit-button {
margin-top: 9px;
}
.field-input + .field-input {
margin-top: 10px;
}
.scenario-row {
display: flex;
flex-wrap: wrap;
gap: 8px;
}
.scenario-chip {
border-radius: 8px;
}
.scenario-chip.active {
background: #fee2e2;
color: #b91c1c;
}
.submit-button {
width: 100%;
}
.assignment-list {
margin-top: 8px;
}
.assignment-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
padding: 13px 0;
border-bottom: 1px solid #e2e8f0;
}
.assignment-row:last-child {
border-bottom: 0;
}
.assignment-copy {
min-width: 0;
flex: 1;
}
.assignment-title,
.assignment-desc {
display: block;
}
.assignment-title {
color: #0f172a;
font-size: 14px;
font-weight: 800;
}
.assignment-desc {
margin-top: 5px;
color: #64748b;
font-size: 12px;
line-height: 1.45;
}
.assignment-source {
flex: 0 0 auto;
padding: 5px 8px;
border-radius: 8px;
background: #e0f2fe;
color: #0369a1;
font-size: 12px;
font-weight: 800;
}
.compact-empty {
padding: 18px 8px 4px;
}
</style>
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,639 @@
<template>
<view class="page review-page">
<view class="subpage-header">
<button class="subpage-back-button" aria-label="返回待复盘" title="返回待复盘" @click="goBack">←</button>
<view class="subpage-heading">
<text class="page-title">复盘详情</text>
<text class="page-subtitle">{{ detail ? `${detail.trainee} · ${detail.scene}` : '训练记录' }}</text>
</view>
<button v-if="loggedIn && reviewId && !accessDenied" class="ghost-button refresh-button" :disabled="loading" @click="loadDetail">
{{ loading ? '刷新中' : '刷新' }}
</button>
</view>
<view v-if="message && !accessDenied" class="status-message">{{ message }}</view>
<view v-if="accessDenied" class="panel supervisor-access-panel">
<text class="panel-title">无主管权限</text>
<text class="muted supervisor-access-copy">当前账号不是主管或项目经理,无法查看团队训练数据。</text>
<view class="supervisor-access-actions">
<button class="secondary-button" @click="goToEmployee">返回员工端</button>
<button class="primary-button" @click="switchAccount">切换账号</button>
</view>
</view>
<view v-else-if="!loggedIn" class="panel login-panel">
<view>
<text class="panel-title">需要登录</text>
<text class="muted block">登录后查看并完成复盘。</text>
</view>
<button class="primary-button login-button" @click="goLogin">去登录</button>
</view>
<template v-else-if="detail">
<view class="panel summary-panel">
<view class="summary-head">
<view class="summary-copy">
<text class="detail-title">{{ detail.trainee }} · {{ detail.scene }}</text>
<text class="detail-meta">{{ detail.time }} · {{ detail.status }}</text>
</view>
<text class="score-pill">{{ detail.score }}分</text>
</view>
<text class="detail-desc">{{ detail.aiComment || detail.summary }}</text>
</view>
<view v-if="detail.scoreItems?.length" class="panel">
<text class="panel-title">评分明细</text>
<view class="score-list">
<view v-for="item in detail.scoreItems" :key="item.label" class="score-row">
<view class="score-copy">
<text class="score-label">{{ item.label }}</text>
<text class="score-note">{{ item.note }}</text>
</view>
<text class="score-value">{{ item.value }}</text>
</view>
</view>
</view>
<view v-if="detail.dialogue?.length" class="panel">
<text class="panel-title">对话记录</text>
<view class="dialogue-list">
<view v-for="(turn, index) in detail.dialogue" :key="`${turn.role}-${index}`" class="dialogue-row">
<text class="dialogue-label">{{ turn.label }}</text>
<text class="dialogue-text">{{ turn.text }}</text>
<view v-if="hasAudio(turn)" class="dialogue-audio-block">
<audio v-if="audioSrc(turn, index)" class="dialogue-audio" controls :src="audioSrc(turn, index)"></audio>
<button
v-else
class="secondary-button audio-button"
:disabled="audioLoading[audioKey(index)]"
@click="loadAudio(turn, index)"
>
{{ audioLoading[audioKey(index)] ? '加载中' : '加载录音' }}
</button>
<text v-if="audioErrors[audioKey(index)]" class="audio-error">{{ audioErrors[audioKey(index)] }}</text>
</view>
</view>
</view>
</view>
<view v-if="detail.annotations?.length || detail.mentorRewrite" class="panel">
<text class="panel-title">标注与建议</text>
<view v-if="detail.annotations?.length" class="annotation-list">
<view v-for="item in detail.annotations" :key="`${item.turnIndex}-${item.issue}`" class="annotation-row">
<text class="annotation-issue">{{ item.issue }}</text>
<text class="annotation-rewrite">建议:{{ item.rewrite }}</text>
<text class="annotation-sop">依据:{{ item.sopPoint }}</text>
</view>
</view>
<view v-if="detail.mentorRewrite" class="mentor-block">
<text class="subsection-title">推荐话术</text>
<text class="mentor-text">{{ detail.mentorRewrite }}</text>
</view>
</view>
<view v-if="editable" class="panel review-form">
<text class="panel-title">主管复盘</text>
<text class="field-label">复盘建议</text>
<textarea
v-model="advice"
class="textarea review-textarea"
maxlength="300"
placeholder="填写复盘建议,可留空直接标记"
/>
<text class="field-label">人工贡献分</text>
<input
v-model="incentivePoint"
class="input point-input"
type="number"
maxlength="3"
placeholder="可留空"
/>
<view class="next-training-section">
<text class="field-label">复盘后专项</text>
<view class="scenario-row">
<button class="chip scenario-chip" :class="{ active: !nextScenarioId }" @click="clearNextScenario">
暂不派发
</button>
<button
v-for="item in supervisorScenarioOptions"
:key="item.id"
class="chip scenario-chip"
:class="{ active: nextScenarioId === item.id }"
@click="selectNextScenario(item.id)"
>
{{ item.name }}
</button>
</view>
<textarea
v-if="nextScenarioId"
v-model="nextReason"
class="textarea next-reason-input"
maxlength="180"
placeholder="填写下一次训练原因"
/>
</view>
<button class="primary-button submit-button" :disabled="marking" @click="markReviewed">
{{ marking ? '提交中' : '标记已复盘' }}
</button>
</view>
<view v-else class="panel review-complete">
<text class="complete-title">复盘已完成</text>
<text class="complete-desc">{{ detail.reviewAdvice || '该训练记录已完成主管复盘。' }}</text>
<text v-if="detail.incentivePoint != null" class="complete-point">
人工贡献分 {{ detail.incentivePoint }}
</text>
</view>
</template>
<view v-else-if="loggedIn && !loading" class="panel empty-panel">
<view class="empty">{{ reviewId ? '复盘详情暂不可用' : '缺少有效的复盘ID' }}</view>
<button class="secondary-button back-list-button" @click="goToReviews">返回待复盘</button>
</view>
</view>
</template>
<script setup lang="ts">
import { computed, onBeforeUnmount, ref } from 'vue';
import { onLoad, onShow } from '@dcloudio/uni-app';
import type { ReviewDetail, ReviewDialogue } from '@/types/api';
import { authenticatedFileUrl, releaseAuthenticatedFileUrl } from '@/services/api';
import { clearAuth, isLoggedIn, rememberLoginRedirect } from '@/services/auth';
import { resetPageScroll } from '@/services/navigation';
import { getPracticeReviewDetail, markPracticeReviewed } from '@/services/practice';
import {
createAsyncGenerationGuard,
isReviewEditable,
isSupervisorAccessDenied,
reviewCompletionAction,
supervisorScenarioOptions,
type SupervisorScenarioId
} from '@/services/supervisor-view';
const basePath = '/pages/supervisor/review/index';
const reviewId = ref(0);
const detail = ref<ReviewDetail | null>(null);
const advice = ref('');
const incentivePoint = ref('');
const nextScenarioId = ref<SupervisorScenarioId | ''>('');
const nextReason = ref('');
const loggedIn = ref(false);
const accessDenied = ref(false);
const loading = ref(false);
const marking = ref(false);
const message = ref('');
const audioSources = ref<Record<string, string>>({});
const audioLoading = ref<Record<string, boolean>>({});
const audioErrors = ref<Record<string, string>>({});
const audioRequests = createAsyncGenerationGuard();
const editable = computed(() => isReviewEditable(detail.value?.status));
const audioKey = (index: number) => `${reviewId.value || 'review'}-${index}`;
const hasAudio = (turn: ReviewDialogue) => Boolean(turn.audioOssId || turn.audioUrl);
const audioSrc = (turn: ReviewDialogue, index: number) =>
audioSources.value[audioKey(index)] || (!turn.audioOssId ? turn.audioUrl || '' : '');
const releaseAudioSources = () => {
audioRequests.invalidate();
Object.values(audioSources.value).forEach(releaseAuthenticatedFileUrl);
audioSources.value = {};
audioLoading.value = {};
audioErrors.value = {};
};
const clearDetail = () => {
releaseAudioSources();
detail.value = null;
advice.value = '';
incentivePoint.value = '';
nextScenarioId.value = '';
nextReason.value = '';
};
const refreshAuthState = () => {
loggedIn.value = isLoggedIn();
};
const handleRequestError = (error: unknown, fallback: string) => {
if (isSupervisorAccessDenied(error)) {
clearDetail();
accessDenied.value = true;
message.value = '';
return;
}
refreshAuthState();
if (!loggedIn.value) {
accessDenied.value = false;
clearDetail();
message.value = '登录已过期,请重新登录';
return;
}
message.value = error instanceof Error ? error.message : fallback;
};
const loadAudio = async (turn: ReviewDialogue, index: number) => {
const key = audioKey(index);
if (audioSrc(turn, index) || !turn.audioOssId || audioLoading.value[key]) return;
const generation = audioRequests.capture();
audioLoading.value = { ...audioLoading.value, [key]: true };
audioErrors.value = { ...audioErrors.value, [key]: '' };
try {
const source = await authenticatedFileUrl(`/api/aihr/mobile/oss/${turn.audioOssId}`);
if (!audioRequests.isCurrent(generation)) {
releaseAuthenticatedFileUrl(source);
return;
}
audioSources.value = {
...audioSources.value,
[key]: source
};
} catch (error) {
if (!audioRequests.isCurrent(generation)) return;
if (isSupervisorAccessDenied(error)) {
handleRequestError(error, '录音加载失败');
return;
}
refreshAuthState();
if (!loggedIn.value) {
accessDenied.value = false;
clearDetail();
message.value = '登录已过期,请重新登录';
return;
}
audioErrors.value = { ...audioErrors.value, [key]: '录音加载失败' };
if (error instanceof Error && error.message === '网络请求失败') {
message.value = '录音加载失败,请检查网络后重试';
}
} finally {
if (audioRequests.isCurrent(generation)) {
audioLoading.value = { ...audioLoading.value, [key]: false };
}
}
};
const loadDetail = async () => {
refreshAuthState();
message.value = '';
if (!loggedIn.value) {
accessDenied.value = false;
clearDetail();
return;
}
if (!reviewId.value) {
clearDetail();
message.value = '缺少有效的复盘ID';
return;
}
if (loading.value) return;
loading.value = true;
releaseAudioSources();
try {
const nextDetail = await getPracticeReviewDetail(reviewId.value);
accessDenied.value = false;
detail.value = nextDetail;
advice.value = detail.value.reviewAdvice || '';
incentivePoint.value = detail.value.incentivePoint == null ? '' : String(detail.value.incentivePoint);
nextScenarioId.value = '';
nextReason.value = '';
} catch (error) {
clearDetail();
handleRequestError(error, '复盘详情加载失败');
} finally {
loading.value = false;
}
};
const selectNextScenario = (scenarioId: SupervisorScenarioId) => {
nextScenarioId.value = scenarioId;
const scenario = supervisorScenarioOptions.find((item) => item.id === scenarioId);
nextReason.value = `复盘后建议补练${scenario?.name || '专项训练'}`;
};
const clearNextScenario = () => {
nextScenarioId.value = '';
nextReason.value = '';
};
const markReviewed = async () => {
if (marking.value || !detail.value?.id) return;
if (!editable.value) {
message.value = '该记录已完成复盘,不能重复提交';
return;
}
const pointText = incentivePoint.value.trim();
const point = pointText ? Number(pointText) : undefined;
if (point !== undefined && !Number.isFinite(point)) {
message.value = '贡献分必须是数字';
return;
}
marking.value = true;
message.value = '';
const assignedNext = Boolean(nextScenarioId.value);
try {
await markPracticeReviewed(detail.value.id, {
reviewer: '主管',
advice: advice.value.trim(),
incentivePoint: point,
nextScenarioId: nextScenarioId.value || undefined,
nextReason: nextScenarioId.value ? nextReason.value.trim() : undefined
});
uni.showToast({ title: assignedNext ? '已复盘并派专项' : '已复盘', icon: 'none' });
const pages = getCurrentPages();
const previousRoute = pages.length > 1 ? pages[pages.length - 2]?.route : undefined;
clearDetail();
if (reviewCompletionAction(previousRoute) === 'back') {
uni.navigateBack({ delta: 1, fail: goToReviews });
} else {
goToReviews();
}
} catch (error) {
handleRequestError(error, '标记失败');
} finally {
marking.value = false;
}
};
const currentPath = () => reviewId.value ? `${basePath}?id=${reviewId.value}` : basePath;
const goLogin = () => {
rememberLoginRedirect(currentPath());
uni.redirectTo({ url: '/pages/auth/login/index' });
};
const goToEmployee = () => {
uni.switchTab({ url: '/pages/user/today/index' });
};
const switchAccount = () => {
clearAuth();
rememberLoginRedirect(currentPath());
uni.redirectTo({ url: '/pages/auth/login/index' });
};
const goToReviews = () => {
uni.redirectTo({ url: '/pages/supervisor/reviews/index' });
};
const goBack = () => {
if (getCurrentPages().length <= 1) {
goToReviews();
return;
}
uni.navigateBack({ delta: 1, fail: goToReviews });
};
onLoad((query) => {
const value = Number(query?.id);
reviewId.value = Number.isInteger(value) && value > 0 ? value : 0;
});
onShow(() => {
resetPageScroll();
refreshAuthState();
if (!loggedIn.value) {
accessDenied.value = false;
clearDetail();
return;
}
if (!detail.value && !loading.value) void loadDetail();
});
onBeforeUnmount(() => {
audioRequests.dispose();
releaseAudioSources();
});
</script>
<style scoped>
.review-page {
padding-bottom: 42px;
background: #f4f7fb;
}
.subpage-header {
align-items: center;
}
.login-panel,
.summary-head,
.score-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
}
.login-button {
min-width: 104px;
}
.refresh-button {
min-width: 78px;
padding: 0 10px;
font-size: 13px;
}
.block {
display: block;
margin-top: 8px;
font-size: 14px;
line-height: 1.5;
}
.review-complete {
border-left: 4px solid #16a34a;
}
.complete-title,
.complete-desc,
.complete-point {
display: block;
}
.complete-title {
color: #166534;
font-size: 16px;
font-weight: 900;
}
.complete-desc,
.complete-point {
margin-top: 8px;
color: #475569;
font-size: 13px;
line-height: 1.5;
}
.summary-copy,
.score-copy {
min-width: 0;
flex: 1;
}
.detail-title,
.detail-meta,
.detail-desc,
.score-label,
.score-note,
.dialogue-label,
.dialogue-text,
.annotation-issue,
.annotation-rewrite,
.annotation-sop,
.subsection-title,
.mentor-text,
.field-label {
display: block;
}
.detail-title {
color: #0f172a;
font-size: 17px;
font-weight: 900;
}
.detail-meta {
margin-top: 5px;
color: #64748b;
font-size: 12px;
}
.detail-desc {
margin-top: 12px;
color: #475569;
font-size: 14px;
line-height: 1.55;
}
.score-pill {
flex: 0 0 auto;
padding: 7px 10px;
border-radius: 8px;
background: #fee2e2;
color: #b91c1c;
font-size: 15px;
font-weight: 900;
}
.score-list,
.dialogue-list,
.annotation-list {
margin-top: 10px;
}
.score-row,
.dialogue-row,
.annotation-row {
padding: 12px 0;
border-bottom: 1px solid #e2e8f0;
}
.score-row:last-child,
.dialogue-row:last-child,
.annotation-row:last-child {
border-bottom: 0;
}
.score-label,
.dialogue-label,
.annotation-issue,
.subsection-title,
.field-label {
color: #1e293b;
font-size: 14px;
font-weight: 800;
}
.score-note,
.dialogue-text,
.annotation-rewrite,
.annotation-sop,
.mentor-text {
margin-top: 6px;
color: #64748b;
font-size: 13px;
line-height: 1.5;
}
.score-value {
flex: 0 0 auto;
color: #0f172a;
font-size: 20px;
font-weight: 900;
}
.dialogue-audio-block {
margin-top: 10px;
}
.dialogue-audio {
display: block;
width: 100%;
}
.audio-button {
width: 104px;
min-height: 36px;
font-size: 13px;
}
.audio-error {
display: block;
margin-top: 6px;
color: #dc2626;
font-size: 12px;
}
.mentor-block {
margin-top: 14px;
padding-top: 14px;
border-top: 1px solid #e2e8f0;
}
.field-label {
margin-top: 16px;
}
.review-textarea,
.point-input,
.scenario-row,
.next-reason-input,
.submit-button {
margin-top: 9px;
}
.scenario-row {
display: flex;
flex-wrap: wrap;
gap: 8px;
}
.scenario-chip {
border-radius: 8px;
}
.scenario-chip.active {
background: #fee2e2;
color: #b91c1c;
}
.next-training-section {
margin-top: 16px;
padding-top: 2px;
border-top: 1px solid #e2e8f0;
}
.submit-button,
.back-list-button {
width: 100%;
}
.empty-panel {
padding-bottom: 18px;
}
</style>
@@ -0,0 +1,284 @@
<template>
<view class="page reviews-page">
<view class="subpage-header">
<button class="subpage-back-button" aria-label="返回主管首页" title="返回主管首页" @click="goBack">←</button>
<view class="subpage-heading">
<text class="page-title">待复盘</text>
<text class="page-subtitle">{{ reviewCountText }}</text>
</view>
<button v-if="loggedIn && !accessDenied" class="ghost-button refresh-button" :disabled="loading" @click="loadPage">
{{ loading ? '刷新中' : '刷新' }}
</button>
</view>
<view v-if="message && !accessDenied" class="status-message">{{ message }}</view>
<view v-if="accessDenied" class="panel supervisor-access-panel">
<text class="panel-title">无主管权限</text>
<text class="muted supervisor-access-copy">当前账号不是主管或项目经理,无法查看团队训练数据。</text>
<view class="supervisor-access-actions">
<button class="secondary-button" @click="goToEmployee">返回员工端</button>
<button class="primary-button" @click="switchAccount">切换账号</button>
</view>
</view>
<view v-else-if="!loggedIn" class="panel login-panel">
<view>
<text class="panel-title">需要登录</text>
<text class="muted block">登录后查看待复盘对练。</text>
</view>
<button class="primary-button login-button" @click="goLogin">去登录</button>
</view>
<view v-else class="panel review-panel">
<view class="section-head">
<text class="panel-title">复盘队列</text>
<text class="muted">低分优先</text>
</view>
<view v-if="reviews.length" class="review-list">
<button
v-for="item in reviews"
:key="item.id || item.sessionId || item.time"
class="review-row"
@click="openReview(item)"
>
<view class="review-copy">
<text class="review-title">{{ item.trainee }} · {{ item.scene }}</text>
<text class="review-desc">{{ item.time }} · {{ item.summary }}</text>
<text class="review-status">{{ item.status }}</text>
</view>
<view class="review-score">
<text>{{ item.score }}</text>
<text>查看</text>
</view>
</button>
</view>
<view v-else-if="!loading" class="empty">暂无待复盘记录</view>
</view>
</view>
</template>
<script setup lang="ts">
import { computed, ref } from 'vue';
import { onShow } from '@dcloudio/uni-app';
import type { PracticeAlert, PracticeRecord } from '@/types/api';
import { clearAuth, isLoggedIn, rememberLoginRedirect } from '@/services/auth';
import { resetPageScroll } from '@/services/navigation';
import { getPracticeAlerts, getPracticeReviews } from '@/services/practice';
import { buildSupervisorMetrics, isSupervisorAccessDenied } from '@/services/supervisor-view';
const currentPath = '/pages/supervisor/reviews/index';
const reviews = ref<PracticeRecord[]>([]);
const alerts = ref<PracticeAlert[]>([]);
const loggedIn = ref(false);
const accessDenied = ref(false);
const loading = ref(false);
const message = ref('');
const pendingReviewTotal = computed(() =>
buildSupervisorMetrics(reviews.value, [], alerts.value)
.find((item) => item.key === 'pendingReviews')?.value || 0);
const reviewCountText = computed(() =>
pendingReviewTotal.value > reviews.value.length
? `${reviews.value.length}/${pendingReviewTotal.value} 条`
: `${reviews.value.length} 条`);
const clearData = () => {
reviews.value = [];
alerts.value = [];
};
const refreshAuthState = () => {
loggedIn.value = isLoggedIn();
};
const handleRequestError = (error: unknown, fallback: string) => {
if (isSupervisorAccessDenied(error)) {
clearData();
accessDenied.value = true;
message.value = '';
return;
}
refreshAuthState();
if (!loggedIn.value) {
accessDenied.value = false;
clearData();
message.value = '登录已过期,请重新登录';
return;
}
message.value = error instanceof Error ? error.message : fallback;
};
const loadPage = async () => {
refreshAuthState();
message.value = '';
if (!loggedIn.value) {
accessDenied.value = false;
clearData();
return;
}
if (loading.value) return;
loading.value = true;
try {
const [nextReviews, nextAlerts] = await Promise.all([
getPracticeReviews(),
getPracticeAlerts()
]);
accessDenied.value = false;
reviews.value = nextReviews;
alerts.value = nextAlerts;
} catch (error) {
handleRequestError(error, '待复盘列表加载失败');
} finally {
loading.value = false;
}
};
const openReview = (item: PracticeRecord) => {
if (!item.id) {
message.value = '该记录缺少复盘ID';
return;
}
uni.navigateTo({ url: `/pages/supervisor/review/index?id=${item.id}` });
};
const goLogin = () => {
rememberLoginRedirect(currentPath);
uni.redirectTo({ url: '/pages/auth/login/index' });
};
const goToEmployee = () => {
uni.switchTab({ url: '/pages/user/today/index' });
};
const switchAccount = () => {
clearAuth();
rememberLoginRedirect(currentPath);
uni.redirectTo({ url: '/pages/auth/login/index' });
};
const goBack = () => {
if (getCurrentPages().length <= 1) {
uni.redirectTo({ url: '/pages/supervisor/index/index' });
return;
}
uni.navigateBack({
delta: 1,
fail: () => uni.redirectTo({ url: '/pages/supervisor/index/index' })
});
};
onShow(() => {
resetPageScroll();
void loadPage();
});
</script>
<style scoped>
.reviews-page {
padding-bottom: 42px;
background: #f4f7fb;
}
.subpage-header {
align-items: center;
}
.login-panel,
.section-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
}
.login-button {
min-width: 104px;
}
.refresh-button {
min-width: 78px;
padding: 0 10px;
font-size: 13px;
}
.block {
display: block;
margin-top: 8px;
font-size: 14px;
line-height: 1.5;
}
.review-list {
margin-top: 8px;
}
.review-row {
display: flex;
width: 100%;
min-height: 88px;
align-items: center;
justify-content: space-between;
gap: 12px;
padding: 13px 0;
border-radius: 0;
border-bottom: 1px solid #e2e8f0;
background: transparent;
text-align: left;
}
.review-row:last-child {
border-bottom: 0;
}
.review-copy {
min-width: 0;
flex: 1;
}
.review-title,
.review-desc,
.review-status {
display: block;
}
.review-title {
color: #0f172a;
font-size: 15px;
font-weight: 800;
}
.review-desc {
margin-top: 5px;
overflow: hidden;
color: #64748b;
font-size: 12px;
line-height: 1.45;
text-overflow: ellipsis;
white-space: nowrap;
}
.review-status {
margin-top: 6px;
color: #c2410c;
font-size: 12px;
font-weight: 800;
}
.review-score {
display: flex;
min-width: 52px;
flex: 0 0 auto;
flex-direction: column;
align-items: flex-end;
gap: 4px;
color: #64748b;
font-size: 12px;
}
.review-score text:first-child {
color: #dc2626;
font-size: 24px;
font-weight: 900;
}
</style>
@@ -0,0 +1,366 @@
<template>
<view class="page team-page">
<view class="subpage-header">
<button class="subpage-back-button" aria-label="返回主管首页" title="返回主管首页" @click="goBack">←</button>
<view class="subpage-heading">
<text class="page-title">团队画像</text>
<text class="page-subtitle">{{ teamProfiles.length }} 名成员</text>
</view>
<button v-if="loggedIn && !accessDenied" class="ghost-button refresh-button" :disabled="loading" @click="loadPage">
{{ loading ? '刷新中' : '刷新' }}
</button>
</view>
<view v-if="message && !accessDenied" class="status-message">{{ message }}</view>
<view v-if="accessDenied" class="panel supervisor-access-panel">
<text class="panel-title">无主管权限</text>
<text class="muted supervisor-access-copy">当前账号不是主管或项目经理,无法查看团队训练数据。</text>
<view class="supervisor-access-actions">
<button class="secondary-button" @click="goToEmployee">返回员工端</button>
<button class="primary-button" @click="switchAccount">切换账号</button>
</view>
</view>
<view v-else-if="!loggedIn" class="panel login-panel">
<view>
<text class="panel-title">需要登录</text>
<text class="muted block">登录后查看团队画像。</text>
</view>
<button class="primary-button login-button" @click="goLogin">去登录</button>
</view>
<template v-else>
<view class="risk-summary">
<view class="risk-item high">
<text class="risk-value">{{ riskCounts.high }}</text>
<text class="risk-label">高风险</text>
</view>
<view class="risk-item medium">
<text class="risk-value">{{ riskCounts.medium }}</text>
<text class="risk-label">待复盘</text>
</view>
<view class="risk-item low">
<text class="risk-value">{{ riskCounts.low }}</text>
<text class="risk-label">正常</text>
</view>
</view>
<view class="panel team-panel">
<view class="section-head">
<text class="panel-title">成员列表</text>
<text class="muted">按风险排序</text>
</view>
<view v-if="teamProfiles.length" class="team-list">
<view v-for="member in teamProfiles" :key="member.key" class="team-row" :class="member.risk">
<view class="team-main">
<view class="team-title-row">
<text class="team-name">{{ member.displayName }}</text>
<text class="team-score">{{ member.latestScoreText }}</text>
</view>
<text class="team-desc">{{ member.reason }}</text>
<view class="team-tags">
<text class="team-tag">待复盘 {{ member.pendingReview }}</text>
<text class="team-tag">待训练 {{ member.pendingAssignment }}</text>
<text v-if="member.latestScene" class="team-tag">{{ member.latestScene }}</text>
</view>
</view>
<button class="secondary-button team-action" @click="assignMember(member)">派专项</button>
</view>
</view>
<view v-else-if="!loading" class="empty">暂无团队画像数据</view>
</view>
</template>
</view>
</template>
<script setup lang="ts">
import { computed, ref } from 'vue';
import { onShow } from '@dcloudio/uni-app';
import type { PracticeAssignment, PracticeRecord, PracticeTeamMember } from '@/types/api';
import { clearAuth, isLoggedIn, rememberLoginRedirect } from '@/services/auth';
import { resetPageScroll } from '@/services/navigation';
import { getPracticeTeamSnapshot } from '@/services/practice';
import {
buildTeamProfiles,
inferSupervisorScenarioId,
isSupervisorAccessDenied,
type TeamProfile
} from '@/services/supervisor-view';
const currentPath = '/pages/supervisor/team/index';
const records = ref<PracticeRecord[]>([]);
const assignments = ref<PracticeAssignment[]>([]);
const members = ref<PracticeTeamMember[]>([]);
const loggedIn = ref(false);
const accessDenied = ref(false);
const loading = ref(false);
const message = ref('');
const teamProfiles = computed(() => buildTeamProfiles(records.value, assignments.value, members.value));
const riskCounts = computed(() => teamProfiles.value.reduce(
(counts, item) => {
counts[item.risk] += 1;
return counts;
},
{ high: 0, medium: 0, low: 0 }
));
const clearData = () => {
records.value = [];
assignments.value = [];
members.value = [];
};
const refreshAuthState = () => {
loggedIn.value = isLoggedIn();
};
const handleRequestError = (error: unknown, fallback: string) => {
if (isSupervisorAccessDenied(error)) {
clearData();
accessDenied.value = true;
message.value = '';
return;
}
refreshAuthState();
if (!loggedIn.value) {
accessDenied.value = false;
clearData();
message.value = '登录已过期,请重新登录';
return;
}
message.value = error instanceof Error ? error.message : fallback;
};
const loadPage = async () => {
refreshAuthState();
message.value = '';
if (!loggedIn.value) {
accessDenied.value = false;
clearData();
return;
}
if (loading.value) return;
loading.value = true;
try {
const snapshot = await getPracticeTeamSnapshot();
accessDenied.value = false;
records.value = snapshot.records;
assignments.value = snapshot.assignments;
members.value = snapshot.members;
} catch (error) {
handleRequestError(error, '团队画像加载失败');
} finally {
loading.value = false;
}
};
const assignMember = (member: TeamProfile) => {
const scenarioId = inferSupervisorScenarioId(`${member.latestScene} ${member.reason}`);
const query = [
`extPartyId=${encodeURIComponent(member.extPartyId)}`,
`name=${encodeURIComponent(member.name)}`,
`scenarioId=${encodeURIComponent(scenarioId)}`,
`reason=${encodeURIComponent(member.reason)}`
].join('&');
uni.navigateTo({ url: `/pages/supervisor/assign/index?${query}` });
};
const goLogin = () => {
rememberLoginRedirect(currentPath);
uni.redirectTo({ url: '/pages/auth/login/index' });
};
const goToEmployee = () => {
uni.switchTab({ url: '/pages/user/today/index' });
};
const switchAccount = () => {
clearAuth();
rememberLoginRedirect(currentPath);
uni.redirectTo({ url: '/pages/auth/login/index' });
};
const goBack = () => {
if (getCurrentPages().length <= 1) {
uni.redirectTo({ url: '/pages/supervisor/index/index' });
return;
}
uni.navigateBack({
delta: 1,
fail: () => uni.redirectTo({ url: '/pages/supervisor/index/index' })
});
};
onShow(() => {
resetPageScroll();
void loadPage();
});
</script>
<style scoped>
.team-page {
padding-bottom: 42px;
background: #f4f7fb;
}
.subpage-header {
align-items: center;
}
.login-button {
min-width: 104px;
}
.refresh-button {
min-width: 78px;
padding: 0 10px;
font-size: 13px;
}
.login-panel,
.section-head,
.team-title-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
}
.block {
display: block;
margin-top: 8px;
font-size: 14px;
line-height: 1.5;
}
.risk-summary {
display: grid;
margin-top: 16px;
overflow: hidden;
border: 1px solid #e2e8f0;
border-radius: 8px;
background: #ffffff;
grid-template-columns: repeat(3, 1fr);
}
.risk-item {
padding: 13px 8px;
border-right: 1px solid #e2e8f0;
text-align: center;
}
.risk-item:last-child {
border-right: 0;
}
.risk-value,
.risk-label {
display: block;
}
.risk-value {
color: #0f172a;
font-size: 23px;
font-weight: 900;
}
.risk-label {
margin-top: 4px;
color: #64748b;
font-size: 12px;
}
.risk-item.high .risk-value {
color: #b91c1c;
}
.risk-item.medium .risk-value {
color: #c2410c;
}
.risk-item.low .risk-value {
color: #15803d;
}
.team-list {
margin-top: 8px;
}
.team-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
padding: 14px 0 14px 12px;
border-bottom: 1px solid #e2e8f0;
border-left: 4px solid #22c55e;
}
.team-row:last-child {
border-bottom: 0;
}
.team-row.high {
border-left-color: #dc2626;
}
.team-row.medium {
border-left-color: #f59e0b;
}
.team-main {
min-width: 0;
flex: 1;
}
.team-name {
min-width: 0;
overflow: hidden;
color: #0f172a;
font-size: 15px;
font-weight: 900;
text-overflow: ellipsis;
white-space: nowrap;
}
.team-score {
flex: 0 0 auto;
color: #1d4ed8;
font-size: 14px;
font-weight: 900;
}
.team-desc {
display: block;
margin-top: 6px;
color: #475569;
font-size: 12px;
line-height: 1.45;
}
.team-tags {
display: flex;
flex-wrap: wrap;
gap: 6px;
margin-top: 8px;
}
.team-tag {
padding: 4px 7px;
border-radius: 8px;
background: #f1f5f9;
color: #64748b;
font-size: 11px;
font-weight: 800;
}
.team-action {
min-width: 72px;
min-height: 38px;
flex: 0 0 auto;
padding: 0 10px;
font-size: 12px;
}
</style>