@fe-free/core 4.0.4 → 5.0.0

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.
@@ -5,6 +5,7 @@ import type { UploadChangeParam } from 'antd/es/upload';
5
5
  import classNames from 'classnames';
6
6
  import type { ReactNode } from 'react';
7
7
  import { useCallback, useMemo, useState } from 'react';
8
+ import { useTranslation } from 'react-i18next';
8
9
  import './style.scss';
9
10
 
10
11
  interface UploadBaseProps {
@@ -28,6 +29,7 @@ function useUpload(
28
29
  props: ImageUploadProps & { onChangeOriginal?: (info: UploadChangeParam<UploadFile>) => void },
29
30
  ) {
30
31
  const { message } = App.useApp();
32
+ const { t } = useTranslation();
31
33
  const { value, onChange, multiple, maxCount, onChangeOriginal } = props;
32
34
  // 转换成 Upload 格式。
33
35
  const defaultFileList = useMemo(() => {
@@ -68,13 +70,21 @@ function useUpload(
68
70
  if (multiple && maxCount && maxCount > 1) {
69
71
  const index = fl.findIndex((item) => item.uid === f.uid);
70
72
  if (index >= maxCount - fileList.length) {
71
- message.warning(`最多只能上传 ${maxCount} 个文件,超出部分会忽略。`);
73
+ message.warning(
74
+ t(
75
+ '@fe-free/core.upload.maxFilesWarning',
76
+ '最多只能上传 {num} 个文件,超出部分会忽略。',
77
+ {
78
+ num: maxCount,
79
+ },
80
+ ),
81
+ );
72
82
  }
73
83
  }
74
84
 
75
85
  return true;
76
86
  },
77
- [multiple, maxCount, fileList.length, message],
87
+ [multiple, maxCount, fileList.length, message, t],
78
88
  );
79
89
 
80
90
  // 多选情况下,超出则上传按钮 disabled
@@ -94,24 +104,26 @@ function useUpload(
94
104
  };
95
105
  }
96
106
 
97
- function defaultChildren(
107
+ function DefaultChildren(
98
108
  props: ImageUploadProps,
99
109
  otherProps: { fileList: UploadFile[]; isDisabled: boolean },
100
110
  ) {
101
111
  const { listType, showCount, multiple, maxCount } = props;
102
112
  const { fileList, isDisabled } = otherProps;
113
+ const { t } = useTranslation();
103
114
 
104
115
  if (listType === 'picture-card') {
105
116
  return (
106
117
  <button style={{ border: 0, background: 'none' }} type="button" disabled={isDisabled}>
107
118
  <PlusOutlined />
108
- <div style={{ marginTop: 8 }}>本地上传</div>
119
+ <div style={{ marginTop: 8 }}>{t('@fe-free/core.upload.localUpload', '本地上传')}</div>
109
120
  </button>
110
121
  );
111
122
  }
112
123
  return (
113
124
  <Button icon={<UploadOutlined />} disabled={isDisabled}>
114
- 本地上传{showCount && multiple ? `(${fileList.length}/${maxCount})` : ''}
125
+ {t('@fe-free/core.upload.localUpload', '本地上传')}
126
+ {showCount && multiple ? `(${fileList.length}/${maxCount})` : ''}
115
127
  </Button>
116
128
  );
117
129
  }
@@ -125,7 +137,7 @@ function Upload(props: ImageUploadProps) {
125
137
  listType,
126
138
  accept,
127
139
  directory,
128
- children = defaultChildren,
140
+ children = DefaultChildren,
129
141
  } = props;
130
142
  const { onChange, beforeUpload, isDisabled, fileList } = useUpload(props);
131
143
 
@@ -169,6 +181,7 @@ function UploadDragger(props: UploadDraggerProps) {
169
181
  directory,
170
182
  } = props;
171
183
  const { onChange, beforeUpload, isDisabled, fileList, successList } = useUpload(props);
184
+ const { t } = useTranslation();
172
185
 
173
186
  const itemRender = useCallback(
174
187
  (originNode, file, fileList) => {
@@ -178,7 +191,10 @@ function UploadDragger(props: UploadDraggerProps) {
178
191
  return (
179
192
  <div>
180
193
  <div className="py-1">
181
- 文件数量 ({successList.length}/{fileList.length})
194
+ {t('@fe-free/core.upload.fileCount', '文件数量 ({success}/{total})', {
195
+ success: successList.length,
196
+ total: fileList.length,
197
+ })}
182
198
  </div>
183
199
  {originNode}
184
200
  </div>
@@ -187,7 +203,7 @@ function UploadDragger(props: UploadDraggerProps) {
187
203
 
188
204
  return originNode;
189
205
  },
190
- [maxCount, showStatus, successList.length],
206
+ [maxCount, showStatus, successList.length, t],
191
207
  );
192
208
 
193
209
  return (
@@ -226,7 +242,7 @@ function UploadDragger(props: UploadDraggerProps) {
226
242
  '!text-03': isDisabled,
227
243
  })}
228
244
  >
229
- {title || '点击或拖拽到此区域进行上传'}
245
+ {title || t('@fe-free/core.upload.dragUpload', '点击或拖拽到此区域进行上传')}
230
246
  </p>
231
247
  {description && <p className={classNames('ant-upload-hint')}>{description}</p>}
232
248
  </div>
@@ -256,13 +272,14 @@ interface AvatarImageUploadProps {
256
272
  }
257
273
  function AvatarImageUpload(props: AvatarImageUploadProps) {
258
274
  const { value, onChange, action, customRequest, accept = 'image/*', headers } = props;
275
+ const { t } = useTranslation();
259
276
 
260
277
  return (
261
278
  <div className="flex gap-2">
262
279
  <Avatar size={80} src={value} shape="square" className="bg-01 shadow" />
263
280
 
264
281
  <div className="flex flex-1 flex-col justify-between">
265
- <div className="text-03">请选择</div>
282
+ <div className="text-03">{t('@fe-free/core.upload.pleaseSelect', '请选择')}</div>
266
283
  <div className="flex gap-2">
267
284
  <AntdUpload
268
285
  action={action}
@@ -277,10 +294,12 @@ function AvatarImageUpload(props: AvatarImageUploadProps) {
277
294
  accept={accept}
278
295
  headers={headers}
279
296
  >
280
- <Button icon={<UploadOutlined />}>本地上传</Button>
297
+ <Button icon={<UploadOutlined />}>
298
+ {t('@fe-free/core.upload.localUpload', '本地上传')}
299
+ </Button>
281
300
  </AntdUpload>
282
301
  <Button icon={<DeleteOutlined />} danger onClick={() => onChange?.()}>
283
- 删除
302
+ {t('@fe-free/core.upload.delete', '删除')}
284
303
  </Button>
285
304
  </div>
286
305
  </div>
@@ -1,6 +1,7 @@
1
1
  import type { ProFormItemProps } from '@ant-design/pro-components';
2
2
  import { Modal } from 'antd';
3
3
  import { useState } from 'react';
4
+ import { useTranslation } from 'react-i18next';
4
5
  import type { EditorJSONProps } from '../editor_json';
5
6
  import { EditorJSON } from '../editor_json';
6
7
 
@@ -10,7 +11,8 @@ interface JSONModalProps extends EditorJSONProps {
10
11
  }
11
12
 
12
13
  function Render(text, props: ProFormItemProps<JSONModalProps>) {
13
- const { title = '查看' } = props.fieldProps || {};
14
+ const { t } = useTranslation();
15
+ const { title = t('@fe-free/core.valueTypeMap.view', '查看') } = props.fieldProps || {};
14
16
 
15
17
  const [show, setShow] = useState(false);
16
18