|
@@ -19,56 +19,121 @@ import history from "@/utils/history";
|
|
import React from "react";
|
|
import React from "react";
|
|
import { getTokenFu } from "@/utils/storage";
|
|
import { getTokenFu } from "@/utils/storage";
|
|
import { MessageFu } from "@/utils/message";
|
|
import { MessageFu } from "@/utils/message";
|
|
-import { A1_APIOupFileIds, A1_APIremoveSure } from "@/store/action/A1Project";
|
|
|
|
|
|
+import {
|
|
|
|
+ A1_APIIupBtnOk,
|
|
|
|
+ A1_APIIupIsList,
|
|
|
|
+ A1_APIremoveSure,
|
|
|
|
+} from "@/store/action/A1Project";
|
|
import { authFilesLookFu, urlChangeFu } from "@/utils/authFilesLook";
|
|
import { authFilesLookFu, urlChangeFu } from "@/utils/authFilesLook";
|
|
import { useSelector } from "react-redux";
|
|
import { useSelector } from "react-redux";
|
|
import { RootState } from "@/store";
|
|
import { RootState } from "@/store";
|
|
|
|
+import { domShowFu } from "@/utils/domShow";
|
|
|
|
|
|
const { Dragger } = Upload;
|
|
const { Dragger } = Upload;
|
|
|
|
|
|
-type SelectType = {
|
|
|
|
- id: string;
|
|
|
|
- value: number | undefined;
|
|
|
|
- txt: string;
|
|
|
|
- tit: string;
|
|
|
|
- fileName: string;
|
|
|
|
-};
|
|
|
|
|
|
+// type SelectType = {
|
|
|
|
+// id: number;
|
|
|
|
+// value: number | undefined;
|
|
|
|
+// txt: string;
|
|
|
|
+// tit: string;
|
|
|
|
+// fileName: string;
|
|
|
|
+// resName:string
|
|
|
|
+// };
|
|
|
|
|
|
type props = {
|
|
type props = {
|
|
myUrl: string;
|
|
myUrl: string;
|
|
upFileFu: () => void;
|
|
upFileFu: () => void;
|
|
closeFu: () => void;
|
|
closeFu: () => void;
|
|
|
|
+ myTitle: string;
|
|
|
|
+ projectId: number;
|
|
};
|
|
};
|
|
|
|
|
|
-function A1IupFile({ myUrl, closeFu, upFileFu }: props) {
|
|
|
|
- // 从仓库获取 内控文件 属性
|
|
|
|
- const typeData = useSelector((state: RootState) => state.A2Dict.A2Tab2Arr);
|
|
|
|
|
|
+function A1IupFile({ myUrl, closeFu, upFileFu, myTitle, projectId }: props) {
|
|
|
|
+ // 获取回显列表,重命名的时候使用
|
|
|
|
+ const [isFileList, setIsFileList] = useState<string[]>([]);
|
|
|
|
|
|
- const [typeSelect, setTypeSelect] = useState([] as SelectType[]);
|
|
|
|
|
|
+ const getIsFileListFu = useCallback(async () => {
|
|
|
|
+ const res = await A1_APIIupIsList(projectId);
|
|
|
|
+ if (res.code === 0) {
|
|
|
|
+ setIsFileList(res.data.map((v: any) => v.fileName));
|
|
|
|
+ }
|
|
|
|
+ }, [projectId]);
|
|
|
|
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
- console.log("pppppppp", typeSelect);
|
|
|
|
- }, [typeSelect]);
|
|
|
|
|
|
+ getIsFileListFu();
|
|
|
|
+ }, [getIsFileListFu]);
|
|
|
|
+
|
|
|
|
+ const [modal, contextHolder] = Modal.useModal();
|
|
|
|
+
|
|
|
|
+ const [fileList, setFileList] = useState<UploadFile[]>([]);
|
|
|
|
+
|
|
|
|
+ const timeRef = useRef(-1);
|
|
|
|
+
|
|
|
|
+ // 从仓库获取 内控文件 属性
|
|
|
|
+ const typeData = useSelector((state: RootState) => state.A2Dict.A2Tab2Arr);
|
|
|
|
|
|
// 下拉框改变
|
|
// 下拉框改变
|
|
const selectChangeFu = useCallback(
|
|
const selectChangeFu = useCallback(
|
|
- (val: number, id: string) => {
|
|
|
|
|
|
+ (val: number, uid: string, id: number) => {
|
|
const info = typeData.find((v) => v.id === val)!;
|
|
const info = typeData.find((v) => v.id === val)!;
|
|
|
|
|
|
const tit = info.suffix ? info.suffix : "all";
|
|
const tit = info.suffix ? info.suffix : "all";
|
|
|
|
|
|
- setTypeSelect(
|
|
|
|
- typeSelect.map((v) => ({
|
|
|
|
|
|
+ const idName = info.name;
|
|
|
|
+
|
|
|
|
+ // 如果已经有相同的重命名
|
|
|
|
+ let resName = myTitle + "_" + idName;
|
|
|
|
+
|
|
|
|
+ const isArr = fileList.find((v) => v.mySelect.resName === resName);
|
|
|
|
+
|
|
|
|
+ const nameArr = fileList.filter((v) =>
|
|
|
|
+ v.mySelect.resName.includes(resName)
|
|
|
|
+ );
|
|
|
|
+
|
|
|
|
+ if (isFileList.length) {
|
|
|
|
+
|
|
|
|
+ console.log(isFileList);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ const isArr2 = isFileList.find((v) => v === resName);
|
|
|
|
+ const nameArr2 = isFileList.filter((v) => v.includes(resName));
|
|
|
|
+
|
|
|
|
+ if (nameArr.length > 0 && nameArr2.length > 0 && isArr && isArr2) {
|
|
|
|
+ resName = `${myTitle}_${idName}(${
|
|
|
|
+ nameArr.length + nameArr2.length + 1
|
|
|
|
+ })`;
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ if (nameArr.length > 0 && isArr) {
|
|
|
|
+ resName = `${myTitle}_${idName}(${nameArr.length + 1})`;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ setFileList(
|
|
|
|
+ fileList.map((v) => ({
|
|
...v,
|
|
...v,
|
|
- value: v.id === id ? val : v.value,
|
|
|
|
- txt: v.id === id ? info.description : v.txt,
|
|
|
|
- tit: v.id === id ? tit : v.tit,
|
|
|
|
|
|
+ mySelect:
|
|
|
|
+ v.uid === uid
|
|
|
|
+ ? {
|
|
|
|
+ ...v.mySelect,
|
|
|
|
+ value: v.mySelect.id === id ? val : v.mySelect.value,
|
|
|
|
+ txt: v.mySelect.id === id ? info.description : v.mySelect.txt,
|
|
|
|
+ tit: v.mySelect.id === id ? tit : v.mySelect.tit,
|
|
|
|
+ resName,
|
|
|
|
+ }
|
|
|
|
+ : v.mySelect,
|
|
}))
|
|
}))
|
|
);
|
|
);
|
|
},
|
|
},
|
|
- [typeData, typeSelect]
|
|
|
|
|
|
+ [fileList, isFileList, myTitle, typeData]
|
|
);
|
|
);
|
|
|
|
|
|
|
|
+ // 重命名的文件后缀
|
|
|
|
+ const houzuiFu = useCallback((name: string) => {
|
|
|
|
+ const arr = name.split(".") || [""];
|
|
|
|
+ return "." + arr[arr.length - 1];
|
|
|
|
+ }, []);
|
|
|
|
+
|
|
// 校验指定格式
|
|
// 校验指定格式
|
|
const typeGeShiFlag = useCallback((val: string, name: string) => {
|
|
const typeGeShiFlag = useCallback((val: string, name: string) => {
|
|
if (val === "all") return false;
|
|
if (val === "all") return false;
|
|
@@ -85,11 +150,14 @@ function A1IupFile({ myUrl, closeFu, upFileFu }: props) {
|
|
}
|
|
}
|
|
}, []);
|
|
}, []);
|
|
|
|
|
|
- // 确定按钮的格式校验
|
|
|
|
- const disBtnOkRes = useMemo(() => {
|
|
|
|
|
|
+ // 确定按钮的格式校验(指定文件类型,没有对应上)
|
|
|
|
+ const disBtnOkRes1 = useMemo(() => {
|
|
let flag = false;
|
|
let flag = false;
|
|
- typeSelect.forEach((v) => {
|
|
|
|
- if (v.tit !== "all") {
|
|
|
|
|
|
+
|
|
|
|
+ const resArr = fileList.map((v) => v.mySelect || {});
|
|
|
|
+
|
|
|
|
+ resArr.forEach((v) => {
|
|
|
|
+ if (v.tit && v.tit !== "all") {
|
|
const arr = v.tit.split(","); //['pdf','gif']
|
|
const arr = v.tit.split(","); //['pdf','gif']
|
|
|
|
|
|
const arr2 = v.fileName.split(".");
|
|
const arr2 = v.fileName.split(".");
|
|
@@ -100,13 +168,20 @@ function A1IupFile({ myUrl, closeFu, upFileFu }: props) {
|
|
}
|
|
}
|
|
});
|
|
});
|
|
return flag;
|
|
return flag;
|
|
- }, [typeSelect]);
|
|
|
|
|
|
+ }, [fileList]);
|
|
|
|
|
|
- const [modal, contextHolder] = Modal.useModal();
|
|
|
|
|
|
+ // 确定按钮的格式校验(有下拉框没有选择)
|
|
|
|
+ const disBtnOkRes2 = useMemo(() => {
|
|
|
|
+ let flag = false;
|
|
|
|
|
|
- const [fileList, setFileList] = useState<UploadFile[]>([]);
|
|
|
|
|
|
+ fileList.forEach((v) => {
|
|
|
|
+ if (v.mySelect) {
|
|
|
|
+ if (!v.mySelect.value) flag = true;
|
|
|
|
+ } else flag = true;
|
|
|
|
+ });
|
|
|
|
|
|
- const timeRef = useRef(-1);
|
|
|
|
|
|
+ return flag;
|
|
|
|
+ }, [fileList]);
|
|
|
|
|
|
const FileProps: UploadProps = {
|
|
const FileProps: UploadProps = {
|
|
name: "file",
|
|
name: "file",
|
|
@@ -154,18 +229,22 @@ function A1IupFile({ myUrl, closeFu, upFileFu }: props) {
|
|
}
|
|
}
|
|
if (status === "done") {
|
|
if (status === "done") {
|
|
// console.log("-----", info);
|
|
// console.log("-----", info);
|
|
-
|
|
|
|
- setTypeSelect([
|
|
|
|
- ...typeSelect,
|
|
|
|
- {
|
|
|
|
- id: info.file.response.data.id,
|
|
|
|
- value: undefined,
|
|
|
|
- txt: "",
|
|
|
|
- tit: "",
|
|
|
|
- fileName: info.file.name,
|
|
|
|
- },
|
|
|
|
- ]);
|
|
|
|
-
|
|
|
|
|
|
+ setFileList(
|
|
|
|
+ info.fileList.map((v) => ({
|
|
|
|
+ ...v,
|
|
|
|
+ mySelect:
|
|
|
|
+ info.file.uid === v.uid
|
|
|
|
+ ? {
|
|
|
|
+ id: info.file.response.data.id,
|
|
|
|
+ value: undefined,
|
|
|
|
+ txt: "",
|
|
|
|
+ tit: "",
|
|
|
|
+ resName: "",
|
|
|
|
+ fileName: info.file.name,
|
|
|
|
+ }
|
|
|
|
+ : v.mySelect,
|
|
|
|
+ }))
|
|
|
|
+ );
|
|
// message.success(`${info.file.fileName} 上传成功.`);
|
|
// message.success(`${info.file.fileName} 上传成功.`);
|
|
} else if (status === "error") {
|
|
} else if (status === "error") {
|
|
message.error(`${info.file.fileName} 上传失败.`);
|
|
message.error(`${info.file.fileName} 上传失败.`);
|
|
@@ -196,9 +275,12 @@ function A1IupFile({ myUrl, closeFu, upFileFu }: props) {
|
|
const res = await A1_APIremoveSure([id + ""]);
|
|
const res = await A1_APIremoveSure([id + ""]);
|
|
|
|
|
|
if (res.code === 0) {
|
|
if (res.code === 0) {
|
|
- setTypeSelect(typeSelect.filter((v) => v.id !== id));
|
|
|
|
|
|
+ domShowFu("#AsyncSpinLoding", true);
|
|
resolve(true);
|
|
resolve(true);
|
|
- MessageFu.success("删除成功!");
|
|
|
|
|
|
+ setTimeout(() => {
|
|
|
|
+ domShowFu("#AsyncSpinLoding", false);
|
|
|
|
+ MessageFu.success("删除成功!");
|
|
|
|
+ }, 2000);
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
resolve(true);
|
|
resolve(true);
|
|
@@ -221,20 +303,24 @@ function A1IupFile({ myUrl, closeFu, upFileFu }: props) {
|
|
|
|
|
|
// 拿到 id集合
|
|
// 拿到 id集合
|
|
|
|
|
|
- const ids: number[] = [];
|
|
|
|
|
|
+ const arr: any = [];
|
|
|
|
|
|
fileList.forEach((v) => {
|
|
fileList.forEach((v) => {
|
|
- ids.push(v.response.data.id);
|
|
|
|
|
|
+ arr.push({
|
|
|
|
+ attributeId: v.mySelect.value,
|
|
|
|
+ fileName: v.mySelect.resName + houzuiFu(v.mySelect.fileName),
|
|
|
|
+ id: v.mySelect.id,
|
|
|
|
+ });
|
|
});
|
|
});
|
|
|
|
|
|
- const res = await A1_APIOupFileIds(ids.join(","));
|
|
|
|
|
|
+ const res = await A1_APIIupBtnOk(projectId, arr);
|
|
|
|
|
|
if (res.code === 0) {
|
|
if (res.code === 0) {
|
|
MessageFu.success("保存成功!");
|
|
MessageFu.success("保存成功!");
|
|
upFileFu();
|
|
upFileFu();
|
|
closeFu();
|
|
closeFu();
|
|
}
|
|
}
|
|
- }, [closeFu, fileList, upFileFu]);
|
|
|
|
|
|
+ }, [closeFu, fileList, houzuiFu, projectId, upFileFu]);
|
|
|
|
|
|
return (
|
|
return (
|
|
<Modal
|
|
<Modal
|
|
@@ -298,8 +384,8 @@ function A1IupFile({ myUrl, closeFu, upFileFu }: props) {
|
|
<Select
|
|
<Select
|
|
style={{ width: 200 }}
|
|
style={{ width: 200 }}
|
|
placeholder="请选择"
|
|
placeholder="请选择"
|
|
- value={typeSelect[i] ? typeSelect[i].value : undefined}
|
|
|
|
- onChange={(e) => selectChangeFu(e, typeSelect[i].id)}
|
|
|
|
|
|
+ value={v.mySelect.value || undefined}
|
|
|
|
+ onChange={(e) => selectChangeFu(e, v.uid, v.mySelect.id)}
|
|
options={typeData.map((v) => ({
|
|
options={typeData.map((v) => ({
|
|
value: v.id,
|
|
value: v.id,
|
|
label: v.name,
|
|
label: v.name,
|
|
@@ -308,45 +394,51 @@ function A1IupFile({ myUrl, closeFu, upFileFu }: props) {
|
|
|
|
|
|
{/* 没选择的时候的提示 */}
|
|
{/* 没选择的时候的提示 */}
|
|
<div className="A1IUselectTit">
|
|
<div className="A1IUselectTit">
|
|
- {typeSelect[i] && typeSelect[i].value ? (
|
|
|
|
|
|
+ {v.mySelect && v.mySelect.value ? (
|
|
<div className="A1IUselectTit2">
|
|
<div className="A1IUselectTit2">
|
|
- <div title={typeSelect[i].txt}>
|
|
|
|
- {typeSelect[i].txt}
|
|
|
|
- </div>
|
|
|
|
|
|
+ <div title={v.mySelect.txt}>{v.mySelect.txt}</div>
|
|
|
|
|
|
{typeGeShiFlag(
|
|
{typeGeShiFlag(
|
|
- typeSelect[i].tit,
|
|
|
|
- typeSelect[i].fileName
|
|
|
|
|
|
+ v.mySelect.tit,
|
|
|
|
+ v.mySelect.fileName
|
|
) ? (
|
|
) ? (
|
|
<div
|
|
<div
|
|
className="A1IUselectTit2Tit"
|
|
className="A1IUselectTit2Tit"
|
|
- title={`该文件类型只支持 ${typeSelect[i].tit}`}
|
|
|
|
|
|
+ title={`该文件类型只支持 ${v.mySelect.tit}`}
|
|
>
|
|
>
|
|
-  该文件类型只支持 {typeSelect[i].tit} 格式
|
|
|
|
|
|
+  该文件类型只支持 {v.mySelect.tit} 格式
|
|
</div>
|
|
</div>
|
|
) : null}
|
|
) : null}
|
|
-
|
|
|
|
- {/* {typeSelect[i].tit !== "all" &&
|
|
|
|
- typeSelect[i].fileName.includes(typeSelect[i].tit) ? (
|
|
|
|
-
|
|
|
|
- ) : (
|
|
|
|
- ""
|
|
|
|
- )} */}
|
|
|
|
</div>
|
|
</div>
|
|
) : (
|
|
) : (
|
|
<div className="A1IUselectTit1">请选择文件类型</div>
|
|
<div className="A1IUselectTit1">请选择文件类型</div>
|
|
)}
|
|
)}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
+
|
|
|
|
+ {/* 重命名 */}
|
|
|
|
+ {v.mySelect.resName ? (
|
|
|
|
+ <div className="A1IUselectName">
|
|
|
|
+ <div className="A1IUselectName1">重命名为:</div>
|
|
|
|
+ <div
|
|
|
|
+ className="A1IUselectName2"
|
|
|
|
+ title={
|
|
|
|
+ v.mySelect.resName + houzuiFu(v.mySelect.fileName)
|
|
|
|
+ }
|
|
|
|
+ >
|
|
|
|
+ {v.mySelect.resName + houzuiFu(v.mySelect.fileName)}
|
|
|
|
+ </div>
|
|
|
|
+ </div>
|
|
|
|
+ ) : null}
|
|
</>
|
|
</>
|
|
) : (
|
|
) : (
|
|
""
|
|
""
|
|
)}
|
|
)}
|
|
|
|
|
|
{/* 3.前面的序号 */}
|
|
{/* 3.前面的序号 */}
|
|
- {/* <div className="mySortQ" hidden={fileList.length <= 1}>
|
|
|
|
|
|
+ <div className="mySortQ" hidden={fileList.length <= 1}>
|
|
{i + 1}.
|
|
{i + 1}.
|
|
- </div> */}
|
|
|
|
|
|
+ </div>
|
|
</div>
|
|
</div>
|
|
))}
|
|
))}
|
|
</div>
|
|
</div>
|
|
@@ -366,11 +458,7 @@ function A1IupFile({ myUrl, closeFu, upFileFu }: props) {
|
|
<Button
|
|
<Button
|
|
type="primary"
|
|
type="primary"
|
|
onClick={btnOkFu}
|
|
onClick={btnOkFu}
|
|
- disabled={
|
|
|
|
- fileList.length <= 0 ||
|
|
|
|
- typeSelect.some((v) => !v.value) ||
|
|
|
|
- disBtnOkRes
|
|
|
|
- }
|
|
|
|
|
|
+ disabled={fileList.length <= 0 || disBtnOkRes1 || disBtnOkRes2}
|
|
>
|
|
>
|
|
确定
|
|
确定
|
|
</Button>
|
|
</Button>
|