fix:限制上传内容大小
All checks were successful
Build and Push Docker Image / build (push) Successful in 3m46s
All checks were successful
Build and Push Docker Image / build (push) Successful in 3m46s
This commit is contained in:
parent
b98300d927
commit
70dda373a1
@ -15,8 +15,8 @@ export default defineConfig({
|
|||||||
proxy: {
|
proxy: {
|
||||||
'/api/': {
|
'/api/': {
|
||||||
// target: 'http://yt:8003',
|
// target: 'http://yt:8003',
|
||||||
target: 'http://10.39.13.78:8001/',
|
// target: 'http://10.39.13.78:8001/',
|
||||||
// target: 'https://test-admin.linyikj.com.cn/',
|
target: 'https://test-admin.linyikj.com.cn/',
|
||||||
// target: 'https://admin.linyikj.com.cn/',
|
// target: 'https://admin.linyikj.com.cn/',
|
||||||
// target: 'http://c789629c.natappfree.cc',
|
// target: 'http://c789629c.natappfree.cc',
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import { MyProFormFieldProps } from '@/common';
|
import { MyProFormFieldProps } from '@/common';
|
||||||
import { Apis } from '@/gen/Apis';
|
import { Apis } from '@/gen/Apis';
|
||||||
import { PlusOutlined, UploadOutlined } from '@ant-design/icons';
|
import { PlusOutlined, UploadOutlined } from '@ant-design/icons';
|
||||||
import { Button, Modal, Upload, UploadFile, UploadProps } from 'antd';
|
import { Button, message, Modal, Upload, UploadFile, UploadProps } from 'antd';
|
||||||
import { RcFile } from 'antd/es/upload';
|
import { RcFile } from 'antd/es/upload';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import { useSetState } from 'react-use';
|
import { useSetState } from 'react-use';
|
||||||
@ -10,6 +10,7 @@ import './MyUploadImages.scss';
|
|||||||
type MyType = {
|
type MyType = {
|
||||||
uploadType?: 'image' | 'video' | 'audio' | 'file';
|
uploadType?: 'image' | 'video' | 'audio' | 'file';
|
||||||
max?: number;
|
max?: number;
|
||||||
|
size?: number;
|
||||||
} & UploadProps<any> &
|
} & UploadProps<any> &
|
||||||
MyProFormFieldProps<UploadFile[]>;
|
MyProFormFieldProps<UploadFile[]>;
|
||||||
|
|
||||||
@ -26,6 +27,7 @@ export function MyUploadImages({
|
|||||||
onChange,
|
onChange,
|
||||||
uploadType = 'image',
|
uploadType = 'image',
|
||||||
max = 1,
|
max = 1,
|
||||||
|
size = 10,
|
||||||
...rest
|
...rest
|
||||||
}: MyType) {
|
}: MyType) {
|
||||||
const [preview, setPreview] = useSetState<{
|
const [preview, setPreview] = useSetState<{
|
||||||
@ -129,10 +131,25 @@ export function MyUploadImages({
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleBeforeUpload = (file: any, fileList: any) => {
|
||||||
|
if (file?.size > 1024 * 1024 * size) {
|
||||||
|
message.error('文件大小不能超过10MB,请选择重新上传!');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
console.log('beforeUpload', file, fileList);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Upload
|
<Upload
|
||||||
accept={uploadType === 'image' ? 'image/*' : '*'}
|
accept={
|
||||||
|
uploadType === 'image'
|
||||||
|
? 'image/*'
|
||||||
|
: uploadType === 'video'
|
||||||
|
? 'video/*'
|
||||||
|
: '*'
|
||||||
|
}
|
||||||
|
beforeUpload={handleBeforeUpload}
|
||||||
fileList={value}
|
fileList={value}
|
||||||
listType={uploadType === 'image' ? 'picture-card' : 'text'}
|
listType={uploadType === 'image' ? 'picture-card' : 'text'}
|
||||||
onPreview={handlePreview}
|
onPreview={handlePreview}
|
||||||
|
|||||||
@ -187,7 +187,7 @@ export default function Create(props: MyBetaModalFormProps) {
|
|||||||
title: '上传图片',
|
title: '上传图片',
|
||||||
// uploadType: 'file',
|
// uploadType: 'file',
|
||||||
required: true,
|
required: true,
|
||||||
tooltip: '限9张图片',
|
tooltip: '限9张图片10M以内',
|
||||||
max: 9,
|
max: 9,
|
||||||
colProps: { span: 24 },
|
colProps: { span: 24 },
|
||||||
}),
|
}),
|
||||||
@ -205,8 +205,8 @@ export default function Create(props: MyBetaModalFormProps) {
|
|||||||
key: 'attachments',
|
key: 'attachments',
|
||||||
title: '上传视频',
|
title: '上传视频',
|
||||||
required: true,
|
required: true,
|
||||||
tooltip: '限1个视频',
|
tooltip: '限1个视频10M以内,格式要求:mp4',
|
||||||
// uploadType: 'file',
|
uploadType: 'video',
|
||||||
max: 1,
|
max: 1,
|
||||||
colProps: { span: 24 },
|
colProps: { span: 24 },
|
||||||
}),
|
}),
|
||||||
@ -260,7 +260,7 @@ export default function Create(props: MyBetaModalFormProps) {
|
|||||||
},
|
},
|
||||||
MyFormItems.UploadImages({
|
MyFormItems.UploadImages({
|
||||||
key: 'cover_image',
|
key: 'cover_image',
|
||||||
tooltip: '限1张图片',
|
tooltip: '限1张图片10M以内',
|
||||||
title: '设置封面',
|
title: '设置封面',
|
||||||
required: true,
|
required: true,
|
||||||
max: 1,
|
max: 1,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user