@hzab/list-render 1.10.20-alpha.0 → 1.10.20
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/CHANGELOG.md +4 -0
- package/README.md +0 -10
- package/package.json +3 -3
- package/src/components/Formily/{--FormilyEditTable.tsx → FormilyEditTable.tsx} +3 -74
- package/src/list-render.jsx +2 -8
- package/src/pagination-render/index.less +54 -11
- package/src/table-render/index.jsx +83 -117
- package/src/EditArrayTable/index.less +0 -11
- package/src/EditArrayTable/index.tsx +0 -198
- package/src/components/Formily/FormilyEditTable/EditTableCell.tsx +0 -157
- package/src/components/Formily/FormilyEditTable/EditTableRow.tsx +0 -71
- package/src/components/Formily/FormilyEditTable/index.tsx +0 -229
- package/src/components/Formily/FormilyEditTable/type.d.ts +0 -6
- package/src/components/Formily/FormilyEditTable/useTableFormilyContext.ts +0 -17
- package/src/components/Formily/SchemaToArrayTable.ts +0 -266
|
@@ -1,266 +0,0 @@
|
|
|
1
|
-
import { cloneDeep } from "lodash";
|
|
2
|
-
import { nanoidNumALetters } from "@hzab/utils/src/nanoid";
|
|
3
|
-
import { Schema } from "@formily/json-schema";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* 普通的 schema 表单字段转为自增表格的列
|
|
7
|
-
* @returns
|
|
8
|
-
*/
|
|
9
|
-
export class SchemaToArrayTable {
|
|
10
|
-
_schema: {
|
|
11
|
-
form: {};
|
|
12
|
-
schema: Schema;
|
|
13
|
-
};
|
|
14
|
-
option = {};
|
|
15
|
-
constructor(params) {
|
|
16
|
-
const { schema, option } = params || {};
|
|
17
|
-
this._schema = cloneDeep(schema);
|
|
18
|
-
this.option = option || {};
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* 处理 schema,把普通的 schema 表单字段转为自增表格的列
|
|
22
|
-
* @returns
|
|
23
|
-
*/
|
|
24
|
-
handleSchema(schema = this._schema, opt?) {
|
|
25
|
-
const { isDargTable, hasAction } = opt || this.option;
|
|
26
|
-
const schemaTpl = this.getSchemaTpl();
|
|
27
|
-
const properties: Record<string, any> = {};
|
|
28
|
-
// schema 布局信息
|
|
29
|
-
schemaTpl.form = {
|
|
30
|
-
...schema.form,
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
// 添加拖拽排序列
|
|
34
|
-
isDargTable && this.pushItem(properties, this.getSortTpl());
|
|
35
|
-
// 添加序号
|
|
36
|
-
isDargTable && this.pushItem(properties, this.getIndexTpl());
|
|
37
|
-
// 处理表单数据列
|
|
38
|
-
Object.keys(schema.schema?.properties).forEach((key, i) => {
|
|
39
|
-
const it = schema.schema?.properties[key];
|
|
40
|
-
// @ts-ignore
|
|
41
|
-
if (it.inTable === false) {
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
this.pushItem(properties, this.handleCol(it));
|
|
45
|
-
});
|
|
46
|
-
// 添加操作列
|
|
47
|
-
hasAction !== false && this.pushItem(properties, this.getActionsTpl());
|
|
48
|
-
// 添加移动排序操作列
|
|
49
|
-
isDargTable && this.pushItem(properties, this.getMoveActionsTpl());
|
|
50
|
-
|
|
51
|
-
schemaTpl.schema.properties.arrayTable.items.properties = properties;
|
|
52
|
-
console.log("schemaTpl", schemaTpl);
|
|
53
|
-
|
|
54
|
-
return schemaTpl;
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* 处理列的数据
|
|
58
|
-
* @param {*} item
|
|
59
|
-
* @param {*} idx
|
|
60
|
-
* @returns
|
|
61
|
-
*/
|
|
62
|
-
handleCol(item, idx = 0) {
|
|
63
|
-
const id = `${item.name}-${nanoidNumALetters()}`;
|
|
64
|
-
const _item = cloneDeep(item);
|
|
65
|
-
_item.title = "";
|
|
66
|
-
return {
|
|
67
|
-
type: "void",
|
|
68
|
-
"x-component": "ArrayTable.Column",
|
|
69
|
-
"x-component-props": {
|
|
70
|
-
title: item.title,
|
|
71
|
-
},
|
|
72
|
-
"x-designable-id": id,
|
|
73
|
-
name: id,
|
|
74
|
-
"x-index": idx,
|
|
75
|
-
properties: {
|
|
76
|
-
[item.name]: _item,
|
|
77
|
-
},
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* 在 properties 中指定序号添加一项
|
|
82
|
-
* @param {*} properties
|
|
83
|
-
* @param {*} item
|
|
84
|
-
* @param {*} idx
|
|
85
|
-
*/
|
|
86
|
-
addItem(properties, item, idx) {
|
|
87
|
-
// 数组存放实际顺序
|
|
88
|
-
const arr = [];
|
|
89
|
-
// 获取当前排序的数组
|
|
90
|
-
Object.keys(properties).forEach((key) => {
|
|
91
|
-
const it = properties[key];
|
|
92
|
-
arr[it["x-index"]] = it;
|
|
93
|
-
});
|
|
94
|
-
// 在指定位置添加项
|
|
95
|
-
arr.splice(idx, 0, item);
|
|
96
|
-
// 根据数组顺序更新源数据
|
|
97
|
-
arr.forEach((it) => {
|
|
98
|
-
properties[it.name] = it;
|
|
99
|
-
});
|
|
100
|
-
return properties;
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* 在 properties 中添加一项
|
|
104
|
-
* @param {*} properties
|
|
105
|
-
* @param {*} item
|
|
106
|
-
*/
|
|
107
|
-
pushItem(properties, item) {
|
|
108
|
-
properties[item.name] = cloneDeep(item);
|
|
109
|
-
properties[item.name]["x-index"] = Object.keys(properties).length - 1;
|
|
110
|
-
return properties;
|
|
111
|
-
}
|
|
112
|
-
sortItems() {}
|
|
113
|
-
/**
|
|
114
|
-
* 获取 schema 模板字符串
|
|
115
|
-
* @returns
|
|
116
|
-
*/
|
|
117
|
-
getSchemaTpl() {
|
|
118
|
-
return {
|
|
119
|
-
form: {},
|
|
120
|
-
schema: {
|
|
121
|
-
type: "object",
|
|
122
|
-
properties: {
|
|
123
|
-
arrayTable: {
|
|
124
|
-
type: "array",
|
|
125
|
-
"x-decorator": "FormItem",
|
|
126
|
-
"x-component": "ArrayTable",
|
|
127
|
-
"x-validator": [],
|
|
128
|
-
"x-component-props": {
|
|
129
|
-
pagination: false,
|
|
130
|
-
onSortStart() {
|
|
131
|
-
console.log("onSortStart");
|
|
132
|
-
},
|
|
133
|
-
onSortEnd() {
|
|
134
|
-
console.log("onSortEnd");
|
|
135
|
-
},
|
|
136
|
-
},
|
|
137
|
-
"x-decorator-props": {},
|
|
138
|
-
"x-designable-id": "arrayTable",
|
|
139
|
-
"x-index": 0,
|
|
140
|
-
items: {
|
|
141
|
-
type: "object",
|
|
142
|
-
"x-designable-id": "gbmerqeme8g",
|
|
143
|
-
properties: {
|
|
144
|
-
// 自增表格列
|
|
145
|
-
},
|
|
146
|
-
},
|
|
147
|
-
// 新增按钮
|
|
148
|
-
properties: {
|
|
149
|
-
// cs1marpxdon: {
|
|
150
|
-
// type: "void",
|
|
151
|
-
// title: "Addition",
|
|
152
|
-
// "x-component": "ArrayTable.Addition",
|
|
153
|
-
// "x-designable-id": "cs1marpxdon",
|
|
154
|
-
// "x-index": 0,
|
|
155
|
-
// },
|
|
156
|
-
},
|
|
157
|
-
},
|
|
158
|
-
},
|
|
159
|
-
"x-designable-id": "un3pxnx4ong",
|
|
160
|
-
},
|
|
161
|
-
};
|
|
162
|
-
}
|
|
163
|
-
/**
|
|
164
|
-
* 获取排序列模板字符串
|
|
165
|
-
* @returns
|
|
166
|
-
*/
|
|
167
|
-
getSortTpl() {
|
|
168
|
-
return {
|
|
169
|
-
name: "sort",
|
|
170
|
-
type: "void",
|
|
171
|
-
"x-component": "ArrayTable.Column",
|
|
172
|
-
"x-component-props": {
|
|
173
|
-
title: "",
|
|
174
|
-
},
|
|
175
|
-
"x-designable-id": "l3z7t4ff7zw",
|
|
176
|
-
"x-index": 0,
|
|
177
|
-
properties: {
|
|
178
|
-
g0cxfnsnevh: {
|
|
179
|
-
type: "void",
|
|
180
|
-
"x-component": "ArrayTable.SortHandle",
|
|
181
|
-
"x-designable-id": "g0cxfnsnevh",
|
|
182
|
-
"x-index": 0,
|
|
183
|
-
},
|
|
184
|
-
},
|
|
185
|
-
};
|
|
186
|
-
}
|
|
187
|
-
getIndexTpl() {
|
|
188
|
-
return {
|
|
189
|
-
name: "index",
|
|
190
|
-
type: "void",
|
|
191
|
-
"x-component": "ArrayTable.Column",
|
|
192
|
-
"x-component-props": {
|
|
193
|
-
title: "序号",
|
|
194
|
-
},
|
|
195
|
-
"x-designable-id": "4ps6b3ut7ft",
|
|
196
|
-
properties: {
|
|
197
|
-
TableIndex: {
|
|
198
|
-
type: "void",
|
|
199
|
-
"x-component": "TableIndex",
|
|
200
|
-
"x-designable-id": "TableIndex",
|
|
201
|
-
"x-index": 0,
|
|
202
|
-
},
|
|
203
|
-
},
|
|
204
|
-
};
|
|
205
|
-
}
|
|
206
|
-
/**
|
|
207
|
-
* 获取操作列模板字符串
|
|
208
|
-
* @returns
|
|
209
|
-
*/
|
|
210
|
-
getActionsTpl() {
|
|
211
|
-
return {
|
|
212
|
-
name: "actions",
|
|
213
|
-
type: "void",
|
|
214
|
-
"x-component": "ArrayTable.Column",
|
|
215
|
-
"x-component-props": {
|
|
216
|
-
title: "操作",
|
|
217
|
-
},
|
|
218
|
-
"x-designable-id": "actions",
|
|
219
|
-
properties: {
|
|
220
|
-
tableActions: {
|
|
221
|
-
type: "void",
|
|
222
|
-
"x-component": "TableActions",
|
|
223
|
-
"x-designable-id": "tableActions",
|
|
224
|
-
"x-index": 0,
|
|
225
|
-
},
|
|
226
|
-
},
|
|
227
|
-
};
|
|
228
|
-
}
|
|
229
|
-
/**
|
|
230
|
-
* 获取移动排序操作列模板字符串
|
|
231
|
-
* @returns
|
|
232
|
-
*/
|
|
233
|
-
getMoveActionsTpl() {
|
|
234
|
-
return {
|
|
235
|
-
name: "move-actions",
|
|
236
|
-
type: "void",
|
|
237
|
-
"x-component": "ArrayTable.Column",
|
|
238
|
-
"x-component-props": {
|
|
239
|
-
title: "",
|
|
240
|
-
},
|
|
241
|
-
"x-designable-id": "move-actions",
|
|
242
|
-
properties: {
|
|
243
|
-
xynjkn08lvp: {
|
|
244
|
-
type: "void",
|
|
245
|
-
"x-component": "ArrayTable.Remove",
|
|
246
|
-
"x-designable-id": "xynjkn08lvp",
|
|
247
|
-
"x-index": 0,
|
|
248
|
-
},
|
|
249
|
-
gvl20uo8m8q: {
|
|
250
|
-
type: "void",
|
|
251
|
-
"x-component": "ArrayTable.MoveDown",
|
|
252
|
-
"x-designable-id": "gvl20uo8m8q",
|
|
253
|
-
"x-index": 1,
|
|
254
|
-
},
|
|
255
|
-
"4c8wbndejhy": {
|
|
256
|
-
type: "void",
|
|
257
|
-
"x-component": "ArrayTable.MoveUp",
|
|
258
|
-
"x-designable-id": "4c8wbndejhy",
|
|
259
|
-
"x-index": 2,
|
|
260
|
-
},
|
|
261
|
-
},
|
|
262
|
-
};
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
export default SchemaToArrayTable;
|