Commit 810a10f2 by 张立顺

fix: align store daily subform rules

1 parent 9beda67d
...@@ -126,7 +126,7 @@ Expected: FAIL because `resolve_sheet_config` and `select_v230_records` do not e ...@@ -126,7 +126,7 @@ Expected: FAIL because `resolve_sheet_config` and `select_v230_records` do not e
), 'store', None) ), 'store', None)
self.assertEqual(tags['type'], 'multipleSelect') self.assertEqual(tags['type'], 'multipleSelect')
self.assertEqual(tags['options'][0], {'label': '已触客', 'value': '已触客'}) self.assertEqual(tags['options'][0], {'label': '已触客', 'value': '已触客'})
self.assertEqual(tags['options'][1]['sourceRule'], '业务分类=轻改 and 品牌=鸿蒙智行 则显示') self.assertNotIn('sourceRule', tags['options'][1])
``` ```
- [ ] **Step 4: Add failing assembly and JS-emission assertions** - [ ] **Step 4: Add failing assembly and JS-emission assertions**
...@@ -239,11 +239,11 @@ TYPE_MAP.update({ ...@@ -239,11 +239,11 @@ TYPE_MAP.update({
- `仅限11位手机号` changes `input` to `phoneInput`. - `仅限11位手机号` changes `input` to `phoneInput`.
- `输入不超过N字` adds `rules.maxLength = N`. - `输入不超过N字` adds `rules.maxLength = N`.
- date text `仅允许选择当前及过去日期` adds `maxDate: today` and `format: date`. - date text `仅允许选择当前及过去日期` adds `maxDate: today` and `format: date` to the child field; the parent subform `childrenRules` uses legacy-compatible `maxDate: 'new Date()'`.
- VIN scan text adds `prefixComponent: scan`. - VIN scan text adds `prefixComponent: scan`.
- `其他规则` containing picker mode `多选` changes `select` to `multipleSelect`. - `其他规则` containing picker mode `多选` changes `select` to `multipleSelect`.
- multiline fixed options strip `选项N:` and store parenthesized annotations as `sourceRule`. - multiline fixed options strip `选项N:` and parenthesized annotations from submitted option values; do not emit the unsupported `sourceRule` field.
- non-static defaults `每月首日...` and `当前用户` become `sourceDefaultRule`; do not set a fake `value`. - non-static defaults `每月首日...` and `当前用户` do not set a fake `value` or emit the unsupported `sourceDefaultRule` field.
- [ ] **Step 4: Add V2.3.0 subform show rules** - [ ] **Step 4: Add V2.3.0 subform show rules**
...@@ -282,9 +282,9 @@ V230_STORE_CHILD_SHOW_RULES = { ...@@ -282,9 +282,9 @@ V230_STORE_CHILD_SHOW_RULES = {
Attach only rules whose target child exists in the assembled subform. Attach only rules whose target child exists in the assembled subform.
- [ ] **Step 5: Make JS emission valid for new metadata** - [ ] **Step 5: Make JS emission valid for supported metadata**
Add `prefixComponent`, `sourceDefaultRule`, and `childrenShowRules` to field property order. Add a dedicated emitter that quotes child keys containing hyphens. Extend option emission to include `sourceRule` when present. Add `prefixComponent` and `childrenShowRules` to field property order. Add a dedicated emitter that quotes child keys containing hyphens and emits `childrenShowRules.result` with outer double quotes and inner single quotes. Keep option emission limited to the supported `label` and `value` properties; do not emit metadata fields that the runtime schema does not consume.
- [ ] **Step 6: Wire CLI version metadata and output paths** - [ ] **Step 6: Wire CLI version metadata and output paths**
...@@ -348,7 +348,7 @@ assert.deepEqual(production.list.find(field => field.key === 'F2-103').brandId, ...@@ -348,7 +348,7 @@ assert.deepEqual(production.list.find(field => field.key === 'F2-103').brandId,
[2695, 2741, 2698, 2797, 2740, 2188]) [2695, 2741, 2698, 2797, 2740, 2188])
``` ```
Also assert `sourceDefaultRule`, option `sourceRule`, `F2-102` filterBrandId/baseSceneCode, static option values, and all eight child show-rule keys. Also assert the absence of unsupported `sourceDefaultRule`/option `sourceRule`, plus `F2-102` filterBrandId/baseSceneCode, static option values, and all eight child show-rule keys.
- [ ] **Step 2: Run the fixture test and verify RED** - [ ] **Step 2: Run the fixture test and verify RED**
......
...@@ -81,14 +81,14 @@ daily/production 只允许品牌 ID 映射不同,字段结构、顺序和规 ...@@ -81,14 +81,14 @@ daily/production 只允许品牌 ID 映射不同,字段结构、顺序和规
- 非负整数映射为 `{ "min": 0, "integer": true }`。 - 非负整数映射为 `{ "min": 0, "integer": true }`。
- 文本长度限制映射到 `rules.maxLength`。 - 文本长度限制映射到 `rules.maxLength`。
- 手机号使用 `phoneInput`,由现有手机号校验实现 11 位号码校验。 - 手机号使用 `phoneInput`,由现有手机号校验实现 11 位号码校验。
- 日期规则映射为 `{ "maxDate": "today", "format": "date" }`。 - 日期字段自身规则映射为 `{ "maxDate": "today", "format": "date" }`;子表单父级 `childrenRules` 按旧引擎协议写为 `{ "maxDate": "new Date()", "format": "date" }`。
- `F2-102` 的动态默认值规则和 `F2-107-6` 的“当前用户”默认值当前不能由 schema 运行时直接执行;模板使用 `sourceDefaultRule` 原样保存 Excel 规则,不伪造静态 `value`。 - `F2-102` 的动态默认值规则和 `F2-107-6` 的“当前用户”默认值当前不能由 schema 运行时直接执行;模板不伪造静态 `value`,也不输出非协议且运行时不消费的 `sourceDefaultRule`。动态默认值规则暂以 Excel 原文为准。
### 选项 ### 选项
- `固定值: A, B` 解析为 `{ label, value }[]`。 - `固定值: A, B` 解析为 `{ label, value }[]`。
- 多行 `固定值 / - 选项N:` 格式按行解析,去掉“选项N”前缀。 - 多行 `固定值 / - 选项N:` 格式按行解析,去掉“选项N”前缀。
- Excel 中选项后的场景/品牌说明从展示文案中剥离,并使用 `sourceRule` 保留在该 option 上,避免把说明文本当成实际提交值。 - Excel 中选项后的场景/品牌说明从展示文案和提交值中剥离,不输出非协议且运行时不消费的 `sourceRule`;条件说明暂以 Excel 和本设计文档为准。
- 动态选项继续使用 `storeStaffList`、`4sStaffList`。 - 动态选项继续使用 `storeStaffList`、`4sStaffList`。
### 品牌与场景 ### 品牌与场景
...@@ -103,7 +103,7 @@ daily/production 只允许品牌 ID 映射不同,字段结构、顺序和规 ...@@ -103,7 +103,7 @@ daily/production 只允许品牌 ID 映射不同,字段结构、顺序和规
### 子表单联动 ### 子表单联动
`F2-107` 的同一行字段依赖写入 `childrenShowRules`,`keys` 按 Excel 条件引用的字段顺序排列,`result` 使用现有 `valN` 表达式风格。 `F2-107` 的同一行字段依赖写入 `childrenShowRules`,`keys` 按 Excel 条件引用的字段顺序排列,`result` 使用现有 `valN` 表达式风格。JS 产物按旧模板格式使用双引号包裹 `result`,条件值使用单引号,不生成 `\'` 形式。
需要生成规则的字段包括: 需要生成规则的字段包括:
......
# DEVLOG — packageDynamicForm # DEVLOG — packageDynamicForm
## 2026-08-10 — 门店日报 V2.3.0 子表单规则兼容
- **模板输出**:`childrenShowRules.result` 改为旧配置格式(外层双引号、条件值单引号),不再生成 `\'`;子表单日期校验在父级 `childrenRules` 输出 `maxDate: 'new Date()'`。
- **小程序求值**:本地安全解析器新增 `||`、`Array.isArray`、`includes`、`!` 和括号支持,覆盖 F2-107 的 8 条行内显隐规则;仍不使用 `eval/new Function`。
- **规则来源**:配置中心模板的 `childrenRules` 经 `normalizeSchemaRoot` 合并到子字段 `rules`,日期 `new Date()` 归一为仅日期校验使用的 `today`。
- **单测**:`group-show-rule-eval-fallback.test.mjs`、`store-v230-template-schema.test.mjs`、`test_store_v230_converter.py`。
## 2026-07-23 — 门店日报上报:save 后 detail.get 再 push ## 2026-07-23 — 门店日报上报:save 后 detail.get 再 push
- **上报**:`dynamic.save` 成功后 `fetchReportDetail` 取 `dailyReportRecordId`,再 `dynamic.data.push`(仅 id) - **上报**:`dynamic.save` 成功后 `fetchReportDetail` 取 `dailyReportRecordId`,再 `dynamic.data.push`(仅 id)
......
...@@ -79,7 +79,9 @@ c:/Users/admin/Downloads/门店工作汇报模板-V2.1.1.xlsx ...@@ -79,7 +79,9 @@ c:/Users/admin/Downloads/门店工作汇报模板-V2.1.1.xlsx
| 日期时间 | `date`(当前及过去日期→ `rules.maxDate: "today"`) | | 日期时间 | `date`(当前及过去日期→ `rules.maxDate: "today"`) |
| 级联选择 | `carBrandSelect` | | 级联选择 | `carBrandSelect` |
V2.3.0 选择器的单选/多选以“其他规则”列为准;多行“固定值 / 选项N”会拆成 `options`,选项后的场景/品牌说明保存为 `sourceRule`。动态默认值(如“当前用户”、“最近一次提交数值”)保存为 `sourceDefaultRule`,不伪造静态 `value`。 V2.3.0 选择器的单选/多选以“其他规则”列为准;多行“固定值 / 选项N”会拆成 `options`,选项后的场景/品牌说明会从提交值中剥离。动态默认值(如“当前用户”、“最近一次提交数值”)不伪造静态 `value`。生成器不会输出非协议、运行时不消费的 `sourceRule`、`sourceDefaultRule`;原始说明仍以 Excel 为准,待运行时存在正式协议后再接入。
V2.3.0 子表单的子字段校验同时汇总到父级 `childrenRules`;日期字段在该索引中按旧引擎协议输出 `maxDate: 'new Date()'`。`childrenShowRules.result` 使用外层双引号、表达式内部单引号,避免配置中心旧解析器无法处理 `\'`。
--- ---
......
...@@ -85,7 +85,7 @@ values['F2-9'] = [ ...@@ -85,7 +85,7 @@ values['F2-9'] = [
## childrenShowRules 求值 ## childrenShowRules 求值
- 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) 内置安全解析器处理,不使用 `eval/new Function`。支持 `valN == '…'`、`valN != null`、`Array.isArray(valN)`、`valN.includes('…')`、`!`、`&&`、`||` 与括号;小程序与 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。 - **联动切换清值**:`childrenShowRules` 导致某 cell 不可见时,[`clearHiddenSubformRowValues`](../form-engine/values.js) 在 `refreshValues` / `applyVisibilityClearing` 中删除 `values[groupKey][row]` 对应 key 并 `rebuildGroupRowsCache`;保存时 [`buildAppJsonContent`](../form-engine/app-subform-json.js) 对每行再 `filterVisibleRowFields` 防御历史脏 cache。
......
...@@ -57,7 +57,7 @@ ...@@ -57,7 +57,7 @@
| Schema 能力 | 实现 | 说明 | | Schema 能力 | 实现 | 说明 |
|-------------|------|------| |-------------|------|------|
| `childrenShowRules` | `group-visibility.js` + `group-show-rule-eval.js` | 小程序用 fallback 解析 `val1 == '是'` 等;与 F3-*-10/11/12/13 链一致 | | `childrenShowRules` | `group-visibility.js` + `group-show-rule-eval.js` | 小程序用安全解析器处理比较、数组包含、`!`、`&&`、`||` 与括号;与 F3-*-10/11/12/13 链一致 |
| `childrenRules` | `schema-normalizer.js` + `field-format-rules.js` | `maxDate: new Date()` → `today`;`type: date` + `format: date` → 仅日期 picker | | `childrenRules` | `schema-normalizer.js` + `field-format-rules.js` | `maxDate: new Date()` → `today`;`type: date` + `format: date` → 仅日期 picker |
| `optionsKey` storeStaffList / 4sStaffList | `fieldOptionsAdapters.js` | `getEmployeeList` | | `optionsKey` storeStaffList / 4sStaffList | `fieldOptionsAdapters.js` | `getEmployeeList` |
| `optionsKey` orderList | `form-field-select.js` → `fetchOrderListOptions` | 须先选成交日期 F3-*-12 | | `optionsKey` orderList | `form-field-select.js` → `fetchOrderListOptions` | 须先选成交日期 F3-*-12 |
......
...@@ -57,7 +57,6 @@ ...@@ -57,7 +57,6 @@
brandId: [], brandId: [],
baseSceneCode: [100101, 100102, 100103], baseSceneCode: [100101, 100102, 100103],
//[门店经营品牌 包含 岚图 or 其他品牌] and [场景 包含 1.1 or 1.2 or 1.3] 则 [显示] //[门店经营品牌 包含 岚图 or 其他品牌] and [场景 包含 1.1 or 1.2 or 1.3] 则 [显示]
sourceDefaultRule: '每月首日: 0\n每月非首日: 最近一次提交数值',
rules: { rules: {
min: 0, min: 0,
integer: true integer: true
...@@ -166,7 +165,7 @@ ...@@ -166,7 +165,7 @@
maxLength: 11 maxLength: 11
}, },
'F2-107-4': { 'F2-107-4': {
maxDate: 'today', maxDate: 'new Date()',
format: 'date' format: 'date'
}, },
'F2-107-8': { 'F2-107-8': {
...@@ -179,35 +178,35 @@ ...@@ -179,35 +178,35 @@
childrenShowRules: { childrenShowRules: {
'F2-107-4': { 'F2-107-4': {
keys: ['F2-107-3'], keys: ['F2-107-3'],
result: 'val1 == \'交付端引流-售前\' || val1 == \'门店引流-售前\'' result: "val1 == '交付端引流-售前' || val1 == '门店引流-售前'"
}, },
'F2-107-12': { 'F2-107-12': {
keys: ['F2-107-7'], keys: ['F2-107-7'],
result: 'Array.isArray(val1) && (val1.includes(\'已触客\') || val1.includes(\'已交付引荐\'))' result: "Array.isArray(val1) && (val1.includes('已触客') || val1.includes('已交付引荐'))"
}, },
'F2-107-13': { 'F2-107-13': {
keys: ['F2-107-7'], keys: ['F2-107-7'],
result: 'Array.isArray(val1) && val1.includes(\'已交付引荐\')' result: "Array.isArray(val1) && val1.includes('已交付引荐')"
}, },
'F2-107-14': { 'F2-107-14': {
keys: ['F2-107-13'], keys: ['F2-107-13'],
result: 'val1 == \'否\'' result: "val1 == '否'"
}, },
'F2-107-15': { 'F2-107-15': {
keys: ['F2-107-7'], keys: ['F2-107-7'],
result: 'Array.isArray(val1) && val1.includes(\'已触客\')' result: "Array.isArray(val1) && val1.includes('已触客')"
}, },
'F2-107-16': { 'F2-107-16': {
keys: ['F2-107-15'], keys: ['F2-107-15'],
result: 'val1 == \'否\'' result: "val1 == '否'"
}, },
'F2-107-17': { 'F2-107-17': {
keys: ['F2-107-7'], keys: ['F2-107-7'],
result: '!Array.isArray(val1) || !val1.includes(\'已触客\')' result: "!Array.isArray(val1) || !val1.includes('已触客')"
}, },
'F2-107-18': { 'F2-107-18': {
keys: ['F2-107-7'], keys: ['F2-107-7'],
result: 'Array.isArray(val1) && val1.includes(\'已触客\')' result: "Array.isArray(val1) && val1.includes('已触客')"
} }
}, },
children: [ children: [
...@@ -252,23 +251,19 @@ ...@@ -252,23 +251,19 @@
options: [ options: [
{ {
label: '销售端引流-售前', label: '销售端引流-售前',
value: '销售端引流-售前', value: '销售端引流-售前'
sourceRule: '场景=轻改'
}, },
{ {
label: '交付端引流-售前', label: '交付端引流-售前',
value: '交付端引流-售前', value: '交付端引流-售前'
sourceRule: '场景=轻改'
}, },
{ {
label: '门店引流-售前', label: '门店引流-售前',
value: '门店引流-售前', value: '门店引流-售前'
sourceRule: '场景=延保or广联权益'
}, },
{ {
label: '门店引流-售后', label: '门店引流-售后',
value: '门店引流-售后', value: '门店引流-售后'
sourceRule: '场景=延保or广联权益'
} }
], ],
rules: {}, rules: {},
...@@ -314,7 +309,6 @@ ...@@ -314,7 +309,6 @@
baseSceneCode: [], baseSceneCode: [],
options: [], options: [],
optionsKey: 'storeStaffList', optionsKey: 'storeStaffList',
sourceDefaultRule: '当前用户',
rules: {}, rules: {},
}, },
...@@ -334,23 +328,19 @@ ...@@ -334,23 +328,19 @@
}, },
{ {
label: '已拉群', label: '已拉群',
value: '已拉群', value: '已拉群'
sourceRule: '业务分类=轻改 and 品牌=鸿蒙智行 则显示'
}, },
{ {
label: '已交付引荐', label: '已交付引荐',
value: '已交付引荐', value: '已交付引荐'
sourceRule: '业务分类=轻改 and 品牌=岚图or其他 则不显示'
}, },
{ {
label: '首保维保客户', label: '首保维保客户',
value: '首保维保客户', value: '首保维保客户'
sourceRule: '业务分类=轻改 and 品牌=鸿蒙智行 则显示'
}, },
{ {
label: '事故车客户', label: '事故车客户',
value: '事故车客户', value: '事故车客户'
sourceRule: '业务分类=轻改 and 品牌=鸿蒙智行 则显示'
} }
], ],
rules: {}, rules: {},
......
...@@ -41,8 +41,7 @@ ...@@ -41,8 +41,7 @@
3458, 3458,
3574, 3574,
3502 3502
], ]
"sourceDefaultRule": "每月首日: 0\n每月非首日: 最近一次提交数值"
}, },
{ {
"label": "明日预计交付数", "label": "明日预计交付数",
...@@ -188,23 +187,19 @@ ...@@ -188,23 +187,19 @@
"options": [ "options": [
{ {
"label": "销售端引流-售前", "label": "销售端引流-售前",
"value": "销售端引流-售前", "value": "销售端引流-售前"
"sourceRule": "场景=轻改"
}, },
{ {
"label": "交付端引流-售前", "label": "交付端引流-售前",
"value": "交付端引流-售前", "value": "交付端引流-售前"
"sourceRule": "场景=轻改"
}, },
{ {
"label": "门店引流-售前", "label": "门店引流-售前",
"value": "门店引流-售前", "value": "门店引流-售前"
"sourceRule": "场景=延保or广联权益"
}, },
{ {
"label": "门店引流-售后", "label": "门店引流-售后",
"value": "门店引流-售后", "value": "门店引流-售后"
"sourceRule": "场景=延保or广联权益"
} }
] ]
}, },
...@@ -246,8 +241,7 @@ ...@@ -246,8 +241,7 @@
"baseSceneCode": [], "baseSceneCode": [],
"rules": {}, "rules": {},
"optionsKey": "storeStaffList", "optionsKey": "storeStaffList",
"options": [], "options": []
"sourceDefaultRule": "当前用户"
}, },
{ {
"label": "客户标签", "label": "客户标签",
...@@ -266,23 +260,19 @@ ...@@ -266,23 +260,19 @@
}, },
{ {
"label": "已拉群", "label": "已拉群",
"value": "已拉群", "value": "已拉群"
"sourceRule": "业务分类=轻改 and 品牌=鸿蒙智行 则显示"
}, },
{ {
"label": "已交付引荐", "label": "已交付引荐",
"value": "已交付引荐", "value": "已交付引荐"
"sourceRule": "业务分类=轻改 and 品牌=岚图or其他 则不显示"
}, },
{ {
"label": "首保维保客户", "label": "首保维保客户",
"value": "首保维保客户", "value": "首保维保客户"
"sourceRule": "业务分类=轻改 and 品牌=鸿蒙智行 则显示"
}, },
{ {
"label": "事故车客户", "label": "事故车客户",
"value": "事故车客户", "value": "事故车客户"
"sourceRule": "业务分类=轻改 and 品牌=鸿蒙智行 则显示"
} }
] ]
}, },
...@@ -534,7 +524,7 @@ ...@@ -534,7 +524,7 @@
"maxLength": 11 "maxLength": 11
}, },
"F2-107-4": { "F2-107-4": {
"maxDate": "today", "maxDate": "new Date()",
"format": "date" "format": "date"
}, },
"F2-107-8": { "F2-107-8": {
......
...@@ -57,7 +57,6 @@ ...@@ -57,7 +57,6 @@
brandId: [], brandId: [],
baseSceneCode: [100101, 100102, 100103], baseSceneCode: [100101, 100102, 100103],
//[门店经营品牌 包含 岚图 or 其他品牌] and [场景 包含 1.1 or 1.2 or 1.3] 则 [显示] //[门店经营品牌 包含 岚图 or 其他品牌] and [场景 包含 1.1 or 1.2 or 1.3] 则 [显示]
sourceDefaultRule: '每月首日: 0\n每月非首日: 最近一次提交数值',
rules: { rules: {
min: 0, min: 0,
integer: true integer: true
...@@ -166,7 +165,7 @@ ...@@ -166,7 +165,7 @@
maxLength: 11 maxLength: 11
}, },
'F2-107-4': { 'F2-107-4': {
maxDate: 'today', maxDate: 'new Date()',
format: 'date' format: 'date'
}, },
'F2-107-8': { 'F2-107-8': {
...@@ -179,35 +178,35 @@ ...@@ -179,35 +178,35 @@
childrenShowRules: { childrenShowRules: {
'F2-107-4': { 'F2-107-4': {
keys: ['F2-107-3'], keys: ['F2-107-3'],
result: 'val1 == \'交付端引流-售前\' || val1 == \'门店引流-售前\'' result: "val1 == '交付端引流-售前' || val1 == '门店引流-售前'"
}, },
'F2-107-12': { 'F2-107-12': {
keys: ['F2-107-7'], keys: ['F2-107-7'],
result: 'Array.isArray(val1) && (val1.includes(\'已触客\') || val1.includes(\'已交付引荐\'))' result: "Array.isArray(val1) && (val1.includes('已触客') || val1.includes('已交付引荐'))"
}, },
'F2-107-13': { 'F2-107-13': {
keys: ['F2-107-7'], keys: ['F2-107-7'],
result: 'Array.isArray(val1) && val1.includes(\'已交付引荐\')' result: "Array.isArray(val1) && val1.includes('已交付引荐')"
}, },
'F2-107-14': { 'F2-107-14': {
keys: ['F2-107-13'], keys: ['F2-107-13'],
result: 'val1 == \'否\'' result: "val1 == '否'"
}, },
'F2-107-15': { 'F2-107-15': {
keys: ['F2-107-7'], keys: ['F2-107-7'],
result: 'Array.isArray(val1) && val1.includes(\'已触客\')' result: "Array.isArray(val1) && val1.includes('已触客')"
}, },
'F2-107-16': { 'F2-107-16': {
keys: ['F2-107-15'], keys: ['F2-107-15'],
result: 'val1 == \'否\'' result: "val1 == '否'"
}, },
'F2-107-17': { 'F2-107-17': {
keys: ['F2-107-7'], keys: ['F2-107-7'],
result: '!Array.isArray(val1) || !val1.includes(\'已触客\')' result: "!Array.isArray(val1) || !val1.includes('已触客')"
}, },
'F2-107-18': { 'F2-107-18': {
keys: ['F2-107-7'], keys: ['F2-107-7'],
result: 'Array.isArray(val1) && val1.includes(\'已触客\')' result: "Array.isArray(val1) && val1.includes('已触客')"
} }
}, },
children: [ children: [
...@@ -252,23 +251,19 @@ ...@@ -252,23 +251,19 @@
options: [ options: [
{ {
label: '销售端引流-售前', label: '销售端引流-售前',
value: '销售端引流-售前', value: '销售端引流-售前'
sourceRule: '场景=轻改'
}, },
{ {
label: '交付端引流-售前', label: '交付端引流-售前',
value: '交付端引流-售前', value: '交付端引流-售前'
sourceRule: '场景=轻改'
}, },
{ {
label: '门店引流-售前', label: '门店引流-售前',
value: '门店引流-售前', value: '门店引流-售前'
sourceRule: '场景=延保or广联权益'
}, },
{ {
label: '门店引流-售后', label: '门店引流-售后',
value: '门店引流-售后', value: '门店引流-售后'
sourceRule: '场景=延保or广联权益'
} }
], ],
rules: {}, rules: {},
...@@ -314,7 +309,6 @@ ...@@ -314,7 +309,6 @@
baseSceneCode: [], baseSceneCode: [],
options: [], options: [],
optionsKey: 'storeStaffList', optionsKey: 'storeStaffList',
sourceDefaultRule: '当前用户',
rules: {}, rules: {},
}, },
...@@ -334,23 +328,19 @@ ...@@ -334,23 +328,19 @@
}, },
{ {
label: '已拉群', label: '已拉群',
value: '已拉群', value: '已拉群'
sourceRule: '业务分类=轻改 and 品牌=鸿蒙智行 则显示'
}, },
{ {
label: '已交付引荐', label: '已交付引荐',
value: '已交付引荐', value: '已交付引荐'
sourceRule: '业务分类=轻改 and 品牌=岚图or其他 则不显示'
}, },
{ {
label: '首保维保客户', label: '首保维保客户',
value: '首保维保客户', value: '首保维保客户'
sourceRule: '业务分类=轻改 and 品牌=鸿蒙智行 则显示'
}, },
{ {
label: '事故车客户', label: '事故车客户',
value: '事故车客户', value: '事故车客户'
sourceRule: '业务分类=轻改 and 品牌=鸿蒙智行 则显示'
} }
], ],
rules: {}, rules: {},
......
...@@ -41,8 +41,7 @@ ...@@ -41,8 +41,7 @@
2698, 2698,
2797, 2797,
2740 2740
], ]
"sourceDefaultRule": "每月首日: 0\n每月非首日: 最近一次提交数值"
}, },
{ {
"label": "明日预计交付数", "label": "明日预计交付数",
...@@ -188,23 +187,19 @@ ...@@ -188,23 +187,19 @@
"options": [ "options": [
{ {
"label": "销售端引流-售前", "label": "销售端引流-售前",
"value": "销售端引流-售前", "value": "销售端引流-售前"
"sourceRule": "场景=轻改"
}, },
{ {
"label": "交付端引流-售前", "label": "交付端引流-售前",
"value": "交付端引流-售前", "value": "交付端引流-售前"
"sourceRule": "场景=轻改"
}, },
{ {
"label": "门店引流-售前", "label": "门店引流-售前",
"value": "门店引流-售前", "value": "门店引流-售前"
"sourceRule": "场景=延保or广联权益"
}, },
{ {
"label": "门店引流-售后", "label": "门店引流-售后",
"value": "门店引流-售后", "value": "门店引流-售后"
"sourceRule": "场景=延保or广联权益"
} }
] ]
}, },
...@@ -246,8 +241,7 @@ ...@@ -246,8 +241,7 @@
"baseSceneCode": [], "baseSceneCode": [],
"rules": {}, "rules": {},
"optionsKey": "storeStaffList", "optionsKey": "storeStaffList",
"options": [], "options": []
"sourceDefaultRule": "当前用户"
}, },
{ {
"label": "客户标签", "label": "客户标签",
...@@ -266,23 +260,19 @@ ...@@ -266,23 +260,19 @@
}, },
{ {
"label": "已拉群", "label": "已拉群",
"value": "已拉群", "value": "已拉群"
"sourceRule": "业务分类=轻改 and 品牌=鸿蒙智行 则显示"
}, },
{ {
"label": "已交付引荐", "label": "已交付引荐",
"value": "已交付引荐", "value": "已交付引荐"
"sourceRule": "业务分类=轻改 and 品牌=岚图or其他 则不显示"
}, },
{ {
"label": "首保维保客户", "label": "首保维保客户",
"value": "首保维保客户", "value": "首保维保客户"
"sourceRule": "业务分类=轻改 and 品牌=鸿蒙智行 则显示"
}, },
{ {
"label": "事故车客户", "label": "事故车客户",
"value": "事故车客户", "value": "事故车客户"
"sourceRule": "业务分类=轻改 and 品牌=鸿蒙智行 则显示"
} }
] ]
}, },
...@@ -534,7 +524,7 @@ ...@@ -534,7 +524,7 @@
"maxLength": 11 "maxLength": 11
}, },
"F2-107-4": { "F2-107-4": {
"maxDate": "today", "maxDate": "new Date()",
"format": "date" "format": "date"
}, },
"F2-107-8": { "F2-107-8": {
......
/** /**
* childrenShowRules.result 求值(小程序无 new Function) * childrenShowRules.result 求值(小程序无 new Function)
* 内置 fallback 解析:valN == '…'、valN != null,多条件用 && 连接 * 内置安全解析器(不使用 eval/new Function):支持 valN 比较、数组包含、!、&&、|| 与括号
*/ */
function evalPart(part = '', ctx = {}) { function tokenize(expr = '') {
const trimmed = part.trim() const tokens = []
const eqMatch = trimmed.match(/^val(\d+)\s*==\s*(?:'([^']*)'|"([^"]*)")$/) let index = 0
if (eqMatch) { while (index < expr.length) {
const actual = ctx[`val${eqMatch[1]}`] const char = expr[index]
const expected = eqMatch[2] != null ? eqMatch[2] : eqMatch[3] if (/\s/.test(char)) {
return actual == expected index += 1
} continue
const neNullMatch = trimmed.match(/^val(\d+)\s*!=\s*null$/) }
if (neNullMatch) {
const actual = ctx[`val${neNullMatch[1]}`] const pair = expr.slice(index, index + 2)
return actual != null && actual !== '' if (['&&', '||', '==', '!='].indexOf(pair) >= 0) {
} tokens.push({ type: 'operator', value: pair })
return false index += 2
continue
}
if (char === '!' || char === '(' || char === ')') {
tokens.push({ type: 'operator', value: char })
index += 1
continue
}
if (char === "'" || char === '"') {
const quote = char
let value = ''
index += 1
let closed = false
while (index < expr.length) {
const current = expr[index]
if (current === quote) {
closed = true
index += 1
break
}
if (current === '\\' && index + 1 < expr.length) {
const escaped = expr[index + 1]
const escapeMap = { n: '\n', r: '\r', t: '\t' }
value += escapeMap[escaped] ?? escaped
index += 2
continue
}
value += current
index += 1
}
if (!closed) throw new Error('unterminated string')
tokens.push({ type: 'string', value })
continue
}
const identifier = expr.slice(index).match(/^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*)*/)
if (identifier) {
tokens.push({ type: 'identifier', value: identifier[0] })
index += identifier[0].length
continue
}
throw new Error(`unsupported token at ${index}`)
}
return tokens
}
function parseExpression(tokens = [], ctx = {}) {
let index = 0
const peek = () => tokens[index]
const take = () => tokens[index++]
const match = value => {
if (peek()?.value !== value) return false
index += 1
return true
}
const expect = value => {
if (!match(value)) throw new Error(`expected ${value}`)
}
const expectType = type => {
const token = take()
if (!token || token.type !== type) throw new Error(`expected ${type}`)
return token.value
}
const resolveVal = name => {
if (!/^val\d+$/.test(name)) throw new Error(`unsupported variable ${name}`)
return ctx[name]
}
let parseOr
const parsePrimary = () => {
if (match('(')) {
const value = parseOr()
expect(')')
return value
}
const identifier = expectType('identifier')
if (identifier === 'Array.isArray') {
expect('(')
const variable = expectType('identifier')
expect(')')
return Array.isArray(resolveVal(variable))
}
if (/^val\d+\.includes$/.test(identifier)) {
const variable = identifier.slice(0, identifier.indexOf('.'))
expect('(')
const expected = expectType('string')
expect(')')
const actual = resolveVal(variable)
return Array.isArray(actual) && actual.indexOf(expected) >= 0
}
if (/^val\d+$/.test(identifier)) {
const operator = take()?.value
if (operator !== '==' && operator !== '!=') {
throw new Error(`unsupported comparison ${operator}`)
}
const expectedToken = take()
if (!expectedToken) throw new Error('missing comparison value')
const actual = resolveVal(identifier)
if (expectedToken.type === 'identifier' && expectedToken.value === 'null') {
return operator === '!='
? actual != null && actual !== ''
: actual == null || actual === ''
}
if (expectedToken.type !== 'string') throw new Error('unsupported comparison value')
return operator === '=='
? actual == expectedToken.value
: actual != expectedToken.value
}
throw new Error(`unsupported expression ${identifier}`)
}
const parseUnary = () => match('!') ? !parseUnary() : parsePrimary()
const parseAnd = () => {
let value = parseUnary()
while (match('&&')) {
const right = parseUnary()
value = value && right
}
return value
}
parseOr = () => {
let value = parseAnd()
while (match('||')) {
const right = parseAnd()
value = value || right
}
return value
}
const result = parseOr()
if (index !== tokens.length) throw new Error('unexpected trailing expression')
return result
} }
function fallbackEvaluate(expr = '', ctx = {}) { function fallbackEvaluate(expr = '', ctx = {}) {
if (!expr) return true if (!expr) return true
return expr.split('&&').every(part => evalPart(part, ctx)) try {
return parseExpression(tokenize(expr), ctx)
} catch (error) {
return false
}
} }
function evaluateShowRule(keys = [], resultExpr = '', rowFields = [], getRowFieldValue) { function evaluateShowRule(keys = [], resultExpr = '', rowFields = [], getRowFieldValue) {
......
...@@ -498,14 +498,10 @@ def parse_options( ...@@ -498,14 +498,10 @@ def parse_options(
continue continue
item = re.sub(r'^[-–—]\s*', '', item) item = re.sub(r'^[-–—]\s*', '', item)
item = re.sub(r'^选项\s*\d+\s*[::]\s*', '', item) item = re.sub(r'^选项\s*\d+\s*[::]\s*', '', item)
source_rule = ''
annotated = re.match(r'^(.+?)\s*[\((](.+)[\))]\s*$', item) annotated = re.match(r'^(.+?)\s*[\((](.+)[\))]\s*$', item)
if annotated: if annotated:
item = annotated.group(1).strip() item = annotated.group(1).strip()
source_rule = annotated.group(2).strip()
option = {'label': item, 'value': item} option = {'label': item, 'value': item}
if source_rule:
option['sourceRule'] = source_rule
option_items.append(option) option_items.append(option)
field['options'] = option_items field['options'] = option_items
if '当前门店驻店人员' in text: if '当前门店驻店人员' in text:
...@@ -613,8 +609,6 @@ def row_to_field( ...@@ -613,8 +609,6 @@ def row_to_field(
default_text = record.get('默认值', '') default_text = record.get('默认值', '')
source_default = version == '2.3.0' and is_source_default_rule(default_text) source_default = version == '2.3.0' and is_source_default_rule(default_text)
if source_default:
field['sourceDefaultRule'] = default_text.strip()
default_val = None if source_default else parse_default_value(default_text, field['type']) default_val = None if source_default else parse_default_value(default_text, field['type'])
if default_val is not None: if default_val is not None:
field['value'] = default_val field['value'] = default_val
...@@ -710,6 +704,8 @@ def build_v230_children_rules(children: list[dict]) -> dict: ...@@ -710,6 +704,8 @@ def build_v230_children_rules(children: list[dict]) -> dict:
for key, value in (child.get('rules') or {}).items() for key, value in (child.get('rules') or {}).items()
if key in allowed if key in allowed
} }
if child_rules.get('maxDate') == 'today':
child_rules['maxDate'] = 'new Date()'
if child_rules: if child_rules:
result[child['key']] = child_rules result[child['key']] = child_rules
return result return result
...@@ -963,8 +959,8 @@ COMMENTS_JSON = PKG_ROOT / 'fixtures/template-field-comments.json' ...@@ -963,8 +959,8 @@ COMMENTS_JSON = PKG_ROOT / 'fixtures/template-field-comments.json'
# 字段属性输出顺序(对齐 V2.0 业务配置粘贴格式) # 字段属性输出顺序(对齐 V2.0 业务配置粘贴格式)
FIELD_PROP_ORDER = [ FIELD_PROP_ORDER = [
'label', 'sortNum', 'key', 'type', 'required', 'sceneType', 'brandId', 'label', 'sortNum', 'key', 'type', 'required', 'sceneType', 'brandId',
'baseSceneCode', 'options', 'optionsKey', 'value', 'sourceDefaultRule', 'baseSceneCode', 'options', 'optionsKey', 'value', 'prefixComponent',
'prefixComponent', 'unit', 'rules', 'unit', 'rules',
'filterBrandId', 'completeFun', 'disabledFun', 'isYB', 'isQY', 'filterBrandId', 'completeFun', 'disabledFun', 'isYB', 'isQY',
'ybCode', 'qyCode', 'qgCode', 'childrenRules', 'childrenShowRules', 'children', 'ybCode', 'qyCode', 'qgCode', 'childrenRules', 'childrenShowRules', 'children',
] ]
...@@ -988,6 +984,19 @@ def _js_str(value: str) -> str: ...@@ -988,6 +984,19 @@ def _js_str(value: str) -> str:
return "'" + escaped + "'" return "'" + escaped + "'"
def _js_double_str(value: str) -> str:
escaped = (
value.replace('\\', '\\\\')
.replace('"', '\\"')
.replace('\r', '\\r')
.replace('\n', '\\n')
.replace('\t', '\\t')
.replace('\u2028', '\\u2028')
.replace('\u2029', '\\u2029')
)
return '"' + escaped + '"'
def _js_value(value, indent: int, inline_comment: str = '') -> str: def _js_value(value, indent: int, inline_comment: str = '') -> str:
pad = ' ' * indent pad = ' ' * indent
suffix = f' {inline_comment}' if inline_comment else '' suffix = f' {inline_comment}' if inline_comment else ''
...@@ -1109,7 +1118,7 @@ def _js_object( ...@@ -1109,7 +1118,7 @@ def _js_object(
return '{\n' + '\n'.join(lines) + f'\n{pad}}}' return '{\n' + '\n'.join(lines) + f'\n{pad}}}'
def _js_fun_obj(obj: dict, indent: int) -> str: def _js_fun_obj(obj: dict, indent: int, *, double_quote_result: bool = False) -> str:
pad = ' ' * indent pad = ' ' * indent
inner = ' ' * (indent + 4) inner = ' ' * (indent + 4)
parts = [] parts = []
...@@ -1118,7 +1127,8 @@ def _js_fun_obj(obj: dict, indent: int) -> str: ...@@ -1118,7 +1127,8 @@ def _js_fun_obj(obj: dict, indent: int) -> str:
if v == '(list.length)': if v == '(list.length)':
parts.append(f'{inner}result: "(list.length)"') parts.append(f'{inner}result: "(list.length)"')
else: else:
parts.append(f'{inner}result: {_js_str(v)}') result = _js_double_str(v) if double_quote_result else _js_str(v)
parts.append(f'{inner}result: {result}')
else: else:
parts.append(f'{inner}{k}: {_js_value(v, indent + 4)}') parts.append(f'{inner}{k}: {_js_value(v, indent + 4)}')
return '{\n' + ',\n'.join(parts) + f'\n{pad}}}' return '{\n' + ',\n'.join(parts) + f'\n{pad}}}'
...@@ -1159,8 +1169,6 @@ def _js_options(options: list, indent: int) -> str: ...@@ -1159,8 +1169,6 @@ def _js_options(options: list, indent: int) -> str:
f'{inner} label: {_js_str(opt["label"])}', f'{inner} label: {_js_str(opt["label"])}',
f'{inner} value: {_js_str(opt["value"])}', f'{inner} value: {_js_str(opt["value"])}',
] ]
if opt.get('sourceRule'):
props.append(f'{inner} sourceRule: {_js_str(opt["sourceRule"])}')
items.append(f'{inner}{{\n' + ',\n'.join(props) + f'\n{inner}}}') items.append(f'{inner}{{\n' + ',\n'.join(props) + f'\n{inner}}}')
return '[\n' + ',\n'.join(items) + f'\n{pad}]' return '[\n' + ',\n'.join(items) + f'\n{pad}]'
...@@ -1170,7 +1178,10 @@ def _js_children_show_rules(rules: dict, indent: int) -> str: ...@@ -1170,7 +1178,10 @@ def _js_children_show_rules(rules: dict, indent: int) -> str:
inner = ' ' * (indent + 4) inner = ' ' * (indent + 4)
lines = [] lines = []
for key, rule in rules.items(): for key, rule in rules.items():
lines.append(f'{inner}{_js_str(key)}: {_js_fun_obj(rule, indent + 4)}') lines.append(
f'{inner}{_js_str(key)}: '
f'{_js_fun_obj(rule, indent + 4, double_quote_result=True)}'
)
if not lines: if not lines:
return '{}' return '{}'
return '{\n' + ',\n'.join(lines) + f'\n{pad}}}' return '{\n' + ',\n'.join(lines) + f'\n{pad}}}'
......
...@@ -15,4 +15,38 @@ describe('group-show-rule-eval fallback', () => { ...@@ -15,4 +15,38 @@ describe('group-show-rule-eval fallback', () => {
true true
) )
}) })
it('IT-SHOW-RULE-FB-002: fallback matches all V2.3.0 store subform expressions', () => {
assert.equal(
fallbackEvaluate(
"val1 == '交付端引流-售前' || val1 == '门店引流-售前'",
{ val1: '门店引流-售前' }
),
true
)
assert.equal(
fallbackEvaluate(
"val1 == '交付端引流-售前' || val1 == '门店引流-售前'",
{ val1: '其他' }
),
false
)
const anyTag = "Array.isArray(val1) && (val1.includes('已触客') || val1.includes('已交付引荐'))"
assert.equal(fallbackEvaluate(anyTag, { val1: ['已交付引荐'] }), true)
assert.equal(fallbackEvaluate(anyTag, { val1: [] }), false)
const delivered = "Array.isArray(val1) && val1.includes('已交付引荐')"
assert.equal(fallbackEvaluate(delivered, { val1: ['已交付引荐'] }), true)
assert.equal(fallbackEvaluate(delivered, { val1: ['已触客'] }), false)
const contacted = "Array.isArray(val1) && val1.includes('已触客')"
assert.equal(fallbackEvaluate(contacted, { val1: ['已触客'] }), true)
assert.equal(fallbackEvaluate(contacted, { val1: null }), false)
const notContacted = "!Array.isArray(val1) || !val1.includes('已触客')"
assert.equal(fallbackEvaluate(notContacted, { val1: null }), true)
assert.equal(fallbackEvaluate(notContacted, { val1: ['已交付引荐'] }), true)
assert.equal(fallbackEvaluate(notContacted, { val1: ['已触客'] }), false)
})
}) })
...@@ -45,6 +45,7 @@ function withoutBrandIds(value) { ...@@ -45,6 +45,7 @@ function withoutBrandIds(value) {
const daily = loadJson('schema-store-daily-v2.3.0.json') const daily = loadJson('schema-store-daily-v2.3.0.json')
const production = loadJson('schema-store-daily-v2.3.0.prod.json') const production = loadJson('schema-store-daily-v2.3.0.prod.json')
const dailyJsSource = fs.readFileSync(path.join(fixturesDir, 'schema-store-daily-v2.3.0.js'), 'utf8')
describe('store daily template V2.3.0 schema', () => { describe('store daily template V2.3.0 schema', () => {
it('IT-V230-001: metadata and exact F2-101 onward shape', () => { it('IT-V230-001: metadata and exact F2-101 onward shape', () => {
...@@ -74,23 +75,24 @@ describe('store daily template V2.3.0 schema', () => { ...@@ -74,23 +75,24 @@ describe('store daily template V2.3.0 schema', () => {
assert.equal(findDeep(daily.list, 'F2-107-9')?.rules?.maxLength, 20) assert.equal(findDeep(daily.list, 'F2-107-9')?.rules?.maxLength, 20)
}) })
it('IT-V230-003: dynamic defaults and option annotations are preserved as source metadata', () => { it('IT-V230-003: unsupported source Rule metadata is not emitted', () => {
const monthly = findDeep(daily.list, 'F2-102') const monthly = findDeep(daily.list, 'F2-102')
assert.match(monthly?.sourceDefaultRule, /每月首日/) assert.equal(Object.hasOwn(monthly, 'sourceDefaultRule'), false)
assert.equal(Object.hasOwn(monthly, 'value'), false) assert.equal(Object.hasOwn(monthly, 'value'), false)
const owner = findDeep(daily.list, 'F2-107-6') const owner = findDeep(daily.list, 'F2-107-6')
assert.equal(owner?.type, 'select') assert.equal(owner?.type, 'select')
assert.equal(owner?.optionsKey, 'storeStaffList') assert.equal(owner?.optionsKey, 'storeStaffList')
assert.match(owner?.sourceDefaultRule, /当前用户/) assert.equal(Object.hasOwn(owner, 'sourceDefaultRule'), false)
const tags = findDeep(daily.list, 'F2-107-7') const tags = findDeep(daily.list, 'F2-107-7')
assert.equal(tags?.type, 'multipleSelect') assert.equal(tags?.type, 'multipleSelect')
assert.ok(tags?.options?.some(option => option.sourceRule)) assert.ok(tags?.options?.every(option => !Object.hasOwn(option, 'sourceRule')))
}) })
it('IT-V230-004: subform childrenShowRules retain every Excel dependency', () => { it('IT-V230-004: subform childrenShowRules retain every Excel dependency', () => {
const rules = findDeep(daily.list, 'F2-107')?.childrenShowRules const subform = findDeep(daily.list, 'F2-107')
const rules = subform?.childrenShowRules
assert.deepEqual(Object.keys(rules), [ assert.deepEqual(Object.keys(rules), [
'F2-107-4', 'F2-107-4',
'F2-107-12', 'F2-107-12',
...@@ -103,6 +105,10 @@ describe('store daily template V2.3.0 schema', () => { ...@@ -103,6 +105,10 @@ describe('store daily template V2.3.0 schema', () => {
]) ])
assert.deepEqual(rules['F2-107-14']?.keys, ['F2-107-13']) assert.deepEqual(rules['F2-107-14']?.keys, ['F2-107-13'])
assert.match(rules['F2-107-12']?.result, /已交付引荐/) assert.match(rules['F2-107-12']?.result, /已交付引荐/)
assert.deepEqual(subform?.childrenRules?.['F2-107-4'], {
maxDate: 'new Date()',
format: 'date'
})
}) })
it('IT-V230-005: daily and production differ only by brand IDs', () => { it('IT-V230-005: daily and production differ only by brand IDs', () => {
...@@ -117,4 +123,13 @@ describe('store daily template V2.3.0 schema', () => { ...@@ -117,4 +123,13 @@ describe('store daily template V2.3.0 schema', () => {
assert.deepEqual(loadBareArray('schema-store-daily-v2.3.0.js'), daily.list) assert.deepEqual(loadBareArray('schema-store-daily-v2.3.0.js'), daily.list)
assert.deepEqual(loadBareArray('schema-store-daily-v2.3.0.prod.js'), production.list) assert.deepEqual(loadBareArray('schema-store-daily-v2.3.0.prod.js'), production.list)
}) })
it('IT-V230-007: child visibility expressions use legacy-compatible double-quoted JS strings', () => {
const resultLines = dailyJsSource
.split(/\r?\n/)
.filter(line => line.trimStart().startsWith('result:'))
assert.equal(resultLines.length, 8)
assert.ok(resultLines.every(line => /^\s*result: "/.test(line)))
assert.ok(resultLines.every(line => !line.includes("\\'")))
})
}) })
...@@ -174,7 +174,7 @@ class StoreV230ConverterTest(unittest.TestCase): ...@@ -174,7 +174,7 @@ class StoreV230ConverterTest(unittest.TestCase):
self.assertEqual(legacy_default['value'], 0) self.assertEqual(legacy_default['value'], 0)
self.assertNotIn('sourceDefaultRule', legacy_default) self.assertNotIn('sourceDefaultRule', legacy_default)
self.assertNotIn('value', v230_default) self.assertNotIn('value', v230_default)
self.assertIn('sourceDefaultRule', v230_default) self.assertNotIn('sourceDefaultRule', v230_default)
def test_maps_new_types_multiline_options_and_source_metadata(self): def test_maps_new_types_multiline_options_and_source_metadata(self):
phone = converter.row_to_field( phone = converter.row_to_field(
...@@ -254,15 +254,23 @@ class StoreV230ConverterTest(unittest.TestCase): ...@@ -254,15 +254,23 @@ class StoreV230ConverterTest(unittest.TestCase):
self.assertEqual(date_field['rules'], {'maxDate': 'today', 'format': 'date'}) self.assertEqual(date_field['rules'], {'maxDate': 'today', 'format': 'date'})
self.assertEqual(tags['type'], 'multipleSelect') self.assertEqual(tags['type'], 'multipleSelect')
self.assertEqual([item['label'] for item in tags['options']], ['已触客', '已拉群', '已交付引荐']) self.assertEqual([item['label'] for item in tags['options']], ['已触客', '已拉群', '已交付引荐'])
self.assertIn('sourceRule', tags['options'][1]) self.assertTrue(all('sourceRule' not in item for item in tags['options']))
self.assertNotIn('value', monthly) self.assertNotIn('value', monthly)
self.assertIn('每月首日', monthly['sourceDefaultRule']) self.assertNotIn('sourceDefaultRule', monthly)
self.assertEqual(car_model['rules']['level'], 4) self.assertEqual(car_model['rules']['level'], 4)
def test_assembles_subform_and_emits_parseable_children_show_rules(self): def test_assembles_subform_and_emits_parseable_children_show_rules(self):
rows = [ rows = [
record('F2-107', '今日非成交客户', '子表单', 142), record('F2-107', '今日非成交客户', '子表单', 142),
record( record(
'F2-107-4',
'实际交付日期',
'日期时间',
4,
required='☑',
other_rules='单日期;仅允许选择当前及过去日期',
),
record(
'F2-107-7', 'F2-107-7',
'客户标签', '客户标签',
'选择器', '选择器',
...@@ -279,14 +287,20 @@ class StoreV230ConverterTest(unittest.TestCase): ...@@ -279,14 +287,20 @@ class StoreV230ConverterTest(unittest.TestCase):
self.assertEqual(subform['key'], 'F2-107') self.assertEqual(subform['key'], 'F2-107')
self.assertEqual( self.assertEqual(
[child['key'] for child in subform['children'][0]], [child['key'] for child in subform['children'][0]],
['F2-107-7', 'F2-107-17'], ['F2-107-4', 'F2-107-7', 'F2-107-17'],
) )
self.assertEqual( self.assertEqual(
subform['childrenShowRules']['F2-107-17']['keys'], subform['childrenShowRules']['F2-107-17']['keys'],
['F2-107-7'], ['F2-107-7'],
) )
self.assertEqual(
subform['childrenRules'].get('F2-107-4'),
{'maxDate': 'new Date()', 'format': 'date'},
)
source = converter.emit_js_array(fields, {}, {'fileHeader': '', 'jsDoc': '', 'fields': {}}) source = converter.emit_js_array(fields, {}, {'fileHeader': '', 'jsDoc': '', 'fields': {}})
self.assertIn('result: "!Array.isArray(val1) || !val1.includes(', source)
self.assertNotIn("result: '!Array.isArray(val1) || !val1.includes(", source)
script = ( script = (
"const source = process.argv[1];" "const source = process.argv[1];"
"const result = Function('return (\\n' + source + '\\n)')();" "const result = Function('return (\\n' + source + '\\n)')();"
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!