fix(util): 🐛 http请求异常bug

BREAKING CHANGE: http请求异常bug
This commit is contained in:
ZOL4789 2024-10-26 17:31:51 +08:00
parent d9e204e180
commit 6e82a099a2
14 changed files with 36 additions and 40 deletions

View File

@ -1,7 +1,7 @@
# 后端服务地址 # 后端服务地址
VITE_SERVICE_URL="http://127.0.0.1:9190" VITE_SERVICE_URL="https://hulaspark.com"
# websocket服务地址 # websocket服务地址
VITE_WEBSOCKET_URL="ws://127.0.0.1:8090" VITE_WEBSOCKET_URL="wss://hulaspark.com"
# 项目标题 # 项目标题
VITE_APP_TITLE="HuLa—IM" VITE_APP_TITLE="HuLa—IM"
# 项目名称 # 项目名称

View File

@ -135,10 +135,10 @@ const footerOptions = ref<OPT.Details[]>([
// TODO (nyh -> 2024-03-25 16:01:23) // TODO (nyh -> 2024-03-25 16:01:23)
router.push('/message') router.push('/message')
apis.sessionDetailWithFriends({ uid: item.value.uid as number }).then((res) => { apis.sessionDetailWithFriends({ uid: item.value.uid as number }).then((res) => {
globalStore.currentSession.roomId = res.data.roomId globalStore.currentSession.roomId = res.roomId
globalStore.currentSession.type = RoomTypeEnum.SINGLE globalStore.currentSession.type = RoomTypeEnum.SINGLE
chatStore.updateSessionLastActiveTime(res.data.roomId, res.data) chatStore.updateSessionLastActiveTime(res.roomId, res)
handleMsgClick(res.data as any) handleMsgClick(res as any)
}) })
Mitt.emit(MittEnum.TO_SEND_MSG, { url: 'message' }) Mitt.emit(MittEnum.TO_SEND_MSG, { url: 'message' })
} }

View File

