diff --git a/app/performance-survey/[[...path]]/page.tsx b/app/performance-survey/[[...path]]/page.tsx index 147448a9..67d36a68 100644 --- a/app/performance-survey/[[...path]]/page.tsx +++ b/app/performance-survey/[[...path]]/page.tsx @@ -8,6 +8,7 @@ import { useSession } from 'next-auth/react' import { pinyin } from 'pinyin-pro' import { createPortal } from 'react-dom' import { sortPerformanceSurveyImagesByName } from '@/lib/performance-survey-image-order' +import { preparePerformanceSurveyImagesInBrowser } from '@/lib/performance-survey-image-browser' import { calculatePerformanceSurveyResponseProgress } from '@/lib/performance-survey-response-progress' import { groupVisualScoresByEvaluator } from '@/lib/performance-survey-result-grouping' @@ -220,8 +221,18 @@ async function uploadPerformanceSurveyImageFiles( onProgress?: (label: string) => void, ) { const { chunkUpload } = await import('@/lib/chunk-upload') - const uploaded: Array<{ uploadId: string; mimeType: string }> = [] - const orderedFiles = sortPerformanceSurveyImagesByName(files, (file) => file.name) + const uploaded: Array<{ + uploadId: string + mimeType: 'image/webp' + width: number + height: number + kind: 'slice' | 'preview' + sourceName: string + sourceIndex: number + sliceIndex: number + sliceCount: number + }> = [] + const processedImages = await preparePerformanceSurveyImagesInBrowser(files, onProgress) const dingtalkToken = getStoredDingtalkPerformanceToken() const requestHeaders = dingtalkToken ? { @@ -230,16 +241,27 @@ async function uploadPerformanceSurveyImageFiles( } : undefined - for (let index = 0; index < orderedFiles.length; index += 1) { - const file = orderedFiles[index] - onProgress?.(`正在上传图片 ${index + 1}/${orderedFiles.length}`) + for (let index = 0; index < processedImages.length; index += 1) { + const image = processedImages[index] + const file = image.file + onProgress?.(`正在上传处理结果 ${index + 1}/${processedImages.length}`) const result = await chunkUpload( file, { materialType: '考核调研-视觉评分', fileName: file.name }, { skipComplete: true, requestHeaders }, ) if (!result?.uploadId) throw new Error(`图片「${file.name}」上传失败,请重试`) - uploaded.push({ uploadId: result.uploadId, mimeType: file.type }) + uploaded.push({ + uploadId: result.uploadId, + mimeType: image.mimeType, + width: image.width, + height: image.height, + kind: image.kind, + sourceName: image.sourceName, + sourceIndex: image.sourceIndex, + sliceIndex: image.sliceIndex, + sliceCount: image.sliceCount, + }) } return uploaded @@ -2832,7 +2854,7 @@ function CreateSurveyForm({ templateVariant: selectedTemplateInfo?.templateVariant || null, assessmentMonth: selectedAssessmentMonth, dueAt: deadlineAt ? new Date(deadlineAt).toISOString() : null, - openNow, + openNow: visualTemplateSelected ? false : openNow, targetEmployeeIds: effectiveTargetEmployees.map((employee) => employee.id), targetItems: targetItemsToSubmit, evaluatorEmployeeIds: evaluatorEmployees.map((employee) => employee.id), @@ -2858,10 +2880,17 @@ function CreateSurveyForm({ targetId: uploadTarget.id, title: draft.title.trim() || `案例 ${index + 1}`, description: draft.description.trim(), - images, + processedImages: images, }), }) } + + setPublishingLabel('正在确认作品并发布调研') + const opened = await apiRequest(`/surveys/${created.id}`, { + method: 'PATCH', + body: JSON.stringify({ status: 'open' }), + }) + setCreatedSurvey(opened) } setTitle('') @@ -2886,7 +2915,7 @@ function CreateSurveyForm({ const message = err instanceof Error ? err.message : '创建失败' setError( createdForAttempt && visualTemplateSelected - ? `调研已创建,但作品没有全部上传完成:${message}` + ? `调研尚未发布,作品没有全部上传完成:${message}` : message, ) } finally { @@ -3077,21 +3106,31 @@ function CreateSurveyForm({ onClick={submit} className="h-12 w-full rounded bg-[#0050cb] px-5 text-[15px] font-bold text-white hover:bg-[#003fa4] disabled:cursor-not-allowed disabled:bg-[#aeb9c9]" > - {saving ? publishingLabel || '发布中...' : createdSurvey ? '调研已发布' : visualTemplateSelected ? '发布并开始自评' : '发布调研'} + {saving + ? publishingLabel || '发布中...' + : createdSurvey?.status === 'open' + ? '调研已发布' + : createdSurvey + ? '调研待完成' + : visualTemplateSelected + ? '上传作品并发布' + : '发布调研'} {createdSurvey && (
- {isVisualTemplate(selectedTemplateInfo) && !currentTargetSelected - ? '已发布,已通知被考核人提交作品' - : '已发布'} + {createdSurvey.status === 'open' + ? isVisualTemplate(selectedTemplateInfo) && !currentTargetSelected + ? '已发布,已通知被考核人提交作品' + : '已发布' + : '尚未发布,请继续上传作品;作品完整后才能发布'} {createdUploadTarget?.id && ( - 上传作品 + {createdSurvey.status === 'open' ? '查看作品' : '继续上传'} )}
@@ -3177,7 +3216,8 @@ function PerformanceSurveyImageDropzone({ > ↑ {dragging ? '松开即可添加' : '拖拽图片到这里'} - 或点击选择 · 单张长图,或最多 60 张有序切片;单张 200MB + 或点击选择 · 单张长图由浏览器切片,多张按数字文件名顺序处理上传;单张 200MB + 请使用桌面版 Chrome 或 Edge ) @@ -4344,10 +4384,32 @@ function VisualCaseSurvey({ }) { const requiredCount = Number(template?.requiredWorkItemCount || 3) const workItems = activeTarget?.workItems || [] - const canUpload = Boolean(activeTarget?.canUploadWorkItems && detail.data?.status === 'open') + const canUpload = Boolean(activeTarget?.canUploadWorkItems && ['draft', 'open'].includes(detail.data?.status)) const canScore = Boolean(activeTarget?.currentAssignment && detail.data?.status === 'open') const submitted = activeTarget?.currentAssignment?.status === 'submitted' const completedScores = workItems.filter((item: any) => item.scores?.length > 0).length + const [publishing, setPublishing] = useState(false) + const [publishError, setPublishError] = useState(null) + const draftReadyToPublish = detail.data?.status === 'draft' + && Boolean(detail.data?.canManage) + && workItems.length >= requiredCount + + const publishDraft = async () => { + if (!draftReadyToPublish || publishing) return + setPublishing(true) + setPublishError(null) + try { + await apiRequest(`/surveys/${surveyId}`, { + method: 'PATCH', + body: JSON.stringify({ status: 'open' }), + }) + await detail.refresh() + } catch (error) { + setPublishError(error instanceof Error ? error.message : '发布失败') + } finally { + setPublishing(false) + } + } return (
@@ -4406,8 +4468,29 @@ function VisualCaseSurvey({ /> )} + {detail.data?.status === 'draft' && ( +
+
+ {draftReadyToPublish + ? '作品已完整,确认发布后才会通知评分人' + : `当前为未发布草稿,还需上传 ${Math.max(0, requiredCount - workItems.length)} 个案例`} +
+ {publishError &&
{publishError}
} + {draftReadyToPublish && ( + + )} +
+ )} + {workItems.length === 0 && ( - detail.data?.status === 'open' ? ( + ['draft', 'open'].includes(detail.data?.status) ? (
{canUpload ? '请先上传案例图片' : '等待被考核人提交案例'}
@@ -4479,6 +4562,7 @@ function WorkItemUploadForm({ const [files, setFiles] = useState([]) const [busy, setBusy] = useState(false) const [message, setMessage] = useState(null) + const [messageTone, setMessageTone] = useState<'progress' | 'success' | 'error'>('progress') const addFiles = (selectedFiles: File[]) => { const merged = [...files, ...selectedFiles].filter((file, index, items) => { @@ -4488,6 +4572,7 @@ function WorkItemUploadForm({ const orderedFiles = sortPerformanceSurveyImagesByName(merged, (file) => file.name) const validationError = validatePerformanceSurveyImageFiles(orderedFiles) if (validationError) { + setMessageTone('error') setMessage(validationError) return } @@ -4499,28 +4584,36 @@ function WorkItemUploadForm({ if (disabled) return const validationError = validatePerformanceSurveyImageFiles(files) if (validationError) { + setMessageTone('error') setMessage(validationError) return } setBusy(true) + setMessageTone('progress') setMessage(null) try { - const images = await uploadPerformanceSurveyImageFiles(files, setMessage) - setMessage('图片上传完成,正在生成评分预览') + const processedImages = await uploadPerformanceSurveyImageFiles(files, (label) => { + setMessageTone('progress') + setMessage(label) + }) + setMessage('图片处理和上传完成,正在保存作品') await apiRequest(`/surveys/${surveyId}/work-items`, { method: 'POST', body: JSON.stringify({ targetId, title: title.trim() || '案例作品', description: description.trim(), - images, + processedImages, }), }) setTitle('') setDescription('') setFiles([]) await onUploaded() + setMessageTone('success') + setMessage('作品已保存') } catch (error) { + setMessageTone('error') setMessage(error instanceof Error ? error.message : '上传失败') } finally { setBusy(false) @@ -4559,7 +4652,17 @@ function WorkItemUploadForm({ setMessage(null) }} /> - {message &&
{message}
} + {message && ( +
+ {message} +
+ )}