import React, { useRef } from 'react' import { Button, message, Form } from 'antd' import { ModalForm, ProFormDependency, ProFormRadio, ProFormSelect, ProFormText } from '@ant-design/pro-form' import type { ProFormColumnsType } from '@ant-design/pro-form' import ProTable from '@ant-design/pro-table' import type { ActionType } from '@ant-design/pro-table' import ShowTitleMenu from '../Attendance/components/ShowTitleMenu' import { useRequest } from '@umijs/max' import { queryNoticeList, sendNotice } from '@/services/user/api' import consts from '@/utils/consts' import { PlusOutlined } from '@ant-design/icons' import useWebSocketFn, { cmdType } from '@/hooks/core/useWebSocketFn' import RighEditor from './components/RighEditor' import { PageContainer } from '@ant-design/pro-layout' export enum msgTypeEnum { Notification = 'notification', Message = 'message' } export enum mediaType { VersionUpdate = 1, HolidayNotice = 2 } const Notification: React.FC = () => { const tRef = useRef(null) const { sendMsg } = useWebSocketFn() const columns: ProFormColumnsType[] = [ { title: '标题', dataIndex: 'title', width: '30%' }, { title: '内容', dataIndex: 'content', width: '50%' }, { title: '推送时间', dataIndex: 'createTime', valueType: 'dateTime' } ] const { run: trySendNotice } = useRequest(sendNotice, { manual: true, onSuccess: result => { tRef.current?.reload() sendMsg(cmdType.Notice, result) }, onError: e => { message.error(e.message) } }) const handleFormValues = values => { const newValues = { ...values } switch (values.msgType) { case msgTypeEnum.Notification: switch (values.media) { case mediaType.VersionUpdate: newValues.avatar = 'https://zhcld.com/resource/notice_email.png' break case mediaType.HolidayNotice: newValues.avatar = 'https://zhcld.com/resource/notice_airplane.png' break default: break } break default: break } return newValues } return (
{/*
通知推送
*/} 新建通知 } initialValues={{ msgType: 'notification', refresh: 0 }} onFinish={async values => { try { const nValues = handleFormValues(values) await trySendNotice(nValues) message.success('添加成功') return true } catch (error) { return false } }}> {/* */} {({ msgType }) => msgType === msgTypeEnum.Notification ? ( ) : null } {({ msgType, media }) => msgType === msgTypeEnum.Notification && media === mediaType.VersionUpdate ? ( ) : null } ] }} request={async (params, sort, filter) => { const { code = -1, data = {} } = await queryNoticeList({ ...params, ...sort, ...filter }) const { message: notices = [], total = 0 } = data return { data: notices, success: code === consts.RET_CODE.SUCCESS, total } }} bordered pagination={{ defaultPageSize: 10 }} rowKey={row => row.id} />
) } export default Notification