ProjectManage.jsx 15.1 KB
Newer Older
皮倩雯's avatar
皮倩雯 committed
1 2 3 4 5
/* eslint-disable array-callback-return */
/* eslint-disable no-shadow */
/* eslint-disable indent */
/* eslint-disable eqeqeq */
import React, { useEffect, useState } from 'react';
6
import {
皮倩雯's avatar
皮倩雯 committed
7 8 9 10 11 12 13 14 15 16
  // Tree,
  Table,
  Space,
  Input,
  Button,
  Select,
  Popconfirm,
  message,
  Tooltip,
  Spin,
17
  notification,
18
  Tag,
19
} from 'antd';
皮倩雯's avatar
皮倩雯 committed
20 21 22 23 24 25
import {
  PlusCircleOutlined,
  EditTwoTone,
  DeleteOutlined,
  FundViewOutlined,
  FieldTimeOutlined,
26
  AlertTwoTone,
皮倩雯's avatar
皮倩雯 committed
27
} from '@ant-design/icons';
28
import { useHistory } from 'react-router-dom';
皮倩雯's avatar
皮倩雯 committed
29
import EditModal from './components/EditModal';
30
import PushTest from './components/PushTest/PushTest';
皮倩雯's avatar
皮倩雯 committed
31 32 33 34 35 36 37
import VisibleRoleModal from './components/RolseSelect/VisibleRoleModal';
import {
  GetMessageConfigList,
  TestPush,
  DeleteMessageConfig,
  GetMsgTypeList,
  DeleteIISAgentConfig,
邓超's avatar
邓超 committed
38
} from '@/services/messagemanage/messagemanage';
皮倩雯's avatar
皮倩雯 committed
39
import styles from './ProjectManage.less';
40 41
const { Search } = Input;
const { Option } = Select;
42
const ProjectManage = props => {
皮倩雯's avatar
皮倩雯 committed
43 44 45 46 47 48
  const history = useHistory();
  const [visibleParams, setvisibleParams] = useState({
    addVisible: false, // 新增弹窗
    delVisible: false, // 删除弹窗
    editVisible: false, // 修改弹窗
    spinLoading: false, // 加载弹窗
49
    pushTestVisible: false, // 推送测试弹窗
皮倩雯's avatar
皮倩雯 committed
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
    btnLoading: false,
    loading: false,
    checkBoxLoading: false,
  });
  const [currentType, setCurrentType] = useState('全部');
  const [currentName, setCurrentName] = useState('全部');
  const [messageTypes, setMessageTypes] = useState([]);
  const [currentTemplate, setCurrentTempalte] = useState({});
  const [flag, setFlag] = useState(0);
  const [pageIndex, setPageIndex] = useState(0);
  const [pageSize, setPageSize] = useState(10);
  const [dataList, setDataList] = useState([]);
  const [treeLoading, setTreeLoading] = useState(false);
  const [showSearchStyle, setShowSearchStyle] = useState(false); // 是否显示模糊查询样式
  const [value, setValue] = useState('');
65
  const [pushTestMsg, setPushTestMsg] = useState('');
66
  const [currentPage, setCurrentPage] = useState(1);
67
  const [nameList, setNameList] = useState([]);
皮倩雯's avatar
皮倩雯 committed
68 69 70 71
  const columns = [
    {
      title: '方案名称',
      dataIndex: 'name',
72
      align: 'center',
皮倩雯's avatar
皮倩雯 committed
73 74 75 76
      key: 'name',
      render: (text, record) => (
        <div>
          {record.type === '定时推送' ? (
77
            <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
皮倩雯's avatar
皮倩雯 committed
78 79 80 81 82 83 84 85 86 87 88
              <Tooltip title={text}>
                <FieldTimeOutlined
                  style={{
                    fontSize: '16px',
                    color: '#1890FF',
                    marginRight: '0.1rem',
                  }}
                />
              </Tooltip>
              {searchStyle(text)}
            </div>
89
          ) : (
90
            <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
91
              <Tooltip title={text}>
92
                <AlertTwoTone style={{ fontSize: '16px', marginRight: '0.1rem' }} />
93 94 95
              </Tooltip>
              {searchStyle(text)}
            </div>
皮倩雯's avatar
皮倩雯 committed
96 97 98 99
          )}
        </div>
      ),
    },
100 101 102 103 104 105 106
    {
      title: '消息标题',
      dataIndex: 'Title',
      align: 'center',
      key: 'Title',
      render: (text, record) => <div>{text === null || !text ? '-' : text}</div>,
    },
皮倩雯's avatar
皮倩雯 committed
107 108 109
    {
      title: '方案类型',
      dataIndex: 'type',
110
      align: 'center',
皮倩雯's avatar
皮倩雯 committed
111
      key: 'type',
112
      width: 200,
113
      render: (text, record) => <div>{text === null || !text ? '-' : text}</div>,
皮倩雯's avatar
皮倩雯 committed
114 115 116 117 118
    },
    {
      title: '推送方式',
      dataIndex: 'send_pattern',
      key: 'send_pattern',
119 120 121 122 123 124 125 126 127 128
      align: 'center',
      onCell: () => ({
        style: {
          maxWidth: 150,
          overflow: 'hidden',
          whiteSpace: 'nowrap',
          textOverflow: 'ellipsis',
          cursor: 'pointer',
        },
      }),
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
      render: (text, record) => {
        console.log(text);
        let arr = text;
        if (text) {
          let list = new Set(text.split(','));
          console.log(list);
          let data = Array.from(list); // 将类数组转化为真数组
          console.log(data);
          arr = data.toString();
        }
        return (
          <span>
            {arr === null || !arr ? (
              '-'
            ) : (
              <Tooltip placement="topLeft" title={arr}>
                {arr}
              </Tooltip>
            )}
          </span>
        );
      },
皮倩雯's avatar
皮倩雯 committed
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
    // {
    //   title: '推送组',
    //   dataIndex: 'receive_person',
    //   key: 'receive_person',
    //   align: 'center',
    //   ellipsis: true,
    //   onCell: () => ({
    //     style: {
    //       maxWidth: 150,
    //       overflow: 'hidden',
    //       whiteSpace: 'nowrap',
    //       textOverflow: 'ellipsis',
    //       cursor: 'pointer',
    //     },
    //   }),
    //   render: (text, record) => (
    //     <span>
    //       {text === null || !text ? (
    //         '-'
    //       ) : (
    //         <Tooltip placement="topLeft" title={text}>
    //           {text}
    //         </Tooltip>
    //       )}
    //     </span>
    //   ),
    // },
皮倩雯's avatar
皮倩雯 committed
179 180 181
    {
      title: '是否启用',
      dataIndex: 'is_use',
182
      align: 'center',
皮倩雯's avatar
皮倩雯 committed
183
      key: 'is_use',
184
      width: '100px',
185 186 187 188 189 190 191
      // render: (text, record) => <div>{text === '0' ? '否' : '是'}</div>,
      render: record => {
        if (record === '1') {
          return <Tag color="success"></Tag>;
        }
        return <Tag color="processing"></Tag>;
      },
皮倩雯's avatar
皮倩雯 committed
192 193 194 195
    },
    {
      title: '操作',
      width: 250,
196
      align: 'center',
皮倩雯's avatar
皮倩雯 committed
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215
      ellipsis: true,
      render: (text, record) => (
        <Space>
          <Tooltip title="测试">
            <FundViewOutlined
              style={{ fontSize: '16px', color: '#1890FF' }}
              onClick={() => {
                TestDesc(record);
              }}
            />
          </Tooltip>
          <Tooltip title="编辑">
            <EditTwoTone
              style={{ fontSize: '16px', color: '#e86060' }}
              onClick={() => {
                changeDesc(record);
              }}
            />
          </Tooltip>
216

217 218 219 220 221 222 223 224 225 226 227 228 229 230
          {record.name != '通用报警' && record.name != '工单提醒' && record.name != '系统通知' && (
            <div onClick={e => e.stopPropagation()}>
              <Popconfirm
                title="是否删除方案?"
                okText="确认"
                cancelText="取消"
                onConfirm={() => {
                  DeleteProject(record);
                }}
              >
                <DeleteOutlined style={{ fontSize: '16px', color: '#e86060' }} />
              </Popconfirm>
            </div>
          )}
皮倩雯's avatar
皮倩雯 committed
231 232 233 234
        </Space>
      ),
    },
  ];
235

皮倩雯's avatar
皮倩雯 committed
236 237 238 239
  // 模糊查询匹配的样式
  const searchStyle = val => {
    let n;
    if (showSearchStyle) {
240
      n = val.replace(new RegExp(value, 'g'), `<span style='color:red'>${value}</span>`);
皮倩雯's avatar
皮倩雯 committed
241 242 243 244 245
    } else {
      n = val;
    }
    return <div dangerouslySetInnerHTML={{ __html: n }} />;
  };
皮倩雯's avatar
皮倩雯 committed
246

皮倩雯's avatar
皮倩雯 committed
247 248
  const placeholder = '请输入方案名称';
  const handleSearch = value => {
249 250 251 252 253 254 255
    GetMessageList({
      pageSize: 10,
      pageIndex: 0,
      search: value,
      infoType: currentType == '全部' ? '' : currentType,
      msgType: currentName == '全部' ? '' : currentName,
    });
皮倩雯's avatar
皮倩雯 committed
256 257 258
    setShowSearchStyle(true);
  };
  const changeDesc = record => {
259
    console.log(record);
皮倩雯's avatar
皮倩雯 committed
260 261
    setCurrentTempalte(record);
    history.push({
262
      pathname: `/platform/schemeDetail`,
263
      state: { template: record, currentPage, nameList },
皮倩雯's avatar
皮倩雯 committed
264 265 266 267
    });
    // handleShowModal("editVisible", true)
  };
  const TestDesc = record => {
268 269
    setPushTestMsg(record);
    handleShowModal('pushTestVisible', true);
皮倩雯's avatar
皮倩雯 committed
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286
  };
  const DeleteProject = record => {
    let agen = record.item.AgentConfig;
    let config = record.item.MessageConfig;
    if (agen) {
      DeleteIISAgentConfig({
        agentName: config.MsgType,
      }).then(res => {
        if (res === 0) {
          DeleteMessageConfig({
            id: config.ID,
          }).then(res3 => {
            if (res3.code === 0) {
              message.success('删除方案成功');
              setFlag(flag + 1);
            }
          });
287
        } else {
皮倩雯's avatar
皮倩雯 committed
288
          message.error(res.msg);
289
        }
皮倩雯's avatar
皮倩雯 committed
290 291 292 293 294 295 296 297
      });
    } else {
      DeleteMessageConfig({
        id: config.ID,
      }).then(res3 => {
        if (res3.code === 0) {
          message.success('删除方案成功');
          setFlag(flag + 1);
298
        }
皮倩雯's avatar
皮倩雯 committed
299
      });
300
    }
皮倩雯's avatar
皮倩雯 committed
301 302 303 304
  };
  const handleReset = () => {
    setCurrentType('全部');
    setCurrentName('全部');
305
    setCurrentPage(1);
皮倩雯's avatar
皮倩雯 committed
306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321
    GetMessageList({ pageSize: 10, pageIndex: 0 });
    setShowSearchStyle(false);
    setValue('');
  };
  // 弹出模态框
  const handleShowModal = (key, value) => {
    setvisibleParams({ ...visibleParams, [key]: value });
  };
  const editModal = () => {
    handleShowModal('editVisbile', false);
    setFlag(flag + 1);
  };
  const bddModal = () => {
    handleShowModal('addVisbile', false);
    setFlag(flag + 1);
  };
322 323 324 325
  const pushTestModal = () => {
    handleShowModal('pushTestVisible', false);
    setFlag(flag + 1);
  };
皮倩雯's avatar
皮倩雯 committed
326 327 328 329
  const onAddClick = () => {
    setCurrentTempalte({});
    // handleShowModal("addVisible", true)
    history.push({
330
      pathname: `/platform/schemeDetail`,
331
      state: { template: {}, nameList },
皮倩雯's avatar
皮倩雯 committed
332 333 334 335
    });
  };
  const onTypeChange = value => {
    if (value == '全部') {
336
      setCurrentType('全部');
337 338 339 340 341 342
      GetMessageList({
        pageIndex,
        pageSize: 10,
        infoType: '',
        msgType: currentName == '全部' ? '' : currentName,
      });
皮倩雯's avatar
皮倩雯 committed
343 344 345 346 347 348 349 350
    } else {
      GetMessageList({
        pageIndex,
        pageSize: 10,
        infoType: value,
        msgType: currentName == '全部' ? '' : currentName,
      });
      setCurrentType(value);
351
    }
皮倩雯's avatar
皮倩雯 committed
352 353 354
  };
  const onNameChange = value => {
    if (value == '全部') {
355
      setCurrentName('全部');
356 357 358 359 360 361
      GetMessageList({
        pageIndex,
        pageSize: 10,
        msgType: '',
        infoType: currentType == '全部' ? '' : currentType,
      });
皮倩雯's avatar
皮倩雯 committed
362 363 364 365 366 367 368 369 370 371
    } else {
      GetMessageList({
        pageIndex,
        pageSize: 10,
        msgType: value,
        infoType: currentType == '全部' ? '' : currentType,
      });
      setCurrentName(value);
    }
  };
372

皮倩雯's avatar
皮倩雯 committed
373 374
  useEffect(() => {
    setTreeLoading(true);
375

皮倩雯's avatar
皮倩雯 committed
376 377 378 379 380 381
    GetMsgTypeList().then(res => {
      setTreeLoading(false);
      if (res.code === 0) {
        setMessageTypes(res.data);
      }
    });
382 383 384 385
    console.log(history.location);
    if (history.location.query) {
      setCurrentPage(history.location.query.currentPage);
    }
皮倩雯's avatar
皮倩雯 committed
386 387 388 389
  }, []);
  useEffect(() => {
    GetMessageList({ pageIndex, pageSize: 10 });
  }, [flag]);
shaoan123's avatar
shaoan123 committed
390

皮倩雯's avatar
皮倩雯 committed
391 392 393 394 395
  const GetMessageList = params => {
    setTreeLoading(true);
    GetMessageConfigList(params).then(res => {
      setTreeLoading(false);
      if (res.code === 0) {
396
        console.log(res.data);
397
        let mesList = [];
398
        let nameArr = [];
399 400
        if (res.code === 0) {
          res.data.MessageConfigModels.map(item => {
401
            nameArr.push(item.MessageConfig.MsgType);
402 403 404 405 406 407 408 409 410
            mesList.push({
              name: item.MessageConfig.MsgType,
              type: item.MessageConfig.ThemeName,
              send_pattern: item.MessageConfig.PushMode,
              receive_person: item.MessageConfig.PushGroup,
              is_use: item.MessageConfig.IsStarted,
              ...item.MessageConfig,
              item,
            });
皮倩雯's avatar
皮倩雯 committed
411
          });
412
          setNameList(nameArr);
413 414 415 416 417 418 419 420
          setDataList(mesList);
        }
      } else {
        notification.error({
          message: '提示',
          duration: 3,
          description: res.msg,
        });
皮倩雯's avatar
皮倩雯 committed
421 422 423
      }
    });
  };
皮倩雯's avatar
皮倩雯 committed
424

皮倩雯's avatar
皮倩雯 committed
425 426 427
  const handleChange = e => {
    setValue(e.target.value);
  };
428

皮倩雯's avatar
皮倩雯 committed
429
  const pagenation = {
430
    showTotal: (total, range) => `第${range[0]}-${range[1]} 条/共 ${total} 条`,
皮倩雯's avatar
皮倩雯 committed
431 432 433 434
    pageSizeOptions: [10, 20, 50, 100],
    defaultPageSize: 10,
    showQuickJumper: true,
    showSizeChanger: true,
435 436 437 438
    current: currentPage,
    onChange: page => {
      setCurrentPage(page);
    },
皮倩雯's avatar
皮倩雯 committed
439 440 441 442 443 444 445 446 447 448 449 450 451 452
  };
  return (
    <div className={styles.project_container}>
      <Spin tip="loading..." spinning={treeLoading}>
        <div className={styles.operate_bar}>
          <div className={styles.template_type}>
            <div className={styles.title}>方案类型</div>
            <Select
              placeholder="请选择方案类型!"
              value={currentType}
              style={{ width: '150px' }}
              onChange={onTypeChange}
            >
              <Option value="全部">全部</Option>
453 454
              <Option value="自定义">自定义</Option>
              <Option value="定时推送">定时推送</Option>
皮倩雯's avatar
皮倩雯 committed
455 456 457 458 459 460
              <Option value="监控报警">监控报警</Option>
              <Option value="工单办理">工单办理</Option>
              <Option value="平台公告">平台公告</Option>
            </Select>
          </div>
          <div className={styles.template_type}>
461
            {/* <div className={styles.title}>方案名称</div>
皮倩雯's avatar
皮倩雯 committed
462 463 464 465 466
            <Select
              placeholder="请选择方案名称!"
              value={currentName}
              style={{ width: '150px' }}
              onChange={onNameChange}
467
              showSearch
皮倩雯's avatar
皮倩雯 committed
468 469 470 471 472 473 474
            >
              <Option value="全部">全部</Option>
              {messageTypes.map((item, idx) => (
                <Option key={idx} value={item.MsgType}>
                  {item.MsgType}
                </Option>
              ))}
475
            </Select> */}
皮倩雯's avatar
皮倩雯 committed
476 477 478 479
          </div>
          <div className={styles.fast_search}>
            <div className={styles.title}>快速检索</div>
            <Search
480
              showSearch
皮倩雯's avatar
皮倩雯 committed
481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511
              allowClear
              placeholder={placeholder}
              onSearch={handleSearch}
              onChange={e => {
                handleChange(e);
              }}
              enterButton
              style={{ width: '300px' }}
              value={value}
            />
          </div>
          <Button type="primary" onClick={handleReset}>
            重置
          </Button>
          <Button
            type="primary"
            style={{ marginLeft: '10px' }}
            icon={<PlusCircleOutlined />}
            onClick={onAddClick}
          >
            <span style={{ marginTop: '-3px' }}>新增</span>
          </Button>
        </div>
        <div className={styles.list_view}>
          <Table
            bordered
            columns={columns}
            dataSource={dataList}
            pagination={pagenation}
            rowKey="ID"
          />
512
        </div>
皮倩雯's avatar
皮倩雯 committed
513 514 515 516 517 518 519 520 521 522 523 524
        <EditModal
          visible={visibleParams.editVisible}
          template={currentTemplate}
          onCancel={() => handleShowModal('editVisible', false)}
          confirmModal={editModal}
        />
        <EditModal
          visible={visibleParams.addVisible}
          template={{}}
          onCancel={() => handleShowModal('addVisible', false)}
          confirmModal={bddModal}
        />
525
        {/* 推送测试模块 */}
526 527 528 529 530 531
        <PushTest
          visible={visibleParams.pushTestVisible}
          onCancel={() => handleShowModal('pushTestVisible', false)}
          confirmModal={pushTestModal}
          pushTestMsg={pushTestMsg}
        />
皮倩雯's avatar
皮倩雯 committed
532 533 534 535 536
      </Spin>
    </div>
  );
};
export default ProjectManage;