import React, {useState, useEffect} from 'react';
import {observer} from 'mobx-react';
import {Form, Input, Select, Modal, Button, Radio} from 'antd';
import {ExclamationCircleOutlined} from '@ant-design/icons';
import {LinkButton, ACEditor} from 'components';
import TemplateSelector from '../exec/task/TemplateSelector';
import {cleanCommand, http} from 'libs';
import store from './store';
export default observer(function () {
const [form] = Form.useForm();
const [showTmp, setShowTmp] = useState(false);
const [command, setCommand] = useState(store.record.command || '');
const [rstValue, setRstValue] = useState({});
const [contacts, setContacts] = useState([]);
useEffect(() => {
const {mode, value} = store.record.rst_notify
setRstValue({[mode]: value})
http.get('/api/alarm/contact/?only_push=1')
.then(res => setContacts(res))
}, []);
function handleAddZone() {
let type;
Modal.confirm({
icon: ,
title: '添加任务类型',
content: (
type = e.target.value}/>
),
onOk: () => {
if (type) {
store.types.push(type);
form.setFieldsValue({type})
}
},
})
}
function canNext() {
const formData = form.getFieldsValue()
return !(formData.type && formData.name && command)
}
function handleNext() {
const notifyMode = store.record.rst_notify.mode
store.record.rst_notify.value = rstValue[notifyMode]
Object.assign(store.record, form.getFieldsValue(), {command: cleanCommand(command)})
store.page += 1;
}
function handleSelect(tpl) {
const {interpreter, body} = tpl;
setCommand(body)
form.setFieldsValue({interpreter})
}
let modePlaceholder;
switch (store.record.rst_notify.mode) {
case '0':
modePlaceholder = '已关闭'
break
case '1':
modePlaceholder = 'https://oapi.dingtalk.com/robot/send?access_token=xxx'
break
case '3':
modePlaceholder = 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=xxx'
break
case '4':
modePlaceholder = 'https://open.feishu.cn/open-apis/bot/v2/hook/xxx'
break
default:
modePlaceholder = '请输入'
}
const notifyMode = store.record.rst_notify.mode
return (
setShowTmp(true)}>从模板添加}>
Shell
Python
{({getFieldValue}) => (
)}
任务执行失败告警通知,
钉钉收不到通知?
)}>
setRstValue(Object.assign({}, rstValue, {[notifyMode]: e.target.value}))}
disabled={notifyMode === '0'}
placeholder={modePlaceholder}/>
{() => }
{showTmp && setShowTmp(false)}/>}
)
})