| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302 |
- import {
- ArrayItems,
- ArrayTable,
- Editable,
- Form,
- FormButtonGroup,
- FormGrid,
- FormItem,
- Input,
- NumberPicker,
- PreviewText,
- Radio,
- Select,
- Space,
- Switch,
- } from '@formily/antd';
- import type { Field } from '@formily/core';
- import {
- createForm,
- FormPath,
- onFieldInit,
- onFieldReact,
- onFieldValueChange,
- registerValidateRules,
- } from '@formily/core';
- import { createSchemaField, observer } from '@formily/react';
- import type { ISchema } from '@formily/json-schema';
- import styles from './index.less';
- import { useEffect, useMemo, useRef, useState } from 'react';
- import FUpload from '@/components/Upload';
- import { useParams } from 'umi';
- import { PageContainer } from '@ant-design/pro-layout';
- import { Card, Col, message, Row } from 'antd';
- import { typeList } from '@/pages/notice';
- import { configService, service, state } from '@/pages/notice/Template';
- import FBraftEditor from '@/components/FBraftEditor';
- import { useAsyncDataSource } from '@/utils/util';
- import WeixinCorp from '@/pages/notice/Template/Detail/doc/WeixinCorp';
- import WeixinApp from '@/pages/notice/Template/Detail/doc/WeixinApp';
- import DingTalk from '@/pages/notice/Template/Detail/doc/DingTalk';
- import DingTalkRebot from '@/pages/notice/Template/Detail/doc/DingTalkRebot';
- import AliyunVoice from '@/pages/notice/Template/Detail/doc/AliyunVoice';
- import AliyunSms from '@/pages/notice/Template/Detail/doc/AliyunSms';
- import Email from '@/pages/notice/Template/Detail/doc/Email';
- import { Store } from 'jetlinks-store';
- import FAutoComplete from '@/components/FAutoComplete';
- import { PermissionButton } from '@/components';
- import usePermissions from '@/hooks/permission';
- export const docMap = {
- weixin: {
- corpMessage: <WeixinCorp />,
- officialMessage: <WeixinApp />,
- },
- dingTalk: {
- dingTalkMessage: <DingTalk />,
- dingTalkRobotWebHook: <DingTalkRebot />,
- },
- voice: {
- aliyun: <AliyunVoice />,
- },
- sms: {
- aliyunSms: <AliyunSms />,
- },
- email: {
- embedded: <Email />,
- },
- };
- const Detail = observer(() => {
- const { id } = useParams<{ id: string }>();
- const [provider, setProvider] = useState<string>('embedded');
- // 正则提取${}里面的值
- const pattern = /(?<=\$\{).*?(?=\})/g;
- // 提取微信服务号里面的值 {{}}
- const weixinPattern = /(?<=\{\{).*?(?=\.DATA}})/g;
- const getConfig = (provider1: string) =>
- configService
- .queryNoPagingPost({
- terms: [
- { column: 'type$IN', value: id },
- { column: 'provider', value: provider1 },
- ],
- })
- .then((resp: any) => {
- return resp.result?.map((item: any) => ({
- label: item.name,
- value: item.id,
- }));
- });
- //需要复杂联动才可以完成
- const getWeixinDept = (configId: string) => service.weixin.getDepartments(configId);
- const getWeixinTags = (configId: string) => service.weixin.getTags(configId);
- const getWeixinUser = (configId: string) => service.weixin.getUser(configId);
- const getDingTalkDept = (configId: string) => service.dingTalk.getDepartments(configId);
- const getDingTalkDeptTree = (configId: string) => service.dingTalk.getDepartmentsTree(configId);
- const getDingTalkUser = (configId: string) => service.dingTalk.getUser(configId);
- const getWeixinOfficialTags = (configId: string) => service.weixin.getOfficialTags(configId);
- const getWeixinOfficialTemplates = (configId: string) =>
- service.weixin.getOfficialTemplates(configId);
- const getAliyunSigns = (configId: string) => service.aliyun.getSigns(configId);
- const getAliyunTemplates = (configId: string) => service.aliyun.getTemplates(configId);
- const variableDefinitionsRef =
- useRef<{ id: string; name: string; type: string; format: string }[]>();
- const form = useMemo(
- () =>
- createForm({
- validateFirst: true,
- effects() {
- onFieldInit('template.message', (field) => {
- if (id === 'email') {
- field.setComponent(FBraftEditor, {
- placeholder:
- '变量格式:${name};\n 示例:尊敬的${name},${time}有设备触发告警,请注意处理',
- height: '100px',
- });
- }
- const _provider = field.query('provider').value();
- if (_provider === 'corpMessage') {
- field.componentProps = {
- disabled: true,
- rows: 5,
- placeholder:
- '变量格式:${name};\n 示例:尊敬的${name},${time}有设备触发告警,请注意处理',
- };
- }
- });
- onFieldValueChange('provider', (field, form1) => {
- const value = field.value;
- setProvider(value);
- if (field.modified) {
- form1.setValuesIn('configId', null);
- form1.setValuesIn('template', null);
- }
- // 设置绑定配置的数据
- form1.setFieldState('configId', async (state1) => {
- state1.dataSource = await getConfig(value);
- });
- if (value === 'officialMessage') {
- form1.setFieldState('template.message', (state5) => {
- state5.decoratorProps = {
- tooltip: '服务号模版消息内容',
- };
- });
- }
- });
- onFieldValueChange('configId', (field, form1) => {
- const value = field.value;
- // 判断provider
- if (!value) return;
- switch (form1.values.provider) {
- case 'corpMessage':
- form1.setFieldState('template.toUser', async (state8) => {
- state8.dataSource = await getWeixinUser(value);
- });
- form1.setFieldState('template.toParty', async (state9) => {
- state9.dataSource = await getWeixinDept(value);
- });
- form1.setFieldState('template.toTag', async (state10) => {
- state10.dataSource = await getWeixinTags(value);
- });
- break;
- case 'officialMessage':
- form1.setFieldState('template.tagid', async (state1) => {
- state1.dataSource = await getWeixinOfficialTags(value);
- });
- form1.setFieldState('template.wxTemplateId', async (state2) => {
- const list = await getWeixinOfficialTemplates(value);
- Store.set('wxTemplate', list);
- state2.dataSource = list;
- });
- break;
- case 'dingTalkMessage':
- form1.setFieldState('template.userIdList', async (state3) => {
- state3.dataSource = await getDingTalkUser(value);
- });
- form1.setFieldState('template.departmentIdList', async (state4) => {
- const list = await getDingTalkDept(value);
- Store.set('wxTemplate', list);
- state4.dataSource = list;
- });
- break;
- case 'aliyun':
- // 阿里云语音
- form1.setFieldState('template.ttsCode', async (state5) => {
- const list = await getAliyunTemplates(value);
- Store.set('AliyunTemplate', list);
- state5.dataSource = list;
- });
- break;
- case 'aliyunSms':
- // 阿里云短信
- form1.setFieldState('template.code', async (state6) => {
- const list = await getAliyunTemplates(value);
- Store.set('AliyunTemplate', list);
- state6.dataSource = list;
- });
- form1.setFieldState('template.signName', async (state7) => {
- // const list =
- // Store.set('AliyunTemplate', list);
- state7.dataSource = await getAliyunSigns(value);
- });
- break;
- default:
- break;
- }
- });
- onFieldValueChange('template.wxTemplateId', (field, form1) => {
- const value = field.value;
- // 处理消息模版。
- const template = Store.get('wxTemplate');
- const data = template?.find((i: { id: any }) => i.id === value);
- if (data) {
- form1.setFieldState('template.title', (state1) => {
- state1.value = data.title;
- state1.disabled = true;
- });
- form1.setFieldState('template.message', (state1) => {
- state1.value = data.content;
- state1.disabled = true;
- });
- }
- });
- onFieldValueChange('template.code', (field, form1) => {
- const value = field.value;
- const template = Store.get('AliyunTemplate');
- const data = template?.find((i: { templateCode: any }) => i.templateCode === value);
- if (data) {
- form1.setFieldState('template.message', (state1) => {
- state1.value = data.templateContent;
- state1.disabled = true;
- });
- }
- });
- onFieldValueChange('template.*(subject,markdown.title)', (field, form1) => {
- const value = (field as Field).value;
- const _message = field.query('template.message').value();
- const titleList =
- (typeof value === 'string' &&
- (value + _message)?.match(pattern)?.filter((i: string) => i)) ||
- // .map((item: string) => ({id: item, type: 'string', format: '--'}))) ||
- [];
- // 拼接message的内容
- form1.setFieldState('variableDefinitions', (state1) => {
- state1.visible = !!titleList && titleList.length > 0;
- });
- if (form1.modified) {
- const oldKey = variableDefinitionsRef.current?.map((i) => i.id);
- const newKey = [...new Set(titleList)];
- const _result = newKey.map((item) =>
- oldKey?.includes(item)
- ? variableDefinitionsRef.current?.find((i) => i.id === item)
- : {
- id: item,
- type: 'string',
- format: '%s',
- },
- );
- form1.setValuesIn('variableDefinitions', _result);
- }
- });
- onFieldValueChange('template.message', (field, form1) => {
- const _provider = field.query('provider').value();
- const value = (field as Field).value;
- const idList =
- (typeof value === 'string' &&
- value
- ?.match(_provider === 'officialMessage' ? weixinPattern : pattern)
- ?.filter((i: string) => i)) ||
- [];
- if (id === 'email') {
- const subject = field.query('template.subject');
- const title = subject.value();
- const titleList = title?.match(pattern)?.filter((i: string) => i);
- // .map((item: string) => ({id: item, type: 'string', format: '--'}));
- if (idList && titleList?.length > 0) {
- idList.unshift(...titleList);
- }
- }
- if (_provider === 'dingTalkRobotWebHook') {
- const title = field.query('template.markdown.title').value();
- const titleList = title?.match(pattern)?.filter((i: string) => i);
- // .map((item: string) => ({id: item, type: 'string', format: '--'}));
- if (idList && titleList?.length > 0) {
- idList.unshift(...titleList);
- }
- }
- form1.setFieldState('variableDefinitions', (state1) => {
- state1.visible = !!idList && idList.length > 0;
- });
- if (form1.modified) {
- // 获取缓存的KEY;
- const oldKey = variableDefinitionsRef.current?.map((i) => i.id);
- const newKey = [...new Set(idList)];
- const _result = newKey.map((item) =>
- oldKey?.includes(item)
- ? variableDefinitionsRef.current?.find((i) => i.id === item)
- : {
- id: item,
- type: 'string',
- format: '%s',
- },
- );
- form1.setValuesIn('variableDefinitions', _result);
- }
- });
- onFieldValueChange('variableDefinitions.*.*', (field) => {
- // 缓存编辑后的数据
- variableDefinitionsRef.current = field.query('variableDefinitions').value();
- });
- onFieldReact('variableDefinitions.*.type', (field) => {
- const value = (field as Field).value;
- const formatPath = FormPath.transform(
- field.path,
- /\d+/,
- (index) => `variableDefinitions.${parseInt(index)}.format`,
- );
- const format = field.query(formatPath).take() as any;
- const fieldModified = field && (field as Field).modified;
- if (!format) return;
- if (fieldModified) {
- format.setValue(undefined);
- }
- switch (value) {
- case 'date':
- format.setComponent(FAutoComplete);
- format.setDataSource([
- { label: 'timestamp', value: 'timestamp' },
- { label: 'yyyy-MM-dd', value: 'yyyy-MM-dd' },
- { label: 'yyyy-MM-dd HH:mm:ss', value: 'yyyy-MM-dd HH:mm:ss' },
- { label: 'yyyy-MM-dd HH:mm:ss EE', value: 'yyyy-MM-dd HH:mm:ss EE' },
- { label: 'yyyy-MM-dd HH:mm:ss zzz', value: 'yyyy-MM-dd HH:mm:ss zzz' },
- ]);
- if (fieldModified) {
- format.setValue('timestamp');
- }
- break;
- case 'string':
- format.setComponent(PreviewText.Input);
- if (fieldModified) {
- format.setValue('%s');
- }
- break;
- case 'number':
- format.setComponent(Input);
- if (fieldModified) {
- format.setValue('%.xf');
- }
- break;
- // case 'file':
- // format.setComponent(Select);
- // format.setDataSource([
- // {label: '视频', value: 'video'},
- // {label: '图片', value: 'img'},
- // {label: '全部', value: 'any'},
- // ]);
- // format.setValue('any');
- // break;
- // case 'other':
- // format.setComponent(PreviewText.Input);
- // format.setValue('--');
- // break;
- }
- });
- },
- }),
- [id],
- );
- useEffect(() => {
- if (state.current) {
- form.setValues(state.current);
- }
- }, []);
- const SchemaField = createSchemaField({
- components: {
- FormItem,
- Input,
- Select,
- Switch,
- Radio,
- Editable,
- PreviewText,
- Space,
- FUpload,
- NumberPicker,
- FBraftEditor,
- ArrayItems,
- FormGrid,
- ArrayTable,
- FAutoComplete,
- },
- });
- const handleSave = async () => {
- const data: TemplateItem = await form.submit();
- // dingTalkRobotWebHook
- // 提交的时候处理内容
- // 钉钉机器人-->dingTalkRobotWebHook
- // r如果是text 的话。template.message=>template.text.content
- // 如果是markdown 的话。 template.message=>template.markdown.text
- // 如果是link的话。 template.message =>template.markdown.text
- // 微信服务号: template.message =>template.content
- if (data.provider === 'dingTalkRobotWebHook') {
- const type = data.template.messageType;
- // emplate.messageType
- switch (type) {
- case 'text':
- data.template.text = {
- content: data.template.message,
- };
- // data.template.text.content = data.template.message;
- break;
- case 'markdown':
- data.template.markdown.text = data.template.message;
- break;
- case 'link':
- data.template.link.text = data.template.message;
- }
- }
- if (id === 'email') {
- data.provider = 'embedded';
- data.template.text = data.template.message;
- }
- let response;
- if (data.id) {
- response = await service.update(data);
- } else {
- response = await service.save(data);
- }
- if (response?.status === 200) {
- message.success('保存成功');
- history.back();
- }
- };
- registerValidateRules({
- batchCheckEmail(value) {
- const regEmail = /^([a-zA-Z]|[0-9])(\w|\-)+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/;
- let error;
- value.some((item: string) => {
- if (!regEmail.test(item)) {
- error = item;
- return true;
- }
- return false;
- });
- return error ? `${error}邮件格式错误` : '';
- },
- });
- const schema: ISchema = {
- type: 'object',
- properties: {
- name: {
- title: '名称',
- type: 'string',
- 'x-decorator': 'FormItem',
- 'x-component': 'Input',
- 'x-component-props': {
- placeholder: '请输入名称',
- },
- name: 'name',
- 'x-validator': [
- {
- max: 64,
- message: '最多可输入64个字符',
- },
- {
- required: true,
- message: '请输入名称',
- },
- ],
- },
- type: {
- title: '类型',
- 'x-value': id,
- 'x-hidden': true,
- },
- provider: {
- title: '类型',
- type: 'string',
- 'x-decorator': 'FormItem',
- 'x-component': 'Radio.Group',
- 'x-component-props': {
- optionType: 'button',
- placeholder: '请选择类型',
- },
- required: true,
- 'x-visible': typeList[id]?.length > 0,
- 'x-hidden': id === 'email',
- 'x-value': typeList[id][0]?.value,
- enum: typeList[id] || [],
- },
- configId: {
- title: '绑定配置',
- type: 'string',
- 'x-decorator': 'FormItem',
- 'x-component': 'Select',
- 'x-component-props': {
- placeholder: '请选择绑定配置',
- },
- required: true,
- 'x-decorator-props': {
- tooltip: '使用固定的通知配置来发送此通知模版',
- },
- 'x-visible': id !== 'email',
- },
- template: {
- type: 'object',
- properties: {
- weixin: {
- type: 'void',
- 'x-visible': id === 'weixin',
- properties: {
- corpMessage: {
- type: 'void',
- properties: {
- agentId: {
- title: 'AgentId',
- 'x-component': 'Input',
- 'x-decorator': 'FormItem',
- 'x-decorator-props': {
- tooltip: '应用唯一标识',
- },
- required: true,
- 'x-component-props': {
- placeholder: '请输入AgentID',
- },
- },
- layout: {
- type: 'void',
- 'x-decorator': 'FormGrid',
- 'x-decorator-props': {
- maxColumns: 2,
- minColumns: 2,
- },
- properties: {
- toUser: {
- title: '收信人',
- 'x-component': 'Select',
- 'x-decorator': 'FormItem',
- 'x-decorator-props': {
- tooltip: '如果不填写该字段,将在使用此模版发送通知时进行指定。',
- gridSpan: 1,
- },
- 'x-component-props': {
- placeholder: '请选择收信人',
- },
- },
- toParty: {
- title: '收信部门',
- 'x-component': 'Select',
- 'x-decorator': 'FormItem',
- 'x-decorator-props': {
- tooltip: '如果不填写该字段,将在使用此模版发送通知时进行指定。',
- gridSpan: 1,
- },
- 'x-component-props': {
- placeholder: '请选择收信部门',
- },
- },
- },
- },
- toTag: {
- title: '标签推送',
- 'x-component': 'Select',
- 'x-decorator': 'FormItem',
- 'x-decorator-props': {
- tooltip:
- '本企业微信的标签ID列表,最多支持100个,如果不填写该字段,将在使用此模版发送通知时进行指定',
- },
- 'x-component-props': {
- placeholder: '请输入标签推送,多个标签用,号分隔',
- },
- },
- },
- 'x-reactions': {
- dependencies: ['provider'],
- fulfill: {
- state: {
- visible: '{{$deps[0]==="corpMessage"}}',
- },
- },
- },
- },
- officialMessage: {
- type: 'void',
- properties: {
- tagid: {
- title: '用户标签',
- type: 'string',
- 'x-decorator': 'FormItem',
- 'x-component': 'Select',
- 'x-component-props': {
- placeholder: '请选择用户标签',
- },
- 'x-decorator-props': {
- tooltip: '如果不填写该字段,将在使用此模板发送通知时进行指定',
- },
- },
- layout: {
- type: 'void',
- 'x-decorator': 'FormGrid',
- 'x-decorator-props': {
- maxColumns: 2,
- minColumns: 2,
- },
- properties: {
- wxTemplateId: {
- title: '消息模版',
- type: 'string',
- 'x-decorator': 'FormItem',
- 'x-component': 'Select',
- 'x-component-props': {
- placeholder: '请选择消息模版',
- },
- required: true,
- 'x-decorator-props': {
- gridSpan: 1,
- tooltip: '微信公众号中配置的消息模版',
- },
- },
- url: {
- title: '模版跳转链接',
- type: 'string',
- 'x-decorator': 'FormItem',
- 'x-component': 'Input',
- 'x-component-props': {
- placeholder: '请输入模版跳转链接',
- },
- 'x-decorator-props': {
- gridSpan: 1,
- tooltip: '用于点击消息后进行页面跳转',
- },
- },
- },
- },
- toMiniProgram: {
- title: '跳转小程序',
- type: 'string',
- 'x-decorator': 'FormItem',
- 'x-component': 'Radio.Group',
- 'x-component-props': {
- // optionType: 'button'
- },
- 'x-decorator-props': {
- tooltip: '配置后点击通知消息将跳转到对应小程序',
- },
- default: false,
- enum: [
- { label: '是', value: true },
- { label: '否', value: false },
- ],
- },
- miniProgram: {
- type: 'void',
- properties: {
- layout: {
- type: 'void',
- 'x-decorator': 'FormGrid',
- 'x-decorator-props': {
- maxColumns: 2,
- minColumns: 2,
- },
- properties: {
- miniProgramId: {
- title: '跳转小程序AppId',
- type: 'string',
- 'x-decorator': 'FormItem',
- 'x-component': 'Input',
- 'x-component-props': {
- placeholder: '请输入跳转小程序AppId',
- },
- 'x-decorator-props': {
- gridSpan: 1,
- tooltip: '小程序唯一性id',
- },
- },
- miniProgramPath: {
- title: '跳转小程序具体路径',
- type: 'string',
- 'x-decorator': 'FormItem',
- 'x-component': 'Input',
- 'x-component-props': {
- placeholder: '请输入跳转小程序具体路径',
- },
- 'x-decorator-props': {
- gridSpan: 1,
- tooltip: '用于点击消息之后跳转到小程序的具体页面',
- },
- },
- },
- },
- },
- 'x-reactions': {
- dependencies: ['.toMiniProgram'],
- fulfill: {
- state: {
- visible: '{{$deps[0]===true}}',
- },
- },
- },
- },
- title: {
- title: '模版标题',
- type: 'string',
- 'x-decorator': 'FormItem',
- 'x-component': 'Input',
- 'x-component-props': {
- placeholder: '这里是回显内容',
- },
- 'x-decorator-props': {
- tooltip: '服务号消息模版标题',
- },
- 'x-disabled': true,
- },
- },
- 'x-reactions': {
- dependencies: ['provider'],
- fulfill: {
- state: {
- visible: '{{$deps[0]==="officialMessage"}}',
- },
- },
- },
- },
- },
- },
- dingTalk: {
- type: 'void',
- 'x-visible': id === 'dingTalk',
- properties: {
- dingTalkMessage: {
- type: 'void',
- properties: {
- agentId: {
- title: 'AgentID',
- required: true,
- 'x-component': 'Input',
- 'x-decorator': 'FormItem',
- 'x-decorator-props': {
- tooltip: '应用唯一标识',
- },
- 'x-component-props': {
- placeholder: '请输入AgentID',
- },
- },
- layout: {
- type: 'void',
- 'x-decorator': 'FormGrid',
- 'x-decorator-props': {
- maxColumns: 2,
- minColumns: 2,
- },
- properties: {
- userIdList: {
- title: '收信人',
- 'x-component': 'Select',
- 'x-decorator': 'FormItem',
- 'x-decorator-props': {
- tooltip: '如果不填写该字段,将在使用此模板发送通知时进行指定',
- gridSpan: 1,
- },
- 'x-component-props': {
- placeholder: '请选择收信人',
- },
- // 'x-reactions': {
- // dependencies: ['configId'],
- // fulfill: {
- // run: '{{useAsyncDataSource(getDingTalkUser($deps[0]))}}',
- // },
- // },
- },
- departmentIdList: {
- title: '收信部门',
- 'x-component': 'Select',
- 'x-decorator': 'FormItem',
- 'x-decorator-props': {
- tooltip: '如果不填写该字段,将在使用此模板发送通知时进行指定',
- gridSpan: 1,
- },
- 'x-component-props': {
- placeholder: '请选择收信部门',
- },
- // 'x-reactions': {
- // dependencies: ['configId'],
- // fulfill: {
- // run: '{{useAsyncDataSource(getDingTalkDept($deps[0]))}}',
- // },
- // },
- },
- },
- },
- },
- 'x-reactions': {
- dependencies: ['provider'],
- fulfill: {
- state: {
- visible: '{{$deps[0]==="dingTalkMessage"}}',
- },
- },
- },
- },
- dingTalkRobotWebHook: {
- type: 'void',
- properties: {
- messageType: {
- title: '消息类型',
- 'x-component': 'Select',
- 'x-decorator': 'FormItem',
- required: true,
- 'x-component-props': {
- placeholder: '请选择消息类型',
- },
- enum: [
- { label: 'markdown', value: 'markdown' },
- { label: 'text', value: 'text' },
- { label: 'link', value: 'link' },
- ],
- },
- markdown: {
- type: 'object',
- properties: {
- title: {
- required: true,
- title: '标题',
- 'x-component': 'Input',
- 'x-decorator': 'FormItem',
- 'x-component-props': {
- placeholder: '请输入标题',
- },
- },
- },
- 'x-reactions': {
- dependencies: ['.messageType'],
- fulfill: {
- state: {
- visible: '{{$deps[0]==="markdown"}}',
- },
- },
- },
- },
- link: {
- type: 'object',
- properties: {
- title: {
- required: true,
- title: '标题',
- 'x-component': 'Input',
- 'x-decorator': 'FormItem',
- 'x-component-props': {
- placeholder: '请输入标题',
- },
- },
- '{url:picUrl}': {
- title: '图片链接',
- 'x-component': 'FUpload',
- 'x-decorator': 'FormItem',
- 'x-component-props': {
- type: 'file',
- placeholder: '请输入图片链接',
- },
- },
- messageUrl: {
- title: '内容链接',
- 'x-component': 'Input',
- 'x-decorator': 'FormItem',
- 'x-component-props': {
- placeholder: '请输入内容链接',
- },
- },
- },
- 'x-reactions': {
- dependencies: ['.messageType'],
- fulfill: {
- state: {
- visible: '{{$deps[0]==="link"}}',
- },
- },
- },
- },
- },
- 'x-reactions': {
- dependencies: ['provider'],
- fulfill: {
- state: {
- visible: '{{$deps[0]==="dingTalkRobotWebHook"}}',
- },
- },
- },
- },
- },
- // 钉钉群机器人配置参数名 类型 说明
- // messageType String 钉钉-消息类型 markdown、text、link
- // ${messageType} String 钉钉-内容
- },
- aliyun: {
- type: 'void',
- properties: {
- voice: {
- 'x-visible': id === 'voice',
- type: 'void',
- properties: {
- layout: {
- type: 'void',
- 'x-decorator': 'FormGrid',
- 'x-decorator-props': {
- maxColumns: 2,
- minColumns: 2,
- },
- properties: {
- ttsCode: {
- title: '模版ID',
- 'x-component': 'Select',
- 'x-decorator': 'FormItem',
- 'x-decorator-props': {
- tooltip: '阿里云内部分配的唯一ID标识',
- gridSpan: 1,
- },
- required: true,
- 'x-component-props': {
- placeholder: '请输入模版ID',
- },
- },
- calledShowNumbers: {
- title: '被叫号码',
- 'x-component': 'Input',
- 'x-decorator': 'FormItem',
- 'x-decorator-props': {
- tooltip: '仅支持中国大陆号码',
- gridSpan: 1,
- },
- 'x-component-props': {
- placeholder: '请输入被叫号码',
- },
- },
- },
- },
- calledNumber: {
- title: '被叫显号',
- 'x-component': 'Input',
- 'x-decorator': 'FormItem',
- 'x-decorator-props': {
- tooltip: '必须是已购买的号码,用于呼叫号码显示',
- },
- 'x-component-props': {
- placeholder: '请输入被叫显号',
- },
- },
- PlayTimes: {
- title: '播放次数',
- 'x-component': 'NumberPicker',
- 'x-decorator': 'FormItem',
- 'x-decorator-props': {
- tooltip: '语音文件的播放次数',
- },
- default: 1,
- 'x-validator': [
- {
- min: 1,
- max: 3,
- message: '仅支持1~3次',
- },
- ],
- 'x-component-props': {
- placeholder: '请输入播放次数',
- },
- },
- },
- },
- sms: {
- 'x-visible': id === 'sms',
- type: 'void',
- properties: {
- layout: {
- type: 'void',
- 'x-decorator': 'FormGrid',
- 'x-decorator-props': {
- maxColumns: 2,
- minColumns: 2,
- },
- properties: {
- code: {
- title: '模版',
- 'x-component': 'Select',
- 'x-decorator': 'FormItem',
- 'x-decorator-props': {
- tooltip: '阿里云短信平台自定义的模版名称',
- gridSpan: 1,
- },
- 'x-component-props': {
- placeholder: '请选择模版',
- },
- 'x-reactions': {
- dependencies: ['configId'],
- fulfill: {
- run: '{{useAsyncDataSource(getAliyunTemplates($deps[0]))}}',
- },
- },
- },
- phoneNumber: {
- title: '收信人',
- 'x-component': 'Input',
- 'x-decorator': 'FormItem',
- 'x-decorator-props': {
- tooltip: '仅支持中国大陆号码',
- gridSpan: 1,
- },
- 'x-validator': ['phone'],
- 'x-component-props': {
- placeholder: '请输入收信人',
- },
- },
- },
- },
- signName: {
- title: '签名',
- 'x-component': 'Select',
- 'x-decorator': 'FormItem',
- 'x-decorator-props': {
- tooltip: '用于短信内容签名信息显示',
- },
- 'x-component-props': {
- placeholder: '请输入签名',
- },
- 'x-reactions': {
- dependencies: ['configId'],
- fulfill: {
- run: '{{useAsyncDataSource(getAliyunSigns($deps[0]))}}',
- },
- },
- },
- },
- },
- },
- },
- email: {
- type: 'void',
- 'x-visible': id === 'email',
- properties: {
- subject: {
- 'x-component': 'Input',
- 'x-decorator': 'FormItem',
- title: '标题',
- 'x-decorator-props': {
- tooltip: '邮件标题',
- },
- required: true,
- 'x-component-props': {
- placeholder: '请输入标题',
- },
- },
- sendTo: {
- 'x-component': 'Select',
- 'x-decorator': 'FormItem',
- title: '收件人',
- 'x-decorator-props': {
- tooltip: '多个收件人用换行分隔 \n最大支持1000个号码',
- },
- 'x-component-props': {
- mode: 'tags',
- placeholder: '请输入收件人邮箱,多个收件人用换行分隔',
- },
- 'x-validator': {
- batchCheckEmail: true,
- },
- },
- attachments: {
- type: 'array',
- title: '附件信息',
- 'x-decorator': 'FormItem',
- 'x-component': 'ArrayItems',
- 'x-decorator-props': {
- style: {
- width: '100%',
- },
- tooltip: '附件只输入文件名称将在发送邮件时进行文件上传',
- },
- items: {
- type: 'object',
- 'x-decorator': 'FormGrid',
- 'x-decorator-props': {
- maxColumns: 24,
- minColumns: 24,
- },
- properties: {
- '{url:location,name:name}': {
- 'x-component': 'FUpload',
- 'x-decorator': 'FormItem',
- 'x-decorator-props': {
- style: {
- width: '100%',
- },
- gridSpan: 23,
- },
- 'x-component-props': {
- type: 'file',
- display: 'name',
- placeholder: '请上传文件或输入文件名称',
- },
- },
- remove: {
- type: 'void',
- 'x-decorator': 'FormItem',
- 'x-component': 'ArrayItems.Remove',
- 'x-decorator-props': {
- gridSpan: 1,
- },
- },
- },
- },
- properties: {
- add: {
- type: 'void',
- 'x-component': 'ArrayItems.Addition',
- title: '添加附件',
- },
- },
- },
- },
- },
- },
- },
- 'template.message': {
- title: '模版内容',
- 'x-component': 'Input.TextArea',
- 'x-decorator': 'FormItem',
- 'x-decorator-props': {
- tooltip: '发送的内容,支持录入变量',
- },
- required: true,
- 'x-reactions': {
- dependencies: ['provider'],
- fulfill: {
- state: {
- hidden: '{{$deps[0]==="aliyun"}}',
- disabled: '{{["aliyunSms","aliyun"].includes($deps[0])}}',
- },
- },
- },
- 'x-component-props': {
- rows: 5,
- placeholder: '变量格式:${name};\n 示例:尊敬的${name},${time}有设备触发告警,请注意处理',
- },
- },
- variableDefinitions: {
- type: 'array',
- title: '变量列表',
- 'x-decorator': 'FormItem',
- 'x-component': 'ArrayTable',
- 'x-component-props': {
- pagination: { pageSize: 9999 },
- scroll: { x: '100%' },
- },
- 'x-decorator-props': {
- style: {
- zIndex: 999,
- },
- },
- 'x-visible': false,
- 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',
- required: true,
- 'x-component': 'Input',
- },
- },
- },
- column3: {
- type: 'void',
- 'x-component': 'ArrayTable.Column',
- 'x-component-props': { title: '类型', width: '120px' },
- properties: {
- type: {
- type: 'string',
- 'x-decorator': 'FormItem',
- 'x-component': 'Select',
- required: true,
- enum: [
- { label: '字符串', value: 'string' },
- { label: '时间', value: 'date' },
- { label: '数字', value: 'number' },
- ],
- },
- },
- },
- column4: {
- type: 'void',
- 'x-component': 'ArrayTable.Column',
- 'x-component-props': { title: '格式', width: '300px' },
- required: true,
- properties: {
- format: {
- type: 'string',
- 'x-decorator': 'FormItem',
- 'x-component': 'Input',
- },
- },
- },
- },
- },
- },
- description: {
- title: '说明',
- 'x-decorator': 'FormItem',
- 'x-component': 'Input.TextArea',
- 'x-component-props': {
- rows: 4,
- },
- },
- },
- };
- const { permission } = usePermissions('notice');
- return (
- <PageContainer>
- <Card>
- <Row>
- <Col span={10}>
- <Form className={styles.form} form={form} layout={'vertical'}>
- <SchemaField
- schema={schema}
- scope={{
- getConfig,
- getDingTalkDept,
- getDingTalkDeptTree,
- getDingTalkUser,
- getWeixinDept,
- getWeixinTags,
- getWeixinUser,
- getAliyunSigns,
- getAliyunTemplates,
- useAsyncDataSource,
- getWeixinOfficialTags,
- getWeixinOfficialTemplates,
- }}
- />
- <FormButtonGroup.Sticky>
- <FormButtonGroup.FormItem>
- <PermissionButton
- type="primary"
- isPermission={permission.add || permission.update}
- onClick={handleSave}
- >
- 保存
- </PermissionButton>
- </FormButtonGroup.FormItem>
- </FormButtonGroup.Sticky>
- </Form>
- </Col>
- <Col span={12} push={2}>
- {docMap[id][provider]}
- </Col>
- </Row>
- </Card>
- </PageContainer>
- );
- });
- export default Detail;
|