AddForm.jsx 4.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

const { Item } = Form;
Maofei94's avatar
Maofei94 committed
8
const { Option } = Select;
张烨's avatar
张烨 committed
9
const AddForm = props => {
张烨's avatar
张烨 committed
10 11 12 13 14 15
  const {
    submitCallback,
    nodeObj,
    addType,
    submitLoading,
    configFiles,
Maofei94's avatar
Maofei94 committed
16
    productList,
张烨's avatar
张烨 committed
17
  } = props;
张烨's avatar
张烨 committed
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
  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,
Maofei94's avatar
Maofei94 committed
55
                message: '请输入菜单名称',
张烨's avatar
张烨 committed
56 57 58
              },
            ]}
          >
Maofei94's avatar
Maofei94 committed
59
            <Input placeholder="请输入菜单名称" />
张烨's avatar
张烨 committed
60 61
          </Item>
          <Item label="菜单别名" name="shortName">
Maofei94's avatar
Maofei94 committed
62
            <Input placeholder="请输入菜单别名" />
张烨's avatar
张烨 committed
63
          </Item>
Maofei94's avatar
Maofei94 committed
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
          <Item
            label="产品类型:"
            name="product"
            rules={[
              {
                required: true,
                message: '请选择产品类型',
              },
            ]}
          >
            <Select placeholder="请选择产品类型">
              {productList &&
                productList.map(item => (
                  <Option value={item.ProductName} key={item.Id}>
                    {item.ProductName}
                  </Option>
                ))}
            </Select>
          </Item>
张烨's avatar
张烨 committed
83 84 85 86 87 88
          <Item
            label="菜单图标"
            name="imageUrl"
            rules={[
              {
                required: true,
Maofei94's avatar
Maofei94 committed
89
                message: '请选择菜单图标',
张烨's avatar
张烨 committed
90 91 92
              },
            ]}
          >
Maofei94's avatar
Maofei94 committed
93
            <PicturesWall picType="menuNew" />
张烨's avatar
张烨 committed
94
          </Item>
Maofei94's avatar
Maofei94 committed
95 96 97 98 99 100 101 102 103 104 105
          <Item
            label="功能路径"
            name="pageUrl"
            rules={[
              {
                required: true,
                message: '请输入功能路径',
              },
            ]}
          >
            <Input placeholder="请输入功能路径" />
张烨's avatar
张烨 committed
106
          </Item>
张烨's avatar
张烨 committed
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
          <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
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
          <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
Maofei94's avatar
Maofei94 committed
142
            label="菜单组名称"
张烨's avatar
张烨 committed
143 144 145 146
            name="menuName"
            rules={[
              {
                required: true,
Maofei94's avatar
Maofei94 committed
147
                message: '请输入菜单组名称',
张烨's avatar
张烨 committed
148 149 150
              },
            ]}
          >
Maofei94's avatar
Maofei94 committed
151
            <Input placeholder="请输入菜单组名称" />
张烨's avatar
张烨 committed
152
          </Item>
Maofei94's avatar
Maofei94 committed
153 154
          <Item label="菜单组别名" name="shortName">
            <Input placeholder="请输入菜单组别名" />
张烨's avatar
张烨 committed
155 156
          </Item>
          <Item
Maofei94's avatar
Maofei94 committed
157
            label="菜单组图标"
张烨's avatar
张烨 committed
158 159 160 161
            name="imageUrl"
            rules={[
              {
                required: true,
Maofei94's avatar
Maofei94 committed
162
                message: '请选择菜单组图标',
张烨's avatar
张烨 committed
163 164 165
              },
            ]}
          >
Maofei94's avatar
Maofei94 committed
166
            <PicturesWall picType="menuNew" />
张烨's avatar
张烨 committed
167 168 169 170 171 172 173 174 175 176 177 178
          </Item>
          <Item wrapperCol={{ offset: 5 }} style={{ marginTop: '40px' }}>
            <Button type="primary" htmlType="submit" loading={submitLoading}>
              提交
            </Button>
          </Item>
        </Form>
      )}
    </div>
  );
};
export default AddForm;