import { PageContainer } from '@ant-design/pro-layout'; import { useRef, useState } from 'react'; import type { ActionType, ProColumns } from '@jetlinks/pro-table'; import { ArrowDownOutlined, BugOutlined, DeleteOutlined, EditOutlined, EyeOutlined, PlusOutlined, UnorderedListOutlined, } from '@ant-design/icons'; import { Space, Upload } from 'antd'; import { useIntl } from '@@/plugin-locale/localeExports'; import Service from '@/pages/notice/Template/service'; import ConfigService from '@/pages/notice/Config/service'; import SearchComponent from '@/components/SearchComponent'; import { history, useLocation } from 'umi'; import { getMenuPathByParams, MENUS_CODE } from '@/utils/menu'; import { model } from '@formily/reactive'; import Debug from './Debug'; import Log from '@/pages/notice/Template/Log'; import { downloadObject, onlyMessage } from '@/utils/util'; import moment from 'moment'; import { PermissionButton, ProTableCard } from '@/components'; import NoticeCard, { typeList } from '@/components/ProTableCard/CardItems/noticeTemplate'; import { observer } from '@formily/react'; import usePermissions from '@/hooks/permission'; export const service = new Service('notifier/template'); export const configService = new ConfigService('notifier/config'); export const state = model<{ current?: TemplateItem; debug?: boolean; log?: boolean; }>({ debug: false, log: false, }); const list = { weixin: { corpMessage: { text: '企业消息', status: 'corpMessage', }, // officialMessage: { // text: '服务号消息', // status: 'officialMessage', // }, }, dingTalk: { dingTalkMessage: { text: '钉钉消息', status: 'dingTalkMessage', }, dingTalkRobotWebHook: { text: '群机器人消息', status: 'dingTalkRobotWebHook', }, }, voice: { aliyun: { text: '阿里云语音', status: 'aliyun', }, }, sms: { aliyunSms: { text: '阿里云短信', status: 'aliyunSms', }, }, email: { embedded: { text: '邮件', status: 'embedded', }, }, webhook: { http: { text: 'Webhook', status: 'http', }, }, }; const Template = observer(() => { const intl = useIntl(); const location = useLocation<{ id: string }>(); const id = (location as any).query?.id; const actionRef = useRef(); const { permission: templatePermission } = usePermissions('notice'); const columns: ProColumns[] = [ { dataIndex: 'name', title: '模版名称', ellipsis: true, }, { dataIndex: 'provider', title: '通知方式', renderText: (text, record) => typeList[record.type][record.provider], valueType: 'select', valueEnum: list[id], }, { dataIndex: 'description', title: '说明', ellipsis: true, }, { title: intl.formatMessage({ id: 'pages.data.option', defaultMessage: '操作', }), valueType: 'option', align: 'left', width: 200, render: (text, record) => [ { state.current = record; history.push(getMenuPathByParams(MENUS_CODE['notice/Template/Detail'], id)); }} tooltip={{ title: intl.formatMessage({ id: 'pages.data.option.edit', defaultMessage: '编辑', }), }} > , { downloadObject( record, `${record.name}-${moment(new Date()).format('YYYY/MM/DD HH:mm:ss')}`, ); }} > , { state.debug = true; state.current = record; }} tooltip={{ title: intl.formatMessage({ id: 'pages.notice.option.debug', defaultMessage: '调试', }), }} > , { state.log = true; }} tooltip={{ title: '通知记录' }} > , { await service.remove(record.id); actionRef.current?.reload(); }, }} tooltip={{ title: intl.formatMessage({ id: 'pages.data.option.remove', defaultMessage: '删除', }), }} isPermission={templatePermission.delete} key="delete" > , ], }, ]; const [param, setParam] = useState({}); return ( { actionRef.current?.reset?.(); setParam(data); }} /> actionRef={actionRef} rowKey="id" search={false} params={param} columns={columns} headerTitle={ { state.current = undefined; history.push(getMenuPathByParams(MENUS_CODE['notice/Template/Detail'], id)); }} key="button" icon={} type="primary" > {intl.formatMessage({ id: 'pages.data.option.add', defaultMessage: '新增', })} { const reader = new FileReader(); reader.readAsText(file); reader.onload = async (result) => { const text = result.target?.result as string; if (!file.type.includes('json')) { onlyMessage('文件内容格式错误', 'warning'); return; } try { const data = JSON.parse(text || '{}'); const res: any = await service.savePatch(data); if (res.status === 200) { onlyMessage('操作成功'); actionRef.current?.reload(); } } catch { onlyMessage('文件内容格式错误', 'warning'); } }; return false; }} > 导入 { const resp: any = await service.queryNoPagingPost({ ...param, paging: false }); if (resp.status === 200) { downloadObject(resp.result, '通知模版数据'); onlyMessage('导出成功'); } else { onlyMessage('导出错误', 'error'); } }, }} isPermission={templatePermission.export} > 导出 } gridColumn={3} cardRender={(record) => ( { state.current = record; history.push(getMenuPathByParams(MENUS_CODE['notice/Template/Detail'], id)); }} > } actions={[ { state.current = record; history.push(getMenuPathByParams(MENUS_CODE['notice/Template/Detail'], id)); }} > 编辑 , { state.debug = true; state.current = record; }} > 调试 , { downloadObject( record, `${record.name}-${moment(new Date()).format('YYYY/MM/DD HH:mm:ss')}`, ); }} > 导出 , { state.log = true; state.current = record; }} > 通知记录 , { await service.remove(record.id); actionRef.current?.reset?.(); }, }} isPermission={templatePermission.delete} key="delete" > , ]} /> )} request={async (params) => service.query({ ...params, sorts: [{ name: 'createTime', order: 'desc' }] }) } /> {state.log && } ); }); export default Template;