123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218 |
- import React, { useState } from "react";
- import { Form, Input, Button, Card, message, Space, Select } from "antd";
- import { ArrowLeftOutlined, SaveOutlined } from "@ant-design/icons";
- import { useNavigate } from "react-router-dom";
- import { autoAccessTasksApi } from "../services/api";
- import { generateSearchTaskId } from "./PendingToolsAdd";
- const { TextArea } = Input;
- const { Option } = Select;
- export const ACCESS_PROVIDER_OPTIONS = [
- { value: "official", label: "official" },
- { value: "302ai", label: "302ai" },
- ];
- const AutoAccessTaskAdd = () => {
- const [form] = Form.useForm();
- const [loading, setLoading] = useState(false);
- const [accessType, setAccessType] = useState(undefined);
- const navigate = useNavigate();
- // 接入方式选项
- const ACCESS_TYPE_OPTIONS = [
- { value: "api_no_crack", label: "API无破解" },
- { value: "api_crack", label: "API破解" },
- { value: "browser_auto_operate", label: "浏览器自动操作" },
- ];
- const handleSubmit = async (values) => {
- try {
- setLoading(true);
- const submitData = {
- access_task_id: generateSearchTaskId(),
- tools_name: values.toolsName,
- tools_function_name: values.toolsFunctionName,
- tools_function_desc: values.toolsFunctionDesc,
- access_type: values.accessType,
- api_provider: values.apiProvider || null,
- api_doc: values.apiDoc || null,
- operate_path_data: values.operatePathData || null,
- };
- await autoAccessTasksApi.create(submitData);
- message.success("新增接入任务成功!");
- navigate("/auto-access-tasks");
- } catch (error) {
- console.error("新增接入任务失败:", error);
- message.error("新增接入任务失败,请重试");
- } finally {
- setLoading(false);
- }
- };
- const handleBack = () => {
- navigate("/auto-access-tasks");
- };
- const handleAccessTypeChange = (value) => {
- setAccessType(value);
- // 清空相关字段
- form.setFieldsValue({
- apiProvider: undefined,
- apiDoc: undefined,
- operatePathData: undefined,
- });
- };
- return (
- <div className="p-6">
- <Card
- title={
- <div style={{ display: "flex", alignItems: "center", justifyContent: "space-between", width: "100%" }}>
- <Button
- type="text"
- icon={<ArrowLeftOutlined />}
- onClick={handleBack}
- >
- 返回列表
- </Button>
- <span style={{ fontSize: "18px", fontWeight: "bold", flex: 1, textAlign: "center" }}>新增接入任务</span>
- <div style={{ width: "80px" }}></div>
- </div>
- }
- >
- <Form
- form={form}
- layout="vertical"
- onFinish={handleSubmit}
- autoComplete="off"
- >
- <Form.Item
- label="工具名称"
- name="toolsName"
- rules={[
- { required: true, message: "请输入工具名称" },
- { max: 100, message: "工具名称不能超过100个字符" },
- ]}
- >
- <Input placeholder="请输入工具名称" />
- </Form.Item>
- <Form.Item
- label="接入方式"
- name="accessType"
- rules={[{ required: true, message: "请选择接入方式" }]}
- >
- <Select
- placeholder="请选择接入方式"
- onChange={handleAccessTypeChange}
- >
- {ACCESS_TYPE_OPTIONS.map((option) => (
- <Option
- key={option.value}
- value={option.value}
- >
- {option.label}
- </Option>
- ))}
- </Select>
- </Form.Item>
- {/* API接入方式时显示的字段 */}
- {(accessType === "api_no_crack" || accessType === "api_crack") && (
- <>
- <Form.Item
- label="API提供方"
- name="apiProvider"
- rules={[{ required: true, message: "请选择API提供方" }]}
- >
- <Select placeholder="请选择API提供方">
- {ACCESS_PROVIDER_OPTIONS.map((option) => (
- <Option
- key={option.value}
- value={option.value}
- >
- {option.label}
- </Option>
- ))}
- </Select>
- </Form.Item>
- <Form.Item
- label="API文档"
- name="apiDoc"
- rules={[
- { required: true, message: "请输入API文档" },
- { max: 500, message: "API文档不能超过500个字符" },
- ]}
- >
- <TextArea
- rows={4}
- placeholder="请输入API文档内容或链接"
- showCount
- maxLength={500}
- />
- </Form.Item>
- </>
- )}
- {/* 浏览器自动操作接入方式时显示的字段 */}
- {accessType === "browser_auto_operate" && (
- <Form.Item
- label="操作路径数据"
- name="operatePathData"
- rules={[
- { required: true, message: "请输入操作路径数据" },
- { max: 1000, message: "操作路径数据不能超过1000个字符" },
- ]}
- >
- <TextArea
- rows={6}
- placeholder="请输入浏览器自动操作的路径数据"
- showCount
- maxLength={1000}
- />
- </Form.Item>
- )}
- <Form.Item
- label="工具功能名称"
- name="toolsFunctionName"
- rules={[{ max: 100, message: "工具功能名称不能超过100个字符" }]}
- >
- <Input placeholder="请输入工具功能名称" />
- </Form.Item>
- <Form.Item
- label="工具功能描述"
- name="toolsFunctionDesc"
- rules={[{ max: 500, message: "工具功能描述不能超过500个字符" }]}
- >
- <TextArea
- rows={4}
- placeholder="请输入工具功能描述"
- showCount
- maxLength={500}
- />
- </Form.Item>
- <Form.Item style={{ textAlign: "center" }}>
- <Space>
- <Button
- type="primary"
- htmlType="submit"
- loading={loading}
- icon={<SaveOutlined />}
- >
- 保存
- </Button>
- <Button onClick={handleBack}>取消</Button>
- </Space>
- </Form.Item>
- </Form>
- </Card>
- </div>
- );
- };
- export default AutoAccessTaskAdd;
|