|
@@ -1,30 +1,17 @@
|
|
|
import React, { useState, useEffect, useRef } from 'react'
|
|
import React, { useState, useEffect, useRef } from 'react'
|
|
|
-import { List, Avatar, Tag, Skeleton, Divider, Button } from 'antd'
|
|
|
|
|
-import { Plus } from '@icon-park/react'
|
|
|
|
|
-import {
|
|
|
|
|
- ModalForm,
|
|
|
|
|
- ProFormDependency,
|
|
|
|
|
- ProFormRadio,
|
|
|
|
|
- ProFormSelect,
|
|
|
|
|
- ProFormText
|
|
|
|
|
-} from '@ant-design/pro-form'
|
|
|
|
|
|
|
+import { List, Avatar, Tag, Skeleton, Divider } from 'antd'
|
|
|
import InfiniteScroll from 'react-infinite-scroll-component'
|
|
import InfiniteScroll from 'react-infinite-scroll-component'
|
|
|
import { queryMessageList, sendMessage } from '@/services/staff'
|
|
import { queryMessageList, sendMessage } from '@/services/staff'
|
|
|
|
|
+import AddMessage from './components/AddMessage'
|
|
|
import consts from '@/consts'
|
|
import consts from '@/consts'
|
|
|
import { useRequest } from 'umi'
|
|
import { useRequest } from 'umi'
|
|
|
-import RighEditor from './components/RighEditor'
|
|
|
|
|
-
|
|
|
|
|
-export const msgTypeEnum = {
|
|
|
|
|
- NotificationOne: 'notification',
|
|
|
|
|
- Message: 'message'
|
|
|
|
|
-}
|
|
|
|
|
-export const mediaType = {
|
|
|
|
|
- VersionUpdate: 1,
|
|
|
|
|
- HolidayNotice: 2
|
|
|
|
|
-}
|
|
|
|
|
|
|
|
|
|
const Notification = () => {
|
|
const Notification = () => {
|
|
|
const tRef = useRef(null)
|
|
const tRef = useRef(null)
|
|
|
|
|
+ const msgTypeEnum = {
|
|
|
|
|
+ message: '通知',
|
|
|
|
|
+ notification: '消息'
|
|
|
|
|
+ }
|
|
|
const [state, setState] = useState({
|
|
const [state, setState] = useState({
|
|
|
loading: false,
|
|
loading: false,
|
|
|
message: [],
|
|
message: [],
|
|
@@ -34,16 +21,6 @@ const Notification = () => {
|
|
|
total: 0,
|
|
total: 0,
|
|
|
msgType: 'notification'
|
|
msgType: 'notification'
|
|
|
})
|
|
})
|
|
|
- const { run: trySendMessage } = useRequest(sendMessage, {
|
|
|
|
|
- manual: true,
|
|
|
|
|
- onSuccess: result => {
|
|
|
|
|
- tRef.current?.reload()
|
|
|
|
|
- sendMsg(cmdType.Notice, result)
|
|
|
|
|
- },
|
|
|
|
|
- onError: e => {
|
|
|
|
|
- message.error(e.message)
|
|
|
|
|
- }
|
|
|
|
|
- })
|
|
|
|
|
const initData = async params => {
|
|
const initData = async params => {
|
|
|
setState({ ...state, loading: true })
|
|
setState({ ...state, loading: true })
|
|
|
const {
|
|
const {
|
|
@@ -67,92 +44,23 @@ const Notification = () => {
|
|
|
const loadMoreData = () => {
|
|
const loadMoreData = () => {
|
|
|
initData({ current: state.current + 1 })
|
|
initData({ current: state.current + 1 })
|
|
|
}
|
|
}
|
|
|
- const handleFormValues = values => {
|
|
|
|
|
- const newValues = { ...values }
|
|
|
|
|
- switch (values.msgType) {
|
|
|
|
|
- case msgTypeEnum.NotificationOne:
|
|
|
|
|
- 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
|
|
|
|
|
|
|
+ const { run: trySendMessage } = useRequest(sendMessage, {
|
|
|
|
|
+ manual: true,
|
|
|
|
|
+ onSuccess: result => {
|
|
|
|
|
+ tRef.current?.reload()
|
|
|
|
|
+ sendMsg(cmdType.Notice, result)
|
|
|
|
|
+ },
|
|
|
|
|
+ onError: e => {
|
|
|
|
|
+ message.error(e.message)
|
|
|
}
|
|
}
|
|
|
- return newValues
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
return (
|
|
return (
|
|
|
<div className="bg-hex-ffffff rounded-md px-6 pb-6">
|
|
<div className="bg-hex-ffffff rounded-md px-6 pb-6">
|
|
|
<div className="flex justify-between items-center">
|
|
<div className="flex justify-between items-center">
|
|
|
<h4 className="py-4 text-xl">通知中心</h4>
|
|
<h4 className="py-4 text-xl">通知中心</h4>
|
|
|
- <ModalForm
|
|
|
|
|
- isKeyPressSubmit={false}
|
|
|
|
|
- key="modalForm"
|
|
|
|
|
- trigger={
|
|
|
|
|
- <Button type="primary">
|
|
|
|
|
- <Plus className="mr-1" />
|
|
|
|
|
- 新建通知
|
|
|
|
|
- </Button>
|
|
|
|
|
- }
|
|
|
|
|
- initialValues={{ msgType: 'notification', refresh: 0 }}
|
|
|
|
|
- onFinish={async values => {
|
|
|
|
|
- try {
|
|
|
|
|
- const nValues = handleFormValues(values)
|
|
|
|
|
- await trySendMessage(nValues)
|
|
|
|
|
- message.success('添加成功')
|
|
|
|
|
- return true
|
|
|
|
|
- } catch (error) {
|
|
|
|
|
- return false
|
|
|
|
|
- }
|
|
|
|
|
- }}>
|
|
|
|
|
- <ProFormText
|
|
|
|
|
- name="title"
|
|
|
|
|
- label="标题"
|
|
|
|
|
- placeholder="请输入标题"
|
|
|
|
|
- rules={[{ required: true, message: '请输入标题' }]}
|
|
|
|
|
- />
|
|
|
|
|
- <ProForm.Item
|
|
|
|
|
- label="内容"
|
|
|
|
|
- name="content"
|
|
|
|
|
- rules={[{ required: true, message: '请输入通知内容' }]}>
|
|
|
|
|
- <RighEditor />
|
|
|
|
|
- </ProForm.Item>
|
|
|
|
|
- <ProFormRadio.Group
|
|
|
|
|
- label="类型"
|
|
|
|
|
- name="msgType"
|
|
|
|
|
- required
|
|
|
|
|
- options={[
|
|
|
|
|
- { label: '通知', value: msgTypeEnum.NotificationOne },
|
|
|
|
|
- { label: '消息', value: msgTypeEnum.Message }
|
|
|
|
|
- ]}
|
|
|
|
|
- />
|
|
|
|
|
- <ProFormDependency name={['msgType']}>
|
|
|
|
|
- {({ msgType }) =>
|
|
|
|
|
- msgType === msgTypeEnum.NotificationOne ? (
|
|
|
|
|
- <ProFormSelect
|
|
|
|
|
- name="media"
|
|
|
|
|
- label="通知类型"
|
|
|
|
|
- rules={[{ required: true, message: '请选择类型' }]}
|
|
|
|
|
- options={[
|
|
|
|
|
- { label: '版本更新', value: mediaType.VersionUpdate },
|
|
|
|
|
- { label: '节假通知', value: mediaType.HolidayNotice }
|
|
|
|
|
- ]}
|
|
|
|
|
- />
|
|
|
|
|
- ) : null
|
|
|
|
|
- }
|
|
|
|
|
- </ProFormDependency>
|
|
|
|
|
- </ModalForm>
|
|
|
|
|
- {/* <Button type="primary" className="mr-1">
|
|
|
|
|
- <Plus className="mr-1" />
|
|
|
|
|
- 新建通知
|
|
|
|
|
- </Button> */}
|
|
|
|
|
|
|
+ <AddMessage onConfirm={trySendMessage} />
|
|
|
</div>
|
|
</div>
|
|
|
<div id="scrollableDiv" style={{ height: 'calc(100vh - 125px - 3.5rem)', overflowY: 'auto' }}>
|
|
<div id="scrollableDiv" style={{ height: 'calc(100vh - 125px - 3.5rem)', overflowY: 'auto' }}>
|
|
|
<InfiniteScroll
|
|
<InfiniteScroll
|