开放考核调研发起与已处理详情

This commit is contained in:
chenpei 2026-07-08 13:32:26 +08:00
parent 9135a160ea
commit 85c545eeb0
2 changed files with 165 additions and 33 deletions

View File

@ -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() {
<CreatedList items={createdItems} onRefresh={surveys.refresh} />
)}
{surveys.data && tab === 'results' && <MyResults items={resultItems} />}
{canManage && tab === 'manage' && (
{surveys.data && tab === 'manage' && (
<ManagePanel
canManage={canManage}
onChanged={async () => {
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"
>
查看
查看详情
</Link>
</div>
</article>
@ -719,13 +720,22 @@ function MyResults({ items }: { items: any[] }) {
)
}
function ManagePanel({ onChanged, templateStats }: { onChanged: () => Promise<void>; templateStats: any[] }) {
function ManagePanel({
canManage,
onChanged,
templateStats,
}: {
canManage: boolean
onChanged: () => Promise<void>
templateStats: any[]
}) {
const templates = useApi<Template[]>('/templates', [])
const departments = useApi<DepartmentOption[]>('/departments?purpose=evaluator', [])
const notifications = useApi<any[]>('/admin/notifications?limit=30', [])
const notificationStatus = useApi<any>('/admin/notifications/status', [])
const notifications = useApi<any[]>(canManage ? '/admin/notifications?limit=30' : null, [canManage])
const notificationStatus = useApi<any>(canManage ? '/admin/notifications/status' : null, [canManage])
const [message, setMessage] = useState<string | null>(null)
const refreshNotifications = async () => {
if (!canManage) return
await Promise.all([notifications.refresh(), notificationStatus.refresh()])
}
@ -738,20 +748,26 @@ function ManagePanel({ onChanged, templateStats }: { onChanged: () => Promise<vo
onCreated={async () => {
setMessage('已创建考核调研')
await onChanged()
await notifications.refresh()
if (canManage) await notifications.refresh()
}}
/>
<TemplateStatsPanel items={templateStats} />
</div>
<div className="grid gap-4 xl:grid-cols-[minmax(340px,0.75fr)_minmax(0,1.25fr)]">
<div className={canManage ? 'grid gap-4 xl:grid-cols-[minmax(340px,0.75fr)_minmax(0,1.25fr)]' : 'grid gap-4'}>
<div className="space-y-4">
<AdminActions
onMessage={setMessage}
onNotificationsChanged={refreshNotifications}
/>
{message && <div className="rounded-[14px] bg-white px-4 py-3 text-sm font-medium text-[#0052d9] shadow-[0_8px_18px_rgba(45,43,80,0.06)] dark:bg-gray-900 dark:text-blue-200">{message}</div>}
{canManage && (
<AdminActions
onMessage={setMessage}
onNotificationsChanged={refreshNotifications}
/>
)}
{message && (
<div className="rounded-[14px] bg-white px-4 py-3 text-sm font-medium text-[#0052d9] shadow-[0_8px_18px_rgba(45,43,80,0.06)] dark:bg-gray-900 dark:text-blue-200">
{message}
</div>
)}
</div>
<NotificationList state={notifications} statusState={notificationStatus} />
{canManage && <NotificationList state={notifications} statusState={notificationStatus} />}
</div>
</div>
)
@ -1560,12 +1576,11 @@ function SurveySubmit({ surveyId, session }: { surveyId: string; session: any })
)}
{submitted ? (
<div className="rounded-[24px] border border-[#dce6f2] bg-white px-4 py-10 text-center shadow-[0_12px_34px_rgba(15,23,42,0.05)]">
<div className="text-[18px] font-semibold text-[#111827]">你已提交该评价</div>
<Link href="/performance-survey" className="mt-4 inline-flex rounded-[10px] bg-[#1677ff] px-4 py-2 text-sm font-semibold text-white">
返回考核调研
</Link>
</div>
<SubmittedResponseDetail
questions={questions}
response={activeTarget?.currentAssignment?.response}
submittedAt={activeTarget?.currentAssignment?.submittedAt}
/>
) : detail.data.status !== 'open' ? (
<div className="rounded-[24px] border border-[#dce6f2] bg-white px-4 py-10 text-center text-[16px] font-semibold text-[#4b5565] shadow-[0_12px_34px_rgba(15,23,42,0.05)]">
该调研未开放或已关闭
@ -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<string, unknown>
: {}
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 (
<div className="space-y-3">
<section className="rounded-[20px] border border-[#dfe6f0] bg-white px-4 py-4 shadow-[0_12px_34px_rgba(15,23,42,0.05)]">
<div className="flex items-center justify-between gap-3">
<div>
<div className="text-[13px] font-semibold text-[#16a34a]">已提交</div>
<div className="mt-1 text-[12px] font-medium text-[#667085]">{submittedLabel}</div>
</div>
<Link
href="/performance-survey?tab=submitted"
className="shrink-0 rounded-full border border-[#dbe5f2] bg-[#f8fbff] px-3 py-1.5 text-[12px] font-semibold text-[#101828]"
>
返回已处理
</Link>
</div>
<div className="mt-4 grid grid-cols-3 gap-2">
<div className="rounded-2xl bg-[#f6f8fb] px-3 py-3">
<div className="text-[11px] font-semibold text-[#667085]">总分</div>
<div className="mt-1 text-[22px] font-semibold text-[#101828]">{formatScore(response?.totalScore)}</div>
</div>
<div className="rounded-2xl bg-[#f6f8fb] px-3 py-3">
<div className="text-[11px] font-semibold text-[#667085]">达成分</div>
<div className="mt-1 text-[22px] font-semibold text-[#101828]">{formatScore(response?.achievementScore)}</div>
</div>
<div className="rounded-2xl bg-[#f6f8fb] px-3 py-3">
<div className="text-[11px] font-semibold text-[#667085]">加权分</div>
<div className="mt-1 text-[22px] font-semibold text-[#101828]">{formatScore(response?.weightedScore)}</div>
</div>
</div>
</section>
{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 (
<section key={question.id} className="rounded-[20px] border border-[#dfe6f0] bg-white px-4 py-4 shadow-[0_12px_34px_rgba(15,23,42,0.05)]">
<div className="grid grid-cols-[32px_minmax(0,1fr)_auto] items-start gap-3">
<span
className="mt-0.5 flex h-7 w-7 items-center justify-center rounded-full text-[14px] font-semibold leading-none text-white"
style={{ backgroundColor: accentColor }}
>
{index + 1}
</span>
<div className="min-w-0">
<div className="text-[11px] font-semibold text-[#98a2b3]">问题 {index + 1}</div>
<h2 className="mt-1 break-words text-[17px] font-semibold leading-6 text-[#111827]">{question.title}</h2>
{question.description && (
<p className="mt-1 text-[13px] font-medium leading-5 text-[#7b8494]">{question.description}</p>
)}
</div>
<div className="rounded-xl bg-[#f6f8fb] px-2.5 py-1.5 text-right">
<span className="text-[18px] font-semibold leading-none" style={{ color: accentColor }}>{formatScore(value)}</span>
<span className="ml-0.5 text-[11px] font-medium text-[#98a2b3]">/20</span>
</div>
</div>
<div className="mt-4 h-1.5 overflow-hidden rounded-full bg-[#e5edf6]">
<div
className="h-full rounded-full"
style={{ width: `${scorePercent}%`, backgroundColor: accentColor }}
/>
</div>
<div className="mt-2 grid grid-cols-5 text-[11px] font-medium text-[#9aa3b2]">
<span>0</span>
<span className="text-center">5</span>
<span className="text-center">10</span>
<span className="text-center">15</span>
<span className="text-right">20</span>
</div>
</section>
)
})}
{response?.comment && (
<section className="rounded-[20px] border border-[#dfe6f0] bg-white px-4 py-4 shadow-[0_12px_34px_rgba(15,23,42,0.05)]">
<div className="text-[15px] font-semibold text-[#111827]">补充评价</div>
<p className="mt-3 whitespace-pre-wrap text-[14px] leading-6 text-[#4b5565]">{response.comment}</p>
</section>
)}
</div>
)
}
function getSurveyInitials(name: string) {
const text = String(name || '').trim()
if (!text) return '用'

View File

@ -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)