flow.jsx 10.7 KB
Newer Older
邓超's avatar
邓超 committed
1 2
import React, { useEffect, useState } from 'react';
import { useHistory } from 'react-router-dom';
邓超's avatar
邓超 committed
3
import { reloadFlows, removeFlowExtend } from '@/services/flow/flow';
4
import { Card, Space, Table, Popconfirm, Spin, Tooltip, notification, message, Button } from 'antd';
邓超's avatar
邓超 committed
5 6 7 8 9 10 11
import {
  DoubleLeftOutlined,
  DoubleRightOutlined,
  EditTwoTone,
  ApartmentOutlined,
  DeleteOutlined,
  OrderedListOutlined,
邓超's avatar
邓超 committed
12
  ControlOutlined,
邓超's avatar
邓超 committed
13 14 15 16 17
} from '@ant-design/icons';
import classnames from 'classnames';
import PageContainer from '@/components/BasePageContainer';
import ProcessConfig from './flowComponents/ProcessConfig';
import Order from './flowComponents/Order';
邓超's avatar
邓超 committed
18
import Timelimit from './flowComponents/Timelimit';
邓超's avatar
邓超 committed
19 20 21 22 23 24 25 26 27 28 29
import styles from './flow.less';

const Flow = () => {
  const history = useHistory();
  const [tableData, setTableData] = useState([]); // 流程对应的回显的表格
  const [processData, setProcessData] = useState([]); // 流程列表总
  const [dataSource, setDataSource] = useState(''); // 是否是返回获取数据
  const [processMsg, setProcessMsg] = useState({}); // 流程配置回显信息
  const [treeLoading, setTreeLoading] = useState(false);
  const [treeVisible, setTreeVisible] = useState(true);
  const [pickItemIndex, setPickItemIndex] = useState(0); // 选中流程索引
30
  const [hoverItemIndex, setHoverItemIndex] = useState(0); // hover流程索引
邓超's avatar
邓超 committed
31 32 33
  const [visible, setVisible] = useState({
    processConfig: false,
    order: false,
邓超's avatar
邓超 committed
34
    auxiliaryView: false,
邓超's avatar
邓超 committed
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 60 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
  }); // 弹窗显示
  // 初始化
  useEffect(() => {
    // 初始化流程列表
    getProcessData();
    if (history.location.state && history.location.state.pickItemIndex) {
      setDataSource('back');
    }
  }, []);
  // 表格数据改变后处理
  useEffect(() => {
    // 判断是否是返回回来的页面
    if (processData.length === 0) {
      return;
    }
    if (dataSource === 'back') {
      setPickItemIndex(history.location.state.pickItemIndex);
      setTableData(processData[history.location.state.pickItemIndex].root);
    } else {
      setTableData(processData[pickItemIndex].root);
    }
  }, [processData]);
  // 弹窗显示控制
  const showModal = (key, value) => {
    setVisible({ ...visible, [key]: value });
  };
  // 初始化流程列表
  const getProcessData = () => {
    setTreeLoading(true);
    reloadFlows()
      .then(res => {
        setTreeLoading(false);
        if (res.code === 0) {
          setProcessData(res.data);
        } else {
          notification.error({
            message: '提示',
            duration: 3,
            description: res.msg,
          });
        }
      })
      .catch(() => {
        setTreeLoading(false);
        notification.error({
          message: '提示',
          duration: 3,
          description: '网络异常',
        });
      });
  };
  // 删除流程
  const delProcess = val => {
    removeFlowExtend({ flowIDs: val.extendID })
      .then(res => {
        if (res.code === 0) {
          setDataSource('current');
          getProcessData();
          notification.success({
            message: '提示',
            duration: 3,
邓超's avatar
邓超 committed
96
            description: '清除成功',
邓超's avatar
邓超 committed
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
          });
        } else {
          notification.error({
            message: '提示',
            duration: 3,
            description: res.msg,
          });
        }
      })
      .catch(() => {
        notification.error({
          message: '提示',
          duration: 3,
          description: '网络异常',
        });
      });
  };
  // 跳转到对应的流程节点
  const toNode = flowName => {
116
    console.log(flowName);
邓超's avatar
邓超 committed
117
    history.push({
118
      pathname: '/biz/workflow/caseNode',
邓超's avatar
邓超 committed
119 120 121 122 123 124 125 126 127 128 129
      state: { flowName, pickItemIndex },
    });
  };
  // 定义表格
  const columns = [
    { title: '名称', dataIndex: 'name', width: 150, align: 'center' },
    {
      title: '前端样式',
      dataIndex: 'extendWebPage',
      align: 'center',
      render: text => (
130
        <span style={{ color: text === '(默认)' ? 'grey' : '000000D9' }}>{text}</span>
邓超's avatar
邓超 committed
131 132 133 134 135 136 137
      ),
    },
    {
      title: '手持样式',
      dataIndex: 'extendMobilePage',
      align: 'center',
      render: text => (
138
        <span style={{ color: text === '(默认)' ? 'grey' : '000000D9' }}>{text}</span>
邓超's avatar
邓超 committed
139 140 141
      ),
    },
    {
邓超's avatar
邓超 committed
142
      title: '辅助视图',
邓超's avatar
邓超 committed
143 144
      dataIndex: 'extendPageCount',
      align: 'center',
邓超's avatar
邓超 committed
145
      width: 80,
146
      render: text => <span style={{ color: text === '(无)' ? 'grey' : '000000D9' }}>{text}</span>,
邓超's avatar
邓超 committed
147 148 149 150 151 152
    },
    {
      title: '流程结束后',
      dataIndex: 'flowEndBehavior',
      align: 'center',
      render: text => (
153
        <span style={{ color: text === '(不做处理)' ? 'grey' : '000000D9' }}>{text}</span>
邓超's avatar
邓超 committed
154 155 156 157 158 159 160 161 162 163 164 165
      ),
    },
    {
      title: '12位编码',
      dataIndex: 'useFixedCodingRule',
      width: 80,
      align: 'center',
    },
    {
      title: '异常节点',
      dataIndex: 'errorNodes',
      align: 'center',
166
      render: text => <span style={{ color: text === '(无)' ? 'grey' : 'red' }}>{text}</span>,
邓超's avatar
邓超 committed
167 168 169 170 171
    },
    {
      title: '接口配置',
      dataIndex: 'interfaceConfig',
      align: 'center',
172
      render: text => <span style={{ color: text === '(无)' ? 'grey' : '000000D9' }}>{text}</span>,
邓超's avatar
邓超 committed
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
    },
    {
      title: '操作',
      align: 'center',
      ellipsis: true,
      render: record => (
        <>
          <Space>
            <Tooltip title="流程配置">
              <EditTwoTone
                onClick={() => {
                  showModal('processConfig', true);
                  setProcessMsg(record);
                }}
                style={{ fontSize: '16px', color: '#1890FF' }}
              />
            </Tooltip>
邓超's avatar
邓超 committed
190 191 192 193 194 195 196 197 198
            <Tooltip title="时限配置">
              <ControlOutlined
                onClick={() => {
                  showModal('auxiliaryView', true);
                  setProcessMsg(record);
                }}
                style={{ fontSize: '16px', color: '#1890FF' }}
              />
            </Tooltip>
邓超's avatar
邓超 committed
199 200 201 202 203 204 205 206 207 208 209 210 211 212
            <Tooltip title="节点配置">
              <ApartmentOutlined
                onClick={() => toNode(record.name)}
                style={{ fontSize: '16px', color: '#1890FF' }}
              />
            </Tooltip>
            <Tooltip title="清除流程配置">
              <Popconfirm
                title="是否清除该流程配置?"
                onConfirm={() => delProcess(record)}
                onCancel={() => message.error('取消清除')}
                okText="是"
                cancelText="否"
              >
213
                <DeleteOutlined style={{ fontSize: '16px', color: '#e86060' }} />
邓超's avatar
邓超 committed
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231
              </Popconfirm>
            </Tooltip>
          </Space>
        </>
      ),
    },
  ];
  return (
    <PageContainer>
      <div className={styles.flowContainer}>
        {/* 左侧事件树 */}
        <Spin spinning={treeLoading} tip="loading...">
          <Card
            className={classnames({
              [styles.orgContainer]: true,
              [styles.orgContainerHide]: !treeVisible,
            })}
          >
232
            <div style={{ height: '100%', display: `${treeVisible ? 'block' : 'none'}` }}>
233 234 235
              <span className={styles.processTitle}>流程列表</span>
              <hr className={styles.splitLine} />
              {/* 流程列表 */}
236
              <div style={{ overflowY: 'scroll', height: 'calc(100% - 30px)' }}>
237 238 239 240 241 242
                {processData.length > 0 &&
                  processData.map((item, index) => (
                    <div
                      className={classnames({
                        [styles.listItem]: true,
                        [styles.pickItem]: index === pickItemIndex,
243
                        [styles.listHover]: index !== pickItemIndex && index === hoverItemIndex,
244
                      })}
245 246 247 248 249 250
                      onMouseEnter={() => {
                        setHoverItemIndex(index);
                      }}
                      onMouseLeave={() => {
                        setHoverItemIndex('');
                      }}
251 252 253 254 255 256 257 258 259 260
                      onClick={() => {
                        setPickItemIndex(index);
                        setTableData(item.root);
                      }}
                      key={item.goupName}
                    >
                      {item.goupName}{item.count ? item.count : ''}
                    </div>
                  ))}
              </div>
261
            </div>
邓超's avatar
邓超 committed
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276
            <div className={styles.switcher}>
              {treeVisible && (
                <Tooltip title="隐藏流程列表">
                  <DoubleLeftOutlined onClick={() => setTreeVisible(false)} />
                </Tooltip>
              )}
              {!treeVisible && (
                <Tooltip title="显示流程列表">
                  <DoubleRightOutlined onClick={() => setTreeVisible(true)} />
                </Tooltip>
              )}
            </div>
          </Card>
        </Spin>
        {/* 右侧流程表 */}
277

邓超's avatar
邓超 committed
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295
        <div className={styles.processContainer}>
          <div className={styles.buttonList}>
            <Button
              onClick={() => {
                showModal('order', true);
              }}
            >
              <OrderedListOutlined />
              排序
            </Button>
          </div>

          <Table
            dataSource={tableData}
            columns={columns}
            rowKey={record => record.ID}
            bordered
            size="small"
296
            scroll={{ x: 'max-content', y: 'calc(100% - 40px)' }}
邓超's avatar
邓超 committed
297 298 299 300 301 302
            onRow={record => ({
              onDoubleClick: () => {
                toNode(record.name);
              },
            })}
            pagination={{
303
              showTotal: (total, range) => `第${range[0]}-${range[1]} 条/共 ${total} 条`,
邓超's avatar
邓超 committed
304
              pageSizeOptions: [10, 20, 50, 100],
305
              defaultPageSize: 20,
邓超's avatar
邓超 committed
306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326
              showQuickJumper: true,
              showSizeChanger: true,
            }}
          />
        </div>
      </div>
      {/* 流程配置弹窗 */}
      <ProcessConfig
        visible={visible.processConfig}
        processMsg={processMsg}
        handleCancel={() => showModal('processConfig', false)}
        onSubumit={() => {
          showModal('processConfig', false);
          setDataSource('current');
          getProcessData();
        }}
      />
      {/* 排序弹窗 */}
      <Order
        visible={visible.order}
        tableData={tableData}
皮倩雯's avatar
皮倩雯 committed
327
        processData={processData}
邓超's avatar
邓超 committed
328 329 330 331 332 333 334
        handleCancel={() => showModal('order', false)}
        submitCallBack={() => {
          showModal('order', false);
          setDataSource('current');
          getProcessData();
        }}
      />
邓超's avatar
邓超 committed
335 336 337 338 339 340
      {/* 流程时限配置 */}
      <Timelimit
        visible={visible.auxiliaryView}
        msg={processMsg}
        handleCancel={() => showModal('auxiliaryView', false)}
      />
邓超's avatar
邓超 committed
341 342 343 344 345
    </PageContainer>
  );
};

export default Flow;