Jelajahi Sumber

feat: 通知中心控制台

lanjianrong 3 tahun lalu
induk
melakukan
9ea30e9410

+ 6 - 0
config/routes.ts

@@ -80,6 +80,12 @@
         name: 'contact',
         name: 'contact',
         component: './business/Contact',
         component: './business/Contact',
         access: 'authRouteFilter'
         access: 'authRouteFilter'
+      },
+      {
+        path: '/business/notice',
+        name: 'notice',
+        component: './business/Notification',
+        access: 'authRouteFilter'
       }
       }
     ]
     ]
   }
   }

+ 1 - 0
src/locales/zh-CN/menu.ts

@@ -13,6 +13,7 @@ export default {
   'menu.business': '业务参数',
   'menu.business': '业务参数',
   'menu.business.attendance': '考勤',
   'menu.business.attendance': '考勤',
   'menu.business.contact': '客户',
   'menu.business.contact': '客户',
+  'menu.business.notice': '通知中心',
   'menu.login': '登录',
   'menu.login': '登录',
   'menu.register': '注册',
   'menu.register': '注册',
   'menu.register.result': '注册结果',
   'menu.register.result': '注册结果',

+ 115 - 0
src/pages/Business/Notification/index.tsx

@@ -0,0 +1,115 @@
+import React, { useRef } from 'react'
+import { Button, message } from 'antd'
+import { ModalForm, ProFormRadio, 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 'umi'
+import { queryNoticeList, sendNotice } from '@/services/user/api'
+import consts from '@/utils/consts'
+import { PlusOutlined } from '@ant-design/icons'
+
+const Notification: React.FC = () => {
+  const tRef = useRef<ActionType>(null)
+
+  const columns: ProFormColumnsType<API.NoticeItem>[] = [
+    {
+      title: '标题',
+      dataIndex: 'title',
+      width: '30%'
+    },
+    {
+      title: '内容',
+      dataIndex: 'content',
+      width: '50%'
+    },
+    {
+      title: '推送时间',
+      dataIndex: 'createTime',
+      valueType: 'dateTime'
+    }
+  ]
+
+  const { run: trySendNotice } = useRequest(sendNotice, {
+    manual: true,
+    onSuccess: () => {
+      tRef.current?.reload()
+    },
+    onError: e => {
+      message.error(e.message)
+    }
+  })
+  return (
+    <div className="h-full w-full flex flex-row">
+      <ShowTitleMenu options={[{ label: '通知', value: 1 }]} defaultValue={1} />
+      <div className="w-max-3/4">
+        <div className="ml-8 bg-white shadow-md shadow-hex-3e2c5a relative">
+          {/* <div className="pb-3 border-b border-b-black border-opacity-8 mb-3 flex items-center justify-between">
+            <div>通知推送</div>
+          </div> */}
+          <ProTable
+            toolbar={{
+              title: '通知推送'
+            }}
+            actionRef={tRef}
+            columns={columns}
+            params={{ msgType: 1 }}
+            search={false}
+            toolbar={{
+              actions: [
+                <ModalForm
+                  key="modalForm"
+                  trigger={
+                    <Button type="primary">
+                      <PlusOutlined />
+                      新建通知
+                    </Button>
+                  }
+                  initialValues={{ msgType: 1 }}
+                  onFinish={async values => {
+                    try {
+                      await trySendNotice(values)
+                      message.success('添加成功')
+                      return true
+                    } catch (error) {
+                      return false
+                    }
+                  }}>
+                  <ProFormText label="标题" name="title" required />
+                  <ProFormText label="内容" name="content" required />
+                  <ProFormRadio.Group
+                    label="类型"
+                    name="msgType"
+                    required
+                    options={[
+                      { label: '通知', value: 1 },
+                      { label: '消息', value: 2 }
+                    ]}></ProFormRadio.Group>
+                </ModalForm>
+              ]
+            }}
+            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}
+          />
+        </div>
+      </div>
+    </div>
+  )
+}
+
+export default Notification

+ 2 - 1
src/pages/Role/System/index.tsx

@@ -220,7 +220,8 @@ const System = () => {
                           name="business"
                           name="business"
                           options={[
                           options={[
                             { value: 'attendance', label: '考勤', disabled: !showBusiness },
                             { value: 'attendance', label: '考勤', disabled: !showBusiness },
-                            { value: 'contact', label: '客户', disabled: !showBusiness }
+                            { value: 'contact', label: '客户', disabled: !showBusiness },
+                            { value: 'notice', label: '推送', disabled: !showBusiness }
                           ]}
                           ]}
                         />
                         />
                       )}
                       )}

+ 18 - 0
src/services/user/api.ts

@@ -1,5 +1,6 @@
 // @ts-ignore
 // @ts-ignore
 /* eslint-disable */
 /* eslint-disable */
+import { Api } from '@icon-park/react'
 import { request } from 'umi'
 import { request } from 'umi'
 
 
 /** 获取当前的用户 GET /backstage/currentUser */
 /** 获取当前的用户 GET /backstage/currentUser */
@@ -169,3 +170,20 @@ export async function updateBusinessGroup(params: API.UpdateBusinessgroupParam)
     data: params
     data: params
   })
   })
 }
 }
+
+/** 获取通知列表 */
+export async function queryNoticeList(
+  params: API.QueryNoticeListParams
+): API.QueryNoticeListResult {
+  return request('/message/list', {
+    params
+  })
+}
+
+/** 发送通知 */
+export async function sendNotice(params: Api.SendNoticeParams) {
+  return request('/message/send', {
+    method: 'POST',
+    data: params
+  })
+}

+ 24 - 0
src/services/user/typings.d.ts

@@ -252,4 +252,28 @@ declare namespace API {
     parametersType: string
     parametersType: string
     content: string
     content: string
   }
   }
+
+  type QueryNoticeListParams = PageParams & {
+    msgType: 1 | 2
+  }
+
+  type QueryNoticeListResult = {
+    message: NoticeItem[]
+    total: number
+  }
+
+  type NoticeItem = {
+    id: string
+    staffId: string
+    isRead: 0 | 1
+    title: string
+    content: string
+    createTime: string
+  }
+
+  type SendNoticeParams = {
+    title: string
+    content: string
+    msgType: 1 | 2
+  }
 }
 }