F2-17 UI: format=amis 剥 page 壳——弹窗只渲表单本体,消三层标题嵌套
format=amis 仅弹窗 service 路径使用;根 type:page 且 body 为单对象时只下发 body,page.title/留白不再叠进 dialog(D4 弹窗嵌整页的运行时修复)。其余形态 (根非 page/body 数组/解析失败)原样下发不冒险拆。 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -232,7 +232,9 @@ public class PageSchemaController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String schemaJson = String.valueOf(row.get("schema_json"));
|
String schemaJson = String.valueOf(row.get("schema_json"));
|
||||||
String body = amisEnvelope ? "{\"status\":0,\"msg\":\"\",\"data\":" + schemaJson + "}" : schemaJson;
|
String body = amisEnvelope
|
||||||
|
? "{\"status\":0,\"msg\":\"\",\"data\":" + unwrapPageChrome(schemaJson) + "}"
|
||||||
|
: schemaJson;
|
||||||
ResponseEntity.BodyBuilder builder = ResponseEntity.ok()
|
ResponseEntity.BodyBuilder builder = ResponseEntity.ok()
|
||||||
.contentType(MediaType.APPLICATION_JSON)
|
.contentType(MediaType.APPLICATION_JSON)
|
||||||
.header(HEADER_SCHEMA_LAYER, layer);
|
.header(HEADER_SCHEMA_LAYER, layer);
|
||||||
@@ -242,6 +244,28 @@ public class PageSchemaController {
|
|||||||
return builder.body(body);
|
return builder.body(body);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* F2-17 UI:弹窗嵌整页剥壳。{@code format=amis} 仅弹窗 service 路径使用(主渲染器取裸
|
||||||
|
* schema),此时去掉 page 包装(page.title 会与 dialog 标题、form 面板叠成多层标题 +
|
||||||
|
* 整页留白)。根节点是 {@code type:page} 且 body 为单个对象时返回 body,其余形态原样返回
|
||||||
|
* (body 为数组/缺失、解析失败都不冒险拆)。
|
||||||
|
*/
|
||||||
|
static String unwrapPageChrome(String schemaJson) {
|
||||||
|
try {
|
||||||
|
com.fasterxml.jackson.databind.JsonNode root = SCHEMA_MAPPER.readTree(schemaJson);
|
||||||
|
if (root != null && root.isObject() && "page".equals(root.path("type").asText())
|
||||||
|
&& root.path("body").isObject()) {
|
||||||
|
return SCHEMA_MAPPER.writeValueAsString(root.get("body"));
|
||||||
|
}
|
||||||
|
} catch (com.fasterxml.jackson.core.JacksonException ex) {
|
||||||
|
log.warn("[F2-17] schema 剥 page 壳失败,按原样下发: {}", ex.getMessage());
|
||||||
|
}
|
||||||
|
return schemaJson;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final com.fasterxml.jackson.databind.ObjectMapper SCHEMA_MAPPER =
|
||||||
|
new com.fasterxml.jackson.databind.ObjectMapper();
|
||||||
|
|
||||||
/** If-None-Match 可为逗号分隔多值或 {@code *};任一匹配即命中。 */
|
/** If-None-Match 可为逗号分隔多值或 {@code *};任一匹配即命中。 */
|
||||||
private boolean etagMatches(String ifNoneMatch, String etag) {
|
private boolean etagMatches(String ifNoneMatch, String etag) {
|
||||||
String header = ifNoneMatch.trim();
|
String header = ifNoneMatch.trim();
|
||||||
|
|||||||
@@ -75,6 +75,38 @@ class PageSchemaControllerTest {
|
|||||||
assertEquals("standard", resp.getHeaders().getFirst(PageSchemaController.HEADER_SCHEMA_LAYER));
|
assertEquals("standard", resp.getHeaders().getFirst(PageSchemaController.HEADER_SCHEMA_LAYER));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("1b. format=amis:信封包裹 + 剥 page 壳(弹窗只渲表单本体,不再三层标题)")
|
||||||
|
void amisEnvelopeUnwrapsPageChrome() {
|
||||||
|
JdbcTemplate jdbc = mock(JdbcTemplate.class);
|
||||||
|
Map<String, Object> row = new LinkedHashMap<>();
|
||||||
|
// page 壳(title 会与 dialog 标题叠层)+ body 为单个 form 对象 → 应只下发 form
|
||||||
|
row.put("schema_json",
|
||||||
|
"{\"type\":\"page\",\"title\":\"通知管理归档表单\",\"body\":{\"type\":\"form\",\"mode\":\"horizontal\"}}");
|
||||||
|
row.put("schema_etag", ETAG_VALUE);
|
||||||
|
when(jdbc.queryForList(anyString(), eq(TID)))
|
||||||
|
.thenReturn(List.of())
|
||||||
|
.thenReturn(List.of(row));
|
||||||
|
PageSchemaController c = new PageSchemaController(jdbc);
|
||||||
|
|
||||||
|
var resp = c.schema(TID, null, null, "amis");
|
||||||
|
assertEquals(HttpStatus.OK, resp.getStatusCode());
|
||||||
|
assertEquals("{\"status\":0,\"msg\":\"\",\"data\":{\"type\":\"form\",\"mode\":\"horizontal\"}}",
|
||||||
|
resp.getBody(), "page 壳应被剥掉,data 直接是 form");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("1c. format=amis:根非 page / body 非单对象 → 不拆,原样包信封")
|
||||||
|
void amisEnvelopeKeepsNonPageSchema() {
|
||||||
|
// 根不是 page → 原样
|
||||||
|
assertEquals("{\"type\":\"crud\"}", PageSchemaController.unwrapPageChrome("{\"type\":\"crud\"}"));
|
||||||
|
// page 但 body 是数组 → 不冒险拆
|
||||||
|
String arrBody = "{\"type\":\"page\",\"body\":[{\"type\":\"form\"}]}";
|
||||||
|
assertEquals(arrBody, PageSchemaController.unwrapPageChrome(arrBody));
|
||||||
|
// 非法 JSON → 原样(不抛)
|
||||||
|
assertEquals("not-json", PageSchemaController.unwrapPageChrome("not-json"));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("2. If-None-Match 命中当前 ETag → 304 空体")
|
@DisplayName("2. If-None-Match 命中当前 ETag → 304 空体")
|
||||||
void notModified304() {
|
void notModified304() {
|
||||||
|
|||||||
Reference in New Issue
Block a user