|
@@ -1,9 +1,9 @@
|
|
<template>
|
|
<template>
|
|
- <div>
|
|
|
|
- <van-nav-bar fixed @click-left="onClickLeft" @click-right="onClickRight">
|
|
|
|
|
|
+ <div class="single-page h-full w-full" style="height: 100vh">
|
|
|
|
+ <van-nav-bar @click-left="onClickLeft" @click-right="onClickRight">
|
|
<template #left>
|
|
<template #left>
|
|
<div>
|
|
<div>
|
|
- <van-icon name="arrow-left" color="black" size="18" />
|
|
|
|
|
|
+ <van-icon name="arrow-left" color="black" size="18"/>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
</template>
|
|
<template #title>
|
|
<template #title>
|
|
@@ -15,170 +15,40 @@
|
|
</div>
|
|
</div>
|
|
</template>
|
|
</template>
|
|
<template #right>
|
|
<template #right>
|
|
- <van-icon name="ellipsis" color="black" size="18" />
|
|
|
|
|
|
+ <van-icon name="ellipsis" color="black" size="18"/>
|
|
</template>
|
|
</template>
|
|
</van-nav-bar>
|
|
</van-nav-bar>
|
|
-
|
|
|
|
- <van-pull-refresh v-model="loading" @refresh="onRefresh">
|
|
|
|
- <div class="w-full h-[100vh] pt-55">
|
|
|
|
- <div ref="messageBoxRef" class="w-full box-border px-12 overflow-y-auto scrollbar">
|
|
|
|
- <van-list
|
|
|
|
- v-model:loading="loading"
|
|
|
|
- :finished="finished"
|
|
|
|
- finished-text="没有更多了"
|
|
|
|
- @load="onLoad"
|
|
|
|
- >
|
|
|
|
- <template v-for="(item, index) in receiveGetter" :key="index">
|
|
|
|
- <!-- 右侧是自己的消息 -->
|
|
|
|
-
|
|
|
|
- <template v-if="item.sendUserId == user.pass">
|
|
|
|
- <!-- 右侧消息 图片 -->
|
|
|
|
- <template v-if="item.messageType == 1">
|
|
|
|
- <div class="w-full text-center text-black/[0.4] mt-24 text-sm">
|
|
|
|
- {{ item.createTime }}
|
|
|
|
- </div>
|
|
|
|
-
|
|
|
|
- <div class="flex justify-end items-start">
|
|
|
|
- <div
|
|
|
|
- class="mr-10 text-left inline-block min-h-46 max-w-full break-words overflow-auto bg-[#FEF4E6] box-border text-base p-12 text-wrap"
|
|
|
|
- >
|
|
|
|
- {{ item.messageContent }}
|
|
|
|
- </div>
|
|
|
|
-
|
|
|
|
- <div class="w-40 h-40 rounded-full overflow-hidden shrink-0">
|
|
|
|
- <img
|
|
|
|
- v-if="user?.headImageUrl"
|
|
|
|
- class="w-full h-full object-cover"
|
|
|
|
- :src="user?.headImageUrl"
|
|
|
|
- alt=""
|
|
|
|
- />
|
|
|
|
- <img
|
|
|
|
- v-else
|
|
|
|
- class="w-full h-full object-cover"
|
|
|
|
- src="~/assets/img/default_avatar.png"
|
|
|
|
- alt=""
|
|
|
|
- />
|
|
|
|
- </div>
|
|
|
|
- </div>
|
|
|
|
- </template>
|
|
|
|
-
|
|
|
|
- <!-- 文字消息 -->
|
|
|
|
- <template v-if="item.messageType == 0 && item.messageContent.trim()">
|
|
|
|
- <div class="w-full text-center text-black/[0.4] mt-24 text-sm">
|
|
|
|
- {{ formatTimestamp(item.createTime) }}
|
|
|
|
- </div>
|
|
|
|
-
|
|
|
|
- <div class="flex justify-end items-start">
|
|
|
|
- <div
|
|
|
|
- class="mr-10 text-left inline-block min-h-46 max-w-full break-words overflow-auto rounded-b-2xl rounded-tl-2xl bg-white box-border text-base p-12 text-wrap"
|
|
|
|
- >
|
|
|
|
- {{ messageContentParse(item.messageContent) }}
|
|
|
|
- </div>
|
|
|
|
- </div>
|
|
|
|
-
|
|
|
|
- <div class="w-40 h-40 rounded-full overflow-hidden shrink-0">
|
|
|
|
- <img
|
|
|
|
- v-if="user?.headImageUrl"
|
|
|
|
- class="w-full h-full object-cover"
|
|
|
|
- :src="user?.headImageUrl"
|
|
|
|
- alt=""
|
|
|
|
- />
|
|
|
|
- <img
|
|
|
|
- v-else
|
|
|
|
- class="w-full h-full object-cover"
|
|
|
|
- src="~/assets/img/default_avatar.png"
|
|
|
|
- alt=""
|
|
|
|
- />
|
|
|
|
- </div>
|
|
|
|
- </template>
|
|
|
|
- </template>
|
|
|
|
-
|
|
|
|
- <!-- 左侧他人的消息 -->
|
|
|
|
- <template v-else>
|
|
|
|
- <!-- 左侧消息 图片 -->
|
|
|
|
- <template v-if="item.messageType == 1">
|
|
|
|
- <div class="w-full text-center text-black/[0.4] mt-24 text-sm">
|
|
|
|
- {{ item.createTime }}
|
|
|
|
- </div>
|
|
|
|
-
|
|
|
|
- <div class="flex justify-end items-start">
|
|
|
|
- <div
|
|
|
|
- class="mr-10 text-left inline-block min-h-46 max-w-full break-words overflow-auto rounded-[4px] bg-white box-border text-base p-12 text-wrap"
|
|
|
|
- >
|
|
|
|
- <!-- {{ item.messageContent }} -->
|
|
|
|
- </div>
|
|
|
|
-
|
|
|
|
- <div class="w-40 h-40 rounded-full overflow-hidden shrink-0">
|
|
|
|
- <img
|
|
|
|
- v-if="user?.headImageUrl"
|
|
|
|
- class="w-full h-full object-cover"
|
|
|
|
- :src="user?.headImageUrl"
|
|
|
|
- alt=""
|
|
|
|
- />
|
|
|
|
- <img
|
|
|
|
- v-else
|
|
|
|
- class="w-full h-full object-cover"
|
|
|
|
- src="~/assets/img/default_avatar.png"
|
|
|
|
- alt=""
|
|
|
|
- />
|
|
|
|
- </div>
|
|
|
|
- </div>
|
|
|
|
- </template>
|
|
|
|
-
|
|
|
|
- <!-- 左侧文字 -->
|
|
|
|
- <!-- <template v-if="item.messageType == 0 && item.messageContent.trim()"> -->
|
|
|
|
- <div class="w-full text-center text-black/[0.4] mt-24 text-sm">
|
|
|
|
- {{ formatTimestamp(item.createTime) }}
|
|
|
|
- </div>
|
|
|
|
-
|
|
|
|
- <div class="flex justify-start items-start">
|
|
|
|
- <div class="w-40 h-40 rounded-full overflow-hidden shrink-0">
|
|
|
|
- <img
|
|
|
|
- v-if="user?.headImageUrl"
|
|
|
|
- class="w-full h-full object-cover"
|
|
|
|
- :src="user?.headImageUrl"
|
|
|
|
- alt=""
|
|
|
|
- />
|
|
|
|
- <img
|
|
|
|
- v-else
|
|
|
|
- class="w-full h-full object-cover"
|
|
|
|
- src="~/assets/img/default_avatar.png"
|
|
|
|
- alt=""
|
|
|
|
- />
|
|
|
|
- </div>
|
|
|
|
-
|
|
|
|
- <div
|
|
|
|
- class="ml-8 inline-block rounded-b-2xl rounded-tr-2xl min-h-46 max-w-full break-words overflow-auto bg-[#F3F3F3] box-border text-base p-12 text-wrap"
|
|
|
|
- >
|
|
|
|
- {{ messageContentParse(item.messageContent) }}
|
|
|
|
- </div>
|
|
|
|
- </div>
|
|
|
|
- <!-- </template> -->
|
|
|
|
- </template>
|
|
|
|
- </template>
|
|
|
|
-
|
|
|
|
- <div ref="msgBottomRef"></div>
|
|
|
|
- </van-list>
|
|
|
|
- </div>
|
|
|
|
- </div>
|
|
|
|
- </van-pull-refresh>
|
|
|
|
-
|
|
|
|
|
|
+ <van-list
|
|
|
|
+ ref="messageBoxRef"
|
|
|
|
+ class="flex-1 overflow-y-auto px-12"
|
|
|
|
+ :finished="true"
|
|
|
|
+ finished-text=""
|
|
|
|
+ >
|
|
|
|
+ <template v-for="(message, index) in receiveGetter" :key="index">
|
|
|
|
+ <ChatMessage :message="message"></ChatMessage>
|
|
|
|
+ </template>
|
|
|
|
+ </van-list>
|
|
|
|
+ <div class="h-88 w-full bg-[#333]"></div>
|
|
<ProfileNewsChatInput
|
|
<ProfileNewsChatInput
|
|
- :shareGroup="false"
|
|
|
|
- @on-select-Img="selectImg"
|
|
|
|
- @on-send-message="sendMessage"
|
|
|
|
|
|
+ :shareGroup="false"
|
|
|
|
+ @on-select-Img="selectImg"
|
|
|
|
+ @on-send-message="sendMessage"
|
|
></ProfileNewsChatInput>
|
|
></ProfileNewsChatInput>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
</template>
|
|
<script setup>
|
|
<script setup>
|
|
-import { messageContentParse, formatTimestamp } from '~/utils/detalTime'
|
|
|
|
|
|
+import ChatMessage from './chat-message'
|
|
|
|
+import {messageContentParse, formatTimestamp} from '~/utils/detalTime'
|
|
|
|
+import {findHyperlinks} from "~/pages/chat/chat-message/link-message/handle";
|
|
|
|
+
|
|
const route = useRoute()
|
|
const route = useRoute()
|
|
const router = useRouter()
|
|
const router = useRouter()
|
|
-
|
|
|
|
|
|
+const refreshing = ref(false)
|
|
const uploadUrl = `${import.meta.env.VITE_APP_BASE_URL}/website/tourMessage/upload`
|
|
const uploadUrl = `${import.meta.env.VITE_APP_BASE_URL}/website/tourMessage/upload`
|
|
const chatStore = useChatStore()
|
|
const chatStore = useChatStore()
|
|
-const { ws, curConversiton, receive, receiveGetter, connectSta, onNewMessage } =
|
|
|
|
- storeToRefs(chatStore)
|
|
|
|
|
|
+const {ws, curConversiton, receive, receiveGetter, connectSta, onNewMessage} =
|
|
|
|
+ storeToRefs(chatStore)
|
|
|
|
+
|
|
const user = computed(() => chatStore.user)
|
|
const user = computed(() => chatStore.user)
|
|
|
|
|
|
// 消息接收者的用户id
|
|
// 消息接收者的用户id
|
|
@@ -230,7 +100,9 @@ const messageList = ref([])
|
|
const title = computed(() => route.query.groupRemark)
|
|
const title = computed(() => route.query.groupRemark)
|
|
|
|
|
|
// 刷新
|
|
// 刷新
|
|
-const onRefresh = () => {}
|
|
|
|
|
|
+const onRefresh = () => {
|
|
|
|
+ refreshing.value = false
|
|
|
|
+}
|
|
|
|
|
|
const onClickLeft = () => router.back()
|
|
const onClickLeft = () => router.back()
|
|
|
|
|
|
@@ -249,7 +121,6 @@ function sendMessage(messageParams) {
|
|
console.log(messageParams, 'messageParams')
|
|
console.log(messageParams, 'messageParams')
|
|
console.log(getUserId.value, '5555')
|
|
console.log(getUserId.value, '5555')
|
|
console.log(noticeType, '5555')
|
|
console.log(noticeType, '5555')
|
|
-
|
|
|
|
if (!messageParams.trim()) return
|
|
if (!messageParams.trim()) return
|
|
let msg = {
|
|
let msg = {
|
|
// getUserId: getUserId.value,
|
|
// getUserId: getUserId.value,
|
|
@@ -264,10 +135,14 @@ function sendMessage(messageParams) {
|
|
id: getLocalId()
|
|
id: getLocalId()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ const isLink = !!findHyperlinks(messageParams)
|
|
|
|
+ if (isLink) {
|
|
|
|
+ msg.messageType = 4
|
|
|
|
+ }
|
|
|
|
|
|
receive.value.push({
|
|
receive.value.push({
|
|
...msg,
|
|
...msg,
|
|
- messageContent: JSON.stringify({ messageContent: msg.messageContent })
|
|
|
|
|
|
+ messageContent: JSON.stringify({messageContent: msg.messageContent})
|
|
})
|
|
})
|
|
messageContent.value = ''
|
|
messageContent.value = ''
|
|
messageBoxRef.value.scrollTop = messageBoxRef.value.scrollHeight
|
|
messageBoxRef.value.scrollTop = messageBoxRef.value.scrollHeight
|
|
@@ -297,8 +172,8 @@ async function getChatHistory(messageId = '') {
|
|
}
|
|
}
|
|
|
|
|
|
const {
|
|
const {
|
|
- data: { data = [], count = [] }
|
|
|
|
- } = await request('/website/tourMessage/getMessageByGroupId', { query })
|
|
|
|
|
|
+ data: {data = [], count = []}
|
|
|
|
+ } = await request('/website/tourMessage/getMessageByGroupId', {query})
|
|
|
|
|
|
messageCount.value = count || 0
|
|
messageCount.value = count || 0
|
|
|
|
|
|
@@ -310,7 +185,7 @@ async function getChatHistory(messageId = '') {
|
|
if (!messageId) {
|
|
if (!messageId) {
|
|
nextTick(() => {
|
|
nextTick(() => {
|
|
setTimeout(() => {
|
|
setTimeout(() => {
|
|
- messageBoxRef.value && messageBoxRef.value.scrollTo({ top: msgBottomRef.value.offsetTop })
|
|
|
|
|
|
+ messageBoxRef.value && messageBoxRef.value.scrollTo({top: msgBottomRef.value.offsetTop})
|
|
}, 100)
|
|
}, 100)
|
|
})
|
|
})
|
|
}
|
|
}
|
|
@@ -321,7 +196,8 @@ async function getChatHistory(messageId = '') {
|
|
function addEventListenerTextarea() {
|
|
function addEventListenerTextarea() {
|
|
nextTick(() => {
|
|
nextTick(() => {
|
|
if (inputBoxRef.value) {
|
|
if (inputBoxRef.value) {
|
|
- inputBoxRef.value.removeEventListener('keydown', () => {})
|
|
|
|
|
|
+ inputBoxRef.value.removeEventListener('keydown', () => {
|
|
|
|
+ })
|
|
inputBoxRef.value.addEventListener('keydown', function (event) {
|
|
inputBoxRef.value.addEventListener('keydown', function (event) {
|
|
if (event.key === 'Enter') {
|
|
if (event.key === 'Enter') {
|
|
event.preventDefault()
|
|
event.preventDefault()
|
|
@@ -336,7 +212,8 @@ function addEventListenerTextarea() {
|
|
function addEventListenerMessage() {
|
|
function addEventListenerMessage() {
|
|
nextTick(() => {
|
|
nextTick(() => {
|
|
if (messageBoxRef.value) {
|
|
if (messageBoxRef.value) {
|
|
- messageBoxRef.value.removeEventListener('scroll', () => {})
|
|
|
|
|
|
+ messageBoxRef.value.removeEventListener('scroll', () => {
|
|
|
|
+ })
|
|
|
|
|
|
messageBoxRef.value.addEventListener('scroll', (e) => {
|
|
messageBoxRef.value.addEventListener('scroll', (e) => {
|
|
if (messageBoxRef.value.scrollTop == 0 && receive.value[0]?.id) {
|
|
if (messageBoxRef.value.scrollTop == 0 && receive.value[0]?.id) {
|
|
@@ -350,51 +227,32 @@ function addEventListenerMessage() {
|
|
}
|
|
}
|
|
|
|
|
|
// 选择发送图片
|
|
// 选择发送图片
|
|
-function selectImg(e) {
|
|
|
|
- const file = e.target.files[0]
|
|
|
|
-
|
|
|
|
- const { size, type, name } = file
|
|
|
|
- const IMIETypes = ['image/jpeg', 'image/png', 'image/gif']
|
|
|
|
-
|
|
|
|
- if (!IMIETypes.includes(type)) {
|
|
|
|
- showToast('请上传图片')
|
|
|
|
-
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- const maxSize = 1024 * 1024 * 20
|
|
|
|
-
|
|
|
|
- if (size > maxSize) {
|
|
|
|
- showFailToast('图片大小不能超过10M')
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- const formData = new FormData()
|
|
|
|
-
|
|
|
|
- formData.append('uploadFile', file)
|
|
|
|
- formData.append('fieldName', 'messageContent')
|
|
|
|
- formData.append('asImage', true)
|
|
|
|
-
|
|
|
|
- request(uploadUrl, { method: 'post', body: formData }).then((res) => {
|
|
|
|
- const {
|
|
|
|
- data: { fileUrl }
|
|
|
|
- } = res
|
|
|
|
- if (fileUrl) {
|
|
|
|
- const msg = {
|
|
|
|
- getUserId: getUserId.value,
|
|
|
|
- sendUserId: sendUserId.value,
|
|
|
|
- specialUserId: '',
|
|
|
|
- groupId: groupId.value,
|
|
|
|
- messageContent: fileUrl,
|
|
|
|
- messageType: 1,
|
|
|
|
- noticeType: noticeType.value,
|
|
|
|
- object: {
|
|
|
|
- id: getLocalId()
|
|
|
|
- }
|
|
|
|
|
|
+function selectImg(fileUrl) {
|
|
|
|
+ try {
|
|
|
|
+ console.log(fileUrl, 'fileUrl')
|
|
|
|
+ const msg = {
|
|
|
|
+ getUserId: getUserId.value,
|
|
|
|
+ sendUserId: sendUserId.value,
|
|
|
|
+ specialUserId: '',
|
|
|
|
+ groupId: groupId.value,
|
|
|
|
+ messageContent: JSON.stringify({messageContent: fileUrl}),
|
|
|
|
+ messageType: 1,
|
|
|
|
+ noticeType: noticeType.value,
|
|
|
|
+ object: {
|
|
|
|
+ id: getLocalId()
|
|
}
|
|
}
|
|
- ws.value.send(JSON.stringify(msg))
|
|
|
|
}
|
|
}
|
|
- })
|
|
|
|
|
|
+ receive.value.push({
|
|
|
|
+ ...msg,
|
|
|
|
+ messageContent: JSON.stringify({messageContent: fileUrl})
|
|
|
|
+ })
|
|
|
|
+ messageBoxRef.value.scrollTop = messageBoxRef.value.scrollHeight
|
|
|
|
+ ws.value.send(JSON.stringify(msg))
|
|
|
|
+ } catch (e) {
|
|
|
|
+ console.error(e, '??')
|
|
|
|
+ } finally {
|
|
|
|
+
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
// 获取我与对方的关注情况
|
|
// 获取我与对方的关注情况
|
|
@@ -404,7 +262,7 @@ async function isFollow() {
|
|
const query = {
|
|
const query = {
|
|
userId: curConversiton.value.toUserId
|
|
userId: curConversiton.value.toUserId
|
|
}
|
|
}
|
|
- const { data: status = 0 } = await request('/website/tourGroup/isFollow', { query })
|
|
|
|
|
|
+ const {data: status = 0} = await request('/website/tourGroup/isFollow', {query})
|
|
followStatus.value = status
|
|
followStatus.value = status
|
|
console.log('关注情况:', status)
|
|
console.log('关注情况:', status)
|
|
}
|
|
}
|
|
@@ -426,7 +284,8 @@ watch(groupId, async () => {
|
|
getChatHistory()
|
|
getChatHistory()
|
|
})
|
|
})
|
|
|
|
|
|
-watch(onNewMessage, getUserId, sendUserId, () => {})
|
|
|
|
|
|
+watch(onNewMessage, getUserId, sendUserId, () => {
|
|
|
|
+})
|
|
|
|
|
|
onMounted(() => {
|
|
onMounted(() => {
|
|
// 获取前会话用户的聊天记录
|
|
// 获取前会话用户的聊天记录
|
|
@@ -443,4 +302,11 @@ definePageMeta({
|
|
layout: false
|
|
layout: false
|
|
})
|
|
})
|
|
</script>
|
|
</script>
|
|
-<style lang="scss" scoped></style>
|
|
|
|
|
|
+<style lang="scss" scoped>
|
|
|
|
+.single-page {
|
|
|
|
+ height: 100vh;
|
|
|
|
+ display: flex;
|
|
|
|
+ flex-direction: column;
|
|
|
|
+ min-height: 0;
|
|
|
|
+}
|
|
|
|
+</style>
|