AutoAccessTaskDetail.js 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  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 { autoAccessTasksApi } from "../services/api";
  6. import moment from "moment";
  7. const { TextArea } = Input;
  8. const { Option } = Select;
  9. const AutoAccessTaskDetail = () => {
  10. const [form] = Form.useForm();
  11. const [data, setData] = useState(null);
  12. const [loading, setLoading] = useState(true);
  13. const [saving, setSaving] = useState(false);
  14. const { id } = useParams();
  15. const navigate = useNavigate();
  16. const location = useLocation();
  17. const isEditMode = location.search.includes("mode=edit");
  18. const getStatusColor = (status) => {
  19. const statusMap = {
  20. 0: "processing",
  21. 1: "warning",
  22. 2: "success",
  23. 3: "error",
  24. 4: "error",
  25. };
  26. return statusMap[status] || "default";
  27. };
  28. const getStatusText = (status) => {
  29. const statusMap = {
  30. 0: "待处理",
  31. 1: "处理中",
  32. 2: "已完成",
  33. 3: "失败",
  34. 4: "异常",
  35. };
  36. return statusMap[status] || "未知";
  37. };
  38. const getAccessTypeText = (type) => {
  39. const typeMap = {
  40. api_no_crack: "API无破解",
  41. api_crack: "API破解",
  42. browser_auto_operate: "浏览器自动操作",
  43. };
  44. return typeMap[type] || type;
  45. };
  46. const fetchData = async () => {
  47. try {
  48. const response = await autoAccessTasksApi.getDetail(id);
  49. setData(response.data);
  50. form.setFieldsValue(response.data);
  51. } catch (error) {
  52. message.error("获取详情失败");
  53. } finally {
  54. setLoading(false);
  55. }
  56. };
  57. const handleSave = async (values) => {
  58. setSaving(true);
  59. try {
  60. await autoAccessTasksApi.update(id, values);
  61. message.success("更新成功");
  62. navigate("/auto-access-tasks");
  63. } catch (error) {
  64. message.error("更新失败");
  65. } finally {
  66. setSaving(false);
  67. }
  68. };
  69. useEffect(() => {
  70. fetchData();
  71. }, [id]);
  72. if (loading) {
  73. return (
  74. <div style={{ textAlign: "center", padding: "50px" }}>
  75. <Spin size="large" />
  76. </div>
  77. );
  78. }
  79. if (!data) {
  80. return <div>数据不存在</div>;
  81. }
  82. return (
  83. <div className="detail-container">
  84. <Button
  85. icon={<ArrowLeftOutlined />}
  86. onClick={() => navigate("/auto-access-tasks")}
  87. style={{ marginBottom: 16 }}
  88. >
  89. 返回列表
  90. </Button>
  91. {isEditMode ? (
  92. <Card
  93. title="编辑自动接入任务"
  94. style={{ marginBottom: 24 }}
  95. >
  96. <Form
  97. form={form}
  98. layout="vertical"
  99. onFinish={handleSave}
  100. className="form-container"
  101. >
  102. <Form.Item
  103. label="检索任务ID"
  104. name="search_task_id"
  105. >
  106. <Input />
  107. </Form.Item>
  108. <Form.Item
  109. label="工具名称"
  110. name="tools_name"
  111. rules={[{ required: true, message: "请输入工具名称" }]}
  112. >
  113. <Input />
  114. </Form.Item>
  115. <Form.Item
  116. label="工具功能名称"
  117. name="tools_function_name"
  118. rules={[{ required: true, message: "请输入工具功能名称" }]}
  119. >
  120. <Input />
  121. </Form.Item>
  122. <Form.Item
  123. label="接入方式"
  124. name="access_type"
  125. rules={[{ required: true, message: "请选择接入方式" }]}
  126. >
  127. <Select>
  128. <Option value="api_no_crack">API无破解</Option>
  129. <Option value="api_crack">API破解</Option>
  130. <Option value="browser_auto_operate">浏览器自动操作</Option>
  131. </Select>
  132. </Form.Item>
  133. <Form.Item
  134. label="工具功能描述"
  135. name="tools_function_desc"
  136. >
  137. <TextArea rows={4} />
  138. </Form.Item>
  139. <Form.Item
  140. label="API文档"
  141. name="api_doc"
  142. >
  143. <TextArea rows={6} />
  144. </Form.Item>
  145. <Form.Item
  146. label="API类名"
  147. name="api_class_name"
  148. >
  149. <Input />
  150. </Form.Item>
  151. <Form.Item
  152. label="操作路径数据"
  153. name="operate_path_data"
  154. >
  155. <TextArea rows={4} />
  156. </Form.Item>
  157. <Form.Item
  158. label="源内容链接"
  159. name="origin_content_link"
  160. >
  161. <Input />
  162. </Form.Item>
  163. <Form.Item
  164. label="状态"
  165. name="status"
  166. rules={[{ required: true, message: "请选择状态" }]}
  167. >
  168. <Select>
  169. <Option value={0}>待处理</Option>
  170. <Option value={1}>处理中</Option>
  171. <Option value={2}>已完成</Option>
  172. <Option value={3}>失败</Option>
  173. <Option value={4}>异常</Option>
  174. </Select>
  175. </Form.Item>
  176. <Form.Item
  177. label="失败原因"
  178. name="fail_reason"
  179. >
  180. <TextArea rows={3} />
  181. </Form.Item>
  182. <div className="button-group">
  183. <Button onClick={() => navigate("/auto-access-tasks")}>取消</Button>
  184. <Button
  185. type="primary"
  186. htmlType="submit"
  187. loading={saving}
  188. >
  189. 保存
  190. </Button>
  191. </div>
  192. </Form>
  193. </Card>
  194. ) : (
  195. <Card title="自动接入任务详情">
  196. <Descriptions
  197. column={2}
  198. bordered
  199. >
  200. <Descriptions.Item label="接入任务ID">{data.access_task_id}</Descriptions.Item>
  201. <Descriptions.Item label="检索任务ID">{data.search_task_id}</Descriptions.Item>
  202. <Descriptions.Item label="工具名称">{data.tools_name}</Descriptions.Item>
  203. <Descriptions.Item label="工具功能名称">{data.tools_function_name}</Descriptions.Item>
  204. <Descriptions.Item label="接入方式">
  205. <Tag color="blue">{getAccessTypeText(data.access_type)}</Tag>
  206. </Descriptions.Item>
  207. <Descriptions.Item label="状态">
  208. <Tag color={getStatusColor(data.status)}>{getStatusText(data.status)}</Tag>
  209. </Descriptions.Item>
  210. <Descriptions.Item
  211. label="工具功能描述"
  212. span={2}
  213. >
  214. {data.tools_function_desc}
  215. </Descriptions.Item>
  216. <Descriptions.Item
  217. label="API文档"
  218. span={2}
  219. >
  220. <div style={{ maxHeight: "200px", overflow: "auto" }}>
  221. <pre style={{ whiteSpace: "pre-wrap", wordBreak: "break-word" }}>{data.api_doc || "无"}</pre>
  222. </div>
  223. </Descriptions.Item>
  224. <Descriptions.Item label="API类名">{data.api_class_name}</Descriptions.Item>
  225. <Descriptions.Item label="源内容链接">
  226. {data.origin_content_link ? (
  227. <a
  228. href={data.origin_content_link}
  229. target="_blank"
  230. rel="noopener noreferrer"
  231. >
  232. {data.origin_content_link}
  233. </a>
  234. ) : (
  235. "无"
  236. )}
  237. </Descriptions.Item>
  238. <Descriptions.Item
  239. label="操作路径数据"
  240. span={2}
  241. >
  242. <div style={{ maxHeight: "200px", overflow: "auto" }}>
  243. <pre style={{ whiteSpace: "pre-wrap", wordBreak: "break-word" }}>{data.operate_path_data || "无"}</pre>
  244. </div>
  245. </Descriptions.Item>
  246. <Descriptions.Item
  247. label="失败原因"
  248. span={2}
  249. >
  250. {data.fail_reason || "无"}
  251. </Descriptions.Item>
  252. <Descriptions.Item label="创建时间">
  253. {moment(data.create_time).format("YYYY-MM-DD HH:mm:ss")}
  254. </Descriptions.Item>
  255. <Descriptions.Item label="更新时间">
  256. {moment(data.update_time).format("YYYY-MM-DD HH:mm:ss")}
  257. </Descriptions.Item>
  258. </Descriptions>
  259. </Card>
  260. )}
  261. </div>
  262. );
  263. };
  264. export default AutoAccessTaskDetail;