fix(global): 🐛 修改全局使用到的一些类型为string

closed #211
This commit is contained in:
Dawn
2025-02-27 22:29:45 +08:00
parent 5cb9bfc41e
commit 3333aa0eb7
40 changed files with 232 additions and 223 deletions
+1 -1
View File
@@ -2236,7 +2236,7 @@ checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9"
[[package]]
name = "hula"
version = "2.6.3"
version = "2.6.5"
dependencies = [
"base64 0.22.1",
"lazy_static",
+1 -1
View File
@@ -1,6 +1,6 @@
[package]
name = "hula"
version = "2.6.3"
version = "2.6.5"
description = "hula"
authors = ["nongyehong"]
license = ""
+5 -5
View File
@@ -52,7 +52,7 @@
</template>
<div
v-if="useUserInfo(uid).value.wearingItemId === 6"
v-if="useUserInfo(uid).value.wearingItemId === '6'"
class="absolute top-72px left-142px bg-[--bate-bg] border-(1px solid [--bate-color]) text-(12px [--bate-color] center) font-bold p-8px rounded-full">
HuLa开发工程师
</div>
@@ -132,7 +132,7 @@ import { storeToRefs } from 'pinia'
import { useWindow } from '@/hooks/useWindow'
const { uid, activeStatus } = defineProps<{
uid: number
uid: string
activeStatus?: OnlineEnum
}>()
const { createWebviewWindow } = useWindow()
@@ -155,7 +155,7 @@ const statusIcon = computed(() => {
const userStateId = userInfo.userStateId
// 如果在线且有特殊状态
if (userStateId && userStateId > 1) {
if (userStateId && userStateId !== '1') {
const state = stateList.value.find((s) => s.id === userStateId)
if (state) {
return state.url
@@ -169,7 +169,7 @@ const currentStateTitle = computed(() => {
const userInfo = useUserInfo(uid).value
const userStateId = userInfo.userStateId
if (userStateId && userStateId > 1) {
if (userStateId && userStateId !== '1') {
const state = stateList.value.find((s) => s.id === userStateId)
if (state) {
return state.title
@@ -191,7 +191,7 @@ const addFriend = async () => {
// 注入 enableAllScroll 方法
const { enableScroll } = inject('popoverControls', { enableScroll: () => {} })
const handleOpenMsgSession = async (uid: number) => {
const handleOpenMsgSession = async (uid: string) => {
enableScroll() // 在打开新会话前恢复所有滚动
await openMsgSession(uid)
}
+2 -2
View File
@@ -62,14 +62,14 @@ import { AvatarUtils } from '@/utils/AvatarUtils'
import { usePopover } from '@/hooks/usePopover'
const contactStore = useContactStore()
const currentUserId = ref(0)
const currentUserId = ref('0')
const loading = ref(false)
const { handlePopoverUpdate, enableScroll } = usePopover(currentUserId, 'friend-request-scrollbar')
provide('popoverControls', { enableScroll })
const avatarSrc = (url: string) => AvatarUtils.getAvatarUrl(url)
const handleAgree = async (applyId: number) => {
const handleAgree = async (applyId: string) => {
loading.value = true
contactStore.onAcceptFriend(applyId).then(() => {
setTimeout(() => {
+1 -1
View File
@@ -145,7 +145,7 @@ const footerOptions = ref<OPT.Details[]>([
console.log(content)
// TODO 需要增加独立窗口功能 (nyh -> 2024-03-25 16:01:23)
//群聊传群id
let id = 0
let id = '0'
if (type === RoomTypeEnum.GROUP) {
id = item.value.roomId
} else {
+1 -1
View File
@@ -262,7 +262,7 @@ const closeMenu = (event: any) => {
onMounted(async () => {
onKeyStroke('Enter', () => {
if (ait.value && selectedAitKey.value > -1) {
if (ait.value && Number(selectedAIKey.value) > -1) {
const item = personList.value.find((item) => item.uid === selectedAitKey.value) as CacheUserItem
handleAit(item)
} else if (aiDialogVisible.value && Number(selectedAIKey.value) > -1) {
@@ -277,7 +277,8 @@ const userList = computed(() => {
}
})
.sort((a, b) => {
return a.uid - b.uid // 根据 uid 升序排序
// 将uid转换为数字进行比较
return Number(a.uid) - Number(b.uid)
})
.slice(0, 10)
})
@@ -376,7 +377,7 @@ const handleConfirm = () => {
// TODO: 删除后当前删除的人提示不准确,无论是删除方还是被删除方都提示“您已被对方拉黑”
})
} else if (optionsType.value === RoomActEnum.EXIT_GROUP) {
if (activeItem.roomId === 1) {
if (activeItem.roomId === '1') {
window.$message.warning('无法退出频道')
modalShow.value = false
return
+8 -8
View File
@@ -185,7 +185,7 @@
<!-- 用户徽章 -->
<n-popover
v-if="
currentRoomId === 1 &&
currentRoomId === '1' &&
useBadgeInfo(useUserInfo(item.fromUser.uid).value.wearingItemId).value.img
"
trigger="hover">
@@ -457,7 +457,7 @@ const currentRoomId = computed(() => globalStore.currentSession?.roomId)
/** 是否是超级管理员 */
// const isAdmin = computed(() => userInfo?.power === PowerEnum.ADMIN)
/** 跳转回复消息后选中效果 */
const activeReply = ref(-1)
const activeReply = ref('')
/** item最小高度,用于计算滚动大小和位置 */
const itemSize = computed(() => (chatStore.isGroup ? 90 : 76))
/** 虚拟列表 */
@@ -629,7 +629,7 @@ const handleTransitionComplete = () => {
}
/** 获取用户头像 */
const getAvatarSrc = (uid: number) => {
const getAvatarSrc = (uid: string) => {
const avatar = uid === userUid.value ? userStore.userInfo.avatar : useUserInfo(uid).value.avatar
return AvatarUtils.getAvatarUrl(avatar as string)
}
@@ -683,7 +683,7 @@ const handleEmojiSelect = (label: string, item: any) => {
// }
/** 跳转到回复消息 */
const jumpToReplyMsg = (key: number) => {
const jumpToReplyMsg = (key: string) => {
nextTick(() => {
// 找到对应消息的索引
const messageIndex = chatMessageList.value.findIndex((msg) => msg.message.id === key)
@@ -744,7 +744,7 @@ const handleMacSelect = (event: any) => {
const closeMenu = (event: any) => {
if (!event.target.matches('.bubble', 'bubble-oneself')) {
activeBubble.value = -1
activeBubble.value = ''
// 解决mac右键会选中文本的问题
if (isMac.value && recordEL.value) {
recordEL.value.classList.remove('select-none')
@@ -759,7 +759,7 @@ const closeMenu = (event: any) => {
activeReplyElement.classList.add('reply-exit')
delay(() => {
activeReplyElement.classList.remove('reply-exit')
activeReply.value = -1
activeReply.value = ''
}, 300)
}
})
@@ -772,7 +772,7 @@ const handleRetry = (item: any) => {
console.log('重试发送消息:', item)
}
const canReEdit = computed(() => (msgId: number) => {
const canReEdit = computed(() => (msgId: string) => {
const recalledMsg = chatStore.getRecalledMessage(msgId)
const message = chatStore.getMessage(msgId)
if (!recalledMsg || !message) return false
@@ -781,7 +781,7 @@ const canReEdit = computed(() => (msgId: number) => {
return message.fromUser.uid === userUid.value
})
const handleReEdit = (msgId: number) => {
const handleReEdit = (msgId: string) => {
const recalledMsg = chatStore.getRecalledMessage(msgId)
if (recalledMsg) {
useMitt.emit(MittEnum.RE_EDIT, recalledMsg.content)
@@ -286,7 +286,7 @@ const handleSelect = () => {
const userStatusStore = useUserStatusStore()
const { stateList } = storeToRefs(userStatusStore)
const getUserState = (stateId: number) => {
const getUserState = (stateId: string) => {
return stateList.value.find((state) => state.id === stateId)
}
+6 -6
View File
@@ -6,11 +6,11 @@ import { useCachedStore } from '@/stores/cached'
* @param uid 用户 ID
* @description 引入该Hook后,可响应式获取用户信息
*/
export const useUserInfo = (uid?: number | ComputedRef<number | undefined> | Ref<number>) => {
export const useUserInfo = (uid?: string | ComputedRef<string | undefined> | Ref<string>) => {
const cachedStore = useCachedStore()
const userInfo = computed(() => (uid && cachedStore.userCachedList[toValue(uid as number)]) || {})
const userInfo = computed(() => (uid && cachedStore.userCachedList[toValue(uid as string)]) || {})
// 如果没有就请求
const resultUid = toValue(uid as number)
const resultUid = toValue(uid as string)
if (resultUid && Object.keys(userInfo.value).length === 0) {
cachedStore.getBatchUserInfo([resultUid])
}
@@ -22,11 +22,11 @@ export const useUserInfo = (uid?: number | ComputedRef<number | undefined> | Ref
* @param itemId 用户徽章ID
* @description 引入该Hook后,可响应式获取用户徽章信息
*/
export const useBadgeInfo = (itemId?: number | ComputedRef<number | undefined>) => {
export const useBadgeInfo = (itemId?: string | ComputedRef<number | undefined>) => {
const cachedStore = useCachedStore()
const badgeInfo = computed(() => (itemId && cachedStore.badgeCachedList[toValue(itemId as number)]) || {})
const badgeInfo = computed(() => (itemId && cachedStore.badgeCachedList[toValue(itemId as string)]) || {})
// 如果没有就请求
const resultItemId = toValue(itemId as number)
const resultItemId = toValue(itemId as string)
if (resultItemId && Object.keys(badgeInfo.value).length === 0) {
cachedStore.getBatchBadgeInfo([resultItemId])
}
+7 -7
View File
@@ -34,13 +34,13 @@ export const useChatMain = () => {
/** 是否是超级管理员 */
// const isAdmin = computed(() => userInfo?.power === PowerEnum.ADMIN)
/** 选中的气泡消息 */
const activeBubble = ref(-1)
const activeBubble = ref('')
/** 提醒框标题 */
const tips = ref()
/** 是否显示删除信息的弹窗 */
const modalShow = ref(false)
/** 需要删除信息的下标 */
const delIndex = ref(0)
const delIndex = ref('')
/** 悬浮的页脚 */
const floatFooter = ref(false)
/** 记录历史消息下标 */
@@ -67,7 +67,7 @@ export const useChatMain = () => {
label: '撤回',
icon: 'corner-down-left',
click: async (item: MessageType) => {
const res = (await apis.recallMsg({ roomId: 1, msgId: item.message.id })) as any
const res = (await apis.recallMsg({ roomId: '1', msgId: item.message.id })) as any
if (res) {
window.$message.error(res)
return
@@ -263,7 +263,7 @@ export const useChatMain = () => {
// 2. 检查房间号是否为1(频道)
const roomId = globalStore.currentSession?.roomId
if (!roomId || roomId === 1) return false
if (!roomId || roomId === '1') return false
// 3. 获取目标用户ID
const targetUid = item.uid || item.fromUser?.uid
@@ -299,7 +299,7 @@ export const useChatMain = () => {
// 2. 检查房间号是否为1(频道)
const roomId = globalStore.currentSession?.roomId
if (!roomId || roomId === 1) return false
if (!roomId || roomId === '1') return false
// 3. 获取目标用户ID
const targetUid = item.uid || item.fromUser?.uid
@@ -340,7 +340,7 @@ export const useChatMain = () => {
// 2. 检查房间号是否为1(频道)
const roomId = globalStore.currentSession?.roomId
if (!roomId || roomId === 1) return false
if (!roomId || roomId === '1') return false
// 3. 获取目标用户ID
const targetUid = item.uid || item.fromUser?.uid
@@ -391,7 +391,7 @@ export const useChatMain = () => {
* @param uid 用户ID
* @param type 检查类型: 'friend' - 仅好友, 'all' - 好友或自己
*/
const checkFriendRelation = (uid: number, type: 'friend' | 'all' = 'all') => {
const checkFriendRelation = (uid: string, type: 'friend' | 'all' = 'all') => {
const contactStore = useContactStore()
const userStore = useUserStore()
const myUid = userStore.userInfo.uid
+1 -1
View File
@@ -687,7 +687,7 @@ export const useCommon = () => {
* @param uid 用户id
* @param type
*/
const openMsgSession = async (uid: number, type: number = 2) => {
const openMsgSession = async (uid: string, type: number = 2) => {
// 获取home窗口实例
const label = await WebviewWindow.getCurrent().label
if (route.name !== '/message' && label === 'home') {
+1 -1
View File
@@ -64,7 +64,7 @@ export const useLogin = () => {
userStore.userInfo = {}
loginStore.loginStatus = LoginStatus.Init
// 3. 重置当前会话为默认值
globalStore.currentSession.roomId = 1
globalStore.currentSession.roomId = '1'
globalStore.currentSession.type = RoomTypeEnum.GROUP
// 4. 清除未读数
chatStore.clearUnreadCount()
+7 -7
View File
@@ -40,8 +40,8 @@ export const useMessage = () => {
// 只有在消息页面且有未读消息时,才标记为已读
if (route.path === '/message' && item.unreadCount > 0) {
apis.markMsgRead({ roomId: item.roomId || 1 }).then(() => {
chatStore.markSessionRead(item.roomId || 1)
apis.markMsgRead({ roomId: item.roomId || '1' }).then(() => {
chatStore.markSessionRead(item.roomId || '1')
// 更新全局未读计数
globalStore.updateGlobalUnreadCount()
})
@@ -52,7 +52,7 @@ export const useMessage = () => {
* 删除会话
* @param roomId 会话信息
*/
const handleMsgDelete = async (roomId: number) => {
const handleMsgDelete = async (roomId: string) => {
const currentSessions = chatStore.sessionList
const currentIndex = currentSessions.findIndex((session) => session.roomId === roomId)
@@ -191,7 +191,7 @@ export const useMessage = () => {
icon: 'delete',
click: async (item: SessionItem) => {
// 不允许解散频道(roomId === 1)
if (item.roomId === 1) {
if (item.roomId === '1') {
window.$message.warning('无法解散频道')
return
}
@@ -209,7 +209,7 @@ export const useMessage = () => {
// 如果不是群聊,不显示
if (item.type !== RoomTypeEnum.GROUP) return false
// 如果是频道,不显示
if (item.roomId === 1) return false
if (item.roomId === '1') return false
// 只有群主才能看到解散群聊选项
return item.operate === SessionOperateEnum.DISSOLUTION_GROUP
}
@@ -219,7 +219,7 @@ export const useMessage = () => {
icon: 'logout',
click: async (item: SessionItem) => {
// 不允许退出频道(roomId === 1)
if (item.roomId === 1) {
if (item.roomId === '1') {
window.$message.warning('无法退出频道')
return
}
@@ -236,7 +236,7 @@ export const useMessage = () => {
// 如果不是群聊,不显示
if (item.type !== RoomTypeEnum.GROUP) return false
// 如果是频道,不显示
if (item.roomId === 1) return false
if (item.roomId === '1') return false
// 如果是群主,不显示退出选项(群主应该看到解散群聊选项)
return item.operate === SessionOperateEnum.EXIT_GROUP
}
+1 -1
View File
@@ -24,7 +24,7 @@ export const useMockMessage = () => {
const currentTimeStamp: number = Date.now()
const random: number = Math.floor(Math.random() * 15)
// 唯一id 后五位时间戳+随机数
const uniqueId: number = Number(String(currentTimeStamp).slice(-7) + random)
const uniqueId = String(currentTimeStamp).slice(-7) + random
const { uid = 0, name: username = '', avatar = '' } = userInfo.value || {}
return {
+3 -3
View File
@@ -194,8 +194,8 @@ export const useMsgInput = (messageInputDom: Ref) => {
* @param userList 用户列表
* @returns 被 @ 用户的uid数组
*/
const extractAtUserIds = (content: string, userList: BaseUserItem[]): number[] => {
const atUserIds: number[] = []
const extractAtUserIds = (content: string, userList: BaseUserItem[]): string[] => {
const atUserIds: string[] = []
// 创建临时DOM元素来解析HTML
const tempDiv = document.createElement('div')
@@ -285,7 +285,7 @@ export const useMsgInput = (messageInputDom: Ref) => {
const msg = await messageStrategy.getMsg(msgInput.value, reply.value)
const atUidList = extractAtUserIds(msgInput.value, cachedStore.currentAtUsersList)
const tempMsgId = Date.now()
const tempMsgId = Date.now().toString()
// 根据消息类型创建消息体
const messageBody = {
+2 -2
View File
@@ -1,7 +1,7 @@
import { Ref } from 'vue'
/**! 这个是暂时用来解决在n-scrollbar中使用n-virtual-list使用n-popover时候滚动出现原生滚动条的方法 */
export const usePopover = (selectKey: Ref<number>, id: string) => {
export const usePopover = (selectKey: Ref<string>, id: string) => {
/**! 暂时使用这些方法来阻止popover显示时候的滚动行为 */
// 禁止滚动的默认行为
const preventDefault = (e: Event) => e.preventDefault()
@@ -20,7 +20,7 @@ export const usePopover = (selectKey: Ref<number>, id: string) => {
}
}
const handlePopoverUpdate = (key: number, show?: boolean) => {
const handlePopoverUpdate = (key: string, show?: boolean) => {
const scrollbar = document.querySelector(`#${id}`) as HTMLElement
if (!scrollbar) return
+1 -1
View File
@@ -16,7 +16,7 @@ export const options = computed(() =>
export const createGroup = async (selectedUids: string[]) => {
try {
const uidList = selectedUids.map((uid) => Number(uid))
const uidList = selectedUids.map((uid) => String(uid))
const result = await apis.createGroup({ uidList })
return result
} catch (error) {
+5 -6
View File
@@ -118,7 +118,7 @@ useMitt.on(WsResponseMessageType.LOGIN_SUCCESS, (data: LoginSuccessResType) => {
}
])
})
useMitt.on(WsResponseMessageType.USER_STATE_CHANGE, async (data: { uid: number; userStateId: number }) => {
useMitt.on(WsResponseMessageType.USER_STATE_CHANGE, async (data: { uid: string; userStateId: string }) => {
console.log('收到用户状态改变', data)
await cachedStore.updateUserState(data)
})
@@ -143,7 +143,7 @@ useMitt.on(WsResponseMessageType.TOKEN_EXPIRED, async (wsTokenExpire: WsTokenExp
await logout()
}
})
useMitt.on(WsResponseMessageType.INVALID_USER, (param: { uid: number }) => {
useMitt.on(WsResponseMessageType.INVALID_USER, (param: { uid: string }) => {
console.log('无效用户')
const data = param
// 消息列表删掉拉黑的发言
@@ -159,11 +159,10 @@ useMitt.on(WsResponseMessageType.MSG_RECALL, (data: RevokedMsgType) => {
})
useMitt.on(WsResponseMessageType.RECEIVE_MESSAGE, async (data: MessageType) => {
chatStore.pushMsg(data)
console.log('接收消息', data)
// 接收到通知就设置图标闪烁
const username = useUserInfo(data.fromUser.uid).value.name!
// 不是自己发的消息才通知
if (data.fromUser.uid !== userStore.userInfo.uid) {
if (Number(data.fromUser.uid) !== Number(userStore.userInfo.uid)) {
await emitTo('tray', 'show_tip')
await emitTo('notify', 'notify_cotent', data)
const throttleSendNotification = useThrottleFn(() => {
@@ -193,8 +192,8 @@ useMitt.on(WsResponseMessageType.REQUEST_NEW_FRIEND, async (data: { uid: number;
useMitt.on(
WsResponseMessageType.NEW_FRIEND_SESSION,
(param: {
roomId: number
uid: number
roomId: string
uid: string
changeType: ChangeTypeEnum
activeStatus: OnlineEnum
lastOptTime: number
+1 -1
View File
@@ -104,7 +104,7 @@ const info = ref({
password: '',
avatar: '',
name: '',
uid: 0
uid: ''
})
const accountPH = ref('输入HuLa账号')
const passwordPH = ref('输入HuLa密码')
+23 -23
View File
@@ -53,79 +53,79 @@ export default {
/** 获取徽章列表 */
getBadgeList: () => GET<BadgeType>(urls.getBadgeList),
/** 设置用户勋章 */
setUserBadge: (badgeId: number) => PUT<void>(urls.setUserBadge, { badgeId }),
setUserBadge: (badgeId: string) => PUT<void>(urls.setUserBadge, { badgeId }),
/** 修改用户名 */
modifyUserName: (name: string) => PUT<void>(urls.modifyUserName, { name }),
/** 撤回消息 */
recallMsg: (data: { msgId: number; roomId: number }) => PUT<void>(urls.recallMsg, data),
recallMsg: (data: { msgId: string; roomId: string }) => PUT<void>(urls.recallMsg, data),
/** 拉黑用户 */
blockUser: (data: { uid: number }) => PUT<void>(urls.blockUser, data),
blockUser: (data: { uid: string }) => PUT<void>(urls.blockUser, data),
/** 获取临时上传链接 */
getUploadUrl: (params: any) => GET<{ downloadUrl: string; uploadUrl: string }>(urls.fileUpload, params),
/** 上传头像 */
uploadAvatar: (data: { avatar: string }) => POST<void>(urls.uploadAvatar, data),
/** 新增表情包 */
addEmoji: (data: { uid: number; expressionUrl: string }) => POST<MessageType>(urls.addEmoji, data),
addEmoji: (data: { uid: string; expressionUrl: string }) => POST<MessageType>(urls.addEmoji, data),
/** 获取表情 **/
getEmoji: (params: { uid: number }) => GET<EmojiItem[]>(urls.getEmoji, { params }),
getEmoji: (params: { uid: string }) => GET<EmojiItem[]>(urls.getEmoji, { params }),
/** 删除Emoji */
deleteEmoji: (params: { id: number }) => DELETE<EmojiItem[]>(urls.deleteEmoji, params),
deleteEmoji: (params: { id: string }) => DELETE<EmojiItem[]>(urls.deleteEmoji, params),
/** 获取联系人列表 */
getContactList: (params?: any) => GET<ListResponse<ContactItem>>(urls.getContactList, params),
/** 获取好友申请列表 */
requestFriendList: (params?: any) => GET<ListResponse<RequestFriendItem>>(urls.requestFriendList, params),
/** 发送添加好友请求 */
sendAddFriendRequest: (params: { targetUid: number; msg: string }) => POST(urls.sendAddFriendRequest, params),
sendAddFriendRequest: (params: { targetUid: string; msg: string }) => POST(urls.sendAddFriendRequest, params),
/** 同意好友申请 */
applyFriendRequest: (params: { applyId: number }) => PUT(urls.sendAddFriendRequest, params),
applyFriendRequest: (params: { applyId: string }) => PUT(urls.sendAddFriendRequest, params),
/** 删除好友 */
deleteFriend: (params: { targetUid: number }) => DELETE(urls.deleteFriend, params),
deleteFriend: (params: { targetUid: string }) => DELETE(urls.deleteFriend, params),
/** 好友申请未读数 */
newFriendCount: () => GET<{ unReadCount: number }>(urls.newFriendCount),
/** 会话列表 */
getSessionList: (params?: any) => GET<ListResponse<SessionItem>>(urls.getSessionList, params),
/** 消息的已读未读列表 */
getMsgReadList: (params?: any) => GET<ListResponse<{ uid: number }>>(urls.getMsgReadList, params),
getMsgReadList: (params?: any) => GET<ListResponse<{ uid: string }>>(urls.getMsgReadList, params),
/** 消息已读未读数 */
getMsgReadCount: (params?: any) => GET<MsgReadUnReadCountType[]>(urls.getMsgReadCount, params),
/** 消息阅读上报 */
markMsgRead: (params?: any) => PUT<MsgReadUnReadCountType[]>(urls.getMsgReadCount, params),
/** 新增群组 */
createGroup: (params: { uidList: number[] }) => POST<{ id: number }>(urls.createGroup, params),
createGroup: (params: { uidList: string[] }) => POST<{ id: number }>(urls.createGroup, params),
/** 邀请群成员 */
inviteGroupMember: (params: { roomId: number; uidList: number[] }) => POST(urls.inviteGroupMember, params),
inviteGroupMember: (params: { roomId: string; uidList: string[] }) => POST(urls.inviteGroupMember, params),
/** 删除群成员 */
removeGroupMember: (params: { roomId: number; uid: number }) => DELETE(urls.inviteGroupMember, params),
removeGroupMember: (params: { roomId: string; uid: string }) => DELETE(urls.inviteGroupMember, params),
/** 群组详情 */
groupDetail: (params: { id: number }) => GET<GroupDetailReq>(urls.groupDetail, params),
groupDetail: (params: { id: string }) => GET<GroupDetailReq>(urls.groupDetail, params),
/** 群聊列表 */
groupList: (params: { current: number; size: number }) => GET<PageInfo<GroupListReq>>(urls.groupList, params),
/** 会话详情 */
sessionDetail: (params: { id: number }) => GET<SessionItem>(urls.sessionDetail, params),
sessionDetail: (params: { id: string }) => GET<SessionItem>(urls.sessionDetail, params),
/** 会话详情(联系人列表发消息用) */
sessionDetailWithFriends: (params: { id: number; roomType: number }) =>
sessionDetailWithFriends: (params: { id: string; roomType: number }) =>
GET<SessionItem>(urls.sessionDetailWithFriends, params),
/** 设置会话置顶 */
setSessionTop: (params: { roomId: number; top: boolean }) => POST<void>(urls.setSessionTop, params),
setSessionTop: (params: { roomId: string; top: boolean }) => POST<void>(urls.setSessionTop, params),
/** 删除会话 */
deleteSession: (params: { roomId: number }) => DELETE<void>(urls.deleteSession, params),
deleteSession: (params: { roomId: string }) => DELETE<void>(urls.deleteSession, params),
/** 修改群信息 */
updateRoomInfo: (params: { roomId: number; roomName: string; roomAvatar: string }) =>
updateRoomInfo: (params: { roomId: string; roomName: string; roomAvatar: string }) =>
POST<void>(urls.updateRoomInfo, params),
/** 添加群管理 */
addAdmin: ({ roomId, uidList }: { roomId: number; uidList: number[] }) =>
addAdmin: ({ roomId, uidList }: { roomId: string; uidList: string[] }) =>
PUT<boolean>(urls.addAdmin, {
roomId,
uidList
}),
/** 撤销群管理 */
revokeAdmin: ({ roomId, uidList }: { roomId: number; uidList: number[] }) =>
revokeAdmin: ({ roomId, uidList }: { roomId: string; uidList: string[] }) =>
DELETE<boolean>(urls.revokeAdmin, {
roomId,
uidList
}),
/** 退群 */
exitGroup: ({ roomId }: { roomId: number }) =>
exitGroup: ({ roomId }: { roomId: string }) =>
DELETE<boolean>(urls.exitGroup, {
roomId
}),
@@ -140,5 +140,5 @@ export default {
/** 获取所有用户状态 */
getAllUserState: () => GET<API.UserState[]>(urls.getAllUserState),
/** 用户状态改变 */
changeUserState: (userStateId: number) => POST(`${urls.changeUserState}/${userStateId}`)
changeUserState: (userStateId: string) => POST(`${urls.changeUserState}/${userStateId}`)
}
-1
View File
@@ -160,7 +160,6 @@ async function Http<T = any>(
// 如果收到响应,说明已经连接到服务器,不需要重试
if (!response.ok) {
const errorType = getErrorType(response.status)
// 如果是非重试状态码,则抛出带有适当错误类型的 AppException
throw new AppException(`HTTP error! status: ${response.status}`, {
type: errorType,
+35 -35
View File
@@ -68,7 +68,7 @@ export type CacheBadgeReq = {
/** 最后更新时间 更新超过 10 分钟异步去更新。 */
lastModifyTime?: number
/** 徽章 ID */
itemId: number
itemId: string
}
export type GroupDetailReq = {
@@ -81,14 +81,14 @@ export type GroupDetailReq = {
/** 成员角色 1群主 2管理员 3普通成员 4踢出群聊 */
role: number
/** 房间id */
roomId: number
roomId: string
}
export type GroupListReq = {
/** 群聊id */
groupId: number
groupId: string
/** 房间id */
roomId: number
roomId: string
/** 群名称 */
roomName: string
/** 群头像 */
@@ -105,14 +105,14 @@ export type CacheBadgeItem = {
/** 徽章图标 */
img: string
/** 徽章 ID */
itemId: number
itemId: string
}
export type CacheUserReq = {
/** 最后更新时间 更新超过 10 分钟异步去更新。 */
lastModifyTime?: number
/** uid */
uid: number
uid: string
}
export type CacheUserItem = {
@@ -121,9 +121,9 @@ export type CacheUserItem = {
/** 最后更新时间 更新超过 10 分钟异步去更新。 */
lastModifyTime: number
/** 获得的徽章 */
itemIds: number[]
itemIds: string[]
/** 佩戴的徽章 */
wearingItemId: number
wearingItemId: string
/** 归属地 */
locPlace: string
/** 头像 */
@@ -133,9 +133,9 @@ export type CacheUserItem = {
/** 用户名称 */
name: string
/** uid */
uid: number
uid: string
/** 用户状态 */
userStateId: number
userStateId: string
}
export type UserItem = {
@@ -148,7 +148,7 @@ export type UserItem = {
/** 用户名称 */
name: string
/** uid */
uid: number
uid: string
/** 归属地 */
locPlace?: string
/** 角色ID */
@@ -170,7 +170,7 @@ export type MessageReplyType = {
/** 跳转间隔的消息条数 */
gapCount: number
/** 消息id */
id: number
id: string
/** 用户名称 */
username: string
}
@@ -181,12 +181,12 @@ export type MarkMsgReq = {
// 标记类型 1点赞 2举报
markType: MarkEnum
// 消息 ID
msgId: number
msgId: string
}
export type UserInfoType = {
/** 用户唯一标识 */
uid: number
uid: string
/** 用户账号 */
account: string
/** Hula号 */
@@ -204,9 +204,9 @@ export type UserInfoType = {
/** 权限 */
power?: number
/** 佩戴的徽章 */
wearingItemId?: number
wearingItemId?: string
/** 用户状态id */
userStateId: number
userStateId: string
/** 头像更新时间 */
avatarUpdateTime: number
/** 客户端 */
@@ -217,7 +217,7 @@ export type BadgeType = {
// 徽章描述
describe: string
// 徽章id
id: number
id: string
// 徽章图标
img: string
// 是否拥有 0否 1是
@@ -228,9 +228,9 @@ export type BadgeType = {
export type MarkItemType = {
/** 操作用户 */
uid: number
uid: string
/** 消息id */
msgId: number
msgId: string
/** 操作类型 1点赞 2举报 */
markType: MarkEnum
/** 数量 */
@@ -241,16 +241,16 @@ export type MarkItemType = {
export type RevokedMsgType = {
/** 消息ID */
msgId: number
msgId: string
/** 会话ID */
roomId?: number
roomId?: string
/** 撤回人ID */
recallUid?: number
recallUid?: string
}
export type EmojiItem = {
expressionUrl: string
id: number
id: string
}
// -------------------- ⬇消息体类型定义⬇ ----------------
@@ -276,7 +276,7 @@ export type MessageType = {
*/
export type MsgUserType = {
/** 用户ID */
uid: number
uid: string
/** 用户名 */
username: string
/** 头像 */
@@ -362,9 +362,9 @@ export type EmojiBody = {
*/
export type MsgType = {
/** 消息ID */
id: number
id: string
/** 房间 ID */
roomId: number
roomId: string
/** 消息类型 */
type: MsgEnum
/** 动态消息体-`根据消息类型变化` */
@@ -378,7 +378,7 @@ export type MsgType = {
}
export type ReplyType = {
id: number
id: string
username: string
type: MsgEnum
/** 根据不同类型回复的消息展示也不同-`过渡版` */
@@ -397,7 +397,7 @@ export type ReplyType = {
*/
export type MessageReq = {
/** 会话id */
roomId: number
roomId: string
/** 消息类型 */
msgType: MsgEnum
/** 消息体 */
@@ -422,7 +422,7 @@ export enum RequestFriendAgreeStatus {
/** 请求添加好友的列表项 */
export type RequestFriendItem = {
/** 申请id */
applyId: number
applyId: string
/** 申请信息 */
msg: string
/** 申请状态 1待审批 2同意 */
@@ -430,9 +430,9 @@ export type RequestFriendItem = {
/** 申请类型 1加好友 */
type: number
/** 申请人uid */
uid: number
uid: string
/** 会话 ID */
roomId: number
roomId: string
}
/** 联系人的列表项 */
export type ContactItem = {
@@ -440,7 +440,7 @@ export type ContactItem = {
activeStatus: OnlineEnum
/** 最后一次上下线时间 */
lastOptTime: number
uid: number
uid: string
}
/** 是否全员展示的会话 0否 1是 */
@@ -458,13 +458,13 @@ export type SessionItem = {
/** 会话头像 */
avatar: string
/** 如果是单聊,则是对方的uid,如果是群聊,则是群id */
id: number
id: string
/** 是否全员展示的会话 0否 1是 */
hotFlag: IsAllUserEnum
/** 会话名称 */
name: string
/** 房间id */
roomId: number
roomId: string
/** 最新消息 */
text: string
/** 房间类型 1群聊 2单聊 */
@@ -482,7 +482,7 @@ export type SessionItem = {
/** 消息已读未读数列表项 */
export type MsgReadUnReadCountType = {
/** 消息 ID */
msgId: number
msgId: string
/** 已读数 */
readCount: number
/** 未读数 */
+1 -1
View File
@@ -66,7 +66,7 @@ export type OnStatusChangeType = {
/** token过期 */
export type WsTokenExpire = {
uid: number
uid: string
ip: string
client: string
}
+18 -14
View File
@@ -11,15 +11,15 @@ export type BaseUserItem = Pick<CacheUserItem, 'uid' | 'avatar' | 'name'>
export const useCachedStore = defineStore('cached', () => {
const globalStore = useGlobalStore()
// 用户信息缓存列表,key为用户ID
const userCachedList = reactive<Record<number, Partial<CacheUserItem>>>({})
const userCachedList = reactive<Record<string, Partial<CacheUserItem>>>({})
// 徽章信息缓存列表,key为徽章ID
const badgeCachedList = reactive<Record<number, Partial<CacheBadgeItem>>>({})
const badgeCachedList = reactive<Record<string, Partial<CacheBadgeItem>>>({})
// 获取当前聊天室ID
const currentRoomId = computed(() => globalStore.currentSession?.roomId)
// @ 用户列表的Mapkey为房间ID,value为用户列表
const atUsersMap = reactive<Record<number, BaseUserItem[]>>({ [currentRoomId.value]: [] }) // 消息Map
const atUsersMap = reactive<Record<string, BaseUserItem[]>>({ [currentRoomId.value]: [] }) // 消息Map
// 当前房间可@ 的用户列表
const currentAtUsersList = computed({
@@ -29,8 +29,12 @@ export const useCachedStore = defineStore('cached', () => {
atUsersMap[currentRoomId.value] = []
}
// 如果是大厅(roomId=1),返回所有缓存的用户
if (currentRoomId.value === 1) {
return Object.values(userCachedList as BaseUserItem[])
if (currentRoomId.value === '1') {
return Object.values(userCachedList).map((user) => ({
uid: user.uid,
avatar: user.avatar,
name: user.name
})) as BaseUserItem[]
}
return atUsersMap[currentRoomId.value]
},
@@ -40,14 +44,14 @@ export const useCachedStore = defineStore('cached', () => {
})
/** 用于存储正在请求的用户ID */
const pendingUids = ref(new Set<number>())
const pendingUids = ref(new Set<string>())
/**
* 批量获取用户详细信息的防抖包装函数
* 300ms 的防抖时间应该足够合并多次快速调用
*/
const debouncedGetBatchUserInfo = useDebounceFn(async (uids: number[]) => {
let result: { uid: number; lastModifyTime: number | undefined }[] = []
const debouncedGetBatchUserInfo = useDebounceFn(async (uids: string[]) => {
let result: { uid: string; lastModifyTime: number | undefined }[] = []
try {
// 去重:过滤掉正在请求的用户ID
@@ -68,7 +72,7 @@ export const useCachedStore = defineStore('cached', () => {
result.forEach((item) => pendingUids.value.add(item.uid))
// 收集需要获取的徽章ID
const itemIdSet: Set<number> = new Set()
const itemIdSet: Set<string> = new Set()
const data = await apis.getUserInfoBatch(result)
for (const item of data || []) {
@@ -100,14 +104,14 @@ export const useCachedStore = defineStore('cached', () => {
* 批量获取用户详细信息
* @param uids 用户ID数组
*/
const getBatchUserInfo = (uids: number[]) => {
const getBatchUserInfo = (uids: string[]) => {
return debouncedGetBatchUserInfo(uids)
}
/** 批量获取徽章详细信息
* @param itemIds 徽章ID数组
*/
const getBatchBadgeInfo = async (itemIds: number[]) => {
const getBatchBadgeInfo = async (itemIds: string[]) => {
// 筛选需要更新的徽章:没有lastModifyTime或距离上次更新超过10分钟的徽章
const result = itemIds
.map((itemId) => {
@@ -146,7 +150,7 @@ export const useCachedStore = defineStore('cached', () => {
* 如果是大厅(roomId=1)则不执行
*/
const getGroupAtUserBaseInfo = async () => {
if (currentRoomId.value === 1) return
if (currentRoomId.value === '1') return
currentAtUsersList.value = await apis.getAllUserBaseInfo({ roomId: currentRoomId.value })
}
@@ -155,7 +159,7 @@ export const useCachedStore = defineStore('cached', () => {
* @param uidList 用户ID列表
* @returns 过滤后的用户列表
*/
const filterUsersByUidList = (uidList: number[]) => {
const filterUsersByUidList = (uidList: string[]) => {
return currentAtUsersList.value.filter((user) => uidList.includes(user.uid))
}
@@ -163,7 +167,7 @@ export const useCachedStore = defineStore('cached', () => {
* 更新用户状态并刷新用户信息
* @param data 用户状态变更数据
*/
const updateUserState = async (data: { uid: number; userStateId: number }) => {
const updateUserState = async (data: { uid: string; userStateId: string }) => {
const { uid, userStateId } = data
// 更新缓存中的用户状态
+35 -35
View File
@@ -15,7 +15,7 @@ import { sendNotification } from '@tauri-apps/plugin-notification'
import { invoke } from '@tauri-apps/api/core'
type RecalledMessage = {
messageId: number
messageId: string
content: string
recallTime: number
}
@@ -56,41 +56,41 @@ export const useChatStore = defineStore(
const currentRoomType = computed(() => globalStore.currentSession?.type)
// 存储所有消息的Map
const messageMap = reactive<Map<number, Map<number, MessageType>>>(new Map([[currentRoomId.value, new Map()]]))
const messageMap = reactive<Map<string, Map<string, MessageType>>>(new Map([[currentRoomId.value, new Map()]]))
// 消息加载状态
const messageOptions = reactive<Map<number, { isLast: boolean; isLoading: boolean; cursor: string }>>(
const messageOptions = reactive<Map<string, { isLast: boolean; isLoading: boolean; cursor: string }>>(
new Map([[currentRoomId.value, { isLast: false, isLoading: false, cursor: '' }]])
)
// 回复消息的映射关系
const replyMapping = reactive<Map<number, Map<number, number[]>>>(new Map([[currentRoomId.value, new Map()]]))
const replyMapping = reactive<Map<string, Map<string, string[]>>>(new Map([[currentRoomId.value, new Map()]]))
// 存储撤回的消息内容和时间
const recalledMessages = reactive<Map<number, RecalledMessage>>(new Map())
const recalledMessages = reactive<Map<string, RecalledMessage>>(new Map())
// 存储每条撤回消息的过期定时器
const expirationTimers = new Map<number, boolean>()
const expirationTimers = new Map<string, boolean>()
// 当前聊天室的消息Map计算属性
const currentMessageMap = computed({
get: () => {
const current = messageMap.get(currentRoomId.value as number)
const current = messageMap.get(currentRoomId.value as string)
if (current === undefined) {
messageMap.set(currentRoomId.value, new Map())
}
return messageMap.get(currentRoomId.value as number)
return messageMap.get(currentRoomId.value as string)
},
set: (val) => {
messageMap.set(currentRoomId.value, val as Map<number, MessageType>)
messageMap.set(currentRoomId.value, val as Map<string, MessageType>)
}
})
// 当前聊天室的消息加载状态计算属性
const currentMessageOptions = computed({
get: () => {
const current = messageOptions.get(currentRoomId.value as number)
const current = messageOptions.get(currentRoomId.value as string)
if (current === undefined) {
messageOptions.set(currentRoomId.value, { isLast: false, isLoading: true, cursor: '' })
}
return messageOptions.get(currentRoomId.value as number)
return messageOptions.get(currentRoomId.value as string)
},
set: (val) => {
messageOptions.set(currentRoomId.value, val as { isLast: boolean; isLoading: boolean; cursor: string })
@@ -100,14 +100,14 @@ export const useChatStore = defineStore(
// 当前聊天室的回复消息映射计算属性
const currentReplyMap = computed({
get: () => {
const current = replyMapping.get(currentRoomId.value as number)
const current = replyMapping.get(currentRoomId.value as string)
if (current === undefined) {
replyMapping.set(currentRoomId.value, new Map())
}
return replyMapping.get(currentRoomId.value as number)
return replyMapping.get(currentRoomId.value as string)
},
set: (val) => {
replyMapping.set(currentRoomId.value, val as Map<number, number[]>)
replyMapping.set(currentRoomId.value, val as Map<string, string[]>)
}
})
@@ -120,13 +120,13 @@ export const useChatStore = defineStore(
)
// 新消息计数相关的响应式数据
const newMsgCount = reactive<Map<number, { count: number; isStart: boolean }>>(
const newMsgCount = reactive<Map<string, { count: number; isStart: boolean }>>(
new Map([
[
currentRoomId.value,
{
count: 0, // 新消息计数
isStart: false // 是否开始计数
count: 0,
isStart: false
}
]
])
@@ -135,11 +135,11 @@ export const useChatStore = defineStore(
// 当前聊天室的新消息计数计算属性
const currentNewMsgCount = computed({
get: () => {
const current = newMsgCount.get(currentRoomId.value as number)
const current = newMsgCount.get(currentRoomId.value as string)
if (current === undefined) {
newMsgCount.set(currentRoomId.value, { count: 0, isStart: false })
}
return newMsgCount.get(currentRoomId.value as number)
return newMsgCount.get(currentRoomId.value as string)
},
set: (val) => {
newMsgCount.set(currentRoomId.value, val as { count: number; isStart: boolean })
@@ -152,7 +152,7 @@ export const useChatStore = defineStore(
// 切换的 rooms是空数据的话就请求消息列表
if (!currentMessageMap.value || currentMessageMap.value.size === 0) {
if (!currentMessageMap.value) {
messageMap.set(currentRoomId.value as number, new Map())
messageMap.set(currentRoomId.value as string, new Map())
}
getMsgList()
}
@@ -200,7 +200,7 @@ export const useChatStore = defineStore(
const computedList = computedTimeBlock(data.list)
/** 收集需要请求用户详情的 uid */
const uidCollectYet: Set<number> = new Set() // 去重用
const uidCollectYet: Set<string> = new Set() // 去重用
for (const msg of computedList) {
const replyItem = msg.message.body?.reply
if (replyItem?.id) {
@@ -263,7 +263,7 @@ export const useChatStore = defineStore(
if (!isFirstInit || isFresh) {
isFirstInit = true
// 只有在没有当前选中会话时,才设置第一个会话为当前会话
if (!currentSelectedRoomId || currentSelectedRoomId === 1) {
if (!currentSelectedRoomId || currentSelectedRoomId === '1') {
globalStore.currentSession.roomId = data.list[0].roomId
globalStore.currentSession.type = data.list[0].type
}
@@ -295,14 +295,14 @@ export const useChatStore = defineStore(
}
// 更新会话
const updateSession = (roomId: number, roomProps: Partial<SessionItem>) => {
const updateSession = (roomId: string, roomProps: Partial<SessionItem>) => {
const session = sessionList.find((item) => item.roomId === roomId)
session && roomProps && Object.assign(session, roomProps)
sortAndUniqueSessionList()
}
// 更新会话最后活跃时间
const updateSessionLastActiveTime = (roomId: number, room?: SessionItem) => {
const updateSessionLastActiveTime = (roomId: string, room?: SessionItem) => {
const session = sessionList.find((item) => item.roomId === roomId)
if (session) {
Object.assign(session, { activeTime: Date.now() })
@@ -315,7 +315,7 @@ export const useChatStore = defineStore(
}
// 通过房间ID获取会话信息
const getSession = (roomId: number): SessionItem => {
const getSession = (roomId: string): SessionItem => {
return sessionList.find((item) => item.roomId === roomId) as SessionItem
}
@@ -383,7 +383,7 @@ export const useChatStore = defineStore(
}
// 过滤掉拉黑用户的发言
const filterUser = (uid: number) => {
const filterUser = (uid: string) => {
for (const messages of messageMap.values()) {
for (const msg of messages.values()) {
if (msg.fromUser.uid === uid) {
@@ -405,8 +405,8 @@ export const useChatStore = defineStore(
}
// 查找消息在列表里面的索引
const getMsgIndex = (msgId: number) => {
if (!msgId || isNaN(Number(msgId))) return -1
const getMsgIndex = (msgId: string) => {
if (!msgId) return -1
const keys = currentMessageMap.value ? Array.from(currentMessageMap.value.keys()) : []
return keys.findIndex((key) => key === msgId)
}
@@ -483,12 +483,12 @@ export const useChatStore = defineStore(
}
// 获取撤回消息
const getRecalledMessage = (msgId: number): RecalledMessage | undefined => {
const getRecalledMessage = (msgId: string): RecalledMessage | undefined => {
return recalledMessages.get(msgId)
}
// 删除消息
const deleteMsg = (msgId: number) => {
const deleteMsg = (msgId: string) => {
currentMessageMap.value?.delete(msgId)
}
@@ -499,9 +499,9 @@ export const useChatStore = defineStore(
newMsgId,
body
}: {
msgId: number
msgId: string
status: MessageStatusEnum
newMsgId?: number
newMsgId?: string
body?: any
}) => {
const msg = currentMessageMap.value?.get(msgId)
@@ -521,7 +521,7 @@ export const useChatStore = defineStore(
}
// 标记已读数为 0
const markSessionRead = (roomId: number) => {
const markSessionRead = (roomId: string) => {
const session = sessionList.find((item) => item.roomId === roomId)
const unreadCount = session?.unreadCount || 0
if (session && session.unreadCount > 0) {
@@ -535,12 +535,12 @@ export const useChatStore = defineStore(
}
// 根据消息id获取消息体
const getMessage = (messageId: number) => {
const getMessage = (messageId: string) => {
return currentMessageMap.value?.get(messageId)
}
// 删除会话
const removeContact = (roomId: number) => {
const removeContact = (roomId: string) => {
const index = sessionList.findIndex((session) => session.roomId === roomId)
if (index !== -1) {
sessionList.splice(index, 1)
+2 -2
View File
@@ -122,7 +122,7 @@ export const useContactStore = defineStore('contact', () => {
* 4. 更新当前选中联系人的状态
* 5. 更新未读数
*/
const onAcceptFriend = async (applyId: number) => {
const onAcceptFriend = async (applyId: string) => {
// 同意好友申请
apis.applyFriendRequest({ applyId }).then(async () => {
// 刷新好友申请列表
@@ -147,7 +147,7 @@ export const useContactStore = defineStore('contact', () => {
* 1. 调用删除好友接口
* 2. 刷新好友列表
*/
const onDeleteContact = async (uid: number) => {
const onDeleteContact = async (uid: string) => {
if (!uid) return
// 删除好友
await apis.deleteFriend({ targetUid: uid })
+1 -1
View File
@@ -37,7 +37,7 @@ export const useEmojiStore = defineStore('emoji', () => {
/**
* 删除表情
*/
const deleteEmoji = async (id: number) => {
const deleteEmoji = async (id: string) => {
if (!id) return
await apis.deleteEmoji({ id })
await getEmojiList()
+5 -5
View File
@@ -24,8 +24,8 @@ export const useGlobalStore = defineStore(
})
// 当前会话信息:包含房间ID和房间类型
const currentSession = reactive<{ roomId: number; type: RoomTypeEnum }>({
roomId: 1,
const currentSession = reactive<{ roomId: string; type: RoomTypeEnum }>({
roomId: '1',
type: RoomTypeEnum.GROUP
})
@@ -33,7 +33,7 @@ export const useGlobalStore = defineStore(
const currentSelectedContact = ref<ContactItem | RequestFriendItem>()
// 添加好友模态框信息
const addFriendModalInfo = ref<{ show: boolean; uid?: number }>({
const addFriendModalInfo = ref<{ show: boolean; uid?: string }>({
show: false,
uid: void 0
})
@@ -71,9 +71,9 @@ export const useGlobalStore = defineStore(
// 延迟1秒后开始查询已读数
setTimeout(readCountQueue, 1000)
// 标记该房间的消息为已读
apis.markMsgRead({ roomId: val.roomId || 1 })
apis.markMsgRead({ roomId: val.roomId || '1' })
// 更新会话的已读状态
chatStore.markSessionRead(val.roomId || 1)
chatStore.markSessionRead(val.roomId || '1')
// 更新全局未读计数
updateGlobalUnreadCount()
})
+8 -8
View File
@@ -103,7 +103,7 @@ export const useGroupStore = defineStore('group', () => {
* 获取群成员列表
* @param refresh 是否刷新(重新加载)
*/
const getGroupUserList = async (refresh = false, specifiedRoomId?: number) => {
const getGroupUserList = async (refresh = false, specifiedRoomId?: string) => {
const data = await apis.getGroupList({
pageSize: pageSize,
cursor: refresh ? '' : userListOptions.cursor,
@@ -119,7 +119,7 @@ export const useGroupStore = defineStore('group', () => {
userListOptions.loading = false
// 收集并获取用户详细信息
const uidCollectYet: Set<number> = new Set()
const uidCollectYet: Set<string> = new Set()
for (const user of data.list || []) {
uidCollectYet.add(user.uid)
}
@@ -163,7 +163,7 @@ export const useGroupStore = defineStore('group', () => {
* 从群成员列表中移除指定用户
* @param uid 要移除的用户ID
*/
const filterUser = (uid: number) => {
const filterUser = (uid: string) => {
if (typeof uid !== 'number') return
userList.value = userList.value.filter((item) => item.uid !== uid)
}
@@ -172,7 +172,7 @@ export const useGroupStore = defineStore('group', () => {
* 添加群管理员
* @param uidList 要添加为管理员的用户ID列表
*/
const addAdmin = async (uidList: number[]) => {
const addAdmin = async (uidList: string[]) => {
await apis.addAdmin({ roomId: currentRoomId.value, uidList })
// 更新本地群成员列表中的角色信息
for (const user of userList.value) {
@@ -186,7 +186,7 @@ export const useGroupStore = defineStore('group', () => {
* 撤销群管理员身份
* @param uidList 要撤销的管理员ID列表
*/
const revokeAdmin = async (uidList: number[]) => {
const revokeAdmin = async (uidList: string[]) => {
await apis.revokeAdmin({ roomId: currentRoomId.value, uidList })
// 更新本地群成员列表中的角色信息
for (const user of userList.value) {
@@ -200,7 +200,7 @@ export const useGroupStore = defineStore('group', () => {
* 退出群聊
* @param roomId 要退出的群聊ID
*/
const exitGroup = async (roomId: number) => {
const exitGroup = async (roomId: string) => {
await apis.exitGroup({ roomId: roomId })
// 从成员列表中移除自己
const index = userList.value.findIndex((user) => user.uid === userStore.userInfo.uid)
@@ -216,10 +216,10 @@ export const useGroupStore = defineStore('group', () => {
*/
const refreshGroupMembers = async () => {
// 始终刷新频道成员列表
await getGroupUserList(true, 1)
await getGroupUserList(true, '1')
// 如果当前选中的是群聊且不是频道,则同时刷新当前群聊的成员列表
if (globalStore.currentSession?.type === RoomTypeEnum.GROUP && currentRoomId.value !== 1) {
if (globalStore.currentSession?.type === RoomTypeEnum.GROUP && currentRoomId.value !== '1') {
await getGroupUserList(true, currentRoomId.value)
}
}
+2 -2
View File
@@ -10,13 +10,13 @@ export const useUserStatusStore = defineStore(
/** 在线状态列表 */
const stateList = ref<STO.UserState[]>([])
const stateId = ref<number>(1)
const stateId = ref<string>('1')
const currentState = computed(() => {
const item = stateList.value.find((state) => state.id === stateId.value)
if (!item) {
const defaultItem = stateList.value.find((state) => state.id === 1)
const defaultItem = stateList.value.find((state) => state.id === '1')
if (defaultItem) {
const img = new Image()
img.src = defaultItem.url
+4 -4
View File
@@ -11,7 +11,7 @@ import DOMPurify from 'dompurify'
interface MessageStrategy {
getMsg: (msgInputValue: string, replyValue: any, fileList?: File[]) => any
buildMessageBody: (msg: any, reply: any) => any
buildMessageType: (messageId: number, messageBody: any, globalStore: any, userUid: Ref<any>) => MessageType
buildMessageType: (messageId: string, messageBody: any, globalStore: any, userUid: Ref<any>) => MessageType
uploadFile: (path: string) => Promise<{ uploadUrl: string; downloadUrl: string }>
doUpload: (path: string, uploadUrl: string) => Promise<void>
}
@@ -23,7 +23,7 @@ abstract class AbstractMessageStrategy implements MessageStrategy {
this.msgType = msgType
}
buildMessageType(messageId: number, messageBody: any, globalStore: any, userUid: Ref<any>): MessageType {
buildMessageType(messageId: string, messageBody: any, globalStore: any, userUid: Ref<any>): MessageType {
const currentTime = new Date().getTime()
return {
fromUser: {
@@ -445,7 +445,7 @@ class FileMessageStrategyImpl extends AbstractMessageStrategy {
throw new AppException('方法暂未实现')
}
buildMessageType(messageId: number, messageBody: any, globalStore: any, userUid: Ref<any>): MessageType {
buildMessageType(messageId: string, messageBody: any, globalStore: any, userUid: Ref<any>): MessageType {
console.log(messageId, messageBody, globalStore, userUid)
throw new AppException('暂未实现该类型')
}
@@ -469,7 +469,7 @@ class UnsupportedMessageStrategyImpl extends AbstractMessageStrategy {
throw new AppException('方法暂未实现')
}
buildMessageType(messageId: number, messageBody: any, globalStore: any, userUid: Ref<any>): MessageType {
buildMessageType(messageId: string, messageBody: any, globalStore: any, userUid: Ref<any>): MessageType {
messageId
messageBody
globalStore
+1 -1
View File
@@ -19,7 +19,7 @@ declare namespace API {
* @param bgColor 背景颜色
*/
type UserState = {
id: number
id: string
title: string
url: string
bgColor?: string
+3 -3
View File
@@ -50,8 +50,8 @@ import { useCommon } from '@/hooks/useCommon.ts'
// 定义分组消息的类型
type GroupedMessage = {
id: number
roomId: number
id: string
roomId: string
latestContent: string
messageCount: number
avatar: string
@@ -94,7 +94,7 @@ const checkIsAtMe = (content: MessageType) => {
}
// 处理点击消息的逻辑
const handleClickMsg = async (uid: number) => {
const handleClickMsg = async (uid: string) => {
// 打开消息页面
await checkWinExist('home')
await handleTip()
+1 -1
View File
@@ -70,7 +70,7 @@ watch(
const addFriend = async () => {
await apis.sendAddFriendRequest({
msg: requestMsg.value,
targetUid: globalStore.addFriendModalInfo.uid as number
targetUid: globalStore.addFriendModalInfo.uid as string
})
window.$message.success('已发送好友申请')
}
+7 -7
View File
@@ -168,8 +168,8 @@ const getCachedUsers = () => {
// 筛选出需要显示的用户(ID在20016-20030之间的用户)
return users
.filter((user) => {
const uid = user.uid as number
return uid >= 20016 && uid <= 20030
const uid = user.uid as string
return uid >= '20016' && uid <= '20030'
})
.map((user) => ({
id: user.uid,
@@ -245,19 +245,19 @@ const isFriend = (uid: number | string) => {
}
// 判断是否是当前登录用户
const isCurrentUser = (uid: number | string) => {
return userStore.userInfo.uid === Number(uid)
const isCurrentUser = (uid: string) => {
return userStore.userInfo.uid === uid
}
// 获取按钮文本
const getButtonText = (uid: number | string) => {
const getButtonText = (uid: string) => {
if (isCurrentUser(uid)) return '编辑资料'
if (isFriend(uid)) return '发消息'
return '添加'
}
// 获取按钮类型
const getButtonType = (uid: number | string) => {
const getButtonType = (uid: string) => {
if (isCurrentUser(uid)) return 'default'
if (isFriend(uid)) return 'info'
return 'primary'
@@ -275,7 +275,7 @@ const handleButtonClick = (item: any) => {
}
// 处理添加好友或群聊
const handleAddFriend = async (uid: number) => {
const handleAddFriend = async (uid: string) => {
if (searchType.value === 'user' || searchType.value === 'recommend') {
await createWebviewWindow('申请加好友', 'addFriendVerify', 380, 300, '', false, 380, 300)
globalStore.addFriendModalInfo.show = true
+5 -5
View File
@@ -111,7 +111,7 @@ const menuList = ref([
{ label: '删除分组', icon: 'delete' }
])
/** 建议把此状态存入localStorage中 */
const activeItem = ref(0)
const activeItem = ref('')
const detailsShow = ref(false)
const shrinkStatus = ref(false)
const contactStore = useContactStore()
@@ -140,7 +140,7 @@ watchEffect(() => {
})
})
const handleClick = (index: number, type: number) => {
const handleClick = (index: string, type: number) => {
detailsShow.value = true
activeItem.value = index
const data = {
@@ -167,15 +167,15 @@ const handleApply = () => {
type: 'apply'
}
})
activeItem.value = 0
activeItem.value = ''
}
/** 获取用户状态 */
const getUserState = (uid: number) => {
const getUserState = (uid: string) => {
const userInfo = useUserInfo(uid).value
const userStateId = userInfo.userStateId
if (userStateId && userStateId > 1) {
if (userStateId && userStateId !== '1') {
return stateList.value.find((state) => state.id === userStateId)
}
return null
+3 -3
View File
@@ -196,14 +196,14 @@ onMounted(() => {
// 监听其他窗口发来的WebSocket发送请求
// TODO:频繁切换会话会导致频繁请求,切换的时候也会有点卡顿
addListener(
appWindow.listen('search_to_msg', (event: { payload: { uid: number; roomType: number } }) => {
appWindow.listen('search_to_msg', (event: { payload: { uid: string; roomType: number } }) => {
openMsgSession(event.payload.uid, event.payload.roomType)
})
)
useMitt.on(MittEnum.DELETE_SESSION, async (roomId: number) => {
useMitt.on(MittEnum.DELETE_SESSION, async (roomId: string) => {
await handleMsgDelete(roomId)
})
useMitt.on(MittEnum.LOCATE_SESSION, async (e: { roomId: number }) => {
useMitt.on(MittEnum.LOCATE_SESSION, async (e: { roomId: string }) => {
const index = sessionList.value.findIndex((item) => item.roomId === e.roomId)
if (index !== -1) {
await nextTick(() => {
+19 -13
View File
@@ -188,7 +188,7 @@ const info = ref({
password: '',
avatar: '',
name: '',
uid: 0
uid: ''
})
/** 协议 */
const protocol = ref(true)
@@ -272,22 +272,28 @@ const normalLogin = async (auto = false) => {
// 自动登录
if (auto) {
loginText.value = '登录中...'
// 添加2秒延迟
await new Promise((resolve) => setTimeout(resolve, 1200))
// 获取用户详情
const userDetail = await apis.getUserDetail()
// 设置用户状态id
stateId.value = userDetail.userStateId
const account = {
...userDetail
}
userStore.userInfo = account
loginHistoriesStore.addLoginHistory(account)
try {
// 获取用户详情
const userDetail = await apis.getUserDetail()
// 设置用户状态id
stateId.value = userDetail.userStateId
const account = {
...userDetail
}
userStore.userInfo = account
loginHistoriesStore.addLoginHistory(account)
await setLoginState()
await openHomeWindow()
loading.value = false
await setLoginState()
await openHomeWindow()
loading.value = false
} catch (error) {
console.error('自动登录失败')
localStorage.removeItem('TOKEN')
}
}
apis
+1 -1
View File
@@ -73,7 +73,7 @@ const handleActive = async (item: API.UserState) => {
onMounted(async () => {
await getCurrentWebviewWindow().show()
currentState.value.id = stateList.value.find((item) => item.title === currentState.value.title)?.id || 1
currentState.value.id = stateList.value.find((item) => item.title === currentState.value.title)?.id || '1'
})
</script>
<style scoped lang="scss">