| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317 |
- import { PageContainer } from '@ant-design/pro-layout';
- import type { ActionType, ProColumns } from '@jetlinks/pro-table';
- import {
- ArrowDownOutlined,
- BarsOutlined,
- BugOutlined,
- DeleteOutlined,
- EditOutlined,
- PlusOutlined,
- UnorderedListOutlined,
- } from '@ant-design/icons';
- import { Button, message, Popconfirm, Space, Tooltip, Upload } from 'antd';
- import { useRef, useState } from 'react';
- import { useIntl } from '@@/plugin-locale/localeExports';
- import { downloadObject } from '@/utils/util';
- import Service from '@/pages/notice/Config/service';
- import { observer } from '@formily/react';
- import SearchComponent from '@/components/SearchComponent';
- import { getMenuPathByParams, MENUS_CODE } from '@/utils/menu';
- import { history, useLocation } from 'umi';
- import { model } from '@formily/reactive';
- import moment from 'moment';
- import { ProTableCard } from '@/components';
- import NoticeConfig from '@/components/ProTableCard/CardItems/noticeConfig';
- import Debug from '@/pages/notice/Config/Debug';
- import Log from '@/pages/notice/Config/Log';
- import { typeList } from '@/components/ProTableCard/CardItems/noticeTemplate';
- export const service = new Service('notifier/config');
- export const state = model<{
- current?: ConfigItem;
- debug?: boolean;
- log?: boolean;
- }>({
- debug: false,
- log: false,
- });
- const Config = observer(() => {
- const intl = useIntl();
- const actionRef = useRef<ActionType>();
- const location = useLocation<{ id: string }>();
- const id = (location as any).query?.id;
- const columns: ProColumns<ConfigItem>[] = [
- {
- dataIndex: 'name',
- title: '配置名称',
- },
- {
- dataIndex: 'provider',
- title: '通知方式',
- renderText: (text, record) => typeList[record.type][record.provider],
- },
- {
- dataIndex: 'description',
- title: '说明',
- },
- {
- title: intl.formatMessage({
- id: 'pages.data.option',
- defaultMessage: '操作',
- }),
- valueType: 'option',
- align: 'center',
- width: 200,
- render: (text, record) => [
- <a
- key="edit"
- onClick={async () => {
- // setLoading(true);
- state.current = record;
- history.push(getMenuPathByParams(MENUS_CODE['notice/Config/Detail'], id));
- }}
- >
- <Tooltip
- title={intl.formatMessage({
- id: 'pages.data.option.edit',
- defaultMessage: '编辑',
- })}
- >
- <EditOutlined />
- </Tooltip>
- </a>,
- <a
- onClick={() =>
- downloadObject(
- record,
- `通知配置${record.name}-${moment(new Date()).format('YYYY/MM/DD HH:mm:ss')}`,
- )
- }
- key="download"
- >
- <Tooltip
- title={intl.formatMessage({
- id: 'pages.data.option.download',
- defaultMessage: '下载配置',
- })}
- >
- <ArrowDownOutlined />
- </Tooltip>
- </a>,
- <a
- key="debug"
- onClick={() => {
- state.debug = true;
- state.current = record;
- }}
- >
- <Tooltip
- title={intl.formatMessage({
- id: 'pages.notice.option.debug',
- defaultMessage: '调试',
- })}
- >
- <BugOutlined />
- </Tooltip>
- </a>,
- <a
- key="record"
- onClick={() => {
- state.log = true;
- }}
- >
- <Tooltip
- title={intl.formatMessage({
- id: 'pages.data.option.record',
- defaultMessage: '通知记录',
- })}
- >
- <BarsOutlined />
- </Tooltip>
- </a>,
- <a key="remove">
- <Popconfirm
- onConfirm={async () => {
- await service.remove(record.id);
- message.success(
- intl.formatMessage({
- id: 'pages.data.option.success',
- defaultMessage: '操作成功!',
- }),
- );
- actionRef.current?.reload();
- }}
- title="确认删除?"
- >
- <Tooltip
- title={intl.formatMessage({
- id: 'pages.data.option.remove',
- defaultMessage: '删除',
- })}
- >
- <DeleteOutlined />
- </Tooltip>
- </Popconfirm>
- </a>,
- ],
- },
- ];
- const [param, setParam] = useState({});
- return (
- <PageContainer>
- <SearchComponent
- defaultParam={[{ column: 'type$IN', value: id }]}
- field={columns}
- onSearch={(data) => {
- actionRef.current?.reset?.();
- setParam(data);
- }}
- />
- <ProTableCard<ConfigItem>
- rowKey="id"
- actionRef={actionRef}
- search={false}
- params={param}
- columns={columns}
- headerTitle={
- <Space>
- <Button
- onClick={() => {
- state.current = undefined;
- history.push(getMenuPathByParams(MENUS_CODE['notice/Config/Detail'], id));
- }}
- key="button"
- icon={<PlusOutlined />}
- type="primary"
- >
- {intl.formatMessage({
- id: 'pages.data.option.add',
- defaultMessage: '新增',
- })}
- </Button>
- <Upload
- key={'import'}
- showUploadList={false}
- beforeUpload={(file) => {
- const reader = new FileReader();
- reader.readAsText(file);
- reader.onload = async (result) => {
- const text = result.target?.result as string;
- if (!file.type.includes('json')) {
- message.warning('文件内容格式错误');
- return;
- }
- try {
- const data = JSON.parse(text || '{}');
- if (Array.isArray(data)) {
- message.warning('文件内容格式错误');
- return;
- }
- const res: any = await service.savePatch(data);
- if (res.status === 200) {
- message.success('操作成功');
- actionRef.current?.reload();
- }
- } catch {
- message.warning('文件内容格式错误');
- }
- };
- return false;
- }}
- >
- <Button style={{ marginLeft: 12 }}>导入</Button>
- </Upload>
- <Popconfirm
- title={'确认导出当前页数据?'}
- onConfirm={async () => {
- const resp: any = await service.queryNoPagingPost({ ...param, paging: false });
- if (resp.status === 200) {
- downloadObject(resp.result, '通知配置数据');
- message.success('导出成功');
- } else {
- message.error('导出错误');
- }
- }}
- >
- <Button>导出</Button>
- </Popconfirm>
- </Space>
- }
- gridColumn={3}
- request={async (params) =>
- service.query({ ...params, sorts: [{ name: 'createTime', order: 'desc' }] })
- }
- cardRender={(record) => (
- <NoticeConfig
- {...record}
- type={id}
- actions={[
- <Button
- key="edit"
- onClick={async () => {
- // setLoading(true);
- state.current = record;
- history.push(getMenuPathByParams(MENUS_CODE['notice/Config/Detail'], id));
- }}
- >
- <EditOutlined />
- 编辑
- </Button>,
- <Button
- key="debug"
- onClick={() => {
- state.debug = true;
- state.current = record;
- }}
- >
- <BugOutlined />
- 调试
- </Button>,
- <Button
- key="export"
- onClick={() =>
- downloadObject(
- record,
- `通知配置${record.name}-${moment(new Date()).format('YYYY/MM/DD HH:mm:ss')}`,
- )
- }
- >
- <ArrowDownOutlined />
- 导出
- </Button>,
- <Button
- key="log"
- onClick={() => {
- state.log = true;
- state.current = record;
- }}
- >
- <UnorderedListOutlined />
- 通知记录
- </Button>,
- <Popconfirm
- key="delete"
- title="确认删除?"
- onConfirm={async () => {
- await service.remove(record.id);
- actionRef.current?.reset?.();
- }}
- >
- <Button key="delete">
- <DeleteOutlined />
- </Button>
- </Popconfirm>,
- ]}
- />
- )}
- />
- <Debug />
- {state.log && <Log />}
- </PageContainer>
- );
- });
- export default Config;
|