feat: add inline work review annotations

This commit is contained in:
江林铖 2026-08-01 13:43:58 +08:00
parent e75fc67b6a
commit 40fc7a4a37
11 changed files with 777 additions and 85 deletions

View File

@ -0,0 +1,61 @@
'use client'
import type { WorkReviewImageAnnotation, WorkReviewRole } from '@/types/work-review'
export type WorkReviewDisplayAnnotation = {
annotation: WorkReviewImageAnnotation
markerNumber: number
reviewerName?: string
reviewerRole?: WorkReviewRole
draft?: boolean
}
function markerTone(item: WorkReviewDisplayAnnotation) {
if (item.draft) return 'bg-[#8a5200] text-white ring-[#fff3d6]'
if (item.reviewerRole === 'final_reviewer') return 'bg-[#087a3c] text-white ring-[#d9f6e5]'
return 'bg-[#0050cb] text-white ring-[#dcecff]'
}
export function WorkReviewAnnotationMarker({
item,
onClick,
}: {
item: WorkReviewDisplayAnnotation
onClick?: () => void
}) {
const { annotation } = item
const alignRight = annotation.x > 0.62
const roleLabel = item.draft
? '当前批注'
: item.reviewerRole === 'final_reviewer'
? '元泽'
: '评审人'
const summary = annotation.comment.trim() || '待填写修改意见'
const label = `${roleLabel}标注 ${item.markerNumber}${item.reviewerName ? `,${item.reviewerName}` : ''}:${summary}`
return (
<button
type="button"
onClick={(event) => {
event.stopPropagation()
onClick?.()
}}
onPointerDown={(event) => event.stopPropagation()}
aria-label={label}
title={label}
className="group absolute z-20 h-11 w-11 -translate-x-1/2 -translate-y-1/2 outline-none"
style={{ left: `${annotation.x * 100}%`, top: `${annotation.y * 100}%` }}
>
<span className={`absolute left-1/2 top-1/2 flex h-7 w-7 -translate-x-1/2 -translate-y-1/2 items-center justify-center rounded-full text-[11px] font-black shadow-[0_3px_10px_rgba(15,23,42,0.35)] ring-4 ${markerTone(item)} group-focus-visible:ring-[#8ab9ff]`}>
{item.markerNumber}
</span>
<span
className={`pointer-events-none absolute top-1/2 hidden max-w-[220px] -translate-y-1/2 truncate rounded-full bg-[#101828]/90 px-3 py-1.5 text-[11px] font-semibold text-white shadow-[0_4px_14px_rgba(15,23,42,0.24)] sm:block ${
alignRight ? 'right-9' : 'left-9'
}`}
>
{summary}
</span>
</button>
)
}

View File

