import { defineStore } from 'pinia' import { getNotificationList } from '@/api/notification' export const useNotificationStore = defineStore('notification', { state() { return { // 通知列表 notificationList: [], // 通知总数 notificationTotal: 0, // 通知列表搜索数据 notificationSearch: { pageNo: 1, pageSize: 50 } } }, actions: { // 删除通知列表某一项数据 deleteNotificationItem(index) { this.notificationList.splice(index, 1) }, // 更新某一项通知列表数据 updateNotificationItem(index, params) { this.notificationList[index] = { ...this.notificationList[index], ...params } }, // 更新通知列表搜索数据 updateNotificationSearch(params) { this.notificationSearch = { ...this.notificationSearch, ...params } }, // 获取通知列表 async getNotificationList(params) { const { code, data, message } = await getNotificationList({ pageNo: params.pageNo, pageSize: params.pageSize }) if (code === 0) { this.notificationTotal = data.total if (params.pageNo === 1) { this.notificationList = data.list } else { this.notificationList = this.notificationList.concat(data.list) } return { code } } return { code, message } } } })