|
@@ -18,7 +18,9 @@ import { API_upFile } from "@/store/action/layout";
|
|
import { forwardRef, useImperativeHandle } from "react";
|
|
import { forwardRef, useImperativeHandle } from "react";
|
|
import MyPopconfirm from "../MyPopconfirm";
|
|
import MyPopconfirm from "../MyPopconfirm";
|
|
|
|
|
|
-// 这个组件 只处理 上传 一张图片或者 视频 音频 模型 的情况
|
|
|
|
|
|
+type MyTypeType = "thumb" | "video" | "audio" | "model" | "pdf";
|
|
|
|
+
|
|
|
|
+// 这个组件 只处理 上传 一张图片或者 视频 音频 模型 pdf 的情况
|
|
|
|
|
|
type Props = {
|
|
type Props = {
|
|
fileCheck: boolean; //有没有点击过确定
|
|
fileCheck: boolean; //有没有点击过确定
|
|
@@ -29,7 +31,7 @@ type Props = {
|
|
formatTxt: string; //上传图片提示
|
|
formatTxt: string; //上传图片提示
|
|
checkTxt: string;
|
|
checkTxt: string;
|
|
upTxt: string;
|
|
upTxt: string;
|
|
- myType: "thumb" | "video" | "audio" | "model";
|
|
|
|
|
|
+ myType: MyTypeType;
|
|
isLook?: boolean; //是不是查看
|
|
isLook?: boolean; //是不是查看
|
|
fromData?: any;
|
|
fromData?: any;
|
|
ref: any; //当前自己的ref,给父组件调用
|
|
ref: any; //当前自己的ref,给父组件调用
|
|
@@ -46,7 +48,7 @@ function ZupOne(
|
|
checkTxt,
|
|
checkTxt,
|
|
upTxt,
|
|
upTxt,
|
|
myType,
|
|
myType,
|
|
- isLook=false,
|
|
|
|
|
|
+ isLook = false,
|
|
fromData,
|
|
fromData,
|
|
}: Props,
|
|
}: Props,
|
|
ref: any
|
|
ref: any
|
|
@@ -64,14 +66,23 @@ function ZupOne(
|
|
if (e.target.files) {
|
|
if (e.target.files) {
|
|
// 拿到files信息
|
|
// 拿到files信息
|
|
const filesInfo = e.target.files[0];
|
|
const filesInfo = e.target.files[0];
|
|
- // console.log('-----',filesInfo.type);
|
|
|
|
-
|
|
|
|
|
|
+ // console.log("-----", filesInfo.type);
|
|
|
|
+
|
|
// 校验格式
|
|
// 校验格式
|
|
const type = format;
|
|
const type = format;
|
|
- if (!type.includes(filesInfo.type)) {
|
|
|
|
- e.target.value = "";
|
|
|
|
- return MessageFu.warning(`只支持${formatTxt}格式!`);
|
|
|
|
|
|
+
|
|
|
|
+ if (myType === "pdf") {
|
|
|
|
+ if (!filesInfo.type.includes("pdf")) {
|
|
|
|
+ e.target.value = "";
|
|
|
|
+ return MessageFu.warning(`只支持${formatTxt}格式!`);
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ if (!type.includes(filesInfo.type)) {
|
|
|
|
+ e.target.value = "";
|
|
|
|
+ return MessageFu.warning(`只支持${formatTxt}格式!`);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
+
|
|
// 校验大小
|
|
// 校验大小
|
|
if (filesInfo.size > size * 1024 * 1024) {
|
|
if (filesInfo.size > size * 1024 * 1024) {
|
|
e.target.value = "";
|
|
e.target.value = "";
|
|
@@ -80,7 +91,9 @@ function ZupOne(
|
|
// 创建FormData对象
|
|
// 创建FormData对象
|
|
const fd = new FormData();
|
|
const fd = new FormData();
|
|
// 把files添加进FormData对象(‘photo’为后端需要的字段)
|
|
// 把files添加进FormData对象(‘photo’为后端需要的字段)
|
|
- fd.append("type", myType);
|
|
|
|
|
|
+ let myTypeRes: string = myType;
|
|
|
|
+ if (["pdf"].includes(myTypeRes)) myTypeRes = "doc";
|
|
|
|
+ fd.append("type", myTypeRes);
|
|
fd.append("dirCode", dirCode);
|
|
fd.append("dirCode", dirCode);
|
|
fd.append("file", filesInfo);
|
|
fd.append("file", filesInfo);
|
|
|
|
|
|
@@ -131,9 +144,30 @@ function ZupOne(
|
|
if (myType === "video") accept = ".mp4";
|
|
if (myType === "video") accept = ".mp4";
|
|
else if (myType === "audio") accept = ".mp3";
|
|
else if (myType === "audio") accept = ".mp3";
|
|
else if (myType === "model") accept = ".4dage";
|
|
else if (myType === "model") accept = ".4dage";
|
|
|
|
+ else if (myType === "pdf") accept = ".pdf";
|
|
return accept;
|
|
return accept;
|
|
}, [myType]);
|
|
}, [myType]);
|
|
|
|
|
|
|
|
+ // 点击 预览(除了图片)
|
|
|
|
+ const lookFileNoImgFu = useCallback(
|
|
|
|
+ (type: MyTypeType) => {
|
|
|
|
+ if (type === "pdf" || type === "thumb") {
|
|
|
|
+ // 新窗口打开
|
|
|
|
+ window.open(baseURL + fileUrl.filePath);
|
|
|
|
+ } else {
|
|
|
|
+ store.dispatch({
|
|
|
|
+ type: "layout/lookDom",
|
|
|
|
+ payload: { src: fileUrl.filePath, type },
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (type === "pdf") {
|
|
|
|
+ } else {
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ [fileUrl.filePath]
|
|
|
|
+ );
|
|
|
|
+
|
|
return (
|
|
return (
|
|
<div className={styles.ZupOne}>
|
|
<div className={styles.ZupOne}>
|
|
<input
|
|
<input
|
|
@@ -205,12 +239,7 @@ function ZupOne(
|
|
<div
|
|
<div
|
|
className="clearCover"
|
|
className="clearCover"
|
|
hidden={!fileUrl.filePath}
|
|
hidden={!fileUrl.filePath}
|
|
- onClick={() =>
|
|
|
|
- store.dispatch({
|
|
|
|
- type: "layout/lookDom",
|
|
|
|
- payload: { src: fileUrl.filePath, type: myType },
|
|
|
|
- })
|
|
|
|
- }
|
|
|
|
|
|
+ onClick={() => lookFileNoImgFu(myType)}
|
|
>
|
|
>
|
|
<EyeOutlined rev={undefined} />
|
|
<EyeOutlined rev={undefined} />
|
|
</div>
|
|
</div>
|