diff --git a/app/performance-survey/[[...path]]/page.tsx b/app/performance-survey/[[...path]]/page.tsx index d559456c..93335f5b 100644 --- a/app/performance-survey/[[...path]]/page.tsx +++ b/app/performance-survey/[[...path]]/page.tsx @@ -350,8 +350,8 @@ function Dashboard() { const departmentLabel = me.data?.employee?.departmentName || me.data?.user?.department || '未同步部门' const positionLabel = [me.data?.employee?.positionTitle, me.data?.employee?.positionLevel].filter(Boolean).join(' · ') const availableTabIds = useMemo( - () => ['pending', 'submitted', 'created', 'results', ...(canManage ? ['manage'] : [])], - [canManage], + () => ['pending', 'submitted', 'created', 'results', 'manage'], + [], ) const tabs = [ @@ -359,7 +359,7 @@ function Dashboard() { { id: 'submitted', label: '已处理', count: submittedTotal }, { id: 'created', label: '我发起的', count: createdTotal }, { id: 'results', label: '我的结果', count: resultTotal }, - ...(canManage ? [{ id: 'manage', label: '管理', count: undefined }] : []), + { id: 'manage', label: canManage ? '管理' : '发起', count: undefined }, ] useEffect(() => { if (availableTabIds.includes(requestedTab) && tab !== requestedTab) { @@ -420,8 +420,9 @@ function Dashboard() { )} {surveys.data && tab === 'results' && } - {canManage && tab === 'manage' && ( + {surveys.data && tab === 'manage' && ( { await surveys.refresh() }} @@ -523,7 +524,7 @@ function SubmittedList({ items }: { items: any[] }) { href={`/performance-survey/survey/${item.surveyId}?targetId=${item.targetId}`} className="inline-flex min-h-[40px] items-center justify-center rounded-[10px] border border-[#dbe5f2] bg-white px-7 font-semibold text-[#101828] shadow-[0_10px_22px_rgba(29,33,41,0.06)] hover:bg-[#f8fbff] dark:border-gray-700 dark:bg-gray-900 dark:text-white" > - 查看 + 查看详情 @@ -719,13 +720,22 @@ function MyResults({ items }: { items: any[] }) { ) } -function ManagePanel({ onChanged, templateStats }: { onChanged: () => Promise; templateStats: any[] }) { +function ManagePanel({ + canManage, + onChanged, + templateStats, +}: { + canManage: boolean + onChanged: () => Promise + templateStats: any[] +}) { const templates = useApi('/templates', []) const departments = useApi('/departments?purpose=evaluator', []) - const notifications = useApi('/admin/notifications?limit=30', []) - const notificationStatus = useApi('/admin/notifications/status', []) + const notifications = useApi(canManage ? '/admin/notifications?limit=30' : null, [canManage]) + const notificationStatus = useApi(canManage ? '/admin/notifications/status' : null, [canManage]) const [message, setMessage] = useState(null) const refreshNotifications = async () => { + if (!canManage) return await Promise.all([notifications.refresh(), notificationStatus.refresh()]) } @@ -738,20 +748,26 @@ function ManagePanel({ onChanged, templateStats }: { onChanged: () => Promise { setMessage('已创建考核调研') await onChanged() - await notifications.refresh() + if (canManage) await notifications.refresh() }} /> -
+
- - {message &&
{message}
} + {canManage && ( + + )} + {message && ( +
+ {message} +
+ )}
- + {canManage && }
) @@ -1560,12 +1576,11 @@ function SurveySubmit({ surveyId, session }: { surveyId: string; session: any }) )} {submitted ? ( -
-
你已提交该评价
- - 返回考核调研 - -
+ ) : detail.data.status !== 'open' ? (
该调研未开放或已关闭 @@ -1703,6 +1718,114 @@ function SurveySubmit({ surveyId, session }: { surveyId: string; session: any }) ) } +function SubmittedResponseDetail({ + questions, + response, + submittedAt, +}: { + questions: Template['questions'] + response?: any + submittedAt?: string | Date | null +}) { + const responseScores = response?.scores && typeof response.scores === 'object' + ? response.scores as Record + : {} + const scoreOf = (questionId: string) => { + const value = Number(responseScores[questionId]) + return Number.isFinite(value) ? value : 0 + } + const formatScore = (value: unknown) => { + const numberValue = Number(value) + if (!Number.isFinite(numberValue)) return '-' + return Number.isInteger(numberValue) ? String(numberValue) : numberValue.toFixed(1) + } + const submittedLabel = submittedAt || response?.createdAt + ? formatDate(submittedAt || response?.createdAt) + : '已提交' + + return ( +
+
+
+
+
已提交
+
{submittedLabel}
+
+ + 返回已处理 + +
+
+
+
总分
+
{formatScore(response?.totalScore)}
+
+
+
达成分
+
{formatScore(response?.achievementScore)}
+
+
+
加权分
+
{formatScore(response?.weightedScore)}
+
+
+
+ + {questions.map((question, index) => { + const value = scoreOf(question.id) + const scorePercent = Math.max(0, Math.min(100, (value / 20) * 100)) + const accentColor = getQuestionAccentColor(index) + return ( +
+
+ + {index + 1} + +
+
问题 {index + 1}
+

{question.title}

+ {question.description && ( +

{question.description}

+ )} +
+
+ {formatScore(value)} + /20 +
+
+
+
+
+
+ 0 + 5 + 10 + 15 + 20 +
+
+ ) + })} + + {response?.comment && ( +
+
补充评价
+

{response.comment}

+
+ )} +
+ ) +} + function getSurveyInitials(name: string) { const text = String(name || '').trim() if (!text) return '用' diff --git a/lib/performance-survey-service.ts b/lib/performance-survey-service.ts index bbc9e342..9ec1c8ac 100644 --- a/lib/performance-survey-service.ts +++ b/lib/performance-survey-service.ts @@ -359,6 +359,7 @@ export async function getPerformanceSurveyMe(session: Session | null) { isDepartmentAdmin: ctx.isDepartmentAdmin, isLeadership: ctx.isLeadership, scopeDepartment: ctx.scopeDepartment, + canCreate: true, }, } } @@ -370,11 +371,6 @@ export async function getPerformanceSurveyTemplates(session: Session | null) { export async function searchPerformanceSurveyEmployees(session: Session | null, params: URLSearchParams) { const ctx = await getPerformanceSurveyContext(session) - if (!ctx.isDepartmentAdmin) { - if (!ctx.employee) return [] - return [serializeEmployee(ctx.employee)] - } - const search = clean(params.get('search')) || '' const department = clean(params.get('department')) const limit = Math.max(1, Math.min(Number(params.get('limit') || 50), 200)) @@ -537,7 +533,6 @@ export async function searchPerformanceSurveyEmployees(session: Session | null, export async function listPerformanceSurveyDepartments(session: Session | null, params?: URLSearchParams) { const ctx = await getPerformanceSurveyContext(session) - ensureManager(ctx) const isEvaluatorPicker = clean(params?.get('purpose')) === 'evaluator' const accountWhere = await getPerformanceSurveyAccountProfileWhere() @@ -785,13 +780,13 @@ export async function listPerformanceSurveys(session: Session | null) { isSystemAdmin: ctx.isSystemAdmin, isDepartmentAdmin: ctx.isDepartmentAdmin, scopeDepartment: ctx.scopeDepartment, + canCreate: true, }, } } export async function createPerformanceSurvey(session: Session | null, body: any) { const ctx = await getPerformanceSurveyContext(session) - ensureManager(ctx) const title = clean(body?.title) if (!title) throw new PerformanceSurveyApiError('调研标题不能为空') @@ -801,10 +796,11 @@ export async function createPerformanceSurvey(session: Session | null, body: any const surveyKind = clean(body?.surveyKind) || template.surveyType const dueAt = toDate(body?.dueAt) const openNow = Boolean(body?.openNow || body?.status === 'open') - const departmentName = clean(body?.departmentName) || ctx.scopeDepartment + const requestedDepartmentName = clean(body?.departmentName) + const departmentName = requestedDepartmentName || ctx.scopeDepartment - if (!ctx.isSystemAdmin && ctx.scopeDepartment && departmentName !== ctx.scopeDepartment) { - throw new PerformanceSurveyApiError('部门管理员只能创建本部门考核调研', 403) + if (!ctx.isSystemAdmin && requestedDepartmentName && requestedDepartmentName !== ctx.scopeDepartment) { + throw new PerformanceSurveyApiError('只能创建本人部门范围内的考核调研', 403) } const targets = await resolveSurveyTargets(body, surveyKind) @@ -910,6 +906,7 @@ export async function getPerformanceSurveyDetail(session: Session | null, survey }, assignments: { where: { evaluatorKey: ctx.evaluatorKey }, + include: { response: true }, }, _count: { select: { assignments: true, responses: true, targets: true }, @@ -952,6 +949,7 @@ export async function getPerformanceSurveyDetail(session: Session | null, survey canViewResults: canManage || survey.creatorUserId === ctx.user.id || (survey.status === 'closed' && isTarget), targets: survey.targets.map((target) => { const currentAssignment = currentAssignments.get(target.id) + const response = currentAssignment?.response return { id: target.id, targetType: target.targetType, @@ -964,6 +962,18 @@ export async function getPerformanceSurveyDetail(session: Session | null, survey id: currentAssignment.id, status: currentAssignment.status, submittedAt: currentAssignment.submittedAt, + response: response + ? { + id: response.id, + scores: response.scores, + comment: response.comment, + totalScore: response.totalScore, + achievementScore: response.achievementScore, + kpiScore: response.kpiScore, + weightedScore: response.weightedScore, + createdAt: response.createdAt, + } + : null, } : null, assignments: canManage @@ -981,7 +991,6 @@ export async function getPerformanceSurveyDetail(session: Session | null, survey export async function updatePerformanceSurvey(session: Session | null, surveyId: string, body: any) { const ctx = await getPerformanceSurveyContext(session) - ensureManager(ctx) const survey = await prisma.performanceSurvey.findUnique({ where: { id: surveyId } }) if (!survey) throw new PerformanceSurveyApiError('调研不存在', 404)