PendingToolsDetail.js 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. import React, { useState, useEffect } from "react";
  2. import { Form, Input, Select, Button, Card, Descriptions, Tag, message, Spin } from "antd";
  3. import { useParams, useNavigate, useLocation } from "react-router-dom";
  4. import { ArrowLeftOutlined } from "@ant-design/icons";
  5. import { pendingToolsApi } from "../services/api";
  6. import moment from "moment";
  7. import { STATUS_TAG_COLOR, STATUS_MAP } from "./PendingToolsList";
  8. const { TextArea } = Input;
  9. const { Option } = Select;
  10. const PendingToolsDetail = () => {
  11. const [form] = Form.useForm();
  12. const [data, setData] = useState(null);
  13. const [loading, setLoading] = useState(true);
  14. const [saving, setSaving] = useState(false);
  15. const { id } = useParams();
  16. const navigate = useNavigate();
  17. const location = useLocation();
  18. const isEditMode = location.search.includes("mode=edit");
  19. const getStatusColor = (status) => {
  20. return STATUS_TAG_COLOR[status] || "default";
  21. };
  22. const getStatusText = (status) => {
  23. return STATUS_MAP[status] || "未知";
  24. };
  25. const fetchData = async () => {
  26. try {
  27. const response = await pendingToolsApi.getDetail(id);
  28. setData(response.data);
  29. if (response.data.task) {
  30. form.setFieldsValue(response.data.task);
  31. }
  32. } catch (error) {
  33. message.error("获取详情失败");
  34. } finally {
  35. setLoading(false);
  36. }
  37. };
  38. const handleSave = async (values) => {
  39. setSaving(true);
  40. try {
  41. await pendingToolsApi.update(id, values);
  42. message.success("更新成功");
  43. navigate("/pending-tools");
  44. } catch (error) {
  45. message.error("更新失败");
  46. } finally {
  47. setSaving(false);
  48. }
  49. };
  50. useEffect(() => {
  51. fetchData();
  52. }, [id]);
  53. if (loading) {
  54. return (
  55. <div className="loading-container">
  56. <Spin size="large" />
  57. </div>
  58. );
  59. }
  60. if (!data) {
  61. return (
  62. <div className="error-container">
  63. <div className="text-red-500 text-lg">数据不存在</div>
  64. </div>
  65. );
  66. }
  67. return (
  68. <div className="space-y-6">
  69. <div className="flex items-center justify-between">
  70. <Button
  71. icon={<ArrowLeftOutlined />}
  72. onClick={() => navigate("/pending-tools")}
  73. className="hover:bg-gray-50"
  74. >
  75. 返回列表
  76. </Button>
  77. <div className="text-sm text-gray-500">{isEditMode ? "编辑模式" : "查看模式"}</div>
  78. </div>
  79. {isEditMode ? (
  80. <Card
  81. title="编辑待接入工具"
  82. className="shadow-lg border-0"
  83. >
  84. <Form
  85. form={form}
  86. layout="vertical"
  87. onFinish={handleSave}
  88. className="form-container"
  89. >
  90. <Form.Item
  91. label="工具名称"
  92. name="tools_name"
  93. rules={[{ required: true, message: "请输入工具名称" }]}
  94. >
  95. <Input />
  96. </Form.Item>
  97. <Form.Item
  98. label="工具功能名称"
  99. name="tools_function_name"
  100. rules={[{ required: true, message: "请输入工具功能名称" }]}
  101. >
  102. <Input />
  103. </Form.Item>
  104. <Form.Item
  105. label="状态"
  106. name="status"
  107. rules={[{ required: true, message: "请选择状态" }]}
  108. >
  109. <Select>
  110. <Option value={0}>待处理</Option>
  111. <Option value={1}>处理中</Option>
  112. <Option value={2}>已完成</Option>
  113. <Option value={3}>失败</Option>
  114. <Option value={4}>待审核</Option>
  115. </Select>
  116. </Form.Item>
  117. <Form.Item
  118. label="工具功能描述"
  119. name="tools_function_desc"
  120. >
  121. <TextArea rows={4} />
  122. </Form.Item>
  123. <Form.Item
  124. label="失败原因"
  125. name="fail_reason"
  126. >
  127. <TextArea rows={3} />
  128. </Form.Item>
  129. <div className="button-group">
  130. <Button onClick={() => navigate("/pending-tools")}>取消</Button>
  131. <Button
  132. type="primary"
  133. htmlType="submit"
  134. loading={saving}
  135. >
  136. 保存
  137. </Button>
  138. </div>
  139. </Form>
  140. </Card>
  141. ) : (
  142. <div className="space-y-6">
  143. <Card
  144. title="基本信息"
  145. className="shadow-lg border-0"
  146. >
  147. <Descriptions
  148. column={2}
  149. bordered
  150. size="small"
  151. >
  152. <Descriptions.Item label="工具ID">{data.task.search_task_id}</Descriptions.Item>
  153. <Descriptions.Item label="工具名称">{data.task.tools_name}</Descriptions.Item>
  154. <Descriptions.Item label="工具功能名称">{data.task.tools_function_name}</Descriptions.Item>
  155. <Descriptions.Item label="状态">
  156. <Tag color={getStatusColor(data.task.status)}>{getStatusText(data.task.status)}</Tag>
  157. </Descriptions.Item>
  158. <Descriptions.Item
  159. label="工具功能描述"
  160. span={2}
  161. >
  162. {data.task.tools_function_desc}
  163. </Descriptions.Item>
  164. <Descriptions.Item
  165. label="失败原因"
  166. span={2}
  167. >
  168. {data.task.fail_reason || "无"}
  169. </Descriptions.Item>
  170. <Descriptions.Item label="创建时间">
  171. {moment(data.task.create_time).format("YYYY-MM-DD HH:mm:ss")}
  172. </Descriptions.Item>
  173. <Descriptions.Item label="更新时间">
  174. {moment(data.task.update_time).format("YYYY-MM-DD HH:mm:ss")}
  175. </Descriptions.Item>
  176. </Descriptions>
  177. </Card>
  178. {data.detail && (
  179. <Card
  180. title="详细信息"
  181. className="shadow-lg border-0"
  182. >
  183. <Descriptions
  184. column={2}
  185. bordered
  186. size="small"
  187. >
  188. <Descriptions.Item label="检索渠道">{data.detail.search_channel}</Descriptions.Item>
  189. <Descriptions.Item
  190. label="检索结果"
  191. span={2}
  192. >
  193. <div style={{ maxHeight: "200px", overflow: "auto" }}>
  194. <pre style={{ whiteSpace: "pre-wrap", wordBreak: "break-word" }}>
  195. {data.detail.search_result || "无"}
  196. </pre>
  197. </div>
  198. </Descriptions.Item>
  199. </Descriptions>
  200. </Card>
  201. )}
  202. </div>
  203. )}
  204. </div>
  205. );
  206. };
  207. export default PendingToolsDetail;