EditModal.jsx 10.8 KB
Newer Older
皮倩雯's avatar
皮倩雯 committed
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 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
/* eslint-disable no-case-declarations */
/* eslint-disable indent */
import React, { useState, useEffect } from 'react';
import {
  Form,
  Modal,
  Input,
  Select,
  notification,
  Slider,
  InputNumber,
  Row,
  Col,
  Image,
  Radio,
  Button,
} from 'antd';
import styles from '../SchemeConfig.less';
import thumbnail_1 from '@/assets/images/thumbnail/thumbnail_1.jpg';
import thumbnail_2 from '@/assets/images/thumbnail/thumbnail_2.jpg';
import thumbnail_3 from '@/assets/images/thumbnail/thumbnail_3.jpg';
import thumbnail_4 from '@/assets/images/thumbnail/thumbnail_4.jpg';
import { SetServiceConfig } from '@/services/webConfig/api';
const { Item } = Form;
const { Option } = Select;
const EditModal = props => {
  const { callBackSubmit = () => {}, type, formObj, visible, baseMap } = props;
  const [loading, setLoading] = useState(false);
  const [radio, setRadio] = useState();
  const [alpha, setAlpha] = useState(1);
  const [mapType, setMapType] = useState(0);
  const [form] = Form.useForm();
  const arr = [
    'assets/images/thumbnail/thumbnail_1.jpg',
    'assets/images/thumbnail/thumbnail_2.jpg',
    'assets/images/thumbnail/thumbnail_3.jpg',
    'assets/images/thumbnail/thumbnail_4.jpg',
  ];

  // 提交
  const onSubmit = () => {
    form.validateFields().then(validate => {
      if (validate) {
        let obj = form.getFieldsValue();
        let arr = {
          servicename: obj.servicename,
          terminalType: 'base',
          isBaseMap: true,
          jsonCfg: JSON.stringify({
            alpha: alpha,
            label: obj.label,
            url: obj.url,
            icon: obj.icon,
            type: obj.type,
          }),
        };
        SetServiceConfig(arr)
          .then(res => {
            setLoading(false);
60
            if (res.code == '0') {
皮倩雯's avatar
皮倩雯 committed
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 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 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202
              form.resetFields();
              callBackSubmit();
              notification.success({
                message: '提示',
                duration: 3,
                description: res.message || type == 'add' ? '新增成功' : '编辑成功',
              });
            } else {
              notification.error({
                message: '提示',
                duration: 3,
                description: res.message || type == 'add' ? '新增失败' : '编辑失败',
              });
            }
          })
          .catch(err => {
            setLoading(false);
          });
      }
    });
  };

  const onFinish = value => {};
  useEffect(() => {
    switch (type) {
      case 'add':
        setRadio('');
        form.resetFields();
        form.setFieldsValue({
          servicename: baseMap[0],
          label: baseMap[0],
          type: servicenameToType(baseMap[0]),
        });

        break;
      case 'edit':
        form.setFieldsValue({ ...formObj });
        let index = formObj.icon.lastIndexOf('/');
        let str = formObj.icon.substring(index + 1, formObj.icon.length);
        let defaultIndex = arr.filter((item, index) => {
          if (item.indexOf(str) !== -1) {
            return index;
          }
        });
        setRadio(defaultIndex[0]);
        break;
      default:
        break;
    }
    // if (form.getFieldsValue('').servicename && baseMap.indexOf(form.getFieldsValue('').servicename) == 2 || baseMap.indexOf(form.getFieldsValue('').servicename) == 3) {
    //   setMapType(1)
    // }
    // else {
    //   setMapType(0)
    // }
  }, [visible]);

  const layout = {
    layout: 'horizontal',
    labelCol: {
      span: 4,
    },
    wrapperCol: {
      span: 18,
    },
  };
  const onChange = value => {
    let silderData = value == 100 ? 1 : (value / 100).toFixed(1);
    setAlpha(silderData);
  };
  const tipFormatter = value => {
    return (value / 100).toFixed(1);
  };

  const imgURL = [
    {
      url: thumbnail_1,
    },
    {
      url: thumbnail_2,
    },
    {
      url: thumbnail_3,
    },
    {
      url: thumbnail_4,
    },
  ];

  const radioChange = e => {
    setRadio(e.target.value);
  };
  const handleChange = value => {
    form.setFieldsValue({
      type: servicenameToType(value),
    });
    // if (baseMap.indexOf(value) == 2 || baseMap.indexOf(value) == 3) {
    //   setMapType(1)
    // }
    // else {
    //   setMapType(0)
    // }
  };
  //添加地图类型
  const servicenameToType = servicename => {
    // if (servicename.indexOf('地形图') > -1)
    //   servicename = '地形图'
    // if (servicename.indexOf('自定义底图') > -1)
    //   servicename = '自定义底图'
    switch (servicename) {
      case '谷歌地形':
        return 'google-v';
      case '谷歌影像(注记)':
        return 'google-i-a';
      case '谷歌影像':
        return 'google-i';
      case '高德影像':
        return 'amap-i';
      case '高德地形':
        return 'amap-v';
      case '天地图影像':
        return 'tianditu-i-ia';
      case '天地图地形':
        return 'tianditu-v-va';
      case '自定义底图':
        return 'google-user';
      case '地形图':
      case '瓦片图':
        return 'pipenet-tile';
      default:
        return 'arcgis-tilelayer';
    }
  };
  // 选择坐标系
  const handleCoordinate = () => {};
  // 选择图层
  const handleLayer = () => {};
  // 选择工作空间
  const handleWorkSpance = () => {};

  return (
    <Modal
203
      title={`${type === 'add' ? '添加' : '编辑'}基础底图`}
皮倩雯's avatar
皮倩雯 committed
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363
      bodyStyle={{ width: '100%', minHeight: '100px' }}
      style={{ top: '150px' }}
      width="700px"
      destroyOnClose
      maskClosable={false}
      cancelText="取消"
      okText="确认"
      {...props}
      onOk={() => onSubmit()}
      confirmLoading={loading}
      forceRender={true}
      getContainer={false}
    >
      {visible && (
        <Form form={form} {...layout} onFinish={onFinish}>
          <Item
            label="服务名"
            name="servicename"
            rules={[{ required: true, message: '请选择服务名' }]}
          >
            <Select onChange={handleChange}>
              {type === 'add'
                ? baseMap.map((item, index) => {
                    return (
                      <Option value={item} key={index}>
                        {item}
                      </Option>
                    );
                  })
                : ''}
            </Select>
          </Item>
          <Item label="标签" name="label" rules={[{ required: true, message: '请输入标签' }]}>
            <Input placeholder="请输入IP" allowClear />
          </Item>

          <Item label="类型" name="type">
            <Input placeholder="请输入类型" allowClear disabled />
          </Item>
          <Item label="URL" name="url">
            <Input placeholder="请输入URL" allowClear />
          </Item>
          <Item label="透明度">
            <Row>
              <Col span={12}>
                <Slider
                  min={0}
                  max={100}
                  onChange={onChange}
                  step={0.1}
                  tipFormatter={tipFormatter}
                  defaultValue={type === 'add' ? 100 : formObj.alpha * 100}
                />
              </Col>
              <Col span={4}>
                <InputNumber
                  min={0}
                  max={1}
                  disabled
                  style={{ margin: '0 16px' }}
                  defaultValue={type === 'add' ? 1 : formObj.alpha}
                  value={alpha}
                  onChange={onChange}
                />
              </Col>
            </Row>
          </Item>
          <Item label="选择缩略图" name="icon">
            <div className={styles.imgList}>
              {imgURL.map((item, index) => {
                return (
                  <div key={index} className={styles.imgItem}>
                    <Image width={100} height={63} src={item.url} />
                    <Radio.Group options={item} onChange={radioChange} value={radio}>
                      <Radio value={arr[index]} />
                    </Radio.Group>
                  </div>
                );
              })}
            </div>
          </Item>
          <Item label="缩略图" name="icon" rules={[{ required: true, message: '请选择缩略图' }]}>
            <Input placeholder="请输入URL" allowClear />
          </Item>
          {mapType === 1 ? (
            <>
              <Item label="ip地址" name="IP" rules={[{ required: true, message: '请输入ip地址' }]}>
                <Input placeholder="请输入ip地址" allowClear />
              </Item>
              <Item
                label="geoserver名"
                name="gis"
                rules={[{ required: true, message: '请选择缩略图' }]}
              >
                <div className={styles.imgList}>
                  <Input placeholder="请输入gis服务器名" allowClear />
                  <Button style={{ marginLeft: '0.5rem' }}>选择工作空间</Button>
                </div>
              </Item>

              <Item
                label="工作空间"
                name="workSpance"
                rules={[{ required: true, message: '请选择工作空间' }]}
              >
                <Select onChange={handleWorkSpance} />
              </Item>
              <Item
                label="图层名"
                name="layer"
                rules={[{ required: true, message: '请选择图层名' }]}
              >
                <Select onChange={handleLayer} />
              </Item>
              <Item
                label="坐标系名"
                name="coordinate"
                rules={[{ required: true, message: '请选择坐标系名' }]}
              >
                <Select onChange={handleCoordinate} />
              </Item>

              <Item
                label="底图范围"
                name="range"
                rules={[{ required: true, message: '请选择底图范围' }]}
              >
                <Input placeholder="xmin,ymin,xmax,ymax" allowClear />
              </Item>
              <Item
                label="起始级别"
                name="initLevel"
                rules={[{ required: true, message: '请选择起始级别' }]}
              >
                <Input placeholder="最初显示级别" allowClear />
              </Item>
              <Item
                label="最大级别"
                name="maxLevel"
                rules={[{ required: true, message: '请选择最大级别' }]}
              >
                <Input placeholder="最大显示级别" allowClear />
              </Item>
              <Item
                label="代理url"
                name="proxy"
                rules={[{ required: true, message: '请选择缩略图' }]}
              >
                <Input placeholder="请输入URL" allowClear />
              </Item>
            </>
          ) : (
            ''
          )}
        </Form>
      )}
    </Modal>
  );
};
export default EditModal;