@fe-free/core 3.0.13 → 3.0.14
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 +7 -0
- package/package.json +2 -2
- package/src/file/helper.tsx +2 -2
- package/src/form/form.stories.tsx +9 -4
- package/src/form/index.tsx +1 -0
- package/src/form/pro_form_upload.tsx +25 -2
- package/src/index.ts +1 -0
- package/src/upload/index.tsx +52 -4
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fe-free/core",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.14",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./src/index.ts",
|
|
6
6
|
"author": "",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"safe-stable-stringify": "^2.5.0",
|
|
42
42
|
"vanilla-jsoneditor": "^0.23.1",
|
|
43
43
|
"zustand": "^4.5.4",
|
|
44
|
-
"@fe-free/tool": "3.0.
|
|
44
|
+
"@fe-free/tool": "3.0.14"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
47
|
"@ant-design/pro-components": "2.8.9",
|
package/src/file/helper.tsx
CHANGED
|
@@ -105,11 +105,11 @@ const PRESET_FILE_ICONS: {
|
|
|
105
105
|
];
|
|
106
106
|
|
|
107
107
|
function isImage(name: string) {
|
|
108
|
-
return IMG_EXTS.includes(name.split('.').pop() || '');
|
|
108
|
+
return IMG_EXTS.includes(name.split('.').pop()?.toLowerCase() || '');
|
|
109
109
|
}
|
|
110
110
|
|
|
111
111
|
function getFileExt(name?: string) {
|
|
112
|
-
return name?.split('.').pop() || '';
|
|
112
|
+
return name?.split('.').pop()?.toLowerCase() || '';
|
|
113
113
|
}
|
|
114
114
|
|
|
115
115
|
function getFileSize(size: number) {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ProForm } from '@ant-design/pro-components';
|
|
2
2
|
import {
|
|
3
|
+
ProFormAvatarImageUpload,
|
|
3
4
|
ProFormEditor,
|
|
4
5
|
ProFormImageUpload,
|
|
5
6
|
ProFormImageUploadDragger,
|
|
@@ -48,10 +49,7 @@ function ProFormBase({
|
|
|
48
49
|
<ProForm
|
|
49
50
|
initialValues={initialValues}
|
|
50
51
|
onValuesChange={(newValues) => {
|
|
51
|
-
setValues(
|
|
52
|
-
...values,
|
|
53
|
-
...newValues,
|
|
54
|
-
});
|
|
52
|
+
setValues(newValues);
|
|
55
53
|
}}
|
|
56
54
|
onFinish={(values) => {
|
|
57
55
|
console.log('values', values);
|
|
@@ -282,6 +280,13 @@ export const ProFormImageUploadComponent: Story = {
|
|
|
282
280
|
customRequest,
|
|
283
281
|
}}
|
|
284
282
|
/>
|
|
283
|
+
<ProFormAvatarImageUpload
|
|
284
|
+
label="avatar_image"
|
|
285
|
+
name="avatar_image"
|
|
286
|
+
fieldProps={{
|
|
287
|
+
customRequest,
|
|
288
|
+
}}
|
|
289
|
+
/>
|
|
285
290
|
</ProFormBase>
|
|
286
291
|
),
|
|
287
292
|
};
|
package/src/form/index.tsx
CHANGED
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
// 避免循环引用
|
|
2
2
|
import { ProForm, type ProFormItemProps } from '@ant-design/pro-components';
|
|
3
3
|
import type {
|
|
4
|
+
AvatarImageUploadProps,
|
|
4
5
|
ImageUploadDraggerProps,
|
|
5
6
|
ImageUploadProps,
|
|
6
7
|
UploadDraggerProps,
|
|
7
8
|
UploadProps,
|
|
8
9
|
} from '../upload';
|
|
9
|
-
import {
|
|
10
|
+
import {
|
|
11
|
+
AvatarImageUpload,
|
|
12
|
+
ImageUpload,
|
|
13
|
+
ImageUploadDragger,
|
|
14
|
+
Upload,
|
|
15
|
+
UploadDragger,
|
|
16
|
+
} from '../upload';
|
|
10
17
|
|
|
11
18
|
function ProFormUpload(props: ProFormItemProps<UploadProps>) {
|
|
12
19
|
const { fieldProps, ...rest } = props;
|
|
@@ -37,6 +44,16 @@ function ProFormImageUpload(props: ProFormItemProps<ImageUploadProps>) {
|
|
|
37
44
|
);
|
|
38
45
|
}
|
|
39
46
|
|
|
47
|
+
function ProFormAvatarImageUpload(props: ProFormItemProps<AvatarImageUploadProps>) {
|
|
48
|
+
const { fieldProps, ...rest } = props;
|
|
49
|
+
|
|
50
|
+
return (
|
|
51
|
+
<ProForm.Item {...rest}>
|
|
52
|
+
<AvatarImageUpload {...fieldProps} />
|
|
53
|
+
</ProForm.Item>
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
40
57
|
function ProFormImageUploadDragger(props: ProFormItemProps<ImageUploadDraggerProps>) {
|
|
41
58
|
const { fieldProps, ...rest } = props;
|
|
42
59
|
|
|
@@ -47,4 +64,10 @@ function ProFormImageUploadDragger(props: ProFormItemProps<ImageUploadDraggerPro
|
|
|
47
64
|
);
|
|
48
65
|
}
|
|
49
66
|
|
|
50
|
-
export {
|
|
67
|
+
export {
|
|
68
|
+
ProFormAvatarImageUpload,
|
|
69
|
+
ProFormImageUpload,
|
|
70
|
+
ProFormImageUploadDragger,
|
|
71
|
+
ProFormUpload,
|
|
72
|
+
ProFormUploadDragger,
|
|
73
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -24,6 +24,7 @@ export { EditorMention } from './editor_mention';
|
|
|
24
24
|
export type { EditorMentionProps } from './editor_mention';
|
|
25
25
|
export { FileCard } from './file';
|
|
26
26
|
export {
|
|
27
|
+
ProFormAvatarImageUpload,
|
|
27
28
|
ProFormEditor,
|
|
28
29
|
ProFormImageUpload,
|
|
29
30
|
ProFormImageUploadDragger,
|
package/src/upload/index.tsx
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// 避免循环引用
|
|
2
|
-
import { InboxOutlined, PlusOutlined, UploadOutlined } from '@ant-design/icons';
|
|
2
|
+
import { DeleteOutlined, InboxOutlined, PlusOutlined, UploadOutlined } from '@ant-design/icons';
|
|
3
3
|
import type { UploadProps as AntdUploadProps, UploadFile } from 'antd';
|
|
4
|
-
import { Upload as AntdUpload, Button, message } from 'antd';
|
|
4
|
+
import { Upload as AntdUpload, Avatar, Button, message } from 'antd';
|
|
5
5
|
import classNames from 'classnames';
|
|
6
6
|
import { useCallback, useMemo, useState } from 'react';
|
|
7
7
|
|
|
@@ -169,5 +169,53 @@ function ImageUploadDragger(props: ImageUploadDraggerProps) {
|
|
|
169
169
|
return <UploadDragger {...props} accept="image/*" listType="picture" />;
|
|
170
170
|
}
|
|
171
171
|
|
|
172
|
-
|
|
173
|
-
|
|
172
|
+
interface AvatarImageUploadProps {
|
|
173
|
+
value?: string;
|
|
174
|
+
onChange?: (value?: string) => void;
|
|
175
|
+
action?: string;
|
|
176
|
+
customRequest?: AntdUploadProps['customRequest'];
|
|
177
|
+
accept?: string;
|
|
178
|
+
headers?: AntdUploadProps['headers'];
|
|
179
|
+
}
|
|
180
|
+
function AvatarImageUpload(props: AvatarImageUploadProps) {
|
|
181
|
+
const { value, onChange, action, customRequest, accept = 'image/*', headers } = props;
|
|
182
|
+
|
|
183
|
+
return (
|
|
184
|
+
<div className="flex gap-2">
|
|
185
|
+
<Avatar size={80} src={value} shape="square" className="bg-01 shadow" />
|
|
186
|
+
|
|
187
|
+
<div className="flex flex-1 flex-col justify-between">
|
|
188
|
+
<div className="text-03">请选择</div>
|
|
189
|
+
<div className="flex gap-2">
|
|
190
|
+
<AntdUpload
|
|
191
|
+
action={action}
|
|
192
|
+
customRequest={customRequest}
|
|
193
|
+
onChange={(info) => {
|
|
194
|
+
const url = info.file.response?.data.url;
|
|
195
|
+
if (url) {
|
|
196
|
+
onChange?.(url);
|
|
197
|
+
}
|
|
198
|
+
}}
|
|
199
|
+
itemRender={() => null}
|
|
200
|
+
accept={accept}
|
|
201
|
+
headers={headers}
|
|
202
|
+
>
|
|
203
|
+
<Button icon={<UploadOutlined />}>本地上传</Button>
|
|
204
|
+
</AntdUpload>
|
|
205
|
+
<Button icon={<DeleteOutlined />} danger onClick={() => onChange?.()}>
|
|
206
|
+
删除
|
|
207
|
+
</Button>
|
|
208
|
+
</div>
|
|
209
|
+
</div>
|
|
210
|
+
</div>
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
export { AvatarImageUpload, ImageUpload, ImageUploadDragger, Upload, UploadDragger };
|
|
215
|
+
export type {
|
|
216
|
+
AvatarImageUploadProps,
|
|
217
|
+
ImageUploadDraggerProps,
|
|
218
|
+
ImageUploadProps,
|
|
219
|
+
UploadDraggerProps,
|
|
220
|
+
UploadProps,
|
|
221
|
+
};
|