@ -16,12 +16,10 @@ import type {
WorkReviewBoardData,
WorkReviewProject,
WorkReviewReviewInput,
WorkReviewRole,
WorkReviewStatus,
WorkReviewSubmissionInput,
WorkReviewVersion,
} from '@/types/work-review'
import { WorkReviewSubmissionDialog, WorkReviewReviewDialog } from './WorkReviewDialogs'
import { WorkReviewSubmissionDialog } from './WorkReviewDialogs'
import { WorkReviewHeader } from './WorkReviewHeader'
import { WorkReviewProjectCard } from './WorkReviewProjectCard'
import { WorkReviewReviewerWorkspace } from './WorkReviewReviewerWorkspace'
@ -85,11 +83,6 @@ export default function WorkReviewBoard() {
mode: 'create' | 'resubmit'
project?: WorkReviewProject
} | null>(null)
const [reviewDialog, setReviewDialog] = useState<{
project: WorkReviewProject
version: WorkReviewVersion
role: WorkReviewRole
} | null>(null)
const { toast, showToast } = useToast()
useEffect(() => {
@ -126,7 +119,7 @@ export default function WorkReviewBoard() {
updateUrl()
}, [sessionStatus, updateUrl])
const load = useCallback(async () => {
const load = useCallback(async (options?: { board?: boolean }) => {
if (sessionStatus !== 'authenticated') return
const sequence = requestSequenceRef.current + 1
requestSequenceRef.current = sequence
@ -136,12 +129,12 @@ export default function WorkReviewBoard() {
setLoading(true)
setError(null)
try {
const deepLinkProject = deepLinkProjectRef.current
const deepLinkProject = options?.board ? '' : deepLinkProjectRef.current
const nextData = await getWorkReviewBoard({
query: debouncedQuery,
status: statusFilter,
query: options?.board ? '' : debouncedQuery,
status: options?.board ? '' : statusFilter,
project: deepLinkProject,
page,
page: options?.board ? 1 : page,
pageSize: 20,
}, controller.signal)
if (sequence !== requestSequenceRef.current) return
@ -218,9 +211,14 @@ export default function WorkReviewBoard() {
const submitReview = async (versionId: string, input: WorkReviewReviewInput) => {
const project = await submitWorkReview(versionId, input)
replaceProject(project)
setReviewDialog(null)
setExpandedProjectId(project.id)
showToast(input.reviewerRole === 'manager' ? '指定评审人意见已提交' : '元泽评审已提交')
if (project.status === 'approved') {
showToast('评审已完成,作品通过结果已通知发起人')
} else if (project.status === 'revision_required') {
showToast('评审已完成,修改意见已通知发起人')
} else {
showToast('评审意见已提交,等待另一位评审完成')
}
}
const pageStats = useMemo(() => {
@ -240,11 +238,10 @@ export default function WorkReviewBoard() {
const me = data?.me
const canSubmit = Boolean(me?.permissions.canSubmit)
const requestedProject = initialProjectRef.current
? data?.items.find((item) => item.id === initialProjectRef.current)
const requestedProject = expandedProjectId
? data?.items.find((item) => item.id === expandedProjectId)
: null
const singleProject = data?.items.length === 1 ? data.items[0] : null
const reviewerCandidate = requestedProject || singleProject
const reviewerCandidate = requestedProject
const reviewerEmployeeId = me?.employee?.id
const reviewerFocusProject = reviewerCandidate && (
reviewerCandidate.permissions.pendingReviewRoles.length > 0
@ -260,13 +257,26 @@ export default function WorkReviewBoard() {
<WorkReviewHeader
name={me?.user.name || session.user?.name || '当前用户'}
avatar={me?.user.avatar || (session.user as any)?.avatar || null}
canCreate={canSubmit}
onCreate={() => setSubmissionDialog({ mode: 'create' })}
wide
primaryAction={{
label: '返回看板',
icon: 'back',
onClick: () => {
deepLinkProjectRef.current = ''
setExpandedProjectId('')
setQuery('')
setDebouncedQuery('')
setStatusFilter('')
setPage(1)
router.replace('/work-review', { scroll: false })
void load({ board: true })
},
}}
/>
<main className="mx-auto w-full max-w-[1600px] px-3 py-3 sm:px-5 sm:py-4">
<WorkReviewReviewerWorkspace
project={reviewerFocusProject}
onReview={(version, role) => setReviewDialog({ project: reviewerFocusProject, version, role })}
onSubmitReview={(version, input) => submitReview(version.id, input)}
/>
</main>
@ -280,15 +290,6 @@ export default function WorkReviewBoard() {
: submitVersion(submissionDialog.project!.id, input)}
/>
)}
{reviewDialog && (
<WorkReviewReviewDialog
project={reviewDialog.project}
version={reviewDialog.version}
role={reviewDialog.role}
onClose={() => setReviewDialog(null)}
onSubmit={(input) => submitReview(reviewDialog.version.id, input)}
/>
)}
{toast?.show && <ToastBubble message={toast.message} variant={toast.variant} topOffsetClass="top-20" zIndexClass="z-[1300]" />}
</div>
)
@ -299,8 +300,11 @@ export default function WorkReviewBoard() {
<WorkReviewHeader
name={me?.user.name || session.user?.name || '当前用户'}
avatar={me?.user.avatar || (session.user as any)?.avatar || null}
canCreate={canSubmit}
onCreate={() => setSubmissionDialog({ mode: 'create' })}
primaryAction={canSubmit ? {
label: '提交作品',
icon: 'add',
onClick: () => setSubmissionDialog({ mode: 'create' }),
} : undefined}
/>
<main className="mx-auto w-full max-w-[1180px] px-4 py-7 pb-16 sm:px-6 sm:py-9">
@ -418,7 +422,10 @@ export default function WorkReviewBoard() {
updateUrl({ project: nextId, replaceProject: true })
}}
onResubmit={() => setSubmissionDialog({ mode: 'resubmit', project })}
onReview={(version, role) => setReviewDialog({ project, version, role })}
onReview={() => {
setExpandedProjectId(project.id)
updateUrl({ project: project.id, replaceProject: true })
}}
/>
))}
@ -501,15 +508,6 @@ export default function WorkReviewBoard() {
: submitVersion(submissionDialog.project!.id, input)}
/>
)}
{reviewDialog && (
<WorkReviewReviewDialog
project={reviewDialog.project}
version={reviewDialog.version}
role={reviewDialog.role}
onClose={() => setReviewDialog(null)}
onSubmit={(input) => submitReview(reviewDialog.version.id, input)}
/>
)}
{toast?.show && <ToastBubble message={toast.message} variant={toast.variant} topOffsetClass="top-20" zIndexClass="z-[1300]" />}
</div>
)

View File

@ -6,19 +6,23 @@ import Link from 'next/link'
export function WorkReviewHeader({
name,
avatar,
onCreate,
canCreate,
primaryAction,
wide = false,
}: {
name: string
avatar?: string | null
canCreate: boolean
onCreate: () => void
primaryAction?: {
label: string
onClick: () => void
icon: 'add' | 'back'
}
wide?: boolean
}) {
const initials = name.trim().slice(0, 2) || '我'
return (
<header className="sticky top-0 z-30 bg-[#1f2937] text-white shadow-sm">
<div className="mx-auto flex min-h-[64px] w-full max-w-[1280px] items-center justify-between gap-4 px-4 py-3 sm:px-6">
<div className={`mx-auto flex min-h-[64px] w-full items-center justify-between gap-4 px-4 py-3 sm:px-6 ${wide ? 'max-w-[1600px]' : 'max-w-[1280px]'}`}>
<div className="flex min-w-0 items-center gap-3">
<div className="flex h-9 w-9 shrink-0 items-center justify-center overflow-hidden rounded-full border border-white/15 bg-white/15 text-[12px] font-bold">
{avatar ? (
@ -39,14 +43,16 @@ export function WorkReviewHeader({
</div>
<div className="flex shrink-0 items-center gap-2">
{canCreate && (
{primaryAction && (
<button
type="button"
onClick={onCreate}
onClick={primaryAction.onClick}
className="inline-flex min-h-9 items-center justify-center rounded bg-[#0050cb] px-3 text-[12px] font-bold text-white transition-colors hover:bg-[#003fa3] sm:px-4 sm:text-[13px]"
>
<span className="mr-1 text-[17px] font-light leading-none">+</span>
提交作品
<span className="mr-1 text-[17px] font-light leading-none" aria-hidden="true">
{primaryAction.icon === 'add' ? '+' : '←'}
</span>
{primaryAction.label}
</button>
)}
<Link

View File

@ -4,6 +4,10 @@ import Image from 'next/image'
import { useEffect, useMemo, useRef, useState } from 'react'
import { createPortal } from 'react-dom'
import type { WorkReviewImageGroup } from '@/types/work-review'
import {
WorkReviewAnnotationMarker,
type WorkReviewDisplayAnnotation,
} from './WorkReviewAnnotationMarker'
const PROXY_HOSTS = new Set(['s3.jiansun.vip', 's3.yydd.ai', 's3.1080p.hk'])
@ -48,10 +52,12 @@ export function WorkReviewImageGallery({
groups,
imageUrls = [],
compact = false,
annotationsByImageIndex = [],
}: {
groups: WorkReviewImageGroup[]
imageUrls?: string[]
compact?: boolean
annotationsByImageIndex?: WorkReviewDisplayAnnotation[][]
}) {
const [activeIndex, setActiveIndex] = useState<number | null>(null)
const displayGroups = useMemo(() => normalizeGroups(groups || [], imageUrls || []), [groups, imageUrls])
@ -91,6 +97,11 @@ export function WorkReviewImageGallery({
长图 · {group.slices.length} 段
</span>
)}
{(annotationsByImageIndex[index]?.length || 0) > 0 && (
<span className="absolute left-2 top-2 rounded-full bg-[#8a5200] px-2 py-0.5 text-[10px] font-bold text-white">
{annotationsByImageIndex[index].length} 个批注
</span>
)}
</div>
</button>
))}
@ -99,6 +110,7 @@ export function WorkReviewImageGallery({
group={activeIndex == null ? null : displayGroups[activeIndex]}
index={activeIndex}
total={displayGroups.length}
annotations={activeIndex == null ? [] : annotationsByImageIndex[activeIndex] || []}
onClose={() => setActiveIndex(null)}
onPrevious={() => setActiveIndex((current) => (
current == null ? null : (current - 1 + displayGroups.length) % displayGroups.length
@ -115,6 +127,7 @@ function WorkReviewImageViewer({
group,
index,
total,
annotations,
onClose,
onPrevious,
onNext,
@ -122,6 +135,7 @@ function WorkReviewImageViewer({
group: WorkReviewImageGroup | null
index: number | null
total: number
annotations: WorkReviewDisplayAnnotation[]
onClose: () => void
onPrevious: () => void
onNext: () => void
@ -223,7 +237,7 @@ function WorkReviewImageViewer({
</button>
</>
)}
<div className="mx-auto max-w-[1200px] overflow-hidden rounded bg-white">
<div className="relative mx-auto max-w-[1200px] overflow-hidden rounded bg-white">
{(group.slices.length > 0 ? group.slices : [{
url: group.previewUrl,
width: group.previewWidth,
@ -240,6 +254,12 @@ function WorkReviewImageViewer({
className="block h-auto w-full"
/>
))}
{annotations.map((item) => (
<WorkReviewAnnotationMarker
key={`${item.reviewerRole}-${item.annotation.id}`}
item={item}
/>
))}
</div>
</div>
</div>,

View File

@ -9,6 +9,7 @@ import type {
WorkReviewVersion,
} from '@/types/work-review'
import { WorkReviewImageGallery } from './WorkReviewImageGallery'
import type { WorkReviewDisplayAnnotation } from './WorkReviewAnnotationMarker'
import { WorkReviewDecisionBadge, WorkReviewStatusBadge } from './WorkReviewStatusBadge'
function formatDateOnly(value: string) {
@ -48,6 +49,23 @@ function getVersionReview(version: WorkReviewVersion, role: WorkReviewRole) {
return version.reviews.find((review) => review.reviewerRole === role) || null
}
function getVersionAnnotations(version: WorkReviewVersion): WorkReviewDisplayAnnotation[][] {
const imageCount = version.imageGroups?.length || version.imageUrls?.length || 0
const result = Array.from({ length: imageCount }, () => [] as WorkReviewDisplayAnnotation[])
for (const review of version.reviews || []) {
for (const imageComment of review.imageComments || []) {
if (!result[imageComment.imageIndex]) continue
result[imageComment.imageIndex].push(...(imageComment.annotations || []).map((annotation, index) => ({
annotation,
markerNumber: index + 1,
reviewerName: review.reviewerName,
reviewerRole: review.reviewerRole,
})))
}
}
return result
}
function ReviewProgress({
project,
version,
@ -86,7 +104,7 @@ export function WorkReviewProjectCard({
expanded: boolean
onToggle: () => void
onResubmit: () => void
onReview: (version: WorkReviewVersion, role: WorkReviewRole) => void
onReview: () => void
}) {
const latestVersion = project.versions[0]
const [selectedVersionId, setSelectedVersionId] = useState(latestVersion?.id || '')
@ -103,6 +121,10 @@ export function WorkReviewProjectCard({
)
const cover = latestVersion?.imageGroups?.[0]?.previewUrl || latestVersion?.imageUrls?.[0] || ''
const isLatestSelected = selectedVersion?.id === latestVersion?.id
const annotationsByImageIndex = useMemo(
() => selectedVersion ? getVersionAnnotations(selectedVersion) : [],
[selectedVersion],
)
if (!latestVersion || !selectedVersion) return null
@ -228,6 +250,7 @@ export function WorkReviewProjectCard({
<WorkReviewImageGallery
groups={selectedVersion.imageGroups || []}
imageUrls={selectedVersion.imageUrls || []}
annotationsByImageIndex={annotationsByImageIndex}
/>
</section>
{(selectedVersion.referenceImageGroups || []).length > 0 && (
@ -259,7 +282,7 @@ export function WorkReviewProjectCard({
isLatestSelected
&& project.permissions.pendingReviewRoles.includes('manager')
)}
onReview={() => onReview(selectedVersion, 'manager')}
onReview={onReview}
/>
<ReviewPanel
label="元泽评审"
@ -269,7 +292,7 @@ export function WorkReviewProjectCard({
isLatestSelected
&& project.permissions.pendingReviewRoles.includes('final_reviewer')
)}
onReview={() => onReview(selectedVersion, 'final_reviewer')}
onReview={onReview}
/>
</div>
</div>

View File

@ -3,15 +3,22 @@
import Image from 'next/image'
import { useEffect, useMemo, useRef, useState } from 'react'
import type {
WorkReviewImageAnnotation,
WorkReviewImageGroup,
WorkReviewProject,
WorkReviewRole,
WorkReviewReviewInput,
WorkReviewVersion,
} from '@/types/work-review'
import {
WorkReviewAnnotationMarker,
type WorkReviewDisplayAnnotation,
} from './WorkReviewAnnotationMarker'
const PROXY_HOSTS = new Set(['s3.jiansun.vip', 's3.yydd.ai', 's3.1080p.hk'])
const MIN_PANE_PERCENT = 14
const MAX_PANE_PERCENT = 86
const MAX_ANNOTATIONS_PER_IMAGE = 50
const MAX_ANNOTATION_COMMENT_LENGTH = 1000
function proxyImageUrl(value: string) {
const url = String(value || '').trim()
@ -54,37 +61,96 @@ function normalizeGroups(
}))
}
function createAnnotationId() {
if (typeof window !== 'undefined' && typeof window.crypto?.randomUUID === 'function') {
return window.crypto.randomUUID()
}
return `point-${Date.now()}-${Math.random().toString(36).slice(2, 9)}`
}
function LongImagePane({
label,
groups,
imageUrls,
emptyMessage,
activeIndex: controlledActiveIndex,
onActiveIndexChange,
annotations = [],
annotationEnabled = false,
annotationMode = false,
onToggleAnnotationMode,
onAddAnnotation,
onSelectDraftAnnotation,
}: {
label: string
groups: WorkReviewImageGroup[]
imageUrls: string[]
emptyMessage: string
activeIndex?: number
onActiveIndexChange?: (index: number) => void
annotations?: WorkReviewDisplayAnnotation[]
annotationEnabled?: boolean
annotationMode?: boolean
onToggleAnnotationMode?: () => void
onAddAnnotation?: (x: number, y: number) => void
onSelectDraftAnnotation?: (annotationId: string) => void
}) {
const displayGroups = useMemo(
() => normalizeGroups(groups || [], imageUrls || [], label),
[groups, imageUrls, label],
)
const [activeIndex, setActiveIndex] = useState(0)
const activeGroup = displayGroups[Math.min(activeIndex, Math.max(0, displayGroups.length - 1))]
const [internalActiveIndex, setInternalActiveIndex] = useState(0)
const pointerStartRef = useRef<{ x: number; y: number } | null>(null)
const activeIndex = Math.min(
controlledActiveIndex ?? internalActiveIndex,
Math.max(0, displayGroups.length - 1),
)
const activeGroup = displayGroups[activeIndex]
useEffect(() => setActiveIndex(0), [displayGroups.length])
useEffect(() => {
if (controlledActiveIndex == null) setInternalActiveIndex(0)
}, [controlledActiveIndex, displayGroups.length])
const selectImage = (index: number) => {
if (controlledActiveIndex == null) setInternalActiveIndex(index)
onActiveIndexChange?.(index)
}
const placeAnnotation = (element: HTMLDivElement, clientX: number, clientY: number) => {
const bounds = element.getBoundingClientRect()
if (bounds.width <= 0 || bounds.height <= 0) return
const x = Math.min(1, Math.max(0, (clientX - bounds.left) / bounds.width))
const y = Math.min(1, Math.max(0, (clientY - bounds.top) / bounds.height))
onAddAnnotation?.(x, y)
}
return (
<section className="flex h-full min-h-0 flex-col bg-white" aria-label={label}>
<div className="flex min-h-12 shrink-0 items-center justify-between gap-3 border-b border-[#e4e7ec] px-3 sm:px-4">
<h2 className="text-[13px] font-bold text-[#101828]">{label}</h2>
<div className="flex min-h-12 shrink-0 items-center justify-between gap-2 border-b border-[#e4e7ec] px-3 py-1.5 sm:px-4">
<div className="flex min-w-0 items-center gap-2">
<h2 className="shrink-0 text-[13px] font-bold text-[#101828]">{label}</h2>
{annotationEnabled && (
<button
type="button"
onClick={onToggleAnnotationMode}
aria-pressed={annotationMode}
className={`min-h-8 shrink-0 rounded px-2.5 text-[11px] font-bold transition-colors ${
annotationMode
? 'bg-[#8a5200] text-white hover:bg-[#6d4100]'
: 'border border-[#d3dae5] bg-white text-[#344054] hover:border-[#8ab9ff]'
}`}
>
{annotationMode ? '取消标注' : '+ 添加标注'}
</button>
)}
</div>
{displayGroups.length > 1 ? (
<div className="flex max-w-[70%] gap-1 overflow-x-auto py-1" aria-label={`${label}选择`}>
<div className="flex max-w-[52%] gap-1 overflow-x-auto py-1" aria-label={`${label}选择`}>
{displayGroups.map((group, index) => (
<button
key={group.imageId || `${group.sourceName}-${index}`}
type="button"
onClick={() => setActiveIndex(index)}
onClick={() => selectImage(index)}
aria-pressed={activeIndex === index}
className={`min-h-8 shrink-0 rounded px-2.5 text-[11px] font-bold transition-colors ${
activeIndex === index
@ -103,9 +169,43 @@ function LongImagePane({
)}
</div>
{annotationMode && (
<div className="shrink-0 bg-[#fff7e6] px-3 py-2 text-center text-[11px] font-semibold text-[#7a4a00]" role="status">
点击作品中的修改位置添加批注;滚动不会产生标记
</div>
)}
<div className="min-h-0 flex-1 overflow-y-auto overscroll-contain bg-[#eef1f5] p-2 sm:p-3">
{activeGroup ? (
<div className="mx-auto max-w-[1200px] overflow-hidden bg-white shadow-[0_8px_28px_rgba(15,23,42,0.08)]">
<div
className={`relative mx-auto max-w-[1200px] overflow-hidden bg-white shadow-[0_8px_28px_rgba(15,23,42,0.08)] ${annotationMode ? 'cursor-crosshair touch-pan-y outline outline-2 outline-[#d49a31]' : ''}`}
role={annotationEnabled ? 'group' : undefined}
aria-label={annotationEnabled ? `${activeGroup.sourceName},可添加位置批注` : undefined}
tabIndex={annotationMode ? 0 : undefined}
onPointerDown={(event) => {
if (!annotationMode || (event.button ?? 0) !== 0) return
pointerStartRef.current = { x: event.clientX, y: event.clientY }
}}
onPointerUp={(event) => {
if (!annotationMode || !pointerStartRef.current) return
const distance = Math.hypot(
event.clientX - pointerStartRef.current.x,
event.clientY - pointerStartRef.current.y,
)
pointerStartRef.current = null
if (distance <= 8) placeAnnotation(event.currentTarget, event.clientX, event.clientY)
}}
onPointerCancel={() => {
pointerStartRef.current = null
}}
onKeyDown={(event) => {
if (annotationMode && (event.key === 'Enter' || event.key === ' ')) {
event.preventDefault()
const bounds = event.currentTarget.getBoundingClientRect()
placeAnnotation(event.currentTarget, bounds.left + bounds.width / 2, bounds.top + bounds.height / 2)
}
}}
>
{(activeGroup.slices.length > 0 ? activeGroup.slices : [{
url: activeGroup.previewUrl,
width: activeGroup.previewWidth,
@ -119,7 +219,15 @@ function LongImagePane({
height={slice.height}
unoptimized
loading={sliceIndex === 0 ? 'eager' : 'lazy'}
className="block h-auto w-full"
className="pointer-events-none block h-auto w-full select-none"
draggable={false}
/>
))}
{annotations.map((item) => (
<WorkReviewAnnotationMarker
key={`${item.draft ? 'draft' : item.reviewerRole}-${item.annotation.id}`}
item={item}
onClick={item.draft ? () => onSelectDraftAnnotation?.(item.annotation.id) : undefined}
/>
))}
</div>
@ -133,23 +241,47 @@ function LongImagePane({
)
}
function getImageCount(version?: WorkReviewVersion) {
if (!version) return 0
return version.imageGroups?.length || version.imageUrls?.length || 0
}
function summarizeAnnotations(annotations: WorkReviewImageAnnotation[]) {
if (annotations.length === 0) return '通过'
return annotations
.map((annotation, index) => `标注 ${index + 1}:${annotation.comment.trim()}`)
.join('\n')
.slice(0, 2000)
}
export function WorkReviewReviewerWorkspace({
project,
onReview,
onSubmitReview,
}: {
project: WorkReviewProject
onReview: (version: WorkReviewVersion, role: WorkReviewRole) => void
onSubmitReview: (version: WorkReviewVersion, input: WorkReviewReviewInput) => Promise<void>
}) {
const latestVersion = project.versions[0]
const [selectedVersionId, setSelectedVersionId] = useState(latestVersion?.id || '')
const [workPanePercent, setWorkPanePercent] = useState(50)
const [activeWorkImageIndex, setActiveWorkImageIndex] = useState(0)
const [draftAnnotations, setDraftAnnotations] = useState<WorkReviewImageAnnotation[][]>(() => (
Array.from({ length: getImageCount(latestVersion) }, () => [])
))
const [selectedAnnotation, setSelectedAnnotation] = useState<{ imageIndex: number; id: string } | null>(null)
const [annotationMode, setAnnotationMode] = useState(false)
const [busyAction, setBusyAction] = useState<'approved' | 'revision_required' | null>(null)
const [error, setError] = useState<string | null>(null)
const [liveMessage, setLiveMessage] = useState('')
const comparisonRef = useRef<HTMLDivElement | null>(null)
const draggingRef = useRef(false)
const mobileScrollerRef = useRef<HTMLDivElement | null>(null)
const annotationInputRef = useRef<HTMLTextAreaElement | null>(null)
const selectedVersion = useMemo(
() => project.versions.find((version) => version.id === selectedVersionId) || latestVersion,
[latestVersion, project.versions, selectedVersionId],
)
const workImageCount = getImageCount(selectedVersion)
useEffect(() => {
if (!project.versions.some((version) => version.id === selectedVersionId)) {
@ -157,12 +289,44 @@ export function WorkReviewReviewerWorkspace({
}
}, [project.versions, selectedVersionId])
useEffect(() => {
setActiveWorkImageIndex(0)
setDraftAnnotations(Array.from({ length: workImageCount }, () => []))
setSelectedAnnotation(null)
setAnnotationMode(false)
setError(null)
}, [selectedVersion?.id, workImageCount])
useEffect(() => {
if (!selectedAnnotation) return
const frame = window.requestAnimationFrame(() => annotationInputRef.current?.focus())
return () => window.cancelAnimationFrame(frame)
}, [selectedAnnotation])
if (!selectedVersion || !latestVersion) return null
const isLatestSelected = selectedVersion.id === latestVersion.id
const pendingRole = isLatestSelected ? project.permissions.pendingReviewRoles[0] : undefined
const hasReferenceImages = (selectedVersion.referenceImageGroups?.length || 0) > 0
|| (selectedVersion.referenceImageUrls?.length || 0) > 0
const currentDrafts = draftAnnotations[activeWorkImageIndex] || []
const selectedDraft = selectedAnnotation
? draftAnnotations[selectedAnnotation.imageIndex]?.find((item) => item.id === selectedAnnotation.id)
: undefined
const totalDraftCount = draftAnnotations.reduce((sum, annotations) => sum + annotations.length, 0)
const submittedAnnotations: WorkReviewDisplayAnnotation[] = selectedVersion.reviews.flatMap((review) => {
const imageComment = (review.imageComments || []).find((item) => item.imageIndex === activeWorkImageIndex)
return (imageComment?.annotations || []).map((annotation, index) => ({
annotation,
markerNumber: index + 1,
reviewerName: review.reviewerName,
reviewerRole: review.reviewerRole,
}))
})
const visibleAnnotations: WorkReviewDisplayAnnotation[] = [
...submittedAnnotations,
...currentDrafts.map((annotation, index) => ({ annotation, markerNumber: index + 1, draft: true })),
]
const updateSplitFromPointer = (clientX: number) => {
const bounds = comparisonRef.current?.getBoundingClientRect()
@ -177,6 +341,106 @@ export function WorkReviewReviewerWorkspace({
scroller.scrollTo({ left: scroller.clientWidth * index, behavior: 'smooth' })
}
const addAnnotation = (x: number, y: number) => {
if (!pendingRole) return
if (currentDrafts.length >= MAX_ANNOTATIONS_PER_IMAGE) {
setError(`单张图片最多添加 ${MAX_ANNOTATIONS_PER_IMAGE} 个批注`)
return
}
const annotation: WorkReviewImageAnnotation = { id: createAnnotationId(), x, y, comment: '' }
setDraftAnnotations((current) => current.map((items, index) => (
index === activeWorkImageIndex ? [...items, annotation] : items
)))
setSelectedAnnotation({ imageIndex: activeWorkImageIndex, id: annotation.id })
setAnnotationMode(false)
setError(null)
setLiveMessage(`已在图 ${activeWorkImageIndex + 1} 添加标注点`)
}
const updateSelectedAnnotation = (comment: string) => {
if (!selectedAnnotation) return
setDraftAnnotations((current) => current.map((items, imageIndex) => (
imageIndex === selectedAnnotation.imageIndex
? items.map((item) => item.id === selectedAnnotation.id ? { ...item, comment } : item)
: items
)))
setError(null)
}
const deleteSelectedAnnotation = () => {
if (!selectedAnnotation) return
setDraftAnnotations((current) => current.map((items, imageIndex) => (
imageIndex === selectedAnnotation.imageIndex
? items.filter((item) => item.id !== selectedAnnotation.id)
: items
)))
setSelectedAnnotation(null)
setError(null)
setLiveMessage('批注已删除')
}
const finishEditingAnnotation = () => {
if (!selectedDraft?.comment.trim()) {
setError('请填写这个标注点的修改意见')
return
}
setSelectedAnnotation(null)
setError(null)
setLiveMessage('批注已保存到本次评审草稿')
}
const findIncompleteAnnotation = () => {
for (let imageIndex = 0; imageIndex < draftAnnotations.length; imageIndex += 1) {
const annotation = draftAnnotations[imageIndex].find((item) => !item.comment.trim())
if (annotation) return { imageIndex, id: annotation.id }
}
return null
}
const submitDecision = async (decision: 'approved' | 'revision_required') => {
if (!pendingRole || workImageCount === 0) return
const incomplete = findIncompleteAnnotation()
if (incomplete) {
setActiveWorkImageIndex(incomplete.imageIndex)
setSelectedAnnotation(incomplete)
setAnnotationMode(false)
setError('请先填写未完成标注点的修改意见')
return
}
if (decision === 'revision_required' && totalDraftCount === 0) {
setError('请先在作品图片上标注至少一个需要修改的位置')
setAnnotationMode(true)
return
}
setBusyAction(decision)
setError(null)
try {
await onSubmitReview(selectedVersion, {
reviewerRole: pendingRole,
imageComments: Array.from({ length: workImageCount }, (_, imageIndex) => {
const annotations = draftAnnotations[imageIndex] || []
return {
imageIndex,
decision: decision === 'revision_required' && annotations.length > 0
? 'revision_required'
: 'approved',
comment: summarizeAnnotations(annotations),
annotations,
}
}),
generalComment: '',
})
setDraftAnnotations(Array.from({ length: workImageCount }, () => []))
setSelectedAnnotation(null)
setAnnotationMode(false)
} catch (submitError) {
setError(submitError instanceof Error ? submitError.message : '评审提交失败')
} finally {
setBusyAction(null)
}
}
return (
<div className="flex min-h-0 flex-col">
<nav
@ -186,11 +450,19 @@ export function WorkReviewReviewerWorkspace({
>
{project.versions.map((version) => {
const active = version.id === selectedVersion.id
const tabId = `work-review-version-tab-${version.id}`
return (
<button
key={version.id}
id={tabId}
type="button"
onClick={() => setSelectedVersionId(version.id)}
onClick={() => {
if (version.id !== selectedVersion.id && totalDraftCount > 0 && pendingRole) {
setError('当前版本还有未提交批注,请先完成评审或删除批注')
return
}
setSelectedVersionId(version.id)
}}
role="tab"
aria-selected={active}
aria-controls="work-review-version-panel"
@ -209,7 +481,8 @@ export function WorkReviewReviewerWorkspace({
<div
id="work-review-version-panel"
role="tabpanel"
className="flex h-[calc(100dvh-144px)] min-h-[520px] flex-col overflow-hidden border border-[#dfe5ee] bg-white"
aria-labelledby={`work-review-version-tab-${selectedVersion.id}`}
className="flex h-[calc(100dvh-144px)] min-h-[600px] flex-col overflow-hidden border border-[#dfe5ee] bg-white"
>
<div className="relative min-h-0 flex-1 overflow-hidden">
<div
@ -224,6 +497,26 @@ export function WorkReviewReviewerWorkspace({
groups={selectedVersion.imageGroups || []}
imageUrls={selectedVersion.imageUrls || []}
emptyMessage="当前版本没有作品图片"
activeIndex={activeWorkImageIndex}
onActiveIndexChange={(index) => {
setActiveWorkImageIndex(index)
setSelectedAnnotation(null)
setAnnotationMode(false)
}}
annotations={visibleAnnotations}
annotationEnabled={Boolean(pendingRole)}
annotationMode={annotationMode}
onToggleAnnotationMode={() => {
setAnnotationMode((current) => !current)
setSelectedAnnotation(null)
setError(null)
}}
onAddAnnotation={addAnnotation}
onSelectDraftAnnotation={(id) => {
setSelectedAnnotation({ imageIndex: activeWorkImageIndex, id })
setAnnotationMode(false)
setError(null)
}}
/>
</div>
{hasReferenceImages && (
@ -304,6 +597,26 @@ export function WorkReviewReviewerWorkspace({
groups={selectedVersion.imageGroups || []}
imageUrls={selectedVersion.imageUrls || []}
emptyMessage="当前版本没有作品图片"
activeIndex={activeWorkImageIndex}
onActiveIndexChange={(index) => {
setActiveWorkImageIndex(index)
setSelectedAnnotation(null)
setAnnotationMode(false)
}}
annotations={visibleAnnotations}
annotationEnabled={Boolean(pendingRole)}
annotationMode={annotationMode}
onToggleAnnotationMode={() => {
setAnnotationMode((current) => !current)
setSelectedAnnotation(null)
setError(null)
}}
onAddAnnotation={addAnnotation}
onSelectDraftAnnotation={(id) => {
setSelectedAnnotation({ imageIndex: activeWorkImageIndex, id })
setAnnotationMode(false)
setError(null)
}}
/>
</div>
{hasReferenceImages && (
@ -319,7 +632,7 @@ export function WorkReviewReviewerWorkspace({
)}
</div>
{hasReferenceImages && (
{hasReferenceImages && !annotationMode && (
<div className="pointer-events-none absolute inset-x-0 bottom-3 z-20 flex justify-center md:hidden">
<span className="rounded-full bg-[#101828]/85 px-3 py-1.5 text-[11px] font-semibold text-white">
左右滑动查看作品与参考
@ -328,17 +641,83 @@ export function WorkReviewReviewerWorkspace({
)}
</div>
{pendingRole && (
<div className="flex shrink-0 justify-end border-t border-[#dfe5ee] bg-white p-3 sm:p-4">
<button
type="button"
onClick={() => onReview(selectedVersion, pendingRole)}
className="min-h-11 w-full rounded bg-[#0050cb] px-5 text-[13px] font-bold text-white hover:bg-[#003fa3] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#0050cb] focus-visible:ring-offset-2 sm:w-auto sm:min-w-32"
>
开始评审
</button>
</div>
)}
<div className="shrink-0 border-t border-[#dfe5ee] bg-white px-3 py-3 pb-[max(0.75rem,env(safe-area-inset-bottom))] sm:px-4" aria-busy={Boolean(busyAction)}>
{pendingRole ? (
<>
{selectedDraft ? (
<div className="mb-3 grid gap-2 sm:grid-cols-[minmax(0,1fr)_auto] sm:items-end">
<label className="grid min-w-0 gap-1.5">
<span className="text-[12px] font-bold text-[#344054]">
图 {selectedAnnotation!.imageIndex + 1} · 标注 {(draftAnnotations[selectedAnnotation!.imageIndex] || []).findIndex((item) => item.id === selectedAnnotation!.id) + 1} 修改意见
</span>
<textarea
ref={annotationInputRef}
value={selectedDraft.comment}
onChange={(event) => updateSelectedAnnotation(event.target.value.slice(0, MAX_ANNOTATION_COMMENT_LENGTH))}
rows={2}
disabled={Boolean(busyAction)}
placeholder="说明这个位置需要如何调整"
className="min-h-16 resize-y rounded border border-[#cfd6e1] px-3 py-2 text-[13px] leading-5 outline-none focus:border-[#0050cb] focus:ring-2 focus:ring-[#dcecff] disabled:bg-[#f2f4f7]"
/>
</label>
<div className="grid grid-cols-2 gap-2 sm:flex">
<button
type="button"
onClick={deleteSelectedAnnotation}
disabled={Boolean(busyAction)}
className="min-h-10 rounded border border-[#e4b3b3] px-3 text-[12px] font-bold text-[#b42318] hover:bg-[#fff5f5] disabled:opacity-45"
>
删除
</button>
<button
type="button"
onClick={finishEditingAnnotation}
disabled={Boolean(busyAction)}
className="min-h-10 rounded bg-[#101828] px-4 text-[12px] font-bold text-white hover:bg-[#26354a] disabled:opacity-45"
>
完成
</button>
</div>
</div>
) : (
<div className="mb-3 flex min-h-8 flex-wrap items-center justify-between gap-2 text-[11px] font-semibold text-[#667085]">
<span>已标注 {totalDraftCount} 个修改点;点击“添加标注”后在作品上选择位置</span>
<span>两位评审均提交后,系统会通知发起人</span>
</div>
)}
{error && (
<div className="mb-3 rounded border border-[#f0b8b8] bg-[#fff5f5] px-3 py-2 text-[12px] font-semibold text-[#b42318]" role="alert">
{error}
</div>
)}
<div className="grid grid-cols-2 gap-2 sm:ml-auto sm:max-w-[520px]">
<button
type="button"
onClick={() => void submitDecision('approved')}
disabled={Boolean(busyAction)}
className="min-h-12 rounded bg-[#087a3c] px-3 text-[13px] font-bold text-white hover:bg-[#066332] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#087a3c] focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:bg-[#9abdab]"
>
{busyAction === 'approved' ? '正在提交…' : '通过'}
</button>
<button
type="button"
onClick={() => void submitDecision('revision_required')}
disabled={Boolean(busyAction)}
className="min-h-12 rounded bg-[#8a5200] px-3 text-[13px] font-bold text-white hover:bg-[#6d4100] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#8a5200] focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:bg-[#c2aa87]"
>
{busyAction === 'revision_required' ? '正在提交…' : '提交给修改人'}
</button>
</div>
</>
) : (
<div className="flex min-h-11 items-center justify-center text-center text-[12px] font-semibold text-[#667085]">
{isLatestSelected ? '你的本轮评审已提交;两位评审完成后系统会通知发起人' : '历史版本仅供查看'}
</div>
)}
<div className="sr-only" aria-live="polite">{liveMessage}</div>
</div>
</div>
</div>
)

View File

@ -1,5 +1,3 @@
/** @jest-environment node */
import {
canSubmitWorkReview,
deriveCompletedWorkReviewStatus,
@ -10,6 +8,7 @@ import {
getWorkReviewReviewerSelectionError,
isSameWorkReviewEmployeeAlias,
isSameWorkReviewEmployeeIdentity,
validateWorkReviewAnnotations,
} from '@/lib/work-review-policy'
describe('work review policy', () => {
@ -100,4 +99,30 @@ describe('work review policy', () => {
{ reviewerRole: 'final_reviewer', decision: 'approved' },
])).toBe('revision_required')
})
test('normalizes image annotations without storing viewport pixels', () => {
expect(validateWorkReviewAnnotations([
{ id: 'point-1', x: 0.123456789, y: 0.75, comment: ' 调整人物位置 ' },
])).toEqual({
ok: true,
annotations: [
{ id: 'point-1', x: 0.123457, y: 0.75, comment: '调整人物位置' },
],
})
expect(validateWorkReviewAnnotations(undefined)).toEqual({ ok: true, annotations: [] })
})
test.each([
[[{ id: 'point-1', x: -0.1, y: 0.5, comment: '越界' }], '图片批注位置无效'],
[[{ id: 'point-1', x: 0.5, y: '0.5', comment: '类型错误' }], '图片批注位置无效'],
[[{ id: 'point-1', x: 0.5, y: 0.5, comment: ' ' }], '请填写每个标注点的修改意见'],
[[
{ id: 'point-1', x: 0.2, y: 0.2, comment: 'A' },
{ id: 'point-1', x: 0.4, y: 0.4, comment: 'B' },
], '图片批注编号无效或重复'],
])('rejects invalid image annotations', (annotations, message) => {
const result = validateWorkReviewAnnotations(annotations)
expect(result.ok).toBe(false)
if (!result.ok) expect(result.error).toBe(message)
})
})

View File

@ -0,0 +1,105 @@
/** @jest-environment jsdom */
import { fireEvent, render, screen, waitFor } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { WorkReviewReviewerWorkspace } from '@/components/work-review/WorkReviewReviewerWorkspace'
import type { WorkReviewProject } from '@/types/work-review'
const project: WorkReviewProject = {
id: 'project-1',
title: '测试作品',
description: null,
workDate: '2026-08-01',
status: 'pending_review',
latestVersion: 1,
submitter: { id: 'submitter-1', name: '提交人' },
manager: { id: 'manager-1', name: '评审人' },
finalReviewer: { id: 'final-1', name: '元泽' },
createdAt: '2026-08-01T00:00:00.000Z',
updatedAt: '2026-08-01T00:00:00.000Z',
versions: [{
id: 'version-1',
version: 1,
submissionNote: null,
status: 'pending_review',
submittedAt: '2026-08-01T00:00:00.000Z',
completedAt: null,
imageUrls: [],
imageGroups: [{
imageId: 'image-1',
sourceName: '作品长图',
previewUrl: '/preview.webp',
previewWidth: 1000,
previewHeight: 2000,
width: 1000,
height: 2000,
slices: [{ url: '/slice.webp', width: 1000, height: 2000 }],
}],
referenceImageUrls: [],
referenceImageGroups: [],
reviews: [],
}],
permissions: {
canResubmit: false,
pendingReviewRoles: ['manager'],
},
}
describe('WorkReviewReviewerWorkspace', () => {
test('adds a normalized point annotation and submits the current review for revision', async () => {
window.PointerEvent = MouseEvent as typeof PointerEvent
const user = userEvent.setup()
const onSubmitReview = jest.fn().mockResolvedValue(undefined)
render(<WorkReviewReviewerWorkspace project={project} onSubmitReview={onSubmitReview} />)
await user.click(screen.getAllByRole('button', { name: '+ 添加标注' })[0])
const canvas = screen.getAllByRole('group', { name: /作品长图,可添加位置批注/ })[0]
jest.spyOn(canvas, 'getBoundingClientRect').mockReturnValue({
x: 0,
y: 0,
top: 0,
left: 0,
right: 1000,
bottom: 2000,
width: 1000,
height: 2000,
toJSON: () => ({}),
})
fireEvent.pointerDown(canvas, { button: 0, clientX: 250, clientY: 500 })
fireEvent.pointerUp(canvas, { button: 0, clientX: 250, clientY: 500 })
const comment = screen.getByRole('textbox', { name: /图 1 · 标注 1 修改意见/ })
await user.type(comment, '人物位置向左移动')
await user.click(screen.getByRole('button', { name: '完成' }))
await user.click(screen.getByRole('button', { name: '提交给修改人' }))
await waitFor(() => expect(onSubmitReview).toHaveBeenCalledTimes(1))
expect(onSubmitReview.mock.calls[0][1]).toMatchObject({
reviewerRole: 'manager',
imageComments: [{
imageIndex: 0,
decision: 'revision_required',
annotations: [{ x: 0.25, y: 0.25, comment: '人物位置向左移动' }],
}],
})
})
test('approves directly without requiring a modification annotation', async () => {
const user = userEvent.setup()
const onSubmitReview = jest.fn().mockResolvedValue(undefined)
render(<WorkReviewReviewerWorkspace project={project} onSubmitReview={onSubmitReview} />)
await user.click(screen.getByRole('button', { name: '通过' }))
await waitFor(() => expect(onSubmitReview).toHaveBeenCalledTimes(1))
expect(onSubmitReview.mock.calls[0][1]).toMatchObject({
reviewerRole: 'manager',
imageComments: [{
imageIndex: 0,
decision: 'approved',
comment: '通过',
annotations: [],
}],
})
})
})

View File

@ -1,6 +1,60 @@
export type WorkReviewDecision = 'approved' | 'revision_required'
export type WorkReviewReviewerRole = 'manager' | 'final_reviewer'
export type NormalizedWorkReviewAnnotation = {
id: string
x: number
y: number
comment: string
}
export type WorkReviewAnnotationValidationResult =
| { ok: true; annotations: NormalizedWorkReviewAnnotation[] }
| { ok: false; error: string }
const WORK_REVIEW_ANNOTATION_LIMIT = 50
const WORK_REVIEW_ANNOTATION_COMMENT_LIMIT = 1000
export function validateWorkReviewAnnotations(value: unknown): WorkReviewAnnotationValidationResult {
if (value == null) return { ok: true, annotations: [] }
if (!Array.isArray(value)) return { ok: false, error: '图片批注格式无效' }
if (value.length > WORK_REVIEW_ANNOTATION_LIMIT) {
return { ok: false, error: `单张图片最多添加 ${WORK_REVIEW_ANNOTATION_LIMIT} 个批注` }
}
const ids = new Set<string>()
const annotations: NormalizedWorkReviewAnnotation[] = []
for (const raw of value) {
if (!raw || typeof raw !== 'object' || Array.isArray(raw)) {
return { ok: false, error: '图片批注格式无效' }
}
const item = raw as Record<string, unknown>
const id = String(item.id ?? '').trim()
const x = item.x
const y = item.y
const comment = String(item.comment ?? '').trim()
if (!id || id.length > 64 || ids.has(id)) {
return { ok: false, error: '图片批注编号无效或重复' }
}
if (typeof x !== 'number' || !Number.isFinite(x) || x < 0 || x > 1
|| typeof y !== 'number' || !Number.isFinite(y) || y < 0 || y > 1) {
return { ok: false, error: '图片批注位置无效' }
}
if (!comment) return { ok: false, error: '请填写每个标注点的修改意见' }
if (comment.length > WORK_REVIEW_ANNOTATION_COMMENT_LIMIT) {
return { ok: false, error: `单个标注点的修改意见不能超过 ${WORK_REVIEW_ANNOTATION_COMMENT_LIMIT} 个字` }
}
ids.add(id)
annotations.push({
id,
x: Math.round(x * 1_000_000) / 1_000_000,
y: Math.round(y * 1_000_000) / 1_000_000,
comment,
})
}
return { ok: true, annotations }
}
type WorkReviewEmployeeIdentity = {
id?: unknown
dingtalkUserId?: unknown

View File

@ -42,6 +42,7 @@ import {
getWorkReviewReviewerSelectionError,
isSameWorkReviewEmployeeAlias,
isSameWorkReviewEmployeeIdentity,
validateWorkReviewAnnotations,
} from '@/lib/work-review-policy'
const REVIEW_ROLES = {
@ -970,7 +971,13 @@ function readImageComments(value: unknown, imageGroups: PerformanceSurveyStoredI
byIndex.set(imageIndex, item)
}
return imageGroups.map((group, imageIndex): ImageCommentInput => {
let annotationCount = 0
return imageGroups.map((group, imageIndex): ImageCommentInput & { annotations: Array<{
id: string
x: number
y: number
comment: string
}> } => {
const item = byIndex.get(imageIndex)
if (!item) throw new WorkReviewApiError(`请填写图片「${group.sourceName}」的评审建议`)
const decision = clean(item.decision)
@ -980,12 +987,17 @@ function readImageComments(value: unknown, imageGroups: PerformanceSurveyStoredI
const comment = clean(item.comment)
if (!comment) throw new WorkReviewApiError(`请填写图片「${group.sourceName}」的评审建议`)
if (comment.length > 2000) throw new WorkReviewApiError('单张图片的评审建议不能超过 2000 个字')
const annotationResult = validateWorkReviewAnnotations(item.annotations)
if (!annotationResult.ok) throw new WorkReviewApiError(annotationResult.error)
annotationCount += annotationResult.annotations.length
if (annotationCount > 200) throw new WorkReviewApiError('单次评审最多添加 200 个批注')
return {
imageId: group.imageId || `image-${imageIndex + 1}`,
imageIndex,
sourceName: group.sourceName,
decision,
comment,
annotations: annotationResult.annotations,
}
})
}

View File

@ -4,6 +4,13 @@ export type WorkReviewRole = 'manager' | 'final_reviewer'
export type WorkReviewDecision = 'approved' | 'revision_required'
export type WorkReviewImageAnnotation = {
id: string
x: number
y: number
comment: string
}
export type WorkReviewImageSlice = {
url: string
width: number
@ -30,6 +37,7 @@ export type WorkReviewImageComment = {
sourceName?: string
decision: WorkReviewDecision
comment: string
annotations?: WorkReviewImageAnnotation[]
}
export type WorkReviewReview = {
@ -152,6 +160,7 @@ export type WorkReviewReviewInput = {
imageIndex: number
decision: WorkReviewDecision
comment: string
annotations?: WorkReviewImageAnnotation[]
}>
generalComment: string
}