|
|
@@ -1,13 +1,17 @@
|
|
|
import { PageContainer } from '@ant-design/pro-layout';
|
|
|
-import BaseService from '@/utils/BaseService';
|
|
|
import { useRef } from 'react';
|
|
|
import type { ActionType, ProColumns } from '@jetlinks/pro-table';
|
|
|
import BaseCrud from '@/components/BaseCrud';
|
|
|
import { ArrowDownOutlined, BugOutlined, EditOutlined, MinusOutlined } from '@ant-design/icons';
|
|
|
import { Tooltip } from 'antd';
|
|
|
import { useIntl } from '@@/plugin-locale/localeExports';
|
|
|
+import type { ISchema } from '@formily/json-schema';
|
|
|
+import Service from '@/pages/notice/Template/service';
|
|
|
+import { useAsyncDataSource } from '@/utils/util';
|
|
|
+import type { Field } from '@formily/core';
|
|
|
+import { onFieldValueChange } from '@formily/core';
|
|
|
|
|
|
-export const service = new BaseService<TemplateItem>('notifier/template');
|
|
|
+export const service = new Service('notifier/template');
|
|
|
const Template = () => {
|
|
|
const intl = useIntl();
|
|
|
const actionRef = useRef<ActionType>();
|
|
|
@@ -48,7 +52,7 @@ const Template = () => {
|
|
|
align: 'center',
|
|
|
width: 200,
|
|
|
render: (text, record) => [
|
|
|
- <a onClick={() => console.log(record)}>
|
|
|
+ <a key="edit" onClick={() => console.log(record)}>
|
|
|
<Tooltip
|
|
|
title={intl.formatMessage({
|
|
|
id: 'pages.data.option.edit',
|
|
|
@@ -58,7 +62,7 @@ const Template = () => {
|
|
|
<EditOutlined />
|
|
|
</Tooltip>
|
|
|
</a>,
|
|
|
- <a>
|
|
|
+ <a key="delete">
|
|
|
<Tooltip
|
|
|
title={intl.formatMessage({
|
|
|
id: 'pages.data.option.remove',
|
|
|
@@ -68,7 +72,7 @@ const Template = () => {
|
|
|
<MinusOutlined />
|
|
|
</Tooltip>
|
|
|
</a>,
|
|
|
- <a>
|
|
|
+ <a key="download">
|
|
|
<Tooltip
|
|
|
title={intl.formatMessage({
|
|
|
id: 'pages.data.option.download',
|
|
|
@@ -78,7 +82,7 @@ const Template = () => {
|
|
|
<ArrowDownOutlined />
|
|
|
</Tooltip>
|
|
|
</a>,
|
|
|
- <a>
|
|
|
+ <a key="debug">
|
|
|
<Tooltip
|
|
|
title={intl.formatMessage({
|
|
|
id: 'pages.notice.option.debug',
|
|
|
@@ -91,8 +95,501 @@ const Template = () => {
|
|
|
],
|
|
|
},
|
|
|
];
|
|
|
+ const providerRef = useRef<NetworkType[]>([]);
|
|
|
|
|
|
- const schema = {};
|
|
|
+ const getTypes = async () =>
|
|
|
+ service.getTypes().then((resp) => {
|
|
|
+ providerRef.current = resp.result;
|
|
|
+ return resp.result.map((item: NetworkType) => ({
|
|
|
+ label: item.name,
|
|
|
+ value: item.id,
|
|
|
+ }));
|
|
|
+ });
|
|
|
+
|
|
|
+ const formEvent = () => {
|
|
|
+ onFieldValueChange('type', async (field, f) => {
|
|
|
+ const type = field.value;
|
|
|
+ if (!type) return;
|
|
|
+ f.setFieldState('provider', (state) => {
|
|
|
+ state.value = undefined;
|
|
|
+ state.dataSource = providerRef.current
|
|
|
+ .find((item) => type === item.id)
|
|
|
+ ?.providerInfos.map((i) => ({ label: i.name, value: i.id }));
|
|
|
+ });
|
|
|
+ });
|
|
|
+ };
|
|
|
+
|
|
|
+ const handleNetwork = (field: Field) => {
|
|
|
+ const provider = field.query('...provider').get('value');
|
|
|
+ const defaultMessage = {
|
|
|
+ MQTT_CLIENT:
|
|
|
+ 'qos1 /device/${#deviceId}\n' +
|
|
|
+ '\n' +
|
|
|
+ '${T(com.alibaba.fastjson.JSON).toJSONString(#this)}',
|
|
|
+ HTTP_CLIENT:
|
|
|
+ 'POST http://[host]:[port]/api\n' +
|
|
|
+ 'Content-Type: application/json\n' +
|
|
|
+ '\n' +
|
|
|
+ '${T(com.alibaba.fastjson.JSON).toJSONString(#this)}',
|
|
|
+ };
|
|
|
+ field.value = defaultMessage[provider];
|
|
|
+ };
|
|
|
+
|
|
|
+ const schema: ISchema = {
|
|
|
+ type: 'object',
|
|
|
+ properties: {
|
|
|
+ name: {
|
|
|
+ type: 'string',
|
|
|
+ title: '名称',
|
|
|
+ required: true,
|
|
|
+ 'x-component': 'Input',
|
|
|
+ 'x-decorator': 'FormItem',
|
|
|
+ },
|
|
|
+ grid: {
|
|
|
+ type: 'void',
|
|
|
+ 'x-component': 'FormGrid',
|
|
|
+ 'x-decorator': 'FormItem',
|
|
|
+ properties: {
|
|
|
+ type: {
|
|
|
+ type: 'string',
|
|
|
+ title: '通知类型',
|
|
|
+ 'x-component': 'Select',
|
|
|
+ 'x-decorator': 'FormItem',
|
|
|
+ 'x-decorator-props': {
|
|
|
+ labelCol: 8,
|
|
|
+ wrapperCol: 12,
|
|
|
+ },
|
|
|
+ 'x-reactions': ['{{useAsyncDataSource(getTypes)}}'],
|
|
|
+ },
|
|
|
+ provider: {
|
|
|
+ type: 'string',
|
|
|
+ title: '服务商',
|
|
|
+ 'x-component': 'Select',
|
|
|
+ 'x-decorator-props': {
|
|
|
+ labelCol: 4,
|
|
|
+ wrapperCol: 16,
|
|
|
+ },
|
|
|
+ 'x-decorator': 'FormItem',
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ template: {
|
|
|
+ type: 'object',
|
|
|
+ properties: {
|
|
|
+ voice: {
|
|
|
+ type: 'void',
|
|
|
+ properties: {
|
|
|
+ ttsCode: {
|
|
|
+ type: 'string',
|
|
|
+ title: '模版ID',
|
|
|
+ 'x-component': 'Input',
|
|
|
+ 'x-decorator': 'FormItem',
|
|
|
+ },
|
|
|
+ calledShowNumbers: {
|
|
|
+ type: 'string',
|
|
|
+ title: '被叫显号',
|
|
|
+ 'x-component': 'Input',
|
|
|
+ 'x-decorator': 'FormItem',
|
|
|
+ },
|
|
|
+ CalledNumber: {
|
|
|
+ type: 'string',
|
|
|
+ title: '被叫号码',
|
|
|
+ 'x-component': 'Input',
|
|
|
+ 'x-decorator': 'FormItem',
|
|
|
+ },
|
|
|
+ PlayTimes: {
|
|
|
+ type: 'string',
|
|
|
+ title: '播放次数',
|
|
|
+ 'x-component': 'Input',
|
|
|
+ 'x-decorator': 'FormItem',
|
|
|
+ },
|
|
|
+ },
|
|
|
+ 'x-visible': false,
|
|
|
+ 'x-reactions': {
|
|
|
+ dependencies: ['...type'],
|
|
|
+ fulfill: {
|
|
|
+ state: {
|
|
|
+ visible: '{{$deps[0]==="voice"}}',
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ sms: {
|
|
|
+ type: 'void',
|
|
|
+ properties: {
|
|
|
+ test: {
|
|
|
+ type: 'void',
|
|
|
+ properties: {
|
|
|
+ text: {
|
|
|
+ type: 'string',
|
|
|
+ title: '应用ID',
|
|
|
+ 'x-component': 'Input.TextArea',
|
|
|
+ 'x-decorator': 'FormItem',
|
|
|
+ },
|
|
|
+ sendTo: {
|
|
|
+ type: 'string',
|
|
|
+ title: '收件人',
|
|
|
+ 'x-component': 'Input.TextArea',
|
|
|
+ 'x-decorator': 'FormItem',
|
|
|
+ 'x-component-props': {
|
|
|
+ placeholder: '多个收件人以 , 分割',
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ 'x-visible': false,
|
|
|
+ 'x-reactions': {
|
|
|
+ dependencies: ['...provider'],
|
|
|
+ fulfill: {
|
|
|
+ state: {
|
|
|
+ visible: '{{$deps[0]==="test"}}',
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ aliyunSms: {
|
|
|
+ type: 'void',
|
|
|
+ properties: {
|
|
|
+ code: {
|
|
|
+ type: 'string',
|
|
|
+ title: '模版编码',
|
|
|
+ 'x-component': 'Input.TextArea',
|
|
|
+ 'x-decorator': 'FormItem',
|
|
|
+ required: true,
|
|
|
+ 'x-component-props': {
|
|
|
+ placeholder: '阿里云短信模版编码',
|
|
|
+ },
|
|
|
+ },
|
|
|
+ signName: {
|
|
|
+ type: 'string',
|
|
|
+ title: '签名',
|
|
|
+ 'x-component': 'Input.TextArea',
|
|
|
+ 'x-decorator': 'FormItem',
|
|
|
+ required: true,
|
|
|
+ 'x-component-props': {
|
|
|
+ placeholder: '阿里云短信模版签名',
|
|
|
+ },
|
|
|
+ },
|
|
|
+ phoneNumber: {
|
|
|
+ type: 'string',
|
|
|
+ title: '收件人',
|
|
|
+ 'x-component': 'Input.TextArea',
|
|
|
+ 'x-decorator': 'FormItem',
|
|
|
+ 'x-component-props': {
|
|
|
+ placeholder: '短信接收者,暂只支持单个联系人',
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ 'x-visible': false,
|
|
|
+ 'x-reactions': {
|
|
|
+ dependencies: ['...provider'],
|
|
|
+ fulfill: {
|
|
|
+ state: {
|
|
|
+ visible: '{{$deps[0]==="aliyunSms"}}',
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ 'x-visible': false,
|
|
|
+ 'x-reactions': {
|
|
|
+ dependencies: ['...type'],
|
|
|
+ fulfill: {
|
|
|
+ state: {
|
|
|
+ visible: '{{$deps[0]==="sms"}}',
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ email: {
|
|
|
+ type: 'void',
|
|
|
+ properties: {
|
|
|
+ subject: {
|
|
|
+ type: 'string',
|
|
|
+ title: '标题',
|
|
|
+ 'x-component': 'Input',
|
|
|
+ 'x-decorator': 'FormItem',
|
|
|
+ },
|
|
|
+ sendTo: {
|
|
|
+ type: 'string',
|
|
|
+ title: '收件人',
|
|
|
+ 'x-component': 'Input.TextArea',
|
|
|
+ 'x-decorator': 'FormItem',
|
|
|
+ 'x-component-props': {
|
|
|
+ placeholder: '多个收件人以 , 分隔',
|
|
|
+ },
|
|
|
+ },
|
|
|
+ attachments: {
|
|
|
+ type: 'string',
|
|
|
+ title: '附件',
|
|
|
+ 'x-component': 'FUpload',
|
|
|
+ 'x-decorator': 'FormItem',
|
|
|
+ 'x-component-props': {
|
|
|
+ type: 'file',
|
|
|
+ },
|
|
|
+ },
|
|
|
+ emailEditor: {
|
|
|
+ type: 'string',
|
|
|
+ title: '正文',
|
|
|
+ 'x-component': 'FBraftEditor',
|
|
|
+ 'x-decorator': 'FormItem',
|
|
|
+ 'x-component-props': {
|
|
|
+ style: {
|
|
|
+ height: '300px',
|
|
|
+ },
|
|
|
+ contentStyle: {
|
|
|
+ height: '200px',
|
|
|
+ // overflowY: 'auto',
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ 'x-visible': false,
|
|
|
+ 'x-reactions': {
|
|
|
+ dependencies: ['...type'],
|
|
|
+ fulfill: {
|
|
|
+ state: {
|
|
|
+ visible: '{{$deps[0]==="email"}}',
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ weixin: {
|
|
|
+ type: 'void',
|
|
|
+ properties: {
|
|
|
+ agentId: {
|
|
|
+ type: 'string',
|
|
|
+ title: '应用ID',
|
|
|
+ 'x-component': 'Input',
|
|
|
+ 'x-decorator': 'FormItem',
|
|
|
+ },
|
|
|
+ toUser: {
|
|
|
+ type: 'string',
|
|
|
+ title: '收信人ID',
|
|
|
+ 'x-component': 'Input',
|
|
|
+ 'x-decorator': 'FormItem',
|
|
|
+ },
|
|
|
+ toParty: {
|
|
|
+ type: 'string',
|
|
|
+ title: '收信部门ID',
|
|
|
+ 'x-component': 'Input',
|
|
|
+ 'x-decorator': 'FormItem',
|
|
|
+ },
|
|
|
+ toTag: {
|
|
|
+ type: 'string',
|
|
|
+ title: '按标签推送',
|
|
|
+ 'x-component': 'Input',
|
|
|
+ 'x-decorator': 'FormItem',
|
|
|
+ },
|
|
|
+ message: {
|
|
|
+ type: 'string',
|
|
|
+ title: '内容',
|
|
|
+ 'x-component': 'Input.TextArea',
|
|
|
+ 'x-decorator': 'FormItem',
|
|
|
+ },
|
|
|
+ },
|
|
|
+ 'x-visible': false,
|
|
|
+ 'x-reactions': {
|
|
|
+ dependencies: ['...type'],
|
|
|
+ fulfill: {
|
|
|
+ state: {
|
|
|
+ visible: '{{$deps[0]==="weixin"}}',
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ dingTalk: {
|
|
|
+ type: 'void',
|
|
|
+ properties: {
|
|
|
+ dingTalkRobotWebHook: {
|
|
|
+ type: 'void',
|
|
|
+ properties: {
|
|
|
+ messageType: {
|
|
|
+ title: '消息类型',
|
|
|
+ type: 'string',
|
|
|
+ 'x-component': 'Select',
|
|
|
+ 'x-decorator': 'FormItem',
|
|
|
+ enum: ['text', 'markdown', 'link'],
|
|
|
+ },
|
|
|
+ text: {
|
|
|
+ type: 'object',
|
|
|
+ properties: {
|
|
|
+ content: {
|
|
|
+ title: '通知内容',
|
|
|
+ type: 'string',
|
|
|
+ 'x-decorator': 'FormItem',
|
|
|
+ 'x-component': 'Input.TextArea',
|
|
|
+ },
|
|
|
+ },
|
|
|
+ 'x-visible': false,
|
|
|
+ 'x-reactions': {
|
|
|
+ dependencies: ['.messageType'],
|
|
|
+ fulfill: {
|
|
|
+ state: {
|
|
|
+ visible: '{{$deps[0]==="text"}}',
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ markdown: {
|
|
|
+ type: 'object',
|
|
|
+ properties: {
|
|
|
+ title: {
|
|
|
+ title: '标题',
|
|
|
+ type: 'string',
|
|
|
+ 'x-decorator': 'FormItem',
|
|
|
+ 'x-component': 'Input',
|
|
|
+ },
|
|
|
+ text: {
|
|
|
+ title: '内容',
|
|
|
+ type: 'string',
|
|
|
+ 'x-decorator': 'FormItem',
|
|
|
+ 'x-component': 'Input.TextArea',
|
|
|
+ },
|
|
|
+ },
|
|
|
+ 'x-visible': false,
|
|
|
+ 'x-reactions': {
|
|
|
+ dependencies: ['.messageType'],
|
|
|
+ fulfill: {
|
|
|
+ state: {
|
|
|
+ visible: '{{$deps[0]==="markdown"}}',
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ link: {
|
|
|
+ type: 'object',
|
|
|
+ properties: {
|
|
|
+ title: {
|
|
|
+ title: '标题',
|
|
|
+ type: 'string',
|
|
|
+ 'x-decorator': 'FormItem',
|
|
|
+ 'x-component': 'Input',
|
|
|
+ },
|
|
|
+ text: {
|
|
|
+ title: '内容',
|
|
|
+ type: 'string',
|
|
|
+ 'x-decorator': 'FormItem',
|
|
|
+ 'x-component': 'Input.TextArea',
|
|
|
+ },
|
|
|
+ picUrl: {
|
|
|
+ title: '图片连接',
|
|
|
+ 'x-decorator': 'FormItem',
|
|
|
+ 'x-component': 'FUpload',
|
|
|
+ },
|
|
|
+ messageUrl: {
|
|
|
+ title: '内容连接',
|
|
|
+ 'x-decorator': 'FormItem',
|
|
|
+ 'x-component': 'Input.TextArea',
|
|
|
+ },
|
|
|
+ },
|
|
|
+ 'x-visible': false,
|
|
|
+ 'x-reactions': {
|
|
|
+ dependencies: ['.messageType'],
|
|
|
+ fulfill: {
|
|
|
+ state: {
|
|
|
+ visible: '{{$deps[0]==="link"}}',
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ 'x-visible': false,
|
|
|
+ 'x-reactions': {
|
|
|
+ dependencies: ['...provider'],
|
|
|
+ fulfill: {
|
|
|
+ state: {
|
|
|
+ visible: '{{$deps[0]==="dingTalkRobotWebHook"}}',
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ dingTalkMessage: {
|
|
|
+ type: 'void',
|
|
|
+ properties: {
|
|
|
+ agentId: {
|
|
|
+ type: 'string',
|
|
|
+ title: '应用ID',
|
|
|
+ 'x-component': 'Input',
|
|
|
+ 'x-decorator': 'FormItem',
|
|
|
+ },
|
|
|
+ userIdList: {
|
|
|
+ type: 'string',
|
|
|
+ title: '收信人ID',
|
|
|
+ 'x-component': 'Input',
|
|
|
+ 'x-decorator': 'FormItem',
|
|
|
+ },
|
|
|
+ departmentIdList: {
|
|
|
+ type: 'string',
|
|
|
+ title: '收信部门ID',
|
|
|
+ 'x-component': 'Input',
|
|
|
+ 'x-decorator': 'FormItem',
|
|
|
+ },
|
|
|
+ toAllUser: {
|
|
|
+ type: 'string',
|
|
|
+ title: '全部用户',
|
|
|
+ 'x-component': 'Select',
|
|
|
+ 'x-decorator': 'FormItem',
|
|
|
+ enum: [
|
|
|
+ { label: '是', value: true },
|
|
|
+ { label: '否', value: false },
|
|
|
+ ],
|
|
|
+ },
|
|
|
+ message: {
|
|
|
+ type: 'string',
|
|
|
+ title: '内容',
|
|
|
+ 'x-component': 'Input.TextArea',
|
|
|
+ 'x-decorator': 'FormItem',
|
|
|
+ },
|
|
|
+ },
|
|
|
+ 'x-visible': false,
|
|
|
+ 'x-reactions': {
|
|
|
+ dependencies: ['...provider'],
|
|
|
+ fulfill: {
|
|
|
+ state: {
|
|
|
+ visible: '{{$deps[0]==="dingTalkMessage"}}',
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ 'x-visible': false,
|
|
|
+ 'x-reactions': {
|
|
|
+ dependencies: ['...type'],
|
|
|
+ fulfill: {
|
|
|
+ state: {
|
|
|
+ visible: '{{$deps[0]==="dingTalk"}}',
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ network: {
|
|
|
+ type: 'void',
|
|
|
+ properties: {
|
|
|
+ text: {
|
|
|
+ type: 'string',
|
|
|
+ title: '消息',
|
|
|
+ 'x-component': 'Input.TextArea',
|
|
|
+ 'x-decorator': 'FormItem',
|
|
|
+ 'x-component-props': {
|
|
|
+ rows: 5,
|
|
|
+ },
|
|
|
+ 'x-reactions': '{{handleNetwork}}',
|
|
|
+ },
|
|
|
+ },
|
|
|
+ 'x-visible': false,
|
|
|
+ 'x-reactions': {
|
|
|
+ dependencies: ['...type'],
|
|
|
+ fulfill: {
|
|
|
+ state: {
|
|
|
+ visible: '{{$deps[0]==="network"}}',
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ };
|
|
|
return (
|
|
|
<PageContainer>
|
|
|
<BaseCrud
|
|
|
@@ -102,7 +599,12 @@ const Template = () => {
|
|
|
id: 'pages.notice.template',
|
|
|
defaultMessage: '通知模版',
|
|
|
})}
|
|
|
+ modelConfig={{
|
|
|
+ width: '50vw',
|
|
|
+ }}
|
|
|
+ formEffect={formEvent}
|
|
|
schema={schema}
|
|
|
+ schemaConfig={{ scope: { useAsyncDataSource, getTypes, handleNetwork } }}
|
|
|
actionRef={actionRef}
|
|
|
/>
|
|
|
</PageContainer>
|