Commit a21c2933 by zhaochengxiang

资产打标签

parent 899804be
...@@ -295,9 +295,13 @@ const AssetAction = (props) => { ...@@ -295,9 +295,13 @@ const AssetAction = (props) => {
</Descriptions.Item> </Descriptions.Item>
} }
<Descriptions.Item label={<div className='title-text' style={{ textAlign: 'right', width: 60 }}>标签</div>} style={{ paddingBottom: 0 }}> <Descriptions.Item label={<div className='title-text' style={{ textAlign: 'right', width: 60 }}>标签</div>} style={{ paddingBottom: 0 }}>
<AppContext.Consumer>
{ {
(currentAction==='add'||currentAction==='edit')?<Tag styleType='complex' id={id} />:<Tag id={id} /> value => {
return (currentAction==='add'||currentAction==='edit')?<Tag styleType='complex' id={id} creator={value?.user?.userName||''} />:<Tag id={id} creator={value?.user?.userName||''} />
} }
}
</AppContext.Consumer>
</Descriptions.Item> </Descriptions.Item>
</Descriptions> </Descriptions>
</div> </div>
......
import React, { useState } from 'react'; import React, { useState, useEffect } from 'react';
import { Modal, Button, AutoComplete, Input, Avatar } from 'antd'; import { Modal, Button, AutoComplete, Input, Avatar, TreeSelect, Form } from 'antd';
import { dispatch } from '../../../../model'; import { dispatch } from '../../../../model';
import { showMessage } from '../../../../util'; import { showMessage } from '../../../../util';
...@@ -18,6 +18,18 @@ const AddTagModal = (props) => { ...@@ -18,6 +18,18 @@ const AddTagModal = (props) => {
const [ options, setOptions ] = useState(); const [ options, setOptions ] = useState();
const [ confirmLoading, setConfirmLoading ] = useState(false); const [ confirmLoading, setConfirmLoading ] = useState(false);
const [ description, setDescription ] = useState(''); const [ description, setDescription ] = useState('');
const [ tagForm, setTagForm ] = useState({});
const [form] = Form.useForm();
useEffect(() => {
if (visible) {
getTagByKeywordAndCreator();
getSupportTagForm();
}
}, [ visible ])
const getTagByKeywordAndCreator = (value=keyword) => { const getTagByKeywordAndCreator = (value=keyword) => {
dispatch({ dispatch({
...@@ -78,6 +90,20 @@ const AddTagModal = (props) => { ...@@ -78,6 +90,20 @@ const AddTagModal = (props) => {
}) })
} }
const getSupportTagForm = () => {
dispatch({
type: 'tag.getSupportTagForm',
payload: {
isDefault: false,
type: 'private',
creator
},
callback: data => {
setTagForm(data||{});
}
})
}
const onOk = () => { const onOk = () => {
if (keyword === '') { if (keyword === '') {
showMessage('warn', '请先填写标签'); showMessage('warn', '请先填写标签');
...@@ -118,33 +144,23 @@ const AddTagModal = (props) => { ...@@ -118,33 +144,23 @@ const AddTagModal = (props) => {
setStep(0); setStep(0);
} }
const onCreate = () => { const onCreate = async () => {
setConfirmLoading(true); try {
dispatch({ const row = await form?.validateFields();
type: 'tag.getSupportTagForm',
payload: { const newTagForm = JSON.parse(JSON.stringify(tagForm));
isDefault: true, (newTagForm?.targetParameters||[]).forEach(param => {
type: 'private', param.value = row[param.name];
creator
},
callback: data => {
const _tagForm = data||{};
(_tagForm.targetParameters||[]).forEach(param => {
if (param.name === 'name') {
param.value = keyword;
}
if (param.name === 'desc') {
param.value = description;
}
}) })
setConfirmLoading(true);
dispatch({ dispatch({
type: 'tag.saveTag', type: 'tag.saveTag',
payload: { payload: {
params: { params: {
isDefault: true isDefault: false
}, },
data: _tagForm data: newTagForm
}, },
callback: data => { callback: data => {
dispatch({ dispatch({
...@@ -170,15 +186,10 @@ const AddTagModal = (props) => { ...@@ -170,15 +186,10 @@ const AddTagModal = (props) => {
setConfirmLoading(false); setConfirmLoading(false);
} }
}) })
},
error: () => {
setConfirmLoading(false);
}
})
}
const onFocus = () => { } catch (errInfo) {
getTagByKeywordAndCreator(); console.log('Validate Failed:', errInfo);
}
} }
const onKeywordChange = (value) => { const onKeywordChange = (value) => {
...@@ -219,6 +230,25 @@ const AddTagModal = (props) => { ...@@ -219,6 +230,25 @@ const AddTagModal = (props) => {
setKeyword(''); setKeyword('');
} }
const loop = (data) =>
data.map(item => {
if ((item.children||[]).length>0) {
return { ...item, ...{title: item.name, value: item.idString, children: loop(item.children)} };
}
return { ...item, ...{ title: item.name, value: item.idString }};
});
const formItemLayout = {
labelCol: {
xs: { span: 24 },
sm: { span: 4 },
},
wrapperCol: {
xs: { span: 24 },
sm: { span: 20 },
},
};
let footer = []; let footer = [];
...@@ -253,7 +283,6 @@ const AddTagModal = (props) => { ...@@ -253,7 +283,6 @@ const AddTagModal = (props) => {
type="primary" type="primary"
loading={confirmLoading} loading={confirmLoading}
onClick={onCreate} onClick={onCreate}
disabled={description===''}
> >
创建 创建
</Button> </Button>
...@@ -276,19 +305,42 @@ const AddTagModal = (props) => { ...@@ -276,19 +305,42 @@ const AddTagModal = (props) => {
allowClear allowClear
value={keyword} value={keyword}
onChange={onKeywordChange} onChange={onKeywordChange}
onFocus={onFocus}
options={options} options={options}
onSelect={onSelect} onSelect={onSelect}
/> />
} }
{ {
step === 1 && <TextArea step === 1 && <Form
row={4} {...formItemLayout}
form={form}
initialValues={{ name: keyword }}
>
{
(tagForm?.targetParameters||[]).map((param, index) => {
if (param.name === 'usable') return null;
return (
<Form.Item
key={index}
label={param.cnName||''}
name={param.name||''}
rules={[{ required: param.required, message: `请选择${param.cnName}!` }]}
>
{
(param.selectMode==='singleSelect') ? <TreeSelect
style={{ width: '100%' }} style={{ width: '100%' }}
value={description} dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
onChange={onDescriptionChange} treeData={loop(param?.tagCatalogNode?.children||[])}
placeholder='为您的新标签填写描述' treeDefaultExpandAll
/> allowClear
/> : <Input disabled={param.name==='name'} />
}
</Form.Item>
);
})
}
</Form>
} }
</Modal> </Modal>
) )
......
...@@ -6,7 +6,7 @@ import AddTagModal from './Component/AddTagModal'; ...@@ -6,7 +6,7 @@ import AddTagModal from './Component/AddTagModal';
import { dispatch } from '../../../model'; import { dispatch } from '../../../model';
const TagColumn = (props) => { const TagColumn = (props) => {
const { id, type = 'dataModel', creator = 'demotest', styleType = 'simple' } = props; const { id, type = 'asset', creator = '', styleType = 'simple' } = props;
const [ ownTags, setOwnTags ] = useState([]); const [ ownTags, setOwnTags ] = useState([]);
const [ addTagModalVisible, setAddTagModalVisible ] = useState(false); const [ addTagModalVisible, setAddTagModalVisible ] = useState(false);
......
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