|
@@ -1,12 +1,23 @@
|
|
|
-import { Button, Modal } from 'antd';
|
|
|
|
|
|
|
+import { message, Modal } from 'antd';
|
|
|
import { useMemo } from 'react';
|
|
import { useMemo } from 'react';
|
|
|
-import { createForm } from '@formily/core';
|
|
|
|
|
|
|
+import { createForm, Field, onFieldReact, onFieldValueChange } from '@formily/core';
|
|
|
import { createSchemaField, observer } from '@formily/react';
|
|
import { createSchemaField, observer } from '@formily/react';
|
|
|
-import { Form, FormItem, Input, Select } from '@formily/antd';
|
|
|
|
|
|
|
+import {
|
|
|
|
|
+ ArrayTable,
|
|
|
|
|
+ DatePicker,
|
|
|
|
|
+ Form,
|
|
|
|
|
+ FormItem,
|
|
|
|
|
+ Input,
|
|
|
|
|
+ NumberPicker,
|
|
|
|
|
+ PreviewText,
|
|
|
|
|
+ Select,
|
|
|
|
|
+} from '@formily/antd';
|
|
|
import { ISchema } from '@formily/json-schema';
|
|
import { ISchema } from '@formily/json-schema';
|
|
|
import { service, state } from '@/pages/notice/Config';
|
|
import { service, state } from '@/pages/notice/Config';
|
|
|
import { useLocation } from 'umi';
|
|
import { useLocation } from 'umi';
|
|
|
import { useAsyncDataSource } from '@/utils/util';
|
|
import { useAsyncDataSource } from '@/utils/util';
|
|
|
|
|
+import { Store } from 'jetlinks-store';
|
|
|
|
|
+import FUpload from '@/components/Upload';
|
|
|
|
|
|
|
|
const Debug = observer(() => {
|
|
const Debug = observer(() => {
|
|
|
const location = useLocation<{ id: string }>();
|
|
const location = useLocation<{ id: string }>();
|
|
@@ -16,9 +27,41 @@ const Debug = observer(() => {
|
|
|
() =>
|
|
() =>
|
|
|
createForm({
|
|
createForm({
|
|
|
validateFirst: true,
|
|
validateFirst: true,
|
|
|
- effects() {},
|
|
|
|
|
|
|
+ effects() {
|
|
|
|
|
+ onFieldValueChange('templateId', (field, form1) => {
|
|
|
|
|
+ const value = field.value;
|
|
|
|
|
+ // 找到模版详情;
|
|
|
|
|
+ const list = Store.get('notice-template-list');
|
|
|
|
|
+
|
|
|
|
|
+ const _template = list.find((item: any) => item.id === value);
|
|
|
|
|
+ form1.setValuesIn('variableDefinitions', _template.variableDefinitions);
|
|
|
|
|
+ });
|
|
|
|
|
+ onFieldReact('variableDefinitions.*.type', (field) => {
|
|
|
|
|
+ const value = (field as Field).value;
|
|
|
|
|
+ const format = field.query('.value').take() as any;
|
|
|
|
|
+ switch (value) {
|
|
|
|
|
+ case 'date':
|
|
|
|
|
+ format.setComponent(DatePicker);
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 'string':
|
|
|
|
|
+ format.setComponent(Input);
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 'number':
|
|
|
|
|
+ format.setComponent(NumberPicker);
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 'file':
|
|
|
|
|
+ format.setComponent(FUpload, {
|
|
|
|
|
+ type: 'file',
|
|
|
|
|
+ });
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 'other':
|
|
|
|
|
+ format.setComponent(Input);
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ },
|
|
|
}),
|
|
}),
|
|
|
- [],
|
|
|
|
|
|
|
+ [state.debug],
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
const SchemaField = createSchemaField({
|
|
const SchemaField = createSchemaField({
|
|
@@ -26,49 +69,124 @@ const Debug = observer(() => {
|
|
|
FormItem,
|
|
FormItem,
|
|
|
Input,
|
|
Input,
|
|
|
Select,
|
|
Select,
|
|
|
|
|
+ ArrayTable,
|
|
|
|
|
+ PreviewText,
|
|
|
},
|
|
},
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- console.log(id, 'testt');
|
|
|
|
|
-
|
|
|
|
|
- const getTemplate = () => {
|
|
|
|
|
- return service.getTemplate(id).then((resp) => {
|
|
|
|
|
- return resp.result?.map((item: any) => ({
|
|
|
|
|
- label: item.name,
|
|
|
|
|
- value: item.id,
|
|
|
|
|
- }));
|
|
|
|
|
- });
|
|
|
|
|
- };
|
|
|
|
|
|
|
+ const getTemplate = () =>
|
|
|
|
|
+ service
|
|
|
|
|
+ .getTemplate(state.current?.id || '', {
|
|
|
|
|
+ terms: [
|
|
|
|
|
+ { column: 'type', value: id },
|
|
|
|
|
+ { column: 'provider', value: state.current?.provider },
|
|
|
|
|
+ ],
|
|
|
|
|
+ })
|
|
|
|
|
+ .then((resp) => {
|
|
|
|
|
+ Store.set('notice-template-list', resp.result);
|
|
|
|
|
+ return resp.result?.map((item: any) => ({
|
|
|
|
|
+ label: item.name,
|
|
|
|
|
+ value: item.id,
|
|
|
|
|
+ }));
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
const schema: ISchema = {
|
|
const schema: ISchema = {
|
|
|
type: 'object',
|
|
type: 'object',
|
|
|
properties: {
|
|
properties: {
|
|
|
- configId: {
|
|
|
|
|
|
|
+ templateId: {
|
|
|
title: '通知模版',
|
|
title: '通知模版',
|
|
|
type: 'string',
|
|
type: 'string',
|
|
|
'x-decorator': 'FormItem',
|
|
'x-decorator': 'FormItem',
|
|
|
'x-component': 'Select',
|
|
'x-component': 'Select',
|
|
|
'x-reactions': '{{useAsyncDataSource(getTemplate)}}',
|
|
'x-reactions': '{{useAsyncDataSource(getTemplate)}}',
|
|
|
},
|
|
},
|
|
|
- bianliang: {
|
|
|
|
|
|
|
+ variableDefinitions: {
|
|
|
title: '变量',
|
|
title: '变量',
|
|
|
type: 'string',
|
|
type: 'string',
|
|
|
'x-decorator': 'FormItem',
|
|
'x-decorator': 'FormItem',
|
|
|
- 'x-component': 'Select',
|
|
|
|
|
|
|
+ 'x-component': 'ArrayTable',
|
|
|
|
|
+ 'x-component-props': {
|
|
|
|
|
+ pagination: { pageSize: 9999 },
|
|
|
|
|
+ scroll: { x: '100%' },
|
|
|
|
|
+ },
|
|
|
|
|
+ items: {
|
|
|
|
|
+ type: 'object',
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ column1: {
|
|
|
|
|
+ type: 'void',
|
|
|
|
|
+ 'x-component': 'ArrayTable.Column',
|
|
|
|
|
+ 'x-component-props': { title: '变量', width: '120px' },
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ id: {
|
|
|
|
|
+ type: 'string',
|
|
|
|
|
+ 'x-decorator': 'FormItem',
|
|
|
|
|
+ 'x-component': 'PreviewText.Input',
|
|
|
|
|
+ 'x-disabled': true,
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
|
|
+ column2: {
|
|
|
|
|
+ type: 'void',
|
|
|
|
|
+ 'x-component': 'ArrayTable.Column',
|
|
|
|
|
+ 'x-component-props': { title: '名称', width: '120px' },
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ name: {
|
|
|
|
|
+ type: 'string',
|
|
|
|
|
+ 'x-decorator': 'FormItem',
|
|
|
|
|
+ 'x-component': 'PreviewText.Input',
|
|
|
|
|
+ 'x-disabled': true,
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
|
|
+ column3: {
|
|
|
|
|
+ type: 'void',
|
|
|
|
|
+ 'x-component': 'ArrayTable.Column',
|
|
|
|
|
+ 'x-component-props': { title: '值', width: '120px' },
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ value: {
|
|
|
|
|
+ type: 'string',
|
|
|
|
|
+ 'x-decorator': 'FormItem',
|
|
|
|
|
+ 'x-component': 'Input',
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
},
|
|
},
|
|
|
},
|
|
},
|
|
|
};
|
|
};
|
|
|
|
|
+
|
|
|
|
|
+ const start = async () => {
|
|
|
|
|
+ const data: { templateId: string; variableDefinitions: any } = await form.submit();
|
|
|
|
|
+ // 应该取选择的配置信息
|
|
|
|
|
+ if (!state.current) return;
|
|
|
|
|
+ const templateId = data.templateId;
|
|
|
|
|
+ const list = Store.get('notice-template-list');
|
|
|
|
|
+ const _template = list.find((item: any) => item.id === templateId);
|
|
|
|
|
+
|
|
|
|
|
+ const resp = await service.debug(state?.current.id, {
|
|
|
|
|
+ template: _template,
|
|
|
|
|
+ context: data.variableDefinitions?.reduce(
|
|
|
|
|
+ (previousValue: any, currentValue: { id: any; value: any }) => {
|
|
|
|
|
+ return {
|
|
|
|
|
+ ...previousValue,
|
|
|
|
|
+ [currentValue.id]: currentValue.value,
|
|
|
|
|
+ };
|
|
|
|
|
+ },
|
|
|
|
|
+ {},
|
|
|
|
|
+ ),
|
|
|
|
|
+ });
|
|
|
|
|
+ if (resp.status === 200) {
|
|
|
|
|
+ message.success('操作成功!');
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
return (
|
|
return (
|
|
|
<Modal
|
|
<Modal
|
|
|
title="调试"
|
|
title="调试"
|
|
|
width="40vw"
|
|
width="40vw"
|
|
|
visible={state.debug}
|
|
visible={state.debug}
|
|
|
onCancel={() => (state.debug = false)}
|
|
onCancel={() => (state.debug = false)}
|
|
|
- footer={
|
|
|
|
|
- <Button type="primary" onClick={() => (state.debug = false)}>
|
|
|
|
|
- 关闭
|
|
|
|
|
- </Button>
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ onOk={start}
|
|
|
>
|
|
>
|
|
|
<Form form={form} layout={'vertical'}>
|
|
<Form form={form} layout={'vertical'}>
|
|
|
<SchemaField schema={schema} scope={{ getTemplate, useAsyncDataSource }} />
|
|
<SchemaField schema={schema} scope={{ getTemplate, useAsyncDataSource }} />
|