群组聊天的基础功能,nvue

This commit is contained in:
2022-02-10 16:46:23 +08:00
parent 13aed4abf5
commit 8656ddef55
19 changed files with 361 additions and 433 deletions

View File

@@ -12,23 +12,24 @@ export default {
contactInfo: (state) => (targetId) => {
if (state.contacts[targetId]) {
const info = state.contacts[targetId]
console.log(targetId, info);
return {
name: info.name,
name: info.name,
hash: info.hash,
portraitUrl: info.localAvatar ? info.localAvatar : require('@/static/user/cover.png')
}
} else {
return {
name: '',
name: '',
hash: '',
portraitUrl: ''
}
}
},
},
// 联系人是否存在
contactIsExist: (state) => (targetId) => {
return Boolean(state.contacts[targetId])
contactIsExist: (state) => (targetId) => {
return Boolean(state.contacts[targetId])
},
sender(state) {
return state.myInfo
@@ -60,11 +61,15 @@ export default {
},
// 更新好友信息这个时候要校验hash值了
updateContact({
commit
commit,
dispatch
}, contactInfo) {
const model = uni.model.contactModel
model.find('targetId=' + contactInfo.targetId, (err, result) => {
if (contactInfo.hash != result[0].hash) {
model.find('targetId="' + contactInfo.targetId + '"', (err, result) => {
if (result.length == 0) {
// 没有数据,直接新增一条
dispatch('initContact', contactInfo)
} else if (contactInfo.hash != result[0].hash) {
commit('updateContactInfo', contactInfo)
if (contactInfo.portraitUrl && contactInfo.portraitUrl != result[0].portraitUrl) {
saveAvatar(contactInfo, (savedFilePath) => {
@@ -86,7 +91,7 @@ export default {
portraitUrl: contactInfo.portraitUrl,
localAvatar: result[0].localAvatar
}
model.update('targetId=' + contactInfo.targetId, info, (err, res) => {})
model.update('targetId="' + contactInfo.targetId + '"', info, (err, res) => {})
}
} else {}
})