@ -74,9 +74,9 @@ export const useChatMain = (activeItem?: SessionItem) => {
label: '撤回', label: '撤回',
icon: 'corner-down-left', icon: 'corner-down-left',
click: async (item: MessageType) => { click: async (item: MessageType) => {
const res = await apis.recallMsg({ roomId: 1, msgId: item.message.id }) const res = (await apis.recallMsg({ roomId: 1, msgId: item.message.id })) as any
if (res.errMsg) { if (res) {
window.$message.error(res.errMsg) window.$message.error(res)
return return
} }
chatStore.updateRecallStatus({ msgId: item.message.id }) chatStore.updateRecallStatus({ msgId: item.message.id })

View File

@ -200,8 +200,8 @@ export const useMsgInput = (messageInputDom: Ref) => {
body: { content: msg.content, replyMsgId: msg.reply !== 0 ? msg.reply : undefined } body: { content: msg.content, replyMsgId: msg.reply !== 0 ? msg.reply : undefined }
}) })
.then(async (res) => { .then(async (res) => {
if (res.data.message.type === MsgEnum.TEXT) { if (res.message.type === MsgEnum.TEXT) {
await chatStore.pushMsg(res.data) await chatStore.pushMsg(res)
} }
// 发完消息就要刷新会话列表, // 发完消息就要刷新会话列表,
// FIXME 如果当前会话已经置顶了,可以不用刷新 // FIXME 如果当前会话已经置顶了,可以不用刷新

View File

@ -83,8 +83,8 @@ export const useUpload = () => {
const thumbFile = new File([blob], name, { type: 'image/jpeg' }) const thumbFile = new File([blob], name, { type: 'image/jpeg' })
// 转成File对象 并上传 // 转成File对象 并上传
apis.getUploadUrl({ fileName: name, scene: '1' }).then(async (res) => { apis.getUploadUrl({ fileName: name, scene: '1' }).then(async (res) => {
if (res.data.uploadUrl && res.data.downloadUrl) { if (res.uploadUrl && res.downloadUrl) {
await upload(res.data.uploadUrl, thumbFile, true) await upload(res.uploadUrl, thumbFile, true)
// 等待上传完成 // 等待上传完成
const timer = setInterval(() => { const timer = setInterval(() => {
if (!isUploading.value) { if (!isUploading.value) {
@ -92,7 +92,7 @@ export const useUpload = () => {
resolve({ resolve({
thumbWidth: canvas.width, thumbWidth: canvas.width,
thumbHeight: canvas.height, thumbHeight: canvas.height,
thumbUrl: res.data.downloadUrl, thumbUrl: res.downloadUrl,
thumbSize: thumbFile.size, thumbSize: thumbFile.size,
tempUrl tempUrl
}) })
@ -198,7 +198,7 @@ export const useUpload = () => {
return return
} }
const { downloadUrl, uploadUrl } = (await apis.getUploadUrl({ fileName: info.name, scene: '1' })).data const { downloadUrl, uploadUrl } = await apis.getUploadUrl({ fileName: info.name, scene: '1' })
if (uploadUrl && downloadUrl) { if (uploadUrl && downloadUrl) {
fileInfo.value = { ...info, downloadUrl } fileInfo.value = { ...info, downloadUrl }

View File

@ -120,9 +120,9 @@ export const leftHook = () => {
window.$message.error('改名次数不足') window.$message.error('改名次数不足')
return return
} }
apis.modifyUserName(editInfo.value.content.name).then((res) => { apis.modifyUserName(editInfo.value.content.name).then((res: any) => {
if (!res.success) { if (!res) {
window.$message.error(res.errMsg) window.$message.error(res)
return return
} }
// 更新本地缓存的用户信息 // 更新本地缓存的用户信息
@ -137,8 +137,8 @@ export const leftHook = () => {
/** 佩戴徽章 */ /** 佩戴徽章 */
const toggleWarningBadge = async (badge: BadgeType) => { const toggleWarningBadge = async (badge: BadgeType) => {
if (!badge?.id) return if (!badge?.id) return
const res = await apis.setUserBadge(badge.id) const res: any = await apis.setUserBadge(badge.id)
if (res.success) { if (res) {
window.$message.success('佩戴成功') window.$message.success('佩戴成功')
/** 获取用户信息 */ /** 获取用户信息 */
apis.getUserInfo().then((res) => { apis.getUserInfo().then((res) => {

View File

@ -43,8 +43,7 @@ export default {
/** 获取群成员统计 */ /** 获取群成员统计 */
getMemberStatistic: () => GET<GroupStatisticType>(urls.getMemberStatistic), getMemberStatistic: () => GET<GroupStatisticType>(urls.getMemberStatistic),
/** 房间内的所有群成员列表-@专用 */ /** 房间内的所有群成员列表-@专用 */
getAllUserBaseInfo: (params?: any) => getAllUserBaseInfo: (params?: any) => GET<CacheUserItem[]>(urls.getAllUserBaseInfo, params),
GET<Pick<CacheUserItem, 'avatar' | 'name' | 'uid'>[]>(urls.getAllUserBaseInfo, params),
/** 批量获取成员详细信息 */ /** 批量获取成员详细信息 */
getUserInfoBatch: (users: CacheUserReq[]) => POST<CacheUserItem[]>(urls.getUserInfoBatch, { reqList: users }), getUserInfoBatch: (users: CacheUserReq[]) => POST<CacheUserItem[]>(urls.getUserInfoBatch, { reqList: users }),
/** 批量获取徽章信息 */ /** 批量获取徽章信息 */

View File

@ -42,7 +42,7 @@ export const useCachedStore = defineStore('cached', () => {
.filter((item) => !item.lastModifyTime || isDiffNow10Min(item.lastModifyTime)) .filter((item) => !item.lastModifyTime || isDiffNow10Min(item.lastModifyTime))
if (!result.length) return if (!result.length) return
const itemIdSet: Set<number> = new Set() const itemIdSet: Set<number> = new Set()
const { data } = await apis.getUserInfoBatch(result) const data = await apis.getUserInfoBatch(result)
data?.forEach((item: CacheUserItem) => { data?.forEach((item: CacheUserItem) => {
// 更新最后更新时间。 // 更新最后更新时间。
userCachedList[item.uid] = { userCachedList[item.uid] = {
@ -70,7 +70,7 @@ export const useCachedStore = defineStore('cached', () => {
}) })
.filter((item) => !item.lastModifyTime || isDiffNow10Min(item.lastModifyTime)) .filter((item) => !item.lastModifyTime || isDiffNow10Min(item.lastModifyTime))
if (!result.length) return if (!result.length) return
const { data } = await apis.getBadgesBatch(result) const data = await apis.getBadgesBatch(result)
data?.forEach( data?.forEach(
(item: CacheBadgeItem) => (item: CacheBadgeItem) =>
// 更新最后更新时间。 // 更新最后更新时间。
@ -85,7 +85,7 @@ export const useCachedStore = defineStore('cached', () => {
/** 房间内的所有群成员列表-@专用 */ /** 房间内的所有群成员列表-@专用 */
const initAllUserBaseInfo = async () => { const initAllUserBaseInfo = async () => {
if (localStorage.getItem('IS_INIT_USER_BASE') === null) { if (localStorage.getItem('IS_INIT_USER_BASE') === null) {
const { data } = await apis.getAllUserBaseInfo({ params: { roomId: currentRoomId.value } }) const data = await apis.getAllUserBaseInfo({ params: { roomId: currentRoomId.value } })
data?.forEach((item: CacheUserItem) => (userCachedList[item.uid] = item)) data?.forEach((item: CacheUserItem) => (userCachedList[item.uid] = item))
localStorage.setItem('IS_INIT_USER_BASE', 'true') localStorage.setItem('IS_INIT_USER_BASE', 'true')
} }
@ -93,7 +93,7 @@ export const useCachedStore = defineStore('cached', () => {
const getGroupAtUserBaseInfo = async () => { const getGroupAtUserBaseInfo = async () => {
if (currentRoomId.value === 1) return if (currentRoomId.value === 1) return
const { data } = await apis.getAllUserBaseInfo({ params: { roomId: currentRoomId.value } }) const data = await apis.getAllUserBaseInfo({ params: { roomId: currentRoomId.value } })
currentAtUsersList.value = data currentAtUsersList.value = data
} }

View File

@ -141,7 +141,7 @@ export const useChatStore = defineStore('chat', () => {
const getMsgList = async (size = pageSize) => { const getMsgList = async (size = pageSize) => {
currentMessageOptions.value && (currentMessageOptions.value.isLoading = true) currentMessageOptions.value && (currentMessageOptions.value.isLoading = true)
const { data } = await apis const data = await apis
.getMsgList({ .getMsgList({
params: { params: {
pageSize: size, pageSize: size,
@ -200,7 +200,7 @@ export const useChatStore = defineStore('chat', () => {
sessionOptions.isLoading = false sessionOptions.isLoading = false
}) })
if (!response) return if (!response) return
const { data } = response const data = response
if (!data) { if (!data) {
return return
} }
@ -281,7 +281,7 @@ export const useChatStore = defineStore('chat', () => {
detailResponse = await apis.sessionDetail({ id: msg.message.roomId }) detailResponse = await apis.sessionDetail({ id: msg.message.roomId })
} }
if (detailResponse) { if (detailResponse) {
const { data } = detailResponse const data = detailResponse
updateSessionLastActiveTime(msg.message.roomId, data) updateSessionLastActiveTime(msg.message.roomId, data)
} }
} }

View File

@ -26,7 +26,7 @@ export const useContactStore = defineStore('contact', () => {
contactsOptions.isLoading = false contactsOptions.isLoading = false
}) })
if (!res) return if (!res) return
const { data } = res const data = res
isFresh ? contactsList.splice(0, contactsList.length, ...data.list) : contactsList.push(...data.list) isFresh ? contactsList.splice(0, contactsList.length, ...data.list) : contactsList.push(...data.list)
contactsOptions.cursor = data.cursor contactsOptions.cursor = data.cursor
contactsOptions.isLast = data.isLast contactsOptions.isLast = data.isLast
@ -39,7 +39,7 @@ export const useContactStore = defineStore('contact', () => {
// //
}) })
if (!res) return if (!res) return
const { data } = res const data = res
if (typeof data?.unReadCount === 'number') { if (typeof data?.unReadCount === 'number') {
globalStore.unReadMark.newFriendUnreadCount = data.unReadCount globalStore.unReadMark.newFriendUnreadCount = data.unReadCount
} }
@ -61,7 +61,7 @@ export const useContactStore = defineStore('contact', () => {
// 每次加载完新的好友邀请列表都要更新申请未读数 // 每次加载完新的好友邀请列表都要更新申请未读数
await getNewFriendCount() await getNewFriendCount()
if (!res) return if (!res) return
const { data } = res const data = res
isFresh isFresh
? requestFriendsList.splice(0, requestFriendsList.length, ...data.list) ? requestFriendsList.splice(0, requestFriendsList.length, ...data.list)
: requestFriendsList.push(...data.list) : requestFriendsList.push(...data.list)

View File

@ -17,10 +17,7 @@ export const useEmojiStore = defineStore('emoji', () => {
isLoading.value = false isLoading.value = false
}) })
if (!res) return if (!res) return
const { emojiList.value = res
data: { data }
} = res
emojiList.value = data
} }
/** /**
@ -30,7 +27,7 @@ export const useEmojiStore = defineStore('emoji', () => {
const { uid } = userStore.userInfo const { uid } = userStore.userInfo
if (!uid || !emojiUrl) return if (!uid || !emojiUrl) return
apis.addEmoji({ uid, expressionUrl: emojiUrl }).then((res) => { apis.addEmoji({ uid, expressionUrl: emojiUrl }).then((res) => {
if (res.success) { if (res) {
window.$message.success('添加成功') window.$message.success('添加成功')
} }
}) })

View File

@ -95,7 +95,7 @@ export const useGroupStore = defineStore('group', () => {
} }
}) })
if (!res) return if (!res) return
const { data } = res const data = res
const tempNew = cloneDeep(uniqueUserList(refresh ? data.list : [...data.list, ...userList.value])) const tempNew = cloneDeep(uniqueUserList(refresh ? data.list : [...data.list, ...userList.value]))
tempNew.sort(sorAction) tempNew.sort(sorAction)
userList.value = tempNew userList.value = tempNew
@ -112,7 +112,7 @@ export const useGroupStore = defineStore('group', () => {
// 获取群成员数量统计 // 获取群成员数量统计
const getCountStatistic = async () => { const getCountStatistic = async () => {
const { data } = await apis.groupDetail({ id: currentRoomId.value }) const data = await apis.groupDetail({ id: currentRoomId.value })
countInfo.value = data countInfo.value = data
} }

View File

@ -84,7 +84,7 @@ export const useSettingStore = defineStore(StoresEnum.SETTING, {
}) })
.filter((item) => !item.lastModifyTime || isDiffNow10Min(item.lastModifyTime)) .filter((item) => !item.lastModifyTime || isDiffNow10Min(item.lastModifyTime))
if (!result.length) return if (!result.length) return
const { data } = await apis.getBadgesBatch(result) const data = await apis.getBadgesBatch(result)
data?.forEach( data?.forEach(
(item: CacheBadgeItem) => (item: CacheBadgeItem) =>
// 更新最后更新时间。 // 更新最后更新时间。

View File

@ -23,7 +23,7 @@ export const useUserStore = defineStore('user', () => {
apis apis
.getUserDetail() .getUserDetail()
.then((res) => { .then((res) => {
userInfo.value = { ...userInfo.value, ...res.data.data } userInfo.value = { ...userInfo.value, ...res }
}) })
.catch(() => { .catch(() => {
// 删除缓存 // 删除缓存