| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574 |
- 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, Row, Tooltip } from 'antd';
- import { typeList } from '@/pages/notice';
- import { configService, service, state } from '@/pages/notice/Template';
- import FBraftEditor from '@/components/FBraftEditor';
- import { onlyMessage, phoneRegEx, 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';
- import FMonacoEditor from '@/components/FMonacoEditor';
- import Webhook from './doc/Webhook';
- import { useModel } from '@@/plugin-model/useModel';
- import { QuestionCircleOutlined } from '@ant-design/icons';
- export const docMap = {
- weixin: {
- corpMessage: <WeixinCorp />,
- officialMessage: <WeixinApp />,
- },
- dingTalk: {
- dingTalkMessage: <DingTalk />,
- dingTalkRobotWebHook: <DingTalkRebot />,
- },
- voice: {
- aliyun: <AliyunVoice />,
- },
- sms: {
- aliyunSms: <AliyunSms />,
- },
- email: {
- embedded: <Email />,
- },
- webhook: {
- http: <Webhook />,
- },
- };
- const Detail = observer(() => {
- const { id } = useParams<{ id: string }>();
- const [provider, setProvider] = useState<string>('embedded');
- const { initialState } = useModel('@@initialState');
- // 正则提取${}里面的值
- 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}有设备触发告警,请注意处理',
- };
- }
- // if (id === 'voice') {
- // const type = field.query('template.*.templateType').value();
- // console.log(type,'111111')
- // field.hidden = false
- // field.disabled = false
- // }
- });
- 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,link.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('template.body', (field, form1) => {
- const value = (field as Field).value;
- console.log(value);
- const idList = value.match(pattern)?.filter((i: string) => i);
- 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: any) =>
- 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 'double':
- format.setComponent(Input);
- if (fieldModified) {
- format.setValue('%.0f');
- }
- 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;
- }
- });
- onFieldValueChange('template.templateType', (field, form1) => {
- const value = (field as Field).value;
- // console.log(value,'11111')
- if (value === 'tts') {
- form1.setFieldState('template.message', (state1) => {
- state1.disabled = false;
- state1.hidden = false;
- });
- }
- });
- },
- }),
- [id],
- );
- useEffect(() => {
- setTimeout(() => {
- if (initialState?.settings?.title) {
- document.title = `通知模板 - ${initialState?.settings?.title}`;
- } else {
- document.title = '通知模板';
- }
- }, 0);
- 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,
- FMonacoEditor,
- },
- });
- 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) {
- onlyMessage('保存成功');
- history.back();
- }
- };
- registerValidateRules({
- batchCheckEmail(value) {
- const regEmail = /^([A-Za-z0-9_\-\.])+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/;
- let error;
- if (value) {
- 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' || id === 'webhook',
- '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',
- },
- 'x-validator': [
- {
- max: 64,
- message: '最多可输入64个字符',
- },
- ],
- },
- 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-validator': [
- {
- max: 64,
- message: '最多可输入64个字符',
- },
- ],
- },
- },
- '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',
- },
- 'x-validator': [
- {
- max: 64,
- message: '最多可输入64个字符',
- },
- ],
- },
- layout: {
- type: 'void',
- 'x-decorator': 'FormGrid',
- 'x-decorator-props': {
- maxColumns: 2,
- minColumns: 2,
- },
- properties: {
- departmentIdList: {
- title: '收信部门',
- // required: true,
- '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]))}}',
- // },
- // },
- },
- 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]))}}',
- // },
- // },
- },
- },
- },
- },
- '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-validator': [
- {
- max: 64,
- message: '最多可输入64个字符',
- },
- ],
- },
- },
- '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: '请输入标题',
- },
- 'x-validator': [
- {
- max: 64,
- message: '最多可输入64个字符',
- },
- ],
- },
- '{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: {
- templateType: {
- title: '类型',
- required: true,
- 'x-component': 'Select',
- 'x-decorator': 'FormItem',
- 'x-decorator-props': {
- tooltip: '语音验证码类型可配置变量,并且只支持数字和英文字母',
- },
- 'x-component-props': {
- placeholder: '请选择类型',
- },
- enum: [
- { label: '语音通知', value: 'voice' },
- { label: '语音验证码', value: 'tts' },
- ],
- },
- layout: {
- type: 'void',
- 'x-decorator': 'FormGrid',
- 'x-decorator-props': {
- maxColumns: 2,
- minColumns: 2,
- },
- properties: {
- templateCode: {
- title: '模版ID',
- 'x-component': 'Input',
- 'x-decorator': 'FormItem',
- 'x-decorator-props': {
- tooltip: '阿里云内部分配的唯一ID标识',
- gridSpan: 1,
- },
- required: true,
- 'x-component-props': {
- placeholder: '请输入模版ID',
- },
- },
- ttsCode: {
- title: '模版ID',
- 'x-component': 'Input',
- 'x-decorator': 'FormItem',
- 'x-hidden': true,
- 'x-reactions': {
- dependencies: ['.templateCode'],
- fulfill: {
- state: {
- value: '{{$deps[0]}}',
- },
- },
- },
- },
- calledNumber: {
- title: '被叫号码',
- 'x-component': 'Input',
- 'x-decorator': 'FormItem',
- 'x-decorator-props': {
- tooltip: '仅支持中国大陆号码',
- gridSpan: 1,
- },
- 'x-component-props': {
- placeholder: '请输入被叫号码',
- },
- 'x-validator': [
- {
- max: 64,
- message: '最多可输入64个字符',
- },
- {
- validator: (value: string) => {
- return new Promise((resolve) => {
- if (!value) resolve('');
- if (!phoneRegEx(value)) {
- resolve('请输入有效号码');
- }
- resolve('');
- });
- },
- },
- ],
- },
- },
- },
- calledShowNumbers: {
- title: '被叫显号',
- 'x-component': 'Input',
- 'x-decorator': 'FormItem',
- 'x-decorator-props': {
- tooltip: '必须是已购买的号码,用于呼叫号码显示',
- },
- 'x-component-props': {
- placeholder: '请输入被叫显号',
- },
- 'x-validator': [
- {
- max: 64,
- message: '最多可输入64个字符',
- },
- {
- validator: (value: string) => {
- return new Promise((resolve) => {
- if (!value) resolve('');
- if (!phoneRegEx(value)) {
- resolve('请输入有效号码');
- }
- resolve('');
- });
- },
- },
- ],
- },
- 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: '模版',
- required: true,
- '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: '签名',
- required: true,
- '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: '请输入标题',
- },
- 'x-validator': [
- {
- max: 64,
- message: '最多可输入64个字符',
- },
- ],
- },
- 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,
- },
- required: true,
- '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: '添加附件',
- },
- },
- },
- },
- },
- webhook: {
- type: 'void',
- 'x-visible': id === 'webhook',
- properties: {
- contextAsBody: {
- title: '请求体',
- type: 'boolean',
- 'x-component': 'Radio.Group',
- 'x-decorator': 'FormItem',
- default: true,
- enum: [
- { label: '默认', value: true },
- { label: '自定义', value: false },
- ],
- },
- body: {
- 'x-decorator': 'FormItem',
- 'x-component': 'FMonacoEditor',
- required: true,
- 'x-component-props': {
- height: 250,
- theme: 'vs',
- language: 'json',
- editorDidMount: (editor1: any) => {
- editor1.onDidScrollChange?.(() => {
- editor1.getAction('editor.action.formatDocument').run();
- });
- },
- },
- // 'x-decorator-props': {
- // style: {
- // zIndex: 9998,
- // },
- // },
- 'x-reactions': {
- dependencies: ['.contextAsBody'],
- fulfill: {
- state: {
- visible: '{{$deps[0]===false}}',
- },
- },
- },
- },
- defaultBody: {
- 'x-decorator': 'FormItem',
- 'x-component': 'Input.TextArea',
- 'x-component-props': {
- rows: 3,
- placeholder: '请求体中的数据来自于发送通知时指定的所有变量',
- },
- 'x-disabled': true,
- 'x-reactions': {
- dependencies: ['.contextAsBody'],
- fulfill: {
- state: {
- visible: '{{$deps[0]===true}}',
- },
- },
- },
- },
- },
- },
- },
- },
- '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"||$deps[0]==="http"}}',
- disabled: '{{["aliyunSms","aliyun"].includes($deps[0])}}',
- },
- },
- },
- 'x-component-props': {
- rows: 5,
- placeholder: '变量格式:${name};\n 示例:尊敬的${name},${time}有设备触发告警,请注意处理',
- },
- 'x-validator': [
- {
- max: 500,
- message: '最多可输入500个字符',
- },
- ],
- },
- 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: '名称', minWidth: '120px' },
- properties: {
- name: {
- type: 'string',
- 'x-decorator': 'FormItem',
- required: true,
- 'x-component': 'Input',
- 'x-component-props': {
- style: {
- width: 100,
- },
- },
- 'x-validator': [
- {
- max: 64,
- message: '最多可输入64个字符',
- },
- ],
- },
- },
- },
- 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: 'double' },
- ],
- },
- },
- },
- 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',
- 'x-reactions': {
- dependencies: ['.type'],
- when: "{{$deps[0]!=='string'}}",
- fulfill: {
- schema: {
- 'x-component-props': {
- suffix: (
- <Tooltip title="格式为:%.xf x代表数字保留的小数位数。当x=0时,代表格式为整数">
- <QuestionCircleOutlined />
- </Tooltip>
- ),
- },
- },
- },
- otherwise: {
- schema: {
- 'x-component-props.suffix': '',
- },
- },
- },
- },
- },
- },
- },
- },
- },
- description: {
- title: '说明',
- 'x-decorator': 'FormItem',
- 'x-component': 'Input.TextArea',
- 'x-component-props': {
- rows: 4,
- },
- 'x-validator': [
- {
- max: 200,
- message: '最多可输入200个字符',
- },
- ],
- // 'x-decorator-props': {
- // style: {
- // zIndex: 998,
- // },
- // },
- },
- },
- };
- 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;
|