From b2c3b20390c6ebe49ebc4f3e62c0bccded6f201b Mon Sep 17 00:00:00 2001 From: chenpei Date: Mon, 27 Jul 2026 18:00:10 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=AE=8C=E5=96=84=E8=80=83=E6=A0=B8?= =?UTF-8?q?=E5=B2=97=E4=BD=8D=E4=B8=8E=E6=A8=A1=E6=9D=BF=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PerformanceSurveyAdminConfig.test.tsx | 104 ++- .../PerformanceSurveyAdminConfig.tsx | 597 ++++++++---------- app/performance-survey/[[...path]]/page.tsx | 2 +- .../performance-survey-position-admin.test.ts | 144 +++++ ...performance-survey-position-config.test.ts | 30 + lib/performance-survey-position-config.ts | 125 +++- lib/performance-survey-service.ts | 30 +- 7 files changed, 627 insertions(+), 405 deletions(-) diff --git a/app/performance-survey/PerformanceSurveyAdminConfig.test.tsx b/app/performance-survey/PerformanceSurveyAdminConfig.test.tsx index bbea0f2f..db0b06bf 100644 --- a/app/performance-survey/PerformanceSurveyAdminConfig.test.tsx +++ b/app/performance-survey/PerformanceSurveyAdminConfig.test.tsx @@ -10,7 +10,7 @@ const templateDefinition = { description: '视觉案例评分', surveyType: 'visual_case', weight: 1, - maxTotal: 120, + maxTotal: 60, questionMaxScore: 20, requiredWorkItemCount: 3, workItemImageRequired: true, @@ -201,7 +201,7 @@ describe('PerformanceSurveyAdminConfig', () => { await waitFor(() => expect(screen.getByLabelText('岗位名称')).toHaveValue('AI 技术设计师')) }) - test('岗位页明确区分未发布草稿与当前生效方案', async () => { + test('岗位页以搜索方式维护草稿考核项,并只展示已选择内容', async () => { const configuration = { ...config, groups: config.groups.map((group: any) => group.id === 'group-1' @@ -219,9 +219,28 @@ describe('PerformanceSurveyAdminConfig', () => { const request = createRequest(configuration) render() - await waitFor(() => expect(screen.getByRole('heading', { name: '方案草稿中的考核项' })).toBeInTheDocument()) - expect(screen.getByText('以下内容尚未生效;请前往“岗位考核方案”检查并发布。')).toBeInTheDocument() - expect(screen.queryByRole('heading', { name: '2026-07 当前生效的考核项' })).not.toBeInTheDocument() + await waitFor(() => expect(screen.getByRole('heading', { name: '岗位考核项' })).toBeInTheDocument()) + expect(screen.getByText('课程分享')).toBeInTheDocument() + expect(screen.queryByText('视觉案例评分')).not.toBeInTheDocument() + + fireEvent.change(screen.getByLabelText('添加考核项'), { target: { value: '视觉案例' } }) + fireEvent.click(screen.getByRole('button', { name: /视觉案例评分/ })) + expect(screen.getByText('视觉案例评分')).toBeInTheDocument() + fireEvent.click(screen.getByRole('button', { name: '保存修改' })) + + await waitFor(() => { + const call = request.mock.calls.find(([path, options]) => ( + path === '/admin/position-groups/group-1' && options?.method === 'PATCH' + )) + expect(JSON.parse(String(call?.[1]?.body || '{}'))).toEqual({ + name: '品牌设计师', + sortOrder: 10, + templateVersionIds: ['version-2', 'version-1'], + effectiveMonth: '2026-07', + }) + }) + expect(screen.queryByText('人员匹配规则')).not.toBeInTheDocument() + expect(screen.queryByRole('button', { name: '复制岗位' })).not.toBeInTheDocument() }) test('新增岗位使用确定的 collection POST 契约', async () => { @@ -240,28 +259,6 @@ describe('PerformanceSurveyAdminConfig', () => { }))) }) - test('复制岗位只要求管理人员填写名称和原因', async () => { - const request = createRequest() - const prompt = jest.spyOn(window, 'prompt') - .mockReturnValueOnce('品牌设计师(副本)') - .mockReturnValueOnce('复用现有配置') - render() - await waitFor(() => expect(screen.getByText('品牌设计师')).toBeInTheDocument()) - - fireEvent.click(screen.getByRole('button', { name: '复制岗位' })) - - await waitFor(() => expect(request).toHaveBeenCalledWith('/admin/position-groups/group-1/copy', expect.objectContaining({ - method: 'POST', - body: JSON.stringify({ - name: '品牌设计师(副本)', - month: '2026-07', - reason: '复用现有配置', - }), - }))) - expect(prompt).toHaveBeenCalledTimes(2) - expect(prompt.mock.calls.flat().join(' ')).not.toContain('岗位代码') - }) - test('人员批量分配提交最终 REST 请求体', async () => { const request = createRequest() render() @@ -288,18 +285,19 @@ describe('PerformanceSurveyAdminConfig', () => { }) }) - test('模板发布前要求先保存 dirty 草稿,并提供复制与归档入口', async () => { + test('已发布模板通过修改按钮生成草稿,并使用统一的删除入口', async () => { const request = createRequest() render() await waitFor(() => expect(screen.getByText(/v1 · 已发布/)).toBeInTheDocument()) - fireEvent.click(screen.getByRole('button', { name: '复制为新草稿' })) + fireEvent.click(screen.getByRole('button', { name: '修改模板' })) await waitFor(() => expect(request).toHaveBeenCalledWith('/admin/templates/version-1/clone', expect.objectContaining({ method: 'POST' }))) fireEvent.change(screen.getByLabelText('模板名称'), { target: { value: '新视觉评分' } }) fireEvent.click(screen.getByRole('button', { name: /发布至/ })) expect(await screen.findByText('请先保存模板草稿,再执行发布')).toBeInTheDocument() - expect(screen.getByRole('button', { name: '归档模板' })).toBeInTheDocument() + expect(screen.getByRole('button', { name: '删除模板' })).toBeInTheDocument() + expect(screen.queryByText('使用场景')).not.toBeInTheDocument() }) test('模板编辑按基本信息、评分项、评审与计分分步展示', async () => { @@ -311,20 +309,56 @@ describe('PerformanceSurveyAdminConfig', () => { fireEvent.click(screen.getByRole('button', { name: '2. 评分项' })) expect(screen.getByRole('heading', { name: '评分项' })).toBeInTheDocument() expect(screen.getByLabelText('评分项名称')).toHaveValue('作品质量') + expect(screen.getByLabelText('总分')).toHaveValue(60) fireEvent.click(screen.getByRole('button', { name: '3. 评审与计分' })) expect(screen.getByRole('heading', { name: '评审与计分' })).toBeInTheDocument() expect(screen.getByLabelText('最终成绩规则')).toBeInTheDocument() }) - test('岗位考核方案可添加排序模板并经过影响确认后发布', async () => { - const request = createRequest() + test('模板草稿可自由增删评分项并显示总分分配状态', async () => { + const configuration = { + ...config, + templates: config.templates.map((template: any) => template.id === 'template-1' + ? { + ...template, + versions: template.versions.map((version: any) => ({ ...version, status: 'draft', effectiveMonth: null })), + } + : template), + } + const request = createRequest(configuration) + render() + await waitFor(() => expect(screen.getByRole('button', { name: '2. 评分项' })).toBeInTheDocument()) + + fireEvent.click(screen.getByRole('button', { name: '2. 评分项' })) + fireEvent.click(screen.getByRole('button', { name: '删除评分项 1' })) + expect(screen.getByText('还没有评分项,请点击“添加评分项”')).toBeInTheDocument() + fireEvent.click(screen.getByRole('button', { name: '添加评分项' })) + expect(screen.getByLabelText('评分项名称')).toHaveValue('评分项 1') + expect(screen.getByText('已分配 20 × 3 个作品 = 60 / 60 分')).toBeInTheDocument() + }) + + test('岗位考核方案只复核岗位页草稿,并经过影响确认后发布', async () => { + const configuration = { + ...config, + groups: config.groups.map((group: any) => group.id === 'group-1' + ? { + ...group, + draftPlan: { + id: 'plan-1', + version: 2, + effectiveMonth: '2026-07', + templateVersionIds: ['version-1', 'version-2'], + }, + } + : group), + } + const request = createRequest(configuration) render() await waitFor(() => expect(screen.getByRole('heading', { name: '岗位考核方案' })).toBeInTheDocument()) - const courseLabel = screen.getByText('课程分享').closest('label') - expect(courseLabel).not.toBeNull() - fireEvent.click(courseLabel!.querySelector('input')!) + expect(screen.getByRole('heading', { name: '待发布的考核项' })).toBeInTheDocument() + expect(screen.queryByRole('heading', { name: '可用已发布模板' })).not.toBeInTheDocument() fireEvent.click(screen.getByRole('button', { name: '发布前检查' })) await waitFor(() => expect(screen.getByRole('region', { name: '发布影响确认' })).toBeInTheDocument()) diff --git a/app/performance-survey/PerformanceSurveyAdminConfig.tsx b/app/performance-survey/PerformanceSurveyAdminConfig.tsx index 48b9691d..3f0b3f41 100644 --- a/app/performance-survey/PerformanceSurveyAdminConfig.tsx +++ b/app/performance-survey/PerformanceSurveyAdminConfig.tsx @@ -10,11 +10,6 @@ type RequestFn = PerformanceSurveyAdminRequest export type PerformanceSurveyAdminMode = 'overview' | 'positions' | 'people' | 'templates' | 'plans' -type RuleDraft = { - departmentPathPrefix: string - positionTitle: string -} - type ReviewerSource = 'self' | 'direct_manager' | 'fixed_employee' | 'manual_selection' type ReviewerDraft = { @@ -82,7 +77,13 @@ type PositionGroupRecord = { isActive: boolean status: 'ready' | 'pending' | 'disabled' memberCount: number - rules: Array + rules: Array<{ + id: string + departmentPathPrefix: string + positionTitle: string + isActive: boolean + sortOrder: number + }> effectivePlan: null | { id: string version: number @@ -132,27 +133,17 @@ const adminConfigApi = { body: JSON.stringify(input), }) }, - copyPositionGroup( - request: RequestFn, - groupId: string, - input: { name: string; month: string; reason: string }, - ) { - return request<{ id?: string; group?: { id?: string } }>(`/admin/position-groups/${groupId}/copy`, { - method: 'POST', - body: JSON.stringify(input), - }) - }, previewPositionGroup(request: RequestFn, groupId: string, month: string) { return request(`/admin/position-groups/${groupId}/preview?month=${encodeURIComponent(month)}`) }, - archivePositionGroup(request: RequestFn, groupId: string, reason: string) { - return request(`/admin/position-groups/${groupId}`, { + removePositionGroup(request: RequestFn, groupId: string, reason: string) { + return request<{ id: string; action: 'deleted' | 'archived' }>(`/admin/position-groups/${groupId}`, { method: 'DELETE', body: JSON.stringify({ mode: 'auto', reason }), }) }, - deleteOrArchiveTemplate(request: RequestFn, templateId: string, reason: string) { - return request(`/admin/templates/${templateId}`, { + removeTemplate(request: RequestFn, templateId: string, reason: string) { + return request<{ id: string; action: 'deleted' | 'archived' }>(`/admin/templates/${templateId}`, { method: 'DELETE', body: JSON.stringify({ mode: 'auto', reason }), }) @@ -176,8 +167,8 @@ function newTemplateDefinition(): TemplateDefinition { description: '', surveyType: 'person_period', weight: 1, - maxTotal: 120, - questions: [{ id: 'score_1', title: '评分项 1', description: '', maxScore: 20 }], + maxTotal: 100, + questions: [{ id: `score_${Date.now().toString(36)}`, title: '评分项 1', description: '', maxScore: 100 }], scoreBands: [], workflow: { stages: [{ @@ -202,9 +193,9 @@ function reviewerSourceLabel(source: ReviewerSource) { function surveyTypeLabel(type: TemplateDefinition['surveyType']) { return { - person_period: '人员周期评分', - visual_case: '视觉案例评分', - item_course: '事项 / 课程评分', + person_period: '按人员评分', + visual_case: '按作品评分', + item_course: '按课程或事项评分', }[type] } @@ -312,7 +303,7 @@ export function PerformanceSurveyAdminConfig({ : mode === 'templates' ? '已发布模板会长期使用;只有评分规则变化时才创建新版本' : mode === 'positions' - ? '岗位名称、人员匹配规则等修改会先保存为草稿,发布后生效' + ? '岗位名称、排序和考核项修改会先保存为草稿,发布后生效' : mode === 'plans' ? `正在查看 ${month} 的生效方案;已发布方案会持续沿用` : `正在维护 ${month};已发布版本保持不变`} @@ -397,9 +388,6 @@ export function PerformanceSurveyAdminConfig({ request={request} onError={setError} onChanged={changed} - onDirtyChange={setDirtyState} - confirmDiscard={confirmDiscard} - dirty={dirty} /> )} @@ -423,7 +411,6 @@ function AdminOverviewWorkspace({ const [auditError, setAuditError] = useState(null) const [auditLoading, setAuditLoading] = useState(true) 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 @@ -439,7 +426,7 @@ function AdminOverviewWorkspace({ )).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 positionsReady = activeGroups.length > 0 const templatesReady = availablePublishedTemplates > 0 const plansReady = activeGroups.length > 0 && effectivePlanCount === activeGroups.length const launchReady = positionsReady && templatesReady && plansReady && data.issues.conflicts.length === 0 @@ -462,7 +449,7 @@ function AdminOverviewWorkspace({ status: positionsReady ? 'done' : 'attention', summary: activeGroups.length === 0 ? '还没有可用岗位' - : `${groupsWithMatchingRules}/${activeGroups.length} 个在用岗位已完成匹配规则${disabledGroups > 0 ? `,另有 ${disabledGroups} 个已归档` : ''}`, + : `${activeGroups.length} 个岗位可用;人员归属请在“人员分配”中维护${disabledGroups > 0 ? `,另有 ${disabledGroups} 个已删除` : ''}`, action: '管理岗位', target: 'positions' as const, }, @@ -641,13 +628,10 @@ function PositionConfigWorkspace({ const selected = data.groups.find((group) => group.id === selectedId) || data.groups[0] const [name, setName] = useState(selected?.name || '') const [sortOrder, setSortOrder] = useState(selected?.sortOrder || 0) - const [rules, setRules] = useState(selected?.rules.map((rule) => ({ - departmentPathPrefix: rule.departmentPathPrefix || '', - positionTitle: rule.positionTitle || '', - })) || []) const [templateVersionIds, setTemplateVersionIds] = useState( selected?.draftPlan?.templateVersionIds || selected?.effectivePlan?.templateVersionIds || [], ) + const [templateSearch, setTemplateSearch] = useState('') const [saving, setSaving] = useState(false) const [creating, setCreating] = useState(false) const [newName, setNewName] = useState('') @@ -657,11 +641,8 @@ function PositionConfigWorkspace({ if (!selected) return setName(selected.name) setSortOrder(selected.sortOrder) - setRules(selected.rules.map((rule) => ({ - departmentPathPrefix: rule.departmentPathPrefix || '', - positionTitle: rule.positionTitle || '', - }))) setTemplateVersionIds(selected.draftPlan?.templateVersionIds || selected.effectivePlan?.templateVersionIds || []) + setTemplateSearch('') onDirtyChange(false) }, [onDirtyChange, selected]) @@ -669,9 +650,30 @@ function PositionConfigWorkspace({ const publishedVersions = useMemo(() => data.templates.flatMap((template) => ( template.versions - .filter((version) => version.status === 'published') + .filter((version) => ( + version.status === 'published' + && (!version.effectiveMonth || version.effectiveMonth <= month) + )) .map((version) => ({ template, version })) - )), [data.templates]) + )), [data.templates, month]) + const versionById = useMemo( + () => new Map(publishedVersions.map((item) => [item.version.id, item])), + [publishedVersions], + ) + const searchResults = useMemo(() => { + const keyword = templateSearch.trim().toLocaleLowerCase('zh-CN') + if (!keyword) return [] + const selectedTemplateIds = new Set( + templateVersionIds + .map((id) => versionById.get(id)?.template.id) + .filter(Boolean), + ) + return publishedVersions.filter(({ template, version }) => ( + !templateVersionIds.includes(version.id) + && !selectedTemplateIds.has(template.id) + && `${version.definition.name} ${template.name}`.toLocaleLowerCase('zh-CN').includes(keyword) + )).slice(0, 8) + }, [publishedVersions, templateSearch, templateVersionIds, versionById]) if (!selected) return
暂无岗位组
@@ -681,9 +683,9 @@ function PositionConfigWorkspace({ try { await request(`/admin/position-groups/${selected.id}`, { method: 'PATCH', - body: JSON.stringify({ name, sortOrder, rules, templateVersionIds, effectiveMonth: month }), + body: JSON.stringify({ name, sortOrder, templateVersionIds, effectiveMonth: month }), }) - await onChanged('岗位方案草稿已保存') + await onChanged('岗位和考核项修改已保存,发布后生效') } catch (actionError) { onError(actionError instanceof Error ? actionError.message : '岗位方案保存失败') } finally { @@ -715,46 +717,52 @@ function PositionConfigWorkspace({ } } - const copyGroup = async () => { + const removeGroup = async () => { if (!selected || !confirmDiscard()) return - const copyName = window.prompt('请输入复制后的岗位名称', `${selected.name}(副本)`)?.trim() - if (!copyName) return - const reason = window.prompt('请输入复制原因', `基于“${selected.name}”创建新岗位`)?.trim() + const memberWarning = selected.memberCount > 0 + ? `当前仍有 ${selected.memberCount} 人属于该岗位,删除后这些人员会变为待分配。` + : '该岗位当前没有人员。' + if (!window.confirm(`确认删除岗位“${selected.name}”吗?${memberWarning}历史调研记录不会删除。`)) return + const reason = window.prompt('请输入删除原因(用于操作记录)')?.trim() if (!reason) return setSaving(true) onError(null) try { - const copied = await adminConfigApi.copyPositionGroup(request, selected.id, { - name: copyName, - month, - reason, - }) - const next = await onChanged(`已复制“${selected.name}”`) - if (copied.id || copied.group?.id) setSelectedId(copied.id || copied.group?.id || '') - else if (next?.groups.length) setSelectedId(next.groups[next.groups.length - 1].id) + const result = await adminConfigApi.removePositionGroup(request, selected.id, reason) + const next = await onChanged( + result.action === 'deleted' + ? `岗位“${selected.name}”已删除` + : `岗位“${selected.name}”已从管理列表删除,历史记录已保留`, + ) + setSelectedId(next?.groups[0]?.id || '') } catch (actionError) { - onError(actionError instanceof Error ? actionError.message : '岗位复制失败') + onError(actionError instanceof Error ? actionError.message : '岗位删除失败') } finally { setSaving(false) } } - const archiveGroup = async () => { - if (!selected || !confirmDiscard()) return - if (!window.confirm(`确认归档“${selected.name}”吗?归档前请确认相关人员已完成转岗。`)) return - const reason = window.prompt('请输入删除或归档原因')?.trim() - if (!reason) return - setSaving(true) - onError(null) - try { - await adminConfigApi.archivePositionGroup(request, selected.id, reason) - const next = await onChanged(`“${selected.name}”已归档`) - setSelectedId(next?.groups.find((group) => group.status !== 'disabled')?.id || next?.groups[0]?.id || '') - } catch (actionError) { - onError(actionError instanceof Error ? actionError.message : '岗位归档失败') - } finally { - setSaving(false) - } + const addTemplateVersion = (versionId: string) => { + setTemplateVersionIds((current) => current.includes(versionId) ? current : [...current, versionId]) + setTemplateSearch('') + markDirty() + } + + const removeTemplateVersion = (versionId: string) => { + setTemplateVersionIds((current) => current.filter((id) => id !== versionId)) + markDirty() + } + + const moveTemplateVersion = (index: number, direction: -1 | 1) => { + const targetIndex = index + direction + if (targetIndex < 0 || targetIndex >= templateVersionIds.length) return + setTemplateVersionIds((current) => { + const next = [...current] + const [moved] = next.splice(index, 1) + next.splice(targetIndex, 0, moved) + return next + }) + markDirty() } const selectGroup = (groupId: string) => { @@ -816,147 +824,86 @@ function PositionConfigWorkspace({
正在编辑:{selected.name}
-

岗位名称、排序和人员匹配规则保存后进入草稿,需要发布岗位考核方案后才会生效。

-
-
- - {selected.status !== 'disabled' && ( - - )} +

岗位名称、排序和考核项保存后进入草稿,需要发布岗位考核方案后才会生效。

+
-
+
{ setName(value); markDirty() }} /> { setSortOrder(Number(value) || 0); markDirty() }} type="number" />
-
-
-

人员匹配规则

-

每行内条件同时满足,多行之间满足任意一行即可

-
- -
-
- {rules.map((rule, index) => ( -
- { - setRules((current) => current.map((item, itemIndex) => itemIndex === index ? { ...item, departmentPathPrefix: event.target.value } : item)) - markDirty() - }} - placeholder="部门路径前缀,例如 品牌中心/品牌创意A部" - aria-label={`规则 ${index + 1} 部门路径前缀`} - className="h-11 rounded border border-[#c2c6d8] px-3 text-[13px] outline-none focus:border-[#0050cb]" - /> - { - setRules((current) => current.map((item, itemIndex) => itemIndex === index ? { ...item, positionTitle: event.target.value } : item)) - markDirty() - }} - placeholder="职位名称(精确匹配)" - aria-label={`规则 ${index + 1} 职位名称`} - className="h-11 rounded border border-[#c2c6d8] px-3 text-[13px] outline-none focus:border-[#0050cb]" - /> - -
- ))} - {rules.length === 0 &&
未配置规则,岗位不能发布
} -
-
- -
-

- {selected.draftPlan ? '方案草稿中的考核项' : `${month} 当前生效的考核项`} -

-

- {selected.draftPlan - ? '以下内容尚未生效;请前往“岗位考核方案”检查并发布。' - : '这里只读展示;添加、移除和排序请前往“岗位考核方案”。'} +

岗位考核项

+

+ 在这里选择该岗位需要参加的考核。保存后会形成草稿,再到“岗位考核方案”检查并发布。

-
- {publishedVersions.map(({ template, version }) => { - const checked = templateVersionIds.includes(version.id) +
+ + {templateSearch.trim() && ( +
+ {searchResults.map(({ template, version }) => ( + + ))} + {searchResults.length === 0 && ( +
没有可添加的匹配模板
+ )} +
+ )} +
+
+ {templateVersionIds.map((id, index) => { + const item = versionById.get(id) return ( - +
+
+
{item?.version.definition.name || item?.template.name || '历史模板'}
+
+ 第 {index + 1} 项{item ? ` · v${item.version.version}` : ''} +
+
+
+ + + +
+
) })} + {templateVersionIds.length === 0 && ( +
+ 尚未选择考核项,请通过上方搜索框添加 +
+ )}
- 考核模板组合与顺序请在“岗位考核方案”中维护 + 保存后请前往“岗位考核方案”发布生效
- - {(data.issues.conflicts.length > 0 || data.issues.unmatched.length > 0) && ( -
-

配置问题

-
- 未匹配 {data.issues.unmatched.length} 人 · 重复匹配 {data.issues.conflicts.length} 人 -
-
- {data.issues.unmatched.length > 0 && ( -
-
未匹配人员
-
- {data.issues.unmatched.map((item) => ( -
- {item.displayName} - {item.departmentPath || item.departmentName || '未填写部门'} · {item.positionTitle || '未填写职位'} -
- ))} -
-
- )} - {data.issues.conflicts.length > 0 && ( -
-
重复匹配人员
-
- {data.issues.conflicts.map((item) => ( -
- {item.displayName}:{item.groupNames.join('、')} -
- ))} -
-
- )} -
-
- )}
) @@ -1005,6 +952,15 @@ function TemplateConfigWorkspace({ const version = selectedTemplate?.versions.find((item) => item.id === versionId) || null const editable = !version || version.status === 'draft' + const questionTotal = definition.questions.reduce( + (sum, question) => sum + Number(question.maxScore || definition.questionMaxScore || 20), + 0, + ) + const calculatedTemplateTotal = questionTotal * ( + definition.surveyType === 'visual_case' ? Math.max(1, Number(definition.requiredWorkItemCount || 1)) : 1 + ) + const templateDefinitionReady = definition.questions.length > 0 + && Math.round(calculatedTemplateTotal * 100) === Math.round(Number(definition.maxTotal || 0) * 100) const updateDefinition = (next: TemplateDefinition | ((current: TemplateDefinition) => TemplateDefinition)) => { setDefinition(next) onDirtyChange(true) @@ -1074,21 +1030,24 @@ function TemplateConfigWorkspace({ } } - const deleteOrArchiveTemplate = async () => { + const removeTemplate = async () => { if (!selectedTemplate || !confirmDiscard()) return - const onlyDrafts = selectedTemplate.versions.every((item) => item.status === 'draft') - const actionLabel = onlyDrafts ? '删除' : '归档' - if (!window.confirm(`确认${actionLabel}模板“${selectedTemplate.name}”吗?已被历史调研引用的数据不会删除。`)) return - const reason = window.prompt(`请输入${actionLabel}原因`)?.trim() + const displayName = version?.definition.name || selectedTemplate.versions[0]?.definition.name || selectedTemplate.name + if (!window.confirm(`确认删除模板“${displayName}”吗?已被历史调研引用的数据会保留;正在被岗位使用的模板需要先从岗位考核项中移除。`)) return + const reason = window.prompt('请输入删除原因(用于操作记录)')?.trim() if (!reason) return setSaving(true) onError(null) try { - await adminConfigApi.deleteOrArchiveTemplate(request, selectedTemplate.id, reason) - const next = await onChanged(`模板“${selectedTemplate.name}”已${actionLabel}`) + const result = await adminConfigApi.removeTemplate(request, selectedTemplate.id, reason) + const next = await onChanged( + result.action === 'deleted' + ? `模板“${displayName}”已删除` + : `模板“${displayName}”已从模板列表删除,历史记录已保留`, + ) setSelectedTemplateId(next?.templates[0]?.id || 'new') } catch (actionError) { - onError(actionError instanceof Error ? actionError.message : `模板${actionLabel}失败`) + onError(actionError instanceof Error ? actionError.message : '模板删除失败') } finally { setSaving(false) } @@ -1107,13 +1066,15 @@ function TemplateConfigWorkspace({ return (
-
正在编辑:{selectedTemplate?.name || '新建模板'}
+
正在编辑:{definition.name || '新建模板'}
{selectedTemplate && (
{selectedTemplate.versions.map((item) => ( @@ -1152,10 +1113,10 @@ function TemplateConfigWorkspace({
)} @@ -1172,9 +1133,9 @@ function TemplateConfigWorkspace({
- {definition.questions.reduce((sum, question) => sum + Number(question.maxScore || definition.questionMaxScore || 20), 0)} + {Number(definition.maxTotal || 0)}
-
评分项合计
+
模板总分
{version ? `v${version.version}` : '新建'}
@@ -1211,19 +1172,23 @@ function TemplateConfigWorkspace({

管理员和员工都会看到这些名称与说明。

- updateDefinition((current) => ({ ...current, name: value }))} disabled={!editable} /> - updateDefinition((current) => ({ ...current, shortName: value }))} disabled={!editable} /> + updateDefinition((current) => ({ ...current, name: value, shortName: value }))} + disabled={!editable} + /> {definition.surveyType === 'visual_case' && ( @@ -1245,13 +1210,6 @@ function TemplateConfigWorkspace({ />
-
- 高级设置(一般无需修改) -
- updateDefinition((current) => ({ ...current, code: value }))} disabled={Boolean(selectedTemplate) || !editable} /> -

新建时已自动生成;创建后不可修改,仅用于系统识别。

-
-
)} @@ -1263,9 +1221,19 @@ function TemplateConfigWorkspace({ )}
- {!editable && } + {!editable && } {editable && } - {editable && versionId && } + {editable && versionId && ( + + )}
@@ -1278,18 +1246,12 @@ function MonthlyPlanWorkspace({ request, onError, onChanged, - onDirtyChange, - confirmDiscard, - dirty, }: { data: AdminConfig month: string request: RequestFn onError: (message: string | null) => void onChanged: (message: string) => Promise - onDirtyChange: (dirty: boolean) => void - confirmDiscard: (message?: string) => boolean - dirty: boolean }) { const [selectedGroupId, setSelectedGroupId] = useState(data.groups.find((group) => group.status !== 'disabled')?.id || data.groups[0]?.id || '') const group = data.groups.find((item) => item.id === selectedGroupId) || data.groups[0] @@ -1309,65 +1271,23 @@ function MonthlyPlanWorkspace({ if (!group) return setTemplateVersionIds(group.draftPlan?.templateVersionIds || group.effectivePlan?.templateVersionIds || []) setPreview(null) - onDirtyChange(false) - }, [group, onDirtyChange]) + }, [group]) const changeGroup = (groupId: string) => { if (groupId === selectedGroupId) return - if (!confirmDiscard('切换岗位会放弃当前岗位考核方案修改,确定继续吗?')) return - onDirtyChange(false) setSelectedGroupId(groupId) } - const moveVersion = (index: number, direction: -1 | 1) => { - const target = index + direction - if (target < 0 || target >= templateVersionIds.length) return - setTemplateVersionIds((current) => { - const next = [...current] - const [moved] = next.splice(index, 1) - next.splice(target, 0, moved) - return next - }) - setPreview(null) - onDirtyChange(true) - } - - const toggleVersion = (versionId: string, checked: boolean) => { - setTemplateVersionIds((current) => checked ? [...current, versionId] : current.filter((id) => id !== versionId)) - setPreview(null) - onDirtyChange(true) - } - - const saveDraft = async (showSuccess = true) => { - if (!group) return false - setSaving(true) - onError(null) - try { - await request(`/admin/position-groups/${group.id}`, { - method: 'PATCH', - body: JSON.stringify({ templateVersionIds, effectiveMonth: month }), - }) - if (showSuccess) await onChanged(`${group.name} 的岗位考核方案草稿已保存,计划从 ${month} 起生效`) - else onDirtyChange(false) - return true - } catch (actionError) { - onError(actionError instanceof Error ? actionError.message : '岗位考核方案保存失败') - return false - } finally { - setSaving(false) - } - } - const openPublishPreview = async () => { if (!group) return + if (!group.draftPlan) { + onError('当前没有待发布的岗位修改,请先到“岗位”页面调整考核项并保存') + return + } if (templateVersionIds.length === 0) { onError('岗位考核方案至少需要 1 个已发布模板') return } - if (dirty) { - const saved = await saveDraft(false) - if (!saved) return - } setSaving(true) onError(null) try { @@ -1389,11 +1309,6 @@ function MonthlyPlanWorkspace({ const publishPlan = async () => { if (!group) return - if (dirty) { - onError('岗位考核方案在预览后又发生了修改,请重新执行发布前检查') - setPreview(null) - return - } const draftPlanId = String(preview?.draftPlanId || '').trim() const draftVersion = Number(preview?.draftVersion) const draftUpdatedAt = String(preview?.draftUpdatedAt || '').trim() @@ -1454,11 +1369,13 @@ function MonthlyPlanWorkspace({

- 已发布方案会从生效月份起持续沿用,后续月份无需重复发布。只有岗位名称、排序、人员匹配规则、考核模板或排列顺序发生变化时,才需要发布新方案。 + 已发布方案会从生效月份起持续沿用,后续月份无需重复发布。请先在“岗位”页面调整考核项并保存,再到这里检查影响并发布。

-

模板顺序

+

+ {group.draftPlan ? '待发布的考核项' : '当前生效的考核项'} +

@@ -1466,7 +1383,6 @@ function MonthlyPlanWorkspace({ - @@ -1475,38 +1391,17 @@ function MonthlyPlanWorkspace({ return ( - + - ) })} - {templateVersionIds.length === 0 && } + {templateVersionIds.length === 0 && }
顺序 模板 版本调整
{index + 1}{item?.version.definition.shortName || item?.template.name || '历史模板版本'}{item?.version.definition.name || item?.template.name || '历史模板版本'} {item ? `v${item.version.version}` : id} - - - -
尚未选择模板
尚未选择考核项,请先到“岗位”页面添加
-
-

可用已发布模板

-
- {publishedVersions.map(({ template, version }) => { - const checked = templateVersionIds.includes(version.id) - return ( - - ) - })} -
-
- {preview && (

发布影响确认

@@ -1530,8 +1425,10 @@ function MonthlyPlanWorkspace({ )}
- - + + {group.draftPlan ? '当前有待发布修改' : '当前没有待发布修改'} + +
) @@ -1546,12 +1443,23 @@ function QuestionEditor({ editable: boolean onChange: (definition: TemplateDefinition) => void }) { + const perItemTotal = definition.questions.reduce( + (sum, question) => sum + Number(question.maxScore || definition.questionMaxScore || 20), + 0, + ) + const workItemCount = definition.surveyType === 'visual_case' + ? Math.max(1, Number(definition.requiredWorkItemCount || 1)) + : 1 + const allocatedTotal = perItemTotal * workItemCount + const configuredTotal = Number(definition.maxTotal || 0) + const totalMatches = Math.round(allocatedTotal * 100) === Math.round(configuredTotal * 100) + return (

评分项

-

评分人将逐项打分,右侧满分会决定该项可填写的最高分。

+

评分人将逐项打分;所有评分项满分之和必须等于总分。

{editable && ( )}
+
+ +
+ {definition.surveyType === 'visual_case' + ? `已分配 ${perItemTotal} × ${workItemCount} 个作品 = ${allocatedTotal} / ${configuredTotal || 0} 分` + : `已分配 ${allocatedTotal} / ${configuredTotal || 0} 分`} + {!totalMatches && 请调整评分项满分或总分,二者一致后才能发布。} +
+
+ {definition.questions.length === 0 && ( +
+ 还没有评分项,请点击“添加评分项” +
+ )} {definition.questions.map((question, index) => (
@@ -1579,26 +1511,25 @@ function QuestionEditor({ {editable && ( )}
-
-
- 高级设置 - -
))}
@@ -1901,14 +1820,14 @@ function AdminField({ disabled?: boolean }) { return ( -