|
@@ -30,7 +30,7 @@
|
|
|
:key="index"
|
|
|
@click="toView(item)"
|
|
|
>
|
|
|
- <div class="line" v-if="item._id == id"></div>
|
|
|
+ <div class="line" v-if="item.id == id"></div>
|
|
|
<el-col :span="4" class="left">
|
|
|
<a-badge :dot="item.is_read == '0'">
|
|
|
<a-avatar :size="60" style="background-color: #409eff">
|
|
@@ -80,7 +80,7 @@
|
|
|
import moment from 'moment'
|
|
|
import Chat from './parts/chat.vue'
|
|
|
import { SearchOutlined } from '@ant-design/icons-vue'
|
|
|
-import { sendWebsocket, closeWebsocket } from '@/utils/websocket'
|
|
|
+// import { sendWebsocket, closeWebsocket } from '@/utils/websocket'
|
|
|
// 接口
|
|
|
import { ChatStore } from '@/store/api/platform/chat'
|
|
|
import { UsersStore } from '@/store/api/user/user'
|
|
@@ -117,31 +117,31 @@ const textarea = ref('')
|
|
|
onMounted(async () => {
|
|
|
loading.value = true
|
|
|
await search()
|
|
|
- sendWebsocket('ws://localhost:9700', wsMessage, wsError, succeed)
|
|
|
+ // sendWebsocket('ws://localhost:9700', wsMessage, wsError, succeed)
|
|
|
loading.value = false
|
|
|
})
|
|
|
|
|
|
-onBeforeUnmount(() => {
|
|
|
- closeWebsocket()
|
|
|
-})
|
|
|
+// onBeforeUnmount(() => {
|
|
|
+// closeWebsocket()
|
|
|
+// })
|
|
|
|
|
|
// ws连接成功,后台返回的ws数据,组件要拿数据渲染页面等操作
|
|
|
const wsMessage = async (data) => {
|
|
|
const dataJson = data
|
|
|
- if (dataJson && dataJson._id) {
|
|
|
+ if (dataJson && dataJson.id) {
|
|
|
if (
|
|
|
- (dataJson.sender_id == user.value.id && dataJson.receiver_id == id.value) ||
|
|
|
- (dataJson.sender_id == id.value && dataJson.receiver_id == user.value.id)
|
|
|
+ (dataJson.senderid == user.value.id && dataJson.receiverid == id.value) ||
|
|
|
+ (dataJson.senderid == id.value && dataJson.receiverid == user.value.id)
|
|
|
) {
|
|
|
await searchList()
|
|
|
list.value.push(dataJson)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-// ws连接失败,组件要执行的代码
|
|
|
-const wsError = async () => {
|
|
|
- sendWebsocket('ws://localhost:9700', wsMessage, wsError, succeed)
|
|
|
-}
|
|
|
+// // ws连接失败,组件要执行的代码
|
|
|
+// const wsError = async () => {
|
|
|
+// sendWebsocket('ws://localhost:9700', wsMessage, wsError, succeed)
|
|
|
+// }
|
|
|
// ws连接成功,组件要执行的代码
|
|
|
const succeed = async () => {
|
|
|
console.log('ws连接成功')
|
|
@@ -162,9 +162,9 @@ const searchList = async () => {
|
|
|
}
|
|
|
|
|
|
const toView = async (item) => {
|
|
|
- id.value = item._id
|
|
|
+ id.value = item.id
|
|
|
info.value = item
|
|
|
- await chatstore.read({ sender_id: user.value.id, receiver_id: id.value })
|
|
|
+ await chatstore.read({ senderid: user.value.id, receiverid: id.value })
|
|
|
await searchList()
|
|
|
await searchChat({ skip, limit })
|
|
|
}
|
|
@@ -172,7 +172,7 @@ const searchChat = async (query = { skip: 0, limit }) => {
|
|
|
const data = {
|
|
|
skip: query.skip,
|
|
|
limit: query.limit,
|
|
|
- user: info.value._id,
|
|
|
+ user: info.value.id,
|
|
|
...searchForm.value
|
|
|
}
|
|
|
const res = await chatstore.query(data)
|
|
@@ -181,8 +181,8 @@ const searchChat = async (query = { skip: 0, limit }) => {
|
|
|
}
|
|
|
const toSend = async () => {
|
|
|
const data = {
|
|
|
- sender_id: user.value.id,
|
|
|
- receiver_id: id.value,
|
|
|
+ senderid: user.value.id,
|
|
|
+ receiverid: id.value,
|
|
|
type: '0',
|
|
|
content: textarea.value,
|
|
|
send_time: moment().format('YYYY-MM-DD HH:mm:ss')
|