Commit 0020f2ca by zhaochengxiang

资产

parent fa425c05
......@@ -165,10 +165,30 @@ export function* getRelAttrByModel(payload) {
return yield call(service.getRelAttrByModel, payload);
}
export function* listSourceModels(payload) {
return yield call(service.listSourceModels, payload);
}
export function* saveEleAndAttrRelWithSourceModel(payload) {
return yield call(service.saveEleAndAttrRelWithSourceModel, payload);
}
export function* getRelAttrBySourceModel(payload) {
return yield call(service.getRelAttrBySourceModel, payload);
}
export function* deleteRelAttrBySourceModel(payload) {
return yield call(service.deleteRelAttrBySourceModel, payload);
}
export function* fillElementValueBeforeCreate(payload) {
return yield call(service.fillElementValueBeforeCreate, payload);
}
export function* listSupportSourceModels() {
return yield call(service.listSupportSourceModels)
}
export function* countResourceState(payload) {
return yield call(service.countResourceState, payload);
}
......
......@@ -172,10 +172,30 @@ export function getRelAttrByModel(payload) {
return PostJSON("/dataassetmanager/eleAndAttrApi/getRelAttrByModel", payload);
}
export function listSourceModels() {
return GetJSON("/dataassetmanager/eleAndAttrApi/listSourceModels")
}
export function saveEleAndAttrRelWithSourceModel(payload) {
return PostJSON("/dataassetmanager/eleAndAttrApi/saveEleAndAttrRelWithSourceModel", payload)
}
export function getRelAttrBySourceModel(payload) {
return GetJSON("/dataassetmanager/eleAndAttrApi/getRelAttrBySourceModel", payload)
}
export function deleteRelAttrBySourceModel(payload) {
return PostJSON("/dataassetmanager/eleAndAttrApi/delEleAndAttrRelWithSourceModel", payload)
}
export function fillElementValueBeforeCreate(payload) {
return PostJSON("/dataassetmanager/eleAndAttrApi/fillElementValueBeforeCreate", payload);
}
export function listSupportSourceModels() {
return GetJSON("/dataassetmanager/eleAndAttrApi/listSupportSourceModels");
}
export function countResourceState(payload) {
return GetJSON("/dataassetmanager/countApi/countResourceState", payload);
}
......
......@@ -125,8 +125,6 @@ const AssetTable = (props) => {
id: MENU_ID,
});
const { env } = useContext(AppContext);
const [ loading, setLoading ] = useState(false);
const [ columns, setColumns ] = useState([]);
const [ assets, setAssets ] = useState([]);
......@@ -158,6 +156,8 @@ const AssetTable = (props) => {
const anchorId = getQueryParam(AnchorId, props.location.search);
const timestamp = getQueryParam(AnchorTimestamp, props.location.search);
const app = useContext(AppContext);
const { env } = app;
const shouldScrollRef = useRef(false);
const metadataIndexRef = useRef('');
......@@ -672,6 +672,16 @@ const AssetTable = (props) => {
});
}
});
} else if (key === 'authorization') {
if (contextMenuItem?.metadata?.metadataTableId) {
console.log('metadataTableId', contextMenuItem?.metadata?.metadataTableId);
app?.setGlobalState && app?.setGlobalState({
message: 'data-govern-assets-admit',
data: contextMenuItem
})
} else {
showMessage("warn","该资产没有关联元数据信息");
}
}
}
......@@ -1005,6 +1015,9 @@ const AssetTable = (props) => {
转为非资产
</RcItem>
}
<RcItem id="authorization" onClick={handleItemClick}>
授权
</RcItem>
</RcMenu>
{contextHolder}
......
import React, { useEffect, useState } from 'react';
import { Modal, Form, TreeSelect, Select, Space, Button, Row, Col, } from 'antd';
import React, { useEffect, useMemo, useRef, useState } from 'react';
import { Modal, Form, TreeSelect, Select, Space, Button, Row, Col, Tabs, Spin, Input } from 'antd';
import { dispatch } from '../../../../model';
import { showMessage } from '../../../../util';
const AddSourceModelName = '新增数据来源'
const MetaModelSelect = ({ value = {}, metaModelTreeData = [], onChange, ...restProps }) => {
const [ attributes, setAttributes ] = useState([]);
......@@ -98,82 +101,79 @@ const MetaModelSelect = ({ value = {}, metaModelTreeData = [], onChange, ...rest
);
}
const AttributeRelationModal = (props) => {
const { visible, onCancel } = props;
const [ confirmLoading, setConfirmLoading ] = useState(false);
const AttributeRelationWithSourceModel = (props) => {
const { elements, sourceModel, supportSourceModelsName, metadataModelTreeData, activeKey, onChange } = props;
const [ metadataModelTreeData, setMetadataModelTreeData ] = useState([]);
const [ elements, setElements] = useState([]);
const [ loading, setLoading ] = useState(false)
const [ confirmLoading, setConfirmLoading ] = useState(false);
const [ currentRelations, setCurrentRelations ] = useState();
const [ form ] = Form.useForm();
const [modal, contextHolder] = Modal.useModal()
useEffect(() => {
if (visible) {
getMetadataModelTree();
if (sourceModel) {
getRelAttrBySourceModel()
} else {
form.resetFields()
}
//eslint-disable-next-line react-hooks/exhaustive-deps
}, [visible])
form.setFieldsValue({ sourceModel })
}, [activeKey, sourceModel])
const getMetadataModelTree = () => {
dispatch({
type: 'assetmanage.getMetadataModelTree',
callback: data => {
let newData = [...data];
function recursion(_data, superKey='') {
if ((_data||[]).length===0) return;
(_data||[]).forEach(item=> {
item.title = item.nodeName||'';
item.value = superKey + '/' +(item.nodeName||'');
recursion(item.children, item.value);
useEffect(() => {
if (currentRelations && elements?.length > 0) {
let newFiledsValue = {};
(currentRelations||[]).forEach(item => {
newFiledsValue[item.elementId] = {model: item.model, modelValue: item.model, attrName: item.attrName||'', attrCnName: item.attrCnName||''};
})
}
recursion(newData);
setMetadataModelTreeData(newData||[]);
loadElementWithoutCustom();
},
error: () => {
}
});
form.setFieldsValue(newFiledsValue);
}
}, [currentRelations, elements])
const loadElementWithoutCustom = () => {
const getRelAttrBySourceModel = () => {
setLoading(true)
dispatch({
type: 'assetmanage.loadElementWithoutCustom',
type: 'assetmanage.getRelAttrBySourceModel',
payload: {
sourceModel
},
callback: data => {
setElements(data||[]);
getRelAttrByModel();
setLoading(false)
setCurrentRelations(data||[])
},
error: () => {
setLoading(false)
}
});
}
const getRelAttrByModel = () => {
const onDelete = () => {
modal.confirm({
title: '提示!',
content: '您确定要删除该来源模型名称吗?',
onOk: () => {
dispatch({
type: 'assetmanage.getRelAttrByModel',
callback: data => {
let _fieldsValue = {};
(data||[]).forEach(item => {
_fieldsValue[item.elementId] = {model: item.model, modelValue: item.model, attrName: item.attrName||'', attrCnName: item.attrCnName||''};
})
form.setFieldsValue(_fieldsValue);
type: 'assetmanage.deleteRelAttrBySourceModel',
payload: {
params: {
sourceModel
}
},
callback: () => {
showMessage('success', '删除成功')
onChange?.('delete')
},
error: () => {
}
});
}
});
}
const onOk = async() => {
const onOk = async () => {
try {
const row = await form.validateFields();
......@@ -189,13 +189,17 @@ const AttributeRelationModal = (props) => {
setConfirmLoading(true);
dispatch({
type: 'assetmanage.saveEleAndAttrRel',
type: 'assetmanage.saveEleAndAttrRelWithSourceModel',
payload: {
data: newRels
data: newRels,
params: {
sourceModel: row.sourceModel,
}
},
callback: data => {
reset();
onCancel && onCancel();
showMessage('success', sourceModel?'更新成功':'新增成功')
setConfirmLoading(false);
onChange?.('update', row.sourceModel)
},
error: () => {
setConfirmLoading(false);
......@@ -208,11 +212,6 @@ const AttributeRelationModal = (props) => {
}
}
const reset = () => {
setConfirmLoading(false);
form.resetFields();
}
const formItemLayout = {
labelCol: {
xs: { span: 24 },
......@@ -224,28 +223,35 @@ const AttributeRelationModal = (props) => {
},
};
return (
<Modal
forceRender
title={'资产属性关联'}
visible={visible}
width={600}
onCancel={() => {
reset();
onCancel && onCancel()
}}
footer={
return <Spin spinning={loading}>
<div className='mb-3' style={{ textAlign: 'right' }}>
<Space>
<Button onClick={() => {
reset();
onCancel && onCancel();
}}>返回</Button>
<Button type="primary" onClick={ onOk } loading={ confirmLoading }>确定</Button>
</Space>
{
sourceModel && <Button type="primary" danger onClick={() => onDelete()}>删除</Button>
}
<Button type="primary" onClick={() => onOk()} loading={confirmLoading}>确定</Button>
</Space>
</div>
<Form form={form} style={{ maxHeight: 400, overflow: 'auto' }} {...formItemLayout}>
<Form.Item
label='来源模型名称'
name='sourceModel'
rules={[{ required: true, message: '请输入来源名称'}]}
>
<div style={{ maxHeight: 500, overflow: 'auto' }}>
<Form form={form} {...formItemLayout}>
<Select
allowClear
placeholder='请选择来源模型名称'
disabled={sourceModel}
>
{
supportSourceModelsName?.map((name, index) => {
return <Select.Option key={index} value={name}>
{ name }
</Select.Option>
})
}
</Select>
</Form.Item>
{
(elements||[]).map((element, index) => {
return (
......@@ -262,7 +268,159 @@ const AttributeRelationModal = (props) => {
})
}
</Form>
</div>
{contextHolder}
</Spin>
}
const AttributeRelationModal = (props) => {
const { visible, onCancel } = props;
const [ supportSourceModelsName, setSupportSourceModelsName ] = useState()
const [ loadingSourceModels, setLoadingSourceModels] = useState(false)
const [ sourceModels, setSourceModels ] = useState()
const [ metadataModelTreeData, setMetadataModelTreeData ] = useState([]);
const [ elements, setElements] = useState([]);
const [ activeKey, setActiveKey ] = useState();
const activeKeyRef = useRef();
useEffect(() => {
if (visible) {
getSupportSourceModelsName();
getSourceModels();
loadElementWithoutCustom();
getMetadataModelTree();
}
//eslint-disable-next-line react-hooks/exhaustive-deps
}, [visible])
const tabData = useMemo(() => {
return [...sourceModels||[], AddSourceModelName]
}, [sourceModels])
const getSupportSourceModelsName = () => {
dispatch({
type: 'assetmanage.listSupportSourceModels',
callback: (data) => {
console.log('data', data)
setSupportSourceModelsName(data||[])
},
})
}
const getSourceModels = () => {
setLoadingSourceModels(true)
dispatch({
type: 'assetmanage.listSourceModels',
callback: (data) => {
setLoadingSourceModels(false)
setSourceModels(data||[])
if (!activeKeyRef.current) {
activeKeyRef.current = data?.length > 0 ? data[0] : AddSourceModelName
setActiveKey(data?.length > 0 ? data[0] : AddSourceModelName)
} else if (activeKeyRef.current !== activeKey) {
setActiveKey(activeKeyRef.current)
}
},
error: () => {
setLoadingSourceModels(false)
}
})
}
const getMetadataModelTree = () => {
dispatch({
type: 'assetmanage.getMetadataModelTree',
callback: data => {
let newData = [...data];
function recursion(_data, superKey='') {
if ((_data||[]).length===0) return;
(_data||[]).forEach(item=> {
item.title = item.nodeName||'';
item.value = superKey + '/' +(item.nodeName||'');
recursion(item.children, item.value);
})
}
recursion(newData);
setMetadataModelTreeData(newData||[]);
},
error: () => {
}
});
}
const loadElementWithoutCustom = () => {
dispatch({
type: 'assetmanage.loadElementWithoutCustom',
callback: data => {
setElements(data||[]);
},
error: () => {
}
});
}
const onTabsChange = (value) => {
activeKeyRef.current = value
setActiveKey(value)
}
const onRelationChange = (type, value) => {
if (type === 'delete') {
activeKeyRef.current = undefined
getSourceModels()
} else if (type === 'update') {
activeKeyRef.current = value
getSourceModels()
}
}
const reset = () => {
setActiveKey(undefined);
}
return (
<Modal
forceRender
title={'资产属性关联'}
visible={visible}
width={1000}
onCancel={() => {
reset();
onCancel?.();
}}
footer={
<Space>
<Button onClick={() => {
reset();
onCancel?.();
}}>取消</Button>
</Space>
}
>
<Tabs tabPosition='left' activeKey={activeKey} onChange={onTabsChange}>
{
tabData?.map((item, i) => {
return <Tabs.TabPane tab={item} key={item}>
<AttributeRelationWithSourceModel
elements={elements}
supportSourceModelsName={supportSourceModelsName}
metadataModelTreeData={metadataModelTreeData}
sourceModel={item === AddSourceModelName ? undefined: item}
activeKey={activeKey}
onChange={onRelationChange}
/>
</Tabs.TabPane>
})
}
</Tabs>
</Modal>
);
}
......
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