outaozhen %!s(int64=3) %!d(string=hai) anos
pai
achega
895ac2f795

+ 2 - 2
src/app.tsx

@@ -160,8 +160,8 @@ export const request: RequestConfig = {
       }
       return response
     }
-  ]
-  // requestInterceptors: [authHeaderInterceptor]
+  ],
+  requestInterceptors: [authHeaderInterceptor]
 }
 
 // ProLayout 支持的api https://procomponents.ant.design/components/layout

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

@@ -0,0 +1,57 @@
+/* eslint-disable react-hooks/rules-of-hooks */
+import { useWebSocket } from 'ahooks'
+import { useEffect, useState } 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
+  console.log(currentUser)
+
+  const [copyCount, setCopyCount] = useState('')
+  const { disconnect, connect, webSocketIns } = useWebSocket(
+    `ws://cld2qa.com/summon/v1/chat/link?username=${currentUser.name}&id=${currentUser.ID}`,
+    {
+      manual: true,
+      onMessage: msg => {
+        const data = JSON.parse(msg.data)
+        if (data.cmd === 1) {
+          setCopyCount(data.CopyCount)
+        }
+      },
+      reconnectLimit: 0,
+      reconnectInterval: 2000
+    }
+  )
+  useEffect(() => {
+    window.addEventListener('beforeunload', () => {
+      disconnect()
+    })
+    if (currentUser && currentUser.staffId) {
+      connect()
+    }
+    return () => {
+      disconnect()
+    }
+  }, [])
+
+  function sendMsg(cmd: cmdType, options: any) {
+    webSocketIns?.send(
+      JSON.stringify({ cmd, userid: `${currentUser.staffId}_${copyCount}`, ...options })
+    )
+  }
+  return { webSocketIns, sendMsg }
+}

+ 3 - 3
src/pages/user/Login/index.tsx

@@ -4,7 +4,7 @@ import React, { useState } from 'react'
 import ProForm, { ProFormCheckbox, ProFormText } from '@ant-design/pro-form'
 import { useIntl, Link, history, FormattedMessage, SelectLang, useModel, useRequest } from 'umi'
 import { login } from '@/services/api/login'
-import { queryAcountList } from '@/services/api/institution'
+import { currentAccount as querycurrentAccount } from '@/services/api/login'
 import consts from '@/utils/consts'
 import styles from './index.less'
 
@@ -37,12 +37,12 @@ const Login: React.FC = () => {
   const [type, setType] = useState<string>('account')
   const { initialState, setInitialState } = useModel('@@initialState')
 
-  const { run, loading } = useRequest(queryAcountList, {
+  const { run, loading } = useRequest(querycurrentAccount, {
     manual: true,
     onSuccess: async result => {
       setInitialState({
         ...initialState,
-        currentUser: result.items
+        currentUser: result.currentAccount
       })
       goto()
     }

+ 7 - 3
src/services/api/login.ts

@@ -1,8 +1,12 @@
 import { request } from 'umi'
 
-// export async function login(params: API.LoginParams) {
-//   return request.post('/login', { data: params })
-// }
+/** 获取当前的用户 GET /backstage/currentUser */
+export async function currentAccount() {
+  return request<API.AurrentAccount>('/login/account', {
+    method: 'GET'
+  })
+}
+
 /** 登录 */
 export async function login(body: API.LoginParams) {
   return request<API.LoginResult>('/login', {

+ 18 - 0
src/services/api/typings.d.ts

@@ -215,4 +215,22 @@ declare namespace API {
     code: number
     msg: number
   }
+
+  type AurrentAccount = {
+    ID: string
+    createdTime: number
+    accountType: string
+    account: string
+    name: string
+    phone: string
+    institution: {
+      ID: string
+      name: string
+    }
+    created: string
+    createdID: string
+    id: string
+    dataID: string
+    gender: string
+  }
 }