Files
Yi.Admin/Yi.Bbs.Vue3/src/stores/chat.js

46 lines
1.1 KiB
JavaScript
Raw Normal View History

2024-04-04 19:28:18 +08:00
import { defineStore } from "pinia";
const chatStore = defineStore("chat", {
state: () => ({
userList: [],
2024-04-06 18:28:32 +08:00
msgList: []
2024-04-04 19:28:18 +08:00
}),
2024-04-06 18:28:32 +08:00
getters: {
allMsgContext: (state) => state.msgList.filter(x=>x.messageType=="All"),
personalMsgContext: (state) => state.msgList.filter(x=>x.messageType=="Personal"),
2024-07-21 13:37:56 +08:00
aiMsgContext: (state) => state.msgList.filter(x=>x.messageType=="Ai")
2024-04-06 18:28:32 +08:00
},
actions:
{
2024-07-21 13:37:56 +08:00
addOrUpdateMsg(msg){
var currentMsg= this.msgList.filter(x => x.id == msg.id)[0];
//当前没有包含,如果有相同的上下文id只需要改变content即可
if(currentMsg==undefined)
{
this.addMsg(msg);
}
else
{
currentMsg.content+=msg.content;
}
},
2024-04-06 18:28:32 +08:00
setMsgList(value) {
this.msgList = value;
},
addMsg(msg) {
this.msgList.push(msg);
},
2024-04-04 19:28:18 +08:00
setUserList(value) {
this.userList = value;
},
2024-04-06 18:28:32 +08:00
addUser(user) {
2024-04-04 19:28:18 +08:00
this.userList.push(user);
},
2024-04-06 18:28:32 +08:00
delUser(userId) {
2024-04-04 19:28:18 +08:00
this.userList = this.userList.filter(obj => obj.userId != userId);
}
},
});
export default chatStore;