Skip to content

Commit

Permalink
feat: 上传图片组件添加可配置项
Browse files Browse the repository at this point in the history
  • Loading branch information
yangxu23 authored and CheshireJCat committed Jan 24, 2025
1 parent 1af15a0 commit 54e1dd2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
4 changes: 3 additions & 1 deletion packages/amis-core/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ import {
register as registerLocale,
extendLocale,
removeLocaleData,
localeable
localeable,
format as localeFormatter
} from './locale';
import type {LocaleProps, TranslateFn} from './locale';

Expand Down Expand Up @@ -203,6 +204,7 @@ export {
extendLocale,
removeLocaleData,
localeable,
localeFormatter,
LocaleProps,
TranslateFn,
ClassNamesFn,
Expand Down
2 changes: 1 addition & 1 deletion packages/amis-core/src/locale.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const fns: {
[propName: string]: TranslateFn;
} = {};

function format(str: string, data?: object) {
export function format(str: string, data?: object) {
return str.replace(/(\\)?\{\{([\s\S]+?)\}\}/g, (_, escape, key) => {
if (escape) {
return _.substring(1);
Expand Down
12 changes: 9 additions & 3 deletions packages/amis/src/renderers/Form/InputImage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import {
resolveEventData,
CustomStyle,
setThemeClassName,
PlainObject
PlainObject,
localeFormatter
} from 'amis-core';
// import 'cropperjs/dist/cropper.css';
const Cropper = React.lazy(() => import('react-cropper'));
Expand Down Expand Up @@ -710,7 +711,10 @@ export default class ImageControl extends React.Component<
// 类型错误
if (err.code === ErrorCode.FileInvalidType) {
if (invalidTypeMessage) {
return invalidTypeMessage;
return localeFormatter(invalidTypeMessage, {
files: file.name,
accept
});
} else {
return __('File.invalidType', {
files: file.name,
Expand All @@ -721,7 +725,9 @@ export default class ImageControl extends React.Component<
// 文件太大
else if (err.code === ErrorCode.FileTooLarge) {
if (invalidSizeMessage) {
return invalidSizeMessage;
return localeFormatter(invalidSizeMessage, {
maxSize: prettyBytes(maxSize as number, 1024)
});
} else {
return __('File.sizeLimit', {
maxSize: prettyBytes(maxSize as number, 1024)
Expand Down

0 comments on commit 54e1dd2

Please sign in to comment.