| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479 |
- import { PageContainer } from '@ant-design/pro-layout';
- import { InstanceModel } from '@/pages/device/Instance';
- import { history, useParams } from 'umi';
- import { Badge, Card, Descriptions, Divider, message, Space, Tooltip } from 'antd';
- import type { ReactNode } from 'react';
- import { useEffect, useState } from 'react';
- import { observer } from '@formily/react';
- import Log from '@/pages/device/Instance/Detail/Log';
- // import Alarm from '@/pages/device/components/Alarm';
- import Info from '@/pages/device/Instance/Detail/Info';
- import Functions from '@/pages/device/Instance/Detail/Functions';
- import Running from '@/pages/device/Instance/Detail/Running';
- import ChildDevice from '@/pages/device/Instance/Detail/ChildDevice';
- import Diagnose from '@/pages/device/Instance/Detail/Diagnose';
- import MetadataMap from '@/pages/device/Instance/Detail/MetadataMap';
- import Opcua from '@/pages/device/Instance/Detail/Opcua';
- import Modbus from '@/pages/device/Instance/Detail/Modbus';
- import { useIntl } from '@@/plugin-locale/localeExports';
- import Metadata from '../../components/Metadata';
- import type { DeviceMetadata } from '@/pages/device/Product/typings';
- import MetadataAction from '@/pages/device/components/Metadata/DataBaseAction';
- import { Store } from 'jetlinks-store';
- import SystemConst from '@/utils/const';
- import { getMenuPathByCode, getMenuPathByParams, MENUS_CODE } from '@/utils/menu';
- import useSendWebsocketMessage from '@/hooks/websocket/useSendWebsocketMessage';
- import { Ellipsis, PermissionButton } from '@/components';
- import { QuestionCircleOutlined } from '@ant-design/icons';
- import Service from '@/pages/device/Instance/service';
- import useLocation from '@/hooks/route/useLocation';
- import { onlyMessage } from '@/utils/util';
- import Parsing from './Parsing';
- export const deviceStatus = new Map();
- deviceStatus.set('online', <Badge status="success" text={'在线'} />);
- deviceStatus.set('offline', <Badge status="error" text={'离线'} />);
- deviceStatus.set('notActive', <Badge status="processing" text={'禁用'} />);
- const InstanceDetail = observer(() => {
- const intl = useIntl();
- // const [tab, setTab] = useState<string>('detail');
- const params = useParams<{ id: string }>();
- const service = new Service('device-instance');
- const { permission } = PermissionButton.usePermission('device/Instance');
- const location = useLocation();
- // const resetMetadata = async () => {
- // const resp = await service.deleteMetadata(params.id);
- // if (resp.status === 200) {
- // message.success('操作成功');
- // Store.set(SystemConst.REFRESH_DEVICE, true);
- // setTimeout(() => {
- // Store.set(SystemConst.REFRESH_METADATA_TABLE, true);
- // }, 400);
- // }
- // };
- const baseList = [
- {
- key: 'detail',
- tab: intl.formatMessage({
- id: 'pages.device.instanceDetail.detail',
- defaultMessage: '实例信息',
- }),
- component: <Info />,
- },
- {
- key: 'running',
- tab: intl.formatMessage({
- id: 'pages.device.instanceDetail.running',
- defaultMessage: '运行状态',
- }),
- component: <Running />,
- },
- {
- key: 'metadata',
- tab: (
- <>
- {intl.formatMessage({
- id: 'pages.device.instanceDetail.metadata',
- defaultMessage: '物模型',
- })}
- <Tooltip
- title={
- <>
- 属性:
- <br />
- 用于描述设备运行时具体信息和状态。
- <br />
- 功能:
- <br />
- 指设备可供外部调用的指令或方法。
- <br />
- 事件:
- <br />
- 设备运行时,主动上报给云端的信息。
- <br />
- 标签:
- <br />
- 统一为设备添加拓展字段,添加后将在设备信息页显示。
- </>
- }
- >
- <QuestionCircleOutlined style={{ marginLeft: 5 }} />
- </Tooltip>
- </>
- ),
- component: (
- <Card>
- <Metadata
- type="device"
- // tabAction={
- // <PermissionButton
- // isPermission={permission.update}
- // popConfirm={{
- // title: '确认重置?',
- // onConfirm: resetMetadata,
- // }}
- // tooltip={{
- // title: '重置后将使用产品的物模型配置',
- // }}
- // key={'reload'}
- // >
- // 重置操作1
- // </PermissionButton>
- // }
- />
- </Card>
- ),
- },
- {
- // 物模型中有事件信息,且设备状态是在线的情况下才显示此模块
- key: 'functions',
- tab: intl.formatMessage({
- id: 'pages.device.instanceDetail.functions',
- defaultMessage: '设备功能',
- }),
- component: <Functions />,
- },
- {
- key: 'log',
- tab: intl.formatMessage({
- id: 'pages.device.instanceDetail.log',
- defaultMessage: '日志管理',
- }),
- component: <Log />,
- },
- {
- key: 'diagnose',
- tab: '设备诊断',
- component: <Diagnose />,
- },
- ];
- const pList = [
- 'websocket-server',
- 'http-server-gateway',
- 'udp-device-gateway',
- 'coap-server-gateway',
- 'mqtt-client-gateway',
- 'mqtt-server-gateway',
- 'tcp-server-gateway',
- ];
- const [list, setList] =
- useState<{ key: string; tab: string | ReactNode; component: ReactNode }[]>(baseList);
- const getDetail = async (id: string) => {
- const response = await service.detail(id);
- if (response.status === 200) {
- InstanceModel.detail = response?.result;
- const datalist = [...baseList];
- if (
- InstanceModel.detail?.accessProvider &&
- pList.includes(InstanceModel.detail?.accessProvider)
- ) {
- datalist.push({
- key: 'metadata-map',
- tab: '物模型映射',
- component: <MetadataMap type="device" />,
- });
- }
- const paring = response.result?.features?.find((item: any) => item.id === 'transparentCodec');
- if (paring) {
- datalist.push({
- key: 'parsing',
- tab: intl.formatMessage({
- id: 'pages.device.instanceDetail.parsing',
- defaultMessage: '数据解析',
- }),
- component: <Parsing tag="device" data={InstanceModel.detail} />,
- });
- }
- if (response.result.protocol === 'modbus-tcp') {
- datalist.push({
- key: 'modbus',
- tab: 'Modbus',
- component: <Modbus />,
- });
- }
- if (response.result.protocol === 'opc-ua') {
- datalist.push({
- key: 'opcua',
- tab: 'OPC UA',
- component: <Opcua />,
- });
- }
- if (response.result.deviceType?.value === 'gateway') {
- // 产品类型为网关的情况下才显示此模块
- datalist.push({
- key: 'child-device',
- tab: '子设备',
- component: <ChildDevice />,
- });
- }
- setList(datalist);
- // 写入物模型数据
- const metadata: DeviceMetadata = JSON.parse(response.result?.metadata || '{}');
- MetadataAction.insert(metadata);
- }
- };
- const [subscribeTopic] = useSendWebsocketMessage();
- useEffect(() => {
- if (subscribeTopic) {
- subscribeTopic(
- `instance-editor-info-status-${params.id}`,
- `/dashboard/device/status/change/realTime`,
- {
- deviceId: params.id,
- },
- // @ts-ignore
- ).subscribe((data: any) => {
- const payload = data.payload;
- const state = payload.value.type;
- InstanceModel.detail.state = {
- value: state,
- text: '',
- };
- });
- }
- }, []);
- useEffect(() => {
- Store.subscribe(SystemConst.REFRESH_DEVICE, () => {
- MetadataAction.clean();
- setTimeout(() => {
- getDetail(params.id);
- }, 200);
- });
- // return subscription.unsubscribe();
- }, []);
- useEffect(() => {
- // console.log(InstanceModel.current)
- if (!InstanceModel.current && !params.id) {
- history.goBack();
- } else {
- // setTab('detail');
- InstanceModel.active = 'detail';
- getDetail(params?.id || InstanceModel.current?.id || '');
- }
- return () => {
- MetadataAction.clean();
- };
- }, [params.id]);
- useEffect(() => {
- if ((location as any).query?.key) {
- // setTab((location as any).query?.key || 'detail');
- InstanceModel.active = (location as any).query?.key || 'detail';
- }
- const subscription = Store.subscribe(SystemConst.BASE_UPDATE_DATA, (data) => {
- if ((window as any).onTabSaveSuccess) {
- (window as any).onTabSaveSuccess(data);
- setTimeout(() => window.close(), 300);
- }
- });
- return () => subscription.unsubscribe();
- }, []);
- useEffect(() => {
- const { state } = location;
- if (state && state?.tab) {
- // setTab(state?.tab);
- InstanceModel.active = state?.tab;
- }
- }, [location]);
- return (
- <PageContainer
- className={'page-title-show'}
- onBack={history.goBack}
- onTabChange={(e) => {
- InstanceModel.active = e;
- }}
- tabList={list}
- tabActiveKey={InstanceModel.active}
- content={
- <Descriptions size="small" column={4}>
- <Descriptions.Item label={'ID'}>
- <Ellipsis
- title={InstanceModel.detail?.id}
- tooltip={{ placement: 'topLeft' }}
- style={{ maxWidth: 250 }}
- limitWidth={250}
- />
- {/*<Tooltip placement="topLeft" title={InstanceModel.detail?.id}>*/}
- {/* <div className="ellipsis" style={{ maxWidth: 250 }}>*/}
- {/* {InstanceModel.detail?.id}*/}
- {/* </div>*/}
- {/*</Tooltip>*/}
- </Descriptions.Item>
- <Descriptions.Item label={'所属产品'}>
- <PermissionButton
- type={'link'}
- size={'small'}
- tooltip={{
- title: InstanceModel.detail?.productName,
- placement: 'topLeft',
- }}
- isPermission={!!getMenuPathByCode(MENUS_CODE['device/Product'])}
- onClick={() => {
- const url = getMenuPathByParams(
- MENUS_CODE['device/Product/Detail'],
- InstanceModel.detail?.productId,
- );
- if (url) {
- history.replace(url);
- }
- }}
- >
- <Ellipsis
- title={InstanceModel.detail?.productName}
- tooltip={{ placement: 'topLeft' }}
- style={{ maxWidth: 250 }}
- limitWidth={250}
- />
- {/*<div className="ellipsis" style={{ width: 250 }}>*/}
- {/* {InstanceModel.detail?.productName}*/}
- {/*</div>*/}
- </PermissionButton>
- </Descriptions.Item>
- </Descriptions>
- }
- title={
- <div style={{ display: 'flex', alignItems: 'center' }}>
- {/*<Tooltip placement="topLeft" title={InstanceModel.detail?.name}>*/}
- {/* <div className="ellipsis" style={{ maxWidth: 250 }}>*/}
- {/* {InstanceModel.detail?.name}*/}
- {/* </div>*/}
- {/*</Tooltip>*/}
- <Ellipsis
- title={InstanceModel.detail?.name}
- tooltip={{ placement: 'topLeft' }}
- style={{ maxWidth: 250 }}
- limitWidth={250}
- />
- <Divider type="vertical" />
- <Space>
- {deviceStatus.get(InstanceModel.detail?.state?.value)}
- {InstanceModel.detail?.state?.value === 'notActive' && (
- <PermissionButton
- type={'link'}
- key={'state'}
- popConfirm={{
- title: '确认启用设备',
- onConfirm: async () => {
- const resp = await service.deployDevice(params.id);
- if (resp.status === 200) {
- onlyMessage(
- intl.formatMessage({
- id: 'pages.data.option.success',
- defaultMessage: '操作成功!',
- }),
- );
- getDetail(params.id);
- }
- },
- }}
- isPermission={permission.action}
- tooltip={{
- title: '启用设备',
- }}
- >
- 启用设备
- </PermissionButton>
- )}
- {InstanceModel.detail?.state?.value === 'online' && (
- <PermissionButton
- type={'link'}
- key={'state'}
- popConfirm={{
- title: '确认断开连接',
- onConfirm: async () => {
- const resp = await service.disconnectDevice(params.id);
- if (resp.status === 200) {
- onlyMessage(
- intl.formatMessage({
- id: 'pages.data.option.success',
- defaultMessage: '操作成功!',
- }),
- );
- getDetail(params.id);
- }
- },
- }}
- isPermission={permission.action}
- tooltip={{
- title: '断开连接',
- }}
- >
- 断开连接
- </PermissionButton>
- )}
- {InstanceModel.detail?.accessProvider === 'child-device' &&
- InstanceModel.detail?.state?.value === 'offline' ? (
- <div>
- <Tooltip
- placement="bottom"
- title={
- InstanceModel.detail?.features?.find((item) => item.id === 'selfManageState')
- ? '该设备的在线状态与父设备(网关设备)保持一致'
- : '该设备在线状态由设备自身运行状态决定,不继承父设备(网关设备)的在线状态'
- }
- >
- <QuestionCircleOutlined style={{ fontSize: 14, marginRight: 5 }} />
- </Tooltip>
- </div>
- ) : (
- ''
- )}
- </Space>
- </div>
- }
- extra={[
- // <Button key="2">
- // {intl.formatMessage({
- // id: 'pages.device.productDetail.disable',
- // defaultMessage: '停用',
- // })}
- // </Button>,
- // <Button key="1" type="primary">
- // {intl.formatMessage({
- // id: 'pages.device.productDetail.setting',
- // defaultMessage: '应用配置',
- // })}
- // </Button>,
- <img
- style={{ marginRight: 20, cursor: 'pointer' }}
- src={require('/public/images/device/button.png')}
- onClick={() => {
- getDetail(params.id);
- service.getConfigMetadata(params.id).then((config) => {
- if (config.status === 200) {
- InstanceModel.config = config?.result || [];
- message.success('操作成功!');
- }
- });
- }}
- />,
- // <SyncOutlined
- // onClick={() => {
- // getDetail(params.id);
- // service.getConfigMetadata(params.id).then((config) => {
- // if (config.status === 200) {
- // InstanceModel.config = config?.result || [];
- // message.success('操作成功!');
- // }
- // });
- // }}
- // style={{ fontSize: 20, marginRight: 20 }}
- // key="1"
- // />,
- ]}
- >
- {list.find((k) => k.key === InstanceModel.active)?.component}
- </PageContainer>
- );
- });
- export default InstanceDetail;
|