|
@@ -1,6 +1,13 @@
|
|
|
import React, { useRef } from 'react'
|
|
|
import { Button, message } from 'antd'
|
|
|
-import { ModalForm, ProFormRadio, ProFormText } from '@ant-design/pro-form'
|
|
|
+import {
|
|
|
+ ModalForm,
|
|
|
+ ProFormDependency,
|
|
|
+ ProFormRadio,
|
|
|
+ ProFormSelect,
|
|
|
+ ProFormText,
|
|
|
+ ProFormTextArea
|
|
|
+} 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'
|
|
@@ -9,9 +16,20 @@ import { useRequest } from 'umi'
|
|
|
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'
|
|
|
+
|
|
|
+export enum msgTypeEnum {
|
|
|
+ Notification = 'notification',
|
|
|
+ Message = 'message'
|
|
|
+}
|
|
|
+export enum mediaType {
|
|
|
+ VersionUpdate = 1,
|
|
|
+ HolidayNotice = 2
|
|
|
+}
|
|
|
|
|
|
const Notification: React.FC = () => {
|
|
|
const tRef = useRef<ActionType>(null)
|
|
|
+ const { sendMsg } = useWebSocketFn()
|
|
|
|
|
|
const columns: ProFormColumnsType<API.NoticeItem>[] = [
|
|
|
{
|
|
@@ -33,13 +51,36 @@ const Notification: React.FC = () => {
|
|
|
|
|
|
const { run: trySendNotice } = useRequest(sendNotice, {
|
|
|
manual: true,
|
|
|
- onSuccess: () => {
|
|
|
+ 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 (
|
|
|
<div className="h-full w-full flex flex-row">
|
|
|
<ShowTitleMenu options={[{ label: '通知', value: 1 }]} defaultValue={1} />
|
|
@@ -54,7 +95,7 @@ const Notification: React.FC = () => {
|
|
|
}}
|
|
|
actionRef={tRef}
|
|
|
columns={columns}
|
|
|
- params={{ msgType: 1 }}
|
|
|
+ params={{ msgType: 'notification' }}
|
|
|
search={false}
|
|
|
toolbar={{
|
|
|
actions: [
|
|
@@ -66,10 +107,11 @@ const Notification: React.FC = () => {
|
|
|
新建通知
|
|
|
</Button>
|
|
|
}
|
|
|
- initialValues={{ msgType: 1 }}
|
|
|
+ initialValues={{ msgType: 'notification', refresh: 0 }}
|
|
|
onFinish={async values => {
|
|
|
try {
|
|
|
- await trySendNotice(values)
|
|
|
+ const nValues = handleFormValues(values)
|
|
|
+ await trySendNotice(nValues)
|
|
|
message.success('添加成功')
|
|
|
return true
|
|
|
} catch (error) {
|
|
@@ -77,15 +119,41 @@ const Notification: React.FC = () => {
|
|
|
}
|
|
|
}}>
|
|
|
<ProFormText label="标题" name="title" required />
|
|
|
- <ProFormText label="内容" name="content" required />
|
|
|
+ <ProFormTextArea label="内容" name="content" required />
|
|
|
<ProFormRadio.Group
|
|
|
label="类型"
|
|
|
name="msgType"
|
|
|
required
|
|
|
options={[
|
|
|
- { label: '通知', value: 1 },
|
|
|
- { label: '消息', value: 2 }
|
|
|
+ { label: '通知', value: msgTypeEnum.Notification },
|
|
|
+ { label: '消息', value: msgTypeEnum.Message }
|
|
|
]}></ProFormRadio.Group>
|
|
|
+ <ProFormDependency name={['msgType']}>
|
|
|
+ {({ msgType }) =>
|
|
|
+ msgType === msgTypeEnum.Notification ? (
|
|
|
+ <ProFormSelect
|
|
|
+ name="media"
|
|
|
+ label="通知类型"
|
|
|
+ options={[
|
|
|
+ { label: '版本更新', value: mediaType.VersionUpdate },
|
|
|
+ { label: '节假通知', value: mediaType.HolidayNotice }
|
|
|
+ ]}
|
|
|
+ />
|
|
|
+ ) : null
|
|
|
+ }
|
|
|
+ </ProFormDependency>
|
|
|
+ <ProFormDependency name={['msgType', 'media']}>
|
|
|
+ {({ msgType, media }) =>
|
|
|
+ msgType === msgTypeEnum.Notification && media === mediaType.VersionUpdate ? (
|
|
|
+ <ProFormRadio.Group
|
|
|
+ name="refresh"
|
|
|
+ options={[
|
|
|
+ { label: '手动刷新', value: 0 },
|
|
|
+ { label: '强制刷新', value: 1 }
|
|
|
+ ]}></ProFormRadio.Group>
|
|
|
+ ) : null
|
|
|
+ }
|
|
|
+ </ProFormDependency>
|
|
|
</ModalForm>
|
|
|
]
|
|
|
}}
|