|
@@ -1,11 +1,12 @@
|
|
|
-import { EditOutlined, SyncOutlined } from '@ant-design/icons';
|
|
|
|
|
-import { Divider, message, Spin } from 'antd';
|
|
|
|
|
|
|
+import { EditOutlined, SyncOutlined, UnorderedListOutlined } from '@ant-design/icons';
|
|
|
|
|
+import { Button, Divider, Input, message, Popover, Spin, Tooltip } from 'antd';
|
|
|
import ProCard from '@ant-design/pro-card';
|
|
import ProCard from '@ant-design/pro-card';
|
|
|
import type { ObserverMetadata, PropertyMetadata } from '@/pages/device/Product/typings';
|
|
import type { ObserverMetadata, PropertyMetadata } from '@/pages/device/Product/typings';
|
|
|
import { Line } from '@ant-design/charts';
|
|
import { Line } from '@ant-design/charts';
|
|
|
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
|
import { service } from '@/pages/device/Instance';
|
|
import { service } from '@/pages/device/Instance';
|
|
|
import { useParams } from 'umi';
|
|
import { useParams } from 'umi';
|
|
|
|
|
+import PropertyList from '@/pages/device/Instance/Detail/PropertyList';
|
|
|
|
|
|
|
|
interface Props {
|
|
interface Props {
|
|
|
data: Partial<PropertyMetadata> & ObserverMetadata;
|
|
data: Partial<PropertyMetadata> & ObserverMetadata;
|
|
@@ -86,20 +87,65 @@ const Property = (props: Props) => {
|
|
|
message.success('操作成功');
|
|
message.success('操作成功');
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
|
|
|
+
|
|
|
|
|
+ const [propertyValue, setPropertyValue] = useState<string>();
|
|
|
|
|
+ const [visible, setVisible] = useState<boolean>(false);
|
|
|
|
|
+ const handleSetPropertyValue = async () => {
|
|
|
|
|
+ const resp = await service.setProperty(params.id, { [`${data.id}`]: propertyValue });
|
|
|
|
|
+ if (resp.status === 200) {
|
|
|
|
|
+ message.success('操作成功');
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ const renderSetProperty = () => {
|
|
|
|
|
+ if (data.expands?.readOnly === false || data.expands?.readOnly === 'false') {
|
|
|
|
|
+ return (
|
|
|
|
|
+ <Popover
|
|
|
|
|
+ trigger="click"
|
|
|
|
|
+ title={
|
|
|
|
|
+ <div
|
|
|
|
|
+ style={{
|
|
|
|
|
+ display: 'flex',
|
|
|
|
|
+ justifyContent: 'space-between',
|
|
|
|
|
+ }}
|
|
|
|
|
+ >
|
|
|
|
|
+ <span>设置属性</span>
|
|
|
|
|
+ <Button size="small" type="primary" onClick={handleSetPropertyValue}>
|
|
|
|
|
+ 设置
|
|
|
|
|
+ </Button>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ }
|
|
|
|
|
+ content={
|
|
|
|
|
+ <Input value={propertyValue} onChange={(e) => setPropertyValue(e.target.value)} />
|
|
|
|
|
+ }
|
|
|
|
|
+ >
|
|
|
|
|
+ <Tooltip placement="top" title="设置属性至设备">
|
|
|
|
|
+ <EditOutlined />
|
|
|
|
|
+ </Tooltip>
|
|
|
|
|
+ <Divider type="vertical" />
|
|
|
|
|
+ </Popover>
|
|
|
|
|
+ );
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
return (
|
|
return (
|
|
|
<ProCard
|
|
<ProCard
|
|
|
title={`${data?.name} ${title}`}
|
|
title={`${data?.name} ${title}`}
|
|
|
extra={
|
|
extra={
|
|
|
<>
|
|
<>
|
|
|
- <EditOutlined
|
|
|
|
|
- onClick={async () => {
|
|
|
|
|
- message.success('设置属性');
|
|
|
|
|
- }}
|
|
|
|
|
- />
|
|
|
|
|
- <Divider type="vertical" />
|
|
|
|
|
- <SyncOutlined onClick={refreshProperty} />
|
|
|
|
|
|
|
+ {renderSetProperty()}
|
|
|
|
|
+ <Tooltip placement="top" title="获取最新属性值">
|
|
|
|
|
+ <SyncOutlined onClick={refreshProperty} />
|
|
|
|
|
+ </Tooltip>
|
|
|
<Divider type="vertical" />
|
|
<Divider type="vertical" />
|
|
|
- <EditOutlined onClick={refreshProperty} />
|
|
|
|
|
|
|
+ <Tooltip placement="top" title="详情">
|
|
|
|
|
+ <UnorderedListOutlined
|
|
|
|
|
+ onClick={() => {
|
|
|
|
|
+ setVisible(true);
|
|
|
|
|
+ }}
|
|
|
|
|
+ />
|
|
|
|
|
+ </Tooltip>
|
|
|
</>
|
|
</>
|
|
|
}
|
|
}
|
|
|
layout="center"
|
|
layout="center"
|
|
@@ -107,9 +153,15 @@ const Property = (props: Props) => {
|
|
|
headerBordered
|
|
headerBordered
|
|
|
colSpan={{ xs: 12, sm: 8, md: 6, lg: 6, xl: 6 }}
|
|
colSpan={{ xs: 12, sm: 8, md: 6, lg: 6, xl: 6 }}
|
|
|
>
|
|
>
|
|
|
- <Spin spinning={loading} style={{ height: 60 }}>
|
|
|
|
|
- {chart()}
|
|
|
|
|
|
|
+ <Spin spinning={loading}>
|
|
|
|
|
+ <div style={{ height: 60 }}>{chart()}</div>
|
|
|
</Spin>
|
|
</Spin>
|
|
|
|
|
+ <PropertyList
|
|
|
|
|
+ data={data}
|
|
|
|
|
+ property={data.id!}
|
|
|
|
|
+ visible={visible}
|
|
|
|
|
+ close={() => setVisible(false)}
|
|
|
|
|
+ />
|
|
|
</ProCard>
|
|
</ProCard>
|
|
|
);
|
|
);
|
|
|
};
|
|
};
|