|
@@ -1,9 +1,10 @@
|
|
|
-import React, { useState } from 'react'
|
|
|
+import React, { useState, useEffect } from 'react'
|
|
|
import { Form, Select, Button, Space, message } from 'antd'
|
|
|
import TaskForm from './TaskForm'
|
|
|
import TaskChartEditor from './TaskChartEditor'
|
|
|
import styled from 'styled-components'
|
|
|
import { useNavigate } from 'react-router'
|
|
|
+import { getJmHomeworkList, createJmJob } from '../services'
|
|
|
|
|
|
const TaskCreater = styled.div`
|
|
|
margin: 20px;
|
|
@@ -45,38 +46,114 @@ const TaskCreaterView = () => {
|
|
|
const navigate = useNavigate()
|
|
|
const [taskType, setTaskType] = useState(null)
|
|
|
const [graphRef, setGraphRef] = useState(null)
|
|
|
+ const [cronNum, setCronNum] = useState(null)
|
|
|
+ const [cronUnit, setCronUnit] = useState(null)
|
|
|
+ const [jmWorkList, setJmWorkList] = useState([])
|
|
|
+
|
|
|
const [taskTypeForm] = Form.useForm()
|
|
|
const [taskForm] = Form.useForm()
|
|
|
const onTaskTypeChange = value => {
|
|
|
setTaskType(value)
|
|
|
}
|
|
|
const onSubmit = () => {
|
|
|
- const cells = graphRef?.state.taskGraph.getCells()
|
|
|
const taskFormData = taskForm.getFieldsValue()
|
|
|
- taskForm
|
|
|
+ taskTypeForm
|
|
|
.validateFields()
|
|
|
.then(() => {
|
|
|
- const params = {
|
|
|
- name: taskFormData.taskName,
|
|
|
- type: taskType === 'singleTask' ? '单作业离线任务' : '多作业离线任务',
|
|
|
- tag: taskFormData.taskTag,
|
|
|
- cron_type: taskFormData.executionCycle,
|
|
|
- user_id: 'test',
|
|
|
- user_name: 'test',
|
|
|
- project_id: 'test',
|
|
|
- }
|
|
|
- console.log('###', cells, taskFormData, params)
|
|
|
+ taskForm
|
|
|
+ .validateFields()
|
|
|
+ .then(() => {
|
|
|
+ let nodes = []
|
|
|
+ let edges = []
|
|
|
+ let type = ''
|
|
|
+ if (taskType === 'singleTask') {
|
|
|
+ type = '单作业离线任务'
|
|
|
+ nodes = [
|
|
|
+ {
|
|
|
+ id: 1,
|
|
|
+ homework_id: taskFormData.job,
|
|
|
+ homework_name: jmWorkList.find(
|
|
|
+ item => item.id === taskFormData.job
|
|
|
+ ).name,
|
|
|
+ start_point: 1,
|
|
|
+ },
|
|
|
+ ]
|
|
|
+ } else {
|
|
|
+ type = '多作业离线任务'
|
|
|
+ const cells = handleNodes()
|
|
|
+ nodes = cells.nodes
|
|
|
+ edges = cells.edges
|
|
|
+ }
|
|
|
+ const params = {
|
|
|
+ name: taskFormData.taskName,
|
|
|
+ type,
|
|
|
+ tag: taskFormData.taskTag,
|
|
|
+ cron_type: taskFormData.executionCycle,
|
|
|
+ user_id: 'test',
|
|
|
+ user_name: 'test',
|
|
|
+ project_id: 'test',
|
|
|
+ nodes,
|
|
|
+ edges,
|
|
|
+ }
|
|
|
+ if (taskType === 'multitasking') {
|
|
|
+ params['json_str'] = JSON.stringify(
|
|
|
+ graphRef?.state.taskGraph.toJSON()
|
|
|
+ )
|
|
|
+ }
|
|
|
+ if (taskFormData.executionCycle === '2') {
|
|
|
+ params['cron_num'] = cronNum
|
|
|
+ params['cron_unit'] = cronUnit
|
|
|
+ }
|
|
|
+ createJmJob(params).then(() => {
|
|
|
+ navigate(-1)
|
|
|
+ })
|
|
|
+ })
|
|
|
+ .catch(err => {
|
|
|
+ message.error('请检查表单数据是否完整')
|
|
|
+ })
|
|
|
})
|
|
|
.catch(err => {
|
|
|
message.error('请检查表单数据是否完整')
|
|
|
})
|
|
|
- // navigate(-1)
|
|
|
+ }
|
|
|
+
|
|
|
+ const handleNodes = () => {
|
|
|
+ const cells = graphRef?.state.taskGraph.getCells()
|
|
|
+ const nodes = []
|
|
|
+ const edges = []
|
|
|
+ cells.forEach(cell => {
|
|
|
+ console.log(cell)
|
|
|
+ if (cell.shape === 'task-node') {
|
|
|
+ nodes.push({
|
|
|
+ id: cell.id,
|
|
|
+ homework_id: cell.data.homework_id,
|
|
|
+ homework_name: cell.data.label,
|
|
|
+ start_point: cell.data.type === 'work' ? 1 : 0,
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ edges.push({ source: cell.source.cell, target: cell.target.cell })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ return { nodes, edges }
|
|
|
}
|
|
|
|
|
|
const onGraphRef = ref => {
|
|
|
setGraphRef(ref)
|
|
|
}
|
|
|
|
|
|
+ const fetchJmWorkList = async () => {
|
|
|
+ const { data } = await getJmHomeworkList('test')
|
|
|
+ if (data.code === 200) {
|
|
|
+ setJmWorkList(data.data)
|
|
|
+ } else {
|
|
|
+ message.error(data.msg)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //初始化作业列表
|
|
|
+ useEffect(() => {
|
|
|
+ fetchJmWorkList()
|
|
|
+ }, [])
|
|
|
+
|
|
|
return (
|
|
|
<TaskCreater>
|
|
|
<div className="tasktype_label">配置任务类型:</div>
|
|
@@ -95,11 +172,19 @@ const TaskCreaterView = () => {
|
|
|
</FormItem>
|
|
|
</Form>
|
|
|
<div className="tasktype_label">配置任务信息:</div>
|
|
|
- <TaskForm taskForm={taskForm} taskType={taskType} />
|
|
|
+ <TaskForm
|
|
|
+ taskForm={taskForm}
|
|
|
+ taskType={taskType}
|
|
|
+ jmWorkList={jmWorkList}
|
|
|
+ setCronNum={cron_num => setCronNum(cron_num)}
|
|
|
+ setCronUnit={cron_unit => setCronUnit(cron_unit)}
|
|
|
+ />
|
|
|
{taskType === 'multitasking' && (
|
|
|
<div className="tasktype_label">作业编排:</div>
|
|
|
)}
|
|
|
- {taskType === 'multitasking' && <TaskChartEditor onRef={onGraphRef} />}
|
|
|
+ {taskType === 'multitasking' && (
|
|
|
+ <TaskChartEditor onRef={onGraphRef} jmWorkList={jmWorkList} />
|
|
|
+ )}
|
|
|
<Space className="tasktype_btns">
|
|
|
<Button onClick={() => navigate(-1)}>取消</Button>
|
|
|
<Button onClick={onSubmit}>提交</Button>
|