|
@@ -3,7 +3,7 @@
|
|
|
<van-nav-bar @click-left="router.back()" @click-right="onClickRight">
|
|
|
<template #left>
|
|
|
<div>
|
|
|
- <van-icon name="arrow-left" color="black" size="18" />
|
|
|
+ <van-icon name="arrow-left" color="black" size="18"/>
|
|
|
</div>
|
|
|
</template>
|
|
|
<template #title>
|
|
@@ -15,11 +15,10 @@
|
|
|
</div>
|
|
|
</template>
|
|
|
<template #right>
|
|
|
- <van-icon name="ellipsis" color="black" size="18" />
|
|
|
+ <van-icon name="ellipsis" color="black" size="18"/>
|
|
|
</template>
|
|
|
</van-nav-bar>
|
|
|
<template v-if="showPage">
|
|
|
- {{sendUserId}}
|
|
|
<van-list
|
|
|
ref="chatListRef"
|
|
|
class="flex-1 overflow-y-auto px-12 flex flex-col"
|
|
@@ -33,6 +32,9 @@
|
|
|
{{ followStatus }}在对方关注或回复前,最多只能发送1条信息
|
|
|
</div>
|
|
|
</van-list>
|
|
|
+<!-- <van-pull-refresh v-model="refreshing" @refresh="loadMore">-->
|
|
|
+<!-- -->
|
|
|
+<!-- </van-pull-refresh>-->
|
|
|
<ChatInput :operates="['image']" @focus="scrollToBottom" @send="handleSendMessage"></ChatInput>
|
|
|
</template>
|
|
|
<template v-else>
|
|
@@ -58,7 +60,7 @@ import {isValidJson} from "~/utils";
|
|
|
|
|
|
const route = useRoute()
|
|
|
const router = useRouter()
|
|
|
-const refreshing = ref(false)
|
|
|
+
|
|
|
const chatsStore = useChatsStore();
|
|
|
const userInfoStore = useUserInfoStore();
|
|
|
|
|
@@ -76,32 +78,42 @@ const getUserId = ref(route.query?.getUserId); // 消息接收者的用户id
|
|
|
const sendUserId = computed(() => userInfo?.value.pass) // 消息发送者:当前登录用户的加密id
|
|
|
const groupId = ref(null); // 会话ID
|
|
|
const showPage = computed(() => getUserId.value && groupId.value)
|
|
|
+
|
|
|
const initGroupId = async () => {
|
|
|
try {
|
|
|
- pageLoading.value = true;
|
|
|
if (!getUserId.value) return;
|
|
|
+ pageLoading.value = true;
|
|
|
const res = await chatsStore.getCurrConversationId(getUserId.value)
|
|
|
await handleResponse(res)
|
|
|
groupId.value = res.data;
|
|
|
- await initData()
|
|
|
+ await getChatList('init')
|
|
|
} catch (e) {
|
|
|
|
|
|
} finally {
|
|
|
pageLoading.value = false;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+let pageNum = ref(0)
|
|
|
const currConversationChatList = ref([]);
|
|
|
-const initData = async () => {
|
|
|
+/**
|
|
|
+ * 加载当前聊天信息
|
|
|
+ * @param type init|more
|
|
|
+ * @returns {Promise<void>}
|
|
|
+ */
|
|
|
+const getChatList = async (type = 'init') => {
|
|
|
try {
|
|
|
+ const page = type === 'init' ? 1 : pageNum.value + 1;
|
|
|
const res = await chatsStore.getChatHistory({
|
|
|
- pageNum: 1,
|
|
|
+ pageNum: page,
|
|
|
pageSize: 100,
|
|
|
groupId: groupId.value,
|
|
|
})
|
|
|
+ pageNum.value = page;
|
|
|
await handleResponse(res);
|
|
|
- currConversationChatList.value = (res.data?.dataList ?? []).filter(o => isValidJson(o.messageContent)).map(o => JSON.parse(o.messageContent));
|
|
|
+ currConversationChatList.value = handleChatList(res.data?.dataList)
|
|
|
console.log(currConversationChatList.value, 'currConversationChatList')
|
|
|
- await scrollToBottom()
|
|
|
+ if (type === 'init') await scrollToBottom()
|
|
|
await getFollowStatus()
|
|
|
} catch (e) {
|
|
|
console.error(e)
|
|
@@ -109,6 +121,9 @@ const initData = async () => {
|
|
|
|
|
|
}
|
|
|
}
|
|
|
+const handleChatList = (list = []) => {
|
|
|
+ return (list ?? []).filter(o => isValidJson(o.messageContent)).map(o => JSON.parse(o.messageContent));
|
|
|
+}
|
|
|
|
|
|
// 发送文本消息
|
|
|
const sendTextMessage = async (text) => {
|
|
@@ -129,7 +144,7 @@ const sendTextMessage = async (text) => {
|
|
|
}
|
|
|
const isLink = !!findHyperlinks(text)
|
|
|
if (isLink) msg.messageType = 4;
|
|
|
-/* currConversationChatList.value.push(msg)*/
|
|
|
+ currConversationChatList.value.push(msg)
|
|
|
const res = await chatsStore.sendSocketMessage(msg)
|
|
|
console.log('luck:', res)
|
|
|
} catch (e) {
|
|
@@ -156,14 +171,14 @@ const sendImageMessage = async (file) => {
|
|
|
getUserId: getUserId.value,
|
|
|
sendUserId: sendUserId.value,
|
|
|
specialUserId: '',
|
|
|
- messageContent: JSON.stringify({messageContent: data.fileUrl}),
|
|
|
+ messageContent: data.fileUrl,
|
|
|
messageType: 1,
|
|
|
noticeType: 1,
|
|
|
object: {
|
|
|
id: getLocalId()
|
|
|
}
|
|
|
}
|
|
|
- /*currConversationChatList.value.push(msg)*/
|
|
|
+ currConversationChatList.value.push(msg)
|
|
|
await chatsStore.sendSocketMessage(msg)
|
|
|
} catch (e) {
|
|
|
console.error(e, '??')
|
|
@@ -192,7 +207,6 @@ const handleSendMessage = async ({type, messageContent}) => {
|
|
|
} finally {
|
|
|
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
const scrollToBottom = async () => {
|
|
@@ -214,9 +228,15 @@ const getFollowStatus = async () => {
|
|
|
}
|
|
|
|
|
|
|
|
|
-// 刷新
|
|
|
-const onRefresh = () => {
|
|
|
- refreshing.value = false
|
|
|
+// 加载更多
|
|
|
+const refreshing = ref(false)
|
|
|
+const loadMore = async () => {
|
|
|
+ try {
|
|
|
+ refreshing.value = true
|
|
|
+ await getChatList('more')
|
|
|
+ } catch (e) { } finally {
|
|
|
+ refreshing.value = false
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
const onClickRight = () => {
|
|
@@ -240,7 +260,7 @@ onMounted(() => {
|
|
|
XYWebSocket.SocketEventsBus.on(XYWebSocket.SocketEvents.chatEvent, async (chat) => {
|
|
|
console.log('XYWebSocket', chat)
|
|
|
if (chat.groupId && chat.groupId === groupId.value) {
|
|
|
- // await initData()
|
|
|
+ // await getChatList()
|
|
|
currConversationChatList.value.push(chat)
|
|
|
}
|
|
|
})
|