|
@@ -1,12 +1,26 @@
|
|
|
-import { Checkbox } from 'antd';
|
|
|
-import { forwardRef, useCallback, useEffect, useImperativeHandle, useMemo, useState } from 'react';
|
|
|
-import { CheckboxValueType } from 'antd/es/checkbox/Group';
|
|
|
-import { DAGE_FILE_CHECKBOX_OPTIONS } from './constants';
|
|
|
-import { DageFileCheckboxMethods, DageFileCheckboxProps } from './types';
|
|
|
-import { DageFileResponseType, DageUpload, DageUploadType } from '../Upload';
|
|
|
-import { FileCheckboxItem } from './style';
|
|
|
+import { Checkbox } from "antd";
|
|
|
+import {
|
|
|
+ forwardRef,
|
|
|
+ useCallback,
|
|
|
+ useEffect,
|
|
|
+ useImperativeHandle,
|
|
|
+ useMemo,
|
|
|
+ useState,
|
|
|
+} from "react";
|
|
|
+import { CheckboxValueType } from "antd/es/checkbox/Group";
|
|
|
+import { DAGE_FILE_CHECKBOX_OPTIONS } from "./constants";
|
|
|
+import { DageFileCheckboxMethods, DageFileCheckboxProps } from "./types";
|
|
|
+import {
|
|
|
+ DageFileResponseType,
|
|
|
+ DageUpload,
|
|
|
+ DageUploadType,
|
|
|
+} from "../DageUpload";
|
|
|
+import { FileCheckboxItem } from "./style";
|
|
|
|
|
|
-export const DageFileCheckbox = forwardRef<DageFileCheckboxMethods, DageFileCheckboxProps>(
|
|
|
+export const DageFileCheckbox = forwardRef<
|
|
|
+ DageFileCheckboxMethods,
|
|
|
+ DageFileCheckboxProps
|
|
|
+>(
|
|
|
(
|
|
|
{
|
|
|
value,
|
|
@@ -21,47 +35,65 @@ export const DageFileCheckbox = forwardRef<DageFileCheckboxMethods, DageFileChec
|
|
|
onChange,
|
|
|
onFileChange,
|
|
|
},
|
|
|
- ref,
|
|
|
+ ref
|
|
|
) => {
|
|
|
- const checkboxVal = useMemo(() => (value ? value.split(',') : []), [value]);
|
|
|
+ const checkboxVal = useMemo(() => (value ? value.split(",") : []), [value]);
|
|
|
const [modelFiles, setModelFiles] = useState<DageFileResponseType[]>([]);
|
|
|
- const [mobileModelFiles, setMobileModelFiles] = useState<DageFileResponseType[]>([]);
|
|
|
+ const [mobileModelFiles, setMobileModelFiles] = useState<
|
|
|
+ DageFileResponseType[]
|
|
|
+ >([]);
|
|
|
const [imgFiles, setImgFiles] = useState<DageFileResponseType[]>([]);
|
|
|
const [videoFiles, setVideoFiles] = useState<DageFileResponseType[]>([]);
|
|
|
const [audioFiles, setAudioFiles] = useState<DageFileResponseType[]>([]);
|
|
|
|
|
|
- const hasModel = useMemo(() => checkboxVal.includes(DageUploadType.MODEL), [checkboxVal]);
|
|
|
- const hasImg = useMemo(() => checkboxVal.includes(DageUploadType.IMG), [checkboxVal]);
|
|
|
- const hasAudio = useMemo(() => checkboxVal.includes(DageUploadType.AUDIO), [checkboxVal]);
|
|
|
- const hasVideo = useMemo(() => checkboxVal.includes(DageUploadType.VIDEO), [checkboxVal]);
|
|
|
+ const hasModel = useMemo(
|
|
|
+ () => checkboxVal.includes(DageUploadType.MODEL),
|
|
|
+ [checkboxVal]
|
|
|
+ );
|
|
|
+ const hasImg = useMemo(
|
|
|
+ () => checkboxVal.includes(DageUploadType.IMG),
|
|
|
+ [checkboxVal]
|
|
|
+ );
|
|
|
+ const hasAudio = useMemo(
|
|
|
+ () => checkboxVal.includes(DageUploadType.AUDIO),
|
|
|
+ [checkboxVal]
|
|
|
+ );
|
|
|
+ const hasVideo = useMemo(
|
|
|
+ () => checkboxVal.includes(DageUploadType.VIDEO),
|
|
|
+ [checkboxVal]
|
|
|
+ );
|
|
|
|
|
|
useImperativeHandle(ref, () => ({
|
|
|
validate(rule, val, callback) {
|
|
|
if (!val) {
|
|
|
- callback('请选择文件类型');
|
|
|
+ callback("请选择文件类型");
|
|
|
} else if (
|
|
|
hasModel &&
|
|
|
- (!modelFiles.length || !modelFiles.some((i) => i.status === 'done'))
|
|
|
+ (!modelFiles.length || !modelFiles.some((i) => i.status === "done"))
|
|
|
) {
|
|
|
- callback('PC端模型文件不能为空');
|
|
|
+ callback("PC端模型文件不能为空");
|
|
|
} else if (
|
|
|
hasModel &&
|
|
|
hasMobileModel &&
|
|
|
- (!mobileModelFiles.length || !mobileModelFiles.some((i) => i.status === 'done'))
|
|
|
+ (!mobileModelFiles.length ||
|
|
|
+ !mobileModelFiles.some((i) => i.status === "done"))
|
|
|
+ ) {
|
|
|
+ callback("移动端模型文件不能为空");
|
|
|
+ } else if (
|
|
|
+ hasImg &&
|
|
|
+ (!imgFiles.length || !imgFiles.some((i) => i.status === "done"))
|
|
|
) {
|
|
|
- callback('移动端模型文件不能为空');
|
|
|
- } else if (hasImg && (!imgFiles.length || !imgFiles.some((i) => i.status === 'done'))) {
|
|
|
- callback('图片文件不能为空');
|
|
|
+ callback("图片文件不能为空");
|
|
|
} else if (
|
|
|
hasVideo &&
|
|
|
- (!videoFiles.length || !videoFiles.some((i) => i.status === 'done'))
|
|
|
+ (!videoFiles.length || !videoFiles.some((i) => i.status === "done"))
|
|
|
) {
|
|
|
- callback('视频文件不能为空');
|
|
|
+ callback("视频文件不能为空");
|
|
|
} else if (
|
|
|
hasAudio &&
|
|
|
- (!audioFiles.length || !audioFiles.some((i) => i.status === 'done'))
|
|
|
+ (!audioFiles.length || !audioFiles.some((i) => i.status === "done"))
|
|
|
) {
|
|
|
- callback('音频文件不能为空');
|
|
|
+ callback("音频文件不能为空");
|
|
|
}
|
|
|
callback();
|
|
|
},
|
|
@@ -104,16 +136,19 @@ export const DageFileCheckbox = forwardRef<DageFileCheckboxMethods, DageFileChec
|
|
|
|
|
|
const handleCheckbox = useCallback(
|
|
|
(val: CheckboxValueType[]) => {
|
|
|
- onChange?.(val.join(','));
|
|
|
+ onChange?.(val.join(","));
|
|
|
},
|
|
|
- [onChange],
|
|
|
+ [onChange]
|
|
|
);
|
|
|
|
|
|
const handleFileChange = useCallback(
|
|
|
- (method: (v: DageFileResponseType[]) => void, list: DageFileResponseType[]) => {
|
|
|
+ (
|
|
|
+ method: (v: DageFileResponseType[]) => void,
|
|
|
+ list: DageFileResponseType[]
|
|
|
+ ) => {
|
|
|
method(list);
|
|
|
},
|
|
|
- [],
|
|
|
+ []
|
|
|
);
|
|
|
|
|
|
useEffect(() => {
|
|
@@ -147,9 +182,9 @@ export const DageFileCheckbox = forwardRef<DageFileCheckboxMethods, DageFileChec
|
|
|
value={checkboxVal}
|
|
|
options={DAGE_FILE_CHECKBOX_OPTIONS}
|
|
|
style={{
|
|
|
- display: 'flex',
|
|
|
- alignItems: 'center',
|
|
|
- height: '32px',
|
|
|
+ display: "flex",
|
|
|
+ alignItems: "center",
|
|
|
+ height: "32px",
|
|
|
}}
|
|
|
onChange={handleCheckbox}
|
|
|
/>
|
|
@@ -181,7 +216,10 @@ export const DageFileCheckbox = forwardRef<DageFileCheckboxMethods, DageFileChec
|
|
|
maxCount={maxMobileModelCount}
|
|
|
maxSize={1000}
|
|
|
tips="仅支持zip格式的压缩包,大小不能超过1000M"
|
|
|
- onChange={handleFileChange.bind(undefined, setMobileModelFiles)}
|
|
|
+ onChange={handleFileChange.bind(
|
|
|
+ undefined,
|
|
|
+ setMobileModelFiles
|
|
|
+ )}
|
|
|
/>
|
|
|
</FileCheckboxItem>
|
|
|
)}
|
|
@@ -234,8 +272,8 @@ export const DageFileCheckbox = forwardRef<DageFileCheckboxMethods, DageFileChec
|
|
|
)}
|
|
|
</div>
|
|
|
);
|
|
|
- },
|
|
|
+ }
|
|
|
);
|
|
|
|
|
|
-export * from './types';
|
|
|
-export * from './constants';
|
|
|
+export * from "./types";
|
|
|
+export * from "./constants";
|