|
@@ -88,24 +88,26 @@ export default defineComponent({
|
|
|
const uploadList = ref([] as any);
|
|
|
|
|
|
// 获取文件后缀名
|
|
|
- // function getFileExtension(filename: string) {
|
|
|
- // return filename.slice(((filename.lastIndexOf('.') - 1) >>> 0) + 2);
|
|
|
- // }
|
|
|
+ function getFileExtension(filename: string) {
|
|
|
+ return filename.slice(((filename.lastIndexOf('.') - 1) >>> 0) + 2);
|
|
|
+ }
|
|
|
|
|
|
- // // 判断是否是允许的文件类型
|
|
|
- // function isAllowedFileType(filename: string, allowedExtensions: any) {
|
|
|
- // const extension = getFileExtension(filename).toLowerCase();
|
|
|
- // return allowedExtensions.includes(extension);
|
|
|
- // }
|
|
|
+ // 判断是否是允许的文件类型
|
|
|
+ function isAllowedFileType(filename: string, allowedExtensions: any) {
|
|
|
+ const extension = getFileExtension(filename).toLowerCase();
|
|
|
+ return allowedExtensions.includes(extension);
|
|
|
+ }
|
|
|
|
|
|
const onBeforeUpload = async (options: any) => {
|
|
|
const file = options.file;
|
|
|
// 文件大小
|
|
|
let isLt2M = true;
|
|
|
|
|
|
- // JPG、PNG、MP3、MP4、PPT
|
|
|
- // const filename = 'example.jpg';
|
|
|
- // const allowedExtensions = ['jpg', 'jpeg', 'png', 'mp4', 'ppt'];
|
|
|
+ const allowedExtensions = ['jpg', 'jpeg', 'png', 'mp4', 'ppt', 'pptx'];
|
|
|
+ if (!isAllowedFileType(file.file.name, allowedExtensions)) {
|
|
|
+ message.error('文件格式不支持');
|
|
|
+ return false;
|
|
|
+ }
|
|
|
|
|
|
const type = file.type.includes('image')
|
|
|
? NaturalTypeEnum.IMG
|