Commit bec4a91d by zhaochengxiang

采集

parent 25c0900a
...@@ -4,6 +4,12 @@ import moment from 'moment'; ...@@ -4,6 +4,12 @@ import moment from 'moment';
import { dispatch } from '../../../../model'; import { dispatch } from '../../../../model';
function compare(val1, val2) {
var a = val1.seq;
var b = val2.seq;
return (a - b);
}
const ScheduleAction = (props) => { const ScheduleAction = (props) => {
const { action, id, form, tid, onChange } = props; const { action, id, form, tid, onChange } = props;
...@@ -11,7 +17,7 @@ const ScheduleAction = (props) => { ...@@ -11,7 +17,7 @@ const ScheduleAction = (props) => {
useEffect(() => { useEffect(() => {
reset(); reset();
if (action === 'add' && tid) { if (action === 'add') {
getScheduleForm(); getScheduleForm();
} else if (action === 'edit' && id) { } else if (action === 'edit' && id) {
getScheduleById(); getScheduleById();
...@@ -26,6 +32,9 @@ const ScheduleAction = (props) => { ...@@ -26,6 +32,9 @@ const ScheduleAction = (props) => {
targetConfId: tid targetConfId: tid
}, },
callback: data => { callback: data => {
(data?.targetParameters||[]).sort(compare);
(data?.scheduleParameters||[]).sort(compare);
setSchedule(data||{}); setSchedule(data||{});
onChange && onChange(data||{}); onChange && onChange(data||{});
} }
...@@ -39,12 +48,6 @@ const ScheduleAction = (props) => { ...@@ -39,12 +48,6 @@ const ScheduleAction = (props) => {
id id
}, },
callback: data => { callback: data => {
function compare(val1, val2) {
var a = val1.seq;
var b = val2.seq;
return (a - b);
}
(data?.targetParameters||[]).sort(compare); (data?.targetParameters||[]).sort(compare);
(data?.scheduleParameters||[]).sort(compare); (data?.scheduleParameters||[]).sort(compare);
......
...@@ -170,7 +170,7 @@ const FC = (props) => { ...@@ -170,7 +170,7 @@ const FC = (props) => {
return () => { return () => {
clearInterval(interval); clearInterval(interval);
} }
}, []) }, [env])
const _columns = useMemo(() => { const _columns = useMemo(() => {
if (visibleCols) { if (visibleCols) {
...@@ -191,6 +191,7 @@ const FC = (props) => { ...@@ -191,6 +191,7 @@ const FC = (props) => {
&& (configState.datasourceId===undefined || item.target?.id === configState.datasourceId) && (configState.datasourceId===undefined || item.target?.id === configState.datasourceId)
&& (configState.targetType===undefined || item.target?.type === configState.targetType) && (configState.targetType===undefined || item.target?.type === configState.targetType)
&& (!keyword || (item.taskCode||'').indexOf(keyword)!==-1 || (item.schema||'').indexOf(keyword)!==-1) && (!keyword || (item.taskCode||'').indexOf(keyword)!==-1 || (item.schema||'').indexOf(keyword)!==-1)
&& item.target?.namespace === env?.domainId?.toString()
}); });
newTasks?.forEach(item => { newTasks?.forEach(item => {
const index = (supportedTargetTypes||[]).findIndex(_item => _item.targetType === item.type); const index = (supportedTargetTypes||[]).findIndex(_item => _item.targetType === item.type);
...@@ -216,7 +217,7 @@ const FC = (props) => { ...@@ -216,7 +217,7 @@ const FC = (props) => {
} }
return [] return []
}, [tasks, pagination, configState, supportedTargetTypes, sortedInfo, keyword]) }, [tasks, pagination, configState, supportedTargetTypes, sortedInfo, keyword, env])
const total = useMemo(() => { const total = useMemo(() => {
if (tasks) { if (tasks) {
...@@ -225,13 +226,14 @@ const FC = (props) => { ...@@ -225,13 +226,14 @@ const FC = (props) => {
&& (configState.datasourceId===undefined || item.target?.id === configState.datasourceId) && (configState.datasourceId===undefined || item.target?.id === configState.datasourceId)
&& (configState.targetType===undefined || item.target?.type === configState.targetType) && (configState.targetType===undefined || item.target?.type === configState.targetType)
&& (!keyword || item.taskCode?.indexOf(keyword)!==-1 || item.schema?.indexOf(keyword)!==-1) && (!keyword || item.taskCode?.indexOf(keyword)!==-1 || item.schema?.indexOf(keyword)!==-1)
&& item.target?.namespace === env?.domainId?.toString()
}); });
return (newTasks||[]).length; return (newTasks||[]).length;
} }
return 0; return 0;
}, [tasks, pagination, configState, keyword]) }, [tasks, pagination, configState, keyword, env])
const getAllTasks = () => { const getAllTasks = () => {
setLoadingTasks(true); setLoadingTasks(true);
...@@ -299,12 +301,9 @@ const FC = (props) => { ...@@ -299,12 +301,9 @@ const FC = (props) => {
setPagination({pageNum: page, pageSize: size }); setPagination({pageNum: page, pageSize: size });
} }
const onUpdateTaskCancel = () => { const onUpdateTaskCancel = (refresh = false) => {
setUpdateTaskParam({ visible: false, action: undefined, id: undefined }); setUpdateTaskParam({ visible: false, action: undefined, id: undefined });
} refresh && getAllTasks();
const onUpdateTaskChange = () => {
getAllTasks();
} }
const onColConfigCancel = (refresh = false) => { const onColConfigCancel = (refresh = false) => {
...@@ -444,7 +443,7 @@ const FC = (props) => { ...@@ -444,7 +443,7 @@ const FC = (props) => {
dataSource={_tasks||[]} dataSource={_tasks||[]}
pagination={false} pagination={false}
onChange={onTableChange} onChange={onTableChange}
scroll={{ y: 'calc(100vh - 330px)' }} scroll={{ y: 'calc(100vh - 315px)' }}
sticky sticky
/> />
<Pagination <Pagination
...@@ -466,7 +465,6 @@ const FC = (props) => { ...@@ -466,7 +465,6 @@ const FC = (props) => {
action={updateTaskParam.action} action={updateTaskParam.action}
id={updateTaskParam.id} id={updateTaskParam.id}
onCancel={onUpdateTaskCancel} onCancel={onUpdateTaskCancel}
onChange={onUpdateTaskChange}
/> />
<ColConfig <ColConfig
...@@ -481,8 +479,6 @@ const FC = (props) => { ...@@ -481,8 +479,6 @@ const FC = (props) => {
export default FC; export default FC;
export const reducer = (prevState, action) => { export const reducer = (prevState, action) => {
const scope = undefined, targetType = undefined, datasourceId = undefined;
if (action.type === 'selectScope') { if (action.type === 'selectScope') {
const [scope] = action.payload const [scope] = action.payload
return { ...prevState, scope } return { ...prevState, scope }
...@@ -493,7 +489,7 @@ export const reducer = (prevState, action) => { ...@@ -493,7 +489,7 @@ export const reducer = (prevState, action) => {
const [datasourceId] = action.payload const [datasourceId] = action.payload
return { ...prevState, datasourceId } return { ...prevState, datasourceId }
} else if (action.type === 'init') { } else if (action.type === 'init') {
return { ...prevState, scope, targetType, datasourceId } return { ...prevState, scope: undefined, targetType: undefined, datasourceId: undefined }
} }
return prevState return prevState
...@@ -531,10 +527,10 @@ export function Config({ onState, autoSelect, setTargetTypes }) { ...@@ -531,10 +527,10 @@ export function Config({ onState, autoSelect, setTargetTypes }) {
setTreeData(env.children); setTreeData(env.children);
setTreeExpandKeys(newExpandKeys); setTreeExpandKeys(newExpandKeys);
dispatchState('init'); dispatchState({type: 'init'});
} else { } else {
setTreeData([]); setTreeData([]);
dispatchState('init'); dispatchState({type: 'init'});
} }
}, [env]) }, [env])
...@@ -544,7 +540,7 @@ export function Config({ onState, autoSelect, setTargetTypes }) { ...@@ -544,7 +540,7 @@ export function Config({ onState, autoSelect, setTargetTypes }) {
useEffect(() => { useEffect(() => {
getDatasources(); getDatasources();
}, [scope]) }, [scope, env])
useEffect(() => { useEffect(() => {
if (autoSelect && (datasources||[]).length > 0) { if (autoSelect && (datasources||[]).length > 0) {
......
...@@ -79,10 +79,13 @@ const FC = (props) => { ...@@ -79,10 +79,13 @@ const FC = (props) => {
}, [reportData]) }, [reportData])
const taskCodes = useMemo(() => { const taskCodes = useMemo(() => {
return tasks?.filter(item => item.taskCode).map(item => item.taskCode) return tasks?.filter(item => item.target?.namespace===env?.domainId?.toString() && item.taskCode).map(item => item.taskCode)
}, [tasks]) }, [tasks, env])
useEffect(() => { useEffect(() => {
setTaskCode(undefined);
setDatasourceName(undefined);
setReportState(undefined);
getAllTasks(); getAllTasks();
getDatasources(); getDatasources();
}, [env]) }, [env])
...@@ -377,7 +380,7 @@ const FC = (props) => { ...@@ -377,7 +380,7 @@ const FC = (props) => {
}, },
}} }}
pagination={false} pagination={false}
scroll={{ y: 'calc(100vh - 415px)' }} scroll={{ y: 'calc(100vh - 400px)' }}
sticky sticky
/> />
<Pagination <Pagination
......
import React, { useEffect, useMemo, useState } from 'react'; import React, { useEffect, useMemo, useState } from 'react';
import { Modal, Checkbox, Row, Col, Divider, Input, Typography, Form, Switch, Spin } from 'antd'; import { Modal, Checkbox, Row, Col, Divider, Input, Typography, Form, Switch, Spin, Space } from 'antd';
import { Config } from './Task'; import { Config } from './Task';
import ScheduleAction from '../../DatasourceManage/Component/ScheduleAction'; import ScheduleAction from '../../DatasourceManage/Component/ScheduleAction';
import { dispatch } from '../../../../model'; import { dispatch } from '../../../../model';
const FC = (props) => { const FC = (props) => {
const {visible, onCancel, onChange, action, id} = props; const {visible, onCancel, action, id} = props;
const [schemas, setSchemas] = useState([]); const [schemas, setSchemas] = useState([]);
const [filterSchemas, setFilterSchemas] = useState([]); const [filterSchemas, setFilterSchemas] = useState([]);
const [selectedSchemas, setSelectedSchemas] = useState([]); const [selectedSchemas, setSelectedSchemas] = useState([]);
...@@ -17,21 +17,25 @@ const FC = (props) => { ...@@ -17,21 +17,25 @@ const FC = (props) => {
const [confirmLoading, setConfirmLoading] = useState(false); const [confirmLoading, setConfirmLoading] = useState(false);
const [checkAllValue, setCheckAllValue] = useState(false); const [checkAllValue, setCheckAllValue] = useState(false);
const [configState, setConfigState] = useState(undefined); const [configState, setConfigState] = useState(undefined);
const [step, setStep] = useState(1);
const [scheduleParam, setScheduleParam] = useState({ const [scheduleParam, setScheduleParam] = useState({
action: undefined, action: undefined,
id: undefined, id: undefined,
tid: undefined tid: undefined
}); });
const [editSchedule, setEditSchedule] = useState(undefined); const [editSchedule, setEditSchedule] = useState(undefined);
const [notConfigSchedule, setNotConfigSchedule] = useState(false);
const [showScheduleCheckbox, setShowScheduleCheckbox] = useState(true);
const [ form ] = Form.useForm(); const [ form ] = Form.useForm();
const [ scheduleForm ] = Form.useForm(); const [ scheduleForm ] = Form.useForm();
useEffect(() => { useEffect(() => {
if (visible) { if (visible) {
if (action==='edit' && id) { if (action === 'add') {
setScheduleParam({ action, id: undefined, tid: undefined });
} else if (action==='edit' && id) {
getTask(); getTask();
getSchedules(id);
} }
} }
}, [visible, action]) }, [visible, action])
...@@ -126,10 +130,11 @@ const FC = (props) => { ...@@ -126,10 +130,11 @@ const FC = (props) => {
} }
}, },
callback: data => { callback: data => {
setStep(2);
if ((data?.datas||[]).length === 0) { if ((data?.datas||[]).length === 0) {
setNotConfigSchedule(true);
setScheduleParam({action: 'add', tid}); setScheduleParam({action: 'add', tid});
} else { } else {
setShowScheduleCheckbox(false);
setScheduleParam({action: 'edit', id: data?.datas[0].id}); setScheduleParam({action: 'edit', id: data?.datas[0].id});
} }
...@@ -143,8 +148,12 @@ const FC = (props) => { ...@@ -143,8 +148,12 @@ const FC = (props) => {
const onOk = async() => { const onOk = async() => {
try { try {
if (step === 1) {
const row = await form.validateFields(); const row = await form.validateFields();
if (!notConfigSchedule) {
await scheduleForm.validateFields();
}
//深拷贝 //深拷贝
let newTask = JSON.parse(JSON.stringify(taskSettings)); let newTask = JSON.parse(JSON.stringify(taskSettings));
...@@ -167,38 +176,31 @@ const FC = (props) => { ...@@ -167,38 +176,31 @@ const FC = (props) => {
data: newTask data: newTask
}, },
callback: data => { callback: data => {
if (!notConfigSchedule) {
dispatch({
type: 'datasource.saveAndStartSchedule',
payload: {
data: {...editSchedule, targetConfId: data}
},
callback: () => {
setConfirmLoading(false); setConfirmLoading(false);
onChange?.(); reset();
if (action === 'add') { onCancel?.(true);
setStep(2);
setScheduleParam({action, tid: data});
} else {
getSchedules(data);
}
}, },
error: () => { error: () => {
setConfirmLoading(false); setConfirmLoading(false);
} }
}) })
} else { } else {
await scheduleForm.validateFields();
setConfirmLoading(true);
dispatch({
type: 'datasource.saveAndStartSchedule',
payload: {
data: editSchedule
},
callback: () => {
setConfirmLoading(false); setConfirmLoading(false);
reset(); reset();
onCancel?.(); onCancel?.(true);
}
}, },
error: () => { error: () => {
setConfirmLoading(false); setConfirmLoading(false);
} }
}) })
}
} catch (errInfo) { } catch (errInfo) {
console.log('Validate Failed:', errInfo); console.log('Validate Failed:', errInfo);
} }
...@@ -212,8 +214,12 @@ const FC = (props) => { ...@@ -212,8 +214,12 @@ const FC = (props) => {
setConfigState(undefined); setConfigState(undefined);
setKeyword(''); setKeyword('');
setCheckAllValue(false); setCheckAllValue(false);
setStep(1); setEditSchedule(undefined);
setNotConfigSchedule(false);
setShowScheduleCheckbox(true);
setScheduleParam({ action: undefined, id: undefined, tid: undefined });
form.resetFields(); form.resetFields();
scheduleForm.resetFields();
} }
const onSearchInputChange = (e) => { const onSearchInputChange = (e) => {
...@@ -242,6 +248,10 @@ const FC = (props) => { ...@@ -242,6 +248,10 @@ const FC = (props) => {
} }
} }
const onScheduleCheckChange = (e) => {
setNotConfigSchedule(e.target.checked);
}
const onScheduleChange = (data) => { const onScheduleChange = (data) => {
setEditSchedule(data); setEditSchedule(data);
} }
...@@ -271,8 +281,7 @@ const FC = (props) => { ...@@ -271,8 +281,7 @@ const FC = (props) => {
onOk={onOk} onOk={onOk}
confirmLoading={confirmLoading} confirmLoading={confirmLoading}
> >
{ <React.Fragment>
step === 1 && <React.Fragment>
{ {
(action === 'add') && <div className='flex' style={{ justifyContent: 'end' }}> (action === 'add') && <div className='flex' style={{ justifyContent: 'end' }}>
<Config autoSelect onState={(state) => { <Config autoSelect onState={(state) => {
...@@ -337,21 +346,26 @@ const FC = (props) => { ...@@ -337,21 +346,26 @@ const FC = (props) => {
}) })
} }
</Form> </Form>
</Spin>
</React.Fragment> <Divider>{
<Space>
<span>定时调度</span>
{
showScheduleCheckbox && <Checkbox checked={notConfigSchedule} onChange={onScheduleCheckChange}>暂不设置</Checkbox>
} }
</Space>
}</Divider>
{ {
step === 2 && <React.Fragment> !notConfigSchedule && <ScheduleAction
<Divider>定时调度</Divider>
<ScheduleAction
action={scheduleParam.action} action={scheduleParam.action}
id={scheduleParam.id} id={scheduleParam.id}
form={scheduleForm} form={scheduleForm}
tid={scheduleParam.tid} tid={scheduleParam.tid}
onChange={onScheduleChange} onChange={onScheduleChange}
/> />
</React.Fragment>
} }
</Spin>
</React.Fragment>
</Modal> </Modal>
); );
} }
......
.metadata-harvester { .metadata-harvester {
height: calc(100vh - 124px); height: calc(100vh - 124px);
padding: 20px; padding: 5px 20px 20px;
background: #fff; background: #fff;
overflow: hidden; overflow: hidden;
} }
\ No newline at end of file
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