diff --git a/app/api/performance-survey/[...path]/route.ts b/app/api/performance-survey/[...path]/route.ts
index 1a37c450..cda50ec4 100644
--- a/app/api/performance-survey/[...path]/route.ts
+++ b/app/api/performance-survey/[...path]/route.ts
@@ -37,6 +37,7 @@ import {
publishPerformanceSurveyAdminPositionGroup,
savePerformanceSurveyAdminTemplate,
clonePerformanceSurveyAdminTemplateVersion,
+ copyPerformanceSurveyAdminTemplateVersion,
publishPerformanceSurveyAdminTemplateVersion,
archivePerformanceSurveyAdminPositionAssignment,
copyPerformanceSurveyAdminPositionGroup,
@@ -298,6 +299,10 @@ export async function POST(request: Request, context: RouteContext) {
return ok(await clonePerformanceSurveyAdminTemplateVersion(session, path[2]), { status: 201 })
}
+ if (path[0] === 'admin' && path[1] === 'templates' && path[2] && path[3] === 'copy') {
+ return ok(await copyPerformanceSurveyAdminTemplateVersion(session, path[2]), { status: 201 })
+ }
+
if (path[0] === 'admin' && path[1] === 'templates' && path[2] && path[3] === 'publish') {
return ok(await publishPerformanceSurveyAdminTemplateVersion(session, path[2], body))
}
diff --git a/app/performance-survey/PerformanceSurveyAdminConfig.test.tsx b/app/performance-survey/PerformanceSurveyAdminConfig.test.tsx
index 5517dd30..0a2782fe 100644
--- a/app/performance-survey/PerformanceSurveyAdminConfig.test.tsx
+++ b/app/performance-survey/PerformanceSurveyAdminConfig.test.tsx
@@ -142,6 +142,9 @@ function createRequest(configuration = config) {
if (path === '/admin/templates/template-1' && options?.method === 'DELETE') {
return { id: 'template-1', action: 'deleted' }
}
+ if (path.endsWith('/copy')) {
+ return { id: 'copied-version-1', templateId: 'copied-template-1', name: '视觉案例评分(副本)' }
+ }
if (path.endsWith('/clone')) return { id: 'draft-version-2' }
return {}
})
@@ -437,6 +440,23 @@ describe('PerformanceSurveyAdminConfig', () => {
expect(screen.queryByText('使用场景')).not.toBeInTheDocument()
})
+ test('已发布模板可通过修改按钮左侧的复制按钮创建独立草稿', async () => {
+ const request = createRequest()
+ render()
+ await waitFor(() => expect(screen.getByRole('button', { name: /视觉案例评分.*可用/ })).toBeInTheDocument())
+
+ const copyButton = screen.getByRole('button', { name: '复制模板' })
+ const modifyButton = screen.getByRole('button', { name: '修改模板' })
+ expect(copyButton.nextElementSibling).toBe(modifyButton)
+
+ fireEvent.click(copyButton)
+
+ await waitFor(() => expect(request).toHaveBeenCalledWith(
+ '/admin/templates/version-1/copy',
+ expect.objectContaining({ method: 'POST', body: '{}' }),
+ ))
+ })
+
test('模板列表将所有已发布版本视为立即可用', async () => {
const configuration = {
...config,
diff --git a/app/performance-survey/PerformanceSurveyAdminConfig.tsx b/app/performance-survey/PerformanceSurveyAdminConfig.tsx
index e1c99294..e09de43b 100644
--- a/app/performance-survey/PerformanceSurveyAdminConfig.tsx
+++ b/app/performance-survey/PerformanceSurveyAdminConfig.tsx
@@ -1339,6 +1339,33 @@ function TemplateConfigWorkspace({
}
}
+ const copyTemplate = async () => {
+ if (!versionId || !selectedTemplate || !await confirmDiscard()) return
+ setSaving(true)
+ onError(null)
+ setOperationFeedback({ state: 'saving', message: '正在复制模板…' })
+ try {
+ const copied = await request<{ id: string; templateId: string; name: string }>(
+ `/admin/templates/${versionId}/copy`,
+ { method: 'POST', body: '{}' },
+ )
+ const next = await onChanged(`已复制为“${copied.name}”草稿`)
+ const nextTemplate = next?.templates.find((template) => (
+ template.id === copied.templateId
+ || template.versions.some((item) => item.id === copied.id)
+ ))
+ if (nextTemplate) setSelectedTemplateId(nextTemplate.id)
+ setVersionId(copied.id)
+ setOperationFeedback({ state: 'saved', message: `已复制为“${copied.name}”草稿` })
+ } catch (actionError) {
+ const message = actionError instanceof Error ? actionError.message : '模板复制失败'
+ onError(message)
+ setOperationFeedback({ state: 'error', message: `复制失败:${message}` })
+ } finally {
+ setSaving(false)
+ }
+ }
+
const publish = async () => {
if (!versionId) return
if (dirty) {
@@ -1700,14 +1727,24 @@ function TemplateConfigWorkspace({
{!editable && (
-
+ <>
+
+
+ >
)}
{editable && (