AddModal.jsx 10.5 KB
Newer Older
1 2 3 4 5 6 7 8
import React, { useState, useEffect } from 'react';
import { Form, Modal, Input, Select, notification, Slider, InputNumber, Row, Col, Image, Radio, Button } from 'antd';
import styles from '../dimensionsConfig.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 {
shaoan123's avatar
shaoan123 committed
9
  AddBaseMap, EditBaseMap
10
} from '@/services/webConfig/api';
11
import { number } from 'prop-types';
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
const { Item } = Form;
const { Option } = Select;
const AddModal = 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) {
shaoan123's avatar
shaoan123 committed
27
        let str = type === 'add' ? AddBaseMap : EditBaseMap
28 29
        let obj = form.getFieldsValue();
        let arr = {
30 31
          name: obj.name,
          type: obj.type,
shaoan123's avatar
shaoan123 committed
32
          opacity: Number(alpha),
33 34
          icon: obj.icon,
          url: obj.url
35
        }
36
        str(arr)
37 38
          .then(res => {
            setLoading(false);
shaoan123's avatar
shaoan123 committed
39
            if (res.msg === "Ok" || res.msg === "") {
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
              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':
shaoan123's avatar
shaoan123 committed
65 66 67 68 69 70 71 72
        setRadio('')
        setAlpha(1)
        form.resetFields();
        form.setFieldsValue({
          name: baseMap[0],
          type: servicenameToType(baseMap[0])
        })

73 74 75
        break;
      case 'edit':
        form.setFieldsValue({ ...formObj });
76
        setAlpha(formObj.opacity)
77 78
        let index = formObj.icon.lastIndexOf("/")
        let str = formObj.icon.substring(index + 1, formObj.icon.length);
79 80
        let flag = ''
        let defaultIndex = arr.filter((item, index1) => {
81
          if (item.indexOf(str) !== -1) {
82
            flag = index1
83
          }
84 85
        });
        setRadio(arr[flag])
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
        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: 16,
    },
  };
  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) {
152 153
      case "高德街道":
        return 'amap-v';
154 155
      case "高德影像":
        return 'amap-i';
156 157
      case "天地图街道":
        return 'tianditu-v';
158
      case "天地图影像":
159
        return 'tianditu-i';
shaoan123's avatar
shaoan123 committed
160
      case "百度街道":
邹绪超's avatar
邹绪超 committed
161
        return 'baiduMapStreet';
shaoan123's avatar
shaoan123 committed
162
      case "百度影像":
邹绪超's avatar
邹绪超 committed
163 164 165 166 167
        return 'baiduMapImage';
      case "mapBox地图" :
        return 'mapBoxImage';
      case "arcgis地图" :
        return "arcgisImage"
168
      default:
169
        return 'amap-v';
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
    }
  }
  //选择坐标系
  const handleCoordinate = () => { }
  //选择图层
  const handleLayer = () => { }
  //选择工作空间
  const handleWorkSpance = () => { }

  return (
    <Modal
      title={`${type === 'add' ? '添加' : '编辑'}底图`}
      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
198 199
            label="名称"
            name="name"
200 201 202 203 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
            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="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}
229
                  defaultValue={type === 'add' ? 100 : formObj.opacity * 100}
230 231 232 233 234 235 236 237
                />
              </Col>
              <Col span={4}>
                <InputNumber
                  min={0}
                  max={1}
                  disabled
                  style={{ margin: '0 16px' }}
238
                  defaultValue={type === 'add' ? 1 : formObj.opacity}
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
                  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>
                  </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}>

                </Select>
              </Item>
              <Item
                label="图层名"
                name="layer"
                rules={[{ required: true, message: '请选择图层名' }]}
              >
                <Select onChange={handleLayer}>

                </Select>
              </Item>
              <Item
                label="坐标系名"
                name="coordinate"
                rules={[{ required: true, message: '请选择坐标系名' }]}
              >
                <Select onChange={handleCoordinate}>

                </Select>
              </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 AddModal;