import React, { useCallback, useEffect, useRef, useState } from "react"; import styles from "./index.module.scss"; import { Button, Form, FormInstance, Input, Select } from "antd"; import ZupOne from "@/components/ZupOne"; import { A1_APIgetInfo, A1_APIsave } from "@/store/action/A1video"; import { MessageFu } from "@/utils/message"; import MyPopconfirm from "@/components/MyPopconfirm"; type Props = { addId: number; closeFu: () => void; addTableFu: () => void; type: "video" | "poster"; }; function A1add({ addId, closeFu, addTableFu, type }: Props) { // 表单的ref const FormBoxRef = useRef(null); // 没有通过校验 const onFinishFailed = useCallback(() => { setFileCheck(true); }, []); // 通过校验点击确定 const onFinish = useCallback( async (value: any) => { setFileCheck(true); const coverUrl1 = ZupOneRef1.current?.fileComFileResFu(); // 没有传 封面图 if (!coverUrl1.filePath) return; let coverUrl2 = { filePath: "", fileName: "" }; if (type === "video") { coverUrl2 = ZupOneRef2.current?.fileComFileResFu(); // 没有传 视频 if (!coverUrl2.filePath) return; } const obj = { ...value, id: addId > 0 ? addId : null, thumb: coverUrl1.filePath, type, filePath: type === "video" ? coverUrl2.filePath : null, fileName: type === "video" ? coverUrl2.fileName : null, }; const res = await A1_APIsave(obj); if (res.code === 0) { MessageFu.success(addId > 0 ? "编辑成功!" : "新增成功!"); addTableFu(); closeFu(); } }, [addId, addTableFu, closeFu, type] ); // 附件 是否 已经点击过确定 const [fileCheck, setFileCheck] = useState(false); // 上传附件的ref const ZupOneRef1 = useRef(null); const ZupOneRef2 = useRef(null); // 通过id获取详情 const getInfoFu = useCallback(async (id: number) => { const res = await A1_APIgetInfo(id); if (res.code === 0) { const data = res.data; FormBoxRef.current?.setFieldsValue({ name: data.name, display: data.display, }); ZupOneRef1.current?.setFileComFileFu({ fileName: "", filePath: data.thumb, }); ZupOneRef2.current?.setFileComFileFu({ fileName: data.fileName, filePath: data.filePath, }); } }, []); useEffect(() => { if (addId > 0) { // 编辑 getInfoFu(addId); } else { // 新增 FormBoxRef.current?.setFieldsValue({ display: 1, }); } }, [addId, getInfoFu]); return (
e.target.value.replace(/\s+/g, "")} > {/* 封面 */}
* {type === "video" ? "封面" : "海报"}:
{/* 视频 */} {type === "video" ? (
* 视频:
) : null}