@fe-free/core 2.5.3 → 2.5.5
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 +14 -0
- package/package.json +2 -2
- package/src/ahooks/ahooks.stories.tsx +0 -1
- package/src/crud/index.tsx +0 -2
- package/src/crud/style.scss +0 -36
- package/src/{crud/crud_of_simple.stories.tsx → crud_of_list/crud_of_list.stories.tsx} +42 -60
- package/src/{crud/crud_of_simple.tsx → crud_of_list/index.tsx} +42 -51
- package/src/crud_of_list/style.scss +37 -0
- package/src/crud_of_pure/crud_of_pure.stories.tsx +90 -0
- package/src/crud_of_pure/index.tsx +59 -0
- package/src/crud_of_pure/style.scss +46 -0
- package/src/index.ts +6 -2
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fe-free/core",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.5",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./src/index.ts",
|
|
6
6
|
"author": "",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"remark-gfm": "^4.0.1",
|
|
42
42
|
"vanilla-jsoneditor": "^0.23.1",
|
|
43
43
|
"zustand": "^4.5.4",
|
|
44
|
-
"@fe-free/tool": "2.5.
|
|
44
|
+
"@fe-free/tool": "2.5.5"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
47
|
"@ant-design/pro-components": "2.8.9",
|
package/src/crud/index.tsx
CHANGED
|
@@ -2,6 +2,4 @@ export { CRUD } from './crud';
|
|
|
2
2
|
export { OperateDelete, useDelete } from './crud_delete';
|
|
3
3
|
export { CRUDDetail } from './crud_detail';
|
|
4
4
|
export type { CRUDDetailProps } from './crud_detail';
|
|
5
|
-
export { CRUDOfSimple } from './crud_of_simple';
|
|
6
|
-
export type { CRUDOfSimpleProps } from './crud_of_simple';
|
|
7
5
|
export type { CRUDMethods, CRUDProps } from './types';
|
package/src/crud/style.scss
CHANGED
|
@@ -8,39 +8,3 @@
|
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
|
-
|
|
12
|
-
.fec-crud-of-simple {
|
|
13
|
-
.ant-pro-table-list-toolbar {
|
|
14
|
-
border-bottom: 1px solid #f0f0f0;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
&.fec-crud-of-simple-hover-show {
|
|
18
|
-
.ant-table-cell-fix-right {
|
|
19
|
-
position: absolute !important;
|
|
20
|
-
display: none;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
.ant-table-row {
|
|
24
|
-
&:hover {
|
|
25
|
-
.ant-table-cell-fix-right {
|
|
26
|
-
display: block;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
&.fec-crud-of-simple-search-width-full {
|
|
33
|
-
.ant-pro-table-list-toolbar-container {
|
|
34
|
-
justify-content: unset;
|
|
35
|
-
|
|
36
|
-
.ant-pro-table-list-toolbar-right {
|
|
37
|
-
justify-content: unset;
|
|
38
|
-
|
|
39
|
-
& > div {
|
|
40
|
-
flex: 1;
|
|
41
|
-
margin-right: 8px;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
@@ -1,36 +1,55 @@
|
|
|
1
1
|
import { ProFormText } from '@ant-design/pro-components';
|
|
2
|
-
import {
|
|
2
|
+
import { CRUDOfList } from '@fe-free/core';
|
|
3
3
|
import type { Meta, StoryObj } from '@storybook/react-vite';
|
|
4
|
-
import { fakeCreate, fakeDeleteByRecord, fakeRequest } from '
|
|
4
|
+
import { fakeCreate, fakeDeleteByRecord, fakeRequest } from '../crud/demo/data';
|
|
5
5
|
|
|
6
|
-
const meta: Meta<typeof
|
|
7
|
-
title: '@fe-free/core/
|
|
8
|
-
component:
|
|
6
|
+
const meta: Meta<typeof CRUDOfList> = {
|
|
7
|
+
title: '@fe-free/core/CRUDOfList',
|
|
8
|
+
component: CRUDOfList,
|
|
9
9
|
tags: ['autodocs'],
|
|
10
|
+
parameters: {
|
|
11
|
+
docs: {
|
|
12
|
+
description: {
|
|
13
|
+
component: `
|
|
14
|
+
CRUDOfList 组件。(简洁的列表形态的 CRUD 组件)
|
|
15
|
+
- 隐藏 label
|
|
16
|
+
- 搜索表单按钮一行
|
|
17
|
+
- 移除卡片布局
|
|
18
|
+
`,
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
decorators: [
|
|
23
|
+
(Story) => {
|
|
24
|
+
return (
|
|
25
|
+
<div className="c-border h-[500px] w-[300px] overflow-y-auto">
|
|
26
|
+
<Story />
|
|
27
|
+
</div>
|
|
28
|
+
);
|
|
29
|
+
},
|
|
30
|
+
],
|
|
10
31
|
};
|
|
11
32
|
|
|
12
33
|
export default meta;
|
|
13
|
-
type Story = StoryObj<typeof
|
|
34
|
+
type Story = StoryObj<typeof CRUDOfList>;
|
|
14
35
|
|
|
15
|
-
|
|
16
|
-
export const Normal: Story = {
|
|
36
|
+
export const Basic: Story = {
|
|
17
37
|
render: () => {
|
|
18
38
|
const columns = [
|
|
19
39
|
{
|
|
20
40
|
title: '名字(省略)',
|
|
21
41
|
dataIndex: 'name',
|
|
22
|
-
search: true,
|
|
42
|
+
// search: true,
|
|
23
43
|
ellipsis: true,
|
|
24
44
|
},
|
|
25
45
|
];
|
|
26
46
|
|
|
27
47
|
return (
|
|
28
|
-
<
|
|
29
|
-
actions={[
|
|
48
|
+
<CRUDOfList
|
|
49
|
+
actions={[]}
|
|
30
50
|
tableProps={{
|
|
31
51
|
columns,
|
|
32
52
|
request: fakeRequest,
|
|
33
|
-
pagination: false,
|
|
34
53
|
}}
|
|
35
54
|
requestDeleteByRecord={fakeDeleteByRecord}
|
|
36
55
|
deleteProps={{
|
|
@@ -38,13 +57,7 @@ export const Normal: Story = {
|
|
|
38
57
|
}}
|
|
39
58
|
detailForm={() => (
|
|
40
59
|
<>
|
|
41
|
-
<ProFormText
|
|
42
|
-
name="name"
|
|
43
|
-
label="名字"
|
|
44
|
-
required
|
|
45
|
-
rules={[{ required: true }]}
|
|
46
|
-
extra="extra extra extra extra"
|
|
47
|
-
/>
|
|
60
|
+
<ProFormText name="name" label="名字" required rules={[{ required: true }]} />
|
|
48
61
|
</>
|
|
49
62
|
)}
|
|
50
63
|
requestCreateByValues={fakeCreate}
|
|
@@ -65,12 +78,11 @@ export const WithSearch: Story = {
|
|
|
65
78
|
];
|
|
66
79
|
|
|
67
80
|
return (
|
|
68
|
-
<
|
|
69
|
-
actions={['
|
|
81
|
+
<CRUDOfList
|
|
82
|
+
actions={['delete']}
|
|
70
83
|
tableProps={{
|
|
71
84
|
columns,
|
|
72
85
|
request: fakeRequest,
|
|
73
|
-
pagination: false,
|
|
74
86
|
}}
|
|
75
87
|
requestDeleteByRecord={fakeDeleteByRecord}
|
|
76
88
|
deleteProps={{
|
|
@@ -78,26 +90,16 @@ export const WithSearch: Story = {
|
|
|
78
90
|
}}
|
|
79
91
|
detailForm={() => (
|
|
80
92
|
<>
|
|
81
|
-
<ProFormText
|
|
82
|
-
name="name"
|
|
83
|
-
label="名字"
|
|
84
|
-
required
|
|
85
|
-
rules={[{ required: true }]}
|
|
86
|
-
extra="extra extra extra extra"
|
|
87
|
-
/>
|
|
93
|
+
<ProFormText name="name" label="名字" required rules={[{ required: true }]} />
|
|
88
94
|
</>
|
|
89
95
|
)}
|
|
90
96
|
requestCreateByValues={fakeCreate}
|
|
91
|
-
simpleSearchProps={{
|
|
92
|
-
name: 'name',
|
|
93
|
-
widthFull: true,
|
|
94
|
-
}}
|
|
95
97
|
/>
|
|
96
98
|
);
|
|
97
99
|
},
|
|
98
100
|
};
|
|
99
101
|
|
|
100
|
-
export const
|
|
102
|
+
export const WithCreateDelete: Story = {
|
|
101
103
|
render: () => {
|
|
102
104
|
const columns = [
|
|
103
105
|
{
|
|
@@ -109,12 +111,11 @@ export const HoverShow: Story = {
|
|
|
109
111
|
];
|
|
110
112
|
|
|
111
113
|
return (
|
|
112
|
-
<
|
|
114
|
+
<CRUDOfList
|
|
113
115
|
actions={['create', 'delete']}
|
|
114
116
|
tableProps={{
|
|
115
117
|
columns,
|
|
116
118
|
request: fakeRequest,
|
|
117
|
-
pagination: false,
|
|
118
119
|
}}
|
|
119
120
|
requestDeleteByRecord={fakeDeleteByRecord}
|
|
120
121
|
deleteProps={{
|
|
@@ -122,40 +123,31 @@ export const HoverShow: Story = {
|
|
|
122
123
|
}}
|
|
123
124
|
detailForm={() => (
|
|
124
125
|
<>
|
|
125
|
-
<ProFormText
|
|
126
|
-
name="name"
|
|
127
|
-
label="名字"
|
|
128
|
-
required
|
|
129
|
-
rules={[{ required: true }]}
|
|
130
|
-
extra="extra extra extra extra"
|
|
131
|
-
/>
|
|
126
|
+
<ProFormText name="name" label="名字" required rules={[{ required: true }]} />
|
|
132
127
|
</>
|
|
133
128
|
)}
|
|
134
129
|
requestCreateByValues={fakeCreate}
|
|
135
|
-
simpleOperateHoverShow
|
|
136
130
|
/>
|
|
137
131
|
);
|
|
138
132
|
},
|
|
139
133
|
};
|
|
140
134
|
|
|
141
|
-
export const
|
|
135
|
+
export const NoSearch: Story = {
|
|
142
136
|
render: () => {
|
|
143
137
|
const columns = [
|
|
144
138
|
{
|
|
145
139
|
title: '名字(省略)',
|
|
146
140
|
dataIndex: 'name',
|
|
147
|
-
search: true,
|
|
148
141
|
ellipsis: true,
|
|
149
142
|
},
|
|
150
143
|
];
|
|
151
144
|
|
|
152
145
|
return (
|
|
153
|
-
<
|
|
154
|
-
actions={['delete']}
|
|
146
|
+
<CRUDOfList
|
|
147
|
+
actions={['create', 'delete']}
|
|
155
148
|
tableProps={{
|
|
156
149
|
columns,
|
|
157
150
|
request: fakeRequest,
|
|
158
|
-
pagination: false,
|
|
159
151
|
}}
|
|
160
152
|
requestDeleteByRecord={fakeDeleteByRecord}
|
|
161
153
|
deleteProps={{
|
|
@@ -163,20 +155,10 @@ export const JustSearch: Story = {
|
|
|
163
155
|
}}
|
|
164
156
|
detailForm={() => (
|
|
165
157
|
<>
|
|
166
|
-
<ProFormText
|
|
167
|
-
name="name"
|
|
168
|
-
label="名字"
|
|
169
|
-
required
|
|
170
|
-
rules={[{ required: true }]}
|
|
171
|
-
extra="extra extra extra extra"
|
|
172
|
-
/>
|
|
158
|
+
<ProFormText name="name" label="名字" required rules={[{ required: true }]} />
|
|
173
159
|
</>
|
|
174
160
|
)}
|
|
175
161
|
requestCreateByValues={fakeCreate}
|
|
176
|
-
simpleSearchProps={{
|
|
177
|
-
name: 'name',
|
|
178
|
-
widthFull: true,
|
|
179
|
-
}}
|
|
180
162
|
/>
|
|
181
163
|
);
|
|
182
164
|
},
|
|
@@ -2,32 +2,26 @@ import { useDebounce } from 'ahooks';
|
|
|
2
2
|
import { Input } from 'antd';
|
|
3
3
|
import classNames from 'classnames';
|
|
4
4
|
import { forwardRef, useCallback, useEffect, useMemo, useState } from 'react';
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
5
|
+
import type { CRUDMethods, CRUDProps } from '../crud';
|
|
6
|
+
import { CRUD } from '../crud';
|
|
7
|
+
import './style.scss';
|
|
7
8
|
|
|
8
|
-
|
|
9
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
|
|
10
|
+
interface CRUDOfListProps<
|
|
9
11
|
DataSource extends Record<string, any> = any,
|
|
10
12
|
Key extends string | number = string,
|
|
11
13
|
> extends CRUDProps<DataSource, Key> {
|
|
12
|
-
|
|
13
|
-
// 传才开启搜索
|
|
14
|
-
simpleSearchProps?: {
|
|
15
|
-
/** 搜索项的名称,默认 keywords */
|
|
16
|
-
name: string;
|
|
17
|
-
/** 搜索项的 placeholder,默认 请输入 */
|
|
18
|
-
placeholder?: string;
|
|
19
|
-
/** 占满宽度 */
|
|
20
|
-
widthFull?: boolean;
|
|
21
|
-
};
|
|
14
|
+
// nothing
|
|
22
15
|
}
|
|
23
16
|
|
|
24
17
|
function useTips(props) {
|
|
25
|
-
const { columns } = props;
|
|
26
|
-
|
|
27
18
|
useEffect(() => {
|
|
28
|
-
const
|
|
29
|
-
if (
|
|
30
|
-
console.warn('
|
|
19
|
+
const count = props.tableProps.columns?.filter((column) => column.search).length;
|
|
20
|
+
if (!count) {
|
|
21
|
+
console.warn('CRUDOfList 的 columns 中至少有一个 search 为 true 的列');
|
|
22
|
+
}
|
|
23
|
+
if (count > 1) {
|
|
24
|
+
console.warn('CRUDOfList 的 columns 中只能有一个 search 为 true 的列');
|
|
31
25
|
}
|
|
32
26
|
}, []);
|
|
33
27
|
}
|
|
@@ -48,14 +42,18 @@ function SearchRender(props: {
|
|
|
48
42
|
);
|
|
49
43
|
}
|
|
50
44
|
|
|
51
|
-
function
|
|
52
|
-
const { simpleSearchProps, tableProps, simpleOperateHoverShow, ...rest } = props;
|
|
53
|
-
|
|
45
|
+
function CRUDOfListComponent(props: CRUDOfListProps, ref: React.ForwardedRef<CRUDMethods>) {
|
|
54
46
|
useTips(props);
|
|
55
|
-
const [searchValue, setSearchValue] = useState<string>('');
|
|
56
47
|
|
|
48
|
+
const { tableProps, ...rest } = props;
|
|
49
|
+
|
|
50
|
+
const [searchValue, setSearchValue] = useState<string>('');
|
|
57
51
|
const debouncedSearchValue = useDebounce(searchValue, { wait: 300 });
|
|
58
52
|
|
|
53
|
+
const searchDataIndex = useMemo(() => {
|
|
54
|
+
return tableProps.columns?.find((column) => column.search)?.dataIndex;
|
|
55
|
+
}, [tableProps.columns]);
|
|
56
|
+
|
|
59
57
|
const newColumns = useMemo(() => {
|
|
60
58
|
return (tableProps.columns || []).map((column) => ({
|
|
61
59
|
...column,
|
|
@@ -66,56 +64,49 @@ function CRUDOfSimpleComponent(props: CRUDOfSimpleProps, ref: React.ForwardedRef
|
|
|
66
64
|
const toolBarRender = useCallback(
|
|
67
65
|
(...args) => {
|
|
68
66
|
return [
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
onChange={(value) => setSearchValue(value)}
|
|
75
|
-
/>
|
|
76
|
-
),
|
|
67
|
+
<div key="search-input-container" className="w-full">
|
|
68
|
+
{searchDataIndex && (
|
|
69
|
+
<SearchRender value={searchValue} onChange={(value) => setSearchValue(value)} />
|
|
70
|
+
)}
|
|
71
|
+
</div>,
|
|
77
72
|
// @ts-ignore
|
|
78
73
|
...(tableProps.toolBarRender ? tableProps.toolBarRender(...args) : []),
|
|
79
74
|
];
|
|
80
75
|
},
|
|
81
|
-
[searchValue,
|
|
76
|
+
[searchValue, searchDataIndex, tableProps],
|
|
82
77
|
);
|
|
83
78
|
|
|
84
79
|
const newParams = useMemo(() => {
|
|
85
|
-
if (!simpleSearchProps) {
|
|
86
|
-
return tableProps.params;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
80
|
return {
|
|
90
|
-
...tableProps.params,
|
|
91
|
-
[
|
|
81
|
+
...(tableProps.params || {}),
|
|
82
|
+
[searchDataIndex]: debouncedSearchValue,
|
|
92
83
|
};
|
|
93
|
-
}, [debouncedSearchValue,
|
|
84
|
+
}, [debouncedSearchValue, searchDataIndex, tableProps.params]);
|
|
94
85
|
|
|
95
86
|
return (
|
|
96
87
|
<div
|
|
97
|
-
className={classNames('fec-crud-of-
|
|
98
|
-
|
|
99
|
-
'fec-crud-of-
|
|
88
|
+
className={classNames('fec-crud-of-list', {
|
|
89
|
+
// 先这样实现
|
|
90
|
+
'fec-crud-of-list-no-toolbar': !searchDataIndex && !props.actions.includes('create'),
|
|
100
91
|
})}
|
|
101
92
|
>
|
|
102
93
|
<CRUD
|
|
103
94
|
ref={ref}
|
|
104
95
|
{...rest}
|
|
105
96
|
tableProps={{
|
|
106
|
-
...tableProps,
|
|
107
|
-
params: newParams,
|
|
108
97
|
cardBordered: false,
|
|
109
98
|
showHeader: false,
|
|
110
99
|
ghost: true,
|
|
111
|
-
columns: newColumns,
|
|
112
|
-
toolBarRender,
|
|
113
100
|
// 简单的隐藏搜索栏
|
|
114
101
|
search: false,
|
|
102
|
+
pagination: false,
|
|
103
|
+
...tableProps,
|
|
104
|
+
params: newParams,
|
|
105
|
+
columns: newColumns,
|
|
106
|
+
toolBarRender,
|
|
115
107
|
}}
|
|
116
108
|
operateColumnProps={{
|
|
117
|
-
|
|
118
|
-
width: simpleOperateHoverShow ? 1 : undefined,
|
|
109
|
+
width: 1,
|
|
119
110
|
...props.operateColumnProps,
|
|
120
111
|
}}
|
|
121
112
|
/>
|
|
@@ -123,12 +114,12 @@ function CRUDOfSimpleComponent(props: CRUDOfSimpleProps, ref: React.ForwardedRef
|
|
|
123
114
|
);
|
|
124
115
|
}
|
|
125
116
|
|
|
126
|
-
const
|
|
117
|
+
const CRUDOfList = forwardRef(CRUDOfListComponent) as <
|
|
127
118
|
DataSource extends Record<string, any> = any,
|
|
128
119
|
Key extends string | number = string,
|
|
129
120
|
>(
|
|
130
|
-
props:
|
|
121
|
+
props: CRUDOfListProps<DataSource, Key> & { ref?: React.ForwardedRef<CRUDMethods> },
|
|
131
122
|
) => JSX.Element;
|
|
132
123
|
|
|
133
|
-
export {
|
|
134
|
-
export type {
|
|
124
|
+
export { CRUDOfList };
|
|
125
|
+
export type { CRUDOfListProps };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
.fec-crud-of-list {
|
|
2
|
+
.ant-pro-table-list-toolbar {
|
|
3
|
+
border-bottom: 1px solid #f0f0f0;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
.ant-table-cell-fix-right {
|
|
7
|
+
position: absolute !important;
|
|
8
|
+
display: none;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
.ant-table-row {
|
|
12
|
+
&:hover {
|
|
13
|
+
.ant-table-cell-fix-right {
|
|
14
|
+
display: block;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.ant-pro-table-list-toolbar-container {
|
|
20
|
+
justify-content: unset;
|
|
21
|
+
|
|
22
|
+
.ant-pro-table-list-toolbar-right {
|
|
23
|
+
justify-content: unset;
|
|
24
|
+
|
|
25
|
+
& > div {
|
|
26
|
+
flex: 1;
|
|
27
|
+
margin-right: 8px;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
&.fec-crud-of-list-no-toolbar {
|
|
33
|
+
.ant-pro-table-list-toolbar-container {
|
|
34
|
+
padding-block: 0;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { ProFormText } from '@ant-design/pro-components';
|
|
2
|
+
import { CRUDOfPure } from '@fe-free/core';
|
|
3
|
+
import type { Meta, StoryObj } from '@storybook/react-vite';
|
|
4
|
+
import { Button } from 'antd';
|
|
5
|
+
import { fakeCreate, fakeDeleteByRecord, fakeRequest } from '../crud/demo/data';
|
|
6
|
+
|
|
7
|
+
const meta: Meta<typeof CRUDOfPure> = {
|
|
8
|
+
title: '@fe-free/core/CRUDOfPure',
|
|
9
|
+
component: CRUDOfPure,
|
|
10
|
+
tags: ['autodocs'],
|
|
11
|
+
parameters: {
|
|
12
|
+
docs: {
|
|
13
|
+
description: {
|
|
14
|
+
component: `
|
|
15
|
+
CRUDOfPure 组件。(更简洁的 CRUD 组件)
|
|
16
|
+
- 隐藏 label
|
|
17
|
+
- 搜索表单按钮一行
|
|
18
|
+
- 移除卡片布局
|
|
19
|
+
`,
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export default meta;
|
|
26
|
+
type Story = StoryObj<typeof CRUDOfPure>;
|
|
27
|
+
|
|
28
|
+
// 基础用法
|
|
29
|
+
export const Normal: Story = {
|
|
30
|
+
render: () => {
|
|
31
|
+
const columns = [
|
|
32
|
+
{
|
|
33
|
+
title: 'id',
|
|
34
|
+
dataIndex: 'id',
|
|
35
|
+
search: true,
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
title: '名字(省略)',
|
|
39
|
+
dataIndex: 'name',
|
|
40
|
+
search: true,
|
|
41
|
+
ellipsis: true,
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
title: 'city',
|
|
45
|
+
dataIndex: 'city',
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
title: 'area',
|
|
49
|
+
dataIndex: 'area',
|
|
50
|
+
},
|
|
51
|
+
];
|
|
52
|
+
|
|
53
|
+
return (
|
|
54
|
+
<CRUDOfPure
|
|
55
|
+
actions={['delete']}
|
|
56
|
+
tableProps={{
|
|
57
|
+
columns,
|
|
58
|
+
request: fakeRequest,
|
|
59
|
+
pagination: false,
|
|
60
|
+
search: {
|
|
61
|
+
optionRender: (_, __, dom) => {
|
|
62
|
+
return [
|
|
63
|
+
...dom,
|
|
64
|
+
<Button key="1" type="primary" className="ml-2">
|
|
65
|
+
额外的按钮
|
|
66
|
+
</Button>,
|
|
67
|
+
];
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
}}
|
|
71
|
+
requestDeleteByRecord={fakeDeleteByRecord}
|
|
72
|
+
deleteProps={{
|
|
73
|
+
nameIndex: 'id',
|
|
74
|
+
}}
|
|
75
|
+
detailForm={() => (
|
|
76
|
+
<>
|
|
77
|
+
<ProFormText
|
|
78
|
+
name="name"
|
|
79
|
+
label="名字"
|
|
80
|
+
required
|
|
81
|
+
rules={[{ required: true }]}
|
|
82
|
+
extra="extra extra extra extra"
|
|
83
|
+
/>
|
|
84
|
+
</>
|
|
85
|
+
)}
|
|
86
|
+
requestCreateByValues={fakeCreate}
|
|
87
|
+
/>
|
|
88
|
+
);
|
|
89
|
+
},
|
|
90
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import classNames from 'classnames';
|
|
2
|
+
import { forwardRef } from 'react';
|
|
3
|
+
import type { CRUDMethods, CRUDProps } from '../crud';
|
|
4
|
+
import { CRUD } from '../crud';
|
|
5
|
+
import './style.scss';
|
|
6
|
+
|
|
7
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
|
|
8
|
+
interface CRUDOfPureProps<
|
|
9
|
+
DataSource extends Record<string, any> = any,
|
|
10
|
+
Key extends string | number = string,
|
|
11
|
+
> extends CRUDProps<DataSource, Key> {
|
|
12
|
+
// nothing
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function CRUDOfPureComponent(props: CRUDOfPureProps, ref: React.ForwardedRef<CRUDMethods>) {
|
|
16
|
+
const newColumns = props.tableProps.columns?.map((column) => {
|
|
17
|
+
if (column.search) {
|
|
18
|
+
return {
|
|
19
|
+
...column,
|
|
20
|
+
// 隐藏 label
|
|
21
|
+
formItemProps: {
|
|
22
|
+
label: '',
|
|
23
|
+
...column.formItemProps,
|
|
24
|
+
},
|
|
25
|
+
// 设置 placeholder
|
|
26
|
+
fieldProps: {
|
|
27
|
+
placeholder:
|
|
28
|
+
column.valueType === 'select' ? `请选择${column.title}` : `请输入${column.title}`,
|
|
29
|
+
...column.fieldProps,
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
return column;
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
return (
|
|
37
|
+
<div className={classNames('fec-crud-of-pure')}>
|
|
38
|
+
<CRUD
|
|
39
|
+
ref={ref}
|
|
40
|
+
{...props}
|
|
41
|
+
tableProps={{
|
|
42
|
+
cardBordered: false,
|
|
43
|
+
...props.tableProps,
|
|
44
|
+
columns: newColumns,
|
|
45
|
+
}}
|
|
46
|
+
/>
|
|
47
|
+
</div>
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const CRUDOfPure = forwardRef(CRUDOfPureComponent) as <
|
|
52
|
+
DataSource extends Record<string, any> = any,
|
|
53
|
+
Key extends string | number = string,
|
|
54
|
+
>(
|
|
55
|
+
props: CRUDOfPureProps<DataSource, Key> & { ref?: React.ForwardedRef<CRUDMethods> },
|
|
56
|
+
) => JSX.Element;
|
|
57
|
+
|
|
58
|
+
export { CRUDOfPure };
|
|
59
|
+
export type { CRUDOfPureProps };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
.fec-crud-of-pure {
|
|
2
|
+
.ant-pro-table .ant-pro-table-search {
|
|
3
|
+
margin-block-end: 0;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
.ant-pro-query-filter.ant-pro-query-filter {
|
|
7
|
+
padding: 8px 16px;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
.ant-pro-card .ant-pro-card-body {
|
|
11
|
+
padding-inline: 16px;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
.ant-pro-query-filter-container {
|
|
15
|
+
.ant-col.ant-col-6,
|
|
16
|
+
.ant-col.ant-col-8,
|
|
17
|
+
.ant-col.ant-col-12 {
|
|
18
|
+
flex: none !important;
|
|
19
|
+
min-width: 150px !important;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
.ant-col.ant-col-offset-6,
|
|
23
|
+
.ant-col.ant-col-offset-8,
|
|
24
|
+
.ant-col.ant-col-offset-12,
|
|
25
|
+
.ant-col.ant-col-offset-16,
|
|
26
|
+
.ant-col.ant-col-offset-24 {
|
|
27
|
+
margin-inline-start: 0 !important;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.ant-pro-query-filter-actions {
|
|
31
|
+
// 可能有问题
|
|
32
|
+
.ant-form-item-label {
|
|
33
|
+
display: none;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.ant-pro-query-filter-collapse-button {
|
|
38
|
+
display: none;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.ant-pro-table-list-toolbar-container {
|
|
43
|
+
padding-block: 0;
|
|
44
|
+
padding-block-end: 8px;
|
|
45
|
+
}
|
|
46
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -6,8 +6,12 @@ export { LoadingButton } from './button';
|
|
|
6
6
|
export { Copy } from './copy';
|
|
7
7
|
export type { CopyProps } from './copy';
|
|
8
8
|
export { CoreApp } from './core_app';
|
|
9
|
-
export { CRUD, CRUDDetail,
|
|
10
|
-
export type { CRUDDetailProps, CRUDMethods,
|
|
9
|
+
export { CRUD, CRUDDetail, OperateDelete, useDelete } from './crud';
|
|
10
|
+
export type { CRUDDetailProps, CRUDMethods, CRUDProps } from './crud';
|
|
11
|
+
export { CRUDOfList } from './crud_of_list';
|
|
12
|
+
export type { CRUDOfListProps } from './crud_of_list';
|
|
13
|
+
export { CRUDOfPure } from './crud_of_pure';
|
|
14
|
+
export type { CRUDOfPureProps } from './crud_of_pure';
|
|
11
15
|
export { Editor } from './editor';
|
|
12
16
|
export type { EditorProps } from './editor';
|
|
13
17
|
export { EditorJSON } from './editor_json';
|