diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..6d51cc5 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,12 @@ +/node_modules +package*.json +.gitignore +*.local +*_local +__test__ +.ide +.vscode +.idea +test +dist +public \ No newline at end of file diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..7530022 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,7 @@ +{ + "useTabs": true, + "tabWidth": 2, + "singleQuote": true, + "trailingComma": "none", + "printWidth": 100 +} diff --git a/src/components/article/item.tsx b/src/components/article/item.tsx index 9c3cc31..739154e 100644 --- a/src/components/article/item.tsx +++ b/src/components/article/item.tsx @@ -2,12 +2,14 @@ import React, {useState} from "react"; import {Input, Popconfirm, Spin, Upload, UploadProps} from "antd"; import {CloseOutlined} from "@ant-design/icons"; import {clsx} from "clsx"; +import {useTranslation} from "react-i18next"; import styles from './article.module.scss' import {getOssPolicy} from "@/service/api/common.ts"; import {showToast} from "@/components/message.ts"; -import {IconAddImage, IconWarningCircle} from "@/components/icons"; -import {useTranslation} from "react-i18next"; +import {IconAddImage} from "@/components/icons"; +import {ModalWarningIcon, ModalWarningTitle} from "@/components/icons/ModalWarning.tsx"; +import { BizError } from '@/service/types.ts'; type Props = { children?: React.ReactNode; @@ -37,6 +39,10 @@ export function BlockImage({data, editable, onChange, onlyUpload, onRemove}: Ima }); const beforeUpload = async (file: any) => { try { + // 判断文件类型 + if (!MimeTypes.includes(file.type)) { + throw new Error('upload_file_type_error') + } // 因为有超时问题,所以每次上传都重新获取参数 Data.uploadConfig = await getOssPolicy(); const suffix = file.name.slice(file.name.lastIndexOf('.')); @@ -52,17 +58,22 @@ export function BlockImage({data, editable, onChange, onlyUpload, onRemove}: Ima const onUploadChange = async (info) => { if (info.fileList.length == 0) return; const file = info.fileList[0]; - console.log('onChange', file); + console.log('onUploadChange', file); if (file.status == 'done') { - setLoading(-1) - onChange?.({type: 'image', content: Data.uploadConfig?.host + '/' + file.url}) + setLoading(-1); + onChange?.({ type: 'image', content: Data.uploadConfig?.host + '/' + file.url }); } else if (file.status == 'error') { - setLoading(-1) - showToast(t('upload.upload_failed'), 'warning') + + if (!MimeTypes.includes(file.type)) { + showToast(t('upload.upload_file_type_error'), 'warning'); + return; + } + setLoading(-1); + showToast(t('upload.upload_failed'), 'warning'); } else if (file.status == 'uploading') { - setLoading(file.percent) + setLoading(file.percent); } - } + }; // return