|
|
@@ -1,124 +1,127 @@
|
|
|
-import { Card, Divider, Empty } from 'antd';
|
|
|
+import { Descriptions, Card, Button } from 'antd';
|
|
|
import { InstanceModel, service } from '@/pages/device/Instance';
|
|
|
-import { useEffect, useState } from 'react';
|
|
|
-import { createSchemaField } from '@formily/react';
|
|
|
-import type { ConfigMetadata, ConfigProperty } from '@/pages/device/Product/typings';
|
|
|
-import type { ISchema } from '@formily/json-schema';
|
|
|
-import { Form, FormGrid, FormItem, FormLayout, Input, Password, PreviewText } from '@formily/antd';
|
|
|
-import { createForm } from '@formily/core';
|
|
|
-import { history, useParams } from 'umi';
|
|
|
-import Tags from '@/pages/device/Instance/Detail/Config/Tags';
|
|
|
+import moment from 'moment';
|
|
|
+import { observer } from '@formily/react';
|
|
|
+import { useIntl } from '@@/plugin-locale/localeExports';
|
|
|
+import { EditOutlined } from '@ant-design/icons';
|
|
|
+import { useState } from 'react';
|
|
|
+import { useParams } from 'umi';
|
|
|
+import Save from '@/pages/device/Instance/Save';
|
|
|
|
|
|
-const componentMap = {
|
|
|
- string: 'Input',
|
|
|
- password: 'Password',
|
|
|
-};
|
|
|
+const Info = observer(() => {
|
|
|
+ const intl = useIntl();
|
|
|
+ const [visible, setVisible] = useState(false);
|
|
|
+ const param = useParams<{ id: string }>();
|
|
|
|
|
|
-const Config = () => {
|
|
|
- const params = useParams<{ id: string }>();
|
|
|
- useEffect(() => {
|
|
|
- const id = InstanceModel.current?.id || params.id;
|
|
|
- if (id) {
|
|
|
- service.getConfigMetadata(id).then((response) => {
|
|
|
- InstanceModel.config = response?.result;
|
|
|
- });
|
|
|
- } else {
|
|
|
- history.goBack();
|
|
|
+ const getDetailInfo = async () => {
|
|
|
+ const res = await service.detail(param.id);
|
|
|
+ if (res.status === 200) {
|
|
|
+ InstanceModel.detail = res.result;
|
|
|
}
|
|
|
- }, []);
|
|
|
-
|
|
|
- const [metadata, setMetadata] = useState<ConfigMetadata[]>([]);
|
|
|
- const [state, setState] = useState<boolean>(false);
|
|
|
-
|
|
|
- const form = createForm({
|
|
|
- validateFirst: true,
|
|
|
- readPretty: state,
|
|
|
- initialValues: InstanceModel.detail?.configuration,
|
|
|
- });
|
|
|
-
|
|
|
- const id = InstanceModel.current?.id;
|
|
|
-
|
|
|
- useEffect(() => {
|
|
|
- if (id) {
|
|
|
- service.getConfigMetadata(id).then((config) => {
|
|
|
- setMetadata(config?.result);
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- return () => {};
|
|
|
- }, [id]);
|
|
|
-
|
|
|
- const SchemaField = createSchemaField({
|
|
|
- components: {
|
|
|
- FormItem,
|
|
|
- Input,
|
|
|
- Password,
|
|
|
- FormGrid,
|
|
|
- PreviewText,
|
|
|
- },
|
|
|
- });
|
|
|
-
|
|
|
- const configToSchema = (data: ConfigProperty[]) => {
|
|
|
- const config = {};
|
|
|
- data.forEach((item) => {
|
|
|
- config[item.property] = {
|
|
|
- type: 'string',
|
|
|
- title: item.name,
|
|
|
- 'x-decorator': 'FormItem',
|
|
|
- 'x-component': componentMap[item.type.type],
|
|
|
- 'x-decorator-props': {
|
|
|
- tooltip: item.description,
|
|
|
- },
|
|
|
- };
|
|
|
- });
|
|
|
- return config;
|
|
|
- };
|
|
|
-
|
|
|
- const renderConfigCard = () => {
|
|
|
- return metadata ? (
|
|
|
- metadata?.map((item) => {
|
|
|
- const itemSchema: ISchema = {
|
|
|
- type: 'object',
|
|
|
- properties: {
|
|
|
- grid: {
|
|
|
- type: 'void',
|
|
|
- 'x-component': 'FormGrid',
|
|
|
- 'x-component-props': {
|
|
|
- minColumns: [2],
|
|
|
- maxColumns: [2],
|
|
|
- },
|
|
|
- properties: configToSchema(item.properties),
|
|
|
- },
|
|
|
- },
|
|
|
- };
|
|
|
-
|
|
|
- return (
|
|
|
- <Card
|
|
|
- title={item.name}
|
|
|
- extra={<a onClick={() => setState(!state)}>{state ? '编辑' : '保存'}</a>}
|
|
|
- >
|
|
|
- <PreviewText.Placeholder value="-">
|
|
|
- <Form form={form}>
|
|
|
- <FormLayout labelCol={6} wrapperCol={16}>
|
|
|
- <SchemaField schema={itemSchema} />
|
|
|
- </FormLayout>
|
|
|
- </Form>
|
|
|
- </PreviewText.Placeholder>
|
|
|
- </Card>
|
|
|
- );
|
|
|
- })
|
|
|
- ) : (
|
|
|
- <Empty />
|
|
|
- );
|
|
|
};
|
|
|
|
|
|
return (
|
|
|
- <>
|
|
|
- {renderConfigCard()}
|
|
|
- <Divider />
|
|
|
- <Tags />
|
|
|
- </>
|
|
|
+ <Card>
|
|
|
+ <Descriptions
|
|
|
+ size="small"
|
|
|
+ column={3}
|
|
|
+ bordered
|
|
|
+ title={[
|
|
|
+ <span key={1}>
|
|
|
+ {intl.formatMessage({
|
|
|
+ id: 'pages.device.instanceDetail.info',
|
|
|
+ defaultMessage: '设备信息',
|
|
|
+ })}
|
|
|
+ </span>,
|
|
|
+ <Button
|
|
|
+ key={2}
|
|
|
+ type={'link'}
|
|
|
+ onClick={() => {
|
|
|
+ setVisible(true);
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ <EditOutlined />
|
|
|
+ </Button>,
|
|
|
+ ]}
|
|
|
+ >
|
|
|
+ <Descriptions.Item
|
|
|
+ label={intl.formatMessage({
|
|
|
+ id: 'pages.device.instanceDetail.deviceType',
|
|
|
+ defaultMessage: '设备类型',
|
|
|
+ })}
|
|
|
+ >
|
|
|
+ {InstanceModel.detail?.deviceType?.text}
|
|
|
+ </Descriptions.Item>
|
|
|
+ <Descriptions.Item
|
|
|
+ label={intl.formatMessage({
|
|
|
+ id: 'pages.device.instanceDetail.transportProtocol',
|
|
|
+ defaultMessage: '链接协议',
|
|
|
+ })}
|
|
|
+ >
|
|
|
+ {InstanceModel.detail?.protocolName}
|
|
|
+ </Descriptions.Item>
|
|
|
+ <Descriptions.Item
|
|
|
+ label={intl.formatMessage({
|
|
|
+ id: 'pages.device.instanceDetail.protocolName',
|
|
|
+ defaultMessage: '消息协议',
|
|
|
+ })}
|
|
|
+ >
|
|
|
+ {InstanceModel.detail?.transport}
|
|
|
+ </Descriptions.Item>
|
|
|
+ <Descriptions.Item
|
|
|
+ label={intl.formatMessage({
|
|
|
+ id: 'pages.device.instanceDetail.IPAddress',
|
|
|
+ defaultMessage: 'IP地址',
|
|
|
+ })}
|
|
|
+ >
|
|
|
+ {InstanceModel.detail?.address}
|
|
|
+ </Descriptions.Item>
|
|
|
+ <Descriptions.Item
|
|
|
+ label={intl.formatMessage({
|
|
|
+ id: 'pages.device.instanceDetail.createTime',
|
|
|
+ defaultMessage: '创建时间',
|
|
|
+ })}
|
|
|
+ >
|
|
|
+ {moment(InstanceModel.detail?.createTime).format('YYYY-MM-DD HH:mm:ss')}
|
|
|
+ </Descriptions.Item>
|
|
|
+ <Descriptions.Item
|
|
|
+ label={intl.formatMessage({
|
|
|
+ id: 'pages.device.instanceDetail.registerTime',
|
|
|
+ defaultMessage: '注册时间',
|
|
|
+ })}
|
|
|
+ >
|
|
|
+ {InstanceModel.detail?.createTime}
|
|
|
+ </Descriptions.Item>
|
|
|
+ <Descriptions.Item
|
|
|
+ label={intl.formatMessage({
|
|
|
+ id: 'pages.device.instanceDetail.lastTimeOnline',
|
|
|
+ defaultMessage: '最后上线时间',
|
|
|
+ })}
|
|
|
+ >
|
|
|
+ {InstanceModel.detail?.createTime}
|
|
|
+ </Descriptions.Item>
|
|
|
+ <Descriptions.Item label={''}>{}</Descriptions.Item>
|
|
|
+ <Descriptions.Item label={''}>{}</Descriptions.Item>
|
|
|
+ <Descriptions.Item
|
|
|
+ label={intl.formatMessage({
|
|
|
+ id: 'pages.table.description',
|
|
|
+ defaultMessage: '说明',
|
|
|
+ })}
|
|
|
+ span={3}
|
|
|
+ >
|
|
|
+ {InstanceModel.detail?.description}
|
|
|
+ </Descriptions.Item>
|
|
|
+ </Descriptions>
|
|
|
+ <Save
|
|
|
+ data={InstanceModel.detail}
|
|
|
+ model={'edit'}
|
|
|
+ close={() => {
|
|
|
+ setVisible(false);
|
|
|
+ }}
|
|
|
+ reload={getDetailInfo}
|
|
|
+ visible={visible}
|
|
|
+ />
|
|
|
+ </Card>
|
|
|
);
|
|
|
-};
|
|
|
-
|
|
|
-export default Config;
|
|
|
+});
|
|
|
+export default Info;
|