diff --git a/src/components/rightBox/Details.vue b/src/components/rightBox/Details.vue index d85207e..96ef860 100644 --- a/src/components/rightBox/Details.vue +++ b/src/components/rightBox/Details.vue @@ -1,13 +1,15 @@ @@ -104,20 +94,12 @@ import { LimitEnum, MsgEnum } from '@/enums' import { useCommon } from '@/hooks/useCommon.ts' import { WebviewWindow } from '@tauri-apps/api/webviewWindow' import { emit } from '@tauri-apps/api/event' -import { useLogin } from '@/hooks/useLogin.ts' -import { useSettingStore } from '@/stores/setting.ts' -const { logout } = useLogin() const { open, onChange, reset } = useFileDialog() -const { login } = useSettingStore() const MsgInputRef = ref() const msgInputDom = ref() const emojiShow = ref() const { insertNode, triggerInputEvent, getEditorRange, imgPaste, FileOrVideoPaste } = useCommon() -/** - * 是否为游客模式 - */ -const isGuest = computed(() => login.accountInfo.token === 'test') /** * 选择表情,并把表情插入输入框 @@ -185,13 +167,6 @@ onMounted(() => { } } -.fuzzy { - @apply bg-transparent select-none cursor-default size-full absolute-flex-center; - overflow: hidden; - backdrop-filter: blur(8px); - -webkit-backdrop-filter: blur(8px); -} - :deep(.n-input .n-input-wrapper) { padding: 0; } diff --git a/src/components/rightBox/chatBox/ChatMain.vue b/src/components/rightBox/chatBox/ChatMain.vue index d8551f0..90b7c63 100644 --- a/src/components/rightBox/chatBox/ChatMain.vue +++ b/src/components/rightBox/chatBox/ChatMain.vue @@ -99,6 +99,7 @@ round v-if="avatarExists(item.fromUser.uid)" :size="34" + :color="'#909090'" @click="selectKey = item.message.id" class="select-none" :src="getAvatarSrc(item.fromUser.uid)" diff --git a/src/components/rightBox/chatBox/ChatSidebar.vue b/src/components/rightBox/chatBox/ChatSidebar.vue index 4c1d219..c41f495 100644 --- a/src/components/rightBox/chatBox/ChatSidebar.vue +++ b/src/components/rightBox/chatBox/ChatSidebar.vue @@ -65,6 +65,7 @@ :special-menu="report"> + + + {{ item.name.slice(0, 1) }} + {{ item.name }}
群主 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 @@