|
@@ -1,7 +1,12 @@
|
|
|
import React, { useEffect, useState } from "react";
|
|
|
import { Card, Dropdown, Modal, Input, message, Tooltip } from "antd";
|
|
|
-import defaultImg from "@/assets/image/default.png"
|
|
|
+import defaultImg from "@/assets/image/default.png";
|
|
|
import { GetFile, DeleteDataModel, SaveDataModel } from "@/api";
|
|
|
+import {
|
|
|
+ EditOutlined,
|
|
|
+ FileTextOutlined,
|
|
|
+ EllipsisOutlined,
|
|
|
+} from "@ant-design/icons";
|
|
|
|
|
|
export default function ProjectCard({
|
|
|
record,
|
|
@@ -16,8 +21,7 @@ export default function ProjectCard({
|
|
|
onChangeLocation: (id: string) => void;
|
|
|
hideRemove?: boolean;
|
|
|
}) {
|
|
|
- const [showMenu, setShowMenu] = useState(false);
|
|
|
- const handleToEdit = () => {
|
|
|
+ const handleToDetail = () => {
|
|
|
const { origin, pathname } = window.location;
|
|
|
const enterpriseCode = sessionStorage.getItem("enterpriseCode");
|
|
|
window.open(
|
|
@@ -25,19 +29,101 @@ export default function ProjectCard({
|
|
|
);
|
|
|
};
|
|
|
|
|
|
+ const handleToEdit = () => {
|
|
|
+ const { origin, pathname } = window.location;
|
|
|
+ const enterpriseCode = sessionStorage.getItem("enterpriseCode");
|
|
|
+ window.open(
|
|
|
+ `${origin}${pathname}#/er/${record.id}?enterpriseCode=${enterpriseCode}`
|
|
|
+ );
|
|
|
+ };
|
|
|
+
|
|
|
const { confirm } = Modal;
|
|
|
|
|
|
const [coverImg, setCoverImg] = useState<string>("");
|
|
|
useEffect(() => {
|
|
|
if (record.coverImage) {
|
|
|
GetFile({ fileId: record.coverImage }).then((res) => {
|
|
|
- const blob = new Blob([res], { type: "image/png" });
|
|
|
- const url = URL.createObjectURL(blob);
|
|
|
- setCoverImg(url);
|
|
|
+ const blob = new Blob([res], { type: "image/png" });
|
|
|
+ const url = URL.createObjectURL(blob);
|
|
|
+ setCoverImg(url);
|
|
|
});
|
|
|
}
|
|
|
}, []);
|
|
|
|
|
|
+ const actions: React.ReactNode[] = [
|
|
|
+ <EditOutlined key="edit" onClick={handleToEdit}/>,
|
|
|
+ <FileTextOutlined key="setting" onClick={handleToDetail}/>,
|
|
|
+ <Dropdown
|
|
|
+ key="more"
|
|
|
+ menu={{
|
|
|
+ items: [
|
|
|
+ {
|
|
|
+ key: "1",
|
|
|
+ label: "重命名",
|
|
|
+ onClick: () => {
|
|
|
+ let name = record.name;
|
|
|
+ confirm({
|
|
|
+ title: "重命名",
|
|
|
+ centered: true,
|
|
|
+ icon: <></>,
|
|
|
+ content: (
|
|
|
+ <Input
|
|
|
+ defaultValue={name}
|
|
|
+ onChange={(e) => {
|
|
|
+ name = e.target.value;
|
|
|
+ }}
|
|
|
+ />
|
|
|
+ ),
|
|
|
+ onOk: async () => {
|
|
|
+ await SaveDataModel({
|
|
|
+ ...record,
|
|
|
+ name,
|
|
|
+ });
|
|
|
+ message.success("更新成功");
|
|
|
+ onFresh();
|
|
|
+ },
|
|
|
+ });
|
|
|
+ },
|
|
|
+ },
|
|
|
+ !hideRemove
|
|
|
+ ? {
|
|
|
+ key: "2",
|
|
|
+ label: "移动",
|
|
|
+ onClick: () => {
|
|
|
+ onChangeLocation?.(record.id);
|
|
|
+ },
|
|
|
+ }
|
|
|
+ : null,
|
|
|
+ {
|
|
|
+ key: "3",
|
|
|
+ label: "删除",
|
|
|
+ danger: true,
|
|
|
+ onClick: () => {
|
|
|
+ confirm({
|
|
|
+ title: "删除",
|
|
|
+ content: "确定删除该模型?",
|
|
|
+ centered: true,
|
|
|
+ onOk: async () => {
|
|
|
+ await DeleteDataModel({
|
|
|
+ id: record.id,
|
|
|
+ });
|
|
|
+ onDelete?.();
|
|
|
+ message.success("删除成功");
|
|
|
+ },
|
|
|
+ });
|
|
|
+ },
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ onClick: (e) => {
|
|
|
+ e.domEvent.stopPropagation();
|
|
|
+ },
|
|
|
+ }}
|
|
|
+ trigger={["click"]}
|
|
|
+ >
|
|
|
+ <EllipsisOutlined/>
|
|
|
+ </Dropdown>,
|
|
|
+ ];
|
|
|
+
|
|
|
return (
|
|
|
<Card
|
|
|
hoverable
|
|
@@ -48,99 +134,30 @@ export default function ProjectCard({
|
|
|
objectFit: "cover",
|
|
|
border: "solid 1px #f5f5f5",
|
|
|
}}
|
|
|
- src={
|
|
|
- coverImg || defaultImg
|
|
|
- }
|
|
|
+ src={coverImg || defaultImg}
|
|
|
+ onClick={handleToDetail}
|
|
|
/>
|
|
|
}
|
|
|
- onClick={() => handleToEdit()}
|
|
|
- onMouseOver={() => setShowMenu(true)}
|
|
|
- onMouseOut={() => setShowMenu(false)}
|
|
|
+ actions={actions}
|
|
|
>
|
|
|
- {showMenu && (
|
|
|
- <Dropdown
|
|
|
- menu={{
|
|
|
- items: [
|
|
|
- {
|
|
|
- key: "1",
|
|
|
- label: "重命名",
|
|
|
- onClick: () => {
|
|
|
- let name = record.name;
|
|
|
- confirm({
|
|
|
- title: "重命名",
|
|
|
- centered: true,
|
|
|
- icon: <></>,
|
|
|
- content: (
|
|
|
- <Input
|
|
|
- defaultValue={name}
|
|
|
- onChange={(e) => {
|
|
|
- name = e.target.value;
|
|
|
- }}
|
|
|
- />
|
|
|
- ),
|
|
|
- onOk: async () => {
|
|
|
- await SaveDataModel({
|
|
|
- ...record,
|
|
|
- name
|
|
|
- });
|
|
|
- message.success('更新成功');
|
|
|
- onFresh();
|
|
|
- },
|
|
|
- });
|
|
|
- },
|
|
|
- },
|
|
|
- !hideRemove
|
|
|
- ? {
|
|
|
- key: "2",
|
|
|
- label: "移动",
|
|
|
- onClick: () => {
|
|
|
- onChangeLocation?.(record.id);
|
|
|
- },
|
|
|
- }
|
|
|
- : null,
|
|
|
- {
|
|
|
- key: "3",
|
|
|
- label: "删除",
|
|
|
- danger: true,
|
|
|
- onClick: () => {
|
|
|
- confirm({
|
|
|
- title: "删除",
|
|
|
- content: "确定删除该模型?",
|
|
|
- centered: true,
|
|
|
- onOk: async () => {
|
|
|
- await DeleteDataModel({
|
|
|
- id: record.id,
|
|
|
- });
|
|
|
- onDelete?.();
|
|
|
- message.success("删除成功");
|
|
|
- },
|
|
|
- });
|
|
|
- },
|
|
|
- },
|
|
|
- ],
|
|
|
- onClick: (e) => {
|
|
|
- e.domEvent.stopPropagation();
|
|
|
- },
|
|
|
- }}
|
|
|
- >
|
|
|
- <div
|
|
|
- className="absolute right-8px top-8px cursor-pointer bg-#adadad99 px-12px rounded-4px text-12px line-height-16px color-#fff"
|
|
|
- onClick={(e) => {
|
|
|
- e.stopPropagation();
|
|
|
- }}
|
|
|
- >
|
|
|
- <i className="iconfont icon-a-zu10687" />
|
|
|
- </div>
|
|
|
- </Dropdown>
|
|
|
- )}
|
|
|
<Card.Meta
|
|
|
title={
|
|
|
<span className="flex items-center justify-between">
|
|
|
- <Tooltip title={record.name}><span className="flex-1 truncate ">{record.name}</span></Tooltip>
|
|
|
- <span className="text-12px font-normal color-#999">更新:{record.updateTime}</span>
|
|
|
+ <Tooltip title={record.name}>
|
|
|
+ <span className="flex-1 truncate ">{record.name}</span>
|
|
|
+ </Tooltip>
|
|
|
+ <span className="text-12px font-normal color-#999">
|
|
|
+ 更新:{record.updateTime}
|
|
|
+ </span>
|
|
|
+ </span>
|
|
|
+ }
|
|
|
+ description={
|
|
|
+ <span className="block truncate">
|
|
|
+ <Tooltip title={record.description}>
|
|
|
+ {record.description || "暂无描述"}
|
|
|
+ </Tooltip>
|
|
|
</span>
|
|
|
}
|
|
|
- description={<span className="block truncate"><Tooltip title={record.description}>{record.description || '暂无描述'}</Tooltip></span>}
|
|
|
/>
|
|
|
</Card>
|
|
|
);
|