Files
td_official/src/store/modules/notice.ts

46 lines
864 B
TypeScript
Raw Normal View History

2025-05-21 11:24:53 +08:00
import { defineStore } from 'pinia';
interface NoticeItem {
title?: string;
read: boolean;
message: any;
time: string;
2025-08-15 01:38:36 +08:00
route?: string;
detailId?: string;
2025-05-21 11:24:53 +08:00
}
export const useNoticeStore = defineStore('notice', () => {
const state = reactive({
2025-08-15 01:38:36 +08:00
notices: [] as NoticeItem[]
2025-05-21 11:24:53 +08:00
});
const addNotice = (notice: NoticeItem) => {
2025-08-15 03:09:20 +08:00
console.log('🚀 ~ addNotice ~ notice:', notice);
2025-05-21 11:24:53 +08:00
state.notices.push(notice);
};
const removeNotice = (notice: NoticeItem) => {
state.notices.splice(state.notices.indexOf(notice), 1);
};
//实现全部已读
const readAll = () => {
state.notices.forEach((item: any) => {
item.read = true;
});
};
const clearNotice = () => {
state.notices = [];
};
return {
state,
addNotice,
removeNotice,
readAll,
clearNotice
};
});
export default useNoticeStore;