@fastspace/schema-form 0.0.8 → 0.0.9

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
@@ -97,6 +97,79 @@ function App() {
97
97
  | `Switch` | 开关 | `boolean` |
98
98
  | `Radio` | 单选组 | `string \| number` |
99
99
 
100
+ ### 选项配置详解 (Select / Autocomplete)
101
+
102
+ `OptionItem` 结构支持以下属性:
103
+
104
+ ```typescript
105
+ type OptionItem = {
106
+ label: string; // 选中后输入框展示的文本
107
+ value: string | number | boolean | null; // 提交到表单的值
108
+ key?: string | number; // [可选] 唯一标识 (当 value 不唯一或 label 重复时使用)
109
+ listLabel?: React.ReactNode; // [可选] 下拉列表展示的内容 (可与 label 不一致)
110
+ disabled?: boolean; // 是否禁用
111
+ };
112
+ ```
113
+
114
+ #### 场景 1:Label 重复导致 React Key 报错
115
+ 如果选项中存在相同的 `label` 或 `value`,请显式提供 `key`:
116
+
117
+ ```typescript
118
+ {
119
+ label: '重复项',
120
+ value: 'dup_1',
121
+ key: 'unique_key_1'
122
+ },
123
+ {
124
+ label: '重复项',
125
+ value: 'dup_2',
126
+ key: 'unique_key_2'
127
+ }
128
+ ```
129
+
130
+ #### 场景 2:列表展示与选中展示不一致
131
+ 例如,列表中展示详细信息(如 "张三 (ID:001)"),选中后只展示姓名("张三"):
132
+
133
+ ```typescript
134
+ {
135
+ label: '张三', // 选中后展示
136
+ value: '001',
137
+ listLabel: ( // 列表中展示
138
+ <div>
139
+ <strong>张三</strong>
140
+ <span style={{ color: '#999', fontSize: 12 }}> (ID: 001)</span>
141
+ </div>
142
+ )
143
+ }
144
+ ```
145
+
146
+ #### 场景 3:选中后触发额外操作
147
+ 可以在 `fieldProps` 中传入 `onChange` 回调:
148
+
149
+ ```typescript
150
+ {
151
+ name: 'userSelect',
152
+ component: 'Select',
153
+ ui: {
154
+ label: '选择用户',
155
+ options: [
156
+ { label: 'User A', value: 'a' },
157
+ { label: 'User B', value: 'b' }
158
+ ]
159
+ },
160
+ fieldProps: {
161
+ // 这里的 onChange 会在表单值更新后触发
162
+ onChange: (event, option) => {
163
+ console.log('选中项:', option);
164
+ // 执行额外逻辑,例如:
165
+ // 1. 调用接口获取详情
166
+ // 2. 联动更新其他字段 (通过 form 实例)
167
+ // 3. 弹窗提示
168
+ }
169
+ }
170
+ }
171
+ ```
172
+
100
173
  ### 日期时间组件
101
174
 
102
175
  | 组件名 | 说明 | 数据类型 |
package/dist/index.d.ts CHANGED
@@ -321,6 +321,10 @@ export declare type OptionItem = {
321
321
  label: string;
322
322
  value: string | number | boolean | null;
323
323
  disabled?: boolean;
324
+ /** 唯一标识 (解决 label 重复问题) */
325
+ key?: string | number;
326
+ /** 列表展示文本 (允许与选中后回显的 label 不一致) */
327
+ listLabel?: React.ReactNode;
324
328
  [key: string]: unknown;
325
329
  };
326
330