@fe-free/core 3.0.13 → 3.0.15

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 CHANGED
@@ -1,5 +1,19 @@
1
1
  # @fe-free/core
2
2
 
3
+ ## 3.0.15
4
+
5
+ ### Patch Changes
6
+
7
+ - feat: uploader
8
+ - @fe-free/tool@3.0.15
9
+
10
+ ## 3.0.14
11
+
12
+ ### Patch Changes
13
+
14
+ - feat: upload
15
+ - @fe-free/tool@3.0.14
16
+
3
17
  ## 3.0.13
4
18
 
5
19
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fe-free/core",
3
- "version": "3.0.13",
3
+ "version": "3.0.15",
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.13"
44
+ "@fe-free/tool": "3.0.15"
45
45
  },
46
46
  "peerDependencies": {
47
47
  "@ant-design/pro-components": "2.8.9",
@@ -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);
@@ -230,7 +228,11 @@ export const ProFormUploadComponent: Story = {
230
228
  <ProFormUploadDragger
231
229
  label="file_dragger"
232
230
  name="file_dragger"
233
- fieldProps={{ customRequest }}
231
+ fieldProps={{
232
+ title: '这是标题',
233
+ description: '这是描述',
234
+ customRequest,
235
+ }}
234
236
  />
235
237
  <ProFormUploadDragger
236
238
  label="files_dragger"
@@ -282,6 +284,13 @@ export const ProFormImageUploadComponent: Story = {
282
284
  customRequest,
283
285
  }}
284
286
  />
287
+ <ProFormAvatarImageUpload
288
+ label="avatar_image"
289
+ name="avatar_image"
290
+ fieldProps={{
291
+ customRequest,
292
+ }}
293
+ />
285
294
  </ProFormBase>
286
295
  ),
287
296
  };
@@ -14,6 +14,7 @@ export {
14
14
  type SwitchOptionsProps,
15
15
  } from './pro_form_switch';
16
16
  export {
17
+ ProFormAvatarImageUpload,
17
18
  ProFormImageUpload,
18
19
  ProFormImageUploadDragger,
19
20
  ProFormUpload,
@@ -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 { ImageUpload, ImageUploadDragger, Upload, UploadDragger } from '../upload';
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 { ProFormImageUpload, ProFormImageUploadDragger, ProFormUpload, ProFormUploadDragger };
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,
@@ -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
 
@@ -19,8 +19,6 @@ interface UploadBaseProps {
19
19
  interface UploadProps extends UploadBaseProps {
20
20
  showCount?: boolean;
21
21
  }
22
- // eslint-disable-next-line @typescript-eslint/no-empty-object-type
23
- interface UploadDraggerProps extends UploadBaseProps {}
24
22
 
25
23
  function useUpload(props: ImageUploadProps) {
26
24
  const { value, onChange, multiple, maxCount } = props;
@@ -115,8 +113,12 @@ function Upload(props: ImageUploadProps) {
115
113
  );
116
114
  }
117
115
 
118
- function UploadDragger(props: ImageUploadDraggerProps) {
119
- const { multiple, maxCount, action, customRequest, listType, accept } = props;
116
+ interface UploadDraggerProps extends UploadBaseProps {
117
+ title?: string;
118
+ description?: string;
119
+ }
120
+ function UploadDragger(props: UploadDraggerProps) {
121
+ const { multiple, maxCount, action, customRequest, listType, accept, title, description } = props;
120
122
  const { onChange, beforeUpload, isDisabled, fileList } = useUpload(props);
121
123
 
122
124
  return (
@@ -150,8 +152,9 @@ function UploadDragger(props: ImageUploadDraggerProps) {
150
152
  '!text-03': isDisabled,
151
153
  })}
152
154
  >
153
- 点击或拖拽到此区域进行上传
155
+ {title || '点击或拖拽到此区域进行上传'}
154
156
  </p>
157
+ {description && <p className={classNames('ant-upload-hint')}>{description}</p>}
155
158
  </div>
156
159
  </AntdUpload.Dragger>
157
160
  );
@@ -169,5 +172,53 @@ function ImageUploadDragger(props: ImageUploadDraggerProps) {
169
172
  return <UploadDragger {...props} accept="image/*" listType="picture" />;
170
173
  }
171
174
 
172
- export { ImageUpload, ImageUploadDragger, Upload, UploadDragger };
173
- export type { ImageUploadDraggerProps, ImageUploadProps, UploadDraggerProps, UploadProps };
175
+ interface AvatarImageUploadProps {
176
+ value?: string;
177
+ onChange?: (value?: string) => void;
178
+ action?: string;
179
+ customRequest?: AntdUploadProps['customRequest'];
180
+ accept?: string;
181
+ headers?: AntdUploadProps['headers'];
182
+ }
183
+ function AvatarImageUpload(props: AvatarImageUploadProps) {
184
+ const { value, onChange, action, customRequest, accept = 'image/*', headers } = props;
185
+
186
+ return (
187
+ <div className="flex gap-2">
188
+ <Avatar size={80} src={value} shape="square" className="bg-01 shadow" />
189
+
190
+ <div className="flex flex-1 flex-col justify-between">
191
+ <div className="text-03">请选择</div>
192
+ <div className="flex gap-2">
193
+ <AntdUpload
194
+ action={action}
195
+ customRequest={customRequest}
196
+ onChange={(info) => {
197
+ const url = info.file.response?.data.url;
198
+ if (url) {
199
+ onChange?.(url);
200
+ }
201
+ }}
202
+ itemRender={() => null}
203
+ accept={accept}
204
+ headers={headers}
205
+ >
206
+ <Button icon={<UploadOutlined />}>本地上传</Button>
207
+ </AntdUpload>
208
+ <Button icon={<DeleteOutlined />} danger onClick={() => onChange?.()}>
209
+ 删除
210
+ </Button>
211
+ </div>
212
+ </div>
213
+ </div>
214
+ );
215
+ }
216
+
217
+ export { AvatarImageUpload, ImageUpload, ImageUploadDragger, Upload, UploadDragger };
218
+ export type {
219
+ AvatarImageUploadProps,
220
+ ImageUploadDraggerProps,
221
+ ImageUploadProps,
222
+ UploadDraggerProps,
223
+ UploadProps,
224
+ };