AutoAccessTaskAdd.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. import React, { useState } from "react";
  2. import { Form, Input, Button, Card, message, Space, Select } from "antd";
  3. import { ArrowLeftOutlined, SaveOutlined } from "@ant-design/icons";
  4. import { useNavigate } from "react-router-dom";
  5. import { autoAccessTasksApi } from "../services/api";
  6. import { generateSearchTaskId } from "./PendingToolsAdd";
  7. import { WEBSITE_LOCATION_OPTIONS } from "./ToolsLibraryDetail";
  8. const { TextArea } = Input;
  9. const { Option } = Select;
  10. export const ACCESS_PROVIDER_OPTIONS = [
  11. { value: "official", label: "official" },
  12. { value: "302ai", label: "302ai" },
  13. ];
  14. const AutoAccessTaskAdd = () => {
  15. const [form] = Form.useForm();
  16. const [loading, setLoading] = useState(false);
  17. const [accessType, setAccessType] = useState(undefined);
  18. const navigate = useNavigate();
  19. // 接入方式选项
  20. const ACCESS_TYPE_OPTIONS = [
  21. { value: "api_no_crack", label: "API无破解" },
  22. { value: "api_crack", label: "API破解" },
  23. { value: "browser_auto_operate", label: "浏览器自动操作" },
  24. ];
  25. const handleSubmit = async (values) => {
  26. try {
  27. setLoading(true);
  28. const submitData = {
  29. access_task_id: generateSearchTaskId(),
  30. tools_name: values.toolsName,
  31. tools_function_name: values.toolsFunctionName,
  32. tools_function_desc: values.toolsFunctionDesc,
  33. access_type: values.accessType,
  34. api_provider: values.apiProvider || null,
  35. api_doc: values.apiDoc || null,
  36. operate_path_data: values.operatePathData || null,
  37. website_location: values.websiteLocation || null,
  38. };
  39. await autoAccessTasksApi.create(submitData);
  40. message.success("新增接入任务成功!");
  41. navigate("/auto-access-tasks");
  42. } catch (error) {
  43. console.error("新增接入任务失败:", error);
  44. message.error("新增接入任务失败,请重试");
  45. } finally {
  46. setLoading(false);
  47. }
  48. };
  49. const handleBack = () => {
  50. navigate("/auto-access-tasks");
  51. };
  52. const handleAccessTypeChange = (value) => {
  53. setAccessType(value);
  54. // 清空相关字段
  55. form.setFieldsValue({
  56. apiProvider: undefined,
  57. apiDoc: undefined,
  58. operatePathData: undefined,
  59. });
  60. };
  61. return (
  62. <div className="p-6">
  63. <Card
  64. title={
  65. <div style={{ display: "flex", alignItems: "center", justifyContent: "space-between", width: "100%" }}>
  66. <Button
  67. type="text"
  68. icon={<ArrowLeftOutlined />}
  69. onClick={handleBack}
  70. >
  71. 返回列表
  72. </Button>
  73. <span style={{ fontSize: "18px", fontWeight: "bold", flex: 1, textAlign: "center" }}>新增接入任务</span>
  74. <div style={{ width: "80px" }}></div>
  75. </div>
  76. }
  77. >
  78. <Form
  79. form={form}
  80. layout="vertical"
  81. onFinish={handleSubmit}
  82. autoComplete="off"
  83. >
  84. <Form.Item
  85. label="工具名称"
  86. name="toolsName"
  87. rules={[
  88. { required: true, message: "请输入工具名称" },
  89. { max: 100, message: "工具名称不能超过100个字符" },
  90. ]}
  91. >
  92. <Input placeholder="请输入工具名称" />
  93. </Form.Item>
  94. <Form.Item
  95. label="接入方式"
  96. name="accessType"
  97. rules={[{ required: true, message: "请选择接入方式" }]}
  98. >
  99. <Select
  100. placeholder="请选择接入方式"
  101. onChange={handleAccessTypeChange}
  102. >
  103. {ACCESS_TYPE_OPTIONS.map((option) => (
  104. <Option
  105. key={option.value}
  106. value={option.value}
  107. >
  108. {option.label}
  109. </Option>
  110. ))}
  111. </Select>
  112. </Form.Item>
  113. {/* API接入方式时显示的字段 */}
  114. {(accessType === "api_no_crack" || accessType === "api_crack") && (
  115. <>
  116. <Form.Item
  117. label="API提供方"
  118. name="apiProvider"
  119. rules={[{ required: true, message: "请选择API提供方" }]}
  120. >
  121. <Select placeholder="请选择API提供方">
  122. {ACCESS_PROVIDER_OPTIONS.map((option) => (
  123. <Option
  124. key={option.value}
  125. value={option.value}
  126. >
  127. {option.label}
  128. </Option>
  129. ))}
  130. </Select>
  131. </Form.Item>
  132. <Form.Item
  133. label="API文档"
  134. name="apiDoc"
  135. rules={[
  136. { required: true, message: "请输入API文档" },
  137. { max: 500, message: "API文档不能超过500个字符" },
  138. ]}
  139. >
  140. <TextArea
  141. rows={4}
  142. placeholder="请输入API文档内容或链接"
  143. showCount
  144. maxLength={500}
  145. />
  146. </Form.Item>
  147. </>
  148. )}
  149. {/* 浏览器自动操作接入方式时显示的字段 */}
  150. {accessType === "browser_auto_operate" && (
  151. <Form.Item
  152. label="操作路径数据"
  153. name="operatePathData"
  154. rules={[
  155. { required: true, message: "请输入操作路径数据" },
  156. { max: 1000, message: "操作路径数据不能超过1000个字符" },
  157. ]}
  158. >
  159. <TextArea
  160. rows={6}
  161. placeholder="请输入浏览器自动操作的路径数据"
  162. showCount
  163. maxLength={1000}
  164. />
  165. </Form.Item>
  166. )}
  167. <Form.Item
  168. label="网站位置"
  169. name="websiteLocation"
  170. rules={[{ max: 200, message: "网站位置不能超过200个字符" }]}
  171. >
  172. <Select placeholder="请选择网站位置">
  173. {WEBSITE_LOCATION_OPTIONS.map((option) => (
  174. <Option
  175. key={option.value}
  176. value={option.value}
  177. >
  178. {option.label}
  179. </Option>
  180. ))}
  181. </Select>
  182. </Form.Item>
  183. <Form.Item
  184. label="工具功能名称"
  185. name="toolsFunctionName"
  186. rules={[{ max: 100, message: "工具功能名称不能超过100个字符" }]}
  187. >
  188. <Input placeholder="请输入工具功能名称" />
  189. </Form.Item>
  190. <Form.Item
  191. label="工具功能描述"
  192. name="toolsFunctionDesc"
  193. rules={[{ max: 500, message: "工具功能描述不能超过500个字符" }]}
  194. >
  195. <TextArea
  196. rows={4}
  197. placeholder="请输入工具功能描述"
  198. showCount
  199. maxLength={500}
  200. />
  201. </Form.Item>
  202. <Form.Item style={{ textAlign: "center" }}>
  203. <Space>
  204. <Button
  205. type="primary"
  206. htmlType="submit"
  207. loading={loading}
  208. icon={<SaveOutlined />}
  209. >
  210. 保存
  211. </Button>
  212. <Button onClick={handleBack}>取消</Button>
  213. </Space>
  214. </Form.Item>
  215. </Form>
  216. </Card>
  217. </div>
  218. );
  219. };
  220. export default AutoAccessTaskAdd;