@hzab/list-render 1.9.7-beta1 → 1.9.7-beta2

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/common/utils.js +60 -18
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hzab/list-render",
3
- "version": "1.9.7-beta1",
3
+ "version": "1.9.7-beta2",
4
4
  "description": "",
5
5
  "main": "src",
6
6
  "scripts": {
@@ -97,7 +97,7 @@ export function getFieldList(_schema, fieldList = [], opt = {}, isTableSortXIdex
97
97
  // 解决 schema 字符串可执行代码、变量等
98
98
  const properties = Schema.getOrderProperties(schema);
99
99
  const { boxList = [] } = opt || {};
100
- let _boxList = ["FormGrid", "FormGrid.GridColumn", "Card"];
100
+ let _boxList = ["FormGrid", "FormGrid.GridColumn"];
101
101
  if (Array.isArray(boxList)) {
102
102
  _boxList = [..._boxList, ...boxList];
103
103
  } else if (boxList === false) {
@@ -202,25 +202,67 @@ export const getOptItByVal = function (val, options, opt) {
202
202
  * @param {Object} data - 原始数据对象
203
203
  * @returns {Object} - 处理后的新对象
204
204
  */
205
- export const removeInTableFalseFields = (data) => {
206
- // 深拷贝原始数据
207
- const result = _.cloneDeep(data);
208
- if (result?.form) {
209
- delete result.form?.labelCol;
210
- delete result.form?.wrapperCol;
211
- }
212
- // 检查是否存在 schema 和 properties
213
- if (result?.schema?.properties) {
214
- // 遍历properties中的所有属性
215
- Object.keys(result.schema.properties).forEach((key) => {
216
- if (result.schema.properties[key].inTable === false) {
217
- // 删除整个包含inTable:false的属性
218
- delete result.schema.properties[key];
219
- } else if (result.schema.properties[key]["x-display"]) {
220
- delete result.schema.properties[key]["x-display"];
205
+
206
+ /**
207
+ * 移除表格中标记为inTable:false的字段
208
+ * @param {Object} data - 原始数据
209
+ * @param {Object} [opt={}] - 配置选项
210
+ * @param {Array} [opt.boxList=[]] - 需要递归处理的组件类型列表
211
+ * @returns {Object} 处理后的数据
212
+ */
213
+
214
+ export function removeInTableFalseFields(_schema, opt = {}) {
215
+ // 1. 深拷贝原始数据
216
+ const result = _.cloneDeep(_schema);
217
+
218
+ // 2. 获取schema对象(支持直接传入schema或包含schema的对象)
219
+ const schema = result?.schema || result;
220
+
221
+ // 3. 处理容器组件配置
222
+ const { boxList = [] } = opt;
223
+ const _boxList =
224
+ boxList === false
225
+ ? []
226
+ : ["Card", "FormGrid", "ArrayCards", "Collapse", "Tabs", ...(Array.isArray(boxList) ? boxList : [])];
227
+
228
+ // 4. 递归删除inTable:false的字段
229
+ const processProperties = (properties) => {
230
+ if (!properties || typeof properties !== "object") return;
231
+
232
+ Object.keys(properties).forEach((key) => {
233
+ const item = properties[key];
234
+
235
+ // 处理容器组件递归
236
+ if (item["x-component"] && _boxList.includes(item["x-component"])) {
237
+ if (item.properties) {
238
+ processProperties(item.properties);
239
+ }
240
+ }
241
+ // 处理数组类型的子项
242
+ else if (item.items?.properties) {
243
+ processProperties(item.items.properties);
244
+ }
245
+ // 处理普通字段
246
+ else if (item.inTable === false) {
247
+ delete properties[key];
248
+ }
249
+ // 移除x-display
250
+ else if (item["x-display"]) {
251
+ delete item["x-display"];
221
252
  }
222
253
  });
254
+ };
255
+
256
+ // 5. 处理主properties
257
+ if (schema.properties) {
258
+ processProperties(schema.properties);
259
+ }
260
+
261
+ // 6. 移除form的布局属性
262
+ if (result.form) {
263
+ delete result.form.labelCol;
264
+ delete result.form.wrapperCol;
223
265
  }
224
266
 
225
267
  return result;
226
- };
268
+ }