|
@@ -1,7 +1,7 @@
|
|
|
import { PageContainer } from '@ant-design/pro-layout';
|
|
import { PageContainer } from '@ant-design/pro-layout';
|
|
|
import { createSchemaField } from '@formily/react';
|
|
import { createSchemaField } from '@formily/react';
|
|
|
import { ISchema } from '@formily/json-schema';
|
|
import { ISchema } from '@formily/json-schema';
|
|
|
-import { Card, Col, Row } from 'antd';
|
|
|
|
|
|
|
+import { Card, Col, message, Row } from 'antd';
|
|
|
import {
|
|
import {
|
|
|
ArrayCollapse,
|
|
ArrayCollapse,
|
|
|
ArrayTable,
|
|
ArrayTable,
|
|
@@ -15,10 +15,12 @@ import {
|
|
|
} from '@formily/antd';
|
|
} from '@formily/antd';
|
|
|
import { PermissionButton } from '@/components';
|
|
import { PermissionButton } from '@/components';
|
|
|
import { useMemo } from 'react';
|
|
import { useMemo } from 'react';
|
|
|
-import { createForm, Field, onFieldReact, onFieldValueChange } from '@formily/core';
|
|
|
|
|
|
|
+import { createForm, Field, onFieldReact, onFieldValueChange, onFormInit } from '@formily/core';
|
|
|
import { useAsyncDataSource } from '@/utils/util';
|
|
import { useAsyncDataSource } from '@/utils/util';
|
|
|
import { service } from '..';
|
|
import { service } from '..';
|
|
|
import { Store } from 'jetlinks-store';
|
|
import { Store } from 'jetlinks-store';
|
|
|
|
|
+import { useParams } from 'umi';
|
|
|
|
|
+import Doc from '@/pages/Northbound/DuerOS/Detail/Doc';
|
|
|
|
|
|
|
|
const Save = () => {
|
|
const Save = () => {
|
|
|
const SchemaField = createSchemaField({
|
|
const SchemaField = createSchemaField({
|
|
@@ -33,6 +35,8 @@ const Save = () => {
|
|
|
},
|
|
},
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
|
|
+ const { id } = useParams<{ id: string }>();
|
|
|
|
|
+
|
|
|
const getProduct = () =>
|
|
const getProduct = () =>
|
|
|
service.getProduct().then((resp) => {
|
|
service.getProduct().then((resp) => {
|
|
|
Store.set('product-list', resp.result);
|
|
Store.set('product-list', resp.result);
|
|
@@ -71,7 +75,7 @@ const Save = () => {
|
|
|
columnGap: 24,
|
|
columnGap: 24,
|
|
|
},
|
|
},
|
|
|
properties: {
|
|
properties: {
|
|
|
- product: {
|
|
|
|
|
|
|
+ id: {
|
|
|
title: '产品',
|
|
title: '产品',
|
|
|
'x-decorator-props': {
|
|
'x-decorator-props': {
|
|
|
gridSpan: 1,
|
|
gridSpan: 1,
|
|
@@ -93,7 +97,7 @@ const Save = () => {
|
|
|
'x-reactions': '{{useAsyncDataSource(getProduct)}}',
|
|
'x-reactions': '{{useAsyncDataSource(getProduct)}}',
|
|
|
required: true,
|
|
required: true,
|
|
|
},
|
|
},
|
|
|
- deviceType: {
|
|
|
|
|
|
|
+ applianceType: {
|
|
|
title: '设备类型',
|
|
title: '设备类型',
|
|
|
'x-decorator-props': {
|
|
'x-decorator-props': {
|
|
|
gridSpan: 1,
|
|
gridSpan: 1,
|
|
@@ -275,7 +279,7 @@ const Save = () => {
|
|
|
},
|
|
},
|
|
|
},
|
|
},
|
|
|
},
|
|
},
|
|
|
- function: {
|
|
|
|
|
|
|
+ inputs: {
|
|
|
title: '参数列表',
|
|
title: '参数列表',
|
|
|
type: 'array',
|
|
type: 'array',
|
|
|
'x-component': 'ArrayTable',
|
|
'x-component': 'ArrayTable',
|
|
@@ -408,6 +412,7 @@ const Save = () => {
|
|
|
label: 'name',
|
|
label: 'name',
|
|
|
value: 'id',
|
|
value: 'id',
|
|
|
},
|
|
},
|
|
|
|
|
+ mode: 'tags',
|
|
|
},
|
|
},
|
|
|
},
|
|
},
|
|
|
},
|
|
},
|
|
@@ -429,35 +434,39 @@ const Save = () => {
|
|
|
},
|
|
},
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- const handleSave = () => {};
|
|
|
|
|
-
|
|
|
|
|
- const findProductMetadata = (id: string) => {
|
|
|
|
|
- if (!id) return;
|
|
|
|
|
|
|
+ const findProductMetadata = (_id: string) => {
|
|
|
|
|
+ if (!_id) return;
|
|
|
const _productList = Store.get('product-list');
|
|
const _productList = Store.get('product-list');
|
|
|
- const _product = _productList.find((item: any) => item.id === id);
|
|
|
|
|
- return _product.metadata && JSON.parse(_product.metadata || '{}');
|
|
|
|
|
|
|
+ const _product = _productList?.find((item: any) => item.id === _id);
|
|
|
|
|
+ return _product?.metadata && JSON.parse(_product.metadata || '{}');
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- const findDeviceType = (id: string) => {
|
|
|
|
|
- if (!id) return;
|
|
|
|
|
|
|
+ const findapplianceType = (_id: string) => {
|
|
|
|
|
+ if (!_id) return;
|
|
|
const _productTypes = Store.get('product-types');
|
|
const _productTypes = Store.get('product-types');
|
|
|
- return _productTypes.find((item: any) => item.id === id);
|
|
|
|
|
|
|
+ return _productTypes?.find((item: any) => item.id === _id);
|
|
|
};
|
|
};
|
|
|
const form = useMemo(
|
|
const form = useMemo(
|
|
|
() =>
|
|
() =>
|
|
|
createForm({
|
|
createForm({
|
|
|
validateFirst: true,
|
|
validateFirst: true,
|
|
|
effects() {
|
|
effects() {
|
|
|
|
|
+ onFormInit(async (form1) => {
|
|
|
|
|
+ await getTypes();
|
|
|
|
|
+ await getProduct();
|
|
|
|
|
+ const resp = await service.detail(id);
|
|
|
|
|
+ form1.setInitialValues(resp.result);
|
|
|
|
|
+ });
|
|
|
onFieldReact('actionMappings.*.layout.action', (field) => {
|
|
onFieldReact('actionMappings.*.layout.action', (field) => {
|
|
|
- const productType = field.query('deviceType').value();
|
|
|
|
|
- (field as Field).setDataSource(findDeviceType(productType)?.actions);
|
|
|
|
|
|
|
+ const productType = field.query('applianceType').value();
|
|
|
|
|
+ (field as Field).setDataSource(findapplianceType(productType)?.actions);
|
|
|
});
|
|
});
|
|
|
onFieldReact('actionMappings.*.layout.command.message.properties', (field) => {
|
|
onFieldReact('actionMappings.*.layout.command.message.properties', (field) => {
|
|
|
- const product = field.query('product').value();
|
|
|
|
|
|
|
+ const product = field.query('id').value();
|
|
|
(field as Field).setDataSource(findProductMetadata(product)?.properties);
|
|
(field as Field).setDataSource(findProductMetadata(product)?.properties);
|
|
|
});
|
|
});
|
|
|
onFieldReact('actionMappings.*.layout.command.message.functionId', (field) => {
|
|
onFieldReact('actionMappings.*.layout.command.message.functionId', (field) => {
|
|
|
- const product = field.query('product').value();
|
|
|
|
|
|
|
+ const product = field.query('id').value();
|
|
|
(field as Field).setDataSource(findProductMetadata(product)?.functions);
|
|
(field as Field).setDataSource(findProductMetadata(product)?.functions);
|
|
|
});
|
|
});
|
|
|
onFieldValueChange(
|
|
onFieldValueChange(
|
|
@@ -465,7 +474,7 @@ const Save = () => {
|
|
|
(field, form1) => {
|
|
(field, form1) => {
|
|
|
const functionId = field.value;
|
|
const functionId = field.value;
|
|
|
if (!functionId) return;
|
|
if (!functionId) return;
|
|
|
- const product = field.query('product').value();
|
|
|
|
|
|
|
+ const product = field.query('id').value();
|
|
|
const _functionList = findProductMetadata(product)?.functions;
|
|
const _functionList = findProductMetadata(product)?.functions;
|
|
|
const _function =
|
|
const _function =
|
|
|
_functionList && _functionList.find((item: any) => item.id === functionId);
|
|
_functionList && _functionList.find((item: any) => item.id === functionId);
|
|
@@ -477,35 +486,44 @@ const Save = () => {
|
|
|
});
|
|
});
|
|
|
},
|
|
},
|
|
|
);
|
|
);
|
|
|
- onFieldReact('propertyMappings.*.layout.target', (field) => {
|
|
|
|
|
- const productType = field.query('deviceType').value();
|
|
|
|
|
- (field as Field).setDataSource(findDeviceType(productType)?.properties);
|
|
|
|
|
- });
|
|
|
|
|
onFieldReact('propertyMappings.*.layout.source', (field) => {
|
|
onFieldReact('propertyMappings.*.layout.source', (field) => {
|
|
|
- const product = field.query('product').value();
|
|
|
|
|
|
|
+ const productType = field.query('applianceType').value();
|
|
|
|
|
+ (field as Field).setDataSource(findapplianceType(productType)?.properties);
|
|
|
|
|
+ });
|
|
|
|
|
+ onFieldReact('propertyMappings.*.layout.target', (field) => {
|
|
|
|
|
+ const product = field.query('id').value();
|
|
|
(field as Field).setDataSource(findProductMetadata(product)?.properties);
|
|
(field as Field).setDataSource(findProductMetadata(product)?.properties);
|
|
|
});
|
|
});
|
|
|
},
|
|
},
|
|
|
}),
|
|
}),
|
|
|
[],
|
|
[],
|
|
|
);
|
|
);
|
|
|
|
|
+
|
|
|
|
|
+ const handleSave = async () => {
|
|
|
|
|
+ const data: any = await form.submit();
|
|
|
|
|
+ await service.savePatch(data);
|
|
|
|
|
+ message.success('保存成功!');
|
|
|
|
|
+ history.back();
|
|
|
|
|
+ };
|
|
|
return (
|
|
return (
|
|
|
- <PageContainer>
|
|
|
|
|
|
|
+ <PageContainer className={'page-title-show'}>
|
|
|
<Card>
|
|
<Card>
|
|
|
<Row>
|
|
<Row>
|
|
|
- <Col span={10}>
|
|
|
|
|
|
|
+ <Col span={12}>
|
|
|
<Form layout="vertical" form={form}>
|
|
<Form layout="vertical" form={form}>
|
|
|
<SchemaField schema={schema} scope={{ useAsyncDataSource, getTypes, getProduct }} />
|
|
<SchemaField schema={schema} scope={{ useAsyncDataSource, getTypes, getProduct }} />
|
|
|
<FormButtonGroup.Sticky>
|
|
<FormButtonGroup.Sticky>
|
|
|
<FormButtonGroup.FormItem>
|
|
<FormButtonGroup.FormItem>
|
|
|
- <PermissionButton type="primary" onClick={handleSave}>
|
|
|
|
|
|
|
+ <PermissionButton isPermission={true} type="primary" onClick={handleSave}>
|
|
|
保存
|
|
保存
|
|
|
</PermissionButton>
|
|
</PermissionButton>
|
|
|
</FormButtonGroup.FormItem>
|
|
</FormButtonGroup.FormItem>
|
|
|
</FormButtonGroup.Sticky>
|
|
</FormButtonGroup.Sticky>
|
|
|
</Form>
|
|
</Form>
|
|
|
</Col>
|
|
</Col>
|
|
|
- <Col span={12} push={2}></Col>
|
|
|
|
|
|
|
+ <Col span={10} push={2}>
|
|
|
|
|
+ <Doc />
|
|
|
|
|
+ </Col>
|
|
|
</Row>
|
|
</Row>
|
|
|
</Card>
|
|
</Card>
|
|
|
</PageContainer>
|
|
</PageContainer>
|