2020-08-02 19:21:51 +08:00
|
|
|
export const NOTIFICATION_API_PATH = '/api/notification'
|
|
|
|
|
|
|
|
const getDefaultListData = () => {
|
|
|
|
return {
|
|
|
|
notifications: [],
|
|
|
|
pagination: {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export const state = () => {
|
|
|
|
return {
|
|
|
|
list: {
|
|
|
|
fetching: false,
|
|
|
|
data: getDefaultListData()
|
2021-03-15 21:16:01 +08:00
|
|
|
},
|
|
|
|
updateState: false
|
2020-08-02 19:21:51 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export const mutations = {
|
|
|
|
// 消息列表
|
|
|
|
updateListFetching(state, action) {
|
|
|
|
state.list.fetching = action
|
|
|
|
},
|
|
|
|
updateListData(state, action) {
|
|
|
|
state.list.data = action
|
2021-03-15 21:16:01 +08:00
|
|
|
},
|
|
|
|
updateState(state, action) {
|
|
|
|
state.updateState = action
|
2020-08-02 19:21:51 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export const actions = {
|
|
|
|
// 获取消息列表
|
2021-03-06 09:59:38 +08:00
|
|
|
fetchList({commit, state}, params = {}) {
|
2020-08-02 19:21:51 +08:00
|
|
|
// 清空已有数据
|
|
|
|
commit('updateListFetching', true)
|
2021-03-06 09:59:38 +08:00
|
|
|
// 当前页判断
|
|
|
|
let currentData = JSON.parse(JSON.stringify(state)).list.data
|
2021-03-15 21:16:01 +08:00
|
|
|
let updateState = state.updateState
|
|
|
|
if (!updateState) {
|
2022-07-26 21:04:19 +08:00
|
|
|
if (Number(params.page) === currentData?.pageNum) {
|
2021-03-15 21:16:01 +08:00
|
|
|
commit('updateListFetching', false)
|
|
|
|
return
|
|
|
|
}
|
2021-03-06 09:59:38 +08:00
|
|
|
}
|
|
|
|
commit('updateListData', getDefaultListData())
|
2020-08-02 19:21:51 +08:00
|
|
|
let data = {
|
|
|
|
page: params.page || 1
|
|
|
|
}
|
|
|
|
|
2021-03-15 21:16:01 +08:00
|
|
|
commit('updateState', false)
|
|
|
|
|
2020-08-02 19:21:51 +08:00
|
|
|
return this.$axios
|
|
|
|
.$get(`${NOTIFICATION_API_PATH}/all`, {
|
|
|
|
params: data
|
|
|
|
})
|
|
|
|
.then(response => {
|
|
|
|
commit('updateListFetching', false);
|
|
|
|
commit('updateListData', response);
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
console.log(error);
|
|
|
|
commit('updateListFetching', false);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|