feat:添加任务
This commit is contained in:
parent
c46fbd2646
commit
667faed54d
|
@ -11,16 +11,30 @@ import {
|
|||
import ParentTask from "../ParentTask";
|
||||
import DatePickerItem from "../DataPickerItem"
|
||||
import "./index.css"
|
||||
import {addTask} from "../../utils";
|
||||
export default () => {
|
||||
const now = new Date()
|
||||
const [form] = Form.useForm();
|
||||
const onFinish = (values) => {
|
||||
// Dialog.alert({
|
||||
// content: <pre>{JSON.stringify(values, null, 2)}</pre>,
|
||||
// })
|
||||
console.log(values)
|
||||
if (values.pidArray===undefined){
|
||||
values.pid='0'
|
||||
}else {
|
||||
values.pid=values.pidArray[values.pidArray.length-1];
|
||||
}
|
||||
addTask(values).then(values=>{
|
||||
Dialog.alert({
|
||||
content: <pre>{JSON.stringify(values, null, 2)}</pre>,
|
||||
content: '添加任务成功' + values.data,
|
||||
onConfirm:()=>{}
|
||||
})
|
||||
})
|
||||
}
|
||||
return (
|
||||
<>
|
||||
<Form
|
||||
form={form}
|
||||
layout='horizontal'
|
||||
onFinish={onFinish}
|
||||
footer={
|
||||
|
@ -29,7 +43,7 @@ export default () => {
|
|||
</Button>
|
||||
}
|
||||
>
|
||||
<ParentTask/>
|
||||
<ParentTask form = {form}/>
|
||||
<Form.Item
|
||||
name='name'
|
||||
label='任务名称'
|
||||
|
@ -48,9 +62,9 @@ export default () => {
|
|||
<Form.Item name='state' label='任务状态' required>
|
||||
<Radio.Group>
|
||||
<Space direction='vertical'>
|
||||
<Radio value='1'><Tag color='danger'>未开始</Tag></Radio>
|
||||
<Radio value='2'><Tag color='warning'>进行中</Tag></Radio>
|
||||
<Radio value='3'><Tag color='success'>已完成</Tag></Radio>
|
||||
<Radio value='8'><Tag color='danger'>未开始</Tag></Radio>
|
||||
<Radio value='9'><Tag color='warning'>进行中</Tag></Radio>
|
||||
<Radio value='7'><Tag color='success'>已完成</Tag></Radio>
|
||||
<Radio value='4'><Tag>已关闭</Tag></Radio>
|
||||
</Space>
|
||||
</Radio.Group>
|
||||
|
@ -58,10 +72,10 @@ export default () => {
|
|||
<Form.Item name='priority' label='任务优先级'>
|
||||
<Radio.Group>
|
||||
<Space direction='vertical'>
|
||||
<Radio value='1'><Tag color='danger'>紧急重要</Tag></Radio>
|
||||
<Radio value='3'><Tag color='danger'>紧急重要</Tag></Radio>
|
||||
<Radio value='2'><Tag color='warning'>不紧急重要</Tag></Radio>
|
||||
<Radio value='3'><Tag>紧急不重要</Tag></Radio>
|
||||
<Radio value='4'><Tag color='success'>不紧急不重要</Tag></Radio>
|
||||
<Radio value='1'><Tag>紧急不重要</Tag></Radio>
|
||||
<Radio value='0'><Tag color='success'>不紧急不重要</Tag></Radio>
|
||||
</Space>
|
||||
</Radio.Group>
|
||||
</Form.Item>
|
||||
|
|
|
@ -1,167 +1,69 @@
|
|||
import {Cascader,Input, Toast} from "antd-mobile";
|
||||
import React, {useState} from "react";
|
||||
import React, {useEffect, useMemo, useState} from "react";
|
||||
import {
|
||||
Form,
|
||||
} from 'antd-mobile'
|
||||
const options = [
|
||||
{
|
||||
label: '浙江',
|
||||
value: '浙江',
|
||||
children: [
|
||||
{
|
||||
label: '杭州',
|
||||
value: '杭州',
|
||||
children: [
|
||||
{
|
||||
label: '西湖区',
|
||||
value: '西湖区',
|
||||
},
|
||||
{
|
||||
label: '上城区',
|
||||
value: '上城区',
|
||||
},
|
||||
{
|
||||
label: '余杭区',
|
||||
value: '余杭区',
|
||||
disabled: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
label: '温州',
|
||||
value: '温州',
|
||||
children: [
|
||||
{
|
||||
label: '鹿城区',
|
||||
value: '鹿城区',
|
||||
},
|
||||
{
|
||||
label: '龙湾区',
|
||||
value: '龙湾区',
|
||||
disabled: true,
|
||||
},
|
||||
{
|
||||
label: '瓯海区',
|
||||
value: '瓯海区',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
label: '宁波',
|
||||
value: '宁波',
|
||||
children: [
|
||||
{
|
||||
label: '海曙区',
|
||||
value: '海曙区',
|
||||
},
|
||||
{
|
||||
label: '江北区',
|
||||
value: '江北区',
|
||||
},
|
||||
{
|
||||
label: '镇海区',
|
||||
value: '镇海区',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
label: '安徽',
|
||||
value: '安徽',
|
||||
children: [
|
||||
{
|
||||
label: '合肥',
|
||||
value: '合肥',
|
||||
children: [
|
||||
{
|
||||
label: '包河区',
|
||||
value: '包河区',
|
||||
},
|
||||
{
|
||||
label: '蜀山区',
|
||||
value: '蜀山区',
|
||||
},
|
||||
{
|
||||
label: '瑶海区',
|
||||
value: '瑶海区',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
label: '芜湖',
|
||||
value: '芜湖',
|
||||
children: [
|
||||
{
|
||||
label: '镜湖区',
|
||||
value: '镜湖区',
|
||||
},
|
||||
{
|
||||
label: '弋江区',
|
||||
value: '弋江区',
|
||||
},
|
||||
{
|
||||
label: '湾沚区',
|
||||
value: '湾沚区',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
label: '江苏',
|
||||
value: '江苏',
|
||||
children: [
|
||||
{
|
||||
label: '南京',
|
||||
value: '南京',
|
||||
children: [
|
||||
{
|
||||
label: '玄武区',
|
||||
value: '玄武区',
|
||||
},
|
||||
{
|
||||
label: '秦淮区',
|
||||
value: '秦淮区',
|
||||
},
|
||||
{
|
||||
label: '建邺区',
|
||||
value: '建邺区',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
label: '苏州',
|
||||
value: '苏州',
|
||||
children: [
|
||||
{
|
||||
label: '虎丘区',
|
||||
value: '虎丘区',
|
||||
},
|
||||
{
|
||||
label: '吴中区',
|
||||
value: '吴中区',
|
||||
},
|
||||
{
|
||||
label: '相城区',
|
||||
value: '相城区',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
]
|
||||
import {getTaskByPid} from "../../utils";
|
||||
|
||||
|
||||
const ParentTask = ()=>{
|
||||
const ParentTask = (props)=>{
|
||||
const [valueToOptions, setValueToOptions] = useState([])
|
||||
const [parentValue, setParentValue] = useState("")
|
||||
const [visible, setVisible] = useState(false)
|
||||
const {form} = props;
|
||||
const options = useMemo(() => {
|
||||
function generate(v) {
|
||||
const options = valueToOptions[v]
|
||||
if (options === null) {
|
||||
return undefined
|
||||
}
|
||||
if (options === undefined) {
|
||||
return Cascader.optionSkeleton
|
||||
}
|
||||
return options.map(option => ({
|
||||
...option,
|
||||
children: generate(option.value),
|
||||
}))
|
||||
}
|
||||
return generate('0') ?? []
|
||||
}, [valueToOptions])
|
||||
|
||||
async function fetchOptionsForValue(v, level) {
|
||||
if (v in valueToOptions) return
|
||||
// if (level >= 3) {
|
||||
// setValueToOptions(prev => ({
|
||||
// ...prev,
|
||||
// [v]: null,
|
||||
// }))
|
||||
// return
|
||||
// }
|
||||
const data = await getTaskByPid(v)
|
||||
console.log("await getTaskByPid(v)",data.data.data.content)
|
||||
const options =
|
||||
data.data.data.content.length === 0
|
||||
? null
|
||||
: data.data.data.content.map(task => ({
|
||||
value: task.id,
|
||||
label: task.name,
|
||||
}))
|
||||
console.log("await getTaskByPid(v) options",options)
|
||||
setValueToOptions(prev => ({
|
||||
...prev,
|
||||
[v]: options,
|
||||
}))
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
fetchOptionsForValue('0', 0)
|
||||
}, [])
|
||||
|
||||
return <Form.Item
|
||||
name='pid'
|
||||
name='pidArray'
|
||||
label='主线任务'
|
||||
onClick={() => {
|
||||
setVisible(true)
|
||||
}}
|
||||
value={parentValue}
|
||||
>
|
||||
<Cascader
|
||||
options={options}
|
||||
|
@ -170,17 +72,26 @@ const ParentTask = ()=>{
|
|||
setVisible(false)
|
||||
}}
|
||||
value={parentValue}
|
||||
onConfirm={setParentValue}
|
||||
onSelect={(val, extend) => {
|
||||
console.log('onSelect', val, extend.items)
|
||||
onConfirm={(val)=>{
|
||||
console.log(val)
|
||||
setParentValue(val[val.length-1])
|
||||
form.setFieldValue('pidArray',val)
|
||||
}}
|
||||
// onSelect={(val, extend) => {
|
||||
// console.log('onSelect', val, extend.items)
|
||||
// }}
|
||||
onSelect={value => {
|
||||
console.log("value",value)
|
||||
value.forEach((v, index) => {
|
||||
fetchOptionsForValue(v, index + 1)
|
||||
})
|
||||
}}
|
||||
>
|
||||
{items => {
|
||||
if (items.every(item => item === null)) {
|
||||
return <span style={{color:"#cccccc"}}>主线任务选线</span>
|
||||
return <span style={{color:"#cccccc"}}>主线任务选填</span>
|
||||
} else {
|
||||
return items.map(item => item?.label ??
|
||||
<span style={{color: "#cccccc"}}>主线任务选线</span>).join('-')
|
||||
return items[items.length-1].label
|
||||
}
|
||||
}}
|
||||
</Cascader>
|
||||
|
|
|
@ -11,7 +11,7 @@ export default class Home extends React.Component {
|
|||
<div style={{"position": "fixed","top":"0","left":"0","width":"100%","zIndex":100}}>
|
||||
<SearchBar placeholder='请输入内容'/>
|
||||
</div>
|
||||
<div style={{marginTop:"40px",width:"100%"}}>
|
||||
<div style={{marginTop:"40px",marginBottom:"49px",width:"100%"}}>
|
||||
<Outlet/>
|
||||
</div>
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import {Dialog,Image, List, SwipeAction} from 'antd-mobile'
|
||||
import {Dialog, Image, List, SwipeAction} from 'antd-mobile'
|
||||
import React, {useEffect, useRef, useState} from 'react'
|
||||
import {
|
||||
DragDropContext,
|
||||
|
@ -117,13 +117,15 @@ const ToDoList = () => {
|
|||
// height={40}
|
||||
// />
|
||||
// }
|
||||
description={item.description}
|
||||
title={<span style={{color:"red"}}>{item.name}</span>}
|
||||
children={item.description}
|
||||
description={item.state}
|
||||
onClick={
|
||||
()=>{console.log("dianji")}
|
||||
() => {
|
||||
console.log("dianji")
|
||||
}
|
||||
>
|
||||
{item.name}
|
||||
</List.Item>
|
||||
}
|
||||
/>
|
||||
</SwipeAction>
|
||||
</div>
|
||||
)}
|
||||
|
|
|
@ -26,5 +26,14 @@ export const getCurrentCity=()=>{
|
|||
|
||||
export const getTaskList= () => {
|
||||
return requestUtil.get('/todo-server/search/task_message_tree?search=%7B%22pageSize%22%3A20%2C%22pageNumber%22%3A1%2C%22data%22%3A%5B%7B%22name%22%3A%22tree%22%2C%22value%22%3A%22TRUE%22%2C%22operateType%22%3A%22TREE-FILTER%22%7D%2C%7B%22name%22%3A%22state%22%2C%22value%22%3A%228%2C9%22%2C%22operateType%22%3A%22IN%22%7D%5D%7D');
|
||||
|
||||
}
|
||||
// 根据pid获取未完成的任务
|
||||
export const getTaskByPid = (pid) => {
|
||||
return requestUtil.get('/todo-server/search/task_message_tree?search=%7B%22pageSize%22%3A1000%2C%22pageNumber%22%3A1%2C%22data%22%3A%5B%7B%22name%22%3A%22pid%22%2C%22value%22%3A%22'+pid+'%22%2C%22operateType%22%3A%22%3D%22%7D%5D%7D');
|
||||
}
|
||||
export const addTask = async (entity) => {
|
||||
// 使用 Axios 发送 POST 请求添加数据
|
||||
const response = await requestUtil.post('/todo-server' + '/task', entity);
|
||||
// 从响应中提取数据并返回
|
||||
return response.data;
|
||||
}
|
Loading…
Reference in New Issue