🎨 获取用户关注用户/粉丝数据功能
This commit is contained in:
parent
c8d2175458
commit
b3bd7a75d5
@ -300,9 +300,12 @@ export default {
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
let user = this.user;
|
||||
let _ts = this;
|
||||
let user = _ts.user;
|
||||
if (user) {
|
||||
this.getUnreadNotifications();
|
||||
_ts.getUnreadNotifications();
|
||||
_ts.$store.dispatch('follow/fetchUserFollowerList');
|
||||
_ts.$store.dispatch('follow/fetchUserFollowingList');
|
||||
// sockClient.initSocket(this.$store.state.userInfo);
|
||||
}
|
||||
}
|
||||
|
95
store/follow.js
Normal file
95
store/follow.js
Normal file
@ -0,0 +1,95 @@
|
||||
/**
|
||||
* @file 用户关注用户、粉丝数据 / ES module
|
||||
* @module store/category
|
||||
* @author Ronger <https://github.com/ronger-x>
|
||||
*/
|
||||
|
||||
export const USER_API_PATH = '/api/user'
|
||||
|
||||
export const state = () => {
|
||||
return {
|
||||
fetching: false,
|
||||
followers: {
|
||||
users: [],
|
||||
pagination: {}
|
||||
},
|
||||
followings: {
|
||||
users: [],
|
||||
pagination: {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const mutations = {
|
||||
updateFetching(state, action) {
|
||||
state.fetching = action
|
||||
},
|
||||
updateUserFollowerList(state, action) {
|
||||
state.followers = action
|
||||
},
|
||||
updateUserFollowingList(state, action) {
|
||||
state.followings = action
|
||||
}
|
||||
}
|
||||
|
||||
export const actions = {
|
||||
fetchUserFollowerList(store) {
|
||||
const {commit, rootState} = store
|
||||
commit('updateFetching', true);
|
||||
commit('updateUserFollowerList', {
|
||||
users: [],
|
||||
pagination: {}
|
||||
})
|
||||
const userInfo = rootState.userInfo
|
||||
if (userInfo == null) {
|
||||
return
|
||||
}
|
||||
let account = userInfo.account
|
||||
return this.$axios
|
||||
.$get(`${USER_API_PATH}/${account}/followers`)
|
||||
.then(response => {
|
||||
commit('updateUserFollowerList', response)
|
||||
commit('updateFetching', false)
|
||||
})
|
||||
.catch(error => {
|
||||
commit('updateFetching', false)
|
||||
})
|
||||
},
|
||||
fetchUserFollowingList(store) {
|
||||
const {commit, rootState} = store
|
||||
commit('updateFetching', true);
|
||||
commit('updateUserFollowingList', {
|
||||
users: [],
|
||||
pagination: {}
|
||||
})
|
||||
const userInfo = rootState.userInfo
|
||||
if (userInfo == null) {
|
||||
return
|
||||
}
|
||||
let account = userInfo.account
|
||||
return this.$axios
|
||||
.$get(`${USER_API_PATH}/${account}/followings`)
|
||||
.then(response => {
|
||||
commit('updateUserFollowingList', response)
|
||||
commit('updateFetching', false)
|
||||
})
|
||||
.catch(error => {
|
||||
commit('updateFetching', false)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export const getters = {
|
||||
isFollower: (state) => (scenes) => {
|
||||
let isFollower = false
|
||||
let users = state.followings.users
|
||||
for (let i in users) {
|
||||
let user = users[i]
|
||||
if (user.idUser === scenes) {
|
||||
isFollower = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return isFollower
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user