fix(tool): top tool

This commit is contained in:
zhangheng
2026-04-16 17:10:12 +08:00
parent fca9430246
commit 47b56412b7
2 changed files with 42 additions and 8 deletions

View File

@@ -307,6 +307,7 @@ const LabelPage = ({
activeOperation,
setActiveOperation,
setDrawOption,
setSubAttrPresetShow,
showObjectList,
showGroupList,
showTaskList,
@@ -1433,6 +1434,31 @@ const LabelPage = ({
const { setShift, focusInput } = useKeyEventStore()
const drawAction = useKeyboardStore((state) => state.drawAction)
const initializedDrawActionTaskIdRef = useRef<number | null>(null)
const handleSelectOperation = useCallback(
(operationId: string) => {
const operationSchema = getOperationSchema(operationId)
if (!operationSchema) return false
setActiveOperation(operationId)
setSubAttrPresetShow(!!operationSchema.sub_attributes_describe?.length)
if (isLabelTask) {
setEditMode(true)
}
return true
},
[
getOperationSchema,
isLabelTask,
setActiveOperation,
setEditMode,
setSubAttrPresetShow,
]
)
const drawShortcutSnapshotRef = useRef<{
activeOperation: string
drawOption: "default" | "intersect" | "unite"
@@ -1441,20 +1467,17 @@ const LabelPage = ({
const handleShortcut = useCallback(
(key: string, ctrl: boolean) => {
let checkOperation = getOperationSchema(key)
const mode = usePaperStore.getState().mode
const nextOperationId = ctrl ? (+key + 10).toString() : key
const checkOperation = getOperationSchema(nextOperationId)
// 标注方案里面存在的非文本类型标注才能切换
if (checkOperation) {
// 辅助标注模式下非多边形类型不能切换
if (mode === "support" && checkOperation.label_type !== 102) return
if (ctrl) {
setActiveOperation((+key + 10).toString())
} else {
setActiveOperation(key)
}
handleSelectOperation(nextOperationId)
}
},
[getOperationSchema, setActiveOperation]
[getOperationSchema, handleSelectOperation]
)
const resolveSelectedObjectContext = useCallback(() => {
@@ -2564,6 +2587,14 @@ const LabelPage = ({
drawShortcutSnapshotRef.current = null
}, [activeImage])
useEffect(() => {
if (!taskDetail?.id || !activeImage || !isLabelTask) return
if (initializedDrawActionTaskIdRef.current === taskDetail.id) return
useKeyboardStore.getState().setDrawAction("subtract")
initializedDrawActionTaskIdRef.current = taskDetail.id
}, [activeImage, isLabelTask, taskDetail?.id])
const handleBeforeUnload = (e: any) => {
e.preventDefault()
// 备份
@@ -2753,6 +2784,7 @@ const LabelPage = ({
oldWorkLoad={oldWorkLoad}
updateOldWorkLoad={updateOldWorkLoad}
isLabelTask={isLabelTask}
onOperationChange={handleSelectOperation}
renderPolygons={
paperContainerRef.current
? paperContainerRef.current.renderPolygons

View File

@@ -118,6 +118,7 @@ interface TopToolsComponentProps {
oldWorkLoad: WorkLoad | null
updateOldWorkLoad: (data: WorkLoad) => void
isLabelTask: boolean
onOperationChange: (operationId: string) => void
renderPolygons: (
operationId: string,
imageData: Map<string, [number, any[], any, any[]][]> | undefined
@@ -161,6 +162,7 @@ const TopTools = (
oldWorkLoad,
updateOldWorkLoad,
isLabelTask,
onOperationChange,
renderPolygons,
} = props
const { backUrl, basePath } = useBackUrlStore()
@@ -2312,7 +2314,7 @@ const TopTools = (
<UnstyledButton
key={item.category_id}
onClick={() => {
setActiveOperation(item.category_id.toString())
onOperationChange(item.category_id.toString())
setOperationPickerOpened(false)
setOperationKeyword("")
}}