2025-12-02 03:05:52 +08:00
|
|
|
const state = {
|
|
|
|
|
list: [],
|
|
|
|
|
unread_count: 0,
|
|
|
|
|
last_unread_item: {"avatar":"","user_id":"","nickname":""},
|
|
|
|
|
settings: {bg:""}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const mutations = {
|
2025-12-05 16:10:52 +08:00
|
|
|
SET_LIST(state, list) {
|
2025-12-02 03:05:52 +08:00
|
|
|
state.list = [...list];
|
|
|
|
|
},
|
|
|
|
|
SET_UNREAD_COUNT(state, count) {
|
|
|
|
|
state.unread_count = count;
|
|
|
|
|
if(count<1){
|
|
|
|
|
uni.removeTabBarBadge({
|
|
|
|
|
index:2
|
|
|
|
|
})
|
|
|
|
|
}else{
|
|
|
|
|
uni.setTabBarBadge({
|
|
|
|
|
index:2,
|
|
|
|
|
text:count
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
SET_LAST_UNREAD(state, data) {
|
|
|
|
|
state.last_unread_item = {...data};
|
|
|
|
|
},
|
|
|
|
|
SET_SETTINGS(state, data) {
|
|
|
|
|
state.settings = {...data};
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const actions = {
|
|
|
|
|
async getFriendCircleList({ commit},params) {
|
|
|
|
|
uni.$u.http.get('/friendcircle/list',params).then(res=>{
|
|
|
|
|
commit("SET_LIST", res.data);
|
|
|
|
|
}).catch(e=>{
|
2025-12-05 16:10:52 +08:00
|
|
|
console.log(e);
|
|
|
|
|
uni.$u.toast("获取信息失败");
|
2025-12-02 03:05:52 +08:00
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
async getFriendCircleInfo({ commit, state}) {
|
|
|
|
|
uni.$u.http.get('/friendcircle/info').then(data=>{
|
|
|
|
|
commit("SET_UNREAD_COUNT", data.count);
|
|
|
|
|
commit("SET_LAST_UNREAD", data.last_unread_item);
|
|
|
|
|
commit("SET_SETTINGS", data.settings);
|
|
|
|
|
}).catch(e=>{
|
2025-12-05 16:10:52 +08:00
|
|
|
uni.$u.toast("获取信息失败");
|
2025-12-02 03:05:52 +08:00
|
|
|
})
|
|
|
|
|
},
|
2025-12-08 02:29:46 +08:00
|
|
|
async comment({ commit, state},params) {
|
|
|
|
|
return new Promise((resolve,reject)=>{
|
|
|
|
|
uni.$u.http.post('/friendcircle/comment',params).then(data=>{
|
|
|
|
|
console.log("评论成功",data);
|
|
|
|
|
let index = -1;
|
|
|
|
|
for(let i=0;i<state.list.length;i++){
|
|
|
|
|
if(state.list[i].id==params.id){
|
|
|
|
|
index = i;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
console.log("index",index);
|
|
|
|
|
if(index!=-1){
|
|
|
|
|
state.list[index].comments.unshift(params);
|
|
|
|
|
resolve(data);
|
|
|
|
|
}else{
|
|
|
|
|
reject(data);
|
|
|
|
|
}
|
|
|
|
|
}).catch(e=>{
|
|
|
|
|
console.log("评论失败",e);
|
|
|
|
|
uni.$u.toast("评论失败");
|
|
|
|
|
reject(e);
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
async like({commit, state},params) {
|
|
|
|
|
return new Promise((resolve,reject)=>{
|
|
|
|
|
uni.$u.http.post('/friendcircle/like',params).then(data=>{
|
|
|
|
|
console.log("点赞成功",data);
|
|
|
|
|
let index = -1;
|
|
|
|
|
for(let i=0;i<state.list.length;i++){
|
|
|
|
|
if(state.list[i].id==params.id){
|
|
|
|
|
index = i;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
console.log("index",index);
|
|
|
|
|
if(index!=-1){
|
|
|
|
|
if(data.is_liked){
|
|
|
|
|
state.list[index].likes.push(params.user_id);
|
|
|
|
|
}else{
|
|
|
|
|
state.list[index].likes.splice(state.list[index].likes.indexOf(params.user_id),1);
|
|
|
|
|
}
|
|
|
|
|
resolve(data);
|
|
|
|
|
}else{
|
|
|
|
|
reject(data);
|
|
|
|
|
}
|
|
|
|
|
}).catch(e=>{
|
|
|
|
|
console.log("点赞失败",e);
|
|
|
|
|
uni.$u.toast("点赞失败");
|
|
|
|
|
reject(e);
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
},
|
2025-12-02 03:05:52 +08:00
|
|
|
async updateUnreadCount({commit,state},v) {
|
|
|
|
|
commit("SET_UNREAD_COUNT", state.unread_count+v);
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
namespaced: true,
|
|
|
|
|
state,
|
|
|
|
|
mutations,
|
|
|
|
|
actions,
|
|
|
|
|
};
|