feat: 头部新增消息按钮

This commit is contained in:
xlsea
2025-06-04 19:27:50 +08:00
parent 3c2f4e45ef
commit c7d850b93a
6 changed files with 167 additions and 2 deletions

View File

@ -1,5 +1,6 @@
import { reactive } from 'vue';
import { defineStore } from 'pinia';
import { SetupStoreId } from '@/enum';
interface NoticeItem {
title?: string;
@ -8,7 +9,7 @@ interface NoticeItem {
time: string;
}
export const useNoticeStore = defineStore('notice', () => {
export const useNoticeStore = defineStore(SetupStoreId.Notice, () => {
const state = reactive({
notices: [] as NoticeItem[]
});
@ -21,6 +22,10 @@ export const useNoticeStore = defineStore('notice', () => {
state.notices.splice(state.notices.indexOf(notice), 1);
};
const readNotice = (notice: NoticeItem) => {
state.notices[state.notices.indexOf(notice)].read = true;
};
// 实现全部已读
const readAll = () => {
state.notices.forEach((item: any) => {
@ -31,10 +36,12 @@ export const useNoticeStore = defineStore('notice', () => {
const clearNotice = () => {
state.notices = [];
};
return {
state,
addNotice,
removeNotice,
readNotice,
readAll,
clearNotice
};