From 3d02643de3629f4c9c5622d0a25e280b14cf8ee5 Mon Sep 17 00:00:00 2001 From: ditiqi Date: Tue, 25 Feb 2025 08:46:22 +0800 Subject: [PATCH] add --- apps/web/src/app/admin/base-setting/page.tsx | 4 +-- .../common/uploader/TusUploader.tsx | 23 ++++++++++----- .../CourseContentForm/SortableLecture.tsx | 28 +++++++++++++++---- packages/common/src/constants.ts | 14 ++++++++++ 4 files changed, 55 insertions(+), 14 deletions(-) diff --git a/apps/web/src/app/admin/base-setting/page.tsx b/apps/web/src/app/admin/base-setting/page.tsx index 1155868..1f8d42f 100755 --- a/apps/web/src/app/admin/base-setting/page.tsx +++ b/apps/web/src/app/admin/base-setting/page.tsx @@ -24,7 +24,8 @@ export default function BaseSettingPage() { const [isFormChanged, setIsFormChanged] = useState(false); const [loading, setLoading] = useState(false); const { user, hasSomePermissions } = useAuth(); - const { pageWidth } = useContext?.(MainLayoutContext); + const context = useContext(MainLayoutContext); + const pageWidth = context?.pageWidth; function handleFieldsChange() { setIsFormChanged(true); } @@ -43,7 +44,6 @@ export default function BaseSettingPage() { } async function onSubmit(values: BaseSetting) { setLoading(true); - try { await update.mutateAsync({ where: { diff --git a/apps/web/src/components/common/uploader/TusUploader.tsx b/apps/web/src/components/common/uploader/TusUploader.tsx index e9fa45b..1811135 100755 --- a/apps/web/src/components/common/uploader/TusUploader.tsx +++ b/apps/web/src/components/common/uploader/TusUploader.tsx @@ -11,6 +11,7 @@ export interface TusUploaderProps { value?: string[]; onChange?: (value: string[]) => void; multiple?: boolean; + allowTypes?: string[]; } interface UploadingFile { @@ -25,8 +26,8 @@ export const TusUploader = ({ value = [], onChange, multiple = true, + allowTypes = undefined, }: TusUploaderProps) => { - const { handleFileUpload, uploadProgress } = useTusUpload(); const [uploadingFiles, setUploadingFiles] = useState([]); const [completedFiles, setCompletedFiles] = useState( @@ -61,7 +62,10 @@ export const TusUploader = ({ const handleBeforeUpload = useCallback( (file: File) => { - + if (allowTypes && !allowTypes.includes(file.type)) { + toast.error(`文件类型 ${file.type} 不在允许范围内`); + return Upload.LIST_IGNORE; // 使用 antd 的官方阻止方式 + } const fileKey = `${file.name}-${Date.now()}`; setUploadingFiles((prev) => [ @@ -136,10 +140,10 @@ export const TusUploader = ({ return (

@@ -149,6 +153,11 @@ export const TusUploader = ({

{multiple ? "支持单个或批量上传文件" : "仅支持上传单个文件"} + {allowTypes && ( + + 允许类型: {allowTypes.join(", ")} + + )}

@@ -165,10 +174,10 @@ export const TusUploader = ({ file.status === "done" ? 100 : Math.round( - uploadProgress?.[ - file.fileKey! - ] || 0 - ) + uploadProgress?.[ + file.fileKey! + ] || 0 + ) } status={ file.status === "error" diff --git a/apps/web/src/components/models/course/editor/form/CourseContentForm/SortableLecture.tsx b/apps/web/src/components/models/course/editor/form/CourseContentForm/SortableLecture.tsx index 7a23629..cb662a3 100755 --- a/apps/web/src/components/models/course/editor/form/CourseContentForm/SortableLecture.tsx +++ b/apps/web/src/components/models/course/editor/form/CourseContentForm/SortableLecture.tsx @@ -10,7 +10,13 @@ import { useSortable } from "@dnd-kit/sortable"; import { CSS } from "@dnd-kit/utilities"; import QuillEditor from "@web/src/components/common/editor/quill/QuillEditor"; import { TusUploader } from "@web/src/components/common/uploader/TusUploader"; -import { Lecture, LectureType, LessonTypeLabel, PostType } from "@nice/common"; +import { + Lecture, + LectureType, + LessonTypeLabel, + PostType, + videoMimeTypes, +} from "@nice/common"; import { usePost } from "@nice/client"; import toast from "react-hot-toast"; @@ -134,7 +140,9 @@ export const SortableLecture: React.FC = ({ name="title" initialValue={field?.title} className="mb-0 flex-1" - rules={[{ required: true }]}> + rules={[ + { required: true, message: "请输入课时标题" }, + ]}> = ({ - + rules={[ + { + required: true, + message: "请输入课时标题", + }, + ]}> + ) : ( + rules={[ + { required: true, message: "请输入内容" }, + ]}> )} diff --git a/packages/common/src/constants.ts b/packages/common/src/constants.ts index 7e9174f..9a36b03 100755 --- a/packages/common/src/constants.ts +++ b/packages/common/src/constants.ts @@ -81,3 +81,17 @@ export const InitAppConfigs: Prisma.AppConfigCreateInput[] = [ description: "", }, ]; +export const videoMimeTypes = [ + "video/*", // 通配符 (部分浏览器可能不支持) + "video/mp4", // .mp4 + "video/quicktime", // .mov + "video/x-msvideo", // .avi + "video/x-matroska", // .mkv + "video/webm", // .webm + "video/ogg", // .ogv + "video/mpeg", // .mpeg + "video/3gpp", // .3gp + "video/3gpp2", // .3g2 + "video/x-flv", // .flv + "video/x-ms-wmv", // .wmv +];