wx-starlock/stores/notification.js

50 lines
1.4 KiB
JavaScript
Raw Permalink Normal View History

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