Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
saas_plus
/
dj-car-boutique-work-wechat
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
1
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit e33f7c5d
authored
Jun 04, 2026
by
张立顺
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
feat 洽谈bug修复
1 parent
a6c88d67
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
219 additions
and
16 deletions
config.js
packageDynamicForm/docs/DEVLOG.md
packageDynamicForm/docs/group-repeater.md
packageDynamicForm/form-engine/core.js
packageDynamicForm/form-engine/group-rows-cache.js
packageDynamicForm/form-engine/group-visibility.js
packageDynamicForm/form-engine/validator.js
packageDynamicForm/form-engine/visibility.js
packageDynamicForm/pages/negotiationDetail/negotiationDetail.js
tests/form-engine.test.mjs
config.js
View file @
e33f7c5
...
...
@@ -18,7 +18,7 @@ export const appId = "wx570d9331f9ace0bd";
* 4预发布
* 5cdptest
*/
let
index
=
2
;
let
index
=
1
;
const
accountInfo
=
wx
.
getAccountInfoSync
();
const
systemInfo
=
wx
.
getSystemInfoSync
();
const
envName
=
accountInfo
.
miniProgram
.
envVersion
;
...
...
packageDynamicForm/docs/DEVLOG.md
View file @
e33f7c5
# DEVLOG — packageDynamicForm
## 2026-06-04 — 洽谈明细多 subform 提交校验误报修复
-
**现象**
:仅填岚图 (F3-1) 可提交;再填问界鸿蒙 (F3-2) 时 Toast「必填不能为空」且不调用
`dynamic.save`
,界面无红字(尤其「是否成交=否」)。
-
**根因**
:
`groupRowsCache`
行快照为空时
`getVisibleGroupChildFields`
未走
`childrenShowRules`
,对隐藏的成交日期/订单等误报必填。
-
**修复**
:
`resolveEffectiveRowFields`
+
`repairGroupRowsCacheFromValues`
(
`validate`
前);
`getRowFieldValue`
双 key 回退;洽谈页校验失败全量 merge 行 map + 首条错误 Toast。
-
**单测**
:
`IT-GROUP-VAL-006`
、
`IT-NEG-015`
。
## 2026-06-04 — 架构演进 P0~P5(设计模式落地)
-
**P0**
:
[
ARCHITECTURE.md
](
./ARCHITECTURE.md
)
增加子表双状态不变式、改 type 触达文件表。
...
...
packageDynamicForm/docs/group-repeater.md
View file @
e33f7c5
...
...
@@ -105,6 +105,7 @@ values['F2-9'] = [
-
**0 行**
(未点「新增」或
`values[groupKey]`
为
`[]`
):不校验该 group,可提交。
-
**≥1 行**
:对每行可见子字段执行
`required`
与
`rules`
(错误 key:
`groupKey__rowIndex__childKey`
)。
-
**cache 空行**
:
`values`
有行而
`groupRowsCache[i]`
为空时,校验前须
`resolveEffectiveRowFields`
/
`repairGroupRowsCacheFromValues`
合成行快照后再应用
`childrenShowRules`
(避免隐藏字段误报)。
-
**行数**
:超过
`rules.maxRows`
(默认 20)时报
`${label}最多N条`
。
-
显式
`rules.minRows`
仅在已有行且行数不足时提示;
`group.required`
不再默认「至少 1 行」。
...
...
packageDynamicForm/form-engine/core.js
View file @
e33f7c5
...
...
@@ -31,6 +31,7 @@ import {
buildGroupRowsCache
,
syncValuesFromGroupCache
,
syncSubformValuesFromCache
,
repairGroupRowsCacheFromValues
,
getRowFieldsFromCache
,
addRowToCache
,
removeRowFromCache
,
...
...
@@ -328,6 +329,7 @@ export function createFormEngine(schemaRoot = {}) {
},
/** @returns {{ ok: boolean, errors: Array, errorMap: object }} 校验结果 */
validate
(
options
=
{})
{
groupRowsCache
=
repairGroupRowsCacheFromValues
(
list
,
values
,
groupRowsCache
)
values
=
syncSubformValuesFromCache
(
values
,
groupRowsCache
,
list
,
pageContext
)
return
validateForm
(
list
,
pageContext
,
values
,
groupRowsCache
,
options
)
},
...
...
packageDynamicForm/form-engine/group-rows-cache.js
View file @
e33f7c5
...
...
@@ -38,6 +38,41 @@ export function syncValuesFromGroupCache(values = {}, groupKey, rowFieldsList =
}
}
function
isEmptyRowFields
(
rowFields
)
{
return
!
Array
.
isArray
(
rowFields
)
||
!
rowFields
.
length
}
/** values 有行而 cache 行快照为空时,从 valueMap 补全 cache(校验前防御) */
export
function
repairGroupRowsCacheFromValues
(
list
=
[],
values
=
{},
cache
=
{})
{
const
next
=
{
...
cache
}
listGroups
(
list
).
forEach
(
group
=>
{
const
groupKey
=
group
.
key
if
(
!
groupKey
)
return
const
columnTemplate
=
getSubformRowTemplateForAdd
(
group
)
if
(
!
columnTemplate
.
length
)
return
const
maps
=
getGroupRows
(
values
,
groupKey
)
if
(
!
maps
.
length
)
return
const
rowList
=
cloneRowFieldsList
(
next
[
groupKey
]
||
[])
while
(
rowList
.
length
<
maps
.
length
)
{
rowList
.
push
([])
}
let
changed
=
false
maps
.
forEach
((
valueMap
,
rowIndex
)
=>
{
if
(
isEmptyRowFields
(
rowList
[
rowIndex
]))
{
rowList
[
rowIndex
]
=
valueMapToRowFieldsFromOrigin
(
columnTemplate
,
valueMap
||
{}
)
changed
=
true
}
})
if
(
changed
||
rowList
.
length
)
{
next
[
groupKey
]
=
rowList
}
})
return
next
}
/** 校验/提交前:以 groupRowsCache 为准回写全部 subform 行,避免 values 与 cache 脱节导致误通过 */
export
function
syncSubformValuesFromCache
(
values
=
{},
groupRowsCache
=
{},
list
=
[],
ctx
=
{})
{
let
next
=
{
...
values
}
...
...
packageDynamicForm/form-engine/group-visibility.js
View file @
e33f7c5
/** 行内子字段显隐 childrenShowRules(对齐 gl_tape EditForm.itemShow) */
const
{
evaluateShowRule
}
=
require
(
'./group-show-rule-eval.js'
)
function
getRowFieldValue
(
rowFields
=
[],
key
=
''
)
{
function
getRowFieldValue
(
rowFields
=
[],
key
=
''
,
rowMap
=
null
)
{
const
field
=
(
rowFields
||
[]).
find
(
item
=>
item
.
key
===
key
)
if
(
!
field
)
return
null
return
field
.
value
==
null
||
field
.
value
===
''
?
null
:
field
.
value
if
(
field
)
{
if
(
field
.
value
!=
null
&&
field
.
value
!==
''
)
{
return
field
.
value
}
const
metaKey
=
field
.
key
if
(
metaKey
!=
null
&&
field
[
metaKey
]
!=
null
&&
field
[
metaKey
]
!==
''
)
{
const
meta
=
field
[
metaKey
]
if
(
typeof
meta
===
'object'
&&
!
Array
.
isArray
(
meta
))
{
return
meta
.
name
??
meta
.
label
??
meta
.
id
??
meta
}
return
meta
}
}
if
(
rowMap
&&
rowMap
[
key
]
!=
null
&&
rowMap
[
key
]
!==
''
)
{
return
rowMap
[
key
]
}
return
null
}
function
isGroupChildVisibleInRow
(
group
=
{},
child
=
{},
rowFields
=
[])
{
function
isGroupChildVisibleInRow
(
group
=
{},
child
=
{},
rowFields
=
[]
,
rowMap
=
null
)
{
const
rules
=
group
.
childrenShowRules
if
(
!
rules
||
!
child
?.
key
)
{
return
true
...
...
@@ -21,12 +36,14 @@ function isGroupChildVisibleInRow(group = {}, child = {}, rowFields = []) {
if
(
!
keys
.
length
||
!
resultExpr
)
{
return
true
}
return
evaluateShowRule
(
keys
,
resultExpr
,
rowFields
,
getRowFieldValue
)
return
evaluateShowRule
(
keys
,
resultExpr
,
rowFields
,
(
rf
,
k
)
=>
getRowFieldValue
(
rf
,
k
,
rowMap
)
)
}
function
filterVisibleRowFields
(
group
=
{},
rowFields
=
[])
{
function
filterVisibleRowFields
(
group
=
{},
rowFields
=
[]
,
rowMap
=
null
)
{
return
(
rowFields
||
[]).
filter
(
field
=>
isGroupChildVisibleInRow
(
group
,
field
,
rowFields
)
isGroupChildVisibleInRow
(
group
,
field
,
rowFields
,
rowMap
)
)
}
...
...
packageDynamicForm/form-engine/validator.js
View file @
e33f7c5
/** 表单校验 — @see packageDynamicForm/docs/ARCHITECTURE.md */
import
{
getVisibleList
,
getVisibleLeafFields
,
getVisibleGroupChildFields
}
from
'./visibility.js'
import
{
getVisibleList
,
getVisibleLeafFields
,
getVisibleGroupChildFields
,
resolveEffectiveRowFields
}
from
'./visibility.js'
import
{
buildGroupErrorKey
,
getGroupRows
}
from
'./group-values.js'
import
{
isCarBrandComplete
,
resolveCarBrandValueForValidation
}
from
'./car-brand-value.js'
import
{
resolveNumberInputMaxLength
}
from
'./field-input-limits.js'
...
...
@@ -228,9 +233,17 @@ export function validateForm(list = [], ctx, values, groupRowsCache = {}, option
for
(
let
rowIndex
=
0
;
rowIndex
<
rowCount
;
rowIndex
++
)
{
const
row
=
rows
[
rowIndex
]
||
{}
const
rowFields
=
rowFieldsList
[
rowIndex
]
||
[]
const
children
=
getVisibleGroupChildFields
(
group
,
ctx
,
values
,
list
,
rowFields
)
const
effectiveRowFields
=
resolveEffectiveRowFields
(
group
,
rowFields
,
row
)
const
children
=
getVisibleGroupChildFields
(
group
,
ctx
,
values
,
list
,
effectiveRowFields
,
row
)
children
.
forEach
(
child
=>
{
const
rowField
=
r
owFields
.
find
(
f
=>
f
.
key
===
child
.
key
)
const
rowField
=
effectiveR
owFields
.
find
(
f
=>
f
.
key
===
child
.
key
)
const
fieldValue
=
resolveSubformChildValue
(
child
,
row
,
rowField
)
const
errorKey
=
buildGroupErrorKey
(
group
.
key
,
rowIndex
,
child
.
key
)
const
fieldErrors
=
validateField
(
child
,
fieldValue
,
{
...
...
packageDynamicForm/form-engine/visibility.js
View file @
e33f7c5
...
...
@@ -6,10 +6,12 @@
* 驻店 F1-1 调休:isAttendanceOnDuty(radio-value.js)
*/
import
{
filterVisibleRowFields
}
from
'./group-visibility.js'
import
{
valueMapToRowFieldsFromOrigin
}
from
'./group-row-adapter.js'
import
{
isSubform
,
isStaticGroup
,
getSubformRowTemplate
,
getSubformRowTemplateForAdd
,
getStaticGroupChildren
,
}
from
'./field-types.js'
import
{
isAttendanceOnDuty
}
from
'./radio-value.js'
...
...
@@ -268,13 +270,51 @@ export function getVisibleLeafFields(list = [], ctx, values) {
return
leaves
}
function
hasRowValueMap
(
row
=
{})
{
if
(
!
row
||
typeof
row
!==
'object'
)
{
return
false
}
return
Object
.
keys
(
row
).
some
(
key
=>
{
const
v
=
row
[
key
]
return
(
v
!==
undefined
&&
v
!==
null
&&
v
!==
''
&&
!
(
Array
.
isArray
(
v
)
&&
v
.
length
===
0
)
)
})
}
/** cache 行快照为空时,用 values 行 valueMap + 列模板合成 FormField[](供校验 childrenShowRules) */
export
function
resolveEffectiveRowFields
(
group
=
{},
rowFields
=
[],
row
=
{})
{
if
(
Array
.
isArray
(
rowFields
)
&&
rowFields
.
length
)
{
return
rowFields
}
if
(
hasRowValueMap
(
row
))
{
const
columnTemplate
=
getSubformRowTemplateForAdd
(
group
)
if
(
columnTemplate
.
length
)
{
return
valueMapToRowFieldsFromOrigin
(
columnTemplate
,
row
)
}
}
return
Array
.
isArray
(
rowFields
)
?
rowFields
:
[]
}
/** subform 行内可见子字段(模板显隐 + childrenShowRules) */
export
function
getVisibleGroupChildFields
(
group
,
ctx
,
values
,
list
=
[],
rowFields
=
null
)
{
export
function
getVisibleGroupChildFields
(
group
,
ctx
,
values
,
list
=
[],
rowFields
=
null
,
row
=
null
)
{
const
templateChildren
=
getVisibleSubformChildren
(
group
,
ctx
,
values
,
list
).
filter
(
isLeafField
)
if
(
!
Array
.
isArray
(
rowFields
)
||
!
rowFields
.
length
)
{
const
rowMap
=
row
&&
typeof
row
===
'object'
?
row
:
{}
const
effectiveRowFields
=
resolveEffectiveRowFields
(
group
,
rowFields
||
[],
rowMap
)
if
(
!
effectiveRowFields
.
length
)
{
return
templateChildren
}
const
visibleInRow
=
filterVisibleRowFields
(
group
,
rowFields
)
const
visibleInRow
=
filterVisibleRowFields
(
group
,
effectiveRowFields
,
rowMap
)
const
visibleKeys
=
new
Set
(
visibleInRow
.
map
(
f
=>
f
.
key
))
return
templateChildren
.
filter
(
child
=>
visibleKeys
.
has
(
child
.
key
))
}
...
...
packageDynamicForm/pages/negotiationDetail/negotiationDetail.js
View file @
e33f7c5
...
...
@@ -500,12 +500,15 @@ Page({
vinApiValidMap
:
this
.
data
.
vinApiValidMap
})
if
(
!
validation
.
ok
)
{
const
firstErr
=
validation
.
errors
[
0
]
this
.
applyEngineView
(
this
.
engine
.
getViewState
(),
{
errors
:
validation
.
errorMap
,
structureChanged
:
tru
e
,
structureChanged
:
fals
e
,
groupActiveIndex
:
this
.
buildGroupActiveIndexFromErrors
(
validation
.
errorMap
)
})
return
wx
.
$util
.
showToast
(
'必填不能为空'
)
return
wx
.
$util
.
showToast
(
firstErr
?.
message
||
firstErr
?.
label
||
'必填不能为空'
)
}
this
.
applyEngineView
(
this
.
engine
.
getViewState
(),
{
errors
:
{},
structureChanged
:
false
})
if
(
!
this
.
reportTemplateId
)
{
...
...
tests/form-engine.test.mjs
View file @
e33f7c5
...
...
@@ -1526,6 +1526,41 @@ describe('group validation', async () => {
assert.equal(second.ok, false, 'other required row fields may still fail')
assert.ok(!second.errorMap[buildGroupErrorKey('F2-9', 0, 'F2-9-1')])
})
it('IT-GROUP-VAL-006: empty cache row applies childrenShowRules from values (F3-2 否)', async () => {
const { validateForm } = await import('../packageDynamicForm/form-engine/validator.js')
const { repairGroupRowsCacheFromValues } = await import(
'../packageDynamicForm/form-engine/group-rows-cache.js'
)
const negotiationSchema = loadSchemaFixture('negotiation')
const ctx = {
baseSceneCode: 110201,
brandIds: [3067, 3454],
sceneList: [{ baseSceneCode: 110201 }, { baseSceneCode: 110202 }]
}
const values = {
'F3-2': [
{
'F3-2-10': '否',
'F3-2-11': '未成交原因',
'F3-2-1': '2026-06-01'
}
]
}
const cache = { 'F3-2': [[]] }
const result = validateForm(negotiationSchema.list, ctx, values, cache)
assert.ok(
!result.errorMap['F3-2__0__F3-2-12'],
'hidden 成交日期 should not validate'
)
assert.ok(!result.errorMap['F3-2__0__F3-2-13'], 'hidden 订单 should not validate')
const repaired = repairGroupRowsCacheFromValues(
negotiationSchema.list,
values,
cache
)
assert.ok((repaired['F3-2'][0] || []).length > 0)
})
})
describe('store schema filterBrandId', async () => {
...
...
@@ -1802,6 +1837,56 @@ describe('negotiation schema (F3)', async () => {
assert.equal(originChild.rules.maxDate, 'today')
})
it('IT-NEG-015: F3-1 and F3-2 both filled (否) validate together', async () => {
const { createFormEngine } = await import('../packageDynamicForm/form-engine/core.js')
const engine = createFormEngine(negotiationSchema)
const carInfo = {
vehicleBrandId: 1,
vehicleBrandName: '岚图',
vehicleSubBrandId: 2,
vehicleSubBrandName: '岚图汽车',
vehicleSeriesId: 3,
vehicleSeriesName: 'FREE',
vehicleShapeId: 4,
vehicleShapeName: '2024款'
}
const vin = 'LHGCV1650MH000001'
engine.init(negotiationSchema, warrantyCtx)
for (const groupKey of ['F3-1', 'F3-2']) {
const group = negotiationSchema.list.find(item => item.key === groupKey)
engine.addGroupRow(group)
engine.setGroupFieldValue(groupKey, 0, `${groupKey}-1`, '2026-06-01')
engine.setGroupFieldValue(groupKey, 0, `${groupKey}-2`, '销售部')
engine.setAppGroupFieldValue(groupKey, 0, `${groupKey}-3`, {
id: '4s-1',
displayLabel: '专员A'
})
engine.setGroupFieldValue(groupKey, 0, `${groupKey}-4`, '客户')
engine.setGroupFieldValue(groupKey, 0, `${groupKey}-5`, '13800138000')
engine.mutateSubform(
groupKey,
0,
`${groupKey}-6`,
{ metaValue: carInfo },
{ appDualKey: true }
)
engine.setGroupFieldValue(groupKey, 0, `${groupKey}-7`, vin)
engine.setAppGroupFieldValue(groupKey, 0, `${groupKey}-8`, {
id: 'staff-1',
displayLabel: '驻店甲'
})
engine.setGroupFieldValue(groupKey, 0, `${groupKey}-9`, '2026-06-01 10:00')
engine.setGroupFieldValue(groupKey, 0, `${groupKey}-10`, '否')
engine.setGroupFieldValue(groupKey, 0, `${groupKey}-11`, '未成交原因')
}
const vinApiValidMap = {
'F3-1__0__F3-1-7': true,
'F3-2__0__F3-2-7': true
}
const result = engine.validate({ vinApiValidMap })
assert.equal(result.ok, true, JSON.stringify(result.errorMap))
})
it('IT-NEG-009: F3-4 row validates with dual-key select and carBrand', async () => {
const { validateForm } = await import('../packageDynamicForm/form-engine/validator.js')
const carInfo = {
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment