(null)
@@ -267,7 +282,8 @@ export function PerformanceSurveyAdminConfig({
if (!confirmDiscard('切换月份会放弃当前未保存修改,确定继续吗?')) return
setDirtyState(false)
setNotice(null)
- setMonth(nextMonth)
+ if (onMonthChange) onMonthChange(nextMonth)
+ else setInternalMonth(nextMonth)
}
const changed = useCallback(async (message: string) => {
@@ -291,7 +307,7 @@ export function PerformanceSurveyAdminConfig({
}[mode]}
- {dirty ? '有未保存修改' : '配置按月份查看;已发布版本保持不变'}
+ {dirty ? `${month} 有未保存修改` : `正在维护 ${month};已发布版本保持不变`}
- {notice && {notice}
}
+ {notice && (
+ <>
+
+ {notice}
+
+
+ {notice}
+
+ >
+ )}
{error && (
{error}
{!data && }
)}
- {loading && !data && 配置加载中...
}
+ {loading && !data && 配置加载中...
}
{data && (
{mode === 'overview' && (
@@ -319,6 +344,7 @@ export function PerformanceSurveyAdminConfig({
data={data}
month={month}
request={request}
+ onNavigate={onNavigate}
/>
)}
{mode === 'positions' && (
@@ -378,18 +404,84 @@ function AdminOverviewWorkspace({
data,
month,
request,
+ onNavigate,
}: {
data: AdminConfig
month: string
request: RequestFn
+ onNavigate?: (mode: PerformanceSurveyAdminMode | 'launch') => void
}) {
const [audits, setAudits] = useState([])
const [auditError, setAuditError] = useState(null)
const [auditLoading, setAuditLoading] = useState(true)
- const readyGroups = data.groups.filter((group) => group.status === 'ready').length
+ const activeGroups = data.groups.filter((group) => group.status !== 'disabled')
+ const groupsWithMatchingRules = activeGroups.filter((group) => group.rules.some((rule) => rule.isActive)).length
const disabledGroups = data.groups.filter((group) => group.status === 'disabled').length
const draftTemplates = data.templates.flatMap((template) => template.versions).filter((version) => version.status === 'draft').length
const publishedTemplates = data.templates.flatMap((template) => template.versions).filter((version) => version.status === 'published').length
+ const availablePublishedTemplates = data.templates
+ .flatMap((template) => template.versions)
+ .filter((version) => (
+ version.status === 'published'
+ && (!version.effectiveMonth || version.effectiveMonth <= month)
+ )).length
+ const effectivePlanCount = activeGroups.filter((group) => group.effectivePlan?.effectiveMonth === month).length
+ const draftPlanCount = activeGroups.filter((group) => group.draftPlan).length
+ const hasPeopleIssues = data.issues.unmatched.length > 0 || data.issues.conflicts.length > 0
+ const positionsReady = activeGroups.length > 0 && groupsWithMatchingRules === activeGroups.length
+ const templatesReady = availablePublishedTemplates > 0
+ const plansReady = activeGroups.length > 0 && effectivePlanCount === activeGroups.length
+ const launchReady = positionsReady && templatesReady && plansReady && data.issues.conflicts.length === 0
+ const steps = [
+ {
+ id: 'people',
+ label: '确认人员资料',
+ status: data.issues.conflicts.length > 0 ? 'blocked' : hasPeopleIssues ? 'attention' : 'done',
+ summary: data.issues.conflicts.length > 0
+ ? `${data.issues.conflicts.length} 人同时匹配多个岗位,必须先处理`
+ : data.issues.unmatched.length > 0
+ ? `${data.issues.unmatched.length} 人待确认:分配岗位,或明确标记为不参与`
+ : '人员岗位归属没有待处理异常',
+ action: '处理人员',
+ target: 'people' as const,
+ },
+ {
+ id: 'positions',
+ label: '确认岗位',
+ status: positionsReady ? 'done' : 'attention',
+ summary: activeGroups.length === 0
+ ? '还没有可用岗位'
+ : `${groupsWithMatchingRules}/${activeGroups.length} 个在用岗位已完成匹配规则${disabledGroups > 0 ? `,另有 ${disabledGroups} 个已归档` : ''}`,
+ action: '管理岗位',
+ target: 'positions' as const,
+ },
+ {
+ id: 'templates',
+ label: '准备考核模板',
+ status: templatesReady ? (draftTemplates > 0 ? 'attention' : 'done') : 'blocked',
+ summary: templatesReady
+ ? `${availablePublishedTemplates} 个版本可用于 ${month}${draftTemplates > 0 ? `,${draftTemplates} 个草稿待确认` : ''}`
+ : `还没有可用于 ${month} 的已发布模板,月度方案无法完成${publishedTemplates > 0 ? `(另有 ${publishedTemplates} 个其它月份版本)` : ''}`,
+ action: '管理模板',
+ target: 'templates' as const,
+ },
+ {
+ id: 'plans',
+ label: '发布月度方案',
+ status: plansReady ? 'done' : draftPlanCount > 0 ? 'attention' : 'blocked',
+ summary: `${effectivePlanCount}/${activeGroups.length} 个在用岗位已有 ${month} 方案${draftPlanCount > 0 ? `,${draftPlanCount} 个草稿待发布` : ''}`,
+ action: '配置方案',
+ target: 'plans' as const,
+ },
+ {
+ id: 'launch',
+ label: '发起调研',
+ status: launchReady ? 'ready' : 'blocked',
+ summary: launchReady ? `${month} 的岗位、模板和方案已可用于发起调研` : '完成上面的必要配置后再发起,避免人员或模板选错',
+ action: '去发起调研',
+ target: 'launch' as const,
+ },
+ ]
const loadAudits = useCallback(async () => {
setAuditLoading(true)
@@ -420,49 +512,53 @@ function AdminOverviewWorkspace({
-
-
-
-
- | 维护项 |
- 当前状态 |
- 需要处理 |
-
-
-
-
- | 岗位 |
- {readyGroups}/{data.groups.length} 个岗位已就绪 |
- {disabledGroups > 0 ? `${disabledGroups} 个已归档` : '无归档岗位'} |
-
-
- | 人员 |
- 未匹配 {data.issues.unmatched.length} 人 |
- 0 ? 'text-[#b42318]' : 'text-[#16794b]'}`}>
- {data.issues.conflicts.length > 0 ? `重复匹配 ${data.issues.conflicts.length} 人` : '无重复匹配'}
- |
-
-
- | 模板 |
- {publishedTemplates} 个已发布版本 |
- {draftTemplates > 0 ? `${draftTemplates} 个草稿待处理` : '无待发布草稿'} |
-
-
- | 月度方案 |
-
- {data.groups.filter((group) => group.effectivePlan?.effectiveMonth === month).length} 个岗位本月已有方案
- |
-
- {data.groups.filter((group) => group.draftPlan).length} 个岗位有未发布草稿
- |
-
-
-
+
+
+
本月上线准备
+
按顺序完成;每一步都可以直接进入对应管理页面。
+
+
+ {steps.map((step, index) => {
+ const statusLabel = {
+ done: '已完成',
+ attention: '待确认',
+ blocked: '未完成',
+ ready: '可发起',
+ }[step.status]
+ const statusClass = {
+ done: 'bg-[#eaf7ef] text-[#16794b]',
+ attention: 'bg-[#fff4da] text-[#7a4b00]',
+ blocked: 'bg-[#f3f3f3] text-[#5f5e5e]',
+ ready: 'bg-[#e9efff] text-[#0050cb]',
+ }[step.status]
+ return (
+ -
+
+ {index + 1}
+
+
+
+
{step.label}
+ {statusLabel}
+
+
{step.summary}
+
+
+
+ )
+ })}
+
{(data.issues.unmatched.length > 0 || data.issues.conflicts.length > 0) && (
- 发布前请先处理人员分配:未匹配 {data.issues.unmatched.length} 人,重复匹配 {data.issues.conflicts.length} 人。
+ “未匹配”不等于必须参与考核。请逐一确认:需要参与的人分配岗位,不参与的人明确标记为“不参与”;重复匹配人员必须先消除冲突。
)}
@@ -473,7 +569,7 @@ function AdminOverviewWorkspace({
刷新
- {auditLoading && 记录加载中...
}
+ {auditLoading && 记录加载中...
}
{auditError && (
配置记录暂不可用:{auditError}
@@ -886,6 +982,7 @@ function TemplateConfigWorkspace({
|| null
const [versionId, setVersionId] = useState(selectedVersion?.id || null)
const [definition, setDefinition] = useState(() => clone(selectedVersion?.definition || newTemplateDefinition()))
+ const [editorStep, setEditorStep] = useState<'basics' | 'questions' | 'workflow'>('basics')
const [saving, setSaving] = useState(false)
const editorRef = useRef(null)
@@ -895,6 +992,7 @@ function TemplateConfigWorkspace({
|| null
setVersionId(nextVersion?.id || null)
setDefinition(clone(nextVersion?.definition || newTemplateDefinition()))
+ setEditorStep('basics')
onDirtyChange(false)
}, [onDirtyChange, selectedTemplate])
@@ -1036,6 +1134,7 @@ function TemplateConfigWorkspace({
onDirtyChange(false)
setVersionId(item.id)
setDefinition(clone(item.definition))
+ setEditorStep('basics')
}}
className={`min-h-10 rounded border px-3 text-left text-[12px] font-bold ${versionId === item.id ? 'border-[#0050cb] bg-[#f1f4ff] text-[#0050cb]' : 'border-[#e2e2e2] text-[#5f5e5e]'}`}
>
@@ -1054,48 +1153,107 @@ function TemplateConfigWorkspace({
)}
-
-
updateDefinition((current) => ({ ...current, code: value }))} disabled={Boolean(selectedTemplate)} />
- updateDefinition((current) => ({ ...current, name: value }))} disabled={!editable} />
- updateDefinition((current) => ({ ...current, shortName: value }))} disabled={!editable} />
-
-
-
-
- {definition.surveyType === 'visual_case' && (
-
-
updateDefinition((current) => ({ ...current, requiredWorkItemCount: Math.max(1, Number(value) || 1), workItemImageRequired: true }))}
- />
+
+
+
+
当前模板
+
{definition.name || '未命名模板'}
+
+ {surveyTypeLabel(definition.surveyType)} · {definition.questions.length} 个评分项 · {definition.workflow.stages.length} 个评审阶段
+
+
+
+
+
+ {definition.questions.reduce((sum, question) => sum + Number(question.maxScore || definition.questionMaxScore || 20), 0)}
+
+
评分项合计
+
+
+
{version ? `v${version.version}` : '新建'}
+
{editable ? '草稿可编辑' : '已发布只读'}
+
+
+
+
+
+
+ {editorStep === 'basics' && (
+
+
+
基本信息
+
管理员和员工都会看到这些名称与说明。
+
+
+
updateDefinition((current) => ({ ...current, name: value }))} disabled={!editable} />
+ updateDefinition((current) => ({ ...current, shortName: value }))} disabled={!editable} />
+
+ {definition.surveyType === 'visual_case' && (
+ updateDefinition((current) => ({ ...current, requiredWorkItemCount: Math.max(1, Number(value) || 1), workItemImageRequired: true }))}
+ />
+ )}
+
+
+
+ 高级设置(一般无需修改)
+
+
updateDefinition((current) => ({ ...current, code: value }))} disabled={Boolean(selectedTemplate) || !editable} />
+ 新建时已自动生成;创建后不可修改,仅用于系统识别。
+
+
+
)}
-
-
+ {editorStep === 'questions' && (
+
+ )}
+ {editorStep === 'workflow' && (
+
+ )}
{!editable &&
}
@@ -1376,9 +1534,12 @@ function QuestionEditor({
onChange: (definition: TemplateDefinition) => void
}) {
return (
-
-
-
评分项
+
+
+
+
评分项
+
评分人将逐项打分,右侧满分会决定该项可填写的最高分。
+
{editable && (
)}
-
+
{definition.questions.map((question, index) => (
-
-
onChange({ ...definition, questions: definition.questions.map((item, itemIndex) => itemIndex === index ? { ...item, id: event.target.value } : item) })} className="h-9 rounded border border-[#e2e2e2] px-2 text-[12px] outline-none disabled:bg-[#f4f4f4]" />
-
onChange({ ...definition, questions: definition.questions.map((item, itemIndex) => itemIndex === index ? { ...item, title: event.target.value } : item) })} className="h-9 rounded border border-[#e2e2e2] px-2 text-[12px] outline-none disabled:bg-[#f4f4f4]" />
-
onChange({ ...definition, questions: definition.questions.map((item, itemIndex) => itemIndex === index ? { ...item, description: event.target.value } : item) })} className="h-9 rounded border border-[#e2e2e2] px-2 text-[12px] outline-none disabled:bg-[#f4f4f4]" />
-
onChange({ ...definition, questions: definition.questions.map((item, itemIndex) => itemIndex === index ? { ...item, maxScore: Number(event.target.value) || 1 } : item) })} className="h-9 rounded border border-[#e2e2e2] px-2 text-[12px] outline-none disabled:bg-[#f4f4f4]" />
- {editable &&
}
+
+
+
评分项 {index + 1}
+ {editable && (
+
+ )}
+
+
+
+
+
+
+
+ 高级设置
+
+
))}
-
+
)
}
@@ -1423,33 +1637,67 @@ function WorkflowEditor({
request: RequestFn
onChange: (definition: TemplateDefinition) => void
}) {
- const updateStages = (stages: StageDraft[]) => onChange({
- ...definition,
- workflow: { ...definition.workflow, stages: stages.map((stage, index) => ({ ...stage, order: index })) },
- })
+ const updateStages = (nextStages: StageDraft[]) => {
+ const stages = nextStages.map((stage, index) => ({ ...stage, order: index }))
+ const currentScoring = definition.workflow.scoring
+ const scoring = currentScoring.mode === 'average_reviewers'
+ ? { mode: 'average_reviewers' as const, stageKeys: stages.map((stage) => stage.key) }
+ : (() => {
+ const selectedStage = stages.find((stage) => stage.key === currentScoring.stageKey) || stages[stages.length - 1]
+ const selectedReviewer = selectedStage?.reviewers.find((reviewer) => reviewer.source === currentScoring.reviewerSource)
+ || selectedStage?.reviewers[0]
+ return {
+ mode: 'final_reviewer' as const,
+ stageKey: selectedStage?.key || '',
+ reviewerSource: selectedReviewer?.source || 'manual_selection' as ReviewerSource,
+ }
+ })()
+ onChange({
+ ...definition,
+ workflow: { ...definition.workflow, stages, scoring },
+ })
+ }
const stages = definition.workflow.stages
return (
-
-
+
+
-
评审流程
+
评审与计分
同阶段并行,上一阶段全部提交后开放下一阶段
- {editable &&
}
+ {editable &&
}
{stages.map((stage, stageIndex) => (
-
-
-
updateStages(stages.map((item, index) => index === stageIndex ? { ...item, key: event.target.value } : item))} className="h-9 rounded border border-[#e2e2e2] px-2 text-[12px] outline-none disabled:bg-[#f4f4f4]" />
-
updateStages(stages.map((item, index) => index === stageIndex ? { ...item, label: event.target.value } : item))} className="h-9 rounded border border-[#e2e2e2] px-2 text-[12px] outline-none disabled:bg-[#f4f4f4]" />
- {editable &&
}
+
+
+
+ {editable && (
+
+ )}
+
本阶段评分人
{stage.reviewers.map((reviewer, reviewerIndex) => (
-
+
))}
- {editable &&
}
+ {editable &&
}
+
+ 高级设置
+
+
))}
-
+
+
最终成绩采用哪一组评分
+
这里只决定最终展示的分数;各评分人的原始分仍会保留。
+
+
{definition.workflow.scoring.mode === 'final_reviewer' && (
<>
>
)}
-
+
)
}
@@ -1562,6 +1842,7 @@ function FixedReviewerPicker({
return (
{
@@ -1569,10 +1850,10 @@ function FixedReviewerPicker({
onChange({ source: 'fixed_employee', label: '固定员工' })
}}
placeholder="搜索固定评分人"
- className="h-9 w-full rounded border border-[#e2e2e2] px-2 text-[12px] outline-none disabled:bg-[#f4f4f4]"
+ className="h-11 w-full rounded border border-[#e2e2e2] px-3 text-[12px] outline-none focus:border-[#0050cb] disabled:bg-[#f4f4f4]"
/>
{items.length > 0 && (
-
+
{items.map((item) => (
@@ -1614,7 +1895,7 @@ function AdminField({
value={value}
disabled={disabled}
onChange={(event) => onChange(event.target.value)}
- className="h-10 rounded border border-[#e2e2e2] px-3 text-[13px] font-semibold text-[#1a1c1c] outline-none focus:border-[#0050cb] disabled:bg-[#f4f4f4] disabled:text-[#8a8a8a]"
+ className="h-11 rounded border border-[#e2e2e2] px-3 text-[13px] font-semibold text-[#1a1c1c] outline-none focus:border-[#0050cb] disabled:bg-[#f4f4f4] disabled:text-[#8a8a8a]"
/>
)
diff --git a/app/performance-survey/PerformanceSurveyAdminPeople.test.tsx b/app/performance-survey/PerformanceSurveyAdminPeople.test.tsx
new file mode 100644
index 00000000..9e4c0418
--- /dev/null
+++ b/app/performance-survey/PerformanceSurveyAdminPeople.test.tsx
@@ -0,0 +1,123 @@
+/** @jest-environment jsdom */
+
+import { fireEvent, render, screen, waitFor, within } from '@testing-library/react'
+import {
+ PerformanceSurveyAdminPeople,
+ type PerformanceSurveyAdminRequest,
+} from './PerformanceSurveyAdminPeople'
+
+const groups = [{
+ id: 'group-1',
+ name: '品牌设计师',
+ status: 'ready' as const,
+ memberCount: 10,
+}]
+
+function renderPeople(request: PerformanceSurveyAdminRequest) {
+ const onError = jest.fn()
+ const onSuccess = jest.fn()
+ render(
+
,
+ )
+ return { onError, onSuccess }
+}
+
+describe('PerformanceSurveyAdminPeople', () => {
+ test('使用每页 50 人,并同时提供桌面表格和移动端卡片', async () => {
+ const request = jest.fn(async () => ({
+ items: [{
+ id: 'employee-1',
+ employeeId: 'employee-1',
+ displayName: '张三',
+ departmentPath: '集团/品牌中心',
+ positionTitle: '设计师',
+ participation: 'unassigned',
+ }],
+ total: 1,
+ })) as unknown as jest.MockedFunction
+
+ renderPeople(request)
+
+ expect(screen.getByRole('status')).toHaveTextContent('正在加载人员列表')
+ await waitFor(() => expect(within(screen.getByTestId('people-mobile-cards')).getByText('张三')).toBeInTheDocument())
+ expect(screen.getByTestId('people-desktop-table')).toBeInTheDocument()
+ expect(screen.getByTestId('people-mobile-cards')).toBeInTheDocument()
+ expect(request).toHaveBeenCalledWith(expect.stringContaining('pageSize=50'))
+ expect(screen.getByRole('status')).toHaveTextContent('人员列表已更新,共 1 人')
+ })
+
+ test('选择跨页保留,并在固定批量栏一次提交全部人员', async () => {
+ const request = jest.fn(async (path: string, _options?: RequestInit) => {
+ if (path.startsWith('/admin/position-assignments?')) {
+ const page = new URL(path, 'https://example.test').searchParams.get('page')
+ return {
+ items: page === '2'
+ ? [{
+ id: 'employee-2',
+ employeeId: 'employee-2',
+ displayName: '李四',
+ departmentName: '摄影中心',
+ positionTitle: '摄影师',
+ participation: 'unassigned',
+ }]
+ : [{
+ id: 'employee-1',
+ employeeId: 'employee-1',
+ displayName: '张三',
+ departmentName: '品牌中心',
+ positionTitle: '设计师',
+ participation: 'unassigned',
+ }],
+ total: 51,
+ }
+ }
+ return {}
+ }) as unknown as jest.MockedFunction
+ const { onSuccess } = renderPeople(request)
+
+ await waitFor(() => expect(screen.getByLabelText('选择 张三')).toBeInTheDocument())
+ fireEvent.click(screen.getByLabelText('选择 张三'))
+ expect(screen.getByRole('region', { name: '批量分配所选人员' })).toHaveTextContent('已选择 1 人')
+
+ fireEvent.click(screen.getByRole('button', { name: '下一页' }))
+ await waitFor(() => expect(screen.getByLabelText('选择 李四')).toBeInTheDocument())
+ fireEvent.click(screen.getByLabelText('选择 李四'))
+ expect(screen.getByRole('region', { name: '批量分配所选人员' })).toHaveTextContent('已选择 2 人')
+
+ fireEvent.change(screen.getByLabelText('批量分配操作'), { target: { value: 'group-1' } })
+ fireEvent.change(screen.getByLabelText('本次调整原因'), { target: { value: '组织调整' } })
+ fireEvent.click(screen.getByRole('button', { name: '应用分配' }))
+
+ await waitFor(() => {
+ const call = request.mock.calls.find(([path, options]) => (
+ path === '/admin/position-assignments' && options?.method === 'POST'
+ ))
+ expect(call).toBeDefined()
+ expect(JSON.parse(String(call?.[1]?.body))).toEqual(expect.objectContaining({
+ employeeIds: ['employee-1', 'employee-2'],
+ positionGroupId: 'group-1',
+ reason: '组织调整',
+ }))
+ })
+ expect(onSuccess).toHaveBeenCalledWith('已为 2 人分配岗位')
+ })
+
+ test('网络失败显示中文可恢复提示', async () => {
+ const request = jest.fn()
+ .mockRejectedValueOnce(new Error('Failed to fetch'))
+ .mockResolvedValueOnce({ items: [], total: 0 }) as unknown as jest.MockedFunction
+
+ renderPeople(request)
+
+ expect(await screen.findByRole('alert')).toHaveTextContent('暂时无法加载人员,请检查网络后重试。')
+ expect(screen.queryByText('Failed to fetch')).not.toBeInTheDocument()
+ fireEvent.click(screen.getByRole('button', { name: '重新加载' }))
+ await waitFor(() => expect(screen.getByRole('status')).toHaveTextContent('人员列表已更新,共 0 人'))
+ })
+})
diff --git a/app/performance-survey/PerformanceSurveyAdminPeople.tsx b/app/performance-survey/PerformanceSurveyAdminPeople.tsx
index 3fd9bed8..1c4997ac 100644
--- a/app/performance-survey/PerformanceSurveyAdminPeople.tsx
+++ b/app/performance-survey/PerformanceSurveyAdminPeople.tsx
@@ -100,6 +100,12 @@ function participationLabel(row: AssignmentRow) {
return '待分配'
}
+function readTechnicalError(error: unknown) {
+ if (!(error instanceof Error)) return null
+ const detail = error.message.trim()
+ return detail && detail !== 'Failed to fetch' ? detail : null
+}
+
export function PerformanceSurveyAdminPeople({
month,
groups,
@@ -117,15 +123,16 @@ export function PerformanceSurveyAdminPeople({
const [statusFilter, setStatusFilter] = useState<'all' | 'assigned' | 'unassigned' | 'excluded'>('all')
const [rows, setRows] = useState([])
const [loading, setLoading] = useState(true)
- const [loadError, setLoadError] = useState(null)
+ const [loadError, setLoadError] = useState<{ message: string; technicalDetail: string | null } | null>(null)
const [selectedIds, setSelectedIds] = useState>(new Set())
+ const selectedRowsRef = useRef