2020-08-11 14:42:45 +08:00
|
|
|
export const DASHBOARD_API_PATH = '/api/admin/dashboard'
|
|
|
|
|
|
|
|
const getDefaultDashboardData = () => {
|
|
|
|
return {
|
|
|
|
dashboard: {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const getDefaultLastThirtyDaysData = () => {
|
|
|
|
return {
|
|
|
|
dates: [],
|
|
|
|
articles: [],
|
|
|
|
users: [],
|
2022-03-14 13:49:36 +08:00
|
|
|
visits: [],
|
|
|
|
visitIps: []
|
2020-08-11 14:42:45 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-13 23:09:34 +08:00
|
|
|
const getDefaultNewUserData = () => {
|
|
|
|
return {
|
|
|
|
users: [],
|
|
|
|
pagination: {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const getDefaultNewBankAccountData = () => {
|
|
|
|
return {
|
|
|
|
bankAccounts: [],
|
|
|
|
pagination: {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const getDefaultNewArticleData = () => {
|
|
|
|
return {
|
|
|
|
articles: [],
|
|
|
|
pagination: {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-11 14:42:45 +08:00
|
|
|
export const state = () => {
|
|
|
|
return {
|
|
|
|
fetching: false,
|
|
|
|
data: getDefaultDashboardData(),
|
|
|
|
lastThirtyDays: getDefaultLastThirtyDaysData(),
|
2022-03-13 23:09:34 +08:00
|
|
|
history: getDefaultLastThirtyDaysData(),
|
|
|
|
users: getDefaultNewUserData(),
|
|
|
|
bankAccounts: getDefaultNewBankAccountData(),
|
|
|
|
articles: getDefaultNewArticleData()
|
2020-08-11 14:42:45 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export const mutations = {
|
|
|
|
updateDashboardFetching(state, action) {
|
|
|
|
state.fetching = action
|
|
|
|
},
|
|
|
|
updateDashboardData(state, action) {
|
|
|
|
state.data = action
|
|
|
|
},
|
|
|
|
updateLastThirtyDaysData(state, action) {
|
|
|
|
state.lastThirtyDays = action
|
|
|
|
},
|
|
|
|
updateHistoryData(state, action) {
|
|
|
|
state.history = action
|
2022-03-13 23:09:34 +08:00
|
|
|
},
|
|
|
|
updateNewUsersData(state, action) {
|
|
|
|
state.users = action
|
|
|
|
},
|
|
|
|
updateNewBankAccountsData(state, action) {
|
|
|
|
state.bankAccounts = action
|
|
|
|
},
|
|
|
|
updateNewArticlesData(state, action) {
|
|
|
|
state.articles = action
|
2020-08-11 14:42:45 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export const actions = {
|
|
|
|
fetchDashboard({commit}, params = {}) {
|
2022-06-21 08:33:33 +08:00
|
|
|
if (params && params.reset === '0') {
|
|
|
|
return true;
|
|
|
|
}
|
2020-08-11 14:42:45 +08:00
|
|
|
// 清空已有数据
|
|
|
|
commit('updateDashboardData', getDefaultDashboardData())
|
|
|
|
commit('updateDashboardFetching', true)
|
|
|
|
|
|
|
|
return this.$axios
|
|
|
|
.$get(`${DASHBOARD_API_PATH}`)
|
|
|
|
.then(response => {
|
|
|
|
commit('updateDashboardFetching', false);
|
|
|
|
commit('updateDashboardData', response);
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
console.log(error);
|
|
|
|
commit('updateDashboardFetching', false);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
fetchLastThirtyDays({commit}, params = {}) {
|
2022-06-21 08:33:33 +08:00
|
|
|
if (params && params.reset === '0') {
|
|
|
|
return true;
|
|
|
|
}
|
2020-08-11 14:42:45 +08:00
|
|
|
// 清空已有数据
|
|
|
|
commit('updateLastThirtyDaysData', getDefaultLastThirtyDaysData())
|
|
|
|
commit('updateDashboardFetching', true)
|
|
|
|
|
|
|
|
return this.$axios
|
|
|
|
.$get(`${DASHBOARD_API_PATH}/last-thirty-days`)
|
|
|
|
.then(response => {
|
|
|
|
commit('updateDashboardFetching', false);
|
|
|
|
commit('updateLastThirtyDaysData', response);
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
console.log(error);
|
|
|
|
commit('updateDashboardFetching', false);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
fetchHistory({commit}, params = {}) {
|
2022-06-21 08:33:33 +08:00
|
|
|
if (params && params.reset === '0') {
|
|
|
|
return true;
|
|
|
|
}
|
2020-08-11 14:42:45 +08:00
|
|
|
// 清空已有数据
|
|
|
|
commit('updateHistoryData', getDefaultLastThirtyDaysData())
|
|
|
|
commit('updateDashboardFetching', true)
|
|
|
|
|
|
|
|
return this.$axios
|
|
|
|
.$get(`${DASHBOARD_API_PATH}/history`)
|
|
|
|
.then(response => {
|
|
|
|
commit('updateDashboardFetching', false);
|
|
|
|
commit('updateHistoryData', response);
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
console.log(error);
|
|
|
|
commit('updateDashboardFetching', false);
|
|
|
|
});
|
2022-03-13 23:09:34 +08:00
|
|
|
},
|
|
|
|
fetchNewUsers({commit}, params = {}) {
|
2022-06-21 08:33:33 +08:00
|
|
|
if (params && params.reset === '0') {
|
|
|
|
return true;
|
|
|
|
}
|
2022-03-13 23:09:34 +08:00
|
|
|
// 清空已有数据
|
|
|
|
commit('updateNewUsersData', getDefaultNewUserData())
|
|
|
|
commit('updateDashboardFetching', true)
|
|
|
|
|
|
|
|
return this.$axios
|
|
|
|
.$get(`${DASHBOARD_API_PATH}/new-users`)
|
|
|
|
.then(response => {
|
|
|
|
commit('updateDashboardFetching', false);
|
|
|
|
commit('updateNewUsersData', response);
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
console.log(error);
|
|
|
|
commit('updateDashboardFetching', false);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
fetchNewBankAccounts({commit}, params = {}) {
|
2022-06-21 08:33:33 +08:00
|
|
|
if (params && params.reset === '0') {
|
|
|
|
return true;
|
|
|
|
}
|
2022-03-13 23:09:34 +08:00
|
|
|
// 清空已有数据
|
|
|
|
commit('updateNewBankAccountsData', getDefaultNewBankAccountData())
|
|
|
|
commit('updateDashboardFetching', true)
|
|
|
|
|
|
|
|
return this.$axios
|
|
|
|
.$get(`${DASHBOARD_API_PATH}/new-bank-accounts`)
|
|
|
|
.then(response => {
|
|
|
|
commit('updateDashboardFetching', false);
|
|
|
|
commit('updateNewBankAccountsData', response);
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
console.log(error);
|
|
|
|
commit('updateDashboardFetching', false);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
fetchNewArticles({commit}, params = {}) {
|
2022-06-21 08:33:33 +08:00
|
|
|
if (params && params.reset === '0') {
|
|
|
|
return true;
|
|
|
|
}
|
2022-03-13 23:09:34 +08:00
|
|
|
// 清空已有数据
|
|
|
|
commit('updateNewArticlesData', getDefaultNewBankAccountData())
|
|
|
|
commit('updateDashboardFetching', true)
|
|
|
|
|
|
|
|
return this.$axios
|
|
|
|
.$get(`${DASHBOARD_API_PATH}/new-articles`)
|
|
|
|
.then(response => {
|
|
|
|
commit('updateDashboardFetching', false);
|
|
|
|
commit('updateNewArticlesData', response);
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
console.log(error);
|
|
|
|
commit('updateDashboardFetching', false);
|
|
|
|
});
|
2020-08-11 14:42:45 +08:00
|
|
|
}
|
|
|
|
}
|