AddForm.jsx 5.38 KB
Newer Older
Maofei94's avatar
Maofei94 committed
1
import React, { useState, useEffect } from 'react';
Maofei94's avatar
Maofei94 committed
2 3 4
import { Form, Input, Button, Row, Col } from 'antd';
import styles from './addForm.less';
import PicturesWall from '@/components/Upload/index';
Maofei94's avatar
Maofei94 committed
5 6
import CheckList from './checkBox';
import checkStyles from './checkBox';
Maofei94's avatar
Maofei94 committed
7 8 9

const { Item } = Form;
const AddForm = props => {
Maofei94's avatar
Maofei94 committed
10 11 12 13 14 15 16 17 18
  const {
    submitCallback,
    nodeType,
    nodeObj,
    addType,
    submitLoading,
    valueCallback,
    addList,
  } = props;
Maofei94's avatar
Maofei94 committed
19
  const [form] = Form.useForm();
Maofei94's avatar
Maofei94 committed
20
  const [otherForm] = Form.useForm();
Maofei94's avatar
Maofei94 committed
21
  console.log(nodeObj, 'nodeObj');
Maofei94's avatar
Maofei94 committed
22
  const layout = {
Maofei94's avatar
Maofei94 committed
23 24 25 26 27 28 29 30 31 32 33 34 35
    layout: 'horizontal',
    labelCol: { span: 4, offset: 1 },
    wrapperCol: { span: 16 },
  };
  const submit = () => {
    if (addType === 1 || addType === 2) {
      let obj = form.getFieldsValue();
      submitCallback(obj, nodeObj);
    }
    if (addType === 3 || addType === 4) {
      let obj = otherForm.getFieldsValue();
      submitCallback(obj, nodeObj);
    }
Maofei94's avatar
Maofei94 committed
36
  };
Maofei94's avatar
Maofei94 committed
37 38 39
  const finish = () => {
    submit();
  };
Maofei94's avatar
Maofei94 committed
40
  useEffect(() => {}, [nodeObj, addType]);
Maofei94's avatar
Maofei94 committed
41
  return (
Maofei94's avatar
Maofei94 committed
42 43
    <div>
      {(addType === 1 || addType === 2) && (
Maofei94's avatar
Maofei94 committed
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
        <Form
          form={form}
          name="groupform"
          {...layout}
          className={styles.formStyle}
          onFinish={finish}
        >
          <Item
            label="分组名称"
            name="menuName"
            rules={[
              {
                required: true,
                message: '请输入分组名称',
              },
            ]}
          >
Maofei94's avatar
Maofei94 committed
61 62 63 64 65 66
            <Input />
          </Item>
          <Item label="分组别名" name="shortName">
            <Input />
          </Item>
          {addType === 1 && (
Maofei94's avatar
Maofei94 committed
67 68 69 70 71 72 73 74 75 76
            <Item
              label="在线图标"
              name="imageUrl"
              rules={[
                {
                  required: true,
                  message: '请选择在线图标',
                },
              ]}
            >
Maofei94's avatar
Maofei94 committed
77 78 79 80
              <PicturesWall />
            </Item>
          )}
          {addType === 1 && (
Maofei94's avatar
Maofei94 committed
81 82 83 84 85 86 87 88 89 90
            <Item
              label="离线图标"
              name="offlineImgUrl"
              rules={[
                {
                  required: true,
                  message: '请选择离线图标',
                },
              ]}
            >
Maofei94's avatar
Maofei94 committed
91 92 93 94 95
              <PicturesWall />
            </Item>
          )}

          {addType === 2 && (
Maofei94's avatar
Maofei94 committed
96 97 98 99 100 101 102 103 104 105
            <Item
              label="分组图标"
              name="imageUrl"
              rules={[
                {
                  required: true,
                  message: '请选择分组图标',
                },
              ]}
            >
Maofei94's avatar
Maofei94 committed
106 107 108 109 110 111 112
              <PicturesWall />
            </Item>
          )}
          <Item label="功能参数" name="funParam">
            <Input />
          </Item>
          <Item wrapperCol={{ offset: 5 }} style={{ marginTop: '40px' }}>
Maofei94's avatar
Maofei94 committed
113
            <Button type="primary" htmlType="submit" loading={submitLoading}>
Maofei94's avatar
Maofei94 committed
114 115 116 117 118 119 120
              提交
            </Button>
          </Item>
        </Form>
      )}

      {(addType === 3 || addType === 4) && (
Maofei94's avatar
Maofei94 committed
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
        <Form
          form={otherForm}
          name="menuform"
          {...layout}
          onFinish={finish}
          className={styles.formStyle}
        >
          <Item
            label="菜单名称"
            name="menuName"
            rules={[
              {
                required: true,
                message: '请输入菜单名称',
              },
            ]}
          >
Maofei94's avatar
Maofei94 committed
138 139 140 141 142 143
            <Input />
          </Item>
          <Item label="菜单别名" name="shortName">
            <Input />
          </Item>
          {addType === 3 && (
Maofei94's avatar
Maofei94 committed
144 145 146 147 148 149 150 151 152 153
            <Item
              label="在线图标"
              name="imageUrl"
              rules={[
                {
                  required: true,
                  message: '请选择在线图标',
                },
              ]}
            >
Maofei94's avatar
Maofei94 committed
154 155 156 157
              <PicturesWall />
            </Item>
          )}
          {addType === 3 && (
Maofei94's avatar
Maofei94 committed
158 159 160 161 162 163 164 165 166 167
            <Item
              label="离线图标"
              name="offlineImgUrl"
              rules={[
                {
                  required: true,
                  message: '请选择离线图标',
                },
              ]}
            >
Maofei94's avatar
Maofei94 committed
168 169 170 171
              <PicturesWall />
            </Item>
          )}
          {addType === 4 && (
Maofei94's avatar
Maofei94 committed
172 173 174 175 176 177 178 179 180 181
            <Item
              label="菜单图标"
              name="imageUrl"
              rules={[
                {
                  required: true,
                  message: '请选择菜单图标',
                },
              ]}
            >
Maofei94's avatar
Maofei94 committed
182 183 184
              <PicturesWall />
            </Item>
          )}
Maofei94's avatar
Maofei94 committed
185 186 187 188 189 190 191 192 193 194
          <Item
            label="功能路径"
            name="pageUrl"
            rules={[
              {
                required: true,
                message: '请输入功能路径',
              },
            ]}
          >
Maofei94's avatar
Maofei94 committed
195 196 197 198 199
            <Input />
          </Item>
          <Item label="功能参数" name="funParam">
            <Input />
          </Item>
Maofei94's avatar
Maofei94 committed
200 201 202 203 204
          {/* <CheckList
            nodeType={addType}
            valueCallback={valueCallback}
            addList={addList}
          /> */}
Maofei94's avatar
Maofei94 committed
205
          <Item wrapperCol={{ offset: 5 }} style={{ marginTop: '40px' }}>
Maofei94's avatar
Maofei94 committed
206
            <Button type="primary" htmlType="submit" loading={submitLoading}>
Maofei94's avatar
Maofei94 committed
207 208 209 210 211 212
              提交
            </Button>
          </Item>
        </Form>
      )}
    </div>
Maofei94's avatar
Maofei94 committed
213 214 215
  );
};
export default AddForm;