AddForm.jsx 3.74 KB
Newer Older
张烨's avatar
张烨 committed
1 2
import React from 'react';
import { Form, Input, Button, Select } from 'antd';
张烨's avatar
张烨 committed
3 4
import styles from './addForm.less';
import PicturesWall from '@/components/Upload/index';
张烨's avatar
张烨 committed
5
import EditeConfigWrapper from './editConfigFileWrapper';
张烨's avatar
张烨 committed
6 7 8

const { Item } = Form;
const AddForm = props => {
张烨's avatar
张烨 committed
9 10 11 12 13 14 15
  const {
    submitCallback,
    nodeObj,
    addType,
    submitLoading,
    configFiles,
  } = props;
张烨's avatar
张烨 committed
16 17 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
  const [form] = Form.useForm();
  const [otherForm] = Form.useForm();
  const layout = {
    layout: 'horizontal',
    labelCol: { span: 4, offset: 1 },
    wrapperCol: { span: 16 },
  };
  const submit = () => {
    if (addType === 1) {
      let obj = form.getFieldsValue();
      submitCallback(obj, nodeObj);
    }
    if (addType === 2) {
      // 分组
      let obj = otherForm.getFieldsValue();
      submitCallback(obj, nodeObj);
    }
  };
  const finish = () => {
    submit();
  };
  return (
    <div>
      {addType === 1 && (
        <Form
          form={form}
          name="groupform"
          {...layout}
          className={styles.formStyle}
          onFinish={finish}
        >
          <Item
            label="菜单名称"
            name="menuName"
            rules={[
              {
                required: true,
                message: '请输入分组名称',
              },
            ]}
          >
            <Input />
          </Item>
          <Item label="菜单别名" name="shortName">
            <Input />
          </Item>
          <Item
            label="菜单图标"
            name="imageUrl"
            rules={[
              {
                required: true,
                message: '请选择在线图标',
              },
            ]}
          >
            <PicturesWall />
          </Item>
张烨's avatar
张烨 committed
74
          <Item label="功能路径" name="pageUrl">
张烨's avatar
张烨 committed
75 76
            <Input />
          </Item>
张烨's avatar
张烨 committed
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
          <Item label="配置文件" name="config">
            <EditeConfigWrapper>
              <Select
                allowClear
                showSearch
                filterOption={(input, option) =>
                  option.children.toLowerCase().indexOf(input.toLowerCase()) >=
                  0
                }
              >
                {configFiles.map(c => (
                  <Select.Option key={c.text} value={c.value}>
                    {c.text}
                  </Select.Option>
                ))}
              </Select>
            </EditeConfigWrapper>
          </Item>
张烨's avatar
张烨 committed
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
          <Item wrapperCol={{ offset: 5 }} style={{ marginTop: '40px' }}>
            <Button type="primary" htmlType="submit" loading={submitLoading}>
              提交
            </Button>
          </Item>
        </Form>
      )}

      {addType === 2 && (
        <Form
          form={otherForm}
          name="menuform"
          {...layout}
          onFinish={finish}
          className={styles.formStyle}
        >
          <Item
            label="菜单名称"
            name="menuName"
            rules={[
              {
                required: true,
                message: '请输入菜单名称',
              },
            ]}
          >
            <Input />
          </Item>
          <Item label="菜单别名" name="shortName">
            <Input />
          </Item>
          <Item
            label="菜单图标"
            name="imageUrl"
            rules={[
              {
                required: true,
                message: '请选择菜单图标',
              },
            ]}
          >
            <PicturesWall />
          </Item>
          <Item wrapperCol={{ offset: 5 }} style={{ marginTop: '40px' }}>
            <Button type="primary" htmlType="submit" loading={submitLoading}>
              提交
            </Button>
          </Item>
        </Form>
      )}
    </div>
  );
};
export default AddForm;