index.tsx 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  1. import { PageContainer } from '@ant-design/pro-layout';
  2. import type { ActionType, ProColumns } from '@jetlinks/pro-table';
  3. import {
  4. ArrowDownOutlined,
  5. BarsOutlined,
  6. BugOutlined,
  7. DeleteOutlined,
  8. EditOutlined,
  9. EyeOutlined,
  10. PlusOutlined,
  11. SmallDashOutlined,
  12. TeamOutlined,
  13. UnorderedListOutlined,
  14. } from '@ant-design/icons';
  15. import { Dropdown, Menu, Space, Upload } from 'antd';
  16. import { useRef, useState } from 'react';
  17. import { useIntl } from '@@/plugin-locale/localeExports';
  18. import { downloadObject, onlyMessage } from '@/utils/util';
  19. import Service from '@/pages/notice/Config/service';
  20. import { observer } from '@formily/react';
  21. import SearchComponent from '@/components/SearchComponent';
  22. import { getMenuPathByParams, MENUS_CODE } from '@/utils/menu';
  23. import { history } from 'umi';
  24. import { model } from '@formily/reactive';
  25. import moment from 'moment';
  26. import { PermissionButton, ProTableCard } from '@/components';
  27. import NoticeConfig from '@/components/ProTableCard/CardItems/noticeConfig';
  28. import Debug from '@/pages/notice/Config/Debug';
  29. import Log from '@/pages/notice/Config/Log';
  30. import { providerObj, typeList, typeObj } from '@/components/ProTableCard/CardItems/noticeTemplate';
  31. import usePermissions from '@/hooks/permission';
  32. import SyncUser from '@/pages/notice/Config/SyncUser';
  33. export const service = new Service('notifier/config');
  34. export const state = model<{
  35. current?: ConfigItem;
  36. debug?: boolean;
  37. log?: boolean;
  38. syncUser: boolean;
  39. }>({
  40. debug: false,
  41. log: false,
  42. syncUser: false,
  43. });
  44. const Config = observer(() => {
  45. const intl = useIntl();
  46. const actionRef = useRef<ActionType>();
  47. // const location = useLocation<{ id: string }>();
  48. const { permission: configPermission } = usePermissions('notice');
  49. // const id = (location as any).query?.id;
  50. const columns: ProColumns<ConfigItem>[] = [
  51. {
  52. dataIndex: 'name',
  53. title: '配置名称',
  54. ellipsis: true,
  55. fixed: 'left',
  56. width: '25%',
  57. },
  58. {
  59. dataIndex: 'type',
  60. title: '通知方式',
  61. renderText: (text, record) => typeObj?.[record.type]?.text || record.type,
  62. valueType: 'select',
  63. valueEnum: typeObj,
  64. },
  65. {
  66. dataIndex: 'provider',
  67. title: '类型',
  68. renderText: (text, record) => {
  69. return typeList[record?.type][record?.provider];
  70. },
  71. valueType: 'select',
  72. valueEnum: providerObj,
  73. },
  74. {
  75. dataIndex: 'description',
  76. ellipsis: true,
  77. title: '说明',
  78. },
  79. {
  80. title: intl.formatMessage({
  81. id: 'pages.data.option',
  82. defaultMessage: '操作',
  83. }),
  84. valueType: 'option',
  85. width: 200,
  86. fixed: 'right',
  87. render: (text, record) => [
  88. (record.provider === 'dingTalkMessage' || record.provider === 'corpMessage') && (
  89. <PermissionButton
  90. tooltip={{
  91. title: '同步用户',
  92. }}
  93. style={{ padding: 0 }}
  94. type="link"
  95. isPermission={configPermission.bind}
  96. onClick={() => {
  97. state.syncUser = true;
  98. state.current = record;
  99. }}
  100. >
  101. <TeamOutlined />
  102. </PermissionButton>
  103. ),
  104. <PermissionButton
  105. key="edit"
  106. type="link"
  107. style={{ padding: 0 }}
  108. isPermission={configPermission.update}
  109. onClick={async () => {
  110. // setLoading(true);
  111. state.current = record;
  112. history.push(getMenuPathByParams(MENUS_CODE['notice/Config/Detail'], record.id));
  113. }}
  114. tooltip={{
  115. title: intl.formatMessage({
  116. id: 'pages.data.option.edit',
  117. defaultMessage: '编辑',
  118. }),
  119. }}
  120. >
  121. <EditOutlined />
  122. </PermissionButton>,
  123. <PermissionButton
  124. type="link"
  125. style={{ padding: 0 }}
  126. isPermission={configPermission.export}
  127. onClick={() =>
  128. downloadObject(
  129. record,
  130. `通知配置${record.name}-${moment(new Date()).format('YYYY/MM/DD HH:mm:ss')}`,
  131. )
  132. }
  133. key="download"
  134. tooltip={{
  135. title: intl.formatMessage({
  136. id: 'pages.data.option.download',
  137. defaultMessage: '下载配置',
  138. }),
  139. }}
  140. >
  141. <ArrowDownOutlined />
  142. </PermissionButton>,
  143. <PermissionButton
  144. type="link"
  145. style={{ padding: 0 }}
  146. isPermission={configPermission.debug}
  147. key="debug"
  148. onClick={() => {
  149. state.debug = true;
  150. state.current = record;
  151. }}
  152. tooltip={{
  153. title: intl.formatMessage({
  154. id: 'pages.notice.option.debug',
  155. defaultMessage: '调试',
  156. }),
  157. }}
  158. >
  159. <BugOutlined />
  160. </PermissionButton>,
  161. <PermissionButton
  162. type="link"
  163. style={{ padding: 0 }}
  164. isPermission={configPermission.log}
  165. key="record"
  166. onClick={() => {
  167. state.log = true;
  168. }}
  169. tooltip={{
  170. title: intl.formatMessage({
  171. id: 'pages.data.option.record',
  172. defaultMessage: '通知记录',
  173. }),
  174. }}
  175. >
  176. <BarsOutlined />
  177. </PermissionButton>,
  178. <PermissionButton
  179. style={{ padding: 0 }}
  180. type="link"
  181. popConfirm={{
  182. onConfirm: async () => {
  183. await service.remove(record.id);
  184. onlyMessage(
  185. intl.formatMessage({
  186. id: 'pages.data.option.success',
  187. defaultMessage: '操作成功!',
  188. }),
  189. );
  190. actionRef.current?.reload();
  191. },
  192. title: '确认删除',
  193. }}
  194. tooltip={{
  195. title: intl.formatMessage({
  196. id: 'pages.data.option.remove',
  197. defaultMessage: '删除',
  198. }),
  199. }}
  200. key="remove"
  201. >
  202. <DeleteOutlined />
  203. </PermissionButton>,
  204. ],
  205. },
  206. ];
  207. const [param, setParam] = useState({});
  208. return (
  209. <PageContainer>
  210. <SearchComponent
  211. // defaultParam={[{ column: 'type$IN', value: id }]}
  212. field={columns}
  213. onSearch={(data) => {
  214. actionRef.current?.reset?.();
  215. setParam(data);
  216. }}
  217. />
  218. <ProTableCard<ConfigItem>
  219. rowKey="id"
  220. actionRef={actionRef}
  221. search={false}
  222. params={param}
  223. columnEmptyText={''}
  224. columns={columns}
  225. scroll={{ x: 1366 }}
  226. headerTitle={
  227. <Space>
  228. <PermissionButton
  229. isPermission={configPermission.add}
  230. onClick={() => {
  231. state.current = undefined;
  232. history.push(getMenuPathByParams(MENUS_CODE['notice/Config/Detail']));
  233. }}
  234. key="button"
  235. icon={<PlusOutlined />}
  236. type="primary"
  237. >
  238. {intl.formatMessage({
  239. id: 'pages.data.option.add',
  240. defaultMessage: '新增',
  241. })}
  242. </PermissionButton>
  243. <Upload
  244. disabled={!configPermission.import}
  245. key={'import'}
  246. showUploadList={false}
  247. beforeUpload={(file) => {
  248. const reader = new FileReader();
  249. reader.readAsText(file);
  250. reader.onload = async (result) => {
  251. const text = result.target?.result as string;
  252. if (!file.type.includes('json')) {
  253. onlyMessage('文件内容格式错误', 'warning');
  254. return;
  255. }
  256. try {
  257. const data = JSON.parse(text || '{}');
  258. const res: any = await service.savePatch(data);
  259. if (res.status === 200) {
  260. onlyMessage('操作成功');
  261. actionRef.current?.reload();
  262. }
  263. } catch {
  264. onlyMessage('文件内容格式错误', 'warning');
  265. }
  266. };
  267. return false;
  268. }}
  269. >
  270. <PermissionButton isPermission={configPermission.import} style={{ marginLeft: 12 }}>
  271. 导入
  272. </PermissionButton>
  273. </Upload>
  274. <PermissionButton
  275. popConfirm={{
  276. title: '确认导出当前页数据?',
  277. onConfirm: async () => {
  278. const resp: any = await service.queryNoPagingPost({ ...param, paging: false });
  279. if (resp.status === 200) {
  280. downloadObject(resp.result, '通知配置数据');
  281. onlyMessage('导出成功');
  282. } else {
  283. onlyMessage('导出错误', 'error');
  284. }
  285. },
  286. }}
  287. isPermission={configPermission.export}
  288. >
  289. 导出
  290. </PermissionButton>
  291. </Space>
  292. }
  293. // gridColumn={3}
  294. gridColumns={[2, 2, 3]}
  295. request={async (params) =>
  296. service.query({ ...params, sorts: [{ name: 'createTime', order: 'desc' }] })
  297. }
  298. cardRender={(record) => (
  299. <NoticeConfig
  300. {...record}
  301. detail={
  302. <div
  303. style={{ fontSize: 18, padding: 8 }}
  304. onClick={() => {
  305. state.current = record;
  306. history.push(getMenuPathByParams(MENUS_CODE['notice/Config/Detail'], record.id));
  307. }}
  308. >
  309. <EyeOutlined />
  310. </div>
  311. }
  312. actions={[
  313. // (record.provider === 'dingTalkMessage' || record.provider === 'corpMessage') && (
  314. // <PermissionButton
  315. // key="syncUser"
  316. // isPermission={true}
  317. // type="link"
  318. // onClick={() => {
  319. // state.syncUser = true;
  320. // state.current = record;
  321. // }}
  322. // >
  323. // <TeamOutlined />
  324. // 同步用户
  325. // </PermissionButton>
  326. // ),
  327. <PermissionButton
  328. isPermission={configPermission.update}
  329. type={'link'}
  330. key="edit"
  331. onClick={async () => {
  332. state.current = record;
  333. history.push(getMenuPathByParams(MENUS_CODE['notice/Config/Detail'], record.id));
  334. }}
  335. >
  336. <EditOutlined />
  337. 编辑
  338. </PermissionButton>,
  339. <PermissionButton
  340. type={'link'}
  341. key="debug"
  342. isPermission={configPermission.debug}
  343. onClick={() => {
  344. state.debug = true;
  345. state.current = record;
  346. }}
  347. >
  348. <BugOutlined />
  349. 调试
  350. </PermissionButton>,
  351. <PermissionButton
  352. type={'link'}
  353. key="log"
  354. isPermission={configPermission.log}
  355. onClick={() => {
  356. state.log = true;
  357. state.current = record;
  358. }}
  359. >
  360. <UnorderedListOutlined />
  361. 通知记录
  362. </PermissionButton>,
  363. <Dropdown
  364. key={'more'}
  365. placement="bottom"
  366. overlay={
  367. <Menu>
  368. <Menu.Item key="export">
  369. <PermissionButton
  370. type={'link'}
  371. key="export"
  372. isPermission={configPermission.export}
  373. onClick={() =>
  374. downloadObject(
  375. record,
  376. `通知配置${record.name}-${moment(new Date()).format(
  377. 'YYYY/MM/DD HH:mm:ss',
  378. )}`,
  379. )
  380. }
  381. >
  382. <ArrowDownOutlined />
  383. 导出
  384. </PermissionButton>
  385. ,
  386. </Menu.Item>
  387. {(record.provider === 'dingTalkMessage' ||
  388. record.provider === 'corpMessage') && (
  389. <Menu.Item key="syncUser">
  390. <PermissionButton
  391. key="syncUser"
  392. isPermission={configPermission.bind}
  393. type="link"
  394. onClick={() => {
  395. state.syncUser = true;
  396. state.current = record;
  397. }}
  398. >
  399. <TeamOutlined />
  400. 同步用户
  401. </PermissionButton>
  402. </Menu.Item>
  403. )}
  404. </Menu>
  405. }
  406. >
  407. <PermissionButton type={'link'} isPermission={true} key="other">
  408. <SmallDashOutlined />
  409. 其他
  410. </PermissionButton>
  411. </Dropdown>,
  412. <PermissionButton
  413. key="delete"
  414. isPermission={configPermission.delete}
  415. popConfirm={{
  416. title: '确认删除?',
  417. onConfirm: async () => {
  418. await service.remove(record.id);
  419. actionRef.current?.reset?.();
  420. },
  421. }}
  422. type={'link'}
  423. >
  424. <DeleteOutlined />
  425. </PermissionButton>,
  426. ]}
  427. />
  428. )}
  429. />
  430. <Debug />
  431. {state.log && <Log />}
  432. {state.syncUser && <SyncUser />}
  433. </PageContainer>
  434. );
  435. });
  436. export default Config;