|
@@ -375,6 +375,10 @@ function ObjectAdd({ id, colsePage, editId, dirCode, upInfoAPIFu }: Props) {
|
|
|
];
|
|
|
}, []);
|
|
|
|
|
|
+ // 上传附件的进度条
|
|
|
+ const UpAsyncLodingDom: any = document.querySelector("#UpAsyncLoding");
|
|
|
+ const progressDom: any = document.querySelector("#progress");
|
|
|
+
|
|
|
// 上传封面
|
|
|
const myInput = useRef<HTMLInputElement>(null);
|
|
|
const handeUpPhoto = async (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
@@ -398,11 +402,16 @@ function ObjectAdd({ id, colsePage, editId, dirCode, upInfoAPIFu }: Props) {
|
|
|
fd.append("type", "thumb");
|
|
|
fd.append("dirCode", dirCode);
|
|
|
fd.append("file", filesInfo);
|
|
|
+
|
|
|
+ e.target.value = "";
|
|
|
+
|
|
|
const res: any = await object1AddUpFileAPI(fd);
|
|
|
if (res.code === 0) {
|
|
|
message.success("上传成功!");
|
|
|
setCover(res.data.filePath);
|
|
|
}
|
|
|
+ UpAsyncLodingDom.style.opacity = 0;
|
|
|
+ progressDom.style.width = "0%";
|
|
|
}
|
|
|
};
|
|
|
|
|
@@ -423,15 +432,41 @@ function ObjectAdd({ id, colsePage, editId, dirCode, upInfoAPIFu }: Props) {
|
|
|
// 拿到files信息
|
|
|
const filesInfo = e.target.files[0];
|
|
|
|
|
|
+ let type = [] as string[];
|
|
|
+
|
|
|
+ let tit = "";
|
|
|
+
|
|
|
+ if (
|
|
|
+ fileSelect === "img" ||
|
|
|
+ fileSelect === "video" ||
|
|
|
+ fileSelect === "audio"
|
|
|
+ ) {
|
|
|
+ if (fileSelect === "img") {
|
|
|
+ type = ["image/jpeg", "image/png", "image/gif"];
|
|
|
+ tit = "只支持jpg、png、gif格式!";
|
|
|
+ } else if (fileSelect === "video") {
|
|
|
+ type = ["video/mp4"];
|
|
|
+ tit = "只支持mp4格式!";
|
|
|
+ } else if (fileSelect === "audio") {
|
|
|
+ type = ["audio/mpeg"];
|
|
|
+ tit = "只支持mp3格式!";
|
|
|
+ }
|
|
|
+ // 校验格式
|
|
|
+ if (!type.includes(filesInfo.type)) {
|
|
|
+ e.target.value = "";
|
|
|
+ return message.warning(tit);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
// 创建FormData对象
|
|
|
const fd = new FormData();
|
|
|
// 把files添加进FormData对象(‘photo’为后端需要的字段)
|
|
|
fd.append("type", fileSelect);
|
|
|
fd.append("dirCode", dirCode);
|
|
|
fd.append("file", filesInfo);
|
|
|
+ e.target.value = "";
|
|
|
|
|
|
const res: any = await object1AddUpFileAPI(fd);
|
|
|
- e.target.value = "";
|
|
|
if (res.code === 0) {
|
|
|
message.success("上传成功!");
|
|
|
if (upFileFlagRef.current) {
|
|
@@ -466,9 +501,18 @@ function ObjectAdd({ id, colsePage, editId, dirCode, upInfoAPIFu }: Props) {
|
|
|
dispatch({ type: "login/setFileData", payload: data });
|
|
|
}
|
|
|
}
|
|
|
+ UpAsyncLodingDom.style.opacity = 0;
|
|
|
+ progressDom.style.width = "0%";
|
|
|
}
|
|
|
},
|
|
|
- [dirCode, dispatch, fileSelect, results]
|
|
|
+ [
|
|
|
+ UpAsyncLodingDom.style,
|
|
|
+ dirCode,
|
|
|
+ dispatch,
|
|
|
+ fileSelect,
|
|
|
+ progressDom.style,
|
|
|
+ results,
|
|
|
+ ]
|
|
|
);
|
|
|
|
|
|
return (
|
|
@@ -815,6 +859,18 @@ function ObjectAdd({ id, colsePage, editId, dirCode, upInfoAPIFu }: Props) {
|
|
|
 
|
|
|
<Button onClick={() => upFileFu()}>上传附件</Button>
|
|
|
</div>
|
|
|
+  
|
|
|
+ <div className="fileBoxRowUpTit">
|
|
|
+ {fileSelect === "img" ? (
|
|
|
+ <>支持上传jpg,png,gif格式</>
|
|
|
+ ) : fileSelect === "video" ? (
|
|
|
+ <>支持上传mp4格式</>
|
|
|
+ ) : fileSelect === "audio" ? (
|
|
|
+ <>支持上传mp3格式</>
|
|
|
+ ) : (
|
|
|
+ ""
|
|
|
+ )}
|
|
|
+ </div>
|
|
|
</div>
|
|
|
{/* 表格主体 */}
|
|
|
<div className="addTableBox_table">
|