|
@@ -10,8 +10,8 @@ import {
|
|
|
Divider,
|
|
|
Button,
|
|
|
} from 'antd'
|
|
|
-import { PlusOutlined } from '@ant-design/icons'
|
|
|
-import { getTagList } from '../services'
|
|
|
+import { PlusOutlined, DeleteOutlined } from '@ant-design/icons'
|
|
|
+import { getTagList, deleteTag } from '../services'
|
|
|
|
|
|
const FormWrapper = styled.div`
|
|
|
.singletask_form {
|
|
@@ -65,15 +65,33 @@ const TaskForm = ({
|
|
|
setTag(event.target.value)
|
|
|
}
|
|
|
|
|
|
- const addItem = e => {
|
|
|
- e.preventDefault()
|
|
|
- if (tag !== null) {
|
|
|
- setTagOptions([...tagOptions, tag])
|
|
|
- setTag(null)
|
|
|
+ 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)
|
|
|
}
|
|
|
- setTimeout(() => {
|
|
|
- inputRef.current?.focus()
|
|
|
- }, 0)
|
|
|
}
|
|
|
|
|
|
const onRadioChange = e => {
|
|
@@ -148,6 +166,7 @@ const TaskForm = ({
|
|
|
<Select
|
|
|
placeholder="选择任务标签"
|
|
|
allowClear
|
|
|
+ optionLabelProp="label"
|
|
|
dropdownRender={menu => (
|
|
|
<>
|
|
|
{menu}
|
|
@@ -166,15 +185,21 @@ const TaskForm = ({
|
|
|
value={tag}
|
|
|
onChange={onNameChange}
|
|
|
/>
|
|
|
- <Button type="text" icon={<PlusOutlined />} onClick={addItem}>
|
|
|
+ <Button
|
|
|
+ type="text"
|
|
|
+ icon={<PlusOutlined />}
|
|
|
+ onClick={addTagItem}>
|
|
|
添加新分类
|
|
|
</Button>
|
|
|
</Space>
|
|
|
</>
|
|
|
)}>
|
|
|
- {tagOptions.map((item, index) => (
|
|
|
- <Option key={index} value={item}>
|
|
|
- {item}
|
|
|
+ {tagOptions.map(item => (
|
|
|
+ <Option key={item}>
|
|
|
+ <Space>
|
|
|
+ <DeleteOutlined onClick={() => onDeleteTag(item)} />
|
|
|
+ <span>{item}</span>
|
|
|
+ </Space>
|
|
|
</Option>
|
|
|
))}
|
|
|
</Select>
|