PendingToolsList.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. import React, { useState, useEffect } from "react";
  2. import { Table, Button, Input, Space, Tag, message, Modal, Tooltip } from "antd";
  3. import { SearchOutlined, EditOutlined, DeleteOutlined, EyeOutlined } from "@ant-design/icons";
  4. import { useNavigate } from "react-router-dom";
  5. import { pendingToolsApi } from "../services/api";
  6. import moment from "moment";
  7. import { render } from "@testing-library/react";
  8. const { Search } = Input;
  9. const { confirm } = Modal;
  10. const PendingToolsList = () => {
  11. const [data, setData] = useState([]);
  12. const [loading, setLoading] = useState(false);
  13. const [pagination, setPagination] = useState({
  14. current: 1,
  15. pageSize: 10,
  16. total: 0,
  17. });
  18. const [searchText, setSearchText] = useState("");
  19. const navigate = useNavigate();
  20. const getStatusColor = (status) => {
  21. const statusMap = {
  22. 0: "processing",
  23. 1: "warning",
  24. 2: "success",
  25. 3: "error",
  26. 4: "pending",
  27. };
  28. return statusMap[status] || "default";
  29. };
  30. const getStatusText = (status) => {
  31. const statusMap = {
  32. 0: "待处理",
  33. 1: "处理中",
  34. 2: "已完成",
  35. 3: "失败",
  36. 4: "待审核",
  37. };
  38. return statusMap[status] || "未知";
  39. };
  40. const columns = [
  41. {
  42. title: "工具ID",
  43. dataIndex: "search_task_id",
  44. key: "search_task_id",
  45. width: 150,
  46. ellipsis: true,
  47. render: (text) => (
  48. <Tooltip title={text}>
  49. <span className="cursor-pointer">{text}</span>
  50. </Tooltip>
  51. ),
  52. },
  53. {
  54. title: "工具名称",
  55. dataIndex: "tools_name",
  56. key: "tools_name",
  57. width: 150,
  58. },
  59. {
  60. title: "工具功能名称",
  61. dataIndex: "tools_function_name",
  62. key: "tools_function_name",
  63. width: 200,
  64. },
  65. {
  66. title: "工具功能描述",
  67. dataIndex: "tools_function_desc",
  68. key: "tools_function_desc",
  69. width: 300,
  70. ellipsis: true,
  71. render: (text) => (
  72. <Tooltip title={text}>
  73. <span className="cursor-pointer">{text}</span>
  74. </Tooltip>
  75. ),
  76. },
  77. {
  78. title: "状态",
  79. dataIndex: "status",
  80. key: "status",
  81. width: 100,
  82. render: (status) => <Tag color={getStatusColor(status)}>{getStatusText(status)}</Tag>,
  83. },
  84. {
  85. title: "失败原因",
  86. dataIndex: "fail_reason",
  87. key: "fail_reason",
  88. width: 200,
  89. },
  90. {
  91. title: "创建时间",
  92. dataIndex: "create_time",
  93. key: "create_time",
  94. width: 180,
  95. render: (time) => moment(time).format("YYYY-MM-DD HH:mm:ss"),
  96. },
  97. {
  98. title: "更新时间",
  99. dataIndex: "update_time",
  100. key: "update_time",
  101. width: 180,
  102. render: (time) => moment(time).format("YYYY-MM-DD HH:mm:ss"),
  103. },
  104. {
  105. title: "操作",
  106. key: "action",
  107. width: 150,
  108. fixed: "right",
  109. render: (_, record) => (
  110. <Space size="small">
  111. <Button
  112. type="primary"
  113. size="small"
  114. icon={<EyeOutlined />}
  115. onClick={() => navigate(`/pending-tools/${record.search_task_id}`)}
  116. >
  117. 详情
  118. </Button>
  119. <Button
  120. size="small"
  121. icon={<EditOutlined />}
  122. onClick={() => navigate(`/pending-tools/${record.search_task_id}?mode=edit`)}
  123. >
  124. 编辑
  125. </Button>
  126. {/* <Button
  127. danger
  128. size="small"
  129. icon={<DeleteOutlined />}
  130. onClick={() => handleDelete(record.search_task_id)}
  131. >
  132. 删除
  133. </Button> */}
  134. </Space>
  135. ),
  136. },
  137. ];
  138. const fetchData = async (page = 1, pageSize = 10, search = "") => {
  139. setLoading(true);
  140. try {
  141. const response = await pendingToolsApi.getList({
  142. page,
  143. pageSize,
  144. search,
  145. });
  146. setData(response.data.data);
  147. setPagination({
  148. current: response.data.page,
  149. pageSize: response.data.pageSize,
  150. total: response.data.total,
  151. });
  152. } catch (error) {
  153. message.error("获取数据失败");
  154. } finally {
  155. setLoading(false);
  156. }
  157. };
  158. const handleTableChange = (paginationConfig) => {
  159. fetchData(paginationConfig.current, paginationConfig.pageSize, searchText);
  160. };
  161. const handleSearch = (value) => {
  162. setSearchText(value);
  163. fetchData(1, pagination.pageSize, value);
  164. };
  165. const handleDelete = (id) => {
  166. confirm({
  167. title: "确认删除",
  168. content: "确定要删除这个工具吗?",
  169. okText: "确认",
  170. cancelText: "取消",
  171. onOk: async () => {
  172. try {
  173. await pendingToolsApi.delete(id);
  174. message.success("删除成功");
  175. fetchData(pagination.current, pagination.pageSize, searchText);
  176. } catch (error) {
  177. message.error("删除失败");
  178. }
  179. },
  180. });
  181. };
  182. useEffect(() => {
  183. fetchData();
  184. }, []);
  185. return (
  186. <div className="space-y-6">
  187. <div className="table-container">
  188. <div className="mb-6">
  189. <Search
  190. placeholder="搜索工具名称、功能名称或描述"
  191. allowClear
  192. enterButton={<SearchOutlined />}
  193. size="large"
  194. onSearch={handleSearch}
  195. className="max-w-md"
  196. />
  197. </div>
  198. <Table
  199. columns={columns}
  200. dataSource={data}
  201. rowKey="search_task_id"
  202. pagination={pagination}
  203. loading={loading}
  204. onChange={handleTableChange}
  205. scroll={{ x: 1500 }}
  206. size="middle"
  207. className="shadow-sm"
  208. />
  209. </div>
  210. </div>
  211. );
  212. };
  213. export default PendingToolsList;