@hw-component/table 1.2.6 → 1.2.8
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/.eslintcache +1 -1
- package/es/HTableBody/Options/utils.d.ts +1 -0
- package/es/HTableBody/RowSelection.js +3 -3
- package/es/HTableBody/hooks.js +5 -7
- package/es/TableConfig.d.ts +4 -2
- package/es/TableConfig.js +5 -2
- package/es/modal.d.ts +4 -3
- package/es/render/TagsComponent.d.ts +20 -0
- package/es/render/TagsComponent.js +123 -0
- package/es/render/config.d.ts +11 -0
- package/es/render/config.js +137 -0
- package/es/render/index.d.ts +5 -0
- package/es/render/index.js +25 -0
- package/lib/HTableBody/Options/utils.d.ts +1 -0
- package/lib/HTableBody/RowSelection.js +3 -3
- package/lib/HTableBody/hooks.js +5 -7
- package/lib/TableConfig.d.ts +4 -2
- package/lib/TableConfig.js +5 -2
- package/lib/modal.d.ts +4 -3
- package/lib/render/TagsComponent.d.ts +20 -0
- package/lib/render/TagsComponent.js +126 -0
- package/lib/render/config.d.ts +11 -0
- package/lib/render/config.js +140 -0
- package/lib/render/index.d.ts +5 -0
- package/lib/render/index.js +28 -0
- package/package.json +2 -1
- package/src/components/HTableBody/RowSelection.tsx +10 -8
- package/src/components/HTableBody/hooks.tsx +5 -8
- package/src/components/HTableBody/index.tsx +64 -67
- package/src/components/HTableHeader/index.tsx +4 -2
- package/src/components/HTablePagination/index.tsx +4 -2
- package/src/components/Table.tsx +9 -4
- package/src/components/TableConfig.tsx +19 -12
- package/src/components/modal.ts +11 -3
- package/src/components/render/TagsComponent.tsx +122 -0
- package/src/components/render/config.tsx +110 -0
- package/src/components/render/index.tsx +25 -0
- package/src/pages/Table/index.tsx +160 -80
|
@@ -21,8 +21,10 @@ export const RowSelectionTitle = ({
|
|
|
21
21
|
});
|
|
22
22
|
const { keys, selectAll } = selectedRowData;
|
|
23
23
|
const allCheck = () => {
|
|
24
|
-
const setKeys = newData.map((item,index) => {
|
|
25
|
-
return typeof rowKey==="function"
|
|
24
|
+
const setKeys = newData.map((item, index) => {
|
|
25
|
+
return typeof rowKey === "function"
|
|
26
|
+
? rowKey(item, index)
|
|
27
|
+
: item[rowKey as string];
|
|
26
28
|
});
|
|
27
29
|
rowOnChange(setKeys, newData);
|
|
28
30
|
onChange?.(setKeys, newData);
|
|
@@ -106,17 +108,17 @@ interface RowSelectionBoxProps {
|
|
|
106
108
|
data: any;
|
|
107
109
|
onChange?: HRowSelection["onChange"];
|
|
108
110
|
getCheckboxProps?: HRowSelection["getCheckboxProps"];
|
|
109
|
-
index:number;
|
|
111
|
+
index: number;
|
|
110
112
|
}
|
|
111
113
|
export const RowSelectionBox = ({
|
|
112
114
|
data,
|
|
113
115
|
onChange,
|
|
114
|
-
|
|
116
|
+
index,
|
|
115
117
|
getCheckboxProps,
|
|
116
118
|
}: RowSelectionBoxProps) => {
|
|
117
119
|
const { selectedRowData, rowOnChange, rowKey = "id" } = useHTableContext();
|
|
118
120
|
const { rowData = [], keys = [] } = selectedRowData;
|
|
119
|
-
const key = typeof rowKey==="function"?rowKey(data,index):data[rowKey];
|
|
121
|
+
const key = typeof rowKey === "function" ? rowKey(data, index) : data[rowKey];
|
|
120
122
|
const check = (e) => {
|
|
121
123
|
const checked = e.target.checked;
|
|
122
124
|
const newKeys = [...keys];
|
|
@@ -128,9 +130,9 @@ export const RowSelectionBox = ({
|
|
|
128
130
|
onChange?.(newKeys, newRowData);
|
|
129
131
|
return;
|
|
130
132
|
}
|
|
131
|
-
const
|
|
132
|
-
newKeys.splice(
|
|
133
|
-
newRowData.splice(
|
|
133
|
+
const keyIndex = newKeys.indexOf(key);
|
|
134
|
+
newKeys.splice(keyIndex, 1);
|
|
135
|
+
newRowData.splice(keyIndex, 1);
|
|
134
136
|
rowOnChange(newKeys, newRowData);
|
|
135
137
|
onChange?.(newKeys, newRowData);
|
|
136
138
|
};
|
|
@@ -12,6 +12,8 @@ import type { SizeType } from "antd/lib/config-provider/SizeContext";
|
|
|
12
12
|
import type { ColumnsStateType } from "@ant-design/pro-table/es/typing";
|
|
13
13
|
import type { ColumnsState } from "@ant-design/pro-table/es/container";
|
|
14
14
|
import { mkChangeValue, outColSetting } from "./utils";
|
|
15
|
+
import configRender from "../render";
|
|
16
|
+
import { useHTableConfigContext } from "@/components/TableConfig";
|
|
15
17
|
const rowSelectionCol = (rowSelection?: HRowSelection) => {
|
|
16
18
|
const { allPageCheck, onChange, getCheckboxProps } = rowSelection || {};
|
|
17
19
|
return {
|
|
@@ -25,7 +27,7 @@ const rowSelectionCol = (rowSelection?: HRowSelection) => {
|
|
|
25
27
|
width: 32,
|
|
26
28
|
rowSelectionTitle: true,
|
|
27
29
|
fixed: "left",
|
|
28
|
-
render: (dom, data,index) => {
|
|
30
|
+
render: (dom, data, index) => {
|
|
29
31
|
return (
|
|
30
32
|
<RowSelectionBox
|
|
31
33
|
data={data}
|
|
@@ -39,6 +41,7 @@ const rowSelectionCol = (rowSelection?: HRowSelection) => {
|
|
|
39
41
|
};
|
|
40
42
|
export const useCols = ({ configData, rowSelection, table }: HTableProps) => {
|
|
41
43
|
const [cols, setCols] = useState<ConfigDataModal>([]);
|
|
44
|
+
const { valueTypeConfig } = useHTableConfigContext({});
|
|
42
45
|
const changeConfigData = (data: ConfigDataModal) => {
|
|
43
46
|
const colsArray = data.filter((item) => {
|
|
44
47
|
return !item.hideInTable;
|
|
@@ -47,15 +50,9 @@ export const useCols = ({ configData, rowSelection, table }: HTableProps) => {
|
|
|
47
50
|
colsArray.splice(0, 0, rowSelectionCol(rowSelection) as any);
|
|
48
51
|
}
|
|
49
52
|
return colsArray.map((item) => {
|
|
50
|
-
const { render } = item;
|
|
51
53
|
return {
|
|
52
54
|
...item,
|
|
53
|
-
render: (
|
|
54
|
-
if (!render) {
|
|
55
|
-
return dom;
|
|
56
|
-
}
|
|
57
|
-
return render(dom, itemData, index, table as HTableInstance);
|
|
58
|
-
},
|
|
55
|
+
render: configRender(item, table as HTableInstance, valueTypeConfig),
|
|
59
56
|
};
|
|
60
57
|
});
|
|
61
58
|
};
|
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
} from "./hooks";
|
|
16
16
|
import { useHTableContext } from "../context";
|
|
17
17
|
import React from "react";
|
|
18
|
-
import {ConfigProvider, Empty, Alert, Space} from "antd";
|
|
18
|
+
import { ConfigProvider, Empty, Alert, Space } from "antd";
|
|
19
19
|
import { useHTableConfigContext } from "../TableConfig";
|
|
20
20
|
import HTablePagination from "../HTablePagination";
|
|
21
21
|
import { useClassName } from "../hooks";
|
|
@@ -125,76 +125,73 @@ export default ({
|
|
|
125
125
|
: optionsNode;
|
|
126
126
|
const alwaysShowAlert = keys.length > 0 || selectAll || configAlwaysShowAlert;
|
|
127
127
|
const className = useClassName("hw-table-body");
|
|
128
|
-
const {tableStyle:defaultTableStyle}=useHTableConfigContext({
|
|
128
|
+
const { tableStyle: defaultTableStyle } = useHTableConfigContext({
|
|
129
|
+
tableStyle,
|
|
130
|
+
});
|
|
129
131
|
return (
|
|
130
132
|
<div style={defaultTableStyle} className={`hw_table_body ${className}`}>
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
return tableEmptyRender?.(tableInstance);
|
|
148
|
-
}}
|
|
149
|
-
>
|
|
133
|
+
<Space size={16} direction={"vertical"} style={{ width: "100%" }}>
|
|
134
|
+
{alwaysShowAlert && (
|
|
135
|
+
<Alert
|
|
136
|
+
message={<AlertMsg actionRender={actionRender} />}
|
|
137
|
+
type="info"
|
|
138
|
+
/>
|
|
139
|
+
)}
|
|
140
|
+
<HeaderTitle headerTitle={headerTitle} rNode={defaultOptionsNode} />
|
|
141
|
+
<ConfigProvider
|
|
142
|
+
renderEmpty={() => {
|
|
143
|
+
if (error) {
|
|
144
|
+
return tableErrorRender?.(tableInstance, error);
|
|
145
|
+
}
|
|
146
|
+
return tableEmptyRender?.(tableInstance);
|
|
147
|
+
}}
|
|
148
|
+
>
|
|
150
149
|
<ProTable
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
pagination={false}
|
|
184
|
-
|
|
150
|
+
{...props}
|
|
151
|
+
columnsState={{
|
|
152
|
+
...selfColStatus,
|
|
153
|
+
value,
|
|
154
|
+
}}
|
|
155
|
+
columns={cols as any}
|
|
156
|
+
size={cuSize}
|
|
157
|
+
search={false}
|
|
158
|
+
onChange={(page, filters, sorter) => {
|
|
159
|
+
if (localSorter) {
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
const { field, order } = sorter as any;
|
|
163
|
+
const orderByField =
|
|
164
|
+
typeof order === "undefined" ? undefined : field;
|
|
165
|
+
const asc =
|
|
166
|
+
typeof order === "undefined" ? undefined : order === "ascend";
|
|
167
|
+
tableInstance.table.reloadWithParams({
|
|
168
|
+
current: 1,
|
|
169
|
+
orderByField,
|
|
170
|
+
asc,
|
|
171
|
+
});
|
|
172
|
+
}}
|
|
173
|
+
tableStyle={{
|
|
174
|
+
paddingBottom: 0,
|
|
175
|
+
}}
|
|
176
|
+
options={false}
|
|
177
|
+
rowSelection={false}
|
|
178
|
+
loading={loading}
|
|
179
|
+
rowKey={rowKey}
|
|
180
|
+
dataSource={records}
|
|
181
|
+
pagination={false}
|
|
185
182
|
/>
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
183
|
+
{pagination !== false && (
|
|
184
|
+
<HTablePagination
|
|
185
|
+
onPageChange={onPageChange}
|
|
186
|
+
paginationStyle={paginationStyle}
|
|
187
|
+
affixProps={affixProps}
|
|
188
|
+
goTop={goTop}
|
|
189
|
+
actionRender={paginationActionRender}
|
|
190
|
+
{...pagination}
|
|
191
|
+
/>
|
|
192
|
+
)}
|
|
193
|
+
</ConfigProvider>
|
|
194
|
+
</Space>
|
|
198
195
|
</div>
|
|
199
196
|
);
|
|
200
197
|
};
|
|
@@ -6,7 +6,7 @@ import { useClassName } from "../hooks";
|
|
|
6
6
|
import type { IHeaderProps } from "./modal";
|
|
7
7
|
import { useHideMoreTitle } from "./hooks";
|
|
8
8
|
import { HeaderProvider } from "./Context";
|
|
9
|
-
import {useHTableConfigContext} from "../TableConfig";
|
|
9
|
+
import { useHTableConfigContext } from "../TableConfig";
|
|
10
10
|
|
|
11
11
|
const defaultSearchSpan = {
|
|
12
12
|
xxl: 4,
|
|
@@ -45,7 +45,9 @@ export default ({
|
|
|
45
45
|
typeof hideLabel === "undefined" ? contextHideLabel : hideLabel;
|
|
46
46
|
const tableLabelWidth = labelWidth || contextLabelWidth;
|
|
47
47
|
const className = useClassName("hw-table-header");
|
|
48
|
-
const {headerStyle:defaultHeaderStyle}=useHTableConfigContext({
|
|
48
|
+
const { headerStyle: defaultHeaderStyle } = useHTableConfigContext({
|
|
49
|
+
headerStyle,
|
|
50
|
+
});
|
|
49
51
|
return (
|
|
50
52
|
<Card
|
|
51
53
|
style={defaultHeaderStyle}
|
|
@@ -6,7 +6,7 @@ import { useClassName } from "../hooks";
|
|
|
6
6
|
import React, { useState } from "react";
|
|
7
7
|
import type { AffixProps } from "antd/lib/affix";
|
|
8
8
|
import GoTop from "../GoTop";
|
|
9
|
-
import {useHTableConfigContext} from "@/components/TableConfig";
|
|
9
|
+
import { useHTableConfigContext } from "@/components/TableConfig";
|
|
10
10
|
export interface IPaginationProps extends PaginationProps {
|
|
11
11
|
onPageChange?: (params: ParamsModal) => void;
|
|
12
12
|
paginationStyle?: React.CSSProperties;
|
|
@@ -37,7 +37,9 @@ export default ({
|
|
|
37
37
|
if (!data) {
|
|
38
38
|
return <></>;
|
|
39
39
|
}
|
|
40
|
-
const {paginationStyle:defaultPaginationStyle}=useHTableConfigContext({
|
|
40
|
+
const { paginationStyle: defaultPaginationStyle } = useHTableConfigContext({
|
|
41
|
+
paginationStyle,
|
|
42
|
+
});
|
|
41
43
|
|
|
42
44
|
if (affixProps === false) {
|
|
43
45
|
return (
|
package/src/components/Table.tsx
CHANGED
|
@@ -8,7 +8,7 @@ import type { HTableProps } from "./modal";
|
|
|
8
8
|
import useReq from "./hooks/useReq";
|
|
9
9
|
import useDispatch from "./hooks/useDispatch";
|
|
10
10
|
import { useState } from "react";
|
|
11
|
-
import {useClassName} from "
|
|
11
|
+
import { useClassName } from "./hooks";
|
|
12
12
|
export default ({
|
|
13
13
|
request,
|
|
14
14
|
configData,
|
|
@@ -57,8 +57,8 @@ export default ({
|
|
|
57
57
|
selectedRowData,
|
|
58
58
|
dataSource: data,
|
|
59
59
|
});
|
|
60
|
-
|
|
61
|
-
|
|
60
|
+
const contentClassName = useClassName("hw-table-content");
|
|
61
|
+
return (
|
|
62
62
|
<HTableContext.Provider
|
|
63
63
|
value={{
|
|
64
64
|
tableInstance,
|
|
@@ -83,7 +83,12 @@ export default ({
|
|
|
83
83
|
labelWidth,
|
|
84
84
|
}}
|
|
85
85
|
>
|
|
86
|
-
<Space
|
|
86
|
+
<Space
|
|
87
|
+
direction={"vertical"}
|
|
88
|
+
size={0}
|
|
89
|
+
style={{ width: "100%" }}
|
|
90
|
+
className={contentClassName}
|
|
91
|
+
>
|
|
87
92
|
{!hideHeader && (
|
|
88
93
|
<Header
|
|
89
94
|
searchSpan={searchSpan}
|
|
@@ -1,33 +1,40 @@
|
|
|
1
1
|
import React, { useContext } from "react";
|
|
2
|
-
import type { HTableInstance } from "
|
|
2
|
+
import type { HTableInstance, ValueTypeConfigModal } from "./modal";
|
|
3
3
|
|
|
4
4
|
interface HTableConfigContextModal {
|
|
5
5
|
emptyRender?: (table: HTableInstance) => React.ReactNode;
|
|
6
6
|
errorRender?: (table: HTableInstance, error: Error) => React.ReactNode;
|
|
7
|
-
headerStyle?:React.CSSProperties;
|
|
8
|
-
tableStyle?:React.CSSProperties;
|
|
9
|
-
paginationStyle?:React.CSSProperties;
|
|
7
|
+
headerStyle?: React.CSSProperties;
|
|
8
|
+
tableStyle?: React.CSSProperties;
|
|
9
|
+
paginationStyle?: React.CSSProperties;
|
|
10
|
+
valueTypeConfig?: ValueTypeConfigModal;
|
|
10
11
|
}
|
|
11
12
|
export const HTableConfigContext =
|
|
12
13
|
React.createContext<HTableConfigContextModal | null>(null);
|
|
13
14
|
|
|
14
|
-
|
|
15
15
|
export const useHTableConfigContext = ({
|
|
16
16
|
emptyRender,
|
|
17
17
|
errorRender,
|
|
18
18
|
headerStyle,
|
|
19
|
-
|
|
20
|
-
paginationStyle
|
|
19
|
+
tableStyle,
|
|
20
|
+
paginationStyle,
|
|
21
21
|
}: HTableConfigContextModal) => {
|
|
22
|
-
const {
|
|
23
|
-
|
|
22
|
+
const {
|
|
23
|
+
errorRender: configErrorRender,
|
|
24
|
+
emptyRender: configEmptyRender,
|
|
25
|
+
headerStyle: configHeaderStyle,
|
|
26
|
+
tableStyle: configTableStyle,
|
|
27
|
+
paginationStyle: configPaginationStyle,
|
|
28
|
+
valueTypeConfig = {},
|
|
29
|
+
} = useContext(HTableConfigContext) || {};
|
|
24
30
|
|
|
25
31
|
return {
|
|
26
32
|
errorRender: errorRender || configErrorRender,
|
|
27
33
|
emptyRender: emptyRender || configEmptyRender,
|
|
28
|
-
headerStyle:headerStyle||configHeaderStyle,
|
|
29
|
-
tableStyle:tableStyle||configTableStyle,
|
|
30
|
-
paginationStyle:paginationStyle||configPaginationStyle
|
|
34
|
+
headerStyle: headerStyle || configHeaderStyle,
|
|
35
|
+
tableStyle: tableStyle || configTableStyle,
|
|
36
|
+
paginationStyle: paginationStyle || configPaginationStyle,
|
|
37
|
+
valueTypeConfig,
|
|
31
38
|
};
|
|
32
39
|
};
|
|
33
40
|
const Index: React.FC<HTableConfigContextModal> = ({ children, ...props }) => {
|
package/src/components/modal.ts
CHANGED
|
@@ -10,6 +10,7 @@ import type { ModalProps } from "antd";
|
|
|
10
10
|
import type { TableProps } from "antd/lib/table";
|
|
11
11
|
import type { AffixProps } from "antd/lib/affix";
|
|
12
12
|
import type { OptionModal } from "./HTableBody";
|
|
13
|
+
import { GetRowKey } from "rc-table/lib/interface";
|
|
13
14
|
|
|
14
15
|
export interface RowObj {
|
|
15
16
|
keys?: React.Key[];
|
|
@@ -43,6 +44,7 @@ interface HColumns extends Omit<ProColumns, "render" | "title"> {
|
|
|
43
44
|
) => React.ReactNode;
|
|
44
45
|
rowSelectionTitle?: boolean;
|
|
45
46
|
title?: string | React.ReactNode;
|
|
47
|
+
valueTypeProps?: Record<string, any>;
|
|
46
48
|
}
|
|
47
49
|
interface BcItemModal {
|
|
48
50
|
childrenDataIndex?: ConfigItemModal[] | string[];
|
|
@@ -66,7 +68,6 @@ export type actionFn = (...arg) => void;
|
|
|
66
68
|
export interface RowSelectionOuter {
|
|
67
69
|
allPageCheck?: boolean;
|
|
68
70
|
}
|
|
69
|
-
type RowKeyFn=(data:any,index:number)=>string;
|
|
70
71
|
export type HRowSelection = RowSelectionOuter &
|
|
71
72
|
(TableProps<any>["rowSelection"] & {
|
|
72
73
|
alwaysShowAlert?: boolean;
|
|
@@ -74,7 +75,7 @@ export type HRowSelection = RowSelectionOuter &
|
|
|
74
75
|
export interface HTableProps
|
|
75
76
|
extends Omit<
|
|
76
77
|
ProTableProps<any, any>,
|
|
77
|
-
"request" | "dataSource" | "
|
|
78
|
+
"request" | "dataSource" | "rowSelection"
|
|
78
79
|
> {
|
|
79
80
|
request?: (params: ParamsModal) => Promise<ResultModal>;
|
|
80
81
|
configData: ConfigDataModal;
|
|
@@ -97,7 +98,6 @@ export interface HTableProps
|
|
|
97
98
|
manual?: boolean;
|
|
98
99
|
dataSource?: ResultModal;
|
|
99
100
|
paginationStyle?: React.CSSProperties;
|
|
100
|
-
rowKey?: string|RowKeyFn;
|
|
101
101
|
allPageCheck?: boolean;
|
|
102
102
|
rowSelection?: HRowSelection | false;
|
|
103
103
|
affixProps?: AffixProps | false;
|
|
@@ -153,3 +153,11 @@ export interface ModalTableProps extends ModalProps {
|
|
|
153
153
|
configData?: HTableProps["configData"];
|
|
154
154
|
request?: HTableProps["request"];
|
|
155
155
|
}
|
|
156
|
+
|
|
157
|
+
export type ValueTypeConfigRenderFn = (
|
|
158
|
+
config: ConfigItemModal,
|
|
159
|
+
itemData: any,
|
|
160
|
+
index: number,
|
|
161
|
+
tableInstance: HTableInstance
|
|
162
|
+
) => React.ReactNode;
|
|
163
|
+
export type ValueTypeConfigModal = Record<string, ValueTypeConfigRenderFn>;
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { Row, Tag, Tooltip, Popover } from "antd";
|
|
2
|
+
import React, { useMemo } from "react";
|
|
3
|
+
import type { TooltipProps } from "antd/lib/tooltip";
|
|
4
|
+
import type { HTableInstance } from "@/components/modal";
|
|
5
|
+
type CloseFn = (key: string, tableInstance?: HTableInstance) => void;
|
|
6
|
+
interface IProps {
|
|
7
|
+
data: any[];
|
|
8
|
+
closable?: boolean;
|
|
9
|
+
onClose?: CloseFn;
|
|
10
|
+
color?: string;
|
|
11
|
+
icon?: React.ReactNode;
|
|
12
|
+
tooltip?: boolean | TooltipProps;
|
|
13
|
+
fieldNames?: { label?: string; value?: string };
|
|
14
|
+
tableInstance?: HTableInstance;
|
|
15
|
+
maxLen?: number | null;
|
|
16
|
+
}
|
|
17
|
+
const getTooltipProps = (
|
|
18
|
+
title: string,
|
|
19
|
+
tooltip?: boolean | TooltipProps
|
|
20
|
+
): TooltipProps => {
|
|
21
|
+
if (!tooltip) {
|
|
22
|
+
return {
|
|
23
|
+
title: null,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
if (tooltip === true) {
|
|
27
|
+
return {
|
|
28
|
+
title,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
return {
|
|
32
|
+
...tooltip,
|
|
33
|
+
title,
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
const TagsComponent = (props: IProps) => {
|
|
37
|
+
const {
|
|
38
|
+
data,
|
|
39
|
+
closable,
|
|
40
|
+
onClose,
|
|
41
|
+
color,
|
|
42
|
+
icon,
|
|
43
|
+
fieldNames = {},
|
|
44
|
+
tooltip,
|
|
45
|
+
tableInstance,
|
|
46
|
+
maxLen,
|
|
47
|
+
} = props;
|
|
48
|
+
const { label = "label", value = "value" } = fieldNames;
|
|
49
|
+
const { tagData, moreTag } = useMemo(() => {
|
|
50
|
+
if (!maxLen || !data) {
|
|
51
|
+
return {
|
|
52
|
+
tagData: data,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
const resultTagData = data.slice(0, maxLen);
|
|
56
|
+
const resultMoreTag = data.slice(maxLen);
|
|
57
|
+
return {
|
|
58
|
+
tagData: resultTagData,
|
|
59
|
+
moreTag: resultMoreTag,
|
|
60
|
+
};
|
|
61
|
+
}, [data, maxLen]);
|
|
62
|
+
const moreLen = moreTag?.length;
|
|
63
|
+
|
|
64
|
+
return (
|
|
65
|
+
<Row gutter={[8, 8]}>
|
|
66
|
+
{tagData?.map((tagItem, index) => {
|
|
67
|
+
const tagProps = {
|
|
68
|
+
closable,
|
|
69
|
+
onClose,
|
|
70
|
+
color,
|
|
71
|
+
icon,
|
|
72
|
+
};
|
|
73
|
+
const indexKey = index.toString();
|
|
74
|
+
if (typeof tagItem === "string") {
|
|
75
|
+
const tooltipProps = getTooltipProps(tagItem, tooltip);
|
|
76
|
+
return (
|
|
77
|
+
<Tooltip {...tooltipProps}>
|
|
78
|
+
<Tag
|
|
79
|
+
key={indexKey}
|
|
80
|
+
{...tagProps}
|
|
81
|
+
onClose={(e) => {
|
|
82
|
+
e.preventDefault();
|
|
83
|
+
onClose?.(indexKey, tableInstance);
|
|
84
|
+
}}
|
|
85
|
+
>
|
|
86
|
+
{tagItem}
|
|
87
|
+
</Tag>
|
|
88
|
+
</Tooltip>
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
const { [label]: tagLabel, [value]: tagValue, ...itemProps } = tagItem;
|
|
92
|
+
const tooltipProps = getTooltipProps(tagLabel, tooltip);
|
|
93
|
+
const cuTagProps = {
|
|
94
|
+
...tagProps,
|
|
95
|
+
...itemProps,
|
|
96
|
+
};
|
|
97
|
+
const cuKey = tagValue || indexKey;
|
|
98
|
+
return (
|
|
99
|
+
<Tooltip {...tooltipProps}>
|
|
100
|
+
<Tag
|
|
101
|
+
key={cuKey}
|
|
102
|
+
{...cuTagProps}
|
|
103
|
+
onClose={(e) => {
|
|
104
|
+
e.preventDefault();
|
|
105
|
+
cuTagProps?.onClose(cuKey, tableInstance);
|
|
106
|
+
}}
|
|
107
|
+
>
|
|
108
|
+
{tagLabel}
|
|
109
|
+
</Tag>
|
|
110
|
+
</Tooltip>
|
|
111
|
+
);
|
|
112
|
+
})}
|
|
113
|
+
{!moreLen ? null : (
|
|
114
|
+
<Popover content={<TagsComponent {...props} maxLen={null} />}>
|
|
115
|
+
<Tag>...等{data.length}个</Tag>
|
|
116
|
+
</Popover>
|
|
117
|
+
)}
|
|
118
|
+
</Row>
|
|
119
|
+
);
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
export default TagsComponent;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import moment from "moment";
|
|
2
|
+
import type { ConfigItemModal, HTableInstance } from "@/components/modal";
|
|
3
|
+
import TagsComponent from "./TagsComponent";
|
|
4
|
+
import copy from "copy-to-clipboard";
|
|
5
|
+
import {Image, message, Typography,Avatar} from "antd";
|
|
6
|
+
|
|
7
|
+
const { Link, Paragraph } = Typography;
|
|
8
|
+
const getTableVal = (config: ConfigItemModal, itemData: any) => {
|
|
9
|
+
const { dataIndex } = config;
|
|
10
|
+
const tableDataIndex = dataIndex as string;
|
|
11
|
+
return itemData[tableDataIndex];
|
|
12
|
+
};
|
|
13
|
+
const dateRender = (config: ConfigItemModal, itemData: any) => {
|
|
14
|
+
const { valueTypeProps = {} } = config;
|
|
15
|
+
const tableVal = getTableVal(config, itemData);
|
|
16
|
+
const { format = "YYYY-MM-DD HH:mm:ss", timeStampType = "X" } =
|
|
17
|
+
valueTypeProps;
|
|
18
|
+
if (!tableVal) {
|
|
19
|
+
return "-";
|
|
20
|
+
}
|
|
21
|
+
const time = moment(tableVal, timeStampType);
|
|
22
|
+
return time.format(format);
|
|
23
|
+
};
|
|
24
|
+
const tagsRender = (
|
|
25
|
+
config: ConfigItemModal,
|
|
26
|
+
itemData: any,
|
|
27
|
+
index: number,
|
|
28
|
+
tableInstance: HTableInstance
|
|
29
|
+
) => {
|
|
30
|
+
const { valueTypeProps = {} } = config;
|
|
31
|
+
const tableVal = getTableVal(config, itemData);
|
|
32
|
+
if (!tableVal) {
|
|
33
|
+
return "-";
|
|
34
|
+
}
|
|
35
|
+
return (
|
|
36
|
+
<TagsComponent
|
|
37
|
+
data={tableVal}
|
|
38
|
+
{...valueTypeProps}
|
|
39
|
+
tableInstance={tableInstance}
|
|
40
|
+
/>
|
|
41
|
+
);
|
|
42
|
+
};
|
|
43
|
+
const copyRender = (config: ConfigItemModal, itemData: any) => {
|
|
44
|
+
const { valueTypeProps = {}, title, titleStr } = config;
|
|
45
|
+
const { successMsg, text } = valueTypeProps;
|
|
46
|
+
const msg = successMsg || `复制${title || titleStr}成功!`;
|
|
47
|
+
const tableVal = getTableVal(config, itemData);
|
|
48
|
+
if (!tableVal) {
|
|
49
|
+
return "-";
|
|
50
|
+
}
|
|
51
|
+
let cpText = text;
|
|
52
|
+
if (typeof text === "function") {
|
|
53
|
+
cpText = text(itemData);
|
|
54
|
+
}
|
|
55
|
+
return (
|
|
56
|
+
<Link
|
|
57
|
+
onClick={() => {
|
|
58
|
+
copy(cpText || tableVal);
|
|
59
|
+
message.success(msg);
|
|
60
|
+
}}
|
|
61
|
+
>
|
|
62
|
+
{tableVal}
|
|
63
|
+
</Link>
|
|
64
|
+
);
|
|
65
|
+
};
|
|
66
|
+
const linkRender = (config: ConfigItemModal, itemData: any) => {
|
|
67
|
+
const { valueTypeProps = {} } = config;
|
|
68
|
+
const { href, target = "_blank" } = valueTypeProps;
|
|
69
|
+
const tableVal = getTableVal(config, itemData);
|
|
70
|
+
let hrefUrl = href;
|
|
71
|
+
if (typeof href === "function") {
|
|
72
|
+
hrefUrl = href(itemData);
|
|
73
|
+
}
|
|
74
|
+
return (
|
|
75
|
+
<Link href={hrefUrl || tableVal} target={target}>
|
|
76
|
+
{tableVal}
|
|
77
|
+
</Link>
|
|
78
|
+
);
|
|
79
|
+
};
|
|
80
|
+
const textRender = (config: ConfigItemModal, itemData: any) => {
|
|
81
|
+
const { valueTypeProps = {} } = config;
|
|
82
|
+
const { addonBefore, addonAfter, type, ellipsis } = valueTypeProps;
|
|
83
|
+
const tableVal = getTableVal(config, itemData);
|
|
84
|
+
return (
|
|
85
|
+
<Paragraph type={type} ellipsis={ellipsis}>
|
|
86
|
+
{addonBefore}
|
|
87
|
+
{tableVal}
|
|
88
|
+
{addonAfter}
|
|
89
|
+
</Paragraph>
|
|
90
|
+
);
|
|
91
|
+
};
|
|
92
|
+
const imageRender=(config: ConfigItemModal, itemData: any)=>{
|
|
93
|
+
const { valueTypeProps = {} } = config;
|
|
94
|
+
const tableVal = getTableVal(config, itemData);
|
|
95
|
+
return <Image src={tableVal} width={48} {...valueTypeProps}/>;
|
|
96
|
+
}
|
|
97
|
+
const avatarRender=(config: ConfigItemModal, itemData: any)=>{
|
|
98
|
+
const { valueTypeProps = {} } = config;
|
|
99
|
+
const tableVal = getTableVal(config, itemData);
|
|
100
|
+
return <Avatar src={tableVal} size={32} {...valueTypeProps}/>;
|
|
101
|
+
}
|
|
102
|
+
export default {
|
|
103
|
+
date: dateRender,
|
|
104
|
+
tags: tagsRender,
|
|
105
|
+
copy: copyRender,
|
|
106
|
+
link: linkRender,
|
|
107
|
+
text: textRender,
|
|
108
|
+
image:imageRender,
|
|
109
|
+
avatar:avatarRender
|
|
110
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { ConfigItemModal, HTableInstance } from "@/components/modal";
|
|
2
|
+
import type React from "react";
|
|
3
|
+
import config from "./config";
|
|
4
|
+
import type { ValueTypeConfigModal } from "../modal";
|
|
5
|
+
export default (
|
|
6
|
+
item: ConfigItemModal,
|
|
7
|
+
tableInstance: HTableInstance,
|
|
8
|
+
valueTypeConfig: ValueTypeConfigModal
|
|
9
|
+
) => {
|
|
10
|
+
const { render, valueType = "" } = item;
|
|
11
|
+
return (dom: React.ReactNode, itemData: any, index: number) => {
|
|
12
|
+
const valType = valueType as string;
|
|
13
|
+
let node=dom;
|
|
14
|
+
if (config[valType]) {
|
|
15
|
+
node= config[valType](item, itemData, index, tableInstance);
|
|
16
|
+
}
|
|
17
|
+
if (valueTypeConfig[valType]) {
|
|
18
|
+
node=valueTypeConfig[valType](item, itemData, index, tableInstance);
|
|
19
|
+
}
|
|
20
|
+
if (render) {
|
|
21
|
+
return render(node, itemData, index, tableInstance);
|
|
22
|
+
}
|
|
23
|
+
return node;
|
|
24
|
+
};
|
|
25
|
+
};
|