|
|
@@ -17,6 +17,7 @@ import {
|
|
|
getWallDetailAPI,
|
|
|
wallUploadAPI,
|
|
|
setWallSave,
|
|
|
+ wallUploadCoverAPI,
|
|
|
} from "@/store/action/A2Wall";
|
|
|
import { fileDomInitialFu } from "@/utils/domShow";
|
|
|
import store from "@/store";
|
|
|
@@ -41,13 +42,16 @@ function WallAdd({ id, closeMoalFu }: Props) {
|
|
|
FormBoxRef.current?.setFieldsValue({ name: res.data.entity.name });
|
|
|
setImgNum(Number(res.data.entity.layout) as 1 | 2);
|
|
|
|
|
|
- setTopType(res.data.entity.type)
|
|
|
+ setTopType(res.data.entity.type);
|
|
|
|
|
|
if (res.data.entity.type === "img") {
|
|
|
const imgListRes = res.data.file;
|
|
|
setImgList(imgListRes);
|
|
|
imgListRef.current = imgListRes;
|
|
|
} else setVideoFile(res.data.file[0]);
|
|
|
+
|
|
|
+ // 设置封面图回显
|
|
|
+ setCover(res.data.entity.thumb);
|
|
|
}, []);
|
|
|
|
|
|
useEffect(() => {
|
|
|
@@ -66,9 +70,13 @@ function WallAdd({ id, closeMoalFu }: Props) {
|
|
|
|
|
|
// 表单的ref
|
|
|
const FormBoxRef = useRef<FormInstance>(null);
|
|
|
- // 上传封面图的ref
|
|
|
+ // 上传 版式 和 视频 的ref
|
|
|
const myInput = useRef<HTMLInputElement>(null);
|
|
|
|
|
|
+ // 上传 封面图 的ref
|
|
|
+ const myInput2 = useRef<HTMLInputElement>(null);
|
|
|
+ const [cover, setCover] = useState("");
|
|
|
+
|
|
|
// 版式的选择
|
|
|
const [imgNum, setImgNum] = useState<1 | 2>(1);
|
|
|
|
|
|
@@ -115,7 +123,7 @@ function WallAdd({ id, closeMoalFu }: Props) {
|
|
|
setImgCheck(true);
|
|
|
}, []);
|
|
|
|
|
|
- // 上传封面图
|
|
|
+ // 上传版式图或者视频
|
|
|
const handeUpPhoto = useCallback(
|
|
|
async (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
|
if (e.target.files) {
|
|
|
@@ -170,6 +178,45 @@ function WallAdd({ id, closeMoalFu }: Props) {
|
|
|
[imgList, topType]
|
|
|
);
|
|
|
|
|
|
+ const handeUpPhoto2 = useCallback(
|
|
|
+ async (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
|
+ if (e.target.files) {
|
|
|
+ // 拿到files信息
|
|
|
+ const filesInfo = e.target.files[0];
|
|
|
+ // 校验格式
|
|
|
+ const type = ["image/jpeg", "image/png"];
|
|
|
+ if (!type.includes(filesInfo.type)) {
|
|
|
+ e.target.value = "";
|
|
|
+ return MessageFu.warning("只支持jpg、png格式!");
|
|
|
+ }
|
|
|
+ // 校验大小
|
|
|
+ if (filesInfo.size > 30 * 1024 * 1024) {
|
|
|
+ e.target.value = "";
|
|
|
+ return MessageFu.warning("最大支持30M!");
|
|
|
+ }
|
|
|
+ // 创建FormData对象
|
|
|
+ const fd = new FormData();
|
|
|
+ // 把files添加进FormData对象(‘photo’为后端需要的字段)
|
|
|
+ fd.append("type", "thumb");
|
|
|
+ fd.append("file", filesInfo);
|
|
|
+
|
|
|
+ e.target.value = "";
|
|
|
+
|
|
|
+ try {
|
|
|
+ const res = await wallUploadCoverAPI(fd);
|
|
|
+ if (res.code === 0) {
|
|
|
+ MessageFu.success("上传成功!");
|
|
|
+ setCover(res.data.filePath);
|
|
|
+ }
|
|
|
+ fileDomInitialFu();
|
|
|
+ } catch (error) {
|
|
|
+ fileDomInitialFu();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ []
|
|
|
+ );
|
|
|
+
|
|
|
// 通过校验点击确定
|
|
|
const onFinish = useCallback(
|
|
|
async (value: { name: string }) => {
|
|
|
@@ -179,6 +226,8 @@ function WallAdd({ id, closeMoalFu }: Props) {
|
|
|
if (topType === "img" && imgList.length < imgNum) return;
|
|
|
if (topType === "video" && !videoFile.filePath) return;
|
|
|
|
|
|
+ if (cover === "") return;
|
|
|
+
|
|
|
const fileIds =
|
|
|
topType === "img"
|
|
|
? imgList.map((v) => v.id).join(",")
|
|
|
@@ -190,6 +239,7 @@ function WallAdd({ id, closeMoalFu }: Props) {
|
|
|
name: value.name,
|
|
|
type: topType,
|
|
|
layout: imgNum,
|
|
|
+ thumb: cover,
|
|
|
};
|
|
|
|
|
|
const res = await setWallSave(obj);
|
|
|
@@ -201,6 +251,7 @@ function WallAdd({ id, closeMoalFu }: Props) {
|
|
|
},
|
|
|
[
|
|
|
closeMoalFu,
|
|
|
+ cover,
|
|
|
id,
|
|
|
imgList,
|
|
|
imgNum,
|
|
|
@@ -242,12 +293,84 @@ function WallAdd({ id, closeMoalFu }: Props) {
|
|
|
<Form.Item
|
|
|
label="名称"
|
|
|
name="name"
|
|
|
- rules={[{ required: true, message: "请输入名称!" }]}
|
|
|
+ // rules={[{ required: true, message: "请输入名称!" }]}
|
|
|
getValueFromEvent={(e) => e.target.value.replace(/\s+/g, "")}
|
|
|
>
|
|
|
<Input maxLength={25} showCount placeholder="请输入内容" />
|
|
|
</Form.Item>
|
|
|
+ {/* 封面图上传 */}
|
|
|
+ <div className="myformBox myformBoxOne">
|
|
|
+ <div className="label">
|
|
|
+ <span>*</span> 封面图:
|
|
|
+ </div>
|
|
|
+ <div className="fileBoxRow_r">
|
|
|
+ <div
|
|
|
+ hidden={cover !== ""}
|
|
|
+ className="fileBoxRow_up"
|
|
|
+ onClick={() => myInput2.current?.click()}
|
|
|
+ >
|
|
|
+ <PlusOutlined />
|
|
|
+ </div>
|
|
|
+ <div className="fileBoxRow_r_img" hidden={cover === ""}>
|
|
|
+ {cover ? (
|
|
|
+ <ImageLazy width={100} height={200} src={cover} noLook />
|
|
|
+ ) : null}
|
|
|
+
|
|
|
+ <div className="clearCover2">
|
|
|
+ {/* 封面图预览 删除 下载 */}
|
|
|
+ <div className="clearCover2DelBox">
|
|
|
+ <Popconfirm
|
|
|
+ title="删除后无法恢复,是否删除?"
|
|
|
+ okText="删除"
|
|
|
+ cancelText="取消"
|
|
|
+ onConfirm={() => setCover("")}
|
|
|
+ >
|
|
|
+ <CloseOutlined />
|
|
|
+ </Popconfirm>
|
|
|
+ </div>
|
|
|
|
|
|
+ <div className="clearCover2DLBox">
|
|
|
+ <EyeOutlined
|
|
|
+ onClick={() =>
|
|
|
+ store.dispatch({
|
|
|
+ type: "layout/lookBigImg",
|
|
|
+ payload: { url: baseURL + cover, show: true },
|
|
|
+ })
|
|
|
+ }
|
|
|
+ />
|
|
|
+ <a
|
|
|
+ href={baseURL + cover}
|
|
|
+ download
|
|
|
+ target="_blank"
|
|
|
+ rel="noreferrer"
|
|
|
+ >
|
|
|
+ <DownloadOutlined />
|
|
|
+ </a>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ <div className="fileBoxRow_r_tit">
|
|
|
+ 支持png、jpg和jpeg的图片格式;最大支持30M。建议上传1111X1111尺寸。
|
|
|
+ <br />
|
|
|
+ <div
|
|
|
+ className={classNames(
|
|
|
+ "noUpThumb",
|
|
|
+ !cover && imgCheck ? "noUpThumbAc" : ""
|
|
|
+ )}
|
|
|
+ >
|
|
|
+ 请上传封面图!
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <input
|
|
|
+ id="upInput"
|
|
|
+ type="file"
|
|
|
+ accept=".png,.jpg,.jpeg"
|
|
|
+ ref={myInput2}
|
|
|
+ onChange={(e) => handeUpPhoto2(e)}
|
|
|
+ />
|
|
|
<input
|
|
|
id="upInput"
|
|
|
type="file"
|