Recently.tsx 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. import React, { useEffect, useState } from "react";
  2. import { ProTable, PageContainer } from "@ant-design/pro-components";
  3. import { Col, Row, Button, Breadcrumb, Empty, Modal, Tree } from "antd";
  4. import { useRequest } from "umi";
  5. import { AppstoreOutlined, MenuOutlined } from "@ant-design/icons";
  6. import { RecentFile } from "@/api/systemDesigner";
  7. import ProjectCard from "./ProjectCard";
  8. import { graphOptions } from "./data";
  9. import { GraphType } from "@/enum";
  10. export default function Recently({ updateKey }: { updateKey: number }) {
  11. const [display, setDisplay] = useState("card");
  12. const [dataSource, setDataSource] = useState<any[]>([]);
  13. const [total, setTotal] = useState(0);
  14. const [searchName, setSearchName] = useState("");
  15. const [currentPage, setCurrentPage] = useState(1);
  16. const [open, setOpen] = useState(false);
  17. const { loading, run, refresh } = useRequest(RecentFile, {
  18. onSuccess: (res) => {
  19. const list = res?.result || [];
  20. setDataSource(list);
  21. setTotal(list.length);
  22. },
  23. });
  24. useEffect(() => {
  25. run();
  26. }, [updateKey]);
  27. const FolderIcon = function () {
  28. return (
  29. <svg className="icon" aria-hidden="true">
  30. <use xlinkHref="#icon-weibiaoti-_huabanfuben"></use>
  31. </svg>
  32. );
  33. };
  34. const folderTreeData = [
  35. {
  36. key: "1",
  37. title: (
  38. <span>
  39. 我的文件<span className="text-12px color-#999">(当前)</span>
  40. </span>
  41. ),
  42. icon: <FolderIcon />,
  43. children: [
  44. {
  45. key: "1-1",
  46. title: "文件夹1",
  47. icon: <FolderIcon />,
  48. },
  49. ],
  50. },
  51. ];
  52. // 搜索文件
  53. const handleSearch = () => {
  54. setCurrentPage(1);
  55. run();
  56. };
  57. // 搜索图形类型
  58. const setSearchGraphType = (type: GraphType) => {};
  59. return (
  60. <>
  61. <PageContainer extra={false} title={false} footer={[]}>
  62. <div className="flex justify-between items-center mb-12px">
  63. <Breadcrumb
  64. items={[
  65. {
  66. title: "最近",
  67. },
  68. ]}
  69. ></Breadcrumb>
  70. <Button
  71. key="2"
  72. onClick={() => {
  73. setDisplay(display === "card" ? "list" : "card");
  74. }}
  75. icon={display === "card" ? <MenuOutlined /> : <AppstoreOutlined />}
  76. />
  77. </div>
  78. {display === "card" ? (
  79. <>
  80. <Row gutter={[8, 16]}>
  81. {dataSource.map((item, index) => {
  82. return (
  83. <Col xs={12} sm={8} md={6} lg={6} xl={6} xxl={6} key={index}>
  84. <ProjectCard
  85. record={item}
  86. onFresh={refresh}
  87. onDelete={refresh}
  88. onChangeLocation={() => {}}
  89. hideRemove={true}
  90. />
  91. </Col>
  92. );
  93. })}
  94. </Row>
  95. {dataSource.length == 0 ? <Empty description="暂无数据" /> : null}
  96. </>
  97. ) : (
  98. <ProTable
  99. loading={loading}
  100. columns={[
  101. {
  102. title: "名称",
  103. dataIndex: "name",
  104. },
  105. {
  106. title: "类型",
  107. dataIndex: "type",
  108. },
  109. {
  110. title: "修改时间",
  111. dataIndex: "updatedTime",
  112. sorter: (a, b) => a.updateTime - b.updateTime,
  113. },
  114. ]}
  115. dataSource={dataSource}
  116. rowKey={"id"}
  117. search={false}
  118. pagination={{
  119. total: total,
  120. pageSize: 10,
  121. current: currentPage,
  122. pageSizeOptions: ["12", "24", "36"],
  123. onChange: (page, pageSize) => {
  124. setCurrentPage(page);
  125. },
  126. }}
  127. />
  128. )}
  129. </PageContainer>
  130. <Modal
  131. title="移动/复制到"
  132. width={440}
  133. open={open}
  134. onCancel={() => setOpen(false)}
  135. centered
  136. footer={
  137. <div>
  138. <Button className="m-r-8px" onClick={() => setOpen(false)}>
  139. 取消
  140. </Button>
  141. <Button
  142. className="m-r-8px"
  143. type="primary"
  144. onClick={() => setOpen(false)}
  145. >
  146. 移动
  147. </Button>
  148. <Button type="primary" onClick={() => setOpen(false)}>
  149. 复制
  150. </Button>
  151. </div>
  152. }
  153. >
  154. <div className="min-h-300px">
  155. <Tree treeData={folderTreeData} showIcon blockNode />
  156. </div>
  157. </Modal>
  158. </>
  159. );
  160. }