solutionConfig.jsx 14.7 KB
Newer Older
1
import { Space, Table, Button, Popconfirm, notification, Divider, Checkbox, Spin } from 'antd';
2
import React, { useState, useEffect, useCallback } from 'react';
3
import VisibleRoleModal from '@/pages/platformCenter/messageManage/projectManage/components/RolseSelect/VisibleRoleModal';
4 5
import { PlusOutlined, UserAddOutlined } from '@ant-design/icons';
import styles from '../dimensionsConfig.less';
6
import {
7 8 9 10 11 12 13
  deleteConfig,
  SettingRoleWebSchema,
  SetServiceConfig,
  DeleteWebSchema,
  GetWebSchemaList,
  GetSchemaInfoList,
  IsActionWebSchema,
14
} from '@/services/webConfig/api';
15
import RoleModal from '../../schemeConfig/solutionConfig/RoleModal';
16
import AddModal from './AddModal';
17
const VectorData = props => {
18 19
  const [treeLoading, setTreeLoading] = useState(false); // 弹窗显示
  const [schemename, setSchemename] = useState([]);
20
  const [record, setRecord] = useState({}); // 选中关联角色的方案名
21 22 23
  const [webCurrent, setWebCurrent] = useState(0); // web列表下标
  const [handCurrent, setHandCurrent] = useState(0); // hand列表下标
  const [webData, setWebData] = useState([]); // web数据
24
  const [handData, setHandData] = useState([]); // 手持数据
25 26 27 28 29 30 31
  const [visible, setVisible] = useState(false); // 弹窗
  const [flag, setFlag] = useState(0); // 更新list
  const [handStatus, setHandStatus] = useState([]); // 更新状态
  const [webStatus, setWebStatus] = useState([]); // 更新状态
  const [type, setType] = useState(''); // 弹窗类型
  const [checkLoading, setCheckLoading] = useState(false);
  const [formObj, setFormObj] = useState({ user: 'admin', password: 'geoserver' });
32 33 34
  const [addVisible, setAddVisible] = useState(false);
  const [checkValue, setCheckValue] = useState([]);

35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
  const columns = [
    {
      title: '默认方案',
      align: 'center',
      render: (text, record, index) => (
        <Space>
          <Checkbox
            checked={webStatus[index + webCurrent * 5]}
            onChange={e => {
              onChangeCheck(e, record, index + webCurrent * 5);
            }}
          />
        </Space>
      ),
    },
    {
      title: '方案名',
      align: 'center',
      render: (text, record, index) => <Space>{record.scheme.schemename}</Space>,
    },
    {
      title: '关联角色',
      align: 'center',
58 59 60 61 62 63
      render: record => (
        <Space size="middle">
          <UserAddOutlined
            onClick={() => pickRole(record)}
            style={{ fontSize: '18px', color: '#1890FF' }}
          />
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
        </Space>
      ),
    },
    {
      title: '编辑',
      align: 'center',
      render: (text, record, index) => (
        <Space>
          <div onClick={e => e.stopPropagation()}>
            <Popconfirm
              title="是否删除此条方案?"
              okText="确认"
              cancelText="取消"
              onConfirm={() => {
                delWebConfirm(record);
              }}
            >
              <Button size="small" danger>
                删除
              </Button>
            </Popconfirm>
          </div>
        </Space>
      ),
    },
  ];
  // const columns1 = [
  //     {
  //         title: '查询方案',
  //         align: 'center',
  //         render: (text, record, index) => (
  //             <Space>
  //                 <Checkbox
  //                     checked={handStatus[index + handCurrent * 5]}
  //                     onChange={e => {
  //                         onChangeHand(e, record, index + handCurrent * 5);
  //                     }}
  //                 />
  //             </Space>
  //         ),
  //     },
  //     {
  //         title: '方案名',
  //         align: 'center',
  //         render: (text, record, index) => (
  //             <Space>
  //               {record.scheme.schemename}
  //             </Space>
  //         ),
  //     },
  //     {
  //         title: '关联角色',
  //         align: 'center',
  //         render: (text, record, index) => (
  //             <Space>
  //                 <div onClick={() => pickRole(record)} style={{ cursor: 'pointer' }}>
  //                     <VisibleRoleModal onSubmit={onPushSubmit} title={"关联角色"} initValues ={record.roles!=null?record.roles.split(","):[]} operate={<UserAddOutlined />} />
  //                 </div>
  //             </Space>
  //         ),
  //     },
  //     {
  //         title: '编辑',
  //         align: 'center',
  //         render: (text, record, index) => (
  //             <Space>
  //                 <div onClick={e => e.stopPropagation()}>
  //                     <Popconfirm
  //                         title="是否删除此条方案?"
  //                         okText="确认"
  //                         cancelText="取消"
  //                         onConfirm={() => {
  //                             delhandConfirm(record);
  //                         }}
  //                     >
  //                         <Button size="small" danger>
  //                             删除
  //                         </Button>
  //                     </Popconfirm>
  //                 </div>
  //             </Space>
  //         ),
  //     }
147

148
  // ];
149
  // 获取选中的角色
150
  const onPushSubmit = value => {
151
    setAddVisible(false);
152 153 154
    if (value.length) {
      let query = {
        schemaname: record.scheme.schemename,
155
        roles: value.join(','),
156 157 158
      };
      SettingRoleWebSchema(query)
        .then(res => {
159
          if (res.code === 0) {
160 161 162 163 164
            prompt('success', '关联角色成功');
            setFlag(flag + 1);
          } else {
            prompt('fail', '关联角色失败');
          }
165
        })
166 167 168
        .catch(err => {
          prompt('fail', '网络请求失败');
        });
169
    }
170
  };
171
  // 获取角色
172 173 174 175 176 177
  const pickRole = e => {
    setRecord(e);
    setAddVisible(true);
    let arr = e.roles != null ? e.roles.split(',') : [];
    console.log(arr);
    setCheckValue(arr);
178
  };
179
  // 设置web方案
180 181 182 183 184 185 186 187 188 189 190 191
  const onChangeCheck = (e, record, index) => {
    setCheckLoading(true);
    IsActionWebSchema({ schemaname: record.scheme.schemename }).then(res => {
      setCheckLoading(false);
      if (res.msg === '') {
        prompt('success', '设置成功');
        setFlag(flag + 1);
      } else {
        prompt('fail', res.msg);
      }
    });
  };
192

193
  // 选择手持方案
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213
  const onChangeHand = (e, record, index) => {
    setCheckLoading(true);
    const newLoadings = [...handStatus];
    newLoadings.map((item, loadIndex) => {
      return loadIndex == index
        ? (newLoadings[loadIndex] = !newLoadings[loadIndex])
        : (newLoadings[loadIndex] = false);
    });
    setHandStatus(newLoadings);
    let query = {
      schemename: record['schemename'],
      terminalType: 'phone',
      isBaseMap: false,
      jsonCfg: JSON.stringify({
        isDefault: newLoadings[index],
      }),
    };
    if (!newLoadings[index]) {
      SetServiceConfig(query).then(res => {
        setCheckLoading(false);
214
        if (res.code == '0') {
215 216 217 218 219 220
          const changehandData = [...handData];
          changehandData[index].isDefault = false;
          setHandData(changehandData);
          prompt('success', '设置成功');
        } else {
          prompt('fail', `${record['schemename']}默认设置时遇到错误:` + res.message);
221
        }
222 223 224 225 226 227 228 229 230 231 232 233 234
      });
      return;
    }
    var beforeDefault = handData.findIndex(item => item['isDefault']);
    SetServiceConfig({
      schemename: record['schemename'],
      terminalType: 'phone',
      isBaseMap: false,
      jsonCfg: JSON.stringify({
        isDefault: true,
      }),
    }).then(res => {
      setCheckLoading(false);
235
      if (res.code == '0') {
236 237 238 239 240 241
        const changehandData = [...handData];
        changehandData[index].isDefault = true;
        setHandData(changehandData);
        if (beforeDefault != -1) {
          SetServiceConfig({
            schemename: changehandData[beforeDefault].schemename,
242 243 244
            terminalType: 'phone',
            isBaseMap: false,
            jsonCfg: JSON.stringify({
245 246 247 248 249 250 251 252 253 254
              isDefault: false,
            }),
          }).then(res => {
            setCheckLoading(false);
            if (res.IsSuccess) {
              const changehandData1 = [...handData];
              changehandData1[beforeDefault].isDefault = false;
              setHandData(changehandData1);
              prompt('success', '设置成功');
              return;
255
            }
256 257
            prompt('fail', `${record['schemename']}默认设置时遇到错误:` + res.message);
          });
258
        }
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274
      }
    });
  };
  const prompt = (type, content) => {
    if (type == 'success') {
      notification.success({
        message: '提示',
        duration: 3,
        description: content,
      });
    } else {
      notification.error({
        message: '提示',
        duration: 3,
        description: content,
      });
275
    }
276 277 278 279 280
  };
  const onSubmit = prop => {
    setVisible(false);
    setFlag(flag + 1);
  };
281
  // 删除web配置方案
282 283 284 285 286 287 288 289 290 291
  const delWebConfirm = record => {
    DeleteWebSchema(record.scheme.schemename).then(res => {
      if (res.msg === '') {
        prompt('success', '删除成功');
        setFlag(flag + 1);
      } else {
        prompt('fail', '删除失败');
      }
    });
  };
292
  // 删除手持配置方案
293 294 295 296 297 298
  const delhandConfirm = record => {
    deleteConfig({
      schemename: record['schemename'],
      terminalType: 'phone',
      isBaseMap: false,
    }).then(res => {
299
      if (res.code == '0') {
300 301 302 303 304 305 306
        prompt('success', '删除成功');
        setFlag(flag + 1);
      } else {
        prompt('fail', '删除失败');
      }
    });
  };
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
  const addType = type => {
    setType(type);
    let listData = [];
    type == 'add' ? (listData = webData) : (listData = handData);
    let webSchemenameArr = [],
      schemeArr = [];
    setTreeLoading(true);
    GetSchemaInfoList().then(res => {
      if (res.data && res.data.length) {
        setTreeLoading(false);
        listData.map(item => {
          webSchemenameArr.push(item.scheme.schemename);
        });
        res.data.map(item => {
          if (!webSchemenameArr.includes(item.schemename)) schemeArr.push(item.schemename);
        });
        setSchemename(schemeArr);
        if (schemeArr.length) {
          setVisible(true);
        } else {
          notification.warning({
            message: '提示',
            duration: 3,
            description: '请先配置方案',
          });
        }
      } else {
        setTreeLoading(false);
        notification.warning({
          message: '提示',
          duration: 3,
          description: '请先配置方案',
        });
      }
    });
  };
  useEffect(() => {
    renderTile();
  }, [flag]);
  // 获取瓦片数据配置数据
  const renderTile = () => {
    setCheckLoading(true);
350
    // 查询手持方案
351 352 353 354
    // var schemeConfigQueryRequest = GetMaplayerByTerminalType({
    //     terminalType: 'phone',
    //     isBaseMap: false
    // })
355
    // 查询web方案
356 357 358 359 360 361 362 363 364 365 366
    var webSchemeQueryRequest = GetWebSchemaList();
    Promise.all([webSchemeQueryRequest])
      .then(res => {
        // if (res[0].msg==="Ok" && res[0].data.phone) {
        //     let arr = []
        //     res[0].data.phone.optionalLayer.layers.map((item, index) => {
        //         if (item.isDefault) {
        //             arr.push(true)
        //         } else {
        //             arr.push(false)
        //         }
367

368 369 370 371 372
        //         item.isStatus = 'phone'
        //         return item
        //     })
        //     setHandData(res[0].data.phone.optionalLayer.layers)
        //     setHandStatus(arr)
373

374 375 376 377 378 379
        // }
        if (res[0].msg === 'Ok' && res[0].data) {
          let arr = [];
          res[0].data.map((item, index) => {
            if (item.isDefault) {
              arr.push(true);
380
            } else {
381
              arr.push(false);
382
            }
383 384 385 386 387 388 389 390 391 392 393 394
            item.isStatus = 'web';
            return item;
          });
          setWebData(res[0].data);
          setWebStatus(arr);
        }
        setCheckLoading(false);
      })
      .catch(e => {
        setCheckLoading(false);
      });
  };
395

396 397 398 399 400 401 402 403 404 405 406 407 408 409
  const rolCallBack = useCallback(list => {
    let strList = [];
    if (list.length > 0) {
      list.forEach(item => {
        console.log(item, 'item');
        Object.keys(item.last).forEach(i => {
          strList.push(i);
        });
      });
      console.log(strList);
      onPushSubmit(strList);
    }
  });

410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430
  return (
    <>
      <Spin tip="loading..." spinning={checkLoading}>
        <div className={styles.solutionConfig}>
          <div>
            <Divider orientation="left">
              <div className={styles.divider}>
                {' '}
                Web{' '}
                <PlusOutlined
                  onClick={() => {
                    addType('add');
                  }}
                  className={styles.dividerIcon}
                />
              </div>
            </Divider>
            <Table
              columns={columns}
              dataSource={webData}
              bordered
431
              style={{ height: 'calc(100vh - 230px)' }}
432 433 434 435 436 437 438 439
              pagination={{
                showTotal: (total, range) => `第${range[0]}-${range[1]} 条/共 ${total} 条`,
                defaultPageSize: 8,
                onChange: value => {
                  setWebCurrent(value - 1);
                },
              }}
              rowKey={(record, index) => record.scheme.schemename}
440
              scroll={{ y: 300 }}
441 442 443
            />
          </div>
          {/* <Divider orientation="left"><div className={styles.divider}>手持 <PlusOutlined
444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461
                        onClick={() => { addType('addHand') }}
                        className={styles.dividerIcon} /></div> </Divider>
                    <Table
                        columns={columns1}
                        dataSource={handData}
                        bordered
                        rowKey="schemename"
                        scroll={{ y: 400 }}
                        pagination={{
                            showTotal: (total, range) =>
                                `第${range[0]}-${range[1]} 条/共 ${total} 条`,
                            defaultPageSize: 8,
                            onChange: (value) => {
                                setHandCurrent(value - 1)
                            }

                        }}
                    >
shaoan123's avatar
shaoan123 committed
462
                    </Table> */}
463 464 465 466 467 468 469 470 471 472
        </div>
      </Spin>
      <AddModal
        visible={visible}
        onCancel={() => setVisible(false)}
        callBackSubmit={onSubmit}
        type={type}
        formObj={formObj}
        listData={schemename}
      />
473 474 475 476 477 478 479 480
      <RoleModal
        selectValue={checkValue.toString()}
        visible={addVisible}
        rolCallBack={roleList => rolCallBack(roleList)}
        onCancel={() => {
          setAddVisible(false);
        }}
      />
481 482 483 484
    </>
  );
};
export default VectorData;