detail-echo.js
2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/** 详情 jsonContent 回显范围:跳过模版 brand/filterBrandId;baseSceneCode 由 specs/index 层校验 */
import { isSubform, isStaticGroup } from '../../field-types.js'
import { ATTENDANCE_KEY, isDividerVisible } from '../../visibility.js'
/** 字段是否受 F1-1 出勤 rules.result 联动(与 field-show-rule.js 一致) */
function isAttendanceGatedField(field = {}) {
const rules = field.rules || {}
const keys = rules.keys || []
return keys.includes(ATTENDANCE_KEY) && !!rules.result
}
function resolveEchoSubformKeys(ctx = {}, options = {}) {
if (options.echoSubformKeys instanceof Set && options.echoSubformKeys.size) {
return options.echoSubformKeys
}
const fromCtx = ctx.echoSubformKeys
if (fromCtx instanceof Set) return fromCtx
return new Set(Array.isArray(fromCtx) ? fromCtx : [])
}
function resolveEchoTopLevelKeys(ctx = {}) {
const fromCtx = ctx.echoTopLevelKeys
if (fromCtx instanceof Set) return fromCtx
return new Set(Array.isArray(fromCtx) ? fromCtx : [])
}
function isInDetailEchoScope(field = {}, ctx = {}, options = {}) {
if (!ctx.hasDetailEcho) return false
const echoSubformKeys = resolveEchoSubformKeys(ctx, options)
if (
field.key &&
echoSubformKeys.has(field.key) &&
(isSubform(field) || isStaticGroup(field))
) {
return true
}
if (options.echoParentKey && echoSubformKeys.has(options.echoParentKey)) {
return true
}
const echoTopLevelKeys = resolveEchoTopLevelKeys(ctx)
if (field.key && echoTopLevelKeys.has(field.key)) {
return true
}
return false
}
/**
* 详情回显 spec:在 echo 范围内则可见(divider 仍走场景规则)
* @returns {boolean|null} true/false 表 decisive;null 表示不在 echo 模式、交给后续 spec
*/
export function detailEchoSpec(field, ctx, _values, options = {}) {
if (!ctx.hasDetailEcho) return null
if (isInDetailEchoScope(field, ctx, options)) {
if (field.type === 'divider') {
return isDividerVisible(field, ctx)
}
// 子表单内的“其他品牌”类字段必须继续服从当前主营品牌,避免历史回显扩大字段范围。
if (options.echoParentKey && field.filterBrandId?.length) {
return null
}
if (
options.hasAttendanceField &&
!options.attendanceOnDuty &&
isAttendanceGatedField(field)
) {
return null
}
return true
}
if (options.hasAttendanceField && options.attendanceOnDuty) {
return null
}
return false
}