@fe-free/core 3.0.33 → 3.0.35
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 +16 -0
- package/package.json +3 -3
- package/src/core_app/index.tsx +11 -1
- package/src/crud/crud.stories.tsx +17 -7
- package/src/crud/crud.tsx +0 -3
- package/src/crud/crud_detail.tsx +4 -22
- package/src/crud/table/style.scss +5 -2
- package/src/crud/types.tsx +0 -2
- package/src/crud_of_pure/index.tsx +7 -2
- package/src/style.scss +5 -3
- package/src/value_type_map/index.tsx +6 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @fe-free/core
|
|
2
2
|
|
|
3
|
+
## 3.0.35
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- feat: crud
|
|
8
|
+
- @fe-free/icons@3.0.35
|
|
9
|
+
- @fe-free/tool@3.0.35
|
|
10
|
+
|
|
11
|
+
## 3.0.34
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- feat: crud
|
|
16
|
+
- @fe-free/icons@3.0.34
|
|
17
|
+
- @fe-free/tool@3.0.34
|
|
18
|
+
|
|
3
19
|
## 3.0.33
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fe-free/core",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.35",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./src/index.ts",
|
|
6
6
|
"author": "",
|
|
@@ -46,8 +46,8 @@
|
|
|
46
46
|
"antd": "^5.27.1",
|
|
47
47
|
"dayjs": "~1.11.10",
|
|
48
48
|
"react": "^19.2.0",
|
|
49
|
-
"@fe-free/icons": "3.0.
|
|
50
|
-
"@fe-free/tool": "3.0.
|
|
49
|
+
"@fe-free/icons": "3.0.35",
|
|
50
|
+
"@fe-free/tool": "3.0.35"
|
|
51
51
|
},
|
|
52
52
|
"scripts": {
|
|
53
53
|
"test": "echo \"Error: no test specified\" && exit 1"
|
package/src/core_app/index.tsx
CHANGED
|
@@ -2,6 +2,7 @@ import { ProConfigProvider } from '@ant-design/pro-components';
|
|
|
2
2
|
import { useTitle } from 'ahooks';
|
|
3
3
|
import { App, ConfigProvider } from 'antd';
|
|
4
4
|
import zhCN from 'antd/locale/zh_CN';
|
|
5
|
+
import classNames from 'classnames';
|
|
5
6
|
import { merge } from 'lodash-es';
|
|
6
7
|
import { useEffect, useMemo } from 'react';
|
|
7
8
|
import { BrowserRouter as Router, useNavigate } from 'react-router-dom';
|
|
@@ -103,6 +104,9 @@ function CoreApp(props: {
|
|
|
103
104
|
appProps?: Omit<React.ComponentProps<typeof App>, 'children'>;
|
|
104
105
|
routerProps?: Omit<Partial<React.ComponentProps<typeof Router>>, 'children'>;
|
|
105
106
|
children: React.ReactNode;
|
|
107
|
+
customConfig?: {
|
|
108
|
+
hiddenFormItemLabelColon?: boolean;
|
|
109
|
+
};
|
|
106
110
|
}) {
|
|
107
111
|
const {
|
|
108
112
|
basename,
|
|
@@ -113,6 +117,7 @@ function CoreApp(props: {
|
|
|
113
117
|
configProviderProps,
|
|
114
118
|
appProps,
|
|
115
119
|
routerProps,
|
|
120
|
+
customConfig,
|
|
116
121
|
} = props;
|
|
117
122
|
|
|
118
123
|
useTitle(name || '');
|
|
@@ -140,7 +145,12 @@ function CoreApp(props: {
|
|
|
140
145
|
locale={configProviderProps?.locale || zhCN}
|
|
141
146
|
theme={theme}
|
|
142
147
|
>
|
|
143
|
-
<App
|
|
148
|
+
<App
|
|
149
|
+
{...appProps}
|
|
150
|
+
className={classNames('fec-app', appProps?.className, {
|
|
151
|
+
'fec-app-hidden-form-item-label-colon': customConfig?.hiddenFormItemLabelColon,
|
|
152
|
+
})}
|
|
153
|
+
>
|
|
144
154
|
<Router {...routerProps} basename={basename}>
|
|
145
155
|
<SetRouteTool basename={basename} />
|
|
146
156
|
{enableCheckUpdate && <CheckUpdate basename={basename} />}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ProColumns } from '@ant-design/pro-components';
|
|
2
2
|
import { ProForm, ProFormSwitch, ProFormText } from '@ant-design/pro-components';
|
|
3
|
-
import type { CRUDRef } from '@fe-free/core';
|
|
4
|
-
import { CRUD, proFormSelectSearchProps } from '@fe-free/core';
|
|
3
|
+
import type { CRUDProps, CRUDRef } from '@fe-free/core';
|
|
4
|
+
import { CRUD, CustomValueTypeEnum, proFormSelectSearchProps } from '@fe-free/core';
|
|
5
5
|
|
|
6
6
|
import type { Meta, StoryObj } from '@storybook/react-vite';
|
|
7
7
|
import { Button } from 'antd';
|
|
@@ -31,6 +31,10 @@ type Story = StoryObj<typeof CRUD>;
|
|
|
31
31
|
export const Normal: Story = {
|
|
32
32
|
render: () => {
|
|
33
33
|
const columns = [
|
|
34
|
+
{
|
|
35
|
+
title: '序号',
|
|
36
|
+
valueType: CustomValueTypeEnum.CustomSerialNumber,
|
|
37
|
+
},
|
|
34
38
|
{
|
|
35
39
|
title: 'id',
|
|
36
40
|
dataIndex: 'id',
|
|
@@ -50,7 +54,7 @@ export const Normal: Story = {
|
|
|
50
54
|
title: 'area',
|
|
51
55
|
dataIndex: 'area',
|
|
52
56
|
},
|
|
53
|
-
];
|
|
57
|
+
] as CRUDProps['tableProps']['columns'];
|
|
54
58
|
|
|
55
59
|
return (
|
|
56
60
|
<CRUD
|
|
@@ -76,7 +80,6 @@ export const Normal: Story = {
|
|
|
76
80
|
)}
|
|
77
81
|
requestGetByRecord={fakeGetByRecord}
|
|
78
82
|
requestCreateByValues={fakeCreate}
|
|
79
|
-
requestUpdateById={fakeUpdateById}
|
|
80
83
|
/>
|
|
81
84
|
);
|
|
82
85
|
},
|
|
@@ -171,6 +174,16 @@ export const MoreCustom: Story = {
|
|
|
171
174
|
toolBarRender: () => {
|
|
172
175
|
return [<div key="custom1">自定义1</div>, <div key="custom2">自定义2</div>];
|
|
173
176
|
},
|
|
177
|
+
search: {
|
|
178
|
+
optionRender: (_, __, dom) => {
|
|
179
|
+
return [
|
|
180
|
+
...dom,
|
|
181
|
+
<Button key="1" type="primary" className="ml-2">
|
|
182
|
+
额外的按钮
|
|
183
|
+
</Button>,
|
|
184
|
+
];
|
|
185
|
+
},
|
|
186
|
+
},
|
|
174
187
|
}}
|
|
175
188
|
operateColumnProps={{
|
|
176
189
|
// 自定义宽度
|
|
@@ -216,7 +229,6 @@ export const MoreCustom: Story = {
|
|
|
216
229
|
)}
|
|
217
230
|
requestGetByRecord={fakeGetByRecord}
|
|
218
231
|
requestCreateByValues={fakeCreate}
|
|
219
|
-
requestUpdateById={fakeUpdateById}
|
|
220
232
|
updateProps={{
|
|
221
233
|
operateIsDisabled: (record) => {
|
|
222
234
|
if (record.id % 3) {
|
|
@@ -567,7 +579,6 @@ export const ExpandedRowRender: Story = {
|
|
|
567
579
|
)}
|
|
568
580
|
requestGetByRecord={fakeGetByRecord}
|
|
569
581
|
requestCreateByValues={fakeCreate}
|
|
570
|
-
requestUpdateById={fakeUpdateById}
|
|
571
582
|
/>
|
|
572
583
|
);
|
|
573
584
|
},
|
|
@@ -623,7 +634,6 @@ export const FullPage: Story = {
|
|
|
623
634
|
)}
|
|
624
635
|
requestGetByRecord={fakeGetByRecord}
|
|
625
636
|
requestCreateByValues={fakeCreate}
|
|
626
|
-
requestUpdateById={fakeUpdateById}
|
|
627
637
|
/>
|
|
628
638
|
</div>
|
|
629
639
|
);
|
package/src/crud/crud.tsx
CHANGED
|
@@ -31,7 +31,6 @@ function CRUD<DataSource extends Record<string, any> = any, Key extends string |
|
|
|
31
31
|
createProps,
|
|
32
32
|
requestCreateByValues,
|
|
33
33
|
updateProps,
|
|
34
|
-
requestUpdateById,
|
|
35
34
|
requestUpdateByValues,
|
|
36
35
|
detailFormInstance,
|
|
37
36
|
requestDeleteByRecords,
|
|
@@ -56,7 +55,6 @@ function CRUD<DataSource extends Record<string, any> = any, Key extends string |
|
|
|
56
55
|
detailForm,
|
|
57
56
|
requestGetByRecord,
|
|
58
57
|
requestCreateByValues,
|
|
59
|
-
requestUpdateById,
|
|
60
58
|
requestUpdateByValues,
|
|
61
59
|
detailFormInstance,
|
|
62
60
|
createProps,
|
|
@@ -67,7 +65,6 @@ function CRUD<DataSource extends Record<string, any> = any, Key extends string |
|
|
|
67
65
|
detailForm,
|
|
68
66
|
requestGetByRecord,
|
|
69
67
|
requestCreateByValues,
|
|
70
|
-
requestUpdateById,
|
|
71
68
|
requestUpdateByValues,
|
|
72
69
|
detailFormInstance,
|
|
73
70
|
createProps,
|
package/src/crud/crud_detail.tsx
CHANGED
|
@@ -23,7 +23,6 @@ interface CRUDDetailProps
|
|
|
23
23
|
| 'readProps'
|
|
24
24
|
| 'requestCreateByValues'
|
|
25
25
|
| 'updateProps'
|
|
26
|
-
| 'requestUpdateById'
|
|
27
26
|
| 'requestUpdateByValues'
|
|
28
27
|
| 'detailForm'
|
|
29
28
|
| 'detailFormInstance'
|
|
@@ -49,7 +48,6 @@ function CRUDDetail(props: CRUDDetailProps) {
|
|
|
49
48
|
readProps,
|
|
50
49
|
requestCreateByValues,
|
|
51
50
|
updateProps,
|
|
52
|
-
requestUpdateById,
|
|
53
51
|
requestUpdateByValues,
|
|
54
52
|
detailFormInstance,
|
|
55
53
|
} = props;
|
|
@@ -76,15 +74,8 @@ function CRUDDetail(props: CRUDDetailProps) {
|
|
|
76
74
|
content,
|
|
77
75
|
});
|
|
78
76
|
}
|
|
79
|
-
if (action === 'update' &&
|
|
80
|
-
|
|
81
|
-
result = await requestUpdateByValues(values);
|
|
82
|
-
} else if (requestUpdateById) {
|
|
83
|
-
result = await requestUpdateById({
|
|
84
|
-
...values,
|
|
85
|
-
id,
|
|
86
|
-
});
|
|
87
|
-
}
|
|
77
|
+
if (action === 'update' && requestUpdateByValues) {
|
|
78
|
+
result = await requestUpdateByValues(values);
|
|
88
79
|
|
|
89
80
|
let content = '更新成功';
|
|
90
81
|
if (updateProps?.successText) {
|
|
@@ -114,16 +105,7 @@ function CRUDDetail(props: CRUDDetailProps) {
|
|
|
114
105
|
}, 10);
|
|
115
106
|
}
|
|
116
107
|
},
|
|
117
|
-
[
|
|
118
|
-
action,
|
|
119
|
-
requestCreateByValues,
|
|
120
|
-
requestUpdateById,
|
|
121
|
-
requestUpdateByValues,
|
|
122
|
-
onSuccess,
|
|
123
|
-
createProps,
|
|
124
|
-
id,
|
|
125
|
-
updateProps,
|
|
126
|
-
],
|
|
108
|
+
[action, requestCreateByValues, requestUpdateByValues, onSuccess, createProps, updateProps],
|
|
127
109
|
);
|
|
128
110
|
|
|
129
111
|
const handleOpenChange = useCallback(
|
|
@@ -164,7 +146,7 @@ function CRUDDetail(props: CRUDDetailProps) {
|
|
|
164
146
|
|
|
165
147
|
if (loading) {
|
|
166
148
|
return (
|
|
167
|
-
<div className="pt-[100px]
|
|
149
|
+
<div className="flex justify-center pt-[100px]">
|
|
168
150
|
<Spin />
|
|
169
151
|
</div>
|
|
170
152
|
);
|
package/src/crud/types.tsx
CHANGED
|
@@ -84,8 +84,6 @@ interface CRUDProps<DataSource = any, Key = string> {
|
|
|
84
84
|
|
|
85
85
|
/** 更新接口,返回 false 则不关闭弹窗 */
|
|
86
86
|
requestUpdateByValues?: (values: Partial<DataSource>) => Promise<false | void>;
|
|
87
|
-
/** @deprecated 请使用 requestUpdateByValues 替代 */
|
|
88
|
-
requestUpdateById?: (values: Partial<DataSource>) => Promise<false | void>;
|
|
89
87
|
updateProps?: {
|
|
90
88
|
/** 文本“编辑” */
|
|
91
89
|
operateText?: string;
|
|
@@ -13,7 +13,10 @@ interface CRUDOfPureProps<
|
|
|
13
13
|
specialToolbar?: boolean;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
function CRUDOfPure
|
|
16
|
+
function CRUDOfPure<
|
|
17
|
+
DataSource extends Record<string, any> = any,
|
|
18
|
+
Key extends string | number = string,
|
|
19
|
+
>(props: CRUDOfPureProps<DataSource, Key>) {
|
|
17
20
|
const newColumns = props.tableProps.columns?.map((column) => {
|
|
18
21
|
if (column.search) {
|
|
19
22
|
return {
|
|
@@ -26,7 +29,9 @@ function CRUDOfPure(props: CRUDOfPureProps) {
|
|
|
26
29
|
// 设置 placeholder
|
|
27
30
|
fieldProps: {
|
|
28
31
|
placeholder:
|
|
29
|
-
column.valueType === 'select'
|
|
32
|
+
column.valueType === 'select' || column.valueEnum
|
|
33
|
+
? `请选择${column.title}`
|
|
34
|
+
: `请输入${column.title}`,
|
|
30
35
|
...column.fieldProps,
|
|
31
36
|
},
|
|
32
37
|
};
|
package/src/style.scss
CHANGED
|
@@ -14,9 +14,11 @@
|
|
|
14
14
|
/* stylelint-disable-next-line at-rule-no-unknown */
|
|
15
15
|
@tailwind utilities;
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
.fec-app-hidden-form-item-label-colon {
|
|
18
|
+
// 隐藏 label 的冒号
|
|
19
|
+
.ant-form-item .ant-form-item-label > label::after {
|
|
20
|
+
visibility: hidden;
|
|
21
|
+
}
|
|
20
22
|
}
|
|
21
23
|
|
|
22
24
|
.ant-modal-footer {
|
|
@@ -16,6 +16,8 @@ enum CustomValueTypeEnum {
|
|
|
16
16
|
/** 渲染开关 */
|
|
17
17
|
CustomSwitchNumber = 'CustomSwitchNumber',
|
|
18
18
|
CustomSwitchOptions = 'CustomSwitchOptions',
|
|
19
|
+
/** CRUD 用,显示序号 */
|
|
20
|
+
CustomSerialNumber = 'CustomSerialNumber',
|
|
19
21
|
}
|
|
20
22
|
|
|
21
23
|
const customValueTypeMap: Record<string, ProRenderFieldPropsType> = {
|
|
@@ -43,6 +45,10 @@ const customValueTypeMap: Record<string, ProRenderFieldPropsType> = {
|
|
|
43
45
|
render: switchOptionsRender.render,
|
|
44
46
|
renderFormItem: switchOptionsRender.renderFormItem,
|
|
45
47
|
},
|
|
48
|
+
[CustomValueTypeEnum.CustomSerialNumber]: {
|
|
49
|
+
render: () => <></>,
|
|
50
|
+
renderFormItem: () => <></>,
|
|
51
|
+
},
|
|
46
52
|
};
|
|
47
53
|
|
|
48
54
|
export { CustomValueTypeEnum, customValueTypeMap };
|