2025-12-02 03:05:52 +08:00
|
|
|
const state = {
|
|
|
|
|
list: [],
|
|
|
|
|
unread_count: 0,
|
2026-01-11 13:51:16 +08:00
|
|
|
top_unread_items: [],
|
2025-12-02 03:05:52 +08:00
|
|
|
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;
|
|
|
|
|
},
|
2026-01-11 13:51:16 +08:00
|
|
|
SET_TOP_UNREAD_ITEMS(state, data) {
|
|
|
|
|
state.top_unread_items = [...data];
|
2025-12-02 03:05:52 +08:00
|
|
|
},
|
|
|
|
|
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=>{
|
2026-02-09 07:29:02 +08:00
|
|
|
console.log("获取朋友圈信息",data);
|
2026-01-11 13:51:16 +08:00
|
|
|
commit("SET_UNREAD_COUNT", data.unread_count);
|
|
|
|
|
commit("SET_TOP_UNREAD_ITEMS", data.top_unread_items);
|
2025-12-02 03:05:52 +08:00
|
|
|
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);
|
2026-01-11 14:00:09 +08:00
|
|
|
const index = state.list.findIndex(i => i.id ==params.id);
|
|
|
|
|
if(index>=0){
|
|
|
|
|
state.list[index].comments.unshift(data);
|
2025-12-08 02:29:46 +08:00
|
|
|
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);
|
2026-01-11 13:51:16 +08:00
|
|
|
const index = state.list.findIndex(i => i.id ==params.id);
|
|
|
|
|
|
|
|
|
|
//console.log("index",index);
|
|
|
|
|
if(index>=0){
|
2025-12-08 02:29:46 +08:00
|
|
|
if(data.is_liked){
|
2026-01-11 13:51:16 +08:00
|
|
|
state.list[index].likes.push({
|
|
|
|
|
user_id:params.user_id,
|
|
|
|
|
nickname:params.nickname,
|
|
|
|
|
avatar:params.avatar
|
|
|
|
|
});
|
|
|
|
|
state.list[index].is_liked = params.is_liked;
|
2025-12-08 02:29:46 +08:00
|
|
|
}else{
|
2026-01-11 13:51:16 +08:00
|
|
|
const likes = state.list[index].likes.filter((item)=>{
|
|
|
|
|
item.user_id != params.user_id
|
|
|
|
|
});
|
|
|
|
|
state.list[index].likes = likes;
|
|
|
|
|
state.list[index].is_liked = params.is_liked;
|
2025-12-08 02:29:46 +08:00
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
},
|
2026-01-15 22:50:35 +08:00
|
|
|
async deleteFriendCircleList({commit,state},params){
|
|
|
|
|
uni.$u.http.post('/friendcircle/delete',params).then(res=>{
|
|
|
|
|
var list = state.list.filter(item=>{
|
|
|
|
|
return item.id!=params.id;
|
|
|
|
|
})
|
|
|
|
|
commit("SET_LIST", list);
|
|
|
|
|
}).catch(e=>{
|
|
|
|
|
console.log(e);
|
|
|
|
|
uni.$u.toast(typeof e == Object ? e?.msg : e);
|
|
|
|
|
})
|
|
|
|
|
}
|
2025-12-02 03:05:52 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
namespaced: true,
|
|
|
|
|
state,
|
|
|
|
|
mutations,
|
|
|
|
|
actions,
|
|
|
|
|
};
|