Commit 881575c8 by zhaochengxiang

资产打标签

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