|
|
@ -1,10 +1,17 @@ |
|
|
<script> |
|
|
<script> |
|
|
|
|
|
import store from './store' |
|
|
|
|
|
|
|
|
export default { |
|
|
export default { |
|
|
|
|
|
data(){ |
|
|
|
|
|
return { |
|
|
|
|
|
audioTip: null |
|
|
|
|
|
} |
|
|
|
|
|
}, |
|
|
methods: { |
|
|
methods: { |
|
|
init(loginInfo) { |
|
|
init(loginInfo) { |
|
|
// 加载数据 |
|
|
// 加载数据 |
|
|
console.log(this) |
|
|
console.log(this) |
|
|
this.$store.dispatch("load").then(() => { |
|
|
store.dispatch("load").then(() => { |
|
|
// 初始化websocket |
|
|
// 初始化websocket |
|
|
this.initWebSocket(loginInfo); |
|
|
this.initWebSocket(loginInfo); |
|
|
}).catch((e) => { |
|
|
}).catch((e) => { |
|
|
@ -52,19 +59,18 @@ |
|
|
}); |
|
|
}); |
|
|
}, |
|
|
}, |
|
|
handlePrivateMessage(msg) { |
|
|
handlePrivateMessage(msg) { |
|
|
// 好友列表存在好友信息,直接插入私聊消息 |
|
|
let friendId = msg.selfSend ? msg.recvId : msg.sendId; |
|
|
let friendId = msg.selfSend ? msg.recvId : msg.sendId; |
|
|
|
|
|
let friend = this.$store.state.friendStore.friends.find((f) => f.id == friendId); |
|
|
let friend = this.$store.state.friendStore.friends.find((f) => f.id == friendId); |
|
|
if (!friend) { |
|
|
if (!friend) { |
|
|
// 好友列表不存在好友信息,则发请求获取好友信息 |
|
|
|
|
|
this.$http({ |
|
|
this.$http({ |
|
|
url: `/friend/find/${msg.sendId}`, |
|
|
url: `/friend/find/${msg.sendId}`, |
|
|
method: 'get' |
|
|
method: 'GET' |
|
|
}).then((friend) => { |
|
|
}).then((friend) => { |
|
|
this.insertPrivateMessage(friend, msg); |
|
|
this.insertPrivateMessage(friend, msg); |
|
|
this.$store.commit("addFriend", friend); |
|
|
this.$store.commit("addFriend", friend); |
|
|
}) |
|
|
}) |
|
|
} else { |
|
|
} else { |
|
|
|
|
|
// 好友列表不存在好友信息,则发请求获取好友信息 |
|
|
this.insertPrivateMessage(friend, msg); |
|
|
this.insertPrivateMessage(friend, msg); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -101,10 +107,8 @@ |
|
|
|
|
|
|
|
|
}, |
|
|
}, |
|
|
handleGroupMessage(msg) { |
|
|
handleGroupMessage(msg) { |
|
|
// 群聊缓存存在,直接插入群聊消息 |
|
|
|
|
|
let group = this.$store.state.groupStore.groups.find((g) => g.id == msg.groupId); |
|
|
let group = this.$store.state.groupStore.groups.find((g) => g.id == msg.groupId); |
|
|
if (!group) { |
|
|
if (!group) { |
|
|
// 群聊缓存存在,直接插入群聊消息 |
|
|
|
|
|
this.$http({ |
|
|
this.$http({ |
|
|
url: `/group/find/${msg.groupId}`, |
|
|
url: `/group/find/${msg.groupId}`, |
|
|
method: 'get' |
|
|
method: 'get' |
|
|
@ -113,6 +117,7 @@ |
|
|
this.$store.commit("addGroup", group); |
|
|
this.$store.commit("addGroup", group); |
|
|
}) |
|
|
}) |
|
|
} else { |
|
|
} else { |
|
|
|
|
|
// 群聊缓存存在,直接插入群聊消息 |
|
|
this.insertGroupMessage(group, msg); |
|
|
this.insertGroupMessage(group, msg); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -132,10 +137,6 @@ |
|
|
!msg.selfSend && this.playAudioTip(); |
|
|
!msg.selfSend && this.playAudioTip(); |
|
|
}, |
|
|
}, |
|
|
quit() { |
|
|
quit() { |
|
|
uni.showToast({ |
|
|
|
|
|
title: "退出登录" |
|
|
|
|
|
}) |
|
|
|
|
|
console.log("退出登录") |
|
|
|
|
|
this.$wsApi.closeWebSocket(); |
|
|
this.$wsApi.closeWebSocket(); |
|
|
uni.removeStorageSync("loginInfo"); |
|
|
uni.removeStorageSync("loginInfo"); |
|
|
uni.navigateTo({ |
|
|
uni.navigateTo({ |
|
|
@ -143,17 +144,15 @@ |
|
|
}) |
|
|
}) |
|
|
}, |
|
|
}, |
|
|
playAudioTip() { |
|
|
playAudioTip() { |
|
|
// let audio = new Audio(); |
|
|
// 音频播放无法成功 |
|
|
// let url = "/static/audio/tip.wav"; |
|
|
// this.audioTip = uni.createInnerAudioContext(); |
|
|
// audio.src = url; |
|
|
// this.audioTip.src = "/static/audio/tip.wav"; |
|
|
// audio.play(); |
|
|
// this.audioTip.play(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
}, |
|
|
}, |
|
|
onLaunch() { |
|
|
onLaunch() { |
|
|
|
|
|
// 登录状态校验 |
|
|
// 跳转到登录页面 |
|
|
|
|
|
console.log("onLaunch") |
|
|
|
|
|
let loginInfo = uni.getStorageSync("loginInfo"); |
|
|
let loginInfo = uni.getStorageSync("loginInfo"); |
|
|
if (loginInfo) { |
|
|
if (loginInfo) { |
|
|
// 初始化 |
|
|
// 初始化 |
|
|
|