@fe-free/core 3.0.37 → 3.0.39
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/crud/crud_delete.tsx +12 -18
- package/src/crud/crud_detail.tsx +2 -1
- package/src/crud/helper.tsx +45 -0
- package/src/crud/use_operate.tsx +49 -33
- package/src/crud/use_row_selection.tsx +5 -3
- package/src/global/error.ts +1 -0
- package/src/upload/index.tsx +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @fe-free/core
|
|
2
2
|
|
|
3
|
+
## 3.0.39
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- feat: crud
|
|
8
|
+
- @fe-free/icons@3.0.39
|
|
9
|
+
- @fe-free/tool@3.0.39
|
|
10
|
+
|
|
11
|
+
## 3.0.38
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- feat: some
|
|
16
|
+
- @fe-free/icons@3.0.38
|
|
17
|
+
- @fe-free/tool@3.0.38
|
|
18
|
+
|
|
3
19
|
## 3.0.37
|
|
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.39",
|
|
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/
|
|
50
|
-
"@fe-free/
|
|
49
|
+
"@fe-free/icons": "3.0.39",
|
|
50
|
+
"@fe-free/tool": "3.0.39"
|
|
51
51
|
},
|
|
52
52
|
"scripts": {
|
|
53
53
|
"test": "echo \"Error: no test specified\" && exit 1"
|
package/src/crud/crud_delete.tsx
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { DeleteOutlined } from '@fe-free/icons';
|
|
2
|
-
import {
|
|
2
|
+
import { App } from 'antd';
|
|
3
3
|
import { useCallback } from 'react';
|
|
4
|
+
import { OperateBtn } from './helper';
|
|
4
5
|
|
|
5
6
|
interface Params {
|
|
6
7
|
name: string;
|
|
@@ -12,10 +13,11 @@ interface Params {
|
|
|
12
13
|
|
|
13
14
|
function useDelete(params: Params) {
|
|
14
15
|
const { name, desc, onDelete } = params;
|
|
16
|
+
const { modal } = App.useApp();
|
|
15
17
|
|
|
16
18
|
const doDelete = useCallback(async () => {
|
|
17
19
|
await new Promise((resolve) => {
|
|
18
|
-
|
|
20
|
+
modal.confirm({
|
|
19
21
|
title: `确认删除 “${name}” 吗?`,
|
|
20
22
|
content: desc || '删除后不可恢复,请谨慎操作',
|
|
21
23
|
okText: '确定',
|
|
@@ -28,7 +30,7 @@ function useDelete(params: Params) {
|
|
|
28
30
|
},
|
|
29
31
|
});
|
|
30
32
|
});
|
|
31
|
-
}, [name, desc, onDelete]);
|
|
33
|
+
}, [modal, name, desc, onDelete]);
|
|
32
34
|
|
|
33
35
|
return {
|
|
34
36
|
doDelete,
|
|
@@ -39,22 +41,14 @@ function OperateDelete(props: Params) {
|
|
|
39
41
|
const { name, desc, onDelete, operateText, disabled } = props;
|
|
40
42
|
const { doDelete } = useDelete({ name, desc, onDelete, operateText });
|
|
41
43
|
|
|
42
|
-
if (disabled) {
|
|
43
|
-
return (
|
|
44
|
-
<Tooltip title="删除">
|
|
45
|
-
<span className="cursor-not-allowed text-lg text-03">
|
|
46
|
-
{operateText || <DeleteOutlined />}
|
|
47
|
-
</span>
|
|
48
|
-
</Tooltip>
|
|
49
|
-
);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
44
|
return (
|
|
53
|
-
<
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
45
|
+
<OperateBtn
|
|
46
|
+
title="删除"
|
|
47
|
+
icon={<DeleteOutlined />}
|
|
48
|
+
operateText={operateText}
|
|
49
|
+
disabled={disabled}
|
|
50
|
+
onClick={doDelete}
|
|
51
|
+
/>
|
|
58
52
|
);
|
|
59
53
|
}
|
|
60
54
|
|
package/src/crud/crud_detail.tsx
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DrawerForm, ProForm } from '@ant-design/pro-components';
|
|
2
|
-
import {
|
|
2
|
+
import { App, Spin } from 'antd';
|
|
3
3
|
import classNames from 'classnames';
|
|
4
4
|
import { isString } from 'lodash-es';
|
|
5
5
|
import { useCallback, useMemo, useState } from 'react';
|
|
@@ -54,6 +54,7 @@ function CRUDDetail(props: CRUDDetailProps) {
|
|
|
54
54
|
const [isOpen, setIsOpen] = useState(false);
|
|
55
55
|
const [loading, setLoading] = useState(id ? true : false);
|
|
56
56
|
const [form] = ProForm.useForm(detailFormInstance);
|
|
57
|
+
const { message } = App.useApp();
|
|
57
58
|
|
|
58
59
|
const handleFinish = useCallback(
|
|
59
60
|
async (values) => {
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Tooltip } from 'antd';
|
|
2
|
+
|
|
3
|
+
function OperateBtn({
|
|
4
|
+
title,
|
|
5
|
+
icon,
|
|
6
|
+
operateText,
|
|
7
|
+
disabled,
|
|
8
|
+
onClick,
|
|
9
|
+
}: {
|
|
10
|
+
title: string;
|
|
11
|
+
icon: React.ReactNode;
|
|
12
|
+
operateText?: string;
|
|
13
|
+
disabled?: boolean;
|
|
14
|
+
onClick?: () => void;
|
|
15
|
+
}) {
|
|
16
|
+
if (disabled) {
|
|
17
|
+
if (operateText) {
|
|
18
|
+
return <span className="cursor-not-allowed text-lg text-03">{operateText || icon}</span>;
|
|
19
|
+
} else {
|
|
20
|
+
return (
|
|
21
|
+
<Tooltip title={title}>
|
|
22
|
+
<span className="cursor-not-allowed text-lg text-03">{icon}</span>
|
|
23
|
+
</Tooltip>
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (operateText) {
|
|
29
|
+
return (
|
|
30
|
+
<span className="cursor-pointer text-lg text-primary" onClick={onClick}>
|
|
31
|
+
{operateText}
|
|
32
|
+
</span>
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return (
|
|
37
|
+
<Tooltip title={title}>
|
|
38
|
+
<span className="cursor-pointer text-lg text-primary" onClick={onClick}>
|
|
39
|
+
{operateText || icon}
|
|
40
|
+
</span>
|
|
41
|
+
</Tooltip>
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export { OperateBtn };
|
package/src/crud/use_operate.tsx
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { EditOutlined, EyeOutlined } from '@fe-free/icons';
|
|
2
|
-
import {
|
|
2
|
+
import { App } from 'antd';
|
|
3
3
|
import { isString } from 'lodash-es';
|
|
4
4
|
import { useCallback, useMemo } from 'react';
|
|
5
|
-
import {
|
|
5
|
+
import { routeTool } from '../route';
|
|
6
6
|
import { OperateDelete } from './crud_delete';
|
|
7
7
|
import { CRUDDetail } from './crud_detail';
|
|
8
|
+
import { OperateBtn } from './helper';
|
|
8
9
|
import type { TableProps } from './table';
|
|
9
10
|
|
|
10
11
|
function useOperate(props, detailProps, actionRef) {
|
|
@@ -18,6 +19,7 @@ function useOperate(props, detailProps, actionRef) {
|
|
|
18
19
|
detailIdIndex,
|
|
19
20
|
requestDeleteByRecord,
|
|
20
21
|
} = props;
|
|
22
|
+
const { message } = App.useApp();
|
|
21
23
|
|
|
22
24
|
const idField = tableProps.rowKey || 'id';
|
|
23
25
|
|
|
@@ -56,13 +58,15 @@ function useOperate(props, detailProps, actionRef) {
|
|
|
56
58
|
|
|
57
59
|
if (!hidden) {
|
|
58
60
|
const disabled = readProps?.operateIsDisabled?.(record) || false;
|
|
61
|
+
|
|
59
62
|
if (disabled) {
|
|
60
63
|
return (
|
|
61
|
-
<
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
64
|
+
<OperateBtn
|
|
65
|
+
title="查看"
|
|
66
|
+
icon={<EyeOutlined />}
|
|
67
|
+
operateText={readProps?.operateText}
|
|
68
|
+
disabled
|
|
69
|
+
/>
|
|
66
70
|
);
|
|
67
71
|
} else {
|
|
68
72
|
return (
|
|
@@ -72,9 +76,11 @@ function useOperate(props, detailProps, actionRef) {
|
|
|
72
76
|
record={record}
|
|
73
77
|
onSuccess={handleReload}
|
|
74
78
|
trigger={
|
|
75
|
-
<
|
|
76
|
-
|
|
77
|
-
|
|
79
|
+
<OperateBtn
|
|
80
|
+
title="查看"
|
|
81
|
+
icon={<EyeOutlined />}
|
|
82
|
+
operateText={readProps?.operateText}
|
|
83
|
+
/>
|
|
78
84
|
}
|
|
79
85
|
action="read"
|
|
80
86
|
{...detailProps}
|
|
@@ -94,24 +100,31 @@ function useOperate(props, detailProps, actionRef) {
|
|
|
94
100
|
const disabled = readProps?.operateIsDisabled?.(record) || false;
|
|
95
101
|
if (disabled) {
|
|
96
102
|
return (
|
|
97
|
-
<
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
103
|
+
<OperateBtn
|
|
104
|
+
title="查看"
|
|
105
|
+
icon={<EyeOutlined />}
|
|
106
|
+
operateText={readProps?.operateText}
|
|
107
|
+
disabled
|
|
108
|
+
/>
|
|
102
109
|
);
|
|
103
110
|
} else {
|
|
104
111
|
return (
|
|
105
|
-
<
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
112
|
+
<OperateBtn
|
|
113
|
+
title="查看"
|
|
114
|
+
icon={<EyeOutlined />}
|
|
115
|
+
operateText={readProps?.operateText}
|
|
116
|
+
onClick={() => {
|
|
117
|
+
if (readProps?.target === '_blank') {
|
|
118
|
+
const url = `${window.location.pathname}/detail/${record[detailIdIndex || 'id']}`;
|
|
119
|
+
window.open(url, readProps?.target);
|
|
120
|
+
} else {
|
|
121
|
+
routeTool.navigateTo({
|
|
122
|
+
path: './detail/:id',
|
|
123
|
+
params: { id: record[detailIdIndex || 'id'] },
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
}}
|
|
127
|
+
/>
|
|
115
128
|
);
|
|
116
129
|
}
|
|
117
130
|
}
|
|
@@ -128,11 +141,12 @@ function useOperate(props, detailProps, actionRef) {
|
|
|
128
141
|
|
|
129
142
|
if (disabled) {
|
|
130
143
|
return (
|
|
131
|
-
<
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
144
|
+
<OperateBtn
|
|
145
|
+
title="编辑"
|
|
146
|
+
icon={<EditOutlined />}
|
|
147
|
+
operateText={updateProps?.operateText}
|
|
148
|
+
disabled
|
|
149
|
+
/>
|
|
136
150
|
);
|
|
137
151
|
} else {
|
|
138
152
|
return (
|
|
@@ -142,9 +156,11 @@ function useOperate(props, detailProps, actionRef) {
|
|
|
142
156
|
record={record}
|
|
143
157
|
onSuccess={handleReload}
|
|
144
158
|
trigger={
|
|
145
|
-
<
|
|
146
|
-
|
|
147
|
-
|
|
159
|
+
<OperateBtn
|
|
160
|
+
title="编辑"
|
|
161
|
+
icon={<EditOutlined />}
|
|
162
|
+
operateText={updateProps?.operateText}
|
|
163
|
+
/>
|
|
148
164
|
}
|
|
149
165
|
action="update"
|
|
150
166
|
{...detailProps}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ActionType } from '@ant-design/pro-components';
|
|
2
|
-
import {
|
|
2
|
+
import { App } from 'antd';
|
|
3
3
|
import type { MutableRefObject } from 'react';
|
|
4
4
|
import { useCallback, useMemo } from 'react';
|
|
5
5
|
import { LoadingButton } from '../button';
|
|
@@ -14,6 +14,8 @@ function useRowSelection<DataSource, Key>({
|
|
|
14
14
|
batchActions?: CRUDProps<DataSource, Key>['batchActions'];
|
|
15
15
|
actionRef?: MutableRefObject<ActionType | undefined>;
|
|
16
16
|
}) {
|
|
17
|
+
const { modal } = App.useApp();
|
|
18
|
+
|
|
17
19
|
const rowSelection = useMemo(
|
|
18
20
|
() => ({
|
|
19
21
|
...originRowSelection,
|
|
@@ -48,7 +50,7 @@ function useRowSelection<DataSource, Key>({
|
|
|
48
50
|
onClick={async (event) => {
|
|
49
51
|
if (action.danger) {
|
|
50
52
|
await new Promise((resolve) => {
|
|
51
|
-
|
|
53
|
+
modal.confirm({
|
|
52
54
|
title: `确定要执行 ${action.btnText} 吗?`,
|
|
53
55
|
onOk: () => {
|
|
54
56
|
resolve(
|
|
@@ -79,7 +81,7 @@ function useRowSelection<DataSource, Key>({
|
|
|
79
81
|
</div>
|
|
80
82
|
);
|
|
81
83
|
},
|
|
82
|
-
[actionRef, batchActions],
|
|
84
|
+
[actionRef, batchActions, modal],
|
|
83
85
|
);
|
|
84
86
|
|
|
85
87
|
if (!batchActions || batchActions.length === 0) {
|
package/src/global/error.ts
CHANGED
package/src/upload/index.tsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DeleteOutlined, InboxOutlined, PlusOutlined, UploadOutlined } from '@fe-free/icons';
|
|
2
2
|
import type { UploadProps as AntdUploadProps, UploadFile } from 'antd';
|
|
3
|
-
import { Upload as AntdUpload, Avatar, Button
|
|
3
|
+
import { Upload as AntdUpload, App, Avatar, Button } from 'antd';
|
|
4
4
|
import type { UploadChangeParam } from 'antd/es/upload';
|
|
5
5
|
import classNames from 'classnames';
|
|
6
6
|
import type { ReactNode } from 'react';
|
|
@@ -26,6 +26,7 @@ interface UploadProps extends UploadBaseProps {
|
|
|
26
26
|
function useUpload(
|
|
27
27
|
props: ImageUploadProps & { onChangeOriginal?: (info: UploadChangeParam<UploadFile>) => void },
|
|
28
28
|
) {
|
|
29
|
+
const { message } = App.useApp();
|
|
29
30
|
const { value, onChange, multiple, maxCount, onChangeOriginal } = props;
|
|
30
31
|
// 转换成 Upload 格式。
|
|
31
32
|
const defaultFileList = useMemo(() => {
|