@hzab/list-render 1.10.21-alpha.4 → 1.10.21-alpha.6

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.
@@ -17,7 +17,7 @@ import { getVal, getFieldList } from "../common/utils";
17
17
  import { handleReactions } from "../common/handleReactions";
18
18
 
19
19
  import { useEditTable, EditableCell } from "../components/Formily/FormilyEditTable";
20
- import CellEditTable from "../components/CellEditTable"
20
+ import CellEditTable from "@hzab/edit-table"
21
21
  import "./index.less";
22
22
 
23
23
  const scenario = "table-render";
@@ -99,12 +99,133 @@ const TableRender = forwardRef(function (props, tableRef) {
99
99
  topProps: props.topProps,
100
100
  });
101
101
 
102
+ /** 处理childrn */
103
+ const handleChildColumns = (childColumns) => {
104
+ const fieldSchemas = formilyRef.current?.fields;
105
+ const { Slots = {} } = props;
106
+ return childColumns?.map((item, colIndex) => {
107
+ if (!(item.inTable !== false)) return
108
+
109
+ const { name, title } = item;
110
+ const comName = item["x-component"];
111
+ let _colConf = {};
112
+ if (props.config?.colConf && props.config?.colConf[item?.name]) {
113
+ _colConf = props.config?.colConf[item?.name];
114
+ }
115
+
116
+ let colRender = undefined;
117
+ if (Slots && Slots[item?.name]) {
118
+ colRender = function (text, record, index) {
119
+ const Slot = Slots[item?.name];
120
+ const slotProps = {
121
+ text,
122
+ record,
123
+ index,
124
+ field: { ...item, ...fieldSchemas?.[item?.name] },
125
+ fieldSchema: fieldSchemas?.[item?.name],
126
+ };
127
+ return <Slot {...slotProps} />;
128
+ };
129
+ } else {
130
+ colRender = function (text, record, index, ...args) {
131
+ const { width, ellipsis, emptyValue, showTags, showPrefixNode, showMode, enumRenderProps } = _colConf || {};
132
+ const schemaDefaultValue = fieldSchemas[item?.name]?.componentProps?.emptyValue;
133
+ const defaultValue = emptyValue ?? schemaDefaultValue ?? tableEmptyValue ?? "";
134
+
135
+ let val = getVal({ ...item, ...fieldSchemas[item?.name] }, record, {
136
+ fieldSchema: fieldSchemas?.[item?.name],
137
+ });
138
+
139
+ if (val === "" || val === undefined || val === null) {
140
+ val = defaultValue;
141
+ }
142
+
143
+ const content = (
144
+ <span className="inline-block-max-w" style={{ width }} title={ellipsis?.showTitle ? val : ""}>
145
+ {val}
146
+ </span>
147
+ );
148
+ if (ellipsis === true || (ellipsis && ellipsis?.showTitle != true)) {
149
+ return (
150
+ <Tooltip className="table-cell-ellipsis" {...ellipsis} title={val}>
151
+ {content}
152
+ </Tooltip>
153
+ );
154
+ }
155
+
156
+ if (showMode || showTags || showPrefixNode || (showPrefixNode !== false && comName === "Switch")) {
157
+ // field 通过 fieldSchemas 获取最新的 field 数据
158
+ let _showMode = showMode;
159
+ if (showTags) {
160
+ _showMode = SHOW_MODE_TYPES.tags;
161
+ } else if (showPrefixNode) {
162
+ _showMode = SHOW_MODE_TYPES.prefixNode;
163
+ }
164
+
165
+ return (
166
+ <EnumRender
167
+ showMode={_showMode}
168
+ value={_.get(record, item?.name)}
169
+ field={{ ...field, ...fieldSchemas?.[item?.name] }}
170
+ {...enumRenderProps}
171
+ />
172
+ );
173
+ }
174
+
175
+ return content;
176
+ };
177
+ }
178
+
179
+
180
+ let _title = isFunction(title) ? title() : title;
181
+ if (_colConf?.title) {
182
+ _title = isFunction(_colConf?.title) ? _colConf?.title() : _colConf?.title;
183
+ }
184
+ const decoratorProps = item["x-decorator-props"] || {};
185
+ if (decoratorProps.tooltip) {
186
+ _title = (
187
+ <span className="col-title-tooltip-wrap inline-block-max-w">
188
+ {_title}
189
+ <Tooltip className="col-title-tooltip" title={decoratorProps.tooltip}>
190
+ <QuestionCircleOutlined className="col-title-tooltip-icon" />
191
+ </Tooltip>
192
+ </span>
193
+ );
194
+ }
195
+ const childSelectList = fieldSchemas?.[item?.name]?.dataSource?.map((el) => ({
196
+ ...el,
197
+ label: el?.[item?.["x-component-props"]?.["fieldNames"]?.["label"]] || el?.label,
198
+ value: el?.[item?.["x-component-props"]?.["fieldNames"]?.["value"]] || el?.value,
199
+ }))
200
+ return {
201
+ getField: () => item,
202
+ editable: true,
203
+ ..._colConf,
204
+ onCell: (record, rowIndex, ci) =>
205
+ _colConf?.onCell?.({ ...record, _field: { ...item, ...(fieldSchemas?.[item?.name] || {}) } }, rowIndex, ci) || {},
206
+ // 函数式传入,解决 title ReactNode 传入报错问题(table 组件内部对 columns 进行 lodash.deepClone 导致 ReactNode 变成对象无法正常渲染) Uncaught TypeError: this.queryFeedbacks is not a function
207
+ title: () => _title,
208
+ key: item?.name,
209
+ dataIndex: item?.name,
210
+ type: item["x-validator"] == "number" ? "Number" : comName,
211
+ validatorList: item["x-validator"] || [],
212
+ nonEditable: editMode != "cell",
213
+ values: item?.enum || childSelectList || [],
214
+ cellProps: item.cellProps,
215
+ children: handleChildColumns(item?.children),
216
+ render: getColRender(colRender),
217
+ }
218
+
219
+ })
220
+
221
+
222
+ }
102
223
  useEffect(() => {
103
224
  if (!(props.schema && props.schema.properties)) {
104
225
  return;
105
226
  }
106
227
  const fieldList = getFieldList(props.schema, [], { ...props.getFieldListOpt, formilyRef }, isTableSortXIdex);
107
- const columns = [];
228
+ let columns = [];
108
229
 
109
230
  // 序号列
110
231
  if (orderColType === "page") {
@@ -130,123 +251,7 @@ const TableRender = forwardRef(function (props, tableRef) {
130
251
  scope: props.schemaScope,
131
252
  formilyRef,
132
253
  });
133
-
134
- _fieldList.forEach((field, colIndex) => {
135
- const fieldSchemas = formilyRef.current?.fields;
136
- if (field.inTable !== false) {
137
- const { name, title } = field;
138
- const comName = field["x-component"];
139
-
140
- let _colConf = {};
141
-
142
- if (props.config?.colConf && props.config?.colConf[name]) {
143
- _colConf = props.config?.colConf[name];
144
- }
145
-
146
- let colRender = undefined;
147
- if (Slots && Slots[name]) {
148
- colRender = function (text, record, index) {
149
- const Slot = Slots[name];
150
- const slotProps = {
151
- text,
152
- record,
153
- index,
154
- field: { ...field, ...fieldSchemas?.[name] },
155
- fieldSchema: fieldSchemas?.[name],
156
- };
157
- return <Slot {...slotProps} />;
158
- };
159
- } else {
160
- colRender = function (text, record, index, ...args) {
161
- const { width, ellipsis, emptyValue, showTags, showPrefixNode, showMode, enumRenderProps } = _colConf || {};
162
- const schemaDefaultValue = fieldSchemas[name]?.componentProps?.emptyValue;
163
- const defaultValue = emptyValue ?? schemaDefaultValue ?? tableEmptyValue ?? "";
164
-
165
- let val = getVal({ ...field, ...fieldSchemas[name] }, record, {
166
- fieldSchema: fieldSchemas?.[name],
167
- });
168
-
169
- if (val === "" || val === undefined || val === null) {
170
- val = defaultValue;
171
- }
172
-
173
- const content = (
174
- <span className="inline-block-max-w" style={{ width }} title={ellipsis?.showTitle ? val : ""}>
175
- {val}
176
- </span>
177
- );
178
- if (ellipsis === true || (ellipsis && ellipsis?.showTitle != true)) {
179
- return (
180
- <Tooltip className="table-cell-ellipsis" {...ellipsis} title={val}>
181
- {content}
182
- </Tooltip>
183
- );
184
- }
185
-
186
- if (showMode || showTags || showPrefixNode || (showPrefixNode !== false && comName === "Switch")) {
187
- // field 通过 fieldSchemas 获取最新的 field 数据
188
- let _showMode = showMode;
189
- if (showTags) {
190
- _showMode = SHOW_MODE_TYPES.tags;
191
- } else if (showPrefixNode) {
192
- _showMode = SHOW_MODE_TYPES.prefixNode;
193
- }
194
-
195
- return (
196
- <EnumRender
197
- showMode={_showMode}
198
- value={_.get(record, name)}
199
- field={{ ...field, ...fieldSchemas?.[name] }}
200
- {...enumRenderProps}
201
- />
202
- );
203
- }
204
-
205
- return content;
206
- };
207
- }
208
-
209
- let _title = isFunction(title) ? title() : title;
210
- if (_colConf?.title) {
211
- _title = isFunction(_colConf?.title) ? _colConf?.title() : _colConf?.title;
212
- }
213
- const decoratorProps = field["x-decorator-props"] || {};
214
- if (decoratorProps.tooltip) {
215
- _title = (
216
- <span className="col-title-tooltip-wrap inline-block-max-w">
217
- {_title}
218
- <Tooltip className="col-title-tooltip" title={decoratorProps.tooltip}>
219
- <QuestionCircleOutlined className="col-title-tooltip-icon" />
220
- </Tooltip>
221
- </span>
222
- );
223
- }
224
- const selectList = fieldSchemas?.[name]?.dataSource?.map((el) => ({
225
- ...el,
226
- label: el?.[field?.["x-component-props"]?.["fieldNames"]?.["label"]] || el?.label,
227
- value: el?.[field?.["x-component-props"]?.["fieldNames"]?.["value"]] || el?.value,
228
- }))
229
-
230
- columns.push({
231
- // field, // HACK: 直接传入 field 在 title 传入 ReactNode,内部深克隆导致页面报错白屏。使用函数获取解决
232
- getField: () => field,
233
- editable: true,
234
- ..._colConf,
235
- onCell: (record, rowIndex, ci) =>
236
- _colConf?.onCell?.({ ...record, _field: { ...field, ...(fieldSchemas?.[name] || {}) } }, rowIndex, ci) || {},
237
- // 函数式传入,解决 title ReactNode 传入报错问题(table 组件内部对 columns 进行 lodash.deepClone 导致 ReactNode 变成对象无法正常渲染) Uncaught TypeError: this.queryFeedbacks is not a function
238
- title: () => _title,
239
- key: name,
240
- dataIndex: name,
241
- type: field["x-validator"] == "number" ? "Number" : comName,
242
- nonEditable: editMode != "cell",
243
- values: field?.enum || selectList || [],
244
- cellProps: field.cellProps,
245
- children: field?.children,
246
- render: getColRender(colRender),
247
- });
248
- }
249
- });
254
+ columns = columns.concat(handleChildColumns(_fieldList))
250
255
 
251
256
  if (props.hasAction !== false) {
252
257
  const { hasEdit, hasDel, hasDelTips, hasDetail = false } = props.config || {};
@@ -1,202 +0,0 @@
1
- // import * as React from "react";
2
-
3
- // import {
4
- // Cell,
5
- // CellTemplate,
6
- // Compatible,
7
- // getCellProperty,
8
- // getCharFromKey,
9
- // isAlphaNumericKey,
10
- // keyCodes,
11
- // Uncertain,
12
- // UncertainCompatible,
13
- // } from "@silevis/reactgrid";
14
- // import { getVal } from "../../../common/utils";
15
-
16
- // import { Select } from "antd";
17
- // import { WidthWrap } from "./widthWrap";
18
-
19
- // export type OptionType = {
20
- // label: string;
21
- // value: string;
22
- // isDisabled?: boolean;
23
- // };
24
-
25
- // export interface SelectCell extends Cell {
26
- // type: "Select";
27
- // selectedValue?: string;
28
- // value: string | number;
29
- // values: OptionType[];
30
- // isDisabled?: boolean;
31
- // isOpen?: boolean;
32
- // inputValue?: string;
33
- // }
34
-
35
- // export class createSelectCellTemplate implements CellTemplate<SelectCell> {
36
- // getCompatibleCell(uncertainCell: Uncertain<SelectCell>): Compatible<SelectCell> {
37
- // let selectedValue: string | undefined;
38
- // try {
39
- // selectedValue = getCellProperty(uncertainCell, "selectedValue", "number");
40
- // } catch {
41
- // selectedValue = undefined;
42
- // }
43
- // const values = getCellProperty(uncertainCell, "values", "object");
44
- // const value = selectedValue ? parseFloat(selectedValue) : NaN;
45
-
46
- // let isDisabled = true;
47
- // try {
48
- // isDisabled = getCellProperty(uncertainCell, "isDisabled", "boolean");
49
- // } catch {
50
- // isDisabled = false;
51
- // }
52
-
53
- // let inputValue: string | undefined;
54
- // try {
55
- // inputValue = getCellProperty(uncertainCell, "inputValue", "string");
56
- // } catch {
57
- // inputValue = undefined;
58
- // }
59
-
60
- // let isOpen: boolean;
61
- // try {
62
- // isOpen = getCellProperty(uncertainCell, "isOpen", "boolean");
63
- // } catch {
64
- // isOpen = false;
65
- // }
66
-
67
- // const text = selectedValue || "";
68
-
69
- // return { ...uncertainCell, selectedValue, text, value, isOpen, values, isDisabled, inputValue };
70
- // }
71
-
72
- // update(cell: Compatible<SelectCell>, cellToMerge: UncertainCompatible<SelectCell>): Compatible<SelectCell> {
73
- // const selectedValueFromText = cell.values.some((val: any) => val.value === cellToMerge.text)
74
- // ? cellToMerge.text
75
- // : undefined;
76
- // return this.getCompatibleCell({
77
- // ...cell,
78
- // selectedValue: selectedValueFromText,
79
- // isOpen: cellToMerge?.isOpen,
80
- // inputValue: cellToMerge.inputValue,
81
- // });
82
- // }
83
-
84
- // getClassName(cell: Compatible<SelectCell>, isInEditMode: boolean): string {
85
- // const isOpen = cell.isOpen ? "open" : "closed";
86
- // return `${cell.className ? cell.className : ""}${isOpen}`;
87
- // }
88
-
89
- // handleKeyDown(
90
- // cell: Compatible<SelectCell>,
91
- // keyCode: number,
92
- // ctrl: boolean,
93
- // shift: boolean,
94
- // alt: boolean,
95
- // key: string,
96
- // capsLock: boolean,
97
- // ): { cell: Compatible<SelectCell>; enableEditMode: boolean } {
98
- // if ((keyCode === keyCodes.SPACE || keyCode === keyCodes.ENTER) && !shift) {
99
- // return {
100
- // cell: this.getCompatibleCell({
101
- // ...cell,
102
- // isOpen: !cell.isOpen,
103
- // }),
104
- // enableEditMode: false,
105
- // };
106
- // }
107
-
108
- // const char = getCharFromKey(key, shift, capsLock);
109
-
110
- // if (!ctrl && !alt && isAlphaNumericKey(keyCode) && !(shift && keyCode === keyCodes.SPACE))
111
- // return {
112
- // cell: this.getCompatibleCell({
113
- // ...cell,
114
- // inputValue: char,
115
- // isOpen: !cell.isOpen,
116
- // }),
117
- // enableEditMode: false,
118
- // };
119
-
120
- // return { cell, enableEditMode: false };
121
- // }
122
-
123
- // handleCompositionEnd(
124
- // cell: Compatible<SelectCell>,
125
- // eventData: any,
126
- // ): { cell: Compatible<SelectCell>; enableEditMode: boolean } {
127
- // return {
128
- // cell: {
129
- // ...cell,
130
- // inputValue: eventData,
131
- // isOpen: !cell.isOpen,
132
- // },
133
- // enableEditMode: false,
134
- // };
135
- // }
136
-
137
- // render(
138
- // cell: Compatible<SelectCell>,
139
- // isInEditMode: boolean,
140
- // onCellChanged: (cell: Compatible<SelectCell>, commit: boolean) => void,
141
- // ): React.ReactNode {
142
- // return (
143
- // <SelectInput
144
- // onCellChanged={(cell) => onCellChanged(this.getCompatibleCell(cell), true)}
145
- // cell={cell}
146
- // isInEditMode={isInEditMode}
147
- // />
148
- // );
149
- // }
150
- // }
151
-
152
- // interface DIProps {
153
- // onCellChanged: (...args: any[]) => void;
154
- // cell: Record<string, any>;
155
- // isInEditMode?: boolean;
156
- // }
157
-
158
- // const SelectInput: React.FC<DIProps> = ({ onCellChanged, cell, isInEditMode }) => {
159
- // const [isOpen, setIsOpen] = React.useState<boolean>(false);
160
- // const datatypeId = cell?.columnId + cell?.rowId;
161
- // React.useEffect(() => {
162
- // // 处理下拉选项弹层失焦逻辑
163
- // function onClick() {
164
- // if (window.gridEditId != datatypeId) {
165
- // setIsOpen(false);
166
- // }
167
- // }
168
- // document.addEventListener("click", onClick);
169
- // return () => {
170
- // document.removeEventListener("click", onClick);
171
- // };
172
- // }, []);
173
-
174
- // return (
175
- // <div
176
- // style={{ width: "100%", height: "100%" }}
177
- // onDoubleClick={(e) => {
178
- // setIsOpen(true);
179
- // }}
180
- // >
181
- // {isOpen ? (
182
- // <div onPointerDown={(e) => e.stopPropagation()}>
183
- // <Select
184
- // open={isOpen}
185
- // style={{ width: "100%" }}
186
- // value={cell?.selectedValue}
187
- // options={cell.values}
188
- // onChange={(e) => {
189
- // onCellChanged({ ...cell, selectedValue: e });
190
- // }}
191
- // ></Select>
192
- // </div>
193
- // ) : (
194
- // <div style={{ height: "100%" }}>
195
- // {getVal(cell?.getField(), { [cell?.getField().name]: cell?.selectedValue })}
196
- // </div>
197
- // )}
198
- // </div>
199
- // );
200
- // };
201
-
202
- // export const SelectTemplate = WidthWrap(Select);