|
@@ -1,5 +1,13 @@
|
|
import { MessageFu } from "@/utils/message";
|
|
import { MessageFu } from "@/utils/message";
|
|
-import { Button, Form, FormInstance, Input, Popconfirm, Radio } from "antd";
|
|
|
|
|
|
+import {
|
|
|
|
+ Button,
|
|
|
|
+ Form,
|
|
|
|
+ FormInstance,
|
|
|
|
+ Input,
|
|
|
|
+ Popconfirm,
|
|
|
|
+ Radio,
|
|
|
|
+ Select,
|
|
|
|
+} from "antd";
|
|
import React, {
|
|
import React, {
|
|
useCallback,
|
|
useCallback,
|
|
useEffect,
|
|
useEffect,
|
|
@@ -34,20 +42,21 @@ import { ReactSortable } from "react-sortablejs";
|
|
type Props = {
|
|
type Props = {
|
|
id: number;
|
|
id: number;
|
|
closeMoalFu: (txt: string) => void;
|
|
closeMoalFu: (txt: string) => void;
|
|
|
|
+ tableType: "img" | "video";
|
|
};
|
|
};
|
|
|
|
|
|
-function WallAdd({ id, closeMoalFu }: Props) {
|
|
|
|
|
|
+function WallAdd({ id, closeMoalFu, tableType }: Props) {
|
|
const getInfoFu = useCallback(async (id: number) => {
|
|
const getInfoFu = useCallback(async (id: number) => {
|
|
const res = await getWallDetailAPI(id);
|
|
const res = await getWallDetailAPI(id);
|
|
- FormBoxRef.current?.setFieldsValue({ name: res.data.entity.name });
|
|
|
|
- setImgNum(Number(res.data.entity.layout) as 1 | 2);
|
|
|
|
-
|
|
|
|
|
|
+ FormBoxRef.current?.setFieldsValue({
|
|
|
|
+ name: res.data.entity.name,
|
|
|
|
+ display: res.data.entity.display,
|
|
|
|
+ });
|
|
setTopType(res.data.entity.type);
|
|
setTopType(res.data.entity.type);
|
|
|
|
|
|
if (res.data.entity.type === "img") {
|
|
if (res.data.entity.type === "img") {
|
|
const imgListRes = res.data.file;
|
|
const imgListRes = res.data.file;
|
|
setImgList(imgListRes);
|
|
setImgList(imgListRes);
|
|
- imgListRef.current = imgListRes;
|
|
|
|
} else setVideoFile(res.data.file[0]);
|
|
} else setVideoFile(res.data.file[0]);
|
|
|
|
|
|
// 设置封面图回显
|
|
// 设置封面图回显
|
|
@@ -56,7 +65,11 @@ function WallAdd({ id, closeMoalFu }: Props) {
|
|
|
|
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
if (id > 0) getInfoFu(id);
|
|
if (id > 0) getInfoFu(id);
|
|
- }, [getInfoFu, id]);
|
|
|
|
|
|
+ else {
|
|
|
|
+ setTopType(tableType);
|
|
|
|
+ FormBoxRef.current?.setFieldsValue({ display: 1 });
|
|
|
|
+ }
|
|
|
|
+ }, [getInfoFu, id, tableType]);
|
|
|
|
|
|
// 类型的选择
|
|
// 类型的选择
|
|
const [topType, setTopType] = useState<"img" | "video">("img");
|
|
const [topType, setTopType] = useState<"img" | "video">("img");
|
|
@@ -77,32 +90,17 @@ function WallAdd({ id, closeMoalFu }: Props) {
|
|
const myInput2 = useRef<HTMLInputElement>(null);
|
|
const myInput2 = useRef<HTMLInputElement>(null);
|
|
const [cover, setCover] = useState("");
|
|
const [cover, setCover] = useState("");
|
|
|
|
|
|
- // 版式的选择
|
|
|
|
- const [imgNum, setImgNum] = useState<1 | 2>(1);
|
|
|
|
-
|
|
|
|
// 上传图片的校验
|
|
// 上传图片的校验
|
|
const [imgCheck, setImgCheck] = useState(false);
|
|
const [imgCheck, setImgCheck] = useState(false);
|
|
|
|
|
|
- // 上传图片的全部数据(最多8张来进行切割)
|
|
|
|
- const imgListRef = useRef<ImgListType[]>([]);
|
|
|
|
-
|
|
|
|
// 在页面展示的图片
|
|
// 在页面展示的图片
|
|
const [imgList, setImgList] = useState<ImgListType[]>([]);
|
|
const [imgList, setImgList] = useState<ImgListType[]>([]);
|
|
|
|
|
|
- // 版式的选择改变,切割数组
|
|
|
|
- useEffect(() => {
|
|
|
|
- if (imgListRef.current.length) {
|
|
|
|
- const newData = imgListRef.current.slice(0, imgNum);
|
|
|
|
- setImgList(newData);
|
|
|
|
- }
|
|
|
|
- }, [imgNum]);
|
|
|
|
-
|
|
|
|
// 删除某一张图片
|
|
// 删除某一张图片
|
|
const delImgListFu = useCallback(
|
|
const delImgListFu = useCallback(
|
|
(id: number) => {
|
|
(id: number) => {
|
|
const newItems = imgList.filter((v) => v.id !== id);
|
|
const newItems = imgList.filter((v) => v.id !== id);
|
|
setImgList(newItems);
|
|
setImgList(newItems);
|
|
- imgListRef.current = imgListRef.current.filter((v) => v.id !== id);
|
|
|
|
},
|
|
},
|
|
[imgList]
|
|
[imgList]
|
|
);
|
|
);
|
|
@@ -111,12 +109,12 @@ function WallAdd({ id, closeMoalFu }: Props) {
|
|
const btnOkCheck = useMemo(() => {
|
|
const btnOkCheck = useMemo(() => {
|
|
let flag = false;
|
|
let flag = false;
|
|
if (topType === "img") {
|
|
if (topType === "img") {
|
|
- if (imgList.length < imgNum) flag = true;
|
|
|
|
|
|
+ if (imgList.length <= 0) flag = true;
|
|
} else {
|
|
} else {
|
|
if (!videoFile.filePath) flag = true;
|
|
if (!videoFile.filePath) flag = true;
|
|
}
|
|
}
|
|
return flag;
|
|
return flag;
|
|
- }, [imgList.length, imgNum, topType, videoFile.filePath]);
|
|
|
|
|
|
+ }, [imgList.length, topType, videoFile.filePath]);
|
|
|
|
|
|
// 没有通过校验
|
|
// 没有通过校验
|
|
const onFinishFailed = useCallback(() => {
|
|
const onFinishFailed = useCallback(() => {
|
|
@@ -166,7 +164,6 @@ function WallAdd({ id, closeMoalFu }: Props) {
|
|
MessageFu.success("上传成功!");
|
|
MessageFu.success("上传成功!");
|
|
if (topType === "img") {
|
|
if (topType === "img") {
|
|
setImgList([...imgList, res.data]);
|
|
setImgList([...imgList, res.data]);
|
|
- imgListRef.current.unshift(res.data);
|
|
|
|
} else setVideoFile(res.data);
|
|
} else setVideoFile(res.data);
|
|
}
|
|
}
|
|
fileDomInitialFu();
|
|
fileDomInitialFu();
|
|
@@ -219,11 +216,11 @@ function WallAdd({ id, closeMoalFu }: Props) {
|
|
|
|
|
|
// 通过校验点击确定
|
|
// 通过校验点击确定
|
|
const onFinish = useCallback(
|
|
const onFinish = useCallback(
|
|
- async (value: { name: string }) => {
|
|
|
|
|
|
+ async (value: { name: string; display: 1 | 0 }) => {
|
|
console.log("通过校验,点击确定");
|
|
console.log("通过校验,点击确定");
|
|
setImgCheck(true);
|
|
setImgCheck(true);
|
|
|
|
|
|
- if (topType === "img" && imgList.length < imgNum) return;
|
|
|
|
|
|
+ if (topType === "img" && imgList.length <= 0) return;
|
|
if (topType === "video" && !videoFile.filePath) return;
|
|
if (topType === "video" && !videoFile.filePath) return;
|
|
|
|
|
|
if (cover === "") return;
|
|
if (cover === "") return;
|
|
@@ -238,8 +235,9 @@ function WallAdd({ id, closeMoalFu }: Props) {
|
|
fileIds,
|
|
fileIds,
|
|
name: value.name,
|
|
name: value.name,
|
|
type: topType,
|
|
type: topType,
|
|
- layout: imgNum,
|
|
|
|
|
|
+ layout: imgList.length,
|
|
thumb: cover,
|
|
thumb: cover,
|
|
|
|
+ display: value.display,
|
|
};
|
|
};
|
|
|
|
|
|
const res = await setWallSave(obj);
|
|
const res = await setWallSave(obj);
|
|
@@ -249,16 +247,7 @@ function WallAdd({ id, closeMoalFu }: Props) {
|
|
closeMoalFu(id > 0 ? "编辑" : "新增");
|
|
closeMoalFu(id > 0 ? "编辑" : "新增");
|
|
}
|
|
}
|
|
},
|
|
},
|
|
- [
|
|
|
|
- closeMoalFu,
|
|
|
|
- cover,
|
|
|
|
- id,
|
|
|
|
- imgList,
|
|
|
|
- imgNum,
|
|
|
|
- topType,
|
|
|
|
- videoFile.filePath,
|
|
|
|
- videoFile.id,
|
|
|
|
- ]
|
|
|
|
|
|
+ [closeMoalFu, cover, id, imgList, topType, videoFile.filePath, videoFile.id]
|
|
);
|
|
);
|
|
|
|
|
|
// 点击预览效果
|
|
// 点击预览效果
|
|
@@ -275,7 +264,7 @@ function WallAdd({ id, closeMoalFu }: Props) {
|
|
onFinishFailed={onFinishFailed}
|
|
onFinishFailed={onFinishFailed}
|
|
autoComplete="off"
|
|
autoComplete="off"
|
|
>
|
|
>
|
|
- <div className="myformBox">
|
|
|
|
|
|
+ <div className="myformBox" hidden>
|
|
<div className="label">
|
|
<div className="label">
|
|
<span>*</span> 类型:
|
|
<span>*</span> 类型:
|
|
</div>
|
|
</div>
|
|
@@ -289,11 +278,11 @@ function WallAdd({ id, closeMoalFu }: Props) {
|
|
</Radio.Group>
|
|
</Radio.Group>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
-
|
|
|
|
|
|
+ <br />
|
|
<Form.Item
|
|
<Form.Item
|
|
label="名称"
|
|
label="名称"
|
|
name="name"
|
|
name="name"
|
|
- // rules={[{ required: true, message: "请输入名称!" }]}
|
|
|
|
|
|
+ rules={[{ required: true, message: "请输入名称!" }]}
|
|
getValueFromEvent={(e) => e.target.value.replace(/\s+/g, "")}
|
|
getValueFromEvent={(e) => e.target.value.replace(/\s+/g, "")}
|
|
>
|
|
>
|
|
<Input maxLength={25} showCount placeholder="请输入内容" />
|
|
<Input maxLength={25} showCount placeholder="请输入内容" />
|
|
@@ -381,29 +370,16 @@ function WallAdd({ id, closeMoalFu }: Props) {
|
|
|
|
|
|
{topType === "img" ? (
|
|
{topType === "img" ? (
|
|
<>
|
|
<>
|
|
- <div className="myformBox">
|
|
|
|
- <div className="label">
|
|
|
|
- <span>*</span> 版式:
|
|
|
|
- </div>
|
|
|
|
- <div className="myformBoxR">
|
|
|
|
- <Radio.Group
|
|
|
|
- onChange={(e) => setImgNum(e.target.value)}
|
|
|
|
- value={imgNum}
|
|
|
|
- >
|
|
|
|
- <Radio value={1}>1</Radio>
|
|
|
|
- <Radio value={2}>2</Radio>
|
|
|
|
- </Radio.Group>
|
|
|
|
- </div>
|
|
|
|
- </div>
|
|
|
|
-
|
|
|
|
{/* 图片上传 */}
|
|
{/* 图片上传 */}
|
|
<div className="myformBox myformBox0">
|
|
<div className="myformBox myformBox0">
|
|
- <div className="label"></div>
|
|
|
|
|
|
+ <div className="label">
|
|
|
|
+ <span>*</span> 图片:
|
|
|
|
+ </div>
|
|
<div className="myformBoxR">
|
|
<div className="myformBoxR">
|
|
<div className="fileBoxRow_r">
|
|
<div className="fileBoxRow_r">
|
|
<div className="upImgBox">
|
|
<div className="upImgBox">
|
|
<div
|
|
<div
|
|
- hidden={imgList.length >= imgNum}
|
|
|
|
|
|
+ hidden={imgList.length >= 9}
|
|
className="fileBoxRow_up"
|
|
className="fileBoxRow_up"
|
|
onClick={() => myInput.current?.click()}
|
|
onClick={() => myInput.current?.click()}
|
|
>
|
|
>
|
|
@@ -470,7 +446,7 @@ function WallAdd({ id, closeMoalFu }: Props) {
|
|
</>
|
|
</>
|
|
) : null}
|
|
) : null}
|
|
{/* 建议尺寸:{12960 / imgNum}*1920 */}
|
|
{/* 建议尺寸:{12960 / imgNum}*1920 */}
|
|
- 支持png、jpg和jpeg的图片格式;最大支持30M。
|
|
|
|
|
|
+ 支持png、jpg和jpeg的图片格式;最大支持30M。最多支持9张。
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
@@ -557,9 +533,24 @@ function WallAdd({ id, closeMoalFu }: Props) {
|
|
btnOkCheck && imgCheck ? "noUpThumbAc" : ""
|
|
btnOkCheck && imgCheck ? "noUpThumbAc" : ""
|
|
)}
|
|
)}
|
|
>
|
|
>
|
|
- {topType === "img" ? `请上传 ${imgNum} 张图片!` : "请上传附件"}
|
|
|
|
|
|
+ {topType === "img" ? `请上传图片!` : "请上传附件"}
|
|
</div>
|
|
</div>
|
|
|
|
|
|
|
|
+ <Form.Item
|
|
|
|
+ label="展示"
|
|
|
|
+ name="display"
|
|
|
|
+ rules={[{ required: true, message: "请选择展示!" }]}
|
|
|
|
+ >
|
|
|
|
+ <Select
|
|
|
|
+ placeholder="请选择"
|
|
|
|
+ style={{ width: 84 }}
|
|
|
|
+ options={[
|
|
|
|
+ { value: 1, label: "启用" },
|
|
|
|
+ { value: 0, label: "停用" },
|
|
|
|
+ ]}
|
|
|
|
+ />
|
|
|
|
+ </Form.Item>
|
|
|
|
+
|
|
{/* 确定和取消按钮 */}
|
|
{/* 确定和取消按钮 */}
|
|
<br />
|
|
<br />
|
|
<Form.Item wrapperCol={{ offset: 9, span: 16 }}>
|
|
<Form.Item wrapperCol={{ offset: 9, span: 16 }}>
|