cluster.tsx 1.7 KB
Newer Older
Z
zengqiao 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
import { IClusterData } from 'types/base-type';
import { users } from 'store/users';
import { wrapper } from 'store';
import { cluster } from 'store/cluster';
import { notification } from 'component/antd';
import { urlPrefix } from 'constants/left-menu';
import { region } from 'store';

export const showCpacityModal = (item: IClusterData) => {
  const xFormModal = {
    formMap: [
      {
        key: 'type',
        label: '扩缩容:',
        type: 'select',
        options: [{
          label: '扩容',
          value: 5,
        }, {
          label: '缩容',
          value: 15,
        }],
        rules: [{ required: true, message: '请选择' }],
        attrs: {
          placeholder: '请选择',
        },
      },
      {
        key: 'description',
        label: '申请原因',
        type: 'text_area',
孙超 已提交
32
        rules: [{ required: true, pattern: /^.{4,}.$/, message: '请输入至少5个字符' }],
Z
zengqiao 已提交
33 34 35 36 37 38 39 40 41 42 43 44 45 46
        attrs: {
          placeholder: '请输入至少5个字符',
        },
      },
    ],
    formData: {},
    visible: true,
    title: '申请扩缩容',
    okText: '确认',
    onSubmit: (value: any) => {
      const cpacityParams = {
        type: value.type,
        applicant: users.currentUser.username,
        description: value.description,
孙超 已提交
47
        extensions: JSON.stringify({ clusterId: item.clusterId }),
Z
zengqiao 已提交
48 49 50 51
      };
      cluster.applyCpacity(cpacityParams).then(data => {
        notification.success({
          message: `申请${value.type === 5 ? '扩容' : '缩容'}成功`,
孙超 已提交
52
        });
Z
zengqiao 已提交
53 54 55 56 57 58
        window.location.href = `${urlPrefix}/user/order-detail/?orderId=${data.id}&region=${region.currentRegion}`;
      });
    },
  };
  wrapper.open(xFormModal);
};