ARCHITECTURE.md
5.11 KB
packageDynamicForm 架构与数据流
分层职责
| 层 | 目录 | 职责 |
|---|---|---|
| Page | pages/*DailyReport*.js |
周历、只读态、loadSeq 竞态、buildFormRequestContext、engine.init、提交 |
| Loader | services/*FormLoader.js |
并行 bootstrap(brand/scene/detail)→ pageContext → schema |
| API 门面 | api/*DailyReport.js |
页面/Loader 调用的稳定方法;组装 pageContext、save payload |
| Adapter | api/*DailyReportAdapters.js |
mock/real 分支;sceneCache / schemaCache / brandCache
|
| Engine | form-engine/ |
显隐、values、校验、normalized save payload |
| Field UI | components/form-field-* |
按 schema type 渲染;optionsKey → fieldOptionsService
|
| Config |
config/apiSwitch.js configCenter.js
|
联调开关、配置中心 schema 拉取与 indexed → list 转换 |
端到端序列(切日期加载)
sequenceDiagram
participant Page as DailyReportPage
participant Loader as FormLoader
participant API as DailyReportApi
participant Adapter as Adapters
participant Engine as formEngine
participant UI as dynamicForm
Page->>Page: dayClick / lastWeek / nextWeek
Page->>Page: loadFormData loadSeq++
Page->>Loader: loadXxxDailyForm
par bootstrap
Loader->>API: fetchMerchantBrandIds
API->>Adapter: fetchBrandAdapter
Loader->>API: fetchMerchantScene
API->>Adapter: fetchSceneAdapter
Loader->>API: fetchReportDetail
API->>Adapter: fetchDetailAdapter
end
Loader->>API: fetchPageContext
Loader->>API: fetchSchema
API->>Adapter: fetchSchemaRootAdapter
Loader-->>Page: pageContext schema detail
Page->>Engine: init schema pageContext
Page->>UI: applyEngineView fixedFields groupFields values
写入与保存
sequenceDiagram
participant UI as formField
participant Page as DailyReportPage
participant Engine as formEngine
participant Assemble as assembleFormListForSaveLists
participant Submit as buildAppDailyReportSubmitPayload
participant Save as buildDailyReportSaveRequest
UI->>Page: change / groupchange
Page->>Engine: setFieldValue / setGroupFieldValue
Page->>Page: submit or saveDraft
Page->>Engine: validate
Page->>Assemble: formList 含 subform.children
Page->>Submit: formList
Submit->>Submit: lists 再 serialize childrenValue
Page->>Save: jsonContent fieldDataList subformDataList
Save->>Adapter: dynamic.save or dynamic.draft.save
详见 daily-report-save-and-json.md。
真接口约定(摘要)
| 能力 | 形态 | 入口 |
|---|---|---|
| Schema | 配置中心数字键 { "0": field, ... } → { list }
|
configCenter.normalizeConfigToSchemaRoot |
| 主营品牌 | merchants.api.open.merchant.info |
carBrandApi → fetchBrandAdapter(按 merchantId 缓存) |
| 详情 |
detail.get + jsonContent + subformDataList
|
fetchDetailAdapter → parseJsonContentDetailValues
|
| 场景 | findAllSceneByMerchantId |
fetchSceneAdapter(按 merchantId 缓存) |
| 周历 | dailyReport.weekly.list |
fetchWeeklyAdapter(页面独立刷新,不在 Loader 内) |
| 字段选项 |
getEmployeeList 等 |
fieldOptionsAdapters + fieldOptionProviders
|
字段类型要点
select / multipleSelect
-
select:标量string;form-picker-popup mode="single";归一化见form-engine/select-value.js。 -
multipleSelect:数组string[];mode="multiple";展示用/拼接 label。 - 选项接口见 field-options-api.md(
storeStaffList、4sStaffList等)。
subform(group-repeater)
- schema
type: subform;行数据在values[groupKey]与groupRowsCache双写。 -
入库 jsonContent:
childrenValue+origin_children(无children);lists 由序列化前含children的 formList 生成。 -
回显:
mergeAppJsonIntoSchema/getSectionRowFieldsList(兼容childrenValue与旧children)→parseJsonContentDetailValues。 - UI 与行数上限详见 group-repeater.md;保存全链路见 daily-report-save-and-json.md。
radio / 出勤显隐
- 配置中心可能用中文 label 作 value;
radio-value.js归一化。 - 驻店
F1-1调休时隐藏其余字段:visibility.js。
Adapter 缓存
| 缓存 | Key | 说明 |
|---|---|---|
| sceneCache | merchantId | 切日期不重复打场景接口 |
| schemaCache | moduleUrl + baseSceneCode | 同场景 schema 复用 |
| brandCache | merchantId | 切日期不重复打 merchant.info |
三页各自 *DailyReportCache.js;单测 beforeEach 需 clear*DailyReportCache()。
相关单测模块
| 模块 | 测试文件 |
|---|---|
| form-engine | tests/form-engine.test.mjs |
| adapters |
tests/staffDailyReportAdapters.test.mjs storeDailyReportAdapters.test.mjs
|
| loaders |
tests/staffDailyFormLoader.test.mjs storeDailyFormLoader.test.mjs
|
| fieldOptions | tests/fieldOptionsAdapters.test.mjs |
| 菜单路由 | tests/dynamicFormMenus.test.mjs |
完整索引:integration-test-plan.md。