|
@@ -22,6 +22,7 @@ import {
|
|
|
Radio,
|
|
Radio,
|
|
|
Select,
|
|
Select,
|
|
|
Space,
|
|
Space,
|
|
|
|
|
+ Switch,
|
|
|
} from '@formily/antd';
|
|
} from '@formily/antd';
|
|
|
import type { ISchema } from '@formily/json-schema';
|
|
import type { ISchema } from '@formily/json-schema';
|
|
|
import {
|
|
import {
|
|
@@ -46,13 +47,16 @@ import { lastValueFrom } from 'rxjs';
|
|
|
import SystemConst from '@/utils/const';
|
|
import SystemConst from '@/utils/const';
|
|
|
import DB from '@/db';
|
|
import DB from '@/db';
|
|
|
import _ from 'lodash';
|
|
import _ from 'lodash';
|
|
|
-import { InstanceModel } from '@/pages/device/Instance';
|
|
|
|
|
|
|
+// import { InstanceModel } from '@/pages/device/Instance';
|
|
|
import FRuleEditor from '@/components/FRuleEditor';
|
|
import FRuleEditor from '@/components/FRuleEditor';
|
|
|
import FIndicators from '@/components/FIndicators';
|
|
import FIndicators from '@/components/FIndicators';
|
|
|
import { action } from '@formily/reactive';
|
|
import { action } from '@formily/reactive';
|
|
|
import { asyncUpdateMedata, updateMetadata } from '../../metadata';
|
|
import { asyncUpdateMedata, updateMetadata } from '../../metadata';
|
|
|
import { onlyMessage } from '@/utils/util';
|
|
import { onlyMessage } from '@/utils/util';
|
|
|
import Editable from '@/components/Metadata/EditTable';
|
|
import Editable from '@/components/Metadata/EditTable';
|
|
|
|
|
+import InputSelect from '../../../InputSelect';
|
|
|
|
|
+import { InstanceModel, service as instanceService } from '@/pages/device/Instance';
|
|
|
|
|
+import { useParams } from 'umi';
|
|
|
|
|
|
|
|
interface Props {
|
|
interface Props {
|
|
|
type: 'product' | 'device';
|
|
type: 'product' | 'device';
|
|
@@ -62,6 +66,7 @@ interface Props {
|
|
|
const Edit = observer((props: Props) => {
|
|
const Edit = observer((props: Props) => {
|
|
|
const intl = useIntl();
|
|
const intl = useIntl();
|
|
|
const [loading, setLoading] = useState<boolean>(false);
|
|
const [loading, setLoading] = useState<boolean>(false);
|
|
|
|
|
+ const param = useParams<{ id: string }>();
|
|
|
const form = useMemo(
|
|
const form = useMemo(
|
|
|
() =>
|
|
() =>
|
|
|
createForm({
|
|
createForm({
|
|
@@ -170,7 +175,9 @@ const Edit = observer((props: Props) => {
|
|
|
Checkbox,
|
|
Checkbox,
|
|
|
FormGrid,
|
|
FormGrid,
|
|
|
DatePicker,
|
|
DatePicker,
|
|
|
|
|
+ Switch,
|
|
|
FIndicators,
|
|
FIndicators,
|
|
|
|
|
+ InputSelect,
|
|
|
},
|
|
},
|
|
|
scope: {
|
|
scope: {
|
|
|
async asyncOtherConfig(field: Field) {
|
|
async asyncOtherConfig(field: Field) {
|
|
@@ -247,12 +254,13 @@ const Edit = observer((props: Props) => {
|
|
|
defaultMessage: '单位',
|
|
defaultMessage: '单位',
|
|
|
}),
|
|
}),
|
|
|
'x-decorator': 'FormItem',
|
|
'x-decorator': 'FormItem',
|
|
|
- 'x-component': 'Select',
|
|
|
|
|
|
|
+ 'x-component': 'InputSelect',
|
|
|
'x-visible': false,
|
|
'x-visible': false,
|
|
|
'x-component-props': {
|
|
'x-component-props': {
|
|
|
showSearch: true,
|
|
showSearch: true,
|
|
|
showArrow: true,
|
|
showArrow: true,
|
|
|
allowClear: true,
|
|
allowClear: true,
|
|
|
|
|
+ mode: 'tags',
|
|
|
filterOption: (input: string, option: any) =>
|
|
filterOption: (input: string, option: any) =>
|
|
|
option.label.toLowerCase().indexOf(input.toLowerCase()) >= 0,
|
|
option.label.toLowerCase().indexOf(input.toLowerCase()) >= 0,
|
|
|
},
|
|
},
|
|
@@ -324,21 +332,22 @@ const Edit = observer((props: Props) => {
|
|
|
'x-decorator': 'FormItem',
|
|
'x-decorator': 'FormItem',
|
|
|
'x-component': 'Select',
|
|
'x-component': 'Select',
|
|
|
enum: DateTypeList,
|
|
enum: DateTypeList,
|
|
|
- default: 'string',
|
|
|
|
|
|
|
+ // default: 'yyyy-MM-DD HH:mm:ss',
|
|
|
|
|
+ 'x-visible': false,
|
|
|
'x-validator': [
|
|
'x-validator': [
|
|
|
{
|
|
{
|
|
|
required: true,
|
|
required: true,
|
|
|
message: '请选择时间格式',
|
|
message: '请选择时间格式',
|
|
|
},
|
|
},
|
|
|
],
|
|
],
|
|
|
- 'x-reactions': {
|
|
|
|
|
- dependencies: ['.type'],
|
|
|
|
|
- fulfill: {
|
|
|
|
|
- state: {
|
|
|
|
|
- visible: "{{['date'].includes($deps[0])}}",
|
|
|
|
|
- },
|
|
|
|
|
- },
|
|
|
|
|
- },
|
|
|
|
|
|
|
+ // 'x-reactions': {
|
|
|
|
|
+ // dependencies: ['.type'],
|
|
|
|
|
+ // fulfill: {
|
|
|
|
|
+ // state: {
|
|
|
|
|
+ // visible: "{{['date'].includes($deps[0])}}",
|
|
|
|
|
+ // },
|
|
|
|
|
+ // },
|
|
|
|
|
+ // },
|
|
|
},
|
|
},
|
|
|
enumConfig: {
|
|
enumConfig: {
|
|
|
title: intl.formatMessage({
|
|
title: intl.formatMessage({
|
|
@@ -608,11 +617,12 @@ const Edit = observer((props: Props) => {
|
|
|
type: 'object',
|
|
type: 'object',
|
|
|
title: '规则配置',
|
|
title: '规则配置',
|
|
|
'x-visible': false,
|
|
'x-visible': false,
|
|
|
- 'x-component': 'Editable.Popover',
|
|
|
|
|
|
|
+ // 'x-component': 'Editable.Popover',
|
|
|
'x-reactions': {
|
|
'x-reactions': {
|
|
|
dependencies: ['.source'],
|
|
dependencies: ['.source'],
|
|
|
fulfill: {
|
|
fulfill: {
|
|
|
state: {
|
|
state: {
|
|
|
|
|
+ // visible: '{{$deps[0]}}',
|
|
|
visible: '{{$deps[0]==="rule"}}',
|
|
visible: '{{$deps[0]==="rule"}}',
|
|
|
},
|
|
},
|
|
|
},
|
|
},
|
|
@@ -636,16 +646,37 @@ const Edit = observer((props: Props) => {
|
|
|
// },
|
|
// },
|
|
|
// ],
|
|
// ],
|
|
|
// },
|
|
// },
|
|
|
-
|
|
|
|
|
|
|
+ isVirtualRule: {
|
|
|
|
|
+ type: 'boolean',
|
|
|
|
|
+ title: '规则配置',
|
|
|
|
|
+ 'x-decorator': 'FormItem',
|
|
|
|
|
+ 'x-component': 'Switch',
|
|
|
|
|
+ },
|
|
|
windowType: {
|
|
windowType: {
|
|
|
type: 'string',
|
|
type: 'string',
|
|
|
title: '窗口',
|
|
title: '窗口',
|
|
|
'x-decorator': 'FormItem',
|
|
'x-decorator': 'FormItem',
|
|
|
'x-component': 'Select',
|
|
'x-component': 'Select',
|
|
|
|
|
+ required: true,
|
|
|
|
|
+ 'x-validator': [
|
|
|
|
|
+ {
|
|
|
|
|
+ required: true,
|
|
|
|
|
+ message: `请选择窗口`,
|
|
|
|
|
+ },
|
|
|
|
|
+ ],
|
|
|
enum: [
|
|
enum: [
|
|
|
{ label: '时间窗口', value: 'time' },
|
|
{ label: '时间窗口', value: 'time' },
|
|
|
{ label: '次数窗口', value: 'num' },
|
|
{ label: '次数窗口', value: 'num' },
|
|
|
],
|
|
],
|
|
|
|
|
+ 'x-visible': false,
|
|
|
|
|
+ 'x-reactions': {
|
|
|
|
|
+ dependencies: ['.isVirtualRule'],
|
|
|
|
|
+ fulfill: {
|
|
|
|
|
+ state: {
|
|
|
|
|
+ visible: '{{$deps[0]}}',
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
'x-component-props': {
|
|
'x-component-props': {
|
|
|
allowClear: true,
|
|
allowClear: true,
|
|
|
},
|
|
},
|
|
@@ -668,29 +699,60 @@ const Edit = observer((props: Props) => {
|
|
|
title: '聚合函数',
|
|
title: '聚合函数',
|
|
|
'x-decorator': 'FormItem',
|
|
'x-decorator': 'FormItem',
|
|
|
'x-component': 'Select',
|
|
'x-component': 'Select',
|
|
|
- 'x-reactions': '{{useAsyncDataSource(getStreamingAggType)}}',
|
|
|
|
|
|
|
+ required: true,
|
|
|
|
|
+ 'x-visible': false,
|
|
|
|
|
+ 'x-validator': [
|
|
|
|
|
+ {
|
|
|
|
|
+ required: true,
|
|
|
|
|
+ message: `请选择聚合函数`,
|
|
|
|
|
+ },
|
|
|
|
|
+ ],
|
|
|
|
|
+ 'x-reactions': [
|
|
|
|
|
+ {
|
|
|
|
|
+ dependencies: ['.isVirtualRule'],
|
|
|
|
|
+ fulfill: {
|
|
|
|
|
+ state: {
|
|
|
|
|
+ visible: '{{$deps[0]}}',
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
|
|
+ '{{useAsyncDataSource(getStreamingAggType)}}',
|
|
|
|
|
+ ],
|
|
|
},
|
|
},
|
|
|
window: {
|
|
window: {
|
|
|
type: 'object',
|
|
type: 'object',
|
|
|
|
|
+ 'x-visible': false,
|
|
|
|
|
+ 'x-reactions': {
|
|
|
|
|
+ dependencies: ['.isVirtualRule'],
|
|
|
|
|
+ fulfill: {
|
|
|
|
|
+ state: {
|
|
|
|
|
+ visible: '{{$deps[0]}}',
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
properties: {
|
|
properties: {
|
|
|
span: {
|
|
span: {
|
|
|
title: '窗口长度',
|
|
title: '窗口长度',
|
|
|
- 'x-component': 'Input',
|
|
|
|
|
|
|
+ 'x-component': 'NumberPicker',
|
|
|
'x-decorator': 'FormItem',
|
|
'x-decorator': 'FormItem',
|
|
|
- format: 'number',
|
|
|
|
|
|
|
+ required: true,
|
|
|
|
|
+ 'x-component-props': {
|
|
|
|
|
+ style: {
|
|
|
|
|
+ width: '100%',
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
'x-validator': [
|
|
'x-validator': [
|
|
|
{
|
|
{
|
|
|
- // triggerType: 'onBlur',
|
|
|
|
|
- validator: (value: any[]) => {
|
|
|
|
|
- return new Promise((resolve) => {
|
|
|
|
|
- const number = Number(value);
|
|
|
|
|
- if (number <= 0 || value.length > 64 || /[.]/.test(value)) {
|
|
|
|
|
- resolve('请输入非0正整数,最多可输入64个字符');
|
|
|
|
|
- } else {
|
|
|
|
|
- resolve('');
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
- },
|
|
|
|
|
|
|
+ required: true,
|
|
|
|
|
+ message: `请输入窗口长度`,
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ format: 'integer',
|
|
|
|
|
+ message: '请输入正整数',
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ min: 1,
|
|
|
|
|
+ message: '请输入正整数',
|
|
|
},
|
|
},
|
|
|
],
|
|
],
|
|
|
'x-reactions': [
|
|
'x-reactions': [
|
|
@@ -725,9 +787,14 @@ const Edit = observer((props: Props) => {
|
|
|
},
|
|
},
|
|
|
every: {
|
|
every: {
|
|
|
title: '步长',
|
|
title: '步长',
|
|
|
- 'x-component': 'Input',
|
|
|
|
|
|
|
+ 'x-component': 'NumberPicker',
|
|
|
'x-decorator': 'FormItem',
|
|
'x-decorator': 'FormItem',
|
|
|
- format: 'number',
|
|
|
|
|
|
|
+ required: true,
|
|
|
|
|
+ 'x-component-props': {
|
|
|
|
|
+ style: {
|
|
|
|
|
+ width: '100%',
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
'x-validator': [
|
|
'x-validator': [
|
|
|
{
|
|
{
|
|
|
// triggerType: 'onBlur',
|
|
// triggerType: 'onBlur',
|
|
@@ -1271,6 +1338,12 @@ const Edit = observer((props: Props) => {
|
|
|
typeMap.set('device', InstanceModel.detail);
|
|
typeMap.set('device', InstanceModel.detail);
|
|
|
const { type } = MetadataModel;
|
|
const { type } = MetadataModel;
|
|
|
|
|
|
|
|
|
|
+ const resetMetadata = async () => {
|
|
|
|
|
+ const resp = await instanceService.detail(param.id);
|
|
|
|
|
+ if (resp.status === 200) {
|
|
|
|
|
+ InstanceModel.detail = resp?.result || [];
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
const saveMetadata = async (deploy?: boolean) => {
|
|
const saveMetadata = async (deploy?: boolean) => {
|
|
|
setLoading(true);
|
|
setLoading(true);
|
|
|
let params;
|
|
let params;
|
|
@@ -1322,6 +1395,7 @@ const Edit = observer((props: Props) => {
|
|
|
if (deploy) {
|
|
if (deploy) {
|
|
|
Store.set('product-deploy', deploy);
|
|
Store.set('product-deploy', deploy);
|
|
|
} else {
|
|
} else {
|
|
|
|
|
+ resetMetadata();
|
|
|
message.success({
|
|
message.success({
|
|
|
key: 'metadata',
|
|
key: 'metadata',
|
|
|
content: '操作成功!',
|
|
content: '操作成功!',
|