merge-form-group-view.js
1.49 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
const {
buildGroupRowViewMaps,
buildVisibleRowFields,
getRowFieldsSnapshot,
getGroupRowTotal
} = require('../form-engine/group-row-snapshot.js')
/** 页面 applyEngineView 时合并 group 行 UI 快照(深拷贝 + 行内显隐 + wx:key) */
function mergeGroupRowMapsIntoData(
nextData = {},
groupFields = [],
groupRowsCache = {},
groupActiveIndex = {},
values = {},
visibilityContext = null
) {
const maps = buildGroupRowViewMaps(
groupFields,
groupRowsCache,
groupActiveIndex,
values,
visibilityContext
)
nextData.groupRowVisibleMap = maps.groupRowVisibleMap
nextData.groupRowTotalMap = maps.groupRowTotalMap
return nextData
}
/** 仅更新单个 group 的 visible/total,避免输入时刷新全部 repeater */
function patchGroupRowMapForKey(
nextData = {},
groupFields = [],
groupKey = '',
groupRowsCache = {},
groupActiveIndex = {},
values = {},
visibilityContext = null
) {
if (!groupKey) return nextData
const group = (groupFields || []).find(item => item.key === groupKey)
if (!group) return nextData
const rowTotal = getGroupRowTotal(groupRowsCache, groupKey, values)
const rowFields = getRowFieldsSnapshot(
groupRowsCache,
groupKey,
groupActiveIndex[groupKey]
)
nextData[`groupRowVisibleMap.${groupKey}`] = buildVisibleRowFields(
group,
rowFields,
groupActiveIndex[groupKey],
rowTotal,
visibilityContext
)
nextData[`groupRowTotalMap.${groupKey}`] = rowTotal
return nextData
}
module.exports = {
mergeGroupRowMapsIntoData,
patchGroupRowMapForKey
}