|
@@ -19,30 +19,33 @@
|
|
|
</template>
|
|
|
</van-nav-bar>
|
|
|
<van-list
|
|
|
- ref="chatListRef"
|
|
|
- class="flex-1 overflow-y-auto px-12 flex flex-col"
|
|
|
- :finished="true"
|
|
|
- finished-text=""
|
|
|
+ ref="chatListRef"
|
|
|
+ class="flex-1 overflow-y-auto px-12 flex flex-col"
|
|
|
+ :finished="true"
|
|
|
+ finished-text=""
|
|
|
>
|
|
|
<template v-for="(message, index) in receiveGetter" :key="index">
|
|
|
<ChatMessage :message="message"></ChatMessage>
|
|
|
</template>
|
|
|
- <div v-if="false" class="text-[#979797] text-sm text-center mt-auto mb-10">{{followStatus}}在对方关注或回复前,最多只能发送1条信息</div>
|
|
|
+ <div v-if="false" class="text-[#979797] text-sm text-center mt-auto mb-10">
|
|
|
+ {{ followStatus }}在对方关注或回复前,最多只能发送1条信息
|
|
|
+ </div>
|
|
|
</van-list>
|
|
|
- <ChatInput :operates="['image']" @focus="scrollToBottom" @send="handleSendMessage"></ChatInput>
|
|
|
+ <ChatInput :operates="['image']" @focus="scrollToBottom" @send="handleSendMessage"></ChatInput>
|
|
|
</div>
|
|
|
</template>
|
|
|
<script setup>
|
|
|
import ChatMessage from './chat-message'
|
|
|
-import ChatInput from "./chat-input";
|
|
|
-import {findHyperlinks} from "~/pages/chat/chat-message/link-message/handle";
|
|
|
+import ChatInput from './chat-input'
|
|
|
+import { findHyperlinks } from '~/pages/chat/chat-message/link-message/handle'
|
|
|
|
|
|
const route = useRoute()
|
|
|
const router = useRouter()
|
|
|
const refreshing = ref(false)
|
|
|
-const chatStore = useChatStore();
|
|
|
+const chatStore = useChatStore()
|
|
|
const user = computed(() => chatStore.user)
|
|
|
-const {ws, curConversiton, receive, conversations, receiveGetter, connectSta, onNewMessage} = storeToRefs(chatStore)
|
|
|
+const { ws, curConversiton, receive, conversations, receiveGetter, connectSta, onNewMessage } =
|
|
|
+ storeToRefs(chatStore)
|
|
|
console.warn(curConversiton, 'curConversitoncurConversiton')
|
|
|
// 单聊的标题
|
|
|
const title = computed(() => route.query.groupRemark)
|
|
@@ -74,7 +77,6 @@ const onRefresh = () => {
|
|
|
refreshing.value = false
|
|
|
}
|
|
|
|
|
|
-
|
|
|
const onClickRight = () => {
|
|
|
navigateTo({
|
|
|
path: '/chat/set-single',
|
|
@@ -90,8 +92,6 @@ const messageCount = ref(0)
|
|
|
|
|
|
// 获取聊天记录
|
|
|
async function getChatHistory(messageId = '') {
|
|
|
- if (curConversiton.value.isLocal) return
|
|
|
-
|
|
|
if (!groupId.value) return
|
|
|
|
|
|
if (receive.value.length >= messageCount.value && receive.value.length > 0) return
|
|
@@ -105,8 +105,8 @@ async function getChatHistory(messageId = '') {
|
|
|
}
|
|
|
|
|
|
const {
|
|
|
- data: {data = [], count = []}
|
|
|
- } = await request('/website/tourMessage/getMessageByGroupId', {query})
|
|
|
+ data: { data = [], count = [] }
|
|
|
+ } = await request('/website/tourMessage/getMessageByGroupId', { query })
|
|
|
|
|
|
messageCount.value = count || 0
|
|
|
|
|
@@ -123,14 +123,14 @@ async function getFollowStatus() {
|
|
|
const query = {
|
|
|
userId: getUserId.value
|
|
|
}
|
|
|
- const {data: status = 0} = await request('/website/tourGroup/isFollow', {query})
|
|
|
+ const { data: status = 0 } = await request('/website/tourGroup/isFollow', { query })
|
|
|
followStatus.value = status
|
|
|
console.log('关注情况:', status)
|
|
|
}
|
|
|
|
|
|
// 发送文本消息
|
|
|
const sendTextMessage = (text) => {
|
|
|
- if(!text) return
|
|
|
+ if (!text) return
|
|
|
let msg = {
|
|
|
groupId: groupId.value,
|
|
|
getUserId: getUserId.value,
|
|
@@ -144,11 +144,11 @@ const sendTextMessage = (text) => {
|
|
|
}
|
|
|
}
|
|
|
const isLink = !!findHyperlinks(text)
|
|
|
- if (isLink) msg.messageType = 4;
|
|
|
+ if (isLink) msg.messageType = 4
|
|
|
|
|
|
receive.value.push({
|
|
|
...msg,
|
|
|
- messageContent: JSON.stringify({messageContent: msg.messageContent})
|
|
|
+ messageContent: JSON.stringify({ messageContent: msg.messageContent })
|
|
|
})
|
|
|
ws.value.send(JSON.stringify(msg))
|
|
|
}
|
|
@@ -160,7 +160,7 @@ const sendImageMessage = async (file) => {
|
|
|
formData.append('uploadFile', file)
|
|
|
formData.append('asImage', true)
|
|
|
formData.append('fieldName', 'messageContent')
|
|
|
- const {data} = await request('/website/tourMessage/upload', {
|
|
|
+ const { data } = await request('/website/tourMessage/upload', {
|
|
|
method: 'post',
|
|
|
body: formData
|
|
|
})
|
|
@@ -170,7 +170,7 @@ const sendImageMessage = async (file) => {
|
|
|
getUserId: getUserId.value,
|
|
|
sendUserId: sendUserId.value,
|
|
|
specialUserId: '',
|
|
|
- messageContent: JSON.stringify({messageContent: data.fileUrl}),
|
|
|
+ messageContent: JSON.stringify({ messageContent: data.fileUrl }),
|
|
|
messageType: 1,
|
|
|
noticeType: 1,
|
|
|
object: {
|
|
@@ -179,46 +179,40 @@ const sendImageMessage = async (file) => {
|
|
|
}
|
|
|
receive.value.push({
|
|
|
...msg,
|
|
|
- messageContent: JSON.stringify({messageContent: data.fileUrl})
|
|
|
+ messageContent: JSON.stringify({ messageContent: data.fileUrl })
|
|
|
})
|
|
|
|
|
|
ws.value.send(JSON.stringify(msg))
|
|
|
} catch (e) {
|
|
|
console.error(e, '??')
|
|
|
} finally {
|
|
|
-
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-const handleSendMessage = async ({type, messageContent}) => {
|
|
|
+const handleSendMessage = async ({ type, messageContent }) => {
|
|
|
try {
|
|
|
switch (type) {
|
|
|
case 'text':
|
|
|
sendTextMessage(messageContent)
|
|
|
- break;
|
|
|
+ break
|
|
|
case 'image':
|
|
|
await sendImageMessage(messageContent)
|
|
|
- break;
|
|
|
+ break
|
|
|
}
|
|
|
await scrollToBottom()
|
|
|
} catch (e) {
|
|
|
-
|
|
|
} finally {
|
|
|
-
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
-
|
|
|
const scrollToBottom = async () => {
|
|
|
- await nextTick(); // 确保DOM已经更新
|
|
|
- const listElement = chatListRef.value?.$el;
|
|
|
+ await nextTick() // 确保DOM已经更新
|
|
|
+ const listElement = chatListRef.value?.$el
|
|
|
if (listElement) {
|
|
|
- const scrollContainer = listElement;
|
|
|
- scrollContainer.scrollTop = scrollContainer.scrollHeight;
|
|
|
+ const scrollContainer = listElement
|
|
|
+ scrollContainer.scrollTop = scrollContainer.scrollHeight
|
|
|
}
|
|
|
-};
|
|
|
-
|
|
|
+}
|
|
|
|
|
|
watch(groupId, () => {
|
|
|
// 消息置空
|
|
@@ -241,6 +235,27 @@ onMounted(() => {
|
|
|
// }, 500)
|
|
|
})
|
|
|
|
|
|
+// 用户删除消息
|
|
|
+const delMessage = (messageId) => {
|
|
|
+ showConfirmDialog({
|
|
|
+ width: 260,
|
|
|
+ message: '是否删除这条消息?',
|
|
|
+ confirmButtonColor: '#FF9300'
|
|
|
+ })
|
|
|
+ .then(async () => {
|
|
|
+ const res = await request('/website/tourMessage/delMessage', {
|
|
|
+ method: 'post',
|
|
|
+ body: {
|
|
|
+ messageId: [messageId]
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ if (res && res?.success) {
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .catch(() => {})
|
|
|
+}
|
|
|
+
|
|
|
definePageMeta({
|
|
|
layout: false
|
|
|
})
|