Commit 881575c8 by zhaochengxiang

资产打标签

parent 649fa45d
......@@ -26,7 +26,7 @@ const AssetAction = (props) => {
const [ resourceRelations, setResourceRelations ] = useState([]);
const { assets, attributes, attributesFoldMap } = assetParams;
const [ assetTagModalVisible, setAssetTagModalVisible ] = useState(false);
const [ keyword, setKeyword ] = useState('');
const [ selectTag, setSelectTag ] = useState({});
useEffect(() => {
if (action === 'add') {
......@@ -235,8 +235,8 @@ const AssetAction = (props) => {
})
}
const onAssetTag = (keyword) => {
setKeyword(keyword);
const onAssetTag = (value) => {
setSelectTag(value);
setAssetTagModalVisible(true);
}
......@@ -487,7 +487,7 @@ const AssetAction = (props) => {
<AssetTagModal
visible={assetTagModalVisible}
id={id}
keyword={keyword}
tag={selectTag}
creator={value?.user?.userName||''}
onCancel={onAssetTagModalCancel}
/>
......
......@@ -48,7 +48,7 @@ const DirsSelect = ({ value = [], data = [], onChange, ...restProps }) => {
const AssetTagModal = (props) => {
const { onCancel, visible, id, keyword, creator } = props;
const { onCancel, visible, id, tag, creator } = props;
const [ form ] = Form.useForm();
const [ confirmLoading, setConfirmLoading ] = useState(false);
const [ elements, setElements ] = useState([]);
......@@ -69,12 +69,12 @@ const AssetTagModal = (props) => {
useEffect(() => {
if (visible && (keyword||'')!=='') {
getDirectoryByName(keyword);
if (visible && (tag?.name||'')!=='') {
getDirectoryByName(tag?.name);
}
//eslint-disable-next-line react-hooks/exhaustive-deps
}, [ visible, keyword ])
}, [ visible ])
const getAsset = () => {
dispatch({
......@@ -140,7 +140,7 @@ const AssetTagModal = (props) => {
});
const params = {
dirId: row.tags.join(','),
dirId: (row.dirs||[]).join(','),
}
if ((metadataId||'')!=='') {
......@@ -156,32 +156,17 @@ const AssetTagModal = (props) => {
data: { ...asset, elements: newElements }
},
callback: () => {
const nameList = [];
(dirs||[]).forEach(dir=>{
if (row.tags.indexOf(dir.id) !== -1) {
nameList.push(dir.path);
}
})
dispatch({
type: 'tag.getTagIdListByNameList',
type: 'tag.batchAddTagResource',
payload: {
params: {
nameList: nameList.join(',')
}
},
callback: data => {
dispatch({
type: 'tag.batchAddTagResourceByTagList',
payload: {
params: {
tagIds: (data||[]).join(','),
tagId: tag?.tagId,
resourceIds: id,
type: 'dataAsset',
creator
}
},
callback: () => {
setConfirmLoading(false);
reset();
onCancel && onCancel(true);
},
......@@ -194,11 +179,6 @@ const AssetTagModal = (props) => {
setConfirmLoading(false);
}
})
},
error: () => {
setConfirmLoading(false);
}
})
} catch (errInfo) {
console.log('Validate Failed:', errInfo);
......@@ -260,7 +240,14 @@ const AssetTagModal = (props) => {
<>
<Form.Item
label='资产标签'
name='tags'
name='tag'
required={true}
>
<span>{tag?.name||''}</span>
</Form.Item>
<Form.Item
label='挂载目录'
name='dirs'
required={true}
>
<DirsSelect data={dirs||[]} />
......
import React, { useState, useEffect } from 'react';
import { Modal, Button, AutoComplete, Input, Avatar, TreeSelect, Form, Select } from 'antd';
import { Modal, Button, AutoComplete, Input, Avatar, TreeSelect, Form, Select, Checkbox } from 'antd';
import { dispatch } from '../../../../model';
import { showMessage } from '../../../../util';
......@@ -40,9 +40,10 @@ const AddTagModal = (props) => {
const [ keyword, setKeyword ] = useState('');
const [ selectTag, setSelectTag ] = useState(null);
const [ matchTags, setMatchTags ] = useState([]);
const [ options, setOptions ] = useState();
const [ options, setOptions ] = useState([]);
const [ confirmLoading, setConfirmLoading ] = useState(false);
const [ tagForm, setTagForm ] = useState({});
const [ onlyTag, setOnlyTag ] = useState(true);
const [form] = Form.useForm();
......@@ -94,7 +95,7 @@ const AddTagModal = (props) => {
tagExsit = true;
}
if (item.name === value) {
if (item.name===value && selectTag===null) {
_selectTag = item;
}
......@@ -135,6 +136,34 @@ const AddTagModal = (props) => {
return;
}
if (onlyTag) {
if (selectTag) {
setConfirmLoading(true);
dispatch({
type: 'tag.batchAddTagResource',
payload: {
params: {
tagId: selectTag.tagId,
resourceIds: id,
type,
creator
}
},
callback: () => {
reset();
onCancel && onCancel(true);
},
error: () => {
setConfirmLoading(false);
}
})
} else {
form.resetFields();
setStep(1);
}
} else {
if (selectTag) {
if (selectTag.type === 'public') {
setConfirmLoading(true);
dispatch({
type: 'assetmanage.listDirectoryByName',
......@@ -145,7 +174,6 @@ const AddTagModal = (props) => {
setConfirmLoading(false);
if ((data||[]).length===0) {
if (selectTag) {
setConfirmLoading(true);
dispatch({
type: 'tag.batchAddTagResource',
......@@ -166,18 +194,41 @@ const AddTagModal = (props) => {
}
})
} else {
setStep(1);
reset();
onAssetTag && onAssetTag(selectTag);
}
},
error: () => {
setConfirmLoading(false);
}
})
} else {
reset();
onAssetTag && onAssetTag(keyword);
setConfirmLoading(true);
dispatch({
type: 'tag.batchAddTagResource',
payload: {
params: {
tagId: selectTag.tagId,
resourceIds: id,
type,
creator
}
},
callback: () => {
reset();
onCancel && onCancel(true);
},
error: () => {
setConfirmLoading(false);
}
})
}
} else {
form.resetFields();
setStep(1);
}
}
}
const cancel = () => {
reset();
......@@ -241,6 +292,7 @@ const AddTagModal = (props) => {
if (value!==undefined && value!==null && typeof(value)!=='string') return;
setSelectTag(null);
setOptions([]);
setKeyword(value||'');
getTagByKeywordAndCreator(value||'');
}
......@@ -269,6 +321,11 @@ const AddTagModal = (props) => {
setStep(0);
setSelectTag(null);
setKeyword('');
setOnlyTag(true);
}
const onOnlyTagChange = (e) => {
setOnlyTag(e.target.checked);
}
const loop = (data) =>
......@@ -306,7 +363,7 @@ const AddTagModal = (props) => {
type="primary"
loading={confirmLoading}
onClick={onOk}
disabled={keyword===''}
disabled={keyword===''||options.length===0}
>
确定
</Button>
......@@ -341,14 +398,17 @@ const AddTagModal = (props) => {
footer={footer}
>
{
step === 0 && <AutoComplete
style={{ width: '100%' }}
step === 0 && <span>
<AutoComplete
style={{ width: '80%', marginRight: 5 }}
allowClear
value={keyword}
onChange={onKeywordChange}
options={options}
onSelect={onSelect}
/>
<Checkbox onChange={onOnlyTagChange} checked={onlyTag}>仅打标签</Checkbox>
</span>
}
{
step === 1 && <Form
......
......@@ -62,9 +62,9 @@ const TagColumn = (props) => {
refresh && getTags();
}
const onAssetTagCancel = (keyword) => {
const onAssetTagCancel = (selectTag) => {
setAddTagModalVisible(false);
onAssetTag && onAssetTag(keyword);
onAssetTag && onAssetTag(selectTag);
}
const handleClose = (index) => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment