用户资料更新规则,基础流程
This commit is contained in:
@@ -11,27 +11,27 @@ export default {
|
||||
},
|
||||
userInfo: (state) => (targetId) => {
|
||||
if (state.friends[targetId]) {
|
||||
return state.friends[targetId]
|
||||
} else {
|
||||
console.log('没找到,死循环了,得处理 todo', targetId);
|
||||
// im.syncUserInfo(targetId)
|
||||
const info = state.friends[targetId]
|
||||
|
||||
return {
|
||||
userId: info.userId,
|
||||
name: info.name,
|
||||
portraitUrl: info.localAvatar ? info.localAvatar : require('@/static/user/cover.png')
|
||||
}
|
||||
} else {
|
||||
return {
|
||||
userId: '',
|
||||
name: '',
|
||||
address: '',
|
||||
hash: '',
|
||||
portraitUrl: ''
|
||||
}
|
||||
}
|
||||
},
|
||||
hasUser: (state) => (targetId) => {
|
||||
return Boolean(state.friends[targetId])
|
||||
},
|
||||
sender(state) {
|
||||
return state.sender
|
||||
}
|
||||
},
|
||||
mutations: {
|
||||
updateFriends(state, userInfo) {
|
||||
updateFriendInfo(state, userInfo) {
|
||||
Vue.set(state.friends, userInfo.userId, userInfo)
|
||||
},
|
||||
SET_state_sender(state, userInfo) {
|
||||
@@ -44,49 +44,79 @@ export default {
|
||||
}, userInfo) {
|
||||
commit('SET_state_sender', userInfo)
|
||||
},
|
||||
updateFriends({
|
||||
// 载入好友信息
|
||||
launchFriend({
|
||||
commit
|
||||
}, data) {
|
||||
commit('updateFriendInfo', data)
|
||||
},
|
||||
// 更新好友信息,这个时候要校验hash值了
|
||||
updateFriend({
|
||||
commit
|
||||
}, userInfo) {
|
||||
commit('updateFriends', userInfo)
|
||||
const model = uni.model.friendModel
|
||||
model.find('userId=' + userInfo.userId, (err, user) => {
|
||||
if (!err && user.length == 0) {
|
||||
saveAvatar(userInfo, (savedFilePath) => {
|
||||
model.insert({
|
||||
model.find('userId=' + userInfo.userId, (err, result) => {
|
||||
if (userInfo.hash != result[0].hash) {
|
||||
commit('updateFriendInfo', userInfo)
|
||||
if (userInfo.portraitUrl && userInfo.portraitUrl != result[0].portraitUrl) {
|
||||
saveAvatar(userInfo, (savedFilePath) => {
|
||||
const info = {
|
||||
userId: userInfo.userId,
|
||||
name: userInfo.name,
|
||||
hash: userInfo.hash,
|
||||
portraitUrl: userInfo.portraitUrl,
|
||||
localAvatar: savedFilePath
|
||||
}
|
||||
model.update('userId=' + userInfo.userId, info)
|
||||
commit('updateFriendInfo', info)
|
||||
})
|
||||
} else {
|
||||
const info = {
|
||||
userId: userInfo.userId,
|
||||
name: userInfo.name,
|
||||
hash: userInfo.hash,
|
||||
address: userInfo.address,
|
||||
portraitUrl: savedFilePath,
|
||||
}, (err, result) => {})
|
||||
userInfo.portraitUrl = savedFilePath
|
||||
commit('updateFriends', userInfo)
|
||||
})
|
||||
} else if (!err && user[0].hash != userInfo.hash) {
|
||||
saveAvatar(userInfo, (savedFilePath) => {
|
||||
model.update('userId=' + userInfo.userId, {
|
||||
name: userInfo.name,
|
||||
hash: userInfo.hash,
|
||||
portraitUrl: savedFilePath,
|
||||
}, (err, result) => {})
|
||||
userInfo.portraitUrl = savedFilePath
|
||||
commit('updateFriends', userInfo)
|
||||
})
|
||||
} else if (!err && user[0].portraitUrl.length > 50) {
|
||||
saveAvatar(userInfo, (savedFilePath) => {
|
||||
model.update('userId=' + userInfo.userId, {
|
||||
name: userInfo.name,
|
||||
hash: userInfo.hash,
|
||||
portraitUrl: savedFilePath,
|
||||
}, (err, result) => {})
|
||||
|
||||
userInfo.portraitUrl = savedFilePath
|
||||
commit('updateFriends', userInfo)
|
||||
})
|
||||
portraitUrl: userInfo.portraitUrl,
|
||||
localAvatar: ''
|
||||
}
|
||||
model.update('userId=' + userInfo.userId, info)
|
||||
}
|
||||
} else {
|
||||
console.log('不用操作', user[0]);
|
||||
console.log('不用更新的用户', userInfo.userId, userInfo.name);
|
||||
}
|
||||
})
|
||||
},
|
||||
// 初始化好友信息
|
||||
initFriend({
|
||||
commit
|
||||
}, userInfo) {
|
||||
// 将好友信息保存到vuex的内存中,方便立即使用
|
||||
commit('updateFriendInfo', userInfo)
|
||||
const model = uni.model.friendModel
|
||||
// 用户头像,是否需要下载到本地
|
||||
if (userInfo.portraitUrl) {
|
||||
saveAvatar(userInfo, (savedFilePath) => {
|
||||
const info = {
|
||||
userId: userInfo.userId,
|
||||
name: userInfo.name,
|
||||
hash: userInfo.hash,
|
||||
portraitUrl: userInfo.portraitUrl,
|
||||
localAvatar: savedFilePath
|
||||
}
|
||||
model.insert(info)
|
||||
// 保存头像后,更新信息
|
||||
commit('updateFriendInfo', info)
|
||||
})
|
||||
} else {
|
||||
// 直接将信息,写入数据库
|
||||
const info = {
|
||||
userId: userInfo.userId,
|
||||
name: userInfo.name,
|
||||
hash: userInfo.hash,
|
||||
portraitUrl: userInfo.portraitUrl,
|
||||
localAvatar: ''
|
||||
}
|
||||
model.insert(info)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user