|
@@ -28,22 +28,38 @@ import {
|
|
|
CloseOutlined,
|
|
|
PlayCircleOutlined,
|
|
|
} from "@ant-design/icons";
|
|
|
-import { goodsUploadAPI } from "@/store/action/B2Goods";
|
|
|
+import {
|
|
|
+ getGoodsInfoByIdAPI,
|
|
|
+ getGoodsSaveAPI,
|
|
|
+ goodsUploadAPI,
|
|
|
+ setGoodsImgBoderAPI,
|
|
|
+} from "@/store/action/B2Goods";
|
|
|
import { baseURL } from "@/utils/http";
|
|
|
+import { FileListType, GoodsTableType } from "@/types";
|
|
|
+
|
|
|
|
|
|
type Props = {
|
|
|
id: number;
|
|
|
closeMoalFu: () => void;
|
|
|
- upListFu: () => void;
|
|
|
+ addListFu: () => void;
|
|
|
+ editListFu: () => void;
|
|
|
};
|
|
|
|
|
|
// 上传附件的进度条
|
|
|
const UpAsyncLodingDom: any = document.querySelector("#UpAsyncLoding");
|
|
|
const progressDom: any = document.querySelector("#progress");
|
|
|
|
|
|
-function GoodsAdd({ id, closeMoalFu, upListFu }: Props) {
|
|
|
+function GoodsAdd({ id, closeMoalFu, addListFu, editListFu }: Props) {
|
|
|
const dispatch = useDispatch();
|
|
|
|
|
|
+ // 上传附件的信息
|
|
|
+ const [fileList, setFileList] = useState({
|
|
|
+ model: {} as FileListType,
|
|
|
+ img: [] as FileListType[],
|
|
|
+ audio: {} as FileListType,
|
|
|
+ video: {} as FileListType,
|
|
|
+ });
|
|
|
+
|
|
|
// 表单的ref
|
|
|
const FormBoxRef = useRef<any>({});
|
|
|
|
|
@@ -51,17 +67,37 @@ function GoodsAdd({ id, closeMoalFu, upListFu }: Props) {
|
|
|
const [dirCode, setDirCode] = useState("");
|
|
|
|
|
|
const getInfoInAPIFu = useCallback(async (id: number) => {
|
|
|
- // const res = await getUserInfoByIdAPI(id);
|
|
|
- // FormBoxRef.current.setFieldsValue(res.data);
|
|
|
- console.log("是编辑,在这里发请求拿数据");
|
|
|
- // setDirCode(data.dirCode!);
|
|
|
+ const res = await getGoodsInfoByIdAPI(id);
|
|
|
+ FormBoxRef.current.setFieldsValue(res.data.entity);
|
|
|
+ setCover(res.data.entity.thumb);
|
|
|
+
|
|
|
+ setTypeCheck(res.data.entity.type.split(","));
|
|
|
+
|
|
|
+ const data: FileListType[] = res.data.file;
|
|
|
+ const obj = {
|
|
|
+ model: {} as FileListType,
|
|
|
+ img: [] as FileListType[],
|
|
|
+ audio: {} as FileListType,
|
|
|
+ video: {} as FileListType,
|
|
|
+ };
|
|
|
+
|
|
|
+ data.forEach((v) => {
|
|
|
+ if (v.type === "img") obj.img.push(v);
|
|
|
+ else obj[v.type!] = v;
|
|
|
+ });
|
|
|
+ setFileList(obj);
|
|
|
+ setDirCode(res.data.entity.dirCode);
|
|
|
}, []);
|
|
|
|
|
|
useEffect(() => {
|
|
|
if (id > 0) getInfoInAPIFu(id);
|
|
|
else {
|
|
|
setDirCode(Date.now() + "");
|
|
|
- FormBoxRef.current.setFieldsValue({ topic: 3, display: 1, aaaaa: 0 });
|
|
|
+ FormBoxRef.current.setFieldsValue({
|
|
|
+ topic: "不展示",
|
|
|
+ display: 1,
|
|
|
+ isBarrage: 0,
|
|
|
+ });
|
|
|
}
|
|
|
}, [getInfoInAPIFu, id]);
|
|
|
|
|
@@ -124,41 +160,22 @@ function GoodsAdd({ id, closeMoalFu, upListFu }: Props) {
|
|
|
];
|
|
|
}, []);
|
|
|
|
|
|
- type FileListType = {
|
|
|
- fileName?: string;
|
|
|
- filePath?: string;
|
|
|
- id?: number;
|
|
|
- done?: boolean;
|
|
|
- };
|
|
|
-
|
|
|
- // 上传附件的信息
|
|
|
- const [fileList, setFileList] = useState({
|
|
|
- model: {} as FileListType,
|
|
|
- img: [
|
|
|
- {
|
|
|
- id: 1,
|
|
|
- fileName: "xxx",
|
|
|
- filePath: "/wall/img/20230202_12193909316.jpg",
|
|
|
- },
|
|
|
- { id: 2, fileName: "xxx", filePath: "/wall/img/20230209_1519270201.gif" },
|
|
|
- ] as FileListType[],
|
|
|
- audio: {} as FileListType,
|
|
|
- video: {} as FileListType,
|
|
|
- });
|
|
|
-
|
|
|
// 上传附件图片的有无边框的选择
|
|
|
const upImgDoneFu = useCallback(
|
|
|
- (val: boolean, id: number) => {
|
|
|
- const newData = {
|
|
|
- ...fileList,
|
|
|
- img: fileList.img.map((v) => {
|
|
|
- return {
|
|
|
- ...v,
|
|
|
- done: v.id === id ? val : v.done,
|
|
|
- };
|
|
|
- }),
|
|
|
- };
|
|
|
- setFileList(newData);
|
|
|
+ async (val: boolean, id: number) => {
|
|
|
+ const res = await setGoodsImgBoderAPI(id, val ? 1 : 0);
|
|
|
+ if (res.code === 0) {
|
|
|
+ const newData = {
|
|
|
+ ...fileList,
|
|
|
+ img: fileList.img.map((v) => {
|
|
|
+ return {
|
|
|
+ ...v,
|
|
|
+ isFrame: v.id === id ? val : v.isFrame,
|
|
|
+ };
|
|
|
+ }),
|
|
|
+ };
|
|
|
+ setFileList(newData);
|
|
|
+ }
|
|
|
},
|
|
|
[fileList]
|
|
|
);
|
|
@@ -193,7 +210,7 @@ function GoodsAdd({ id, closeMoalFu, upListFu }: Props) {
|
|
|
|
|
|
// 上传附件的处理函数
|
|
|
const handeUpPhoto2 = useCallback(
|
|
|
- (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
|
+ async (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
|
if (e.target.files) {
|
|
|
// 拿到files信息
|
|
|
const filesInfo = e.target.files[0];
|
|
@@ -247,19 +264,19 @@ function GoodsAdd({ id, closeMoalFu, upListFu }: Props) {
|
|
|
|
|
|
e.target.value = "";
|
|
|
|
|
|
- // const res: any = await goodsUploadAPI(fd);
|
|
|
- // if (res.code === 0) {
|
|
|
- // MessageFu.success("上传成功!");
|
|
|
- // if (fileOneType === "img")
|
|
|
- // setFileList({ ...fileList, img: [res.data, ...fileList.img] });
|
|
|
- // else setFileList({ ...fileList, [fileOneType]: res.data });
|
|
|
+ const res: any = await goodsUploadAPI(fd);
|
|
|
|
|
|
- // }
|
|
|
+ if (res.code === 0) {
|
|
|
+ MessageFu.success("上传成功!");
|
|
|
+ if (fileOneType === "img")
|
|
|
+ setFileList({ ...fileList, img: [res.data, ...fileList.img] });
|
|
|
+ else setFileList({ ...fileList, [fileOneType]: res.data });
|
|
|
+ }
|
|
|
UpAsyncLodingDom.style.opacity = 0;
|
|
|
progressDom.style.width = "0%";
|
|
|
}
|
|
|
},
|
|
|
- [dirCode, fileOneType]
|
|
|
+ [dirCode, fileList, fileOneType]
|
|
|
);
|
|
|
|
|
|
// 附件图片的拖动
|
|
@@ -302,13 +319,53 @@ function GoodsAdd({ id, closeMoalFu, upListFu }: Props) {
|
|
|
}, []);
|
|
|
|
|
|
// 通过校验点击确定
|
|
|
- const onFinish = useCallback(() => {
|
|
|
- console.log("通过校验,点击确定");
|
|
|
- setCoverCheck(true);
|
|
|
- setTypeOk(true);
|
|
|
- if (typeCheck.length === 0) return MessageFu.warning("有表单不符号规则!");
|
|
|
- if (cover === "") return MessageFu.warning("有表单不符号规则!");
|
|
|
- }, [cover, typeCheck.length]);
|
|
|
+ const onFinish = useCallback(
|
|
|
+ async (value: GoodsTableType) => {
|
|
|
+ console.log("通过校验,点击确定");
|
|
|
+ setCoverCheck(true);
|
|
|
+ setTypeOk(true);
|
|
|
+ if (typeCheck.length === 0 || cover === "" || fileCheckFu)
|
|
|
+ return MessageFu.warning("有表单不符号规则!");
|
|
|
+
|
|
|
+ const fileIds = [];
|
|
|
+ if (fileList.model.id) fileIds.push(fileList.model.id);
|
|
|
+ if (fileList.audio.id) fileIds.push(fileList.audio.id);
|
|
|
+ if (fileList.video.id) fileIds.push(fileList.video.id);
|
|
|
+ fileList.img.forEach((v) => {
|
|
|
+ if (v.id) fileIds.push(v.id);
|
|
|
+ });
|
|
|
+
|
|
|
+ const obj = {
|
|
|
+ ...value,
|
|
|
+ id: id > 0 ? id : null,
|
|
|
+ dirCode,
|
|
|
+ fileIds: fileIds.join(","),
|
|
|
+ thumb: cover,
|
|
|
+ type: typeCheck.join(","),
|
|
|
+ } as GoodsTableType;
|
|
|
+ const res = await getGoodsSaveAPI(obj);
|
|
|
+ if (res.code === 0) {
|
|
|
+ MessageFu.success(id > 0 ? "编辑成功!" : "新增成功!");
|
|
|
+ closeMoalFu();
|
|
|
+ if (id > 0) editListFu();
|
|
|
+ else addListFu();
|
|
|
+ }
|
|
|
+ },
|
|
|
+ [
|
|
|
+ typeCheck,
|
|
|
+ cover,
|
|
|
+ fileCheckFu,
|
|
|
+ fileList.model.id,
|
|
|
+ fileList.audio.id,
|
|
|
+ fileList.video.id,
|
|
|
+ fileList.img,
|
|
|
+ id,
|
|
|
+ dirCode,
|
|
|
+ closeMoalFu,
|
|
|
+ editListFu,
|
|
|
+ addListFu,
|
|
|
+ ]
|
|
|
+ );
|
|
|
|
|
|
return (
|
|
|
<div className={styles.GoodsAdd}>
|
|
@@ -395,9 +452,9 @@ function GoodsAdd({ id, closeMoalFu, upListFu }: Props) {
|
|
|
placeholder="请选择"
|
|
|
style={{ width: 400 }}
|
|
|
options={[
|
|
|
- { value: 1, label: "战争" },
|
|
|
- { value: 2, label: "生活" },
|
|
|
- { value: 3, label: "不展示" },
|
|
|
+ { value: "战争", label: "战争" },
|
|
|
+ { value: "生活", label: "生活" },
|
|
|
+ { value: "不展示", label: "不展示" },
|
|
|
]}
|
|
|
/>
|
|
|
</Form.Item>
|
|
@@ -577,7 +634,7 @@ function GoodsAdd({ id, closeMoalFu, upListFu }: Props) {
|
|
|
<Switch
|
|
|
checkedChildren="有"
|
|
|
unCheckedChildren="无"
|
|
|
- checked={v.done}
|
|
|
+ checked={v.isFrame}
|
|
|
onChange={(val) => upImgDoneFu(val, v.id!)}
|
|
|
/>
|
|
|
</div>
|
|
@@ -611,7 +668,7 @@ function GoodsAdd({ id, closeMoalFu, upListFu }: Props) {
|
|
|
<br />
|
|
|
</>
|
|
|
) : null}
|
|
|
- 支持png、jpg、gif和jpeg的图片格式;最大支持20M;最多支持9张。
|
|
|
+ 支持png、jpg、gif和jpeg的图片格式;最大支持20M;最多支持30张。
|
|
|
</div>
|
|
|
</div>
|
|
|
</>
|
|
@@ -674,7 +731,7 @@ function GoodsAdd({ id, closeMoalFu, upListFu }: Props) {
|
|
|
</div>
|
|
|
{fileList.video.id ? (
|
|
|
<div className="fileInfo">
|
|
|
- <div className="upSuccTxt">{fileList.video.filePath}</div>
|
|
|
+ <div className="upSuccTxt">{fileList.video.fileName}</div>
|
|
|
<div
|
|
|
className="clearCover"
|
|
|
hidden={!fileList.video.filePath}
|
|
@@ -741,7 +798,7 @@ function GoodsAdd({ id, closeMoalFu, upListFu }: Props) {
|
|
|
|
|
|
<Form.Item
|
|
|
label="弹幕留言"
|
|
|
- name="aaaaa"
|
|
|
+ name="isBarrage"
|
|
|
rules={[{ required: true, message: "请选择弹幕留言!" }]}
|
|
|
>
|
|
|
<Select
|