diff --git a/frontend/src/components/document-preview.vue b/frontend/src/components/document-preview.vue index 422f814..bd48c9b 100644 --- a/frontend/src/components/document-preview.vue +++ b/frontend/src/components/document-preview.vue @@ -410,7 +410,11 @@ async function renderExcel(blob: Blob, fileType?: string) { await nextTick(); const container = previewContent.value as HTMLElement | null; if (container && drawings.length > 0) { - mountExcelPreviewImages(container, drawings); + // Async: the mount retries while the panel fades in and logs the count, + // so a silent no-image state is diagnosable from the console. + mountExcelPreviewImages(container, drawings).then(mounted => { + console.info(`[DocumentPreview] embedded images mounted: ${mounted}/${drawings.length}`); + }); } } diff --git a/frontend/src/utils/xlsxDrawings.ts b/frontend/src/utils/xlsxDrawings.ts index 0fa3898..1664c80 100644 --- a/frontend/src/utils/xlsxDrawings.ts +++ b/frontend/src/utils/xlsxDrawings.ts @@ -163,7 +163,17 @@ export async function extractExcelImages(buf: ArrayBuffer): Promise { + // The preview panel may still be fading in when renderExcel finishes: a + // hidden table reports zero-size rects, which would collapse every image + // to 2x2 px. Wait (bounded) until the grid has real geometry. + for (let attempt = 0; attempt < 20; attempt++) { + const probe = container.querySelector('#sheet-0') as HTMLTableElement | null; + if (!probe || probe.getBoundingClientRect().width > 0) break; + await new Promise(resolve => setTimeout(resolve, 100)); + } + + let mounted = 0; for (const img of images) { const table = container.querySelector(`#sheet-${img.sheetIndex}`) as HTMLTableElement | null; if (!table) continue; @@ -207,5 +217,7 @@ export function mountExcelPreviewImages(container: HTMLElement, images: ExcelDra el.style.objectFit = 'fill'; el.style.zIndex = '5'; parent.appendChild(el); + mounted++; } + return mounted; } diff --git a/internal/agent/tools/xlsx_translate.go b/internal/agent/tools/xlsx_translate.go index 69089b6..db5349b 100644 --- a/internal/agent/tools/xlsx_translate.go +++ b/internal/agent/tools/xlsx_translate.go @@ -214,10 +214,16 @@ func (t *XlsxTranslateTool) Execute(ctx context.Context, args json.RawMessage) ( // both into the agent's knowledge base when one is selected; ingestion // runs through the normal async pipeline, so failures never block // delivering the translated workbook. - if t.ingestKB != "" && t.knowledge != nil { + switch { + case t.ingestKB != "" && t.knowledge != nil: if warn := t.ingestToKnowledge(ctx, tenantID, source, data, outName, translated); warn != "" { report.Warnings = append(report.Warnings, warn) } + default: + // Silent skipping here is how the "knowledge library stays empty" + // confusion happens — surface the missing configuration instead. + report.Warnings = append(report.Warnings, + "本智能体未勾选知识库,原件与译文未入库(管理员在智能体编辑中为本智能体勾选知识库后启用自动入库)") } logger.Infof(ctx, "[Tool][XlsxTranslate] session=%s file=%s -> %s units=%d residual=%d llm_calls=%d",