群主
diff --git a/src/hooks/useLogin.ts b/src/hooks/useLogin.ts
index 07faa9d..578bb01 100644
--- a/src/hooks/useLogin.ts
+++ b/src/hooks/useLogin.ts
@@ -16,20 +16,13 @@ export const useLogin = () => {
/**
* 登出账号
- * @param isToQrcode 是否返回到二维码页面
*/
- const logout = async (isToQrcode = false) => {
+ const logout = async () => {
const { createWebviewWindow } = useWindow()
- localStorage.removeItem('USER_INFO')
- localStorage.removeItem('TOKEN')
// todo 退出账号 需要关闭其他的全部窗口
await createWebviewWindow('登录', 'login', 320, 448, 'home', false, 320, 448).then(() => {
emit(EventEnum.LOGOUT)
emit('logout_success')
- // 用于跳转到二维码页面
- if (isToQrcode) {
- localStorage.setItem('isToQrcode', '1')
- }
})
}
diff --git a/src/layout/left/components/InfoEdit.vue b/src/layout/left/components/InfoEdit.vue
index e348a16..f58e63a 100644
--- a/src/layout/left/components/InfoEdit.vue
+++ b/src/layout/left/components/InfoEdit.vue
@@ -24,7 +24,20 @@
-
+
+
+
当前佩戴的徽章:
diff --git a/src/layout/left/config.tsx b/src/layout/left/config.tsx
index de06c43..7d13c75 100644
--- a/src/layout/left/config.tsx
+++ b/src/layout/left/config.tsx
@@ -4,10 +4,14 @@ import Mitt from '@/utils/Bus.ts'
import { useLogin } from '@/hooks/useLogin.ts'
import { useSettingStore } from '@/stores/setting.ts'
import apis from '@/services/apis.ts'
+import { LoginStatus, useWsLoginStore } from '@/stores/ws.ts'
+import { useUserStore } from '@/stores/user.ts'
const { createWebviewWindow } = useWindow()
const { logout } = useLogin()
const settingStore = useSettingStore()
+const loginStore = useWsLoginStore()
+const userStore = useUserStore()
const { login } = storeToRefs(settingStore)
/**
* 这里的顶部的操作栏使用pinia写入了localstorage中
@@ -97,7 +101,15 @@ const moreList = ref([
.logout()
.then(async () => {
await logout()
- login.value.accountInfo.token = ''
+ // 如果没有设置自动登录,则清除用户信息
+ if (!login.value.autoLogin) {
+ login.value.accountInfo.token = ''
+ userStore.userInfo = {}
+ localStorage.removeItem('USER_INFO')
+ localStorage.removeItem('TOKEN')
+ }
+ userStore.isSign = false
+ loginStore.loginStatus = LoginStatus.Init
})
.catch(() => {
window.$message.error('退出账号失败')
diff --git a/src/services/apis.ts b/src/services/apis.ts
index 4ae0466..b087e63 100644
--- a/src/services/apis.ts
+++ b/src/services/apis.ts
@@ -47,7 +47,7 @@ export default {
/** 标记消息,点赞等 */
markMsg: (data?: MarkMsgReq) => PUT(urls.markMsg, data),
/** 获取用户详细信息 */
- getUserDetail: () => GET(urls.getUserInfoDetail, {}),
+ getUserDetail: () => GET(urls.getUserInfoDetail),
/** 获取徽章列表 */
getBadgeList: (): Promise => GET(urls.getBadgeList),
/** 设置用户勋章 */
diff --git a/src/services/http.ts b/src/services/http.ts
index a8af1ae..3c05909 100644
--- a/src/services/http.ts
+++ b/src/services/http.ts
@@ -33,9 +33,22 @@ async function Http(
fullResponse?: true,
abort?: AbortController
): Promise<{ data: Promise; resp: Response }> {
+ // 获取token
+ const token = localStorage.getItem('TOKEN')
+
// 构建请求头
const httpHeaders = new Headers(options.headers || {})
+ // 设置Content-Type
+ if (!httpHeaders.has('Content-Type') && !(options.body instanceof FormData)) {
+ httpHeaders.set('Content-Type', 'application/json')
+ }
+
+ // 设置Authorization
+ if (token) {
+ httpHeaders.set('Authorization', `Bearer ${token}`)
+ }
+
// 构建 fetch 请求选项
const fetchOptions: RequestInit = {
method: options.method,
diff --git a/src/services/webSocket.ts b/src/services/webSocket.ts
index fcdc4da..06a3335 100644
--- a/src/services/webSocket.ts
+++ b/src/services/webSocket.ts
@@ -40,11 +40,11 @@ class WS {
worker.postMessage(`{"type":"initWS","value":${token ? `"${token}"` : null}}`)
}
- onWorkerMsg = (e: MessageEvent) => {
+ onWorkerMsg = async (e: MessageEvent) => {
const params: { type: string; value: unknown } = JSON.parse(e.data)
switch (params.type) {
case 'message': {
- this.onMessage(params.value as string)
+ await this.onMessage(params.value as string)
break
}
case 'open': {
@@ -100,7 +100,7 @@ class WS {
}
// 收到消息回调
- onMessage = (value: string) => {
+ onMessage = async (value: string) => {
// FIXME 可能需要 try catch,
const params: { type: WsResponseMessageType; data: unknown } = JSON.parse(value)
const loginStore = useWsLoginStore()
@@ -148,14 +148,14 @@ class WS {
}
])
// 获取用户详情
- chatStore.getSessionList(true)
+ await chatStore.getSessionList(true)
// 自定义表情列表
- emojiStore.getEmojiList()
+ await emojiStore.getEmojiList()
break
}
// 收到消息
case WsResponseMessageType.ReceiveMessage: {
- chatStore.pushMsg(params.data as MessageType)
+ await chatStore.pushMsg(params.data as MessageType)
Mitt.emit(MittEnum.SEND_MESSAGE, params.data)
break
}
diff --git a/src/stores/loginHistory.ts b/src/stores/loginHistory.ts
index 26895b2..8089e6e 100644
--- a/src/stores/loginHistory.ts
+++ b/src/stores/loginHistory.ts
@@ -1,6 +1,6 @@
import { ref } from 'vue'
import { defineStore } from 'pinia'
-import { StoresEnum } from '../enums'
+import { StoresEnum } from '@/enums'
export const useLoginHistoriesStore = defineStore(
StoresEnum.LOGIN_HISTORY,
diff --git a/src/views/LockScreen.vue b/src/views/LockScreen.vue
index c254562..5b7deed 100644
--- a/src/views/LockScreen.vue
+++ b/src/views/LockScreen.vue
@@ -101,7 +101,7 @@
返回
- 退出登录
+ 退出登录
忘记密码
进入系统
diff --git a/src/views/homeWindow/FriendsList.vue b/src/views/homeWindow/FriendsList.vue
index 4e2baeb..9d60636 100644
--- a/src/views/homeWindow/FriendsList.vue
+++ b/src/views/homeWindow/FriendsList.vue
@@ -29,15 +29,28 @@
:key="item.uid">
+
+ {{ useUserInfo(item.uid).value.name?.slice(0, 1) }}
+
+
{{
useUserInfo(item.uid).value.name
diff --git a/src/views/homeWindow/message/index.vue b/src/views/homeWindow/message/index.vue
index c4c359d..d40a284 100644
--- a/src/views/homeWindow/message/index.vue
+++ b/src/views/homeWindow/message/index.vue
@@ -17,7 +17,11 @@
@dblclick="handleMsgDblclick(item)"
@select="$event.click(item)">
-
+
+
+
+ {{ item.name.slice(0, 1) }}
+
diff --git a/src/views/loginWindow/Login.vue b/src/views/loginWindow/Login.vue
index c3d0bce..4790347 100644
--- a/src/views/loginWindow/Login.vue
+++ b/src/views/loginWindow/Login.vue
@@ -151,15 +151,21 @@