alarm.tsx 2.4 KB
Newer Older
Z
zengqiao 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13
import { notification } from 'component/antd';
import { wrapper, region } from 'store';
import { IMonitorSilences } from 'types/base-type';
import { alarm } from 'store/alarm';
import { urlPrefix } from 'constants/left-menu';
import moment from 'moment';
import { timeFormat } from 'constants/strategy';

export const  createMonitorSilences = (monitorId: number, monitorName: string) => {
  const xFormWrapper = {
    formMap: [
      {
        key: 'monitorName',
Z
zengqiao 已提交
14
        label: '告警规则',
Z
zengqiao 已提交
15 16
        rules: [{
          required: true,
Z
zengqiao 已提交
17
          message: '请输入告警规则',
Z
zengqiao 已提交
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
        }],
        attrs: {
          disabled: true,
        },
      },
      {
        key: 'beginEndTime',
        label: '开始~结束时间',
        type: 'range_picker',
        rules: [{
          required: true,
          message: '请输入开始~结束时间',
        }],
        attrs: {
          placeholder: ['开始时间', '结束时间'],
          format: timeFormat,
          showTime: true,
          ranges: {
            '1小时': [moment(), moment().add(1, 'hour')],
            '2小时': [moment(), moment().add(2, 'hour')],
            '6小时': [moment(), moment().add(6, 'hour')],
            '12小时': [moment(), moment().add(12, 'hour')],
            '1天': [moment(), moment().add(1, 'day')],
            '2天': [moment(), moment().add(7, 'day')],
            '7天': [moment(), moment().add(7, 'day')],
          },
        },
      },
      {
        key: 'description',
        label: '说明',
        type: 'text_area',
        rules: [{
          required: true,
          message: '请输入说明',
        }],
        attrs: {
          placeholder: '请输入备注',
        },
      },
    ],
    formData: {
      monitorName,
    },
    okText: '确认',
    visible: true,
    width: 600,
    title: '屏蔽',
    onSubmit: (value: any) => {
      const params = {
        description: value.description,
        startTime: +moment(value.beginEndTime[0]).format('x'),
        endTime:  +moment(value.beginEndTime[1]).format('x'),
        monitorId,
      } as IMonitorSilences;
      alarm.createSilences(params, monitorId).then(data => {
        notification.success({ message: '屏蔽成功' });
        window.location.href = `${urlPrefix}/alarm/alarm-detail?id=${monitorId}&region=${region.currentRegion}#3`;
      });
    },
  };
  wrapper.open(xFormWrapper);
};