!50 add 新增 前端接入websocket接收消息

*  add 新增 前端接入websocket接收消息
This commit is contained in:
三个三
2023-11-02 04:36:31 +00:00
committed by 疯狂的狮子Li
parent 1e3f18ce22
commit a8a334b3c3
8 changed files with 344 additions and 0 deletions

View File

@ -0,0 +1,42 @@
import { defineStore } from 'pinia';
interface NoticeItem {
title?: string;
read: boolean;
message: any;
time: string;
}
export const useNoticeStore = defineStore('notice', () => {
const state = reactive({
notices: [] as NoticeItem[]
});
const addNotice = (notice: NoticeItem) => {
state.notices.push(notice);
};
const removeNotice = (notice: NoticeItem) => {
state.notices.splice(state.notices.indexOf(notice), 1);
};
//实现全部已读
const readAll = () => {
state.notices.forEach((item) => {
item.read = true;
});
};
const clearNotice = () => {
state.notices = [];
};
return {
state,
addNotice,
removeNotice,
readAll,
clearNotice
};
});
export default useNoticeStore;