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 02a10bde
authored
Jun 10, 2026
by
张立顺
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
fix bug
1 parent
be014512
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
37 changed files
with
814 additions
and
227 deletions
config.js
packageDynamicForm/api/mockStoreDynamicDetail.js
packageDynamicForm/api/storeDailyReport.js
packageDynamicForm/api/storeDailyReportAdapters.js
packageDynamicForm/components/form-field-input/form-field-input.wxml
packageDynamicForm/components/form-field-input/form-field-input.wxss
packageDynamicForm/docs/ARCHITECTURE.md
packageDynamicForm/docs/PAGES.md
packageDynamicForm/docs/daily-report-save-and-json.md
packageDynamicForm/docs/field-options-api.md
packageDynamicForm/docs/group-repeater.md
packageDynamicForm/docs/staff-template-features.md
packageDynamicForm/fixtures/schema-staff-daily-full.js
packageDynamicForm/form-engine/app-subform-json.js
packageDynamicForm/form-engine/core.js
packageDynamicForm/form-engine/group-row-adapter.js
packageDynamicForm/form-engine/group-rows-cache.js
packageDynamicForm/form-engine/group-show-rule-eval.js
packageDynamicForm/form-engine/save-request.js
packageDynamicForm/form-engine/submit-adapter.js
packageDynamicForm/form-engine/values.js
packageDynamicForm/form-engine/visibility.js
packageDynamicForm/form-engine/visibility/specs/field-show-rule.js
packageDynamicForm/form-engine/visibility/specs/index.js
packageDynamicForm/tests/app-children-value-json.test.mjs
packageDynamicForm/tests/app-save-lists-from-json.test.mjs
packageDynamicForm/tests/app-subform-json.test.mjs
packageDynamicForm/tests/app-submit-order.test.mjs
packageDynamicForm/tests/dailyReportSaveRequest.test.mjs
packageDynamicForm/tests/form-engine.test.mjs
packageDynamicForm/tests/group-show-rule-eval.test.mjs
packageDynamicForm/tests/hidden-clear.test.mjs
packageDynamicForm/tests/store-app-json-content.test.mjs
packageDynamicForm/tests/store-app-json-echo.test.mjs
packageDynamicForm/tests/storeDailyReportAdapters.test.mjs
packageDynamicForm/tests/storeDailyReportDetail.test.mjs
packageDynamicForm/tests/visibility-specs.test.mjs
config.js
View file @
02a10bd
...
@@ -18,7 +18,7 @@ export const appId = "wx570d9331f9ace0bd";
...
@@ -18,7 +18,7 @@ export const appId = "wx570d9331f9ace0bd";
* 4预发布
* 4预发布
* 5cdptest
* 5cdptest
*/
*/
let
index
=
2
;
let
index
=
0
;
const
accountInfo
=
wx
.
getAccountInfoSync
();
const
accountInfo
=
wx
.
getAccountInfoSync
();
const
systemInfo
=
wx
.
getSystemInfoSync
();
const
systemInfo
=
wx
.
getSystemInfoSync
();
const
envName
=
accountInfo
.
miniProgram
.
envVersion
;
const
envName
=
accountInfo
.
miniProgram
.
envVersion
;
...
...
packageDynamicForm/api/mockStoreDynamicDetail.js
View file @
02a10bd
...
@@ -2,6 +2,7 @@ const { WARRANTY_PAGE_CONTEXT } = require('../fixtures/mock-meta.js')
...
@@ -2,6 +2,7 @@ const { WARRANTY_PAGE_CONTEXT } = require('../fixtures/mock-meta.js')
const
schemaIndexed
=
require
(
'../fixtures/schema-store-daily-full.js'
)
const
schemaIndexed
=
require
(
'../fixtures/schema-store-daily-full.js'
)
const
{
buildMockDetailJsonContent
}
=
require
(
'./mockDetailJsonContent.js'
)
const
{
buildMockDetailJsonContent
}
=
require
(
'./mockDetailJsonContent.js'
)
const
{
DEFAULT_REPORT_TEMPLATE_ID
:
TEMPLATE_IDS
}
=
require
(
'../config/dailyReportConstants.js'
)
const
{
DEFAULT_REPORT_TEMPLATE_ID
:
TEMPLATE_IDS
}
=
require
(
'../config/dailyReportConstants.js'
)
const
{
parseRequestJsonLists
}
=
require
(
'../form-engine/save-request.js'
)
const
detailStore
=
new
Map
()
const
detailStore
=
new
Map
()
const
DEFAULT_REPORT_TEMPLATE_ID
=
TEMPLATE_IDS
.
store
const
DEFAULT_REPORT_TEMPLATE_ID
=
TEMPLATE_IDS
.
store
...
@@ -167,10 +168,15 @@ function saveMockStoreDynamicDetail(params = {}) {
...
@@ -167,10 +168,15 @@ function saveMockStoreDynamicDetail(params = {}) {
dailyReportRecordId
,
dailyReportRecordId
,
fieldDataList
,
fieldDataList
,
subformDataList
,
subformDataList
,
requestJson
,
jsonContent
,
jsonContent
,
reportStatus
reportStatus
}
=
params
}
=
params
if
(
!
reportDate
)
return
null
if
(
!
reportDate
)
return
null
const
listsFromRequestJson
=
requestJson
!=
null
&&
requestJson
!==
''
?
parseRequestJsonLists
(
requestJson
)
:
null
const
storeKey
=
getStoreKey
({
merchantId
,
staffUuid
,
reportDate
})
const
storeKey
=
getStoreKey
({
merchantId
,
staffUuid
,
reportDate
})
const
prev
=
detailStore
.
get
(
storeKey
)
||
{}
const
prev
=
detailStore
.
get
(
storeKey
)
||
{}
const
nextRecord
=
{
const
nextRecord
=
{
...
@@ -178,8 +184,16 @@ function saveMockStoreDynamicDetail(params = {}) {
...
@@ -178,8 +184,16 @@ function saveMockStoreDynamicDetail(params = {}) {
dailyReportRecordId
:
dailyReportRecordId
||
prev
.
dailyReportRecordId
||
Date
.
now
(),
dailyReportRecordId
:
dailyReportRecordId
||
prev
.
dailyReportRecordId
||
Date
.
now
(),
baseSceneCode
:
prev
.
baseSceneCode
??
WARRANTY_PAGE_CONTEXT
.
baseSceneCode
,
baseSceneCode
:
prev
.
baseSceneCode
??
WARRANTY_PAGE_CONTEXT
.
baseSceneCode
,
reportStatus
:
reportStatus
!=
null
?
String
(
reportStatus
)
:
prev
.
reportStatus
??
'0'
,
reportStatus
:
reportStatus
!=
null
?
String
(
reportStatus
)
:
prev
.
reportStatus
??
'0'
,
fieldDataList
:
fieldDataList
??
prev
.
fieldDataList
??
[],
fieldDataList
:
subformDataList
:
subformDataList
??
prev
.
subformDataList
??
[],
fieldDataList
??
listsFromRequestJson
?.
fieldDataList
??
prev
.
fieldDataList
??
[],
subformDataList
:
subformDataList
??
listsFromRequestJson
?.
subformDataList
??
prev
.
subformDataList
??
[],
jsonContent
:
jsonContent
??
prev
.
jsonContent
??
''
jsonContent
:
jsonContent
??
prev
.
jsonContent
??
''
}
}
detailStore
.
set
(
storeKey
,
nextRecord
)
detailStore
.
set
(
storeKey
,
nextRecord
)
...
...
packageDynamicForm/api/storeDailyReport.js
View file @
02a10bd
...
@@ -51,6 +51,23 @@ const {
...
@@ -51,6 +51,23 @@ const {
const
IS_PRODUCTION
=
envIndex
===
3
const
IS_PRODUCTION
=
envIndex
===
3
/** 非生产环境:打印 save 请求体并校验 requestJson */
function
logStoreSaveRequestDebug
(
label
,
saveRequest
=
{})
{
if
(
IS_PRODUCTION
)
{
return
}
console
.
log
(
label
,
saveRequest
)
if
(
!
saveRequest
.
requestJson
)
{
console
.
error
(
'[storeDailyReport] missing requestJson in save request'
)
return
}
try
{
console
.
log
(
`
${
label
}
requestJson`
,
JSON
.
parse
(
saveRequest
.
requestJson
))
}
catch
(
parseError
)
{
console
.
warn
(
'[storeDailyReport] requestJson parse failed'
,
parseError
)
}
}
/**
/**
* 联调:有日报记录但 subform 行未解析时告警(detail.get jsonContent 应含 subform.children 行数据)
* 联调:有日报记录但 subform 行未解析时告警(detail.get jsonContent 应含 subform.children 行数据)
*/
*/
...
@@ -440,8 +457,8 @@ async function submitForm(payload = {}) {
...
@@ -440,8 +457,8 @@ async function submitForm(payload = {}) {
templateType
:
DAILY_REPORT_TEMPLATE_TYPE
.
store
,
templateType
:
DAILY_REPORT_TEMPLATE_TYPE
.
store
,
dailyReportSource
:
DAILY_REPORT_SOURCE
.
miniapp
dailyReportSource
:
DAILY_REPORT_SOURCE
.
miniapp
})
})
logStoreSaveRequestDebug
(
'[storeDailyReport] dynamic.save 提交数据结构'
,
saveRequest
)
if
(
!
IS_PRODUCTION
)
{
if
(
!
IS_PRODUCTION
)
{
console
.
log
(
'[storeDailyReport] dynamic.save 提交数据结构'
,
saveRequest
)
try
{
try
{
console
.
log
(
console
.
log
(
'[storeDailyReport] dynamic.save jsonContent'
,
'[storeDailyReport] dynamic.save jsonContent'
,
...
@@ -512,9 +529,7 @@ async function saveDraftForm(payload = {}) {
...
@@ -512,9 +529,7 @@ async function saveDraftForm(payload = {}) {
templateType
:
DAILY_REPORT_TEMPLATE_TYPE
.
store
,
templateType
:
DAILY_REPORT_TEMPLATE_TYPE
.
store
,
dailyReportSource
:
DAILY_REPORT_SOURCE
.
miniapp
dailyReportSource
:
DAILY_REPORT_SOURCE
.
miniapp
})
})
if
(
!
IS_PRODUCTION
)
{
logStoreSaveRequestDebug
(
'[storeDailyReport] dynamic.draft.save 草稿数据结构'
,
saveRequest
)
console
.
log
(
'[storeDailyReport] dynamic.draft.save 草稿数据结构'
,
saveRequest
)
}
const
result
=
await
saveDraftAdapter
(
saveRequest
)
const
result
=
await
saveDraftAdapter
(
saveRequest
)
const
{
code
,
message
,
data
}
=
unwrapResponse
(
result
)
const
{
code
,
message
,
data
}
=
unwrapResponse
(
result
)
if
(
code
==
0
)
{
if
(
code
==
0
)
{
...
...
packageDynamicForm/api/storeDailyReportAdapters.js
View file @
02a10bd
...
@@ -274,7 +274,7 @@ async function fetchMonthlyPendingCountAdapter(params = {}) {
...
@@ -274,7 +274,7 @@ async function fetchMonthlyPendingCountAdapter(params = {}) {
}
}
/**
/**
* 从 monthly.pending 接口 data 提取待邀约数(兼容
/ pendingC
ount / 标量)
* 从 monthly.pending 接口 data 提取待邀约数(兼容
pendingcount / pendingCount / pending_c
ount / 标量)
* @param {*} data
* @param {*} data
* @returns {number|undefined}
* @returns {number|undefined}
*/
*/
...
@@ -292,7 +292,8 @@ function extractPendingCountFromResponseData(data) {
...
@@ -292,7 +292,8 @@ function extractPendingCountFromResponseData(data) {
if
(
typeof
data
===
'object'
)
{
if
(
typeof
data
===
'object'
)
{
const
raw
=
const
raw
=
data
.
pendingCount
??
data
.
pendingCount
??
data
.
pending_count
data
.
pending_count
??
data
.
pendingcount
if
(
raw
==
null
||
raw
===
''
)
{
if
(
raw
==
null
||
raw
===
''
)
{
return
undefined
return
undefined
}
}
...
...
packageDynamicForm/components/form-field-input/form-field-input.wxml
View file @
02a10bd
...
@@ -5,15 +5,19 @@
...
@@ -5,15 +5,19 @@
</view>
</view>
<view class="form-info-row__input-wrap">
<view class="form-info-row__input-wrap">
<input
<input
wx:if="{{ !disabled }}"
value="{{ displayValue }}"
value="{{ displayValue }}"
class="form-info-row__input {{ error ? 'is-error' : '' }}"
class="form-info-row__input {{ error ? 'is-error' : '' }}"
placeholder="
{{ disabled ? '' : '请输入' }}
"
placeholder="
请输入
"
placeholder-class="form-info-row__placeholder"
placeholder-class="form-info-row__placeholder"
disabled="{{ disabled }}"
maxlength="{{ showOcr ? (field.rules.maxLength || 20) : (field.rules.maxLength || 140) }}"
maxlength="{{ showOcr ? (field.rules.maxLength || 20) : (field.rules.maxLength || 140) }}"
bindinput="onInput"
bindinput="onInput"
bindblur="onBlur"
bindblur="onBlur"
/>
/>
<text
wx:else
class="form-info-row__input form-info-row__input--readonly {{ error ? 'is-error' : '' }}"
>{{ displayValue }}</text>
<view wx:if="{{ showOcr }}" class="form-info-row__scan" bindtap="onOcr">
<view wx:if="{{ showOcr }}" class="form-info-row__scan" bindtap="onOcr">
<image
<image
wx:if="{{ scanIcon }}"
wx:if="{{ scanIcon }}"
...
...
packageDynamicForm/components/form-field-input/form-field-input.wxss
View file @
02a10bd
...
@@ -10,14 +10,21 @@
...
@@ -10,14 +10,21 @@
.form-info-row__input {
.form-info-row__input {
flex: 1;
flex: 1;
min-width:
120rpx
;
min-width:
0
;
height: 96rpx;
height: 96rpx;
text-align: right;
text-align: right;
font-size: 28rpx;
font-size: 28rpx;
line-height:
40
rpx;
line-height:
96
rpx;
color: #292d33;
color: #292d33;
}
}
.form-info-row__input--readonly {
display: block;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
.form-info-row.is-disabled .form-info-row__input {
.form-info-row.is-disabled .form-info-row__input {
color: #5a5e66;
color: #5a5e66;
}
}
...
...
packageDynamicForm/docs/ARCHITECTURE.md
View file @
02a10bd
...
@@ -135,8 +135,8 @@ sequenceDiagram
...
@@ -135,8 +135,8 @@ sequenceDiagram
**不变式(任一步破坏即可能出 bug)**
**不变式(任一步破坏即可能出 bug)**
1.
**加载**
:
`buildInitialValues`
→
`buildGroupRowsCache`
→
`
clearHiddenFieldValues`
(
`loadSchema`
/
`init`
内可能执行两次 clearHidden + rebuild cache
)。
1.
**加载**
:
`buildInitialValues`
→
`buildGroupRowsCache`
→
`
applyVisibilityClearing`
(
`clearHiddenFieldValues`
+
`clearHiddenSubformRowValues`
+ rebuild cache;
`loadSchema`
/
`init`
内可能执行两次
)。
2.
**子表单元格编辑**
:先写
`groupRowsCache`
(
`setRowFieldInCache`
/
`setNegotiationDualKeyFieldInCache`
)→
`syncValuesFromGroupCache`
→
`
clearHiddenFieldValues
`
→
`alignGroupRowsCacheAfterHiddenClear`
(隐藏 subform 时删 cache key)。
2.
**子表单元格编辑**
:先写
`groupRowsCache`
(
`setRowFieldInCache`
/
`setNegotiationDualKeyFieldInCache`
)→
`syncValuesFromGroupCache`
→
`
applyVisibilityClearing
`
→
`alignGroupRowsCacheAfterHiddenClear`
(隐藏 subform 时删 cache key)。
3.
**校验**
:
`validate()`
开头
`syncSubformValuesFromCache`
(cache → values)。
3.
**校验**
:
`validate()`
开头
`syncSubformValuesFromCache`
(cache → values)。
4.
**保存**
:
`collectSaveValues`
/
`collectSubformStorageValues`
对 subform
**以 cache 为准**
覆盖
`values[groupKey]`
。
4.
**保存**
:
`collectSaveValues`
/
`collectSubformStorageValues`
对 subform
**以 cache 为准**
覆盖
`values[groupKey]`
。
5.
**对外写入**
:Page 只调
`engine.setGroupFieldValue`
/
`setAppGroupFieldValue`
/
`mutateSubform`
;勿直接改
`getViewState().groupRowsCache`
再写回。
5.
**对外写入**
:Page 只调
`engine.setGroupFieldValue`
/
`setAppGroupFieldValue`
/
`mutateSubform`
;勿直接改
`getViewState().groupRowsCache`
再写回。
...
...
packageDynamicForm/docs/PAGES.md
View file @
02a10bd
...
@@ -54,7 +54,7 @@
...
@@ -54,7 +54,7 @@
与洽谈、门店共用
[
`visibility.js`
](
../form-engine/visibility.js
)
:
`filterBrandId`
表示已有专属品牌区块;门店
`brandIds`
**至少有一个不在该列表**
时展示「其他品牌」类字段/分组(如
**F1-11**
)。
`fetchPageContext`
从
`detail.jsonContent`
写入
`echoSubformKeys`
(含
`group`
),详情回显时不受
`filterBrandId`
等限制。
与洽谈、门店共用
[
`visibility.js`
](
../form-engine/visibility.js
)
:
`filterBrandId`
表示已有专属品牌区块;门店
`brandIds`
**至少有一个不在该列表**
时展示「其他品牌」类字段/分组(如
**F1-11**
)。
`fetchPageContext`
从
`detail.jsonContent`
写入
`echoSubformKeys`
(含
`group`
),详情回显时不受
`filterBrandId`
等限制。
**调休**
:
`F1-1`
选「调休」时仅出勤字段可见;等价于模版
`rules.result: val1 == "在岗"`
,由
`isAttendanceOnDuty`
统一处理,不 eval 字段级表达式
。见
[
staff-template-features.md
](
./staff-template-features.md
)
。
**调休**
:
带
`rules.result: val1 == "在岗"`
的字段/group 隐藏;无
`rules.result`
的字段(如 F1-4 备注)仍可见
。见
[
staff-template-features.md
](
./staff-template-features.md
)
。
### 相关单测
### 相关单测
...
...
packageDynamicForm/docs/daily-report-save-and-json.md
View file @
02a10bd
...
@@ -33,7 +33,7 @@ sequenceDiagram
...
@@ -33,7 +33,7 @@ sequenceDiagram
| 3 | 同一 list →
**childrenValue**
入库 jsonContent |
`serializeFormListForAppJsonStorage(list)`
|
| 3 | 同一 list →
**childrenValue**
入库 jsonContent |
`serializeFormListForAppJsonStorage(list)`
|
| 4 | 请求体 |
[
`buildDailyReportSaveRequest`
](
../form-engine/save-request.js
)
|
| 4 | 请求体 |
[
`buildDailyReportSaveRequest`
](
../form-engine/save-request.js
)
|
**HTTP 传输**
:
空
`fieldDataList`
序列化为
`'[]'`
;空
`subformDataList`
**不传**
;返回值中的 lists 仍为数组,供 mock 回显。非空 lists 仍走 qs 索引格式
。
**HTTP 传输**
:
`fieldDataList`
/
`subformDataList`
不再作为顶层字段;由
[
`save-request.js`
](
../form-engine/save-request.js
)
组装
**`requestJson`**
(
`JSON.stringify({ fieldDataList, subformDataList? })`
,与
`jsonContent`
同级字符串)。空
`subformDataList`
在
`requestJson`
对象内
**不传**
;
`buildDailyReportSaveRequest`
返回值中的 lists 仍为数组,供 mock 回显
。
**统一提交入口**
:
[
`buildAppDailyReportSubmitPayload`
](
../form-engine/app-subform-json.js
)
**统一提交入口**
:
[
`buildAppDailyReportSubmitPayload`
](
../form-engine/app-subform-json.js
)
...
@@ -50,7 +50,7 @@ App 草稿 `saveReport` 仅做 childrenValue 序列化、**不产** fieldDataLis
...
@@ -50,7 +50,7 @@ App 草稿 `saveReport` 仅做 childrenValue 序列化、**不产** fieldDataLis
### 2.1 顶层字段
### 2.1 顶层字段
-
普通字段:
`type`
非
`subform`
,保留
**`value`**
(
`select`
/ 远程 select 可有双 key
`field[field.key]`
)。
-
普通字段:
`type`
非
`subform`
,保留
**`value`**
(
`select`
/ 远程 select 可有双 key
`field[field.key]`
)。
远程
**单选**
入库 jsonContent:
`value`
为回显名,
`field[field.key]`
为
**id 字符串**
(非
`{ id, name }`
对象)。
-
远程
**`multipleSelect`**
(
`optionsKey`
为
`storeStaffList`
等,见
`REMOTE_SELECT_OPTIONS_KEYS`
):双 key 与 App 一致——
**`value`**
为选中项名称
`/`
拼接展示串,
**`field[field.key]`**
为 id 字符串数组(如 F2-1 今日驻店人员);引擎回显优先读
`field[field.key]`
。
`fieldDataList`
仍为
`[{ id, name, ... }, ...]`
JSON,与 jsonContent 形态独立。
-
远程
**`multipleSelect`**
(
`optionsKey`
为
`storeStaffList`
等,见
`REMOTE_SELECT_OPTIONS_KEYS`
):双 key 与 App 一致——
**`value`**
为选中项名称
`/`
拼接展示串,
**`field[field.key]`**
为 id 字符串数组(如 F2-1 今日驻店人员);引擎回显优先读
`field[field.key]`
。
`fieldDataList`
仍为
`[{ id, name, ... }, ...]`
JSON,与 jsonContent 形态独立。
-
静态
`type: 'group'`
:保留
**`children`**
(扁平子字段列表 + 各字段
`value`
),
**不**
转为
`childrenValue`
。
-
静态
`type: 'group'`
:保留
**`children`**
(扁平子字段列表 + 各字段
`value`
),
**不**
转为
`childrenValue`
。
...
@@ -65,7 +65,7 @@ App 草稿 `saveReport` 仅做 childrenValue 序列化、**不产** fieldDataLis
...
@@ -65,7 +65,7 @@ App 草稿 `saveReport` 仅做 childrenValue 序列化、**不产** fieldDataLis
childrenValue
:
[
childrenValue
:
[
{
{
'F2-9'
:
{
'F2-9'
:
{
'F2-9-1'
:
{
text
:
'张三'
,
value
:
{
id
:
'...'
,
name
:
'张三'
,
phone
:
'...'
}
},
'F2-9-1'
:
{
text
:
'张三'
,
value
:
'uuid-staff-id'
},
'F2-9-2'
:
5
'F2-9-2'
:
5
}
}
}
}
...
@@ -74,18 +74,16 @@ App 草稿 `saveReport` 仅做 childrenValue 序列化、**不产** fieldDataLis
...
@@ -74,18 +74,16 @@ App 草稿 `saveReport` 仅做 childrenValue 序列化、**不产** fieldDataLis
}
}
```
```
-
远程
`select`
(
`4sStaffList`
/
`storeStaffList`
/
`orderList`
):
有双 key 时存
`{ text, value }`
,
`text`
为展示名,
`value`
为 meta 对象
。
-
远程
`select`
(
`4sStaffList`
/
`storeStaffList`
/
`orderList`
):
`childrenValue`
行内存
`{ text, value }`
——
`text`
为回显名,
`value`
为 id 字符串;完整 option 对象仅出现在
`fieldDataList`
/
`subformDataList`
。
-
仅当
**`type === 'subform'`**
时删除
`children`
与
`value`
(对齐 mixins
`if (e.type == 'subform') delete e.children`
)。
-
仅当
**`type === 'subform'`**
时删除
`children`
与
`value`
(对齐 mixins
`if (e.type == 'subform') delete e.children`
)。
### 2.3 运行时(提交前,仅引擎/ lists 用)
### 2.3 运行时(提交前,仅引擎/ lists 用)
-
subform 在引擎 cache 与
`assembleFormListForSaveLists`
中为
**
`children`
: FormField
[
][
]
`。
-
subform 在引擎 cache 与
`assembleFormListForSaveLists`
中为
**
`children`
: FormField
[
][
]
`。
- `
fieldDataList
` / `
subformDataList
` **必须**在此形态下生成,再对同一 list 做 `
childrenValue
` 序列化。
- `
fieldDataList
` / `
subformDataList
` **必须**在此形态下生成,再对同一 list 做 `
childrenValue
` 序列化。
- `
fieldDataList
`:顶层字段(含 group 子字段、固定字段);当 `
FIELD_DATA_LIST_INCLUDE_SUBFORM_ROWS === true
`([`
app-subform-json.js
`](../form-engine/app-subform-json.js) 默认)时,**同时双写** subform 行字段(含 `
groupKey
` / `
rowIndex
`)。
- `
fieldDataList
`:顶层字段(含 group 子字段、固定字段);**不含** subform 占位(`
fieldType: 'subform'
`)与 subform 行级双写(`
groupKey
`/`
rowIndex
`)。开关 `
FIELD_DATA_LIST_INCLUDE_SUBFORM_ROWS
` / `
FIELD_DATA_LIST_INCLUDE_SUBFORM_SECTIONS
`([`
app-subform-json.js
`](../form-engine/app-subform-json.js) 默认均为 `
false
`);设为 `
true
` 可恢复历史双写/占位行为。
- 当 `
FIELD_DATA_LIST_INCLUDE_SUBFORM_SECTIONS === true
`(默认)且某 subform **无行数据**时,为每个可见 subform 区块写入一条占位:`
fieldKey
` = 区块 key、`
fieldType
` = `
subform
`、`
fieldValue
` = `
'
[
]'
`(与空 `
childrenValue
` 对齐);已有行级条目(`
groupKey
` 命中)时不再写占位。
- `
subformDataList
`:subform 行字段(`
parentFieldKey
` / `
rowIndex
` / `
columnFieldKey
`),不出现顶层字段。
- `
subformDataList
`:subform 行字段(`
parentFieldKey
` / `
rowIndex
` / `
columnFieldKey
`),不出现顶层字段。
- 开关为 `
false
` 时两项 list 互斥(subform 行仅出现在 `
subformDataList
`);为 `
true
` 时 subform 行在两份 list 中双写。
- HTTP 传输:lists 写入 **`
requestJson
` 字符串**(见 §1);**空 `
subformDataList
` 在 requestJson 对象内不传**。
- HTTP 传输:空 `
fieldDataList
` 由 [`
save-request.js
`](../form-engine/save-request.js) 序列化为 `
'
[
]'
`;**空 `
subformDataList
` 不传**(请求体不含该键)。
---
---
...
@@ -122,7 +120,7 @@ App 回显模板:`childrenValue` + `origin_children` → 重建 `children`(
...
@@ -122,7 +120,7 @@ App 回显模板:`childrenValue` + `origin_children` → 重建 `children`(
|
`serializeFormListForAppJsonStorage`
| formList → 入库 jsonContent |
|
`serializeFormListForAppJsonStorage`
| formList → 入库 jsonContent |
|
`buildAppJsonContent`
| cache → subform section(children) |
|
`buildAppJsonContent`
| cache → subform section(children) |
|
`formatFieldForAppJsonContent`
| 单行 FormField App 双 key |
|
`formatFieldForAppJsonContent`
| 单行 FormField App 双 key |
|
`buildAppNormalizedListsFromJsonContent`
| jsonContent 或 formList → lists(默认 fieldDataList
双写 subform 行,见
`FIELD_DATA_LIST_INCLUDE_SUBFORM_ROWS`
) |
|
`buildAppNormalizedListsFromJsonContent`
| jsonContent 或 formList → lists(默认 fieldDataList
不含 subform,见 §2.3 开关
) |
|
`getSectionRowFieldsList`
| section → FormField
[
][
]
(回显) |
|
`getSectionRowFieldsList`
| section → FormField
[
][
]
(回显) |
|
`childrenValueToRowFieldsList`
/
`childrenToChildrenValue`
| 编解码 |
|
`childrenValueToRowFieldsList`
/
`childrenToChildrenValue`
| 编解码 |
|
`mergeAppJsonIntoSchema`
| 详情 jsonContent → schema |
|
`mergeAppJsonIntoSchema`
| 详情 jsonContent → schema |
...
...
packageDynamicForm/docs/field-options-api.md
View file @
02a10bd
...
@@ -56,7 +56,7 @@ const subformDataList = buildAppSubformDataListFromJsonContent(jsonContent)
...
@@ -56,7 +56,7 @@ const subformDataList = buildAppSubformDataListFromJsonContent(jsonContent)
`jsonContent`
支持
`string`
/
`array`
/
`{ list: [] }`
三种包装。
`jsonContent`
支持
`string`
/
`array`
/
`{ list: [] }`
三种包装。
**注意**
:远程 select 双 key 约定
:
`value`
为展示名,
`field[key]`
为完整 option 对象
`{ id, name, phone, ... }`
(小程序 save 经
`formatFieldForAppJsonContent`
写入
)。历史 App 数据若
`field[key]`
仅为 id 标量,lists 仍可解析为
`{ id, name: 展示名 }`
。
**注意**
:远程 select 双 key 约定
(入库
**jsonContent**
):
`value`
/
`text`
为回显名,
`field[field.key]`
/
`childrenValue.value`
为
**id 字符串**
。运行时 formList /
`fieldDataList`
/
`subformDataList`
仍可用完整 option 对象
`{ id, name, phone, ... }`
(
`formatFieldForAppJsonContent`
默认保留 meta;
`serializeFormListForAppJsonStorage`
瘦身 id
)。历史 App 数据若
`field[key]`
仅为 id 标量,lists 仍可解析为
`{ id, name: 展示名 }`
。
**小程序提交**
:驻店/门店/洽谈 save 的
`fieldDataList`
/
`subformDataList`
与 App 共用
[
`buildAppNormalizedListsFromJsonContent`
](
../form-engine/app-subform-json.js
)
。门店/洽谈
`jsonContent`
与 lists 同源(
[
`assembleFormListForSaveLists`
](
../form-engine/submit-adapter.js
)
→ 顶层字段带
`value`
+ subform
`children`
双 key)。
**小程序提交**
:驻店/门店/洽谈 save 的
`fieldDataList`
/
`subformDataList`
与 App 共用
[
`buildAppNormalizedListsFromJsonContent`
](
../form-engine/app-subform-json.js
)
。门店/洽谈
`jsonContent`
与 lists 同源(
[
`assembleFormListForSaveLists`
](
../form-engine/submit-adapter.js
)
→ 顶层字段带
`value`
+ subform
`children`
双 key)。
...
...
packageDynamicForm/docs/group-repeater.md
View file @
02a10bd
...
@@ -86,6 +86,7 @@ values['F2-9'] = [
...
@@ -86,6 +86,7 @@ values['F2-9'] = [
-
Schema:
`{ keys: ['F3-1-10', ...], result: "val1 == '是' && val2 != null" }`
,
`valN`
与
`keys`
下标一一对应。
-
Schema:
`{ keys: ['F3-1-10', ...], result: "val1 == '是' && val2 != null" }`
,
`valN`
与
`keys`
下标一一对应。
-
由
[
`group-show-rule-eval.js`
](
../form-engine/group-show-rule-eval.js
)
内置 fallback 解析(
`valN == '…'`
、
`valN != null`
,
`&&`
连接);小程序与 Node 单测路径一致。
-
由
[
`group-show-rule-eval.js`
](
../form-engine/group-show-rule-eval.js
)
内置 fallback 解析(
`valN == '…'`
、
`valN != null`
,
`&&`
连接);小程序与 Node 单测路径一致。
-
求值失败时
**隐藏**
该子字段(
`return false`
)。
-
求值失败时
**隐藏**
该子字段(
`return false`
)。
-
**联动切换清值**
:
`childrenShowRules`
导致某 cell 不可见时,
[
`clearHiddenSubformRowValues`
](
../form-engine/values.js
)
在
`refreshValues`
/
`applyVisibilityClearing`
中删除
`values[groupKey][row]`
对应 key 并
`rebuildGroupRowsCache`
;保存时
[
`buildAppJsonContent`
](
../form-engine/app-subform-json.js
)
对每行再
`filterVisibleRowFields`
防御历史脏 cache。
## 多行输入隔离(避免多框联动)
## 多行输入隔离(避免多框联动)
...
...
packageDynamicForm/docs/staff-template-features.md
View file @
02a10bd
...
@@ -36,7 +36,7 @@
...
@@ -36,7 +36,7 @@
|------|-----|------|
|------|-----|------|
| 出勤 | F1-1 | radio:在岗 / 调休;默认在岗 |
| 出勤 | F1-1 | radio:在岗 / 调休;默认在岗 |
| 延保退单 | F1-2、F1-3 | 仅延保场景 + 在岗时可见(见下) |
| 延保退单 | F1-2、F1-3 | 仅延保场景 + 在岗时可见(见下) |
| 备注 | F1-4 | 始终可见(
在岗时
) |
| 备注 | F1-4 | 始终可见(
含调休
) |
| 品牌 group | F1-5~F1-10 | 各
`brandId`
一块,子字段按轻改/延保
`sceneType`
+
`baseSceneCode`
|
| 品牌 group | F1-5~F1-10 | 各
`brandId`
一块,子字段按轻改/延保
`sceneType`
+
`baseSceneCode`
|
| 岚图 group | F1-10 | 5 个子字段(无「交付引荐」) |
| 岚图 group | F1-10 | 5 个子字段(无「交付引荐」) |
| 其他品牌 | F1-11 |
`filterBrandId`
;8 个子字段(含权益未触客 F1-11-8) |
| 其他品牌 | F1-11 |
`filterBrandId`
;8 个子字段(含权益未触客 F1-11-8) |
...
@@ -47,14 +47,15 @@
...
@@ -47,14 +47,15 @@
| Schema 能力 | 实现 | 说明 |
| Schema 能力 | 实现 | 说明 |
|-------------|------|------|
|-------------|------|------|
| F1-1 出勤 radio |
[
`visibility.js`
](
../form-engine/visibility.js
)
+
[
`radio-value.js`
](
../form-engine/radio-value.js
)
|
**调休**
时除 F1-1 外全部隐藏(
`attendanceOnDuty`
gate);不逐字段 eval
`rules.result`
|
| F1-1 出勤 radio |
[
`radio-value.js`
](
../form-engine/radio-value.js
)
| 无
`rules.result`
,始终可见 |
| F1-2/F1-3
`rules.keys`
+
`result: val1 == "在岗"`` | 同上 gate | 与 group `
rules.keys:
[
'F1-1'
]
` 等价;**不执行** rules 内表达式 |
| F1-2/F1-3、group
`rules.keys`
+
`result: val1 == "在岗"`
|
[
`field-show-rule.js`
](
../form-engine/visibility/specs/field-show-rule.js
)
| eval
`rules.result`
;调休时隐藏 |
| F1-4 备注 | 无
`rules.result`
| 调休时仍可见 |
| group
`rules`
/
`childrenRules`
|
`schema-normalizer`
→
`normalizeStaticGroupChildren`
|
`childrenRules`
合并进子字段
`rules`
(min/integer 等) |
| group
`rules`
/
`childrenRules`
|
`schema-normalizer`
→
`normalizeStaticGroupChildren`
|
`childrenRules`
合并进子字段
`rules`
(min/integer 等) |
| 子字段
`sceneType`
/
`baseSceneCode`
|
`isFieldVisible`
→
`matchesBaseSceneCode`
| 轻改码 vs 延保码分行展示 |
| 子字段
`sceneType`
/
`baseSceneCode`
|
`isFieldVisible`
→
`matchesBaseSceneCode`
| 轻改码 vs 延保码分行展示 |
| group
`brandId`
|
`hasIntersection(brandId, ctx.brandIds)`
| 无该品牌则不展示整块 group |
| group
`brandId`
|
`hasIntersection(brandId, ctx.brandIds)`
| 无该品牌则不展示整块 group |
| F1-11
`filterBrandId`
|
`shouldHideByFilterBrandId`
| 经营品牌全部在列表内时隐藏「其他品牌」 |
| F1-11
`filterBrandId`
|
`shouldHideByFilterBrandId`
| 经营品牌全部在列表内时隐藏「其他品牌」 |
| 详情回显 |
`hasDetailEcho`
+
`echoSubformKeys`
(含 group) | 回显白名单内跳过 brand/filter 限制 |
| 详情回显 |
`hasDetailEcho`
+
`echoSubformKeys`
(含 group) | 回显白名单内跳过 brand/filter 限制 |
| 保存 | `
buildDynamicSavePayload
` / App jsonContent | 顶层 value;无 subform;
**调休**时 jsonContent 仍写入在岗可见字段骨架(默认 value),`
F1-1
` 为调休;`
fieldDataList
` 仅 F1-1
|
| 保存 |
`buildDynamicSavePayload`
/ App jsonContent | 顶层 value;无 subform;
`jsonContent`
与
`fieldDataList`
均仅当前可见字段(调休时含 F1-1、F1-4 等无 result 字段)
|
---
---
...
@@ -63,7 +64,7 @@
...
@@ -63,7 +64,7 @@
| 模版字段 | 小程序行为 |
| 模版字段 | 小程序行为 |
|----------|------------|
|----------|------------|
| F1-1
`value: '在岗'`
、options 中文 value | 兼容配置中心中文值;历史 fixture 用
`'1'/'2'`
,
`resolveRadioOptionValue`
双向归一 |
| F1-1
`value: '在岗'`
、options 中文 value | 兼容配置中心中文值;历史 fixture 用
`'1'/'2'`
,
`resolveRadioOptionValue`
双向归一 |
| 字段/ group `
rules.result
` 字符串 |
**不 eval**;在岗显隐由 `
isAttendanceOnDuty
` 统一处理
|
| 字段/ group
`rules.result`
字符串 |
由
`fieldShowRuleSpec`
eval(支持
`val1 == "在岗"`
双引号);无 keys/result 的字段不受出勤联动
|
| 子字段
`value: 0`
| 详见
[
MAINTENANCE.md § Schema fixture 维护
](
./MAINTENANCE.md#schema-fixture-维护mock
)
|
| 子字段
`value: 0`
| 详见
[
MAINTENANCE.md § Schema fixture 维护
](
./MAINTENANCE.md#schema-fixture-维护mock
)
|
---
---
...
...
packageDynamicForm/fixtures/schema-staff-daily-full.js
View file @
02a10bd
...
@@ -283,7 +283,12 @@ module.exports = {
...
@@ -283,7 +283,12 @@ module.exports = {
110201
,
110201
,
110202
110202
],
],
"rules"
:
{},
"rules"
:
{
"keys"
:
[
"F1-1"
],
"result"
:
"val1 == \"在岗\""
},
"children"
:
[
"children"
:
[
{
{
"label"
:
"轻改个人大定触客/进群数"
,
"label"
:
"轻改个人大定触客/进群数"
,
...
@@ -430,7 +435,12 @@ module.exports = {
...
@@ -430,7 +435,12 @@ module.exports = {
110201
,
110201
,
110202
110202
],
],
"rules"
:
{},
"rules"
:
{
"keys"
:
[
"F1-1"
],
"result"
:
"val1 == \"在岗\""
},
"children"
:
[
"children"
:
[
{
{
"label"
:
"轻改个人大定触客/进群数"
,
"label"
:
"轻改个人大定触客/进群数"
,
...
@@ -577,7 +587,12 @@ module.exports = {
...
@@ -577,7 +587,12 @@ module.exports = {
110201
,
110201
,
110202
110202
],
],
"rules"
:
{},
"rules"
:
{
"keys"
:
[
"F1-1"
],
"result"
:
"val1 == \"在岗\""
},
"children"
:
[
"children"
:
[
{
{
"label"
:
"轻改个人大定触客/进群数"
,
"label"
:
"轻改个人大定触客/进群数"
,
...
@@ -724,7 +739,12 @@ module.exports = {
...
@@ -724,7 +739,12 @@ module.exports = {
110201
,
110201
,
110202
110202
],
],
"rules"
:
{},
"rules"
:
{
"keys"
:
[
"F1-1"
],
"result"
:
"val1 == \"在岗\""
},
"children"
:
[
"children"
:
[
{
{
"label"
:
"轻改个人大定触客/进群数"
,
"label"
:
"轻改个人大定触客/进群数"
,
...
@@ -871,7 +891,12 @@ module.exports = {
...
@@ -871,7 +891,12 @@ module.exports = {
110201
,
110201
,
110202
110202
],
],
"rules"
:
{},
"rules"
:
{
"keys"
:
[
"F1-1"
],
"result"
:
"val1 == \"在岗\""
},
"children"
:
[
"children"
:
[
{
{
"label"
:
"轻改实际售前触客数"
,
"label"
:
"轻改实际售前触客数"
,
...
...
packageDynamicForm/form-engine/app-subform-json.js
View file @
02a10bd
...
@@ -6,9 +6,9 @@
...
@@ -6,9 +6,9 @@
*/
*/
/** true:fieldDataList 双写 subform 行(groupKey/rowIndex);false:仅 subformDataList */
/** true:fieldDataList 双写 subform 行(groupKey/rowIndex);false:仅 subformDataList */
const
FIELD_DATA_LIST_INCLUDE_SUBFORM_ROWS
=
tru
e
const
FIELD_DATA_LIST_INCLUDE_SUBFORM_ROWS
=
fals
e
/** true:无行数据时为每个可见 subform 区块写入 fieldType=subform 占位;false:仅写有值行 */
/** true:无行数据时为每个可见 subform 区块写入 fieldType=subform 占位;false:仅写有值行 */
const
FIELD_DATA_LIST_INCLUDE_SUBFORM_SECTIONS
=
tru
e
const
FIELD_DATA_LIST_INCLUDE_SUBFORM_SECTIONS
=
fals
e
// --- 内联工具(与 field-submit-value / group-row-adapter 等保持同步) ---
// --- 内联工具(与 field-submit-value / group-row-adapter 等保持同步) ---
...
@@ -371,6 +371,39 @@ function isRemoteMultipleSelectField(field = {}) {
...
@@ -371,6 +371,39 @@ function isRemoteMultipleSelectField(field = {}) {
)
)
}
}
function
isRemoteSelectField
(
field
=
{})
{
return
(
field
.
type
===
'select'
&&
field
.
optionsKey
&&
REMOTE_SELECT_OPTIONS_KEYS
.
has
(
field
.
optionsKey
)
)
}
/** jsonContent childrenValue:text=回显名,value=id 字符串 */
function
resolveRemoteSelectTextAndId
(
field
=
{})
{
const
fk
=
field
.
key
const
meta
=
fk
!=
null
?
field
[
fk
]
:
undefined
const
fallbackLabel
=
typeof
field
.
value
===
'string'
&&
field
.
value
!==
''
?
field
.
value
:
''
const
{
id
,
label
}
=
extractSelectIdAndLabel
(
meta
??
field
.
value
,
fallbackLabel
)
if
(
id
==
null
||
id
===
''
)
{
return
null
}
let
text
=
''
if
(
typeof
field
.
value
===
'string'
&&
field
.
value
!==
''
&&
String
(
field
.
value
)
!==
String
(
id
)
)
{
text
=
field
.
value
}
else
if
(
label
)
{
text
=
label
}
else
if
(
typeof
field
.
value
===
'string'
)
{
text
=
field
.
value
}
return
{
text
,
value
:
String
(
id
)
}
}
/** 从引擎值提取 multipleSelect 双 key:id 数组 + / 拼接展示名 */
/** 从引擎值提取 multipleSelect 双 key:id 数组 + / 拼接展示名 */
function
extractMultipleSelectIdsAndLabels
(
raw
,
field
=
{})
{
function
extractMultipleSelectIdsAndLabels
(
raw
,
field
=
{})
{
const
coerced
=
coerceMultipleSelectValue
(
raw
)
const
coerced
=
coerceMultipleSelectValue
(
raw
)
...
@@ -936,6 +969,13 @@ export function rowFieldsToChildrenValueRow(groupKey, rowFields = []) {
...
@@ -936,6 +969,13 @@ export function rowFieldsToChildrenValueRow(groupKey, rowFields = []) {
return
return
}
}
const
fk
=
field
.
key
const
fk
=
field
.
key
if
(
isRemoteSelectField
(
field
))
{
const
pair
=
resolveRemoteSelectTextAndId
(
field
)
if
(
pair
)
{
rowBag
[
groupKey
][
fk
]
=
pair
}
return
}
const
text
=
field
.
value
??
''
const
text
=
field
.
value
??
''
const
meta
=
field
[
fk
]
const
meta
=
field
[
fk
]
if
(
meta
!=
null
&&
meta
!==
''
)
{
if
(
meta
!=
null
&&
meta
!==
''
)
{
...
@@ -983,7 +1023,11 @@ export function childrenValueToRowFieldsList(section = {}) {
...
@@ -983,7 +1023,11 @@ export function childrenValueToRowFieldsList(section = {}) {
item
.
value
=
val
item
.
value
=
val
}
else
if
(
typeof
val
===
'object'
)
{
}
else
if
(
typeof
val
===
'object'
)
{
item
.
value
=
val
.
text
item
.
value
=
val
.
text
item
[
fk
]
=
val
.
value
if
(
val
.
value
!=
null
&&
val
.
value
!==
''
)
{
item
[
fk
]
=
isPlainObject
(
val
.
value
)
?
extractSelectIdAndLabel
(
val
.
value
,
val
.
text
).
id
??
val
.
value
:
val
.
value
}
}
else
{
}
else
{
item
.
value
=
val
item
.
value
=
val
}
}
...
@@ -1042,11 +1086,20 @@ export function serializeSubformSectionForJsonContent(section = {}) {
...
@@ -1042,11 +1086,20 @@ export function serializeSubformSectionForJsonContent(section = {}) {
/** formList 保存入库:subform 节点序列化为 childrenValue 形态 */
/** formList 保存入库:subform 节点序列化为 childrenValue 形态 */
export
function
serializeFormListForAppJsonStorage
(
formList
=
[])
{
export
function
serializeFormListForAppJsonStorage
(
formList
=
[])
{
const
jsonStorage
=
{
jsonStorage
:
true
}
return
(
formList
||
[]).
map
(
field
=>
{
return
(
formList
||
[]).
map
(
field
=>
{
if
(
field
.
type
===
'subform'
)
{
if
(
field
.
type
===
'subform'
)
{
return
serializeSubformSectionForJsonContent
(
field
)
return
serializeSubformSectionForJsonContent
(
field
)
}
}
return
formatFieldForAppJsonContent
(
field
)
if
(
field
.
type
===
'group'
)
{
const
next
=
formatFieldForAppJsonContent
(
field
,
jsonStorage
)
const
children
=
getStaticGroupChildren
(
next
)
if
(
children
.
length
)
{
next
.
children
=
children
.
map
(
child
=>
formatFieldForAppJsonContent
(
child
,
jsonStorage
))
}
return
next
}
return
formatFieldForAppJsonContent
(
field
,
jsonStorage
)
})
})
}
}
...
@@ -1067,10 +1120,11 @@ export function isValueMapList(list = []) {
...
@@ -1067,10 +1120,11 @@ export function isValueMapList(list = []) {
return
first
&&
typeof
first
===
'object'
&&
!
Array
.
isArray
(
first
)
&&
first
.
key
==
null
return
first
&&
typeof
first
===
'object'
&&
!
Array
.
isArray
(
first
)
&&
first
.
key
==
null
}
}
/** 保存前:FormField 按 App 双 key 格式化 */
/** 保存前:FormField 按 App 双 key 格式化
;jsonStorage 时 field[key] 仅存 id 字符串(入库 jsonContent)
*/
export
function
formatFieldForAppJsonContent
(
field
=
{})
{
export
function
formatFieldForAppJsonContent
(
field
=
{}
,
options
=
{}
)
{
const
next
=
cloneJson
(
field
)
const
next
=
cloneJson
(
field
)
const
key
=
next
.
key
const
key
=
next
.
key
const
jsonStorage
=
options
.
jsonStorage
===
true
if
(
next
.
type
===
'carBrandSelect'
)
{
if
(
next
.
type
===
'carBrandSelect'
)
{
const
raw
=
next
[
key
]
??
next
.
value
const
raw
=
next
[
key
]
??
next
.
value
...
@@ -1113,7 +1167,7 @@ export function formatFieldForAppJsonContent(field = {}) {
...
@@ -1113,7 +1167,7 @@ export function formatFieldForAppJsonContent(field = {}) {
)
{
)
{
metaObject
.
name
=
next
.
value
metaObject
.
name
=
next
.
value
}
}
next
[
key
]
=
metaObject
next
[
key
]
=
jsonStorage
?
String
(
id
)
:
metaObject
if
(
label
)
{
if
(
label
)
{
next
.
value
=
label
next
.
value
=
label
}
else
if
(
next
.
value
==
null
||
next
.
value
===
''
||
isPlainObject
(
next
.
value
))
{
}
else
if
(
next
.
value
==
null
||
next
.
value
===
''
||
isPlainObject
(
next
.
value
))
{
...
@@ -1193,6 +1247,83 @@ export function mergeAppJsonIntoSchema(schemaRoot = {}, detail = {}) {
...
@@ -1193,6 +1247,83 @@ export function mergeAppJsonIntoSchema(schemaRoot = {}, detail = {}) {
return
nextSchema
return
nextSchema
}
}
function
evalShowRulePart
(
part
=
''
,
ctx
=
{})
{
const
trimmed
=
part
.
trim
()
const
eqMatch
=
trimmed
.
match
(
/^val
(\d
+
)\s
*==
\s
*
(?:
'
([^
'
]
*
)
'|"
([^
"
]
*
)
"
)
$/
)
if
(
eqMatch
)
{
const
actual
=
ctx
[
`val
${
eqMatch
[
1
]}
`
]
const
expected
=
eqMatch
[
2
]
!=
null
?
eqMatch
[
2
]
:
eqMatch
[
3
]
return
actual
==
expected
}
const
neNullMatch
=
trimmed
.
match
(
/^val
(\d
+
)\s
*!=
\s
*null$/
)
if
(
neNullMatch
)
{
const
actual
=
ctx
[
`val
${
neNullMatch
[
1
]}
`
]
return
actual
!=
null
&&
actual
!==
''
}
return
false
}
function
evaluateShowRuleForJson
(
keys
=
[],
resultExpr
=
''
,
rowFields
=
[],
getRowFieldValue
)
{
if
(
!
keys
.
length
||
!
resultExpr
)
{
return
true
}
try
{
const
ctx
=
{}
keys
.
forEach
((
key
,
index
)
=>
{
ctx
[
`val
${
index
+
1
}
`
]
=
getRowFieldValue
(
rowFields
,
key
)
})
return
resultExpr
.
split
(
'&&'
).
every
(
part
=>
evalShowRulePart
(
part
,
ctx
))
}
catch
(
error
)
{
return
false
}
}
function
getRowFieldValueForShowRule
(
rowFields
=
[],
key
=
''
,
rowMap
=
null
)
{
const
field
=
(
rowFields
||
[]).
find
(
item
=>
item
.
key
===
key
)
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
isGroupChildVisibleInRowForJson
(
group
=
{},
child
=
{},
rowFields
=
[],
rowMap
=
null
)
{
const
rules
=
group
.
childrenShowRules
if
(
!
rules
||
!
child
?.
key
)
{
return
true
}
const
rule
=
rules
[
child
.
key
]
if
(
!
rule
)
{
return
true
}
const
keys
=
rule
.
keys
||
[]
const
resultExpr
=
rule
.
result
if
(
!
keys
.
length
||
!
resultExpr
)
{
return
true
}
return
evaluateShowRuleForJson
(
keys
,
resultExpr
,
rowFields
,
(
rf
,
k
)
=>
getRowFieldValueForShowRule
(
rf
,
k
,
rowMap
)
)
}
function
filterVisibleRowFieldsForJson
(
group
=
{},
rowFields
=
[],
rowMap
=
null
)
{
return
(
rowFields
||
[]).
filter
(
field
=>
isGroupChildVisibleInRowForJson
(
group
,
field
,
rowFields
,
rowMap
)
)
}
/** 从 engine 组装 App 形态 jsonContent(subform.children) */
/** 从 engine 组装 App 形态 jsonContent(subform.children) */
export
function
buildAppJsonContent
(
visibleList
=
[],
groupRowsCache
=
{})
{
export
function
buildAppJsonContent
(
visibleList
=
[],
groupRowsCache
=
{})
{
const
sections
=
[]
const
sections
=
[]
...
@@ -1206,9 +1337,11 @@ export function buildAppJsonContent(visibleList = [], groupRowsCache = {}) {
...
@@ -1206,9 +1337,11 @@ export function buildAppJsonContent(visibleList = [], groupRowsCache = {}) {
const
section
=
cloneJson
(
field
)
const
section
=
cloneJson
(
field
)
delete
section
.
value
delete
section
.
value
const
children
=
cloneRowFieldsList
(
rowFieldsList
).
map
(
row
=>
const
children
=
cloneRowFieldsList
(
rowFieldsList
).
map
(
row
=>
{
row
.
map
(
cell
=>
formatFieldForAppJsonContent
(
cell
))
const
rowMap
=
rowFieldsToStorageValueMap
(
row
)
)
const
visibleRow
=
filterVisibleRowFieldsForJson
(
field
,
row
,
rowMap
)
return
visibleRow
.
map
(
cell
=>
formatFieldForAppJsonContent
(
cell
))
})
section
.
children
=
children
section
.
children
=
children
if
(
Array
.
isArray
(
field
.
origin_children
)
&&
field
.
origin_children
.
length
)
{
if
(
Array
.
isArray
(
field
.
origin_children
)
&&
field
.
origin_children
.
length
)
{
...
...
packageDynamicForm/form-engine/core.js
View file @
02a10bd
...
@@ -15,7 +15,8 @@ import {
...
@@ -15,7 +15,8 @@ import {
buildInitialValues
,
buildInitialValues
,
applyInitialValues
,
applyInitialValues
,
setFieldValue
,
setFieldValue
,
clearHiddenFieldValues
clearHiddenFieldValues
,
clearHiddenSubformRowValues
}
from
'./values.js'
}
from
'./values.js'
import
{
assertEngineSubformsAligned
}
from
'./subform-invariants.js'
import
{
assertEngineSubformsAligned
}
from
'./subform-invariants.js'
import
{
validateForm
}
from
'./validator.js'
import
{
validateForm
}
from
'./validator.js'
...
@@ -38,7 +39,8 @@ import {
...
@@ -38,7 +39,8 @@ import {
setRowFieldInCache
,
setRowFieldInCache
,
setNegotiationDualKeyFieldInCache
,
setNegotiationDualKeyFieldInCache
,
replaceRowInCache
,
replaceRowInCache
,
getGroupRowFieldsList
getGroupRowFieldsList
,
stripHiddenSubformCellsFromCache
}
from
'./group-rows-cache.js'
}
from
'./group-rows-cache.js'
import
{
cloneRowFieldsList
,
cloneRowTemplateForAdd
}
from
'./group-row-adapter.js'
import
{
cloneRowFieldsList
,
cloneRowTemplateForAdd
}
from
'./group-row-adapter.js'
import
{
flattenFields
}
from
'./visibility.js'
import
{
flattenFields
}
from
'./visibility.js'
...
@@ -79,9 +81,15 @@ export function createFormEngine(schemaRoot = {}) {
...
@@ -79,9 +81,15 @@ export function createFormEngine(schemaRoot = {}) {
groupRowsCache
=
buildGroupRowsCache
(
list
,
values
)
groupRowsCache
=
buildGroupRowsCache
(
list
,
values
)
}
}
function
refreshValues
()
{
function
applyVisibilityClearing
()
{
values
=
clearHiddenFieldValues
(
list
,
pageContext
,
values
)
values
=
clearHiddenFieldValues
(
list
,
pageContext
,
values
)
values
=
clearHiddenSubformRowValues
(
list
,
pageContext
,
values
)
rebuildGroupRowsCache
()
rebuildGroupRowsCache
()
groupRowsCache
=
stripHiddenSubformCellsFromCache
(
list
,
pageContext
,
values
,
groupRowsCache
)
}
function
refreshValues
()
{
applyVisibilityClearing
()
}
}
function
finishSubformMutation
()
{
function
finishSubformMutation
()
{
...
@@ -134,8 +142,7 @@ export function createFormEngine(schemaRoot = {}) {
...
@@ -134,8 +142,7 @@ export function createFormEngine(schemaRoot = {}) {
values
=
applyInitialValues
(
values
,
pageContext
.
initialValues
)
values
=
applyInitialValues
(
values
,
pageContext
.
initialValues
)
}
}
rebuildGroupRowsCache
()
rebuildGroupRowsCache
()
values
=
clearHiddenFieldValues
(
list
,
pageContext
,
values
)
applyVisibilityClearing
()
rebuildGroupRowsCache
()
return
getViewState
()
return
getViewState
()
},
},
/** 更新页面上下文并刷新隐藏字段与缓存,返回最新视图状态 */
/** 更新页面上下文并刷新隐藏字段与缓存,返回最新视图状态 */
...
@@ -218,7 +225,7 @@ export function createFormEngine(schemaRoot = {}) {
...
@@ -218,7 +225,7 @@ export function createFormEngine(schemaRoot = {}) {
rowTemplate
rowTemplate
)
)
values
=
syncValuesFromGroupCache
(
values
,
groupKey
,
groupRowsCache
[
groupKey
])
values
=
syncValuesFromGroupCache
(
values
,
groupKey
,
groupRowsCache
[
groupKey
])
values
=
clearHiddenFieldValues
(
list
,
pageContext
,
values
)
applyVisibilityClearing
(
)
finishSubformMutation
()
finishSubformMutation
()
return
getViewState
()
return
getViewState
()
},
},
...
@@ -267,7 +274,7 @@ export function createFormEngine(schemaRoot = {}) {
...
@@ -267,7 +274,7 @@ export function createFormEngine(schemaRoot = {}) {
rowTemplate
rowTemplate
)
)
values
=
syncValuesFromGroupCache
(
values
,
groupKey
,
groupRowsCache
[
groupKey
])
values
=
syncValuesFromGroupCache
(
values
,
groupKey
,
groupRowsCache
[
groupKey
])
values
=
clearHiddenFieldValues
(
list
,
pageContext
,
values
)
applyVisibilityClearing
(
)
finishSubformMutation
()
finishSubformMutation
()
return
getViewState
()
return
getViewState
()
},
},
...
@@ -278,8 +285,7 @@ export function createFormEngine(schemaRoot = {}) {
...
@@ -278,8 +285,7 @@ export function createFormEngine(schemaRoot = {}) {
replaceGroupRow
(
groupKey
,
rowIndex
,
rowFields
)
{
replaceGroupRow
(
groupKey
,
rowIndex
,
rowFields
)
{
groupRowsCache
=
replaceRowInCache
(
groupRowsCache
,
groupKey
,
rowIndex
,
rowFields
)
groupRowsCache
=
replaceRowInCache
(
groupRowsCache
,
groupKey
,
rowIndex
,
rowFields
)
values
=
replaceGroupRow
(
values
,
groupKey
,
rowIndex
,
rowFields
)
values
=
replaceGroupRow
(
values
,
groupKey
,
rowIndex
,
rowFields
)
values
=
clearHiddenFieldValues
(
list
,
pageContext
,
values
)
applyVisibilityClearing
()
rebuildGroupRowsCache
()
return
getViewState
()
return
getViewState
()
},
},
/** 新增 subform 行,返回视图状态及 rowIndex */
/** 新增 subform 行,返回视图状态及 rowIndex */
...
@@ -295,7 +301,7 @@ export function createFormEngine(schemaRoot = {}) {
...
@@ -295,7 +301,7 @@ export function createFormEngine(schemaRoot = {}) {
const
cacheResult
=
addRowToCache
(
groupRowsCache
,
group
)
const
cacheResult
=
addRowToCache
(
groupRowsCache
,
group
)
groupRowsCache
=
cacheResult
.
cache
groupRowsCache
=
cacheResult
.
cache
values
=
syncValuesFromGroupCache
(
values
,
group
.
key
,
groupRowsCache
[
group
.
key
])
values
=
syncValuesFromGroupCache
(
values
,
group
.
key
,
groupRowsCache
[
group
.
key
])
values
=
clearHiddenFieldValues
(
list
,
pageContext
,
values
)
applyVisibilityClearing
(
)
finishSubformMutation
()
finishSubformMutation
()
const
nextLen
=
(
groupRowsCache
[
group
.
key
]
||
[]).
length
const
nextLen
=
(
groupRowsCache
[
group
.
key
]
||
[]).
length
return
{
return
{
...
@@ -311,7 +317,7 @@ export function createFormEngine(schemaRoot = {}) {
...
@@ -311,7 +317,7 @@ export function createFormEngine(schemaRoot = {}) {
if
(
groupRowsCache
[
groupKey
])
{
if
(
groupRowsCache
[
groupKey
])
{
values
=
syncValuesFromGroupCache
(
values
,
groupKey
,
groupRowsCache
[
groupKey
])
values
=
syncValuesFromGroupCache
(
values
,
groupKey
,
groupRowsCache
[
groupKey
])
}
}
values
=
clearHiddenFieldValues
(
list
,
pageContext
,
values
)
applyVisibilityClearing
(
)
finishSubformMutation
()
finishSubformMutation
()
return
getViewState
()
return
getViewState
()
},
},
...
@@ -335,7 +341,7 @@ export function createFormEngine(schemaRoot = {}) {
...
@@ -335,7 +341,7 @@ export function createFormEngine(schemaRoot = {}) {
prepareForSubmit
()
{
prepareForSubmit
()
{
groupRowsCache
=
repairGroupRowsCacheFromValues
(
list
,
values
,
groupRowsCache
)
groupRowsCache
=
repairGroupRowsCacheFromValues
(
list
,
values
,
groupRowsCache
)
values
=
syncSubformValuesFromCache
(
values
,
groupRowsCache
,
list
,
pageContext
)
values
=
syncSubformValuesFromCache
(
values
,
groupRowsCache
,
list
,
pageContext
)
values
=
clearHiddenFieldValues
(
list
,
pageContext
,
values
)
applyVisibilityClearing
(
)
},
},
/** @returns {{ ok: boolean, errors: Array, errorMap: object }} 校验结果 */
/** @returns {{ ok: boolean, errors: Array, errorMap: object }} 校验结果 */
validate
(
options
=
{})
{
validate
(
options
=
{})
{
...
...
packageDynamicForm/form-engine/group-row-adapter.js
View file @
02a10bd
...
@@ -75,6 +75,29 @@ export function isRowFieldsList(value) {
...
@@ -75,6 +75,29 @@ export function isRowFieldsList(value) {
)
)
}
}
function
isPlainObject
(
value
)
{
return
value
!=
null
&&
typeof
value
===
'object'
&&
!
Array
.
isArray
(
value
)
}
/** optionsKey select 写入 values:有独立展示名时存 { id, name },否则存 id 标量 */
function
selectValueMapEntry
(
field
=
{})
{
const
storageValue
=
extractSelectStorageValueFromRowField
(
field
)
if
(
storageValue
===
undefined
||
storageValue
===
null
||
storageValue
===
''
)
{
return
undefined
}
if
(
isPlainObject
(
storageValue
))
{
const
id
=
storageValue
.
id
??
storageValue
.
value
const
name
=
storageValue
.
name
??
storageValue
.
label
??
''
if
(
id
!=
null
&&
id
!==
''
&&
name
!==
''
&&
String
(
name
)
!==
String
(
id
))
{
return
storageValue
}
if
(
id
!=
null
&&
id
!==
''
)
{
return
String
(
id
)
}
}
return
storageValue
}
/** FormField[] 转为行 valueMap(跳过空值) */
/** FormField[] 转为行 valueMap(跳过空值) */
export
function
rowFieldsToValueMap
(
rowFields
=
[])
{
export
function
rowFieldsToValueMap
(
rowFields
=
[])
{
const
map
=
{}
const
map
=
{}
...
@@ -88,9 +111,11 @@ export function rowFieldsToValueMap(rowFields = []) {
...
@@ -88,9 +111,11 @@ export function rowFieldsToValueMap(rowFields = []) {
return
return
}
}
if
(
field
.
type
===
'select'
)
{
if
(
field
.
type
===
'select'
)
{
const
meta
=
field
[
field
.
key
]
if
(
field
.
optionsKey
)
{
if
(
field
.
optionsKey
&&
meta
!=
null
&&
meta
!==
''
)
{
const
entry
=
selectValueMapEntry
(
field
)
map
[
field
.
key
]
=
meta
if
(
entry
!==
undefined
)
{
map
[
field
.
key
]
=
entry
}
return
return
}
}
if
(
typeof
v
===
'object'
&&
v
!==
null
&&
!
Array
.
isArray
(
v
))
{
if
(
typeof
v
===
'object'
&&
v
!==
null
&&
!
Array
.
isArray
(
v
))
{
...
...
packageDynamicForm/form-engine/group-rows-cache.js
View file @
02a10bd
...
@@ -10,7 +10,10 @@ import {
...
@@ -10,7 +10,10 @@ import {
import
{
getSubformRowTemplateForAdd
}
from
'./field-types.js'
import
{
getSubformRowTemplateForAdd
}
from
'./field-types.js'
import
{
normalizeOptionRecord
}
from
'./field-submit-value.js'
import
{
normalizeOptionRecord
}
from
'./field-submit-value.js'
import
{
getGroupRows
,
listGroups
}
from
'./group-values.js'
import
{
getGroupRows
,
listGroups
}
from
'./group-values.js'
import
{
clearHiddenFieldValues
}
from
'./values.js'
import
{
clearHiddenFieldValues
,
clearHiddenSubformRowValues
}
from
'./values.js'
import
{
filterVisibleRowFields
}
from
'./group-visibility.js'
import
{
resolveEffectiveRowFields
}
from
'./visibility.js'
import
{
listSubforms
}
from
'./field-types.js'
import
{
resolveSubformMaxRows
}
from
'./subform-limits.js'
import
{
resolveSubformMaxRows
}
from
'./subform-limits.js'
/** 从 values 构建 groupRowsCache(FormField[][])
/** 从 values 构建 groupRowsCache(FormField[][])
...
@@ -18,7 +21,7 @@ import { resolveSubformMaxRows } from './subform-limits.js'
...
@@ -18,7 +21,7 @@ import { resolveSubformMaxRows } from './subform-limits.js'
export
function
buildGroupRowsCache
(
list
=
[],
values
=
{})
{
export
function
buildGroupRowsCache
(
list
=
[],
values
=
{})
{
const
cache
=
{}
const
cache
=
{}
listGroups
(
list
).
forEach
(
group
=>
{
listGroups
(
list
).
forEach
(
group
=>
{
const
columnTemplate
=
getSubform
RowTemplateForAdd
(
group
)
const
columnTemplate
=
clone
RowTemplateForAdd
(
group
)
const
maps
=
getGroupRows
(
values
,
group
.
key
)
const
maps
=
getGroupRows
(
values
,
group
.
key
)
if
(
!
columnTemplate
.
length
||
!
maps
.
length
)
{
if
(
!
columnTemplate
.
length
||
!
maps
.
length
)
{
cache
[
group
.
key
]
=
[]
cache
[
group
.
key
]
=
[]
...
@@ -73,6 +76,25 @@ export function repairGroupRowsCacheFromValues(list = [], values = {}, cache = {
...
@@ -73,6 +76,25 @@ export function repairGroupRowsCacheFromValues(list = [], values = {}, cache = {
return
next
return
next
}
}
/** rebuild 后剔除 childrenShowRules 不可见 cell(cache 列模板仍含 hidden 空位) */
export
function
stripHiddenSubformCellsFromCache
(
list
=
[],
ctx
=
{},
values
=
{},
cache
=
{})
{
const
next
=
{
...
cache
}
listSubforms
(
list
).
forEach
(
group
=>
{
const
groupKey
=
group
.
key
const
rowList
=
next
[
groupKey
]
if
(
!
groupKey
||
!
Array
.
isArray
(
rowList
)
||
!
rowList
.
length
)
{
return
}
const
maps
=
getGroupRows
(
values
,
groupKey
)
next
[
groupKey
]
=
rowList
.
map
((
rowFields
,
rowIndex
)
=>
{
const
rowMap
=
maps
[
rowIndex
]
||
{}
const
effective
=
resolveEffectiveRowFields
(
group
,
rowFields
,
rowMap
)
return
filterVisibleRowFields
(
group
,
effective
,
rowMap
)
})
})
return
next
}
/** 校验/提交前:以 groupRowsCache 为准回写全部 subform 行,避免 values 与 cache 脱节导致误通过 */
/** 校验/提交前:以 groupRowsCache 为准回写全部 subform 行,避免 values 与 cache 脱节导致误通过 */
export
function
syncSubformValuesFromCache
(
values
=
{},
groupRowsCache
=
{},
list
=
[],
ctx
=
{})
{
export
function
syncSubformValuesFromCache
(
values
=
{},
groupRowsCache
=
{},
list
=
[],
ctx
=
{})
{
let
next
=
{
...
values
}
let
next
=
{
...
values
}
...
@@ -82,7 +104,11 @@ export function syncSubformValuesFromCache(values = {}, groupRowsCache = {}, lis
...
@@ -82,7 +104,11 @@ export function syncSubformValuesFromCache(values = {}, groupRowsCache = {}, lis
next
=
syncValuesFromGroupCache
(
next
,
group
.
key
,
rowFieldsList
)
next
=
syncValuesFromGroupCache
(
next
,
group
.
key
,
rowFieldsList
)
}
}
})
})
return
clearHiddenFieldValues
(
list
,
ctx
,
next
)
return
clearHiddenSubformRowValues
(
list
,
ctx
,
clearHiddenFieldValues
(
list
,
ctx
,
next
)
)
}
}
/** @returns {Array} 指定行的 FormField[] 深拷贝 */
/** @returns {Array} 指定行的 FormField[] 深拷贝 */
...
@@ -151,6 +177,7 @@ export function setRowFieldInCache(cache = {}, groupKey, rowIndex, childKey, val
...
@@ -151,6 +177,7 @@ export function setRowFieldInCache(cache = {}, groupKey, rowIndex, childKey, val
return
cache
return
cache
}
}
const
field
=
{
...
row
[
idx
]
}
const
field
=
{
...
row
[
idx
]
}
const
fieldKey
=
field
.
key
??
childKey
if
(
if
(
value
===
''
||
value
===
''
||
value
===
null
||
value
===
null
||
...
@@ -158,8 +185,20 @@ export function setRowFieldInCache(cache = {}, groupKey, rowIndex, childKey, val
...
@@ -158,8 +185,20 @@ export function setRowFieldInCache(cache = {}, groupKey, rowIndex, childKey, val
(
Array
.
isArray
(
value
)
&&
value
.
length
===
0
)
(
Array
.
isArray
(
value
)
&&
value
.
length
===
0
)
)
{
)
{
delete
field
.
value
delete
field
.
value
if
(
field
.
optionsKey
&&
fieldKey
!=
null
)
{
delete
field
[
fieldKey
]
}
}
else
{
}
else
{
field
.
value
=
value
field
.
value
=
value
if
(
field
.
optionsKey
&&
fieldKey
!=
null
)
{
if
(
typeof
value
===
'object'
&&
value
!==
null
&&
!
Array
.
isArray
(
value
))
{
const
normalized
=
normalizeOptionRecord
(
value
)
||
value
field
[
fieldKey
]
=
normalized
field
.
value
=
normalized
.
name
??
normalized
.
label
??
field
.
value
}
else
{
field
[
fieldKey
]
=
value
}
}
}
}
row
[
idx
]
=
field
row
[
idx
]
=
field
list
[
rowIndex
]
=
row
list
[
rowIndex
]
=
row
...
...
packageDynamicForm/form-engine/group-show-rule-eval.js
View file @
02a10bd
...
@@ -4,10 +4,11 @@
...
@@ -4,10 +4,11 @@
*/
*/
function
evalPart
(
part
=
''
,
ctx
=
{})
{
function
evalPart
(
part
=
''
,
ctx
=
{})
{
const
trimmed
=
part
.
trim
()
const
trimmed
=
part
.
trim
()
const
eqMatch
=
trimmed
.
match
(
/^val
(\d
+
)\s
*==
\s
*
'
([^
'
]
*
)
'
$/
)
const
eqMatch
=
trimmed
.
match
(
/^val
(\d
+
)\s
*==
\s
*
(?:
'
([^
'
]
*
)
'|"
([^
"
]
*
)
"
)
$/
)
if
(
eqMatch
)
{
if
(
eqMatch
)
{
const
actual
=
ctx
[
`val
${
eqMatch
[
1
]}
`
]
const
actual
=
ctx
[
`val
${
eqMatch
[
1
]}
`
]
return
actual
==
eqMatch
[
2
]
const
expected
=
eqMatch
[
2
]
!=
null
?
eqMatch
[
2
]
:
eqMatch
[
3
]
return
actual
==
expected
}
}
const
neNullMatch
=
trimmed
.
match
(
/^val
(\d
+
)\s
*!=
\s
*null$/
)
const
neNullMatch
=
trimmed
.
match
(
/^val
(\d
+
)\s
*!=
\s
*null$/
)
if
(
neNullMatch
)
{
if
(
neNullMatch
)
{
...
@@ -38,7 +39,11 @@ function evaluateShowRule(keys = [], resultExpr = '', rowFields = [], getRowFiel
...
@@ -38,7 +39,11 @@ function evaluateShowRule(keys = [], resultExpr = '', rowFields = [], getRowFiel
}
}
}
}
module
.
exports
=
{
export
{
evaluateShowRule
,
fallbackEvaluate
}
evaluateShowRule
,
fallbackEvaluate
if
(
typeof
module
!==
'undefined'
&&
module
.
exports
)
{
module
.
exports
=
{
evaluateShowRule
,
fallbackEvaluate
}
}
}
packageDynamicForm/form-engine/save-request.js
View file @
02a10bd
...
@@ -6,16 +6,34 @@ const {
...
@@ -6,16 +6,34 @@ const {
}
=
require
(
'../config/dailyReportConstants.js'
)
}
=
require
(
'../config/dailyReportConstants.js'
)
const
{
resolveSaveMerchantId
,
resolveShopMerchantName
}
=
require
(
'../utils/user-merchant.js'
)
const
{
resolveSaveMerchantId
,
resolveShopMerchantName
}
=
require
(
'../utils/user-merchant.js'
)
/** fieldDataList 为空时序列化为 '[]',避免 qs.stringify 丢弃空数组导致 HTTP 参数缺失 */
/** 组装 requestJson 对象并 JSON.stringify(与 jsonContent 同级字符串传输) */
function
formatFieldDataListForApi
(
list
)
{
function
buildRequestJsonForApi
(
fieldDataList
=
[],
subformDataList
=
[])
{
if
(
!
Array
.
isArray
(
list
)
||
list
.
length
===
0
)
{
const
payload
=
{
return
'[]'
fieldDataList
:
Array
.
isArray
(
fieldDataList
)
?
fieldDataList
:
[]
}
if
(
Array
.
isArray
(
subformDataList
)
&&
subformDataList
.
length
>
0
)
{
payload
.
subformDataList
=
subformDataList
}
return
JSON
.
stringify
(
payload
)
}
/** 解析 save 请求体中的 requestJson(供 mock / 测试回显) */
function
parseRequestJsonLists
(
requestJson
)
{
if
(
requestJson
==
null
||
requestJson
===
''
)
{
return
{
fieldDataList
:
[],
subformDataList
:
[]
}
}
const
parsed
=
typeof
requestJson
===
'string'
?
JSON
.
parse
(
requestJson
)
:
requestJson
return
{
fieldDataList
:
Array
.
isArray
(
parsed
.
fieldDataList
)
?
parsed
.
fieldDataList
:
[],
subformDataList
:
Array
.
isArray
(
parsed
.
subformDataList
)
?
parsed
.
subformDataList
:
[]
}
}
return
list
}
}
/**
/**
* 组装 dynamic.save/1.0.0 请求体(含 jsonContent 与
规范化 fieldDataList
)。
* 组装 dynamic.save/1.0.0 请求体(含 jsonContent 与
requestJson
)。
* @returns {{ request: object, fieldDataList: Array, subformDataList: Array }}
* @returns {{ request: object, fieldDataList: Array, subformDataList: Array }}
*/
*/
function
buildDailyReportSaveRequest
({
function
buildDailyReportSaveRequest
({
...
@@ -53,11 +71,10 @@ function buildDailyReportSaveRequest({
...
@@ -53,11 +71,10 @@ function buildDailyReportSaveRequest({
templateType
,
templateType
,
reportTemplateId
:
formPayload
.
reportTemplateId
,
reportTemplateId
:
formPayload
.
reportTemplateId
,
jsonContent
:
formPayload
.
jsonContent
,
jsonContent
:
formPayload
.
jsonContent
,
fieldDataList
:
formatFieldDataListForApi
(
formPayload
.
fieldDataList
)
requestJson
:
buildRequestJsonForApi
(
}
formPayload
.
fieldDataList
,
formPayload
.
subformDataList
if
(
Array
.
isArray
(
formPayload
.
subformDataList
)
&&
formPayload
.
subformDataList
.
length
>
0
)
{
)
request
.
subformDataList
=
formPayload
.
subformDataList
}
}
if
(
formPayload
.
dailyReportRecordId
)
{
if
(
formPayload
.
dailyReportRecordId
)
{
...
@@ -72,5 +89,7 @@ function buildDailyReportSaveRequest({
...
@@ -72,5 +89,7 @@ function buildDailyReportSaveRequest({
}
}
module
.
exports
=
{
module
.
exports
=
{
buildDailyReportSaveRequest
buildDailyReportSaveRequest
,
buildRequestJsonForApi
,
parseRequestJsonLists
}
}
packageDynamicForm/form-engine/submit-adapter.js
View file @
02a10bd
...
@@ -6,19 +6,8 @@
...
@@ -6,19 +6,8 @@
* buildDynamicSavePayload:visibleFormList + normalized 字段列表
* buildDynamicSavePayload:visibleFormList + normalized 字段列表
* parseJsonContentDetailValues:仅从 jsonContent 解析 values;radio/select/multipleSelect 归一化
* parseJsonContentDetailValues:仅从 jsonContent 解析 values;radio/select/multipleSelect 归一化
*/
*/
import
{
import
{
getVisibleList
,
getVisibleLeafFields
}
from
'./visibility.js'
getVisibleList
,
import
{
normalizeRadioValuesInMap
}
from
'./radio-value.js'
getVisibleLeafFields
,
schemaHasAttendanceField
,
ATTENDANCE_KEY
}
from
'./visibility.js'
import
{
normalizeRadioValuesInMap
,
isAttendanceOnDuty
,
getAttendanceField
,
getOnDutyOption
}
from
'./radio-value.js'
import
{
buildInitialValues
}
from
'./values.js'
import
{
normalizeSelectValuesInMap
,
coerceSelectValue
}
from
'./select-value.js'
import
{
normalizeSelectValuesInMap
,
coerceSelectValue
}
from
'./select-value.js'
import
{
normalizeMultipleSelectValuesInMap
,
coerceMultipleSelectValue
}
from
'./multiple-select-value.js'
import
{
normalizeMultipleSelectValuesInMap
,
coerceMultipleSelectValue
}
from
'./multiple-select-value.js'
import
{
getGroupRows
}
from
'./group-values.js'
import
{
getGroupRows
}
from
'./group-values.js'
...
@@ -158,29 +147,6 @@ export function assembleFormListForSaveLists(engine, visibleList = []) {
...
@@ -158,29 +147,6 @@ export function assembleFormListForSaveLists(engine, visibleList = []) {
return
assembleFormListForSaveListsWithValues
(
engine
,
visibleList
,
saveValues
)
return
assembleFormListForSaveListsWithValues
(
engine
,
visibleList
,
saveValues
)
}
}
/**
* 驻店保存:调休时 jsonContent 写入「在岗可见」字段骨架(F1-1 仍为调休),fieldDataList 仍仅当前可见
*/
export
function
assembleStaffSaveFormList
(
engine
)
{
const
list
=
engine
.
getSchemaList
?.()
||
[]
const
ctx
=
engine
.
getPageContext
?.()
||
{}
const
visibleList
=
engine
.
getVisibleList
()
const
actualValues
=
collectSaveValues
(
engine
,
visibleList
)
if
(
!
schemaHasAttendanceField
(
list
)
||
isAttendanceOnDuty
(
list
,
actualValues
))
{
return
assembleFormListForSaveLists
(
engine
,
visibleList
)
}
const
attendanceField
=
getAttendanceField
(
list
)
const
onDutyOption
=
getOnDutyOption
(
attendanceField
)
const
onDutyValue
=
onDutyOption
?.
value
const
onDutyProbe
=
{
...
actualValues
,
[
ATTENDANCE_KEY
]:
onDutyValue
}
const
expandedVisible
=
getVisibleList
(
list
,
ctx
,
onDutyProbe
)
const
jsonValues
=
{
...
buildInitialValues
(
list
),
...
actualValues
}
return
assembleFormListForSaveListsWithValues
(
engine
,
expandedVisible
,
jsonValues
)
}
/** 从 formList 提取 values(含 subform 行与静态 group 子字段) */
/** 从 formList 提取 values(含 subform 行与静态 group 子字段) */
export
function
extractValuesFromFormList
(
list
=
[])
{
export
function
extractValuesFromFormList
(
list
=
[])
{
const
values
=
{}
const
values
=
{}
...
@@ -283,11 +249,10 @@ export function buildDynamicSavePayload({
...
@@ -283,11 +249,10 @@ export function buildDynamicSavePayload({
let
subformDataList
=
[]
let
subformDataList
=
[]
let
jsonContent
let
jsonContent
if
(
normalizedFieldDataList
)
{
if
(
normalizedFieldDataList
)
{
const
formListForJson
=
assembleStaffSaveFormList
(
engine
)
const
formListForSave
=
assembleFormListForSaveLists
(
engine
,
visibleList
)
const
formListForLists
=
assembleFormListForSaveLists
(
engine
,
visibleList
)
jsonContent
=
JSON
.
stringify
(
serializeFormListForAppJsonStorage
(
formListForSave
))
jsonContent
=
JSON
.
stringify
(
serializeFormListForAppJsonStorage
(
formListForJson
))
;({
fieldDataList
,
subformDataList
}
=
;({
fieldDataList
,
subformDataList
}
=
buildAppDailyReportSubmitPayload
(
formListFor
Lists
))
buildAppDailyReportSubmitPayload
(
formListFor
Save
))
}
else
{
}
else
{
fieldDataList
=
buildFieldDataList
(
visibleList
,
listValues
)
fieldDataList
=
buildFieldDataList
(
visibleList
,
listValues
)
jsonContent
=
JSON
.
stringify
(
jsonContent
=
JSON
.
stringify
(
...
@@ -387,7 +352,6 @@ export default {
...
@@ -387,7 +352,6 @@ export default {
buildDynamicSavePayload
,
buildDynamicSavePayload
,
buildVisibleFormList
,
buildVisibleFormList
,
assembleFormListForSaveLists
,
assembleFormListForSaveLists
,
assembleStaffSaveFormList
,
collectSaveValues
,
collectSaveValues
,
mergeValuesIntoSchema
,
mergeValuesIntoSchema
,
extractValuesFromFormList
,
extractValuesFromFormList
,
...
...
packageDynamicForm/form-engine/values.js
View file @
02a10bd
/** 表单 values 读写与隐藏字段清理 — @see packageDynamicForm/docs/ARCHITECTURE.md */
/** 表单 values 读写与隐藏字段清理 — @see packageDynamicForm/docs/ARCHITECTURE.md */
import
{
getVisibleList
,
getVisibleLeafFields
}
from
'./visibility.js'
import
{
getVisibleList
,
getVisibleLeafFields
,
resolveEffectiveRowFields
}
from
'./visibility.js'
import
{
filterVisibleRowFields
}
from
'./group-visibility.js'
import
{
import
{
listSubforms
,
listSubforms
,
listStaticGroups
,
listStaticGroups
,
getStaticGroupChildren
,
getStaticGroupChildren
,
getSubformRowTemplate
getSubformRowTemplate
,
getSubformRowTemplateForAdd
}
from
'./field-types.js'
}
from
'./field-types.js'
import
{
getGroupRows
}
from
'./group-values.js'
import
{
normalizeFieldValueByType
}
from
'./field-types/registry.js'
import
{
normalizeFieldValueByType
}
from
'./field-types/registry.js'
import
{
normalizeSelectValuesInMap
}
from
'./select-value.js'
import
{
normalizeSelectValuesInMap
}
from
'./select-value.js'
import
{
coerceMultipleSelectValue
}
from
'./multiple-select-value.js'
import
{
coerceMultipleSelectValue
}
from
'./multiple-select-value.js'
...
@@ -158,3 +161,53 @@ export function clearHiddenFieldValues(list, ctx, values) {
...
@@ -158,3 +161,53 @@ export function clearHiddenFieldValues(list, ctx, values) {
})
})
return
nextValues
return
nextValues
}
}
/** 清除 subform 行内 childrenShowRules 不可见 cell 的值(联动切换后清 hidden) */
export
function
clearHiddenSubformRowValues
(
list
,
ctx
,
values
)
{
const
visibleSubformKeys
=
new
Set
(
getVisibleList
(
list
,
ctx
,
values
)
.
filter
(
field
=>
field
.
type
===
'subform'
)
.
map
(
field
=>
field
.
key
)
)
const
nextValues
=
{
...
values
}
listSubforms
(
list
).
forEach
(
group
=>
{
const
groupKey
=
group
.
key
if
(
!
groupKey
||
!
visibleSubformKeys
.
has
(
groupKey
))
{
return
}
const
template
=
getSubformRowTemplateForAdd
(
group
)
if
(
!
template
.
length
)
{
return
}
const
rows
=
getGroupRows
(
nextValues
,
groupKey
)
if
(
!
rows
.
length
)
{
return
}
let
changed
=
false
const
nextRows
=
rows
.
map
(
rowMap
=>
{
const
rowFields
=
resolveEffectiveRowFields
(
group
,
[],
rowMap
)
const
visibleKeys
=
new
Set
(
filterVisibleRowFields
(
group
,
rowFields
,
rowMap
).
map
(
field
=>
field
.
key
)
)
const
nextRow
=
{
...
rowMap
}
template
.
forEach
(
child
=>
{
if
(
!
child
?.
key
||
visibleKeys
.
has
(
child
.
key
))
{
return
}
if
(
nextRow
[
child
.
key
]
!==
undefined
)
{
delete
nextRow
[
child
.
key
]
changed
=
true
}
})
return
nextRow
})
if
(
changed
)
{
nextValues
[
groupKey
]
=
nextRows
}
})
return
nextValues
}
packageDynamicForm/form-engine/visibility.js
View file @
02a10bd
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
* @see packageDynamicForm/docs/ARCHITECTURE.md
* @see packageDynamicForm/docs/ARCHITECTURE.md
*
*
* getVisibleList:按 pageContext 与 values 过滤 schema list
* getVisibleList:按 pageContext 与 values 过滤 schema list
* 驻店 F1-1
调休:isAttendanceOnDuty(radio-valu
e.js)
* 驻店 F1-1
联动显隐:field.rules.keys + rules.result(field-show-rul
e.js)
*/
*/
import
{
filterVisibleRowFields
}
from
'./group-visibility.js'
import
{
filterVisibleRowFields
}
from
'./group-visibility.js'
import
{
valueMapToRowFieldsFromOrigin
}
from
'./group-row-adapter.js'
import
{
valueMapToRowFieldsFromOrigin
}
from
'./group-row-adapter.js'
...
@@ -14,8 +14,8 @@ import {
...
@@ -14,8 +14,8 @@ import {
getSubformRowTemplateForAdd
,
getSubformRowTemplateForAdd
,
getStaticGroupChildren
,
getStaticGroupChildren
,
}
from
'./field-types.js'
}
from
'./field-types.js'
import
{
isAttendanceOnDuty
}
from
'./radio-value.js'
import
{
isFieldVisibleBySpecs
}
from
'./visibility/specs/index.js'
import
{
isFieldVisibleBySpecs
}
from
'./visibility/specs/index.js'
import
{
isAttendanceOnDuty
}
from
'./radio-value.js'
export
const
ATTENDANCE_KEY
=
'F1-1'
export
const
ATTENDANCE_KEY
=
'F1-1'
export
const
ON_DUTY
=
'1'
export
const
ON_DUTY
=
'1'
...
@@ -166,6 +166,7 @@ function sortBySortNum(list = []) {
...
@@ -166,6 +166,7 @@ function sortBySortNum(list = []) {
function
getVisibilityOptions
(
list
=
[],
values
=
{},
ctx
=
{})
{
function
getVisibilityOptions
(
list
=
[],
values
=
{},
ctx
=
{})
{
return
{
return
{
schemaList
:
list
,
hasAttendanceField
:
schemaHasAttendanceField
(
list
),
hasAttendanceField
:
schemaHasAttendanceField
(
list
),
attendanceOnDuty
:
isAttendanceOnDuty
(
list
,
values
),
attendanceOnDuty
:
isAttendanceOnDuty
(
list
,
values
),
echoSubformKeys
:
resolveEchoSubformKeys
(
ctx
,
{})
echoSubformKeys
:
resolveEchoSubformKeys
(
ctx
,
{})
...
...
packageDynamicForm/form-engine/visibility/specs/field-show-rule.js
0 → 100644
View file @
02a10bd
/** 顶层字段 rules.keys + rules.result 显隐(对齐配置中心模版) */
import
{
evaluateShowRule
}
from
'../../group-show-rule-eval.js'
import
{
flattenFields
}
from
'../../visibility.js'
import
{
resolveRadioOptionValue
}
from
'../../radio-value.js'
function
findFieldByKey
(
list
=
[],
key
=
''
)
{
return
flattenFields
(
list
).
find
(
field
=>
field
.
key
===
key
)
}
function
getTopLevelFieldValue
(
list
=
[],
values
=
{},
key
=
''
)
{
const
field
=
findFieldByKey
(
list
,
key
)
const
raw
=
values
[
key
]
if
(
!
field
)
{
return
raw
==
null
||
raw
===
''
?
null
:
raw
}
if
(
field
.
type
===
'radio'
)
{
const
resolved
=
resolveRadioOptionValue
(
field
,
raw
)
return
resolved
==
null
||
resolved
===
''
?
null
:
resolved
}
return
raw
==
null
||
raw
===
''
?
null
:
raw
}
/** @returns {boolean} 无 keys/result 时恒为 true */
export
function
fieldShowRuleSpec
(
field
,
ctx
,
values
,
options
=
{})
{
const
rules
=
field
.
rules
||
{}
const
keys
=
rules
.
keys
||
[]
const
resultExpr
=
rules
.
result
if
(
!
keys
.
length
||
!
resultExpr
)
{
return
true
}
const
list
=
options
.
schemaList
||
ctx
.
schemaList
||
[]
return
evaluateShowRule
(
keys
,
resultExpr
,
[],
(
_rowFields
,
key
)
=>
getTopLevelFieldValue
(
list
,
values
,
key
)
)
}
packageDynamicForm/form-engine/visibility/specs/index.js
View file @
02a10bd
/** 显隐 Specification 组合 */
/** 显隐 Specification 组合 */
import
{
detailEchoSpec
}
from
'./detail-echo.js'
import
{
detailEchoSpec
}
from
'./detail-echo.js'
import
{
attendanceGateSpec
}
from
'./attendance-gat
e.js'
import
{
fieldShowRuleSpec
}
from
'./field-show-rul
e.js'
import
{
baseSceneSpec
}
from
'./base-scene.js'
import
{
baseSceneSpec
}
from
'./base-scene.js'
import
{
brandSpec
}
from
'./brand.js'
import
{
brandSpec
}
from
'./brand.js'
export
const
visibilitySpecs
=
[
export
const
visibilitySpecs
=
[
attendanceGateSpec
,
detailEchoSpec
,
detailEchoSpec
,
fieldShowRuleSpec
,
baseSceneSpec
,
baseSceneSpec
,
brandSpec
brandSpec
]
]
/** 与 visibility.isFieldVisible 等价 */
/** 与 visibility.isFieldVisible 等价 */
export
function
isFieldVisibleBySpecs
(
field
,
ctx
,
values
,
options
=
{})
{
export
function
isFieldVisibleBySpecs
(
field
,
ctx
,
values
,
options
=
{})
{
if
(
!
attendanceGateSpec
(
field
,
ctx
,
values
,
options
))
{
return
false
}
const
echoResult
=
detailEchoSpec
(
field
,
ctx
,
values
,
options
)
const
echoResult
=
detailEchoSpec
(
field
,
ctx
,
values
,
options
)
if
(
echoResult
!==
null
)
{
if
(
echoResult
!==
null
)
{
return
echoResult
===
true
return
echoResult
===
true
}
}
if
(
!
fieldShowRuleSpec
(
field
,
ctx
,
values
,
options
))
{
return
false
}
if
(
!
baseSceneSpec
(
field
,
ctx
,
values
,
options
))
{
if
(
!
baseSceneSpec
(
field
,
ctx
,
values
,
options
))
{
return
false
return
false
}
}
...
@@ -29,4 +29,4 @@ export function isFieldVisibleBySpecs(field, ctx, values, options = {}) {
...
@@ -29,4 +29,4 @@ export function isFieldVisibleBySpecs(field, ctx, values, options = {}) {
return
true
return
true
}
}
export
{
detailEchoSpec
,
attendanceGat
eSpec
,
baseSceneSpec
,
brandSpec
}
export
{
detailEchoSpec
,
fieldShowRul
eSpec
,
baseSceneSpec
,
brandSpec
}
packageDynamicForm/tests/app-children-value-json.test.mjs
View file @
02a10bd
...
@@ -8,6 +8,13 @@ import {
...
@@ -8,6 +8,13 @@ import {
} from '../form-engine/app-subform-json.js'
} from '../form-engine/app-subform-json.js'
import { parseJsonContentDetailValues } from '../form-engine/submit-adapter.js'
import { parseJsonContentDetailValues } from '../form-engine/submit-adapter.js'
function selectValueMapId(value) {
if (value != null && typeof value === 'object' && !Array.isArray(value)) {
return value.id ?? value.value
}
return value
}
const originChildren = [
const originChildren = [
{ key: 'F2-9-1', label: '交付专员', type: 'select', optionsKey: '4sStaffList' },
{ key: 'F2-9-1', label: '交付专员', type: 'select', optionsKey: '4sStaffList' },
{ key: 'F2-9-2', label: '今日交车', type: 'numberInput' }
{ key: 'F2-9-2', label: '今日交车', type: 'numberInput' }
...
@@ -38,7 +45,7 @@ describe('app childrenValue jsonContent codec', () => {
...
@@ -38,7 +45,7 @@ describe('app childrenValue jsonContent codec', () => {
const childrenValue = childrenToChildrenValue(sectionWithChildren)
const childrenValue = childrenToChildrenValue(sectionWithChildren)
assert.deepEqual(childrenValue[0]['F2-9']['F2-9-1'], {
assert.deepEqual(childrenValue[0]['F2-9']['F2-9-1'], {
text: '张三',
text: '张三',
value:
{ id: 'uuid-1', name: '张三', phone: '13800138000' }
value:
'uuid-1'
})
})
assert.equal(childrenValue[0]['F2-9']['F2-9-2'], 5)
assert.equal(childrenValue[0]['F2-9']['F2-9-2'], 5)
...
@@ -50,26 +57,46 @@ describe('app childrenValue jsonContent codec', () => {
...
@@ -50,26 +57,46 @@ describe('app childrenValue jsonContent codec', () => {
assert.equal(rows.length, 1)
assert.equal(rows.length, 1)
const staff = rows[0].find(f => f.key === 'F2-9-1')
const staff = rows[0].find(f => f.key === 'F2-9-1')
assert.equal(staff.value, '张三')
assert.equal(staff.value, '张三')
assert.
deepEqual(staff['F2-9-1'], { id: 'uuid-1', name: '张三', phone: '13800138000' }
)
assert.
equal(staff['F2-9-1'], 'uuid-1'
)
assert.equal(rows[0].find(f => f.key === 'F2-9-2').value, 5)
assert.equal(rows[0].find(f => f.key === 'F2-9-2').value, 5)
})
})
it('IT-APP-CV-002:
normalized lists equal for children vs childrenValue json
', () => {
it('IT-APP-CV-002:
lists from formList before serialize; childrenValue stores text + id
', () => {
const formList = [sectionWithChildren]
const formList = [sectionWithChildren]
const fromChildren = buildAppNormalizedListsFromJsonContent(formList)
const fromChildren = buildAppNormalizedListsFromJsonContent(JSON.stringify(formList))
const serialized = serializeFormListForAppJsonStorage(formList)
const fromPreSerialize = buildAppNormalizedListsFromJsonContent(
const fromChildrenValue = buildAppNormalizedListsFromJsonContent(serialized)
JSON.stringify(JSON.parse(JSON.stringify(formList)))
)
assert.deepEqual(fromPreSerialize.fieldDataList, fromChildren.fieldDataList)
assert.deepEqual(fromPreSerialize.subformDataList, fromChildren.subformDataList)
assert.deepEqual(fromChildrenValue.fieldDataList, fromChildren.fieldDataList)
const serialized = serializeFormListForAppJsonStorage(formList)
assert.deepEqual(fromChildrenValue.subformDataList, fromChildren.subformDataList)
assert.deepEqual(serialized[0].childrenValue[0]['F2-9']['F2-9-1'], {
text: '张三',
value: 'uuid-1'
})
assert.ok(!serialized[0].children)
assert.ok(!serialized[0].children)
assert.ok(Array.isArray(serialized[0].childrenValue))
assert.ok(Array.isArray(serialized[0].childrenValue))
})
})
it('IT-APP-CV-003: parseJsonContentDetailValues reads childrenValue like children', () => {
it('IT-APP-CV-004: serializeFormListForAppJsonStorage top-level remote select id in dual key', () => {
const serialized = serializeFormListForAppJsonStorage([
{
key: 'F2-9-1',
type: 'select',
optionsKey: '4sStaffList',
value: '张三',
'F2-9-1': { id: 'uuid-1', name: '张三', phone: '13800138000' }
}
])
assert.equal(serialized[0].value, '张三')
assert.equal(serialized[0]['F2-9-1'], 'uuid-1')
})
it('IT-APP-CV-003: parseJsonContentDetailValues reads childrenValue id from jsonContent', () => {
const serialized = serializeFormListForAppJsonStorage([sectionWithChildren])
const serialized = serializeFormListForAppJsonStorage([sectionWithChildren])
const fromChildren = parseJsonContentDetailValues(JSON.stringify([sectionWithChildren]), [])
const fromChildrenValue = parseJsonContentDetailValues(JSON.stringify(serialized), [])
const fromChildrenValue = parseJsonContentDetailValues(JSON.stringify(serialized), [])
assert.deepEqual(fromChildrenValue['F2-9'], fromChildren['F2-9'])
assert.equal(fromChildrenValue['F2-9'][0]['F2-9-2'], 5)
assert.equal(selectValueMapId(fromChildrenValue['F2-9'][0]['F2-9-1']), 'uuid-1')
})
})
})
})
packageDynamicForm/tests/app-save-lists-from-json.test.mjs
View file @
02a10bd
...
@@ -92,11 +92,7 @@ describe('App save lists from jsonContent', () => {
...
@@ -92,11 +92,7 @@ describe('App save lists from jsonContent', () => {
name: '张三'
name: '张三'
})
})
const flatItem = fieldDataList.find(
assert.ok(!fieldDataList.some(item => item.groupKey === 'F2-9'))
item => item.groupKey === 'F2-9' && item.fieldKey === 'F2-9-1' && item.rowIndex === 0
)
assert.ok(flatItem)
assert.equal(flatItem.fieldValue, subformItem.fieldValue)
})
})
it('IT-APP-LISTS-003: split builders match combined result', () => {
it('IT-APP-LISTS-003: split builders match combined result', () => {
...
@@ -134,7 +130,7 @@ describe('App save lists from jsonContent', () => {
...
@@ -134,7 +130,7 @@ describe('App save lists from jsonContent', () => {
assert.deepEqual(fromChildrenValue.subformDataList, fromChildren.subformDataList)
assert.deepEqual(fromChildrenValue.subformDataList, fromChildren.subformDataList)
})
})
it('IT-APP-LISTS-007: empty subform section
writes fieldType subform
placeholder', () => {
it('IT-APP-LISTS-007: empty subform section
does not write fieldDataList
placeholder', () => {
const emptySubformJson = JSON.stringify([
const emptySubformJson = JSON.stringify([
{
{
key: 'F3-1',
key: 'F3-1',
...
@@ -145,19 +141,15 @@ describe('App save lists from jsonContent', () => {
...
@@ -145,19 +141,15 @@ describe('App save lists from jsonContent', () => {
}
}
])
])
const { fieldDataList } = buildAppNormalizedListsFromJsonContent(emptySubformJson)
const { fieldDataList } = buildAppNormalizedListsFromJsonContent(emptySubformJson)
assert.equal(fieldDataList.length, 1)
assert.equal(fieldDataList.length, 0)
assert.deepEqual(fieldDataList[0], {
assert.ok(!fieldDataList.some(item => item.fieldType === 'subform'))
fieldKey: 'F3-1',
displayName: '洽谈明细',
fieldName: '洽谈明细',
fieldType: 'subform',
fieldValue: '[]'
})
})
})
it('IT-APP-LISTS-008: subform with row data does not write section placeholder', () => {
it('IT-APP-LISTS-008: subform row data stays in subformDataList only', () => {
const { fieldDataList } = buildAppNormalizedListsFromJsonContent(subformJsonContent)
const { fieldDataList, subformDataList } =
buildAppNormalizedListsFromJsonContent(subformJsonContent)
assert.ok(!fieldDataList.some(item => item.fieldType === 'subform'))
assert.ok(!fieldDataList.some(item => item.fieldType === 'subform'))
assert.ok(fieldDataList.some(item => item.groupKey === 'F2-9'))
assert.ok(!fieldDataList.some(item => item.groupKey === 'F2-9'))
assert.ok(subformDataList.some(item => item.parentFieldKey === 'F2-9'))
})
})
})
})
packageDynamicForm/tests/app-subform-json.test.mjs
View file @
02a10bd
...
@@ -2,6 +2,13 @@
...
@@ -2,6 +2,13 @@
import assert from 'node:assert/strict'
import assert from 'node:assert/strict'
import { createFormEngine } from '../form-engine/core.js'
import { createFormEngine } from '../form-engine/core.js'
function selectValueMapId(value) {
if (value != null && typeof value === 'object' && !Array.isArray(value)) {
return value.id ?? value.value
}
return value
}
const carInfo = {
const carInfo = {
vehicleBrandId: 1,
vehicleBrandId: 1,
vehicleBrandName: '问界',
vehicleBrandName: '问界',
...
@@ -91,19 +98,23 @@ describe('app-subform-json', async () => {
...
@@ -91,19 +98,23 @@ describe('app-subform-json', async () => {
})
})
it('IT-APP-002: formatFieldForAppJsonContent select object → dual key with full meta', () => {
it('IT-APP-002: formatFieldForAppJsonContent select object → dual key with full meta', () => {
const f
ormatted = formatFieldForAppJsonContent(
{
const f
ield =
{
key: 'F2-9-1',
key: 'F2-9-1',
type: 'select',
type: 'select',
optionsKey: '4sStaffList',
optionsKey: '4sStaffList',
value: { id: 'uuid-1', name: '张三', phone: '13800138000' },
value: { id: 'uuid-1', name: '张三', phone: '13800138000' },
'F2-9-1': { id: 'uuid-1', name: '张三', phone: '13800138000' }
'F2-9-1': { id: 'uuid-1', name: '张三', phone: '13800138000' }
})
}
const formatted = formatFieldForAppJsonContent(field)
assert.equal(formatted.value, '张三')
assert.equal(formatted.value, '张三')
assert.deepEqual(formatted['F2-9-1'], {
assert.deepEqual(formatted['F2-9-1'], {
id: 'uuid-1',
id: 'uuid-1',
name: '张三',
name: '张三',
phone: '13800138000'
phone: '13800138000'
})
})
const jsonStored = formatFieldForAppJsonContent(field, { jsonStorage: true })
assert.equal(jsonStored.value, '张三')
assert.equal(jsonStored['F2-9-1'], 'uuid-1')
})
})
it('IT-APP-003: formatFieldForAppJsonContent carBrand dual key', () => {
it('IT-APP-003: formatFieldForAppJsonContent carBrand dual key', () => {
...
@@ -153,15 +164,15 @@ describe('app-subform-json', async () => {
...
@@ -153,15 +164,15 @@ describe('app-subform-json', async () => {
]),
]),
[]
[]
)
)
assert.equal(
values['F2-9'][0]['F2-9-1']
, 'uuid-1')
assert.equal(
selectValueMapId(values['F2-9'][0]['F2-9-1'])
, 'uuid-1')
})
})
it('IT-NEG-002: parse App jsonContent children with dual-key fields', () => {
it('IT-NEG-002: parse App jsonContent children with dual-key fields', () => {
const section = buildAppSubformSection(buildAppCarBrandDisplayString(carInfo))
const section = buildAppSubformSection(buildAppCarBrandDisplayString(carInfo))
const values = parseJsonContentDetailValues(JSON.stringify([section]), [])
const values = parseJsonContentDetailValues(JSON.stringify([section]), [])
assert.equal(
values['F3-1'][0]['F3-1-3']
, 'uuid-staff-001')
assert.equal(
selectValueMapId(values['F3-1'][0]['F3-1-3'])
, 'uuid-staff-001')
assert.equal(
values['F3-1'][0]['F3-1-13']
, 'order-001')
assert.equal(
selectValueMapId(values['F3-1'][0]['F3-1-13'])
, 'order-001')
assert.equal(values['F3-1'][0]['F3-1-6'].vehicleShapeId, 4)
assert.equal(values['F3-1'][0]['F3-1-6'].vehicleShapeId, 4)
})
})
...
@@ -255,11 +266,15 @@ describe('app-subform-json', async () => {
...
@@ -255,11 +266,15 @@ describe('app-subform-json', async () => {
})
})
assert.equal(payload.fieldDataList.length, 0)
assert.equal(payload.fieldDataList.length, 0)
assert.ok(payload.subformDataList.length > 0)
assert.ok(
payload.subformDataList.some(
item => item.columnFieldKey === 'F3-1-3' && item.parentFieldKey === 'F3-1'
)
)
const parsed = JSON.parse(payload.jsonContent)
const parsed = JSON.parse(payload.jsonContent)
assert.deepEqual(parsed[0].childrenValue[0]['F3-1']['F3-1-3'], {
assert.deepEqual(parsed[0].childrenValue[0]['F3-1']['F3-1-3'], {
text: '王五',
text: '王五',
value:
{ id: 'uuid-staff-003', name: '王五' }
value:
'uuid-staff-003'
})
})
})
})
...
...
packageDynamicForm/tests/app-submit-order.test.mjs
View file @
02a10bd
...
@@ -81,11 +81,15 @@ describe('app submit order (mixins.submitReport)', () => {
...
@@ -81,11 +81,15 @@ describe('app submit order (mixins.submitReport)', () => {
const payload = buildAppDailySavePayload({ reportTemplateId: 10003, engine })
const payload = buildAppDailySavePayload({ reportTemplateId: 10003, engine })
assert.equal(payload.fieldDataList.length, 0)
assert.equal(payload.fieldDataList.length, 0)
assert.ok(payload.subformDataList.length > 0)
assert.ok(
payload.subformDataList.some(
item => item.columnFieldKey === 'F3-1-3' && item.parentFieldKey === 'F3-1'
)
)
const parsed = JSON.parse(payload.jsonContent)
const parsed = JSON.parse(payload.jsonContent)
assert.deepEqual(parsed[0].childrenValue[0]['F3-1']['F3-1-3'], {
assert.deepEqual(parsed[0].childrenValue[0]['F3-1']['F3-1-3'], {
text: '王五',
text: '王五',
value:
{ id: 'uuid-staff-003', name: '王五' }
value:
'uuid-staff-003'
})
})
})
})
})
})
packageDynamicForm/tests/dailyReportSaveRequest.test.mjs
View file @
02a10bd
...
@@ -3,7 +3,7 @@ import assert from 'node:assert/strict'
...
@@ -3,7 +3,7 @@ import assert from 'node:assert/strict'
import { createRequire } from 'node:module'
import { createRequire } from 'node:module'
const require = createRequire(import.meta.url)
const require = createRequire(import.meta.url)
const { buildDailyReportSaveRequest } = require('../form-engine/save-request.js')
const { buildDailyReportSaveRequest
, parseRequestJsonLists
} = require('../form-engine/save-request.js')
const {
const {
DAILY_REPORT_TEMPLATE_TYPE,
DAILY_REPORT_TEMPLATE_TYPE,
DAILY_REPORT_SOURCE
DAILY_REPORT_SOURCE
...
@@ -55,20 +55,24 @@ describe('dailyReportSaveRequest', async () => {
...
@@ -55,20 +55,24 @@ describe('dailyReportSaveRequest', async () => {
assert.equal(request.reportTemplateId, 10001)
assert.equal(request.reportTemplateId, 10001)
assert.equal(request.dailyReportRecordId, 90001)
assert.equal(request.dailyReportRecordId, 90001)
assert.ok(typeof request.jsonContent === 'string')
assert.ok(typeof request.jsonContent === 'string')
assert.ok(Array.isArray(request.fieldDataList))
assert.ok(typeof request.requestJson === 'string')
assert.ok(request.fieldDataList.length > 0)
assert.equal(request.fieldDataList, undefined)
assert.deepEqual(request.fieldDataList, fieldDataList)
assert.equal(request.subformDataList, undefined)
assert.equal(request.subformDataList, undefined)
const requestLists = parseRequestJsonLists(request.requestJson)
assert.ok(Array.isArray(requestLists.fieldDataList))
assert.ok(requestLists.fieldDataList.length > 0)
assert.deepEqual(requestLists.fieldDataList, fieldDataList)
assert.deepEqual(requestLists.subformDataList, [])
assert.deepEqual(subformDataList, [])
assert.deepEqual(subformDataList, [])
const jsonContent = JSON.parse(request.jsonContent)
const jsonContent = JSON.parse(request.jsonContent)
assert.ok(Array.isArray(jsonContent))
assert.ok(Array.isArray(jsonContent))
const f11Item = request.fieldDataList.find(item => item.fieldKey === 'F1-1')
const f11Item = request
Lists
.fieldDataList.find(item => item.fieldKey === 'F1-1')
assert.ok(f11Item)
assert.ok(f11Item)
assert.equal(f11Item.fieldType, 'STRING')
assert.equal(f11Item.fieldType, 'STRING')
assert.equal(f11Item.fieldValue, '在岗')
assert.equal(f11Item.fieldValue, '在岗')
assert.ok(f11Item.displayName)
assert.ok(f11Item.displayName)
assert.equal(f11Item.fieldName, f11Item.displayName)
assert.equal(f11Item.fieldName, f11Item.displayName)
const f151Item = request.fieldDataList.find(item => item.fieldKey === 'F1-5-1')
const f151Item = request
Lists
.fieldDataList.find(item => item.fieldKey === 'F1-5-1')
assert.ok(f151Item)
assert.ok(f151Item)
assert.equal(f151Item.fieldType, 'INT')
assert.equal(f151Item.fieldType, 'INT')
assert.equal(f151Item.fieldValue, '1')
assert.equal(f151Item.fieldValue, '1')
...
@@ -123,7 +127,9 @@ describe('dailyReportSaveRequest', async () => {
...
@@ -123,7 +127,9 @@ describe('dailyReportSaveRequest', async () => {
})
})
assert.equal(request.dailyReportRecordId, undefined)
assert.equal(request.dailyReportRecordId, undefined)
assert.equal(request.fieldDataList, undefined)
assert.equal(request.subformDataList, undefined)
assert.equal(request.subformDataList, undefined)
assert.deepEqual(parseRequestJsonLists(request.requestJson).subformDataList, [])
})
})
it('empty negotiation save serializes empty lists for API transport', () => {
it('empty negotiation save serializes empty lists for API transport', () => {
...
@@ -145,21 +151,10 @@ describe('dailyReportSaveRequest', async () => {
...
@@ -145,21 +151,10 @@ describe('dailyReportSaveRequest', async () => {
templateType: DAILY_REPORT_TEMPLATE_TYPE.negotiation
templateType: DAILY_REPORT_TEMPLATE_TYPE.negotiation
})
})
assert.ok(Array.isArray(request.fieldDataList))
const requestLists = parseRequestJsonLists(request.requestJson)
assert.ok(request.fieldDataList.length > 0)
assert.deepEqual(requestLists.fieldDataList, [])
assert.ok(fieldDataList.length > 0)
assert.deepEqual(fieldDataList, [])
fieldDataList.forEach(item => {
assert.deepEqual(requestLists.subformDataList, [])
assert.equal(item.fieldType, 'subform')
assert.equal(item.fieldValue, '[]')
})
const jsonKeys = JSON.parse(request.jsonContent)
.filter(item => item?.type === 'subform')
.map(item => item.key)
assert.deepEqual(
fieldDataList.map(item => item.fieldKey).sort(),
jsonKeys.sort()
)
assert.equal(request.subformDataList, undefined)
assert.deepEqual(subformDataList, [])
assert.deepEqual(subformDataList, [])
})
})
...
@@ -184,17 +179,14 @@ describe('dailyReportSaveRequest', async () => {
...
@@ -184,17 +179,14 @@ describe('dailyReportSaveRequest', async () => {
templateType: DAILY_REPORT_TEMPLATE_TYPE.store
templateType: DAILY_REPORT_TEMPLATE_TYPE.store
})
})
assert.ok(request.subformDataList.length > 0)
const requestLists = parseRequestJsonLists(request.requestJson)
assert.ok(requestLists.subformDataList.length > 0)
assert.ok(
assert.ok(
request.subformDataList.some(
request
Lists
.subformDataList.some(
item => item.parentFieldKey === 'F2-9' && item.columnFieldKey === 'F2-9-2'
item => item.parentFieldKey === 'F2-9' && item.columnFieldKey === 'F2-9-2'
)
)
)
)
assert.ok(
assert.ok(!requestLists.fieldDataList.some(item => item.groupKey === 'F2-9'))
request.fieldDataList.some(
item => item.groupKey === 'F2-9' && item.fieldKey === 'F2-9-2' && item.rowIndex === 0
)
)
})
})
it('IT-SAVE-LISTS-001: store save preserves phone via buildAppNormalizedListsFromJsonContent', async () => {
it('IT-SAVE-LISTS-001: store save preserves phone via buildAppNormalizedListsFromJsonContent', async () => {
...
@@ -226,7 +218,8 @@ describe('dailyReportSaveRequest', async () => {
...
@@ -226,7 +218,8 @@ describe('dailyReportSaveRequest', async () => {
templateType: DAILY_REPORT_TEMPLATE_TYPE.store
templateType: DAILY_REPORT_TEMPLATE_TYPE.store
})
})
const subformItem = request.subformDataList.find(
const requestLists = parseRequestJsonLists(request.requestJson)
const subformItem = requestLists.subformDataList.find(
item =>
item =>
item.parentFieldKey === 'F2-9' &&
item.parentFieldKey === 'F2-9' &&
item.columnFieldKey === 'F2-9-1' &&
item.columnFieldKey === 'F2-9-1' &&
...
@@ -236,7 +229,7 @@ describe('dailyReportSaveRequest', async () => {
...
@@ -236,7 +229,7 @@ describe('dailyReportSaveRequest', async () => {
assert.deepEqual(JSON.parse(subformItem.fieldValue), staff)
assert.deepEqual(JSON.parse(subformItem.fieldValue), staff)
})
})
it('IT-SAVE-LISTS-003: jsonContent
subform stores full option in field[key]
', async () => {
it('IT-SAVE-LISTS-003: jsonContent
childrenValue text+id; lists keep full option
', async () => {
const { createFormEngine } = await import('../form-engine/core.js')
const { createFormEngine } = await import('../form-engine/core.js')
const storeSchema = loadSchemaFixture('store')
const storeSchema = loadSchemaFixture('store')
const engine = createFormEngine(storeSchema)
const engine = createFormEngine(storeSchema)
...
@@ -269,9 +262,18 @@ describe('dailyReportSaveRequest', async () => {
...
@@ -269,9 +262,18 @@ describe('dailyReportSaveRequest', async () => {
const f29 = parsed.find(item => item.key === 'F2-9')
const f29 = parsed.find(item => item.key === 'F2-9')
assert.deepEqual(f29.childrenValue[0]['F2-9']['F2-9-1'], {
assert.deepEqual(f29.childrenValue[0]['F2-9']['F2-9-1'], {
text: staff.name,
text: staff.name,
value: staff
value: staff
.id
})
})
const requestLists = parseRequestJsonLists(request.requestJson)
const subformFromRequest = requestLists.subformDataList.find(
item =>
item.parentFieldKey === 'F2-9' &&
item.columnFieldKey === 'F2-9-1' &&
item.rowIndex === 0
)
assert.deepEqual(JSON.parse(subformFromRequest.fieldValue), staff)
const { buildAppNormalizedListsFromJsonContent } = await import(
const { buildAppNormalizedListsFromJsonContent } = await import(
'../form-engine/app-subform-json.js'
'../form-engine/app-subform-json.js'
)
)
...
@@ -282,7 +284,10 @@ describe('dailyReportSaveRequest', async () => {
...
@@ -282,7 +284,10 @@ describe('dailyReportSaveRequest', async () => {
item.columnFieldKey === 'F2-9-1' &&
item.columnFieldKey === 'F2-9-1' &&
item.rowIndex === 0
item.rowIndex === 0
)
)
assert.deepEqual(JSON.parse(subformItem.fieldValue), staff)
assert.deepEqual(JSON.parse(subformItem.fieldValue), {
id: staff.id,
name: staff.name
})
})
})
it('IT-SAVE-LISTS-002: unified lists match legacy buildNormalized* for store', async () => {
it('IT-SAVE-LISTS-002: unified lists match legacy buildNormalized* for store', async () => {
...
@@ -317,13 +322,12 @@ describe('dailyReportSaveRequest', async () => {
...
@@ -317,13 +322,12 @@ describe('dailyReportSaveRequest', async () => {
const unified = buildAppNormalizedListsFromJsonContent(
const unified = buildAppNormalizedListsFromJsonContent(
assembleFormListForSaveLists(engine, visibleList)
assembleFormListForSaveLists(engine, visibleList)
)
)
const subformOnly = lists => ({
const f29SubformRows = lists =>
fieldDataList: (lists.fieldDataList || []).filter(
(lists.subformDataList || []).filter(item => item.parentFieldKey === 'F2-9')
item => item.groupKey === 'F2-9' || item.parentFieldKey === 'F2-9'
assert.deepEqual(f29SubformRows(unified), f29SubformRows(legacy))
),
assert.ok(
subformDataList: lists.subformDataList || []
(unified.fieldDataList || []).every(item => !item.groupKey && item.fieldType !== 'subform')
})
)
assert.deepEqual(subformOnly(unified), subformOnly(legacy))
})
})
})
})
...
...
packageDynamicForm/tests/form-engine.test.mjs
View file @
02a10bd
This diff is collapsed.
Click to expand it.
packageDynamicForm/tests/group-show-rule-eval.test.mjs
View file @
02a10bd
...
@@ -75,4 +75,16 @@ describe('group-show-rule-eval', () => {
...
@@ -75,4 +75,16 @@ describe('group-show-rule-eval', () => {
false
false
)
)
})
})
it('IT-SHOW-RULE-005: double-quoted val1 == "在岗"', () => {
const rowFields = [{ key: 'F1-1', value: '在岗' }]
assert.equal(
evaluateShowRule(['F1-1'], 'val1 == "在岗"', rowFields, getRowFieldValue),
true
)
assert.equal(
evaluateShowRule(['F1-1'], 'val1 == "在岗"', [{ key: 'F1-1', value: '调休' }], getRowFieldValue),
false
)
})
})
})
packageDynamicForm/tests/hidden-clear.test.mjs
0 → 100644
View file @
02a10bd
import { describe, it } from 'node:test'
import assert from 'node:assert/strict'
import { loadSchemaFixture } from './schemaFixture.mjs'
describe('hidden field clear on linkage toggle', async () => {
const { createFormEngine } = await import('../form-engine/core.js')
const { buildAppDailySavePayload } = await import('../form-engine/app-daily-save.js')
const negotiationSchema = loadSchemaFixture('negotiation')
const staffSchema = loadSchemaFixture('staff')
const warrantyCtx = {
baseSceneCode: 110201,
brandIds: [3067, 3454],
sceneList: [{ baseSceneCode: 110201 }, { baseSceneCode: 110202 }]
}
const staffCtx = {
baseSceneCode: 100101,
brandIds: [3454],
merchantId: '100',
sceneList: [{ baseSceneCode: 100101 }]
}
it('IT-HIDDEN-CLEAR-001: F3-1 是否成交 是→否 clears deal fields in values and cache', () => {
const engine = createFormEngine(negotiationSchema)
engine.init(negotiationSchema, warrantyCtx)
const group = negotiationSchema.list.find(item => item.key === 'F3-1')
engine.addGroupRow(group)
engine.setGroupFieldValue('F3-1', 0, 'F3-1-10', '是')
engine.setGroupFieldValue('F3-1', 0, 'F3-1-12', '2026-06-01')
engine.setGroupFieldValue('F3-1', 0, 'F3-1-13', '订单A')
let state = engine.getViewState()
assert.equal(state.values['F3-1'][0]['F3-1-12'], '2026-06-01')
assert.equal(state.values['F3-1'][0]['F3-1-13'], '订单A')
engine.setGroupFieldValue('F3-1', 0, 'F3-1-10', '否')
engine.setGroupFieldValue('F3-1', 0, 'F3-1-11', '未成交原因')
state = engine.getViewState()
const rowMap = state.values['F3-1'][0]
assert.equal(rowMap['F3-1-10'], '否')
assert.equal(rowMap['F3-1-11'], '未成交原因')
assert.equal(rowMap['F3-1-12'], undefined)
assert.equal(rowMap['F3-1-13'], undefined)
const cacheRow = state.groupRowsCache['F3-1'][0]
const cacheKeys = cacheRow.map(field => field.key)
assert.ok(!cacheKeys.includes('F3-1-12'))
assert.ok(!cacheKeys.includes('F3-1-13'))
assert.ok(cacheKeys.includes('F3-1-11'))
})
it('IT-HIDDEN-CLEAR-002: staff 调休 clears rules.result hidden field values', () => {
const engine = createFormEngine(staffSchema)
engine.init(staffSchema, staffCtx)
engine.setFieldValue('F1-1', '在岗')
engine.setFieldValue('F1-5-1', 1)
engine.setFieldValue('F1-5-2', 2)
engine.setFieldValue('F1-5-3', 3)
let state = engine.getViewState()
assert.equal(state.values['F1-5-1'], 1)
engine.setFieldValue('F1-1', '调休')
state = engine.getViewState()
assert.equal(state.values['F1-1'], '调休')
assert.equal(state.values['F1-5-1'], undefined)
assert.equal(state.values['F1-5-2'], undefined)
assert.equal(state.values['F1-5-3'], undefined)
assert.equal(state.values['F1-2'], undefined)
})
it('IT-HIDDEN-CLEAR-003: save jsonContent excludes hidden subform cells after toggle', () => {
const engine = createFormEngine(negotiationSchema)
engine.init(negotiationSchema, warrantyCtx)
const group = negotiationSchema.list.find(item => item.key === 'F3-1')
engine.addGroupRow(group)
engine.setGroupFieldValue('F3-1', 0, 'F3-1-10', '是')
engine.setGroupFieldValue('F3-1', 0, 'F3-1-12', '2026-06-01')
engine.setGroupFieldValue('F3-1', 0, 'F3-1-13', '订单A')
engine.setGroupFieldValue('F3-1', 0, 'F3-1-10', '否')
engine.setGroupFieldValue('F3-1', 0, 'F3-1-11', '未成交原因')
const payload = buildAppDailySavePayload({
reportTemplateId: 10003,
engine
})
const jsonContent = JSON.parse(payload.jsonContent)
const f31 = jsonContent.find(item => item.key === 'F3-1')
assert.ok(f31)
const rowBag = f31.childrenValue?.[0]?.['F3-1'] || {}
assert.ok(Object.prototype.hasOwnProperty.call(rowBag, 'F3-1-10'))
assert.ok(Object.prototype.hasOwnProperty.call(rowBag, 'F3-1-11'))
assert.ok(!Object.prototype.hasOwnProperty.call(rowBag, 'F3-1-12'))
assert.ok(!Object.prototype.hasOwnProperty.call(rowBag, 'F3-1-13'))
})
})
packageDynamicForm/tests/store-app-json-content.test.mjs
View file @
02a10bd
import { describe, it } from 'node:test'
import { describe, it } from 'node:test'
import assert from 'node:assert/strict'
import assert from 'node:assert/strict'
import { createFormEngine } from '../form-engine/core.js'
import { createFormEngine } from '../form-engine/core.js'
import { buildDailyReportSaveRequest } from '../form-engine/save-request.js'
import { buildDailyReportSaveRequest
, parseRequestJsonLists
} from '../form-engine/save-request.js'
import { DAILY_REPORT_TEMPLATE_TYPE } from '../config/dailyReportConstants.js'
import { DAILY_REPORT_TEMPLATE_TYPE } from '../config/dailyReportConstants.js'
import { loadSchemaFixture } from './schemaFixture.mjs'
import { loadSchemaFixture } from './schemaFixture.mjs'
...
@@ -15,6 +15,8 @@ describe('store App jsonContent', () => {
...
@@ -15,6 +15,8 @@ describe('store App jsonContent', () => {
merchantId: '1001',
merchantId: '1001',
sceneList: [{ baseSceneCode: 110201 }]
sceneList: [{ baseSceneCode: 110201 }]
})
})
const f29Group = storeSchema.list.find(item => item.key === 'F2-9')
engine.addGroupRow(f29Group)
engine.setAppGroupFieldValue('F2-9', 0, 'F2-9-1', {
engine.setAppGroupFieldValue('F2-9', 0, 'F2-9-1', {
id: '4s-001',
id: '4s-001',
displayLabel: '交付专员A'
displayLabel: '交付专员A'
...
@@ -37,7 +39,7 @@ describe('store App jsonContent', () => {
...
@@ -37,7 +39,7 @@ describe('store App jsonContent', () => {
assert.equal(f29.value, undefined)
assert.equal(f29.value, undefined)
assert.deepEqual(f29.childrenValue[0]['F2-9']['F2-9-1'], {
assert.deepEqual(f29.childrenValue[0]['F2-9']['F2-9-1'], {
text: '交付专员A',
text: '交付专员A',
value:
{ id: '4s-001', name: '交付专员A' }
value:
'4s-001'
})
})
})
})
...
@@ -80,7 +82,8 @@ describe('store App jsonContent', () => {
...
@@ -80,7 +82,8 @@ describe('store App jsonContent', () => {
assert.ok(Array.isArray(f29.childrenValue))
assert.ok(Array.isArray(f29.childrenValue))
assert.equal(f29.children, undefined)
assert.equal(f29.children, undefined)
const f21List = request.fieldDataList.find(item => item.fieldKey === 'F2-1')
const requestLists = parseRequestJsonLists(request.requestJson)
const f21List = requestLists.fieldDataList.find(item => item.fieldKey === 'F2-1')
assert.ok(f21List)
assert.ok(f21List)
assert.deepEqual(JSON.parse(f21List.fieldValue), staffList)
assert.deepEqual(JSON.parse(f21List.fieldValue), staffList)
})
})
...
...
packageDynamicForm/tests/store-app-json-echo.test.mjs
View file @
02a10bd
...
@@ -13,6 +13,13 @@ import { createFormEngine } from '../form-engine/core.js'
...
@@ -13,6 +13,13 @@ import { createFormEngine } from '../form-engine/core.js'
import { buildDailyReportSaveRequest } from '../form-engine/save-request.js'
import { buildDailyReportSaveRequest } from '../form-engine/save-request.js'
import { DAILY_REPORT_TEMPLATE_TYPE } from '../config/dailyReportConstants.js'
import { DAILY_REPORT_TEMPLATE_TYPE } from '../config/dailyReportConstants.js'
import { isRowFieldsList } from '../form-engine/group-row-adapter.js'
import { isRowFieldsList } from '../form-engine/group-row-adapter.js'
function selectValueMapId(value) {
if (value != null && typeof value === 'object' && !Array.isArray(value)) {
return value.id ?? value.value
}
return value
}
import { loadSchemaFixture } from './schemaFixture.mjs'
import { loadSchemaFixture } from './schemaFixture.mjs'
const originChildren = [
const originChildren = [
...
@@ -120,7 +127,7 @@ describe('store App jsonContent subform echo', () => {
...
@@ -120,7 +127,7 @@ describe('store App jsonContent subform echo', () => {
engine.init(schema, { baseSceneCode: 110201, brandIds: [3454] })
engine.init(schema, { baseSceneCode: 110201, brandIds: [3454] })
const rows = engine.getGroupRows('F2-9')
const rows = engine.getGroupRows('F2-9')
assert.equal(rows.length, 1)
assert.equal(rows.length, 1)
assert.equal(
rows[0]['F2-9-1']
, 'uuid-staff-002')
assert.equal(
selectValueMapId(rows[0]['F2-9-1'])
, 'uuid-staff-002')
assert.equal(rows[0]['F2-9-2'], 3)
assert.equal(rows[0]['F2-9-2'], 3)
})
})
...
@@ -136,7 +143,7 @@ describe('store App jsonContent subform echo', () => {
...
@@ -136,7 +143,7 @@ describe('store App jsonContent subform echo', () => {
])
])
const values = parseJsonContentDetailValues(jsonContent, schemaRoot.list)
const values = parseJsonContentDetailValues(jsonContent, schemaRoot.list)
assert.equal(values['F2-9'].length, 1)
assert.equal(values['F2-9'].length, 1)
assert.equal(
values['F2-9'][0]['F2-9-1']
, '4s-001')
assert.equal(
selectValueMapId(values['F2-9'][0]['F2-9-1'])
, '4s-001')
assert.equal(values['F2-9'][0]['F2-9-2'], 2)
assert.equal(values['F2-9'][0]['F2-9-2'], 2)
})
})
...
@@ -156,7 +163,7 @@ describe('store App jsonContent subform echo', () => {
...
@@ -156,7 +163,7 @@ describe('store App jsonContent subform echo', () => {
]
]
}
}
const values = parseJsonContentDetailValues(JSON.stringify(wrapped), schemaRoot.list)
const values = parseJsonContentDetailValues(JSON.stringify(wrapped), schemaRoot.list)
assert.equal(
values['F2-9'][0]['F2-9-1']
, '4s-001')
assert.equal(
selectValueMapId(values['F2-9'][0]['F2-9-1'])
, '4s-001')
assert.equal(values['F2-9'][0]['F2-9-2'], 4)
assert.equal(values['F2-9'][0]['F2-9-2'], 4)
})
})
...
@@ -240,6 +247,6 @@ describe('store App jsonContent subform echo', () => {
...
@@ -240,6 +247,6 @@ describe('store App jsonContent subform echo', () => {
)
)
const values = parseJsonContentDetailValues(jsonContent, [])
const values = parseJsonContentDetailValues(jsonContent, [])
assert.equal(values['F2-9'][0]['F2-9-2'], 5)
assert.equal(values['F2-9'][0]['F2-9-2'], 5)
assert.
deepEqual(values['F2-9'][0]['F2-9-1'], { id: '4s-001', name: '交付专员A' }
)
assert.
equal(selectValueMapId(values['F2-9'][0]['F2-9-1']), '4s-001'
)
})
})
})
})
packageDynamicForm/tests/storeDailyReportAdapters.test.mjs
View file @
02a10bd
...
@@ -407,6 +407,56 @@ describe('storeDailyReportAdapters', () => {
...
@@ -407,6 +407,56 @@ describe('storeDailyReportAdapters', () => {
}
}
})
})
it('IT-STORE-DRAFT-003: saveDraftAdapter passes requestJson from buildDailyReportSaveRequest', async () => {
const { createFormEngine } = await import('../form-engine/core.js')
const { buildDailyReportSaveRequest, parseRequestJsonLists } = require(
'../form-engine/save-request.js'
)
const engine = createFormEngine(schemaTemplate)
engine.setPageContext({
baseSceneCode: 110201,
brandIds: [3454],
merchantId: 1001,
sceneList: [{ baseSceneCode: 110201 }]
})
engine.setFieldValue('F2-2', 3)
const { request: saveRequest } = buildDailyReportSaveRequest({
reportDate: '2026-05-27',
userContext: { merchantId: 1001, staffUuid: 's1', staffName: '李四' },
pageContext: { merchantId: 1001 },
engine,
reportTemplateId: 10002,
templateType: DAILY_REPORT_TEMPLATE_TYPE.store
})
assert.ok(typeof saveRequest.requestJson === 'string')
assert.equal(saveRequest.fieldDataList, undefined)
const lists = parseRequestJsonLists(saveRequest.requestJson)
assert.ok(lists.fieldDataList.length > 0)
const original = STORE_DAILY_API_SWITCH.save
STORE_DAILY_API_SWITCH.save = 'real'
let captured = null
adapters.__setDynamicDailyReportApi({
dynamicDailyReportDraftSave: async data => {
captured = data
return { code: 0, message: 'ok', data: { dailyReportRecordId: 88003 } }
}
})
try {
const res = await adapters.saveDraftAdapter(saveRequest)
assert.equal(res.code, 0)
assert.ok(typeof captured.requestJson === 'string')
assert.equal(captured.fieldDataList, undefined)
assert.deepEqual(
parseRequestJsonLists(captured.requestJson).fieldDataList,
lists.fieldDataList
)
} finally {
adapters.__setDynamicDailyReportApi(null)
STORE_DAILY_API_SWITCH.save = original
}
})
it('IT-STORE-DRAFT-002: saveDraftAdapter mock save does not call HTTP', async () => {
it('IT-STORE-DRAFT-002: saveDraftAdapter mock save does not call HTTP', async () => {
const original = STORE_DAILY_API_SWITCH.save
const original = STORE_DAILY_API_SWITCH.save
STORE_DAILY_API_SWITCH.save = 'mock'
STORE_DAILY_API_SWITCH.save = 'mock'
...
...
packageDynamicForm/tests/storeDailyReportDetail.test.mjs
View file @
02a10bd
...
@@ -12,6 +12,13 @@ const { isReportSubmitted, normalizeReportStatus } = require('../utils/report-st
...
@@ -12,6 +12,13 @@ const { isReportSubmitted, normalizeReportStatus } = require('../utils/report-st
const { DEFAULT_REPORT_TEMPLATE_ID } = require('../api/mockStoreDynamicDetail.js')
const { DEFAULT_REPORT_TEMPLATE_ID } = require('../api/mockStoreDynamicDetail.js')
const { loadSchemaFixture } = await import('./schemaFixture.mjs')
const { loadSchemaFixture } = await import('./schemaFixture.mjs')
function selectValueMapId(value) {
if (value != null && typeof value === 'object' && !Array.isArray(value)) {
return value.id ?? value.value
}
return value
}
function normalizeDetailResponse(detail = {}, reportTemplateId) {
function normalizeDetailResponse(detail = {}, reportTemplateId) {
const recordId = detail.dailyReportRecordId ?? detail.id ?? null
const recordId = detail.dailyReportRecordId ?? detail.id ?? null
const jsonContent = detail.jsonContent || ''
const jsonContent = detail.jsonContent || ''
...
@@ -150,7 +157,7 @@ describe('storeDailyReport detail response', () => {
...
@@ -150,7 +157,7 @@ describe('storeDailyReport detail response', () => {
brandIds: [3067, 3454],
brandIds: [3067, 3454],
sceneList: [{ baseSceneCode: 110201 }]
sceneList: [{ baseSceneCode: 110201 }]
})
})
assert.equal(
viewState.values['F2-9'][0]['F2-9-1']
, '4s-002')
assert.equal(
selectValueMapId(viewState.values['F2-9'][0]['F2-9-1'])
, '4s-002')
})
})
})
})
...
...
packageDynamicForm/tests/visibility-specs.test.mjs
View file @
02a10bd
...
@@ -2,25 +2,36 @@
...
@@ -2,25 +2,36 @@
import assert from 'node:assert/strict'
import assert from 'node:assert/strict'
import {
import {
attendanceGateSpec,
baseSceneSpec,
baseSceneSpec,
brandSpec,
brandSpec,
detailEchoSpec,
detailEchoSpec,
fieldShowRuleSpec,
isFieldVisibleBySpecs
isFieldVisibleBySpecs
} from '../form-engine/visibility/specs/index.js'
} from '../form-engine/visibility/specs/index.js'
import { ATTENDANCE_KEY } from '../form-engine/visibility.js'
import { loadSchemaFixture } from './schemaFixture.mjs'
const staffSchema = loadSchemaFixture('staff')
describe('visibility specs', () => {
describe('visibility specs', () => {
it('IT-VIS-SPEC-001: attendance gate hides non-F1-1 when off duty', () => {
it('IT-VIS-SPEC-001: fieldShowRuleSpec hides fields with on-duty result when off duty', () => {
const field = { key: 'F1-2', type: 'numberInput' }
const field = { key: 'F1-2', type: 'numberInput', rules: { keys: ['F1-1'], result: 'val1 == "在岗"' } }
const options = { hasAttendanceField: true, attendanceOnDuty: false }
const options = { schemaList: staffSchema.list }
assert.equal(attendanceGateSpec(field, {}, {}, options), false)
assert.equal(
fieldShowRuleSpec(field, {}, { 'F1-1': '调休' }, options),
false
)
assert.equal(
assert.equal(
attendanceGateSpec({ key: ATTENDANCE_KEY }, {}, {
}, options),
fieldShowRuleSpec(field, {}, { 'F1-1': '在岗'
}, options),
true
true
)
)
})
})
it('IT-VIS-SPEC-001b: field without rules.result stays visible when off duty', () => {
const field = staffSchema.list.find(item => item.key === 'F1-4')
const options = { schemaList: staffSchema.list }
assert.equal(fieldShowRuleSpec(field, {}, { 'F1-1': '调休' }, options), true)
})
it('IT-VIS-SPEC-002: brandId requires intersection', () => {
it('IT-VIS-SPEC-002: brandId requires intersection', () => {
const field = { key: 'x', brandId: [1, 2] }
const field = { key: 'x', brandId: [1, 2] }
assert.equal(brandSpec(field, { brandIds: [2, 3] }), true)
assert.equal(brandSpec(field, { brandIds: [2, 3] }), true)
...
@@ -44,18 +55,23 @@ describe('visibility specs', () => {
...
@@ -44,18 +55,23 @@ describe('visibility specs', () => {
})
})
it('IT-STAFF-OFF-001: on-duty passes detail echo when key not in echoTopLevelKeys', () => {
it('IT-STAFF-OFF-001: on-duty passes detail echo when key not in echoTopLevelKeys', () => {
const field = { key: 'F1-5', type: 'group', brandId: [3454] }
const field = { key: 'F1-5', type: 'group', brandId: [3454]
, rules: { keys: ['F1-1'], result: 'val1 == "在岗"' }
}
const ctx = {
const ctx = {
hasDetailEcho: true,
hasDetailEcho: true,
echoTopLevelKeys: ['F1-1']
echoTopLevelKeys: ['F1-1']
}
}
const options = { hasAttendanceField: true, attendanceOnDuty: true }
const values = { 'F1-1': '在岗' }
assert.equal(detailEchoSpec(field, ctx, { 'F1-1': '在岗' }, options), null)
const options = {
schemaList: staffSchema.list,
hasAttendanceField: true,
attendanceOnDuty: true
}
assert.equal(detailEchoSpec(field, ctx, values, options), null)
assert.equal(
assert.equal(
isFieldVisibleBySpecs(
isFieldVisibleBySpecs(
field,
field,
{ ...ctx, brandIds: [3454], sceneList: [{ baseSceneCode: 100101 }] },
{ ...ctx, brandIds: [3454], sceneList: [{ baseSceneCode: 100101 }] },
{ 'F1-1': '在岗' }
,
values
,
options
options
),
),
true
true
...
...
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