瀏覽代碼

feat: 优化版本通知触发条件

lanjianrong 3 年之前
父節點
當前提交
a09e2fc88f

+ 5 - 0
config/proxy.ts

@@ -12,6 +12,11 @@ export default {
       changeOrigin: true,
       pathRewrite: { '^': '' }
     }
+    // '/192.168.1.26/': {
+    //   target: 'ws://192.168.1.26:8848/',
+    //   changeOrigin: true,
+    //   pathRewrite: { '^': '' }
+    // }
   },
   test: {
     '/api/': {

+ 44 - 0
src/hooks/core/useWebSocketFn.ts

@@ -0,0 +1,44 @@
+/* eslint-disable react-hooks/rules-of-hooks */
+import { useWebSocket } from 'ahooks'
+import { useEffect } from 'react'
+import { useModel } from 'umi'
+
+export enum cmdType {
+  Single = 10,
+  Group = 11,
+  OnlineList = 12,
+  Notice = 13
+}
+
+export enum noticeType {
+  Notice = 1,
+  Message = 2
+}
+
+export default function useWebSocketFn() {
+  const { initialState } = useModel('@@initialState')
+
+  const { currentUser } = initialState
+
+  const { disconnect, connect, webSocketIns } = useWebSocket(
+    `ws://cld2qa.com/summon/v1/chat/link?username=${currentUser.username}&id=${currentUser.staffId}`,
+    {
+      manual: true,
+      reconnectLimit: 3,
+      reconnectInterval: 2000
+    }
+  )
+  useEffect(() => {
+    if (currentUser && currentUser.staffId) {
+      connect()
+    }
+    return () => {
+      disconnect()
+    }
+  }, [])
+
+  function sendMsg(cmd: cmdType, options: any) {
+    webSocketIns?.send(JSON.stringify({ cmd, userid: currentUser.staffId, ...options }))
+  }
+  return { webSocketIns, sendMsg }
+}

+ 76 - 8
src/pages/Business/Notification/index.tsx

@@ -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>
               ]
             }}

+ 18 - 8
src/pages/Role/Customer/index.tsx

@@ -221,7 +221,7 @@ const Customer = () => {
                       label={
                         <span className="flex items-center">
                           <EveryUser className="mr-1" className="flex items-baseline mr-1" />
-                          联系人
+                          客户
                         </span>
                       }
                     />
@@ -232,8 +232,13 @@ const Customer = () => {
                           name="client"
                           options={[
                             { value: 'access', label: '查看', disabled: !showClient },
-                            { value: 'add', label: '添加联系人', disabled: !showClient },
-                            { value: 'delete', label: '删除联系人', disabled: !showClient }
+                            { value: 'add', label: '添加客户', disabled: !showClient },
+                            // { value: 'delete', label: '删除客户', disabled: !showClient },
+                            {
+                              value: 'edit_team_tags',
+                              label: '编辑协作标签',
+                              disabled: !showClient
+                            }
                           ]}
                         />
                       )}
@@ -250,7 +255,7 @@ const Customer = () => {
                       label={
                         <span className="flex items-center">
                           <EveryUser className="mr-1" className="flex items-baseline mr-1" />
-                          客户
+                          单位
                         </span>
                       }
                     />
@@ -262,8 +267,13 @@ const Customer = () => {
                           name="company"
                           options={[
                             { value: 'access', label: '查看', disabled: !showCompany },
-                            { value: 'add', label: '添加客户', disabled: !showCompany },
-                            { value: 'delete', label: '删除客户', disabled: !showCompany }
+                            { value: 'add', label: '添加单位', disabled: !showCompany },
+                            // { value: 'delete', label: '删除单位', disabled: !showCompany },
+                            {
+                              value: 'edit_team_tags',
+                              label: '编辑协作标签',
+                              disabled: !showCompany
+                            }
                           ]}
                         />
                       )}
@@ -291,8 +301,8 @@ const Customer = () => {
                           name="business"
                           options={[
                             { value: 'access', label: '查看', disabled: !showBusiness },
-                            { value: 'add', label: '添加商机', disabled: !showBusiness },
-                            { value: 'delete', label: '删除商机', disabled: !showBusiness }
+                            { value: 'add', label: '添加商机', disabled: !showBusiness }
+                            // { value: 'delete', label: '删除商机', disabled: !showBusiness }
                           ]}
                         />
                       )}

+ 3 - 1
src/pages/Role/Hr/index.tsx

@@ -224,7 +224,9 @@ const Hr = () => {
                           options={[
                             { value: 'access', label: '查看', disabled: !showEmployee },
                             { value: 'add', label: '添加', disabled: !showEmployee },
-                            { value: 'delete', label: '删除', disabled: !showEmployee }
+                            { value: 'delete', label: '删除', disabled: !showEmployee },
+                            { value: 'add_department', label: '新增部门', disabled: !showEmployee },
+                            { value: 'del_department', label: '删除部门', disabled: !showEmployee }
                           ]}
                         />
                       )}