@kne/form-creator 0.1.23 → 0.1.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1515,44 +1515,56 @@ render(<FormInfoFieldExample />);
1515
1515
  ```
1516
1516
 
1517
1517
  - 语言切换(全屏)
1518
- - FormCreator locale prop 切换中/英;检查内置 Field Type 分组与选项、列表类型 Tag、Select/DatePicker 占位
1519
- - _FormCreator(@kne/current-lib_form-creator)[import * as _FormCreator from "@kne/form-creator"],(@kne/current-lib_form-creator/dist/index.css)[import "@kne/form-creator/dist/index.css"],antd(antd)[import antd from "antd"]
1518
+ - FormCreator locale prop 切换中/英;检查内置 Field Type 分组与选项、列表类型 Tag、Select/DatePicker 占位,以及 Schema 多语言文案随语言切换
1519
+ - _FormCreator(@kne/current-lib_form-creator)[import * as _FormCreator from "@kne/form-creator"],(@kne/current-lib_form-creator/dist/index.css)[import "@kne/form-creator/dist/index.css"],antd(antd)[import antd from "antd"],remoteLoader(@kne/remote-loader)
1520
1520
 
1521
1521
  ```jsx
1522
1522
  const { default: FormCreator, defaultSchema, createBlock, createField } = _FormCreator;
1523
+ const { createWithRemoteLoader } = remoteLoader;
1523
1524
  const { useState } = React;
1524
1525
  const { Radio, Space, Typography, Alert } = antd;
1525
1526
 
1526
1527
  const { Text, Paragraph } = Typography;
1527
1528
 
