|
@@ -1,7 +1,18 @@
|
|
|
-import React, { useState, useEffect } from 'react'
|
|
|
+import React, { useState, useEffect, useRef } from 'react'
|
|
|
import styled from 'styled-components'
|
|
|
-import { Form, Select, Input, Radio, Space, message } from 'antd'
|
|
|
+import {
|
|
|
+ Form,
|
|
|
+ Select,
|
|
|
+ Input,
|
|
|
+ Radio,
|
|
|
+ Space,
|
|
|
+ message,
|
|
|
+ Divider,
|
|
|
+ Button,
|
|
|
+} from 'antd'
|
|
|
+import { PlusOutlined } from '@ant-design/icons'
|
|
|
import { getTagList } from '../services'
|
|
|
+import { months } from 'moment'
|
|
|
|
|
|
const FormWrapper = styled.div`
|
|
|
.singletask_form {
|
|
@@ -27,26 +38,57 @@ const layout = {
|
|
|
},
|
|
|
}
|
|
|
|
|
|
+const units = {
|
|
|
+ 分: 'min',
|
|
|
+ 时: 'hour',
|
|
|
+ 日: 'day',
|
|
|
+ 周: 'week',
|
|
|
+ 月: 'month',
|
|
|
+}
|
|
|
+
|
|
|
const TaskForm = ({
|
|
|
taskForm,
|
|
|
taskType,
|
|
|
+ taskInfo,
|
|
|
jmWorkList,
|
|
|
setCronNum,
|
|
|
setCronUnit,
|
|
|
}) => {
|
|
|
const [radioValue, setRadioValue] = useState(null)
|
|
|
+ const [cronNumValue, setCronNumValue] = useState('')
|
|
|
+ const [cronUnitValue, setCronUnitValue] = useState(null)
|
|
|
const [tagOptions, setTagOptions] = useState([])
|
|
|
const [jmWorkOptions, setJmWorkOptions] = useState([])
|
|
|
+ const [tag, setTag] = useState(null)
|
|
|
+ const inputRef = useRef(null)
|
|
|
+
|
|
|
+ const onNameChange = event => {
|
|
|
+ setTag(event.target.value)
|
|
|
+ }
|
|
|
+
|
|
|
+ const addItem = e => {
|
|
|
+ e.preventDefault()
|
|
|
+ if (tag !== null) {
|
|
|
+ setTagOptions([...tagOptions, tag])
|
|
|
+ setTag(null)
|
|
|
+ }
|
|
|
+ setTimeout(() => {
|
|
|
+ inputRef.current?.focus()
|
|
|
+ }, 0)
|
|
|
+ }
|
|
|
|
|
|
const onRadioChange = e => {
|
|
|
setRadioValue(e.target.value)
|
|
|
}
|
|
|
|
|
|
const onCronNumChange = e => {
|
|
|
+ setCronNumValue(e.target.value)
|
|
|
setCronNum(e.target.value)
|
|
|
}
|
|
|
|
|
|
const onCronUnitChange = params => {
|
|
|
+ console.log(params)
|
|
|
+ setCronUnitValue(params)
|
|
|
setCronUnit(params?.label)
|
|
|
}
|
|
|
|
|
@@ -59,6 +101,26 @@ const TaskForm = ({
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ const handleInitTask = taskInfo => {
|
|
|
+ console.log(taskInfo)
|
|
|
+ setRadioValue(taskInfo.cron_type)
|
|
|
+ if (taskInfo.cron_type === 2) {
|
|
|
+ setCronNumValue(taskInfo.cron_num)
|
|
|
+ setCronNum(taskInfo.cron_num)
|
|
|
+ setCronUnitValue({
|
|
|
+ value: units[taskInfo.cron_unit],
|
|
|
+ label: taskInfo.cron_unit,
|
|
|
+ })
|
|
|
+ setCronUnit(taskInfo.cron_unit)
|
|
|
+ }
|
|
|
+ taskForm.setFieldsValue({
|
|
|
+ taskName: taskInfo.name,
|
|
|
+ taskTag: taskInfo.tag,
|
|
|
+ job: taskInfo.nodes[0].homework_id,
|
|
|
+ executionCycle: taskInfo.cron_type,
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
//初始化tag列表
|
|
|
useEffect(() => {
|
|
|
fetchTagList()
|
|
@@ -69,6 +131,10 @@ const TaskForm = ({
|
|
|
setJmWorkOptions(jmWorkList)
|
|
|
}, [jmWorkList])
|
|
|
|
|
|
+ useEffect(() => {
|
|
|
+ if (taskInfo !== null) handleInitTask(taskInfo)
|
|
|
+ }, [taskInfo])
|
|
|
+
|
|
|
return (
|
|
|
<FormWrapper>
|
|
|
<Form {...layout} form={taskForm} className="singletask_form">
|
|
@@ -82,7 +148,33 @@ const TaskForm = ({
|
|
|
name="taskTag"
|
|
|
label="任务分类"
|
|
|
rules={[{ required: true, message: '请选择任务分类!' }]}>
|
|
|
- <Select placeholder="选择任务分类" allowClear>
|
|
|
+ <Select
|
|
|
+ placeholder="选择任务分类"
|
|
|
+ allowClear
|
|
|
+ dropdownRender={menu => (
|
|
|
+ <>
|
|
|
+ {menu}
|
|
|
+ <Divider
|
|
|
+ style={{
|
|
|
+ margin: '8px 0',
|
|
|
+ }}
|
|
|
+ />
|
|
|
+ <Space
|
|
|
+ style={{
|
|
|
+ padding: '0 8px 4px',
|
|
|
+ }}>
|
|
|
+ <Input
|
|
|
+ placeholder="请输入"
|
|
|
+ ref={inputRef}
|
|
|
+ value={tag}
|
|
|
+ onChange={onNameChange}
|
|
|
+ />
|
|
|
+ <Button type="text" icon={<PlusOutlined />} onClick={addItem}>
|
|
|
+ 添加新分类
|
|
|
+ </Button>
|
|
|
+ </Space>
|
|
|
+ </>
|
|
|
+ )}>
|
|
|
{tagOptions.map((item, index) => (
|
|
|
<Option key={index} value={item}>
|
|
|
{item}
|
|
@@ -110,20 +202,22 @@ const TaskForm = ({
|
|
|
rules={[{ required: true, message: '请设置执行周期!' }]}>
|
|
|
<RadioGroup onChange={onRadioChange}>
|
|
|
<Space direction="vertical">
|
|
|
- <Radio value='1'>只执行一次,下次手动执行</Radio>
|
|
|
- <Radio value='2'>
|
|
|
+ <Radio value={1}>只执行一次,下次手动执行</Radio>
|
|
|
+ <Radio value={2}>
|
|
|
执行周期
|
|
|
- {radioValue === '2' ? (
|
|
|
+ {radioValue === 2 ? (
|
|
|
<Space className="form_executionCycle">
|
|
|
<span>每</span>
|
|
|
<input
|
|
|
style={{ width: '50px' }}
|
|
|
+ value={cronNumValue}
|
|
|
onChange={onCronNumChange}
|
|
|
/>
|
|
|
<Select
|
|
|
placeholder="选择数"
|
|
|
allowClear
|
|
|
labelInValue
|
|
|
+ value={cronUnitValue}
|
|
|
onChange={onCronUnitChange}>
|
|
|
<Option value="min">分</Option>
|
|
|
<Option value="hour">时</Option>
|