|
@@ -4,6 +4,7 @@ import { useEffect, useState } from 'react';
|
|
|
import ReadProperty from '../../device/readProperty';
|
|
import ReadProperty from '../../device/readProperty';
|
|
|
import TopCard from '../device/TopCard';
|
|
import TopCard from '../device/TopCard';
|
|
|
import DeviceModel from '../model';
|
|
import DeviceModel from '../model';
|
|
|
|
|
+import FunctionCall from './functionCall';
|
|
|
import WriteProperty from './WriteProperty';
|
|
import WriteProperty from './WriteProperty';
|
|
|
|
|
|
|
|
interface Props {
|
|
interface Props {
|
|
@@ -15,6 +16,9 @@ export default observer((props: Props) => {
|
|
|
const [deviceMessageType, setDeviceMessageType] = useState('WRITE_PROPERTY');
|
|
const [deviceMessageType, setDeviceMessageType] = useState('WRITE_PROPERTY');
|
|
|
const [properties, setProperties] = useState([]); // 物模型-属性
|
|
const [properties, setProperties] = useState([]); // 物模型-属性
|
|
|
const [propertiesId, setPropertiesId] = useState<string | undefined>(''); // 物模型-属性ID,用于串行
|
|
const [propertiesId, setPropertiesId] = useState<string | undefined>(''); // 物模型-属性ID,用于串行
|
|
|
|
|
+ const [functionList, setFunctionList] = useState<any>([]); // 物模型-功能
|
|
|
|
|
+ const [functionId, setFunctionId] = useState('');
|
|
|
|
|
+ const [functions, setFunctions] = useState([]);
|
|
|
|
|
|
|
|
const TypeList = [
|
|
const TypeList = [
|
|
|
{
|
|
{
|
|
@@ -41,18 +45,42 @@ export default observer((props: Props) => {
|
|
|
if (DeviceModel.productDetail) {
|
|
if (DeviceModel.productDetail) {
|
|
|
const metadata = JSON.parse(DeviceModel.productDetail?.metadata || '{}');
|
|
const metadata = JSON.parse(DeviceModel.productDetail?.metadata || '{}');
|
|
|
setProperties(metadata.properties);
|
|
setProperties(metadata.properties);
|
|
|
|
|
+ setFunctions(metadata.functions);
|
|
|
}
|
|
}
|
|
|
- }, [DeviceModel.productDetail]);
|
|
|
|
|
|
|
+ }, [DeviceModel.productDetail, functionId]);
|
|
|
|
|
+
|
|
|
|
|
+ useEffect(() => {
|
|
|
|
|
+ if (functionId && functions.length !== 0) {
|
|
|
|
|
+ const functionItem: any = functions.find((item: any) => item.id === functionId);
|
|
|
|
|
+ if (functionItem) {
|
|
|
|
|
+ const item = functionItem.valueType
|
|
|
|
|
+ ? functionItem.valueType.properties
|
|
|
|
|
+ : functionItem.inputs;
|
|
|
|
|
+ const array = [];
|
|
|
|
|
+ for (const datum of item) {
|
|
|
|
|
+ array.push({
|
|
|
|
|
+ id: datum.id,
|
|
|
|
|
+ name: datum.name,
|
|
|
|
|
+ type: datum.valueType ? datum.valueType.type : '-',
|
|
|
|
|
+ format: datum.valueType ? datum.valueType.format : undefined,
|
|
|
|
|
+ options: datum.valueType ? datum.valueType.elements : undefined,
|
|
|
|
|
+ value: undefined,
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ setFunctionList(array);
|
|
|
|
|
+ console.log(propertiesId, 'array');
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }, [functions, functionId]);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
|
props.get(form);
|
|
props.get(form);
|
|
|
- console.log(propertiesId);
|
|
|
|
|
}, [form]);
|
|
}, [form]);
|
|
|
|
|
|
|
|
return (
|
|
return (
|
|
|
<div>
|
|
<div>
|
|
|
<Form form={form} layout={'vertical'}>
|
|
<Form form={form} layout={'vertical'}>
|
|
|
- <Form.Item name="messageType" label="动作类型" required>
|
|
|
|
|
|
|
+ <Form.Item name="messageType" label="动作类型" required initialValue="WRITE_PROPERTY">
|
|
|
<TopCard
|
|
<TopCard
|
|
|
typeList={TypeList}
|
|
typeList={TypeList}
|
|
|
onChange={(value: string) => {
|
|
onChange={(value: string) => {
|
|
@@ -61,9 +89,36 @@ export default observer((props: Props) => {
|
|
|
/>
|
|
/>
|
|
|
</Form.Item>
|
|
</Form.Item>
|
|
|
{deviceMessageType === 'INVOKE_FUNCTION' && (
|
|
{deviceMessageType === 'INVOKE_FUNCTION' && (
|
|
|
- <Form.Item name={['device', 'message', 'inputs']} label="功能调用" required>
|
|
|
|
|
- <Select></Select>
|
|
|
|
|
- </Form.Item>
|
|
|
|
|
|
|
+ <>
|
|
|
|
|
+ <Form.Item
|
|
|
|
|
+ name={['device', 'message', 'functionId']}
|
|
|
|
|
+ label="功能调用"
|
|
|
|
|
+ rules={[{ required: true, message: '请选择功能' }]}
|
|
|
|
|
+ >
|
|
|
|
|
+ <Select
|
|
|
|
|
+ showSearch
|
|
|
|
|
+ allowClear
|
|
|
|
|
+ options={functions}
|
|
|
|
|
+ fieldNames={{ label: 'name', value: 'id' }}
|
|
|
|
|
+ style={{ width: '100%' }}
|
|
|
|
|
+ placeholder={'请选择功能'}
|
|
|
|
|
+ filterOption={(input: string, option: any) =>
|
|
|
|
|
+ option.name.toLowerCase().indexOf(input.toLowerCase()) >= 0
|
|
|
|
|
+ }
|
|
|
|
|
+ onChange={(value) => {
|
|
|
|
|
+ setFunctionId(value);
|
|
|
|
|
+ }}
|
|
|
|
|
+ />
|
|
|
|
|
+ </Form.Item>
|
|
|
|
|
+ {functionId && (
|
|
|
|
|
+ <Form.Item
|
|
|
|
|
+ name={['device', 'message', 'inputs']}
|
|
|
|
|
+ rules={[{ required: true, message: '请输入功能值' }]}
|
|
|
|
|
+ >
|
|
|
|
|
+ <FunctionCall functionData={functionList} productId={DeviceModel.productId[0]} />
|
|
|
|
|
+ </Form.Item>
|
|
|
|
|
+ )}
|
|
|
|
|
+ </>
|
|
|
)}
|
|
)}
|
|
|
{deviceMessageType === 'READ_PROPERTY' && (
|
|
{deviceMessageType === 'READ_PROPERTY' && (
|
|
|
<Form.Item
|
|
<Form.Item
|