1529
+ const languages = [
1530
+ { value: 'zh-CN', label: '中文' },
1531
+ { value: 'en-US', label: 'English' }
1532
+ ];
1533
+
1528
1534
  const demoSchema = () => ({
1529
1535
  ...defaultSchema(),
1530
1536
  blocks: [
1531
1537
  createBlock('formInfo', {
1532
- title: 'Basic Info',
1538
+ title: { 'zh-CN': '基本信息', 'en-US': 'Basic Info' },
1533
1539
  column: 2,
1534
1540
  list: [
1535
1541
  createField({
1536
1542
  type: 'Input',
1537
1543
  name: 'name',
1538
- label: 'Name',
1544
+ label: { 'zh-CN': '姓名', 'en-US': 'Name' },
1539
1545
  rule: 'REQ'
1540
1546
  }),
1547
+ createField({
1548
+ type: 'Input',
1549
+ name: 'email',
1550
+ label: { 'zh-CN': '邮箱', 'en-US': 'Email' },
1551
+ rule: 'EMAIL LEN-6-30'
1552
+ }),
1541
1553
  createField({
1542
1554
  type: 'Select',
1543
1555
  name: 'city',
1544
- label: 'City',
1556
+ label: { 'zh-CN': '城市', 'en-US': 'City' },
1545
1557
  props: {
1546
1558
  options: [
1547
- { label: 'Shanghai', value: 'sh' },
1548
- { label: 'Beijing', value: 'bj' }
1559
+ { label: { 'zh-CN': '上海', 'en-US': 'Shanghai' }, value: 'sh' },
1560
+ { label: { 'zh-CN': '北京', 'en-US': 'Beijing' }, value: 'bj' }
1549
1561
  ]
1550
1562
  }
1551
1563
  }),
1552
1564
  createField({
1553
1565
  type: 'DatePicker',
1554
1566
  name: 'birthday',
1555
- label: 'Birthday'
1567
+ label: { 'zh-CN': '生日', 'en-US': 'Birthday' }
1556
1568
  })
1557
1569
  ]
1558
1570
  })
@@ -1564,11 +1576,17 @@ const demoSchema = () => ({
1564
1576
  * - 编辑器壳层文案(Add Section / Field Type 等)
1565
1577
  * - 内置 Field Type 分组与选项(Single-line Text / Dropdown)
1566
1578
  * - 左侧列表字段类型 Tag、Select/DatePicker 默认占位
1579
+ * - Schema 内多语言文案({ 'zh-CN', 'en-US' })随 locale 切换;languages 决定编辑时有哪几栏输入
1580
+ * - 内置校验(EMAIL / TEL / LEN)错误提示随 locale 切换
1581
+ * - DatePicker 面板等 antd 内置文案由外层 PureGlobal 的 preset.locale 决定
1567
1582
  *
1568
1583
  * 注意:扩展字段(Rate/Slider)若曾打开过「preset 扩展」示例,会残留中文 label;
1569
1584
  * 那是全局 registry 污染,不在本示例内重注册(避免热更新循环)。
1570
1585
  */
1571
- const LocaleSwitchExample = () => {
1586
+ const LocaleSwitchExample = createWithRemoteLoader({
1587
+ modules: ['components-core:Global@PureGlobal']
1588
+ })(({ remoteModules }) => {
1589
+ const [PureGlobal] = remoteModules;
1572
1590
  const [locale, setLocale] = useState('en-US');
1573
1591
  const [schema, setSchema] = useState(demoSchema);
1574
1592
 
@@ -1580,8 +1598,7 @@ const LocaleSwitchExample = () => {
1580
1598
  message="Language switch"
1581
1599
  description={
1582
1600
  <Paragraph style={{ marginBottom: 0 }}>
1583
- Toggle locale, then open <Text code>Edit Field</Text> and check built-in <Text strong>Field Type</Text>{' '}
1584
- groups/options, type tags, and Select/DatePicker placeholders.
1601
+ Toggle locale, then open <Text code>Edit Field</Text> and check built-in <Text strong>Field Type</Text> groups/options, type tags, and Select/DatePicker placeholders.
1585
1602
  </Paragraph>
1586
1603
  }
1587
1604
  />
@@ -1590,17 +1607,302 @@ const LocaleSwitchExample = () => {
1590
1607
  buttonStyle="solid"
1591
1608
  value={locale}
1592
1609
  onChange={e => setLocale(e.target.value)}
1593
- options={[
1594
- { label: '中文', value: 'zh-CN' },
1595
- { label: 'English', value: 'en-US' }
1610
+ options={languages}
1611
+ />
1612
+ <PureGlobal key={locale} preset={{ locale }}>
1613
+ <FormCreator locale={locale} languages={languages} value={schema} onChange={setSchema} />
1614
+ </PureGlobal>
1615
+ </Space>
1616
+ );
1617
+ });
1618
+
1619
+ render(<LocaleSwitchExample />);
1620
+
1621
+ ```
1622
+
1623
+ - 固定填写项
1624
+ - 字段设置 locked: true 后不可编辑、删除或移动,所在模块位置固定;适合业务依赖的固定字段
1625
+ - _FormCreator(@kne/current-lib_form-creator)[import * as _FormCreator from "@kne/form-creator"],(@kne/current-lib_form-creator/dist/index.css)[import "@kne/form-creator/dist/index.css"],antd(antd)[import antd from "antd"]
1626
+
1627
+ ```jsx
1628
+ const { default: FormCreator, defaultSchema, createBlock, createField } = _FormCreator;
1629
+ const { useState } = React;
1630
+ const { Alert, Space, Typography } = antd;
1631
+ const { Text } = Typography;
1632
+
1633
+ const LockedFieldExample = () => {
1634
+ const [schema, setSchema] = useState(() => ({
1635
+ ...defaultSchema(),
1636
+ blocks: [
1637
+ createBlock('formInfo', {
1638
+ title: '面试评价',
1639
+ column: 1,
1640
+ list: [
1641
+ createField({
1642
+ type: 'RadioGroup',
1643
+ name: 'recommendation',
1644
+ label: '是否通过',
1645
+ rule: 'REQ',
1646
+ locked: true,
1647
+ props: {
1648
+ options: [
1649
+ { label: '通过', value: 'pass' },
1650
+ { label: '待定', value: 'hold' },
1651
+ { label: '不通过', value: 'reject' }
1652
+ ]
1653
+ }
1654
+ }),
1655
+ createField({ type: 'InputNumber', name: 'score', label: '综合评分(1-5)', rule: 'REQ', locked: true, props: { min: 1, max: 5 } }),
1656
+ createField({ type: 'TextArea', name: 'strengths', label: '优势', block: true, props: { rows: 3 } }),
1657
+ createField({ type: 'TextArea', name: 'notes', label: '备注', block: true, props: { rows: 3 } })
1658
+ ]
1659
+ }),
1660
+ createBlock('formInfo', {
1661
+ title: '补充信息',
1662
+ column: 2,
1663
+ list: [createField({ type: 'Input', name: 'expectedSalary', label: '期望薪资', props: { placeholder: '请输入期望薪资' } })]
1664
+ })
1665
+ ]
1666
+ }));
1667
+
1668
+ return (
1669
+ <Space direction="vertical" size={16} style={{ width: '100%' }}>
1670
+ <Alert
1671
+ type="info"
1672
+ showIcon
1673
+ message="固定填写项"
1674
+ description={
1675
+ <span>
1676
+ 字段设置 <Text code>locked: true</Text> 后不可编辑、删除或移动,其他字段也不能换到它前面;所在模块(含步骤、选项)不可删除、不可移动。适合「是否通过」「综合评分」这类业务依赖的固定字段。
1677
+ </span>
1678
+ }
1679
+ />
1680
+ <FormCreator value={schema} onChange={setSchema} />
1681
+ </Space>
1682
+ );
1683
+ };
1684
+
1685
+ render(<LockedFieldExample />);
1686
+
1687
+ ```
1688
+
1689
+ - 超长文案(全屏)
1690
+ - 模块标题、字段 label、选项、步骤标题均为超长文本并叠加固定/隐藏/整行标签,检查编辑器列表与预览的换行和省略
1691
+ - _FormCreator(@kne/current-lib_form-creator)[import * as _FormCreator from "@kne/form-creator"],(@kne/current-lib_form-creator/dist/index.css)[import "@kne/form-creator/dist/index.css"],antd(antd)[import antd from "antd"]
1692
+
1693
+ ```jsx
1694
+ const { default: FormCreator, defaultSchema, createBlock, createField, createStep } = _FormCreator;
1695
+ const { useState } = React;
1696
+ const { Alert, Space, Typography } = antd;
1697
+ const { Text } = Typography;
1698
+
1699
+ const LongLabelExample = () => {
1700
+ const [schema, setSchema] = useState(() => ({
1701
+ ...defaultSchema(),
1702
+ blocks: [
1703
+ createBlock('formInfo', {
1704
+ title: '候选人面试综合评价表(适用于技术岗位、产品岗位以及跨部门协作岗位的多轮面试场景)',
1705
+ subtitle: '请面试官在面试结束后 24 小时内完成填写,评价结果将同步给招聘负责人、用人部门负责人以及 HRBP 作为录用决策依据',
1706
+ column: 2,
1707
+ list: [
1708
+ createField({
1709
+ type: 'RadioGroup',
1710
+ name: 'recommendation',
1711
+ label: '综合以上所有面试环节的表现,您是否推荐该候选人进入下一轮面试或直接发放录用通知',
1712
+ rule: 'REQ',
1713
+ locked: true,
1714
+ props: {
1715
+ options: [
1716
+ { label: '强烈推荐,候选人能力明显超出岗位要求,建议尽快推进后续流程', value: 'pass' },
1717
+ { label: '待定,需要结合其他面试官意见或补充一轮面试后再做决定', value: 'hold' },
1718
+ { label: '不推荐,候选人在核心能力项上与岗位要求存在明显差距', value: 'reject' }
1719
+ ]
1720
+ }
1721
+ }),
1722
+ createField({
1723
+ type: 'InputNumber',
1724
+ name: 'score',
1725
+ label: '综合评分(1-5 分,请结合专业能力、沟通表达、文化契合度与成长潜力综合打分)',
1726
+ rule: 'REQ',
1727
+ locked: true,
1728
+ props: { min: 1, max: 5 }
1729
+ }),
1730
+ createField({
1731
+ type: 'Input',
1732
+ name: 'expectedSalaryAndAvailableDateAndOtherRemarks',
1733
+ label: '候选人期望薪资、最快到岗时间以及其他需要招聘负责人特别关注的事项说明',
1734
+ hidden: true,
1735
+ props: { placeholder: '例如:期望 35K × 15 薪,最快一个月后到岗,需要确认是否接受出差' }
1736
+ }),
1737
+ createField({
1738
+ type: 'Select',
1739
+ name: 'interviewRound',
1740
+ label: '本次面试所属轮次(如为加面或交叉面,请选择最接近的轮次并在备注中说明)',
1741
+ props: {
1742
+ options: [
1743
+ { label: '第一轮:业务部门技术或专业能力面试', value: 'first' },
1744
+ { label: '第二轮:部门负责人综合面试', value: 'second' },
1745
+ { label: '终面:HRBP 与高管联合面试', value: 'final' }
1746
+ ]
1747
+ }
1748
+ }),
1749
+ createField({
1750
+ type: 'TextArea',
1751
+ name: 'strengthsAndWeaknesses',
1752
+ label: '请详细描述候选人在本轮面试中展现出的主要优势、明显短板以及对岗位胜任力的整体判断依据',
1753
+ block: true,
1754
+ props: { rows: 3 }
1755
+ })
1756
+ ]
1757
+ }),
1758
+ createBlock('steps', {
1759
+ title: '分步骤填写的超长模块标题:第一步填写基础评价,第二步填写补充说明与附件',
1760
+ items: [
1761
+ createStep({
1762
+ title: '第一步:基础评价信息(包括专业能力、沟通表达与团队协作等维度)',
1763
+ column: 1,
1764
+ list: [createField({ type: 'Input', name: 'stepRemark', label: '对候选人专业能力与过往项目经验真实性的核实情况说明', props: {} })]
1765
+ }),
1766
+ createStep({
1767
+ title: '第二步:补充说明',
1768
+ column: 1,
1769
+ list: [createField({ type: 'TextArea', name: 'stepNotes', label: '其他补充说明', props: { rows: 2 } })]
1770
+ })
1771
+ ]
1772
+ })
1773
+ ]
1774
+ }));
1775
+
1776
+ return (
1777
+ <Space direction="vertical" size={16} style={{ width: '100%' }}>
1778
+ <Alert
1779
+ type="info"
1780
+ showIcon
1781
+ message="超长文案"
1782
+ description={
1783
+ <span>
1784
+ 模块标题、副标题、字段 label、选项文案、步骤标题均为超长文本,并叠加 <Text code>locked</Text> / <Text code>hidden</Text> / <Text code>block</Text>{' '}
1785
+ 标签,用于检查编辑器列表与右侧预览的换行、省略与对齐。
1786
+ </span>
1787
+ }
1788
+ />
1789
+ <FormCreator value={schema} onChange={setSchema} />
1790
+ </Space>
1791
+ );
1792
+ };
1793
+
1794
+ render(<LongLabelExample />);
1795
+
1796
+ ```
1797
+
1798
+ - 条件显示(全屏)
1799
+ - 字段配置 visibleWhen:按其他字段的值(等于、属于其一、多选包含、数值比较、正则匹配,支持且/或组合)决定是否显示,隐藏时不校验并清空值
1800
+ - _FormCreator(@kne/current-lib_form-creator)[import * as _FormCreator from "@kne/form-creator"],(@kne/current-lib_form-creator/dist/index.css)[import "@kne/form-creator/dist/index.css"],antd(antd)[import antd from "antd"]
1801
+
1802
+ ```jsx
1803
+ const { default: FormCreator, defaultSchema, createBlock, createField, schemaToDataSchema } = _FormCreator;
1804
+ const { useState } = React;
1805
+ const { Alert, Collapse, Space, Typography } = antd;
1806
+ const { Text } = Typography;
1807
+
1808
+ const ConditionalFieldExample = () => {
1809
+ const [schema, setSchema] = useState(() => ({
1810
+ ...defaultSchema(),
1811
+ blocks: [
1812
+ createBlock('formInfo', {
1813
+ title: '面试评价',
1814
+ column: 1,
1815
+ list: [
1816
+ createField({
1817
+ type: 'RadioGroup',
1818
+ name: 'recommendation',
1819
+ label: '是否通过',
1820
+ rule: 'REQ',
1821
+ props: {
1822
+ options: [
1823
+ { label: '通过', value: 'pass' },
1824
+ { label: '待定', value: 'hold' },
1825
+ { label: '不通过', value: 'reject' }
1826
+ ]
1827
+ }
1828
+ }),
1829
+ createField({
1830
+ type: 'TextArea',
1831
+ name: 'rejectReason',
1832
+ label: '不通过原因',
1833
+ rule: 'REQ',
1834
+ block: true,
1835
+ props: { rows: 3 },
1836
+ visibleWhen: { logic: 'and', conditions: [{ field: 'recommendation', operator: 'eq', value: 'reject' }] }
1837
+ }),
1838
+ createField({ type: 'InputNumber', name: 'score', label: '综合评分(1-5)', rule: 'REQ', props: { min: 1, max: 5 } }),
1839
+ createField({
1840
+ type: 'TextArea',
1841
+ name: 'improvement',
1842
+ label: '改进建议',
1843
+ block: true,
1844
+ props: { rows: 3 },
1845
+ visibleWhen: { logic: 'and', conditions: [{ field: 'score', operator: 'lte', value: 2 }] }
1846
+ }),
1847
+ createField({
1848
+ type: 'CheckboxGroup',
1849
+ name: 'dimensions',
1850
+ label: '考察维度',
1851
+ props: {
1852
+ options: [
1853
+ { label: '专业能力', value: 'skill' },
1854
+ { label: '沟通表达', value: 'communication' },
1855
+ { label: '管理能力', value: 'management' }
1856
+ ]
1857
+ }
1858
+ }),
1859
+ createField({
1860
+ type: 'InputNumber',
1861
+ name: 'teamSize',
1862
+ label: '带过的团队规模(人)',
1863
+ rule: 'REQ',
1864
+ props: { min: 1 },
1865
+ visibleWhen: { logic: 'and', conditions: [{ field: 'dimensions', operator: 'includesAny', value: ['management'] }] }
1866
+ }),
1867
+ createField({ type: 'Input', name: 'interviewerEmail', label: '面试官邮箱' }),
1868
+ createField({
1869
+ type: 'Input',
1870
+ name: 'referrer',
1871
+ label: '内部推荐人',
1872
+ visibleWhen: { logic: 'and', conditions: [{ field: 'interviewerEmail', operator: 'regex', value: '@leapin\\.ai$', flags: 'i' }] }
1873
+ })
1874
+ ]
1875
+ })
1876
+ ]
1877
+ }));
1878
+
1879
+ return (
1880
+ <Space direction="vertical" size={16} style={{ width: '100%' }}>
1881
+ <Alert
1882
+ type="info"
1883
+ showIcon
1884
+ message="条件显示"
1885
+ description={
1886
+ <span>
1887
+ 字段配置 <Text code>visibleWhen</Text> 后,满足条件才显示:选「不通过」出现「不通过原因」;评分 ≤ 2 出现「改进建议」;考察维度勾选「管理能力」出现「团队规模」;面试官邮箱匹配 <Text code>/@leapin\.ai$/i</Text> 出现「内部推荐人」。隐藏的字段不参与校验,已填的值会被清空。在编辑弹窗的「条件显示」中可修改条件。
1888
+ </span>
1889
+ }
1890
+ />
1891
+ <FormCreator value={schema} onChange={setSchema} />
1892
+ <Collapse
1893
+ items={[
1894
+ {
1895
+ key: 'data-schema',
1896
+ label: 'schemaToDataSchema 输出(条件字段不进 required,description 附条件说明)',
1897
+ children: <pre style={{ margin: 0, maxHeight: 360, overflow: 'auto' }}>{JSON.stringify(schemaToDataSchema(schema), null, 2)}</pre>
1898
+ }
1596
1899
  ]}
1597
1900
  />
1598
- <FormCreator key={locale} locale={locale} value={schema} onChange={setSchema} />
1599
1901
  </Space>
1600
1902
  );
1601
1903
  };
1602
1904
 
1603
- render(<LocaleSwitchExample />);
1905
+ render(<ConditionalFieldExample />);
1604
1906
 
1605
1907
  ```
1606
1908
 
@@ -1616,6 +1918,7 @@ render(<LocaleSwitchExample />);
1616
1918
  | formProps | object | {} | 透传给预览区 Form / FormSteps 的属性 |
1617
1919
  | renderModal | function(props) | - | 自定义编辑弹窗渲染,透传给内部 FormModal(同 super-select / form-info) |
1618
1920
  | extraToolbar | ReactNode \| function({ schema }) | - | 追加在「添加模块」与设置按钮后面的自定义按钮区 |
1921
+ | languages | { value, label }[] | - | Schema 文案支持的语言,首项为基础语言;不传为单语言输入(见「多语言文案」) |
1619
1922
 
1620
1923
  ```js
1621
1924
  <FormCreator
@@ -1646,6 +1949,7 @@ render(<LocaleSwitchExample />);
1646
1949
  | buttonFooterProps | object | - | 透传给 `ButtonFooter`(如 `placement`、`target`、`className`) |
1647
1950
  | children | ReactNode | - | 追加到表单内容与操作区之间 |
1648
1951
  | showActions | boolean | true | 是否展示提交/重置操作区(默认开启,可不传) |
1952
+ | languages | { value, label }[] | - | 多语言文案回退顺序,同 FormCreator;不传按 `zh-CN` → `en-US` |
1649
1953
  | actions | ReactNode \| false | - | 自定义操作区;不传则按 Schema `actions` / 默认居中「提交/重置」;`false` 隐藏 |
1650
1954
  | showSubmit | boolean | - | 覆盖 Schema;不传则读 `schema.actions.showSubmit`(默认 true) |
1651
1955
  | showReset | boolean | - | 覆盖 Schema;不传则读 `schema.actions.showReset`(默认 true) |
@@ -1699,6 +2003,7 @@ import { SchemaRenderer } from '@kne/form-creator';
1699
2003
  | className | string | - | 包在表单区块外层的 className(可选) |
1700
2004
  | children | ReactNode | - | 追加内容 |
1701
2005
  | showActions | boolean | true | 是否展示提交/重置操作区(默认开启,可不传) |
2006
+ | languages | { value, label }[] | - | 多语言文案回退顺序,同 FormCreator;不传按 `zh-CN` → `en-US` |
1702
2007
  | actions / showSubmit / showReset / submitText / resetText / \*ButtonProps | - | - | 同 SchemaRenderer |
1703
2008
  | bodyClassName / footerClassName / buttonFooter / buttonFooterProps | - | - | 同 SchemaRenderer |
1704
2009
 
@@ -1727,6 +2032,7 @@ import { Form, SubmitButton } from '@kne/form-info';
1727
2032
  | data | object | - | 提交数据;为 `null` / `undefined` 时展示空状态 |
1728
2033
  | className | string | - | 根节点类名 |
1729
2034
  | empty | ReactNode | - | 自定义空状态;不传则用默认 Empty |
2035
+ | languages | { value, label }[] | - | 多语言文案回退顺序,同 FormCreator;不传按 `zh-CN` → `en-US` |
1730
2036
 
1731
2037
  `SchemaContentInner` 只渲染分组内容,**不包**外层 `InfoPage`,便于放入业务已有详情页。
1732
2038
 
@@ -1743,14 +2049,15 @@ import { SchemaContent, SchemaContentInner } from '@kne/form-creator';
1743
2049
  #### Schema 结构
1744
2050
 
1745
2051
  ```js
2052
+ // LocaleText = string | { [language: string]: string },如 { 'zh-CN': '姓名', 'en-US': 'Name' },title / label 等展示文案均可用(见「多语言文案」)
1746
2053
  {
1747
2054
  actions?: {
1748
2055
  showSubmit?: boolean, // 默认 true
1749
2056
  showReset?: boolean, // 默认 true
1750
2057
  showCancel?: boolean, // 默认 false(可选取消按钮)
1751
- submitText?: string, // 空则用「提交」
1752
- resetText?: string, // 空则用「重置」
1753
- cancelText?: string, // 空则用「取消」
2058
+ submitText?: LocaleText, // 空则用「提交」
2059
+ resetText?: LocaleText, // 空则用「重置」
2060
+ cancelText?: LocaleText, // 空则用「取消」
1754
2061
  align?: 'center' | 'start' | 'end', // 默认 center
1755
2062
  gap?: number, // 按钮间距,默认 16
1756
2063
  submitButtonProps?: object,
@@ -1763,7 +2070,7 @@ import { SchemaContent, SchemaContentInner } from '@kne/form-creator';
1763
2070
  title?, subtitle?, column?, gap?, bordered?, important?,
1764
2071
  name?, label?, addText?, addPosition?, maxLength?, minLength?, fieldType?, autoStep?,
1765
2072
  mode?, selectorName?, selectorInData?, discriminator?,
1766
- list?: [{ id, type, name, label, tips?, description?, rule?, block?, hidden?, props? }],
2073
+ list?: [{ id, type, name, label, tips?, description?, rule?, block?, hidden?, locked?, visibleWhen?, props? }],
1767
2074
  itemBlocks?: Block[], // list / editableList:列表项内子模块
1768
2075
  blocks?: Block[], // formInfo / object:子模块
1769
2076
  options?: [{ id, title, list?, blocks?: Block[] }], // choice
@@ -1774,7 +2081,82 @@ import { SchemaContent, SchemaContentInner } from '@kne/form-creator';
1774
2081
 
1775
2082
  `actions` 由 FormCreator 顶部「添加模块」旁的设置按钮弹窗配置,写入 Schema;`SchemaRenderer` 会读取并渲染居中操作按钮(组件 props 可覆盖 Schema)。设置按钮后面可用 `extraToolbar` 追加自定义按钮。
1776
2083
 
2084
+ 字段 `locked: true` 为固定填写项:编辑器中不可编辑、删除或移动,其他字段也不能与其交换位置;包含锁定字段的模块、步骤、选项不可删除、不可移动。渲染与提交不受影响。工具方法 `isFieldLocked(field)`、`blockHasLockedField(block)` 可用于业务侧判断。
2085
+
2086
+ #### 条件显示(visibleWhen)
2087
+
2088
+ 字段可配置 `visibleWhen`,表单中其他字段的值满足条件时才显示该字段(编辑弹窗「条件显示」中配置):
2089
+
2090
+ ```js
2091
+ {
2092
+ name: 'rejectReason',
2093
+ label: '不通过原因',
2094
+ rule: 'REQ',
2095
+ visibleWhen: {
2096
+ logic: 'and', // 'and' 全部满足 | 'or' 满足任一,缺省 and
2097
+ conditions: [{ field: 'recommendation', operator: 'eq', value: 'reject' }]
2098
+ }
2099
+ }
2100
+ ```
2101
+
2102
+ | operator | 含义 | value |
2103
+ |----------|------|-------|
2104
+ | `eq` / `neq` | 等于 / 不等于 | 单值 |
2105
+ | `in` | 属于其一 | 数组 |
2106
+ | `includesAny` | 多选值包含任一 | 数组 |
2107
+ | `empty` / `notEmpty` | 为空 / 不为空(`undefined`、`null`、`''`、`[]` 视为空) | 无 |
2108
+ | `gt` / `gte` / `lt` / `lte` | 数值比较,非数字视为不满足 | 数字 |
2109
+ | `regex` | 正则匹配;值为数组时任一项匹配即满足 | 正则源码(不含 `/`),可加 `flags`(仅 `i` `m` `s` `u`) |
2110
+
2111
+ 规则:
2112
+
2113
+ - `field` 为提交数据中的路径,object 模块内字段带前缀,如 `contact.phone`
2114
+ - 不满足条件的字段不渲染、不参与校验,已填的值会被清空;`SchemaContent` 按数据同样隐藏
2115
+ - 列表类模块(list / tableList / editableList / multiField)内的字段既不能配置条件,也不能作为触发字段
2116
+ - 条件引用的字段不存在、位于列表类模块内或正则无效时,该条件被忽略(编辑器显示「条件失效」);全部条件失效时字段照常显示
2117
+ - 编辑器会拦截循环依赖;触发字段改名时自动同步引用
2118
+ - `schemaToDataSchema` 中条件字段不进入 `required`,并在 `description` 中附加条件说明
2119
+ - 工具方法:`evaluateVisibleWhen(visibleWhen, formData, knownNames?)`、`evaluateCondition(condition, formData)`、`collectConditionFields(schema)`、`findConditionCycle(schema)`、`renameConditionReferences(schema, oldPath, newPath)`
2120
+
1777
2121
  顶层模块渲染时会自动挂上 `InfoPage.partRootClassName`,嵌入外层 FormInfo Part 时标题从一级重新起算;模块内再嵌套仍为二级胶囊。
2122
+ #### 多语言文案
2123
+
2124
+ Schema 内的展示文案既可以是字符串,也可以是按语言区分的对象:`{ 'zh-CN': '姓名', 'en-US': 'Name' }`。`SchemaRenderer` / `SchemaRendererInner` / `SchemaContent` 渲染前按当前 `locale` 解析:字符串(旧格式)不论语言原样显示;多语言对象先取当前语言,取不到按 `languages` 顺序回退(未传 `languages` 时为 `zh-CN` → `en-US`),都没有内容为空。
2125
+
2126
+ | 支持多语言的位置 | 说明 |
2127
+ |------|------|
2128
+ | 字段 | label、tips、description、props.placeholder、props.options[].label / description、Switch 的 checkedChildren / unCheckedChildren |
2129
+ | 模块 | title、subtitle、label、addText;tableList 列 title;choice 选项 title;steps 步骤 title |
2130
+ | actions | submitText、resetText、cancelText |
2131
+
2132
+ 支持哪些语言由调用方通过 `languages` 决定,组件不内置语言列表:
2133
+
2134
+ ```jsx
2135
+ const languages = [
2136
+ { value: 'zh-CN', label: '中文' },
2137
+ { value: 'en-US', label: 'English' }
2138
+ ];
2139
+
2140
+ <FormCreator languages={languages} value={schema} onChange={setSchema} />
2141
+ <SchemaRenderer languages={languages} schema={schema} />
2142
+ ```
2143
+
2144
+ FormCreator 不传 `languages` 时为单语言输入(与改造前一致,存字符串);传入后每种语言一栏输入,首项为基础语言:只填基础语言时存为字符串(与旧 Schema 兼容),填了其它语言才存为对象;选项值联动时取基础语言文案。数据标识(`name`、选项 `value`)与语言无关。
2145
+
2146
+ | 方法 / 组件 | 参数 | 返回值 | 说明 |
2147
+ |------|------|------|------|
2148
+ | localizeSchema | (schema, locale, languages?) | object | 深度解析多语言文案,返回新对象,不修改原 Schema |
2149
+ | resolveLocaleText | (value, locale, languages?) | string | 解析单个文案;非多语言对象原样返回 |
2150
+ | isLocaleText | (value) | boolean | 是否为多语言文案对象 |
2151
+ | hasLocaleText | (value) | boolean | 文案(字符串或多语言)是否有内容 |
2152
+ | LocaleInput / LocaleTextArea | 同 react-form-antd 字段,另可传 languages | - | 多语言文案表单字段 |
2153
+ | LocaleTextControl | value, onChange, placeholder, multiline, compact, languages | - | 非表单场景的多语言输入控件 |
2154
+ | LocaleTextProvider | languages, children | - | 给内部的 LocaleInput / LocaleTextControl 统一下发 languages(FormCreator 已内置) |
2155
+
2156
+ `SchemaRenderer` 创建表单时按当前 `locale` 传入表单级 `rules`,让内置 `TEL` / `EMAIL` / `LEN` 的错误提示随语言切换(`@kne/react-form` 内置提示为中文);业务通过 `preset` 覆盖了同名规则时不替换,`formProps.rules` 优先级最高。`SchemaRendererInner` 嵌在外部表单中,规则由外部表单决定。
2157
+
2158
+ `schemaToDataSchema(schema, { locale, languages })` 与 `formatFieldDisplayValue(field, value, { formatMessage, locale, languages })` 也接受 `locale` / `languages`,回退规则同上。
2159
+
1778
2160
  #### 区块类型
1779
2161
 
1780
2162
  | kind | 说明 | 主要参数 |
@@ -1829,6 +2211,7 @@ const dataSchema = schemaToDataSchema(schema);
1829
2211
  说明:
1830
2212
 
1831
2213
  - **hidden 字段仍进入** data schema(可提交)
2214
+ - 配置了 `visibleWhen` 的字段不进入 `required`,`description` 追加条件说明(按 `options.locale` 输出中文或英文)
1832
2215
  - 字段值类型来自 registry 的 `valueSchema`;`rule` 含 `REQ` 时写入父 object 的 `required`(choice 支内同样生效)
1833
2216
  - 扩展字段在 `preset` / `registerField` 中声明 `valueSchema`(对象或 `(field) => schema`);未声明则回退 `{ type: 'string' }`
1834
2217