index.tsx 60 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705
  1. import {
  2. ArrayItems,
  3. ArrayTable,
  4. Editable,
  5. Form,
  6. FormButtonGroup,
  7. FormGrid,
  8. FormItem,
  9. Input,
  10. NumberPicker,
  11. PreviewText,
  12. Radio,
  13. Select,
  14. Space,
  15. Switch,
  16. } from '@formily/antd';
  17. import type { Field } from '@formily/core';
  18. import {
  19. createForm,
  20. FormPath,
  21. onFieldInit,
  22. onFieldReact,
  23. onFieldValueChange,
  24. onFormInit,
  25. registerValidateRules,
  26. } from '@formily/core';
  27. import { createSchemaField, observer } from '@formily/react';
  28. import type { ISchema } from '@formily/json-schema';
  29. import styles from './index.less';
  30. import { useEffect, useMemo, useRef, useState } from 'react';
  31. import FUpload from '@/components/Upload';
  32. import { useParams } from 'umi';
  33. import { PageContainer } from '@ant-design/pro-layout';
  34. import { Card, Col, Row, Tooltip } from 'antd';
  35. import { configService, service } from '@/pages/notice/Template';
  36. import FBraftEditor from '@/components/FBraftEditor';
  37. import { onlyMessage, phoneRegEx, useAsyncDataSource } from '@/utils/util';
  38. import WeixinCorp from '@/pages/notice/Template/Detail/doc/WeixinCorp';
  39. import WeixinApp from '@/pages/notice/Template/Detail/doc/WeixinApp';
  40. import DingTalk from '@/pages/notice/Template/Detail/doc/DingTalk';
  41. import DingTalkRebot from '@/pages/notice/Template/Detail/doc/DingTalkRebot';
  42. import AliyunVoice from '@/pages/notice/Template/Detail/doc/AliyunVoice';
  43. import AliyunSms from '@/pages/notice/Template/Detail/doc/AliyunSms';
  44. import Email from '@/pages/notice/Template/Detail/doc/Email';
  45. import { Store } from 'jetlinks-store';
  46. import FAutoComplete from '@/components/FAutoComplete';
  47. import { PermissionButton } from '@/components';
  48. import usePermissions from '@/hooks/permission';
  49. import FMonacoEditor from '@/components/FMonacoEditor';
  50. import Webhook from './doc/Webhook';
  51. import { useModel } from '@@/plugin-model/useModel';
  52. import { QuestionCircleOutlined } from '@ant-design/icons';
  53. import { typeArray } from '@/components/ProTableCard/CardItems/noticeTemplate';
  54. import { typeList } from '../..';
  55. export const docMap = {
  56. weixin: {
  57. corpMessage: <WeixinCorp />,
  58. officialMessage: <WeixinApp />,
  59. },
  60. dingTalk: {
  61. dingTalkMessage: <DingTalk />,
  62. dingTalkRobotWebHook: <DingTalkRebot />,
  63. },
  64. voice: {
  65. aliyun: <AliyunVoice />,
  66. },
  67. sms: {
  68. aliyunSms: <AliyunSms />,
  69. },
  70. email: {
  71. embedded: <Email />,
  72. },
  73. webhook: {
  74. http: <Webhook />,
  75. },
  76. };
  77. const Detail = observer(() => {
  78. const { id } = useParams<{ id: string }>();
  79. const [typeItem, setTypeItem] = useState<string>('email');
  80. const [providerItem, setProviderItem] = useState<string>('embedded');
  81. const [loading, setLoading] = useState<boolean>(false);
  82. const { initialState } = useModel('@@initialState');
  83. // 正则提取${}里面的值
  84. const pattern = /(?<=\$\{).*?(?=\})/g;
  85. // 提取微信服务号里面的值 {{}}
  86. const weixinPattern = /(?<=\{\{).*?(?=\.DATA}})/g;
  87. const getConfig = (type1: string, provider1: string) =>
  88. configService
  89. .queryNoPagingPost({
  90. terms: [
  91. { column: 'type$IN', value: type1 },
  92. { column: 'provider', value: provider1 },
  93. ],
  94. })
  95. .then((resp: any) => {
  96. return resp.result?.map((item: any) => ({
  97. label: item.name,
  98. value: item.id,
  99. }));
  100. });
  101. //需要复杂联动才可以完成
  102. const getWeixinDept = (configId: string) => service.weixin.getDepartments(configId);
  103. const getWeixinTags = (configId: string) => service.weixin.getTags(configId);
  104. const getWeixinUser = (configId: string) => service.weixin.getUser(configId);
  105. const getDingTalkDept = (configId: string) => service.dingTalk.getDepartments(configId);
  106. const getDingTalkDeptTree = (configId: string) => service.dingTalk.getDepartmentsTree(configId);
  107. const getDingTalkUser = (configId: string) => service.dingTalk.getUser(configId);
  108. const getWeixinOfficialTags = (configId: string) => service.weixin.getOfficialTags(configId);
  109. const getWeixinOfficialTemplates = (configId: string) =>
  110. service.weixin.getOfficialTemplates(configId);
  111. const getAliyunSigns = (configId: string) => service.aliyun.getSigns(configId);
  112. const getAliyunTemplates = (configId: string) => service.aliyun.getTemplates(configId);
  113. const variableDefinitionsRef =
  114. useRef<{ id: string; name: string; type: string; format: string }[]>();
  115. const form = useMemo(
  116. () =>
  117. createForm({
  118. validateFirst: true,
  119. effects() {
  120. onFormInit(async (form1) => {
  121. if (id === ':id' || !id) {
  122. form1.setValues({
  123. type: 'email',
  124. provider: 'embedded',
  125. });
  126. } else {
  127. const resp = await service.detail(id);
  128. if (resp.status === 200) {
  129. form1.setValues(resp.result);
  130. }
  131. }
  132. });
  133. onFieldInit('template.message', async (field) => {
  134. if (id === 'email') {
  135. field.setComponent(FBraftEditor, {
  136. placeholder:
  137. '变量格式:${name};\n 示例:尊敬的${name},${time}有设备触发告警,请注意处理',
  138. // height: '100px',
  139. });
  140. }
  141. const _provider = field.query('provider').value();
  142. if (_provider === 'corpMessage') {
  143. field.componentProps = {
  144. // disabled: true,
  145. rows: 5,
  146. placeholder:
  147. '变量格式:${name};\n 示例:尊敬的${name},${time}有设备触发告警,请注意处理',
  148. };
  149. }
  150. // if (id === 'voice') {
  151. // const type = field.query('template.*.templateType').value();
  152. // console.log(type,'111111')
  153. // field.hidden = false
  154. // field.disabled = false
  155. // }
  156. });
  157. onFieldValueChange('type', async (field, f) => {
  158. const value = field.value;
  159. setTypeItem(value);
  160. if (!value) return;
  161. f.setFieldState('provider', (state1) => {
  162. if (id === ':id' || !id) {
  163. state1.value = typeList[value][0].value;
  164. }
  165. state1.dataSource = typeList[value];
  166. });
  167. });
  168. onFieldValueChange('provider', async (field, form1) => {
  169. const value = field.value;
  170. if (field.modified) {
  171. form1.setValuesIn('configId', null);
  172. form1.setValuesIn('template', null);
  173. }
  174. const _type = field.query('type').value();
  175. // 设置绑定配置的数据
  176. const _list = await getConfig(_type, value);
  177. form1.setFieldState('configId', async (state1) => {
  178. state1.dataSource = _list;
  179. });
  180. if (_type === 'email') {
  181. setProviderItem('embedded');
  182. } else {
  183. setProviderItem(value);
  184. }
  185. if (value === 'officialMessage') {
  186. form1.setFieldState('template.message', (state5) => {
  187. state5.decoratorProps = {
  188. tooltip: '服务号模版消息内容',
  189. };
  190. });
  191. }
  192. });
  193. onFieldValueChange('configId', (field, form1) => {
  194. const value = field.value;
  195. // 判断provider
  196. if (!value) return;
  197. switch (form1.values.provider) {
  198. case 'corpMessage':
  199. form1.setFieldState('template.toUser', async (state8) => {
  200. state8.dataSource = await getWeixinUser(value);
  201. });
  202. form1.setFieldState('template.toParty', async (state9) => {
  203. state9.dataSource = await getWeixinDept(value);
  204. });
  205. form1.setFieldState('template.toTag', async (state10) => {
  206. state10.dataSource = await getWeixinTags(value);
  207. });
  208. break;
  209. case 'officialMessage':
  210. form1.setFieldState('template.tagid', async (state1) => {
  211. state1.dataSource = await getWeixinOfficialTags(value);
  212. });
  213. form1.setFieldState('template.wxTemplateId', async (state2) => {
  214. const list = await getWeixinOfficialTemplates(value);
  215. Store.set('wxTemplate', list);
  216. state2.dataSource = list;
  217. });
  218. break;
  219. case 'dingTalkMessage':
  220. form1.setFieldState('template.userIdList', async (state3) => {
  221. state3.dataSource = await getDingTalkUser(value);
  222. });
  223. form1.setFieldState('template.departmentIdList', async (state4) => {
  224. const list = await getDingTalkDept(value);
  225. Store.set('wxTemplate', list);
  226. state4.dataSource = list;
  227. });
  228. break;
  229. case 'aliyun':
  230. // 阿里云语音
  231. form1.setFieldState('template.ttsCode', async (state5) => {
  232. const list = await getAliyunTemplates(value);
  233. Store.set('AliyunTemplate', list);
  234. state5.dataSource = list;
  235. });
  236. break;
  237. case 'aliyunSms':
  238. // 阿里云短信
  239. form1.setFieldState('template.code', async (state6) => {
  240. const list = await getAliyunTemplates(value);
  241. Store.set('AliyunTemplate', list);
  242. state6.dataSource = list;
  243. });
  244. form1.setFieldState('template.signName', async (state7) => {
  245. // const list =
  246. // Store.set('AliyunTemplate', list);
  247. state7.dataSource = await getAliyunSigns(value);
  248. });
  249. break;
  250. default:
  251. break;
  252. }
  253. });
  254. onFieldValueChange('template.wxTemplateId', (field, form1) => {
  255. const value = field.value;
  256. // 处理消息模版。
  257. const template = Store.get('wxTemplate');
  258. const data = template?.find((i: { id: any }) => i.id === value);
  259. if (data) {
  260. form1.setFieldState('template.title', (state1) => {
  261. state1.value = data.title;
  262. state1.disabled = true;
  263. });
  264. form1.setFieldState('template.message', (state1) => {
  265. state1.value = data.content;
  266. state1.disabled = true;
  267. });
  268. }
  269. });
  270. onFieldValueChange('template.code', (field, form1) => {
  271. const value = field.value;
  272. const template = Store.get('AliyunTemplate');
  273. const data = template?.find((i: { templateCode: any }) => i.templateCode === value);
  274. if (data) {
  275. form1.setFieldState('template.message', (state1) => {
  276. state1.value = data.templateContent;
  277. state1.disabled = true;
  278. });
  279. }
  280. });
  281. onFieldValueChange('template.*(subject,markdown.title,link.title)', (field, form1) => {
  282. const value = (field as Field).value;
  283. const _message = field.query('template.message').value();
  284. const titleList =
  285. (typeof value === 'string' &&
  286. (value + _message)?.match(pattern)?.filter((i: string) => i)) ||
  287. // .map((item: string) => ({id: item, type: 'string', format: '--'}))) ||
  288. [];
  289. // 拼接message的内容
  290. form1.setFieldState('variableDefinitions', (state1) => {
  291. state1.visible = !!titleList && titleList.length > 0;
  292. });
  293. if (form1.modified) {
  294. const oldKey = variableDefinitionsRef.current?.map((i) => i.id);
  295. const newKey = [...new Set(titleList)];
  296. const _result = newKey.map((item) =>
  297. oldKey?.includes(item)
  298. ? variableDefinitionsRef.current?.find((i) => i.id === item)
  299. : {
  300. id: item,
  301. type: 'string',
  302. format: '%s',
  303. },
  304. );
  305. form1.setValuesIn('variableDefinitions', _result);
  306. }
  307. });
  308. onFieldValueChange('template.message', (field, form1) => {
  309. const _provider = field.query('provider').value();
  310. const value = (field as Field).value;
  311. const idList =
  312. (typeof value === 'string' &&
  313. value
  314. ?.match(_provider === 'officialMessage' ? weixinPattern : pattern)
  315. ?.filter((i: string) => i)) ||
  316. [];
  317. if (id === 'email') {
  318. const subject = field.query('template.subject');
  319. const title = subject.value();
  320. const titleList = title?.match(pattern)?.filter((i: string) => i);
  321. // .map((item: string) => ({id: item, type: 'string', format: '--'}));
  322. if (idList && titleList?.length > 0) {
  323. idList.unshift(...titleList);
  324. }
  325. }
  326. if (_provider === 'dingTalkRobotWebHook') {
  327. const title = field.query('template.markdown.title').value();
  328. const titleList = title?.match(pattern)?.filter((i: string) => i);
  329. // .map((item: string) => ({id: item, type: 'string', format: '--'}));
  330. if (idList && titleList?.length > 0) {
  331. idList.unshift(...titleList);
  332. }
  333. }
  334. form1.setFieldState('variableDefinitions', (state1) => {
  335. state1.visible = !!idList && idList.length > 0;
  336. });
  337. if (form1.modified) {
  338. // 获取缓存的KEY;
  339. const oldKey = variableDefinitionsRef.current?.map((i) => i.id);
  340. const newKey = [...new Set(idList)];
  341. const _result = newKey.map((item) =>
  342. oldKey?.includes(item)
  343. ? variableDefinitionsRef.current?.find((i) => i.id === item)
  344. : {
  345. id: item,
  346. type: 'string',
  347. format: '%s',
  348. },
  349. );
  350. form1.setValuesIn('variableDefinitions', _result);
  351. }
  352. });
  353. onFieldValueChange('template.body', (field, form1) => {
  354. const value = (field as Field).value;
  355. // console.log(value);
  356. const idList = (value || '').match(pattern)?.filter((i: string) => i);
  357. form1.setFieldState('variableDefinitions', (state1) => {
  358. state1.visible = !!idList && idList.length > 0;
  359. });
  360. if (form1.modified) {
  361. // 获取缓存的KEY;
  362. const oldKey = variableDefinitionsRef.current?.map((i) => i.id);
  363. const newKey = [...new Set(idList)];
  364. const _result = newKey.map((item: any) =>
  365. oldKey?.includes(item)
  366. ? variableDefinitionsRef.current?.find((i) => i.id === item)
  367. : {
  368. id: item,
  369. type: 'string',
  370. format: '%s',
  371. },
  372. );
  373. form1.setValuesIn('variableDefinitions', _result);
  374. }
  375. });
  376. onFieldValueChange('variableDefinitions.*.*', (field) => {
  377. // 缓存编辑后的数据
  378. variableDefinitionsRef.current = field.query('variableDefinitions').value();
  379. });
  380. onFieldReact('variableDefinitions.*.type', (field) => {
  381. const value = (field as Field).value;
  382. const formatPath = FormPath.transform(
  383. field.path,
  384. /\d+/,
  385. (index) => `variableDefinitions.${parseInt(index)}.format`,
  386. );
  387. const format = field.query(formatPath).take() as any;
  388. const fieldModified = field && (field as Field).modified;
  389. if (!format) return;
  390. if (fieldModified) {
  391. format.setValue(undefined);
  392. }
  393. switch (value) {
  394. case 'date':
  395. format.setComponent(FAutoComplete);
  396. format.setDataSource([
  397. { label: 'timestamp', value: 'timestamp' },
  398. { label: 'yyyy-MM-dd', value: 'yyyy-MM-dd' },
  399. { label: 'yyyy-MM-dd HH:mm:ss', value: 'yyyy-MM-dd HH:mm:ss' },
  400. // { label: 'yyyy-MM-dd HH:mm:ss EE', value: 'yyyy-MM-dd HH:mm:ss EE' },
  401. // { label: 'yyyy-MM-dd HH:mm:ss zzz', value: 'yyyy-MM-dd HH:mm:ss zzz' },
  402. ]);
  403. if (fieldModified) {
  404. format.setValue('timestamp');
  405. }
  406. break;
  407. case 'string':
  408. format.setComponent(PreviewText.Input);
  409. if (fieldModified) {
  410. format.setValue('%s');
  411. }
  412. break;
  413. case 'double':
  414. format.setComponent(Input);
  415. if (fieldModified) {
  416. format.setValue('%.0f');
  417. }
  418. break;
  419. // case 'file':
  420. // format.setComponent(Select);
  421. // format.setDataSource([
  422. // {label: '视频', value: 'video'},
  423. // {label: '图片', value: 'img'},
  424. // {label: '全部', value: 'any'},
  425. // ]);
  426. // format.setValue('any');
  427. // break;
  428. // case 'other':
  429. // format.setComponent(PreviewText.Input);
  430. // format.setValue('--');
  431. // break;
  432. }
  433. });
  434. onFieldReact('template.templateType', (field, form1) => {
  435. const value = (field as Field).value;
  436. form1.setFieldState('template.message', (state1) => {
  437. if (value === 'tts') {
  438. state1.disabled = false;
  439. state1.hidden = false;
  440. state1.required = false;
  441. state1.decoratorProps = {
  442. tooltip: '语音验证码内容输入框,用于渲染验语音证码变量。',
  443. };
  444. state1.componentProps = {
  445. rows: 5,
  446. placeholder: '内容中的变量将用于阿里云语音验证码。',
  447. };
  448. } else {
  449. state1.hidden = true;
  450. state1.value = undefined;
  451. }
  452. });
  453. });
  454. },
  455. }),
  456. [id],
  457. );
  458. useEffect(() => {
  459. setTimeout(() => {
  460. if (initialState?.settings?.title) {
  461. document.title = `通知模板 - ${initialState?.settings?.title}`;
  462. } else {
  463. document.title = '通知模板';
  464. }
  465. }, 0);
  466. // if (state.current) {
  467. // form.setValues(state.current);
  468. // }
  469. }, []);
  470. const SchemaField = createSchemaField({
  471. components: {
  472. FormItem,
  473. Input,
  474. Select,
  475. Switch,
  476. Radio,
  477. Editable,
  478. PreviewText,
  479. Space,
  480. FUpload,
  481. NumberPicker,
  482. FBraftEditor,
  483. ArrayItems,
  484. FormGrid,
  485. ArrayTable,
  486. FAutoComplete,
  487. FMonacoEditor,
  488. },
  489. });
  490. const handleSave = async () => {
  491. const data: TemplateItem = await form.submit();
  492. setLoading(true);
  493. // dingTalkRobotWebHook
  494. // 提交的时候处理内容
  495. // 钉钉机器人-->dingTalkRobotWebHook
  496. // r如果是text 的话。template.message=>template.text.content
  497. // 如果是markdown 的话。 template.message=>template.markdown.text
  498. // 如果是link的话。 template.message =>template.markdown.text
  499. // 微信服务号: template.message =>template.content
  500. if (data.provider === 'dingTalkRobotWebHook') {
  501. const type = data.template.messageType;
  502. // emplate.messageType
  503. switch (type) {
  504. case 'text':
  505. data.template.text = {
  506. content: data.template.message,
  507. };
  508. // data.template.text.content = data.template.message;
  509. break;
  510. case 'markdown':
  511. data.template.markdown.text = data.template.message;
  512. break;
  513. case 'link':
  514. data.template.link.text = data.template.message;
  515. }
  516. }
  517. if (data.type === 'email') {
  518. data.provider = 'embedded';
  519. data.template.text = data.template.message;
  520. }
  521. let response;
  522. if (data.id) {
  523. response = await service.update(data);
  524. } else {
  525. response = await service.save(data);
  526. }
  527. setLoading(false);
  528. if (response?.status === 200) {
  529. onlyMessage('保存成功');
  530. history.back();
  531. }
  532. };
  533. registerValidateRules({
  534. batchCheckEmail(value) {
  535. const regEmail = /^([A-Za-z0-9_\-\.])+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/;
  536. let error;
  537. if (value) {
  538. value.some((item: string) => {
  539. if (!regEmail.test(item)) {
  540. error = item;
  541. return true;
  542. }
  543. return false;
  544. });
  545. }
  546. return error ? `${error}邮件格式错误` : '';
  547. },
  548. });
  549. const schema: ISchema = {
  550. type: 'object',
  551. properties: {
  552. type: {
  553. title: '通知方式',
  554. 'x-component': 'Select',
  555. 'x-decorator': 'FormItem',
  556. 'x-component-props': {
  557. placeholder: '请选择通知方式',
  558. },
  559. 'x-disabled': !!id && id !== ':id',
  560. 'x-validator': [
  561. {
  562. required: true,
  563. message: '请选择通知方式',
  564. },
  565. ],
  566. enum: typeArray.map((item) => {
  567. return { label: item.text, value: item.status };
  568. }),
  569. },
  570. name: {
  571. title: '名称',
  572. type: 'string',
  573. 'x-decorator': 'FormItem',
  574. 'x-component': 'Input',
  575. 'x-component-props': {
  576. placeholder: '请输入名称',
  577. },
  578. name: 'name',
  579. 'x-validator': [
  580. {
  581. max: 64,
  582. message: '最多可输入64个字符',
  583. },
  584. {
  585. required: true,
  586. message: '请输入名称',
  587. },
  588. ],
  589. },
  590. provider: {
  591. title: '类型',
  592. type: 'string',
  593. 'x-decorator': 'FormItem',
  594. 'x-component': 'Radio.Group',
  595. 'x-component-props': {
  596. optionType: 'button',
  597. placeholder: '请选择类型',
  598. },
  599. 'x-validator': [
  600. {
  601. required: true,
  602. message: '请选择类型',
  603. },
  604. ],
  605. // 'x-visible': typeList[typeItem]?.length > 0,
  606. // 'x-hidden': typeItem === 'email' || typeItem === 'webhook',
  607. // 'x-value': typeList[typeItem]?.[0]?.value,
  608. // enum: typeList[typeItem] || [],
  609. 'x-reactions': {
  610. dependencies: ['type'],
  611. fulfill: {
  612. state: {
  613. hidden: '{{!(!!$deps[0] && $deps[0] !== "email" && $deps[0] !== "webhook")}}',
  614. },
  615. },
  616. },
  617. },
  618. configId: {
  619. title: '绑定配置',
  620. type: 'string',
  621. 'x-decorator': 'FormItem',
  622. 'x-component': 'Select',
  623. 'x-component-props': {
  624. placeholder: '请选择绑定配置',
  625. },
  626. required: true,
  627. 'x-decorator-props': {
  628. tooltip: '使用固定的通知配置来发送此通知模版',
  629. },
  630. // 'x-visible': id !== 'email',
  631. 'x-reactions': {
  632. dependencies: ['type'],
  633. fulfill: {
  634. state: {
  635. visible: '{{$deps[0] !=="email"}}',
  636. },
  637. },
  638. },
  639. },
  640. template: {
  641. type: 'object',
  642. properties: {
  643. weixin: {
  644. type: 'void',
  645. // 'x-visible': id === 'weixin',
  646. 'x-reactions': {
  647. dependencies: ['type'],
  648. fulfill: {
  649. state: {
  650. visible: '{{$deps[0]==="weixin"}}',
  651. },
  652. },
  653. },
  654. properties: {
  655. corpMessage: {
  656. type: 'void',
  657. properties: {
  658. agentId: {
  659. title: 'AgentId',
  660. 'x-component': 'Input',
  661. 'x-decorator': 'FormItem',
  662. 'x-decorator-props': {
  663. tooltip: '应用唯一标识',
  664. },
  665. required: true,
  666. 'x-component-props': {
  667. placeholder: '请输入AgentID',
  668. },
  669. 'x-validator': [
  670. {
  671. max: 64,
  672. message: '最多可输入64个字符',
  673. },
  674. ],
  675. },
  676. layout: {
  677. type: 'void',
  678. 'x-decorator': 'FormGrid',
  679. 'x-decorator-props': {
  680. maxColumns: 2,
  681. minColumns: 2,
  682. },
  683. properties: {
  684. toUser: {
  685. title: '收信人',
  686. 'x-component': 'Select',
  687. 'x-decorator': 'FormItem',
  688. 'x-decorator-props': {
  689. tooltip: '如果不填写该字段,将在使用此模版发送通知时进行指定。',
  690. gridSpan: 1,
  691. },
  692. 'x-component-props': {
  693. placeholder: '请选择收信人',
  694. },
  695. },
  696. toParty: {
  697. title: '收信部门',
  698. 'x-component': 'Select',
  699. 'x-decorator': 'FormItem',
  700. // 'x-decorator-props': {
  701. // tooltip: '如果不填写该字段,将在使用此模版发送通知时进行指定。',
  702. // gridSpan: 1,
  703. // },
  704. 'x-component-props': {
  705. placeholder: '请选择收信部门',
  706. },
  707. },
  708. },
  709. },
  710. toTag: {
  711. title: '标签推送',
  712. 'x-component': 'Select',
  713. 'x-decorator': 'FormItem',
  714. 'x-decorator-props': {
  715. tooltip:
  716. '本企业微信的标签ID列表,最多支持100个,如果不填写该字段,将在使用此模版发送通知时进行指定',
  717. },
  718. 'x-component-props': {
  719. placeholder: '请选择标签推送,多个标签用,号分隔',
  720. },
  721. },
  722. },
  723. 'x-reactions': {
  724. dependencies: ['provider'],
  725. fulfill: {
  726. state: {
  727. visible: '{{$deps[0]==="corpMessage"}}',
  728. },
  729. },
  730. },
  731. },
  732. officialMessage: {
  733. type: 'void',
  734. properties: {
  735. tagid: {
  736. title: '用户标签',
  737. type: 'string',
  738. 'x-decorator': 'FormItem',
  739. 'x-component': 'Select',
  740. 'x-component-props': {
  741. placeholder: '请选择用户标签',
  742. },
  743. 'x-decorator-props': {
  744. tooltip: '如果不填写该字段,将在使用此模板发送通知时进行指定',
  745. },
  746. },
  747. layout: {
  748. type: 'void',
  749. 'x-decorator': 'FormGrid',
  750. 'x-decorator-props': {
  751. maxColumns: 2,
  752. minColumns: 2,
  753. },
  754. properties: {
  755. wxTemplateId: {
  756. title: '消息模版',
  757. type: 'string',
  758. 'x-decorator': 'FormItem',
  759. 'x-component': 'Select',
  760. 'x-component-props': {
  761. placeholder: '请选择消息模版',
  762. },
  763. required: true,
  764. 'x-decorator-props': {
  765. gridSpan: 1,
  766. tooltip: '微信公众号中配置的消息模版',
  767. },
  768. },
  769. url: {
  770. title: '模版跳转链接',
  771. type: 'string',
  772. 'x-decorator': 'FormItem',
  773. 'x-component': 'Input',
  774. 'x-component-props': {
  775. placeholder: '请输入模版跳转链接',
  776. },
  777. 'x-decorator-props': {
  778. gridSpan: 1,
  779. tooltip: '用于点击消息后进行页面跳转',
  780. },
  781. },
  782. },
  783. },
  784. toMiniProgram: {
  785. title: '跳转小程序',
  786. type: 'string',
  787. 'x-decorator': 'FormItem',
  788. 'x-component': 'Radio.Group',
  789. 'x-component-props': {
  790. // optionType: 'button'
  791. },
  792. 'x-decorator-props': {
  793. tooltip: '配置后点击通知消息将跳转到对应小程序',
  794. },
  795. default: false,
  796. enum: [
  797. { label: '是', value: true },
  798. { label: '否', value: false },
  799. ],
  800. },
  801. miniProgram: {
  802. type: 'void',
  803. properties: {
  804. layout: {
  805. type: 'void',
  806. 'x-decorator': 'FormGrid',
  807. 'x-decorator-props': {
  808. maxColumns: 2,
  809. minColumns: 2,
  810. },
  811. properties: {
  812. miniProgramId: {
  813. title: '跳转小程序AppId',
  814. type: 'string',
  815. 'x-decorator': 'FormItem',
  816. 'x-component': 'Input',
  817. 'x-component-props': {
  818. placeholder: '请输入跳转小程序AppId',
  819. },
  820. 'x-decorator-props': {
  821. gridSpan: 1,
  822. tooltip: '小程序唯一性id',
  823. },
  824. },
  825. miniProgramPath: {
  826. title: '跳转小程序具体路径',
  827. type: 'string',
  828. 'x-decorator': 'FormItem',
  829. 'x-component': 'Input',
  830. 'x-component-props': {
  831. placeholder: '请输入跳转小程序具体路径',
  832. },
  833. 'x-decorator-props': {
  834. gridSpan: 1,
  835. tooltip: '用于点击消息之后跳转到小程序的具体页面',
  836. },
  837. },
  838. },
  839. },
  840. },
  841. 'x-reactions': {
  842. dependencies: ['.toMiniProgram'],
  843. fulfill: {
  844. state: {
  845. visible: '{{$deps[0]===true}}',
  846. },
  847. },
  848. },
  849. },
  850. title: {
  851. title: '模版标题',
  852. type: 'string',
  853. 'x-decorator': 'FormItem',
  854. 'x-component': 'Input',
  855. 'x-component-props': {
  856. placeholder: '这里是回显内容',
  857. },
  858. 'x-decorator-props': {
  859. tooltip: '服务号消息模版标题',
  860. },
  861. 'x-disabled': true,
  862. 'x-validator': [
  863. {
  864. max: 64,
  865. message: '最多可输入64个字符',
  866. },
  867. ],
  868. },
  869. },
  870. 'x-reactions': {
  871. dependencies: ['provider'],
  872. fulfill: {
  873. state: {
  874. visible: '{{$deps[0]==="officialMessage"}}',
  875. },
  876. },
  877. },
  878. },
  879. },
  880. },
  881. dingTalk: {
  882. type: 'void',
  883. // 'x-visible': id === 'dingTalk',
  884. 'x-reactions': {
  885. dependencies: ['type'],
  886. fulfill: {
  887. state: {
  888. visible: '{{$deps[0]==="dingTalk"}}',
  889. },
  890. },
  891. },
  892. properties: {
  893. dingTalkMessage: {
  894. type: 'void',
  895. properties: {
  896. agentId: {
  897. title: 'AgentID',
  898. required: true,
  899. 'x-component': 'Input',
  900. 'x-decorator': 'FormItem',
  901. 'x-decorator-props': {
  902. tooltip: '应用唯一标识',
  903. },
  904. 'x-component-props': {
  905. placeholder: '请输入AgentID',
  906. },
  907. 'x-validator': [
  908. {
  909. max: 64,
  910. message: '最多可输入64个字符',
  911. },
  912. ],
  913. },
  914. layout: {
  915. type: 'void',
  916. 'x-decorator': 'FormGrid',
  917. 'x-decorator-props': {
  918. maxColumns: 2,
  919. minColumns: 2,
  920. },
  921. properties: {
  922. departmentIdList: {
  923. title: '收信部门',
  924. // required: true,
  925. 'x-component': 'Select',
  926. 'x-decorator': 'FormItem',
  927. // 'x-decorator-props': {
  928. // tooltip: '如果不填写该字段,将在使用此模板发送通知时进行指定',
  929. // gridSpan: 1,
  930. // },
  931. 'x-component-props': {
  932. placeholder: '请选择收信部门',
  933. },
  934. // 'x-reactions': {
  935. // dependencies: ['configId'],
  936. // fulfill: {
  937. // run: '{{useAsyncDataSource(getDingTalkDept($deps[0]))}}',
  938. // },
  939. // },
  940. },
  941. userIdList: {
  942. title: '收信人',
  943. 'x-component': 'Select',
  944. 'x-decorator': 'FormItem',
  945. 'x-decorator-props': {
  946. tooltip: '如果不填写该字段,将在使用此模板发送通知时进行指定',
  947. gridSpan: 1,
  948. },
  949. 'x-component-props': {
  950. placeholder: '请选择收信人',
  951. },
  952. // 'x-reactions': {
  953. // dependencies: ['configId'],
  954. // fulfill: {
  955. // run: '{{useAsyncDataSource(getDingTalkUser($deps[0]))}}',
  956. // },
  957. // },
  958. },
  959. },
  960. },
  961. },
  962. 'x-reactions': {
  963. dependencies: ['provider'],
  964. fulfill: {
  965. state: {
  966. visible: '{{$deps[0]==="dingTalkMessage"}}',
  967. },
  968. },
  969. },
  970. },
  971. dingTalkRobotWebHook: {
  972. type: 'void',
  973. properties: {
  974. messageType: {
  975. title: '消息类型',
  976. 'x-component': 'Select',
  977. 'x-decorator': 'FormItem',
  978. required: true,
  979. 'x-component-props': {
  980. placeholder: '请选择消息类型',
  981. },
  982. enum: [
  983. { label: 'markdown', value: 'markdown' },
  984. { label: 'text', value: 'text' },
  985. { label: 'link', value: 'link' },
  986. ],
  987. },
  988. markdown: {
  989. type: 'object',
  990. properties: {
  991. title: {
  992. required: true,
  993. title: '标题',
  994. 'x-component': 'Input',
  995. 'x-decorator': 'FormItem',
  996. 'x-component-props': {
  997. placeholder: '请输入标题',
  998. },
  999. 'x-validator': [
  1000. {
  1001. max: 64,
  1002. message: '最多可输入64个字符',
  1003. },
  1004. ],
  1005. },
  1006. },
  1007. 'x-reactions': {
  1008. dependencies: ['.messageType'],
  1009. fulfill: {
  1010. state: {
  1011. visible: '{{$deps[0]==="markdown"}}',
  1012. },
  1013. },
  1014. },
  1015. },
  1016. link: {
  1017. type: 'object',
  1018. properties: {
  1019. title: {
  1020. required: true,
  1021. title: '标题',
  1022. 'x-component': 'Input',
  1023. 'x-decorator': 'FormItem',
  1024. 'x-component-props': {
  1025. placeholder: '请输入标题',
  1026. },
  1027. 'x-validator': [
  1028. {
  1029. max: 64,
  1030. message: '最多可输入64个字符',
  1031. },
  1032. ],
  1033. },
  1034. '{url:picUrl}': {
  1035. title: '图片链接',
  1036. 'x-component': 'FUpload',
  1037. 'x-decorator': 'FormItem',
  1038. 'x-component-props': {
  1039. type: 'file',
  1040. placeholder: '请输入图片链接',
  1041. },
  1042. },
  1043. messageUrl: {
  1044. title: '内容链接',
  1045. 'x-component': 'Input',
  1046. 'x-decorator': 'FormItem',
  1047. 'x-component-props': {
  1048. placeholder: '请输入内容链接',
  1049. },
  1050. },
  1051. },
  1052. 'x-reactions': {
  1053. dependencies: ['.messageType'],
  1054. fulfill: {
  1055. state: {
  1056. visible: '{{$deps[0]==="link"}}',
  1057. },
  1058. },
  1059. },
  1060. },
  1061. },
  1062. 'x-reactions': {
  1063. dependencies: ['provider'],
  1064. fulfill: {
  1065. state: {
  1066. visible: '{{$deps[0]==="dingTalkRobotWebHook"}}',
  1067. },
  1068. },
  1069. },
  1070. },
  1071. },
  1072. // 钉钉群机器人配置参数名 类型 说明
  1073. // messageType String 钉钉-消息类型 markdown、text、link
  1074. // ${messageType} String 钉钉-内容
  1075. },
  1076. aliyun: {
  1077. type: 'void',
  1078. properties: {
  1079. voice: {
  1080. // 'x-visible': id === 'voice',
  1081. 'x-reactions': {
  1082. dependencies: ['type'],
  1083. fulfill: {
  1084. state: {
  1085. visible: '{{$deps[0]==="voice"}}',
  1086. },
  1087. },
  1088. },
  1089. type: 'void',
  1090. properties: {
  1091. templateType: {
  1092. title: '类型',
  1093. required: true,
  1094. 'x-component': 'Select',
  1095. 'x-decorator': 'FormItem',
  1096. 'x-decorator-props': {
  1097. tooltip: '语音验证码类型可配置变量,并且只支持数字和英文字母',
  1098. },
  1099. 'x-component-props': {
  1100. placeholder: '请选择类型',
  1101. },
  1102. default: 'tts',
  1103. enum: [
  1104. { label: '语音通知', value: 'voice' },
  1105. { label: '语音验证码', value: 'tts' },
  1106. ],
  1107. },
  1108. layout: {
  1109. type: 'void',
  1110. 'x-decorator': 'FormGrid',
  1111. 'x-decorator-props': {
  1112. maxColumns: 2,
  1113. minColumns: 2,
  1114. },
  1115. properties: {
  1116. templateCode: {
  1117. title: '模版ID',
  1118. 'x-component': 'Input',
  1119. 'x-decorator': 'FormItem',
  1120. 'x-decorator-props': {
  1121. tooltip: '阿里云内部分配的唯一ID标识',
  1122. gridSpan: 1,
  1123. },
  1124. required: true,
  1125. 'x-component-props': {
  1126. placeholder: '请输入模版ID',
  1127. },
  1128. },
  1129. ttsCode: {
  1130. title: '模版ID',
  1131. 'x-component': 'Input',
  1132. 'x-decorator': 'FormItem',
  1133. 'x-hidden': true,
  1134. 'x-reactions': {
  1135. dependencies: ['.templateCode'],
  1136. fulfill: {
  1137. state: {
  1138. value: '{{$deps[0]}}',
  1139. },
  1140. },
  1141. },
  1142. },
  1143. calledNumber: {
  1144. title: '被叫号码',
  1145. 'x-component': 'Input',
  1146. 'x-decorator': 'FormItem',
  1147. 'x-decorator-props': {
  1148. tooltip: '仅支持中国大陆号码',
  1149. gridSpan: 1,
  1150. },
  1151. 'x-component-props': {
  1152. placeholder: '请输入被叫号码',
  1153. },
  1154. 'x-validator': [
  1155. {
  1156. max: 64,
  1157. message: '最多可输入64个字符',
  1158. },
  1159. {
  1160. validator: (value: string) => {
  1161. return new Promise((resolve) => {
  1162. if (!value) resolve('');
  1163. if (!phoneRegEx(value)) {
  1164. resolve('请输入有效号码');
  1165. }
  1166. resolve('');
  1167. });
  1168. },
  1169. },
  1170. ],
  1171. },
  1172. },
  1173. },
  1174. calledShowNumbers: {
  1175. title: '被叫显号',
  1176. 'x-component': 'Input',
  1177. 'x-decorator': 'FormItem',
  1178. 'x-decorator-props': {
  1179. tooltip: '必须是已购买的号码,用于呼叫号码显示',
  1180. },
  1181. 'x-component-props': {
  1182. placeholder: '请输入被叫显号',
  1183. },
  1184. 'x-validator': [
  1185. {
  1186. max: 64,
  1187. message: '最多可输入64个字符',
  1188. },
  1189. {
  1190. validator: (value: string) => {
  1191. return new Promise((resolve) => {
  1192. if (!value) resolve('');
  1193. if (!phoneRegEx(value)) {
  1194. resolve('请输入有效号码');
  1195. }
  1196. resolve('');
  1197. });
  1198. },
  1199. },
  1200. ],
  1201. },
  1202. playTimes: {
  1203. title: '播放次数',
  1204. 'x-component': 'NumberPicker',
  1205. 'x-decorator': 'FormItem',
  1206. 'x-decorator-props': {
  1207. tooltip: '语音文件的播放次数',
  1208. },
  1209. default: 1,
  1210. 'x-validator': [
  1211. {
  1212. min: 1,
  1213. max: 3,
  1214. message: '仅支持1~3次',
  1215. },
  1216. ],
  1217. 'x-component-props': {
  1218. placeholder: '请输入播放次数',
  1219. },
  1220. },
  1221. },
  1222. },
  1223. sms: {
  1224. // 'x-visible': id === 'sms',
  1225. 'x-reactions': {
  1226. dependencies: ['type'],
  1227. fulfill: {
  1228. state: {
  1229. visible: '{{$deps[0]==="sms"}}',
  1230. },
  1231. },
  1232. },
  1233. type: 'void',
  1234. properties: {
  1235. layout: {
  1236. type: 'void',
  1237. 'x-decorator': 'FormGrid',
  1238. 'x-decorator-props': {
  1239. maxColumns: 2,
  1240. minColumns: 2,
  1241. },
  1242. properties: {
  1243. code: {
  1244. title: '模版',
  1245. required: true,
  1246. 'x-component': 'Select',
  1247. 'x-decorator': 'FormItem',
  1248. 'x-decorator-props': {
  1249. tooltip: '阿里云短信平台自定义的模版名称',
  1250. gridSpan: 1,
  1251. },
  1252. 'x-component-props': {
  1253. placeholder: '请选择模版',
  1254. },
  1255. 'x-reactions': {
  1256. dependencies: ['configId'],
  1257. fulfill: {
  1258. run: '{{useAsyncDataSource(getAliyunTemplates($deps[0]))}}',
  1259. },
  1260. },
  1261. },
  1262. phoneNumber: {
  1263. title: '收信人',
  1264. 'x-component': 'Input',
  1265. 'x-decorator': 'FormItem',
  1266. 'x-decorator-props': {
  1267. tooltip: '仅支持中国大陆号码',
  1268. gridSpan: 1,
  1269. },
  1270. 'x-validator': ['phone'],
  1271. 'x-component-props': {
  1272. placeholder: '请输入收信人',
  1273. },
  1274. },
  1275. },
  1276. },
  1277. signName: {
  1278. title: '签名',
  1279. required: true,
  1280. 'x-component': 'Select',
  1281. 'x-decorator': 'FormItem',
  1282. 'x-decorator-props': {
  1283. tooltip: '用于短信内容签名信息显示',
  1284. },
  1285. 'x-component-props': {
  1286. placeholder: '请输入签名',
  1287. },
  1288. 'x-reactions': {
  1289. dependencies: ['configId'],
  1290. fulfill: {
  1291. run: '{{useAsyncDataSource(getAliyunSigns($deps[0]))}}',
  1292. },
  1293. },
  1294. },
  1295. },
  1296. },
  1297. },
  1298. },
  1299. email: {
  1300. type: 'void',
  1301. // 'x-visible': id === 'email',
  1302. 'x-reactions': {
  1303. dependencies: ['type'],
  1304. fulfill: {
  1305. state: {
  1306. visible: '{{$deps[0]==="email"}}',
  1307. },
  1308. },
  1309. },
  1310. properties: {
  1311. subject: {
  1312. 'x-component': 'Input',
  1313. 'x-decorator': 'FormItem',
  1314. title: '标题',
  1315. 'x-decorator-props': {
  1316. tooltip: '邮件标题',
  1317. },
  1318. required: true,
  1319. 'x-component-props': {
  1320. placeholder: '请输入标题',
  1321. },
  1322. 'x-validator': [
  1323. {
  1324. max: 64,
  1325. message: '最多可输入64个字符',
  1326. },
  1327. ],
  1328. },
  1329. sendTo: {
  1330. 'x-component': 'Select',
  1331. 'x-decorator': 'FormItem',
  1332. title: '收件人',
  1333. 'x-decorator-props': {
  1334. tooltip: '多个收件人用换行分隔 \n最大支持1000个号码',
  1335. },
  1336. 'x-component-props': {
  1337. mode: 'tags',
  1338. placeholder: '请输入收件人邮箱,多个收件人用换行分隔',
  1339. },
  1340. 'x-validator': {
  1341. batchCheckEmail: true,
  1342. },
  1343. },
  1344. attachments: {
  1345. type: 'array',
  1346. title: '附件信息',
  1347. 'x-decorator': 'FormItem',
  1348. 'x-component': 'ArrayItems',
  1349. 'x-decorator-props': {
  1350. style: {
  1351. width: '100%',
  1352. },
  1353. tooltip: '附件只输入文件名称将在发送邮件时进行文件上传',
  1354. },
  1355. items: {
  1356. type: 'object',
  1357. 'x-decorator': 'FormGrid',
  1358. 'x-decorator-props': {
  1359. maxColumns: 24,
  1360. minColumns: 24,
  1361. },
  1362. properties: {
  1363. '{url:location,name:name}': {
  1364. 'x-component': 'FUpload',
  1365. 'x-decorator': 'FormItem',
  1366. 'x-decorator-props': {
  1367. style: {
  1368. width: '100%',
  1369. },
  1370. gridSpan: 23,
  1371. },
  1372. required: true,
  1373. 'x-component-props': {
  1374. type: 'file',
  1375. display: 'name',
  1376. placeholder: '请上传文件或输入文件名称',
  1377. },
  1378. },
  1379. remove: {
  1380. type: 'void',
  1381. 'x-decorator': 'FormItem',
  1382. 'x-component': 'ArrayItems.Remove',
  1383. 'x-decorator-props': {
  1384. gridSpan: 1,
  1385. },
  1386. },
  1387. },
  1388. },
  1389. properties: {
  1390. add: {
  1391. type: 'void',
  1392. 'x-component': 'ArrayItems.Addition',
  1393. title: '添加附件',
  1394. },
  1395. },
  1396. },
  1397. },
  1398. },
  1399. webhook: {
  1400. type: 'void',
  1401. 'x-visible': id === 'webhook',
  1402. 'x-reactions': {
  1403. dependencies: ['type'],
  1404. fulfill: {
  1405. state: {
  1406. visible: '{{$deps[0]==="webhook"}}',
  1407. },
  1408. },
  1409. },
  1410. properties: {
  1411. contextAsBody: {
  1412. title: '请求体',
  1413. type: 'boolean',
  1414. 'x-component': 'Radio.Group',
  1415. 'x-decorator': 'FormItem',
  1416. default: true,
  1417. enum: [
  1418. { label: '默认', value: true },
  1419. { label: '自定义', value: false },
  1420. ],
  1421. },
  1422. body: {
  1423. 'x-decorator': 'FormItem',
  1424. 'x-component': 'FMonacoEditor',
  1425. required: true,
  1426. 'x-component-props': {
  1427. height: 250,
  1428. theme: 'vs',
  1429. language: 'json',
  1430. editorDidMount: (editor1: any) => {
  1431. editor1.onDidScrollChange?.(() => {
  1432. editor1.getAction('editor.action.formatDocument').run();
  1433. });
  1434. },
  1435. },
  1436. // 'x-decorator-props': {
  1437. // style: {
  1438. // zIndex: 9998,
  1439. // },
  1440. // },
  1441. 'x-reactions': {
  1442. dependencies: ['.contextAsBody'],
  1443. fulfill: {
  1444. state: {
  1445. visible: '{{$deps[0]===false}}',
  1446. },
  1447. },
  1448. },
  1449. },
  1450. defaultBody: {
  1451. 'x-decorator': 'FormItem',
  1452. 'x-component': 'Input.TextArea',
  1453. 'x-component-props': {
  1454. rows: 3,
  1455. placeholder: '请求体中的数据来自于发送通知时指定的所有变量',
  1456. },
  1457. 'x-disabled': true,
  1458. 'x-reactions': {
  1459. dependencies: ['.contextAsBody'],
  1460. fulfill: {
  1461. state: {
  1462. visible: '{{$deps[0]===true}}',
  1463. },
  1464. },
  1465. },
  1466. },
  1467. },
  1468. },
  1469. },
  1470. },
  1471. 'template.message': {
  1472. title: '模版内容',
  1473. 'x-component': 'Input.TextArea',
  1474. 'x-decorator': 'FormItem',
  1475. 'x-decorator-props': {
  1476. tooltip: '发送的内容,支持录入变量',
  1477. },
  1478. required: true,
  1479. 'x-reactions': {
  1480. dependencies: ['provider'],
  1481. fulfill: {
  1482. state: {
  1483. hidden: '{{$deps[0]==="aliyun"||$deps[0]==="http"}}',
  1484. disabled: '{{["aliyunSms","aliyun"].includes($deps[0])}}',
  1485. },
  1486. },
  1487. },
  1488. 'x-component-props': {
  1489. rows: 5,
  1490. placeholder: '变量格式:${name};\n 示例:尊敬的${name},${time}有设备触发告警,请注意处理',
  1491. },
  1492. 'x-validator': [
  1493. {
  1494. max: 500,
  1495. message: '最多可输入500个字符',
  1496. },
  1497. ],
  1498. },
  1499. variableDefinitions: {
  1500. type: 'array',
  1501. title: '变量列表',
  1502. 'x-decorator': 'FormItem',
  1503. 'x-component': 'ArrayTable',
  1504. 'x-component-props': {
  1505. pagination: { pageSize: 9999 },
  1506. scroll: { x: '100%' },
  1507. },
  1508. 'x-decorator-props': {
  1509. style: {
  1510. zIndex: 999,
  1511. },
  1512. },
  1513. 'x-visible': false,
  1514. items: {
  1515. type: 'object',
  1516. properties: {
  1517. column1: {
  1518. type: 'void',
  1519. 'x-component': 'ArrayTable.Column',
  1520. 'x-component-props': { title: '变量', width: '120px' },
  1521. properties: {
  1522. id: {
  1523. type: 'string',
  1524. 'x-decorator': 'FormItem',
  1525. 'x-component': 'PreviewText.Input',
  1526. 'x-disabled': true,
  1527. },
  1528. },
  1529. },
  1530. column2: {
  1531. type: 'void',
  1532. 'x-component': 'ArrayTable.Column',
  1533. 'x-component-props': { title: '名称', minWidth: '120px' },
  1534. properties: {
  1535. name: {
  1536. type: 'string',
  1537. 'x-decorator': 'FormItem',
  1538. required: true,
  1539. 'x-component': 'Input',
  1540. 'x-component-props': {
  1541. style: {
  1542. width: 100,
  1543. },
  1544. },
  1545. 'x-validator': [
  1546. {
  1547. max: 64,
  1548. message: '最多可输入64个字符',
  1549. },
  1550. ],
  1551. },
  1552. },
  1553. },
  1554. column3: {
  1555. type: 'void',
  1556. 'x-component': 'ArrayTable.Column',
  1557. 'x-component-props': { title: '类型', width: '120px' },
  1558. properties: {
  1559. type: {
  1560. type: 'string',
  1561. 'x-decorator': 'FormItem',
  1562. 'x-component': 'Select',
  1563. required: true,
  1564. enum: [
  1565. { label: '字符串', value: 'string' },
  1566. { label: '时间', value: 'date' },
  1567. { label: '数字', value: 'double' },
  1568. ],
  1569. },
  1570. },
  1571. },
  1572. column4: {
  1573. type: 'void',
  1574. 'x-component': 'ArrayTable.Column',
  1575. 'x-component-props': { title: '格式', width: '300px' },
  1576. required: true,
  1577. properties: {
  1578. format: {
  1579. type: 'string',
  1580. 'x-decorator': 'FormItem',
  1581. 'x-component': 'Input',
  1582. 'x-reactions': {
  1583. dependencies: ['.type'],
  1584. when: "{{$deps[0]!=='string'}}",
  1585. fulfill: {
  1586. schema: {
  1587. 'x-component-props': {
  1588. suffix: (
  1589. <Tooltip title="格式为:%.xf x代表数字保留的小数位数。当x=0时,代表格式为整数">
  1590. <QuestionCircleOutlined />
  1591. </Tooltip>
  1592. ),
  1593. },
  1594. },
  1595. },
  1596. otherwise: {
  1597. schema: {
  1598. 'x-component-props.suffix': '',
  1599. },
  1600. },
  1601. },
  1602. },
  1603. },
  1604. },
  1605. },
  1606. },
  1607. },
  1608. description: {
  1609. title: '说明',
  1610. 'x-decorator': 'FormItem',
  1611. 'x-component': 'Input.TextArea',
  1612. 'x-component-props': {
  1613. rows: 5,
  1614. placeholder: '请输入说明',
  1615. showCount: true,
  1616. maxLength: 200,
  1617. },
  1618. 'x-validator': [
  1619. {
  1620. max: 200,
  1621. message: '最多可输入200个字符',
  1622. },
  1623. ],
  1624. // 'x-decorator-props': {
  1625. // style: {
  1626. // zIndex: 998,
  1627. // },
  1628. // },
  1629. },
  1630. },
  1631. };
  1632. const { permission } = usePermissions('notice/Template');
  1633. return (
  1634. <PageContainer>
  1635. <Card>
  1636. <Row>
  1637. <Col span={10}>
  1638. <Form className={styles.form} form={form} layout={'vertical'}>
  1639. <SchemaField
  1640. schema={schema}
  1641. scope={{
  1642. getConfig,
  1643. getDingTalkDept,
  1644. getDingTalkDeptTree,
  1645. getDingTalkUser,
  1646. getWeixinDept,
  1647. getWeixinTags,
  1648. getWeixinUser,
  1649. getAliyunSigns,
  1650. getAliyunTemplates,
  1651. useAsyncDataSource,
  1652. getWeixinOfficialTags,
  1653. getWeixinOfficialTemplates,
  1654. }}
  1655. />
  1656. <FormButtonGroup.Sticky>
  1657. <FormButtonGroup.FormItem>
  1658. <PermissionButton
  1659. type="primary"
  1660. loading={loading}
  1661. isPermission={permission.add || permission.update}
  1662. onClick={handleSave}
  1663. >
  1664. 保存
  1665. </PermissionButton>
  1666. </FormButtonGroup.FormItem>
  1667. </FormButtonGroup.Sticky>
  1668. </Form>
  1669. </Col>
  1670. <Col span={12} push={2}>
  1671. {docMap?.[typeItem]?.[providerItem]}
  1672. </Col>
  1673. </Row>
  1674. </Card>
  1675. </PageContainer>
  1676. );
  1677. });
  1678. export default Detail;