|
@@ -6,7 +6,7 @@ import { baseURL } from "./http";
|
|
|
export const urlChangeFu = async (
|
|
|
url: string,
|
|
|
flag: boolean,
|
|
|
- type?: "img" | "video" | "audio" | "pdf",
|
|
|
+ type?: "img" | "video" | "audio" | ".pdf" | ".txt" | ".docx" | ".xlsx",
|
|
|
name?: string
|
|
|
) => {
|
|
|
// flag true 为 生成 a标签 下载
|
|
@@ -34,7 +34,7 @@ export const urlChangeFu = async (
|
|
|
show: true,
|
|
|
},
|
|
|
});
|
|
|
- } else if (type === "pdf") {
|
|
|
+ } else if (type === ".pdf" || type === ".txt") {
|
|
|
window.open(srcRes);
|
|
|
} else if (type === "audio" || type === "video") {
|
|
|
store.dispatch({
|
|
@@ -45,6 +45,15 @@ export const urlChangeFu = async (
|
|
|
flag: true,
|
|
|
},
|
|
|
});
|
|
|
+ } else if (
|
|
|
+ type &&
|
|
|
+ name &&
|
|
|
+ [".doc", ".docx", ".ppt", ".pptx", ".xls", ".xlsx"].includes(type)
|
|
|
+ ) {
|
|
|
+ store.dispatch({
|
|
|
+ type: "layout/fileLookUrl",
|
|
|
+ payload: { url: srcRes, name: type },
|
|
|
+ });
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -61,13 +70,18 @@ export const authFilesLookFu = (
|
|
|
|
|
|
const nameRes = name ? name : "";
|
|
|
|
|
|
- if (nameRes.toLowerCase().endsWith(".pdf")) {
|
|
|
- if (url) {
|
|
|
- noAuth ? window.open(baseURL + url) : urlChangeFu(url, false, "pdf");
|
|
|
+ // pdf和txt 直接新窗口打开
|
|
|
+ const arr0: (".pdf" | ".txt")[] = [".pdf", ".txt"];
|
|
|
+ arr0.forEach((v) => {
|
|
|
+ if (nameRes.toLowerCase().endsWith(v)) {
|
|
|
+ if (url) {
|
|
|
+ noAuth ? window.open(baseURL + url) : urlChangeFu(url, false, v);
|
|
|
+ }
|
|
|
+ flag = true;
|
|
|
}
|
|
|
- flag = true;
|
|
|
- }
|
|
|
+ });
|
|
|
|
|
|
+ // 图片使用 antd的图片预览组件
|
|
|
const arr1 = [".png", ".jpg", ".jpeg", ".gif"];
|
|
|
arr1.forEach((v) => {
|
|
|
if (nameRes.toLowerCase().endsWith(v)) {
|
|
@@ -87,10 +101,9 @@ export const authFilesLookFu = (
|
|
|
}
|
|
|
});
|
|
|
|
|
|
+ // 视频和音频 使用自己的封装的组件
|
|
|
let type: "" | "video" | "audio" = "";
|
|
|
-
|
|
|
const arr2 = [".mp3", ".wav"];
|
|
|
-
|
|
|
arr2.forEach((v) => {
|
|
|
if (nameRes.toLowerCase().endsWith(v)) {
|
|
|
type = "audio";
|
|
@@ -115,5 +128,21 @@ export const authFilesLookFu = (
|
|
|
: urlChangeFu(url, false, type);
|
|
|
}
|
|
|
|
|
|
+ // ppt,doc,Excel使用插件
|
|
|
+ const arr3: (".docx" | ".xlsx")[] = [".docx", ".xlsx"];
|
|
|
+ arr3.forEach((v) => {
|
|
|
+ if (nameRes.toLowerCase().endsWith(v)) {
|
|
|
+ if (url) {
|
|
|
+ noAuth
|
|
|
+ ? store.dispatch({
|
|
|
+ type: "layout/fileLookUrl",
|
|
|
+ payload: { url: baseURL + url, name: v },
|
|
|
+ })
|
|
|
+ : urlChangeFu(url, false, v, nameRes);
|
|
|
+ }
|
|
|
+ flag = true;
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
return flag;
|
|
|
};
|