feat
parent
8f73ce1086
commit
4d54b425f2
|
|
@ -10,9 +10,9 @@ module.exports = {
|
|||
javaGitBranch: "dev",
|
||||
// 本地联调 safetyEval-service(context-path: /safetyEval,默认端口 8095)
|
||||
// 可通过环境变量覆盖: SAFETY_EVAL_API_HOST=http://192.168.x.x:8095
|
||||
API_HOST: "http://localhost:80",
|
||||
//API_HOST: "http://localhost:80",
|
||||
|
||||
// API_HOST: "http://192.168.0.134",
|
||||
API_HOST: "http://192.168.0.134",
|
||||
// API_HOST: "http://192.168.0.150", //太浅
|
||||
// API_HOST: "http://192.168.0.152",
|
||||
//API_HOST: "http://192.168.0.103", //huwei
|
||||
|
|
|
|||
|
|
@ -1,108 +0,0 @@
|
|||
import { Image, Modal } from "antd";
|
||||
|
||||
function resolveUrl(raw) {
|
||||
if (!raw) return "";
|
||||
const u = String(raw);
|
||||
if (/^https?:\/\//i.test(u)) return u;
|
||||
const base = window.fileUrl || "";
|
||||
return base ? `${base}${u}` : u;
|
||||
}
|
||||
|
||||
export function getFilePreviewType(url = "", fileName = "") {
|
||||
const hint = `${fileName || ""} ${url || ""}`.toLowerCase();
|
||||
if (/\.(jpe?g|png|gif|webp|bmp)(\?|#|$)/i.test(hint)) {
|
||||
return "image";
|
||||
}
|
||||
return "other";
|
||||
}
|
||||
|
||||
export function FilePreviewContent({ url, fileName, style }) {
|
||||
const resolved = resolveUrl(url);
|
||||
if (!resolved) {
|
||||
return (
|
||||
<div style={{
|
||||
minHeight: 120,
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
justifyContent: "center",
|
||||
background: "#fafafa",
|
||||
color: "rgba(0,0,0,0.45)",
|
||||
...style,
|
||||
}}
|
||||
>
|
||||
暂无上传文件
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const type = getFilePreviewType(resolved, fileName);
|
||||
if (type === "image") {
|
||||
return <Image src={resolved} alt={fileName || "预览"} style={{ maxHeight: 480, ...style }} />;
|
||||
}
|
||||
|
||||
return (
|
||||
<div style={{
|
||||
minHeight: 120,
|
||||
display: "flex",
|
||||
flexDirection: "column",
|
||||
alignItems: "center",
|
||||
justifyContent: "center",
|
||||
background: "#fafafa",
|
||||
color: "rgba(0,0,0,0.45)",
|
||||
...style,
|
||||
}}
|
||||
>
|
||||
<span style={{ marginBottom: 8 }}>此文件类型不支持内嵌预览</span>
|
||||
<span>请点击下方「新窗口打开」按钮在浏览器中查看</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default function FilePreviewModal({
|
||||
open,
|
||||
title = "文件预览",
|
||||
fileName,
|
||||
url,
|
||||
width = 720,
|
||||
onCancel,
|
||||
}) {
|
||||
const resolved = resolveUrl(url);
|
||||
const isImageFile = resolved && /\.(jpe?g|png|gif|webp|bmp)(\?|#|$)/i.test(resolved.toLowerCase());
|
||||
|
||||
return (
|
||||
<Modal
|
||||
open={open}
|
||||
destroyOnHidden
|
||||
title={title}
|
||||
width={width}
|
||||
cancelText="关闭"
|
||||
okText={resolved ? (isImageFile ? "新窗口打开" : "重新打开") : "关闭"}
|
||||
onCancel={onCancel}
|
||||
onOk={() => {
|
||||
if (resolved) {
|
||||
window.open(resolved, "_blank");
|
||||
}
|
||||
onCancel?.();
|
||||
}}
|
||||
>
|
||||
{open && (
|
||||
<div>
|
||||
{fileName && (
|
||||
<div style={{
|
||||
padding: 12,
|
||||
background: "#f8fafc",
|
||||
border: "1px solid #f0f0f0",
|
||||
borderRadius: 4,
|
||||
marginBottom: 12,
|
||||
fontWeight: 500,
|
||||
}}
|
||||
>
|
||||
{fileName}
|
||||
</div>
|
||||
)}
|
||||
<FilePreviewContent url={resolved} fileName={fileName} />
|
||||
</div>
|
||||
)}
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
|
|
@ -1,43 +0,0 @@
|
|||
import { Upload, Button, message } from "antd";
|
||||
import { UploadOutlined } from "@ant-design/icons";
|
||||
import { parseUploadFileList, resolveUploadFileId } from "~/utils/mockUpload";
|
||||
|
||||
export default function FilingUpload({
|
||||
value,
|
||||
onChange,
|
||||
disabled,
|
||||
maxCount = 1,
|
||||
accept,
|
||||
}) {
|
||||
const fileList = Array.isArray(value) ? value : parseUploadFileList(value);
|
||||
|
||||
return (
|
||||
<Upload
|
||||
maxCount={maxCount}
|
||||
accept={accept}
|
||||
action={`${window.process.env.app.API_HOST}/safetyEval/file/upload`}
|
||||
disabled={disabled}
|
||||
fileList={fileList}
|
||||
beforeUpload={(file) => {
|
||||
const ext = "." + file.name.split(".").pop().toLowerCase();
|
||||
if (ext === ".gif") {
|
||||
message.error("不支持 GIF 格式图片上传");
|
||||
return Upload.LIST_IGNORE;
|
||||
}
|
||||
return true;
|
||||
}}
|
||||
onChange={(info) => {
|
||||
if (disabled) return;
|
||||
onChange?.(info.fileList);
|
||||
}}
|
||||
>
|
||||
{(!fileList || fileList.length < maxCount) && (
|
||||
<Button icon={<UploadOutlined />}>上传</Button>
|
||||
)}
|
||||
</Upload>
|
||||
);
|
||||
}
|
||||
|
||||
export function resolveFilingUploadUrl(files) {
|
||||
return resolveUploadFileId(files);
|
||||
}
|
||||
Loading…
Reference in New Issue