import React, { useState, useEffect, useRef, forwardRef } from 'react' import styled from 'styled-components' import { Form, Select, Input, Radio, Space, message, Divider, Button, } from 'antd' import { PlusOutlined, DeleteOutlined } from '@ant-design/icons' import { getTagList, deleteTag } from '../services' import CronSelect from '../../../component/CronSelect' const FormWrapper = styled.div` .singletask_form { margin-top: 20px; } .form_executionCycle { margin-left: 10px; } ` const FormItem = Form.Item const { Option } = Select const RadioGroup = Radio.Group const layout = { labelCol: { span: 2, }, wrapperCol: { span: 10, }, } const TaskForm = ({ taskForm, taskType, taskInfo, jmWorkList }, ref) => { const [radioValue, setRadioValue] = useState(null) const [tagOptions, setTagOptions] = useState([]) const [jmWorkOptions, setJmWorkOptions] = useState([]) const [tag, setTag] = useState(null) const [cronData, setCronData] = useState(null) const inputRef = useRef(null) const onNameChange = event => { setTag(event.target.value) } const addTagItem = e => { if (tag) { e.preventDefault() if (!tagOptions.find(item => item === tag)) { setTagOptions([...tagOptions, tag]) taskForm.setFieldValue('taskTag', tag) setTag(null) setTimeout(() => { inputRef.current?.focus() }, 0) } else { message.error('存在同名标签') } } else { message.error('请输入自定义作业标签名称') } } const onDeleteTag = async val => { const { data } = await deleteTag({ type: '任务标签', val }) if (data.code === 200) { taskForm.setFieldValue('taskTag', null) message.success('删除成功') fetchTagList() } else { message.error(data.msg) } } const onRadioChange = e => { setRadioValue(e.target.value) } const fetchTagList = async () => { const { data } = await getTagList('任务标签') if (data.code === 200) { setTagOptions(data.data) } else { message.error(data.msg) } } const handleInitTask = taskInfo => { setRadioValue(taskInfo.cron_type) if (taskInfo.cron_type === 2) { setCronData(taskInfo.cron_expression_dict) } taskForm.setFieldsValue({ taskName: taskInfo.name, taskTag: taskInfo.tag, job: taskInfo.nodes[0].homework_id, executionCycle: taskInfo.cron_type, }) } //初始化tag列表 useEffect(() => { fetchTagList() }, []) //初始化作业列表 useEffect(() => { setJmWorkOptions(jmWorkList) }, [jmWorkList]) useEffect(() => { if (taskInfo !== null) handleInitTask(taskInfo) }, [taskInfo]) return (
)}> {tagOptions.map(item => ( ))} {taskType !== 'multitasking' && ( )} 只执行一次,下次手动执行 执行周期 {radioValue === 2 ? ( ) : null}
) } export default forwardRef(TaskForm)