AuxiliaryView.jsx 7.2 KB
Newer Older
邓超's avatar
邓超 committed
1
import React, { useEffect, useState } from 'react';
邓超's avatar
邓超 committed
2
import { reloadFlowNodeExtendPages, removeFlowNodeExtendPage } from '@/services/flow/flow';
邓超's avatar
邓超 committed
3 4 5 6 7 8 9 10 11 12 13
import {
  Table,
  Modal,
  Space,
  Tooltip,
  Popconfirm,
  Button,
  notification,
  message,
  Spin,
} from 'antd';
14
import { EditTwoTone, PlusOutlined, DeleteOutlined, EyeOutlined } from '@ant-design/icons';
邓超's avatar
邓超 committed
15 16 17 18
import AddModal from './auxiliaryComponents/AddModal';
import styles from '../flowNode.less';

const AuxiliaryView = props => {
19
  const { handleCancel, visible, msg, allDisabled } = props;
邓超's avatar
邓超 committed
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 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
  const [tableData, setTableData] = useState([]); // 辅助视图对应的回显的表格
  const [viewModal, setViewModal] = useState(false); // 辅助视图新政编辑模态框
  const [modalType, setModalType] = useState(''); // 模态框是编辑还是修改的状态
  const [editMsg, setEditMsg] = useState({}); // 保存编辑的信息
  const [title, setTitle] = useState('');
  const [flowNodeId, setFlowNodeId] = useState('');
  const [loading, setLoading] = useState(false);
  useEffect(() => {
    if (visible) {
      console.log(msg);
      setFlowNodeId(msg.ID);
      setTitle(`${msg.flowName}/${msg.name}`);
      getData();
    }
  }, [visible]);
  // 数据初始化
  const getData = () => {
    setLoading(true);
    reloadFlowNodeExtendPages({ flowNodeId: msg.ID }).then(res => {
      setLoading(false);
      if (res.code === 0) {
        setTableData(res.data);
      }
    });
  };
  // 编辑辅助视图
  const toEdit = val => {
    setViewModal(true);
    setModalType('edit');
    setEditMsg(val);
  };
  // 删除辅助视图
  const delRow = record => {
    removeFlowNodeExtendPage({ flowNodeExtendId: record.ID })
      .then(res => {
        if (res.code === 0) {
          getData();
          notification.success({
            message: '提示',
            duration: 3,
            description: '删除成功',
          });
        } else {
          notification.error({
            message: '提示',
            duration: 3,
            description: res.msg,
          });
        }
      })
      .catch(() => {
        notification.error({
          message: '提示',
          duration: 3,
          description: '网络异常',
        });
      });
  };

  // 定义表格
  const columns = [
    {
      title: '前端便签',
      dataIndex: 'WebLabel',
      align: 'center',
皮倩雯's avatar
皮倩雯 committed
85 86 87 88 89 90
      render: text => {
        if (text === '(未配置)' || text === '(无)') {
          return <span style={{ color: 'grey' }}>{text}</span>;
        }
        return <span>{text}</span>;
      },
邓超's avatar
邓超 committed
91 92 93 94 95
    },
    {
      title: '前端视图',
      dataIndex: 'WebPage',
      align: 'center',
96 97 98
      ellipsis: {
        showTitle: true,
      },
皮倩雯's avatar
皮倩雯 committed
99 100 101 102
      render: text => {
        if (text === '(未配置)' || text === '(无)') {
          return <span style={{ color: 'grey' }}>{text}</span>;
        }
103 104 105 106 107
        return (
          <Tooltip placement="topLeft" title={text}>
            <span>{text}</span>
          </Tooltip>
        );
皮倩雯's avatar
皮倩雯 committed
108
      },
邓超's avatar
邓超 committed
109 110 111 112 113
    },
    {
      title: '前端参数',
      dataIndex: 'WebParam',
      align: 'center',
114 115 116
      ellipsis: {
        showTitle: true,
      },
皮倩雯's avatar
皮倩雯 committed
117 118 119 120
      render: text => {
        if (text === '(未配置)' || text === '(无)') {
          return <span style={{ color: 'grey' }}>{text}</span>;
        }
121 122 123 124 125
        return (
          <Tooltip placement="topLeft" title={text}>
            <span>{text}</span>
          </Tooltip>
        );
皮倩雯's avatar
皮倩雯 committed
126
      },
邓超's avatar
邓超 committed
127 128 129 130 131
    },
    {
      title: '手持标签',
      dataIndex: 'MobileLabel',
      align: 'center',
皮倩雯's avatar
皮倩雯 committed
132 133 134 135 136 137
      render: text => {
        if (text === '(未配置)' || text === '(无)') {
          return <span style={{ color: 'grey' }}>{text}</span>;
        }
        return <span>{text}</span>;
      },
邓超's avatar
邓超 committed
138 139 140 141 142
    },
    {
      title: '手持视图',
      dataIndex: 'MobilePage',
      align: 'center',
皮倩雯's avatar
皮倩雯 committed
143 144 145 146 147 148
      render: text => {
        if (text === '(未配置)' || text === '(无)') {
          return <span style={{ color: 'grey' }}>{text}</span>;
        }
        return <span>{text}</span>;
      },
邓超's avatar
邓超 committed
149 150 151 152 153
    },
    {
      title: '手持参数',
      dataIndex: 'MobileParam',
      align: 'center',
皮倩雯's avatar
皮倩雯 committed
154 155 156 157 158 159
      render: text => {
        if (text === '(未配置)' || text === '(无)') {
          return <span style={{ color: 'grey' }}>{text}</span>;
        }
        return <span>{text}</span>;
      },
邓超's avatar
邓超 committed
160 161 162 163 164 165 166 167
    },
    {
      title: '操作',
      align: 'center',
      ellipsis: true,
      render: record => (
        <>
          <Space>
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
            {allDisabled ? (
              <Tooltip title="查看节点辅助视图">
                <EyeOutlined
                  onClick={() => toEdit(record)}
                  style={{ fontSize: '16px', color: '#1890FF' }}
                />
              </Tooltip>
            ) : (
              <Tooltip title="修改节点辅助视图">
                <EditTwoTone
                  onClick={() => toEdit(record)}
                  style={{ fontSize: '16px', color: '#1890FF' }}
                />
              </Tooltip>
            )}
            {allDisabled ? null : (
              <Tooltip title="删除节点辅助视图">
                <Popconfirm
                  title="是否清除该辅助视图?"
                  onConfirm={() => delRow(record)}
                  onCancel={() => message.error('取消清除')}
                  okText="是"
                  cancelText="否"
                >
                  <DeleteOutlined style={{ fontSize: '16px', color: '#e86060' }} />
                </Popconfirm>
              </Tooltip>
            )}
邓超's avatar
邓超 committed
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
          </Space>
        </>
      ),
    },
  ];
  return (
    <Modal
      title={`${title} 的辅助视图`}
      visible={visible}
      width="1200px"
      onCancel={handleCancel}
      maskClosable={false}
      centered
      footer={null}
    >
211 212
      <div className={styles.auxiliaryViewBox}>
        <div className={styles.buttonList}>
213 214 215 216 217 218 219 220 221 222 223 224
          {allDisabled ? null : (
            <Button
              type="primary"
              onClick={() => {
                setViewModal(true);
                setModalType('add');
              }}
              icon={<PlusOutlined />}
            >
              新增辅助视图
            </Button>
          )}
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247
        </div>
        <Spin spinning={loading} tip="loading...">
          <Table
            dataSource={tableData}
            columns={columns}
            rowKey={record => record.ID}
            bordered
            size="small"
            scroll={{ y: '400px' }}
            onRow={record => ({
              onDoubleClick: () => {
                toEdit(record);
              },
            })}
            pagination={{
              showTotal: (total, range) => `第${range[0]}-${range[1]} 条/共 ${total} 条`,
              pageSizeOptions: [10, 20, 50, 100],
              defaultPageSize: 10,
              showQuickJumper: true,
              showSizeChanger: true,
            }}
          />
        </Spin>
邓超's avatar
邓超 committed
248 249 250 251 252 253 254 255 256 257 258 259
      </div>
      <AddModal
        visible={viewModal}
        msg={editMsg}
        title={title}
        flowNodeId={flowNodeId}
        modalType={modalType}
        handleCancel={() => setViewModal(false)}
        onSubumit={() => {
          setViewModal(false);
          getData();
        }}
260
        allDisabled={allDisabled}
邓超's avatar
邓超 committed
261 262 263 264 265
      />
    </Modal>
  );
};
export default AuxiliaryView;