|
@@ -80,7 +80,8 @@ import {
|
|
|
watch,
|
|
|
nextTick,
|
|
|
onUnmounted,
|
|
|
- onActivated, onMounted
|
|
|
+ onMounted,
|
|
|
+ onActivated
|
|
|
} from "vue";
|
|
|
import Client from "../../../../utils/client";
|
|
|
import {
|
|
@@ -212,7 +213,6 @@ export default defineComponent({
|
|
|
if (data.length < 20) {
|
|
|
state.isFinished = true;
|
|
|
}
|
|
|
- let beforeListHeight = (messageListDom.value as HTMLElement).offsetHeight;
|
|
|
state.messageList.unshift(...data.reverse())
|
|
|
nextTick(() => {
|
|
|
if (state.page === 1) {
|
|
@@ -221,6 +221,7 @@ export default defineComponent({
|
|
|
} else if (state.page === 2) {
|
|
|
scrollToBottom()
|
|
|
} else {
|
|
|
+ const beforeListHeight = (messageListDom.value as HTMLElement).offsetHeight;
|
|
|
setScrollTop(beforeListHeight)
|
|
|
}
|
|
|
state.page++
|
|
@@ -231,7 +232,7 @@ export default defineComponent({
|
|
|
}
|
|
|
|
|
|
const scrollToBottom = () => {
|
|
|
- (messageContentDom.value as HTMLElement).scrollTop = (messageContentDom.value as HTMLElement).scrollHeight
|
|
|
+ (messageContentDom.value as HTMLElement).scrollTop = (messageContentDom.value as HTMLElement)?.scrollHeight
|
|
|
}
|
|
|
|
|
|
const setScrollTop = (beforeListHeight: number) => {
|
|
@@ -253,34 +254,40 @@ export default defineComponent({
|
|
|
}
|
|
|
})
|
|
|
|
|
|
- // @ts-ignore
|
|
|
- new Client({ //这里是私聊
|
|
|
- userId: store.state.userInfo.id,
|
|
|
- notify: function (data: string) {
|
|
|
- const msg = JSON.parse(data)
|
|
|
- if (store.state.chatUserInfo.friendId === msg.fromUserId) {
|
|
|
- state.messageList.push(msg)
|
|
|
- nextTick(() => {
|
|
|
- scrollToBottom()
|
|
|
- })
|
|
|
- } else {
|
|
|
- store.commit('setNotReadMessage', msg.fromUserId)
|
|
|
- store.commit('hasNotReadMsgUserSort')
|
|
|
- }
|
|
|
- }
|
|
|
+ onActivated(() => {
|
|
|
+ scrollToBottom()
|
|
|
})
|
|
|
|
|
|
- const groupClient: Obj = {}
|
|
|
+ if (!store.state.client) {
|
|
|
+ // @ts-ignore
|
|
|
+ const client = new Client({ //这里是私聊
|
|
|
+ userId: store.state.userInfo.id,
|
|
|
+ notify: function (data: string) {
|
|
|
+ const msg = JSON.parse(data)
|
|
|
+ if (store.state.chatUserInfo.friendId === msg.fromUserId) {
|
|
|
+ state.messageList.push(msg)
|
|
|
+ nextTick(() => {
|
|
|
+ scrollToBottom()
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ store.commit('setNotReadMessage', msg.fromUserId)
|
|
|
+ store.commit('hasNotReadMsgUserSort')
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ store.commit('setClient', client)
|
|
|
+ }
|
|
|
+
|
|
|
watch(() => store.state.chatUserInfo, val => {
|
|
|
// isGroup:1是私聊,2是群聊
|
|
|
if (val.isGroup !== 2) {
|
|
|
return;
|
|
|
}
|
|
|
- if (groupClient[val.friendId]) {
|
|
|
+ if (store.state.groupClient[val.friendId]) {
|
|
|
return
|
|
|
}
|
|
|
// @ts-ignore
|
|
|
- groupClient[val.friendId] = new Client({ // 这里是群聊
|
|
|
+ const client = new Client({ // 这里是群聊
|
|
|
friendId: val.friendId,
|
|
|
notify: function (data: string) {
|
|
|
const msg = JSON.parse(data)
|
|
@@ -297,9 +304,10 @@ export default defineComponent({
|
|
|
}
|
|
|
}
|
|
|
})
|
|
|
+ store.commit('setGroupClient', {[val.friendId]: client})
|
|
|
})
|
|
|
|
|
|
- const sendMsg = async () => {
|
|
|
+ const sendMsg = async (isSendLink?: any) => {
|
|
|
let content = state.message.trim()
|
|
|
// 把表情包转成:__表情包的英文名字__
|
|
|
content = content.replace(RE.emoji, (a, emoji) => `__${emojiMap[emoji.codePointAt(0)]}__`)
|
|
@@ -315,7 +323,7 @@ export default defineComponent({
|
|
|
}
|
|
|
state.message = ''
|
|
|
state.messageList.push(data)
|
|
|
- document.getElementById('textarea')?.focus()
|
|
|
+ isSendLink !== true && document.getElementById('textarea')?.focus()
|
|
|
nextTick(() => {
|
|
|
scrollToBottom()
|
|
|
})
|
|
@@ -348,7 +356,7 @@ export default defineComponent({
|
|
|
confirmButtonText: '发送链接'
|
|
|
}).then(() => {
|
|
|
state.message = message
|
|
|
- sendMsg()
|
|
|
+ sendMsg(true)
|
|
|
Toast(store.state.chatUserInfo.isGroup === 1 ? '会议链接已发送给好友' : '会议链接已发送到群里')
|
|
|
}).catch(() => {
|
|
|
toClipboard(message).then(() => {
|
|
@@ -378,7 +386,11 @@ export default defineComponent({
|
|
|
await deleteFriend({id: chatUserInfo.friendId})
|
|
|
let i = store.state.userList.indexOf(chatUserInfo)
|
|
|
store.state.userList.splice(i, 1)
|
|
|
- store.commit('setIsShowRight', false)
|
|
|
+ if (Config.isPhone) {
|
|
|
+ router.back()
|
|
|
+ } else {
|
|
|
+ store.commit('setIsShowRight', false)
|
|
|
+ }
|
|
|
Toast.success('删除成功')
|
|
|
})
|
|
|
}
|
|
@@ -394,7 +406,11 @@ export default defineComponent({
|
|
|
})
|
|
|
let i = store.state.userList.indexOf(chatUserInfo)
|
|
|
store.state.userList.splice(i, 1)
|
|
|
- store.commit('setIsShowRight', false)
|
|
|
+ if (Config.isPhone) {
|
|
|
+ router.back()
|
|
|
+ } else {
|
|
|
+ store.commit('setIsShowRight', false)
|
|
|
+ }
|
|
|
})
|
|
|
}
|
|
|
}
|
|
@@ -609,7 +625,6 @@ export default defineComponent({
|
|
|
}
|
|
|
|
|
|
.send-btn {
|
|
|
- margin-left: 6px;
|
|
|
margin-bottom: 9px;
|
|
|
|
|
|
.text {
|