|
|
@@ -20,7 +20,7 @@ import {
|
|
|
onFieldValueChange,
|
|
|
onFormValuesChange,
|
|
|
} from '@formily/core';
|
|
|
-import { forwardRef, useImperativeHandle, useMemo, useRef } from 'react';
|
|
|
+import { forwardRef, useEffect, useImperativeHandle, useMemo, useRef } from 'react';
|
|
|
import FTermArrayCards from '@/components/FTermArrayCards';
|
|
|
import FTermTypeSelect from '@/components/FTermTypeSelect';
|
|
|
import styles from './index.less';
|
|
|
@@ -30,6 +30,7 @@ import { Store } from 'jetlinks-store';
|
|
|
import { treeFilter } from '@/utils/tree';
|
|
|
import FInputGroup from '@/components/FInputGroup';
|
|
|
import { Button } from 'antd';
|
|
|
+import _ from 'lodash';
|
|
|
|
|
|
const service = new Service('scene');
|
|
|
|
|
|
@@ -89,35 +90,6 @@ const TriggerTerm = (props: Props, ref: any) => {
|
|
|
() =>
|
|
|
createForm({
|
|
|
validateFirst: true,
|
|
|
- initialValues:
|
|
|
- {
|
|
|
- trigger: [
|
|
|
- {
|
|
|
- type: 'and',
|
|
|
- termType: 'eq',
|
|
|
- options: [],
|
|
|
- terms: [
|
|
|
- {
|
|
|
- column: 'timestamp',
|
|
|
- value: { source: 'manual', value: ['3123', '312321'] },
|
|
|
- type: 'and',
|
|
|
- termType: 'btw',
|
|
|
- options: [],
|
|
|
- terms: [],
|
|
|
- },
|
|
|
- {
|
|
|
- column: '_now',
|
|
|
- value: { source: 'manual', value: '2022-05-24 00:00:06' },
|
|
|
- type: 'and',
|
|
|
- termType: 'eq',
|
|
|
- options: [],
|
|
|
- terms: [],
|
|
|
- },
|
|
|
- ],
|
|
|
- },
|
|
|
- ],
|
|
|
- } || props.value,
|
|
|
-
|
|
|
effects() {
|
|
|
onFormValuesChange(async (f) => {
|
|
|
if (props.onChange) {
|
|
|
@@ -181,21 +153,7 @@ const TriggerTerm = (props: Props, ref: any) => {
|
|
|
: treeValue[0];
|
|
|
|
|
|
const source = (field as Field).value;
|
|
|
- const termType = field.query('..termType').value();
|
|
|
- const tag = ['nbtw', 'btw'].includes(termType);
|
|
|
- // 如果是范围..那么就应该取.value.0; 如果不是就是.value
|
|
|
- const pathMap = {
|
|
|
- range: field.query('.value.0'),
|
|
|
- value: field.query('.value'),
|
|
|
- metric: field.query('.metric'),
|
|
|
- };
|
|
|
- let value;
|
|
|
- if (source === 'manual') {
|
|
|
- value = tag ? pathMap['range'] : pathMap['value'];
|
|
|
- } else {
|
|
|
- value = pathMap['metric'];
|
|
|
- }
|
|
|
- // const value = field.query(source === 'manual' ? '.value.0' : '.metric');
|
|
|
+ const value = field.query(source === 'manual' ? '.value.0' : '.metric');
|
|
|
if (target) {
|
|
|
if (source === 'manual') {
|
|
|
// 手动输入
|
|
|
@@ -238,6 +196,8 @@ const TriggerTerm = (props: Props, ref: any) => {
|
|
|
}
|
|
|
});
|
|
|
} else if (source === 'metrics') {
|
|
|
+ const termType = field.query('..termType').value();
|
|
|
+ const tag = ['nbtw', 'btw'].includes(termType);
|
|
|
// 指标
|
|
|
form1.setFieldState(value, (state) => {
|
|
|
state.componentType = Select;
|
|
|
@@ -257,10 +217,34 @@ const TriggerTerm = (props: Props, ref: any) => {
|
|
|
[props.value, props.params],
|
|
|
);
|
|
|
|
|
|
+ useEffect(() => {
|
|
|
+ const data = props.value;
|
|
|
+ data?.trigger?.map((item: { terms: any[] }) =>
|
|
|
+ item.terms?.map((j) => {
|
|
|
+ if (typeof j.value.value === 'string') {
|
|
|
+ j.value.value = [j.value.value];
|
|
|
+ }
|
|
|
+ return j;
|
|
|
+ }),
|
|
|
+ );
|
|
|
+ form.setInitialValues(data);
|
|
|
+ }, [props.value]);
|
|
|
+
|
|
|
useImperativeHandle(ref, () => ({
|
|
|
getTriggerForm: async () => {
|
|
|
await form.validate();
|
|
|
- return form.submit();
|
|
|
+ const data: any = await form.submit().then((_data: any) => {
|
|
|
+ _data.trigger?.map((item: { terms: any[] }) =>
|
|
|
+ item.terms.map((j) => {
|
|
|
+ if (j.value.value.length === 1) {
|
|
|
+ j.value.value = j.value.value[0];
|
|
|
+ }
|
|
|
+ return j;
|
|
|
+ }),
|
|
|
+ );
|
|
|
+ return _data;
|
|
|
+ });
|
|
|
+ return data;
|
|
|
},
|
|
|
}));
|
|
|
const SchemaField = createSchemaField({
|
|
|
@@ -378,58 +362,65 @@ const TriggerTerm = (props: Props, ref: any) => {
|
|
|
},
|
|
|
},
|
|
|
},
|
|
|
- range: {
|
|
|
- type: 'void',
|
|
|
- 'x-reactions': {
|
|
|
- dependencies: ['.source', '..termType'],
|
|
|
- fulfill: {
|
|
|
- state: {
|
|
|
- visible:
|
|
|
- '{{$deps[0]==="manual"&&(["nbtw","btw"].includes($deps[1]))}}',
|
|
|
- },
|
|
|
+ 'value[0]': {
|
|
|
+ type: 'string',
|
|
|
+ 'x-component': 'Input',
|
|
|
+ 'x-decorator': 'FormItem',
|
|
|
+ 'x-decorator-props': {
|
|
|
+ style: {
|
|
|
+ width: 'calc(100% - 110px)',
|
|
|
},
|
|
|
},
|
|
|
- properties: {
|
|
|
- 'value[0]': {
|
|
|
- type: 'string',
|
|
|
- 'x-component': 'Input',
|
|
|
- 'x-decorator': 'FormItem',
|
|
|
- 'x-decorator-props': {
|
|
|
- style: {
|
|
|
- width: 'calc(50% - 55px)',
|
|
|
+ required: true,
|
|
|
+ 'x-reactions': [
|
|
|
+ {
|
|
|
+ dependencies: ['..source'],
|
|
|
+ fulfill: {
|
|
|
+ state: {
|
|
|
+ visible: '{{$deps[0]==="manual"}}',
|
|
|
},
|
|
|
},
|
|
|
- required: true,
|
|
|
},
|
|
|
- 'value[1]': {
|
|
|
- type: 'string',
|
|
|
- 'x-component': 'Input',
|
|
|
- 'x-decorator': 'FormItem',
|
|
|
- 'x-decorator-props': {
|
|
|
- style: {
|
|
|
- width: 'calc(50% - 55px)',
|
|
|
+ {
|
|
|
+ dependencies: ['...termType'],
|
|
|
+ when: '{{["nbtw","btw"].includes($deps[0])}}',
|
|
|
+ fulfill: {
|
|
|
+ state: {
|
|
|
+ decoratorProps: {
|
|
|
+ style: {
|
|
|
+ width: 'calc(50% - 55px)',
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ otherwise: {
|
|
|
+ state: {
|
|
|
+ decoratorProps: {
|
|
|
+ style: {
|
|
|
+ width: 'calc(100% - 110px)',
|
|
|
+ },
|
|
|
+ },
|
|
|
},
|
|
|
},
|
|
|
- required: true,
|
|
|
},
|
|
|
- },
|
|
|
+ ],
|
|
|
},
|
|
|
- value: {
|
|
|
+ 'value[1]': {
|
|
|
type: 'string',
|
|
|
'x-component': 'Input',
|
|
|
'x-decorator': 'FormItem',
|
|
|
'x-decorator-props': {
|
|
|
style: {
|
|
|
- width: 'calc(100% - 110px)',
|
|
|
+ width: 'calc(50% - 55px)',
|
|
|
},
|
|
|
},
|
|
|
required: true,
|
|
|
'x-reactions': {
|
|
|
- dependencies: ['.source', '..termType'],
|
|
|
+ dependencies: ['..source', '...termType'],
|
|
|
fulfill: {
|
|
|
state: {
|
|
|
visible:
|
|
|
- '{{$deps[0]==="manual"&&!(["nbtw","btw"].includes($deps[1]))}}',
|
|
|
+ '{{$deps[0]==="manual"&&["nbtw","btw"].includes($deps[1])}}',
|
|
|
},
|
|
|
},
|
|
|
},
|
|
|
@@ -501,10 +492,22 @@ const TriggerTerm = (props: Props, ref: any) => {
|
|
|
<SchemaField schema={schema} scope={{ useAsyncDataSource, getParseTerm }} />
|
|
|
<Button
|
|
|
onClick={async () => {
|
|
|
- console.log(await form.submit());
|
|
|
+ const data: any = await form.submit();
|
|
|
+ data.trigger?.map((item: { terms: any[] }) =>
|
|
|
+ item.terms.map((j) => {
|
|
|
+ if (j.value.value.length === 1) {
|
|
|
+ j.value.value = j.value.value[0];
|
|
|
+ }
|
|
|
+ return j;
|
|
|
+ }),
|
|
|
+ );
|
|
|
+ const value = _.get(data, 'trigger[*].terms[*].value.value');
|
|
|
+ console.log(value, 'vvvv');
|
|
|
+ _.set(value, 'x[*].xxx', 'test');
|
|
|
+ console.log(data);
|
|
|
}}
|
|
|
>
|
|
|
- 保存
|
|
|
+ 保存数据
|
|
|
</Button>
|
|
|
</Form>
|
|
|
);
|