| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406 |
- import { Badge, Button, Card, Divider, Dropdown, Input, Menu } from 'antd';
- import { useDomFullHeight } from '@/hooks';
- import './index.less';
- import SearchComponent from '@/components/SearchComponent';
- import ProTable, { ActionType, ProColumns } from '@jetlinks/pro-table';
- import PermissionButton from '@/components/PermissionButton';
- import {
- DeleteOutlined,
- EditOutlined,
- ExportOutlined,
- ImportOutlined,
- PlayCircleOutlined,
- PlusOutlined,
- StopOutlined,
- } from '@ant-design/icons';
- import { useRef, useState } from 'react';
- import { useIntl } from 'umi';
- import ChannelCard from '../channelCard';
- import { PageContainer } from '@ant-design/pro-layout';
- import Service from './service';
- import SaveChannel from './saveChannel';
- import SavePoint from './savePoint';
- export const service = new Service('');
- const NewModbus = () => {
- const { minHeight } = useDomFullHeight(`.modbus`);
- const intl = useIntl();
- const actionRef = useRef<ActionType>();
- const { permission } = PermissionButton.usePermission('link/Channel/Modbus');
- const [param, setParam] = useState({});
- const [activeKey, setActiveKey] = useState<any>('');
- const [visible, setVisible] = useState<boolean>(false);
- const [visiblePoint, setVisiblePoint] = useState<boolean>(false);
- const [current, setCurrent] = useState<any>({});
- const [pointDetail, setPointDetail] = useState<any>({});
- const data = [
- {
- id: 1,
- status: 'connect',
- state: {
- text: '正常',
- value: 'enabled',
- },
- },
- {
- id: 2,
- status: 'disconnect',
- state: {
- text: '禁用',
- value: 'disabled',
- },
- },
- ];
- const columns: ProColumns<any>[] = [
- {
- title: '名称',
- dataIndex: 'name',
- ellipsis: true,
- width: 200,
- fixed: 'left',
- },
- {
- title: '功能码',
- dataIndex: 'host',
- },
- {
- title: '从站ID',
- dataIndex: 'port',
- search: false,
- valueType: 'digit',
- },
- {
- title: '寄存器数量',
- dataIndex: 'port',
- search: false,
- valueType: 'digit',
- },
- {
- title: '地址',
- dataIndex: 'port',
- search: false,
- valueType: 'digit',
- },
- {
- title: '当前数据',
- dataIndex: 'port',
- search: false,
- valueType: 'digit',
- },
- {
- title: '采集状态',
- dataIndex: 'port',
- search: false,
- valueType: 'digit',
- },
- {
- title: '状态',
- dataIndex: 'state',
- renderText: (state) => (
- <Badge text={state?.text} status={state?.value === 'disabled' ? 'error' : 'success'} />
- ),
- valueType: 'select',
- valueEnum: {
- disabled: {
- text: intl.formatMessage({
- id: 'pages.data.option.disabled',
- defaultMessage: '禁用',
- }),
- status: 'disabled',
- },
- enabled: {
- text: '正常',
- status: 'enabled',
- },
- },
- filterMultiple: false,
- },
- {
- title: '操作',
- valueType: 'option',
- align: 'center',
- width: 120,
- fixed: 'right',
- render: (text, record) => [
- <PermissionButton
- isPermission={permission.update}
- key="edit"
- onClick={() => {
- // setVisible(true);
- // setCurrent(record);
- }}
- type={'link'}
- style={{ padding: 0 }}
- tooltip={{
- title: intl.formatMessage({
- id: 'pages.data.option.edit',
- defaultMessage: '编辑',
- }),
- }}
- >
- <EditOutlined />
- </PermissionButton>,
- <PermissionButton
- type="link"
- key={'action'}
- style={{ padding: 0 }}
- popConfirm={{
- title: intl.formatMessage({
- id: `pages.data.option.${
- record.state.value !== 'disabled' ? 'disabled' : 'enabled'
- }.tips`,
- defaultMessage: '确认禁用?',
- }),
- onConfirm: async () => {
- // if (record.state.value === 'disabled') {
- // await service.edit({
- // ...record,
- // state: 'enabled',
- // });
- // } else {
- // await service.edit({
- // ...record,
- // state: 'disabled',
- // });
- // }
- // onlyMessage(
- // intl.formatMessage({
- // id: 'pages.data.option.success',
- // defaultMessage: '操作成功!',
- // }),
- // );
- // actionRef.current?.reload();
- },
- }}
- isPermission={permission.action}
- tooltip={{
- title: intl.formatMessage({
- id: `pages.data.option.${record.state.value !== 'disabled' ? 'disabled' : 'enabled'}`,
- defaultMessage: record.state.value !== 'disabled' ? '禁用' : '启用',
- }),
- }}
- >
- {record.state.value !== 'disabled' ? <StopOutlined /> : <PlayCircleOutlined />}
- </PermissionButton>,
- <PermissionButton
- isPermission={permission.delete}
- style={{ padding: 0 }}
- disabled={record.state.value === 'enabled'}
- popConfirm={{
- title: '确认删除',
- disabled: record.state.value === 'enabled',
- onConfirm: async () => {
- // const resp: any = await service.remove(record.id);
- // if (resp.status === 200) {
- // onlyMessage(
- // intl.formatMessage({
- // id: 'pages.data.option.success',
- // defaultMessage: '操作成功!',
- // }),
- // );
- // actionRef.current?.reload();
- // }
- },
- }}
- key="delete"
- type="link"
- >
- <DeleteOutlined />
- </PermissionButton>,
- ],
- },
- ];
- const menu = (
- <Menu>
- <Menu.Item key="1">
- <PermissionButton
- isPermission={permission.export}
- icon={<ExportOutlined />}
- type="default"
- onClick={() => {
- // setExportVisible(true);
- }}
- >
- 批量导出设备
- </PermissionButton>
- </Menu.Item>
- <Menu.Item key="2">
- <PermissionButton
- isPermission={permission.import}
- icon={<ImportOutlined />}
- onClick={() => {
- // setImportVisible(true);
- }}
- >
- 批量导入设备
- </PermissionButton>
- </Menu.Item>
- </Menu>
- );
- return (
- <PageContainer>
- <Card className="modbus" style={{ minHeight }}>
- <div className="item">
- <div className="item-left">
- <div style={{ width: 220 }}>
- <Input.Search
- placeholder="请输入名称"
- allowClear
- onSearch={(value) => {
- console.log(value);
- }}
- />
- <PermissionButton
- onClick={() => {
- setVisible(true);
- setCurrent({});
- }}
- isPermission={permission.add}
- key="add"
- icon={<PlusOutlined />}
- type="default"
- style={{ width: '100%', marginTop: 16 }}
- >
- 新增
- </PermissionButton>
- <div className="item-left-list">
- {data.map((item) => (
- <ChannelCard
- active={activeKey === item.id}
- data={item}
- onClick={() => {
- setActiveKey(item.id);
- }}
- actions={
- <>
- <PermissionButton
- isPermission={permission.update}
- key="edit"
- onClick={() => {
- // setVisible(true);
- // setCurrent(record);
- }}
- type={'link'}
- style={{ padding: 0 }}
- >
- <EditOutlined />
- 编辑
- </PermissionButton>
- <Divider type="vertical" />
- <PermissionButton
- isPermission={permission.update}
- key="enbale"
- type={'link'}
- style={{ padding: 0 }}
- popConfirm={{
- title: intl.formatMessage({
- id: `pages.data.option.${
- item.state.value !== 'disabled' ? 'disabled' : 'enabled'
- }.tips`,
- defaultMessage: '确认禁用?',
- }),
- onConfirm: async () => {},
- }}
- >
- {item.state.value === 'enabled' ? (
- <StopOutlined />
- ) : (
- <PlayCircleOutlined />
- )}
- {item.state.value === 'enabled' ? '禁用' : '启用'}
- </PermissionButton>
- <Divider type="vertical" />
- <PermissionButton
- isPermission={permission.delete}
- style={{ padding: 0 }}
- disabled={item.state.value === 'enabled'}
- popConfirm={{
- title: '确认删除',
- disabled: item.state.value === 'enabled',
- onConfirm: async () => {},
- }}
- key="delete"
- type="link"
- >
- <DeleteOutlined />
- </PermissionButton>
- </>
- }
- />
- ))}
- </div>
- </div>
- </div>
- <div className="item-right">
- <SearchComponent<any>
- field={columns}
- target="modbus"
- onSearch={(value) => {
- actionRef.current?.reset?.();
- setParam(value);
- }}
- />
- <ProTable
- actionRef={actionRef}
- params={param}
- columns={columns}
- rowKey="id"
- columnEmptyText={''}
- // scroll={{ x: 1000 }}
- search={false}
- headerTitle={
- <>
- <PermissionButton
- onClick={() => {
- setPointDetail({});
- setVisiblePoint(true);
- }}
- isPermission={permission.add}
- key="add"
- icon={<PlusOutlined />}
- type="primary"
- style={{ marginRight: 10 }}
- >
- {intl.formatMessage({
- id: 'pages.data.option.add',
- defaultMessage: '新增',
- })}
- </PermissionButton>
- <Dropdown key={'more'} overlay={menu} placement="bottom">
- <Button>批量操作</Button>
- </Dropdown>
- </>
- }
- // request={async (params) =>
- // service.query({ ...params, sorts: [{ name: 'createTime', order: 'desc' }] })
- // }
- />
- </div>
- </div>
- </Card>
- {visible && (
- <SaveChannel
- data={current}
- close={() => {
- setVisible(false);
- actionRef.current?.reload();
- }}
- />
- )}
- {visiblePoint && (
- <SavePoint
- data={pointDetail}
- close={() => {
- setVisiblePoint(false);
- actionRef.current?.reload();
- }}
- />
- )}
- </PageContainer>
- );
- };
- export default NewModbus;
|