diff --git a/furniture-3d-system/package.json b/furniture-3d-system/package.json index 4e95d7e1..a3e55f2b 100644 --- a/furniture-3d-system/package.json +++ b/furniture-3d-system/package.json @@ -18,6 +18,7 @@ "prisma:studio": "prisma studio", "sync:supply-chain-product-archive": "tsx scripts/sync-supply-chain-product-archive.ts", "sync:supply-chain-product-archive-enrichment": "tsx scripts/sync-supply-chain-product-archive-enrichment.ts", + "sync:supply-chain-product-archive-sales-performance": "tsx scripts/sync-supply-chain-product-archive-sales-performance.ts", "sync:jst-sku-product-archive": "tsx scripts/sync-jst-sku-product-archive.ts", "sync:bom-cost-reference": "tsx scripts/sync-bom-cost-reference.ts", "backtest:bom-cost-reference": "tsx scripts/backtest-bom-cost-reference.ts", diff --git a/furniture-3d-system/prisma/migrations/20260817103000_add_product_archive_sales_performance/migration.sql b/furniture-3d-system/prisma/migrations/20260817103000_add_product_archive_sales_performance/migration.sql new file mode 100644 index 00000000..a5b8373c --- /dev/null +++ b/furniture-3d-system/prisma/migrations/20260817103000_add_product_archive_sales_performance/migration.sql @@ -0,0 +1,35 @@ +-- CreateTable +CREATE TABLE "SupplyChainProductArchiveSalesPerformance" ( + "archiveId" TEXT NOT NULL, + "barcode" TEXT NOT NULL, + "periodStart" DATE NOT NULL, + "periodEnd" DATE NOT NULL, + "shipAmount" DECIMAL(24,4) NOT NULL, + "returnAmount" DECIMAL(24,4) NOT NULL, + "realPerformance" DECIMAL(24,4) NOT NULL, + "shipQty" BIGINT NOT NULL, + "returnQty" BIGINT NOT NULL, + "grossProfit" DECIMAL(24,4) NOT NULL, + "grossMargin" DECIMAL(20,8), + "syncedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + + CONSTRAINT "SupplyChainProductArchiveSalesPerformance_pkey" PRIMARY KEY ("archiveId") +); + +-- CreateIndex +CREATE UNIQUE INDEX "SupplyChainProductArchiveSalesPerformance_barcode_key" +ON "SupplyChainProductArchiveSalesPerformance"("barcode"); + +-- CreateIndex +CREATE INDEX "SupplyChainProductArchiveSalesPerformance_periodEnd_idx" +ON "SupplyChainProductArchiveSalesPerformance"("periodEnd"); + +-- CreateIndex +CREATE INDEX "SupplyChainProductArchiveSalesPerformance_syncedAt_idx" +ON "SupplyChainProductArchiveSalesPerformance"("syncedAt"); + +-- AddForeignKey +ALTER TABLE "SupplyChainProductArchiveSalesPerformance" +ADD CONSTRAINT "SupplyChainProductArchiveSalesPerformance_archiveId_fkey" +FOREIGN KEY ("archiveId") REFERENCES "SupplyChainProductArchive"("id") +ON DELETE CASCADE ON UPDATE CASCADE; diff --git a/furniture-3d-system/prisma/schema.prisma b/furniture-3d-system/prisma/schema.prisma index 0a450446..07c841d0 100644 --- a/furniture-3d-system/prisma/schema.prisma +++ b/furniture-3d-system/prisma/schema.prisma @@ -563,6 +563,7 @@ model SupplyChainProductArchive { sources SupplyChainProductArchiveSource[] imageEmbedding ProductArchiveImageEmbedding? imageCache SupplyChainProductArchiveImageCache? + salesPerformance SupplyChainProductArchiveSalesPerformance? createdAt DateTime @default(now()) updatedAt DateTime @updatedAt @@ -576,6 +577,26 @@ model SupplyChainProductArchive { @@index([firstSourceCode, createdAt]) } +// 销售宽表按条码汇总的每日快照;费比和营业利润额待完整费用字段开放后再接入。 +model SupplyChainProductArchiveSalesPerformance { + archiveId String @id + archive SupplyChainProductArchive @relation(fields: [archiveId], references: [id], onDelete: Cascade) + barcode String @unique + periodStart DateTime @db.Date + periodEnd DateTime @db.Date + shipAmount Decimal @db.Decimal(24, 4) + returnAmount Decimal @db.Decimal(24, 4) + realPerformance Decimal @db.Decimal(24, 4) + shipQty BigInt + returnQty BigInt + grossProfit Decimal @db.Decimal(24, 4) + grossMargin Decimal? @db.Decimal(20, 8) + syncedAt DateTime @default(now()) + + @@index([periodEnd]) + @@index([syncedAt]) +} + // 图纸与视频导出来源:按条码保存当前有效的图纸/视频状态,支持月度增量覆盖。 model SupplyChainProductArchiveImageCache { id String @id @default(cuid()) diff --git a/furniture-3d-system/scripts/install-supply-chain-product-archive-sales-performance-sync-timer.sh b/furniture-3d-system/scripts/install-supply-chain-product-archive-sales-performance-sync-timer.sh new file mode 100644 index 00000000..851e5a78 --- /dev/null +++ b/furniture-3d-system/scripts/install-supply-chain-product-archive-sales-performance-sync-timer.sh @@ -0,0 +1,68 @@ +#!/usr/bin/env bash +set -euo pipefail + +BASE="${FURNITURE_PROD_BASE:-/opt/furniture-3d-system-prod}" +SERVICE_NAME="${SUPPLY_CHAIN_ARCHIVE_SALES_SYNC_SERVICE_NAME:-furniture-supply-chain-product-archive-sales-performance-sync}" +APP_ROOT="$BASE/current/furniture-3d-system" +SHARED="$BASE/shared" +APP_ENV="$SHARED/.env" +SYNC_ENV="$SHARED/supply-chain-product-archive-sync.env" +SERVICE_FILE="/etc/systemd/system/$SERVICE_NAME.service" +TIMER_FILE="/etc/systemd/system/$SERVICE_NAME.timer" +SYNC_CALENDAR="${SUPPLY_CHAIN_ARCHIVE_SALES_SYNC_CALENDAR:-*-*-* 03:30:00}" + +if [ "$(id -u)" -ne 0 ]; then + echo "This installer must run as root." >&2 + exit 1 +fi + +if [ ! -d "$APP_ROOT" ]; then + echo "Missing app root: $APP_ROOT" >&2 + exit 1 +fi + +if [ ! -f "$APP_ENV" ]; then + echo "Missing app env: $APP_ENV" >&2 + exit 1 +fi + +if [ ! -f "$SYNC_ENV" ]; then + echo "Missing sync env: $SYNC_ENV" >&2 + echo "Run install-supply-chain-product-archive-sync-timer.sh and fill the guard identities first." >&2 + exit 1 +fi + +cat >"$SERVICE_FILE" <"$TIMER_FILE" < argument.startsWith(prefix))?.slice(prefix.length) ?? '' +} + +function databaseIdentity(databaseUrl: string) { + const parsed = new URL(databaseUrl) + return [ + parsed.protocol.replace(/:$/, ''), + decodeURIComponent(parsed.username || ''), + parsed.hostname, + parsed.port || '', + parsed.pathname.replace(/^\//, ''), + parsed.searchParams.get('schema') ?? '', + ].join('|') +} + +function sourceDatabaseIdentity() { + const host = process.env.JST_REPORT_DB_HOST?.trim() ?? '' + const database = process.env.JST_REPORT_DB_NAME?.trim() ?? '' + const user = process.env.JST_REPORT_DB_USER?.trim() ?? '' + if (!host || !database || !user) return '' + return [ + 'sqlserver', + user, + host, + process.env.JST_REPORT_DB_PORT?.trim() || '1433', + database, + process.env.JST_REPORT_DB_SCHEMA?.trim() || 'rpt', + ].join('|') +} + +function readAsOf() { + const value = readArgument('as-of') + if (!value) return undefined + if (!/^\d{4}-\d{2}-\d{2}$/.test(value)) { + throw new Error('--as-of must use YYYY-MM-DD.') + } + const date = new Date(`${value}T00:00:00.000Z`) + if (Number.isNaN(date.getTime())) throw new Error('--as-of is not a valid date.') + return date +} + +async function main() { + if (!process.argv.includes('--apply')) { + throw new Error('This sync writes the archive. Pass --apply explicitly.') + } + if (readArgument('confirm') !== CONFIRM_TOKEN) { + throw new Error(`Pass --confirm=${CONFIRM_TOKEN}.`) + } + + const databaseUrl = process.env.DATABASE_URL?.trim() ?? '' + if (!databaseUrl) throw new Error('DATABASE_URL is required.') + const actualDatabaseIdentity = databaseIdentity(databaseUrl) + if (readArgument('expected-database-identity') !== actualDatabaseIdentity) { + throw new Error(`Pass --expected-database-identity=${actualDatabaseIdentity}.`) + } + + const actualSourceIdentity = sourceDatabaseIdentity() + if (!actualSourceIdentity) throw new Error('JST_REPORT_DB_* is required.') + if (readArgument('expected-source-database-identity') !== actualSourceIdentity) { + throw new Error(`Pass --expected-source-database-identity=${actualSourceIdentity}.`) + } + + const batchSize = Number(readArgument('batch-size') || '1000') + if (!Number.isSafeInteger(batchSize) || batchSize < 1 || batchSize > 2_000) { + throw new Error('--batch-size must be an integer between 1 and 2000.') + } + + const [ + { prisma }, + { supplyChainProductArchiveSalesPerformanceSyncService }, + ] = await Promise.all([ + import('../src/lib/prisma'), + import('../src/server/services/supply-chain-product-archive-sales-performance-sync.service'), + ]) + try { + const result = await supplyChainProductArchiveSalesPerformanceSyncService.syncAll({ + asOf: readAsOf(), + batchSize, + }) + console.log(JSON.stringify(result, null, 2)) + } finally { + await prisma.$disconnect() + } +} + +void main().catch((error) => { + console.error(error instanceof Error ? error.message : String(error)) + process.exitCode = 1 +}) diff --git a/furniture-3d-system/src/app/api/installation-demo-workbench/drawing-text-annotations/route.ts b/furniture-3d-system/src/app/api/installation-demo-workbench/drawing-text-annotations/route.ts new file mode 100644 index 00000000..dad767f4 --- /dev/null +++ b/furniture-3d-system/src/app/api/installation-demo-workbench/drawing-text-annotations/route.ts @@ -0,0 +1,50 @@ +import { NextRequest } from "next/server"; +import { AppError } from "@/server/core/errors"; +import { handleRequest, jsonError, jsonSuccess } from "@/server/core/response"; +import { installationDemoDrawingTextAnnotationService } from "@/server/services/installation-demo/installation-demo-drawing-text-annotation.service"; + +function respondWithAppError(error: unknown, requestId: string) { + if (error instanceof AppError) { + return jsonError(error.code, error.message, error.statusCode, requestId); + } + throw error; +} + +export const dynamic = "force-dynamic"; + +export async function GET(request: NextRequest) { + return handleRequest( + request, + async (ctx) => { + try { + const snapshot = await installationDemoDrawingTextAnnotationService.get( + ctx.user, + request.nextUrl.searchParams.get("drawingId"), + ); + return jsonSuccess({ snapshot }, 200, ctx.requestId); + } catch (error) { + return respondWithAppError(error, ctx.requestId); + } + }, + { requireAuth: true }, + ); +} + +export async function PATCH(request: NextRequest) { + return handleRequest( + request, + async (ctx) => { + try { + const snapshot = + await installationDemoDrawingTextAnnotationService.updateTarget( + ctx.user, + await request.json(), + ); + return jsonSuccess({ snapshot }, 200, ctx.requestId); + } catch (error) { + return respondWithAppError(error, ctx.requestId); + } + }, + { requireAuth: true }, + ); +} diff --git a/furniture-3d-system/src/app/installation-demo-share/[token]/InstallationDemoShareDrawingPage.tsx b/furniture-3d-system/src/app/installation-demo-share/[token]/InstallationDemoShareDrawingPage.tsx index efab831c..7366f261 100644 --- a/furniture-3d-system/src/app/installation-demo-share/[token]/InstallationDemoShareDrawingPage.tsx +++ b/furniture-3d-system/src/app/installation-demo-share/[token]/InstallationDemoShareDrawingPage.tsx @@ -65,6 +65,9 @@ function InstallationDemoShareDrawingPanel({ imageMode={imageMode} snapshotUrls={snapshot.numberingSnapshotUrls} snapshotLineArtUrls={snapshotLineArtUrls} + textAnnotationsByTargetKey={ + snapshot.drawingDocument?.textAnnotationsByTargetKey ?? {} + } allowManualCapture={false} readOnly /> diff --git a/furniture-3d-system/src/app/installation-demo-share/[token]/installationDemoShareDrawingDocument.test.ts b/furniture-3d-system/src/app/installation-demo-share/[token]/installationDemoShareDrawingDocument.test.ts index b6c7fda1..779e36ef 100644 --- a/furniture-3d-system/src/app/installation-demo-share/[token]/installationDemoShareDrawingDocument.test.ts +++ b/furniture-3d-system/src/app/installation-demo-share/[token]/installationDemoShareDrawingDocument.test.ts @@ -41,6 +41,7 @@ function createSnapshot(): InstallationDemoShareSnapshot { actions: [], inventoryTransforms: {}, }, + textAnnotationsByTargetKey: {}, snapshotLineArtUrls: {}, toolSnapshotLineArtUrls: {}, }, diff --git a/furniture-3d-system/src/app/installation-demo-workbench/InstallationDemoWorkbenchClient.tsx b/furniture-3d-system/src/app/installation-demo-workbench/InstallationDemoWorkbenchClient.tsx index f188ff3b..6e37fa52 100644 --- a/furniture-3d-system/src/app/installation-demo-workbench/InstallationDemoWorkbenchClient.tsx +++ b/furniture-3d-system/src/app/installation-demo-workbench/InstallationDemoWorkbenchClient.tsx @@ -107,6 +107,7 @@ import { InstallationDrawingToolLineArtGenerator } from "./components/Installati import { useInstallationDrawingCapture } from "./hooks/useInstallationDrawingCapture"; import { useInstallationDrawingAutoCapture } from "./hooks/useInstallationDrawingAutoCapture"; import { useInstallationDrawingConfirmation } from "./hooks/useInstallationDrawingConfirmation"; +import { useInstallationDrawingTextAnnotations } from "./hooks/useInstallationDrawingTextAnnotations"; import { buildInstallationDrawingCaptureFingerprint } from "./lib/installationDrawingCaptureFingerprint"; import { isInstallationDrawingActionCaptureTarget, @@ -401,6 +402,10 @@ export default function InstallationDemoWorkbenchClient({ setMode, setActiveStepId: stepEditor.setActiveStepId, }); + const drawingTextAnnotations = useInstallationDrawingTextAnnotations( + selectedDrawingId, + catalog.access.canEdit, + ); const drawingOverviewCaptureActive = isInstallationDrawingOverviewCaptureTarget(drawingCapture.captureTarget); const drawingActionCaptureTarget = isInstallationDrawingActionCaptureTarget( @@ -1732,6 +1737,8 @@ export default function InstallationDemoWorkbenchClient({ templateId: "set-1", imageMode: drawingImageMode ?? "line-art", captures: drawingCapture.captures, + textAnnotationsByTargetKey: + drawingTextAnnotations.annotationsByTargetKey, snapshotLineArtUrls: shareNumberingSnapshotBatch.snapshotLineArtUrls ?? {}, toolSnapshotLineArtUrls: @@ -1763,6 +1770,7 @@ export default function InstallationDemoWorkbenchClient({ numberingModelParts.length, numberingPlaying, drawingCapture.captures, + drawingTextAnnotations.annotationsByTargetKey, drawingTools.selectedTools, numberingVisibleModelParts, playing, @@ -2614,6 +2622,10 @@ export default function InstallationDemoWorkbenchClient({ numberingLineArtGenerating || Boolean(missingDrawingToolLineArt) } captures={drawingCapture.captures} + textAnnotationsByTargetKey={ + drawingTextAnnotations.annotationsByTargetKey + } + textAnnotationMessage={drawingTextAnnotations.message} initialScrollTop={ drawingSheetScrollPosition.drawingId === selectedDrawingId ? drawingSheetScrollPosition.scrollTop @@ -2638,6 +2650,9 @@ export default function InstallationDemoWorkbenchClient({ numberingMarkerCountOverrides, ); }} + onUpdateTextAnnotations={ + drawingTextAnnotations.saveTargetAnnotations + } autoCapture={{ phase: drawingAutoCapture.phase, error: drawingAutoCapture.error, diff --git a/furniture-3d-system/src/app/installation-demo-workbench/components/InstallationDrawingActionsPage.tsx b/furniture-3d-system/src/app/installation-demo-workbench/components/InstallationDrawingActionsPage.tsx index 9db6a7cb..36b032b8 100644 --- a/furniture-3d-system/src/app/installation-demo-workbench/components/InstallationDrawingActionsPage.tsx +++ b/furniture-3d-system/src/app/installation-demo-workbench/components/InstallationDrawingActionsPage.tsx @@ -1,14 +1,22 @@ -import { ListChecks, Maximize2 } from 'lucide-react' +import { ListChecks, Maximize2, Type } from 'lucide-react' import type { InstallationDrawingActionCapture, InstallationDrawingCaptureTarget, InstallationDrawingImageMode, InstallationDrawingNumberMarker, } from '../lib/installationDrawingCaptureTypes' -import { isInstallationDrawingImageCaptured } from '../lib/installationDrawingCaptureTypes' +import { + getInstallationDrawingCaptureTargetKey, + isInstallationDrawingImageCaptured, +} from '../lib/installationDrawingCaptureTypes' import type { InstallationDrawingActionGroup } from '../lib/installationDrawingLayout' +import type { + InstallationDrawingTextAnnotation, + InstallationDrawingTextAnnotationsByTarget, +} from '../lib/installationDrawingTextAnnotations' import { InstallationDrawingImageFrame } from './InstallationDrawingImageFrame' import { InstallationDrawingNumberMarkers } from './InstallationDrawingNumberMarkers' +import { InstallationDrawingTextAnnotations } from './InstallationDrawingTextAnnotations' interface Props { groups: InstallationDrawingActionGroup[] @@ -23,6 +31,12 @@ interface Props { target: InstallationDrawingCaptureTarget, markers: InstallationDrawingNumberMarker[], ) => void + textAnnotationsByTargetKey?: InstallationDrawingTextAnnotationsByTarget + onManageTextAnnotations?: (target: InstallationDrawingCaptureTarget) => void + onCommitTextAnnotations?: ( + target: InstallationDrawingCaptureTarget, + annotations: InstallationDrawingTextAnnotation[], + ) => void allowManualCapture: boolean readOnly?: boolean } @@ -77,6 +91,9 @@ export function InstallationDrawingActionsPage({ onAdjustImage, onManageNumberingMarkers, onCommitNumberingMarkers, + textAnnotationsByTargetKey = {}, + onManageTextAnnotations, + onCommitTextAnnotations, allowManualCapture, readOnly = false, }: Props) { @@ -100,6 +117,8 @@ export function InstallationDrawingActionsPage({ actionId: action.actionId, sequence: action.sequence, } + const targetKey = getInstallationDrawingCaptureTargetKey(target) + const textAnnotations = textAnnotationsByTargetKey[targetKey] ?? [] const captured = capture ? isInstallationDrawingImageCaptured(capture.image) : false return (
) : null} + {captured && textAnnotations.length > 0 ? ( + onCommitTextAnnotations(target, annotations) + : undefined} + /> + ) : null} {capture && capture.tools.length > 0 ? ( @@ -155,6 +183,17 @@ export function InstallationDrawingActionsPage({ ) : null} + {capture && captured ? ( + + ) : null} {capture && captured ? ( - ) : ( - - )} - {hasDraftBatch && !running ? ( - - 已完成 {completedCount}/{totalCount} - + <> +
+ {settled ? ( + + ) : running ? ( + + ) : ( + + )} + {hasDraftBatch && !running ? ( + + 已完成 {completedCount}/{totalCount} + + ) : null} + {configurationChanged ? ( + + 配置已变更 + + ) : null} + {error && !running ? ( + + {error} + + ) : null} +
+ + {restartDialogOpen ? ( +
+
+
+
+ +

+ 重新批量带入全部画面? +

+
+ +
+
+

+ 将重新抓取 {totalCount} 张原图和打印线稿。当前版本会保留到新批次全部完成,已有画面位置和编号设置继续沿用。 +

+
+ + +
+
+
+
) : null} - {configurationChanged ? ( - - 配置已变更 - - ) : null} - {error && !running ? ( - - {error} - - ) : null} - + ); } diff --git a/furniture-3d-system/src/app/installation-demo-workbench/components/InstallationDrawingSheet.tsx b/furniture-3d-system/src/app/installation-demo-workbench/components/InstallationDrawingSheet.tsx index 527d0237..66e7ae03 100644 --- a/furniture-3d-system/src/app/installation-demo-workbench/components/InstallationDrawingSheet.tsx +++ b/furniture-3d-system/src/app/installation-demo-workbench/components/InstallationDrawingSheet.tsx @@ -12,6 +12,7 @@ import type { } from "../types"; import type { InstallationDrawingCaptures, + InstallationDrawingActionCaptureTarget, InstallationDrawingCaptureTarget, InstallationDrawingCapturedImage, InstallationDrawingImageMode, @@ -20,11 +21,16 @@ import type { } from "../lib/installationDrawingCaptureTypes"; import { DEFAULT_INSTALLATION_DRAWING_IMAGE_TRANSFORM, + getInstallationDrawingCaptureTargetKey, isInstallationDrawingImageAvailable, isInstallationDrawingImageCaptured, resolveInstallationDrawingConfirmedAtForMode, resolveInstallationDrawingImageMode, } from "../lib/installationDrawingCaptureTypes"; +import type { + InstallationDrawingTextAnnotation, + InstallationDrawingTextAnnotationsByTarget, +} from "../lib/installationDrawingTextAnnotations"; import { buildInstallationDrawingLayout } from "../lib/installationDrawingLayout"; import { useInstallationDrawingMarkerInventory } from "../hooks/useInstallationDrawingMarkerInventory"; import { @@ -39,6 +45,7 @@ import { InstallationDrawingInventoryPage } from "./InstallationDrawingInventory import { InstallationDrawingOverviewPage } from "./InstallationDrawingOverviewPage"; import { InstallationDrawingImageAdjustDialog } from "./InstallationDrawingImageAdjustDialog"; import { InstallationDrawingMarkerManagerDialog } from "./InstallationDrawingMarkerManagerDialog"; +import { InstallationDrawingTextAnnotationDialog } from "./InstallationDrawingTextAnnotationDialog"; import { buildInstallationDrawingInventoryItems, type InstallationDrawingOverviewTool, @@ -57,6 +64,8 @@ interface InstallationDrawingSheetProps { toolSnapshotLineArtUrls: Record; lineArtGenerating?: boolean; captures: InstallationDrawingCaptures; + textAnnotationsByTargetKey: InstallationDrawingTextAnnotationsByTarget; + textAnnotationMessage?: string | null; initialScrollTop: number; onCaptureTarget: ( target: InstallationDrawingCaptureTarget, @@ -68,6 +77,10 @@ interface InstallationDrawingSheetProps { numberingMarkers: InstallationDrawingNumberMarker[], numberingMarkerCountOverrides: Record, ) => void; + onUpdateTextAnnotations: ( + targetKey: string, + annotations: InstallationDrawingTextAnnotation[], + ) => void; autoCapture: { phase: | "loading" @@ -162,9 +175,12 @@ export function InstallationDrawingSheet({ toolSnapshotLineArtUrls, lineArtGenerating = false, captures, + textAnnotationsByTargetKey, + textAnnotationMessage = null, initialScrollTop, onCaptureTarget, onUpdateImageLayout, + onUpdateTextAnnotations, autoCapture, confirmation, onClose, @@ -180,6 +196,8 @@ export function InstallationDrawingSheet({ ); const [adjustTarget, setAdjustTarget] = useState(null); + const [textAnnotationTarget, setTextAnnotationTarget] = + useState(null); const scrollContainerRef = useRef(null); const { markerManagerTarget, @@ -297,6 +315,23 @@ export function InstallationDrawingSheet({ image.numberingMarkerCountOverrides, ); }; + const commitTextAnnotations = ( + target: InstallationDrawingActionCaptureTarget, + annotations: InstallationDrawingTextAnnotation[], + ) => { + const image = resolveCapturedImage(reconciledCaptures, target); + if (!image) return; + onUpdateTextAnnotations( + getInstallationDrawingCaptureTargetKey(target), + annotations, + ); + onUpdateImageLayout( + target, + image.transform, + image.numberingMarkers, + image.numberingMarkerCountOverrides, + ); + }; const captureFromCurrentPosition = ( target: InstallationDrawingCaptureTarget, ) => { @@ -429,6 +464,14 @@ export function InstallationDrawingSheet({ {confirmation.message}

) : null} + {textAnnotationMessage ? ( +

+ {textAnnotationMessage} +

+ ) : null}
{ + if (target.kind === "action") setTextAnnotationTarget(target); + }} + onCommitTextAnnotations={(target, annotations) => { + if (target.kind === "action") { + commitTextAnnotations(target, annotations); + } + }} allowManualCapture={ !autoCapture.running && !autoCapture.hasDraftBatch } @@ -647,6 +699,21 @@ export function InstallationDrawingSheet({ onClose={() => setMarkerManagerTarget(null)} /> ) : null} + {textAnnotationTarget ? ( + { + commitTextAnnotations(textAnnotationTarget, annotations); + setTextAnnotationTarget(null); + }} + onClose={() => setTextAnnotationTarget(null)} + /> + ) : null}
, document.body, ); diff --git a/furniture-3d-system/src/app/installation-demo-workbench/components/InstallationDrawingSheetScroll.test.tsx b/furniture-3d-system/src/app/installation-demo-workbench/components/InstallationDrawingSheetScroll.test.tsx index 1fbf77f8..0703228c 100644 --- a/furniture-3d-system/src/app/installation-demo-workbench/components/InstallationDrawingSheetScroll.test.tsx +++ b/furniture-3d-system/src/app/installation-demo-workbench/components/InstallationDrawingSheetScroll.test.tsx @@ -80,9 +80,11 @@ function buildProps(initialScrollTop: number, onCaptureTarget: jest.Mock) { actions: [], inventoryTransforms: {}, }, + textAnnotationsByTargetKey: {}, initialScrollTop, onCaptureTarget, onUpdateImageLayout: jest.fn(), + onUpdateTextAnnotations: jest.fn(), autoCapture: { phase: "idle" as const, error: null, diff --git a/furniture-3d-system/src/app/installation-demo-workbench/components/InstallationDrawingTextAnnotationDialog.tsx b/furniture-3d-system/src/app/installation-demo-workbench/components/InstallationDrawingTextAnnotationDialog.tsx new file mode 100644 index 00000000..002fe343 --- /dev/null +++ b/furniture-3d-system/src/app/installation-demo-workbench/components/InstallationDrawingTextAnnotationDialog.tsx @@ -0,0 +1,199 @@ +"use client"; + +import { useState } from "react"; +import { Check, Minus, Plus, Trash2, Type, X } from "lucide-react"; +import { + MAX_INSTALLATION_DRAWING_TEXT_ANNOTATIONS_PER_TARGET, + MAX_INSTALLATION_DRAWING_TEXT_FONT_SIZE, + MAX_INSTALLATION_DRAWING_TEXT_LENGTH, + MIN_INSTALLATION_DRAWING_TEXT_FONT_SIZE, + clampInstallationDrawingTextFontSize, + cloneInstallationDrawingTextAnnotations, + createInstallationDrawingTextAnnotation, + type InstallationDrawingTextAnnotation, +} from "../lib/installationDrawingTextAnnotations"; + +interface Props { + title: string; + annotations: InstallationDrawingTextAnnotation[]; + onSave: (annotations: InstallationDrawingTextAnnotation[]) => void; + onClose: () => void; +} + +export function InstallationDrawingTextAnnotationDialog({ + title, + annotations, + onSave, + onClose, +}: Props) { + const [items, setItems] = useState(() => + cloneInstallationDrawingTextAnnotations(annotations), + ); + + const updateItem = ( + id: string, + patch: Partial, + ) => { + setItems((current) => + current.map((item) => (item.id === id ? { ...item, ...patch } : item)), + ); + }; + + return ( +
+
+
+
+

文字标注 · {title}

+

+ 保存后直接在动作画面中拖动文字到目标位置。 +

+
+ +
+ +
+
+ 共 {items.length} 个文本框 + +
+ + {items.length === 0 ? ( +
+ 点击“添加文本”创建第一个文字标注 +
+ ) : ( +
+ {items.map((item, index) => ( +
+ + {index + 1} + +