diff --git a/backend/app/services/shipping_notice/order_document_profile_service.py b/backend/app/services/shipping_notice/order_document_profile_service.py
index 6b444c0f..d5bbc3d8 100644
--- a/backend/app/services/shipping_notice/order_document_profile_service.py
+++ b/backend/app/services/shipping_notice/order_document_profile_service.py
@@ -965,9 +965,13 @@ def list_preview_pages(profile_id: int, *, document_id: int, actor_id: int | Non
def render_preview_page(*, token: str, page_no: int, actor_id: int | None) -> bytes:
- """ PNG PDF?HTML"""
+ """按页返回受控 PNG;令牌在 TTL 内可重复使用,以支持标注画布翻页回访。
+
+ 核心逻辑:校验 Redis 中的短时 grant(不 getdel);token 仍绑定 profile/document/actor/page。
+ 标注编辑需要在多页间来回切换,一次性消费会导致每次翻页都「画布不可用」。
+ """
store = _preview_grant_store()
- raw_grant = store.getdel(f'{PREVIEW_GRANT_KEY_PREFIX}{str(token)}')
+ raw_grant = store.get(f'{PREVIEW_GRANT_KEY_PREFIX}{str(token)}')
try:
grant = json.loads(raw_grant) if raw_grant else None
except (TypeError, json.JSONDecodeError):
diff --git a/backend/app/services/shipping_notice/preview_grant_store.py b/backend/app/services/shipping_notice/preview_grant_store.py
index ec166831..1bb04da2 100644
--- a/backend/app/services/shipping_notice/preview_grant_store.py
+++ b/backend/app/services/shipping_notice/preview_grant_store.py
@@ -3,7 +3,8 @@ backend/app/services/shipping_notice/preview_grant_store.py
用途:为订单文档模板页预览令牌提供受控存储后端选择。
依赖:Flask current_app、统一 Redis client。
-逻辑:生产默认强依赖 Redis;开发单进程可按配置回退到进程内一次性令牌存储。
+逻辑:生产默认强依赖 Redis;开发单进程可按配置回退到进程内短时令牌存储。
+ PNG 页预览令牌在 TTL 内可重复 get(支持翻页);原 PDF 预览仍可用 getdel 单次消费。
"""
from __future__ import annotations
@@ -19,7 +20,7 @@ from app.services.redis_client import get_redis_client
class _MemoryGrantStore:
- """为单进程开发环境提供最小 setex/getdel 语义,保持一次性令牌行为。"""
+ """为单进程开发环境提供 setex/get/getdel,PNG 页令牌可在 TTL 内重复读取。"""
def __init__(self) -> None:
self._lock = threading.Lock()
@@ -30,6 +31,19 @@ class _MemoryGrantStore:
with self._lock:
self._items[key] = (expires_at, value)
+ def get(self, key: str) -> str | None:
+ """读取未过期令牌且不删除,供标注画布翻页回访同一 PNG grant。"""
+ now = time.time()
+ with self._lock:
+ row = self._items.get(key)
+ if row is None:
+ return None
+ expires_at, value = row
+ if expires_at <= now:
+ self._items.pop(key, None)
+ return None
+ return value
+
def getdel(self, key: str) -> str | None:
now = time.time()
with self._lock:
@@ -57,7 +71,7 @@ def preview_grant_store() -> Any:
返回模板预览授权存储。
AI/调用方触发时机:仅供订单文档模板预览接口内部使用。Redis 不可用时,
- 只有启用了开发兜底配置,才允许退回进程内一次性 token 存储。
+ 只有启用了开发兜底配置,才允许退回进程内短时 token 存储。
"""
client = get_redis_client()
if client is not None:
diff --git a/backend/tests/test_shipping_order_document_profile_service.py b/backend/tests/test_shipping_order_document_profile_service.py
index de43f473..0cec410e 100644
--- a/backend/tests/test_shipping_order_document_profile_service.py
+++ b/backend/tests/test_shipping_order_document_profile_service.py
@@ -2100,8 +2100,8 @@ def test_profile_sample_api_supports_secure_preview_create_and_version_update(ap
assert updated['lock_version'] == draft['lock_version'] + 1
-def test_profile_page_preview_is_bound_single_use_and_never_exposes_storage_url(app, monkeypatch):
- """页面预览只允许绑定样本,令牌限管理员/单页/单次且响应禁止缓存和暴露存储地址。"""
+def test_profile_page_preview_is_bound_ttl_reusable_and_never_exposes_storage_url(app, monkeypatch):
+ """页面预览只允许绑定样本;PNG 令牌在 TTL 内可翻页回访,响应禁止缓存和暴露存储地址。"""
app.config['AUTH_JWT_REQUIRED'] = False
with app.app_context():
schema = _schema_version()
@@ -2144,11 +2144,14 @@ def test_profile_page_preview_is_bound_single_use_and_never_exposes_storage_url(
preview_store: dict[str, str] = {}
class PreviewStore:
- """模拟 Redis 的 TTL 写入和原子 GETDEL,验证预览令牌无法重放。"""
+ """模拟 Redis 的 TTL 写入与 GET;PNG 页令牌在过期前可重复读取以支持翻页。"""
def setex(self, key, _ttl, value):
preview_store[key] = value
+ def get(self, key):
+ return preview_store.get(key)
+
def getdel(self, key):
return preview_store.pop(key, None)
@@ -2175,11 +2178,13 @@ def test_profile_page_preview_is_bound_single_use_and_never_exposes_storage_url(
assert image.mimetype == 'image/png'
assert image.headers['Cache-Control'] == 'private, no-store, max-age=0'
assert b'private-bucket' not in image.data and b'internal/preview.pdf' not in image.data
+ # 关键断言:TTL 内再次用同一 token 拉同页必须成功,否则标注画布翻页会「画布不可用」。
replay = client.get(
f"/api/admin/shipping-notice/order-document-profiles/{profile_id}/preview-pages/1",
query_string={'preview_token': grant['preview_token']}, headers=headers,
)
- assert replay.status_code == 404
+ assert replay.status_code == 200
+ assert replay.mimetype == 'image/png'
candidates = client.get(
f"/api/admin/shipping-notice/order-document-profiles/{profile_id}/preview-pages/1/text-candidates",
query_string={'document_id': document_id}, headers=headers,
@@ -2259,14 +2264,16 @@ def test_profile_page_preview_fails_closed_without_redis_or_sample_binding(app,
def test_profile_page_preview_uses_memory_fallback_in_development(app, monkeypatch):
- """开发环境允许单进程内存兜底,仍需保持一次性令牌语义。"""
+ """开发环境允许单进程内存兜底;PNG 令牌在 TTL 内可重复 get。"""
with app.app_context():
app.config['ORDER_DOCUMENT_PROFILE_PREVIEW_ALLOW_MEMORY_FALLBACK'] = True
monkeypatch.setattr(preview_grant_store_service, 'get_redis_client', lambda: None)
store = service._preview_grant_store()
store.setex('preview-token', 30, '{"page_no":1}')
+ assert store.get('preview-token') == '{"page_no":1}'
+ assert store.get('preview-token') == '{"page_no":1}'
assert store.getdel('preview-token') == '{"page_no":1}'
- assert store.getdel('preview-token') is None
+ assert store.get('preview-token') is None
def test_preview_page_region_text_reads_only_the_admin_selected_glyphs(app, monkeypatch):
diff --git a/frontend/src/features/admin/modules/shipping-order-document-profiles/OrderProfileEditorPage.vue b/frontend/src/features/admin/modules/shipping-order-document-profiles/OrderProfileEditorPage.vue
index a49a8d5d..f6ff1e9c 100644
--- a/frontend/src/features/admin/modules/shipping-order-document-profiles/OrderProfileEditorPage.vue
+++ b/frontend/src/features/admin/modules/shipping-order-document-profiles/OrderProfileEditorPage.vue
@@ -4,11 +4,13 @@
依赖:受控预览 API、Schema API、DocumentCanvas、useOrderProfileValueAdapter、
XfaDatasetTree、XfaCollectionSelector、XfaSplitRulePanel、shippingOrderField.utils。
逻辑:PDF 与 XFA 共用同一 desk DOM(main + aside.config + OrderProfileDocumentCanvas);
- XFA 仅在属性区插入读取方式/数据源/拆分/样本显示增量;OCR 建议进入普通建议区。
+ XFA 仅在属性区插入读取方式/数据源/拆分/样本显示增量;OCR 建议进入普通建议区;
+ 未绑定订单字段框通过横幅 + 画布高亮强制展示,避免空白底图漏看导致发布失败。
-->
@@ -409,7 +501,16 @@ onBeforeUnmount(() => { endMove(); endPan(); endCreation(); URL.revokeObjectURL(
role="button"
tabindex="0"
class="region"
- :class="[`region-${region.kind}`, { selected: selected.has(region.id), 'region-preview': region.isPreview }, region.visualBindingStatus ? `region-visual--${region.visualBindingStatus}` : '']"
+ :data-region-id="region.id"
+ :class="[
+ `region-${region.kind}`,
+ {
+ selected: selected.has(region.id),
+ 'region-preview': region.isPreview,
+ 'region--unbound': isUnboundOrderFieldCanvasRegion(region),
+ },
+ region.visualBindingStatus ? `region-visual--${region.visualBindingStatus}` : '',
+ ]"
:style="{ left: `${region.region.x0 * 100}%`, top: `${region.region.y0 * 100}%`, width: `${(region.region.x1 - region.region.x0) * 100}%`, height: `${(region.region.y1 - region.region.y0) * 100}%` }"
:aria-label="displayRegionLabel(region)"
@pointerdown.stop="beginDrag($event, region, 'move')"
@@ -502,6 +603,24 @@ onBeforeUnmount(() => { endMove(); endPan(); endCreation(); URL.revokeObjectURL(
.region-header_field .region-label, .region-header_field .resize-handle { background: #b45309; }
.region-order_field { z-index: 2; border: 1.5px solid #22c55e; background: rgb(34 197 94 / .08); }
.region-order_field .region-label, .region-order_field .resize-handle { background: #15803d; }
+/* 未绑定订单字段:底图常为空白(如签名控件),必须用高对比框强制可见。 */
+.region--unbound {
+ z-index: 6;
+ min-width: 14px;
+ min-height: 14px;
+ border: 2.5px solid #d97706;
+ background: rgb(245 158 11 / .42);
+ box-shadow: 0 0 0 2px rgb(255 255 255 / .95), 0 0 14px rgb(245 158 11 / .75);
+}
+.region--unbound .region-label {
+ top: 0;
+ left: 0;
+ max-width: 100%;
+ border-radius: 0;
+ background: #b45309;
+ white-space: normal;
+}
+.region--unbound .resize-handle { background: #b45309; }
.region-order_anchor { z-index: 2; border: 1.5px solid #a855f7; background: rgb(168 85 247 / .08); }
.region-order_anchor .region-label, .region-order_anchor .resize-handle { background: #7e22ce; }
.region-document_anchor_label { z-index: 2; border: 1.5px solid #0ea5e9; background: rgb(14 165 233 / .1); }
diff --git a/frontend/src/features/admin/modules/shipping-order-document-profiles/orderProfileForm.utils.spec.ts b/frontend/src/features/admin/modules/shipping-order-document-profiles/orderProfileForm.utils.spec.ts
index b48f1630..94de8b75 100644
--- a/frontend/src/features/admin/modules/shipping-order-document-profiles/orderProfileForm.utils.spec.ts
+++ b/frontend/src/features/admin/modules/shipping-order-document-profiles/orderProfileForm.utils.spec.ts
@@ -29,10 +29,18 @@ import {
toOrderProfileHeaderFieldRegion,
resolveCoordinateFieldScope,
isOrderProfileVisualFieldEligible,
+ isUnboundOrderFieldCanvasRegion,
buildAutomarkSuggestionSummary,
} from './orderProfileForm.utils';
describe('order profile form rules', () => {
+ it('marks order fields without fieldCode as unbound for forced canvas display', () => {
+ // 关键断言:无 Schema 绑定的订单字段框必须被识别,供画布高亮与发布前横幅共用。
+ expect(isUnboundOrderFieldCanvasRegion({ kind: 'order_field', fieldCode: null })).toBe(true);
+ expect(isUnboundOrderFieldCanvasRegion({ kind: 'order_field', fieldCode: 'currency' })).toBe(false);
+ expect(isUnboundOrderFieldCanvasRegion({ kind: 'header_field', fieldCode: null })).toBe(false);
+ });
+
it('restores a Reservation ID region from a Vue reactive profile without structured-clone failure', () => {
const persisted = reactive({
region: { x0: .05, y0: .71, x1: .28, y1: .73 },
diff --git a/frontend/src/features/admin/modules/shipping-order-document-profiles/orderProfileForm.utils.ts b/frontend/src/features/admin/modules/shipping-order-document-profiles/orderProfileForm.utils.ts
index 16ebb659..4e2e3ef6 100644
--- a/frontend/src/features/admin/modules/shipping-order-document-profiles/orderProfileForm.utils.ts
+++ b/frontend/src/features/admin/modules/shipping-order-document-profiles/orderProfileForm.utils.ts
@@ -2,7 +2,8 @@
* features/admin/modules/shipping-order-document-profiles/orderProfileForm.utils.ts
* 用途:构造可视化订单模板的白名单列规则、明细字段分组,并控制样本表格配置区的安全显示。
* 依赖:订单 Profile DTO。
- * 逻辑:页面状态只允许 direct 或已注册复合解析器;同一目标字段跨列只能出现一次。
+ * 逻辑:页面状态只允许 direct 或已注册复合解析器;同一目标字段跨列只能出现一次;
+ * 另提供「未绑定订单字段」判定,供画布强制高亮与编辑横幅共用。
*/
import type {
@@ -39,6 +40,17 @@ export const isOrderProfileVisualFieldEligible = (
&& (usesExternalValueSource || Boolean(field.allowed_sources?.includes('pdf_coordinate')))
);
+/**
+ * 判断画布区域是否为「未绑定 Schema 字段」的订单字段框。
+ * 核心逻辑:仅 order_field 且无 fieldCode 视为未绑定;这些框会写入
+ * draft_unbound_order_field_layouts 并在发布时硬阻断,必须在画布强制可见。
+ * @param region - 画布区域。
+ * @returns 是否需要未绑定高亮与横幅列出。
+ */
+export const isUnboundOrderFieldCanvasRegion = (
+ region: Pick,
+): boolean => region.kind === 'order_field' && !region.fieldCode;
+
/**
* 将画布中的视觉表头文字转换为 v2 字段区域。
* 核心逻辑:视觉位置不是业务 scope;调用方必须按 Schema 传入 header/line,
diff --git a/frontend/src/features/admin/modules/shipping-order-document-profiles/orderProfileReadonlyCanvas.utils.spec.ts b/frontend/src/features/admin/modules/shipping-order-document-profiles/orderProfileReadonlyCanvas.utils.spec.ts
index e7d093e5..4a3aafb6 100644
--- a/frontend/src/features/admin/modules/shipping-order-document-profiles/orderProfileReadonlyCanvas.utils.spec.ts
+++ b/frontend/src/features/admin/modules/shipping-order-document-profiles/orderProfileReadonlyCanvas.utils.spec.ts
@@ -2,7 +2,8 @@
* features/admin/modules/shipping-order-document-profiles/orderProfileReadonlyCanvas.utils.spec.ts
* 用途:验证版本只读画布完整恢复模板定义中的诊断区域。
* 依赖:Vitest、orderProfileReadonlyCanvas.utils。
- * 逻辑:已发布版本的必需锚点必须同时显示标签框和值框,且区域 ID 与冻结诊断接口一致。
+ * 逻辑:已发布版本的必需锚点必须同时显示标签框和值框,且区域 ID 与冻结诊断接口一致;
+ * 仅含 fallback 的未绑定订单字段框也必须恢复,供签名空白区强制可见。
*/
import { describe, expect, it } from 'vitest';
@@ -40,4 +41,40 @@ describe('buildOrderProfileReadonlyRegions', () => {
expect.objectContaining({ id: 'plant_address_value', kind: 'document_anchor_value', configuredValue: 'No. 88' }),
]));
});
+
+ it('restores fallback-only unbound order fields so blank signature areas stay visible', () => {
+ const profile = {
+ definition: {
+ document_match: { required_anchors: [], optional_anchors: [] },
+ table_regions: [],
+ order_field_layouts: [],
+ draft_unbound_order_field_layouts: [{
+ layout_id: 'order_field_2__1',
+ label: 'Sign12 · 待绑定列 1',
+ page_scope: 'exact_page',
+ page_no: 2,
+ anchor: null,
+ absolute_value_region: null,
+ fallback_value_region: { x0: .02, y0: .89, x1: .15, y1: .92 },
+ value_mode: 'single_line',
+ stop_anchors: [],
+ minimum_evidence_level: 'coordinate',
+ }],
+ },
+ } as unknown as ShippingOrderDocumentProfile;
+
+ const regions = buildOrderProfileReadonlyRegions(profile);
+
+ // 关键断言:无 anchor/absolute 时仍用 fallback 恢复未绑定框,否则签名空白区会漏展示。
+ expect(regions).toEqual(expect.arrayContaining([
+ expect.objectContaining({
+ id: 'unbound-order_field_2__1',
+ kind: 'order_field',
+ fieldCode: null,
+ pageNo: 2,
+ label: 'Sign12 · 待绑定列 1',
+ region: { x0: .02, y0: .89, x1: .15, y1: .92 },
+ }),
+ ]));
+ });
});
diff --git a/frontend/src/features/admin/modules/shipping-order-document-profiles/orderProfileReadonlyCanvas.utils.ts b/frontend/src/features/admin/modules/shipping-order-document-profiles/orderProfileReadonlyCanvas.utils.ts
index 46cfbaa0..2d06dd92 100644
--- a/frontend/src/features/admin/modules/shipping-order-document-profiles/orderProfileReadonlyCanvas.utils.ts
+++ b/frontend/src/features/admin/modules/shipping-order-document-profiles/orderProfileReadonlyCanvas.utils.ts
@@ -85,6 +85,7 @@ export const buildOrderProfileReadonlyRegions = (
}),
...(definition.draft_unbound_order_field_layouts || []).flatMap((item) => {
const pageNo = pageNoOf(item.page_scope, item.page_no);
+ // 仅有 fallback 的未绑定框也必须恢复;签名区底图常空白,缺框会导致发布前无法发现。
if (!item.anchor?.region || !item.absolute_value_region) {
return [{
id: `unbound-${item.layout_id}`,
diff --git a/frontend/src/locales/en/admin.json b/frontend/src/locales/en/admin.json
index bbfbe1e3..919275b7 100644
--- a/frontend/src/locales/en/admin.json
+++ b/frontend/src/locales/en/admin.json
@@ -3657,6 +3657,10 @@
"schemaBreaking": "Breaking field changes require migration",
"regionSuggestionReady": "Review the generated row and column marks, then confirm field bindings before saving.",
"unboundColumn": "Unbound column {count}",
+ "unboundRegionsBanner": "{count} unbound order-field boxes remain in this draft (they block publish). Open that page to see the amber boxes, select to delete, or clear all.",
+ "unboundRegionsBannerAria": "Unbound order-field box list",
+ "unboundRegionChip": "P{page} · {label}",
+ "clearUnboundRegions": "Clear all unbound boxes",
"drawHeader": "Draw header",
"drawOrderField": "Draw order field",
"drawOrderAnchor": "Draw order field label",
diff --git a/frontend/src/locales/th/admin.json b/frontend/src/locales/th/admin.json
index b16dc94e..cea78eac 100644
--- a/frontend/src/locales/th/admin.json
+++ b/frontend/src/locales/th/admin.json
@@ -3526,6 +3526,10 @@
"schemaBreaking": "การเปลี่ยนแปลงฟิลด์ที่ไม่เข้ากันต้องย้ายข้อมูล",
"regionSuggestionReady": "สร้างเครื่องหมายแถวและคอลัมน์เพื่อการตรวจทานแล้ว โปรดยืนยันการผูกฟิลด์ก่อนบันทึก",
"unboundColumn": "คอลัมน์ที่ยังไม่ผูก {count}",
+ "unboundRegionsBanner": "ยังมีกล่องฟิลด์คำสั่งซื้อที่ยังไม่ผูก {count} รายการในฉบับร่าง (จะบล็อกการเผยแพร่) เปิดหน้านั้นเพื่อเห็นกล่องสีส้ม เลือกเพื่อลบ หรือล้างทั้งหมด",
+ "unboundRegionsBannerAria": "รายการกล่องฟิลด์คำสั่งซื้อที่ยังไม่ผูก",
+ "unboundRegionChip": "P{page} · {label}",
+ "clearUnboundRegions": "ล้างกล่องที่ยังไม่ผูกทั้งหมด",
"drawHeader": "วาดหัวตาราง",
"drawOrderField": "วาดฟิลด์คำสั่งซื้อ",
"drawOrderAnchor": "วาดป้ายกำกับฟิลด์คำสั่งซื้อ",
diff --git a/frontend/src/locales/zh-CN/admin.json b/frontend/src/locales/zh-CN/admin.json
index eff26412..36aaecb9 100644
--- a/frontend/src/locales/zh-CN/admin.json
+++ b/frontend/src/locales/zh-CN/admin.json
@@ -3769,6 +3769,10 @@
"schemaBreaking": "字段版本存在不兼容变更,需要迁移",
"regionSuggestionReady": "已生成待复核的行和列标记,请确认字段绑定后保存。",
"unboundColumn": "待绑定列 {count}",
+ "unboundRegionsBanner": "草稿仍有 {count} 个未绑定订单字段框(会阻断发布)。请到对应页查看橙色框,选中后可删除,或一键清除。",
+ "unboundRegionsBannerAria": "未绑定订单字段框列表",
+ "unboundRegionChip": "P{page} · {label}",
+ "clearUnboundRegions": "清除全部未绑定框",
"drawHeader": "绘制表头",
"drawOrderField": "绘制订单字段",
"drawOrderAnchor": "绘制订单字段标签",
diff --git a/frontend/src/locales/zh-TW/admin.json b/frontend/src/locales/zh-TW/admin.json
index 1bbf456f..6a448ab8 100644
--- a/frontend/src/locales/zh-TW/admin.json
+++ b/frontend/src/locales/zh-TW/admin.json
@@ -3531,6 +3531,10 @@
"schemaBreaking": "欄位版本存在不相容變更,需要遷移",
"regionSuggestionReady": "已產生待複核的行和欄位標記,請確認欄位綁定後儲存。",
"unboundColumn": "待綁定欄 {count}",
+ "unboundRegionsBanner": "草稿仍有 {count} 個未綁定訂單欄位框(會阻斷發布)。請到對應頁查看橙色框,選取後可刪除,或一鍵清除。",
+ "unboundRegionsBannerAria": "未綁定訂單欄位框列表",
+ "unboundRegionChip": "P{page} · {label}",
+ "clearUnboundRegions": "清除全部未綁定框",
"drawHeader": "繪製表頭",
"drawOrderField": "繪製訂單欄位",
"drawOrderAnchor": "繪製訂單欄位標籤",